[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r16581 - in gnunet/src: arm ats block chat core datacache d
From: |
gnunet |
Subject: |
[GNUnet-SVN] r16581 - in gnunet/src: arm ats block chat core datacache datastore dht dv fragmentation fs hello hostlist include mesh nat nse peerinfo peerinfo-tool statistics template testing topology transport transport/wlan util vpn |
Date: |
Mon, 15 Aug 2011 23:46:36 +0200 |
Author: grothoff
Date: 2011-08-15 23:46:35 +0200 (Mon, 15 Aug 2011)
New Revision: 16581
Modified:
gnunet/src/arm/arm_api.c
gnunet/src/arm/do_start_process.c
gnunet/src/arm/gnunet-arm.c
gnunet/src/arm/gnunet-service-arm.c
gnunet/src/arm/gnunet-service-arm.h
gnunet/src/arm/gnunet-service-arm_interceptor.c
gnunet/src/arm/mockup-service.c
gnunet/src/arm/test_arm_api.c
gnunet/src/arm/test_exponential_backoff.c
gnunet/src/arm/test_gnunet_service_manager.c
gnunet/src/ats/ats_api.c
gnunet/src/block/block.c
gnunet/src/block/plugin_block_dht.c
gnunet/src/block/plugin_block_dns.c
gnunet/src/block/plugin_block_fs.c
gnunet/src/block/plugin_block_template.c
gnunet/src/block/plugin_block_test.c
gnunet/src/block/test_block.c
gnunet/src/chat/chat.c
gnunet/src/chat/gnunet-chat.c
gnunet/src/chat/gnunet-service-chat.c
gnunet/src/chat/test_chat.c
gnunet/src/chat/test_chat_private.c
gnunet/src/core/core_api.c
gnunet/src/core/core_api_iterate_peers.c
gnunet/src/core/gnunet-core-list-connections.c
gnunet/src/core/gnunet-service-core.c
gnunet/src/core/test_core_api.c
gnunet/src/core/test_core_api_preferences.c
gnunet/src/core/test_core_api_reliability.c
gnunet/src/core/test_core_api_send_to_self.c
gnunet/src/core/test_core_api_start_only.c
gnunet/src/core/test_core_quota_compliance.c
gnunet/src/datacache/datacache.c
gnunet/src/datacache/perf_datacache.c
gnunet/src/datacache/plugin_datacache_mysql.c
gnunet/src/datacache/plugin_datacache_postgres.c
gnunet/src/datacache/plugin_datacache_sqlite.c
gnunet/src/datacache/plugin_datacache_template.c
gnunet/src/datacache/test_datacache.c
gnunet/src/datacache/test_datacache_quota.c
gnunet/src/datastore/datastore.h
gnunet/src/datastore/datastore_api.c
gnunet/src/datastore/gnunet-service-datastore.c
gnunet/src/datastore/perf_datastore_api.c
gnunet/src/datastore/perf_plugin_datastore.c
gnunet/src/datastore/plugin_datastore_mysql.c
gnunet/src/datastore/plugin_datastore_postgres.c
gnunet/src/datastore/plugin_datastore_sqlite.c
gnunet/src/datastore/plugin_datastore_template.c
gnunet/src/datastore/test_datastore_api.c
gnunet/src/datastore/test_datastore_api_management.c
gnunet/src/datastore/test_plugin_datastore.c
gnunet/src/dht/dht.h
gnunet/src/dht/dht_api.c
gnunet/src/dht/dht_api_find_peer.c
gnunet/src/dht/dht_api_get_put.c
gnunet/src/dht/dhtlog.c
gnunet/src/dht/dhtlog.h
gnunet/src/dht/gnunet-dht-driver.c
gnunet/src/dht/gnunet-dht-get-peer.c
gnunet/src/dht/gnunet-dht-get.c
gnunet/src/dht/gnunet-dht-put.c
gnunet/src/dht/gnunet-service-dht.c
gnunet/src/dht/plugin_dhtlog_dummy.c
gnunet/src/dht/plugin_dhtlog_mysql.c
gnunet/src/dht/plugin_dhtlog_mysql_dump.c
gnunet/src/dht/plugin_dhtlog_mysql_dump_load.c
gnunet/src/dht/test_dht_api.c
gnunet/src/dht/test_dht_multipeer.c
gnunet/src/dht/test_dht_twopeer.c
gnunet/src/dht/test_dht_twopeer_path_tracking.c
gnunet/src/dht/test_dht_twopeer_put_get.c
gnunet/src/dht/test_dhtlog.c
gnunet/src/dv/dv.h
gnunet/src/dv/dv_api.c
gnunet/src/dv/gnunet-service-dv.c
gnunet/src/dv/plugin_transport_dv.c
gnunet/src/dv/test_transport_api_dv.c
gnunet/src/fragmentation/defragmentation.c
gnunet/src/fragmentation/fragmentation.c
gnunet/src/fragmentation/test_fragmentation.c
gnunet/src/fs/fs.c
gnunet/src/fs/fs.h
gnunet/src/fs/fs_directory.c
gnunet/src/fs/fs_download.c
gnunet/src/fs/fs_file_information.c
gnunet/src/fs/fs_getopt.c
gnunet/src/fs/fs_list_indexed.c
gnunet/src/fs/fs_misc.c
gnunet/src/fs/fs_namespace.c
gnunet/src/fs/fs_publish.c
gnunet/src/fs/fs_search.c
gnunet/src/fs/fs_test_lib.c
gnunet/src/fs/fs_test_lib.h
gnunet/src/fs/fs_tree.c
gnunet/src/fs/fs_tree.h
gnunet/src/fs/fs_unindex.c
gnunet/src/fs/fs_uri.c
gnunet/src/fs/gnunet-directory.c
gnunet/src/fs/gnunet-download.c
gnunet/src/fs/gnunet-pseudonym.c
gnunet/src/fs/gnunet-publish.c
gnunet/src/fs/gnunet-search.c
gnunet/src/fs/gnunet-service-fs.c
gnunet/src/fs/gnunet-service-fs.h
gnunet/src/fs/gnunet-service-fs_cp.c
gnunet/src/fs/gnunet-service-fs_cp.h
gnunet/src/fs/gnunet-service-fs_indexing.c
gnunet/src/fs/gnunet-service-fs_indexing.h
gnunet/src/fs/gnunet-service-fs_lc.c
gnunet/src/fs/gnunet-service-fs_lc.h
gnunet/src/fs/gnunet-service-fs_pe.c
gnunet/src/fs/gnunet-service-fs_pe.h
gnunet/src/fs/gnunet-service-fs_pr.c
gnunet/src/fs/gnunet-service-fs_pr.h
gnunet/src/fs/gnunet-service-fs_push.c
gnunet/src/fs/gnunet-service-fs_push.h
gnunet/src/fs/gnunet-service-fs_put.c
gnunet/src/fs/gnunet-service-fs_put.h
gnunet/src/fs/gnunet-unindex.c
gnunet/src/fs/perf_gnunet_service_fs_p2p.c
gnunet/src/fs/perf_gnunet_service_fs_p2p_trust.c
gnunet/src/fs/test_fs.c
gnunet/src/fs/test_fs_directory.c
gnunet/src/fs/test_fs_download.c
gnunet/src/fs/test_fs_download_indexed.c
gnunet/src/fs/test_fs_download_persistence.c
gnunet/src/fs/test_fs_download_recursive.c
gnunet/src/fs/test_fs_file_information.c
gnunet/src/fs/test_fs_getopt.c
gnunet/src/fs/test_fs_list_indexed.c
gnunet/src/fs/test_fs_namespace.c
gnunet/src/fs/test_fs_namespace_list_updateable.c
gnunet/src/fs/test_fs_publish.c
gnunet/src/fs/test_fs_publish_persistence.c
gnunet/src/fs/test_fs_search.c
gnunet/src/fs/test_fs_search_persistence.c
gnunet/src/fs/test_fs_search_ranking.c
gnunet/src/fs/test_fs_start_stop.c
gnunet/src/fs/test_fs_test_lib.c
gnunet/src/fs/test_fs_unindex.c
gnunet/src/fs/test_fs_unindex_persistence.c
gnunet/src/fs/test_fs_uri.c
gnunet/src/fs/test_gnunet_service_fs_migration.c
gnunet/src/fs/test_gnunet_service_fs_p2p.c
gnunet/src/hello/hello.c
gnunet/src/hello/test_hello.c
gnunet/src/hostlist/gnunet-daemon-hostlist.c
gnunet/src/hostlist/hostlist-client.c
gnunet/src/hostlist/hostlist-client.h
gnunet/src/hostlist/hostlist-server.c
gnunet/src/hostlist/hostlist-server.h
gnunet/src/hostlist/test_gnunet_daemon_hostlist.c
gnunet/src/hostlist/test_gnunet_daemon_hostlist_learning.c
gnunet/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c
gnunet/src/include/gettext.h
gnunet/src/include/gnunet_arm_service.h
gnunet/src/include/gnunet_ats_service.h
gnunet/src/include/gnunet_bandwidth_lib.h
gnunet/src/include/gnunet_bio_lib.h
gnunet/src/include/gnunet_block_lib.h
gnunet/src/include/gnunet_block_plugin.h
gnunet/src/include/gnunet_chat_service.h
gnunet/src/include/gnunet_client_lib.h
gnunet/src/include/gnunet_common.h
gnunet/src/include/gnunet_configuration_lib.h
gnunet/src/include/gnunet_connection_lib.h
gnunet/src/include/gnunet_container_lib.h
gnunet/src/include/gnunet_core_service.h
gnunet/src/include/gnunet_crypto_lib.h
gnunet/src/include/gnunet_datacache_lib.h
gnunet/src/include/gnunet_datacache_plugin.h
gnunet/src/include/gnunet_datastore_plugin.h
gnunet/src/include/gnunet_datastore_service.h
gnunet/src/include/gnunet_dht_service.h
gnunet/src/include/gnunet_disk_lib.h
gnunet/src/include/gnunet_dv_service.h
gnunet/src/include/gnunet_fragmentation_lib.h
gnunet/src/include/gnunet_fs_service.h
gnunet/src/include/gnunet_getopt_lib.h
gnunet/src/include/gnunet_hello_lib.h
gnunet/src/include/gnunet_load_lib.h
gnunet/src/include/gnunet_mesh_service.h
gnunet/src/include/gnunet_mesh_service_new.h
gnunet/src/include/gnunet_nat_lib.h
gnunet/src/include/gnunet_network_lib.h
gnunet/src/include/gnunet_nse_service.h
gnunet/src/include/gnunet_os_lib.h
gnunet/src/include/gnunet_peer_lib.h
gnunet/src/include/gnunet_peerinfo_service.h
gnunet/src/include/gnunet_pseudonym_lib.h
gnunet/src/include/gnunet_resolver_service.h
gnunet/src/include/gnunet_scheduler_lib.h
gnunet/src/include/gnunet_server_lib.h
gnunet/src/include/gnunet_service_lib.h
gnunet/src/include/gnunet_statistics_service.h
gnunet/src/include/gnunet_strings_lib.h
gnunet/src/include/gnunet_testing_lib.h
gnunet/src/include/gnunet_time_lib.h
gnunet/src/include/gnunet_transport_plugin.h
gnunet/src/include/gnunet_transport_service.h
gnunet/src/include/platform.h
gnunet/src/include/plibc.h
gnunet/src/include/winproc.h
gnunet/src/mesh/gnunet-service-mesh.c
gnunet/src/mesh/mesh.h
gnunet/src/mesh/mesh_api.c
gnunet/src/mesh/mesh_api_new.c
gnunet/src/mesh/mesh_protocol.h
gnunet/src/mesh/test_mesh_api.c
gnunet/src/mesh/test_mesh_small.c
gnunet/src/nat/gnunet-helper-nat-client-windows.c
gnunet/src/nat/gnunet-helper-nat-client.c
gnunet/src/nat/gnunet-helper-nat-server-windows.c
gnunet/src/nat/gnunet-helper-nat-server.c
gnunet/src/nat/gnunet-nat-server.c
gnunet/src/nat/nat.c
gnunet/src/nat/nat.h
gnunet/src/nat/nat_mini.c
gnunet/src/nat/nat_test.c
gnunet/src/nat/test_nat.c
gnunet/src/nat/test_nat_mini.c
gnunet/src/nat/test_nat_test.c
gnunet/src/nse/gnunet-nse-profiler.c
gnunet/src/nse/gnunet-service-nse.c
gnunet/src/nse/nse_api.c
gnunet/src/nse/test_nse_api.c
gnunet/src/nse/test_nse_multipeer.c
gnunet/src/peerinfo-tool/gnunet-peerinfo.c
gnunet/src/peerinfo/gnunet-service-peerinfo.c
gnunet/src/peerinfo/peerinfo_api.c
gnunet/src/peerinfo/peerinfo_api_notify.c
gnunet/src/peerinfo/perf_peerinfo_api.c
gnunet/src/peerinfo/test_peerinfo_api.c
gnunet/src/statistics/gnunet-service-statistics.c
gnunet/src/statistics/gnunet-statistics.c
gnunet/src/statistics/statistics.h
gnunet/src/statistics/statistics_api.c
gnunet/src/statistics/test_statistics_api.c
gnunet/src/statistics/test_statistics_api_loop.c
gnunet/src/statistics/test_statistics_api_watch.c
gnunet/src/template/gnunet-service-template.c
gnunet/src/template/gnunet-template.c
gnunet/src/testing/test_testing.c
gnunet/src/testing/test_testing_connect.c
gnunet/src/testing/test_testing_group.c
gnunet/src/testing/test_testing_group_remote.c
gnunet/src/testing/test_testing_large_topology.c
gnunet/src/testing/test_testing_peergroup.c
gnunet/src/testing/test_testing_reconnect.c
gnunet/src/testing/test_testing_topology.c
gnunet/src/testing/test_testing_topology_blacklist.c
gnunet/src/testing/test_testing_topology_churn.c
gnunet/src/testing/testing.c
gnunet/src/testing/testing_group.c
gnunet/src/testing/testing_peergroup.c
gnunet/src/topology/gnunet-daemon-topology.c
gnunet/src/topology/test_gnunet_daemon_topology.c
gnunet/src/transport/gnunet-service-transport-new.c
gnunet/src/transport/gnunet-service-transport.c
gnunet/src/transport/gnunet-service-transport_ats.c
gnunet/src/transport/gnunet-service-transport_ats.h
gnunet/src/transport/gnunet-service-transport_blacklist.c
gnunet/src/transport/gnunet-service-transport_blacklist.h
gnunet/src/transport/gnunet-service-transport_clients.c
gnunet/src/transport/gnunet-service-transport_clients.h
gnunet/src/transport/gnunet-service-transport_hello.c
gnunet/src/transport/gnunet-service-transport_hello.h
gnunet/src/transport/gnunet-service-transport_neighbours.c
gnunet/src/transport/gnunet-service-transport_neighbours.h
gnunet/src/transport/gnunet-service-transport_plugins.c
gnunet/src/transport/gnunet-service-transport_plugins.h
gnunet/src/transport/gnunet-service-transport_validation.c
gnunet/src/transport/gnunet-service-transport_validation.h
gnunet/src/transport/gnunet-transport-certificate-creation.c
gnunet/src/transport/gnunet-transport-list-connections.c
gnunet/src/transport/gnunet-transport-wlan-helper.c
gnunet/src/transport/gnunet-transport-wlan-helper.h
gnunet/src/transport/ieee80211_radiotap.h
gnunet/src/transport/perf_transport_ats.c
gnunet/src/transport/plugin_transport_http.c
gnunet/src/transport/plugin_transport_smtp.c
gnunet/src/transport/plugin_transport_tcp.c
gnunet/src/transport/plugin_transport_template.c
gnunet/src/transport/plugin_transport_udp.c
gnunet/src/transport/plugin_transport_unix.c
gnunet/src/transport/plugin_transport_wlan.c
gnunet/src/transport/plugin_transport_wlan.h
gnunet/src/transport/test_plugin_transport.c
gnunet/src/transport/test_plugin_transport_http.c
gnunet/src/transport/test_plugin_transport_https.c
gnunet/src/transport/test_plugin_transport_udp.c
gnunet/src/transport/test_plugin_transport_wlan_dummy.c
gnunet/src/transport/test_quota_compliance.c
gnunet/src/transport/test_transport_api.c
gnunet/src/transport/test_transport_api_disconnect.c
gnunet/src/transport/test_transport_api_multiaddress.c
gnunet/src/transport/test_transport_api_reliability.c
gnunet/src/transport/test_transport_api_unreliability.c
gnunet/src/transport/test_transport_ats.c
gnunet/src/transport/test_transport_ats_multiple_peers.c
gnunet/src/transport/test_transport_testing.c
gnunet/src/transport/transport-testing.c
gnunet/src/transport/transport-testing.h
gnunet/src/transport/transport.h
gnunet/src/transport/transport_api.c
gnunet/src/transport/transport_api_address_iterate.c
gnunet/src/transport/transport_api_address_lookup.c
gnunet/src/transport/transport_api_blacklist.c
gnunet/src/transport/transport_api_peer_address_lookup.c
gnunet/src/transport/wlan/byteorder.h
gnunet/src/transport/wlan/crctable_osdep.h
gnunet/src/transport/wlan/helper_common.c
gnunet/src/transport/wlan/helper_common.h
gnunet/src/transport/wlan/ieee80211.h
gnunet/src/transport/wlan/ieee80211_radiotap.h
gnunet/src/transport/wlan/loopback_helper.h
gnunet/src/transport/wlan/radiotap-parser.c
gnunet/src/transport/wlan/radiotap-parser.h
gnunet/src/util/bandwidth.c
gnunet/src/util/bio.c
gnunet/src/util/client.c
gnunet/src/util/common_allocation.c
gnunet/src/util/common_logging.c
gnunet/src/util/configuration.c
gnunet/src/util/connection.c
gnunet/src/util/container_bloomfilter.c
gnunet/src/util/container_heap.c
gnunet/src/util/container_meta_data.c
gnunet/src/util/container_multihashmap.c
gnunet/src/util/container_slist.c
gnunet/src/util/crypto_aes.c
gnunet/src/util/crypto_crc.c
gnunet/src/util/crypto_hash.c
gnunet/src/util/crypto_hkdf.c
gnunet/src/util/crypto_kdf.c
gnunet/src/util/crypto_ksk.c
gnunet/src/util/crypto_random.c
gnunet/src/util/crypto_rsa.c
gnunet/src/util/disk.c
gnunet/src/util/disk.h
gnunet/src/util/getopt.c
gnunet/src/util/getopt_helpers.c
gnunet/src/util/gnunet-config-diff.c
gnunet/src/util/gnunet-resolver.c
gnunet/src/util/gnunet-service-resolver.c
gnunet/src/util/load.c
gnunet/src/util/network.c
gnunet/src/util/os_installation.c
gnunet/src/util/os_network.c
gnunet/src/util/os_priority.c
gnunet/src/util/peer.c
gnunet/src/util/perf_crypto_hash.c
gnunet/src/util/plugin.c
gnunet/src/util/program.c
gnunet/src/util/pseudonym.c
gnunet/src/util/resolver_api.c
gnunet/src/util/scheduler.c
gnunet/src/util/server.c
gnunet/src/util/server_mst.c
gnunet/src/util/server_nc.c
gnunet/src/util/server_tc.c
gnunet/src/util/service.c
gnunet/src/util/signal.c
gnunet/src/util/strings.c
gnunet/src/util/test_bio.c
gnunet/src/util/test_client.c
gnunet/src/util/test_common_allocation.c
gnunet/src/util/test_common_logging.c
gnunet/src/util/test_configuration.c
gnunet/src/util/test_connection.c
gnunet/src/util/test_connection_addressing.c
gnunet/src/util/test_connection_receive_cancel.c
gnunet/src/util/test_connection_timeout.c
gnunet/src/util/test_connection_timeout_no_connect.c
gnunet/src/util/test_connection_transmit_cancel.c
gnunet/src/util/test_container_bloomfilter.c
gnunet/src/util/test_container_heap.c
gnunet/src/util/test_container_meta_data.c
gnunet/src/util/test_container_multihashmap.c
gnunet/src/util/test_container_slist.c
gnunet/src/util/test_crypto_aes.c
gnunet/src/util/test_crypto_aes_weak.c
gnunet/src/util/test_crypto_hash.c
gnunet/src/util/test_crypto_hkdf.c
gnunet/src/util/test_crypto_ksk.c
gnunet/src/util/test_crypto_random.c
gnunet/src/util/test_crypto_rsa.c
gnunet/src/util/test_disk.c
gnunet/src/util/test_getopt.c
gnunet/src/util/test_os_start_process.c
gnunet/src/util/test_peer.c
gnunet/src/util/test_program.c
gnunet/src/util/test_pseudonym.c
gnunet/src/util/test_resolver_api.c
gnunet/src/util/test_scheduler.c
gnunet/src/util/test_scheduler_delay.c
gnunet/src/util/test_server.c
gnunet/src/util/test_server_disconnect.c
gnunet/src/util/test_server_with_client.c
gnunet/src/util/test_server_with_client_unix.c
gnunet/src/util/test_service.c
gnunet/src/util/test_strings.c
gnunet/src/util/test_time.c
gnunet/src/util/time.c
gnunet/src/util/winproc.c
gnunet/src/vpn/gnunet-daemon-exit.c
gnunet/src/vpn/gnunet-daemon-vpn-dns.c
gnunet/src/vpn/gnunet-daemon-vpn-dns.h
gnunet/src/vpn/gnunet-daemon-vpn-helper.c
gnunet/src/vpn/gnunet-daemon-vpn-helper.h
gnunet/src/vpn/gnunet-daemon-vpn.c
gnunet/src/vpn/gnunet-daemon-vpn.h
gnunet/src/vpn/gnunet-dns-parser.c
gnunet/src/vpn/gnunet-dns-parser.h
gnunet/src/vpn/gnunet-helper-hijack-dns.c
gnunet/src/vpn/gnunet-helper-vpn-api.c
gnunet/src/vpn/gnunet-helper-vpn.c
gnunet/src/vpn/gnunet-service-dns-p.h
gnunet/src/vpn/gnunet-service-dns.c
gnunet/src/vpn/gnunet-vpn-checksum.c
gnunet/src/vpn/gnunet-vpn-checksum.h
gnunet/src/vpn/gnunet-vpn-packet.h
Log:
indentation
Modified: gnunet/src/arm/arm_api.c
===================================================================
--- gnunet/src/arm/arm_api.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/arm/arm_api.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -106,61 +106,58 @@
struct ShutdownContext *shutdown_ctx = cls;
if ((msg == NULL) && (shutdown_ctx->confirmed != GNUNET_YES))
- {
+ {
#if DEBUG_ARM
- /* Means the other side closed the connection and never confirmed a
shutdown */
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Service handle shutdown before ACK!\n");
+ /* Means the other side closed the connection and never confirmed a
shutdown */
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Service handle shutdown before ACK!\n");
#endif
- if (shutdown_ctx->cont != NULL)
- shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_SYSERR);
- GNUNET_SCHEDULER_cancel(shutdown_ctx->cancel_task);
- GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
- GNUNET_free(shutdown_ctx);
- }
+ if (shutdown_ctx->cont != NULL)
+ shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_SYSERR);
+ GNUNET_SCHEDULER_cancel (shutdown_ctx->cancel_task);
+ GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
+ GNUNET_free (shutdown_ctx);
+ }
else if ((msg == NULL) && (shutdown_ctx->confirmed == GNUNET_YES))
- {
+ {
#if DEBUG_ARM
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Service shutdown complete.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service shutdown complete.\n");
#endif
- if (shutdown_ctx->cont != NULL)
- shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_NO);
+ if (shutdown_ctx->cont != NULL)
+ shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_NO);
- GNUNET_SCHEDULER_cancel(shutdown_ctx->cancel_task);
- GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
- GNUNET_free(shutdown_ctx);
- }
+ GNUNET_SCHEDULER_cancel (shutdown_ctx->cancel_task);
+ GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
+ GNUNET_free (shutdown_ctx);
+ }
else
+ {
+ GNUNET_assert (ntohs (msg->size) == sizeof (struct GNUNET_MessageHeader));
+ switch (ntohs (msg->type))
{
- GNUNET_assert(ntohs(msg->size) == sizeof(struct GNUNET_MessageHeader));
- switch (ntohs(msg->type))
- {
- case GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN_ACK:
+ case GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN_ACK:
#if DEBUG_ARM
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Received confirmation for service shutdown.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received confirmation for service shutdown.\n");
#endif
- shutdown_ctx->confirmed = GNUNET_YES;
- GNUNET_CLIENT_receive (shutdown_ctx->sock,
- &service_shutdown_handler,
- shutdown_ctx,
- GNUNET_TIME_UNIT_FOREVER_REL);
- break;
- default: /* Fall through */
+ shutdown_ctx->confirmed = GNUNET_YES;
+ GNUNET_CLIENT_receive (shutdown_ctx->sock,
+ &service_shutdown_handler,
+ shutdown_ctx, GNUNET_TIME_UNIT_FOREVER_REL);
+ break;
+ default: /* Fall through */
#if DEBUG_ARM
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Service shutdown refused!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service shutdown refused!\n");
#endif
- if (shutdown_ctx->cont != NULL)
- shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_YES);
+ if (shutdown_ctx->cont != NULL)
+ shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_YES);
- GNUNET_SCHEDULER_cancel(shutdown_ctx->cancel_task);
- GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
- GNUNET_free(shutdown_ctx);
- break;
- }
+ GNUNET_SCHEDULER_cancel (shutdown_ctx->cancel_task);
+ GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
+ GNUNET_free (shutdown_ctx);
+ break;
}
+ }
}
/**
@@ -169,16 +166,18 @@
* @param cls closure
* @param tc context information (why was this task triggered now)
*/
-void service_shutdown_cancel (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext * tc)
+void
+service_shutdown_cancel (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct ShutdownContext *shutdown_ctx = cls;
+
#if DEBUG_ARM
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "service_shutdown_cancel called!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "service_shutdown_cancel called!\n");
#endif
- shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_SYSERR);
+ shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_SYSERR);
GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
- GNUNET_free(shutdown_ctx);
+ GNUNET_free (shutdown_ctx);
}
@@ -198,21 +197,22 @@
struct ShutdownContext *shutdown_ctx = cls;
if (size < sizeof (struct GNUNET_MessageHeader))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to transmit shutdown request to client.\n"));
- shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_SYSERR);
- GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
- GNUNET_free(shutdown_ctx);
- return 0; /* client disconnected */
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Failed to transmit shutdown request to client.\n"));
+ shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_SYSERR);
+ GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
+ GNUNET_free (shutdown_ctx);
+ return 0; /* client disconnected */
+ }
GNUNET_CLIENT_receive (shutdown_ctx->sock,
- &service_shutdown_handler, shutdown_ctx,
- GNUNET_TIME_UNIT_FOREVER_REL);
- shutdown_ctx->cancel_task = GNUNET_SCHEDULER_add_delayed
(GNUNET_TIME_absolute_get_remaining(shutdown_ctx->timeout),
-
&service_shutdown_cancel,
- shutdown_ctx);
+ &service_shutdown_handler, shutdown_ctx,
+ GNUNET_TIME_UNIT_FOREVER_REL);
+ shutdown_ctx->cancel_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
+ (shutdown_ctx->timeout),
+ &service_shutdown_cancel, shutdown_ctx);
msg = (struct GNUNET_MessageHeader *) buf;
msg->type = htons (GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN);
msg->size = htons (sizeof (struct GNUNET_MessageHeader));
@@ -235,22 +235,22 @@
*/
static void
arm_service_shutdown (struct GNUNET_CLIENT_Connection *sock,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_CLIENT_ShutdownTask cont,
- void *cont_cls)
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_CLIENT_ShutdownTask cont, void *cont_cls)
{
struct ShutdownContext *shutdown_ctx;
- shutdown_ctx = GNUNET_malloc(sizeof(struct ShutdownContext));
+
+ shutdown_ctx = GNUNET_malloc (sizeof (struct ShutdownContext));
shutdown_ctx->cont = cont;
shutdown_ctx->cont_cls = cont_cls;
shutdown_ctx->sock = sock;
- shutdown_ctx->timeout = GNUNET_TIME_relative_to_absolute(timeout);
+ shutdown_ctx->timeout = GNUNET_TIME_relative_to_absolute (timeout);
GNUNET_CLIENT_notify_transmit_ready (sock,
- sizeof (struct
- GNUNET_MessageHeader),
- timeout,
- GNUNET_YES,
- &write_shutdown, shutdown_ctx);
+ sizeof (struct
+ GNUNET_MessageHeader),
+ timeout,
+ GNUNET_YES,
+ &write_shutdown, shutdown_ctx);
}
@@ -266,7 +266,7 @@
*/
struct GNUNET_ARM_Handle *
GNUNET_ARM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *service)
+ const char *service)
{
struct GNUNET_ARM_Handle *ret;
@@ -351,8 +351,7 @@
* @param tc why were we called (reason says if ARM is running)
*/
static void
-arm_service_report (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+arm_service_report (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct RequestContext *pos = cls;
struct GNUNET_OS_Process *proc;
@@ -362,111 +361,91 @@
char *lopostfix;
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
- {
+ {
#if DEBUG_ARM
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Looks like `%s' is already running.\n",
- "gnunet-service-arm");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Looks like `%s' is already running.\n", "gnunet-service-arm");
#endif
- /* arm is running! */
- if (pos->callback != NULL)
- pos->callback (pos->cls, GNUNET_YES);
- GNUNET_free (pos);
- return;
- }
+ /* arm is running! */
+ if (pos->callback != NULL)
+ pos->callback (pos->cls, GNUNET_YES);
+ GNUNET_free (pos);
+ return;
+ }
#if DEBUG_ARM
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Looks like `%s' is not running, will start it.\n",
- "gnunet-service-arm");
+ "Looks like `%s' is not running, will start it.\n",
+ "gnunet-service-arm");
#endif
- if (GNUNET_OK !=
+ if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (pos->h->cfg,
- "arm", "PREFIX", &loprefix))
+ "arm", "PREFIX", &loprefix))
loprefix = GNUNET_strdup ("");
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (pos->h->cfg,
- "arm", "OPTIONS", &lopostfix))
+ "arm", "OPTIONS", &lopostfix))
lopostfix = GNUNET_strdup ("");
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (pos->h->cfg,
- "arm",
- "BINARY",
- &binary))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Configuration failes to specify option `%s' in section
`%s'!\n"),
- "BINARY",
- "arm");
- if (pos->callback != NULL)
- pos->callback (pos->cls, GNUNET_SYSERR);
- GNUNET_free (pos);
- GNUNET_free (loprefix);
- GNUNET_free (lopostfix);
- return;
- }
+ "arm", "BINARY", &binary))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Configuration failes to specify option `%s' in section
`%s'!\n"),
+ "BINARY", "arm");
+ if (pos->callback != NULL)
+ pos->callback (pos->cls, GNUNET_SYSERR);
+ GNUNET_free (pos);
+ GNUNET_free (loprefix);
+ GNUNET_free (lopostfix);
+ return;
+ }
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_filename (pos->h->cfg,
- "arm", "CONFIG", &config))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Configuration fails to specify option `%s' in section
`%s'!\n"),
- "CONFIG",
- "arm");
- if (pos->callback != NULL)
- pos->callback (pos->cls, GNUNET_SYSERR);
- GNUNET_free (binary);
- GNUNET_free (pos);
- GNUNET_free (loprefix);
- GNUNET_free (lopostfix);
- return;
- }
- if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value (pos->h->cfg,
- "TESTING",
- "WEAKRANDOM")) &&
- (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (pos->h->cfg,
- "TESTING",
- "WEAKRANDOM")) &&
- (GNUNET_NO == GNUNET_CONFIGURATION_have_value (pos->h->cfg,
- "TESTING",
- "HOSTFILE")) /* Means we
are ONLY running locally */
- )
- {
- /* we're clearly running a test, don't daemonize */
- proc = do_start_process (NULL,
- loprefix,
- binary,
- "-c", config,
+ "arm", "CONFIG", &config))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Configuration fails to specify option `%s' in section
`%s'!\n"),
+ "CONFIG", "arm");
+ if (pos->callback != NULL)
+ pos->callback (pos->cls, GNUNET_SYSERR);
+ GNUNET_free (binary);
+ GNUNET_free (pos);
+ GNUNET_free (loprefix);
+ GNUNET_free (lopostfix);
+ return;
+ }
+ if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value (pos->h->cfg, "TESTING",
"WEAKRANDOM")) && (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno
(pos->h->cfg, "TESTING", "WEAKRANDOM")) && (GNUNET_NO ==
GNUNET_CONFIGURATION_have_value (pos->h->cfg, "TESTING", "HOSTFILE")) /*
Means we are ONLY running locally */
+ )
+ {
+ /* we're clearly running a test, don't daemonize */
+ proc = do_start_process (NULL, loprefix, binary, "-c", config,
#if DEBUG_ARM
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- /* no daemonization! */
- lopostfix,
- NULL);
- }
+ /* no daemonization! */
+ lopostfix, NULL);
+ }
else
- {
- proc = do_start_process (NULL,
- loprefix,
- binary,
- "-c", config,
+ {
+ proc = do_start_process (NULL, loprefix, binary, "-c", config,
#if DEBUG_ARM
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-d",
- lopostfix,
- NULL);
- }
+ "-d", lopostfix, NULL);
+ }
GNUNET_free (binary);
GNUNET_free (config);
GNUNET_free (loprefix);
GNUNET_free (lopostfix);
if (proc == NULL)
- {
- if (pos->callback != NULL)
- pos->callback (pos->cls, GNUNET_SYSERR);
- GNUNET_free (pos);
- return;
- }
+ {
+ if (pos->callback != NULL)
+ pos->callback (pos->cls, GNUNET_SYSERR);
+ GNUNET_free (pos);
+ return;
+ }
if (pos->callback != NULL)
pos->callback (pos->cls, GNUNET_YES);
GNUNET_free (proc);
@@ -488,44 +467,41 @@
int ret;
if (msg == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Error receiving response to `%s' request from ARM for
service `%s'\n"),
- (sc->type == GNUNET_MESSAGE_TYPE_ARM_START)
- ? "START"
- : "STOP",
- (const char*) &sc[1]);
- GNUNET_CLIENT_disconnect (sc->h->client, GNUNET_NO);
- sc->h->client = GNUNET_CLIENT_connect ("arm",
- sc->h->cfg);
- GNUNET_assert (NULL != sc->h->client);
- GNUNET_CLIENT_ignore_shutdown (sc->h->client, GNUNET_YES);
- if (sc->callback != NULL)
- sc->callback (sc->cls, GNUNET_SYSERR);
- GNUNET_free (sc);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Error receiving response to `%s' request from ARM for
service `%s'\n"),
+ (sc->type == GNUNET_MESSAGE_TYPE_ARM_START) ? "START" : "STOP",
+ (const char *) &sc[1]);
+ GNUNET_CLIENT_disconnect (sc->h->client, GNUNET_NO);
+ sc->h->client = GNUNET_CLIENT_connect ("arm", sc->h->cfg);
+ GNUNET_assert (NULL != sc->h->client);
+ GNUNET_CLIENT_ignore_shutdown (sc->h->client, GNUNET_YES);
+ if (sc->callback != NULL)
+ sc->callback (sc->cls, GNUNET_SYSERR);
+ GNUNET_free (sc);
+ return;
+ }
#if DEBUG_ARM
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received response from ARM for service `%s': %u\n",
- (const char*) &sc[1],
- ntohs(msg->type));
+ (const char *) &sc[1], ntohs (msg->type));
#endif
switch (ntohs (msg->type))
- {
- case GNUNET_MESSAGE_TYPE_ARM_IS_UP:
- ret = GNUNET_YES;
- break;
- case GNUNET_MESSAGE_TYPE_ARM_IS_DOWN:
- ret = GNUNET_NO;
- break;
- case GNUNET_MESSAGE_TYPE_ARM_IS_UNKNOWN:
- ret = GNUNET_SYSERR;
- break;
- default:
- GNUNET_break (0);
- ret = GNUNET_SYSERR;
- }
+ {
+ case GNUNET_MESSAGE_TYPE_ARM_IS_UP:
+ ret = GNUNET_YES;
+ break;
+ case GNUNET_MESSAGE_TYPE_ARM_IS_DOWN:
+ ret = GNUNET_NO;
+ break;
+ case GNUNET_MESSAGE_TYPE_ARM_IS_UNKNOWN:
+ ret = GNUNET_SYSERR;
+ break;
+ default:
+ GNUNET_break (0);
+ ret = GNUNET_SYSERR;
+ }
if (sc->callback != NULL)
sc->callback (sc->cls, ret);
GNUNET_free (sc);
@@ -544,7 +520,7 @@
*/
static void
change_service (struct GNUNET_ARM_Handle *h,
- const char *service_name,
+ const char *service_name,
struct GNUNET_TIME_Relative timeout,
GNUNET_ARM_Callback cb, void *cb_cls, uint16_t type)
{
@@ -553,19 +529,19 @@
struct GNUNET_MessageHeader *msg;
slen = strlen (service_name) + 1;
- if (slen + sizeof (struct GNUNET_MessageHeader) >=
GNUNET_SERVER_MAX_MESSAGE_SIZE)
- {
- GNUNET_break (0);
- if (cb != NULL)
- cb (cb_cls, GNUNET_NO);
- return;
- }
+ if (slen + sizeof (struct GNUNET_MessageHeader) >=
+ GNUNET_SERVER_MAX_MESSAGE_SIZE)
+ {
+ GNUNET_break (0);
+ if (cb != NULL)
+ cb (cb_cls, GNUNET_NO);
+ return;
+ }
#if DEBUG_ARM
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
(type == GNUNET_MESSAGE_TYPE_ARM_START)
- ? _("Requesting start of service `%s'.\n")
- : _("Requesting termination of service `%s'.\n"),
- service_name);
+ ? _("Requesting start of service `%s'.\n")
+ : _("Requesting termination of service `%s'.\n"), service_name);
#endif
sctx = GNUNET_malloc (sizeof (struct RequestContext) + slen);
sctx->h = h;
@@ -580,23 +556,26 @@
memcpy (&msg[1], service_name, slen);
if (GNUNET_OK !=
GNUNET_CLIENT_transmit_and_get_response (sctx->h->client,
- msg,
-
GNUNET_TIME_absolute_get_remaining (sctx->timeout),
- GNUNET_YES,
- &handle_response,
- sctx))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- (type == GNUNET_MESSAGE_TYPE_ARM_START)
- ? _("Error while trying to transmit request to start `%s' to
ARM\n")
- : _("Error while trying to transmit request to stop `%s' to
ARM\n"),
- (const char*) &service_name);
- if (cb != NULL)
- cb (cb_cls, GNUNET_SYSERR);
- GNUNET_free (sctx);
- GNUNET_free (msg);
- return;
- }
+ msg,
+
GNUNET_TIME_absolute_get_remaining
+ (sctx->timeout), GNUNET_YES,
+ &handle_response, sctx))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ (type == GNUNET_MESSAGE_TYPE_ARM_START)
+ ?
+ _
+ ("Error while trying to transmit request to start `%s' to
ARM\n")
+ :
+ _
+ ("Error while trying to transmit request to stop `%s' to
ARM\n"),
+ (const char *) &service_name);
+ if (cb != NULL)
+ cb (cb_cls, GNUNET_SYSERR);
+ GNUNET_free (sctx);
+ GNUNET_free (msg);
+ return;
+ }
GNUNET_free (msg);
}
@@ -612,7 +591,7 @@
*/
void
GNUNET_ARM_start_service (struct GNUNET_ARM_Handle *h,
- const char *service_name,
+ const char *service_name,
struct GNUNET_TIME_Relative timeout,
GNUNET_ARM_Callback cb, void *cb_cls)
{
@@ -623,39 +602,42 @@
#if DEBUG_ARM
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
_("Asked to start service `%s' within %llu ms\n"), service_name,
- (unsigned long long) timeout.rel_value);
+ (unsigned long long) timeout.rel_value);
#endif
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
_("Asked to start service `%s' within %llu ms\n"), service_name,
(unsigned long long) timeout.rel_value);
if (0 == strcasecmp ("arm", service_name))
+ {
+ slen = strlen ("arm") + 1;
+ sctx = GNUNET_malloc (sizeof (struct RequestContext) + slen);
+ sctx->h = h;
+ sctx->callback = cb;
+ sctx->cls = cb_cls;
+ sctx->timeout = GNUNET_TIME_relative_to_absolute (timeout);
+ memcpy (&sctx[1], service_name, slen);
+ GNUNET_CLIENT_service_test ("arm",
+ h->cfg, timeout, &arm_service_report, sctx);
+ return;
+ }
+ if (h->client == NULL)
+ {
+ client = GNUNET_CLIENT_connect ("arm", h->cfg);
+ if (client == NULL)
{
- slen = strlen ("arm") + 1;
- sctx = GNUNET_malloc (sizeof (struct RequestContext) + slen);
- sctx->h = h;
- sctx->callback = cb;
- sctx->cls = cb_cls;
- sctx->timeout = GNUNET_TIME_relative_to_absolute (timeout);
- memcpy (&sctx[1], service_name, slen);
- GNUNET_CLIENT_service_test ("arm",
- h->cfg, timeout, &arm_service_report, sctx);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "arm_api, GNUNET_CLIENT_connect returned NULL\n");
+ cb (cb_cls, GNUNET_SYSERR);
return;
}
- if (h->client == NULL)
- {
- client = GNUNET_CLIENT_connect ("arm", h->cfg);
- if (client == NULL)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "arm_api, GNUNET_CLIENT_connect
returned NULL\n");
- cb (cb_cls, GNUNET_SYSERR);
- return;
- }
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "arm_api, GNUNET_CLIENT_connect
returned non-NULL\n");
- GNUNET_CLIENT_ignore_shutdown (client, GNUNET_YES);
- h->client = client;
- }
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "arm_api, h->client non-NULL\n");
- change_service (h, service_name, timeout, cb, cb_cls,
GNUNET_MESSAGE_TYPE_ARM_START);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "arm_api, GNUNET_CLIENT_connect returned non-NULL\n");
+ GNUNET_CLIENT_ignore_shutdown (client, GNUNET_YES);
+ h->client = client;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "arm_api, h->client non-NULL\n");
+ change_service (h, service_name, timeout, cb, cb_cls,
+ GNUNET_MESSAGE_TYPE_ARM_START);
}
/**
@@ -666,15 +648,15 @@
* @param reason reason for callback, GNUNET_NO if arm is shutdown
* GNUNET_YES if arm remains running, and GNUNET_SYSERR on error
*/
-void arm_shutdown_callback (void *cls,
- int reason)
+void
+arm_shutdown_callback (void *cls, int reason)
{
struct ARM_ShutdownContext *arm_shutdown_ctx = cls;
if (arm_shutdown_ctx->cb != NULL)
arm_shutdown_ctx->cb (arm_shutdown_ctx->cb_cls, reason);
- GNUNET_free(arm_shutdown_ctx);
+ GNUNET_free (arm_shutdown_ctx);
}
@@ -698,28 +680,30 @@
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
_("Stopping service `%s' within %llu ms\n"), service_name,
- (unsigned long long) timeout.rel_value);
+ (unsigned long long) timeout.rel_value);
if (h->client == NULL)
+ {
+ client = GNUNET_CLIENT_connect ("arm", h->cfg);
+ if (client == NULL)
{
- client = GNUNET_CLIENT_connect ("arm", h->cfg);
- if (client == NULL)
- {
- cb (cb_cls, GNUNET_SYSERR);
- return;
- }
- GNUNET_CLIENT_ignore_shutdown (client, GNUNET_YES);
- h->client = client;
- }
- if (0 == strcasecmp ("arm", service_name))
- {
- arm_shutdown_ctx = GNUNET_malloc(sizeof(struct ARM_ShutdownContext));
- arm_shutdown_ctx->cb = cb;
- arm_shutdown_ctx->cb_cls = cb_cls;
- arm_service_shutdown (h->client, timeout, &arm_shutdown_callback,
arm_shutdown_ctx);
- h->client = NULL;
+ cb (cb_cls, GNUNET_SYSERR);
return;
}
- change_service (h, service_name, timeout, cb, cb_cls,
GNUNET_MESSAGE_TYPE_ARM_STOP);
+ GNUNET_CLIENT_ignore_shutdown (client, GNUNET_YES);
+ h->client = client;
+ }
+ if (0 == strcasecmp ("arm", service_name))
+ {
+ arm_shutdown_ctx = GNUNET_malloc (sizeof (struct ARM_ShutdownContext));
+ arm_shutdown_ctx->cb = cb;
+ arm_shutdown_ctx->cb_cls = cb_cls;
+ arm_service_shutdown (h->client, timeout, &arm_shutdown_callback,
+ arm_shutdown_ctx);
+ h->client = NULL;
+ return;
+ }
+ change_service (h, service_name, timeout, cb, cb_cls,
+ GNUNET_MESSAGE_TYPE_ARM_STOP);
}
Modified: gnunet/src/arm/do_start_process.c
===================================================================
--- gnunet/src/arm/do_start_process.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/arm/do_start_process.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -13,8 +13,7 @@
* @return PID of the started process, -1 on error
*/
static struct GNUNET_OS_Process *
-do_start_process (const int *lsocks,
- const char *first_arg, ...)
+do_start_process (const int *lsocks, const char *first_arg, ...)
{
va_list ap;
char **argv;
@@ -34,24 +33,24 @@
do
{
/* *INDENT-ON* */
- rpos = arg;
- while ('\0' != *rpos)
- {
- if (' ' == *rpos)
- {
- if (last != NULL)
- argv_size++;
- last = NULL;
- while (' ' == *rpos)
- rpos++;
- }
- if ( (last == NULL) && (*rpos != '\0') )
- last = rpos;
- if (*rpos != '\0')
- rpos++;
- }
+ rpos = arg;
+ while ('\0' != *rpos)
+ {
+ if (' ' == *rpos)
+ {
if (last != NULL)
- argv_size++;
+ argv_size++;
+ last = NULL;
+ while (' ' == *rpos)
+ rpos++;
+ }
+ if ((last == NULL) && (*rpos != '\0'))
+ last = rpos;
+ if (*rpos != '\0')
+ rpos++;
+ }
+ if (last != NULL)
+ argv_size++;
/* *INDENT-OFF* */
}
while (NULL != (arg = (va_arg (ap, const char*))));
@@ -67,29 +66,29 @@
do
{
/* *INDENT-ON* */
- cp = GNUNET_strdup (arg);
- pos = cp;
- while ('\0' != *pos)
- {
- if (' ' == *pos)
- {
- *pos = '\0';
- if (last != NULL)
- argv[argv_size++] = GNUNET_strdup (last);
- last = NULL;
- pos++;
- while (' ' == *pos)
- pos++;
- }
- if ( (last == NULL) && (*pos != '\0') )
- last = pos;
- if (*pos != '\0')
- pos++;
- }
+ cp = GNUNET_strdup (arg);
+ pos = cp;
+ while ('\0' != *pos)
+ {
+ if (' ' == *pos)
+ {
+ *pos = '\0';
if (last != NULL)
- argv[argv_size++] = GNUNET_strdup (last);
+ argv[argv_size++] = GNUNET_strdup (last);
last = NULL;
- GNUNET_free (cp);
+ pos++;
+ while (' ' == *pos)
+ pos++;
+ }
+ if ((last == NULL) && (*pos != '\0'))
+ last = pos;
+ if (*pos != '\0')
+ pos++;
+ }
+ if (last != NULL)
+ argv[argv_size++] = GNUNET_strdup (last);
+ last = NULL;
+ GNUNET_free (cp);
/* *INDENT-OFF* */
}
while (NULL != (arg = (va_arg (ap, const char*))));
Modified: gnunet/src/arm/gnunet-arm.c
===================================================================
--- gnunet/src/arm/gnunet-arm.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/arm/gnunet-arm.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -138,9 +138,7 @@
* @param cls closure, unused
* @param tc context, unused
*/
-static void
-cps_loop (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+static void cps_loop (void *cls, const struct GNUNET_SCHEDULER_TaskContext
*tc);
/**
@@ -154,39 +152,39 @@
confirm_cb (void *cls, int success)
{
const char *service = cls;
+
switch (success)
+ {
+ case GNUNET_OK:
+ if (quiet != GNUNET_YES)
+ fprintf (stdout, _("Service `%s' has been started.\n"), service);
+ if ((phase - 1 != 2) && (phase - 1 != 3))
{
- case GNUNET_OK:
if (quiet != GNUNET_YES)
- fprintf(stdout, _("Service `%s' has been started.\n"), service);
- if ((phase - 1 != 2) && (phase - 1 != 3))
- {
- if (quiet != GNUNET_YES)
- fprintf(stdout, _("Failed to stop service `%s'!\n"), service);
- ret = 1;
- }
- break;
- case GNUNET_NO:
+ fprintf (stdout, _("Failed to stop service `%s'!\n"), service);
+ ret = 1;
+ }
+ break;
+ case GNUNET_NO:
+ if (quiet != GNUNET_YES)
+ fprintf (stdout, _("Service `%s' has been stopped.\n"), service);
+ if ((phase - 1 != 0) && (phase - 1 != 1))
+ {
if (quiet != GNUNET_YES)
- fprintf(stdout, _("Service `%s' has been stopped.\n"), service);
- if ((phase - 1 != 0) && (phase - 1 != 1))
- {
- if (quiet != GNUNET_YES)
- fprintf(stdout, _("Failed to start service `%s'!\n"), service);
- ret = 1;
- }
- break;
- case GNUNET_SYSERR:
- if (quiet != GNUNET_YES)
- fprintf(stdout,
- _("Some error communicating with service `%s'.\n"), service);
+ fprintf (stdout, _("Failed to start service `%s'!\n"), service);
ret = 1;
- break;
}
+ break;
+ case GNUNET_SYSERR:
+ if (quiet != GNUNET_YES)
+ fprintf (stdout,
+ _("Some error communicating with service `%s'.\n"), service);
+ ret = 1;
+ break;
+ }
GNUNET_SCHEDULER_add_continuation (&cps_loop,
- NULL,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ NULL,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
}
@@ -203,18 +201,17 @@
const char *service = cls;
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
- {
- if (quiet != GNUNET_YES)
- fprintf(stdout, _("Service `%s' is running.\n"), service);
- }
+ {
+ if (quiet != GNUNET_YES)
+ fprintf (stdout, _("Service `%s' is running.\n"), service);
+ }
else
- {
- if (quiet != GNUNET_YES)
- fprintf(stdout, _("Service `%s' is not running.\n"), service);
- }
+ {
+ if (quiet != GNUNET_YES)
+ fprintf (stdout, _("Service `%s' is not running.\n"), service);
+ }
GNUNET_SCHEDULER_add_continuation (&cps_loop,
- NULL,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ NULL,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
}
@@ -229,30 +226,29 @@
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *c)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
{
cfg = c;
config_file = cfgfile;
- if (GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "SERVICEHOME", &dir)
!= GNUNET_OK)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Fatal configuration error: `%s' option in section `%s'
missing.\n"),
- "SERVICEHOME",
- "PATHS");
- return;
- }
+ if (GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", "SERVICEHOME", &dir)
+ != GNUNET_OK)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _
+ ("Fatal configuration error: `%s' option in section `%s'
missing.\n"),
+ "SERVICEHOME", "PATHS");
+ return;
+ }
h = GNUNET_ARM_connect (cfg, NULL);
if (h == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Fatal error initializing ARM API.\n"));
- ret = 1;
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Fatal error initializing ARM API.\n"));
+ ret = 1;
+ return;
+ }
GNUNET_SCHEDULER_add_continuation (&cps_loop,
- NULL,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ NULL,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
}
/**
@@ -260,20 +256,23 @@
* on arm shutdown provided the end and delete options
* were specified when gnunet-arm was run.
*/
-static void delete_files()
+static void
+delete_files ()
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Will attempt to remove configuration
file %s and service directory %s\n", config_file, dir);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Will attempt to remove configuration file %s and service
directory %s\n",
+ config_file, dir);
- if (UNLINK(config_file) != 0)
+ if (UNLINK (config_file) != 0)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to remove configuration file %s\n"), config_file);
+ _("Failed to remove configuration file %s\n"), config_file);
}
- if (GNUNET_DISK_directory_remove(dir) != GNUNET_OK)
+ if (GNUNET_DISK_directory_remove (dir) != GNUNET_OK)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to remove servicehome directory %s\n"), dir);
+ _("Failed to remove servicehome directory %s\n"), dir);
}
}
@@ -286,75 +285,89 @@
* @param tc context, unused
*/
static void
-cps_loop (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+cps_loop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
while (1)
+ {
+ switch (phase++)
{
- switch (phase++)
- {
- case 0:
- if (term != NULL)
- {
- GNUNET_ARM_stop_service (h, term, (0 == timeout.rel_value) ?
STOP_TIMEOUT : timeout, &confirm_cb, term);
- return;
- }
- break;
- case 1:
- if ((end) || (restart))
- {
- GNUNET_ARM_stop_service (h, "arm", (0 == timeout.rel_value) ?
STOP_TIMEOUT_ARM : timeout, &confirm_cb, "arm");
- return;
- }
- break;
- case 2:
- if (start)
- {
- GNUNET_ARM_start_service (h, "arm", (0 == timeout.rel_value) ?
START_TIMEOUT : timeout, &confirm_cb, "arm");
- return;
- }
- break;
- case 3:
- if (init != NULL)
- {
- GNUNET_ARM_start_service (h, init, (0 == timeout.rel_value) ?
START_TIMEOUT : timeout, &confirm_cb, init);
- return;
- }
- break;
- case 4:
- if (test != NULL)
- {
- GNUNET_CLIENT_service_test (test, cfg, (0 == timeout.rel_value) ?
TEST_TIMEOUT : timeout, &confirm_task, test);
- return;
- }
- break;
- case 5:
- if (restart)
- {
- GNUNET_ARM_disconnect (h);
- phase = 0;
- end = 0;
- start = 1;
- restart = 0;
- h = GNUNET_ARM_connect (cfg, NULL);
- if (h == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Fatal error initializing ARM API.\n"));
- ret = 1;
- return;
- }
- GNUNET_SCHEDULER_add_now(&cps_loop, NULL);
- return;
- }
- /* Fall through */
- default: /* last phase */
- GNUNET_ARM_disconnect (h);
- if ((end == GNUNET_YES) && (delete == GNUNET_YES))
- delete_files();
- return;
- }
+ case 0:
+ if (term != NULL)
+ {
+ GNUNET_ARM_stop_service (h, term,
+ (0 ==
+ timeout.rel_value) ? STOP_TIMEOUT : timeout,
+ &confirm_cb, term);
+ return;
+ }
+ break;
+ case 1:
+ if ((end) || (restart))
+ {
+ GNUNET_ARM_stop_service (h, "arm",
+ (0 ==
+ timeout.rel_value) ? STOP_TIMEOUT_ARM :
+ timeout, &confirm_cb, "arm");
+ return;
+ }
+ break;
+ case 2:
+ if (start)
+ {
+ GNUNET_ARM_start_service (h, "arm",
+ (0 ==
+ timeout.rel_value) ? START_TIMEOUT :
timeout,
+ &confirm_cb, "arm");
+ return;
+ }
+ break;
+ case 3:
+ if (init != NULL)
+ {
+ GNUNET_ARM_start_service (h, init,
+ (0 ==
+ timeout.rel_value) ? START_TIMEOUT :
timeout,
+ &confirm_cb, init);
+ return;
+ }
+ break;
+ case 4:
+ if (test != NULL)
+ {
+ GNUNET_CLIENT_service_test (test, cfg,
+ (0 ==
+ timeout.rel_value) ? TEST_TIMEOUT :
+ timeout, &confirm_task, test);
+ return;
+ }
+ break;
+ case 5:
+ if (restart)
+ {
+ GNUNET_ARM_disconnect (h);
+ phase = 0;
+ end = 0;
+ start = 1;
+ restart = 0;
+ h = GNUNET_ARM_connect (cfg, NULL);
+ if (h == NULL)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Fatal error initializing ARM API.\n"));
+ ret = 1;
+ return;
+ }
+ GNUNET_SCHEDULER_add_now (&cps_loop, NULL);
+ return;
+ }
+ /* Fall through */
+ default: /* last phase */
+ GNUNET_ARM_disconnect (h);
+ if ((end == GNUNET_YES) && (delete == GNUNET_YES))
+ delete_files ();
+ return;
}
+ }
}
@@ -379,16 +392,19 @@
GNUNET_YES, &GNUNET_GETOPT_set_string, &term},
{'s', "start", NULL, gettext_noop ("start all GNUnet default services"),
GNUNET_NO, &GNUNET_GETOPT_set_one, &start},
- {'r', "restart", NULL, gettext_noop ("stop and start all GNUnet default
services"),
+ {'r', "restart", NULL,
+ gettext_noop ("stop and start all GNUnet default services"),
GNUNET_NO, &GNUNET_GETOPT_set_one, &restart},
{'t', "test", "SERVICE",
gettext_noop ("test if a particular service is running"),
GNUNET_YES, &GNUNET_GETOPT_set_string, &test},
- {'d', "delete", NULL, gettext_noop ("delete config file and directory on
exit"),
+ {'d', "delete", NULL,
+ gettext_noop ("delete config file and directory on exit"),
GNUNET_NO, &GNUNET_GETOPT_set_one, &delete},
{'q', "quiet", NULL, gettext_noop ("don't print status messages"),
GNUNET_NO, &GNUNET_GETOPT_set_one, &quiet},
- {'T', "timeout", NULL, gettext_noop ("timeout for completing current
operation"),
+ {'T', "timeout", NULL,
+ gettext_noop ("timeout for completing current operation"),
GNUNET_YES, &GNUNET_GETOPT_set_ulong, &temp_timeout_ms},
GNUNET_GETOPT_OPTION_END
};
@@ -397,16 +413,16 @@
timeout.rel_value = temp_timeout_ms;
if (GNUNET_OK == GNUNET_PROGRAM_run (argc,
- argv,
- "gnunet-arm",
- gettext_noop
- ("Control services and the Automated Restart Manager
(ARM)"),
- options, &run, NULL))
- {
- return ret;
- }
+ argv,
+ "gnunet-arm",
+ gettext_noop
+ ("Control services and the Automated
Restart Manager (ARM)"),
+ options, &run, NULL))
+ {
+ return ret;
+ }
- return 1;
+ return 1;
}
/* end of gnunet-arm.c */
Modified: gnunet/src/arm/gnunet-service-arm.c
===================================================================
--- gnunet/src/arm/gnunet-service-arm.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/arm/gnunet-service-arm.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -188,7 +188,7 @@
* @param cls closure, NULL if we need to self-restart
* @param tc context
*/
-static void
+static void
config_change_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct ServiceList *pos;
@@ -196,21 +196,21 @@
pos = running_head;
while (pos != NULL)
+ {
+ /* FIXME: this test for config change may be a bit too coarse grained */
+ if ((0 == STAT (pos->config, &sbuf)) &&
+ (pos->mtime < sbuf.st_mtime) && (pos->proc != NULL))
{
- /* FIXME: this test for config change may be a bit too coarse grained */
- if ( (0 == STAT (pos->config, &sbuf)) &&
- (pos->mtime < sbuf.st_mtime) &&
- (pos->proc != NULL) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Restarting service `%s' due to configuration file
change.\n"));
- if (0 != GNUNET_OS_process_kill (pos->proc, SIGTERM))
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
- else
- pos->backoff = GNUNET_TIME_UNIT_MILLISECONDS;
- }
- pos = pos->next;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _
+ ("Restarting service `%s' due to configuration file
change.\n"));
+ if (0 != GNUNET_OS_process_kill (pos->proc, SIGTERM))
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
+ else
+ pos->backoff = GNUNET_TIME_UNIT_MILLISECONDS;
}
+ pos = pos->next;
+ }
}
@@ -229,15 +229,14 @@
struct GNUNET_MessageHeader *msg;
if (buf == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Could not send status result to client\n"));
- return 0; /* error, not much we can do */
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Could not send status result to client\n"));
+ return 0; /* error, not much we can do */
+ }
#if DEBUG_ARM
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending status response %u to client\n",
- (unsigned int) *res);
+ "Sending status response %u to client\n", (unsigned int) *res);
#endif
GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader));
msg = buf;
@@ -259,29 +258,27 @@
*/
static void
signal_result (struct GNUNET_SERVER_Client *client,
- const char *name, uint16_t result)
+ const char *name, uint16_t result)
{
uint16_t *res;
if (NULL == client)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _
- ("Not sending status result to client: no client known\n"));
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Not sending status result to client: no client known\n"));
+ return;
+ }
#if DEBUG_ARM
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Telling client that service `%s' is now %s\n",
- name,
- result == GNUNET_MESSAGE_TYPE_ARM_IS_DOWN ? "down" : "up");
+ "Telling client that service `%s' is now %s\n",
+ name, result == GNUNET_MESSAGE_TYPE_ARM_IS_DOWN ? "down" : "up");
#endif
res = GNUNET_malloc (sizeof (uint16_t));
*res = result;
GNUNET_SERVER_notify_transmit_ready (client,
- sizeof (struct GNUNET_MessageHeader),
- GNUNET_TIME_UNIT_FOREVER_REL,
- &write_result, res);
+ sizeof (struct GNUNET_MessageHeader),
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &write_result, res);
}
@@ -299,11 +296,11 @@
pos = running_head;
while (pos != NULL)
- {
- if (0 == strcmp (pos->name, name))
- return pos;
- pos = pos->next;
- }
+ {
+ if (0 == strcmp (pos->name, name))
+ return pos;
+ pos = pos->next;
+ }
return NULL;
}
@@ -316,9 +313,7 @@
static void
free_service (struct ServiceList *pos)
{
- GNUNET_CONTAINER_DLL_remove (running_head,
- running_tail,
- pos);
+ GNUNET_CONTAINER_DLL_remove (running_head, running_tail, pos);
GNUNET_free_non_null (pos->config);
GNUNET_free_non_null (pos->binary);
GNUNET_free (pos->name);
@@ -336,8 +331,7 @@
* @param lsocks -1 terminated list of listen sockets to pass (systemd style),
or NULL
*/
static void
-start_process (struct ServiceList *sl,
- const int *lsocks)
+start_process (struct ServiceList *sl, const int *lsocks)
{
char *loprefix;
char *options;
@@ -351,85 +345,70 @@
/* start service */
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
- sl->name, "PREFIX", &loprefix))
+ sl->name, "PREFIX", &loprefix))
loprefix = GNUNET_strdup (prefix_command);
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
- sl->name, "OPTIONS", &options))
- {
- options = GNUNET_strdup (final_option);
- if (NULL == strstr (options, "%"))
- {
- /* replace '{}' with service name */
- while (NULL != (optpos = strstr (options, "{}")))
- {
- optpos[0] = '%';
- optpos[1] = 's';
- GNUNET_asprintf (&optpos,
- options,
- sl->name);
- GNUNET_free (options);
- options = optpos;
- }
- /* replace '$PATH' with value associated with "PATH" */
- while (NULL != (optpos = strstr (options, "$")))
- {
- optend = optpos + 1;
- while (isupper ( (unsigned char) *optend)) optend++;
- b = *optend;
- if ('\0' == b)
- next = "";
- else
- next = optend+1;
- *optend = '\0';
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS",
- optpos+1,
- &val))
- val = GNUNET_strdup ("");
- *optpos = '\0';
- GNUNET_asprintf (&optpos,
- "%s%s%c%s",
- options,
- val,
- b,
- next);
- GNUNET_free (options);
- GNUNET_free (val);
- options = optpos;
- }
- }
+ sl->name, "OPTIONS", &options))
+ {
+ options = GNUNET_strdup (final_option);
+ if (NULL == strstr (options, "%"))
+ {
+ /* replace '{}' with service name */
+ while (NULL != (optpos = strstr (options, "{}")))
+ {
+ optpos[0] = '%';
+ optpos[1] = 's';
+ GNUNET_asprintf (&optpos, options, sl->name);
+ GNUNET_free (options);
+ options = optpos;
+ }
+ /* replace '$PATH' with value associated with "PATH" */
+ while (NULL != (optpos = strstr (options, "$")))
+ {
+ optend = optpos + 1;
+ while (isupper ((unsigned char) *optend))
+ optend++;
+ b = *optend;
+ if ('\0' == b)
+ next = "";
+ else
+ next = optend + 1;
+ *optend = '\0';
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS",
+ optpos + 1, &val))
+ val = GNUNET_strdup ("");
+ *optpos = '\0';
+ GNUNET_asprintf (&optpos, "%s%s%c%s", options, val, b, next);
+ GNUNET_free (options);
+ GNUNET_free (val);
+ options = optpos;
+ }
}
+ }
use_debug = GNUNET_CONFIGURATION_get_value_yesno (cfg, sl->name, "DEBUG");
#if DEBUG_ARM
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Starting service `%s' using binary `%s' and configuration
`%s'\n",
- sl->name, sl->binary, sl->config);
+ "Starting service `%s' using binary `%s' and configuration
`%s'\n",
+ sl->name, sl->binary, sl->config);
#endif
if (GNUNET_YES == use_debug)
sl->proc = do_start_process (lsocks,
- loprefix,
- sl->binary,
- "-c", sl->config,
- "-L", "DEBUG",
- options,
- NULL);
+ loprefix,
+ sl->binary,
+ "-c", sl->config,
+ "-L", "DEBUG", options, NULL);
else
sl->proc = do_start_process (lsocks,
- loprefix,
- sl->binary,
- "-c", sl->config,
- options,
- NULL);
+ loprefix,
+ sl->binary, "-c", sl->config, options, NULL);
if (sl->proc == NULL)
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to start service `%s'\n"),
- sl->name);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to start service `%s'\n"), sl->name);
else
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Starting service `%s'\n"),
- sl->name);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Starting service `%s'\n"),
sl->name);
GNUNET_free (loprefix);
GNUNET_free (options);
}
@@ -444,9 +423,8 @@
* @return GNUNET_OK on success, GNUNET_SYSERR on error
*/
int
-start_service (struct GNUNET_SERVER_Client *client,
- const char *servicename,
- const int *lsocks)
+start_service (struct GNUNET_SERVER_Client *client,
+ const char *servicename, const int *lsocks)
{
struct ServiceList *sl;
char *binary;
@@ -454,46 +432,46 @@
struct stat sbuf;
if (GNUNET_YES == in_shutdown)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("ARM is shutting down, service `%s' not started.\n"),
- servicename);
- signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("ARM is shutting down, service `%s' not started.\n"),
+ servicename);
+ signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
+ return GNUNET_SYSERR;
+ }
sl = find_service (servicename);
if (sl != NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Service `%s' already running.\n"), servicename);
- signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_UP);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ _("Service `%s' already running.\n"), servicename);
+ signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_UP);
+ return GNUNET_SYSERR;
+ }
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
- servicename, "BINARY", &binary))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Binary implementing service `%s' not known!\n"),
- servicename);
- signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
- return GNUNET_SYSERR;
- }
+ servicename, "BINARY", &binary))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Binary implementing service `%s' not known!\n"),
+ servicename);
+ signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
+ return GNUNET_SYSERR;
+ }
if ((GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_filename (cfg,
- servicename,
- "CONFIG",
- &config)) ||
+ servicename,
+ "CONFIG",
+ &config)) ||
(0 != STAT (config, &sbuf)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Configuration file `%s' for service `%s' not known!\n"),
- config, servicename);
- signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
- GNUNET_free (binary);
- GNUNET_free_non_null (config);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Configuration file `%s' for service `%s' not known!\n"),
+ config, servicename);
+ signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
+ GNUNET_free (binary);
+ GNUNET_free_non_null (config);
+ return GNUNET_SYSERR;
+ }
(void) stop_listening (servicename);
sl = GNUNET_malloc (sizeof (struct ServiceList));
sl->name = GNUNET_strdup (servicename);
@@ -502,9 +480,7 @@
sl->mtime = sbuf.st_mtime;
sl->backoff = GNUNET_TIME_UNIT_MILLISECONDS;
sl->restartAt = GNUNET_TIME_UNIT_FOREVER_ABS;
- GNUNET_CONTAINER_DLL_insert (running_head,
- running_tail,
- sl);
+ GNUNET_CONTAINER_DLL_insert (running_head, running_tail, sl);
start_process (sl, lsocks);
if (NULL != client)
signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_UP);
@@ -519,58 +495,57 @@
* @param servicename name of the service to stop
*/
static void
-stop_service (struct GNUNET_SERVER_Client *client,
- const char *servicename)
+stop_service (struct GNUNET_SERVER_Client *client, const char *servicename)
{
struct ServiceList *pos;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Preparing to stop `%s'\n"), servicename);
+ _("Preparing to stop `%s'\n"), servicename);
pos = find_service (servicename);
if (pos == NULL)
- {
- if (GNUNET_OK == stop_listening (servicename))
- signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
- else
- signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_UNKNOWN);
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
- return;
- }
+ {
+ if (GNUNET_OK == stop_listening (servicename))
+ signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
+ else
+ signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_UNKNOWN);
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ return;
+ }
if (pos->killing_client != NULL)
- {
- /* killing already in progress */
+ {
+ /* killing already in progress */
#if DEBUG_ARM
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Service `%s' is already down\n", servicename);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Service `%s' is already down\n", servicename);
#endif
- signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
- return;
- }
+ signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ return;
+ }
if (GNUNET_YES == in_shutdown)
- {
+ {
#if DEBUG_ARM
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Termination request already sent to `%s' (since ARM is in
shutdown).\n",
- servicename);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Termination request already sent to `%s' (since ARM is in
shutdown).\n",
+ servicename);
#endif
- signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
- return;
- }
+ signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ return;
+ }
if (pos->proc == NULL)
- {
- /* process is in delayed restart, simply remove it! */
- free_service (pos);
- signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
- return;
- }
+ {
+ /* process is in delayed restart, simply remove it! */
+ free_service (pos);
+ signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ return;
+ }
#if DEBUG_ARM
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending kill signal to service `%s', waiting for process to
die.\n",
- servicename);
+ "Sending kill signal to service `%s', waiting for process to
die.\n",
+ servicename);
#endif
if (0 != GNUNET_OS_process_kill (pos->proc, SIGTERM))
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
@@ -590,8 +565,8 @@
*/
static void
handle_start (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
const char *servicename;
uint16_t size;
@@ -600,11 +575,11 @@
size -= sizeof (struct GNUNET_MessageHeader);
servicename = (const char *) &message[1];
if ((size == 0) || (servicename[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;
+ }
start_service (client, servicename, NULL);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
@@ -621,8 +596,8 @@
*/
static void
handle_stop (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
const char *servicename;
uint16_t size;
@@ -631,11 +606,11 @@
size -= sizeof (struct GNUNET_MessageHeader);
servicename = (const char *) &message[1];
if ((size == 0) || (servicename[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;
+ }
stop_service (client, servicename);
}
@@ -650,14 +625,14 @@
{
struct ServiceList *pos;
struct ServiceList *next;
-
+
next = running_head;
while (NULL != (pos = next))
- {
- next = pos->next;
- if (pos->proc == NULL)
- free_service (pos);
- }
+ {
+ next = pos->next;
+ if (pos->proc == NULL)
+ free_service (pos);
+ }
}
@@ -669,15 +644,15 @@
do_shutdown ()
{
if (NULL != server)
- {
- GNUNET_SERVER_destroy (server);
- server = NULL;
- }
+ {
+ GNUNET_SERVER_destroy (server);
+ server = NULL;
+ }
if (GNUNET_SCHEDULER_NO_TASK != child_death_task)
- {
- GNUNET_SCHEDULER_cancel (child_death_task);
- child_death_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (child_death_task);
+ child_death_task = GNUNET_SCHEDULER_NO_TASK;
+ }
}
@@ -688,35 +663,31 @@
* @param tc context
*/
static void
-shutdown_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct ServiceList *pos;
#if DEBUG_ARM
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Stopping all services\n"));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Stopping all services\n"));
#endif
if (GNUNET_SCHEDULER_NO_TASK != child_restart_task)
- {
- GNUNET_SCHEDULER_cancel (child_restart_task);
- child_restart_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (child_restart_task);
+ child_restart_task = GNUNET_SCHEDULER_NO_TASK;
+ }
in_shutdown = GNUNET_YES;
stop_listening (NULL);
pos = running_head;
while (NULL != pos)
+ {
+ if (pos->proc != NULL)
{
- if (pos->proc != NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Stopping service `%s'\n",
- pos->name);
- if (0 != GNUNET_OS_process_kill (pos->proc, SIGTERM))
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
- }
- pos = pos->next;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stopping service `%s'\n",
pos->name);
+ if (0 != GNUNET_OS_process_kill (pos->proc, SIGTERM))
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
}
+ pos = pos->next;
+ }
if (running_head == NULL)
do_shutdown ();
}
@@ -741,40 +712,39 @@
lowestRestartDelay = GNUNET_TIME_UNIT_FOREVER_REL;
/* check for services that need to be restarted due to
- configuration changes or because the last restart failed */
+ * configuration changes or because the last restart failed */
pos = running_head;
while (pos != NULL)
+ {
+ if (pos->proc == NULL)
{
- if (pos->proc == NULL)
- {
- if (GNUNET_TIME_absolute_get_remaining (pos->restartAt).rel_value ==
0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Restarting service `%s'.\n"), pos->name);
- start_process (pos, NULL);
- }
- else
- {
- lowestRestartDelay
- = GNUNET_TIME_relative_min (lowestRestartDelay,
- GNUNET_TIME_absolute_get_remaining
- (pos->restartAt));
- }
- }
- pos = pos->next;
- }
+ if (GNUNET_TIME_absolute_get_remaining (pos->restartAt).rel_value == 0)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Restarting service `%s'.\n"), pos->name);
+ start_process (pos, NULL);
+ }
+ else
+ {
+ lowestRestartDelay
+ = GNUNET_TIME_relative_min (lowestRestartDelay,
+ GNUNET_TIME_absolute_get_remaining
+ (pos->restartAt));
+ }
+ }
+ pos = pos->next;
+ }
if (lowestRestartDelay.rel_value != GNUNET_TIME_UNIT_FOREVER_REL.rel_value)
- {
+ {
#if DEBUG_ARM
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Will restart process in %llums\n",
- (unsigned long long) lowestRestartDelay.rel_value);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Will restart process in %llums\n",
+ (unsigned long long) lowestRestartDelay.rel_value);
#endif
- child_restart_task
- = GNUNET_SCHEDULER_add_delayed (lowestRestartDelay,
- &delayed_restart_task,
- NULL);
- }
+ child_restart_task
+ = GNUNET_SCHEDULER_add_delayed (lowestRestartDelay,
+ &delayed_restart_task, NULL);
+ }
}
@@ -786,8 +756,7 @@
* @param tc context
*/
static void
-maint_child_death (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+maint_child_death (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct ServiceList *pos;
struct ServiceList *next;
@@ -800,93 +769,89 @@
child_death_task = GNUNET_SCHEDULER_NO_TASK;
if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY))
- {
- /* shutdown scheduled us, ignore! */
- child_death_task =
- GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, pr,
- &maint_child_death, NULL);
- return;
- }
+ {
+ /* shutdown scheduled us, ignore! */
+ child_death_task =
+ GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, pr,
+ &maint_child_death, NULL);
+ return;
+ }
/* consume the signal */
GNUNET_break (0 < GNUNET_DISK_file_read (pr, &c, sizeof (c)));
/* check for services that died (WAITPID) */
next = running_head;
while (NULL != (pos = next))
- {
- next = pos->next;
- if (pos->proc == NULL)
- continue;
- if ((GNUNET_SYSERR == (ret = GNUNET_OS_process_status (pos->proc,
- &statusType,
- &statusCode))) ||
- ( (ret == GNUNET_NO) ||
- (statusType == GNUNET_OS_PROCESS_STOPPED) ||
- (statusType == GNUNET_OS_PROCESS_RUNNING)) )
- continue;
+ {
+ next = pos->next;
+ if (pos->proc == NULL)
+ continue;
+ if ((GNUNET_SYSERR == (ret = GNUNET_OS_process_status (pos->proc,
+ &statusType,
+ &statusCode))) ||
+ ((ret == GNUNET_NO) ||
+ (statusType == GNUNET_OS_PROCESS_STOPPED) ||
+ (statusType == GNUNET_OS_PROCESS_RUNNING)))
+ continue;
- if (statusType == GNUNET_OS_PROCESS_EXITED)
- {
- statstr = _( /* process termination method */ "exit");
- statcode = statusCode;
- }
- else if (statusType == GNUNET_OS_PROCESS_SIGNALED)
- {
- statstr = _( /* process termination method */ "signal");
- statcode = statusCode;
- }
- else
- {
- statstr = _( /* process termination method */ "unknown");
- statcode = 0;
- }
- GNUNET_OS_process_close (pos->proc);
- pos->proc = NULL;
- if (NULL != pos->killing_client)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Service `%s' stopped\n"),
- pos->name);
- signal_result (pos->killing_client,
- pos->name, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
- GNUNET_SERVER_receive_done (pos->killing_client, GNUNET_OK);
- GNUNET_SERVER_client_drop (pos->killing_client);
- free_service (pos);
- continue;
- }
- if (GNUNET_YES != in_shutdown)
- {
- if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Service `%s' terminated with status %s/%d, will try
to restart it!\n"),
- pos->name, statstr, statcode);
- /* schedule restart */
- pos->restartAt
- = GNUNET_TIME_relative_to_absolute (pos->backoff);
- if (pos->backoff.rel_value < EXPONENTIAL_BACKOFF_THRESHOLD)
- pos->backoff
- = GNUNET_TIME_relative_multiply (pos->backoff, 2);
- if (GNUNET_SCHEDULER_NO_TASK != child_restart_task)
- GNUNET_SCHEDULER_cancel (child_restart_task);
- child_restart_task
- = GNUNET_SCHEDULER_add_with_priority
(GNUNET_SCHEDULER_PRIORITY_IDLE,
- &delayed_restart_task,
- NULL);
- }
+ if (statusType == GNUNET_OS_PROCESS_EXITED)
+ {
+ statstr = _( /* process termination method */ "exit");
+ statcode = statusCode;
+ }
+ else if (statusType == GNUNET_OS_PROCESS_SIGNALED)
+ {
+ statstr = _( /* process termination method */ "signal");
+ statcode = statusCode;
+ }
+ else
+ {
+ statstr = _( /* process termination method */ "unknown");
+ statcode = 0;
+ }
+ GNUNET_OS_process_close (pos->proc);
+ pos->proc = NULL;
+ if (NULL != pos->killing_client)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Service `%s' stopped\n"), pos->name);
+ signal_result (pos->killing_client,
+ pos->name, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
+ GNUNET_SERVER_receive_done (pos->killing_client, GNUNET_OK);
+ GNUNET_SERVER_client_drop (pos->killing_client);
+ free_service (pos);
+ continue;
+ }
+ if (GNUNET_YES != in_shutdown)
+ {
+ if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Service `%s' terminated with status %s/%d, will try to
restart it!\n"),
+ pos->name, statstr, statcode);
+ /* schedule restart */
+ pos->restartAt = GNUNET_TIME_relative_to_absolute (pos->backoff);
+ if (pos->backoff.rel_value < EXPONENTIAL_BACKOFF_THRESHOLD)
+ pos->backoff = GNUNET_TIME_relative_multiply (pos->backoff, 2);
+ if (GNUNET_SCHEDULER_NO_TASK != child_restart_task)
+ GNUNET_SCHEDULER_cancel (child_restart_task);
+ child_restart_task
+ = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
+ &delayed_restart_task, NULL);
+ }
#if DEBUG_ARM
- else
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Service `%s' terminated with status %s/%d\n",
- pos->name, statstr, statcode);
+ else
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Service `%s' terminated with status %s/%d\n",
+ pos->name, statstr, statcode);
#endif
- }
+ }
child_death_task =
- GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, pr,
- &maint_child_death, NULL);
+ GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, pr,
+ &maint_child_death, NULL);
if (GNUNET_YES == in_shutdown)
clean_up_running ();
- if ( (NULL == running_head) &&
- (GNUNET_YES == in_shutdown) )
+ if ((NULL == running_head) && (GNUNET_YES == in_shutdown))
do_shutdown ();
}
@@ -898,25 +863,24 @@
struct GNUNET_MessageHeader *msg;
if (size < sizeof (struct GNUNET_MessageHeader))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Failed to transmit shutdown ACK.\n"));
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return 0; /* client disconnected */
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Failed to transmit shutdown ACK.\n"));
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return 0; /* client disconnected */
+ }
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Transmitting shutdown ACK.\n"));
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Transmitting shutdown ACK.\n"));
/* Make the connection flushing for the purpose of ACK transmitting,
- needed on W32 to ensure that the message is even received, harmless
- on other platforms... */
+ * needed on W32 to ensure that the message is even received, harmless
+ * on other platforms... */
GNUNET_break (GNUNET_OK == GNUNET_SERVER_client_disable_corking (client));
msg = (struct GNUNET_MessageHeader *) buf;
msg->type = htons (GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN_ACK);
msg->size = htons (sizeof (struct GNUNET_MessageHeader));
GNUNET_SERVER_receive_done (client, GNUNET_OK);
- GNUNET_SERVER_client_drop(client);
+ GNUNET_SERVER_client_drop (client);
return sizeof (struct GNUNET_MessageHeader);
}
@@ -933,11 +897,11 @@
struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
- GNUNET_SERVER_client_keep(client);
+ GNUNET_SERVER_client_keep (client);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
_("Initiating shutdown as requested by client.\n"));
GNUNET_SERVER_notify_transmit_ready (client,
- sizeof(struct GNUNET_MessageHeader),
+ sizeof (struct GNUNET_MessageHeader),
GNUNET_TIME_UNIT_FOREVER_REL,
&transmit_shutdown_ack, client);
GNUNET_SERVER_client_persist_ (client);
@@ -953,12 +917,13 @@
sighandler_child_death ()
{
static char c;
- int old_errno = errno; /* back-up errno */
- GNUNET_break (1 ==
- GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle
- (sigpipe, GNUNET_DISK_PIPE_END_WRITE),
&c,
- sizeof (c)));
- errno = old_errno; /* restore errno */
+ int old_errno = errno; /* back-up errno */
+
+ GNUNET_break (1 ==
+ GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle
+ (sigpipe, GNUNET_DISK_PIPE_END_WRITE),
+ &c, sizeof (c)));
+ errno = old_errno; /* restore errno */
}
@@ -991,63 +956,59 @@
GNUNET_assert (pr != NULL);
GNUNET_SERVER_ignore_shutdown (serv, GNUNET_YES);
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task,
- NULL);
+ &shutdown_task, NULL);
child_death_task =
- GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, pr,
- &maint_child_death, NULL);
+ GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, pr,
+ &maint_child_death, NULL);
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
- "ARM",
- "GLOBAL_PREFIX",
- &prefix_command))
+ "ARM",
+ "GLOBAL_PREFIX", &prefix_command))
prefix_command = GNUNET_strdup ("");
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
- "ARM",
- "GLOBAL_POSTFIX",
- &final_option))
+ "ARM",
+ "GLOBAL_POSTFIX", &final_option))
final_option = GNUNET_strdup ("");
/* start default services... */
if (GNUNET_OK ==
GNUNET_CONFIGURATION_get_value_string (cfg,
- "ARM",
- "DEFAULTSERVICES",
- &defaultservices))
- {
+ "ARM",
+ "DEFAULTSERVICES",
+ &defaultservices))
+ {
#if DEBUG_ARM
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Starting default services `%s'\n", defaultservices);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Starting default services `%s'\n", defaultservices);
#endif
- if (0 < strlen (defaultservices))
- {
- pos = strtok (defaultservices, " ");
- while (pos != NULL)
- {
- start_service (NULL, pos, NULL);
- pos = strtok (NULL, " ");
- }
- }
- GNUNET_free (defaultservices);
+ if (0 < strlen (defaultservices))
+ {
+ pos = strtok (defaultservices, " ");
+ while (pos != NULL)
+ {
+ start_service (NULL, pos, NULL);
+ pos = strtok (NULL, " ");
+ }
}
+ GNUNET_free (defaultservices);
+ }
else
- {
+ {
#if DEBUG_ARM
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "No default services configured.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No default services configured.\n");
#endif
- }
+ }
- /* create listening sockets for future services*/
+ /* create listening sockets for future services */
prepareServices (cfg);
-
+
/* process client requests */
GNUNET_SERVER_add_handlers (server, handlers);
/* manage services */
GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
- &config_change_task, NULL);
+ &config_change_task, NULL);
}
@@ -1066,10 +1027,11 @@
sigpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO);
GNUNET_assert (sigpipe != NULL);
- shc_chld = GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD,
&sighandler_child_death);
- ret = (GNUNET_OK ==
- GNUNET_SERVICE_run (argc,
- argv, "arm", GNUNET_YES, &run, NULL)) ? 0 : 1;
+ shc_chld =
+ GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death);
+ ret =
+ (GNUNET_OK ==
+ GNUNET_SERVICE_run (argc, argv, "arm", GNUNET_YES, &run, NULL)) ? 0 : 1;
GNUNET_SIGNAL_handler_uninstall (shc_chld);
shc_chld = NULL;
GNUNET_DISK_pipe_close (sigpipe);
@@ -1085,8 +1047,8 @@
*/
void __attribute__ ((constructor)) GNUNET_ARM_memory_init ()
{
- mallopt (M_TRIM_THRESHOLD, 4*1024);
- mallopt (M_TOP_PAD, 1*1024);
+ mallopt (M_TRIM_THRESHOLD, 4 * 1024);
+ mallopt (M_TOP_PAD, 1 * 1024);
malloc_trim (0);
}
#endif
Modified: gnunet/src/arm/gnunet-service-arm.h
===================================================================
--- gnunet/src/arm/gnunet-service-arm.h 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/arm/gnunet-service-arm.h 2011-08-15 21:46:35 UTC (rev 16581)
@@ -36,8 +36,7 @@
* @return GNUNET_OK on success
*/
int start_service (struct GNUNET_SERVER_Client *client,
- const char *servicename,
- const int *lsocks);
+ const char *servicename, const int *lsocks);
/**
* Stop listening for connections to a service.
@@ -49,6 +48,6 @@
int stop_listening (const char *serviceName);
void prepareServices (const struct GNUNET_CONFIGURATION_Handle
- *configurationHandle);
+ *configurationHandle);
#endif
Modified: gnunet/src/arm/gnunet-service-arm_interceptor.c
===================================================================
--- gnunet/src/arm/gnunet-service-arm_interceptor.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/arm/gnunet-service-arm_interceptor.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -153,12 +153,12 @@
* Timeout for forwarding.
*/
struct GNUNET_TIME_Absolute timeout;
-
+
/**
* Current back-off value.
*/
struct GNUNET_TIME_Relative back_off;
-
+
/**
* Task that tries to initiate forwarding.
*/
@@ -243,10 +243,10 @@
s = GNUNET_strdup (services);
token = strtok (s, " ");
while (NULL != token)
- {
- numDefaultServices++;
- token = strtok (NULL, " ");
- }
+ {
+ numDefaultServices++;
+ token = strtok (NULL, " ");
+ }
GNUNET_free (s);
defaultServicesList = GNUNET_malloc (numDefaultServices * sizeof (char *));
@@ -254,10 +254,10 @@
s = GNUNET_strdup (services);
token = strtok (s, " ");
while (NULL != token)
- {
- defaultServicesList[i++] = GNUNET_strdup (token);
- token = strtok (NULL, " ");
- }
+ {
+ defaultServicesList[i++] = GNUNET_strdup (token);
+ token = strtok (NULL, " ");
+ }
GNUNET_free (s);
GNUNET_assert (i == numDefaultServices);
}
@@ -272,9 +272,10 @@
isInDefaultList (const char *serviceName)
{
unsigned int i;
+
for (i = 0; i < numDefaultServices; i++)
if (strcmp (serviceName, defaultServicesList[i]) == 0)
- return GNUNET_YES;
+ return GNUNET_YES;
return GNUNET_NO;
}
@@ -286,52 +287,45 @@
* @param reason which direction to close
*/
static void
-closeClientAndServiceSockets (struct ForwardedConnection *fc,
- int reason)
+closeClientAndServiceSockets (struct ForwardedConnection *fc, int reason)
{
- if (0 != (REASON_SERVICE_TO_CLIENT & reason))
- {
+ if (0 != (REASON_SERVICE_TO_CLIENT & reason))
+ {
#if DEBUG_SERVICE_MANAGER
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Stopping forwarding from service to client\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Stopping forwarding from service to client\n");
#endif
- if (fc->armClientSocket != NULL)
- GNUNET_NETWORK_socket_shutdown (fc->armClientSocket,
- SHUT_WR);
- if (fc->armServiceSocket != NULL)
- GNUNET_NETWORK_socket_shutdown (fc->armServiceSocket,
- SHUT_RD);
- }
- if (0 != (REASON_CLIENT_TO_SERVICE & reason))
- {
+ if (fc->armClientSocket != NULL)
+ GNUNET_NETWORK_socket_shutdown (fc->armClientSocket, SHUT_WR);
+ if (fc->armServiceSocket != NULL)
+ GNUNET_NETWORK_socket_shutdown (fc->armServiceSocket, SHUT_RD);
+ }
+ if (0 != (REASON_CLIENT_TO_SERVICE & reason))
+ {
#if DEBUG_SERVICE_MANAGER
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Stopping forwarding from client to service\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Stopping forwarding from client to service\n");
#endif
- if (fc->armClientSocket != NULL)
- GNUNET_NETWORK_socket_shutdown (fc->armClientSocket,
- SHUT_RD);
- if (fc->armServiceSocket != NULL)
- GNUNET_NETWORK_socket_shutdown (fc->armServiceSocket,
- SHUT_WR);
- }
+ if (fc->armClientSocket != NULL)
+ GNUNET_NETWORK_socket_shutdown (fc->armClientSocket, SHUT_RD);
+ if (fc->armServiceSocket != NULL)
+ GNUNET_NETWORK_socket_shutdown (fc->armServiceSocket, SHUT_WR);
+ }
#if DEBUG_SERVICE_MANAGER
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Closing forwarding connection (done with both directions)\n");
+ "Closing forwarding connection (done with both directions)\n");
#endif
fc->reference_count -= 1;
if (fc->reference_count <= 0)
{
- if ( (NULL != fc->armClientSocket) &&
- (GNUNET_SYSERR ==
- GNUNET_NETWORK_socket_close (fc->armClientSocket)) )
+ if ((NULL != fc->armClientSocket) &&
+ (GNUNET_SYSERR == GNUNET_NETWORK_socket_close (fc->armClientSocket)))
{
GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "close");
fc->armClientSocket = NULL;
}
- if ( (NULL != fc->armServiceSocket) &&
- (GNUNET_SYSERR ==
- GNUNET_NETWORK_socket_close (fc->armServiceSocket)) )
+ if ((NULL != fc->armServiceSocket) &&
+ (GNUNET_SYSERR == GNUNET_NETWORK_socket_close (fc->armServiceSocket)))
{
GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "close");
fc->armServiceSocket = NULL;
@@ -380,8 +374,7 @@
*
*/
static void
-start_forwarding (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+start_forwarding (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
@@ -399,54 +392,46 @@
fc->service_to_client_task = GNUNET_SCHEDULER_NO_TASK;
if (GNUNET_YES != GNUNET_NETWORK_fdset_isset (tc->write_ready,
- fc->armClientSocket))
- {
- fc->service_to_client_task =
- GNUNET_SCHEDULER_add_write_net (
- GNUNET_TIME_UNIT_FOREVER_REL,
- fc->armClientSocket,
- &forwardToClient, fc);
- return;
- }
+ fc->armClientSocket))
+ {
+ fc->service_to_client_task =
+ GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ fc->armClientSocket,
+ &forwardToClient, fc);
+ return;
+ }
/* Forwarding service response to client */
numberOfBytesSent =
- GNUNET_NETWORK_socket_send (fc->armClientSocket,
- fc->service_to_client_bufferPos,
- fc->service_to_client_bufferDataLength);
+ GNUNET_NETWORK_socket_send (fc->armClientSocket,
+ fc->service_to_client_bufferPos,
+ fc->service_to_client_bufferDataLength);
if (numberOfBytesSent <= 0)
- {
- if ( (errno != EPIPE) &&
- (errno != ECONNRESET) )
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Failed to forward %u bytes of data to client: %s\n",
- fc->service_to_client_bufferDataLength,
- STRERROR (errno));
- closeClientAndServiceSockets (fc,
- REASON_SERVICE_TO_CLIENT);
- return;
- }
+ {
+ if ((errno != EPIPE) && (errno != ECONNRESET))
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to forward %u bytes of data to client: %s\n",
+ fc->service_to_client_bufferDataLength, STRERROR (errno));
+ closeClientAndServiceSockets (fc, REASON_SERVICE_TO_CLIENT);
+ return;
+ }
#if DEBUG_SERVICE_MANAGER
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Forwarded %d bytes to client\n",
- numberOfBytesSent);
+ "Forwarded %d bytes to client\n", numberOfBytesSent);
#endif
if (numberOfBytesSent < fc->service_to_client_bufferDataLength)
- {
- fc->service_to_client_bufferPos += numberOfBytesSent;
- fc->service_to_client_bufferDataLength -= numberOfBytesSent;
- fc->service_to_client_task =
- GNUNET_SCHEDULER_add_write_net (
- GNUNET_TIME_UNIT_FOREVER_REL,
- fc->armClientSocket,
- &forwardToClient,
- fc);
- return;
- }
+ {
+ fc->service_to_client_bufferPos += numberOfBytesSent;
+ fc->service_to_client_bufferDataLength -= numberOfBytesSent;
+ fc->service_to_client_task =
+ GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ fc->armClientSocket,
+ &forwardToClient, fc);
+ return;
+ }
fc->service_to_client_task =
- GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- fc->armServiceSocket,
- &receiveFromService,
- fc);
+ GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ fc->armServiceSocket,
+ &receiveFromService, fc);
}
@@ -457,98 +442,92 @@
* @param tc scheduler context
*/
static void
-receiveFromService (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+receiveFromService (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct ForwardedConnection *fc = cls;
struct GNUNET_TIME_Relative rem;
fc->service_to_client_task = GNUNET_SCHEDULER_NO_TASK;
- if ( (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) &&
- (fc->first_write_done != GNUNET_YES) )
- {
- closeClientAndServiceSockets (fc, REASON_ERROR);
- return;
- }
+ if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) &&
+ (fc->first_write_done != GNUNET_YES))
+ {
+ closeClientAndServiceSockets (fc, REASON_ERROR);
+ return;
+ }
if (GNUNET_YES != GNUNET_NETWORK_fdset_isset (tc->read_ready,
- fc->armServiceSocket))
- {
- fc->service_to_client_task =
- GNUNET_SCHEDULER_add_read_net (
- GNUNET_TIME_UNIT_FOREVER_REL,
- fc->armServiceSocket,
- &receiveFromService, fc);
- return;
- }
+ fc->armServiceSocket))
+ {
+ fc->service_to_client_task =
+ GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ fc->armServiceSocket,
+ &receiveFromService, fc);
+ return;
+ }
fc->service_to_client_bufferPos = fc->service_to_client_buffer;
fc->service_to_client_bufferDataLength =
- GNUNET_NETWORK_socket_recv (fc->armServiceSocket,
- fc->service_to_client_buffer,
- BUFFER_SIZE);
+ GNUNET_NETWORK_socket_recv (fc->armServiceSocket,
+ fc->service_to_client_buffer, BUFFER_SIZE);
if (fc->service_to_client_bufferDataLength <= 0)
- {
+ {
#if DEBUG_SERVICE_MANAGER
- if (fc->service_to_client_bufferDataLength == 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Service `%s' stopped sending data.\n",
- fc->listen_info->serviceName);
- }
+ if (fc->service_to_client_bufferDataLength == 0)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Service `%s' stopped sending data.\n",
+ fc->listen_info->serviceName);
+ }
#endif
- if (fc->first_write_done != GNUNET_YES)
- {
- fc->service_to_client_bufferDataLength = 0;
- GNUNET_break (GNUNET_OK ==
- GNUNET_NETWORK_socket_close (fc->armServiceSocket));
- fc->armServiceSocket = NULL;
- if ( (fc->client_to_service_bufferDataLength > 0) &&
- (fc->client_to_service_task != GNUNET_SCHEDULER_NO_TASK) )
- {
- GNUNET_SCHEDULER_cancel (fc->client_to_service_task);
- fc->client_to_service_task = GNUNET_SCHEDULER_NO_TASK;
- }
- fc->back_off = GNUNET_TIME_relative_multiply (fc->back_off, 2);
+ if (fc->first_write_done != GNUNET_YES)
+ {
+ fc->service_to_client_bufferDataLength = 0;
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_NETWORK_socket_close (fc->armServiceSocket));
+ fc->armServiceSocket = NULL;
+ if ((fc->client_to_service_bufferDataLength > 0) &&
+ (fc->client_to_service_task != GNUNET_SCHEDULER_NO_TASK))
+ {
+ GNUNET_SCHEDULER_cancel (fc->client_to_service_task);
+ fc->client_to_service_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ fc->back_off = GNUNET_TIME_relative_multiply (fc->back_off, 2);
#if DEBUG_SERVICE_MANAGER
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Failed to connected to service `%s' at `%s', will try
again in %llu ms\n",
- fc->listen_info->serviceName,
- GNUNET_a2s (fc->listen_info->service_addr,
- fc->listen_info->service_addr_len),
- (unsigned long long) GNUNET_TIME_relative_min
(fc->back_off,
-
rem).rel_value);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to connected to service `%s' at `%s', will try again
in %llu ms\n",
+ fc->listen_info->serviceName,
+ GNUNET_a2s (fc->listen_info->service_addr,
+ fc->listen_info->service_addr_len),
+ (unsigned long long) GNUNET_TIME_relative_min (fc->back_off,
+
rem).rel_value);
#endif
- rem = GNUNET_TIME_absolute_get_remaining (fc->timeout);
- GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == fc->start_task);
- fc->start_task
- = GNUNET_SCHEDULER_add_delayed (
- GNUNET_TIME_relative_min
(fc->back_off,
- rem),
- &start_forwarding,
- fc);
- }
- else
- {
+ rem = GNUNET_TIME_absolute_get_remaining (fc->timeout);
+ GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == fc->start_task);
+ fc->start_task
+ =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_min
+ (fc->back_off, rem), &start_forwarding,
+ fc);
+ }
+ else
+ {
#if DEBUG_SERVICE_MANAGER
- if (fc->service_to_client_bufferDataLength != 0)
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Error receiving from service: %s\n",
- STRERROR (errno));
+ if (fc->service_to_client_bufferDataLength != 0)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Error receiving from service: %s\n", STRERROR (errno));
#endif
- closeClientAndServiceSockets (fc, REASON_SERVICE_TO_CLIENT);
- }
- return;
+ closeClientAndServiceSockets (fc, REASON_SERVICE_TO_CLIENT);
}
+ return;
+ }
fc->first_write_done = GNUNET_YES;
#if DEBUG_SERVICE_MANAGER
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received %d bytes for client\n",
- fc->service_to_client_bufferDataLength);
+ "Received %d bytes for client\n",
+ fc->service_to_client_bufferDataLength);
#endif
- fc->service_to_client_task =
- GNUNET_SCHEDULER_add_write_net (
- GNUNET_TIME_UNIT_FOREVER_REL,
- fc->armClientSocket,
- &forwardToClient, fc);
+ fc->service_to_client_task =
+ GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ fc->armClientSocket,
+ &forwardToClient, fc);
}
@@ -559,98 +538,92 @@
* @param tc scheduler context
*/
static void
-forwardToService (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+forwardToService (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct ForwardedConnection *fc = cls;
ssize_t numberOfBytesSent;
struct GNUNET_TIME_Relative rem;
fc->client_to_service_task = GNUNET_SCHEDULER_NO_TASK;
- if ( (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) &&
- (fc->first_write_done != GNUNET_YES) )
- {
- closeClientAndServiceSockets (fc, REASON_ERROR);
- return;
- }
+ if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) &&
+ (fc->first_write_done != GNUNET_YES))
+ {
+ closeClientAndServiceSockets (fc, REASON_ERROR);
+ return;
+ }
if (GNUNET_YES != GNUNET_NETWORK_fdset_isset (tc->write_ready,
- fc->armServiceSocket))
- {
- fc->client_to_service_task =
- GNUNET_SCHEDULER_add_write_net (
- GNUNET_TIME_UNIT_FOREVER_REL,
- fc->armServiceSocket,
- &forwardToService, fc);
- return;
- }
+ fc->armServiceSocket))
+ {
+ fc->client_to_service_task =
+ GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ fc->armServiceSocket,
+ &forwardToService, fc);
+ return;
+ }
numberOfBytesSent =
- GNUNET_NETWORK_socket_send (fc->armServiceSocket,
- fc->client_to_service_bufferPos,
- fc->client_to_service_bufferDataLength);
+ GNUNET_NETWORK_socket_send (fc->armServiceSocket,
+ fc->client_to_service_bufferPos,
+ fc->client_to_service_bufferDataLength);
if (numberOfBytesSent <= 0)
+ {
+ if (GNUNET_YES != fc->first_write_done)
{
- if (GNUNET_YES != fc->first_write_done)
- {
- GNUNET_break (GNUNET_OK ==
- GNUNET_NETWORK_socket_close (fc->armServiceSocket));
- fc->armServiceSocket = NULL;
- if ( (fc->service_to_client_bufferDataLength == 0) &&
- (fc->service_to_client_task != GNUNET_SCHEDULER_NO_TASK) )
- {
- GNUNET_SCHEDULER_cancel (fc->service_to_client_task);
- fc->service_to_client_task = GNUNET_SCHEDULER_NO_TASK;
- }
- fc->back_off = GNUNET_TIME_relative_multiply (fc->back_off, 2);
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_NETWORK_socket_close (fc->armServiceSocket));
+ fc->armServiceSocket = NULL;
+ if ((fc->service_to_client_bufferDataLength == 0) &&
+ (fc->service_to_client_task != GNUNET_SCHEDULER_NO_TASK))
+ {
+ GNUNET_SCHEDULER_cancel (fc->service_to_client_task);
+ fc->service_to_client_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ fc->back_off = GNUNET_TIME_relative_multiply (fc->back_off, 2);
#if DEBUG_SERVICE_MANAGER
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Failed to connect to service `%s' at `%s', will try
again in %llu ms\n",
- fc->listen_info->serviceName,
- GNUNET_a2s (fc->listen_info->service_addr,
- fc->listen_info->service_addr_len),
- (unsigned long long) GNUNET_TIME_relative_min
(fc->back_off,
-
rem).rel_value);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to connect to service `%s' at `%s', will try again
in %llu ms\n",
+ fc->listen_info->serviceName,
+ GNUNET_a2s (fc->listen_info->service_addr,
+ fc->listen_info->service_addr_len),
+ (unsigned long long) GNUNET_TIME_relative_min (fc->back_off,
+
rem).rel_value);
#endif
- rem = GNUNET_TIME_absolute_get_remaining (fc->timeout);
- GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == fc->start_task);
- fc->start_task
- = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_min
(fc->back_off,
- rem),
- &start_forwarding,
- fc);
- }
- else
- {
- if ( (errno != EPIPE) &&
- (errno != ECONNRESET) )
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Failed to forward data to service: %s\n",
- STRERROR (errno));
- closeClientAndServiceSockets (fc,
- REASON_CLIENT_TO_SERVICE);
- }
- return;
+ rem = GNUNET_TIME_absolute_get_remaining (fc->timeout);
+ GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == fc->start_task);
+ fc->start_task
+ =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_min
+ (fc->back_off, rem), &start_forwarding,
+ fc);
}
+ else
+ {
+ if ((errno != EPIPE) && (errno != ECONNRESET))
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to forward data to service: %s\n",
+ STRERROR (errno));
+ closeClientAndServiceSockets (fc, REASON_CLIENT_TO_SERVICE);
+ }
+ return;
+ }
#if DEBUG_SERVICE_MANAGER
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Forwarded %d bytes to service\n",
- numberOfBytesSent);
+ "Forwarded %d bytes to service\n", numberOfBytesSent);
#endif
fc->first_write_done = GNUNET_YES;
if (numberOfBytesSent < fc->client_to_service_bufferDataLength)
- {
- fc->client_to_service_bufferPos += numberOfBytesSent;
- fc->client_to_service_bufferDataLength -= numberOfBytesSent;
- fc->client_to_service_task =
- GNUNET_SCHEDULER_add_write_net (
- GNUNET_TIME_UNIT_FOREVER_REL,
- fc->armServiceSocket,
- &forwardToService, fc);
- return;
- }
+ {
+ fc->client_to_service_bufferPos += numberOfBytesSent;
+ fc->client_to_service_bufferDataLength -= numberOfBytesSent;
+ fc->client_to_service_task =
+ GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ fc->armServiceSocket,
+ &forwardToService, fc);
+ return;
+ }
fc->client_to_service_task =
- GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- fc->armClientSocket,
- &receiveFromClient, fc);
+ GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ fc->armClientSocket,
+ &receiveFromClient, fc);
}
@@ -667,76 +640,73 @@
fc->client_to_service_task = GNUNET_SCHEDULER_NO_TASK;
if (GNUNET_YES != GNUNET_NETWORK_fdset_isset (tc->read_ready,
- fc->armClientSocket))
- {
- fc->client_to_service_task =
- GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- fc->armClientSocket,
- &receiveFromClient, fc);
- return;
- }
+ fc->armClientSocket))
+ {
+ fc->client_to_service_task =
+ GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ fc->armClientSocket,
+ &receiveFromClient, fc);
+ return;
+ }
fc->client_to_service_bufferPos = fc->client_to_service_buffer;
fc->client_to_service_bufferDataLength =
- GNUNET_NETWORK_socket_recv (fc->armClientSocket,
- fc->client_to_service_buffer,
- BUFFER_SIZE);
+ GNUNET_NETWORK_socket_recv (fc->armClientSocket,
+ fc->client_to_service_buffer, BUFFER_SIZE);
if (fc->client_to_service_bufferDataLength <= 0)
+ {
+ if (fc->client_to_service_bufferDataLength == 0)
{
- if (fc->client_to_service_bufferDataLength == 0)
- {
#if DEBUG_SERVICE_MANAGER
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Client closed connection with service `%s'\n",
- fc->listen_info->serviceName);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Client closed connection with service `%s'\n",
+ fc->listen_info->serviceName);
#endif
- }
- else
- {
+ }
+ else
+ {
#if DEBUG_SERVICE_MANAGER
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Error receiving from client: %s\n",
- STRERROR (errno));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Error receiving from client: %s\n", STRERROR (errno));
#endif
- }
- closeClientAndServiceSockets (fc, REASON_CLIENT_TO_SERVICE);
- return;
}
+ closeClientAndServiceSockets (fc, REASON_CLIENT_TO_SERVICE);
+ return;
+ }
#if DEBUG_SERVICE_MANAGER
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received %d bytes for service\n",
- fc->client_to_service_bufferDataLength);
+ "Received %d bytes for service\n",
+ fc->client_to_service_bufferDataLength);
#endif
- if (fc->armServiceSocket != NULL)
- fc->client_to_service_task =
- GNUNET_SCHEDULER_add_write_net (
- GNUNET_TIME_UNIT_FOREVER_REL,
- fc->armServiceSocket,
- &forwardToService, fc);
+ if (fc->armServiceSocket != NULL)
+ fc->client_to_service_task =
+ GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ fc->armServiceSocket,
+ &forwardToService, fc);
else
- /* We have not added any task with fc as a closure, so we're
- * dropping our reference to fc
- */
+ /* We have not added any task with fc as a closure, so we're
+ * dropping our reference to fc
+ */
fc->reference_count -= 1;
}
static void
-fc_acceptConnection (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+fc_acceptConnection (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct ServiceListeningInfo *sli = cls;
struct ForwardedConnection *fc = sli->fc;
if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY))
- {
- GNUNET_assert (GNUNET_OK == GNUNET_NETWORK_socket_close
(sli->listeningSocket));
- closeClientAndServiceSockets (fc, REASON_ERROR);
- GNUNET_free (sli);
- return;
- }
+ {
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_NETWORK_socket_close (sli->listeningSocket));
+ closeClientAndServiceSockets (fc, REASON_ERROR);
+ GNUNET_free (sli);
+ return;
+ }
#if DEBUG_SERVICE_MANAGER
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connected to service, now starting forwarding\n");
+ "Connected to service, now starting forwarding\n");
#endif
fc->armServiceSocket = sli->listeningSocket;
GNUNET_free (fc->listen_info->service_addr);
@@ -749,72 +719,70 @@
*/
fc->reference_count -= 1;
if (fc->client_to_service_task == GNUNET_SCHEDULER_NO_TASK)
- {
- if (fc->client_to_service_bufferDataLength == 0)
- fc->client_to_service_task =
- GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- fc->armClientSocket,
- &receiveFromClient, fc);
- else
- fc->client_to_service_task =
- GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
- fc->armServiceSocket,
- &forwardToService, fc);
- fc->reference_count += 1;
- }
+ {
+ if (fc->client_to_service_bufferDataLength == 0)
+ fc->client_to_service_task =
+ GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ fc->armClientSocket,
+ &receiveFromClient, fc);
+ else
+ fc->client_to_service_task =
+ GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ fc->armServiceSocket,
+ &forwardToService, fc);
+ fc->reference_count += 1;
+ }
if (fc->service_to_client_task == GNUNET_SCHEDULER_NO_TASK)
- {
- if (fc->service_to_client_bufferDataLength == 0)
- fc->service_to_client_task =
- GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- fc->armServiceSocket,
- &receiveFromService, fc);
- else
- fc->service_to_client_task =
- GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
- fc->armClientSocket,
- &forwardToClient, fc);
- fc->reference_count += 1;
- }
+ {
+ if (fc->service_to_client_bufferDataLength == 0)
+ fc->service_to_client_task =
+ GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ fc->armServiceSocket,
+ &receiveFromService, fc);
+ else
+ fc->service_to_client_task =
+ GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ fc->armClientSocket,
+ &forwardToClient, fc);
+ fc->reference_count += 1;
+ }
GNUNET_free (sli);
}
static struct ServiceListeningInfo *
-service_try_to_connect (const struct sockaddr *addr,
- int pf,
- socklen_t addrlen,
- struct ForwardedConnection *fc)
+service_try_to_connect (const struct sockaddr *addr,
+ int pf,
+ socklen_t addrlen, struct ForwardedConnection *fc)
{
struct GNUNET_NETWORK_Handle *sock;
struct ServiceListeningInfo *serviceListeningInfo;
sock = GNUNET_NETWORK_socket_create (pf, SOCK_STREAM, 0);
if (sock == NULL)
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "socket");
- return NULL;
- }
- if ( (GNUNET_SYSERR == GNUNET_NETWORK_socket_connect (sock, addr, addrlen))
&&
- (errno != EINPROGRESS) )
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "connect");
- GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
- return NULL;
- }
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "socket");
+ return NULL;
+ }
+ if ((GNUNET_SYSERR == GNUNET_NETWORK_socket_connect (sock, addr, addrlen)) &&
+ (errno != EINPROGRESS))
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "connect");
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
+ return NULL;
+ }
serviceListeningInfo = GNUNET_malloc (sizeof (struct ServiceListeningInfo));
serviceListeningInfo->serviceName = NULL;
serviceListeningInfo->service_addr = GNUNET_malloc (addrlen);
- memcpy (serviceListeningInfo->service_addr,
- addr,
- addrlen);
+ memcpy (serviceListeningInfo->service_addr, addr, addrlen);
serviceListeningInfo->service_addr_len = addrlen;
serviceListeningInfo->listeningSocket = sock;
serviceListeningInfo->fc = fc;
serviceListeningInfo->acceptTask =
- GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
- serviceListeningInfo->listeningSocket,
- &fc_acceptConnection, serviceListeningInfo);
+ GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ serviceListeningInfo->listeningSocket,
+ &fc_acceptConnection,
+ serviceListeningInfo);
return serviceListeningInfo;
}
@@ -823,8 +791,7 @@
*
*/
static void
-start_forwarding (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+start_forwarding (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct ForwardedConnection *fc = cls;
struct ServiceListeningInfo *sc;
@@ -835,91 +802,80 @@
char listen_address[INET6_ADDRSTRLEN];
fc->start_task = GNUNET_SCHEDULER_NO_TASK;
- if ( (NULL != tc) &&
- (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Unable to forward to service `%s': shutdown\n"),
- fc->listen_info->serviceName);
- closeClientAndServiceSockets (fc, REASON_ERROR);
- return;
- }
+ if ((NULL != tc) && (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Unable to forward to service `%s': shutdown\n"),
+ fc->listen_info->serviceName);
+ closeClientAndServiceSockets (fc, REASON_ERROR);
+ return;
+ }
if (0 == GNUNET_TIME_absolute_get_remaining (fc->timeout).rel_value)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _
+ ("Unable to forward to service `%s': timeout before
connect\n"),
+ fc->listen_info->serviceName);
+ closeClientAndServiceSockets (fc, REASON_ERROR);
+ return;
+ }
+ switch (fc->listen_info->service_addr->sa_family)
+ {
+ case AF_UNSPEC:
+ GNUNET_break (0);
+ closeClientAndServiceSockets (fc, REASON_ERROR);
+ return;
+ case AF_INET:
+ v4 = (const struct sockaddr_in *) fc->listen_info->service_addr;
+ inet_ntop (fc->listen_info->service_addr->sa_family,
+ (const void *) &v4->sin_addr, listen_address, INET_ADDRSTRLEN);
+ if (0 == strncmp (listen_address, "0.0.0.0", 7))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Unable to forward to service `%s': timeout before
connect\n"),
- fc->listen_info->serviceName);
- closeClientAndServiceSockets (fc, REASON_ERROR);
- return;
+ /* connect to [::1] and 127.0.0.1 instead of [::] and 0.0.0.0 */
+ memset (&target_ipv4, 0, sizeof (target_ipv4));
+ GNUNET_assert (1 ==
+ inet_pton (AF_INET, "127.0.0.1", &target_ipv4.sin_addr));
+ target_ipv4.sin_family = AF_INET;
+ target_ipv4.sin_port = v4->sin_port;
+ v4 = &target_ipv4;
}
- switch (fc->listen_info->service_addr->sa_family)
+ sc = service_try_to_connect ((const struct sockaddr *) v4,
+ PF_INET, sizeof (struct sockaddr_in), fc);
+ break;
+ case AF_INET6:
+ v6 = (struct sockaddr_in6 *) fc->listen_info->service_addr;
+ inet_ntop (fc->listen_info->service_addr->sa_family,
+ (const void *) &v6->sin6_addr, listen_address,
INET6_ADDRSTRLEN);
+ if ((strncmp (listen_address, "[::]:", 5) == 0) ||
+ (strncmp (listen_address, "::", 2) == 0))
{
- case AF_UNSPEC:
- GNUNET_break (0);
- closeClientAndServiceSockets (fc, REASON_ERROR);
- return;
- case AF_INET:
- v4 = (const struct sockaddr_in *) fc->listen_info->service_addr;
- inet_ntop (fc->listen_info->service_addr->sa_family,
- (const void *) &v4->sin_addr,
- listen_address,
- INET_ADDRSTRLEN);
- if (0 == strncmp (listen_address, "0.0.0.0", 7))
- {
- /* connect to [::1] and 127.0.0.1 instead of [::] and 0.0.0.0 */
- memset (&target_ipv4, 0, sizeof (target_ipv4));
- GNUNET_assert (1 ==
- inet_pton (AF_INET,
- "127.0.0.1",
- &target_ipv4.sin_addr));
- target_ipv4.sin_family = AF_INET;
- target_ipv4.sin_port = v4->sin_port;
- v4 = &target_ipv4;
- }
- sc = service_try_to_connect ((const struct sockaddr*) v4,
- PF_INET,
- sizeof (struct sockaddr_in),
- fc);
- break;
- case AF_INET6:
- v6 = (struct sockaddr_in6 *)fc->listen_info->service_addr;
- inet_ntop (fc->listen_info->service_addr->sa_family,
- (const void *) &v6->sin6_addr,
- listen_address,
- INET6_ADDRSTRLEN);
- if ( (strncmp (listen_address, "[::]:", 5) == 0) || (strncmp
(listen_address, "::", 2) == 0) )
- {
- memset (&target_ipv6, 0, sizeof (target_ipv6));
- target_ipv6.sin6_addr = in6addr_loopback;
- target_ipv6.sin6_family = AF_INET6;
- target_ipv6.sin6_port = v6->sin6_port;
- v6 = &target_ipv6;
- }
- sc = service_try_to_connect ((const struct sockaddr*) v6,
- PF_INET6,
- sizeof (struct sockaddr_in6),
- fc);
- break;
- case AF_UNIX:
- sc = service_try_to_connect (fc->listen_info->service_addr,
- PF_UNIX,
- fc->listen_info->service_addr_len,
- fc);
- break;
- default:
- GNUNET_break (0);
- closeClientAndServiceSockets (fc, REASON_ERROR);
- return;
- }
- if (NULL == sc)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _ ("Unable to start service `%s': %s\n"),
- fc->listen_info->serviceName,
- STRERROR (errno));
- closeClientAndServiceSockets (fc, REASON_ERROR);
- return;
+ memset (&target_ipv6, 0, sizeof (target_ipv6));
+ target_ipv6.sin6_addr = in6addr_loopback;
+ target_ipv6.sin6_family = AF_INET6;
+ target_ipv6.sin6_port = v6->sin6_port;
+ v6 = &target_ipv6;
}
+ sc = service_try_to_connect ((const struct sockaddr *) v6,
+ PF_INET6, sizeof (struct sockaddr_in6), fc);
+ break;
+ case AF_UNIX:
+ sc = service_try_to_connect (fc->listen_info->service_addr,
+ PF_UNIX,
+ fc->listen_info->service_addr_len, fc);
+ break;
+ default:
+ GNUNET_break (0);
+ closeClientAndServiceSockets (fc, REASON_ERROR);
+ return;
+ }
+ if (NULL == sc)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Unable to start service `%s': %s\n"),
+ fc->listen_info->serviceName, STRERROR (errno));
+ closeClientAndServiceSockets (fc, REASON_ERROR);
+ return;
+ }
}
@@ -932,27 +888,25 @@
struct ServiceListeningInfo *pos;
struct ServiceListeningInfo *next;
int ret;
-
+
ret = GNUNET_NO;
next = serviceListeningInfoList_head;
while (NULL != (pos = next))
- {
- next = pos->next;
- if ( (serviceName != NULL) &&
- (strcmp (pos->serviceName, serviceName) != 0) )
- continue;
- if (pos->acceptTask != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel (pos->acceptTask);
- GNUNET_break (GNUNET_OK ==
- GNUNET_NETWORK_socket_close (pos->listeningSocket));
- GNUNET_CONTAINER_DLL_remove (serviceListeningInfoList_head,
- serviceListeningInfoList_tail,
- pos);
- GNUNET_free (pos->serviceName);
- GNUNET_free (pos->service_addr);
- GNUNET_free (pos);
- ret = GNUNET_OK;
- }
+ {
+ next = pos->next;
+ if ((serviceName != NULL) && (strcmp (pos->serviceName, serviceName) != 0))
+ continue;
+ if (pos->acceptTask != GNUNET_SCHEDULER_NO_TASK)
+ GNUNET_SCHEDULER_cancel (pos->acceptTask);
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_NETWORK_socket_close (pos->listeningSocket));
+ GNUNET_CONTAINER_DLL_remove (serviceListeningInfoList_head,
+ serviceListeningInfoList_tail, pos);
+ GNUNET_free (pos->serviceName);
+ GNUNET_free (pos->service_addr);
+ GNUNET_free (pos);
+ ret = GNUNET_OK;
+ }
return ret;
}
@@ -978,46 +932,44 @@
fc->service_to_client_bufferPos = fc->service_to_client_buffer;
fc->client_to_service_bufferPos = fc->client_to_service_buffer;
fc->client_addr_len = sizeof (fc->client_addr);
- fc->armClientSocket = GNUNET_NETWORK_socket_accept
(serviceListeningInfo->listeningSocket,
- (struct sockaddr*)
fc->client_addr,
- &fc->client_addr_len);
+ fc->armClientSocket =
+ GNUNET_NETWORK_socket_accept (serviceListeningInfo->listeningSocket,
+ (struct sockaddr *) fc->client_addr,
+ &fc->client_addr_len);
if (NULL == fc->armClientSocket)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Unable to accept connection for service `%s': %s\n"),
- serviceListeningInfo->serviceName,
- STRERROR (errno));
- GNUNET_free (fc);
- GNUNET_CONTAINER_DLL_insert (serviceListeningInfoList_head,
- serviceListeningInfoList_tail,
- serviceListeningInfo);
- serviceListeningInfo->acceptTask =
- GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- serviceListeningInfo->listeningSocket,
- &acceptConnection,
- serviceListeningInfo);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Unable to accept connection for service `%s': %s\n"),
+ serviceListeningInfo->serviceName, STRERROR (errno));
+ GNUNET_free (fc);
+ GNUNET_CONTAINER_DLL_insert (serviceListeningInfoList_head,
+ serviceListeningInfoList_tail,
+ serviceListeningInfo);
+ serviceListeningInfo->acceptTask =
+ GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ serviceListeningInfo->listeningSocket,
+ &acceptConnection,
serviceListeningInfo);
+ return;
+ }
GNUNET_break (GNUNET_OK ==
- GNUNET_NETWORK_socket_close
(serviceListeningInfo->listeningSocket));
+ GNUNET_NETWORK_socket_close
+ (serviceListeningInfo->listeningSocket));
start_service (NULL, serviceListeningInfo->serviceName, NULL);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Service `%s' started\n"),
- fc->listen_info->serviceName);
- fc->timeout = GNUNET_TIME_relative_to_absolute
(GNUNET_CONSTANTS_SERVICE_TIMEOUT);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Service `%s' started\n"), fc->listen_info->serviceName);
+ fc->timeout =
+ GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_SERVICE_TIMEOUT);
fc->back_off = GNUNET_TIME_UNIT_MILLISECONDS;
fc->client_to_service_task =
- GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- fc->armClientSocket,
- &receiveFromClient, fc);
+ GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ fc->armClientSocket,
+ &receiveFromClient, fc);
GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == fc->start_task);
/* We're creating another chain of tasks for this fc that
* will have its own reference to it.
*/
fc->reference_count += 1;
- fc->start_task
- = GNUNET_SCHEDULER_add_now (&start_forwarding,
- fc);
+ fc->start_task = GNUNET_SCHEDULER_add_now (&start_forwarding, fc);
}
@@ -1042,59 +994,54 @@
if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
return;
GNUNET_CONTAINER_DLL_remove (serviceListeningInfoList_head,
- serviceListeningInfoList_tail,
- sli);
+ serviceListeningInfoList_tail, sli);
#ifndef MINGW
use_lsocks = GNUNET_NO;
if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (cfg,
- sli->serviceName,
-
"DISABLE_SOCKET_FORWARDING"))
+ sli->serviceName,
+
"DISABLE_SOCKET_FORWARDING"))
use_lsocks = GNUNET_CONFIGURATION_get_value_yesno (cfg,
- sli->serviceName,
-
"DISABLE_SOCKET_FORWARDING");
+ sli->serviceName,
+
"DISABLE_SOCKET_FORWARDING");
#else
use_lsocks = GNUNET_YES;
#endif
if (GNUNET_NO != use_lsocks)
- {
- accept_and_forward (sli);
- return;
- }
+ {
+ accept_and_forward (sli);
+ return;
+ }
lsocks = NULL;
ls = 0;
next = serviceListeningInfoList_head;
while (NULL != (pos = next))
+ {
+ next = pos->next;
+ if (0 == strcmp (pos->serviceName, sli->serviceName))
{
- next = pos->next;
- if (0 == strcmp (pos->serviceName,
- sli->serviceName))
- {
- GNUNET_array_append (lsocks, ls,
- GNUNET_NETWORK_get_fd (pos->listeningSocket));
- GNUNET_free (pos->listeningSocket); /* deliberately no closing! */
- GNUNET_free (pos->service_addr);
- GNUNET_free (pos->serviceName);
- GNUNET_SCHEDULER_cancel (pos->acceptTask);
- GNUNET_CONTAINER_DLL_remove (serviceListeningInfoList_head,
- serviceListeningInfoList_tail,
- pos);
- GNUNET_free (pos);
- }
+ GNUNET_array_append (lsocks, ls,
+ GNUNET_NETWORK_get_fd (pos->listeningSocket));
+ GNUNET_free (pos->listeningSocket); /* deliberately no closing! */
+ GNUNET_free (pos->service_addr);
+ GNUNET_free (pos->serviceName);
+ GNUNET_SCHEDULER_cancel (pos->acceptTask);
+ GNUNET_CONTAINER_DLL_remove (serviceListeningInfoList_head,
+ serviceListeningInfoList_tail, pos);
+ GNUNET_free (pos);
}
- GNUNET_array_append (lsocks, ls,
- GNUNET_NETWORK_get_fd (sli->listeningSocket));
- GNUNET_free (sli->listeningSocket); /* deliberately no closing! */
+ }
+ GNUNET_array_append (lsocks, ls,
+ GNUNET_NETWORK_get_fd (sli->listeningSocket));
+ GNUNET_free (sli->listeningSocket); /* deliberately no closing! */
GNUNET_free (sli->service_addr);
GNUNET_array_append (lsocks, ls, -1);
- start_service (NULL,
- sli->serviceName,
- lsocks);
+ start_service (NULL, sli->serviceName, lsocks);
ls = 0;
while (lsocks[ls] != -1)
- GNUNET_break (0 == close (lsocks[ls++]));
+ GNUNET_break (0 == close (lsocks[ls++]));
GNUNET_array_grow (lsocks, ls, 0);
GNUNET_free (sli->serviceName);
- GNUNET_free (sli);
+ GNUNET_free (sli);
}
@@ -1107,89 +1054,84 @@
* @param serviceName the name of the service in question
*/
static void
-createListeningSocket(struct sockaddr *sa, socklen_t addr_len,
- const char *serviceName)
+createListeningSocket (struct sockaddr *sa, socklen_t addr_len,
+ const char *serviceName)
{
const static int on = 1;
struct GNUNET_NETWORK_Handle *sock;
struct ServiceListeningInfo *serviceListeningInfo;
switch (sa->sa_family)
- {
- case AF_INET:
- sock = GNUNET_NETWORK_socket_create (PF_INET, SOCK_STREAM, 0);
- break;
- case AF_INET6:
- sock = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0);
- break;
- case AF_UNIX:
- if (strcmp(GNUNET_a2s (sa, addr_len), "@") == 0) /* Do not bind to blank
UNIX path! */
- return;
- sock = GNUNET_NETWORK_socket_create (PF_UNIX, SOCK_STREAM, 0);
- break;
- default:
- GNUNET_break (0);
- sock = NULL;
- errno = EAFNOSUPPORT;
- break;
- }
- if (NULL == sock)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Unable to create socket for service `%s': %s\n"),
- serviceName,
- STRERROR (errno));
- GNUNET_free (sa);
+ {
+ case AF_INET:
+ sock = GNUNET_NETWORK_socket_create (PF_INET, SOCK_STREAM, 0);
+ break;
+ case AF_INET6:
+ sock = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0);
+ break;
+ case AF_UNIX:
+ if (strcmp (GNUNET_a2s (sa, addr_len), "@") == 0) /* Do not bind to
blank UNIX path! */
return;
- }
+ sock = GNUNET_NETWORK_socket_create (PF_UNIX, SOCK_STREAM, 0);
+ break;
+ default:
+ GNUNET_break (0);
+ sock = NULL;
+ errno = EAFNOSUPPORT;
+ break;
+ }
+ if (NULL == sock)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Unable to create socket for service `%s': %s\n"),
+ serviceName, STRERROR (errno));
+ GNUNET_free (sa);
+ return;
+ }
if (GNUNET_NETWORK_socket_setsockopt
(sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK)
GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"setsockopt");
#ifdef IPV6_V6ONLY
- if ( (sa->sa_family == AF_INET6) &&
- (GNUNET_NETWORK_socket_setsockopt
- (sock, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof (on)) != GNUNET_OK))
+ if ((sa->sa_family == AF_INET6) &&
+ (GNUNET_NETWORK_socket_setsockopt
+ (sock, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof (on)) != GNUNET_OK))
GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "setsockopt");
+ "setsockopt");
#endif
if (GNUNET_NETWORK_socket_bind
(sock, (const struct sockaddr *) sa, addr_len) != GNUNET_OK)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Unable to bind listening socket for service `%s' to
address `%s': %s\n"),
- serviceName,
- GNUNET_a2s (sa, addr_len),
- STRERROR (errno));
- GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
- GNUNET_free (sa);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Unable to bind listening socket for service `%s' to address
`%s': %s\n"),
+ serviceName, GNUNET_a2s (sa, addr_len), STRERROR (errno));
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
+ GNUNET_free (sa);
+ return;
+ }
if (GNUNET_NETWORK_socket_listen (sock, 5) != GNUNET_OK)
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
- "listen");
- GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
- GNUNET_free (sa);
- return;
- }
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "listen");
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
+ GNUNET_free (sa);
+ return;
+ }
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("ARM now monitors connections to service `%s' at `%s'\n"),
- serviceName,
- GNUNET_a2s (sa, addr_len));
+ _("ARM now monitors connections to service `%s' at `%s'\n"),
+ serviceName, GNUNET_a2s (sa, addr_len));
serviceListeningInfo = GNUNET_malloc (sizeof (struct ServiceListeningInfo));
serviceListeningInfo->serviceName = GNUNET_strdup (serviceName);
serviceListeningInfo->service_addr = sa;
serviceListeningInfo->service_addr_len = addr_len;
serviceListeningInfo->listeningSocket = sock;
serviceListeningInfo->acceptTask =
- GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, sock,
- &acceptConnection,
- serviceListeningInfo);
+ GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, sock,
+ &acceptConnection, serviceListeningInfo);
GNUNET_CONTAINER_DLL_insert (serviceListeningInfoList_head,
- serviceListeningInfoList_tail,
- serviceListeningInfo);
+ serviceListeningInfoList_tail,
+ serviceListeningInfo);
}
@@ -1204,22 +1146,20 @@
*/
static void
checkPortNumberCB (void *cls,
- const char *section,
- const char *option,
- const char *value)
+ const char *section, const char *option, const char *value)
{
struct sockaddr **addrs;
socklen_t *addr_lens;
int ret;
unsigned int i;
-
- if ( (strcasecmp (section, "arm") == 0) ||
- (strcasecmp (option, "AUTOSTART") != 0) ||
- (strcasecmp (value, "YES") != 0) ||
- (isInDefaultList (section) == GNUNET_YES) )
+
+ if ((strcasecmp (section, "arm") == 0) ||
+ (strcasecmp (option, "AUTOSTART") != 0) ||
+ (strcasecmp (value, "YES") != 0) ||
+ (isInDefaultList (section) == GNUNET_YES))
return;
if (0 >= (ret = GNUNET_SERVICE_get_server_addresses (section, cfg, &addrs,
- &addr_lens)))
+ &addr_lens)))
return;
/* this will free (or capture) addrs[i] */
for (i = 0; i < ret; i++)
@@ -1235,8 +1175,7 @@
* @param configurationHandle configuration to use to get services
*/
void
-prepareServices (const struct GNUNET_CONFIGURATION_Handle
- *configurationHandle)
+prepareServices (const struct GNUNET_CONFIGURATION_Handle *configurationHandle)
{
char *defaultServicesString;
@@ -1244,13 +1183,13 @@
/* Split the default services into a list */
if (GNUNET_OK ==
GNUNET_CONFIGURATION_get_value_string (cfg, "arm", "DEFAULTSERVICES",
- &defaultServicesString))
- {
- addDefaultServicesToList (defaultServicesString);
- GNUNET_free (defaultServicesString);
- }
+ &defaultServicesString))
+ {
+ addDefaultServicesToList (defaultServicesString);
+ GNUNET_free (defaultServicesString);
+ }
/* Spot the services from the configuration and create a listening
- socket for each */
+ * socket for each */
GNUNET_CONFIGURATION_iterate (cfg, &checkPortNumberCB, NULL);
}
Modified: gnunet/src/arm/mockup-service.c
===================================================================
--- gnunet/src/arm/mockup-service.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/arm/mockup-service.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -36,21 +36,20 @@
struct GNUNET_MessageHeader *msg;
if (size < sizeof (struct GNUNET_MessageHeader))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Failed to transmit shutdown ACK.\n"));
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return 0; /* client disconnected */
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Failed to transmit shutdown ACK.\n"));
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return 0; /* client disconnected */
+ }
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Transmitting shutdown ACK.\n"));
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Transmitting shutdown ACK.\n"));
msg = (struct GNUNET_MessageHeader *) buf;
msg->type = htons (GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN_ACK);
msg->size = htons (sizeof (struct GNUNET_MessageHeader));
GNUNET_SERVER_receive_done (client, GNUNET_OK);
- GNUNET_SERVER_client_drop(client);
+ GNUNET_SERVER_client_drop (client);
return sizeof (struct GNUNET_MessageHeader);
}
@@ -66,12 +65,12 @@
struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
- GNUNET_SERVER_client_keep(client);
+ GNUNET_SERVER_client_keep (client);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
_("Initiating shutdown as requested by client.\n"));
GNUNET_SERVER_notify_transmit_ready (client,
- sizeof(struct GNUNET_MessageHeader),
+ sizeof (struct GNUNET_MessageHeader),
GNUNET_TIME_UNIT_FOREVER_REL,
&transmit_shutdown_ack, client);
GNUNET_SERVER_client_persist_ (client);
@@ -95,14 +94,15 @@
}
-int main(int argc, char *const *argv)
+int
+main (int argc, char *const *argv)
{
int ret;
-
+
ret = (GNUNET_OK ==
- GNUNET_SERVICE_run (argc,
+ GNUNET_SERVICE_run (argc,
argv,
"do-nothing", GNUNET_SERVICE_OPTION_NONE,
- &run, NULL)) ? 0 : 1;
+ &run, NULL)) ? 0 : 1;
return ret;
}
Modified: gnunet/src/arm/test_arm_api.c
===================================================================
--- gnunet/src/arm/test_arm_api.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/arm/test_arm_api.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -47,7 +47,7 @@
static void
arm_stopped (void *cls, int success)
{
- if (success != GNUNET_NO)
+ if (success != GNUNET_NO)
ok = 3;
else if (ok == 1)
ok = 0;
@@ -67,15 +67,15 @@
dns_notify (void *cls, const struct sockaddr *addr, socklen_t addrlen)
{
if (addr == NULL)
+ {
+ if (ok != 0)
{
- if (ok != 0)
- {
- GNUNET_break (0);
- ok = 2;
- }
- GNUNET_ARM_stop_service (arm, "resolver", TIMEOUT, &arm_notify_stop,
NULL);
- return;
+ GNUNET_break (0);
+ ok = 2;
}
+ GNUNET_ARM_stop_service (arm, "resolver", TIMEOUT, &arm_notify_stop, NULL);
+ return;
+ }
GNUNET_assert (addr != NULL);
ok = 0;
}
@@ -85,14 +85,14 @@
resolver_notify (void *cls, int success)
{
if (success != GNUNET_YES)
- {
- GNUNET_break (0);
- ok = 2;
+ {
+ GNUNET_break (0);
+ ok = 2;
#if START_ARM
- GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL);
+ GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL);
#endif
- return;
- }
+ return;
+ }
GNUNET_RESOLVER_ip_get ("localhost", AF_INET, TIMEOUT, &dns_notify, NULL);
}
@@ -101,22 +101,22 @@
arm_notify (void *cls, int success)
{
if (success != GNUNET_YES)
- {
- GNUNET_break (0);
- ok = 2;
+ {
+ GNUNET_break (0);
+ ok = 2;
#if START_ARM
- GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL);
+ GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL);
#endif
- }
- GNUNET_ARM_start_service (arm, "resolver", START_TIMEOUT, &resolver_notify,
NULL);
+ }
+ GNUNET_ARM_start_service (arm, "resolver", START_TIMEOUT, &resolver_notify,
+ NULL);
}
static void
task (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *c)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
{
cfg = c;
arm = GNUNET_ARM_connect (cfg, NULL);
Modified: gnunet/src/arm/test_exponential_backoff.c
===================================================================
--- gnunet/src/arm/test_exponential_backoff.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/arm/test_exponential_backoff.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -102,58 +102,55 @@
{
struct ShutdownContext *shutdown_ctx = cls;
- if ((msg == NULL) && (shutdown_ctx->confirmed != GNUNET_YES))
- {
- /* Means the other side closed the connection and never confirmed a
shutdown */
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Service handle shutdown before ACK!\n");
- if (shutdown_ctx->cont != NULL)
- shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_SYSERR);
- GNUNET_SCHEDULER_cancel(shutdown_ctx->cancel_task);
- GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
- GNUNET_free(shutdown_ctx);
- }
+ if ((msg == NULL) && (shutdown_ctx->confirmed != GNUNET_YES))
+ {
+ /* Means the other side closed the connection and never confirmed a
shutdown */
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Service handle shutdown before ACK!\n");
+ if (shutdown_ctx->cont != NULL)
+ shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_SYSERR);
+ GNUNET_SCHEDULER_cancel (shutdown_ctx->cancel_task);
+ GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
+ GNUNET_free (shutdown_ctx);
+ }
else if ((msg == NULL) && (shutdown_ctx->confirmed == GNUNET_YES))
- {
+ {
#if VERBOSE
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Service shutdown complete.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service shutdown complete.\n");
#endif
- if (shutdown_ctx->cont != NULL)
- shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_NO);
+ if (shutdown_ctx->cont != NULL)
+ shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_NO);
- GNUNET_SCHEDULER_cancel(shutdown_ctx->cancel_task);
- GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
- GNUNET_free(shutdown_ctx);
- }
+ GNUNET_SCHEDULER_cancel (shutdown_ctx->cancel_task);
+ GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
+ GNUNET_free (shutdown_ctx);
+ }
else
+ {
+ GNUNET_assert (ntohs (msg->size) == sizeof (struct GNUNET_MessageHeader));
+ switch (ntohs (msg->type))
{
- GNUNET_assert(ntohs(msg->size) == sizeof(struct GNUNET_MessageHeader));
- switch (ntohs(msg->type))
- {
- case GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN_ACK:
+ case GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN_ACK:
#if VERBOSE
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Received confirmation for service shutdown.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received confirmation for service shutdown.\n");
#endif
- shutdown_ctx->confirmed = GNUNET_YES;
- GNUNET_CLIENT_receive (shutdown_ctx->sock,
- &service_shutdown_handler,
- shutdown_ctx,
- GNUNET_TIME_UNIT_FOREVER_REL);
- break;
- default: /* Fall through */
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
- "Service shutdown refused!\n");
- if (shutdown_ctx->cont != NULL)
- shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_YES);
-
- GNUNET_SCHEDULER_cancel(shutdown_ctx->cancel_task);
- GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
- GNUNET_free(shutdown_ctx);
- break;
- }
+ shutdown_ctx->confirmed = GNUNET_YES;
+ GNUNET_CLIENT_receive (shutdown_ctx->sock,
+ &service_shutdown_handler,
+ shutdown_ctx, GNUNET_TIME_UNIT_FOREVER_REL);
+ break;
+ default: /* Fall through */
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Service shutdown refused!\n");
+ if (shutdown_ctx->cont != NULL)
+ shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_YES);
+
+ GNUNET_SCHEDULER_cancel (shutdown_ctx->cancel_task);
+ GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
+ GNUNET_free (shutdown_ctx);
+ break;
}
+ }
}
/**
@@ -162,14 +159,16 @@
* @param cls closure
* @param tc context information (why was this task triggered now)
*/
-void service_shutdown_cancel (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext * tc)
+void
+service_shutdown_cancel (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct ShutdownContext *shutdown_ctx = cls;
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "service_shutdown_cancel called!\n");
- shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_SYSERR);
+
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "service_shutdown_cancel called!\n");
+ shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_SYSERR);
GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
- GNUNET_free(shutdown_ctx);
+ GNUNET_free (shutdown_ctx);
}
@@ -189,21 +188,22 @@
struct ShutdownContext *shutdown_ctx = cls;
if (size < sizeof (struct GNUNET_MessageHeader))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to transmit shutdown request to client.\n"));
- shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_SYSERR);
- GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
- GNUNET_free(shutdown_ctx);
- return 0; /* client disconnected */
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Failed to transmit shutdown request to client.\n"));
+ shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_SYSERR);
+ GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
+ GNUNET_free (shutdown_ctx);
+ return 0; /* client disconnected */
+ }
GNUNET_CLIENT_receive (shutdown_ctx->sock,
- &service_shutdown_handler, shutdown_ctx,
- GNUNET_TIME_UNIT_FOREVER_REL);
- shutdown_ctx->cancel_task = GNUNET_SCHEDULER_add_delayed
(GNUNET_TIME_absolute_get_remaining(shutdown_ctx->timeout),
-
&service_shutdown_cancel,
- shutdown_ctx);
+ &service_shutdown_handler, shutdown_ctx,
+ GNUNET_TIME_UNIT_FOREVER_REL);
+ shutdown_ctx->cancel_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
+ (shutdown_ctx->timeout),
+ &service_shutdown_cancel, shutdown_ctx);
msg = (struct GNUNET_MessageHeader *) buf;
msg->type = htons (GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN);
msg->size = htons (sizeof (struct GNUNET_MessageHeader));
@@ -226,22 +226,22 @@
*/
static void
arm_service_shutdown (struct GNUNET_CLIENT_Connection *sock,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_CLIENT_ShutdownTask cont,
- void *cont_cls)
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_CLIENT_ShutdownTask cont, void *cont_cls)
{
struct ShutdownContext *shutdown_ctx;
- shutdown_ctx = GNUNET_malloc(sizeof(struct ShutdownContext));
+
+ shutdown_ctx = GNUNET_malloc (sizeof (struct ShutdownContext));
shutdown_ctx->cont = cont;
shutdown_ctx->cont_cls = cont_cls;
shutdown_ctx->sock = sock;
- shutdown_ctx->timeout = GNUNET_TIME_relative_to_absolute(timeout);
+ shutdown_ctx->timeout = GNUNET_TIME_relative_to_absolute (timeout);
GNUNET_CLIENT_notify_transmit_ready (sock,
- sizeof (struct
- GNUNET_MessageHeader),
- timeout,
- GNUNET_NO,
- &write_shutdown, shutdown_ctx);
+ sizeof (struct
+ GNUNET_MessageHeader),
+ timeout,
+ GNUNET_NO,
+ &write_shutdown, shutdown_ctx);
}
@@ -256,8 +256,7 @@
static void
-kill_task (void *cbData,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+kill_task (void *cbData, const struct GNUNET_SCHEDULER_TaskContext *tc);
static void
@@ -265,65 +264,55 @@
{
GNUNET_assert (success == GNUNET_YES);
ok = 1;
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
- &kill_task, NULL);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &kill_task, NULL);
}
static void
arm_notify (void *cls, int success)
-{
+{
GNUNET_assert (success == GNUNET_YES);
- GNUNET_ARM_start_service (arm,
- "do-nothing", TIMEOUT,
- &do_nothing_notify, NULL);
+ GNUNET_ARM_start_service (arm,
+ "do-nothing", TIMEOUT, &do_nothing_notify, NULL);
}
static void
-kill_task (void *cbData,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+kill_task (void *cbData, const struct GNUNET_SCHEDULER_TaskContext *tc);
static void
do_nothing_restarted_notify_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
+ const struct GNUNET_SCHEDULER_TaskContext
*tc)
+{
static char a;
-
+
trialCount++;
-#if LOG_BACKOFF
- if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- {
- fprintf(killLogFilePtr,
- "%d.Reason is shutdown!\n",
- trialCount);
- }
- else if ((tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT) != 0)
- {
- fprintf(killLogFilePtr,
- "%d.Reason is timeout!\n",
- trialCount);
- }
- else if ((tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE) != 0)
- {
- fprintf(killLogFilePtr,
- "%d.Service is running!\n",
- trialCount);
- }
+#if LOG_BACKOFF
+ if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
+ {
+ fprintf (killLogFilePtr, "%d.Reason is shutdown!\n", trialCount);
+ }
+ else if ((tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT) != 0)
+ {
+ fprintf (killLogFilePtr, "%d.Reason is timeout!\n", trialCount);
+ }
+ else if ((tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE) != 0)
+ {
+ fprintf (killLogFilePtr, "%d.Service is running!\n", trialCount);
+ }
#endif
GNUNET_SCHEDULER_add_now (&kill_task, &a);
}
static void
-do_test (void *cbData,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
- GNUNET_CLIENT_service_test("do-nothing",
- cfg, TIMEOUT,
- &do_nothing_restarted_notify_task, NULL);
+do_test (void *cbData, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ GNUNET_CLIENT_service_test ("do-nothing",
+ cfg, TIMEOUT,
+ &do_nothing_restarted_notify_task, NULL);
}
@@ -331,63 +320,56 @@
shutdown_cont (void *cls, int reason)
{
trialCount++;
- startedWaitingAt = GNUNET_TIME_absolute_get();
- GNUNET_SCHEDULER_add_delayed (waitedFor,
- &do_test,
- NULL);
+ startedWaitingAt = GNUNET_TIME_absolute_get ();
+ GNUNET_SCHEDULER_add_delayed (waitedFor, &do_test, NULL);
}
static void
-kill_task (void *cbData,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+kill_task (void *cbData, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- static struct GNUNET_CLIENT_Connection * doNothingConnection = NULL;
+ static struct GNUNET_CLIENT_Connection *doNothingConnection = NULL;
- if (NULL != cbData)
- {
- waitedFor = GNUNET_TIME_absolute_get_duration (startedWaitingAt);
-
+ if (NULL != cbData)
+ {
+ waitedFor = GNUNET_TIME_absolute_get_duration (startedWaitingAt);
+
#if LOG_BACKOFF
- fprintf(killLogFilePtr,
- "Waited for: %llu ms\n",
- (unsigned long long) waitedFor.rel_value);
+ fprintf (killLogFilePtr,
+ "Waited for: %llu ms\n", (unsigned long long)
waitedFor.rel_value);
#endif
- }
+ }
else
- {
- waitedFor.rel_value = 0;
- }
+ {
+ waitedFor.rel_value = 0;
+ }
/* Connect to the doNothing task */
doNothingConnection = GNUNET_CLIENT_connect ("do-nothing", cfg);
GNUNET_assert (doNothingConnection != NULL);
- if (trialCount == 12) {
+ if (trialCount == 12)
+ {
GNUNET_CLIENT_disconnect (doNothingConnection, GNUNET_NO);
- GNUNET_ARM_stop_service (arm,
- "do-nothing",
- TIMEOUT,
- &arm_notify_stop, NULL);
+ GNUNET_ARM_stop_service (arm,
+ "do-nothing", TIMEOUT, &arm_notify_stop, NULL);
ok = 0;
return;
}
/* Use the created connection to kill the doNothingTask */
- arm_service_shutdown(doNothingConnection,
- TIMEOUT,
- &shutdown_cont, NULL);
+ arm_service_shutdown (doNothingConnection, TIMEOUT, &shutdown_cont, NULL);
}
-
+
static void
task (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *c)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
{
cfg = c;
-
- arm = GNUNET_ARM_connect (cfg,NULL);
+
+ arm = GNUNET_ARM_connect (cfg, NULL);
#if START_ARM
- GNUNET_ARM_start_service (arm, "arm", GNUNET_TIME_UNIT_ZERO, &arm_notify,
NULL);
+ GNUNET_ARM_start_service (arm, "arm", GNUNET_TIME_UNIT_ZERO, &arm_notify,
+ NULL);
#else
arm_do_nothing (NULL, GNUNET_YES);
#endif
@@ -407,39 +389,41 @@
struct GNUNET_GETOPT_CommandLineOption options[] = {
GNUNET_GETOPT_OPTION_END
};
-
+
/* Running ARM and running the do_nothing task */
GNUNET_assert (GNUNET_OK ==
GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
argv,
"test-exponential-backoff",
"nohelp", options, &task, NULL));
-
-
+
+
return ok;
}
static int
-init()
+init ()
{
#if LOG_BACKOFF
- killLogFileName = GNUNET_DISK_mktemp("exponential-backoff-waiting.log");
- if (NULL == (killLogFilePtr = FOPEN(killLogFileName, "w"))) {
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "fopen",
killLogFileName);
+ killLogFileName = GNUNET_DISK_mktemp ("exponential-backoff-waiting.log");
+ if (NULL == (killLogFilePtr = FOPEN (killLogFileName, "w")))
+ {
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "fopen",
+ killLogFileName);
GNUNET_free (killLogFileName);
return GNUNET_SYSERR;
- }
+ }
#endif
return GNUNET_OK;
}
static void
-houseKeep()
+houseKeep ()
{
#if LOG_BACKOFF
GNUNET_assert (0 == fclose (killLogFilePtr));
- GNUNET_free(killLogFileName);
+ GNUNET_free (killLogFileName);
#endif
}
@@ -456,10 +440,10 @@
"WARNING",
#endif
NULL);
-
- init();
+
+ init ();
ret = check ();
- houseKeep();
+ houseKeep ();
return ret;
}
Modified: gnunet/src/arm/test_gnunet_service_manager.c
===================================================================
--- gnunet/src/arm/test_gnunet_service_manager.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/arm/test_gnunet_service_manager.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -53,41 +53,36 @@
static void
arm_stopped (void *cls, int success)
{
- if (success != GNUNET_NO)
- {
- GNUNET_break (0);
- ret = 4;
- }
+ if (success != GNUNET_NO)
+ {
+ GNUNET_break (0);
+ ret = 4;
+ }
else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "ARM stopped\n");
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM stopped\n");
+ }
#if START_ARM
GNUNET_ARM_disconnect (arm);
arm = NULL;
#endif
}
-static void
-hostNameResolveCB(void *cls,
- const struct sockaddr *addr,
- socklen_t addrlen)
+static void
+hostNameResolveCB (void *cls, const struct sockaddr *addr, socklen_t addrlen)
{
- if ( (ret == 0) || (ret == 4) )
+ if ((ret == 0) || (ret == 4))
return;
if (NULL == addr)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Name not resolved!\n");
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Name not resolved!\n");
#if START_ARM
- GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL);
+ GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL);
#endif
- ret = 3;
- return;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Resolved hostname, now stopping ARM\n");
+ ret = 3;
+ return;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Resolved hostname, now stopping
ARM\n");
ret = 0;
#if START_ARM
GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL);
@@ -99,34 +94,31 @@
arm_notify (void *cls, int success)
{
if (success != GNUNET_YES)
- {
- GNUNET_break (0);
- ret = 1;
- return;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Trying to resolve our own hostname!\n");
+ {
+ GNUNET_break (0);
+ ret = 1;
+ return;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to resolve our own
hostname!\n");
/* connect to the resolver service */
if (NULL == GNUNET_RESOLVER_hostname_resolve (AF_UNSPEC,
- TIMEOUT,
- &hostNameResolveCB,
- NULL))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unable initiate connection to resolver service\n");
- ret = 2;
+ TIMEOUT,
+ &hostNameResolveCB, NULL))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unable initiate connection to resolver service\n");
+ ret = 2;
#if START_ARM
- GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL);
+ GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL);
#endif
- }
+ }
}
static void
-run(void *cls,
- char * const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *c)
+run (void *cls,
+ char *const *args,
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
{
cfg = c;
#if START_ARM
@@ -139,7 +131,7 @@
static void
-check()
+check ()
{
char *const argv[] = {
"test-gnunet-service-manager",
@@ -153,39 +145,40 @@
GNUNET_GETOPT_OPTION_END
};
GNUNET_assert (GNUNET_OK ==
- GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
- argv,
- "test-gnunet-service-manager",
- "nohelp", options, &run, NULL));
+ GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
+ argv,
+ "test-gnunet-service-manager",
+ "nohelp", options, &run, NULL));
}
int
main (int argc, char *argv[])
{
- char hostname[GNUNET_OS_get_hostname_max_length() + 1];
+ 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");
- fprintf (stderr, "Failed to determine my own hostname, testcase not
run.\n");
- return 0;
- }
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR |
+ GNUNET_ERROR_TYPE_BULK, "gethostname");
+ fprintf (stderr,
+ "Failed to determine my own hostname, testcase not run.\n");
+ return 0;
+ }
if (NULL == gethostbyname (hostname))
- {
- fprintf (stderr, "Failed to resolve my hostname `%s', testcase not
run.\n",
- hostname);
- return 0;
- }
+ {
+ fprintf (stderr, "Failed to resolve my hostname `%s', testcase not run.\n",
+ hostname);
+ return 0;
+ }
- GNUNET_log_setup("test-gnunet-service-manager",
+ GNUNET_log_setup ("test-gnunet-service-manager",
#if VERBOSE
- "DEBUG",
+ "DEBUG",
#else
- "WARNING",
+ "WARNING",
#endif
- NULL);
- check();
+ NULL);
+ check ();
return ret;
}
Modified: gnunet/src/ats/ats_api.c
===================================================================
--- gnunet/src/ats/ats_api.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/ats/ats_api.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -67,7 +67,7 @@
/**
* Number of bytes in plugin_addr.
*/
- size_t plugin_addr_len;
+ size_t plugin_addr_len;
/**
* Number of entries in 'ats'.
@@ -105,12 +105,12 @@
/**
* Global ATS handle.
- */
+ */
struct GNUNET_ATS_Handle *atc;
/**
* Which peer are we monitoring?
- */
+ */
struct GNUNET_PeerIdentity target;
};
@@ -169,13 +169,11 @@
* @return GNUNET_YES (continue iteration)
*/
static int
-count_connections (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+count_connections (void *cls, const GNUNET_HashCode * key, void *value)
{
unsigned int *ac = cls;
struct AllocationRecord *ar = value;
-
+
if (GNUNET_YES == ar->connected)
(*ac)++;
return GNUNET_YES;
@@ -208,35 +206,29 @@
* @return GNUNET_YES (continue iteration)
*/
static int
-set_bw_connections (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+set_bw_connections (void *cls, const GNUNET_HashCode * key, void *value)
{
struct SetBandwidthContext *sbc = cls;
struct AllocationRecord *ar = value;
-
+
if (GNUNET_YES == ar->connected)
- {
- ar->bandwidth = sbc->bw;
- sbc->atc->alloc_cb (sbc->atc->alloc_cb_cls,
- (const struct GNUNET_PeerIdentity*) key,
- ar->plugin_name,
- ar->session,
- ar->plugin_addr,
- ar->plugin_addr_len,
- ar->bandwidth);
- }
- else if (ntohl(ar->bandwidth.value__) > 0)
- {
- ar->bandwidth = GNUNET_BANDWIDTH_value_init (0);
- sbc->atc->alloc_cb (sbc->atc->alloc_cb_cls,
- (const struct GNUNET_PeerIdentity*) key,
- ar->plugin_name,
- ar->session,
- ar->plugin_addr,
- ar->plugin_addr_len,
- ar->bandwidth);
- }
+ {
+ ar->bandwidth = sbc->bw;
+ sbc->atc->alloc_cb (sbc->atc->alloc_cb_cls,
+ (const struct GNUNET_PeerIdentity *) key,
+ ar->plugin_name,
+ ar->session,
+ ar->plugin_addr, ar->plugin_addr_len, ar->bandwidth);
+ }
+ else if (ntohl (ar->bandwidth.value__) > 0)
+ {
+ ar->bandwidth = GNUNET_BANDWIDTH_value_init (0);
+ sbc->atc->alloc_cb (sbc->atc->alloc_cb_cls,
+ (const struct GNUNET_PeerIdentity *) key,
+ ar->plugin_name,
+ ar->session,
+ ar->plugin_addr, ar->plugin_addr_len, ar->bandwidth);
+ }
return GNUNET_YES;
}
@@ -246,10 +238,9 @@
*
* @param cls the 'struct GNUNET_ATS_Handle'
* @param tc scheduler context
- */
+ */
static void
-update_bandwidth_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+update_bandwidth_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext
*tc)
{
struct GNUNET_ATS_Handle *atc = cls;
unsigned int ac;
@@ -257,14 +248,10 @@
atc->ba_task = GNUNET_SCHEDULER_NO_TASK;
/* FIXME: update calculations NICELY; what follows is a naive version */
- GNUNET_CONTAINER_multihashmap_iterate (atc->peers,
- &count_connections,
- &ac);
+ GNUNET_CONTAINER_multihashmap_iterate (atc->peers, &count_connections, &ac);
bwc.atc = atc;
bwc.bw = GNUNET_BANDWIDTH_value_init (atc->total_bps / ac);
- GNUNET_CONTAINER_multihashmap_iterate (atc->peers,
- &set_bw_connections,
- &bwc);
+ GNUNET_CONTAINER_multihashmap_iterate (atc->peers, &set_bw_connections,
&bwc);
}
@@ -276,12 +263,11 @@
*/
static void
update_bandwidth_assignment (struct GNUNET_ATS_Handle *atc,
- struct AllocationRecord *change)
+ struct AllocationRecord *change)
{
/* FIXME: based on the 'change', update the LP-problem... */
if (atc->ba_task == GNUNET_SCHEDULER_NO_TASK)
- atc->ba_task = GNUNET_SCHEDULER_add_now (&update_bandwidth_task,
- atc);
+ atc->ba_task = GNUNET_SCHEDULER_add_now (&update_bandwidth_task, atc);
}
@@ -294,21 +280,19 @@
* @return GNUNET_NO if we're done, GNUNET_YES if we did not suggest an
address yet
*/
static int
-suggest_address (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+suggest_address (void *cls, const GNUNET_HashCode * key, void *value)
{
struct GNUNET_ATS_SuggestionContext *asc = cls;
struct AllocationRecord *ar = value;
-
+
/* trivial strategy: pick first available address... */
asc->cb (asc->cb_cls,
- &asc->target,
- ar->plugin_name,
- ar->plugin_addr,
- ar->plugin_addr_len,
- GNUNET_BANDWIDTH_value_init (asc->atc->total_bps / 32),
- ar->ats, ar->ats_count);
+ &asc->target,
+ ar->plugin_name,
+ ar->plugin_addr,
+ ar->plugin_addr_len,
+ GNUNET_BANDWIDTH_value_init (asc->atc->total_bps / 32),
+ ar->ats, ar->ats_count);
asc->cb = NULL;
return GNUNET_NO;
}
@@ -325,9 +309,9 @@
*/
struct GNUNET_ATS_SuggestionContext *
GNUNET_ATS_suggest_address (struct GNUNET_ATS_Handle *atc,
- const struct GNUNET_PeerIdentity *peer,
- GNUNET_ATS_AddressSuggestionCallback cb,
- void *cb_cls)
+ const struct GNUNET_PeerIdentity *peer,
+ GNUNET_ATS_AddressSuggestionCallback cb,
+ void *cb_cls)
{
struct GNUNET_ATS_SuggestionContext *asc;
@@ -338,17 +322,16 @@
asc->target = *peer;
GNUNET_CONTAINER_multihashmap_get_multiple (atc->peers,
&peer->hashPubKey,
- &suggest_address,
- asc);
+ &suggest_address, asc);
if (NULL == asc->cb)
- {
- GNUNET_free (asc);
- return NULL;
- }
+ {
+ GNUNET_free (asc);
+ return NULL;
+ }
GNUNET_CONTAINER_multihashmap_put (atc->notify_map,
- &peer->hashPubKey,
- asc,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
+ &peer->hashPubKey,
+ asc,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
return asc;
}
@@ -362,9 +345,9 @@
GNUNET_ATS_suggest_address_cancel (struct GNUNET_ATS_SuggestionContext *asc)
{
GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_remove (asc->atc->notify_map,
- &asc->target.hashPubKey,
- asc));
+ GNUNET_CONTAINER_multihashmap_remove (asc->atc->notify_map,
+ &asc->target.hashPubKey,
+ asc));
GNUNET_free (asc);
}
@@ -379,8 +362,8 @@
*/
struct GNUNET_ATS_Handle *
GNUNET_ATS_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
- GNUNET_TRANSPORT_ATS_AllocationNotification alloc_cb,
- void *alloc_cb_cls)
+ GNUNET_TRANSPORT_ATS_AllocationNotification alloc_cb,
+ void *alloc_cb_cls)
{
struct GNUNET_ATS_Handle *atc;
@@ -390,9 +373,8 @@
atc->alloc_cb_cls = alloc_cb_cls;
atc->peers = GNUNET_CONTAINER_multihashmap_create (256);
GNUNET_CONFIGURATION_get_value_number (cfg,
- "core",
- "TOTAL_QUOTA_OUT",
- &atc->total_bps);
+ "core",
+ "TOTAL_QUOTA_OUT", &atc->total_bps);
return atc;
}
@@ -406,9 +388,7 @@
* @return GNUNET_OK (continue to iterate)
*/
static int
-destroy_allocation_record (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+destroy_allocation_record (void *cls, const GNUNET_HashCode * key, void *value)
{
struct AllocationRecord *ar = value;
@@ -428,13 +408,12 @@
GNUNET_ATS_shutdown (struct GNUNET_ATS_Handle *atc)
{
if (GNUNET_SCHEDULER_NO_TASK != atc->ba_task)
- {
- GNUNET_SCHEDULER_cancel (atc->ba_task);
- atc->ba_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (atc->ba_task);
+ atc->ba_task = GNUNET_SCHEDULER_NO_TASK;
+ }
GNUNET_CONTAINER_multihashmap_iterate (atc->peers,
- &destroy_allocation_record,
- NULL);
+ &destroy_allocation_record, NULL);
GNUNET_CONTAINER_multihashmap_destroy (atc->peers);
GNUNET_assert (GNUNET_CONTAINER_multihashmap_size (atc->notify_map) == 0);
GNUNET_CONTAINER_multihashmap_destroy (atc->notify_map);
@@ -470,9 +449,7 @@
* GNUNET_NO if the record do match and 'old' was updated
*/
static int
-update_session (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+update_session (void *cls, const GNUNET_HashCode * key, void *value)
{
struct UpdateSessionContext *usc = cls;
struct AllocationRecord *arnew = usc->arnew;
@@ -481,32 +458,30 @@
if (0 != strcmp (arnew->plugin_name, arold->plugin_name))
return GNUNET_YES;
- if ( (arnew->session == arold->session) ||
- ( (arold->session == NULL) &&
- (arold->plugin_addr_len == arnew->plugin_addr_len) &&
- (0 == memcmp (arold->plugin_addr,
- arnew->plugin_addr,
- arnew->plugin_addr_len)) ) )
+ if ((arnew->session == arold->session) ||
+ ((arold->session == NULL) &&
+ (arold->plugin_addr_len == arnew->plugin_addr_len) &&
+ (0 == memcmp (arold->plugin_addr,
+ arnew->plugin_addr, arnew->plugin_addr_len))))
+ {
+ change = GNUNET_NO;
+ /* records match */
+ if (arnew->session != arold->session)
{
- change = GNUNET_NO;
- /* records match */
- if (arnew->session != arold->session)
- {
- arold->session = arnew->session;
- change = GNUNET_YES;
- }
- if ( (arnew->connected == GNUNET_YES) &&
- (arold->connected == GNUNET_NO) )
- {
- arold->connected = GNUNET_YES;
- change = GNUNET_YES;
- }
- // FIXME: merge ats arrays of (arold, arnew);
-
- if (GNUNET_YES == change)
- update_bandwidth_assignment (usc->atc, arold);
- return GNUNET_NO;
+ arold->session = arnew->session;
+ change = GNUNET_YES;
}
+ if ((arnew->connected == GNUNET_YES) && (arold->connected == GNUNET_NO))
+ {
+ arold->connected = GNUNET_YES;
+ change = GNUNET_YES;
+ }
+ // FIXME: merge ats arrays of (arold, arnew);
+
+ if (GNUNET_YES == change)
+ update_bandwidth_assignment (usc->atc, arold);
+ return GNUNET_NO;
+ }
return GNUNET_YES;
}
@@ -523,11 +498,11 @@
*/
static struct AllocationRecord *
create_allocation_record (const char *plugin_name,
- struct Session *session,
- const void *plugin_addr,
- size_t plugin_addr_len,
- const struct GNUNET_TRANSPORT_ATS_Information *ats,
- uint32_t ats_count)
+ struct Session *session,
+ const void *plugin_addr,
+ size_t plugin_addr_len,
+ const struct GNUNET_TRANSPORT_ATS_Information *ats,
+ uint32_t ats_count)
{
struct AllocationRecord *ar;
@@ -537,12 +512,9 @@
memcpy (&ar[1], plugin_addr, plugin_addr_len);
ar->session = session;
ar->plugin_addr_len = plugin_addr_len;
- GNUNET_array_grow (ar->ats,
- ar->ats_count,
- ats_count);
- memcpy (ar->ats,
- ats,
- ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
+ GNUNET_array_grow (ar->ats, ar->ats_count, ats_count);
+ memcpy (ar->ats,
+ ats, ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
return ar;
}
@@ -556,18 +528,16 @@
* @return GNUNET_OK (continue to iterate)
*/
static int
-disconnect_peer (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+disconnect_peer (void *cls, const GNUNET_HashCode * key, void *value)
{
struct GNUNET_ATS_Handle *atc = cls;
struct AllocationRecord *ar = value;
if (GNUNET_YES == ar->connected)
- {
- ar->connected = GNUNET_NO;
- update_bandwidth_assignment (atc, ar);
- }
+ {
+ ar->connected = GNUNET_NO;
+ update_bandwidth_assignment (atc, ar);
+ }
return GNUNET_OK;
}
@@ -588,42 +558,36 @@
*/
void
GNUNET_ATS_peer_connect (struct GNUNET_ATS_Handle *atc,
- const struct GNUNET_PeerIdentity *peer,
- const char *plugin_name,
- struct Session *session,
- const void *plugin_addr,
- size_t plugin_addr_len,
- const struct GNUNET_TRANSPORT_ATS_Information *ats,
- uint32_t ats_count)
+ const struct GNUNET_PeerIdentity *peer,
+ const char *plugin_name,
+ struct Session *session,
+ const void *plugin_addr,
+ size_t plugin_addr_len,
+ const struct GNUNET_TRANSPORT_ATS_Information *ats,
+ uint32_t ats_count)
{
struct AllocationRecord *ar;
struct UpdateSessionContext usc;
(void) GNUNET_CONTAINER_multihashmap_iterate (atc->peers,
- &disconnect_peer,
- atc);
+ &disconnect_peer, atc);
ar = create_allocation_record (plugin_name,
- session,
- plugin_addr,
- plugin_addr_len,
- ats,
- ats_count);
+ session,
+ plugin_addr, plugin_addr_len, ats, ats_count);
ar->connected = GNUNET_YES;
usc.atc = atc;
usc.arnew = ar;
if (GNUNET_SYSERR ==
- GNUNET_CONTAINER_multihashmap_iterate (atc->peers,
- &update_session,
- &usc))
- {
- destroy_allocation_record (NULL, &peer->hashPubKey, ar);
- return;
- }
+ GNUNET_CONTAINER_multihashmap_iterate (atc->peers, &update_session,
&usc))
+ {
+ destroy_allocation_record (NULL, &peer->hashPubKey, ar);
+ return;
+ }
GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_put (atc->peers,
- &peer->hashPubKey,
- ar,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
+ GNUNET_CONTAINER_multihashmap_put (atc->peers,
+ &peer->hashPubKey,
+ ar,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
}
@@ -637,12 +601,11 @@
*/
void
GNUNET_ATS_peer_disconnect (struct GNUNET_ATS_Handle *atc,
- const struct GNUNET_PeerIdentity *peer)
+ const struct GNUNET_PeerIdentity *peer)
{
(void) GNUNET_CONTAINER_multihashmap_get_multiple (atc->peers,
- &peer->hashPubKey,
- &disconnect_peer,
- atc);
+ &peer->hashPubKey,
+ &disconnect_peer, atc);
}
@@ -672,9 +635,7 @@
* @return GNUNET_OK (continue to iterate)
*/
static int
-destroy_session (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+destroy_session (void *cls, const GNUNET_HashCode * key, void *value)
{
struct SessionDestroyContext *sdc = cls;
struct AllocationRecord *ar = value;
@@ -685,14 +646,13 @@
if (ar->plugin_addr != NULL)
return GNUNET_OK;
GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_remove (sdc->atc->peers,
- key,
- ar));
- if (GNUNET_YES == ar->connected);
- {
- /* FIXME: is this supposed to be allowed? What to do then? */
- GNUNET_break (0);
- }
+ GNUNET_CONTAINER_multihashmap_remove (sdc->atc->peers,
+ key, ar));
+ if (GNUNET_YES == ar->connected) ;
+ {
+ /* FIXME: is this supposed to be allowed? What to do then? */
+ GNUNET_break (0);
+ }
destroy_allocation_record (NULL, key, ar);
return GNUNET_OK;
}
@@ -707,16 +667,15 @@
*/
void
GNUNET_ATS_session_destroyed (struct GNUNET_ATS_Handle *atc,
- const struct GNUNET_PeerIdentity *peer,
- const struct Session *session)
+ const struct GNUNET_PeerIdentity *peer,
+ const struct Session *session)
{
struct SessionDestroyContext sdc;
sdc.atc = atc;
sdc.session = session;
(void) GNUNET_CONTAINER_multihashmap_iterate (atc->peers,
- &destroy_session,
- &sdc);
+ &destroy_session, &sdc);
}
@@ -729,20 +688,18 @@
* @return GNUNET_YES (continue to iterate)
*/
static int
-notify_valid (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+notify_valid (void *cls, const GNUNET_HashCode * key, void *value)
{
struct AllocationRecord *ar = cls;
struct GNUNET_ATS_SuggestionContext *asc = value;
asc->cb (asc->cb_cls,
- &asc->target,
- ar->plugin_name,
- ar->plugin_addr,
- ar->plugin_addr_len,
- GNUNET_BANDWIDTH_value_init (asc->atc->total_bps / 32),
- ar->ats, ar->ats_count);
+ &asc->target,
+ ar->plugin_name,
+ ar->plugin_addr,
+ ar->plugin_addr_len,
+ GNUNET_BANDWIDTH_value_init (asc->atc->total_bps / 32),
+ ar->ats, ar->ats_count);
GNUNET_ATS_suggest_address_cancel (asc);
return GNUNET_OK;
}
@@ -768,43 +725,37 @@
*/
void
GNUNET_ATS_address_update (struct GNUNET_ATS_Handle *atc,
- const struct GNUNET_PeerIdentity *peer,
- struct GNUNET_TIME_Absolute valid_until,
- const char *plugin_name,
- struct Session *session,
- const void *plugin_addr,
- size_t plugin_addr_len,
- const struct GNUNET_TRANSPORT_ATS_Information *ats,
- uint32_t ats_count)
+ const struct GNUNET_PeerIdentity *peer,
+ struct GNUNET_TIME_Absolute valid_until,
+ const char *plugin_name,
+ struct Session *session,
+ const void *plugin_addr,
+ size_t plugin_addr_len,
+ const struct GNUNET_TRANSPORT_ATS_Information *ats,
+ uint32_t ats_count)
{
struct AllocationRecord *ar;
struct UpdateSessionContext usc;
- ar = create_allocation_record (plugin_name,
- session,
- plugin_addr,
- plugin_addr_len,
- ats,
- ats_count);
+ ar = create_allocation_record (plugin_name,
+ session,
+ plugin_addr, plugin_addr_len, ats, ats_count);
usc.atc = atc;
- usc.arnew = ar;
+ usc.arnew = ar;
if (GNUNET_SYSERR ==
- GNUNET_CONTAINER_multihashmap_iterate (atc->peers,
- &update_session,
- &usc))
- {
- destroy_allocation_record (NULL, &peer->hashPubKey, ar);
- return;
- }
+ GNUNET_CONTAINER_multihashmap_iterate (atc->peers, &update_session,
&usc))
+ {
+ destroy_allocation_record (NULL, &peer->hashPubKey, ar);
+ return;
+ }
GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_put (atc->peers,
- &peer->hashPubKey,
- ar,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
+ GNUNET_CONTAINER_multihashmap_put (atc->peers,
+ &peer->hashPubKey,
+ ar,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
GNUNET_CONTAINER_multihashmap_get_multiple (atc->notify_map,
- &peer->hashPubKey,
- ¬ify_valid,
- ar);
+ &peer->hashPubKey,
+ ¬ify_valid, ar);
}
/* end of file gnunet-service-transport_ats.c */
Modified: gnunet/src/block/block.c
===================================================================
--- gnunet/src/block/block.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/block/block.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -37,9 +37,9 @@
{
/**
* Name of the shared library.
- */
+ */
char *library_name;
-
+
/**
* Plugin API.
*/
@@ -59,7 +59,7 @@
/**
* Our configuration.
- */
+ */
const struct GNUNET_CONFIGURATION_Handle *cfg;
};
@@ -73,14 +73,11 @@
*/
void
GNUNET_BLOCK_mingle_hash (const GNUNET_HashCode * in,
- uint32_t mingle_number,
- GNUNET_HashCode * hc)
+ uint32_t mingle_number, GNUNET_HashCode * hc)
{
GNUNET_HashCode m;
- GNUNET_CRYPTO_hash (&mingle_number,
- sizeof (uint32_t),
- &m);
+ GNUNET_CRYPTO_hash (&mingle_number, sizeof (uint32_t), &m);
GNUNET_CRYPTO_hash_xor (&m, in, hc);
}
@@ -106,39 +103,33 @@
ctx->cfg = cfg;
num_plugins = 0;
if (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "block", "PLUGINS", &plugs))
+ GNUNET_CONFIGURATION_get_value_string (cfg, "block", "PLUGINS", &plugs))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Loading block plugins `%s'\n"), plugs);
+ pos = strtok (plugs, " ");
+ while (pos != NULL)
{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Loading block plugins `%s'\n"), plugs);
- pos = strtok (plugs, " ");
- while (pos != NULL)
- {
- GNUNET_asprintf (&libname, "libgnunet_plugin_block_%s", pos);
- api = GNUNET_PLUGIN_load (libname, NULL);
- if (api == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to load block plugin `%s'\n"),
- pos);
- GNUNET_free (libname);
- }
- else
- {
- plugin = GNUNET_malloc (sizeof (struct Plugin));
- plugin->api = api;
- plugin->library_name = libname;
- GNUNET_array_append (ctx->plugins,
- num_plugins,
- plugin);
- }
- pos = strtok (NULL, " ");
- }
- GNUNET_free (plugs);
+ GNUNET_asprintf (&libname, "libgnunet_plugin_block_%s", pos);
+ api = GNUNET_PLUGIN_load (libname, NULL);
+ if (api == NULL)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to load block plugin `%s'\n"), pos);
+ GNUNET_free (libname);
+ }
+ else
+ {
+ plugin = GNUNET_malloc (sizeof (struct Plugin));
+ plugin->api = api;
+ plugin->library_name = libname;
+ GNUNET_array_append (ctx->plugins, num_plugins, plugin);
+ }
+ pos = strtok (NULL, " ");
}
- GNUNET_array_append (ctx->plugins,
- num_plugins,
- NULL);
+ GNUNET_free (plugs);
+ }
+ GNUNET_array_append (ctx->plugins, num_plugins, NULL);
return ctx;
}
@@ -156,14 +147,13 @@
i = 0;
while (NULL != (plugin = ctx->plugins[i]))
- {
- GNUNET_break (NULL ==
- GNUNET_PLUGIN_unload (plugin->library_name,
- plugin->api));
- GNUNET_free (plugin->library_name);
- GNUNET_free (plugin);
- i++;
- }
+ {
+ GNUNET_break (NULL ==
+ GNUNET_PLUGIN_unload (plugin->library_name, plugin->api));
+ GNUNET_free (plugin->library_name);
+ GNUNET_free (plugin);
+ i++;
+ }
GNUNET_free (ctx->plugins);
GNUNET_free (ctx);
}
@@ -177,8 +167,7 @@
* @return NULL if no matching plugin exists
*/
static struct GNUNET_BLOCK_PluginFunctions *
-find_plugin (struct GNUNET_BLOCK_Context *ctx,
- enum GNUNET_BLOCK_Type type)
+find_plugin (struct GNUNET_BLOCK_Context *ctx, enum GNUNET_BLOCK_Type type)
{
struct Plugin *plugin;
unsigned int i;
@@ -186,16 +175,16 @@
i = 0;
while (NULL != (plugin = ctx->plugins[i]))
+ {
+ j = 0;
+ while (0 != (plugin->api->types[j]))
{
- j = 0;
- while (0 != (plugin->api->types[j]))
- {
- if (type == plugin->api->types[j])
- return plugin->api;
- j++;
- }
- i++;
+ if (type == plugin->api->types[j])
+ return plugin->api;
+ j++;
}
+ i++;
+ }
return NULL;
}
@@ -220,22 +209,21 @@
*/
enum GNUNET_BLOCK_EvaluationResult
GNUNET_BLOCK_evaluate (struct GNUNET_BLOCK_Context *ctx,
- enum GNUNET_BLOCK_Type type,
- const GNUNET_HashCode *query,
- struct GNUNET_CONTAINER_BloomFilter **bf,
- int32_t bf_mutator,
- const void *xquery,
- size_t xquery_size,
- const void *reply_block,
- size_t reply_block_size)
+ enum GNUNET_BLOCK_Type type,
+ const GNUNET_HashCode * query,
+ struct GNUNET_CONTAINER_BloomFilter **bf,
+ int32_t bf_mutator,
+ const void *xquery,
+ size_t xquery_size,
+ const void *reply_block, size_t reply_block_size)
{
struct GNUNET_BLOCK_PluginFunctions *plugin = find_plugin (ctx, type);
if (plugin == NULL)
return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
return plugin->evaluate (plugin->cls,
- type, query, bf, bf_mutator,
- xquery, xquery_size, reply_block, reply_block_size);
+ type, query, bf, bf_mutator,
+ xquery, xquery_size, reply_block, reply_block_size);
}
@@ -252,17 +240,15 @@
*/
int
GNUNET_BLOCK_get_key (struct GNUNET_BLOCK_Context *ctx,
- enum GNUNET_BLOCK_Type type,
- const void *block,
- size_t block_size,
- GNUNET_HashCode *key)
+ enum GNUNET_BLOCK_Type type,
+ const void *block,
+ size_t block_size, GNUNET_HashCode * key)
{
struct GNUNET_BLOCK_PluginFunctions *plugin = find_plugin (ctx, type);
if (plugin == NULL)
return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
- return plugin->get_key (plugin->cls,
- type, block, block_size, key);
+ return plugin->get_key (plugin->cls, type, block, block_size, key);
}
Modified: gnunet/src/block/plugin_block_dht.c
===================================================================
--- gnunet/src/block/plugin_block_dht.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/block/plugin_block_dht.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -50,14 +50,13 @@
*/
static enum GNUNET_BLOCK_EvaluationResult
block_plugin_dht_evaluate (void *cls,
- enum GNUNET_BLOCK_Type type,
- const GNUNET_HashCode *query,
- struct GNUNET_CONTAINER_BloomFilter **bf,
- int32_t bf_mutator,
- const void *xquery,
- size_t xquery_size,
- const void *reply_block,
- size_t reply_block_size)
+ enum GNUNET_BLOCK_Type type,
+ const GNUNET_HashCode * query,
+ struct GNUNET_CONTAINER_BloomFilter **bf,
+ int32_t bf_mutator,
+ const void *xquery,
+ size_t xquery_size,
+ const void *reply_block, size_t reply_block_size)
{
switch (type)
{
@@ -67,7 +66,7 @@
if (reply_block_size == 0)
return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
GNUNET_break (NULL == *bf);
- return GNUNET_BLOCK_EVALUATION_OK_LAST;
+ return GNUNET_BLOCK_EVALUATION_OK_LAST;
default:
return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
}
@@ -87,10 +86,9 @@
*/
static int
block_plugin_dht_get_key (void *cls,
- enum GNUNET_BLOCK_Type type,
- const void *block,
- size_t block_size,
- GNUNET_HashCode *key)
+ enum GNUNET_BLOCK_Type type,
+ const void *block,
+ size_t block_size, GNUNET_HashCode * key)
{
const struct GNUNET_MessageHeader *msg;
const struct GNUNET_HELLO_Message *hello;
@@ -99,49 +97,46 @@
if (type != GNUNET_BLOCK_TYPE_DHT_HELLO)
return GNUNET_SYSERR;
if (block_size < sizeof (struct GNUNET_MessageHeader))
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
- "block-dht",
- _("Block not of type %u\n"),
- GNUNET_BLOCK_TYPE_DHT_HELLO);
- return GNUNET_NO;
- }
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
+ "block-dht",
+ _("Block not of type %u\n"), GNUNET_BLOCK_TYPE_DHT_HELLO);
+ return GNUNET_NO;
+ }
msg = block;
if (block_size != ntohs (msg->size))
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
- "block-dht",
- _("Size mismatch for block\n"),
- GNUNET_BLOCK_TYPE_DHT_HELLO);
- return GNUNET_NO;
- }
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
+ "block-dht",
+ _("Size mismatch for block\n"),
+ GNUNET_BLOCK_TYPE_DHT_HELLO);
+ return GNUNET_NO;
+ }
hello = block;
- pid = (struct GNUNET_PeerIdentity*) key;
- if (GNUNET_OK !=
- GNUNET_HELLO_get_id (hello,
- pid))
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
- "block-dht",
- _("Block of type %u is malformed\n"),
- GNUNET_BLOCK_TYPE_DHT_HELLO);
- return GNUNET_NO;
- }
+ pid = (struct GNUNET_PeerIdentity *) key;
+ if (GNUNET_OK != GNUNET_HELLO_get_id (hello, pid))
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
+ "block-dht",
+ _("Block of type %u is malformed\n"),
+ GNUNET_BLOCK_TYPE_DHT_HELLO);
+ return GNUNET_NO;
+ }
return GNUNET_OK;
}
-
+
/**
* Entry point for the plugin.
*/
void *
libgnunet_plugin_block_dht_init (void *cls)
{
- static enum GNUNET_BLOCK_Type types[] =
- {
- GNUNET_BLOCK_TYPE_DHT_HELLO,
- GNUNET_BLOCK_TYPE_ANY /* end of list */
- };
+ static enum GNUNET_BLOCK_Type types[] =
+ {
+ GNUNET_BLOCK_TYPE_DHT_HELLO,
+ GNUNET_BLOCK_TYPE_ANY /* end of list */
+ };
struct GNUNET_BLOCK_PluginFunctions *api;
api = GNUNET_malloc (sizeof (struct GNUNET_BLOCK_PluginFunctions));
Modified: gnunet/src/block/plugin_block_dns.c
===================================================================
--- gnunet/src/block/plugin_block_dns.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/block/plugin_block_dns.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -48,14 +48,13 @@
*/
static enum GNUNET_BLOCK_EvaluationResult
block_plugin_dns_evaluate (void *cls,
- enum GNUNET_BLOCK_Type type,
- const GNUNET_HashCode *query,
- struct GNUNET_CONTAINER_BloomFilter **bf,
- int32_t bf_mutator,
- const void *xquery,
- size_t xquery_size,
- const void *reply_block,
- size_t reply_block_size)
+ enum GNUNET_BLOCK_Type type,
+ const GNUNET_HashCode * query,
+ struct GNUNET_CONTAINER_BloomFilter **bf,
+ int32_t bf_mutator,
+ const void *xquery,
+ size_t xquery_size,
+ const void *reply_block, size_t reply_block_size)
{
switch (type)
{
@@ -66,37 +65,43 @@
if (reply_block_size == 0)
return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
- if (reply_block_size != sizeof(struct GNUNET_DNS_Record))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DNS-Block is invalid:
reply_block_size=%d != %d\n", reply_block_size, sizeof(struct
GNUNET_DNS_Record));
- return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
- }
+ if (reply_block_size != sizeof (struct GNUNET_DNS_Record))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "DNS-Block is invalid: reply_block_size=%d != %d\n",
+ reply_block_size, sizeof (struct GNUNET_DNS_Record));
+ return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
+ }
- const struct GNUNET_DNS_Record* rec = reply_block;
+ const struct GNUNET_DNS_Record *rec = reply_block;
- if (ntohl(rec->purpose.size) != sizeof(struct GNUNET_DNS_Record) -
sizeof(struct GNUNET_CRYPTO_RsaSignature))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "DNS-Block is invalid: rec->purpose.size=%d != %d\n",
- ntohl(rec->purpose.size),
- sizeof(struct GNUNET_DNS_Record) - sizeof(struct
GNUNET_CRYPTO_RsaSignature));
- return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
- }
+ if (ntohl (rec->purpose.size) !=
+ sizeof (struct GNUNET_DNS_Record) -
+ sizeof (struct GNUNET_CRYPTO_RsaSignature))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "DNS-Block is invalid: rec->purpose.size=%d != %d\n",
+ ntohl (rec->purpose.size),
+ sizeof (struct GNUNET_DNS_Record) -
+ sizeof (struct GNUNET_CRYPTO_RsaSignature));
+ return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
+ }
- if (GNUNET_TIME_relative_get_zero().rel_value ==
GNUNET_TIME_absolute_get_remaining(rec->expiration_time).rel_value)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DNS-Block is invalid: Timeout\n");
- return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
- }
+ if (GNUNET_TIME_relative_get_zero ().rel_value ==
+ GNUNET_TIME_absolute_get_remaining (rec->expiration_time).rel_value)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "DNS-Block is invalid: Timeout\n");
+ return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
+ }
- if (GNUNET_OK != GNUNET_CRYPTO_rsa_verify
(htonl(GNUNET_SIGNATURE_PURPOSE_DNS_RECORD),
- &rec->purpose,
- &rec->signature,
- &rec->peer))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DNS-Block is invalid: invalid
signature\n");
- return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
- }
+ if (GNUNET_OK !=
+ GNUNET_CRYPTO_rsa_verify (htonl (GNUNET_SIGNATURE_PURPOSE_DNS_RECORD),
+ &rec->purpose, &rec->signature, &rec->peer))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "DNS-Block is invalid: invalid signature\n");
+ return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
+ }
/* How to decide whether there are no more? */
return GNUNET_BLOCK_EVALUATION_OK_MORE;
@@ -119,15 +124,15 @@
*/
static int
block_plugin_dns_get_key (void *cls,
- enum GNUNET_BLOCK_Type type,
- const void *block,
- size_t block_size,
- GNUNET_HashCode *key)
+ enum GNUNET_BLOCK_Type type,
+ const void *block,
+ size_t block_size, GNUNET_HashCode * key)
{
if (type != GNUNET_BLOCK_TYPE_DNS)
return GNUNET_SYSERR;
- const struct GNUNET_DNS_Record* rec = block;
- memcpy(key, &rec->service_descriptor, sizeof(GNUNET_HashCode));
+ const struct GNUNET_DNS_Record *rec = block;
+
+ memcpy (key, &rec->service_descriptor, sizeof (GNUNET_HashCode));
return GNUNET_OK;
}
@@ -137,11 +142,11 @@
void *
libgnunet_plugin_block_dns_init (void *cls)
{
- static enum GNUNET_BLOCK_Type types[] =
- {
- GNUNET_BLOCK_TYPE_DNS,
- GNUNET_BLOCK_TYPE_ANY /* end of list */
- };
+ static enum GNUNET_BLOCK_Type types[] =
+ {
+ GNUNET_BLOCK_TYPE_DNS,
+ GNUNET_BLOCK_TYPE_ANY /* end of list */
+ };
struct GNUNET_BLOCK_PluginFunctions *api;
api = GNUNET_malloc (sizeof (struct GNUNET_BLOCK_PluginFunctions));
Modified: gnunet/src/block/plugin_block_fs.c
===================================================================
--- gnunet/src/block/plugin_block_fs.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/block/plugin_block_fs.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -57,14 +57,13 @@
*/
static enum GNUNET_BLOCK_EvaluationResult
block_plugin_fs_evaluate (void *cls,
- enum GNUNET_BLOCK_Type type,
- const GNUNET_HashCode *query,
- struct GNUNET_CONTAINER_BloomFilter **bf,
- int32_t bf_mutator,
- const void *xquery,
- size_t xquery_size,
- const void *reply_block,
- size_t reply_block_size)
+ enum GNUNET_BLOCK_Type type,
+ const GNUNET_HashCode * query,
+ struct GNUNET_CONTAINER_BloomFilter **bf,
+ int32_t bf_mutator,
+ const void *xquery,
+ size_t xquery_size,
+ const void *reply_block, size_t reply_block_size)
{
const struct SBlock *sb;
GNUNET_HashCode chash;
@@ -73,92 +72,81 @@
GNUNET_HashCode sh;
switch (type)
+ {
+ case GNUNET_BLOCK_TYPE_FS_DBLOCK:
+ case GNUNET_BLOCK_TYPE_FS_IBLOCK:
+ if (xquery_size != 0)
{
- case GNUNET_BLOCK_TYPE_FS_DBLOCK:
- case GNUNET_BLOCK_TYPE_FS_IBLOCK:
- if (xquery_size != 0)
- {
- GNUNET_break_op (0);
- return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
- }
- if (reply_block == NULL)
- return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
- return GNUNET_BLOCK_EVALUATION_OK_LAST;
- case GNUNET_BLOCK_TYPE_FS_KBLOCK:
- case GNUNET_BLOCK_TYPE_FS_NBLOCK:
- if (xquery_size != 0)
- {
- GNUNET_break_op (0);
- return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
- }
- if (reply_block == NULL)
- return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
- 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);
- return GNUNET_BLOCK_EVALUATION_OK_MORE;
- case GNUNET_BLOCK_TYPE_FS_SBLOCK:
- if (xquery_size != sizeof (GNUNET_HashCode))
- {
- GNUNET_break_op (0);
- return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
- }
- if (reply_block == NULL)
- return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
- nsid = xquery;
- if (reply_block_size < sizeof (struct SBlock))
- {
- GNUNET_break_op (0);
- return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
- }
- sb = reply_block;
- GNUNET_CRYPTO_hash (&sb->subspace,
- sizeof (struct
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
- &sh);
- if (0 != memcmp (nsid,
- &sh,
- sizeof (GNUNET_HashCode)))
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
- "block-fs",
- _("Reply mismatched in terms of namespace.
Discarded.\n"));
- return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
- }
- 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);
- return GNUNET_BLOCK_EVALUATION_OK_MORE;
- default:
- return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
+ GNUNET_break_op (0);
+ return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
}
+ if (reply_block == NULL)
+ return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
+ return GNUNET_BLOCK_EVALUATION_OK_LAST;
+ case GNUNET_BLOCK_TYPE_FS_KBLOCK:
+ case GNUNET_BLOCK_TYPE_FS_NBLOCK:
+ if (xquery_size != 0)
+ {
+ GNUNET_break_op (0);
+ return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
+ }
+ if (reply_block == NULL)
+ return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
+ 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);
+ return GNUNET_BLOCK_EVALUATION_OK_MORE;
+ case GNUNET_BLOCK_TYPE_FS_SBLOCK:
+ if (xquery_size != sizeof (GNUNET_HashCode))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
+ }
+ if (reply_block == NULL)
+ return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
+ nsid = xquery;
+ if (reply_block_size < sizeof (struct SBlock))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
+ }
+ sb = reply_block;
+ GNUNET_CRYPTO_hash (&sb->subspace,
+ sizeof (struct
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+ &sh);
+ if (0 != memcmp (nsid, &sh, sizeof (GNUNET_HashCode)))
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
+ "block-fs",
+ _
+ ("Reply mismatched in terms of namespace.
Discarded.\n"));
+ return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
+ }
+ 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);
+ return GNUNET_BLOCK_EVALUATION_OK_MORE;
+ default:
+ return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
+ }
}
@@ -175,142 +163,138 @@
*/
static int
block_plugin_fs_get_key (void *cls,
- enum GNUNET_BLOCK_Type type,
- const void *block,
- size_t block_size,
- GNUNET_HashCode *key)
+ enum GNUNET_BLOCK_Type type,
+ const void *block,
+ size_t block_size, GNUNET_HashCode * key)
{
const struct KBlock *kb;
const struct SBlock *sb;
const struct NBlock *nb;
switch (type)
+ {
+ case GNUNET_BLOCK_TYPE_FS_DBLOCK:
+ case GNUNET_BLOCK_TYPE_FS_IBLOCK:
+ GNUNET_CRYPTO_hash (block, block_size, key);
+ return GNUNET_OK;
+ case GNUNET_BLOCK_TYPE_FS_KBLOCK:
+ if (block_size < sizeof (struct KBlock))
{
- case GNUNET_BLOCK_TYPE_FS_DBLOCK:
- case GNUNET_BLOCK_TYPE_FS_IBLOCK:
- GNUNET_CRYPTO_hash (block, block_size, key);
- return GNUNET_OK;
- case GNUNET_BLOCK_TYPE_FS_KBLOCK:
- if (block_size < sizeof (struct KBlock))
- {
- GNUNET_break_op (0);
- return GNUNET_NO;
- }
- kb = block;
- if (block_size - sizeof (struct KBlock) !=
- ntohl (kb->purpose.size)
- - sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose)
- - sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) )
- {
- GNUNET_break_op (0);
- return GNUNET_NO;
- }
- if (GNUNET_OK !=
- GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_KBLOCK,
- &kb->purpose,
- &kb->signature,
- &kb->keyspace))
- {
- GNUNET_break_op (0);
- return GNUNET_NO;
- }
- if (key != NULL)
- GNUNET_CRYPTO_hash (&kb->keyspace,
- sizeof (struct
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
- key);
- return GNUNET_OK;
- case GNUNET_BLOCK_TYPE_FS_SBLOCK:
- if (block_size < sizeof (struct SBlock))
- {
- GNUNET_break_op (0);
- return GNUNET_NO;
- }
- sb = block;
- if (block_size !=
- ntohl (sb->purpose.size) + sizeof (struct GNUNET_CRYPTO_RsaSignature))
- {
- GNUNET_break_op (0);
- return GNUNET_NO;
- }
- if (GNUNET_OK !=
- GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_SBLOCK,
- &sb->purpose,
- &sb->signature,
- &sb->subspace))
- {
- GNUNET_break_op (0);
- return GNUNET_NO;
- }
- if (key != NULL)
- *key = sb->identifier;
- return GNUNET_OK;
- case GNUNET_BLOCK_TYPE_FS_NBLOCK:
- if (block_size < sizeof (struct NBlock))
- {
- GNUNET_break_op (0);
- return GNUNET_NO;
- }
- nb = block;
- if (block_size - sizeof (struct NBlock) !=
- ntohl (nb->ns_purpose.size)
- - sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose)
- - sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) )
- {
- GNUNET_break_op (0);
- return GNUNET_NO;
- }
- if (block_size !=
- ntohl (nb->ksk_purpose.size) + sizeof (struct
GNUNET_CRYPTO_RsaSignature))
- {
- GNUNET_break_op (0);
- return GNUNET_NO;
- }
- if (GNUNET_OK !=
- GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK_KSIG,
- &nb->ksk_purpose,
- &nb->ksk_signature,
- &nb->keyspace))
- {
- GNUNET_break_op (0);
- return GNUNET_NO;
- }
- if (GNUNET_OK !=
- GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK,
- &nb->ns_purpose,
- &nb->ns_signature,
- &nb->subspace))
- {
- GNUNET_break_op (0);
- return GNUNET_NO;
- }
- /* FIXME: we used to xor ID with NSID,
- why not here? */
- if (key != NULL)
- GNUNET_CRYPTO_hash (&nb->keyspace,
- sizeof (struct
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
- key);
- return GNUNET_OK;
- default:
- return GNUNET_SYSERR;
+ GNUNET_break_op (0);
+ return GNUNET_NO;
}
+ kb = block;
+ if (block_size - sizeof (struct KBlock) !=
+ ntohl (kb->purpose.size)
+ - sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose)
+ - sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_NO;
+ }
+ if (GNUNET_OK !=
+ GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_KBLOCK,
+ &kb->purpose, &kb->signature, &kb->keyspace))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_NO;
+ }
+ if (key != NULL)
+ GNUNET_CRYPTO_hash (&kb->keyspace,
+ sizeof (struct
+ GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+ key);
+ return GNUNET_OK;
+ case GNUNET_BLOCK_TYPE_FS_SBLOCK:
+ if (block_size < sizeof (struct SBlock))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_NO;
+ }
+ sb = block;
+ if (block_size !=
+ ntohl (sb->purpose.size) + sizeof (struct GNUNET_CRYPTO_RsaSignature))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_NO;
+ }
+ if (GNUNET_OK !=
+ GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_SBLOCK,
+ &sb->purpose, &sb->signature, &sb->subspace))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_NO;
+ }
+ if (key != NULL)
+ *key = sb->identifier;
+ return GNUNET_OK;
+ case GNUNET_BLOCK_TYPE_FS_NBLOCK:
+ if (block_size < sizeof (struct NBlock))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_NO;
+ }
+ nb = block;
+ if (block_size - sizeof (struct NBlock) !=
+ ntohl (nb->ns_purpose.size)
+ - sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose)
+ - sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_NO;
+ }
+ if (block_size !=
+ ntohl (nb->ksk_purpose.size) +
+ sizeof (struct GNUNET_CRYPTO_RsaSignature))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_NO;
+ }
+ if (GNUNET_OK !=
+ GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK_KSIG,
+ &nb->ksk_purpose,
+ &nb->ksk_signature, &nb->keyspace))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_NO;
+ }
+ if (GNUNET_OK !=
+ GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK,
+ &nb->ns_purpose,
+ &nb->ns_signature, &nb->subspace))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_NO;
+ }
+ /* FIXME: we used to xor ID with NSID,
+ * why not here? */
+ if (key != NULL)
+ GNUNET_CRYPTO_hash (&nb->keyspace,
+ sizeof (struct
+ GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+ key);
+ return GNUNET_OK;
+ default:
+ return GNUNET_SYSERR;
+ }
}
-
+
/**
* Entry point for the plugin.
*/
void *
libgnunet_plugin_block_fs_init (void *cls)
{
- static enum GNUNET_BLOCK_Type types[] =
- {
- GNUNET_BLOCK_TYPE_FS_DBLOCK,
- GNUNET_BLOCK_TYPE_FS_IBLOCK,
- GNUNET_BLOCK_TYPE_FS_KBLOCK,
- GNUNET_BLOCK_TYPE_FS_SBLOCK,
- GNUNET_BLOCK_TYPE_FS_NBLOCK,
- GNUNET_BLOCK_TYPE_ANY /* end of list */
- };
+ static enum GNUNET_BLOCK_Type types[] =
+ {
+ GNUNET_BLOCK_TYPE_FS_DBLOCK,
+ GNUNET_BLOCK_TYPE_FS_IBLOCK,
+ GNUNET_BLOCK_TYPE_FS_KBLOCK,
+ GNUNET_BLOCK_TYPE_FS_SBLOCK,
+ GNUNET_BLOCK_TYPE_FS_NBLOCK,
+ GNUNET_BLOCK_TYPE_ANY /* end of list */
+ };
struct GNUNET_BLOCK_PluginFunctions *api;
api = GNUNET_malloc (sizeof (struct GNUNET_BLOCK_PluginFunctions));
Modified: gnunet/src/block/plugin_block_template.c
===================================================================
--- gnunet/src/block/plugin_block_template.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/block/plugin_block_template.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -47,14 +47,14 @@
*/
static enum GNUNET_BLOCK_EvaluationResult
block_plugin_template_evaluate (void *cls,
- enum GNUNET_BLOCK_Type type,
- const GNUNET_HashCode *query,
- struct GNUNET_CONTAINER_BloomFilter **bf,
- int32_t bf_mutator,
- const void *xquery,
- size_t xquery_size,
- const void *reply_block,
- size_t reply_block_size)
+ enum GNUNET_BLOCK_Type type,
+ const GNUNET_HashCode * query,
+ struct GNUNET_CONTAINER_BloomFilter **bf,
+ int32_t bf_mutator,
+ const void *xquery,
+ size_t xquery_size,
+ const void *reply_block,
+ size_t reply_block_size)
{
return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
}
@@ -73,26 +73,25 @@
*/
static int
block_plugin_template_get_key (void *cls,
- enum GNUNET_BLOCK_Type type,
- const void *block,
- size_t block_size,
- GNUNET_HashCode *key)
+ enum GNUNET_BLOCK_Type type,
+ const void *block,
+ size_t block_size, GNUNET_HashCode * key)
{
return GNUNET_SYSERR;
}
-
+
/**
* Entry point for the plugin.
*/
void *
libgnunet_plugin_block_template_init (void *cls)
{
- static enum GNUNET_BLOCK_Type types[] =
- {
- /* FIXME: insert supported block types here */
- GNUNET_BLOCK_TYPE_ANY /* end of list */
- };
+ static enum GNUNET_BLOCK_Type types[] =
+ {
+ /* FIXME: insert supported block types here */
+ GNUNET_BLOCK_TYPE_ANY /* end of list */
+ };
struct GNUNET_BLOCK_PluginFunctions *api;
api = GNUNET_malloc (sizeof (struct GNUNET_BLOCK_PluginFunctions));
Modified: gnunet/src/block/plugin_block_test.c
===================================================================
--- gnunet/src/block/plugin_block_test.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/block/plugin_block_test.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -54,42 +54,36 @@
*/
static enum GNUNET_BLOCK_EvaluationResult
block_plugin_test_evaluate (void *cls,
- enum GNUNET_BLOCK_Type type,
- const GNUNET_HashCode *query,
- struct GNUNET_CONTAINER_BloomFilter **bf,
- int32_t bf_mutator,
- const void *xquery,
- size_t xquery_size,
- const void *reply_block,
- size_t reply_block_size)
+ enum GNUNET_BLOCK_Type type,
+ const GNUNET_HashCode * query,
+ struct GNUNET_CONTAINER_BloomFilter **bf,
+ int32_t bf_mutator,
+ const void *xquery,
+ size_t xquery_size,
+ const void *reply_block, size_t reply_block_size)
{
GNUNET_HashCode chash;
GNUNET_HashCode mhash;
- if (type != GNUNET_BLOCK_TYPE_TEST)
+ if (type != GNUNET_BLOCK_TYPE_TEST)
return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
if (xquery_size != 0)
return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
if (reply_block_size == 0)
return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
- GNUNET_CRYPTO_hash (reply_block,
- reply_block_size,
- &chash);
+ 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);
- }
- 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;
}
@@ -107,28 +101,27 @@
*/
static int
block_plugin_test_get_key (void *cls,
- enum GNUNET_BLOCK_Type type,
- const void *block,
- size_t block_size,
- GNUNET_HashCode *key)
+ enum GNUNET_BLOCK_Type type,
+ const void *block,
+ size_t block_size, GNUNET_HashCode * key)
{
/* always fails since there is no fixed relationship between
- keys and values for test values */
+ * keys and values for test values */
return GNUNET_SYSERR;
}
-
+
/**
* Entry point for the plugin.
*/
void *
libgnunet_plugin_block_test_init (void *cls)
{
- static enum GNUNET_BLOCK_Type types[] =
- {
- GNUNET_BLOCK_TYPE_TEST,
- GNUNET_BLOCK_TYPE_ANY /* end of list */
- };
+ static enum GNUNET_BLOCK_Type types[] =
+ {
+ GNUNET_BLOCK_TYPE_TEST,
+ GNUNET_BLOCK_TYPE_ANY /* end of list */
+ };
struct GNUNET_BLOCK_PluginFunctions *api;
api = GNUNET_malloc (sizeof (struct GNUNET_BLOCK_PluginFunctions));
Modified: gnunet/src/block/test_block.c
===================================================================
--- gnunet/src/block/test_block.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/block/test_block.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -38,35 +38,24 @@
memset (block, 1, sizeof (block));
if (GNUNET_OK !=
GNUNET_BLOCK_get_key (ctx,
- GNUNET_BLOCK_TYPE_FS_DBLOCK,
- block,
- sizeof (block),
- &key))
+ GNUNET_BLOCK_TYPE_FS_DBLOCK,
+ block, sizeof (block), &key))
return 1;
if (GNUNET_BLOCK_EVALUATION_OK_LAST !=
GNUNET_BLOCK_evaluate (ctx,
- GNUNET_BLOCK_TYPE_FS_DBLOCK,
- &key,
- NULL, 0,
- NULL, 0,
- block, sizeof (block)))
+ GNUNET_BLOCK_TYPE_FS_DBLOCK,
+ &key, NULL, 0, NULL, 0, block, sizeof (block)))
return 2;
if (GNUNET_BLOCK_EVALUATION_REQUEST_VALID !=
GNUNET_BLOCK_evaluate (ctx,
- GNUNET_BLOCK_TYPE_FS_DBLOCK,
- &key,
- NULL, 0,
- NULL, 0,
- NULL, 0))
+ GNUNET_BLOCK_TYPE_FS_DBLOCK,
+ &key, NULL, 0, NULL, 0, NULL, 0))
return 4;
GNUNET_log_skip (1, GNUNET_NO);
- if (GNUNET_BLOCK_EVALUATION_REQUEST_INVALID !=
+ if (GNUNET_BLOCK_EVALUATION_REQUEST_INVALID !=
GNUNET_BLOCK_evaluate (ctx,
- GNUNET_BLOCK_TYPE_FS_DBLOCK,
- &key,
- NULL, 0,
- "bogus", 5,
- NULL, 0))
+ GNUNET_BLOCK_TYPE_FS_DBLOCK,
+ &key, NULL, 0, "bogus", 5, NULL, 0))
return 8;
GNUNET_log_skip (0, GNUNET_YES);
return 0;
@@ -81,10 +70,7 @@
GNUNET_log_setup ("test-block", "WARNING", NULL);
cfg = GNUNET_CONFIGURATION_create ();
- GNUNET_CONFIGURATION_set_value_string (cfg,
- "block",
- "PLUGINS",
- "fs");
+ GNUNET_CONFIGURATION_set_value_string (cfg, "block", "PLUGINS", "fs");
ctx = GNUNET_BLOCK_context_create (cfg);
ret = test_fs (ctx);
GNUNET_BLOCK_context_destroy (ctx);
Modified: gnunet/src/chat/chat.c
===================================================================
--- gnunet/src/chat/chat.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/chat/chat.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -148,8 +148,7 @@
/**
* Ask client to send a join request.
*/
-static int
-rejoin_room (struct GNUNET_CHAT_Room *chat_room);
+static int rejoin_room (struct GNUNET_CHAT_Room *chat_room);
/**
@@ -161,9 +160,7 @@
* @return number of bytes written to buf
*/
static size_t
-transmit_acknowledge_request (void *cls,
- size_t size,
- void *buf)
+transmit_acknowledge_request (void *cls, size_t size, void *buf)
{
struct GNUNET_CHAT_SendReceiptContext *src = cls;
struct ConfirmationReceiptMessage *receipt;
@@ -172,11 +169,11 @@
size_t msg_size;
if (NULL == buf)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Could not transmit confirmation receipt\n"));
- return 0;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Could not transmit confirmation receipt\n"));
+ return 0;
+ }
#if DEBUG_CHAT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Transmitting confirmation receipt to the service\n");
@@ -185,8 +182,7 @@
GNUNET_assert (size >= msg_size);
receipt = buf;
receipt->header.size = htons (msg_size);
- receipt->header.type =
- htons (GNUNET_MESSAGE_TYPE_CHAT_CONFIRMATION_RECEIPT);
+ receipt->header.type = htons (GNUNET_MESSAGE_TYPE_CHAT_CONFIRMATION_RECEIPT);
receipt->reserved = htonl (0);
receipt->sequence_number = src->received_msg->sequence_number;
receipt->reserved2 = htonl (0);
@@ -196,17 +192,15 @@
sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
&receipt->target);
receipt->author = src->received_msg->sender;
- receipt->purpose.purpose =
- htonl (GNUNET_SIGNATURE_PURPOSE_CHAT_RECEIPT);
+ receipt->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CHAT_RECEIPT);
receipt->purpose.size =
- htonl (msg_size -
- sizeof (struct GNUNET_MessageHeader) -
- sizeof (uint32_t) -
- sizeof (struct GNUNET_CRYPTO_RsaSignature));
+ htonl (msg_size -
+ sizeof (struct GNUNET_MessageHeader) -
+ sizeof (uint32_t) - sizeof (struct GNUNET_CRYPTO_RsaSignature));
msg_len = ntohs (src->received_msg->header.size) -
- sizeof (struct ReceiveNotificationMessage);
+ sizeof (struct ReceiveNotificationMessage);
GNUNET_CRYPTO_hash (&src->received_msg[1], msg_len, &receipt->content);
- GNUNET_assert (GNUNET_OK ==
+ GNUNET_assert (GNUNET_OK ==
GNUNET_CRYPTO_rsa_sign (src->chat_room->my_private_key,
&receipt->purpose,
&receipt->signature));
@@ -244,187 +238,186 @@
size = ntohs (reply->size);
switch (ntohs (reply->type))
- {
- case GNUNET_MESSAGE_TYPE_CHAT_JOIN_NOTIFICATION:
+ {
+ case GNUNET_MESSAGE_TYPE_CHAT_JOIN_NOTIFICATION:
#if DEBUG_CHAT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got a join notification\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got a join notification\n");
#endif
- if (size < sizeof (struct JoinNotificationMessage))
- {
- GNUNET_break (0);
- return;
- }
- join_msg = (struct JoinNotificationMessage *) reply;
- meta_len = size - sizeof (struct JoinNotificationMessage);
- meta =
+ if (size < sizeof (struct JoinNotificationMessage))
+ {
+ GNUNET_break (0);
+ return;
+ }
+ join_msg = (struct JoinNotificationMessage *) reply;
+ meta_len = size - sizeof (struct JoinNotificationMessage);
+ meta =
GNUNET_CONTAINER_meta_data_deserialize ((const char *) &join_msg[1],
meta_len);
- if (NULL == meta)
- {
- GNUNET_break (0);
- return;
- }
- pos = GNUNET_malloc (sizeof (struct MemberList));
- pos->meta = meta;
- GNUNET_CRYPTO_hash (&join_msg->public_key,
- sizeof (struct
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
- &pos->id);
- GNUNET_PSEUDONYM_add (room->cfg, &pos->id, meta);
- pos->next = room->members;
- room->members = pos;
- if (GNUNET_NO == room->is_joined)
- {
- GNUNET_CRYPTO_rsa_key_get_public (room->my_private_key, &pkey);
- if (0 == memcmp (&join_msg->public_key,
- &pkey,
- sizeof (struct
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)))
- {
- room->join_callback (room->join_callback_cls);
- room->is_joined = GNUNET_YES;
- }
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("The current user must be the the first one
joined\n"));
- GNUNET_break (0);
- return;
- }
- }
- else
+ if (NULL == meta)
+ {
+ GNUNET_break (0);
+ return;
+ }
+ pos = GNUNET_malloc (sizeof (struct MemberList));
+ pos->meta = meta;
+ GNUNET_CRYPTO_hash (&join_msg->public_key,
+ sizeof (struct
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+ &pos->id);
+ GNUNET_PSEUDONYM_add (room->cfg, &pos->id, meta);
+ pos->next = room->members;
+ room->members = pos;
+ if (GNUNET_NO == room->is_joined)
+ {
+ GNUNET_CRYPTO_rsa_key_get_public (room->my_private_key, &pkey);
+ if (0 == memcmp (&join_msg->public_key,
+ &pkey,
+ sizeof (struct
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)))
+ {
+ room->join_callback (room->join_callback_cls);
+ room->is_joined = GNUNET_YES;
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("The current user must be the the first one joined\n"));
+ GNUNET_break (0);
+ return;
+ }
+ }
+ else
room->member_list_callback (room->member_list_callback_cls,
meta, &join_msg->public_key,
ntohl (join_msg->msg_options));
- break;
- case GNUNET_MESSAGE_TYPE_CHAT_LEAVE_NOTIFICATION:
+ break;
+ case GNUNET_MESSAGE_TYPE_CHAT_LEAVE_NOTIFICATION:
#if DEBUG_CHAT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got a leave notification\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got a leave notification\n");
#endif
- if (size < sizeof (struct LeaveNotificationMessage))
- {
- GNUNET_break (0);
- return;
- }
- leave_msg = (struct LeaveNotificationMessage *) reply;
- room->member_list_callback (room->member_list_callback_cls,
- NULL, &leave_msg->user,
- GNUNET_CHAT_MSG_OPTION_NONE);
- GNUNET_CRYPTO_hash (&leave_msg->user,
- sizeof (struct
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
- &id);
- prev = NULL;
- pos = room->members;
- while ((NULL != pos) &&
- (0 != memcmp (&pos->id, &id, sizeof (GNUNET_HashCode))))
- {
- prev = pos;
- pos = pos->next;
- }
- GNUNET_assert (NULL != pos);
- if (NULL == prev)
- room->members = pos->next;
- else
- prev->next = pos->next;
- GNUNET_CONTAINER_meta_data_destroy (pos->meta);
- GNUNET_free (pos);
- break;
- case GNUNET_MESSAGE_TYPE_CHAT_MESSAGE_NOTIFICATION:
+ if (size < sizeof (struct LeaveNotificationMessage))
+ {
+ GNUNET_break (0);
+ return;
+ }
+ leave_msg = (struct LeaveNotificationMessage *) reply;
+ room->member_list_callback (room->member_list_callback_cls,
+ NULL, &leave_msg->user,
+ GNUNET_CHAT_MSG_OPTION_NONE);
+ GNUNET_CRYPTO_hash (&leave_msg->user,
+ sizeof (struct
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+ &id);
+ prev = NULL;
+ pos = room->members;
+ while ((NULL != pos) &&
+ (0 != memcmp (&pos->id, &id, sizeof (GNUNET_HashCode))))
+ {
+ prev = pos;
+ pos = pos->next;
+ }
+ GNUNET_assert (NULL != pos);
+ if (NULL == prev)
+ room->members = pos->next;
+ else
+ prev->next = pos->next;
+ GNUNET_CONTAINER_meta_data_destroy (pos->meta);
+ GNUNET_free (pos);
+ break;
+ case GNUNET_MESSAGE_TYPE_CHAT_MESSAGE_NOTIFICATION:
#if DEBUG_CHAT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got a message notification\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got a message notification\n");
#endif
- if (size <= sizeof (struct ReceiveNotificationMessage))
- {
- GNUNET_break (0);
- return;
- }
- received_msg = (struct ReceiveNotificationMessage *) reply;
- if (0 !=
- (ntohl (received_msg->msg_options) & GNUNET_CHAT_MSG_ACKNOWLEDGED))
- {
- src = GNUNET_malloc (sizeof (struct GNUNET_CHAT_SendReceiptContext));
- src->chat_room = room;
- src->received_msg = GNUNET_memdup (received_msg, size);
- GNUNET_CLIENT_notify_transmit_ready (room->client,
- sizeof (struct
ConfirmationReceiptMessage),
-
GNUNET_CONSTANTS_SERVICE_TIMEOUT,
- GNUNET_YES,
- &transmit_acknowledge_request,
- src);
- }
- msg_len = size - sizeof (struct ReceiveNotificationMessage);
- if (0 !=
- (ntohl (received_msg->msg_options) & GNUNET_CHAT_MSG_PRIVATE))
- {
- if (-1 == GNUNET_CRYPTO_rsa_decrypt (room->my_private_key,
- &received_msg->encrypted_key,
- &key,
- sizeof (struct
GNUNET_CRYPTO_AesSessionKey)))
- {
- GNUNET_break (0);
- return;
- }
- msg_len = GNUNET_CRYPTO_aes_decrypt (&received_msg[1],
- msg_len,
- &key,
- (const struct
GNUNET_CRYPTO_AesInitializationVector *) INITVALUE,
- decrypted_msg);
- message_content = decrypted_msg;
- }
- else
- {
- message_content = GNUNET_malloc (msg_len + 1);
- memcpy (message_content, &received_msg[1], msg_len);
- }
- message_content[msg_len] = '\0';
- if (0 != (ntohl (received_msg->msg_options) & GNUNET_CHAT_MSG_ANONYMOUS))
- {
- sender = NULL;
- meta = NULL;
- }
- else
- {
+ if (size <= sizeof (struct ReceiveNotificationMessage))
+ {
+ GNUNET_break (0);
+ return;
+ }
+ received_msg = (struct ReceiveNotificationMessage *) reply;
+ if (0 != (ntohl (received_msg->msg_options) &
GNUNET_CHAT_MSG_ACKNOWLEDGED))
+ {
+ src = GNUNET_malloc (sizeof (struct GNUNET_CHAT_SendReceiptContext));
+ src->chat_room = room;
+ src->received_msg = GNUNET_memdup (received_msg, size);
+ GNUNET_CLIENT_notify_transmit_ready (room->client,
+ sizeof (struct
+ ConfirmationReceiptMessage),
+ GNUNET_CONSTANTS_SERVICE_TIMEOUT,
+ GNUNET_YES,
+ &transmit_acknowledge_request, src);
+ }
+ msg_len = size - sizeof (struct ReceiveNotificationMessage);
+ if (0 != (ntohl (received_msg->msg_options) & GNUNET_CHAT_MSG_PRIVATE))
+ {
+ if (-1 == GNUNET_CRYPTO_rsa_decrypt (room->my_private_key,
+ &received_msg->encrypted_key,
+ &key,
+ sizeof (struct
+
GNUNET_CRYPTO_AesSessionKey)))
+ {
+ GNUNET_break (0);
+ return;
+ }
+ msg_len = GNUNET_CRYPTO_aes_decrypt (&received_msg[1],
+ msg_len,
+ &key,
+ (const struct
+
GNUNET_CRYPTO_AesInitializationVector
+ *) INITVALUE, decrypted_msg);
+ message_content = decrypted_msg;
+ }
+ else
+ {
+ message_content = GNUNET_malloc (msg_len + 1);
+ memcpy (message_content, &received_msg[1], msg_len);
+ }
+ message_content[msg_len] = '\0';
+ if (0 != (ntohl (received_msg->msg_options) & GNUNET_CHAT_MSG_ANONYMOUS))
+ {
+ sender = NULL;
+ meta = NULL;
+ }
+ else
+ {
pos = room->members;
while ((NULL != pos) &&
(0 != memcmp (&pos->id,
- &received_msg->sender,
- sizeof (GNUNET_HashCode))))
+ &received_msg->sender, sizeof (GNUNET_HashCode))))
pos = pos->next;
GNUNET_assert (NULL != pos);
- sender = &received_msg->sender;
- meta = pos->meta;
- }
- room->message_callback (room->message_callback_cls,
- room,
- sender,
- meta,
- message_content,
- GNUNET_TIME_absolute_ntoh
(received_msg->timestamp),
- ntohl (received_msg->msg_options));
- if (message_content != decrypted_msg)
- GNUNET_free (message_content);
- break;
- case GNUNET_MESSAGE_TYPE_CHAT_CONFIRMATION_NOTIFICATION:
+ sender = &received_msg->sender;
+ meta = pos->meta;
+ }
+ room->message_callback (room->message_callback_cls,
+ room,
+ sender,
+ meta,
+ message_content,
+ GNUNET_TIME_absolute_ntoh
(received_msg->timestamp),
+ ntohl (received_msg->msg_options));
+ if (message_content != decrypted_msg)
+ GNUNET_free (message_content);
+ break;
+ case GNUNET_MESSAGE_TYPE_CHAT_CONFIRMATION_NOTIFICATION:
#if DEBUG_CHAT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got a confirmation receipt\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got a confirmation receipt\n");
#endif
- if (size < sizeof (struct ConfirmationReceiptMessage))
- {
- GNUNET_break (0);
- return;
- }
- receipt = (struct ConfirmationReceiptMessage *) reply;
- if (NULL != room->confirmation_callback)
- room->confirmation_callback (room->confirmation_cls,
- room,
- ntohl (receipt->sequence_number),
- GNUNET_TIME_absolute_ntoh
(receipt->timestamp),
- &receipt->target);
- break;
- default:
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Unknown message type: '%u'\n"), ntohs (reply->type));
- GNUNET_break_op (0);
- break;
+ if (size < sizeof (struct ConfirmationReceiptMessage))
+ {
+ GNUNET_break (0);
+ return;
}
+ receipt = (struct ConfirmationReceiptMessage *) reply;
+ if (NULL != room->confirmation_callback)
+ room->confirmation_callback (room->confirmation_cls,
+ room,
+ ntohl (receipt->sequence_number),
+ GNUNET_TIME_absolute_ntoh
+ (receipt->timestamp), &receipt->target);
+ break;
+ default:
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Unknown message type: '%u'\n"), ntohs (reply->type));
+ GNUNET_break_op (0);
+ break;
+ }
}
@@ -435,9 +428,8 @@
* @param cls closure, pointer to the 'struct GNUNET_CHAT_Room'
* @param msg message received, NULL on timeout or fatal error
*/
-static void
-receive_results (void *cls,
- const struct GNUNET_MessageHeader *msg)
+static void
+receive_results (void *cls, const struct GNUNET_MessageHeader *msg)
{
struct GNUNET_CHAT_Room *chat_room = cls;
@@ -447,19 +439,18 @@
if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & GNUNET_SCHEDULER_get_reason ()))
return;
if (NULL == msg)
- {
- GNUNET_break (0);
- rejoin_room (chat_room);
- return;
- }
+ {
+ GNUNET_break (0);
+ rejoin_room (chat_room);
+ return;
+ }
process_result (chat_room, msg);
if (NULL == chat_room->client)
- return; /* fatal error */
+ return; /* fatal error */
/* continue receiving */
GNUNET_CLIENT_receive (chat_room->client,
&receive_results,
- chat_room,
- GNUNET_TIME_UNIT_FOREVER_REL);
+ chat_room, GNUNET_TIME_UNIT_FOREVER_REL);
}
@@ -480,30 +471,25 @@
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Initializing private key\n");
#endif
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (cfg,
- "chat",
- "HOME",
- &home))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Configuration option `%s' in section `%s' missing\n"),
- "HOME",
- "chat");
- return NULL;
- }
+ GNUNET_CONFIGURATION_get_value_filename (cfg, "chat", "HOME", &home))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Configuration option `%s' in section `%s' missing\n"),
+ "HOME", "chat");
+ return NULL;
+ }
GNUNET_DISK_directory_create (home);
if (GNUNET_OK != GNUNET_DISK_directory_test (home))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to access chat home directory `%s'\n"),
- home);
- GNUNET_free (home);
- return NULL;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to access chat home directory `%s'\n"), home);
+ GNUNET_free (home);
+ return NULL;
+ }
/* read or create private key */
keyfile =
- GNUNET_malloc (strlen (home) + strlen (NICK_IDENTITY_PREFIX) +
- strlen (nick_name) + 2);
+ GNUNET_malloc (strlen (home) + strlen (NICK_IDENTITY_PREFIX) +
+ strlen (nick_name) + 2);
strcpy (keyfile, home);
GNUNET_free (home);
if (keyfile[strlen (keyfile) - 1] != DIR_SEPARATOR)
@@ -512,11 +498,10 @@
strcat (keyfile, nick_name);
privKey = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
if (NULL == privKey)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to create/open key in file `%s'\n"),
- keyfile);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to create/open key in file `%s'\n"), keyfile);
+ }
GNUNET_free (keyfile);
return privKey;
}
@@ -531,9 +516,7 @@
* @return number of bytes written to buf
*/
static size_t
-transmit_join_request (void *cls,
- size_t size,
- void *buf)
+transmit_join_request (void *cls, size_t size, void *buf)
{
struct GNUNET_CHAT_Room *chat_room = cls;
struct JoinRequestMessage *join_msg;
@@ -544,20 +527,21 @@
size_t size_of_join;
if (NULL == buf)
- {
+ {
#if DEBUG_CHAT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Could not transmit join request, retrying...\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Could not transmit join request, retrying...\n");
#endif
- rejoin_room (chat_room);
- return 0;
- }
+ rejoin_room (chat_room);
+ return 0;
+ }
#if DEBUG_CHAT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Transmitting join request to the service\n");
#endif
room_len = strlen (chat_room->room_name);
- meta_len = GNUNET_CONTAINER_meta_data_get_serialized_size
(chat_room->member_info);
+ meta_len =
+ GNUNET_CONTAINER_meta_data_get_serialized_size (chat_room->member_info);
size_of_join = sizeof (struct JoinRequestMessage) + meta_len + room_len;
GNUNET_assert (size >= size_of_join);
join_msg = buf;
@@ -567,7 +551,8 @@
join_msg->room_name_len = htons (room_len);
join_msg->reserved = htons (0);
join_msg->reserved2 = htonl (0);
- GNUNET_CRYPTO_rsa_key_get_public (chat_room->my_private_key,
&join_msg->public_key);
+ GNUNET_CRYPTO_rsa_key_get_public (chat_room->my_private_key,
+ &join_msg->public_key);
room = (char *) &join_msg[1];
memcpy (room, chat_room->room_name, room_len);
meta = &room[room_len];
@@ -576,15 +561,13 @@
&meta,
meta_len,
GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Could not serialize metadata\n"));
- return 0;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not serialize metadata\n"));
+ return 0;
+ }
GNUNET_CLIENT_receive (chat_room->client,
&receive_results,
- chat_room,
- GNUNET_TIME_UNIT_FOREVER_REL);
+ chat_room, GNUNET_TIME_UNIT_FOREVER_REL);
return size_of_join;
}
@@ -598,15 +581,14 @@
size_t size_of_join;
size_of_join = sizeof (struct JoinRequestMessage) +
- GNUNET_CONTAINER_meta_data_get_serialized_size (chat_room->member_info) +
- strlen (chat_room->room_name);
+ GNUNET_CONTAINER_meta_data_get_serialized_size (chat_room->member_info) +
+ strlen (chat_room->room_name);
if (NULL ==
GNUNET_CLIENT_notify_transmit_ready (chat_room->client,
size_of_join,
GNUNET_CONSTANTS_SERVICE_TIMEOUT,
GNUNET_YES,
- &transmit_join_request,
- chat_room))
+ &transmit_join_request, chat_room))
return GNUNET_SYSERR;
return GNUNET_OK;
}
@@ -629,12 +611,12 @@
GNUNET_CONTAINER_meta_data_destroy (chat_room->member_info);
GNUNET_CRYPTO_rsa_key_free (chat_room->my_private_key);
while (NULL != chat_room->members)
- {
- pos = chat_room->members;
- chat_room->members = pos->next;
- GNUNET_CONTAINER_meta_data_destroy (pos->meta);
- GNUNET_free (pos);
- }
+ {
+ pos = chat_room->members;
+ chat_room->members = pos->next;
+ GNUNET_CONTAINER_meta_data_destroy (pos->meta);
+ GNUNET_free (pos);
+ }
GNUNET_free (chat_room);
}
@@ -675,8 +657,7 @@
GNUNET_CHAT_MemberListCallback memberCallback,
void *member_cls,
GNUNET_CHAT_MessageConfirmation confirmationCallback,
- void *confirmation_cls,
- GNUNET_HashCode *me)
+ void *confirmation_cls, GNUNET_HashCode * me)
{
struct GNUNET_CHAT_Room *chat_room;
struct GNUNET_CRYPTO_RsaPrivateKey *priv_key;
@@ -696,29 +677,29 @@
GNUNET_PSEUDONYM_add (cfg, me, member_info);
client = GNUNET_CLIENT_connect ("chat", cfg);
if (NULL == client)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to connect to the chat service\n"));
- return NULL;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to connect to the chat service\n"));
+ return NULL;
+ }
if (NULL == joinCallback)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Undefined mandatory parameter: joinCallback\n"));
- return NULL;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Undefined mandatory parameter: joinCallback\n"));
+ return NULL;
+ }
if (NULL == messageCallback)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Undefined mandatory parameter: messageCallback\n"));
- return NULL;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Undefined mandatory parameter: messageCallback\n"));
+ return NULL;
+ }
if (NULL == memberCallback)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Undefined mandatory parameter: memberCallback\n"));
- return NULL;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Undefined mandatory parameter: memberCallback\n"));
+ return NULL;
+ }
chat_room = GNUNET_malloc (sizeof (struct GNUNET_CHAT_Room));
chat_room->msg_options = msg_options;
chat_room->room_name = GNUNET_strdup (room_name);
@@ -737,10 +718,10 @@
chat_room->client = client;
chat_room->members = NULL;
if (GNUNET_SYSERR == rejoin_room (chat_room))
- {
- GNUNET_CHAT_leave_room (chat_room);
- return NULL;
- }
+ {
+ GNUNET_CHAT_leave_room (chat_room);
+ return NULL;
+ }
return chat_room;
}
@@ -754,22 +735,19 @@
* @return number of bytes written to buf
*/
static size_t
-transmit_send_request (void *cls,
- size_t size,
- void *buf)
+transmit_send_request (void *cls, size_t size, void *buf)
{
struct GNUNET_CHAT_SendMessageContext *smc = cls;
struct TransmitRequestMessage *msg_to_send;
size_t msg_size;
if (NULL == buf)
- {
+ {
#if DEBUG_CHAT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Could not transmit a chat message\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Could not transmit a chat
message\n");
#endif
- return 0;
- }
+ return 0;
+ }
#if DEBUG_CHAT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Transmitting a chat message to the service\n");
@@ -782,7 +760,7 @@
msg_to_send->msg_options = htonl (smc->options);
msg_to_send->sequence_number = htonl (smc->sequence_number);
msg_to_send->timestamp =
- GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ());
+ GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ());
msg_to_send->reserved = htonl (0);
if (NULL == smc->receiver)
memset (&msg_to_send->target, 0, sizeof (GNUNET_HashCode));
@@ -796,18 +774,18 @@
* stored on the service side.
*/
if (smc->options & GNUNET_CHAT_MSG_AUTHENTICATED)
- {
- msg_to_send->purpose.purpose =
+ {
+ msg_to_send->purpose.purpose =
htonl (GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE);
- msg_to_send->purpose.size =
+ msg_to_send->purpose.size =
htonl (msg_size -
sizeof (struct GNUNET_MessageHeader) -
sizeof (struct GNUNET_CRYPTO_RsaSignature));
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CRYPTO_rsa_sign (smc->chat_room->my_private_key,
- &msg_to_send->purpose,
- &msg_to_send->signature));
- }
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CRYPTO_rsa_sign (smc->chat_room->my_private_key,
+ &msg_to_send->purpose,
+ &msg_to_send->signature));
+ }
GNUNET_free (smc->message);
GNUNET_free (smc);
return msg_size;
@@ -827,8 +805,8 @@
GNUNET_CHAT_send_message (struct GNUNET_CHAT_Room *room,
const char *message,
enum GNUNET_CHAT_MsgOptions options,
- const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
*receiver,
- uint32_t *sequence_number)
+ const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
+ *receiver, uint32_t * sequence_number)
{
size_t msg_size;
struct GNUNET_CHAT_SendMessageContext *smc;
@@ -849,9 +827,7 @@
GNUNET_CLIENT_notify_transmit_ready (room->client,
msg_size,
GNUNET_CONSTANTS_SERVICE_TIMEOUT,
- GNUNET_YES,
- &transmit_send_request,
- smc);
+ GNUNET_YES, &transmit_send_request,
smc);
}
/* end of chat.c */
Modified: gnunet/src/chat/gnunet-chat.c
===================================================================
--- gnunet/src/chat/gnunet-chat.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/chat/gnunet-chat.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -44,7 +44,8 @@
static struct GNUNET_CHAT_Room *room;
-static GNUNET_SCHEDULER_TaskIdentifier handle_cmd_task =
GNUNET_SCHEDULER_NO_TASK;
+static GNUNET_SCHEDULER_TaskIdentifier handle_cmd_task =
+ GNUNET_SCHEDULER_NO_TASK;
struct ChatCommand
{
@@ -66,12 +67,13 @@
free_user_list ()
{
struct UserList *next;
+
while (NULL != users)
- {
- next = users->next;
- GNUNET_free (users);
- users = next;
- }
+ {
+ next = users->next;
+ GNUNET_free (users);
+ users = next;
+ }
}
static int do_help (const char *args, const void *xtra);
@@ -107,7 +109,7 @@
static int
receive_cb (void *cls,
struct GNUNET_CHAT_Room *room,
- const GNUNET_HashCode *sender,
+ const GNUNET_HashCode * sender,
const struct GNUNET_CONTAINER_MetaData *member_info,
const char *message,
struct GNUNET_TIME_Absolute timestamp,
@@ -122,43 +124,45 @@
else
nick = GNUNET_strdup (_("anonymous"));
fmt = NULL;
- switch ( (int) options)
- {
- case GNUNET_CHAT_MSG_OPTION_NONE:
- case GNUNET_CHAT_MSG_ANONYMOUS:
- fmt = _("(%s) `%s' said: %s\n");
- break;
- case GNUNET_CHAT_MSG_PRIVATE:
- fmt = _("(%s) `%s' said to you: %s\n");
- break;
- case GNUNET_CHAT_MSG_PRIVATE | GNUNET_CHAT_MSG_ANONYMOUS:
- fmt = _("(%s) `%s' said to you: %s\n");
- break;
- case GNUNET_CHAT_MSG_AUTHENTICATED:
- fmt = _("(%s) `%s' said for sure: %s\n");
- break;
- case GNUNET_CHAT_MSG_PRIVATE | GNUNET_CHAT_MSG_AUTHENTICATED:
- fmt = _("(%s) `%s' said to you for sure: %s\n");
- break;
- case GNUNET_CHAT_MSG_ACKNOWLEDGED:
- fmt = _("(%s) `%s' was confirmed that you received: %s\n");
- break;
- case GNUNET_CHAT_MSG_PRIVATE | GNUNET_CHAT_MSG_ACKNOWLEDGED:
- fmt = _("(%s) `%s' was confirmed that you and only you received: %s\n");
- break;
- case GNUNET_CHAT_MSG_AUTHENTICATED | GNUNET_CHAT_MSG_ACKNOWLEDGED:
- fmt = _("(%s) `%s' was confirmed that you received from him or her:
%s\n");
- break;
- case GNUNET_CHAT_MSG_AUTHENTICATED | GNUNET_CHAT_MSG_PRIVATE |
GNUNET_CHAT_MSG_ACKNOWLEDGED:
- fmt = _("(%s) `%s' was confirmed that you and only you received from him
or her: %s\n");
- break;
- case GNUNET_CHAT_MSG_OFF_THE_RECORD:
- fmt = _("(%s) `%s' said off the record: %s\n");
- break;
- default:
- fmt = _("(%s) <%s> said using an unknown message type: %s\n");
- break;
- }
+ switch ((int) options)
+ {
+ case GNUNET_CHAT_MSG_OPTION_NONE:
+ case GNUNET_CHAT_MSG_ANONYMOUS:
+ fmt = _("(%s) `%s' said: %s\n");
+ break;
+ case GNUNET_CHAT_MSG_PRIVATE:
+ fmt = _("(%s) `%s' said to you: %s\n");
+ break;
+ case GNUNET_CHAT_MSG_PRIVATE | GNUNET_CHAT_MSG_ANONYMOUS:
+ fmt = _("(%s) `%s' said to you: %s\n");
+ break;
+ case GNUNET_CHAT_MSG_AUTHENTICATED:
+ fmt = _("(%s) `%s' said for sure: %s\n");
+ break;
+ case GNUNET_CHAT_MSG_PRIVATE | GNUNET_CHAT_MSG_AUTHENTICATED:
+ fmt = _("(%s) `%s' said to you for sure: %s\n");
+ break;
+ case GNUNET_CHAT_MSG_ACKNOWLEDGED:
+ fmt = _("(%s) `%s' was confirmed that you received: %s\n");
+ break;
+ case GNUNET_CHAT_MSG_PRIVATE | GNUNET_CHAT_MSG_ACKNOWLEDGED:
+ fmt = _("(%s) `%s' was confirmed that you and only you received: %s\n");
+ break;
+ case GNUNET_CHAT_MSG_AUTHENTICATED | GNUNET_CHAT_MSG_ACKNOWLEDGED:
+ fmt = _("(%s) `%s' was confirmed that you received from him or her: %s\n");
+ break;
+ case GNUNET_CHAT_MSG_AUTHENTICATED | GNUNET_CHAT_MSG_PRIVATE |
GNUNET_CHAT_MSG_ACKNOWLEDGED:
+ fmt =
+ _
+ ("(%s) `%s' was confirmed that you and only you received from him or
her: %s\n");
+ break;
+ case GNUNET_CHAT_MSG_OFF_THE_RECORD:
+ fmt = _("(%s) `%s' said off the record: %s\n");
+ break;
+ default:
+ fmt = _("(%s) <%s> said using an unknown message type: %s\n");
+ break;
+ }
time = GNUNET_STRINGS_absolute_time_to_string (timestamp);
fprintf (stdout, fmt, time, nick, message);
GNUNET_free (nick);
@@ -183,7 +187,7 @@
struct GNUNET_CHAT_Room *room,
uint32_t orig_seq_number,
struct GNUNET_TIME_Absolute timestamp,
- const GNUNET_HashCode *receiver)
+ const GNUNET_HashCode * receiver)
{
char *nick;
@@ -222,40 +226,41 @@
? _("`%s' entered the room\n") : _("`%s' left the room\n"), nick);
GNUNET_free (nick);
if (NULL != member_info)
+ {
+ /* user joining */
+ pos = GNUNET_malloc (sizeof (struct UserList));
+ pos->next = users;
+ pos->pkey = *member_id;
+ pos->ignored = GNUNET_NO;
+ users = pos;
+ }
+ else
+ {
+ /* user leaving */
+ prev = NULL;
+ pos = users;
+ while ((NULL != pos) &&
+ (0 != memcmp (&pos->pkey,
+ member_id,
+ sizeof (struct
+ GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded))))
{
- /* user joining */
- pos = GNUNET_malloc (sizeof (struct UserList));
- pos->next = users;
- pos->pkey = *member_id;
- pos->ignored = GNUNET_NO;
- users = pos;
+ prev = pos;
+ pos = pos->next;
}
- else
+ if (NULL == pos)
{
- /* user leaving */
- prev = NULL;
- pos = users;
- while ((NULL != pos) &&
- (0 != memcmp (&pos->pkey,
- member_id,
- sizeof (struct
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded))))
- {
- prev = pos;
- pos = pos->next;
- }
- if (NULL == pos)
- {
- GNUNET_break (0);
- }
+ GNUNET_break (0);
+ }
+ else
+ {
+ if (NULL == prev)
+ users = pos->next;
else
- {
- if (NULL == prev)
- users = pos->next;
- else
- prev->next = pos->next;
- GNUNET_free (pos);
- }
+ prev->next = pos->next;
+ GNUNET_free (pos);
}
+ }
return GNUNET_OK;
}
@@ -282,12 +287,13 @@
&member_list_cb, NULL,
&confirmation_cb, NULL, &me);
if (NULL == room)
- {
- fprintf (stdout, _("Could not change username\n"));
- return GNUNET_SYSERR;
- }
+ {
+ fprintf (stdout, _("Could not change username\n"));
+ return GNUNET_SYSERR;
+ }
my_name = GNUNET_PSEUDONYM_id_to_name (cfg, &me);
- fprintf (stdout, _("Joining room `%s' as user `%s'...\n"), room_name,
my_name);
+ fprintf (stdout, _("Joining room `%s' as user `%s'...\n"), room_name,
+ my_name);
GNUNET_free (my_name);
return GNUNET_OK;
}
@@ -310,8 +316,7 @@
EXTRACTOR_METATYPE_TITLE,
EXTRACTOR_METAFORMAT_UTF8,
"text/plain",
- nickname,
- strlen(nickname)+1);
+ nickname, strlen (nickname) + 1);
room = GNUNET_CHAT_join_room (cfg,
nickname,
meta,
@@ -322,10 +327,10 @@
&member_list_cb, NULL,
&confirmation_cb, NULL, &me);
if (NULL == room)
- {
- fprintf (stdout, _("Could not change username\n"));
- return GNUNET_SYSERR;
- }
+ {
+ fprintf (stdout, _("Could not change username\n"));
+ return GNUNET_SYSERR;
+ }
my_name = GNUNET_PSEUDONYM_id_to_name (cfg, &me);
fprintf (stdout, _("Changed username to `%s'\n"), my_name);
GNUNET_free (my_name);
@@ -343,15 +348,15 @@
fprintf (stdout, _("Users in room `%s': "), room_name);
pos = users;
while (NULL != pos)
- {
- GNUNET_CRYPTO_hash (&pos->pkey,
- sizeof (struct
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
- &pid);
- name = GNUNET_PSEUDONYM_id_to_name (cfg, &pid);
- fprintf (stdout, "`%s' ", name);
- GNUNET_free (name);
- pos = pos->next;
- }
+ {
+ GNUNET_CRYPTO_hash (&pos->pkey,
+ sizeof (struct
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+ &pid);
+ name = GNUNET_PSEUDONYM_id_to_name (cfg, &pid);
+ fprintf (stdout, "`%s' ", name);
+ GNUNET_free (name);
+ pos = pos->next;
+ }
fprintf (stdout, "\n");
return GNUNET_OK;
}
@@ -361,10 +366,8 @@
do_send (const char *msg, const void *xtra)
{
uint32_t seq;
- GNUNET_CHAT_send_message (room,
- msg,
- GNUNET_CHAT_MSG_OPTION_NONE,
- NULL, &seq);
+
+ GNUNET_CHAT_send_message (room, msg, GNUNET_CHAT_MSG_OPTION_NONE, NULL,
&seq);
return GNUNET_OK;
}
@@ -379,40 +382,37 @@
struct UserList *pos;
if (NULL == strstr (msg, " "))
- {
- fprintf (stderr, _("Syntax: /msg USERNAME MESSAGE"));
- return GNUNET_OK;
- }
+ {
+ fprintf (stderr, _("Syntax: /msg USERNAME MESSAGE"));
+ return GNUNET_OK;
+ }
user = GNUNET_strdup (msg);
strstr (user, " ")[0] = '\0';
msg += strlen (user) + 1;
if (GNUNET_OK != GNUNET_PSEUDONYM_name_to_id (cfg, user, &uid))
- {
- fprintf (stderr, _("Unknown user `%s'\n"), user);
- GNUNET_free (user);
- return GNUNET_OK;
- }
+ {
+ fprintf (stderr, _("Unknown user `%s'\n"), user);
+ GNUNET_free (user);
+ return GNUNET_OK;
+ }
pos = users;
while (NULL != pos)
- {
- GNUNET_CRYPTO_hash (&pos->pkey,
- sizeof (struct
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
- &pid);
- if (0 == memcmp (&pid, &uid, sizeof (GNUNET_HashCode)))
- break;
- pos = pos->next;
- }
+ {
+ GNUNET_CRYPTO_hash (&pos->pkey,
+ sizeof (struct
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+ &pid);
+ if (0 == memcmp (&pid, &uid, sizeof (GNUNET_HashCode)))
+ break;
+ pos = pos->next;
+ }
if (NULL == pos)
- {
- fprintf (stderr, _("User `%s' is currently not in the room!\n"), user);
- GNUNET_free (user);
- return GNUNET_OK;
- }
+ {
+ fprintf (stderr, _("User `%s' is currently not in the room!\n"), user);
+ GNUNET_free (user);
+ return GNUNET_OK;
+ }
GNUNET_CHAT_send_message (room,
- msg,
- GNUNET_CHAT_MSG_PRIVATE,
- &pos->pkey,
- &seq);
+ msg, GNUNET_CHAT_MSG_PRIVATE, &pos->pkey, &seq);
GNUNET_free (user);
return GNUNET_OK;
}
@@ -422,10 +422,9 @@
do_send_sig (const char *msg, const void *xtra)
{
uint32_t seq;
+
GNUNET_CHAT_send_message (room,
- msg,
- GNUNET_CHAT_MSG_AUTHENTICATED,
- NULL, &seq);
+ msg, GNUNET_CHAT_MSG_AUTHENTICATED, NULL, &seq);
return GNUNET_OK;
}
@@ -434,10 +433,9 @@
do_send_ack (const char *msg, const void *xtra)
{
uint32_t seq;
+
GNUNET_CHAT_send_message (room,
- msg,
- GNUNET_CHAT_MSG_ACKNOWLEDGED,
- NULL, &seq);
+ msg, GNUNET_CHAT_MSG_ACKNOWLEDGED, NULL, &seq);
return GNUNET_OK;
}
@@ -446,10 +444,8 @@
do_send_anonymous (const char *msg, const void *xtra)
{
uint32_t seq;
- GNUNET_CHAT_send_message (room,
- msg,
- GNUNET_CHAT_MSG_ANONYMOUS,
- NULL, &seq);
+
+ GNUNET_CHAT_send_message (room, msg, GNUNET_CHAT_MSG_ANONYMOUS, NULL, &seq);
return GNUNET_OK;
}
@@ -509,8 +505,8 @@
{"/help", &do_help,
gettext_noop ("Use `/help command' to get help for a specific command")},
/* Add standard commands:
- /whois (print metadata),
- /ignore (set flag, check on receive!) */
+ * /whois (print metadata),
+ * /ignore (set flag, check on receive!) */
/* the following three commands must be last! */
{"/", &do_unknown, NULL},
{"", &do_send, NULL},
@@ -522,41 +518,40 @@
do_help (const char *args, const void *xtra)
{
int i;
+
i = 0;
while ((NULL != args) &&
(0 != strlen (args)) && (commands[i].Action != &do_help))
+ {
+ if (0 == strncasecmp (&args[1], &commands[i].command[1], strlen (args) -
1))
{
- if (0 ==
- strncasecmp (&args[1], &commands[i].command[1], strlen (args) - 1))
- {
- fprintf (stdout, "%s\n", gettext (commands[i].helptext));
- return GNUNET_OK;
- }
- i++;
+ fprintf (stdout, "%s\n", gettext (commands[i].helptext));
+ return GNUNET_OK;
}
+ i++;
+ }
i = 0;
fprintf (stdout, "Available commands:");
while (commands[i].Action != &do_help)
- {
- fprintf (stdout, " %s", gettext (commands[i].command));
- i++;
- }
+ {
+ fprintf (stdout, " %s", gettext (commands[i].command));
+ i++;
+ }
fprintf (stdout, "\n");
fprintf (stdout, "%s\n", gettext (commands[i].helptext));
return GNUNET_OK;
}
-static void
-do_stop_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+static void
+do_stop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GNUNET_CHAT_leave_room (room);
if (handle_cmd_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (handle_cmd_task);
- handle_cmd_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (handle_cmd_task);
+ handle_cmd_task = GNUNET_SCHEDULER_NO_TASK;
+ }
free_user_list ();
GNUNET_CONTAINER_meta_data_destroy (meta);
GNUNET_free (room_name);
@@ -591,10 +586,9 @@
next:
handle_cmd_task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_MILLISECONDS,
- 100),
- &handle_command,
- NULL);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MILLISECONDS, 100),
+ &handle_command, NULL);
return;
out:
@@ -614,8 +608,7 @@
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *c)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
{
GNUNET_HashCode me;
char *my_name;
@@ -623,11 +616,11 @@
cfg = c;
/* check arguments */
if (NULL == nickname)
- {
- fprintf (stderr, _("You must specify a nickname\n"));
- ret = -1;
- return;
- }
+ {
+ fprintf (stderr, _("You must specify a nickname\n"));
+ ret = -1;
+ return;
+ }
if (NULL == room_name)
room_name = GNUNET_strdup ("gnunet");
meta = GNUNET_CONTAINER_meta_data_create ();
@@ -636,8 +629,7 @@
EXTRACTOR_METATYPE_TITLE,
EXTRACTOR_METAFORMAT_UTF8,
"text/plain",
- nickname,
- strlen(nickname)+1);
+ nickname, strlen (nickname) + 1);
room = GNUNET_CHAT_join_room (cfg,
nickname,
meta,
@@ -648,24 +640,23 @@
&member_list_cb, NULL,
&confirmation_cb, NULL, &me);
if (NULL == room)
- {
- fprintf (stderr, _("Failed to join room `%s'\n"), room_name);
- GNUNET_free (room_name);
- GNUNET_free (nickname);
- GNUNET_CONTAINER_meta_data_destroy (meta);
- ret = -1;
- return;
- }
+ {
+ fprintf (stderr, _("Failed to join room `%s'\n"), room_name);
+ GNUNET_free (room_name);
+ GNUNET_free (nickname);
+ GNUNET_CONTAINER_meta_data_destroy (meta);
+ ret = -1;
+ return;
+ }
my_name = GNUNET_PSEUDONYM_id_to_name (cfg, &me);
- fprintf (stdout, _("Joining room `%s' as user `%s'...\n"), room_name,
my_name);
+ fprintf (stdout, _("Joining room `%s' as user `%s'...\n"), room_name,
+ my_name);
GNUNET_free (my_name);
handle_cmd_task =
- GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_UI,
- &handle_command,
- NULL);
+ GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_UI,
+ &handle_command, NULL);
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_stop_task,
- NULL);
+ &do_stop_task, NULL);
}
@@ -680,6 +671,7 @@
main (int argc, char *const *argv)
{
int flags;
+
static const struct GNUNET_GETOPT_CommandLineOption options[] = {
{'n', "nick", "NAME",
gettext_noop ("set the nickname to use (required)"),
Modified: gnunet/src/chat/gnunet-service-chat.c
===================================================================
--- gnunet/src/chat/gnunet-service-chat.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/chat/gnunet-service-chat.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -105,7 +105,7 @@
/**
* The peer's identity.
*/
- GNUNET_PEER_Id pid;
+ GNUNET_PEER_Id pid;
};
/**
@@ -157,10 +157,11 @@
* Map of peer identifiers to "struct ConnectedPeer" (for that peer).
*/
static struct GNUNET_CONTAINER_MultiHashMap *connected_peers;
-
+
static void
-remember_anonymous_message (const struct P2PReceiveNotificationMessage
*p2p_rnmsg)
+remember_anonymous_message (const struct P2PReceiveNotificationMessage
+ *p2p_rnmsg)
{
static GNUNET_HashCode hash;
struct AnonymousMessage *anon_msg;
@@ -175,17 +176,17 @@
anon_list_len = 1;
prev = NULL;
while ((NULL != anon_msg->next))
- {
- prev = anon_msg;
- anon_msg = anon_msg->next;
- anon_list_len++;
- }
+ {
+ prev = anon_msg;
+ anon_msg = anon_msg->next;
+ anon_list_len++;
+ }
if (anon_list_len == MAX_ANONYMOUS_MSG_LIST_LENGTH)
- {
- GNUNET_free (anon_msg);
- if (NULL != prev)
- prev->next = NULL;
- }
+ {
+ GNUNET_free (anon_msg);
+ if (NULL != prev)
+ prev->next = NULL;
+ }
}
@@ -213,9 +214,7 @@
* @return number of bytes written to buf
*/
static size_t
-transmit_message_notification_to_peer (void *cls,
- size_t size,
- void *buf)
+transmit_message_notification_to_peer (void *cls, size_t size, void *buf)
{
struct P2PReceiveNotificationMessage *my_msg = cls;
struct P2PReceiveNotificationMessage *m = buf;
@@ -226,14 +225,14 @@
"Transmitting P2P message notification\n");
#endif
if (buf == NULL)
- {
- /* client disconnected */
+ {
+ /* client disconnected */
#if DEBUG_CHAT_SERVICE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Buffer is NULL, dropping the message\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Buffer is NULL, dropping the message\n");
#endif
- return 0;
- }
+ return 0;
+ }
msg_size = ntohs (my_msg->header.size);
GNUNET_assert (size >= msg_size);
memcpy (m, my_msg, msg_size);
@@ -246,9 +245,7 @@
* Ask to send a message notification to the peer.
*/
static int
-send_message_noficiation (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+send_message_noficiation (void *cls, const GNUNET_HashCode * key, void *value)
{
struct P2PReceiveNotificationMessage *msg = cls;
struct ConnectedPeer *cp = value;
@@ -262,7 +259,7 @@
#endif
my_msg = GNUNET_memdup (msg, ntohs (msg->header.size));
if (NULL == GNUNET_CORE_notify_transmit_ready (core,
- GNUNET_NO,
+ GNUNET_NO,
1,
MAX_TRANSMIT_DELAY,
&pid,
@@ -304,35 +301,36 @@
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Client sent a chat message\n");
if (ntohs (message->size) <= sizeof (struct TransmitRequestMessage))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed message: wrong size\n");
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed message: wrong size\n");
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
trmsg = (const struct TransmitRequestMessage *) message;
msg_len = ntohs (trmsg->header.size) - sizeof (struct
TransmitRequestMessage);
is_priv = (0 != (ntohl (trmsg->msg_options) & GNUNET_CHAT_MSG_PRIVATE));
if (is_priv)
- {
+ {
#if DEBUG_CHAT_SERVICE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypting the message text\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypting the message text\n");
#endif
- GNUNET_CRYPTO_aes_create_session_key (&key);
- msg_len = GNUNET_CRYPTO_aes_encrypt (&trmsg[1],
- msg_len,
- &key,
- (const struct
GNUNET_CRYPTO_AesInitializationVector *) INITVALUE,
- encrypted_msg);
- if (-1 == msg_len)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Could not encrypt the message text\n");
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ GNUNET_CRYPTO_aes_create_session_key (&key);
+ msg_len = GNUNET_CRYPTO_aes_encrypt (&trmsg[1],
+ msg_len,
+ &key,
+ (const struct
+ GNUNET_CRYPTO_AesInitializationVector
+ *) INITVALUE, encrypted_msg);
+ if (-1 == msg_len)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Could not encrypt the message text\n");
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
}
+ }
rnmsg = GNUNET_malloc (sizeof (struct ReceiveNotificationMessage) + msg_len);
rnmsg->header.size = htons (sizeof (struct ReceiveNotificationMessage) +
msg_len);
@@ -343,134 +341,134 @@
while ((NULL != pos) && (pos->client != client))
pos = pos->next;
if (NULL == pos)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "The client is not a member of a chat room. Client has to "
- "join a chat room first\n");
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- GNUNET_free (rnmsg);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "The client is not a member of a chat room. Client has to "
+ "join a chat room first\n");
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ GNUNET_free (rnmsg);
+ return;
+ }
room = pos->room;
pos->msg_sequence_number = ntohl (trmsg->sequence_number);
is_anon = (0 != (ntohl (trmsg->msg_options) & GNUNET_CHAT_MSG_ANONYMOUS));
if (is_anon)
- {
+ {
memset (&rnmsg->sender, 0, sizeof (GNUNET_HashCode));
- rnmsg->sequence_number = 0;
- }
+ rnmsg->sequence_number = 0;
+ }
else
- {
- rnmsg->sender = pos->id;
- rnmsg->sequence_number = trmsg->sequence_number;
- }
+ {
+ rnmsg->sender = pos->id;
+ rnmsg->sequence_number = trmsg->sequence_number;
+ }
if (is_priv)
- {
+ {
#if DEBUG_CHAT_SERVICE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Encrypting the session key using the public key of '%s'\n",
- GNUNET_h2s (&trmsg->target));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Encrypting the session key using the public key of '%s'\n",
+ GNUNET_h2s (&trmsg->target));
#endif
- if (0 == memcmp (&all_zeros, &trmsg->target, sizeof (GNUNET_HashCode)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Malformed message: private, but no target\n");
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- GNUNET_free (rnmsg);
- return;
- }
- memcpy (&rnmsg[1], encrypted_msg, msg_len);
- target = client_list_head;
- while ((NULL != target) &&
- (0 != memcmp (&target->id,
- &trmsg->target,
- sizeof (GNUNET_HashCode))))
- target = target->next;
- if (NULL == target)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unknown target of the private message\n");
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- GNUNET_free (rnmsg);
- return;
- }
- if (GNUNET_SYSERR == GNUNET_CRYPTO_rsa_encrypt (&key,
- sizeof (struct
GNUNET_CRYPTO_AesSessionKey),
- &target->public_key,
- &rnmsg->encrypted_key))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Could not encrypt the session key\n");
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- GNUNET_free (rnmsg);
- return;
- }
+ if (0 == memcmp (&all_zeros, &trmsg->target, sizeof (GNUNET_HashCode)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Malformed message: private, but no target\n");
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ GNUNET_free (rnmsg);
+ return;
}
- else
+ memcpy (&rnmsg[1], encrypted_msg, msg_len);
+ target = client_list_head;
+ while ((NULL != target) &&
+ (0 != memcmp (&target->id,
+ &trmsg->target, sizeof (GNUNET_HashCode))))
+ target = target->next;
+ if (NULL == target)
{
- memcpy (&rnmsg[1], &trmsg[1], msg_len);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unknown target of the private message\n");
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ GNUNET_free (rnmsg);
+ return;
}
+ if (GNUNET_SYSERR == GNUNET_CRYPTO_rsa_encrypt (&key,
+ sizeof (struct
+
GNUNET_CRYPTO_AesSessionKey),
+ &target->public_key,
+ &rnmsg->encrypted_key))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Could not encrypt the session key\n");
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ GNUNET_free (rnmsg);
+ return;
+ }
+ }
+ else
+ {
+ memcpy (&rnmsg[1], &trmsg[1], msg_len);
+ }
pos = client_list_head;
#if DEBUG_CHAT_SERVICE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending message to local room
members\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending message to local room members\n");
#endif
while (NULL != pos)
+ {
+ if ((0 == strcmp (room, pos->room)) &&
+ (NULL != pos->client) && (pos->client != client))
{
- if ((0 == strcmp (room, pos->room)) &&
- (NULL != pos->client) &&
- (pos->client != client))
- {
- if (((!is_priv) ||
- (0 == memcmp (&trmsg->target,
- &pos->id,
- sizeof (GNUNET_HashCode)))) &&
- (0 == (ntohl (trmsg->msg_options) & (~pos->msg_options))))
- {
- GNUNET_SERVER_notification_context_unicast (nc,
- pos->client,
- &rnmsg->header,
- GNUNET_NO);
- }
- }
- pos = pos->next;
+ if (((!is_priv) ||
+ (0 == memcmp (&trmsg->target,
+ &pos->id,
+ sizeof (GNUNET_HashCode)))) &&
+ (0 == (ntohl (trmsg->msg_options) & (~pos->msg_options))))
+ {
+ GNUNET_SERVER_notification_context_unicast (nc,
+ pos->client,
+ &rnmsg->header, GNUNET_NO);
+ }
}
+ pos = pos->next;
+ }
#if DEBUG_CHAT_SERVICE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Broadcasting message to neighbour peers\n");
#endif
if (is_anon)
- {
- room_len = strlen (room);
- p2p_rnmsg = GNUNET_malloc (sizeof (struct P2PReceiveNotificationMessage)
+
- msg_len + room_len);
- p2p_rnmsg->header.size =
+ {
+ room_len = strlen (room);
+ p2p_rnmsg = GNUNET_malloc (sizeof (struct P2PReceiveNotificationMessage) +
+ msg_len + room_len);
+ p2p_rnmsg->header.size =
htons (sizeof (struct P2PReceiveNotificationMessage) + msg_len +
room_len);
- p2p_rnmsg->room_name_len = htons (room_len);
- memcpy ((char *) &p2p_rnmsg[1], room, room_len);
- memcpy ((char *) &p2p_rnmsg[1] + room_len, &trmsg[1], msg_len);
- }
+ p2p_rnmsg->room_name_len = htons (room_len);
+ memcpy ((char *) &p2p_rnmsg[1], room, room_len);
+ memcpy ((char *) &p2p_rnmsg[1] + room_len, &trmsg[1], msg_len);
+ }
else
- {
- p2p_rnmsg = GNUNET_malloc (sizeof (struct P2PReceiveNotificationMessage) +
- msg_len);
- p2p_rnmsg->header.size =
+ {
+ p2p_rnmsg = GNUNET_malloc (sizeof (struct P2PReceiveNotificationMessage) +
+ msg_len);
+ p2p_rnmsg->header.size =
htons (sizeof (struct P2PReceiveNotificationMessage) + msg_len);
- if (is_priv)
+ if (is_priv)
{
memcpy (&p2p_rnmsg[1], encrypted_msg, msg_len);
memcpy (&p2p_rnmsg->encrypted_key,
&rnmsg->encrypted_key,
sizeof (struct GNUNET_CRYPTO_RsaEncryptedData));
}
- else
+ else
memcpy (&p2p_rnmsg[1], &trmsg[1], msg_len);
- }
- p2p_rnmsg->header.type = htons
(GNUNET_MESSAGE_TYPE_CHAT_P2P_MESSAGE_NOTIFICATION);
+ }
+ p2p_rnmsg->header.type =
+ htons (GNUNET_MESSAGE_TYPE_CHAT_P2P_MESSAGE_NOTIFICATION);
p2p_rnmsg->msg_options = trmsg->msg_options;
p2p_rnmsg->sequence_number = trmsg->sequence_number;
p2p_rnmsg->timestamp = trmsg->timestamp;
@@ -480,8 +478,7 @@
if (is_anon)
remember_anonymous_message (p2p_rnmsg);
GNUNET_CONTAINER_multihashmap_iterate (connected_peers,
- &send_message_noficiation,
- p2p_rnmsg);
+ &send_message_noficiation, p2p_rnmsg);
GNUNET_free (p2p_rnmsg);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
GNUNET_free (rnmsg);
@@ -497,9 +494,7 @@
* @return number of bytes written to buf
*/
static size_t
-transmit_join_notification_to_peer (void *cls,
- size_t size,
- void *buf)
+transmit_join_notification_to_peer (void *cls, size_t size, void *buf)
{
struct ChatClient *entry = cls;
struct P2PJoinNotificationMessage *m = buf;
@@ -509,8 +504,7 @@
char *roomptr;
#if DEBUG_CHAT_SERVICE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitting P2P join notification\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting P2P join notification\n");
#endif
room_len = strlen (entry->room);
meta_len = entry->meta_len;
@@ -537,9 +531,7 @@
* Ask to send a join notification to the peer.
*/
static int
-send_join_noficiation (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+send_join_noficiation (void *cls, const GNUNET_HashCode * key, void *value)
{
struct ChatClient *entry = cls;
struct ConnectedPeer *cp = value;
@@ -552,10 +544,9 @@
"Sending join notification to `%s'\n", GNUNET_i2s (&pid));
#endif
msg_size = sizeof (struct P2PJoinNotificationMessage) +
- strlen (entry->room) +
- entry->meta_len;
+ strlen (entry->room) + entry->meta_len;
if (NULL == GNUNET_CORE_notify_transmit_ready (core,
- GNUNET_NO,
+ GNUNET_NO,
1,
MAX_TRANSMIT_DELAY,
&pid,
@@ -594,26 +585,24 @@
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Client sent a join request\n");
if (ntohs (message->size) <= sizeof (struct JoinRequestMessage))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed message: wrong size\n");
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed message: wrong size\n");
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
jrmsg = (const struct JoinRequestMessage *) message;
header_size = ntohs (jrmsg->header.size);
room_name_len = ntohs (jrmsg->room_name_len);
- if (header_size - sizeof (struct JoinRequestMessage) <=
- room_name_len)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Malformed message: wrong length of the room name\n");
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
- meta_len =
- header_size - sizeof (struct JoinRequestMessage) - room_name_len;
+ if (header_size - sizeof (struct JoinRequestMessage) <= room_name_len)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Malformed message: wrong length of the room name\n");
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
+ meta_len = header_size - sizeof (struct JoinRequestMessage) - room_name_len;
roomptr = (const char *) &jrmsg[1];
room_name = GNUNET_malloc (room_name_len + 1);
memcpy (room_name, roomptr, room_name_len);
@@ -625,10 +614,10 @@
new_entry->public_key = jrmsg->public_key;
new_entry->meta_len = meta_len;
if (meta_len > 0)
- {
- new_entry->member_info = GNUNET_malloc (meta_len);
- memcpy (new_entry->member_info, &roomptr[room_name_len], meta_len);
- }
+ {
+ new_entry->member_info = GNUNET_malloc (meta_len);
+ memcpy (new_entry->member_info, &roomptr[room_name_len], meta_len);
+ }
else
new_entry->member_info = NULL;
GNUNET_CRYPTO_hash (&new_entry->public_key,
@@ -644,50 +633,47 @@
jnmsg = GNUNET_malloc (sizeof (struct JoinNotificationMessage) + meta_len);
jnmsg->header.type = htons (GNUNET_MESSAGE_TYPE_CHAT_JOIN_NOTIFICATION);
jnmsg->header.size =
- htons (sizeof (struct JoinNotificationMessage) + meta_len);
+ htons (sizeof (struct JoinNotificationMessage) + meta_len);
jnmsg->msg_options = jrmsg->msg_options;
jnmsg->public_key = new_entry->public_key;
memcpy (&jnmsg[1], &roomptr[room_name_len], meta_len);
GNUNET_SERVER_notification_context_add (nc, client);
entry = client_list_head;
while (NULL != entry)
+ {
+ if (0 == strcmp (room_name, entry->room))
{
- if (0 == strcmp (room_name, entry->room))
- {
- if (NULL != entry->client)
- GNUNET_SERVER_notification_context_unicast (nc,
- entry->client,
- &jnmsg->header,
- GNUNET_NO);
- if (entry->client != client)
- {
- entry_jnmsg =
- GNUNET_malloc (sizeof (struct JoinNotificationMessage) +
- entry->meta_len);
- entry_jnmsg->header.type =
- htons (GNUNET_MESSAGE_TYPE_CHAT_JOIN_NOTIFICATION);
- entry_jnmsg->header.size =
- htons (sizeof (struct JoinNotificationMessage) +
- entry->meta_len);
- entry_jnmsg->msg_options = entry->msg_options;
- entry_jnmsg->public_key = entry->public_key;
- memcpy (&entry_jnmsg[1], entry->member_info, entry->meta_len);
- GNUNET_SERVER_notification_context_unicast (nc,
- client,
- &entry_jnmsg->header,
- GNUNET_NO);
- GNUNET_free (entry_jnmsg);
- }
- }
- entry = entry->next;
+ if (NULL != entry->client)
+ GNUNET_SERVER_notification_context_unicast (nc,
+ entry->client,
+ &jnmsg->header, GNUNET_NO);
+ if (entry->client != client)
+ {
+ entry_jnmsg =
+ GNUNET_malloc (sizeof (struct JoinNotificationMessage) +
+ entry->meta_len);
+ entry_jnmsg->header.type =
+ htons (GNUNET_MESSAGE_TYPE_CHAT_JOIN_NOTIFICATION);
+ entry_jnmsg->header.size =
+ htons (sizeof (struct JoinNotificationMessage) + entry->meta_len);
+ entry_jnmsg->msg_options = entry->msg_options;
+ entry_jnmsg->public_key = entry->public_key;
+ memcpy (&entry_jnmsg[1], entry->member_info, entry->meta_len);
+ GNUNET_SERVER_notification_context_unicast (nc,
+ client,
+ &entry_jnmsg->header,
+ GNUNET_NO);
+ GNUNET_free (entry_jnmsg);
+ }
}
+ entry = entry->next;
+ }
#if DEBUG_CHAT_SERVICE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Broadcasting join notification to neighbour peers\n");
#endif
GNUNET_CONTAINER_multihashmap_iterate (connected_peers,
- &send_join_noficiation,
- new_entry);
+ &send_join_noficiation, new_entry);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
GNUNET_free (jnmsg);
}
@@ -701,9 +687,7 @@
* @return number of bytes written to buf
*/
static size_t
-transmit_confirmation_receipt_to_peer (void *cls,
- size_t size,
- void *buf)
+transmit_confirmation_receipt_to_peer (void *cls, size_t size, void *buf)
{
struct P2PConfirmationReceiptMessage *receipt = cls;
size_t msg_size;
@@ -714,14 +698,14 @@
GNUNET_h2s (&receipt->target));
#endif
if (buf == NULL)
- {
- /* client disconnected */
+ {
+ /* client disconnected */
#if DEBUG_CHAT_SERVICE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Buffer is NULL, dropping the message\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Buffer is NULL, dropping the message\n");
#endif
- return 0;
- }
+ return 0;
+ }
msg_size = sizeof (struct P2PConfirmationReceiptMessage);
GNUNET_assert (size >= msg_size);
memcpy (buf, receipt, msg_size);
@@ -734,9 +718,7 @@
* Ask to send a confirmation receipt to the peer.
*/
static int
-send_confirmation_receipt (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+send_confirmation_receipt (void *cls, const GNUNET_HashCode * key, void *value)
{
struct P2PConfirmationReceiptMessage *receipt = cls;
struct ConnectedPeer *cp = value;
@@ -753,7 +735,7 @@
my_receipt = GNUNET_memdup (receipt,
sizeof (struct P2PConfirmationReceiptMessage));
if (NULL == GNUNET_CORE_notify_transmit_ready (core,
- GNUNET_YES,
+ GNUNET_YES,
1,
MAX_TRANSMIT_DELAY,
&pid,
@@ -791,86 +773,84 @@
author = client_list_head;
while ((NULL != author) &&
(0 != memcmp (&receipt->author,
- &author->id,
- sizeof (GNUNET_HashCode))))
+ &author->id, sizeof (GNUNET_HashCode))))
author = author->next;
if (NULL == author)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unknown author of the original message\n");
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unknown author of the original message\n");
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
target = client_list_head;
while ((NULL != target) &&
(0 != memcmp (&receipt->target,
- &target->id,
- sizeof (GNUNET_HashCode))))
+ &target->id, sizeof (GNUNET_HashCode))))
target = target->next;
if (NULL == target)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unknown target of the confirmation receipt\n");
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
+ if (NULL == author->client)
+ {
+ target->rcpt_sequence_number++;
+#if DEBUG_CHAT_SERVICE
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Broadcasting %s's receipt #%u to neighbour peers\n",
+ GNUNET_h2s (&target->id), target->rcpt_sequence_number);
+#endif
+ p2p_crmsg = GNUNET_malloc (sizeof (struct P2PConfirmationReceiptMessage));
+ p2p_crmsg->header.size =
+ htons (sizeof (struct P2PConfirmationReceiptMessage));
+ p2p_crmsg->header.type =
+ htons (GNUNET_MESSAGE_TYPE_CHAT_P2P_CONFIRMATION_RECEIPT);
+ p2p_crmsg->reserved = htonl (0);
+ p2p_crmsg->signature = receipt->signature;
+ p2p_crmsg->purpose = receipt->purpose;
+ p2p_crmsg->msg_sequence_number = receipt->sequence_number;
+ p2p_crmsg->timestamp = receipt->timestamp;
+ p2p_crmsg->target = receipt->target;
+ p2p_crmsg->author = receipt->author;
+ p2p_crmsg->content = receipt->content;
+ p2p_crmsg->sequence_number = htonl (target->rcpt_sequence_number);
+ GNUNET_CONTAINER_multihashmap_iterate (connected_peers,
+ &send_confirmation_receipt,
+ p2p_crmsg);
+ GNUNET_free (p2p_crmsg);
+ }
+ else
+ {
+#if DEBUG_CHAT_SERVICE
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Verifying signature of the receipt\n");
+#endif
+ if (GNUNET_OK !=
+ GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_CHAT_RECEIPT,
+ &receipt->purpose,
+ &receipt->signature, &target->public_key))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unknown target of the confirmation receipt\n");
+ "Invalid signature of the receipt\n");
GNUNET_break (0);
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
- if (NULL == author->client)
- {
- target->rcpt_sequence_number++;
#if DEBUG_CHAT_SERVICE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Broadcasting %s's receipt #%u to neighbour peers\n",
- GNUNET_h2s (&target->id), target->rcpt_sequence_number);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending receipt to the client which sent the original
message\n");
#endif
- p2p_crmsg = GNUNET_malloc (sizeof (struct
P2PConfirmationReceiptMessage));
- p2p_crmsg->header.size = htons (sizeof (struct
P2PConfirmationReceiptMessage));
- p2p_crmsg->header.type = htons
(GNUNET_MESSAGE_TYPE_CHAT_P2P_CONFIRMATION_RECEIPT);
- p2p_crmsg->reserved = htonl (0);
- p2p_crmsg->signature = receipt->signature;
- p2p_crmsg->purpose = receipt->purpose;
- p2p_crmsg->msg_sequence_number = receipt->sequence_number;
- p2p_crmsg->timestamp = receipt->timestamp;
- p2p_crmsg->target = receipt->target;
- p2p_crmsg->author = receipt->author;
- p2p_crmsg->content = receipt->content;
- p2p_crmsg->sequence_number = htonl (target->rcpt_sequence_number);
- GNUNET_CONTAINER_multihashmap_iterate (connected_peers,
- &send_confirmation_receipt,
- p2p_crmsg);
- GNUNET_free (p2p_crmsg);
- }
- else
- {
-#if DEBUG_CHAT_SERVICE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Verifying signature of the receipt\n");
-#endif
- if (GNUNET_OK !=
- GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_CHAT_RECEIPT,
- &receipt->purpose,
- &receipt->signature,
- &target->public_key))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Invalid signature of the receipt\n");
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
-#if DEBUG_CHAT_SERVICE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending receipt to the client which sent the original
message\n");
-#endif
- crmsg = GNUNET_memdup (receipt, sizeof (struct
ConfirmationReceiptMessage));
- crmsg->header.type = htons
(GNUNET_MESSAGE_TYPE_CHAT_CONFIRMATION_NOTIFICATION);
- GNUNET_SERVER_notification_context_unicast (nc,
- author->client,
- &crmsg->header,
- GNUNET_NO);
- GNUNET_free (crmsg);
- }
+ crmsg = GNUNET_memdup (receipt, sizeof (struct
ConfirmationReceiptMessage));
+ crmsg->header.type =
+ htons (GNUNET_MESSAGE_TYPE_CHAT_CONFIRMATION_NOTIFICATION);
+ GNUNET_SERVER_notification_context_unicast (nc, author->client,
+ &crmsg->header, GNUNET_NO);
+ GNUNET_free (crmsg);
+ }
GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
@@ -885,27 +865,24 @@
* @return number of bytes written to buf
*/
static size_t
-transmit_leave_notification_to_peer (void *cls,
- size_t size,
- void *buf)
+transmit_leave_notification_to_peer (void *cls, size_t size, void *buf)
{
struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key = cls;
struct P2PLeaveNotificationMessage *m = buf;
size_t msg_size;
#if DEBUG_CHAT_SERVICE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitting P2P leave notification\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting P2P leave
notification\n");
#endif
if (buf == NULL)
- {
- /* client disconnected */
+ {
+ /* client disconnected */
#if DEBUG_CHAT_SERVICE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Buffer is NULL, dropping the message\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Buffer is NULL, dropping the message\n");
#endif
- return 0;
- }
+ return 0;
+ }
msg_size = sizeof (struct P2PLeaveNotificationMessage);
GNUNET_assert (size >= msg_size);
m = buf;
@@ -922,9 +899,7 @@
* Ask to send a leave notification to the peer.
*/
static int
-send_leave_noficiation (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+send_leave_noficiation (void *cls, const GNUNET_HashCode * key, void *value)
{
struct ChatClient *entry = cls;
struct ConnectedPeer *cp = value;
@@ -939,15 +914,13 @@
#endif
msg_size = sizeof (struct P2PLeaveNotificationMessage);
public_key = GNUNET_memdup (&entry->public_key,
- sizeof (struct
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
- if (NULL == GNUNET_CORE_notify_transmit_ready (core,
- GNUNET_YES,
- 1,
- MAX_TRANSMIT_DELAY,
- &pid,
- msg_size,
-
&transmit_leave_notification_to_peer,
- public_key))
+ sizeof (struct
+
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
+ if (NULL ==
+ GNUNET_CORE_notify_transmit_ready (core, GNUNET_YES, 1,
+ MAX_TRANSMIT_DELAY, &pid, msg_size,
+ &transmit_leave_notification_to_peer,
+ public_key))
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
_("Failed to queue a leave notification\n"));
return GNUNET_YES;
@@ -962,8 +935,7 @@
* @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 ChatClient *entry;
struct ChatClient *pos;
@@ -974,18 +946,18 @@
pos = client_list_head;
prev = NULL;
while ((NULL != pos) && (pos->client != client))
- {
- prev = pos;
- pos = pos->next;
- }
+ {
+ prev = pos;
+ pos = pos->next;
+ }
if (NULL == pos)
- {
+ {
#if DEBUG_CHAT_SERVICE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "No such client. There is nothing to do\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "No such client. There is nothing to do\n");
#endif
- return;
- }
+ return;
+ }
if (NULL == prev)
client_list_head = pos->next;
else
@@ -1000,24 +972,21 @@
lnmsg.reserved = htonl (0);
lnmsg.user = pos->public_key;
while (NULL != entry)
+ {
+ if ((0 == strcmp (pos->room, entry->room)) && (NULL != entry->client))
{
- if ((0 == strcmp (pos->room, entry->room)) &&
- (NULL != entry->client))
- {
- GNUNET_SERVER_notification_context_unicast (nc,
- entry->client,
- &lnmsg.header,
- GNUNET_NO);
- }
- entry = entry->next;
+ GNUNET_SERVER_notification_context_unicast (nc,
+ entry->client,
+ &lnmsg.header, GNUNET_NO);
}
+ entry = entry->next;
+ }
#if DEBUG_CHAT_SERVICE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Broadcasting leave notification to neighbour peers\n");
#endif
GNUNET_CONTAINER_multihashmap_iterate (connected_peers,
- &send_leave_noficiation,
- pos);
+ &send_leave_noficiation, pos);
GNUNET_free (pos->room);
GNUNET_free_non_null (pos->member_info);
GNUNET_free (pos);
@@ -1038,7 +1007,8 @@
handle_p2p_join_notification (void *cls,
const struct GNUNET_PeerIdentity *other,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_TRANSPORT_ATS_Information
*atsi)
+ const struct GNUNET_TRANSPORT_ATS_Information
+ *atsi)
{
const struct P2PJoinNotificationMessage *p2p_jnmsg;
char *room_name;
@@ -1053,40 +1023,39 @@
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Got P2P join notification\n");
if (ntohs (message->size) <= sizeof (struct P2PJoinNotificationMessage))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed message: wrong size\n");
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed message: wrong size\n");
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
p2p_jnmsg = (const struct P2PJoinNotificationMessage *) message;
header_size = ntohs (p2p_jnmsg->header.size);
room_name_len = ntohs (p2p_jnmsg->room_name_len);
- if (header_size - sizeof (struct P2PJoinNotificationMessage) <=
- room_name_len)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Malformed message: wrong length of the room name\n");
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
+ if (header_size - sizeof (struct P2PJoinNotificationMessage) <=
room_name_len)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Malformed message: wrong length of the room name\n");
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
GNUNET_CRYPTO_hash (&p2p_jnmsg->public_key,
sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
&id);
entry = client_list_head;
while (NULL != entry)
+ {
+ if (0 == memcmp (&entry->id, &id, sizeof (GNUNET_HashCode)))
{
- if (0 == memcmp (&entry->id, &id, sizeof (GNUNET_HashCode)))
- {
#if DEBUG_CHAT_SERVICE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "The client has already joined. There is nothing to
do\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "The client has already joined. There is nothing to do\n");
#endif
- return GNUNET_OK;
- }
- entry = entry->next;
+ return GNUNET_OK;
}
+ entry = entry->next;
+ }
meta_len =
- header_size - sizeof (struct P2PJoinNotificationMessage) - room_name_len;
+ header_size - sizeof (struct P2PJoinNotificationMessage) - room_name_len;
roomptr = (const char *) &p2p_jnmsg[1];
room_name = GNUNET_malloc (room_name_len + 1);
memcpy (room_name, roomptr, room_name_len);
@@ -1099,10 +1068,10 @@
new_entry->public_key = p2p_jnmsg->public_key;
new_entry->meta_len = meta_len;
if (meta_len > 0)
- {
- new_entry->member_info = GNUNET_malloc (meta_len);
- memcpy (new_entry->member_info, &roomptr[room_name_len], meta_len);
- }
+ {
+ new_entry->member_info = GNUNET_malloc (meta_len);
+ memcpy (new_entry->member_info, &roomptr[room_name_len], meta_len);
+ }
else
new_entry->member_info = NULL;
new_entry->msg_options = ntohl (p2p_jnmsg->msg_options);
@@ -1115,30 +1084,27 @@
jnmsg = GNUNET_malloc (sizeof (struct JoinNotificationMessage) + meta_len);
jnmsg->header.type = htons (GNUNET_MESSAGE_TYPE_CHAT_JOIN_NOTIFICATION);
jnmsg->header.size =
- htons (sizeof (struct JoinNotificationMessage) + meta_len);
+ htons (sizeof (struct JoinNotificationMessage) + meta_len);
jnmsg->msg_options = p2p_jnmsg->msg_options;
jnmsg->public_key = new_entry->public_key;
memcpy (&jnmsg[1], &roomptr[room_name_len], meta_len);
entry = client_list_head;
while (NULL != entry)
+ {
+ if ((0 == strcmp (room_name, entry->room)) && (NULL != entry->client))
{
- if ((0 == strcmp (room_name, entry->room)) &&
- (NULL != entry->client))
- {
- GNUNET_SERVER_notification_context_unicast (nc,
- entry->client,
- &jnmsg->header,
- GNUNET_NO);
- }
- entry = entry->next;
+ GNUNET_SERVER_notification_context_unicast (nc,
+ entry->client,
+ &jnmsg->header, GNUNET_NO);
}
+ entry = entry->next;
+ }
#if DEBUG_CHAT_SERVICE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Broadcasting join notification to neighbour peers\n");
#endif
GNUNET_CONTAINER_multihashmap_iterate (connected_peers,
- &send_join_noficiation,
- new_entry);
+ &send_join_noficiation, new_entry);
GNUNET_free (jnmsg);
return GNUNET_OK;
}
@@ -1158,7 +1124,8 @@
handle_p2p_leave_notification (void *cls,
const struct GNUNET_PeerIdentity *other,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_TRANSPORT_ATS_Information
*atsi)
+ const struct GNUNET_TRANSPORT_ATS_Information
+ *atsi)
{
const struct P2PLeaveNotificationMessage *p2p_lnmsg;
GNUNET_HashCode id;
@@ -1175,20 +1142,20 @@
pos = client_list_head;
prev = NULL;
while (NULL != pos)
- {
- if (0 == memcmp (&pos->id, &id, sizeof (GNUNET_HashCode)))
- break;
- prev = pos;
- pos = pos->next;
- }
+ {
+ if (0 == memcmp (&pos->id, &id, sizeof (GNUNET_HashCode)))
+ break;
+ prev = pos;
+ pos = pos->next;
+ }
if (NULL == pos)
- {
+ {
#if DEBUG_CHAT_SERVICE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "No such client. There is nothing to do\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "No such client. There is nothing to do\n");
#endif
- return GNUNET_OK;
- }
+ return GNUNET_OK;
+ }
if (NULL == prev)
client_list_head = pos->next;
else
@@ -1203,24 +1170,21 @@
lnmsg.user = pos->public_key;
entry = client_list_head;
while (NULL != entry)
+ {
+ if (0 == strcmp (pos->room, entry->room) && (NULL != entry->client))
{
- if (0 == strcmp (pos->room, entry->room) &&
- (NULL != entry->client))
- {
- GNUNET_SERVER_notification_context_unicast (nc,
- entry->client,
- &lnmsg.header,
- GNUNET_NO);
- }
- entry = entry->next;
+ GNUNET_SERVER_notification_context_unicast (nc,
+ entry->client,
+ &lnmsg.header, GNUNET_NO);
}
+ entry = entry->next;
+ }
#if DEBUG_CHAT_SERVICE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Broadcasting leave notification to neighbour peers\n");
#endif
GNUNET_CONTAINER_multihashmap_iterate (connected_peers,
- &send_leave_noficiation,
- pos);
+ &send_leave_noficiation, pos);
GNUNET_free (pos->room);
GNUNET_free_non_null (pos->member_info);
GNUNET_free (pos);
@@ -1242,7 +1206,8 @@
handle_p2p_message_notification (void *cls,
const struct GNUNET_PeerIdentity *other,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_TRANSPORT_ATS_Information
*atsi)
+ const struct GNUNET_TRANSPORT_ATS_Information
+ *atsi)
{
const struct P2PReceiveNotificationMessage *p2p_rnmsg;
struct P2PReceiveNotificationMessage *my_p2p_rnmsg;
@@ -1259,74 +1224,73 @@
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Got P2P message notification\n");
if (ntohs (message->size) <= sizeof (struct P2PReceiveNotificationMessage))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed message: wrong size\n");
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed message: wrong size\n");
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
p2p_rnmsg = (const struct P2PReceiveNotificationMessage *) message;
msg_len = ntohs (p2p_rnmsg->header.size) -
- sizeof (struct P2PReceiveNotificationMessage);
+ sizeof (struct P2PReceiveNotificationMessage);
is_anon = (0 != (ntohl (p2p_rnmsg->msg_options) &
GNUNET_CHAT_MSG_ANONYMOUS));
if (is_anon)
+ {
+ room_name_len = ntohs (p2p_rnmsg->room_name_len);
+ if (msg_len <= room_name_len)
{
- room_name_len = ntohs (p2p_rnmsg->room_name_len);
- if (msg_len <= room_name_len)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Malformed message: wrong length of the room name\n");
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- msg_len -= room_name_len;
- if (lookup_anonymous_message (p2p_rnmsg))
- {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Malformed message: wrong length of the room name\n");
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ msg_len -= room_name_len;
+ if (lookup_anonymous_message (p2p_rnmsg))
+ {
#if DEBUG_CHAT_SERVICE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "This anonymous message has already been handled.");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "This anonymous message has already been handled.");
#endif
- return GNUNET_OK;
- }
- remember_anonymous_message (p2p_rnmsg);
- room_name = GNUNET_malloc (room_name_len + 1);
- memcpy (room_name, (char *) &p2p_rnmsg[1], room_name_len);
- room_name[room_name_len] = '\0';
- text = (char *) &p2p_rnmsg[1] + room_name_len;
+ return GNUNET_OK;
}
+ remember_anonymous_message (p2p_rnmsg);
+ room_name = GNUNET_malloc (room_name_len + 1);
+ memcpy (room_name, (char *) &p2p_rnmsg[1], room_name_len);
+ room_name[room_name_len] = '\0';
+ text = (char *) &p2p_rnmsg[1] + room_name_len;
+ }
else
+ {
+ sender = client_list_head;
+ while ((NULL != sender) &&
+ (0 != memcmp (&sender->id,
+ &p2p_rnmsg->sender, sizeof (GNUNET_HashCode))))
+ sender = sender->next;
+ if (NULL == sender)
{
- sender = client_list_head;
- while ((NULL != sender) &&
- (0 != memcmp (&sender->id,
- &p2p_rnmsg->sender,
- sizeof (GNUNET_HashCode))))
- sender = sender->next;
- if (NULL == sender)
- {
- /* not an error since the sender may have left before we got the
- message */
+ /* not an error since the sender may have left before we got the
+ * message */
#if DEBUG_CHAT_SERVICE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Unknown source. Rejecting the message\n");
#endif
- return GNUNET_OK;
+ return GNUNET_OK;
}
- if (sender->msg_sequence_number >= ntohl (p2p_rnmsg->sequence_number))
+ if (sender->msg_sequence_number >= ntohl (p2p_rnmsg->sequence_number))
{
#if DEBUG_CHAT_SERVICE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"This message has already been handled."
" Sequence numbers (msg/sender): %u/%u\n",
- ntohl (p2p_rnmsg->sequence_number),
- sender->msg_sequence_number);
+ ntohl (p2p_rnmsg->sequence_number),
+ sender->msg_sequence_number);
#endif
return GNUNET_OK;
}
- sender->msg_sequence_number = ntohl (p2p_rnmsg->sequence_number);
- room_name = sender->room;
- text = (char *) &p2p_rnmsg[1];
- }
+ sender->msg_sequence_number = ntohl (p2p_rnmsg->sequence_number);
+ room_name = sender->room;
+ text = (char *) &p2p_rnmsg[1];
+ }
#if DEBUG_CHAT_SERVICE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1341,7 +1305,7 @@
rnmsg->reserved = htonl (0);
rnmsg->timestamp = p2p_rnmsg->timestamp;
is_priv = (0 != memcmp (&all_zeros,
- &p2p_rnmsg->target, sizeof (GNUNET_HashCode)));
+ &p2p_rnmsg->target, sizeof (GNUNET_HashCode)));
if (is_priv)
memcpy (&rnmsg->encrypted_key,
&p2p_rnmsg->encrypted_key,
@@ -1350,24 +1314,22 @@
memcpy (&rnmsg[1], text, msg_len);
pos = client_list_head;
while (NULL != pos)
+ {
+ if ((0 == strcmp (room_name, pos->room)) && (NULL != pos->client))
{
- if ((0 == strcmp (room_name, pos->room)) &&
- (NULL != pos->client))
- {
- if (((!is_priv) ||
- (0 == memcmp (&p2p_rnmsg->target,
- &pos->id,
- sizeof (GNUNET_HashCode)))) &&
- (0 == (ntohl (p2p_rnmsg->msg_options) & (~pos->msg_options))))
- {
- GNUNET_SERVER_notification_context_unicast (nc,
- pos->client,
- &rnmsg->header,
- GNUNET_NO);
- }
- }
- pos = pos->next;
+ if (((!is_priv) ||
+ (0 == memcmp (&p2p_rnmsg->target,
+ &pos->id,
+ sizeof (GNUNET_HashCode)))) &&
+ (0 == (ntohl (p2p_rnmsg->msg_options) & (~pos->msg_options))))
+ {
+ GNUNET_SERVER_notification_context_unicast (nc,
+ pos->client,
+ &rnmsg->header, GNUNET_NO);
+ }
}
+ pos = pos->next;
+ }
if (is_anon)
GNUNET_free (room_name);
#if DEBUG_CHAT_SERVICE
@@ -1410,21 +1372,20 @@
#endif
entry = client_list_head;
while (NULL != entry)
- {
- msg_size = sizeof (struct P2PJoinNotificationMessage) +
- strlen (entry->room) +
- entry->meta_len;
- th = GNUNET_CORE_notify_transmit_ready (core,
- GNUNET_NO,
- 1,
- MAX_TRANSMIT_DELAY,
- other,
- msg_size,
-
&transmit_join_notification_to_peer,
- entry);
- GNUNET_assert (NULL != th);
- entry = entry->next;
- }
+ {
+ msg_size = sizeof (struct P2PJoinNotificationMessage) +
+ strlen (entry->room) + entry->meta_len;
+ th = GNUNET_CORE_notify_transmit_ready (core,
+ GNUNET_NO,
+ 1,
+ MAX_TRANSMIT_DELAY,
+ other,
+ msg_size,
+
&transmit_join_notification_to_peer,
+ entry);
+ GNUNET_assert (NULL != th);
+ entry = entry->next;
+ }
return GNUNET_OK;
}
@@ -1443,7 +1404,8 @@
handle_p2p_confirmation_receipt (void *cls,
const struct GNUNET_PeerIdentity *other,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_TRANSPORT_ATS_Information
*atsi)
+ const struct GNUNET_TRANSPORT_ATS_Information
+ *atsi)
{
const struct P2PConfirmationReceiptMessage *p2p_crmsg;
struct P2PConfirmationReceiptMessage *my_p2p_crmsg;
@@ -1456,94 +1418,94 @@
target = client_list_head;
while ((NULL != target) &&
(0 != memcmp (&target->id,
- &p2p_crmsg->target,
- sizeof (GNUNET_HashCode))))
+ &p2p_crmsg->target, sizeof (GNUNET_HashCode))))
target = target->next;
if (NULL == target)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unknown source of the receipt. Rejecting the message\n");
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unknown source of the receipt. Rejecting the message\n");
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
if (target->rcpt_sequence_number >= ntohl (p2p_crmsg->sequence_number))
- {
+ {
#if DEBUG_CHAT_SERVICE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "This receipt has already been handled."
- " Sequence numbers (msg/sender): %u/%u\n",
- ntohl (p2p_crmsg->sequence_number),
target->rcpt_sequence_number);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "This receipt has already been handled."
+ " Sequence numbers (msg/sender): %u/%u\n",
+ ntohl (p2p_crmsg->sequence_number),
+ target->rcpt_sequence_number);
#endif
- return GNUNET_OK;
- }
+ return GNUNET_OK;
+ }
target->rcpt_sequence_number = ntohl (p2p_crmsg->sequence_number);
author = client_list_head;
while ((NULL != author) &&
(0 != memcmp (&author->id,
- &p2p_crmsg->author,
- sizeof (GNUNET_HashCode))))
+ &p2p_crmsg->author, sizeof (GNUNET_HashCode))))
author = author->next;
if (NULL == author)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unknown addressee. Rejecting the receipt\n");
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unknown addressee. Rejecting the receipt\n");
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
if (NULL == author->client)
- {
+ {
#if DEBUG_CHAT_SERVICE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "The author of the original message is not a local client."
- " Broadcasting receipt to neighbour peers\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "The author of the original message is not a local client."
+ " Broadcasting receipt to neighbour peers\n");
#endif
- my_p2p_crmsg = GNUNET_memdup (p2p_crmsg, sizeof (struct
P2PConfirmationReceiptMessage));
- GNUNET_CONTAINER_multihashmap_iterate (connected_peers,
- &send_confirmation_receipt,
- my_p2p_crmsg);
- GNUNET_free (my_p2p_crmsg);
- }
+ my_p2p_crmsg =
+ GNUNET_memdup (p2p_crmsg,
+ sizeof (struct P2PConfirmationReceiptMessage));
+ GNUNET_CONTAINER_multihashmap_iterate (connected_peers,
+ &send_confirmation_receipt,
+ my_p2p_crmsg);
+ GNUNET_free (my_p2p_crmsg);
+ }
else
- {
+ {
#if DEBUG_CHAT_SERVICE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "The author of the original message is a local client."
- " Verifying signature of the receipt\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "The author of the original message is a local client."
+ " Verifying signature of the receipt\n");
#endif
- crmsg = GNUNET_malloc (sizeof (struct ConfirmationReceiptMessage));
- crmsg->header.size = htons (sizeof (struct ConfirmationReceiptMessage));
- crmsg->header.type = htons
(GNUNET_MESSAGE_TYPE_CHAT_CONFIRMATION_NOTIFICATION);
- crmsg->signature = p2p_crmsg->signature;
- crmsg->purpose = p2p_crmsg->purpose;
- crmsg->sequence_number = p2p_crmsg->msg_sequence_number;
- crmsg->reserved2 = 0;
- crmsg->timestamp = p2p_crmsg->timestamp;
- crmsg->target = p2p_crmsg->target;
- crmsg->author = p2p_crmsg->author;
- crmsg->content = p2p_crmsg->content;
- if (GNUNET_OK !=
- GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_CHAT_RECEIPT,
- &crmsg->purpose,
- &crmsg->signature,
- &target->public_key))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Invalid signature of the receipt\n");
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
+ crmsg = GNUNET_malloc (sizeof (struct ConfirmationReceiptMessage));
+ crmsg->header.size = htons (sizeof (struct ConfirmationReceiptMessage));
+ crmsg->header.type =
+ htons (GNUNET_MESSAGE_TYPE_CHAT_CONFIRMATION_NOTIFICATION);
+ crmsg->signature = p2p_crmsg->signature;
+ crmsg->purpose = p2p_crmsg->purpose;
+ crmsg->sequence_number = p2p_crmsg->msg_sequence_number;
+ crmsg->reserved2 = 0;
+ crmsg->timestamp = p2p_crmsg->timestamp;
+ crmsg->target = p2p_crmsg->target;
+ crmsg->author = p2p_crmsg->author;
+ crmsg->content = p2p_crmsg->content;
+ if (GNUNET_OK !=
+ GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_CHAT_RECEIPT,
+ &crmsg->purpose,
+ &crmsg->signature, &target->public_key))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Invalid signature of the receipt\n");
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
#if DEBUG_CHAT_SERVICE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "The author of the original message is a local client."
- " Sending receipt to the client\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "The author of the original message is a local client."
+ " Sending receipt to the client\n");
#endif
- GNUNET_SERVER_notification_context_unicast (nc,
- author->client,
- &crmsg->header,
- GNUNET_NO);
- GNUNET_free (crmsg);
- }
+ GNUNET_SERVER_notification_context_unicast (nc,
+ author->client,
+ &crmsg->header, GNUNET_NO);
+ GNUNET_free (crmsg);
+ }
return GNUNET_OK;
}
@@ -1557,9 +1519,7 @@
* @return number of bytes written to buf
*/
static size_t
-transmit_sync_request_to_peer (void *cls,
- size_t size,
- void *buf)
+transmit_sync_request_to_peer (void *cls, size_t size, void *buf)
{
struct GNUNET_MessageHeader *m = buf;
size_t msg_size;
@@ -1584,7 +1544,7 @@
* @param peer peer identity this notification is about
* @param atsi performance data
*/
-static void
+static void
peer_connect_handler (void *cls,
const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_TRANSPORT_ATS_Information *atsi)
@@ -1597,21 +1557,19 @@
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Peer connected: %s\n", GNUNET_i2s (peer));
th = GNUNET_CORE_notify_transmit_ready (core,
- GNUNET_YES,
+ GNUNET_YES,
1,
MAX_TRANSMIT_DELAY,
peer,
sizeof (struct GNUNET_MessageHeader),
- &transmit_sync_request_to_peer,
- NULL);
+ &transmit_sync_request_to_peer,
NULL);
GNUNET_assert (NULL != th);
- cp = GNUNET_CONTAINER_multihashmap_get (connected_peers,
- &peer->hashPubKey);
+ cp = GNUNET_CONTAINER_multihashmap_get (connected_peers, &peer->hashPubKey);
if (NULL != cp)
- {
- GNUNET_break (0);
- return;
- }
+ {
+ GNUNET_break (0);
+ return;
+ }
cp = GNUNET_malloc (sizeof (struct ConnectedPeer));
cp->pid = GNUNET_PEER_intern (peer);
GNUNET_break (GNUNET_OK ==
@@ -1630,22 +1588,19 @@
* @param value value in the hash map (peer entry)
* @return GNUNET_YES (we should continue to iterate)
*/
-static int
-clean_peer (void *cls,
- const GNUNET_HashCode * key,
- void *value)
+static int
+clean_peer (void *cls, const GNUNET_HashCode * key, void *value)
{
struct ConnectedPeer *cp;
- const struct GNUNET_PeerIdentity *peer = (const struct GNUNET_PeerIdentity
*) key;
+ const struct GNUNET_PeerIdentity *peer =
+ (const struct GNUNET_PeerIdentity *) key;
- cp = GNUNET_CONTAINER_multihashmap_get (connected_peers,
- &peer->hashPubKey);
+ cp = GNUNET_CONTAINER_multihashmap_get (connected_peers, &peer->hashPubKey);
if (cp == NULL)
return GNUNET_YES;
GNUNET_break (GNUNET_YES ==
GNUNET_CONTAINER_multihashmap_remove (connected_peers,
- &peer->hashPubKey,
- cp));
+ &peer->hashPubKey, cp));
GNUNET_PEER_change_rc (cp->pid, -1);
GNUNET_free (cp);
return GNUNET_YES;
@@ -1659,8 +1614,7 @@
* @param peer peer identity this notification is about
*/
static void
-peer_disconnect_handler (void *cls,
- const struct GNUNET_PeerIdentity *peer)
+peer_disconnect_handler (void *cls, const struct GNUNET_PeerIdentity *peer)
{
if (0 == memcmp (peer, me, sizeof (struct GNUNET_PeerIdentity)))
@@ -1678,40 +1632,37 @@
* @param tc unused
*/
static void
-cleanup_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct AnonymousMessage *next_msg;
struct ChatClient *next_client;
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Cleaning up\n");
if (NULL != core)
- {
- GNUNET_CORE_disconnect (core);
- core = NULL;
- }
+ {
+ GNUNET_CORE_disconnect (core);
+ core = NULL;
+ }
if (NULL != nc)
- {
- GNUNET_SERVER_notification_context_destroy (nc);
- nc = NULL;
- }
+ {
+ GNUNET_SERVER_notification_context_destroy (nc);
+ nc = NULL;
+ }
while (NULL != client_list_head)
- {
- next_client = client_list_head->next;
- GNUNET_free (client_list_head->room);
- GNUNET_free_non_null (client_list_head->member_info);
- GNUNET_free (client_list_head);
- client_list_head = next_client;
- }
+ {
+ next_client = client_list_head->next;
+ GNUNET_free (client_list_head->room);
+ GNUNET_free_non_null (client_list_head->member_info);
+ GNUNET_free (client_list_head);
+ client_list_head = next_client;
+ }
while (NULL != anonymous_list_head)
- {
- next_msg = anonymous_list_head->next;
- GNUNET_free (anonymous_list_head);
- anonymous_list_head = next_msg;
- }
- GNUNET_CONTAINER_multihashmap_iterate (connected_peers,
- &clean_peer,
- NULL);
+ {
+ next_msg = anonymous_list_head->next;
+ GNUNET_free (anonymous_list_head);
+ anonymous_list_head = next_msg;
+ }
+ GNUNET_CONTAINER_multihashmap_iterate (connected_peers, &clean_peer, NULL);
GNUNET_CONTAINER_multihashmap_destroy (connected_peers);
connected_peers = NULL;
}
@@ -1748,34 +1699,32 @@
struct GNUNET_SERVER_Handle *server,
const struct GNUNET_CONFIGURATION_Handle *c)
{
- static const struct GNUNET_SERVER_MessageHandler handlers[] =
- {
- { &handle_join_request, NULL,
- GNUNET_MESSAGE_TYPE_CHAT_JOIN_REQUEST, 0 },
- { &handle_transmit_request, NULL,
- GNUNET_MESSAGE_TYPE_CHAT_TRANSMIT_REQUEST, 0 },
- { &handle_acknowledge_request, NULL,
- GNUNET_MESSAGE_TYPE_CHAT_CONFIRMATION_RECEIPT,
- sizeof (struct ConfirmationReceiptMessage) },
- { NULL, NULL, 0, 0 }
- };
- static const struct GNUNET_CORE_MessageHandler p2p_handlers[] =
- {
- { &handle_p2p_join_notification,
- GNUNET_MESSAGE_TYPE_CHAT_P2P_JOIN_NOTIFICATION, 0 },
- { &handle_p2p_leave_notification,
- GNUNET_MESSAGE_TYPE_CHAT_P2P_LEAVE_NOTIFICATION,
- sizeof (struct P2PLeaveNotificationMessage) },
- { &handle_p2p_message_notification,
- GNUNET_MESSAGE_TYPE_CHAT_P2P_MESSAGE_NOTIFICATION, 0 },
- { &handle_p2p_sync_request,
- GNUNET_MESSAGE_TYPE_CHAT_P2P_SYNC_REQUEST,
- sizeof (struct GNUNET_MessageHeader) },
- { &handle_p2p_confirmation_receipt,
- GNUNET_MESSAGE_TYPE_CHAT_P2P_CONFIRMATION_RECEIPT,
- sizeof (struct P2PConfirmationReceiptMessage) },
- { NULL, 0, 0 }
- };
+ static const struct GNUNET_SERVER_MessageHandler handlers[] = {
+ {&handle_join_request, NULL,
+ GNUNET_MESSAGE_TYPE_CHAT_JOIN_REQUEST, 0},
+ {&handle_transmit_request, NULL,
+ GNUNET_MESSAGE_TYPE_CHAT_TRANSMIT_REQUEST, 0},
+ {&handle_acknowledge_request, NULL,
+ GNUNET_MESSAGE_TYPE_CHAT_CONFIRMATION_RECEIPT,
+ sizeof (struct ConfirmationReceiptMessage)},
+ {NULL, NULL, 0, 0}
+ };
+ static const struct GNUNET_CORE_MessageHandler p2p_handlers[] = {
+ {&handle_p2p_join_notification,
+ GNUNET_MESSAGE_TYPE_CHAT_P2P_JOIN_NOTIFICATION, 0},
+ {&handle_p2p_leave_notification,
+ GNUNET_MESSAGE_TYPE_CHAT_P2P_LEAVE_NOTIFICATION,
+ sizeof (struct P2PLeaveNotificationMessage)},
+ {&handle_p2p_message_notification,
+ GNUNET_MESSAGE_TYPE_CHAT_P2P_MESSAGE_NOTIFICATION, 0},
+ {&handle_p2p_sync_request,
+ GNUNET_MESSAGE_TYPE_CHAT_P2P_SYNC_REQUEST,
+ sizeof (struct GNUNET_MessageHeader)},
+ {&handle_p2p_confirmation_receipt,
+ GNUNET_MESSAGE_TYPE_CHAT_P2P_CONFIRMATION_RECEIPT,
+ sizeof (struct P2PConfirmationReceiptMessage)},
+ {NULL, 0, 0}
+ };
GNUNET_log_setup ("gnunet-service-chat",
#if DEBUG_CHAT_SERVICE
@@ -1786,7 +1735,8 @@
NULL);
cfg = c;
nc = GNUNET_SERVER_notification_context_create (server, 16);
- connected_peers = GNUNET_CONTAINER_multihashmap_create
(EXPECTED_NEIGHBOUR_COUNT);
+ connected_peers =
+ GNUNET_CONTAINER_multihashmap_create (EXPECTED_NEIGHBOUR_COUNT);
GNUNET_SERVER_add_handlers (server, handlers);
core = GNUNET_CORE_connect (cfg,
QUEUE_SIZE,
@@ -1795,15 +1745,10 @@
&peer_connect_handler,
&peer_disconnect_handler,
NULL,
- NULL, GNUNET_NO,
- NULL, GNUNET_NO,
- p2p_handlers);
- GNUNET_SERVER_disconnect_notify (server,
- &handle_client_disconnect,
- NULL);
+ 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);
+ &cleanup_task, NULL);
}
@@ -1821,8 +1766,7 @@
GNUNET_SERVICE_run (argc,
argv,
"chat",
- GNUNET_SERVICE_OPTION_NONE,
- &run, NULL)) ? 0 : 1;
+ GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
}
/* end of gnunet-service-chat.c */
Modified: gnunet/src/chat/test_chat.c
===================================================================
--- gnunet/src/chat/test_chat.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/chat/test_chat.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -119,11 +119,11 @@
p->cfg = GNUNET_CONFIGURATION_create ();
#if START_ARM
p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
- "gnunet-service-arm",
+ "gnunet-service-arm",
#if VERBOSE
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", cfgname, NULL);
+ "-c", cfgname, NULL);
#endif
GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
}
@@ -135,10 +135,11 @@
#if START_ARM
if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
- if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK)
+ if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "ARM process %u stopped\n", GNUNET_OS_process_get_pid
(p->arm_proc));
+ "ARM process %u stopped\n",
+ GNUNET_OS_process_get_pid (p->arm_proc));
GNUNET_OS_process_close (p->arm_proc);
p->arm_proc = NULL;
#endif
@@ -147,36 +148,34 @@
static void
-abort_test (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+abort_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
if (alice_room != NULL)
- {
- GNUNET_CHAT_leave_room (alice_room);
- alice_room = NULL;
- }
+ {
+ GNUNET_CHAT_leave_room (alice_room);
+ alice_room = NULL;
+ }
if (bob_room != NULL)
- {
- GNUNET_CHAT_leave_room (bob_room);
- bob_room = NULL;
- }
+ {
+ GNUNET_CHAT_leave_room (bob_room);
+ bob_room = NULL;
+ }
err = 1;
}
static void
-timeout_kill (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+timeout_kill (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
#if VERBOSE
printf ("Timed out, stopping the test.\n");
#endif
kill_task = GNUNET_SCHEDULER_NO_TASK;
if (wait_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (wait_task);
- wait_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (wait_task);
+ wait_task = GNUNET_SCHEDULER_NO_TASK;
+ }
GNUNET_SCHEDULER_add_continuation (&abort_test, NULL,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
}
@@ -207,11 +206,11 @@
#if VERBOSE
printf ("%s - told that %s has %s\n",
- want->me,
- member_info == NULL ? NULL
- : GNUNET_CONTAINER_meta_data_get_by_type (member_info,
- EXTRACTOR_METATYPE_TITLE),
- member_info == NULL ? "left" : "joined");
+ want->me,
+ member_info == NULL ? NULL
+ : GNUNET_CONTAINER_meta_data_get_by_type (member_info,
+ EXTRACTOR_METATYPE_TITLE),
+ member_info == NULL ? "left" : "joined");
#endif
GNUNET_CRYPTO_hash (member_id,
sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
@@ -225,16 +224,16 @@
(GNUNET_CONTAINER_meta_data_test_equal (member_info,
want->meta)))) &&
(options == want->opt))
- {
- if (NULL != want->next_task)
- GNUNET_SCHEDULER_add_now (want->next_task, want->next_task_cls);
- }
+ {
+ if (NULL != want->next_task)
+ GNUNET_SCHEDULER_add_now (want->next_task, want->next_task_cls);
+ }
else
- {
- GNUNET_SCHEDULER_cancel (kill_task);
- kill_task = GNUNET_SCHEDULER_NO_TASK;
- GNUNET_SCHEDULER_add_now (&abort_test, NULL);
- }
+ {
+ GNUNET_SCHEDULER_cancel (kill_task);
+ kill_task = GNUNET_SCHEDULER_NO_TASK;
+ GNUNET_SCHEDULER_add_now (&abort_test, NULL);
+ }
return GNUNET_OK;
}
@@ -242,7 +241,7 @@
static int
receive_cb (void *cls,
struct GNUNET_CHAT_Room *room,
- const GNUNET_HashCode *sender,
+ const GNUNET_HashCode * sender,
const struct GNUNET_CONTAINER_MetaData *meta,
const char *message,
struct GNUNET_TIME_Absolute timestamp,
@@ -269,16 +268,16 @@
* slightly greater
*/
(timestamp.abs_value >= want->timestamp.abs_value))
- {
- if (NULL != want->next_task)
- GNUNET_SCHEDULER_add_now (want->next_task, want->next_task_cls);
- }
+ {
+ if (NULL != want->next_task)
+ GNUNET_SCHEDULER_add_now (want->next_task, want->next_task_cls);
+ }
else
- {
- GNUNET_SCHEDULER_cancel (kill_task);
- kill_task = GNUNET_SCHEDULER_NO_TASK;
- GNUNET_SCHEDULER_add_now (&abort_test, NULL);
- }
+ {
+ GNUNET_SCHEDULER_cancel (kill_task);
+ kill_task = GNUNET_SCHEDULER_NO_TASK;
+ GNUNET_SCHEDULER_add_now (&abort_test, NULL);
+ }
return GNUNET_OK;
}
@@ -288,7 +287,7 @@
struct GNUNET_CHAT_Room *room,
uint32_t orig_seq_number,
struct GNUNET_TIME_Absolute timestamp,
- const GNUNET_HashCode *receiver)
+ const GNUNET_HashCode * receiver)
{
struct Wanted *want = cls;
@@ -303,23 +302,22 @@
sizeof (GNUNET_HashCode))) &&
(orig_seq_number == want->sequence_number) &&
(timestamp.abs_value >= want->timestamp.abs_value))
- {
- if (NULL != want->next_task)
- GNUNET_SCHEDULER_add_now (want->next_task, want->next_task_cls);
- }
+ {
+ if (NULL != want->next_task)
+ GNUNET_SCHEDULER_add_now (want->next_task, want->next_task_cls);
+ }
else
- {
- GNUNET_SCHEDULER_cancel (kill_task);
- kill_task = GNUNET_SCHEDULER_NO_TASK;
- GNUNET_SCHEDULER_add_now (&abort_test, NULL);
- }
+ {
+ GNUNET_SCHEDULER_cancel (kill_task);
+ kill_task = GNUNET_SCHEDULER_NO_TASK;
+ GNUNET_SCHEDULER_add_now (&abort_test, NULL);
+ }
return GNUNET_OK;
}
static void
-wait_until_ready (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+wait_until_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GNUNET_SCHEDULER_Task task = cls;
@@ -327,22 +325,20 @@
printf ("Waiting...\n");
#endif
if (is_ready)
- {
- wait_task = GNUNET_SCHEDULER_NO_TASK;
- GNUNET_SCHEDULER_add_now (task, NULL);
- }
+ {
+ wait_task = GNUNET_SCHEDULER_NO_TASK;
+ GNUNET_SCHEDULER_add_now (task, NULL);
+ }
else
wait_task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_MILLISECONDS,
- 50),
- &wait_until_ready,
- task);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MILLISECONDS, 50),
+ &wait_until_ready, task);
}
static void
-disconnect_alice (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+disconnect_alice (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
#if VERBOSE
printf ("Alice is leaving.\n");
@@ -357,8 +353,7 @@
static void
-disconnect_bob (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+disconnect_bob (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
#if VERBOSE
printf ("Bod is leaving.\n");
@@ -375,16 +370,14 @@
static void
-set_ready (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+set_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
is_ready = GNUNET_YES;
}
static void
-send_to_alice (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+send_to_alice (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
#if VERBOSE
printf ("Bob says 'Hi!'\n");
@@ -399,15 +392,12 @@
alice_wanted.next_task_cls = NULL;
GNUNET_CHAT_send_message (bob_room,
"Hi Alice!",
- GNUNET_CHAT_MSG_OPTION_NONE,
- NULL,
- NULL);
+ GNUNET_CHAT_MSG_OPTION_NONE, NULL, NULL);
}
static void
-send_to_bob (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+send_to_bob (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
enum GNUNET_CHAT_MsgOptions options;
uint32_t *seq = NULL;
@@ -416,39 +406,39 @@
printf ("Alice says 'Hi!'\n");
#endif
if (is_ackn)
- {
- options = GNUNET_CHAT_MSG_ACKNOWLEDGED;
- alice_wanted.meta = bob_meta;
- alice_wanted.sender = &bob;
- alice_wanted.timestamp = GNUNET_TIME_absolute_get ();
- alice_wanted.next_task = &disconnect_bob;
- alice_wanted.next_task_cls = NULL;
- bob_wanted.meta = alice_meta;
- bob_wanted.sender = &alice;
- bob_wanted.next_task = NULL;
- seq = &(alice_wanted.sequence_number);
- }
+ {
+ options = GNUNET_CHAT_MSG_ACKNOWLEDGED;
+ alice_wanted.meta = bob_meta;
+ alice_wanted.sender = &bob;
+ alice_wanted.timestamp = GNUNET_TIME_absolute_get ();
+ alice_wanted.next_task = &disconnect_bob;
+ alice_wanted.next_task_cls = NULL;
+ bob_wanted.meta = alice_meta;
+ bob_wanted.sender = &alice;
+ bob_wanted.next_task = NULL;
+ seq = &(alice_wanted.sequence_number);
+ }
else if (is_anon)
- {
- options = GNUNET_CHAT_MSG_ANONYMOUS;
- bob_wanted.meta = NULL;
- bob_wanted.sender = NULL;
- bob_wanted.next_task = &disconnect_bob;
- }
+ {
+ options = GNUNET_CHAT_MSG_ANONYMOUS;
+ bob_wanted.meta = NULL;
+ bob_wanted.sender = NULL;
+ bob_wanted.next_task = &disconnect_bob;
+ }
else if (is_auth)
- {
- options = GNUNET_CHAT_MSG_AUTHENTICATED;
- bob_wanted.meta = alice_meta;
- bob_wanted.sender = &alice;
- bob_wanted.next_task = &disconnect_bob;
- }
+ {
+ options = GNUNET_CHAT_MSG_AUTHENTICATED;
+ bob_wanted.meta = alice_meta;
+ bob_wanted.sender = &alice;
+ bob_wanted.next_task = &disconnect_bob;
+ }
else
- {
- options = GNUNET_CHAT_MSG_OPTION_NONE;
- bob_wanted.meta = alice_meta;
- bob_wanted.sender = &alice;
- bob_wanted.next_task = &send_to_alice;
- }
+ {
+ options = GNUNET_CHAT_MSG_OPTION_NONE;
+ bob_wanted.meta = alice_meta;
+ bob_wanted.sender = &alice;
+ bob_wanted.next_task = &send_to_alice;
+ }
bob_wanted.msg = "Hi Bob!";
bob_wanted.opt = options;
bob_wanted.timestamp = GNUNET_TIME_absolute_get ();
@@ -471,8 +461,7 @@
static void
-join_bob_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+join_bob_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
#if VERBOSE
printf ("Bob joining\n");
@@ -487,27 +476,25 @@
bob_wanted.next_task_cls = NULL;
is_ready = GNUNET_NO;
bob_room =
- GNUNET_CHAT_join_room (is_p2p ? p2.cfg : p1.cfg, "bob", bob_meta,
- "test", -1,
- &join_cb, &bob_wanted,
- &receive_cb, &bob_wanted,
- &member_list_cb, &bob_wanted,
- &confirmation_cb, &bob_wanted,
- &bob);
+ GNUNET_CHAT_join_room (is_p2p ? p2.cfg : p1.cfg, "bob", bob_meta,
+ "test", -1,
+ &join_cb, &bob_wanted,
+ &receive_cb, &bob_wanted,
+ &member_list_cb, &bob_wanted,
+ &confirmation_cb, &bob_wanted, &bob);
if (NULL == bob_room)
- {
- GNUNET_SCHEDULER_cancel (kill_task);
- kill_task = GNUNET_SCHEDULER_NO_TASK;
- GNUNET_CHAT_leave_room (alice_room);
- alice_room = NULL;
- err = 1;
- }
+ {
+ GNUNET_SCHEDULER_cancel (kill_task);
+ kill_task = GNUNET_SCHEDULER_NO_TASK;
+ GNUNET_CHAT_leave_room (alice_room);
+ alice_room = NULL;
+ err = 1;
+ }
}
static void
-join_alice_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+join_alice_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
#if VERBOSE
printf ("Alice joining\n");
@@ -515,33 +502,31 @@
alice_wanted.next_task = &join_bob_task;
alice_wanted.next_task_cls = NULL;
alice_room =
- GNUNET_CHAT_join_room (p1.cfg, "alice", alice_meta,
- "test", -1,
- &join_cb, &alice_wanted,
- &receive_cb, &alice_wanted,
- &member_list_cb, &alice_wanted,
- &confirmation_cb, &alice_wanted,
- &alice);
+ GNUNET_CHAT_join_room (p1.cfg, "alice", alice_meta,
+ "test", -1,
+ &join_cb, &alice_wanted,
+ &receive_cb, &alice_wanted,
+ &member_list_cb, &alice_wanted,
+ &confirmation_cb, &alice_wanted, &alice);
if (NULL == alice_room)
- {
- GNUNET_SCHEDULER_cancel (kill_task);
- kill_task = GNUNET_SCHEDULER_NO_TASK;
- err = 1;
- }
+ {
+ GNUNET_SCHEDULER_cancel (kill_task);
+ kill_task = GNUNET_SCHEDULER_NO_TASK;
+ err = 1;
+ }
}
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
if (is_p2p)
- {
- setup_peer (&p1, "test_chat_peer1.conf");
- setup_peer (&p2, "test_chat_peer2.conf");
- }
+ {
+ setup_peer (&p1, "test_chat_peer1.conf");
+ setup_peer (&p2, "test_chat_peer2.conf");
+ }
else
setup_peer (&p1, "test_chat_data.conf");
@@ -555,19 +540,14 @@
EXTRACTOR_METATYPE_TITLE,
EXTRACTOR_METAFORMAT_UTF8,
"text/plain",
- "Alice",
- strlen("Alice")+1);
+ "Alice", strlen ("Alice") + 1);
bob_meta = GNUNET_CONTAINER_meta_data_create ();
GNUNET_CONTAINER_meta_data_insert (bob_meta,
"<gnunet>",
EXTRACTOR_METATYPE_TITLE,
EXTRACTOR_METAFORMAT_UTF8,
- "text/plain",
- "Bob",
- strlen("Bob")+1);
- kill_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &timeout_kill,
- NULL);
+ "text/plain", "Bob", strlen ("Bob") + 1);
+ kill_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_kill, NULL);
GNUNET_SCHEDULER_add_now (&join_alice_task, NULL);
}
@@ -575,7 +555,7 @@
int
main (int argc, char *argv[])
{
- char *const argvx[] = {
+ char *const argvx[] = {
"test-chat",
"-c",
"test_chat_data.conf",
@@ -588,40 +568,39 @@
GNUNET_GETOPT_OPTION_END
};
- GNUNET_log_setup ("test_chat",
+ GNUNET_log_setup ("test_chat",
#if VERBOSE
"DEBUG",
#else
"WARNING",
#endif
NULL);
- if (strstr(argv[0], "p2p") != NULL)
- {
- is_p2p = GNUNET_YES;
- }
- if (strstr(argv[0], "acknowledgment") != NULL)
- {
- is_ackn = GNUNET_YES;
- }
- else if (strstr(argv[0], "anonymous") != NULL)
- {
- is_anon = GNUNET_YES;
- }
- else if (strstr(argv[0], "authentication") != NULL)
- {
- is_auth = GNUNET_YES;
- }
+ if (strstr (argv[0], "p2p") != NULL)
+ {
+ is_p2p = GNUNET_YES;
+ }
+ if (strstr (argv[0], "acknowledgment") != NULL)
+ {
+ is_ackn = GNUNET_YES;
+ }
+ else if (strstr (argv[0], "anonymous") != NULL)
+ {
+ is_anon = GNUNET_YES;
+ }
+ else if (strstr (argv[0], "authentication") != NULL)
+ {
+ is_auth = GNUNET_YES;
+ }
GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
- argvx, "test-chat",
- "nohelp", options, &run, NULL);
+ argvx, "test-chat", "nohelp", options, &run, NULL);
stop_arm (&p1);
GNUNET_CONTAINER_meta_data_destroy (alice_meta);
GNUNET_CONTAINER_meta_data_destroy (bob_meta);
if (is_p2p)
- {
- GNUNET_DISK_directory_remove ("/tmp/gnunet-test-chat-peer-1/");
- GNUNET_DISK_directory_remove ("/tmp/gnunet-test-chat-peer-2/");
- }
+ {
+ GNUNET_DISK_directory_remove ("/tmp/gnunet-test-chat-peer-1/");
+ GNUNET_DISK_directory_remove ("/tmp/gnunet-test-chat-peer-2/");
+ }
else
GNUNET_DISK_directory_remove ("/tmp/gnunet-test-chat/");
return err;
Modified: gnunet/src/chat/test_chat_private.c
===================================================================
--- gnunet/src/chat/test_chat_private.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/chat/test_chat_private.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -133,11 +133,11 @@
p->cfg = GNUNET_CONFIGURATION_create ();
#if START_ARM
p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
- "gnunet-service-arm",
+ "gnunet-service-arm",
#if VERBOSE
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", cfgname, NULL);
+ "-c", cfgname, NULL);
#endif
GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
}
@@ -149,10 +149,11 @@
#if START_ARM
if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
- if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK)
+ if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "ARM process %u stopped\n", GNUNET_OS_process_get_pid
(p->arm_proc));
+ "ARM process %u stopped\n",
+ GNUNET_OS_process_get_pid (p->arm_proc));
GNUNET_OS_process_close (p->arm_proc);
p->arm_proc = NULL;
#endif
@@ -161,41 +162,39 @@
static void
-abort_test (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+abort_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
if (alice_room != NULL)
- {
- GNUNET_CHAT_leave_room (alice_room);
- alice_room = NULL;
- }
+ {
+ GNUNET_CHAT_leave_room (alice_room);
+ alice_room = NULL;
+ }
if (bob_room != NULL)
- {
- GNUNET_CHAT_leave_room (bob_room);
- bob_room = NULL;
- }
+ {
+ GNUNET_CHAT_leave_room (bob_room);
+ bob_room = NULL;
+ }
if (carol_room != NULL)
- {
- GNUNET_CHAT_leave_room (carol_room);
- carol_room = NULL;
- }
+ {
+ GNUNET_CHAT_leave_room (carol_room);
+ carol_room = NULL;
+ }
err = 1;
}
static void
-timeout_kill (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+timeout_kill (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
#if VERBOSE
printf ("Timed out, stopping the test.\n");
#endif
kill_task = GNUNET_SCHEDULER_NO_TASK;
if (wait_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (wait_task);
- wait_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (wait_task);
+ wait_task = GNUNET_SCHEDULER_NO_TASK;
+ }
GNUNET_SCHEDULER_add_continuation (&abort_test, NULL,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
}
@@ -226,11 +225,11 @@
#if VERBOSE
printf ("%s - told that %s has %s\n",
- want->me,
- member_info == NULL ? NULL
- : GNUNET_CONTAINER_meta_data_get_by_type (member_info,
- EXTRACTOR_METATYPE_TITLE),
- member_info == NULL ? "left" : "joined");
+ want->me,
+ member_info == NULL ? NULL
+ : GNUNET_CONTAINER_meta_data_get_by_type (member_info,
+ EXTRACTOR_METATYPE_TITLE),
+ member_info == NULL ? "left" : "joined");
#endif
GNUNET_CRYPTO_hash (member_id,
sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
@@ -248,34 +247,34 @@
GNUNET_CONTAINER_meta_data_test_equal (member_info,
want->meta2))))) &&
(options == want->opt))
- {
- /* remember Bob's public key, we need it to send private message */
- if (NULL == bob_public_key &&
- (0 == memcmp (&bob, want->sender, sizeof (GNUNET_HashCode))))
- bob_public_key =
+ {
+ /* remember Bob's public key, we need it to send private message */
+ if (NULL == bob_public_key &&
+ (0 == memcmp (&bob, want->sender, sizeof (GNUNET_HashCode))))
+ bob_public_key =
GNUNET_memdup (member_id,
- sizeof (struct
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
- if (want->sender2 != NULL)
- {
- /* flush alternative sender */
- if (0 == memcmp (&sender, want->sender, sizeof (GNUNET_HashCode)))
- {
- want->sender = want->sender2;
- want->meta = want->meta2;
- }
- want->sender2 = NULL;
- want->meta2 = NULL;
- }
- else
- if (NULL != want->next_task)
- GNUNET_SCHEDULER_add_now (want->next_task, want->next_task_cls);
- }
- else
+ sizeof (struct
+ GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
+ if (want->sender2 != NULL)
{
- GNUNET_SCHEDULER_cancel (kill_task);
- kill_task = GNUNET_SCHEDULER_NO_TASK;
- GNUNET_SCHEDULER_add_now (&abort_test, NULL);
+ /* flush alternative sender */
+ if (0 == memcmp (&sender, want->sender, sizeof (GNUNET_HashCode)))
+ {
+ want->sender = want->sender2;
+ want->meta = want->meta2;
+ }
+ want->sender2 = NULL;
+ want->meta2 = NULL;
}
+ else if (NULL != want->next_task)
+ GNUNET_SCHEDULER_add_now (want->next_task, want->next_task_cls);
+ }
+ else
+ {
+ GNUNET_SCHEDULER_cancel (kill_task);
+ kill_task = GNUNET_SCHEDULER_NO_TASK;
+ GNUNET_SCHEDULER_add_now (&abort_test, NULL);
+ }
return GNUNET_OK;
}
@@ -283,7 +282,7 @@
static int
receive_cb (void *cls,
struct GNUNET_CHAT_Room *room,
- const GNUNET_HashCode *sender,
+ const GNUNET_HashCode * sender,
const struct GNUNET_CONTAINER_MetaData *meta,
const char *message,
struct GNUNET_TIME_Absolute timestamp,
@@ -311,25 +310,24 @@
* slightly greater
*/
(timestamp.abs_value >= want->timestamp.abs_value))
- {
- if (NULL != want->next_task)
- GNUNET_SCHEDULER_add_now (want->next_task, want->next_task_cls);
- }
+ {
+ if (NULL != want->next_task)
+ GNUNET_SCHEDULER_add_now (want->next_task, want->next_task_cls);
+ }
else
- {
- GNUNET_SCHEDULER_cancel (kill_task);
- kill_task = GNUNET_SCHEDULER_NO_TASK;
- GNUNET_SCHEDULER_cancel (finish_task);
- finish_task = GNUNET_SCHEDULER_NO_TASK;
- GNUNET_SCHEDULER_add_now (&abort_test, NULL);
- }
+ {
+ GNUNET_SCHEDULER_cancel (kill_task);
+ kill_task = GNUNET_SCHEDULER_NO_TASK;
+ GNUNET_SCHEDULER_cancel (finish_task);
+ finish_task = GNUNET_SCHEDULER_NO_TASK;
+ GNUNET_SCHEDULER_add_now (&abort_test, NULL);
+ }
return GNUNET_OK;
}
static void
-wait_until_all_ready (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+wait_until_all_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GNUNET_SCHEDULER_Task task = cls;
@@ -337,38 +335,34 @@
printf ("Waiting...\n");
#endif
if (alice_ready && bob_ready)
- {
- wait_task = GNUNET_SCHEDULER_NO_TASK;
- GNUNET_SCHEDULER_add_now (task, NULL);
- }
+ {
+ wait_task = GNUNET_SCHEDULER_NO_TASK;
+ GNUNET_SCHEDULER_add_now (task, NULL);
+ }
else
wait_task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_MILLISECONDS,
- 5000),
- &wait_until_all_ready,
- task);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MILLISECONDS, 5000),
+ &wait_until_all_ready, task);
}
static void
-set_alice_ready (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+set_alice_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
alice_ready = GNUNET_YES;
}
static void
-set_bob_ready (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+set_bob_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
bob_ready = GNUNET_YES;
}
static void
-disconnect_alice (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+disconnect_alice (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
#if VERBOSE
printf ("Alice is leaving.\n");
@@ -383,8 +377,7 @@
static void
-disconnect_bob (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+disconnect_bob (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
#if VERBOSE
printf ("Bod is leaving.\n");
@@ -403,8 +396,7 @@
static void
-disconnect_carol (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+disconnect_carol (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
#if VERBOSE
printf ("Carol is leaving.\n");
@@ -454,8 +446,7 @@
carol_wanted.next_task_cls = NULL;
GNUNET_CHAT_send_message (alice_room,
"Hi Bob!",
- GNUNET_CHAT_MSG_PRIVATE,
- bob_public_key, &seq);
+ GNUNET_CHAT_MSG_PRIVATE, bob_public_key, &seq);
finish_task = GNUNET_SCHEDULER_add_delayed (PM_TIMEOUT,
&wait_until_all_ready,
&disconnect_carol);
@@ -477,12 +468,13 @@
static void
prepare_carol_for_alice_and_bob_task (void *cls,
- const struct
GNUNET_SCHEDULER_TaskContext *tc)
+ const struct GNUNET_SCHEDULER_TaskContext
+ *tc)
{
carol_wanted.meta = alice_meta;
carol_wanted.sender = &alice;
/* set alternative meta/sender since we don't know from which peer
- notification will come first */
+ * notification will come first */
carol_wanted.meta2 = bob_meta;
carol_wanted.sender2 = &bob;
carol_wanted.msg = NULL;
@@ -493,8 +485,7 @@
static void
-join_carol_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+join_carol_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
#if VERBOSE
printf ("Carol joining\n");
@@ -516,28 +507,27 @@
carol_wanted.next_task = &prepare_carol_for_alice_and_bob_task;
carol_wanted.next_task_cls = NULL;
carol_room =
- GNUNET_CHAT_join_room (is_p2p ? p3.cfg : p1.cfg, "carol", carol_meta,
- "test", -1,
- &join_cb, &carol_wanted,
- &receive_cb, &carol_wanted,
- &member_list_cb, &carol_wanted,
- NULL, NULL, &carol);
+ GNUNET_CHAT_join_room (is_p2p ? p3.cfg : p1.cfg, "carol", carol_meta,
+ "test", -1,
+ &join_cb, &carol_wanted,
+ &receive_cb, &carol_wanted,
+ &member_list_cb, &carol_wanted,
+ NULL, NULL, &carol);
if (NULL == carol_room)
- {
- GNUNET_SCHEDULER_cancel (kill_task);
- kill_task = GNUNET_SCHEDULER_NO_TASK;
- GNUNET_CHAT_leave_room (alice_room);
- alice_room = NULL;
- GNUNET_CHAT_leave_room (bob_room);
- bob_room = NULL;
- err = 1;
- }
+ {
+ GNUNET_SCHEDULER_cancel (kill_task);
+ kill_task = GNUNET_SCHEDULER_NO_TASK;
+ GNUNET_CHAT_leave_room (alice_room);
+ alice_room = NULL;
+ GNUNET_CHAT_leave_room (bob_room);
+ bob_room = NULL;
+ err = 1;
+ }
}
static void
-join_bob_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+join_bob_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
#if VERBOSE
printf ("Bob joining\n");
@@ -553,26 +543,24 @@
bob_wanted.next_task_cls = NULL;
bob_ready = GNUNET_NO;
bob_room =
- GNUNET_CHAT_join_room (is_p2p ? p2.cfg : p1.cfg, "bob", bob_meta,
- "test", -1,
- &join_cb, &bob_wanted,
- &receive_cb, &bob_wanted,
- &member_list_cb, &bob_wanted,
- NULL, NULL, &bob);
+ GNUNET_CHAT_join_room (is_p2p ? p2.cfg : p1.cfg, "bob", bob_meta,
+ "test", -1,
+ &join_cb, &bob_wanted,
+ &receive_cb, &bob_wanted,
+ &member_list_cb, &bob_wanted, NULL, NULL, &bob);
if (NULL == bob_room)
- {
- GNUNET_SCHEDULER_cancel (kill_task);
- kill_task = GNUNET_SCHEDULER_NO_TASK;
- GNUNET_CHAT_leave_room (alice_room);
- alice_room = NULL;
- err = 1;
- }
+ {
+ GNUNET_SCHEDULER_cancel (kill_task);
+ kill_task = GNUNET_SCHEDULER_NO_TASK;
+ GNUNET_CHAT_leave_room (alice_room);
+ alice_room = NULL;
+ err = 1;
+ }
}
static void
-join_alice_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+join_alice_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
#if VERBOSE
printf ("Alice joining\n");
@@ -580,33 +568,32 @@
alice_wanted.next_task = &join_bob_task;
alice_wanted.next_task_cls = NULL;
alice_room =
- GNUNET_CHAT_join_room (p1.cfg, "alice", alice_meta,
- "test", -1,
- &join_cb, &alice_wanted,
- &receive_cb, &alice_wanted,
- &member_list_cb, &alice_wanted,
- NULL, NULL, &alice);
+ GNUNET_CHAT_join_room (p1.cfg, "alice", alice_meta,
+ "test", -1,
+ &join_cb, &alice_wanted,
+ &receive_cb, &alice_wanted,
+ &member_list_cb, &alice_wanted,
+ NULL, NULL, &alice);
if (NULL == alice_room)
- {
- GNUNET_SCHEDULER_cancel (kill_task);
- kill_task = GNUNET_SCHEDULER_NO_TASK;
- err = 1;
- }
+ {
+ GNUNET_SCHEDULER_cancel (kill_task);
+ kill_task = GNUNET_SCHEDULER_NO_TASK;
+ err = 1;
+ }
}
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
if (is_p2p)
- {
- setup_peer (&p1, "test_chat_peer1.conf");
- setup_peer (&p2, "test_chat_peer2.conf");
- setup_peer (&p3, "test_chat_peer3.conf");
- }
+ {
+ setup_peer (&p1, "test_chat_peer1.conf");
+ setup_peer (&p2, "test_chat_peer2.conf");
+ setup_peer (&p3, "test_chat_peer3.conf");
+ }
else
setup_peer (&p1, "test_chat_data.conf");
@@ -622,24 +609,20 @@
EXTRACTOR_METATYPE_TITLE,
EXTRACTOR_METAFORMAT_UTF8,
"text/plain",
- "Alice",
- strlen("Alice")+1);
+ "Alice", strlen ("Alice") + 1);
bob_meta = GNUNET_CONTAINER_meta_data_create ();
GNUNET_CONTAINER_meta_data_insert (bob_meta,
"<gnunet>",
EXTRACTOR_METATYPE_TITLE,
EXTRACTOR_METAFORMAT_UTF8,
- "text/plain",
- "Bob",
- strlen("Bob")+1);
+ "text/plain", "Bob", strlen ("Bob") + 1);
carol_meta = GNUNET_CONTAINER_meta_data_create ();
GNUNET_CONTAINER_meta_data_insert (carol_meta,
"<gnunet>",
EXTRACTOR_METATYPE_TITLE,
EXTRACTOR_METAFORMAT_UTF8,
"text/plain",
- "Carol",
- strlen("Carol")+1);
+ "Carol", strlen ("Carol") + 1);
kill_task = GNUNET_SCHEDULER_add_delayed (KILL_TIMEOUT, &timeout_kill, NULL);
GNUNET_SCHEDULER_add_now (&join_alice_task, NULL);
}
@@ -648,7 +631,7 @@
int
main (int argc, char *argv[])
{
- char *const argvx[] = {
+ char *const argvx[] = {
"test-chat",
"-c",
"test_chat_data.conf",
@@ -661,30 +644,29 @@
GNUNET_GETOPT_OPTION_END
};
- GNUNET_log_setup ("test_chat",
+ GNUNET_log_setup ("test_chat",
#if VERBOSE
"DEBUG",
#else
"WARNING",
#endif
NULL);
- if (strstr(argv[0], "p2p") != NULL)
- {
- is_p2p = GNUNET_YES;
- }
+ if (strstr (argv[0], "p2p") != NULL)
+ {
+ is_p2p = GNUNET_YES;
+ }
GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
- argvx, "test-chat",
- "nohelp", options, &run, NULL);
+ argvx, "test-chat", "nohelp", options, &run, NULL);
stop_arm (&p1);
GNUNET_CONTAINER_meta_data_destroy (alice_meta);
GNUNET_CONTAINER_meta_data_destroy (bob_meta);
GNUNET_CONTAINER_meta_data_destroy (carol_meta);
if (is_p2p)
- {
- GNUNET_DISK_directory_remove ("/tmp/gnunet-test-chat-peer-1/");
- GNUNET_DISK_directory_remove ("/tmp/gnunet-test-chat-peer-2/");
- GNUNET_DISK_directory_remove ("/tmp/gnunet-test-chat-peer-3/");
- }
+ {
+ GNUNET_DISK_directory_remove ("/tmp/gnunet-test-chat-peer-1/");
+ GNUNET_DISK_directory_remove ("/tmp/gnunet-test-chat-peer-2/");
+ GNUNET_DISK_directory_remove ("/tmp/gnunet-test-chat-peer-3/");
+ }
else
GNUNET_DISK_directory_remove ("/tmp/gnunet-test-chat/");
return err;
Modified: gnunet/src/core/core_api.c
===================================================================
--- gnunet/src/core/core_api.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/core/core_api.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -116,7 +116,7 @@
* SendMessageRequest ID generator for this peer.
*/
uint16_t smr_id_gen;
-
+
};
@@ -143,7 +143,7 @@
* Function to run after transmission failed/succeeded.
*/
GNUNET_CORE_ControlContinuation cont;
-
+
/**
* Closure for 'cont'.
*/
@@ -190,9 +190,9 @@
/**
* Function to call whenever we're notified about a peer changing status.
- */
+ */
GNUNET_CORE_PeerStatusEventHandler status_events;
-
+
/**
* Function to call whenever we receive an inbound message.
*/
@@ -371,8 +371,7 @@
*
* @param h our handle to the core service
*/
-static void
-reconnect (struct GNUNET_CORE_Handle *h);
+static void reconnect (struct GNUNET_CORE_Handle *h);
/**
@@ -382,15 +381,14 @@
* @param tc task 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_CORE_Handle *h = cls;
h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
#if DEBUG_CORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connecting to CORE service after delay\n");
+ "Connecting to CORE service after delay\n");
#endif
reconnect (h);
}
@@ -407,8 +405,7 @@
*/
static int
disconnect_and_free_peer_entry (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+ const GNUNET_HashCode * key, void *value)
{
static struct GNUNET_BANDWIDTH_Value32NBO zero;
struct GNUNET_CORE_Handle *h = cls;
@@ -418,61 +415,47 @@
void *pcic_cls;
if (pr->timeout_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (pr->timeout_task);
- pr->timeout_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (pr->timeout_task);
+ pr->timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ }
if (pr->ntr_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (pr->ntr_task);
- pr->ntr_task = GNUNET_SCHEDULER_NO_TASK;
- }
- if ( (pr->prev != NULL) ||
- (pr->next != NULL) ||
- (h->ready_peer_head == pr) )
- GNUNET_CONTAINER_DLL_remove (h->ready_peer_head,
- h->ready_peer_tail,
- pr);
+ {
+ GNUNET_SCHEDULER_cancel (pr->ntr_task);
+ pr->ntr_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ if ((pr->prev != NULL) || (pr->next != NULL) || (h->ready_peer_head == pr))
+ GNUNET_CONTAINER_DLL_remove (h->ready_peer_head, h->ready_peer_tail, pr);
if (h->disconnects != NULL)
- h->disconnects (h->cls,
- &pr->peer);
+ h->disconnects (h->cls, &pr->peer);
/* all requests should have been cancelled, clean up anyway, just in case */
GNUNET_break (pr->queue_size == 0);
if (NULL != (pcic = pr->pcic))
- {
- GNUNET_break (0);
- pcic_cls = pr->pcic_cls;
- GNUNET_CORE_peer_change_preference_cancel (pr->pcic_ptr);
- pcic (pcic_cls,
- &pr->peer,
- zero,
- 0,
- GNUNET_TIME_UNIT_FOREVER_REL,
- 0);
- }
+ {
+ GNUNET_break (0);
+ pcic_cls = pr->pcic_cls;
+ GNUNET_CORE_peer_change_preference_cancel (pr->pcic_ptr);
+ pcic (pcic_cls, &pr->peer, zero, 0, GNUNET_TIME_UNIT_FOREVER_REL, 0);
+ }
while (NULL != (th = pr->pending_head))
- {
- GNUNET_break (0);
- GNUNET_CONTAINER_DLL_remove (pr->pending_head,
- pr->pending_tail,
- th);
- pr->queue_size--;
- if (th->cm != NULL)
- th->cm->th = NULL;
- GNUNET_free (th);
- }
+ {
+ GNUNET_break (0);
+ GNUNET_CONTAINER_DLL_remove (pr->pending_head, pr->pending_tail, th);
+ pr->queue_size--;
+ if (th->cm != NULL)
+ th->cm->th = NULL;
+ GNUNET_free (th);
+ }
/* done with 'voluntary' cleanups, now on to normal freeing */
GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove (h->peers,
- key,
- pr));
+ GNUNET_CONTAINER_multihashmap_remove (h->peers, key, pr));
GNUNET_assert (pr->pending_head == NULL);
GNUNET_assert (pr->pending_tail == NULL);
GNUNET_assert (pr->ch = h);
GNUNET_assert (pr->queue_size == 0);
GNUNET_assert (pr->timeout_task == GNUNET_SCHEDULER_NO_TASK);
GNUNET_assert (pr->ntr_task == GNUNET_SCHEDULER_NO_TASK);
- GNUNET_free (pr);
+ GNUNET_free (pr);
return GNUNET_YES;
}
@@ -491,41 +474,36 @@
GNUNET_assert (h->reconnect_task == GNUNET_SCHEDULER_NO_TASK);
if (NULL != h->cth)
- {
- GNUNET_CLIENT_notify_transmit_ready_cancel (h->cth);
- h->cth = NULL;
- }
+ {
+ GNUNET_CLIENT_notify_transmit_ready_cancel (h->cth);
+ h->cth = NULL;
+ }
if (h->client != NULL)
- {
- GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
- h->client = NULL;
- }
+ {
+ GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
+ h->client = NULL;
+ }
h->currently_down = GNUNET_YES;
GNUNET_assert (h->reconnect_task == GNUNET_SCHEDULER_NO_TASK);
h->reconnect_task = GNUNET_SCHEDULER_add_delayed (h->retry_backoff,
- &reconnect_task,
- h);
+ &reconnect_task, h);
while (NULL != (cm = h->control_pending_head))
- {
- GNUNET_CONTAINER_DLL_remove (h->control_pending_head,
- h->control_pending_tail,
- cm);
- if (cm->th != NULL)
- cm->th->cm = NULL;
- if (cm->cont != NULL)
- cm->cont (cm->cont_cls, GNUNET_NO);
- GNUNET_free (cm);
- }
+ {
+ GNUNET_CONTAINER_DLL_remove (h->control_pending_head,
+ h->control_pending_tail, cm);
+ if (cm->th != NULL)
+ cm->th->cm = NULL;
+ if (cm->cont != NULL)
+ cm->cont (cm->cont_cls, GNUNET_NO);
+ GNUNET_free (cm);
+ }
GNUNET_CONTAINER_multihashmap_iterate (h->peers,
- &disconnect_and_free_peer_entry,
- h);
- while (NULL != (pr = h->ready_peer_head))
- GNUNET_CONTAINER_DLL_remove (h->ready_peer_head,
- h->ready_peer_tail,
- pr);
+ &disconnect_and_free_peer_entry, h);
+ while (NULL != (pr = h->ready_peer_head))
+ GNUNET_CONTAINER_DLL_remove (h->ready_peer_head, h->ready_peer_tail, pr);
GNUNET_assert (h->control_pending_head == NULL);
h->retry_backoff = GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_SECONDS,
- h->retry_backoff);
+ h->retry_backoff);
h->retry_backoff = GNUNET_TIME_relative_multiply (h->retry_backoff, 2);
}
@@ -538,8 +516,7 @@
* @param ignore_currently_down transmit message even if not initialized?
*/
static void
-trigger_next_request (struct GNUNET_CORE_Handle *h,
- int ignore_currently_down);
+trigger_next_request (struct GNUNET_CORE_Handle *h, int ignore_currently_down);
/**
@@ -550,8 +527,7 @@
* @param tc context, can be NULL (!)
*/
static void
-transmission_timeout (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+transmission_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext
*tc);
/**
@@ -569,27 +545,27 @@
struct GNUNET_CORE_TransmitHandle *th;
if (pr->timeout_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (pr->timeout_task);
- pr->timeout_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (pr->timeout_task);
+ pr->timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ }
if (NULL == (th = pr->pending_head))
- {
- trigger_next_request (h, GNUNET_NO);
- return;
- }
+ {
+ trigger_next_request (h, GNUNET_NO);
+ return;
+ }
if (th->cm != NULL)
- return; /* already done */
+ return; /* already done */
GNUNET_assert (pr->prev == NULL);
GNUNET_assert (pr->next == NULL);
- pr->timeout_task = GNUNET_SCHEDULER_add_delayed
(GNUNET_TIME_absolute_get_remaining (th->timeout),
- &transmission_timeout,
- pr);
- cm = GNUNET_malloc (sizeof (struct ControlMessage) +
- sizeof (struct SendMessageRequest));
+ pr->timeout_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
+ (th->timeout), &transmission_timeout, pr);
+ cm = GNUNET_malloc (sizeof (struct ControlMessage) +
+ sizeof (struct SendMessageRequest));
th->cm = cm;
cm->th = th;
- smr = (struct SendMessageRequest*) &cm[1];
+ smr = (struct SendMessageRequest *) &cm[1];
smr->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST);
smr->header.size = htons (sizeof (struct SendMessageRequest));
smr->priority = htonl (th->priority);
@@ -599,12 +575,11 @@
smr->size = htons (th->msize);
smr->smr_id = htons (th->smr_id = pr->smr_id_gen++);
GNUNET_CONTAINER_DLL_insert_tail (h->control_pending_head,
- h->control_pending_tail,
- cm);
+ h->control_pending_tail, cm);
#if DEBUG_CORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Adding SEND REQUEST for peer `%s' to message queue\n",
- GNUNET_i2s (&pr->peer));
+ "Adding SEND REQUEST for peer `%s' to message queue\n",
+ GNUNET_i2s (&pr->peer));
#endif
trigger_next_request (h, GNUNET_NO);
}
@@ -618,33 +593,26 @@
* @param tc context, can be NULL (!)
*/
static void
-transmission_timeout (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+transmission_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct PeerRecord *pr = cls;
struct GNUNET_CORE_Handle *h = pr->ch;
struct GNUNET_CORE_TransmitHandle *th;
-
+
pr->timeout_task = GNUNET_SCHEDULER_NO_TASK;
th = pr->pending_head;
- GNUNET_CONTAINER_DLL_remove (pr->pending_head,
- pr->pending_tail,
- th);
+ GNUNET_CONTAINER_DLL_remove (pr->pending_head, pr->pending_tail, th);
pr->queue_size--;
- if ( (pr->prev != NULL) ||
- (pr->next != NULL) ||
- (pr == h->ready_peer_head) )
- {
- /* the request that was 'approved' by core was
- canceled before it could be transmitted; remove
- us from the 'ready' list */
- GNUNET_CONTAINER_DLL_remove (h->ready_peer_head,
- h->ready_peer_tail,
- pr);
- }
+ if ((pr->prev != NULL) || (pr->next != NULL) || (pr == h->ready_peer_head))
+ {
+ /* the request that was 'approved' by core was
+ * canceled before it could be transmitted; remove
+ * us from the 'ready' list */
+ GNUNET_CONTAINER_DLL_remove (h->ready_peer_head, h->ready_peer_tail, pr);
+ }
#if DEBUG_CORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Signalling timeout of request for transmission to CORE
service\n");
+ "Signalling timeout of request for transmission to CORE
service\n");
#endif
request_next_transmission (pr);
GNUNET_assert (0 == th->get_message (th->get_message_cls, 0, NULL));
@@ -656,9 +624,7 @@
* Transmit the next message to the core service.
*/
static size_t
-transmit_message (void *cls,
- size_t size,
- void *buf)
+transmit_message (void *cls, size_t size, void *buf)
{
struct GNUNET_CORE_Handle *h = cls;
struct ControlMessage *cm;
@@ -672,117 +638,108 @@
GNUNET_assert (h->reconnect_task == GNUNET_SCHEDULER_NO_TASK);
h->cth = NULL;
if (buf == NULL)
- {
+ {
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmission failed, initiating reconnect\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Transmission failed, initiating reconnect\n");
#endif
- reconnect_later (h);
- return 0;
- }
+ reconnect_later (h);
+ return 0;
+ }
/* first check for control messages */
if (NULL != (cm = h->control_pending_head))
+ {
+ hdr = (const struct GNUNET_MessageHeader *) &cm[1];
+ msize = ntohs (hdr->size);
+ if (size < msize)
{
- hdr = (const struct GNUNET_MessageHeader*) &cm[1];
- msize = ntohs (hdr->size);
- if (size < msize)
- {
- trigger_next_request (h, GNUNET_NO);
- return 0;
- }
-#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitting control message with %u bytes of type %u to
core.\n",
- (unsigned int) msize,
- (unsigned int) ntohs (hdr->type));
-#endif
- memcpy (buf, hdr, msize);
- GNUNET_CONTAINER_DLL_remove (h->control_pending_head,
- h->control_pending_tail,
- cm);
- if (cm->th != NULL)
- cm->th->cm = NULL;
- if (NULL != cm->cont)
- cm->cont (cm->cont_cls, GNUNET_OK);
- GNUNET_free (cm);
trigger_next_request (h, GNUNET_NO);
- return msize;
+ return 0;
}
+#if DEBUG_CORE
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Transmitting control message with %u bytes of type %u to
core.\n",
+ (unsigned int) msize, (unsigned int) ntohs (hdr->type));
+#endif
+ memcpy (buf, hdr, msize);
+ GNUNET_CONTAINER_DLL_remove (h->control_pending_head,
+ h->control_pending_tail, cm);
+ if (cm->th != NULL)
+ cm->th->cm = NULL;
+ if (NULL != cm->cont)
+ cm->cont (cm->cont_cls, GNUNET_OK);
+ GNUNET_free (cm);
+ trigger_next_request (h, GNUNET_NO);
+ return msize;
+ }
/* now check for 'ready' P2P messages */
if (NULL != (pr = h->ready_peer_head))
+ {
+ GNUNET_assert (pr->pending_head != NULL);
+ th = pr->pending_head;
+ if (size < th->msize + sizeof (struct SendMessage))
{
- GNUNET_assert (pr->pending_head != NULL);
- th = pr->pending_head;
- if (size < th->msize + sizeof (struct SendMessage))
- {
- trigger_next_request (h, GNUNET_NO);
- return 0;
- }
- GNUNET_CONTAINER_DLL_remove (h->ready_peer_head,
- h->ready_peer_tail,
- pr);
- GNUNET_CONTAINER_DLL_remove (pr->pending_head,
- pr->pending_tail,
- th);
- pr->queue_size--;
- if (pr->timeout_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (pr->timeout_task);
- pr->timeout_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ trigger_next_request (h, GNUNET_NO);
+ return 0;
+ }
+ GNUNET_CONTAINER_DLL_remove (h->ready_peer_head, h->ready_peer_tail, pr);
+ GNUNET_CONTAINER_DLL_remove (pr->pending_head, pr->pending_tail, th);
+ pr->queue_size--;
+ if (pr->timeout_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (pr->timeout_task);
+ pr->timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ }
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitting SEND request to `%s' with %u bytes.\n",
- GNUNET_i2s (&pr->peer),
- (unsigned int) th->msize);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Transmitting SEND request to `%s' with %u bytes.\n",
+ GNUNET_i2s (&pr->peer), (unsigned int) th->msize);
#endif
- sm = (struct SendMessage *) buf;
- sm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_SEND);
- sm->priority = htonl (th->priority);
- sm->deadline = GNUNET_TIME_absolute_hton (th->timeout);
- sm->peer = pr->peer;
- sm->cork = htonl ((uint32_t) th->cork);
- sm->reserved = htonl (0);
- ret = th->get_message (th->get_message_cls,
- size - sizeof (struct SendMessage),
- &sm[1]);
-
+ sm = (struct SendMessage *) buf;
+ sm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_SEND);
+ sm->priority = htonl (th->priority);
+ sm->deadline = GNUNET_TIME_absolute_hton (th->timeout);
+ sm->peer = pr->peer;
+ sm->cork = htonl ((uint32_t) th->cork);
+ sm->reserved = htonl (0);
+ ret = th->get_message (th->get_message_cls,
+ size - sizeof (struct SendMessage), &sm[1]);
+
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitting SEND request to `%s' yielded %u bytes.\n",
- GNUNET_i2s (&pr->peer),
- ret);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Transmitting SEND request to `%s' yielded %u bytes.\n",
+ GNUNET_i2s (&pr->peer), ret);
#endif
- GNUNET_free (th);
- if (0 == ret)
- {
+ GNUNET_free (th);
+ if (0 == ret)
+ {
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Size of clients message to peer %s is 0!\n",
- GNUNET_i2s(&pr->peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Size of clients message to peer %s is 0!\n",
+ GNUNET_i2s (&pr->peer));
#endif
- /* client decided to send nothing! */
- request_next_transmission (pr);
- return 0;
- }
+ /* client decided to send nothing! */
+ request_next_transmission (pr);
+ return 0;
+ }
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Produced SEND message to core with %u bytes payload\n",
- (unsigned int) ret);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Produced SEND message to core with %u bytes payload\n",
+ (unsigned int) ret);
#endif
- GNUNET_assert (ret >= sizeof (struct GNUNET_MessageHeader));
- if (ret + sizeof (struct SendMessage) >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
- {
- GNUNET_break (0);
- request_next_transmission (pr);
- return 0;
- }
- ret += sizeof (struct SendMessage);
- sm->header.size = htons (ret);
- GNUNET_assert (ret <= size);
+ GNUNET_assert (ret >= sizeof (struct GNUNET_MessageHeader));
+ if (ret + sizeof (struct SendMessage) >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
+ {
+ GNUNET_break (0);
request_next_transmission (pr);
- return ret;
+ return 0;
}
+ ret += sizeof (struct SendMessage);
+ sm->header.size = htons (ret);
+ GNUNET_assert (ret <= size);
+ request_next_transmission (pr);
+ return ret;
+ }
return 0;
}
@@ -795,45 +752,46 @@
* @param ignore_currently_down transmit message even if not initialized?
*/
static void
-trigger_next_request (struct GNUNET_CORE_Handle *h,
- int ignore_currently_down)
+trigger_next_request (struct GNUNET_CORE_Handle *h, int ignore_currently_down)
{
uint16_t msize;
- if ( (GNUNET_YES == h->currently_down) &&
- (ignore_currently_down == GNUNET_NO) )
- {
+ if ((GNUNET_YES == h->currently_down) && (ignore_currently_down ==
GNUNET_NO))
+ {
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Core connection down, not processing queue\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Core connection down, not processing queue\n");
#endif
- return;
- }
+ return;
+ }
if (NULL != h->cth)
- {
+ {
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Request pending, not processing queue\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Request pending, not processing queue\n");
#endif
- return;
- }
+ return;
+ }
if (h->control_pending_head != NULL)
- msize = ntohs (((struct GNUNET_MessageHeader*)
&h->control_pending_head[1])->size);
- else if (h->ready_peer_head != NULL)
- msize = h->ready_peer_head->pending_head->msize + sizeof (struct
SendMessage);
+ msize =
+ ntohs (((struct GNUNET_MessageHeader *) &h->
+ control_pending_head[1])->size);
+ else if (h->ready_peer_head != NULL)
+ msize =
+ h->ready_peer_head->pending_head->msize + sizeof (struct SendMessage);
else
- {
+ {
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Request queue empty, not processing queue\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Request queue empty, not processing queue\n");
#endif
- return; /* no pending message */
- }
+ return; /* no pending message */
+ }
h->cth = GNUNET_CLIENT_notify_transmit_ready (h->client,
- msize,
- GNUNET_TIME_UNIT_FOREVER_REL,
- GNUNET_NO,
- &transmit_message, h);
+ msize,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_NO,
+ &transmit_message, h);
}
@@ -844,8 +802,7 @@
* @param msg the message received from the core service
*/
static void
-main_notify_handler (void *cls,
- const struct GNUNET_MessageHeader *msg)
+main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
{
struct GNUNET_CORE_Handle *h = cls;
const struct InitReplyMessage *m;
@@ -868,13 +825,13 @@
uint32_t ats_count;
if (msg == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _
- ("Client was disconnected from core service, trying to
reconnect.\n"));
- reconnect_later (h);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _
+ ("Client was disconnected from core service, trying to
reconnect.\n"));
+ reconnect_later (h);
+ return;
+ }
msize = ntohs (msg->size);
#if DEBUG_CORE > 2
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -882,425 +839,401 @@
ntohs (msg->type), msize);
#endif
switch (ntohs (msg->type))
+ {
+ case GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY:
+ if (ntohs (msg->size) != sizeof (struct InitReplyMessage))
{
- case GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY:
- if (ntohs (msg->size) != sizeof (struct InitReplyMessage))
- {
- GNUNET_break (0);
- reconnect_later (h);
- return;
- }
- m = (const struct InitReplyMessage *) msg;
- GNUNET_break (0 == ntohl (m->reserved));
- /* start our message processing loop */
- if (GNUNET_YES == h->currently_down)
- {
- h->currently_down = GNUNET_NO;
- trigger_next_request (h, GNUNET_NO);
- }
- h->retry_backoff = GNUNET_TIME_UNIT_MILLISECONDS;
- GNUNET_CRYPTO_hash (&m->publicKey,
- sizeof (struct
- GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
- &h->me.hashPubKey);
- if (NULL != (init = h->init))
- {
- /* mark so we don't call init on reconnect */
- h->init = NULL;
+ GNUNET_break (0);
+ reconnect_later (h);
+ return;
+ }
+ m = (const struct InitReplyMessage *) msg;
+ GNUNET_break (0 == ntohl (m->reserved));
+ /* start our message processing loop */
+ if (GNUNET_YES == h->currently_down)
+ {
+ h->currently_down = GNUNET_NO;
+ trigger_next_request (h, GNUNET_NO);
+ }
+ h->retry_backoff = GNUNET_TIME_UNIT_MILLISECONDS;
+ GNUNET_CRYPTO_hash (&m->publicKey,
+ sizeof (struct
+ GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+ &h->me.hashPubKey);
+ if (NULL != (init = h->init))
+ {
+ /* mark so we don't call init on reconnect */
+ h->init = NULL;
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connected to core service of peer `%s'.\n",
- GNUNET_i2s (&h->me));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Connected to core service of peer `%s'.\n",
+ GNUNET_i2s (&h->me));
#endif
- init (h->cls, h, &h->me, &m->publicKey);
- }
- else
- {
+ init (h->cls, h, &h->me, &m->publicKey);
+ }
+ else
+ {
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Successfully reconnected to core service.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Successfully reconnected to core service.\n");
#endif
- }
- /* fake 'connect to self' */
- pr = GNUNET_CONTAINER_multihashmap_get (h->peers,
- &h->me.hashPubKey);
- GNUNET_assert (pr == NULL);
- pr = GNUNET_malloc (sizeof (struct PeerRecord));
- pr->peer = h->me;
- pr->ch = h;
- GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_put (h->peers,
- &h->me.hashPubKey,
- pr,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
- if (NULL != h->connects)
- h->connects (h->cls,
- &h->me,
- NULL);
- break;
- case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT:
- if (msize < sizeof (struct ConnectNotifyMessage))
- {
- GNUNET_break (0);
- reconnect_later (h);
- return;
- }
- cnm = (const struct ConnectNotifyMessage *) msg;
- ats_count = ntohl (cnm->ats_count);
- if ( (msize != sizeof (struct ConnectNotifyMessage) + ats_count * sizeof
(struct GNUNET_TRANSPORT_ATS_Information)) ||
- (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR != ntohl
((&cnm->ats)[ats_count].type)) )
- {
- GNUNET_break (0);
- reconnect_later (h);
- return;
- }
+ }
+ /* fake 'connect to self' */
+ pr = GNUNET_CONTAINER_multihashmap_get (h->peers, &h->me.hashPubKey);
+ GNUNET_assert (pr == NULL);
+ pr = GNUNET_malloc (sizeof (struct PeerRecord));
+ pr->peer = h->me;
+ pr->ch = h;
+ GNUNET_assert (GNUNET_YES ==
+ GNUNET_CONTAINER_multihashmap_put (h->peers,
+ &h->me.hashPubKey,
+ pr,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
+ if (NULL != h->connects)
+ h->connects (h->cls, &h->me, NULL);
+ break;
+ case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT:
+ if (msize < sizeof (struct ConnectNotifyMessage))
+ {
+ GNUNET_break (0);
+ reconnect_later (h);
+ return;
+ }
+ cnm = (const struct ConnectNotifyMessage *) msg;
+ ats_count = ntohl (cnm->ats_count);
+ if ((msize !=
+ sizeof (struct ConnectNotifyMessage) +
+ ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)) ||
+ (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR !=
+ ntohl ((&cnm->ats)[ats_count].type)))
+ {
+ GNUNET_break (0);
+ reconnect_later (h);
+ return;
+ }
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received notification about connection from `%s'.\n",
- GNUNET_i2s (&cnm->peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received notification about connection from `%s'.\n",
+ GNUNET_i2s (&cnm->peer));
#endif
- if (0 == memcmp (&h->me,
- &cnm->peer,
- sizeof (struct GNUNET_PeerIdentity)))
- {
- /* connect to self!? */
- GNUNET_break (0);
- return;
- }
- pr = GNUNET_CONTAINER_multihashmap_get (h->peers,
- &cnm->peer.hashPubKey);
- if (pr != NULL)
- {
- GNUNET_break (0);
- reconnect_later (h);
- return;
- }
- pr = GNUNET_malloc (sizeof (struct PeerRecord));
- pr->peer = cnm->peer;
- pr->ch = h;
- GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_put (h->peers,
- &cnm->peer.hashPubKey,
- pr,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
- if (NULL != h->connects)
- h->connects (h->cls,
- &cnm->peer,
- &cnm->ats);
- break;
- case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT:
- if (msize != sizeof (struct DisconnectNotifyMessage))
- {
- GNUNET_break (0);
- reconnect_later (h);
- return;
- }
- dnm = (const struct DisconnectNotifyMessage *) msg;
- if (0 == memcmp (&h->me,
- &dnm->peer,
- sizeof (struct GNUNET_PeerIdentity)))
- {
- /* connection to self!? */
- GNUNET_break (0);
- return;
- }
- GNUNET_break (0 == ntohl (dnm->reserved));
+ if (0 == memcmp (&h->me, &cnm->peer, sizeof (struct GNUNET_PeerIdentity)))
+ {
+ /* connect to self!? */
+ GNUNET_break (0);
+ return;
+ }
+ pr = GNUNET_CONTAINER_multihashmap_get (h->peers, &cnm->peer.hashPubKey);
+ if (pr != NULL)
+ {
+ GNUNET_break (0);
+ reconnect_later (h);
+ return;
+ }
+ pr = GNUNET_malloc (sizeof (struct PeerRecord));
+ pr->peer = cnm->peer;
+ pr->ch = h;
+ GNUNET_assert (GNUNET_YES ==
+ GNUNET_CONTAINER_multihashmap_put (h->peers,
+ &cnm->peer.hashPubKey,
+ pr,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
+ if (NULL != h->connects)
+ h->connects (h->cls, &cnm->peer, &cnm->ats);
+ break;
+ case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT:
+ if (msize != sizeof (struct DisconnectNotifyMessage))
+ {
+ GNUNET_break (0);
+ reconnect_later (h);
+ return;
+ }
+ dnm = (const struct DisconnectNotifyMessage *) msg;
+ if (0 == memcmp (&h->me, &dnm->peer, sizeof (struct GNUNET_PeerIdentity)))
+ {
+ /* connection to self!? */
+ GNUNET_break (0);
+ return;
+ }
+ GNUNET_break (0 == ntohl (dnm->reserved));
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received notification about disconnect from `%s'.\n",
- GNUNET_i2s (&dnm->peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received notification about disconnect from `%s'.\n",
+ GNUNET_i2s (&dnm->peer));
#endif
- pr = GNUNET_CONTAINER_multihashmap_get (h->peers,
- &dnm->peer.hashPubKey);
- if (pr == NULL)
- {
- GNUNET_break (0);
- reconnect_later (h);
- return;
- }
- trigger = ( (pr->prev != NULL) ||
- (pr->next != NULL) ||
- (h->ready_peer_head == pr) );
- disconnect_and_free_peer_entry (h, &dnm->peer.hashPubKey, pr);
- if (trigger)
- trigger_next_request (h, GNUNET_NO);
- break;
- case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_STATUS_CHANGE:
- if (NULL == h->status_events)
- {
- GNUNET_break (0);
- return;
- }
- if (msize < sizeof (struct PeerStatusNotifyMessage))
- {
- GNUNET_break (0);
- reconnect_later (h);
- return;
- }
- psnm = (const struct PeerStatusNotifyMessage *) msg;
- if (0 == memcmp (&h->me,
- &psnm->peer,
- sizeof (struct GNUNET_PeerIdentity)))
- {
- /* self-change!? */
- GNUNET_break (0);
- return;
- }
- ats_count = ntohl (psnm->ats_count);
- if ( (msize != sizeof (struct PeerStatusNotifyMessage) + ats_count *
sizeof (struct GNUNET_TRANSPORT_ATS_Information)) ||
- (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR != ntohl
((&psnm->ats)[ats_count].type)) )
- {
- GNUNET_break (0);
- reconnect_later (h);
- return;
- }
+ pr = GNUNET_CONTAINER_multihashmap_get (h->peers, &dnm->peer.hashPubKey);
+ if (pr == NULL)
+ {
+ GNUNET_break (0);
+ reconnect_later (h);
+ return;
+ }
+ trigger = ((pr->prev != NULL) ||
+ (pr->next != NULL) || (h->ready_peer_head == pr));
+ disconnect_and_free_peer_entry (h, &dnm->peer.hashPubKey, pr);
+ if (trigger)
+ trigger_next_request (h, GNUNET_NO);
+ break;
+ case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_STATUS_CHANGE:
+ if (NULL == h->status_events)
+ {
+ GNUNET_break (0);
+ return;
+ }
+ if (msize < sizeof (struct PeerStatusNotifyMessage))
+ {
+ GNUNET_break (0);
+ reconnect_later (h);
+ return;
+ }
+ psnm = (const struct PeerStatusNotifyMessage *) msg;
+ if (0 == memcmp (&h->me, &psnm->peer, sizeof (struct GNUNET_PeerIdentity)))
+ {
+ /* self-change!? */
+ GNUNET_break (0);
+ return;
+ }
+ ats_count = ntohl (psnm->ats_count);
+ if ((msize !=
+ sizeof (struct PeerStatusNotifyMessage) +
+ ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)) ||
+ (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR !=
+ ntohl ((&psnm->ats)[ats_count].type)))
+ {
+ GNUNET_break (0);
+ reconnect_later (h);
+ return;
+ }
#if DEBUG_CORE > 1
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received notification about status change by `%s'.\n",
- GNUNET_i2s (&psnm->peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received notification about status change by `%s'.\n",
+ GNUNET_i2s (&psnm->peer));
#endif
- pr = GNUNET_CONTAINER_multihashmap_get (h->peers,
- &psnm->peer.hashPubKey);
- if (pr == NULL)
- {
- GNUNET_break (0);
- reconnect_later (h);
- return;
- }
- h->status_events (h->cls,
- &psnm->peer,
- psnm->bandwidth_in,
- psnm->bandwidth_out,
- GNUNET_TIME_absolute_ntoh (psnm->timeout),
- &psnm->ats);
- break;
- case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND:
- if (msize < sizeof (struct NotifyTrafficMessage))
- {
- GNUNET_break (0);
- reconnect_later (h);
- return;
- }
- ntm = (const struct NotifyTrafficMessage *) msg;
+ pr = GNUNET_CONTAINER_multihashmap_get (h->peers, &psnm->peer.hashPubKey);
+ if (pr == NULL)
+ {
+ GNUNET_break (0);
+ reconnect_later (h);
+ return;
+ }
+ h->status_events (h->cls,
+ &psnm->peer,
+ psnm->bandwidth_in,
+ psnm->bandwidth_out,
+ GNUNET_TIME_absolute_ntoh (psnm->timeout), &psnm->ats);
+ break;
+ case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND:
+ if (msize < sizeof (struct NotifyTrafficMessage))
+ {
+ GNUNET_break (0);
+ reconnect_later (h);
+ return;
+ }
+ ntm = (const struct NotifyTrafficMessage *) msg;
- ats_count = ntohl (ntm->ats_count);
- if ( (msize < sizeof (struct NotifyTrafficMessage) + ats_count * sizeof
(struct GNUNET_TRANSPORT_ATS_Information)
- + sizeof (struct GNUNET_MessageHeader)) ||
- (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR != ntohl
((&ntm->ats)[ats_count].type)) )
- {
- GNUNET_break (0);
- reconnect_later (h);
- return;
- }
- em = (const struct GNUNET_MessageHeader *) &(&ntm->ats)[ats_count+1];
+ ats_count = ntohl (ntm->ats_count);
+ if ((msize <
+ sizeof (struct NotifyTrafficMessage) +
+ ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information) +
+ sizeof (struct GNUNET_MessageHeader)) ||
+ (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR !=
+ ntohl ((&ntm->ats)[ats_count].type)))
+ {
+ GNUNET_break (0);
+ reconnect_later (h);
+ return;
+ }
+ em = (const struct GNUNET_MessageHeader *) &(&ntm->ats)[ats_count + 1];
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received message of type %u and size %u from peer `%4s'\n",
- ntohs (em->type),
- ntohs (em->size),
- GNUNET_i2s (&ntm->peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received message of type %u and size %u from peer `%4s'\n",
+ ntohs (em->type), ntohs (em->size), GNUNET_i2s (&ntm->peer));
#endif
- pr = GNUNET_CONTAINER_multihashmap_get (h->peers,
- &ntm->peer.hashPubKey);
- if (pr == NULL)
- {
- GNUNET_break (0);
- reconnect_later (h);
- return;
- }
- if ((GNUNET_NO == h->inbound_hdr_only) &&
- (msize != ntohs (em->size) + sizeof (struct NotifyTrafficMessage) +
- + ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)) )
- {
- GNUNET_break (0);
- reconnect_later (h);
- return;
- }
- et = ntohs (em->type);
- for (hpos = 0; hpos < h->hcnt; hpos++)
- {
- mh = &h->handlers[hpos];
- if (mh->type != et)
- continue;
- if ((mh->expected_size != ntohs (em->size)) &&
- (mh->expected_size != 0))
- {
- GNUNET_break (0);
- continue;
- }
- if (GNUNET_OK !=
- h->handlers[hpos].callback (h->cls, &ntm->peer, em,
- &ntm->ats))
- {
- /* error in processing, do not process other messages! */
- break;
- }
- }
- if (NULL != h->inbound_notify)
- h->inbound_notify (h->cls, &ntm->peer, em,
- &ntm->ats);
- break;
- case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND:
- if (msize < sizeof (struct NotifyTrafficMessage))
- {
- GNUNET_break (0);
- reconnect_later (h);
- return;
- }
- ntm = (const struct NotifyTrafficMessage *) msg;
- if (0 == memcmp (&h->me,
- &ntm->peer,
- sizeof (struct GNUNET_PeerIdentity)))
- {
- /* self-change!? */
- GNUNET_break (0);
- return;
- }
- ats_count = ntohl (ntm->ats_count);
- if ( (msize < sizeof (struct NotifyTrafficMessage) + ats_count * sizeof
(struct GNUNET_TRANSPORT_ATS_Information)
- + sizeof (struct GNUNET_MessageHeader)) ||
- (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR != ntohl
((&ntm->ats)[ats_count].type)) )
- {
- GNUNET_break (0);
- reconnect_later (h);
- return;
- }
- em = (const struct GNUNET_MessageHeader *) &(&ntm->ats)[ats_count+1];
- pr = GNUNET_CONTAINER_multihashmap_get (h->peers,
- &ntm->peer.hashPubKey);
- if (pr == NULL)
- {
- GNUNET_break (0);
- reconnect_later (h);
- return;
- }
+ pr = GNUNET_CONTAINER_multihashmap_get (h->peers, &ntm->peer.hashPubKey);
+ if (pr == NULL)
+ {
+ GNUNET_break (0);
+ reconnect_later (h);
+ return;
+ }
+ if ((GNUNET_NO == h->inbound_hdr_only) &&
+ (msize != ntohs (em->size) + sizeof (struct NotifyTrafficMessage) +
+ +ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)))
+ {
+ GNUNET_break (0);
+ reconnect_later (h);
+ return;
+ }
+ et = ntohs (em->type);
+ for (hpos = 0; hpos < h->hcnt; hpos++)
+ {
+ mh = &h->handlers[hpos];
+ if (mh->type != et)
+ continue;
+ if ((mh->expected_size != ntohs (em->size)) && (mh->expected_size != 0))
+ {
+ GNUNET_break (0);
+ continue;
+ }
+ if (GNUNET_OK !=
+ h->handlers[hpos].callback (h->cls, &ntm->peer, em, &ntm->ats))
+ {
+ /* error in processing, do not process other messages! */
+ break;
+ }
+ }
+ if (NULL != h->inbound_notify)
+ h->inbound_notify (h->cls, &ntm->peer, em, &ntm->ats);
+ break;
+ case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND:
+ if (msize < sizeof (struct NotifyTrafficMessage))
+ {
+ GNUNET_break (0);
+ reconnect_later (h);
+ return;
+ }
+ ntm = (const struct NotifyTrafficMessage *) msg;
+ if (0 == memcmp (&h->me, &ntm->peer, sizeof (struct GNUNET_PeerIdentity)))
+ {
+ /* self-change!? */
+ GNUNET_break (0);
+ return;
+ }
+ ats_count = ntohl (ntm->ats_count);
+ if ((msize <
+ sizeof (struct NotifyTrafficMessage) +
+ ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information) +
+ sizeof (struct GNUNET_MessageHeader)) ||
+ (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR !=
+ ntohl ((&ntm->ats)[ats_count].type)))
+ {
+ GNUNET_break (0);
+ reconnect_later (h);
+ return;
+ }
+ em = (const struct GNUNET_MessageHeader *) &(&ntm->ats)[ats_count + 1];
+ pr = GNUNET_CONTAINER_multihashmap_get (h->peers, &ntm->peer.hashPubKey);
+ if (pr == NULL)
+ {
+ GNUNET_break (0);
+ reconnect_later (h);
+ return;
+ }
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received notification about transmission to `%s'.\n",
- GNUNET_i2s (&ntm->peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received notification about transmission to `%s'.\n",
+ GNUNET_i2s (&ntm->peer));
#endif
- if ((GNUNET_NO == h->outbound_hdr_only) &&
- (msize != ntohs (em->size) + sizeof (struct NotifyTrafficMessage)
- + ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)) )
- {
- GNUNET_break (0);
- reconnect_later (h);
- return;
- }
- if (NULL == h->outbound_notify)
- {
- GNUNET_break (0);
- break;
- }
- h->outbound_notify (h->cls, &ntm->peer, em,
- &ntm->ats);
+ if ((GNUNET_NO == h->outbound_hdr_only) &&
+ (msize != ntohs (em->size) + sizeof (struct NotifyTrafficMessage)
+ + ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)))
+ {
+ GNUNET_break (0);
+ reconnect_later (h);
+ return;
+ }
+ if (NULL == h->outbound_notify)
+ {
+ GNUNET_break (0);
break;
- case GNUNET_MESSAGE_TYPE_CORE_SEND_READY:
- if (msize != sizeof (struct SendMessageReady))
- {
- GNUNET_break (0);
- reconnect_later (h);
- return;
- }
- smr = (const struct SendMessageReady *) msg;
- pr = GNUNET_CONTAINER_multihashmap_get (h->peers,
- &smr->peer.hashPubKey);
- if (pr == NULL)
- {
- GNUNET_break (0);
- reconnect_later (h);
- return;
- }
+ }
+ h->outbound_notify (h->cls, &ntm->peer, em, &ntm->ats);
+ break;
+ case GNUNET_MESSAGE_TYPE_CORE_SEND_READY:
+ if (msize != sizeof (struct SendMessageReady))
+ {
+ GNUNET_break (0);
+ reconnect_later (h);
+ return;
+ }
+ smr = (const struct SendMessageReady *) msg;
+ pr = GNUNET_CONTAINER_multihashmap_get (h->peers, &smr->peer.hashPubKey);
+ if (pr == NULL)
+ {
+ GNUNET_break (0);
+ reconnect_later (h);
+ return;
+ }
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received notification about transmission readiness to
`%s'.\n",
- GNUNET_i2s (&smr->peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received notification about transmission readiness to
`%s'.\n",
+ GNUNET_i2s (&smr->peer));
#endif
- if (pr->pending_head == NULL)
- {
- /* request must have been cancelled between the original request
- and the response from core, ignore core's readiness */
- break;
- }
+ if (pr->pending_head == NULL)
+ {
+ /* request must have been cancelled between the original request
+ * and the response from core, ignore core's readiness */
+ break;
+ }
- th = pr->pending_head;
- if (ntohs (smr->smr_id) != th->smr_id)
- {
- /* READY message is for expired or cancelled message,
- ignore! (we should have already sent another request) */
- break;
- }
- if ( (pr->prev != NULL) ||
- (pr->next != NULL) ||
- (h->ready_peer_head == pr) )
- {
- /* we should not already be on the ready list... */
- GNUNET_break (0);
- reconnect_later (h);
- return;
- }
- GNUNET_CONTAINER_DLL_insert (h->ready_peer_head,
- h->ready_peer_tail,
- pr);
- trigger_next_request (h, GNUNET_NO);
+ th = pr->pending_head;
+ if (ntohs (smr->smr_id) != th->smr_id)
+ {
+ /* READY message is for expired or cancelled message,
+ * ignore! (we should have already sent another request) */
break;
- case GNUNET_MESSAGE_TYPE_CORE_CONFIGURATION_INFO:
- if (ntohs (msg->size) != sizeof (struct ConfigurationInfoMessage))
- {
- GNUNET_break (0);
- reconnect_later (h);
- return;
- }
- cim = (const struct ConfigurationInfoMessage*) msg;
- if (0 == memcmp (&h->me,
- &cim->peer,
- sizeof (struct GNUNET_PeerIdentity)))
- {
- /* self-change!? */
- GNUNET_break (0);
- return;
- }
+ }
+ if ((pr->prev != NULL) || (pr->next != NULL) || (h->ready_peer_head == pr))
+ {
+ /* we should not already be on the ready list... */
+ GNUNET_break (0);
+ reconnect_later (h);
+ return;
+ }
+ GNUNET_CONTAINER_DLL_insert (h->ready_peer_head, h->ready_peer_tail, pr);
+ trigger_next_request (h, GNUNET_NO);
+ break;
+ case GNUNET_MESSAGE_TYPE_CORE_CONFIGURATION_INFO:
+ if (ntohs (msg->size) != sizeof (struct ConfigurationInfoMessage))
+ {
+ GNUNET_break (0);
+ reconnect_later (h);
+ return;
+ }
+ cim = (const struct ConfigurationInfoMessage *) msg;
+ if (0 == memcmp (&h->me, &cim->peer, sizeof (struct GNUNET_PeerIdentity)))
+ {
+ /* self-change!? */
+ GNUNET_break (0);
+ return;
+ }
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received notification about configuration update for `%s'
with RIM %u.\n",
- GNUNET_i2s (&cim->peer),
- (unsigned int) ntohl (cim->rim_id));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received notification about configuration update for `%s'
with RIM %u.\n",
+ GNUNET_i2s (&cim->peer), (unsigned int) ntohl (cim->rim_id));
#endif
- pr = GNUNET_CONTAINER_multihashmap_get (h->peers,
- &cim->peer.hashPubKey);
- if (pr == NULL)
- {
- GNUNET_break (0);
- reconnect_later (h);
- return;
- }
- if (pr->rim_id != ntohl (cim->rim_id))
- {
+ pr = GNUNET_CONTAINER_multihashmap_get (h->peers, &cim->peer.hashPubKey);
+ if (pr == NULL)
+ {
+ GNUNET_break (0);
+ reconnect_later (h);
+ return;
+ }
+ if (pr->rim_id != ntohl (cim->rim_id))
+ {
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Reservation ID mismatch in notification...\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Reservation ID mismatch in notification...\n");
#endif
- break;
- }
- pcic = pr->pcic;
- pr->pcic = NULL;
- GNUNET_free_non_null (pr->pcic_ptr);
- pr->pcic_ptr = NULL;
- if (pcic != NULL)
- pcic (pr->pcic_cls,
- &pr->peer,
- cim->bw_out,
- ntohl (cim->reserved_amount),
- GNUNET_TIME_relative_ntoh (cim->reserve_delay),
- GNUNET_ntohll (cim->preference));
break;
- default:
- reconnect_later (h);
- return;
}
+ pcic = pr->pcic;
+ pr->pcic = NULL;
+ GNUNET_free_non_null (pr->pcic_ptr);
+ pr->pcic_ptr = NULL;
+ if (pcic != NULL)
+ pcic (pr->pcic_cls,
+ &pr->peer,
+ cim->bw_out,
+ ntohl (cim->reserved_amount),
+ GNUNET_TIME_relative_ntoh (cim->reserve_delay),
+ GNUNET_ntohll (cim->preference));
+ break;
+ default:
+ reconnect_later (h);
+ return;
+ }
GNUNET_CLIENT_receive (h->client,
- &main_notify_handler, h,
- GNUNET_TIME_UNIT_FOREVER_REL);
+ &main_notify_handler, h,
GNUNET_TIME_UNIT_FOREVER_REL);
}
@@ -1312,27 +1245,24 @@
* @param success were we successful
*/
static void
-init_done_task (void *cls,
- int success)
+init_done_task (void *cls, int success)
{
struct GNUNET_CORE_Handle *h = cls;
if (success == GNUNET_SYSERR)
- return; /* shutdown */
+ return; /* shutdown */
if (success == GNUNET_NO)
- {
+ {
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Failed to exchange INIT with core, retrying\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to exchange INIT with core, retrying\n");
#endif
- if (h->reconnect_task == GNUNET_SCHEDULER_NO_TASK)
- reconnect_later (h);
- return;
- }
+ if (h->reconnect_task == GNUNET_SCHEDULER_NO_TASK)
+ reconnect_later (h);
+ return;
+ }
GNUNET_CLIENT_receive (h->client,
- &main_notify_handler,
- h,
- GNUNET_TIME_UNIT_FOREVER_REL);
+ &main_notify_handler, h,
GNUNET_TIME_UNIT_FOREVER_REL);
}
@@ -1353,49 +1283,46 @@
unsigned int hpos;
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Reconnecting to CORE service\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Reconnecting to CORE service\n");
#endif
GNUNET_assert (h->client == NULL);
GNUNET_assert (h->currently_down == GNUNET_YES);
h->client = GNUNET_CLIENT_connect ("core", h->cfg);
if (h->client == NULL)
- {
- reconnect_later (h);
- return;
- }
+ {
+ reconnect_later (h);
+ return;
+ }
msize = h->hcnt * sizeof (uint16_t) + sizeof (struct InitMessage);
- cm = GNUNET_malloc (sizeof (struct ControlMessage) +
- msize);
+ cm = GNUNET_malloc (sizeof (struct ControlMessage) + msize);
cm->cont = &init_done_task;
cm->cont_cls = h;
- init = (struct InitMessage*) &cm[1];
+ init = (struct InitMessage *) &cm[1];
init->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_INIT);
init->header.size = htons (msize);
opt = GNUNET_CORE_OPTION_SEND_CONNECT | GNUNET_CORE_OPTION_SEND_DISCONNECT;
if (h->status_events != NULL)
opt |= GNUNET_CORE_OPTION_SEND_STATUS_CHANGE;
if (h->inbound_notify != NULL)
- {
- if (h->inbound_hdr_only)
- opt |= GNUNET_CORE_OPTION_SEND_HDR_INBOUND;
- else
- opt |= GNUNET_CORE_OPTION_SEND_FULL_INBOUND;
- }
+ {
+ if (h->inbound_hdr_only)
+ opt |= GNUNET_CORE_OPTION_SEND_HDR_INBOUND;
+ else
+ opt |= GNUNET_CORE_OPTION_SEND_FULL_INBOUND;
+ }
if (h->outbound_notify != NULL)
- {
- if (h->outbound_hdr_only)
- opt |= GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND;
- else
- opt |= GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND;
- }
+ {
+ if (h->outbound_hdr_only)
+ opt |= GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND;
+ else
+ opt |= GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND;
+ }
init->options = htonl (opt);
- ts = (uint16_t *) &init[1];
+ ts = (uint16_t *) & init[1];
for (hpos = 0; hpos < h->hcnt; hpos++)
ts[hpos] = htons (h->handlers[hpos].type);
GNUNET_CONTAINER_DLL_insert (h->control_pending_head,
- h->control_pending_tail,
- cm);
+ h->control_pending_tail, cm);
trigger_next_request (h, GNUNET_YES);
}
@@ -1427,12 +1354,12 @@
*/
struct GNUNET_CORE_Handle *
GNUNET_CORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
- unsigned int queue_size,
+ unsigned int queue_size,
void *cls,
GNUNET_CORE_StartupCallback init,
GNUNET_CORE_ConnectEventHandler connects,
GNUNET_CORE_DisconnectEventHandler disconnects,
- GNUNET_CORE_PeerStatusEventHandler status_events,
+ GNUNET_CORE_PeerStatusEventHandler status_events,
GNUNET_CORE_MessageCallback inbound_notify,
int inbound_hdr_only,
GNUNET_CORE_MessageCallback outbound_notify,
@@ -1464,8 +1391,7 @@
(GNUNET_SERVER_MAX_MESSAGE_SIZE -
sizeof (struct InitMessage)) / sizeof (uint16_t));
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connecting to CORE service\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting to CORE service\n");
#endif
reconnect (h);
return h;
@@ -1483,40 +1409,38 @@
GNUNET_CORE_disconnect (struct GNUNET_CORE_Handle *handle)
{
struct ControlMessage *cm;
-
+
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Disconnecting from CORE service\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from CORE service\n");
#endif
if (handle->cth != NULL)
- {
- GNUNET_CLIENT_notify_transmit_ready_cancel (handle->cth);
- handle->cth = NULL;
- }
+ {
+ GNUNET_CLIENT_notify_transmit_ready_cancel (handle->cth);
+ handle->cth = NULL;
+ }
while (NULL != (cm = handle->control_pending_head))
- {
- GNUNET_CONTAINER_DLL_remove (handle->control_pending_head,
- handle->control_pending_tail,
- cm);
- if (cm->th != NULL)
- cm->th->cm = NULL;
- if (cm->cont != NULL)
- cm->cont (cm->cont_cls, GNUNET_SYSERR);
- GNUNET_free (cm);
- }
+ {
+ GNUNET_CONTAINER_DLL_remove (handle->control_pending_head,
+ handle->control_pending_tail, cm);
+ if (cm->th != NULL)
+ cm->th->cm = NULL;
+ if (cm->cont != NULL)
+ cm->cont (cm->cont_cls, GNUNET_SYSERR);
+ GNUNET_free (cm);
+ }
if (handle->client != NULL)
- {
- GNUNET_CLIENT_disconnect (handle->client, GNUNET_NO);
- handle->client = NULL;
- }
+ {
+ GNUNET_CLIENT_disconnect (handle->client, GNUNET_NO);
+ handle->client = NULL;
+ }
GNUNET_CONTAINER_multihashmap_iterate (handle->peers,
- &disconnect_and_free_peer_entry,
- handle);
+ &disconnect_and_free_peer_entry,
+ handle);
if (handle->reconnect_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (handle->reconnect_task);
- handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (handle->reconnect_task);
+ handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
+ }
GNUNET_CONTAINER_multihashmap_destroy (handle->peers);
handle->peers = NULL;
GNUNET_break (handle->ready_peer_head == NULL);
@@ -1532,7 +1456,7 @@
*/
static void
run_request_next_transmission (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct PeerRecord *pr = cls;
@@ -1562,7 +1486,7 @@
*/
struct GNUNET_CORE_TransmitHandle *
GNUNET_CORE_notify_transmit_ready (struct GNUNET_CORE_Handle *handle,
- int cork,
+ int cork,
uint32_t priority,
struct GNUNET_TIME_Relative maxdelay,
const struct GNUNET_PeerIdentity *target,
@@ -1576,22 +1500,21 @@
struct GNUNET_CORE_TransmitHandle *prev;
struct GNUNET_CORE_TransmitHandle *minp;
- pr = GNUNET_CONTAINER_multihashmap_get (handle->peers,
- &target->hashPubKey);
+ pr = GNUNET_CONTAINER_multihashmap_get (handle->peers, &target->hashPubKey);
if (NULL == pr)
- {
- /* attempt to send to peer that is not connected */
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
- "Attempting to send to peer `%s' from peer `%s', but not
connected!\n",
- GNUNET_i2s(target), GNUNET_h2s(&handle->me.hashPubKey));
- GNUNET_break (0);
- return NULL;
- }
+ {
+ /* attempt to send to peer that is not connected */
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Attempting to send to peer `%s' from peer `%s', but not
connected!\n",
+ GNUNET_i2s (target), GNUNET_h2s (&handle->me.hashPubKey));
+ GNUNET_break (0);
+ return NULL;
+ }
GNUNET_assert (notify_size + sizeof (struct SendMessage) <
GNUNET_SERVER_MAX_MESSAGE_SIZE);
th = GNUNET_malloc (sizeof (struct GNUNET_CORE_TransmitHandle));
th->peer = pr;
- GNUNET_assert(NULL != notify);
+ GNUNET_assert (NULL != notify);
th->get_message = notify;
th->get_message_cls = notify_cls;
th->timeout = GNUNET_TIME_relative_to_absolute (maxdelay);
@@ -1600,81 +1523,72 @@
th->cork = cork;
/* bound queue size */
if (pr->queue_size == handle->queue_size)
+ {
+ /* find lowest-priority entry, but skip the head of the list */
+ minp = pr->pending_head->next;
+ prev = minp;
+ while (prev != NULL)
{
- /* find lowest-priority entry, but skip the head of the list */
- minp = pr->pending_head->next;
- prev = minp;
- while (prev != NULL)
- {
- if (prev->priority < minp->priority)
- minp = prev;
- prev = prev->next;
- }
- if (minp == NULL)
- {
- GNUNET_break (handle->queue_size != 0);
- GNUNET_break (pr->queue_size == 1);
- GNUNET_free(th);
+ if (prev->priority < minp->priority)
+ minp = prev;
+ prev = prev->next;
+ }
+ if (minp == NULL)
+ {
+ GNUNET_break (handle->queue_size != 0);
+ GNUNET_break (pr->queue_size == 1);
+ GNUNET_free (th);
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Dropping transmission request: cannot drop queue head
and limit is one\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Dropping transmission request: cannot drop queue head and
limit is one\n");
#endif
- return NULL;
- }
- if (priority <= minp->priority)
- {
+ return NULL;
+ }
+ if (priority <= minp->priority)
+ {
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Dropping transmission request: priority too low\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Dropping transmission request: priority too low\n");
#endif
- GNUNET_free(th);
- return NULL; /* priority too low */
- }
- GNUNET_CONTAINER_DLL_remove (pr->pending_head,
- pr->pending_tail,
- minp);
- pr->queue_size--;
- GNUNET_assert (0 ==
- minp->get_message (minp->get_message_cls,
- 0, NULL));
- GNUNET_free (minp);
+ GNUNET_free (th);
+ return NULL; /* priority too low */
}
+ GNUNET_CONTAINER_DLL_remove (pr->pending_head, pr->pending_tail, minp);
+ pr->queue_size--;
+ GNUNET_assert (0 == minp->get_message (minp->get_message_cls, 0, NULL));
+ GNUNET_free (minp);
+ }
/* Order entries by deadline, but SKIP 'HEAD' if
- we're in the 'ready_peer_*' DLL */
+ * we're in the 'ready_peer_*' DLL */
pos = pr->pending_head;
- if ( (pr->prev != NULL) ||
- (pr->next != NULL) ||
- (pr == handle->ready_peer_head) )
- {
- GNUNET_assert (pos != NULL);
- pos = pos->next; /* skip head */
- }
+ if ((pr->prev != NULL) ||
+ (pr->next != NULL) || (pr == handle->ready_peer_head))
+ {
+ GNUNET_assert (pos != NULL);
+ pos = pos->next; /* skip head */
+ }
/* insertion sort */
prev = pos;
- while ( (pos != NULL) &&
- (pos->timeout.abs_value < th->timeout.abs_value) )
- {
- prev = pos;
- pos = pos->next;
- }
+ while ((pos != NULL) && (pos->timeout.abs_value < th->timeout.abs_value))
+ {
+ prev = pos;
+ pos = pos->next;
+ }
GNUNET_CONTAINER_DLL_insert_after (pr->pending_head,
- pr->pending_tail,
- prev,
- th);
+ pr->pending_tail, prev, th);
pr->queue_size++;
/* was the request queue previously empty? */
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmission request added to queue\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmission request added to
queue\n");
#endif
- if ( (pr->pending_head == th) &&
- (pr->ntr_task == GNUNET_SCHEDULER_NO_TASK) &&
- (pr->next == NULL) &&
- (pr->prev == NULL) &&
- (handle->ready_peer_head != pr) )
- pr->ntr_task = GNUNET_SCHEDULER_add_now (&run_request_next_transmission,
pr);
+ if ((pr->pending_head == th) &&
+ (pr->ntr_task == GNUNET_SCHEDULER_NO_TASK) &&
+ (pr->next == NULL) &&
+ (pr->prev == NULL) && (handle->ready_peer_head != pr))
+ pr->ntr_task =
+ GNUNET_SCHEDULER_add_now (&run_request_next_transmission, pr);
return th;
}
@@ -1685,42 +1599,34 @@
* @param th handle that was returned by "notify_transmit_ready".
*/
void
-GNUNET_CORE_notify_transmit_ready_cancel (struct GNUNET_CORE_TransmitHandle
- *th)
+GNUNET_CORE_notify_transmit_ready_cancel (struct GNUNET_CORE_TransmitHandle
*th)
{
struct PeerRecord *pr = th->peer;
struct GNUNET_CORE_Handle *h = pr->ch;
int was_head;
was_head = (pr->pending_head == th);
- GNUNET_CONTAINER_DLL_remove (pr->pending_head,
- pr->pending_tail,
- th);
+ GNUNET_CONTAINER_DLL_remove (pr->pending_head, pr->pending_tail, th);
pr->queue_size--;
if (th->cm != NULL)
- {
- /* we're currently in the control queue, remove */
- GNUNET_CONTAINER_DLL_remove (h->control_pending_head,
- h->control_pending_tail,
- th->cm);
- GNUNET_free (th->cm);
- }
+ {
+ /* we're currently in the control queue, remove */
+ GNUNET_CONTAINER_DLL_remove (h->control_pending_head,
+ h->control_pending_tail, th->cm);
+ GNUNET_free (th->cm);
+ }
GNUNET_free (th);
if (was_head)
+ {
+ if ((pr->prev != NULL) || (pr->next != NULL) || (pr == h->ready_peer_head))
{
- if ( (pr->prev != NULL) ||
- (pr->next != NULL) ||
- (pr == h->ready_peer_head) )
- {
- /* the request that was 'approved' by core was
- canceled before it could be transmitted; remove
- us from the 'ready' list */
- GNUNET_CONTAINER_DLL_remove (h->ready_peer_head,
- h->ready_peer_tail,
- pr);
- }
- request_next_transmission (pr);
+ /* the request that was 'approved' by core was
+ * canceled before it could be transmitted; remove
+ * us from the 'ready' list */
+ GNUNET_CONTAINER_DLL_remove (h->ready_peer_head, h->ready_peer_tail, pr);
}
+ request_next_transmission (pr);
+ }
}
@@ -1766,13 +1672,12 @@
* @param success was the request transmitted?
*/
static void
-peer_request_connect_cont (void *cls,
- int success)
+peer_request_connect_cont (void *cls, int success)
{
struct GNUNET_CORE_PeerRequestHandle *ret = cls;
-
+
if (ret->cont != NULL)
- ret->cont (ret->cont_cls, success);
+ ret->cont (ret->cont_cls, success);
GNUNET_free (ret);
}
@@ -1798,34 +1703,31 @@
*/
struct GNUNET_CORE_PeerRequestHandle *
GNUNET_CORE_peer_request_connect (struct GNUNET_CORE_Handle *h,
- const struct GNUNET_PeerIdentity * peer,
- GNUNET_CORE_ControlContinuation cont,
- void *cont_cls)
+ const struct GNUNET_PeerIdentity *peer,
+ GNUNET_CORE_ControlContinuation cont,
+ void *cont_cls)
{
struct GNUNET_CORE_PeerRequestHandle *ret;
struct ControlMessage *cm;
struct ConnectMessage *msg;
- if (NULL != GNUNET_CONTAINER_multihashmap_get (h->peers,
- &peer->hashPubKey))
- {
+ if (NULL != GNUNET_CONTAINER_multihashmap_get (h->peers, &peer->hashPubKey))
+ {
#if DEBUG_CORE
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Peers are already connected!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers are already connected!\n");
#endif
- return NULL;
- }
-
- cm = GNUNET_malloc (sizeof (struct ControlMessage) +
- sizeof (struct ConnectMessage));
- msg = (struct ConnectMessage*) &cm[1];
+ return NULL;
+ }
+
+ cm = GNUNET_malloc (sizeof (struct ControlMessage) +
+ sizeof (struct ConnectMessage));
+ msg = (struct ConnectMessage *) &cm[1];
msg->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_REQUEST_CONNECT);
msg->header.size = htons (sizeof (struct ConnectMessage));
msg->reserved = htonl (0);
msg->peer = *peer;
GNUNET_CONTAINER_DLL_insert_tail (h->control_pending_head,
- h->control_pending_tail,
- cm);
+ h->control_pending_tail, cm);
ret = GNUNET_malloc (sizeof (struct GNUNET_CORE_PeerRequestHandle));
ret->h = h;
ret->cm = cm;
@@ -1834,8 +1736,7 @@
cm->cont = &peer_request_connect_cont;
cm->cont_cls = ret;
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Queueing REQUEST_CONNECT request\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Queueing REQUEST_CONNECT request\n");
#endif
trigger_next_request (h, GNUNET_NO);
return ret;
@@ -1849,18 +1750,18 @@
* @param req request handle that was returned for the original request
*/
void
-GNUNET_CORE_peer_request_connect_cancel (struct GNUNET_CORE_PeerRequestHandle
*req)
+GNUNET_CORE_peer_request_connect_cancel (struct GNUNET_CORE_PeerRequestHandle
+ *req)
{
struct GNUNET_CORE_Handle *h = req->h;
struct ControlMessage *cm = req->cm;
#if DEBUG_CORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "A CHANGE PREFERENCE request was cancelled!\n");
+ "A CHANGE PREFERENCE request was cancelled!\n");
#endif
GNUNET_CONTAINER_DLL_remove (h->control_pending_head,
- h->control_pending_tail,
- cm);
+ h->control_pending_tail, cm);
GNUNET_free (cm);
GNUNET_free (req);
}
@@ -1869,9 +1770,9 @@
/* ****************** GNUNET_CORE_peer_change_preference ********************
*/
-struct GNUNET_CORE_InformationRequestContext
+struct GNUNET_CORE_InformationRequestContext
{
-
+
/**
* Our connection to the service.
*/
@@ -1879,7 +1780,7 @@
/**
* Link to control message, NULL if CM was sent.
- */
+ */
struct ControlMessage *cm;
/**
@@ -1896,8 +1797,7 @@
* @param success were we successful?
*/
static void
-change_preference_send_continuation (void *cls,
- int success)
+change_preference_send_continuation (void *cls, int success)
{
struct GNUNET_CORE_InformationRequestContext *irc = cls;
@@ -1931,61 +1831,58 @@
*/
struct GNUNET_CORE_InformationRequestContext *
GNUNET_CORE_peer_change_preference (struct GNUNET_CORE_Handle *h,
- const struct GNUNET_PeerIdentity *peer,
- struct GNUNET_TIME_Relative timeout,
- struct GNUNET_BANDWIDTH_Value32NBO bw_out,
- int32_t amount,
- uint64_t preference,
- GNUNET_CORE_PeerConfigurationInfoCallback
info,
- void *info_cls)
+ const struct GNUNET_PeerIdentity *peer,
+ struct GNUNET_TIME_Relative timeout,
+ struct GNUNET_BANDWIDTH_Value32NBO bw_out,
+ int32_t amount,
+ uint64_t preference,
+ GNUNET_CORE_PeerConfigurationInfoCallback
+ info, void *info_cls)
{
struct GNUNET_CORE_InformationRequestContext *irc;
struct PeerRecord *pr;
struct RequestInfoMessage *rim;
struct ControlMessage *cm;
- pr = GNUNET_CONTAINER_multihashmap_get (h->peers,
- &peer->hashPubKey);
+ pr = GNUNET_CONTAINER_multihashmap_get (h->peers, &peer->hashPubKey);
if (NULL == pr)
- {
- /* attempt to change preference on peer that is not connected */
- GNUNET_assert (0);
- return NULL;
- }
+ {
+ /* attempt to change preference on peer that is not connected */
+ GNUNET_assert (0);
+ return NULL;
+ }
if (pr->pcic != NULL)
- {
- /* second change before first one is done */
- GNUNET_break (0);
- return NULL;
- }
+ {
+ /* second change before first one is done */
+ GNUNET_break (0);
+ return NULL;
+ }
irc = GNUNET_malloc (sizeof (struct GNUNET_CORE_InformationRequestContext));
irc->h = h;
irc->pr = pr;
cm = GNUNET_malloc (sizeof (struct ControlMessage) +
- sizeof (struct RequestInfoMessage));
+ sizeof (struct RequestInfoMessage));
cm->cont = &change_preference_send_continuation;
cm->cont_cls = irc;
irc->cm = cm;
- rim = (struct RequestInfoMessage*) &cm[1];
+ rim = (struct RequestInfoMessage *) &cm[1];
rim->header.size = htons (sizeof (struct RequestInfoMessage));
rim->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_REQUEST_INFO);
rim->rim_id = htonl (pr->rim_id = h->rim_id_gen++);
rim->limit_outbound = bw_out;
rim->reserve_inbound = htonl (amount);
- rim->preference_change = GNUNET_htonll(preference);
+ rim->preference_change = GNUNET_htonll (preference);
rim->peer = *peer;
#if DEBUG_CORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Queueing CHANGE PREFERENCE request for peer `%s' with RIM %u\n",
- GNUNET_i2s (peer),
- (unsigned int) pr->rim_id);
+ "Queueing CHANGE PREFERENCE request for peer `%s' with RIM %u\n",
+ GNUNET_i2s (peer), (unsigned int) pr->rim_id);
#endif
GNUNET_CONTAINER_DLL_insert_tail (h->control_pending_head,
- h->control_pending_tail,
- cm);
+ h->control_pending_tail, cm);
pr->pcic = info;
pr->pcic_cls = info_cls;
- pr->pcic_ptr = irc; /* for free'ing irc */
+ pr->pcic_ptr = irc; /* for free'ing irc */
if (NULL != h->client)
trigger_next_request (h, GNUNET_NO);
return irc;
@@ -2004,19 +1901,20 @@
* @param irc context returned by the original GNUNET_CORE_peer_get_info call
*/
void
-GNUNET_CORE_peer_change_preference_cancel (struct
GNUNET_CORE_InformationRequestContext *irc)
+GNUNET_CORE_peer_change_preference_cancel (struct
+
GNUNET_CORE_InformationRequestContext
+ *irc)
{
struct GNUNET_CORE_Handle *h = irc->h;
struct PeerRecord *pr = irc->pr;
GNUNET_assert (pr->pcic_ptr == irc);
if (irc->cm != NULL)
- {
- GNUNET_CONTAINER_DLL_remove (h->control_pending_head,
- h->control_pending_tail,
- irc->cm);
- GNUNET_free (irc->cm);
- }
+ {
+ GNUNET_CONTAINER_DLL_remove (h->control_pending_head,
+ h->control_pending_tail, irc->cm);
+ GNUNET_free (irc->cm);
+ }
pr->pcic = NULL;
pr->pcic_cls = NULL;
pr->pcic_ptr = NULL;
Modified: gnunet/src/core/core_api_iterate_peers.c
===================================================================
--- gnunet/src/core/core_api_iterate_peers.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/core/core_api_iterate_peers.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -66,8 +66,7 @@
* @param msg NULL on error or last entry
*/
static void
-receive_info (void *cls,
- const struct GNUNET_MessageHeader *msg)
+receive_info (void *cls, const struct GNUNET_MessageHeader *msg)
{
struct GNUNET_CORE_RequestContext *request_context = cls;
const struct ConnectNotifyMessage *connect_message;
@@ -75,53 +74,51 @@
uint16_t msize;
/* Handle last message or error case, disconnect and clean up */
- if ( (msg == NULL) ||
+ if ((msg == NULL) ||
((ntohs (msg->type) == GNUNET_MESSAGE_TYPE_CORE_ITERATE_PEERS_END) &&
- (ntohs (msg->size) == sizeof (struct GNUNET_MessageHeader))) )
- {
- if (request_context->peer_cb != NULL)
- request_context->peer_cb (request_context->cb_cls,
- NULL, NULL);
- GNUNET_CLIENT_disconnect (request_context->client, GNUNET_NO);
- GNUNET_free (request_context);
- return;
- }
+ (ntohs (msg->size) == sizeof (struct GNUNET_MessageHeader))))
+ {
+ if (request_context->peer_cb != NULL)
+ request_context->peer_cb (request_context->cb_cls, NULL, NULL);
+ GNUNET_CLIENT_disconnect (request_context->client, GNUNET_NO);
+ GNUNET_free (request_context);
+ return;
+ }
msize = ntohs (msg->size);
/* Handle incorrect message type or size, disconnect and clean up */
- if ( (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT) ||
- (msize < sizeof (struct ConnectNotifyMessage)) )
- {
- GNUNET_break (0);
- if (request_context->peer_cb != NULL)
- request_context->peer_cb (request_context->cb_cls,
- NULL, NULL);
- GNUNET_CLIENT_disconnect (request_context->client, GNUNET_NO);
- GNUNET_free (request_context);
- return;
- }
+ if ((ntohs (msg->type) != GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT) ||
+ (msize < sizeof (struct ConnectNotifyMessage)))
+ {
+ GNUNET_break (0);
+ if (request_context->peer_cb != NULL)
+ request_context->peer_cb (request_context->cb_cls, NULL, NULL);
+ GNUNET_CLIENT_disconnect (request_context->client, GNUNET_NO);
+ GNUNET_free (request_context);
+ return;
+ }
connect_message = (const struct ConnectNotifyMessage *) msg;
ats_count = ntohl (connect_message->ats_count);
- if ( (msize != sizeof (struct ConnectNotifyMessage) + ats_count * sizeof
(struct GNUNET_TRANSPORT_ATS_Information)) ||
- (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR != ntohl
((&connect_message->ats)[ats_count].type)) )
- {
- GNUNET_break (0);
- if (request_context->peer_cb != NULL)
- request_context->peer_cb (request_context->cb_cls,
- NULL, NULL);
- GNUNET_CLIENT_disconnect (request_context->client, GNUNET_NO);
- GNUNET_free (request_context);
- return;
- }
+ if ((msize !=
+ sizeof (struct ConnectNotifyMessage) +
+ ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)) ||
+ (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR !=
+ ntohl ((&connect_message->ats)[ats_count].type)))
+ {
+ GNUNET_break (0);
+ if (request_context->peer_cb != NULL)
+ request_context->peer_cb (request_context->cb_cls, NULL, NULL);
+ GNUNET_CLIENT_disconnect (request_context->client, GNUNET_NO);
+ GNUNET_free (request_context);
+ return;
+ }
/* Normal case */
if (request_context->peer_cb != NULL)
request_context->peer_cb (request_context->cb_cls,
- &connect_message->peer,
- &connect_message->ats);
- GNUNET_CLIENT_receive(request_context->client,
- &receive_info,
- request_context,
- GNUNET_TIME_UNIT_FOREVER_REL);
+ &connect_message->peer, &connect_message->ats);
+ GNUNET_CLIENT_receive (request_context->client,
+ &receive_info,
+ request_context, GNUNET_TIME_UNIT_FOREVER_REL);
}
/**
@@ -136,28 +133,29 @@
* @return number of bytes written to buf
*/
static size_t
-transmit_request(void *cls,
- size_t size, void *buf)
+transmit_request (void *cls, size_t size, void *buf)
{
struct GNUNET_MessageHeader *msg;
struct GNUNET_PeerIdentity *peer = cls;
int msize;
if (peer == NULL)
- msize = sizeof(struct GNUNET_MessageHeader);
+ msize = sizeof (struct GNUNET_MessageHeader);
else
- msize = sizeof(struct GNUNET_MessageHeader) + sizeof(struct
GNUNET_PeerIdentity);
+ msize =
+ sizeof (struct GNUNET_MessageHeader) +
+ sizeof (struct GNUNET_PeerIdentity);
if ((size < msize) || (buf == NULL))
return 0;
- msg = (struct GNUNET_MessageHeader *)buf;
+ msg = (struct GNUNET_MessageHeader *) buf;
msg->size = htons (msize);
if (peer != NULL)
- {
- msg->type = htons (GNUNET_MESSAGE_TYPE_CORE_PEER_CONNECTED);
- memcpy(&msg[1], peer, sizeof(struct GNUNET_PeerIdentity));
- }
+ {
+ msg->type = htons (GNUNET_MESSAGE_TYPE_CORE_PEER_CONNECTED);
+ memcpy (&msg[1], peer, sizeof (struct GNUNET_PeerIdentity));
+ }
else
msg->type = htons (GNUNET_MESSAGE_TYPE_CORE_ITERATE_PEERS);
@@ -189,21 +187,26 @@
client = GNUNET_CLIENT_connect ("core", cfg);
if (client == NULL)
return GNUNET_SYSERR;
- GNUNET_assert(peer != NULL);
+ GNUNET_assert (peer != NULL);
request_context = GNUNET_malloc (sizeof (struct GNUNET_CORE_RequestContext));
request_context->client = client;
request_context->peer_cb = peer_cb;
request_context->cb_cls = cb_cls;
request_context->peer = peer;
- request_context->th = GNUNET_CLIENT_notify_transmit_ready(client,
- sizeof(struct
GNUNET_MessageHeader) + sizeof(struct GNUNET_PeerIdentity),
-
GNUNET_TIME_relative_get_forever(),
- GNUNET_YES,
- &transmit_request,
- peer);
- GNUNET_assert(request_context->th != NULL);
- GNUNET_CLIENT_receive(client, &receive_info, request_context,
GNUNET_TIME_relative_get_forever());
+ request_context->th = GNUNET_CLIENT_notify_transmit_ready (client,
+ sizeof (struct
+
GNUNET_MessageHeader)
+ +
+ sizeof (struct
+
GNUNET_PeerIdentity),
+
GNUNET_TIME_relative_get_forever
+ (), GNUNET_YES,
+ &transmit_request,
+ peer);
+ GNUNET_assert (request_context->th != NULL);
+ GNUNET_CLIENT_receive (client, &receive_info, request_context,
+ GNUNET_TIME_relative_get_forever ());
return GNUNET_OK;
}
@@ -235,14 +238,16 @@
request_context->peer_cb = peer_cb;
request_context->cb_cls = cb_cls;
- request_context->th = GNUNET_CLIENT_notify_transmit_ready(client,
- sizeof(struct
GNUNET_MessageHeader),
-
GNUNET_TIME_relative_get_forever(),
- GNUNET_YES,
- &transmit_request,
- NULL);
+ request_context->th = GNUNET_CLIENT_notify_transmit_ready (client,
+ sizeof (struct
+
GNUNET_MessageHeader),
+
GNUNET_TIME_relative_get_forever
+ (), GNUNET_YES,
+ &transmit_request,
+ NULL);
- GNUNET_CLIENT_receive(client, &receive_info, request_context,
GNUNET_TIME_relative_get_forever());
+ GNUNET_CLIENT_receive (client, &receive_info, request_context,
+ GNUNET_TIME_relative_get_forever ());
return GNUNET_OK;
}
Modified: gnunet/src/core/gnunet-core-list-connections.c
===================================================================
--- gnunet/src/core/gnunet-core-list-connections.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/core/gnunet-core-list-connections.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -36,7 +36,7 @@
static int no_resolve;
#if VERBOSE
- static unsigned int peer_count;
+static unsigned int peer_count;
#endif
static const struct GNUNET_CONFIGURATION_Handle *cfg;
@@ -74,15 +74,15 @@
struct AddressStringList *address;
GNUNET_CRYPTO_hash_to_enc (&pc->peer.hashPubKey, &enc);
- printf (_("Peer `%s'\n"),
- (const char *) &enc);
+ printf (_("Peer `%s'\n"), (const char *) &enc);
while (NULL != (address = pc->address_list_head))
- {
- printf ("\t%s\n", address->address_string);
- GNUNET_free(address->address_string);
- GNUNET_CONTAINER_DLL_remove(pc->address_list_head,
pc->address_list_tail, address);
- GNUNET_free(address);
- }
+ {
+ printf ("\t%s\n", address->address_string);
+ GNUNET_free (address->address_string);
+ GNUNET_CONTAINER_DLL_remove (pc->address_list_head, pc->address_list_tail,
+ address);
+ GNUNET_free (address);
+ }
printf ("\n");
@@ -97,24 +97,24 @@
* @param address NULL on error, otherwise 0-terminated printable UTF-8 string
*/
static void
-process_resolved_address (void *cls,
- const char *address)
+process_resolved_address (void *cls, const char *address)
{
struct PrintContext *pc = cls;
struct AddressStringList *new_address;
if (address == NULL)
- {
- dump_pc (pc);
- return;
- }
+ {
+ dump_pc (pc);
+ return;
+ }
- new_address = GNUNET_malloc(sizeof(struct AddressStringList));
+ new_address = GNUNET_malloc (sizeof (struct AddressStringList));
#if VERBOSE
- fprintf(stderr, "Received address %s\n", address);
+ fprintf (stderr, "Received address %s\n", address);
#endif
- new_address->address_string = GNUNET_strdup(address);
- GNUNET_CONTAINER_DLL_insert(pc->address_list_head, pc->address_list_tail,
new_address);
+ new_address->address_string = GNUNET_strdup (address);
+ GNUNET_CONTAINER_DLL_insert (pc->address_list_head, pc->address_list_tail,
+ new_address);
}
@@ -127,23 +127,23 @@
{
struct PrintContext *pc;
- if (peer != NULL) /* Not yet finished */
- {
+ if (peer != NULL) /* Not yet finished */
+ {
#if VERBOSE
- fprintf(stderr, "Learned about peer %s\n", GNUNET_i2s(peer));
- peer_count++;
+ fprintf (stderr, "Learned about peer %s\n", GNUNET_i2s (peer));
+ peer_count++;
#endif
- pc = GNUNET_malloc (sizeof (struct PrintContext));
- pc->peer = *peer;
- GNUNET_TRANSPORT_peer_address_lookup (cfg, peer,
- GNUNET_TIME_UNIT_MINUTES,
- &process_resolved_address, pc);
- }
+ pc = GNUNET_malloc (sizeof (struct PrintContext));
+ pc->peer = *peer;
+ GNUNET_TRANSPORT_peer_address_lookup (cfg, peer,
+ GNUNET_TIME_UNIT_MINUTES,
+ &process_resolved_address, pc);
+ }
#if VERBOSE
else
- {
- fprintf(stderr, "Counted %u total connected peers.\n", peer_count);
- }
+ {
+ fprintf (stderr, "Counted %u total connected peers.\n", peer_count);
+ }
#endif
}
@@ -159,22 +159,17 @@
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *c)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
{
cfg = c;
if (args[0] != NULL)
- {
- fprintf (stderr,
- _("Invalid command line argument `%s'\n"),
- args[0]);
- return;
- }
+ {
+ fprintf (stderr, _("Invalid command line argument `%s'\n"), args[0]);
+ return;
+ }
- GNUNET_CORE_iterate_peers (cfg,
- &connected_peer_callback,
- NULL);
+ GNUNET_CORE_iterate_peers (cfg, &connected_peer_callback, NULL);
}
@@ -199,7 +194,8 @@
GNUNET_PROGRAM_run (argc,
argv,
"gnunet-list-connections",
- gettext_noop ("Print information about connected
peers."),
+ gettext_noop
+ ("Print information about connected peers."),
options, &run, NULL)) ? 0 : 1;
}
Modified: gnunet/src/core/gnunet-service-core.c
===================================================================
--- gnunet/src/core/gnunet-service-core.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/core/gnunet-service-core.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -164,7 +164,7 @@
* We've sent our session key.
*/
PEER_STATE_KEY_SENT,
-
+
/**
* We've received the other peers session key.
*/
@@ -241,7 +241,7 @@
* Message type is CORE_PING.
*/
struct GNUNET_MessageHeader header;
-
+
/**
* Seed for the IV
*/
@@ -271,7 +271,7 @@
* Message type is CORE_PONG.
*/
struct GNUNET_MessageHeader header;
-
+
/**
* Seed for the IV
*/
@@ -489,7 +489,7 @@
/**
* Performance data for the peer.
- */
+ */
struct GNUNET_TRANSPORT_ATS_Information *ats;
/**
@@ -578,7 +578,7 @@
/**
* Number of entries in 'ats'.
- */
+ */
unsigned int ats_count;
/**
@@ -601,12 +601,12 @@
/**
* Available bandwidth in for this peer (current target).
*/
- struct GNUNET_BANDWIDTH_Value32NBO bw_in;
+ struct GNUNET_BANDWIDTH_Value32NBO bw_in;
/**
* Available bandwidth out for this peer (current target).
*/
- struct GNUNET_BANDWIDTH_Value32NBO bw_out;
+ struct GNUNET_BANDWIDTH_Value32NBO bw_out;
/**
* Internal bandwidth limit set for this peer (initially typically
@@ -634,7 +634,7 @@
/**
* Are we currently connected to this neighbour?
- */
+ */
int is_connected;
};
@@ -731,7 +731,7 @@
* Unique request ID (in big endian).
*/
uint16_t smr_id;
-
+
};
@@ -754,7 +754,7 @@
/**
* Bitmap of message types this peer is able to handle.
*/
-static uint32_t my_type_map[(UINT16_MAX + 1)/32];
+static uint32_t my_type_map[(UINT16_MAX + 1) / 32];
/**
* Handle to peerinfo service.
@@ -821,9 +821,8 @@
*/
static void
derive_auth_key (struct GNUNET_CRYPTO_AuthKey *akey,
- const struct GNUNET_CRYPTO_AesSessionKey *skey,
- uint32_t seed,
- struct GNUNET_TIME_Absolute creation_time)
+ const struct GNUNET_CRYPTO_AesSessionKey *skey,
+ uint32_t seed, struct GNUNET_TIME_Absolute creation_time)
{
static const char ctx[] = "authentication key";
struct GNUNET_TIME_AbsoluteNBO ctbe;
@@ -833,13 +832,10 @@
GNUNET_CRYPTO_hmac_derive_key (akey,
skey,
&seed,
- sizeof(seed),
+ sizeof (seed),
&skey->key,
- sizeof(skey->key),
- &ctbe,
- sizeof(ctbe),
- ctx,
- sizeof(ctx), NULL);
+ sizeof (skey->key),
+ &ctbe, sizeof (ctbe), ctx, sizeof (ctx),
NULL);
}
@@ -848,19 +844,18 @@
*/
static void
derive_iv (struct GNUNET_CRYPTO_AesInitializationVector *iv,
- const struct GNUNET_CRYPTO_AesSessionKey *skey, uint32_t seed,
- const struct GNUNET_PeerIdentity *identity)
+ const struct GNUNET_CRYPTO_AesSessionKey *skey, uint32_t seed,
+ const struct GNUNET_PeerIdentity *identity)
{
static const char ctx[] = "initialization vector";
GNUNET_CRYPTO_aes_derive_iv (iv,
skey,
&seed,
- sizeof(seed),
+ sizeof (seed),
&identity->hashPubKey.bits,
- sizeof(identity->hashPubKey.bits),
- ctx,
- sizeof(ctx), NULL);
+ sizeof (identity->hashPubKey.bits),
+ ctx, sizeof (ctx), NULL);
}
/**
@@ -868,21 +863,19 @@
*/
static void
derive_pong_iv (struct GNUNET_CRYPTO_AesInitializationVector *iv,
- const struct GNUNET_CRYPTO_AesSessionKey *skey, uint32_t seed,
- uint32_t challenge, const struct GNUNET_PeerIdentity *identity)
+ const struct GNUNET_CRYPTO_AesSessionKey *skey, uint32_t seed,
+ uint32_t challenge, const struct GNUNET_PeerIdentity *identity)
{
static const char ctx[] = "pong initialization vector";
GNUNET_CRYPTO_aes_derive_iv (iv,
skey,
&seed,
- sizeof(seed),
+ sizeof (seed),
&identity->hashPubKey.bits,
- sizeof(identity->hashPubKey.bits),
+ sizeof (identity->hashPubKey.bits),
&challenge,
- sizeof(challenge),
- ctx,
- sizeof(ctx), NULL);
+ sizeof (challenge), ctx, sizeof (ctx), NULL);
}
@@ -893,11 +886,11 @@
* @param n neighbour in question
* @return absolute timeout
*/
-static struct GNUNET_TIME_Absolute
+static struct GNUNET_TIME_Absolute
get_neighbour_timeout (struct Neighbour *n)
{
return GNUNET_TIME_absolute_add (n->last_activity,
- GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
+ GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
}
@@ -905,9 +898,7 @@
* Helper function for update_preference_sum.
*/
static int
-update_preference (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+update_preference (void *cls, const GNUNET_HashCode * key, void *value)
{
unsigned long long *ps = cls;
struct Neighbour *n = value;
@@ -915,7 +906,7 @@
n->current_preference /= 2;
*ps += n->current_preference;
return GNUNET_OK;
-}
+}
/**
@@ -932,13 +923,13 @@
os = preference_sum;
preference_sum += inc;
if (preference_sum >= os)
- return; /* done! */
+ return; /* done! */
/* overflow! compensate by cutting all values in half! */
preference_sum = 0;
GNUNET_CONTAINER_multihashmap_iterate (neighbours,
- &update_preference,
- &preference_sum);
- GNUNET_STATISTICS_set (stats, gettext_noop ("# total peer preference"),
preference_sum, GNUNET_NO);
+ &update_preference, &preference_sum);
+ GNUNET_STATISTICS_set (stats, gettext_noop ("# total peer preference"),
+ preference_sum, GNUNET_NO);
}
@@ -966,19 +957,17 @@
*/
static void
send_to_client (struct Client *client,
- const struct GNUNET_MessageHeader *msg,
- int can_drop)
+ const struct GNUNET_MessageHeader *msg, int can_drop)
{
-#if DEBUG_CORE_CLIENT
+#if DEBUG_CORE_CLIENT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Preparing to send %u bytes of message of type %u to client.\n",
- (unsigned int) ntohs (msg->size),
+ (unsigned int) ntohs (msg->size),
(unsigned int) ntohs (msg->type));
-#endif
+#endif
GNUNET_SERVER_notification_context_unicast (notifier,
- client->client_handle,
- msg,
- can_drop);
+ client->client_handle,
+ msg, can_drop);
}
@@ -991,26 +980,25 @@
* @param options mask to use
*/
static void
-send_to_all_clients (const struct GNUNET_MessageHeader *msg,
- int can_drop,
- int options)
+send_to_all_clients (const struct GNUNET_MessageHeader *msg,
+ int can_drop, int options)
{
struct Client *c;
c = clients;
while (c != NULL)
+ {
+ if (0 != (c->options & options))
{
- if (0 != (c->options & options))
- {
#if DEBUG_CORE_CLIENT > 1
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending message of type %u to client.\n",
- (unsigned int) ntohs (msg->type));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending message of type %u to client.\n",
+ (unsigned int) ntohs (msg->type));
#endif
- send_to_client (c, msg, can_drop);
- }
- c = c->next;
+ send_to_client (c, msg, can_drop);
}
+ c = c->next;
+ }
}
@@ -1028,27 +1016,23 @@
struct GNUNET_TRANSPORT_ATS_Information *ats;
size_t size;
- if ( (! n->is_connected) ||
- (n->status != PEER_STATE_KEY_CONFIRMED) )
+ if ((!n->is_connected) || (n->status != PEER_STATE_KEY_CONFIRMED))
return;
#if DEBUG_CORE > 1
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peer `%4s' changed status\n",
- GNUNET_i2s (&n->peer));
+ "Peer `%4s' changed status\n", GNUNET_i2s (&n->peer));
#endif
size = sizeof (struct PeerStatusNotifyMessage) +
- n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
+ n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
- {
- GNUNET_break (0);
- /* recovery strategy: throw away performance data */
- GNUNET_array_grow (n->ats,
- n->ats_count,
- 0);
- size = sizeof (struct PeerStatusNotifyMessage) +
- n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
- }
- psnm = (struct PeerStatusNotifyMessage*) buf;
+ {
+ GNUNET_break (0);
+ /* recovery strategy: throw away performance data */
+ GNUNET_array_grow (n->ats, n->ats_count, 0);
+ size = sizeof (struct PeerStatusNotifyMessage) +
+ n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
+ }
+ psnm = (struct PeerStatusNotifyMessage *) buf;
psnm->header.size = htons (size);
psnm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_STATUS_CHANGE);
psnm->timeout = GNUNET_TIME_absolute_hton (get_neighbour_timeout (n));
@@ -1058,17 +1042,15 @@
psnm->ats_count = htonl (n->ats_count);
ats = &psnm->ats;
memcpy (ats,
- n->ats,
- n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
+ n->ats,
+ n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
ats[n->ats_count].type = htonl (0);
ats[n->ats_count].value = htonl (0);
- send_to_all_clients (&psnm->header,
- GNUNET_YES,
- GNUNET_CORE_OPTION_SEND_STATUS_CHANGE);
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# peer status changes"),
- 1,
- GNUNET_NO);
+ send_to_all_clients (&psnm->header,
+ GNUNET_YES, GNUNET_CORE_OPTION_SEND_STATUS_CHANGE);
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# peer status changes"),
+ 1, GNUNET_NO);
}
@@ -1088,55 +1070,53 @@
struct Client *c;
struct MessageEntry *mqe;
unsigned int queue_size;
-
+
/* check if neighbour queue is empty enough! */
if (n != &self)
+ {
+ queue_size = 0;
+ mqe = n->messages;
+ while (mqe != NULL)
{
- queue_size = 0;
- mqe = n->messages;
- while (mqe != NULL)
- {
- queue_size++;
- mqe = mqe->next;
- }
- if (queue_size >= MAX_PEER_QUEUE_SIZE)
- {
+ queue_size++;
+ mqe = mqe->next;
+ }
+ if (queue_size >= MAX_PEER_QUEUE_SIZE)
+ {
#if DEBUG_CORE_CLIENT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Not considering client transmission requests: queue
full\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Not considering client transmission requests: queue
full\n");
#endif
- return; /* queue still full */
- }
- /* find highest priority request */
- pos = n->active_client_request_head;
- car = NULL;
- while (pos != NULL)
- {
- if ( (car == NULL) ||
- (pos->priority > car->priority) )
- car = pos;
- pos = pos->next;
- }
+ return; /* queue still full */
}
- else
+ /* find highest priority request */
+ pos = n->active_client_request_head;
+ car = NULL;
+ while (pos != NULL)
{
- car = n->active_client_request_head;
+ if ((car == NULL) || (pos->priority > car->priority))
+ car = pos;
+ pos = pos->next;
}
+ }
+ else
+ {
+ car = n->active_client_request_head;
+ }
if (car == NULL)
- return; /* no pending requests */
+ return; /* no pending requests */
#if DEBUG_CORE_CLIENT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Permitting client transmission request to `%s'\n",
- GNUNET_i2s (&n->peer));
+ "Permitting client transmission request to `%s'\n",
+ GNUNET_i2s (&n->peer));
#endif
c = car->client;
GNUNET_CONTAINER_DLL_remove (n->active_client_request_head,
- n->active_client_request_tail,
- car);
+ n->active_client_request_tail, car);
GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove (c->requests,
- &n->peer.hashPubKey,
- car));
+ GNUNET_CONTAINER_multihashmap_remove (c->requests,
+ &n->peer.hashPubKey,
+ car));
smr.header.size = htons (sizeof (struct SendMessageReady));
smr.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_SEND_READY);
smr.size = htons (car->msize);
@@ -1160,27 +1140,28 @@
struct GNUNET_MessageHeader *hdr;
#ifdef compressBound
- dlen = compressBound (sizeof(my_type_map));
+ dlen = compressBound (sizeof (my_type_map));
#else
- dlen = sizeof(my_type_map) + (sizeof(my_type_map) / 100) + 20;
+ dlen = sizeof (my_type_map) + (sizeof (my_type_map) / 100) + 20;
/* documentation says 100.1% oldSize + 12 bytes, but we
- should be able to overshoot by more to be safe */
+ * should be able to overshoot by more to be safe */
#endif
hdr = GNUNET_malloc (dlen + sizeof (struct GNUNET_MessageHeader));
hdr->size = htons ((uint16_t) dlen + sizeof (struct GNUNET_MessageHeader));
- tmp = (char*) &hdr[1];
- if ( (Z_OK != compress2 ((Bytef *) tmp,
- &dlen, (const Bytef *) my_type_map, sizeof
(my_type_map), 9)) ||
- (dlen >= sizeof(my_type_map)) )
- {
- dlen = sizeof (my_type_map);
- memcpy (tmp, my_type_map, sizeof (my_type_map));
- hdr->type = htons (GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP);
- }
+ tmp = (char *) &hdr[1];
+ if ((Z_OK != compress2 ((Bytef *) tmp,
+ &dlen, (const Bytef *) my_type_map,
+ sizeof (my_type_map), 9)) ||
+ (dlen >= sizeof (my_type_map)))
+ {
+ dlen = sizeof (my_type_map);
+ memcpy (tmp, my_type_map, sizeof (my_type_map));
+ hdr->type = htons (GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP);
+ }
else
- {
- hdr->type = htons (GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP);
- }
+ {
+ hdr->type = htons (GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP);
+ }
return hdr;
}
@@ -1194,9 +1175,7 @@
* @return always GNUNET_OK
*/
static int
-send_type_map_to_neighbour (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+send_type_map_to_neighbour (void *cls, const GNUNET_HashCode * key, void
*value)
{
struct GNUNET_MessageHeader *hdr = cls;
struct Neighbour *n = value;
@@ -1225,15 +1204,14 @@
*/
static void
broadcast_my_type_map ()
-{
+{
struct GNUNET_MessageHeader *hdr;
if (NULL == neighbours)
return;
hdr = compute_type_map_message ();
GNUNET_CONTAINER_multihashmap_iterate (neighbours,
- &send_type_map_to_neighbour,
- hdr);
+ &send_type_map_to_neighbour, hdr);
GNUNET_free (hdr);
}
@@ -1243,72 +1221,68 @@
*/
static void
handle_client_send_request (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
const struct SendMessageRequest *req;
struct Neighbour *n;
struct Client *c;
struct ClientActiveRequest *car;
- req = (const struct SendMessageRequest*) message;
+ req = (const struct SendMessageRequest *) message;
if (0 == memcmp (&req->peer,
- &my_identity,
- sizeof (struct GNUNET_PeerIdentity)))
+ &my_identity, sizeof (struct GNUNET_PeerIdentity)))
n = &self;
else
n = find_neighbour (&req->peer);
- if ( (n == NULL) ||
- (GNUNET_YES != n->is_connected) ||
- (n->status != PEER_STATE_KEY_CONFIRMED) )
- {
- /* neighbour must have disconnected since request was issued,
- ignore (client will realize it once it processes the
- disconnect notification) */
+ if ((n == NULL) ||
+ (GNUNET_YES != n->is_connected) ||
+ (n->status != PEER_STATE_KEY_CONFIRMED))
+ {
+ /* neighbour must have disconnected since request was issued,
+ * ignore (client will realize it once it processes the
+ * disconnect notification) */
#if DEBUG_CORE_CLIENT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Dropped client request for transmission (am disconnected)\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Dropped client request for transmission (am disconnected)\n");
#endif
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# send requests dropped
(disconnected)"),
- 1,
- GNUNET_NO);
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
- return;
- }
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# send requests dropped (disconnected)"), 1,
+ GNUNET_NO);
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ return;
+ }
c = clients;
- while ( (c != NULL) &&
- (c->client_handle != client) )
+ while ((c != NULL) && (c->client_handle != client))
c = c->next;
if (c == NULL)
- {
- /* client did not send INIT first! */
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ {
+ /* client did not send INIT first! */
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
if (c->requests == NULL)
c->requests = GNUNET_CONTAINER_multihashmap_create (16);
#if DEBUG_CORE_CLIENT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received client transmission request. queueing\n");
#endif
- car = GNUNET_CONTAINER_multihashmap_get (c->requests,
- &req->peer.hashPubKey);
+ car = GNUNET_CONTAINER_multihashmap_get (c->requests, &req->peer.hashPubKey);
if (car == NULL)
- {
- /* create new entry */
- car = GNUNET_malloc (sizeof (struct ClientActiveRequest));
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_put (c->requests,
- &req->peer.hashPubKey,
- car,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
- GNUNET_CONTAINER_DLL_insert (n->active_client_request_head,
- n->active_client_request_tail,
- car);
- car->client = c;
- }
+ {
+ /* create new entry */
+ car = GNUNET_malloc (sizeof (struct ClientActiveRequest));
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONTAINER_multihashmap_put (c->requests,
+ &req->peer.hashPubKey,
+ car,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
+ GNUNET_CONTAINER_DLL_insert (n->active_client_request_head,
+ n->active_client_request_tail, car);
+ car->client = c;
+ }
car->deadline = GNUNET_TIME_absolute_ntoh (req->deadline);
car->priority = ntohl (req->priority);
car->queue_size = ntohl (req->queue_size);
@@ -1324,8 +1298,7 @@
*/
static int
notify_client_about_neighbour (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+ const GNUNET_HashCode * key, void *value)
{
struct Client *c = cls;
struct Neighbour *n = value;
@@ -1335,36 +1308,34 @@
struct ConnectNotifyMessage *cnm;
size = sizeof (struct ConnectNotifyMessage) +
- (n->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
+ (n->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
- {
- GNUNET_break (0);
- /* recovery strategy: throw away performance data */
- GNUNET_array_grow (n->ats,
- n->ats_count,
- 0);
- size = sizeof (struct ConnectNotifyMessage) +
- (n->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
- }
- cnm = (struct ConnectNotifyMessage*) buf;
+ {
+ GNUNET_break (0);
+ /* recovery strategy: throw away performance data */
+ GNUNET_array_grow (n->ats, n->ats_count, 0);
+ size = sizeof (struct ConnectNotifyMessage) +
+ (n->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
+ }
+ cnm = (struct ConnectNotifyMessage *) buf;
cnm->header.size = htons (size);
cnm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT);
cnm->ats_count = htonl (n->ats_count);
ats = &cnm->ats;
memcpy (ats,
- n->ats,
- sizeof (struct GNUNET_TRANSPORT_ATS_Information) * n->ats_count);
+ n->ats,
+ sizeof (struct GNUNET_TRANSPORT_ATS_Information) * n->ats_count);
ats[n->ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
ats[n->ats_count].value = htonl (0);
if (n->status == PEER_STATE_KEY_CONFIRMED)
- {
+ {
#if DEBUG_CORE_CLIENT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending `%s' message to client.\n", "NOTIFY_CONNECT");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending `%s' message to client.\n", "NOTIFY_CONNECT");
#endif
- cnm->peer = n->peer;
- send_to_client (c, &cnm->header, GNUNET_NO);
- }
+ cnm->peer = n->peer;
+ send_to_client (c, &cnm->header, GNUNET_NO);
+ }
return GNUNET_OK;
}
@@ -1388,28 +1359,27 @@
#if DEBUG_CORE_CLIENT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Client connecting to core service with `%s' message\n",
- "INIT");
+ "Client connecting to core service with `%s' message\n", "INIT");
#endif
/* check that we don't have an entry already */
c = clients;
while (c != NULL)
+ {
+ if (client == c->client_handle)
{
- if (client == c->client_handle)
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
- c = c->next;
- }
- msize = ntohs (message->size);
- if (msize < sizeof (struct InitMessage))
- {
GNUNET_break (0);
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
+ c = c->next;
+ }
+ msize = ntohs (message->size);
+ if (msize < sizeof (struct InitMessage))
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
GNUNET_SERVER_notification_context_add (notifier, client);
im = (const struct InitMessage *) message;
types = (const uint16_t *) &im[1];
@@ -1420,20 +1390,19 @@
clients = c;
c->tcnt = msize / sizeof (uint16_t);
c->types = (const uint16_t *) &c[1];
- wtypes = (uint16_t *) &c[1];
- for (i=0;i<c->tcnt;i++)
- {
- wtypes[i] = ntohs (types[i]);
- my_type_map[wtypes[i]/32] |= (1 << (wtypes[i] % 32));
- }
+ wtypes = (uint16_t *) & c[1];
+ for (i = 0; i < c->tcnt; i++)
+ {
+ wtypes[i] = ntohs (types[i]);
+ my_type_map[wtypes[i] / 32] |= (1 << (wtypes[i] % 32));
+ }
if (c->tcnt > 0)
broadcast_my_type_map ();
c->options = ntohl (im->options);
#if DEBUG_CORE_CLIENT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Client %p is interested in %u message types\n",
- c,
- (unsigned int) c->tcnt);
+ "Client %p is interested in %u message types\n",
+ c, (unsigned int) c->tcnt);
#endif
/* send init reply message */
irm.header.size = htons (sizeof (struct InitReplyMessage));
@@ -1448,12 +1417,11 @@
#endif
send_to_client (c, &irm.header, GNUNET_NO);
if (0 != (c->options & GNUNET_CORE_OPTION_SEND_CONNECT))
- {
- /* notify new client about existing neighbours */
- GNUNET_CONTAINER_multihashmap_iterate (neighbours,
- ¬ify_client_about_neighbour,
- c);
- }
+ {
+ /* notify new client about existing neighbours */
+ GNUNET_CONTAINER_multihashmap_iterate (neighbours,
+ ¬ify_client_about_neighbour, c);
+ }
GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
@@ -1468,8 +1436,7 @@
*/
static int
destroy_active_client_request (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+ const GNUNET_HashCode * key, void *value)
{
struct ClientActiveRequest *car = value;
struct Neighbour *n;
@@ -1479,8 +1446,7 @@
n = find_neighbour (&peer);
GNUNET_assert (NULL != n);
GNUNET_CONTAINER_DLL_remove (n->active_client_request_head,
- n->active_client_request_tail,
- car);
+ n->active_client_request_tail, car);
GNUNET_free (car);
return GNUNET_YES;
}
@@ -1504,44 +1470,43 @@
return;
#if DEBUG_CORE_CLIENT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Client %p has disconnected from core service.\n",
- client);
+ "Client %p has disconnected from core service.\n", client);
#endif
prev = NULL;
pos = clients;
while (pos != NULL)
- {
- if (client == pos->client_handle)
- break;
- prev = pos;
- pos = pos->next;
- }
+ {
+ if (client == pos->client_handle)
+ break;
+ prev = pos;
+ pos = pos->next;
+ }
if (pos == NULL)
- {
- /* client never sent INIT */
- return;
- }
+ {
+ /* client never sent INIT */
+ return;
+ }
if (prev == NULL)
clients = pos->next;
else
prev->next = pos->next;
if (pos->requests != NULL)
- {
- GNUNET_CONTAINER_multihashmap_iterate (pos->requests,
- &destroy_active_client_request,
- NULL);
- GNUNET_CONTAINER_multihashmap_destroy (pos->requests);
- }
+ {
+ GNUNET_CONTAINER_multihashmap_iterate (pos->requests,
+ &destroy_active_client_request,
+ NULL);
+ GNUNET_CONTAINER_multihashmap_destroy (pos->requests);
+ }
GNUNET_free (pos);
/* rebuild my_type_map */
memset (my_type_map, 0, sizeof (my_type_map));
for (pos = clients; NULL != pos; pos = pos->next)
- {
- wtypes = (const uint16_t *) &pos[1];
- for (i=0;i<pos->tcnt;i++)
- my_type_map[wtypes[i]/32] |= (1 << (wtypes[i] % 32));
- }
+ {
+ wtypes = (const uint16_t *) &pos[1];
+ for (i = 0; i < pos->tcnt; i++)
+ my_type_map[wtypes[i] / 32] |= (1 << (wtypes[i] % 32));
+ }
broadcast_my_type_map ();
}
@@ -1555,9 +1520,7 @@
* @return GNUNET_OK (continue to iterate)
*/
static int
-queue_connect_message (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+queue_connect_message (void *cls, const GNUNET_HashCode * key, void *value)
{
struct GNUNET_SERVER_TransmitContext *tc = cls;
struct Neighbour *n = value;
@@ -1566,39 +1529,35 @@
size_t size;
struct ConnectNotifyMessage *cnm;
- cnm = (struct ConnectNotifyMessage*) buf;
+ cnm = (struct ConnectNotifyMessage *) buf;
if (n->status != PEER_STATE_KEY_CONFIRMED)
return GNUNET_OK;
size = sizeof (struct ConnectNotifyMessage) +
- (n->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
+ (n->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
- {
- GNUNET_break (0);
- /* recovery strategy: throw away performance data */
- GNUNET_array_grow (n->ats,
- n->ats_count,
- 0);
- size = sizeof (struct PeerStatusNotifyMessage) +
- n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
- }
- cnm = (struct ConnectNotifyMessage*) buf;
+ {
+ GNUNET_break (0);
+ /* recovery strategy: throw away performance data */
+ GNUNET_array_grow (n->ats, n->ats_count, 0);
+ size = sizeof (struct PeerStatusNotifyMessage) +
+ n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
+ }
+ cnm = (struct ConnectNotifyMessage *) buf;
cnm->header.size = htons (size);
cnm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT);
cnm->ats_count = htonl (n->ats_count);
ats = &cnm->ats;
memcpy (ats,
- n->ats,
- n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
+ n->ats,
+ n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
ats[n->ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
- ats[n->ats_count].value = htonl (0);
+ ats[n->ats_count].value = htonl (0);
#if DEBUG_CORE_CLIENT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending `%s' message to client.\n",
- "NOTIFY_CONNECT");
+ "Sending `%s' message to client.\n", "NOTIFY_CONNECT");
#endif
cnm->peer = n->peer;
- GNUNET_SERVER_transmit_context_append_message (tc,
- &cnm->header);
+ GNUNET_SERVER_transmit_context_append_message (tc, &cnm->header);
return GNUNET_OK;
}
@@ -1612,27 +1571,27 @@
*/
static void
handle_client_iterate_peers (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
-
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
struct GNUNET_MessageHeader done_msg;
struct GNUNET_SERVER_TransmitContext *tc;
int msize;
+
/* notify new client about existing neighbours */
- msize = ntohs(message->size);
+ msize = ntohs (message->size);
tc = GNUNET_SERVER_transmit_context_create (client);
- if (msize == sizeof(struct GNUNET_MessageHeader))
- GNUNET_CONTAINER_multihashmap_iterate (neighbours, &queue_connect_message,
tc);
+ if (msize == sizeof (struct GNUNET_MessageHeader))
+ GNUNET_CONTAINER_multihashmap_iterate (neighbours, &queue_connect_message,
+ tc);
else
- GNUNET_break(0);
+ GNUNET_break (0);
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);
- GNUNET_SERVER_transmit_context_run (tc,
- GNUNET_TIME_UNIT_FOREVER_REL);
+ GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
}
@@ -1645,9 +1604,8 @@
*/
static void
handle_client_have_peer (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
-
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
struct GNUNET_MessageHeader done_msg;
struct GNUNET_SERVER_TransmitContext *tc;
@@ -1655,15 +1613,13 @@
tc = GNUNET_SERVER_transmit_context_create (client);
peer = (struct GNUNET_PeerIdentity *) &message[1];
- GNUNET_CONTAINER_multihashmap_get_multiple(neighbours,
- &peer->hashPubKey,
- &queue_connect_message,
- tc);
+ GNUNET_CONTAINER_multihashmap_get_multiple (neighbours,
+ &peer->hashPubKey,
+ &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);
- GNUNET_SERVER_transmit_context_run (tc,
- GNUNET_TIME_UNIT_FOREVER_REL);
+ GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
}
@@ -1676,8 +1632,8 @@
*/
static void
handle_client_request_info (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
const struct RequestInfoMessage *rcm;
struct Client *pos;
@@ -1688,97 +1644,94 @@
unsigned long long old_preference;
struct GNUNET_TIME_Relative rdelay;
- rdelay = GNUNET_TIME_relative_get_zero();
+ rdelay = GNUNET_TIME_relative_get_zero ();
#if DEBUG_CORE_CLIENT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Core service receives `%s' request.\n", "REQUEST_INFO");
#endif
pos = clients;
while (pos != NULL)
- {
- if (client == pos->client_handle)
- break;
- pos = pos->next;
- }
+ {
+ if (client == pos->client_handle)
+ break;
+ pos = pos->next;
+ }
if (pos == NULL)
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
rcm = (const struct RequestInfoMessage *) message;
n = find_neighbour (&rcm->peer);
memset (&cim, 0, sizeof (cim));
- if ( (n != NULL) && (GNUNET_YES == n->is_connected) )
+ if ((n != NULL) && (GNUNET_YES == n->is_connected))
+ {
+ want_reserv = ntohl (rcm->reserve_inbound);
+ if (n->bw_out_internal_limit.value__ != rcm->limit_outbound.value__)
{
- want_reserv = ntohl (rcm->reserve_inbound);
- if (n->bw_out_internal_limit.value__ != rcm->limit_outbound.value__)
- {
- n->bw_out_internal_limit = rcm->limit_outbound;
- if (n->bw_out.value__ != GNUNET_BANDWIDTH_value_min
(n->bw_out_internal_limit,
-
n->bw_out_external_limit).value__)
- {
- n->bw_out = GNUNET_BANDWIDTH_value_min (n->bw_out_internal_limit,
- n->bw_out_external_limit);
- GNUNET_BANDWIDTH_tracker_update_quota (&n->available_recv_window,
- n->bw_out);
- GNUNET_TRANSPORT_set_quota (transport,
- &n->peer,
- n->bw_in,
- n->bw_out);
- handle_peer_status_change (n);
- }
- }
- if (want_reserv < 0)
- {
- got_reserv = want_reserv;
- }
- else if (want_reserv > 0)
- {
- rdelay = GNUNET_BANDWIDTH_tracker_get_delay
(&n->available_recv_window,
- want_reserv);
- if (rdelay.rel_value == 0)
- got_reserv = want_reserv;
- else
- got_reserv = 0; /* all or nothing */
- }
+ n->bw_out_internal_limit = rcm->limit_outbound;
+ if (n->bw_out.value__ !=
+ GNUNET_BANDWIDTH_value_min (n->bw_out_internal_limit,
+ n->bw_out_external_limit).value__)
+ {
+ n->bw_out = GNUNET_BANDWIDTH_value_min (n->bw_out_internal_limit,
+ n->bw_out_external_limit);
+ GNUNET_BANDWIDTH_tracker_update_quota (&n->available_recv_window,
+ n->bw_out);
+ GNUNET_TRANSPORT_set_quota (transport, &n->peer, n->bw_in, n->bw_out);
+ handle_peer_status_change (n);
+ }
+ }
+ if (want_reserv < 0)
+ {
+ got_reserv = want_reserv;
+ }
+ else if (want_reserv > 0)
+ {
+ rdelay = GNUNET_BANDWIDTH_tracker_get_delay (&n->available_recv_window,
+ want_reserv);
+ if (rdelay.rel_value == 0)
+ got_reserv = want_reserv;
else
- got_reserv = 0;
- GNUNET_BANDWIDTH_tracker_consume (&n->available_recv_window,
- got_reserv);
- old_preference = n->current_preference;
- n->current_preference += GNUNET_ntohll(rcm->preference_change);
- if (old_preference > n->current_preference)
- {
- /* overflow; cap at maximum value */
- n->current_preference = ULLONG_MAX;
- }
- update_preference_sum (n->current_preference - old_preference);
-#if DEBUG_CORE_QUOTA
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received reservation request for %d bytes for peer `%4s',
reserved %d bytes, suggesting delay of %llu ms\n",
- (int) want_reserv,
- GNUNET_i2s (&rcm->peer),
- (int) got_reserv,
- (unsigned long long) rdelay.rel_value);
-#endif
- cim.reserved_amount = htonl (got_reserv);
- cim.reserve_delay = GNUNET_TIME_relative_hton (rdelay);
- cim.bw_out = n->bw_out;
- cim.preference = n->current_preference;
+ got_reserv = 0; /* all or nothing */
}
- else
+ else
+ got_reserv = 0;
+ GNUNET_BANDWIDTH_tracker_consume (&n->available_recv_window, got_reserv);
+ old_preference = n->current_preference;
+ n->current_preference += GNUNET_ntohll (rcm->preference_change);
+ if (old_preference > n->current_preference)
{
- /* Technically, this COULD happen (due to asynchronous behavior),
- but it should be rare, so we should generate an info event
- to help diagnosis of serious errors that might be masked by this */
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Client asked for preference change with peer `%s', which
is not connected!\n"),
- GNUNET_i2s (&rcm->peer));
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
- return;
+ /* overflow; cap at maximum value */
+ n->current_preference = ULLONG_MAX;
}
+ update_preference_sum (n->current_preference - old_preference);
+#if DEBUG_CORE_QUOTA
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received reservation request for %d bytes for peer `%4s',
reserved %d bytes, suggesting delay of %llu ms\n",
+ (int) want_reserv,
+ GNUNET_i2s (&rcm->peer),
+ (int) got_reserv, (unsigned long long) rdelay.rel_value);
+#endif
+ cim.reserved_amount = htonl (got_reserv);
+ cim.reserve_delay = GNUNET_TIME_relative_hton (rdelay);
+ cim.bw_out = n->bw_out;
+ cim.preference = n->current_preference;
+ }
+ else
+ {
+ /* Technically, this COULD happen (due to asynchronous behavior),
+ * but it should be rare, so we should generate an info event
+ * to help diagnosis of serious errors that might be masked by this */
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _
+ ("Client asked for preference change with peer `%s', which is
not connected!\n"),
+ GNUNET_i2s (&rcm->peer));
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ return;
+ }
cim.header.size = htons (sizeof (struct ConfigurationInfoMessage));
cim.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_CONFIGURATION_INFO);
cim.peer = rcm->peer;
@@ -1806,47 +1759,44 @@
#if DEBUG_CORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Destroying neighbour entry for peer `%4s'\n",
- GNUNET_i2s (&n->peer));
+ "Destroying neighbour entry for peer `%4s'\n",
+ GNUNET_i2s (&n->peer));
#endif
if (n->pitr != NULL)
- {
- GNUNET_PEERINFO_iterate_cancel (n->pitr);
- n->pitr = NULL;
- }
+ {
+ GNUNET_PEERINFO_iterate_cancel (n->pitr);
+ n->pitr = NULL;
+ }
if (n->skm != NULL)
- {
- GNUNET_free (n->skm);
- n->skm = NULL;
- }
+ {
+ GNUNET_free (n->skm);
+ n->skm = NULL;
+ }
while (NULL != (m = n->messages))
- {
- n->messages = m->next;
- GNUNET_free (m);
- }
+ {
+ n->messages = m->next;
+ GNUNET_free (m);
+ }
while (NULL != (m = n->encrypted_head))
- {
- GNUNET_CONTAINER_DLL_remove (n->encrypted_head,
- n->encrypted_tail,
- m);
- GNUNET_free (m);
- }
+ {
+ GNUNET_CONTAINER_DLL_remove (n->encrypted_head, n->encrypted_tail, m);
+ GNUNET_free (m);
+ }
while (NULL != (car = n->active_client_request_head))
- {
- GNUNET_CONTAINER_DLL_remove (n->active_client_request_head,
- n->active_client_request_tail,
- car);
- GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove
(car->client->requests,
- &n->peer.hashPubKey,
- car));
- GNUNET_free (car);
- }
+ {
+ GNUNET_CONTAINER_DLL_remove (n->active_client_request_head,
+ n->active_client_request_tail, car);
+ GNUNET_assert (GNUNET_YES ==
+ GNUNET_CONTAINER_multihashmap_remove (car->client->requests,
+ &n->peer.hashPubKey,
+ car));
+ GNUNET_free (car);
+ }
if (NULL != n->th)
- {
- GNUNET_TRANSPORT_notify_transmit_ready_cancel (n->th);
- n->th = NULL;
- }
+ {
+ GNUNET_TRANSPORT_notify_transmit_ready_cancel (n->th);
+ n->th = NULL;
+ }
if (n->retry_plaintext_task != GNUNET_SCHEDULER_NO_TASK)
GNUNET_SCHEDULER_cancel (n->retry_plaintext_task);
if (n->retry_set_key_task != GNUNET_SCHEDULER_NO_TASK)
@@ -1855,13 +1805,12 @@
GNUNET_SCHEDULER_cancel (n->quota_update_task);
if (n->dead_clean_task != GNUNET_SCHEDULER_NO_TASK)
GNUNET_SCHEDULER_cancel (n->dead_clean_task);
- if (n->keep_alive_task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel (n->keep_alive_task);
+ if (n->keep_alive_task != GNUNET_SCHEDULER_NO_TASK)
+ GNUNET_SCHEDULER_cancel (n->keep_alive_task);
if (n->status == PEER_STATE_KEY_CONFIRMED)
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# established sessions"),
- -1,
- GNUNET_NO);
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# established sessions"),
+ -1, GNUNET_NO);
GNUNET_array_grow (n->ats, n->ats_count, 0);
GNUNET_free_non_null (n->public_key);
GNUNET_free_non_null (n->pending_ping);
@@ -1893,27 +1842,27 @@
*/
static int
do_encrypt (struct Neighbour *n,
- const struct GNUNET_CRYPTO_AesInitializationVector * iv,
+ const struct GNUNET_CRYPTO_AesInitializationVector *iv,
const void *in, void *out, size_t size)
{
if (size != (uint16_t) size)
- {
- GNUNET_break (0);
- return GNUNET_NO;
- }
+ {
+ GNUNET_break (0);
+ return GNUNET_NO;
+ }
GNUNET_assert (size ==
GNUNET_CRYPTO_aes_encrypt (in,
(uint16_t) size,
- &n->encrypt_key,
- iv, out));
- GNUNET_STATISTICS_update (stats, gettext_noop ("# bytes encrypted"), size,
GNUNET_NO);
+ &n->encrypt_key, iv, out));
+ GNUNET_STATISTICS_update (stats, gettext_noop ("# bytes encrypted"), size,
+ GNUNET_NO);
#if DEBUG_CORE > 2
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Encrypted %u bytes for `%4s' using key %u, IV %u\n",
- (unsigned int) size,
+ (unsigned int) size,
GNUNET_i2s (&n->peer),
- (unsigned int) n->encrypt_key.crc32,
- GNUNET_CRYPTO_crc32_n (iv, sizeof(iv)));
+ (unsigned int) n->encrypt_key.crc32,
+ GNUNET_CRYPTO_crc32_n (iv, sizeof (iv)));
#endif
return GNUNET_OK;
}
@@ -1925,8 +1874,7 @@
*
* @param n neighbour to consider discarding
*/
-static void
-consider_free_neighbour (struct Neighbour *n);
+static void consider_free_neighbour (struct Neighbour *n);
/**
@@ -1937,8 +1885,7 @@
* @param tc scheduler context (not used)
*/
static void
-send_keep_alive (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+send_keep_alive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct Neighbour *n = cls;
struct GNUNET_TIME_Relative retry;
@@ -1956,26 +1903,23 @@
me->priority = PING_PRIORITY;
me->size = sizeof (struct PingMessage);
GNUNET_CONTAINER_DLL_insert_after (n->encrypted_head,
- n->encrypted_tail,
- n->encrypted_tail,
- me);
+ n->encrypted_tail, n->encrypted_tail, me);
pm = (struct PingMessage *) &me[1];
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);
+ UINT32_MAX);
derive_iv (&iv, &n->encrypt_key, pm->iv_seed, &n->peer);
pp.challenge = n->ping_challenge;
pp.target = n->peer;
#if DEBUG_HANDSHAKE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Encrypting `%s' message with challenge %u for `%4s' using key
%u, IV %u (salt %u).\n",
- "PING",
- (unsigned int) n->ping_challenge,
- GNUNET_i2s (&n->peer),
- (unsigned int) n->encrypt_key.crc32,
- GNUNET_CRYPTO_crc32_n (&iv, sizeof(iv)),
- pm->iv_seed);
+ "PING",
+ (unsigned int) n->ping_challenge,
+ GNUNET_i2s (&n->peer),
+ (unsigned int) n->encrypt_key.crc32,
+ GNUNET_CRYPTO_crc32_n (&iv, sizeof (iv)), pm->iv_seed);
#endif
do_encrypt (n,
&iv,
@@ -1987,11 +1931,9 @@
/* reschedule PING job */
left = GNUNET_TIME_absolute_get_remaining (get_neighbour_timeout (n));
retry = GNUNET_TIME_relative_max (GNUNET_TIME_relative_divide (left, 2),
- MIN_PING_FREQUENCY);
- n->keep_alive_task
- = GNUNET_SCHEDULER_add_delayed (retry,
- &send_keep_alive,
- n);
+ MIN_PING_FREQUENCY);
+ n->keep_alive_task
+ = GNUNET_SCHEDULER_add_delayed (retry, &send_keep_alive, n);
}
@@ -2003,8 +1945,7 @@
* @param tc scheduler context (not used)
*/
static void
-consider_free_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+consider_free_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct Neighbour *n = cls;
@@ -2021,33 +1962,29 @@
*/
static void
consider_free_neighbour (struct Neighbour *n)
-{
+{
struct GNUNET_TIME_Relative left;
- if ( (n->th != NULL) ||
- (n->pitr != NULL) ||
- (GNUNET_YES == n->is_connected) )
- return; /* no chance */
-
+ if ((n->th != NULL) || (n->pitr != NULL) || (GNUNET_YES == n->is_connected))
+ return; /* no chance */
+
left = GNUNET_TIME_absolute_get_remaining (get_neighbour_timeout (n));
if (left.rel_value > 0)
- {
- if (n->dead_clean_task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel (n->dead_clean_task);
- n->dead_clean_task = GNUNET_SCHEDULER_add_delayed (left,
- &consider_free_task,
- n);
- return;
- }
+ {
+ if (n->dead_clean_task != GNUNET_SCHEDULER_NO_TASK)
+ GNUNET_SCHEDULER_cancel (n->dead_clean_task);
+ n->dead_clean_task = GNUNET_SCHEDULER_add_delayed (left,
+ &consider_free_task, n);
+ return;
+ }
/* actually free the neighbour... */
GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove (neighbours,
- &n->peer.hashPubKey,
- n));
+ GNUNET_CONTAINER_multihashmap_remove (neighbours,
+ &n->peer.hashPubKey,
n));
GNUNET_STATISTICS_set (stats,
- gettext_noop ("# neighbour entries allocated"),
- GNUNET_CONTAINER_multihashmap_size (neighbours),
- GNUNET_NO);
+ gettext_noop ("# neighbour entries allocated"),
+ GNUNET_CONTAINER_multihashmap_size (neighbours),
+ GNUNET_NO);
free_neighbour (n);
}
@@ -2062,9 +1999,7 @@
* @return number of bytes transmitted
*/
static size_t
-notify_encrypted_transmit_ready (void *cls,
- size_t size,
- void *buf)
+notify_encrypted_transmit_ready (void *cls, size_t size, void *buf)
{
struct Neighbour *n = cls;
struct MessageEntry *m;
@@ -2074,50 +2009,48 @@
n->th = NULL;
m = n->encrypted_head;
if (m == NULL)
- {
+ {
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Encrypted message queue empty, no messages added to buffer
for `%4s'\n",
- GNUNET_i2s (&n->peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Encrypted message queue empty, no messages added to buffer
for `%4s'\n",
+ GNUNET_i2s (&n->peer));
#endif
- return 0;
- }
- GNUNET_CONTAINER_DLL_remove (n->encrypted_head,
- n->encrypted_tail,
- m);
+ return 0;
+ }
+ GNUNET_CONTAINER_DLL_remove (n->encrypted_head, n->encrypted_tail, m);
ret = 0;
cbuf = buf;
if (buf != NULL)
- {
- GNUNET_assert (size >= m->size);
- memcpy (cbuf, &m[1], m->size);
- ret = m->size;
- GNUNET_BANDWIDTH_tracker_consume (&n->available_send_window,
- m->size);
+ {
+ GNUNET_assert (size >= m->size);
+ memcpy (cbuf, &m[1], m->size);
+ ret = m->size;
+ GNUNET_BANDWIDTH_tracker_consume (&n->available_send_window, 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));
+ 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));
#endif
- process_encrypted_neighbour_queue (n);
- }
+ process_encrypted_neighbour_queue (n);
+ }
else
- {
+ {
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmission of message of type %u and size %u failed\n",
- (unsigned int) ntohs (((struct GNUNET_MessageHeader *)
&m[1])->type),
- (unsigned int) m->size);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Transmission of message of type %u and size %u failed\n",
+ (unsigned int)
+ ntohs (((struct GNUNET_MessageHeader *) &m[1])->type),
+ (unsigned int) m->size);
#endif
- }
+ }
GNUNET_free (m);
consider_free_neighbour (n);
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# encrypted bytes given to
transport"),
- ret,
- GNUNET_NO);
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# encrypted bytes given to transport"), ret,
+ GNUNET_NO);
return ret;
}
@@ -2143,47 +2076,46 @@
process_encrypted_neighbour_queue (struct Neighbour *n)
{
struct MessageEntry *m;
-
+
if (n->th != NULL)
- return; /* request already pending */
+ return; /* request already pending */
if (GNUNET_YES != n->is_connected)
- {
- GNUNET_break (0);
- return;
- }
+ {
+ GNUNET_break (0);
+ return;
+ }
m = n->encrypted_head;
if (m == NULL)
- {
- /* encrypted queue empty, try plaintext instead */
- process_plaintext_neighbour_queue (n);
- return;
- }
+ {
+ /* encrypted queue empty, try plaintext instead */
+ process_plaintext_neighbour_queue (n);
+ return;
+ }
#if DEBUG_CORE > 1
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Asking transport for transmission of %u bytes to `%4s' in next
%llu ms\n",
(unsigned int) m->size,
GNUNET_i2s (&n->peer),
- (unsigned long long) GNUNET_TIME_absolute_get_remaining
(m->deadline).rel_value);
+ (unsigned long long)
+ GNUNET_TIME_absolute_get_remaining (m->deadline).rel_value);
#endif
n->th =
- GNUNET_TRANSPORT_notify_transmit_ready (transport, &n->peer,
- m->size,
- m->priority,
- GNUNET_TIME_absolute_get_remaining
- (m->deadline),
- ¬ify_encrypted_transmit_ready,
- n);
+ GNUNET_TRANSPORT_notify_transmit_ready (transport, &n->peer,
+ m->size,
+ m->priority,
+
GNUNET_TIME_absolute_get_remaining
+ (m->deadline),
+ ¬ify_encrypted_transmit_ready,
+ n);
if (n->th == NULL)
- {
- /* message request too large or duplicate request */
- GNUNET_break (0);
- /* discard encrypted message */
- GNUNET_CONTAINER_DLL_remove (n->encrypted_head,
- n->encrypted_tail,
- m);
- GNUNET_free (m);
- process_encrypted_neighbour_queue (n);
- }
+ {
+ /* message request too large or duplicate request */
+ GNUNET_break (0);
+ /* discard encrypted message */
+ GNUNET_CONTAINER_DLL_remove (n->encrypted_head, n->encrypted_tail, m);
+ GNUNET_free (m);
+ process_encrypted_neighbour_queue (n);
+ }
}
@@ -2201,41 +2133,36 @@
*/
static int
do_decrypt (struct Neighbour *n,
- const struct GNUNET_CRYPTO_AesInitializationVector * iv,
+ const struct GNUNET_CRYPTO_AesInitializationVector *iv,
const void *in, void *out, size_t size)
{
if (size != (uint16_t) size)
- {
- GNUNET_break (0);
- return GNUNET_NO;
- }
+ {
+ GNUNET_break (0);
+ return GNUNET_NO;
+ }
if ((n->status != PEER_STATE_KEY_RECEIVED) &&
(n->status != PEER_STATE_KEY_CONFIRMED))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
if (size !=
- GNUNET_CRYPTO_aes_decrypt (in,
- (uint16_t) size,
- &n->decrypt_key,
- iv,
- out))
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# bytes decrypted"),
- size,
- GNUNET_NO);
+ GNUNET_CRYPTO_aes_decrypt (in, (uint16_t) size, &n->decrypt_key, iv,
out))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# bytes decrypted"),
+ size, GNUNET_NO);
#if DEBUG_CORE > 1
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Decrypted %u bytes from `%4s' using key %u, IV %u\n",
- (unsigned int) size,
- GNUNET_i2s (&n->peer),
- (unsigned int) n->decrypt_key.crc32,
- GNUNET_CRYPTO_crc32_n (iv, sizeof(*iv)));
+ (unsigned int) size,
+ GNUNET_i2s (&n->peer),
+ (unsigned int) n->decrypt_key.crc32,
+ GNUNET_CRYPTO_crc32_n (iv, sizeof (*iv)));
#endif
return GNUNET_OK;
}
@@ -2270,7 +2197,7 @@
struct GNUNET_TIME_Absolute now;
struct GNUNET_TIME_Relative delta;
uint64_t avail;
- struct GNUNET_TIME_Relative slack; /* how long could we wait before
missing deadlines? */
+ struct GNUNET_TIME_Relative slack; /* how long could we wait before
missing deadlines? */
size_t off;
uint64_t tsize;
unsigned int queue_size;
@@ -2281,171 +2208,172 @@
/* last entry in linked list of messages processed */
last = NULL;
/* should we remove the entry with the lowest
- priority from consideration for scheduling at the
- end of the loop? */
+ * priority from consideration for scheduling at the
+ * end of the loop? */
queue_size = 0;
tsize = 0;
pos = n->messages;
while (pos != NULL)
- {
- queue_size++;
- tsize += pos->size;
- pos = pos->next;
- }
+ {
+ queue_size++;
+ tsize += pos->size;
+ pos = pos->next;
+ }
discard_low_prio = GNUNET_YES;
while (GNUNET_YES == discard_low_prio)
+ {
+ min = NULL;
+ min_prio = UINT_MAX;
+ discard_low_prio = GNUNET_NO;
+ /* calculate number of bytes available for transmission at time "t" */
+ avail = GNUNET_BANDWIDTH_tracker_get_available (&n->available_send_window);
+ t = now;
+ /* how many bytes have we (hypothetically) scheduled so far */
+ off = 0;
+ /* maximum time we can wait before transmitting anything
+ * and still make all of our deadlines */
+ slack = GNUNET_TIME_UNIT_FOREVER_REL;
+ pos = n->messages;
+ /* note that we use "*2" here because we want to look
+ * a bit further into the future; much more makes no
+ * sense since new message might be scheduled in the
+ * meantime... */
+ while ((pos != NULL) && (off < size * 2))
{
- min = NULL;
- min_prio = UINT_MAX;
- discard_low_prio = GNUNET_NO;
- /* calculate number of bytes available for transmission at time "t" */
- avail = GNUNET_BANDWIDTH_tracker_get_available
(&n->available_send_window);
- t = now;
- /* how many bytes have we (hypothetically) scheduled so far */
- off = 0;
- /* maximum time we can wait before transmitting anything
- and still make all of our deadlines */
- slack = GNUNET_TIME_UNIT_FOREVER_REL;
- pos = n->messages;
- /* note that we use "*2" here because we want to look
- a bit further into the future; much more makes no
- sense since new message might be scheduled in the
- meantime... */
- while ((pos != NULL) && (off < size * 2))
- {
- if (pos->do_transmit == GNUNET_YES)
- {
- /* already removed from consideration */
- pos = pos->next;
- continue;
- }
- if (discard_low_prio == GNUNET_NO)
- {
- delta = GNUNET_TIME_absolute_get_difference (t, pos->deadline);
- if (delta.rel_value > 0)
- {
- // FIXME: HUH? Check!
- t = pos->deadline;
- avail += GNUNET_BANDWIDTH_value_get_available_until
(n->bw_out,
- delta);
- }
- if (avail < pos->size)
- {
- // FIXME: HUH? Check!
- discard_low_prio = GNUNET_YES; /* we could not
schedule this one! */
- }
- else
- {
- avail -= pos->size;
- /* update slack, considering both its absolute deadline
- and relative deadlines caused by other messages
- with their respective load */
- slack = GNUNET_TIME_relative_min (slack,
-
GNUNET_BANDWIDTH_value_get_delay_for (n->bw_out,
-
avail));
- if (pos->deadline.abs_value <= now.abs_value)
- {
- /* now or never */
- slack = GNUNET_TIME_UNIT_ZERO;
- }
- else if (GNUNET_YES == pos->got_slack)
- {
- /* should be soon now! */
- slack = GNUNET_TIME_relative_min (slack,
-
GNUNET_TIME_absolute_get_remaining (pos->slack_deadline));
- }
- else
- {
- slack =
- GNUNET_TIME_relative_min (slack,
-
GNUNET_TIME_absolute_get_difference (now, pos->deadline));
- pos->got_slack = GNUNET_YES;
- pos->slack_deadline = GNUNET_TIME_absolute_min
(pos->deadline,
-
GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_MAX_CORK_DELAY));
- }
- }
- }
- off += pos->size;
- t = GNUNET_TIME_absolute_max (pos->deadline, t); // HUH? Check!
- if (pos->priority <= min_prio)
- {
- /* update min for discard */
- min_prio = pos->priority;
- min = pos;
- }
- pos = pos->next;
+ if (pos->do_transmit == GNUNET_YES)
+ {
+ /* already removed from consideration */
+ pos = pos->next;
+ continue;
+ }
+ if (discard_low_prio == GNUNET_NO)
+ {
+ delta = GNUNET_TIME_absolute_get_difference (t, pos->deadline);
+ if (delta.rel_value > 0)
+ {
+ // FIXME: HUH? Check!
+ t = pos->deadline;
+ avail += GNUNET_BANDWIDTH_value_get_available_until (n->bw_out,
+ delta);
}
- if (discard_low_prio)
+ if (avail < pos->size)
{
- GNUNET_assert (min != NULL);
- /* remove lowest-priority entry from consideration */
- min->do_transmit = GNUNET_YES; /* means: discard (for now) */
+ // FIXME: HUH? Check!
+ discard_low_prio = GNUNET_YES; /* we could not schedule this
one! */
}
- last = pos;
+ else
+ {
+ avail -= pos->size;
+ /* update slack, considering both its absolute deadline
+ * and relative deadlines caused by other messages
+ * with their respective load */
+ slack = GNUNET_TIME_relative_min (slack,
+
GNUNET_BANDWIDTH_value_get_delay_for
+ (n->bw_out, avail));
+ if (pos->deadline.abs_value <= now.abs_value)
+ {
+ /* now or never */
+ slack = GNUNET_TIME_UNIT_ZERO;
+ }
+ else if (GNUNET_YES == pos->got_slack)
+ {
+ /* should be soon now! */
+ slack = GNUNET_TIME_relative_min (slack,
+
GNUNET_TIME_absolute_get_remaining
+ (pos->slack_deadline));
+ }
+ else
+ {
+ slack =
+ GNUNET_TIME_relative_min (slack,
+ GNUNET_TIME_absolute_get_difference
+ (now, pos->deadline));
+ pos->got_slack = GNUNET_YES;
+ pos->slack_deadline = GNUNET_TIME_absolute_min (pos->deadline,
+
GNUNET_TIME_relative_to_absolute
+
(GNUNET_CONSTANTS_MAX_CORK_DELAY));
+ }
+ }
+ }
+ off += pos->size;
+ t = GNUNET_TIME_absolute_max (pos->deadline, t); // HUH? Check!
+ if (pos->priority <= min_prio)
+ {
+ /* update min for discard */
+ min_prio = pos->priority;
+ min = pos;
+ }
+ pos = pos->next;
}
+ if (discard_low_prio)
+ {
+ GNUNET_assert (min != NULL);
+ /* remove lowest-priority entry from consideration */
+ min->do_transmit = GNUNET_YES; /* means: discard (for now) */
+ }
+ last = pos;
+ }
/* guard against sending "tiny" messages with large headers without
- urgent deadlines */
- if ( (slack.rel_value > GNUNET_CONSTANTS_MAX_CORK_DELAY.rel_value) &&
- (size > 4 * off) &&
- (queue_size <= MAX_PEER_QUEUE_SIZE - 2) )
+ * urgent deadlines */
+ if ((slack.rel_value > GNUNET_CONSTANTS_MAX_CORK_DELAY.rel_value) &&
+ (size > 4 * off) && (queue_size <= MAX_PEER_QUEUE_SIZE - 2))
+ {
+ /* less than 25% of message would be filled with deadlines still
+ * being met if we delay by one second or more; so just wait for
+ * more data; but do not wait longer than 1s (since we don't want
+ * to delay messages for a really long time either). */
+ *retry_time = GNUNET_CONSTANTS_MAX_CORK_DELAY;
+ /* reset do_transmit values for next time */
+ while (pos != last)
{
- /* less than 25% of message would be filled with deadlines still
- being met if we delay by one second or more; so just wait for
- more data; but do not wait longer than 1s (since we don't want
- to delay messages for a really long time either). */
- *retry_time = GNUNET_CONSTANTS_MAX_CORK_DELAY;
- /* reset do_transmit values for next time */
- while (pos != last)
- {
- pos->do_transmit = GNUNET_NO;
- pos = pos->next;
- }
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# transmissions delayed due to
corking"),
- 1, GNUNET_NO);
+ pos->do_transmit = GNUNET_NO;
+ pos = pos->next;
+ }
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# transmissions delayed due to corking"), 1,
+ GNUNET_NO);
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Deferring transmission for %llums due to underfull message
buffer size (%u/%u)\n",
- (unsigned long long) retry_time->rel_value,
- (unsigned int) off,
- (unsigned int) size);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Deferring transmission for %llums due to underfull message
buffer size (%u/%u)\n",
+ (unsigned long long) retry_time->rel_value,
+ (unsigned int) off, (unsigned int) size);
#endif
- return 0;
- }
+ return 0;
+ }
/* select marked messages (up to size) for transmission */
off = 0;
pos = n->messages;
while (pos != last)
+ {
+ if ((pos->size <= size) && (pos->do_transmit == GNUNET_NO))
{
- if ((pos->size <= size) && (pos->do_transmit == GNUNET_NO))
- {
- pos->do_transmit = GNUNET_YES; /* mark for transmission */
- off += pos->size;
- size -= pos->size;
+ pos->do_transmit = GNUNET_YES; /* mark for transmission */
+ off += pos->size;
+ size -= pos->size;
#if DEBUG_CORE > 1
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Selecting message of size %u for transmission\n",
- (unsigned int) pos->size);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Selecting message of size %u for transmission\n",
+ (unsigned int) pos->size);
#endif
- }
- else
- {
+ }
+ else
+ {
#if DEBUG_CORE > 1
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Not selecting message of size %u for transmission at
this time (maximum is %u)\n",
- (unsigned int) pos->size,
- size);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Not selecting message of size %u for transmission at this
time (maximum is %u)\n",
+ (unsigned int) pos->size, size);
#endif
- pos->do_transmit = GNUNET_NO; /* mark for not transmitting! */
- }
- pos = pos->next;
+ pos->do_transmit = GNUNET_NO; /* mark for not transmitting! */
}
+ pos = pos->next;
+ }
#if DEBUG_CORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Selected %llu/%llu bytes of %u/%u plaintext messages for
transmission to `%4s'.\n",
(unsigned long long) off, (unsigned long long) tsize,
- queue_size, (unsigned int) MAX_PEER_QUEUE_SIZE,
- GNUNET_i2s (&n->peer));
+ queue_size, (unsigned int) MAX_PEER_QUEUE_SIZE,
+ GNUNET_i2s (&n->peer));
#endif
return off;
}
@@ -2468,29 +2396,28 @@
char *buf,
size_t size,
struct GNUNET_TIME_Absolute *deadline,
- struct GNUNET_TIME_Relative *retry_time,
- unsigned int *priority)
+ struct GNUNET_TIME_Relative *retry_time, unsigned int *priority)
{
char ntmb[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1];
- struct NotifyTrafficMessage *ntm = (struct NotifyTrafficMessage*) ntmb;
+ struct NotifyTrafficMessage *ntm = (struct NotifyTrafficMessage *) ntmb;
struct MessageEntry *pos;
struct MessageEntry *prev;
struct MessageEntry *next;
size_t ret;
-
+
ret = 0;
*priority = 0;
*deadline = GNUNET_TIME_UNIT_FOREVER_ABS;
*retry_time = GNUNET_TIME_UNIT_FOREVER_REL;
if (0 == select_messages (n, size, retry_time))
- {
+ {
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "No messages selected, will try again in %llu ms\n",
- retry_time->rel_value);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "No messages selected, will try again in %llu ms\n",
+ retry_time->rel_value);
#endif
- return 0;
- }
+ return 0;
+ }
ntm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND);
ntm->ats_count = htonl (0);
ntm->ats.type = htonl (0);
@@ -2499,72 +2426,74 @@
pos = n->messages;
prev = NULL;
while ((pos != NULL) && (size >= sizeof (struct GNUNET_MessageHeader)))
+ {
+ next = pos->next;
+ if (GNUNET_YES == pos->do_transmit)
{
- next = pos->next;
- if (GNUNET_YES == pos->do_transmit)
- {
- GNUNET_assert (pos->size <= size);
- /* do notifications */
- /* FIXME: track if we have *any* client that wants
- full notifications and only do this if that is
- actually true */
- if (pos->size < GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct
NotifyTrafficMessage))
- {
- memcpy (&ntm[1], &pos[1], pos->size);
- ntm->header.size = htons (sizeof (struct NotifyTrafficMessage) +
- sizeof (struct GNUNET_MessageHeader));
- send_to_all_clients (&ntm->header,
- GNUNET_YES,
- GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND);
- }
- else
- {
- /* message too large for 'full' notifications, we do at
- least the 'hdr' type */
- memcpy (&ntm[1],
- &pos[1],
- sizeof (struct GNUNET_MessageHeader));
- }
- ntm->header.size = htons (sizeof (struct NotifyTrafficMessage) +
- pos->size);
- send_to_all_clients (&ntm->header,
- GNUNET_YES,
- GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND);
+ GNUNET_assert (pos->size <= size);
+ /* do notifications */
+ /* FIXME: track if we have *any* client that wants
+ * full notifications and only do this if that is
+ * actually true */
+ if (pos->size <
+ GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct
NotifyTrafficMessage))
+ {
+ memcpy (&ntm[1], &pos[1], pos->size);
+ ntm->header.size = htons (sizeof (struct NotifyTrafficMessage) +
+ sizeof (struct GNUNET_MessageHeader));
+ send_to_all_clients (&ntm->header,
+ GNUNET_YES, GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND);
+ }
+ else
+ {
+ /* message too large for 'full' notifications, we do at
+ * least the 'hdr' type */
+ memcpy (&ntm[1], &pos[1], sizeof (struct GNUNET_MessageHeader));
+ }
+ ntm->header.size = htons (sizeof (struct NotifyTrafficMessage) +
+ pos->size);
+ send_to_all_clients (&ntm->header,
+ GNUNET_YES, GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND);
#if DEBUG_HANDSHAKE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Encrypting %u bytes with message of type %u and size
%u\n",
- pos->size,
- (unsigned int) ntohs(((const struct
GNUNET_MessageHeader*)&pos[1])->type),
- (unsigned int) ntohs(((const struct
GNUNET_MessageHeader*)&pos[1])->size));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Encrypting %u bytes with message of type %u and size %u\n",
+ pos->size,
+ (unsigned int)
+ ntohs (((const struct GNUNET_MessageHeader *)
&pos[1])->type),
+ (unsigned int)
+ ntohs (((const struct GNUNET_MessageHeader *)
+ &pos[1])->size));
#endif
- /* copy for encrypted transmission */
- memcpy (&buf[ret], &pos[1], pos->size);
- ret += pos->size;
- size -= pos->size;
- *priority += pos->priority;
+ /* copy for encrypted transmission */
+ memcpy (&buf[ret], &pos[1], pos->size);
+ ret += pos->size;
+ size -= pos->size;
+ *priority += pos->priority;
#if DEBUG_CORE > 1
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Adding plaintext message of size %u with deadline %llu
ms to batch\n",
- (unsigned int) pos->size,
- (unsigned long long) GNUNET_TIME_absolute_get_remaining
(pos->deadline).rel_value);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Adding plaintext message of size %u with deadline %llu ms
to batch\n",
+ (unsigned int) pos->size,
+ (unsigned long long)
+ GNUNET_TIME_absolute_get_remaining
(pos->deadline).rel_value);
#endif
- deadline->abs_value = GNUNET_MIN (deadline->abs_value,
pos->deadline.abs_value);
- GNUNET_free (pos);
- if (prev == NULL)
- n->messages = next;
- else
- prev->next = next;
- }
+ deadline->abs_value =
+ GNUNET_MIN (deadline->abs_value, pos->deadline.abs_value);
+ GNUNET_free (pos);
+ if (prev == NULL)
+ n->messages = next;
else
- {
- prev = pos;
- }
- pos = next;
+ prev->next = next;
}
+ else
+ {
+ prev = pos;
+ }
+ pos = next;
+ }
#if DEBUG_CORE > 1
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Deadline for message batch is %llu ms\n",
- GNUNET_TIME_absolute_get_remaining (*deadline).rel_value);
+ "Deadline for message batch is %llu ms\n",
+ GNUNET_TIME_absolute_get_remaining (*deadline).rel_value);
#endif
return ret;
}
@@ -2590,32 +2519,32 @@
now = GNUNET_TIME_absolute_get ();
prev = NULL;
pos = n->messages;
- while (pos != NULL)
+ while (pos != NULL)
+ {
+ next = pos->next;
+ delta = GNUNET_TIME_absolute_get_difference (pos->deadline, now);
+ if (delta.rel_value > PAST_EXPIRATION_DISCARD_TIME.rel_value)
{
- next = pos->next;
- delta = GNUNET_TIME_absolute_get_difference (pos->deadline, now);
- if (delta.rel_value > PAST_EXPIRATION_DISCARD_TIME.rel_value)
- {
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Message is %llu ms past due, discarding.\n",
- delta.rel_value);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Message is %llu ms past due, discarding.\n",
+ delta.rel_value);
#endif
- if (prev == NULL)
- n->messages = next;
- else
- prev->next = next;
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# messages discarded
(expired prior to transmission)"),
- 1,
- GNUNET_NO);
- disc = GNUNET_YES;
- GNUNET_free (pos);
- }
+ if (prev == NULL)
+ n->messages = next;
else
- prev = pos;
- pos = next;
+ prev->next = next;
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# messages discarded (expired prior to
transmission)"),
+ 1, GNUNET_NO);
+ disc = GNUNET_YES;
+ GNUNET_free (pos);
}
+ else
+ prev = pos;
+ pos = next;
+ }
if (GNUNET_YES == disc)
schedule_peer_messages (n);
}
@@ -2656,12 +2585,11 @@
#if DEBUG_CORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Retrying key transmission to `%4s'\n",
- GNUNET_i2s (&n->peer));
+ "Retrying key transmission to `%4s'\n", GNUNET_i2s (&n->peer));
#endif
n->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK;
n->set_key_retry_frequency =
- GNUNET_TIME_relative_multiply (n->set_key_retry_frequency, 2);
+ GNUNET_TIME_relative_multiply (n->set_key_retry_frequency, 2);
send_key (n);
}
@@ -2676,7 +2604,7 @@
static void
process_plaintext_neighbour_queue (struct Neighbour *n)
{
- char pbuf[GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE + sizeof (struct
EncryptedMessage)]; /* plaintext */
+ char pbuf[GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE + sizeof (struct
EncryptedMessage)]; /* plaintext */
size_t used;
struct EncryptedMessage *em; /* encrypted message */
struct EncryptedMessage *ph; /* plaintext header */
@@ -2688,66 +2616,66 @@
struct GNUNET_CRYPTO_AuthKey auth_key;
if (n->retry_plaintext_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (n->retry_plaintext_task);
- n->retry_plaintext_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (n->retry_plaintext_task);
+ n->retry_plaintext_task = GNUNET_SCHEDULER_NO_TASK;
+ }
switch (n->status)
- {
- case PEER_STATE_DOWN:
- send_key (n);
+ {
+ case PEER_STATE_DOWN:
+ send_key (n);
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Not yet connected to `%4s', deferring processing of
plaintext messages.\n",
- GNUNET_i2s(&n->peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Not yet connected to `%4s', deferring processing of plaintext
messages.\n",
+ GNUNET_i2s (&n->peer));
#endif
- return;
- case PEER_STATE_KEY_SENT:
- if (n->retry_set_key_task == GNUNET_SCHEDULER_NO_TASK)
- n->retry_set_key_task
- = GNUNET_SCHEDULER_add_delayed (n->set_key_retry_frequency,
- &set_key_retry_task, n);
+ return;
+ case PEER_STATE_KEY_SENT:
+ if (n->retry_set_key_task == GNUNET_SCHEDULER_NO_TASK)
+ n->retry_set_key_task
+ = GNUNET_SCHEDULER_add_delayed (n->set_key_retry_frequency,
+ &set_key_retry_task, n);
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Not yet connected to `%4s', deferring processing of
plaintext messages.\n",
- GNUNET_i2s(&n->peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Not yet connected to `%4s', deferring processing of plaintext
messages.\n",
+ GNUNET_i2s (&n->peer));
#endif
- return;
- case PEER_STATE_KEY_RECEIVED:
- if (n->retry_set_key_task == GNUNET_SCHEDULER_NO_TASK)
- n->retry_set_key_task
- = GNUNET_SCHEDULER_add_delayed (n->set_key_retry_frequency,
- &set_key_retry_task, n);
+ return;
+ case PEER_STATE_KEY_RECEIVED:
+ if (n->retry_set_key_task == GNUNET_SCHEDULER_NO_TASK)
+ n->retry_set_key_task
+ = GNUNET_SCHEDULER_add_delayed (n->set_key_retry_frequency,
+ &set_key_retry_task, n);
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Not yet connected to `%4s', deferring processing of
plaintext messages.\n",
- GNUNET_i2s(&n->peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Not yet connected to `%4s', deferring processing of plaintext
messages.\n",
+ GNUNET_i2s (&n->peer));
#endif
- return;
- case PEER_STATE_KEY_CONFIRMED:
- /* ready to continue */
- break;
- }
+ return;
+ case PEER_STATE_KEY_CONFIRMED:
+ /* ready to continue */
+ break;
+ }
discard_expired_messages (n);
if (n->messages == NULL)
- {
+ {
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Plaintext message queue for `%4s' is empty.\n",
- GNUNET_i2s(&n->peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Plaintext message queue for `%4s' is empty.\n",
+ GNUNET_i2s (&n->peer));
#endif
- return; /* no pending messages */
- }
+ return; /* no pending messages */
+ }
if (n->encrypted_head != NULL)
- {
+ {
#if DEBUG_CORE > 2
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Encrypted message queue for `%4s' is still full, delaying
plaintext processing.\n",
- GNUNET_i2s(&n->peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Encrypted message queue for `%4s' is still full, delaying
plaintext processing.\n",
+ GNUNET_i2s (&n->peer));
#endif
- return; /* wait for messages already encrypted to be
- processed first! */
- }
+ return; /* wait for messages already encrypted to be
+ * processed first! */
+ }
ph = (struct EncryptedMessage *) pbuf;
deadline = GNUNET_TIME_UNIT_FOREVER_ABS;
priority = 0;
@@ -2757,25 +2685,26 @@
GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE,
&deadline, &retry_time, &priority);
if (used == sizeof (struct EncryptedMessage))
- {
+ {
#if DEBUG_CORE > 1
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "No messages selected for transmission to `%4s' at this
time, will try again later.\n",
- GNUNET_i2s(&n->peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "No messages selected for transmission to `%4s' at this time,
will try again later.\n",
+ GNUNET_i2s (&n->peer));
#endif
- /* no messages selected for sending, try again later... */
- n->retry_plaintext_task =
+ /* no messages selected for sending, try again later... */
+ n->retry_plaintext_task =
GNUNET_SCHEDULER_add_delayed (retry_time,
&retry_plaintext_processing, n);
- return;
- }
-#if DEBUG_CORE_QUOTA
+ return;
+ }
+#if DEBUG_CORE_QUOTA
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending %u b/s as new limit to peer `%4s'\n",
- (unsigned int) ntohl (n->bw_in.value__),
- GNUNET_i2s (&n->peer));
+ "Sending %u b/s as new limit to peer `%4s'\n",
+ (unsigned int) ntohl (n->bw_in.value__), GNUNET_i2s (&n->peer));
#endif
- ph->iv_seed = htonl (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
UINT32_MAX));
+ ph->iv_seed =
+ htonl (GNUNET_CRYPTO_random_u32
+ (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX));
ph->sequence_number = htonl (++n->last_sequence_number_sent);
ph->inbound_bw_limit = n->bw_in;
ph->timestamp = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ());
@@ -2791,39 +2720,35 @@
em->iv_seed = ph->iv_seed;
derive_iv (&iv, &n->encrypt_key, ph->iv_seed, &n->peer);
/* encrypt */
-#if DEBUG_HANDSHAKE
+#if DEBUG_HANDSHAKE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Encrypting %u bytes of plaintext messages for `%4s' for
transmission in %llums.\n",
- (unsigned int) used - ENCRYPTED_HEADER_SIZE,
- GNUNET_i2s(&n->peer),
- (unsigned long long) GNUNET_TIME_absolute_get_remaining
(deadline).rel_value);
+ (unsigned int) used - ENCRYPTED_HEADER_SIZE,
+ GNUNET_i2s (&n->peer),
+ (unsigned long long)
+ GNUNET_TIME_absolute_get_remaining (deadline).rel_value);
#endif
GNUNET_assert (GNUNET_OK ==
do_encrypt (n,
&iv,
&ph->sequence_number,
- &em->sequence_number, used -
ENCRYPTED_HEADER_SIZE));
- derive_auth_key (&auth_key,
- &n->encrypt_key,
- ph->iv_seed,
+ &em->sequence_number,
+ used - ENCRYPTED_HEADER_SIZE));
+ derive_auth_key (&auth_key, &n->encrypt_key, ph->iv_seed,
n->encrypt_key_created);
- GNUNET_CRYPTO_hmac (&auth_key,
- &em->sequence_number,
- used - ENCRYPTED_HEADER_SIZE,
- &em->hmac);
+ GNUNET_CRYPTO_hmac (&auth_key, &em->sequence_number,
+ used - ENCRYPTED_HEADER_SIZE, &em->hmac);
#if DEBUG_HANDSHAKE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Authenticated %u bytes of ciphertext %u: `%s'\n",
used - ENCRYPTED_HEADER_SIZE,
GNUNET_CRYPTO_crc32_n (&em->sequence_number,
- used - ENCRYPTED_HEADER_SIZE),
+ used - ENCRYPTED_HEADER_SIZE),
GNUNET_h2s (&em->hmac));
#endif
/* append to transmission list */
GNUNET_CONTAINER_DLL_insert_after (n->encrypted_head,
- n->encrypted_tail,
- n->encrypted_tail,
- me);
+ n->encrypted_tail, n->encrypted_tail, me);
process_encrypted_neighbour_queue (n);
schedule_peer_messages (n);
}
@@ -2838,7 +2763,7 @@
*/
static void
neighbour_quota_update (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+ const struct GNUNET_SCHEDULER_TaskContext *tc);
/**
@@ -2849,12 +2774,10 @@
static void
schedule_quota_update (struct Neighbour *n)
{
- GNUNET_assert (n->quota_update_task ==
- GNUNET_SCHEDULER_NO_TASK);
+ GNUNET_assert (n->quota_update_task == GNUNET_SCHEDULER_NO_TASK);
n->quota_update_task
- = GNUNET_SCHEDULER_add_delayed (QUOTA_UPDATE_FREQUENCY,
- &neighbour_quota_update,
- n);
+ = GNUNET_SCHEDULER_add_delayed (QUOTA_UPDATE_FREQUENCY,
+ &neighbour_quota_update, n);
}
@@ -2872,8 +2795,7 @@
#if DEBUG_CORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Creating neighbour entry for peer `%4s'\n",
- GNUNET_i2s (pid));
+ "Creating neighbour entry for peer `%4s'\n", GNUNET_i2s (pid));
#endif
n = GNUNET_malloc (sizeof (struct Neighbour));
n->peer = *pid;
@@ -2888,13 +2810,14 @@
n->bw_out_external_limit = GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT;
n->ping_challenge = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
UINT32_MAX);
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_put (neighbours,
- &n->peer.hashPubKey,
- n,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
- GNUNET_STATISTICS_set (stats, gettext_noop ("# neighbour entries
allocated"),
- GNUNET_CONTAINER_multihashmap_size (neighbours),
GNUNET_NO);
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONTAINER_multihashmap_put (neighbours,
+ &n->peer.hashPubKey,
+ n,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+ GNUNET_STATISTICS_set (stats, gettext_noop ("# neighbour entries allocated"),
+ GNUNET_CONTAINER_multihashmap_size (neighbours),
+ GNUNET_NO);
neighbour_quota_update (n, NULL);
consider_free_neighbour (n);
return n;
@@ -2917,7 +2840,7 @@
struct Neighbour *n;
struct MessageEntry *prev;
struct MessageEntry *pos;
- struct MessageEntry *e;
+ struct MessageEntry *e;
struct MessageEntry *min_prio_entry;
struct MessageEntry *min_prio_prev;
unsigned int min_prio;
@@ -2927,124 +2850,122 @@
msize = ntohs (message->size);
if (msize <
sizeof (struct SendMessage) + sizeof (struct GNUNET_MessageHeader))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "msize is %u, should be at least %u (in %s:%d)\n",
- msize,
- sizeof (struct SendMessage) + sizeof (struct
GNUNET_MessageHeader),
- __FILE__, __LINE__);
- GNUNET_break (0);
- if (client != NULL)
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "msize is %u, should be at least %u (in %s:%d)\n",
+ msize,
+ sizeof (struct SendMessage) +
+ sizeof (struct GNUNET_MessageHeader), __FILE__, __LINE__);
+ GNUNET_break (0);
+ if (client != NULL)
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
sm = (const struct SendMessage *) message;
msize -= sizeof (struct SendMessage);
- if (0 == memcmp (&sm->peer, &my_identity, sizeof (struct
GNUNET_PeerIdentity)))
- {
- /* loopback */
- GNUNET_SERVER_mst_receive (mst,
- &self,
- (const char*) &sm[1],
- msize,
- GNUNET_YES,
- GNUNET_NO);
- if (client != NULL)
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
- return;
- }
+ if (0 ==
+ memcmp (&sm->peer, &my_identity, sizeof (struct GNUNET_PeerIdentity)))
+ {
+ /* loopback */
+ GNUNET_SERVER_mst_receive (mst,
+ &self,
+ (const char *) &sm[1],
+ msize, GNUNET_YES, GNUNET_NO);
+ if (client != NULL)
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ return;
+ }
n = find_neighbour (&sm->peer);
- if ( (n == NULL) ||
- (GNUNET_YES != n->is_connected) ||
- (n->status != PEER_STATE_KEY_CONFIRMED) )
- {
- /* attempt to send message to peer that is not connected anymore
- (can happen due to asynchrony) */
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# messages discarded
(disconnected)"),
- 1,
- GNUNET_NO);
- if (client != NULL)
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
- return;
- }
+ if ((n == NULL) ||
+ (GNUNET_YES != n->is_connected) ||
+ (n->status != PEER_STATE_KEY_CONFIRMED))
+ {
+ /* attempt to send message to peer that is not connected anymore
+ * (can happen due to asynchrony) */
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# messages discarded (disconnected)"), 1,
+ GNUNET_NO);
+ if (client != NULL)
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ return;
+ }
#if DEBUG_CORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Core received `%s' request, queueing %u bytes of plaintext data
for transmission to `%4s'.\n",
- "SEND",
- (unsigned int) msize,
- GNUNET_i2s (&sm->peer));
+ "SEND", (unsigned int) msize, GNUNET_i2s (&sm->peer));
#endif
discard_expired_messages (n);
/* bound queue size */
/* NOTE: this entire block to bound the queue size should be
- obsolete with the new client-request code and the
- 'schedule_peer_messages' mechanism; we still have this code in
- here for now as a sanity check for the new mechanmism;
- ultimately, we should probably simply reject SEND messages that
- are not 'approved' (or provide a new core API for very unreliable
- delivery that always sends with priority 0). Food for thought. */
+ * obsolete with the new client-request code and the
+ * 'schedule_peer_messages' mechanism; we still have this code in
+ * here for now as a sanity check for the new mechanmism;
+ * ultimately, we should probably simply reject SEND messages that
+ * are not 'approved' (or provide a new core API for very unreliable
+ * delivery that always sends with priority 0). Food for thought. */
min_prio = UINT32_MAX;
min_prio_entry = NULL;
min_prio_prev = NULL;
queue_size = 0;
prev = NULL;
pos = n->messages;
- while (pos != NULL)
+ while (pos != NULL)
+ {
+ if (pos->priority <= min_prio)
{
- if (pos->priority <= min_prio)
- {
- min_prio_entry = pos;
- min_prio_prev = prev;
- min_prio = pos->priority;
- }
- queue_size++;
- prev = pos;
- pos = pos->next;
+ min_prio_entry = pos;
+ min_prio_prev = prev;
+ min_prio = pos->priority;
}
+ queue_size++;
+ prev = pos;
+ pos = pos->next;
+ }
if (queue_size >= MAX_PEER_QUEUE_SIZE)
+ {
+ /* queue full */
+ if (ntohl (sm->priority) <= min_prio)
{
- /* queue full */
- if (ntohl(sm->priority) <= min_prio)
- {
- /* discard new entry; this should no longer happen! */
- GNUNET_break (0);
+ /* discard new entry; this should no longer happen! */
+ GNUNET_break (0);
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Queue full (%u/%u), discarding new request (%u bytes of
type %u)\n",
- queue_size,
- (unsigned int) MAX_PEER_QUEUE_SIZE,
- (unsigned int) msize,
- (unsigned int) ntohs (message->type));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Queue full (%u/%u), discarding new request (%u bytes of
type %u)\n",
+ queue_size,
+ (unsigned int) MAX_PEER_QUEUE_SIZE,
+ (unsigned int) msize, (unsigned int) ntohs (message->type));
#endif
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# discarded CORE_SEND
requests"),
- 1, GNUNET_NO);
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# discarded CORE_SEND
requests"),
+ 1, GNUNET_NO);
- if (client != NULL)
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
- return;
- }
- GNUNET_assert (min_prio_entry != NULL);
- /* discard "min_prio_entry" */
+ if (client != NULL)
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ return;
+ }
+ GNUNET_assert (min_prio_entry != NULL);
+ /* discard "min_prio_entry" */
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Queue full, discarding existing older request\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Queue full, discarding existing older request\n");
#endif
- GNUNET_STATISTICS_update (stats, gettext_noop ("# discarded lower
priority CORE_SEND requests"), 1, GNUNET_NO);
- if (min_prio_prev == NULL)
- n->messages = min_prio_entry->next;
- else
- min_prio_prev->next = min_prio_entry->next;
- GNUNET_free (min_prio_entry);
- }
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# discarded lower priority CORE_SEND
requests"),
+ 1, GNUNET_NO);
+ if (min_prio_prev == NULL)
+ n->messages = min_prio_entry->next;
+ else
+ min_prio_prev->next = min_prio_entry->next;
+ GNUNET_free (min_prio_entry);
+ }
#if DEBUG_CORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Adding transmission request for `%4s' of size %u to queue\n",
- GNUNET_i2s (&sm->peer),
- (unsigned int) msize);
-#endif
+ "Adding transmission request for `%4s' of size %u to queue\n",
+ GNUNET_i2s (&sm->peer), (unsigned int) msize);
+#endif
GNUNET_break (0 == ntohl (sm->reserved));
e = GNUNET_malloc (sizeof (struct MessageEntry) + msize);
e->deadline = GNUNET_TIME_absolute_ntoh (sm->deadline);
@@ -3058,10 +2979,10 @@
prev = NULL;
pos = n->messages;
while ((pos != NULL) && (pos->deadline.abs_value < e->deadline.abs_value))
- {
- prev = pos;
- pos = pos->next;
- }
+ {
+ prev = pos;
+ pos = pos->next;
+ }
if (prev == NULL)
n->messages = e;
else
@@ -3084,46 +3005,41 @@
*/
static void
handle_client_request_connect (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
- const struct ConnectMessage *cm = (const struct ConnectMessage*) message;
+ const struct ConnectMessage *cm = (const struct ConnectMessage *) message;
struct Neighbour *n;
- if (0 == memcmp (&cm->peer,
- &my_identity,
- sizeof (struct GNUNET_PeerIdentity)))
- {
- /* In this case a client has asked us to connect to ourselves, not
really an error! */
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
- return;
- }
+ if (0 == memcmp (&cm->peer,
+ &my_identity, sizeof (struct GNUNET_PeerIdentity)))
+ {
+ /* In this case a client has asked us to connect to ourselves, not really
an error! */
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ return;
+ }
GNUNET_break (ntohl (cm->reserved) == 0);
#if DEBUG_CORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Core received `%s' request for `%4s', will try to establish
connection\n",
- "REQUEST_CONNECT",
- GNUNET_i2s (&cm->peer));
+ "Core received `%s' request for `%4s', will try to establish
connection\n",
+ "REQUEST_CONNECT", GNUNET_i2s (&cm->peer));
#endif
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# connection requests received"),
- 1,
- GNUNET_NO);
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# connection requests received"),
+ 1, GNUNET_NO);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
n = find_neighbour (&cm->peer);
- if ( (n == NULL) ||
- (GNUNET_YES != n->is_connected) )
- {
- GNUNET_TRANSPORT_try_connect (transport,
- &cm->peer);
- }
+ if ((n == NULL) || (GNUNET_YES != n->is_connected))
+ {
+ GNUNET_TRANSPORT_try_connect (transport, &cm->peer);
+ }
else
- {
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# connection requests ignored
(already connected)"),
- 1,
- GNUNET_NO);
- }
+ {
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# connection requests ignored (already
connected)"),
+ 1, GNUNET_NO);
+ }
}
@@ -3153,81 +3069,78 @@
}
if (peer == NULL)
+ {
+#if DEBUG_CORE
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Entered `%s' and `%s' is NULL!\n",
+ "process_hello_retry_send_key", "peer");
+#endif
+ n->pitr = NULL;
+ if (n->public_key != NULL)
{
+ if (n->retry_set_key_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (n->retry_set_key_task);
+ n->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# SET_KEY messages deferred (need public
key)"),
+ -1, GNUNET_NO);
+ send_key (n);
+ }
+ else
+ {
#if DEBUG_CORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Entered `%s' and `%s' is NULL!\n",
- "process_hello_retry_send_key",
- "peer");
+ "Failed to obtain public key for peer `%4s', delaying
processing of SET_KEY\n",
+ GNUNET_i2s (&n->peer));
#endif
- n->pitr = NULL;
- if (n->public_key != NULL)
- {
- if (n->retry_set_key_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (n->retry_set_key_task);
- n->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK;
- }
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# SET_KEY messages deferred
(need public key)"),
- -1,
- GNUNET_NO);
- send_key (n);
- }
- else
- {
-#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 (&n->peer));
-#endif
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# Delayed connecting due to
lack of public key"),
- 1,
- GNUNET_NO);
- if (GNUNET_SCHEDULER_NO_TASK == n->retry_set_key_task)
- n->retry_set_key_task
- = GNUNET_SCHEDULER_add_delayed (n->set_key_retry_frequency,
- &set_key_retry_task, n);
- }
- return;
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# Delayed connecting due to lack of public
key"),
+ 1, GNUNET_NO);
+ if (GNUNET_SCHEDULER_NO_TASK == n->retry_set_key_task)
+ n->retry_set_key_task
+ = GNUNET_SCHEDULER_add_delayed (n->set_key_retry_frequency,
+ &set_key_retry_task, n);
}
+ return;
+ }
#if DEBUG_CORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Entered `%s' for peer `%4s'\n",
- "process_hello_retry_send_key",
- GNUNET_i2s (peer));
+ "process_hello_retry_send_key", GNUNET_i2s (peer));
#endif
if (n->public_key != NULL)
- {
- /* already have public key, why are we here? */
- GNUNET_break (0);
- return;
- }
+ {
+ /* already have public key, why are we here? */
+ GNUNET_break (0);
+ return;
+ }
#if DEBUG_CORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received new `%s' message for `%4s', initiating key
exchange.\n",
- "HELLO",
- GNUNET_i2s (peer));
+ "HELLO", GNUNET_i2s (peer));
#endif
n->public_key =
- GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
+ GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
if (GNUNET_OK != GNUNET_HELLO_get_key (hello, n->public_key))
- {
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# Error extracting public key
from HELLO"),
- 1,
- GNUNET_NO);
- GNUNET_free (n->public_key);
- n->public_key = NULL;
+ {
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# Error extracting public key from HELLO"), 1,
+ GNUNET_NO);
+ GNUNET_free (n->public_key);
+ n->public_key = NULL;
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "GNUNET_HELLO_get_key returned awfully\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "GNUNET_HELLO_get_key returned awfully\n");
#endif
- return;
- }
+ return;
+ }
}
@@ -3247,121 +3160,115 @@
struct GNUNET_CRYPTO_AesInitializationVector iv;
if (n->retry_set_key_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (n->retry_set_key_task);
- n->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (n->retry_set_key_task);
+ n->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK;
+ }
if (n->pitr != NULL)
- {
+ {
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Key exchange in progress with `%4s'.\n",
- GNUNET_i2s (&n->peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Key exchange in progress with `%4s'.\n",
+ GNUNET_i2s (&n->peer));
#endif
- return; /* already in progress */
- }
+ return; /* already in progress */
+ }
if (GNUNET_YES != n->is_connected)
- {
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# Asking transport to connect
(for SET_KEY)"),
- 1,
- GNUNET_NO);
- GNUNET_TRANSPORT_try_connect (transport,
- &n->peer);
- return;
- }
+ {
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# Asking transport to connect (for SET_KEY)"),
+ 1, GNUNET_NO);
+ GNUNET_TRANSPORT_try_connect (transport, &n->peer);
+ return;
+ }
#if DEBUG_CORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Asked to perform key exchange with `%4s'.\n",
GNUNET_i2s (&n->peer));
#endif
if (n->public_key == NULL)
- {
- /* lookup n's public key, then try again */
+ {
+ /* lookup n's public key, then try again */
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Lacking public key for `%4s', trying to obtain one
(send_key).\n",
- GNUNET_i2s (&n->peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Lacking public key for `%4s', trying to obtain one
(send_key).\n",
+ GNUNET_i2s (&n->peer));
#endif
- GNUNET_assert (n->pitr == NULL);
- n->pitr = GNUNET_PEERINFO_iterate (peerinfo,
- &n->peer,
-
GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 20),
- &process_hello_retry_send_key, n);
- return;
- }
+ GNUNET_assert (n->pitr == NULL);
+ n->pitr = GNUNET_PEERINFO_iterate (peerinfo,
+ &n->peer,
+ GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 20),
+ &process_hello_retry_send_key, n);
+ return;
+ }
pos = n->encrypted_head;
while (pos != NULL)
+ {
+ if (GNUNET_YES == pos->is_setkey)
{
- if (GNUNET_YES == pos->is_setkey)
- {
- if (pos->sender_status == n->status)
- {
+ if (pos->sender_status == n->status)
+ {
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "`%s' message for `%4s' queued already\n",
- "SET_KEY",
- GNUNET_i2s (&n->peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "`%s' message for `%4s' queued already\n",
+ "SET_KEY", GNUNET_i2s (&n->peer));
#endif
- goto trigger_processing;
- }
- GNUNET_CONTAINER_DLL_remove (n->encrypted_head,
- n->encrypted_tail,
- pos);
- GNUNET_free (pos);
+ goto trigger_processing;
+ }
+ GNUNET_CONTAINER_DLL_remove (n->encrypted_head, n->encrypted_tail, pos);
+ GNUNET_free (pos);
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Removing queued `%s' message for `%4s', will create a
new one\n",
- "SET_KEY",
- GNUNET_i2s (&n->peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Removing queued `%s' message for `%4s', will create a new
one\n",
+ "SET_KEY", GNUNET_i2s (&n->peer));
#endif
- break;
- }
- pos = pos->next;
+ break;
}
+ pos = pos->next;
+ }
/* update status */
switch (n->status)
- {
- case PEER_STATE_DOWN:
- n->status = PEER_STATE_KEY_SENT;
- break;
- case PEER_STATE_KEY_SENT:
- break;
- case PEER_STATE_KEY_RECEIVED:
- break;
- case PEER_STATE_KEY_CONFIRMED:
- break;
- default:
- GNUNET_break (0);
- break;
- }
-
+ {
+ case PEER_STATE_DOWN:
+ n->status = PEER_STATE_KEY_SENT;
+ break;
+ case PEER_STATE_KEY_SENT:
+ break;
+ case PEER_STATE_KEY_RECEIVED:
+ break;
+ case PEER_STATE_KEY_CONFIRMED:
+ break;
+ default:
+ GNUNET_break (0);
+ break;
+ }
+
/* first, set key message */
me = GNUNET_malloc (sizeof (struct MessageEntry) +
sizeof (struct SetKeyMessage) +
- sizeof (struct PingMessage));
+ sizeof (struct PingMessage));
me->deadline = GNUNET_TIME_relative_to_absolute (MAX_SET_KEY_DELAY);
me->priority = SET_KEY_PRIORITY;
me->size = sizeof (struct SetKeyMessage) + sizeof (struct PingMessage);
me->is_setkey = GNUNET_YES;
- me->got_slack = GNUNET_YES; /* do not defer this one! */
+ me->got_slack = GNUNET_YES; /* do not defer this one! */
me->sender_status = n->status;
GNUNET_CONTAINER_DLL_insert_after (n->encrypted_head,
- n->encrypted_tail,
- n->encrypted_tail,
- me);
+ n->encrypted_tail, n->encrypted_tail, me);
sm = (struct SetKeyMessage *) &me[1];
sm->header.size = htons (sizeof (struct SetKeyMessage));
sm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_SET_KEY);
sm->sender_status = htonl ((int32_t) ((n->status == PEER_STATE_DOWN) ?
PEER_STATE_KEY_SENT : n->status));
sm->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));
sm->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_SET_KEY);
sm->creation_time = GNUNET_TIME_absolute_hton (n->encrypt_key_created);
sm->target = n->peer;
@@ -3369,15 +3276,15 @@
GNUNET_CRYPTO_rsa_encrypt (&n->encrypt_key,
sizeof (struct
GNUNET_CRYPTO_AesSessionKey),
- n->public_key,
- &sm->encrypted_key));
+ n->public_key,
&sm->encrypted_key));
GNUNET_assert (GNUNET_OK ==
GNUNET_CRYPTO_rsa_sign (my_private_key, &sm->purpose,
- &sm->signature));
+ &sm->signature));
pm = (struct PingMessage *) &sm[1];
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);
+ pm->iv_seed =
+ GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX);
derive_iv (&iv, &n->encrypt_key, pm->iv_seed, &n->peer);
pp.challenge = n->ping_challenge;
pp.target = n->peer;
@@ -3385,11 +3292,10 @@
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Encrypting `%s' and `%s' messages with challenge %u for `%4s'
using key %u, IV %u (salt %u).\n",
"SET_KEY", "PING",
- (unsigned int) n->ping_challenge,
- GNUNET_i2s (&n->peer),
- (unsigned int) n->encrypt_key.crc32,
- GNUNET_CRYPTO_crc32_n (&iv, sizeof(iv)),
- pm->iv_seed);
+ (unsigned int) n->ping_challenge,
+ GNUNET_i2s (&n->peer),
+ (unsigned int) n->encrypt_key.crc32,
+ GNUNET_CRYPTO_crc32_n (&iv, sizeof (iv)), pm->iv_seed);
#endif
do_encrypt (n,
&iv,
@@ -3397,24 +3303,25 @@
&pm->target,
sizeof (struct PingMessage) -
((void *) &pm->target - (void *) pm));
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# SET_KEY and PING messages
created"),
- 1,
- GNUNET_NO);
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# SET_KEY and PING messages created"), 1,
+ GNUNET_NO);
#if DEBUG_CORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Have %llu ms left for `%s' transmission.\n",
- (unsigned long long) GNUNET_TIME_absolute_get_remaining
(me->deadline).rel_value,
- "SET_KEY");
+ (unsigned long long)
+ GNUNET_TIME_absolute_get_remaining (me->deadline).rel_value,
+ "SET_KEY");
#endif
- trigger_processing:
+trigger_processing:
/* trigger queue processing */
process_encrypted_neighbour_queue (n);
- if ( (n->status != PEER_STATE_KEY_CONFIRMED) &&
- (GNUNET_SCHEDULER_NO_TASK == n->retry_set_key_task) )
+ if ((n->status != PEER_STATE_KEY_CONFIRMED) &&
+ (GNUNET_SCHEDULER_NO_TASK == n->retry_set_key_task))
n->retry_set_key_task
- = GNUNET_SCHEDULER_add_delayed (n->set_key_retry_frequency,
- &set_key_retry_task, n);
+ = GNUNET_SCHEDULER_add_delayed (n->set_key_retry_frequency,
+ &set_key_retry_task, n);
}
@@ -3429,9 +3336,9 @@
*/
static void
handle_set_key (struct Neighbour *n,
- const struct SetKeyMessage *m,
- const struct GNUNET_TRANSPORT_ATS_Information *ats,
- uint32_t ats_count);
+ const struct SetKeyMessage *m,
+ const struct GNUNET_TRANSPORT_ATS_Information *ats,
+ uint32_t ats_count);
@@ -3462,40 +3369,38 @@
}
if (peer == NULL)
+ {
+ n->skm = NULL;
+ n->pitr = NULL;
+ if (n->public_key != NULL)
{
- n->skm = NULL;
- n->pitr = NULL;
- if (n->public_key != NULL)
- {
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received `%s' for `%4s', continuing processing of `%s'
message.\n",
- "HELLO",
- GNUNET_i2s (&n->peer),
- "SET_KEY");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received `%s' for `%4s', continuing processing of `%s'
message.\n",
+ "HELLO", GNUNET_i2s (&n->peer), "SET_KEY");
#endif
- handle_set_key (n, sm, NULL, 0);
- }
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Ignoring `%s' message due to lack of public key for
peer `%4s' (failed to obtain one).\n"),
- "SET_KEY",
- GNUNET_i2s (&n->peer));
- }
- GNUNET_free (sm);
- return;
+ handle_set_key (n, sm, NULL, 0);
}
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ _
+ ("Ignoring `%s' message due to lack of public key for peer
`%4s' (failed to obtain one).\n"),
+ "SET_KEY", GNUNET_i2s (&n->peer));
+ }
+ GNUNET_free (sm);
+ return;
+ }
if (n->public_key != NULL)
return; /* multiple HELLOs match!? */
n->public_key =
- GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
+ GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
if (GNUNET_OK != GNUNET_HELLO_get_key (hello, n->public_key))
- {
- GNUNET_break_op (0);
- GNUNET_free (n->public_key);
- n->public_key = NULL;
- }
+ {
+ GNUNET_break_op (0);
+ GNUNET_free (n->public_key);
+ n->public_key = NULL;
+ }
}
@@ -3509,8 +3414,8 @@
*/
static void
update_neighbour_performance (struct Neighbour *n,
- const struct GNUNET_TRANSPORT_ATS_Information
*ats,
- uint32_t ats_count)
+ const struct GNUNET_TRANSPORT_ATS_Information
+ *ats, uint32_t ats_count)
{
uint32_t i;
unsigned int j;
@@ -3518,22 +3423,20 @@
if (ats_count == 0)
return;
for (i = 0; i < ats_count; i++)
+ {
+ for (j = 0; j < n->ats_count; j++)
{
- for (j=0;j < n->ats_count; j++)
- {
- if (n->ats[j].type == ats[i].type)
- {
- n->ats[j].value = ats[i].value;
- break;
- }
- }
- if (j == n->ats_count)
- {
- GNUNET_array_append (n->ats,
- n->ats_count,
- ats[i]);
- }
+ if (n->ats[j].type == ats[i].type)
+ {
+ n->ats[j].value = ats[i].value;
+ break;
+ }
}
+ if (j == n->ats_count)
+ {
+ GNUNET_array_append (n->ats, n->ats_count, ats[i]);
+ }
+ }
}
@@ -3548,9 +3451,9 @@
*/
static void
handle_ping (struct Neighbour *n,
- const struct PingMessage *m,
- const struct GNUNET_TRANSPORT_ATS_Information *ats,
- uint32_t ats_count)
+ const struct PingMessage *m,
+ const struct GNUNET_TRANSPORT_ATS_Information *ats,
+ uint32_t ats_count)
{
struct PingMessage t;
struct PongMessage tx;
@@ -3578,37 +3481,32 @@
"PING",
GNUNET_i2s (&t.target),
(unsigned int) t.challenge,
- (unsigned int) n->decrypt_key.crc32,
- GNUNET_CRYPTO_crc32_n (&iv, sizeof(iv)),
- m->iv_seed);
+ (unsigned int) n->decrypt_key.crc32,
+ GNUNET_CRYPTO_crc32_n (&iv, sizeof (iv)), m->iv_seed);
#endif
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# PING messages decrypted"),
- 1,
- GNUNET_NO);
+ gettext_noop ("# PING messages decrypted"),
+ 1, GNUNET_NO);
if (0 != memcmp (&t.target,
&my_identity, sizeof (struct GNUNET_PeerIdentity)))
- {
- char sender[9];
- char peer[9];
+ {
+ char sender[9];
+ char peer[9];
- GNUNET_snprintf(sender, sizeof (sender), "%8s", GNUNET_i2s (&n->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"),
- sender,
- GNUNET_i2s (&my_identity),
- peer);
- GNUNET_break_op (0);
- return;
- }
+ GNUNET_snprintf (sender, sizeof (sender), "%8s", GNUNET_i2s (&n->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"),
+ sender, GNUNET_i2s (&my_identity), peer);
+ GNUNET_break_op (0);
+ return;
+ }
update_neighbour_performance (n, ats, ats_count);
me = GNUNET_malloc (sizeof (struct MessageEntry) +
sizeof (struct PongMessage));
GNUNET_CONTAINER_DLL_insert_after (n->encrypted_head,
- n->encrypted_tail,
- n->encrypted_tail,
- me);
+ n->encrypted_tail, n->encrypted_tail, me);
me->deadline = GNUNET_TIME_relative_to_absolute (MAX_PONG_DELAY);
me->priority = PONG_PRIORITY;
me->size = sizeof (struct PongMessage);
@@ -3618,7 +3516,8 @@
tp = (struct PongMessage *) &me[1];
tp->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_PONG);
tp->header.size = htons (sizeof (struct PongMessage));
- tp->iv_seed = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE,
UINT32_MAX);
+ tp->iv_seed =
+ GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX);
derive_pong_iv (&iv, &n->encrypt_key, tp->iv_seed, t.challenge, &n->peer);
do_encrypt (n,
&iv,
@@ -3626,18 +3525,16 @@
&tp->challenge,
sizeof (struct PongMessage) -
((void *) &tp->challenge - (void *) tp));
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# PONG messages created"),
- 1,
- GNUNET_NO);
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# PONG messages created"),
+ 1, GNUNET_NO);
#if DEBUG_HANDSHAKE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Encrypting `%s' with challenge %u using key %u, IV %u (salt
%u)\n",
- "PONG",
+ "PONG",
(unsigned int) t.challenge,
- (unsigned int) n->encrypt_key.crc32,
- GNUNET_CRYPTO_crc32_n (&iv, sizeof(iv)),
- tp->iv_seed);
+ (unsigned int) n->encrypt_key.crc32,
+ GNUNET_CRYPTO_crc32_n (&iv, sizeof (iv)), tp->iv_seed);
#endif
/* trigger queue processing */
process_encrypted_neighbour_queue (n);
@@ -3653,10 +3550,10 @@
* @param ats_count number of entries in ats (excluding 0-termination)
*/
static void
-handle_pong (struct Neighbour *n,
- const struct PongMessage *m,
- const struct GNUNET_TRANSPORT_ATS_Information *ats,
- uint32_t ats_count)
+handle_pong (struct Neighbour *n,
+ const struct PongMessage *m,
+ const struct GNUNET_TRANSPORT_ATS_Information *ats,
+ uint32_t ats_count)
{
struct PongMessage t;
struct ConnectNotifyMessage *cnm;
@@ -3673,7 +3570,7 @@
/* mark as garbage, just to be sure */
memset (&t, 255, sizeof (t));
derive_pong_iv (&iv, &n->decrypt_key, m->iv_seed, n->ping_challenge,
- &my_identity);
+ &my_identity);
if (GNUNET_OK !=
do_decrypt (n,
&iv,
@@ -3681,14 +3578,13 @@
&t.challenge,
sizeof (struct PongMessage) -
((void *) &m->challenge - (void *) m)))
- {
- GNUNET_break_op (0);
- return;
- }
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# PONG messages decrypted"),
- 1,
- GNUNET_NO);
+ {
+ GNUNET_break_op (0);
+ return;
+ }
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# PONG messages decrypted"),
+ 1, GNUNET_NO);
#if DEBUG_HANDSHAKE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Decrypted `%s' from `%4s' with challenge %u using key %u, IV %u
(salt %u)\n",
@@ -3696,115 +3592,107 @@
GNUNET_i2s (&t.target),
(unsigned int) t.challenge,
(unsigned int) n->decrypt_key.crc32,
- GNUNET_CRYPTO_crc32_n (&iv, sizeof(iv)),
- m->iv_seed);
+ GNUNET_CRYPTO_crc32_n (&iv, sizeof (iv)), m->iv_seed);
#endif
if ((0 != memcmp (&t.target,
&n->peer,
sizeof (struct GNUNET_PeerIdentity))) ||
(n->ping_challenge != t.challenge))
- {
- /* PONG malformed */
+ {
+ /* PONG malformed */
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received malformed `%s' wanted sender `%4s' with challenge
%u\n",
- "PONG",
- GNUNET_i2s (&n->peer),
- (unsigned int) n->ping_challenge);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received malformed `%s' received from `%4s' with challenge
%u\n",
- "PONG", GNUNET_i2s (&t.target),
- (unsigned int) t.challenge);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received malformed `%s' wanted sender `%4s' with challenge
%u\n",
+ "PONG",
+ GNUNET_i2s (&n->peer), (unsigned int) n->ping_challenge);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received malformed `%s' received from `%4s' with challenge
%u\n",
+ "PONG", GNUNET_i2s (&t.target), (unsigned int) t.challenge);
#endif
- GNUNET_break_op (n->ping_challenge != t.challenge);
- return;
- }
+ GNUNET_break_op (n->ping_challenge != t.challenge);
+ return;
+ }
switch (n->status)
+ {
+ case PEER_STATE_DOWN:
+ GNUNET_break (0); /* should be impossible */
+ return;
+ case PEER_STATE_KEY_SENT:
+ GNUNET_break (0); /* should be impossible, how did we decrypt? */
+ return;
+ case PEER_STATE_KEY_RECEIVED:
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# Session keys confirmed via PONG"), 1,
+ GNUNET_NO);
+ n->status = PEER_STATE_KEY_CONFIRMED;
{
- case PEER_STATE_DOWN:
- GNUNET_break (0); /* should be impossible */
- return;
- case PEER_STATE_KEY_SENT:
- GNUNET_break (0); /* should be impossible, how did we decrypt? */
- return;
- case PEER_STATE_KEY_RECEIVED:
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# Session keys confirmed via
PONG"),
- 1,
- GNUNET_NO);
- n->status = PEER_STATE_KEY_CONFIRMED;
- {
- struct GNUNET_MessageHeader *hdr;
+ struct GNUNET_MessageHeader *hdr;
- hdr = compute_type_map_message ();
- send_type_map_to_neighbour (hdr, &n->peer.hashPubKey, n);
- GNUNET_free (hdr);
- }
- if (n->bw_out_external_limit.value__ != t.inbound_bw_limit.value__)
- {
- n->bw_out_external_limit = t.inbound_bw_limit;
- n->bw_out = GNUNET_BANDWIDTH_value_min (n->bw_out_external_limit,
- n->bw_out_internal_limit);
- GNUNET_BANDWIDTH_tracker_update_quota (&n->available_send_window,
- n->bw_out);
- GNUNET_TRANSPORT_set_quota (transport,
- &n->peer,
- n->bw_in,
- n->bw_out);
- }
+ hdr = compute_type_map_message ();
+ send_type_map_to_neighbour (hdr, &n->peer.hashPubKey, n);
+ GNUNET_free (hdr);
+ }
+ if (n->bw_out_external_limit.value__ != t.inbound_bw_limit.value__)
+ {
+ n->bw_out_external_limit = t.inbound_bw_limit;
+ n->bw_out = GNUNET_BANDWIDTH_value_min (n->bw_out_external_limit,
+ n->bw_out_internal_limit);
+ GNUNET_BANDWIDTH_tracker_update_quota (&n->available_send_window,
+ n->bw_out);
+ GNUNET_TRANSPORT_set_quota (transport, &n->peer, n->bw_in, n->bw_out);
+ }
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Confirmed key via `%s' message for peer `%4s'\n",
- "PONG", GNUNET_i2s (&n->peer));
-#endif
- if (n->retry_set_key_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (n->retry_set_key_task);
- n->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK;
- }
- update_neighbour_performance (n, ats, ats_count);
- size = sizeof (struct ConnectNotifyMessage) +
- (n->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
- if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
- {
- GNUNET_break (0);
- /* recovery strategy: throw away performance data */
- GNUNET_array_grow (n->ats,
- n->ats_count,
- 0);
- size = sizeof (struct PeerStatusNotifyMessage) +
- n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
- }
- cnm = (struct ConnectNotifyMessage*) buf;
- cnm->header.size = htons (size);
- cnm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT);
- cnm->ats_count = htonl (n->ats_count);
- cnm->peer = n->peer;
- mats = &cnm->ats;
- memcpy (mats,
- n->ats,
- n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
- mats[n->ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
- mats[n->ats_count].value = htonl (0);
- send_to_all_clients (&cnm->header,
- GNUNET_NO,
- GNUNET_CORE_OPTION_SEND_CONNECT);
- process_encrypted_neighbour_queue (n);
- /* fall-through! */
- case PEER_STATE_KEY_CONFIRMED:
- n->last_activity = GNUNET_TIME_absolute_get ();
- if (n->keep_alive_task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel (n->keep_alive_task);
- n->keep_alive_task
- = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide
(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 2),
- &send_keep_alive,
- n);
- handle_peer_status_change (n);
- break;
- default:
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Confirmed key via `%s' message for peer `%4s'\n",
+ "PONG", GNUNET_i2s (&n->peer));
+#endif
+ if (n->retry_set_key_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (n->retry_set_key_task);
+ n->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ update_neighbour_performance (n, ats, ats_count);
+ size = sizeof (struct ConnectNotifyMessage) +
+ (n->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
+ if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
+ {
GNUNET_break (0);
- break;
+ /* recovery strategy: throw away performance data */
+ GNUNET_array_grow (n->ats, n->ats_count, 0);
+ size = sizeof (struct PeerStatusNotifyMessage) +
+ n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
}
+ cnm = (struct ConnectNotifyMessage *) buf;
+ cnm->header.size = htons (size);
+ cnm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT);
+ cnm->ats_count = htonl (n->ats_count);
+ cnm->peer = n->peer;
+ mats = &cnm->ats;
+ memcpy (mats,
+ n->ats,
+ n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
+ mats[n->ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
+ mats[n->ats_count].value = htonl (0);
+ send_to_all_clients (&cnm->header,
+ GNUNET_NO, GNUNET_CORE_OPTION_SEND_CONNECT);
+ process_encrypted_neighbour_queue (n);
+ /* fall-through! */
+ case PEER_STATE_KEY_CONFIRMED:
+ n->last_activity = GNUNET_TIME_absolute_get ();
+ if (n->keep_alive_task != GNUNET_SCHEDULER_NO_TASK)
+ GNUNET_SCHEDULER_cancel (n->keep_alive_task);
+ n->keep_alive_task
+ =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide
+
(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
+ 2), &send_keep_alive, n);
+ handle_peer_status_change (n);
+ break;
+ default:
+ GNUNET_break (0);
+ break;
+ }
}
@@ -3818,10 +3706,10 @@
* @param ats_count number of entries in ats (excluding 0-termination)
*/
static void
-handle_set_key (struct Neighbour *n,
- const struct SetKeyMessage *m,
- const struct GNUNET_TRANSPORT_ATS_Information *ats,
- uint32_t ats_count)
+handle_set_key (struct Neighbour *n,
+ const struct SetKeyMessage *m,
+ const struct GNUNET_TRANSPORT_ATS_Information *ats,
+ uint32_t ats_count)
{
struct SetKeyMessage *m_cpy;
struct GNUNET_TIME_Absolute t;
@@ -3836,45 +3724,44 @@
"SET_KEY", GNUNET_i2s (&n->peer));
#endif
if (n->public_key == NULL)
+ {
+ if (n->pitr != NULL)
{
- if (n->pitr != NULL)
- {
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Ignoring `%s' message due to lack of public key for peer
(still trying to obtain one).\n",
- "SET_KEY");
-#endif
- return;
- }
-#if DEBUG_CORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Lacking public key for peer, trying to obtain one
(handle_set_key).\n");
+ "Ignoring `%s' message due to lack of public key for peer
(still trying to obtain one).\n",
+ "SET_KEY");
#endif
- m_cpy = GNUNET_malloc (sizeof (struct SetKeyMessage));
- memcpy (m_cpy, m, sizeof (struct SetKeyMessage));
- /* lookup n's public key, then try again */
- GNUNET_assert (n->skm == NULL);
- n->skm = m_cpy;
- n->pitr = GNUNET_PEERINFO_iterate (peerinfo,
- &n->peer,
- GNUNET_TIME_UNIT_MINUTES,
- &process_hello_retry_handle_set_key,
n);
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# SET_KEY messages deferred
(need public key)"),
- 1,
- GNUNET_NO);
return;
}
+#if DEBUG_CORE
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Lacking public key for peer, trying to obtain one
(handle_set_key).\n");
+#endif
+ m_cpy = GNUNET_malloc (sizeof (struct SetKeyMessage));
+ memcpy (m_cpy, m, sizeof (struct SetKeyMessage));
+ /* lookup n's public key, then try again */
+ GNUNET_assert (n->skm == NULL);
+ n->skm = m_cpy;
+ n->pitr = GNUNET_PEERINFO_iterate (peerinfo,
+ &n->peer,
+ GNUNET_TIME_UNIT_MINUTES,
+ &process_hello_retry_handle_set_key, n);
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# SET_KEY messages deferred (need public
key)"),
+ 1, GNUNET_NO);
+ return;
+ }
if (0 != memcmp (&m->target,
- &my_identity,
- sizeof (struct GNUNET_PeerIdentity)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Received `%s' message that was for `%s', not for me.
Ignoring.\n"),
- "SET_KEY",
- GNUNET_i2s (&m->target));
- return;
- }
+ &my_identity, sizeof (struct GNUNET_PeerIdentity)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ _
+ ("Received `%s' message that was for `%s', not for me.
Ignoring.\n"),
+ "SET_KEY", GNUNET_i2s (&m->target));
+ return;
+ }
if ((ntohl (m->purpose.size) !=
sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
sizeof (struct GNUNET_TIME_AbsoluteNBO) +
@@ -3883,107 +3770,103 @@
(GNUNET_OK !=
GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_SET_KEY,
&m->purpose, &m->signature, n->public_key)))
- {
- /* invalid signature */
- GNUNET_break_op (0);
- return;
- }
+ {
+ /* invalid signature */
+ GNUNET_break_op (0);
+ return;
+ }
t = GNUNET_TIME_absolute_ntoh (m->creation_time);
if (((n->status == PEER_STATE_KEY_RECEIVED) ||
(n->status == PEER_STATE_KEY_CONFIRMED)) &&
(t.abs_value < n->decrypt_key_created.abs_value))
- {
- /* this could rarely happen due to massive re-ordering of
- messages on the network level, but is most likely either
- a bug or some adversary messing with us. Report. */
- GNUNET_break_op (0);
- return;
- }
+ {
+ /* this could rarely happen due to massive re-ordering of
+ * messages on the network level, but is most likely either
+ * a bug or some adversary messing with us. Report. */
+ GNUNET_break_op (0);
+ return;
+ }
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Decrypting key material.\n");
-#endif
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decrypting key material.\n");
+#endif
if ((GNUNET_CRYPTO_rsa_decrypt (my_private_key,
&m->encrypted_key,
&k,
sizeof (struct GNUNET_CRYPTO_AesSessionKey))
!= sizeof (struct GNUNET_CRYPTO_AesSessionKey)) ||
(GNUNET_OK != GNUNET_CRYPTO_aes_check_session_key (&k)))
- {
- /* failed to decrypt !? */
- GNUNET_break_op (0);
- return;
- }
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# SET_KEY messages decrypted"),
- 1,
- GNUNET_NO);
+ {
+ /* failed to decrypt !? */
+ GNUNET_break_op (0);
+ return;
+ }
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# SET_KEY messages decrypted"),
+ 1, GNUNET_NO);
n->decrypt_key = k;
if (n->decrypt_key_created.abs_value != t.abs_value)
- {
- /* fresh key, reset sequence numbers */
- n->last_sequence_number_received = 0;
- n->last_packets_bitmap = 0;
- n->decrypt_key_created = t;
- }
+ {
+ /* fresh key, reset sequence numbers */
+ n->last_sequence_number_received = 0;
+ n->last_packets_bitmap = 0;
+ n->decrypt_key_created = t;
+ }
update_neighbour_performance (n, ats, ats_count);
sender_status = (enum PeerStateMachine) ntohl (m->sender_status);
switch (n->status)
+ {
+ case PEER_STATE_DOWN:
+ n->status = PEER_STATE_KEY_RECEIVED;
+#if DEBUG_CORE
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Responding to `%s' with my own key.\n", "SET_KEY");
+#endif
+ send_key (n);
+ break;
+ case PEER_STATE_KEY_SENT:
+ case PEER_STATE_KEY_RECEIVED:
+ n->status = PEER_STATE_KEY_RECEIVED;
+ if ((sender_status != PEER_STATE_KEY_RECEIVED) &&
+ (sender_status != PEER_STATE_KEY_CONFIRMED))
{
- case PEER_STATE_DOWN:
- n->status = PEER_STATE_KEY_RECEIVED;
#if DEBUG_CORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Responding to `%s' with my own key.\n", "SET_KEY");
+ "Responding to `%s' with my own key (other peer has status
%u).\n",
+ "SET_KEY", (unsigned int) sender_status);
#endif
send_key (n);
- break;
- case PEER_STATE_KEY_SENT:
- case PEER_STATE_KEY_RECEIVED:
- n->status = PEER_STATE_KEY_RECEIVED;
- if ((sender_status != PEER_STATE_KEY_RECEIVED) &&
- (sender_status != PEER_STATE_KEY_CONFIRMED))
- {
+ }
+ break;
+ case PEER_STATE_KEY_CONFIRMED:
+ if ((sender_status != PEER_STATE_KEY_RECEIVED) &&
+ (sender_status != PEER_STATE_KEY_CONFIRMED))
+ {
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Responding to `%s' with my own key (other peer has
status %u).\n",
- "SET_KEY",
- (unsigned int) sender_status);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Responding to `%s' with my own key (other peer has status
%u), I was already fully up.\n",
+ "SET_KEY", (unsigned int) sender_status);
#endif
- send_key (n);
- }
- break;
- case PEER_STATE_KEY_CONFIRMED:
- if ((sender_status != PEER_STATE_KEY_RECEIVED) &&
- (sender_status != PEER_STATE_KEY_CONFIRMED))
- {
-#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Responding to `%s' with my own key (other peer has
status %u), I was already fully up.\n",
- "SET_KEY",
- (unsigned int) sender_status);
-#endif
- send_key (n);
- }
- break;
- default:
- GNUNET_break (0);
- break;
+ send_key (n);
}
+ break;
+ default:
+ GNUNET_break (0);
+ break;
+ }
if (n->pending_ping != NULL)
- {
- ping = n->pending_ping;
- n->pending_ping = NULL;
- handle_ping (n, ping, NULL, 0);
- GNUNET_free (ping);
- }
+ {
+ ping = n->pending_ping;
+ n->pending_ping = NULL;
+ handle_ping (n, ping, NULL, 0);
+ GNUNET_free (ping);
+ }
if (n->pending_pong != NULL)
- {
- pong = n->pending_pong;
- n->pending_pong = NULL;
- handle_pong (n, pong, NULL, 0);
- GNUNET_free (pong);
- }
+ {
+ pong = n->pending_pong;
+ n->pending_pong = NULL;
+ handle_pong (n, pong, NULL, 0);
+ GNUNET_free (pong);
+ }
}
@@ -3997,31 +3880,29 @@
*/
static void
send_p2p_message_to_client (struct Neighbour *sender,
- struct Client *client,
- const void *m, size_t msize)
+ struct Client *client, const void *m, size_t msize)
{
size_t size = msize + sizeof (struct NotifyTrafficMessage) +
- (sender->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
+ (sender->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
char buf[size];
struct NotifyTrafficMessage *ntm;
struct GNUNET_TRANSPORT_ATS_Information *ats;
GNUNET_assert (GNUNET_YES == sender->is_connected);
if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
- {
- GNUNET_break (0);
- /* recovery strategy: throw performance data away... */
- GNUNET_array_grow (sender->ats,
- sender->ats_count,
- 0);
- size = msize + sizeof (struct NotifyTrafficMessage) +
- (sender->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
- }
+ {
+ GNUNET_break (0);
+ /* recovery strategy: throw performance data away... */
+ GNUNET_array_grow (sender->ats, sender->ats_count, 0);
+ size = msize + sizeof (struct NotifyTrafficMessage) +
+ (sender->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
+ }
#if DEBUG_CORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Core service passes message from `%4s' of type %u to client.\n",
- GNUNET_i2s(&sender->peer),
- (unsigned int) ntohs (((const struct GNUNET_MessageHeader *)
m)->type));
+ GNUNET_i2s (&sender->peer),
+ (unsigned int)
+ ntohs (((const struct GNUNET_MessageHeader *) m)->type));
#endif
ntm = (struct NotifyTrafficMessage *) buf;
ntm->header.size = htons (size);
@@ -4030,13 +3911,11 @@
ntm->peer = sender->peer;
ats = &ntm->ats;
memcpy (ats,
- sender->ats,
- sizeof (struct GNUNET_TRANSPORT_ATS_Information) * sender->ats_count);
+ sender->ats,
+ sizeof (struct GNUNET_TRANSPORT_ATS_Information) *
sender->ats_count);
ats[sender->ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
- ats[sender->ats_count].value = htonl (0);
- memcpy (&ats[sender->ats_count+1],
- m,
- msize);
+ ats[sender->ats_count].value = htonl (0);
+ memcpy (&ats[sender->ats_count + 1], m, msize);
send_to_client (client, &ntm->header, GNUNET_YES);
}
@@ -4049,9 +3928,7 @@
* @param m the message
*/
static void
-deliver_message (void *cls,
- void *client,
- const struct GNUNET_MessageHeader *m)
+deliver_message (void *cls, void *client, const struct GNUNET_MessageHeader *m)
{
struct Neighbour *sender = client;
size_t msize = ntohs (m->size);
@@ -4065,66 +3942,61 @@
type = ntohs (m->type);
#if DEBUG_CORE > 1
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received encapsulated message of type %u and size %u from
`%4s'\n",
- (unsigned int) type,
- ntohs (m->size),
- GNUNET_i2s (&sender->peer));
+ "Received encapsulated message of type %u and size %u from
`%4s'\n",
+ (unsigned int) type, ntohs (m->size), GNUNET_i2s
(&sender->peer));
#endif
GNUNET_snprintf (buf,
- sizeof(buf),
- gettext_noop ("# bytes of messages of type %u received"),
- (unsigned int) type);
- GNUNET_STATISTICS_update (stats,
- buf,
- msize,
- GNUNET_NO);
- if ( (GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP == type) ||
- (GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP == type) )
- {
- /* FIXME: update message type map for 'Neighbour' */
- return;
- }
+ sizeof (buf),
+ gettext_noop ("# bytes of messages of type %u received"),
+ (unsigned int) type);
+ GNUNET_STATISTICS_update (stats, buf, msize, GNUNET_NO);
+ if ((GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP == type) ||
+ (GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP == type))
+ {
+ /* FIXME: update message type map for 'Neighbour' */
+ return;
+ }
dropped = GNUNET_YES;
cpos = clients;
while (cpos != NULL)
+ {
+ deliver_full = GNUNET_NO;
+ if (0 != (cpos->options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND))
+ deliver_full = GNUNET_YES;
+ else
{
- deliver_full = GNUNET_NO;
- if (0 != (cpos->options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND))
+ for (tpos = 0; tpos < cpos->tcnt; tpos++)
+ {
+ if (type != cpos->types[tpos])
+ continue;
deliver_full = GNUNET_YES;
- else
- {
- for (tpos = 0; tpos < cpos->tcnt; tpos++)
- {
- if (type != cpos->types[tpos])
- continue;
- deliver_full = GNUNET_YES;
- break;
- }
- }
- if (GNUNET_YES == deliver_full)
- {
- send_p2p_message_to_client (sender, cpos, m, msize);
- dropped = GNUNET_NO;
- }
- else if (cpos->options & GNUNET_CORE_OPTION_SEND_HDR_INBOUND)
- {
- send_p2p_message_to_client (sender, cpos, m,
- sizeof (struct GNUNET_MessageHeader));
- }
- cpos = cpos->next;
+ break;
+ }
}
- if (dropped == GNUNET_YES)
+ if (GNUNET_YES == deliver_full)
{
+ send_p2p_message_to_client (sender, cpos, m, msize);
+ dropped = GNUNET_NO;
+ }
+ else if (cpos->options & GNUNET_CORE_OPTION_SEND_HDR_INBOUND)
+ {
+ send_p2p_message_to_client (sender, cpos, m,
+ sizeof (struct GNUNET_MessageHeader));
+ }
+ cpos = cpos->next;
+ }
+ if (dropped == GNUNET_YES)
+ {
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Message of type %u from `%4s' not delivered to any
client.\n",
- (unsigned int) type,
- GNUNET_i2s (&sender->peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Message of type %u from `%4s' not delivered to any client.\n",
+ (unsigned int) type, GNUNET_i2s (&sender->peer));
#endif
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# messages not delivered to any
client"),
- 1, GNUNET_NO);
- }
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# messages not delivered to any client"), 1,
+ GNUNET_NO);
+ }
}
@@ -4140,8 +4012,8 @@
static void
handle_encrypted_message (struct Neighbour *n,
const struct EncryptedMessage *m,
- const struct GNUNET_TRANSPORT_ATS_Information *ats,
- uint32_t ats_count)
+ const struct GNUNET_TRANSPORT_ATS_Information *ats,
+ uint32_t ats_count)
{
size_t size = ntohs (m->header.size);
char buf[size];
@@ -4156,147 +4028,140 @@
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Core service receives `%s' request from `%4s'.\n",
"ENCRYPTED_MESSAGE", GNUNET_i2s (&n->peer));
-#endif
+#endif
/* validate hash */
derive_auth_key (&auth_key,
- &n->decrypt_key,
- m->iv_seed,
- n->decrypt_key_created);
+ &n->decrypt_key, m->iv_seed, n->decrypt_key_created);
GNUNET_CRYPTO_hmac (&auth_key,
- &m->sequence_number,
- size - ENCRYPTED_HEADER_SIZE, &ph);
+ &m->sequence_number, size - ENCRYPTED_HEADER_SIZE, &ph);
#if DEBUG_HANDSHAKE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Re-Authenticated %u bytes of ciphertext (`%u'): `%s'\n",
- (unsigned int) size - ENCRYPTED_HEADER_SIZE,
+ (unsigned int) size - ENCRYPTED_HEADER_SIZE,
GNUNET_CRYPTO_crc32_n (&m->sequence_number,
- size - ENCRYPTED_HEADER_SIZE),
- GNUNET_h2s (&ph));
+ size - ENCRYPTED_HEADER_SIZE),
+ GNUNET_h2s (&ph));
#endif
- if (0 != memcmp (&ph,
- &m->hmac,
- sizeof (GNUNET_HashCode)))
- {
- /* checksum failed */
- GNUNET_break_op (0);
- return;
- }
+ if (0 != memcmp (&ph, &m->hmac, sizeof (GNUNET_HashCode)))
+ {
+ /* checksum failed */
+ GNUNET_break_op (0);
+ return;
+ }
derive_iv (&iv, &n->decrypt_key, m->iv_seed, &my_identity);
/* decrypt */
if (GNUNET_OK !=
do_decrypt (n,
&iv,
&m->sequence_number,
- &buf[ENCRYPTED_HEADER_SIZE],
- size - ENCRYPTED_HEADER_SIZE))
+ &buf[ENCRYPTED_HEADER_SIZE], size - ENCRYPTED_HEADER_SIZE))
return;
pt = (struct EncryptedMessage *) buf;
/* validate sequence number */
snum = ntohl (pt->sequence_number);
if (n->last_sequence_number_received == snum)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Received duplicate message, ignoring.\n");
+ /* duplicate, ignore */
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# bytes dropped (duplicates)"),
+ size, GNUNET_NO);
+ return;
+ }
+ if ((n->last_sequence_number_received > snum) &&
+ (n->last_sequence_number_received - snum > 32))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Received ancient out of sequence message, ignoring.\n");
+ /* ancient out of sequence, ignore */
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# bytes dropped (out of sequence)"), size,
+ GNUNET_NO);
+ return;
+ }
+ if (n->last_sequence_number_received > snum)
+ {
+ unsigned int rotbit = 1 << (n->last_sequence_number_received - snum - 1);
+
+ if ((n->last_packets_bitmap & rotbit) != 0)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Received duplicate message, ignoring.\n");
- /* duplicate, ignore */
GNUNET_STATISTICS_update (stats,
gettext_noop ("# bytes dropped (duplicates)"),
- size,
- GNUNET_NO);
+ size, GNUNET_NO);
+ /* duplicate, ignore */
return;
}
- if ((n->last_sequence_number_received > snum) &&
- (n->last_sequence_number_received - snum > 32))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Received ancient out of sequence message, ignoring.\n");
- /* ancient out of sequence, ignore */
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# bytes dropped (out of
sequence)"),
- size,
- GNUNET_NO);
- return;
- }
- if (n->last_sequence_number_received > snum)
- {
- unsigned int rotbit =
- 1 << (n->last_sequence_number_received - snum - 1);
- if ((n->last_packets_bitmap & rotbit) != 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Received duplicate message, ignoring.\n");
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# bytes dropped
(duplicates)"),
- size,
- GNUNET_NO);
- /* duplicate, ignore */
- return;
- }
- n->last_packets_bitmap |= rotbit;
- }
+ n->last_packets_bitmap |= rotbit;
+ }
if (n->last_sequence_number_received < snum)
- {
- int shift = (snum - n->last_sequence_number_received);
- if (shift >= 8 * sizeof(n->last_packets_bitmap))
- n->last_packets_bitmap = 0;
- else
- n->last_packets_bitmap <<= shift;
- n->last_sequence_number_received = snum;
- }
+ {
+ int shift = (snum - n->last_sequence_number_received);
+ if (shift >= 8 * sizeof (n->last_packets_bitmap))
+ n->last_packets_bitmap = 0;
+ else
+ n->last_packets_bitmap <<= shift;
+ n->last_sequence_number_received = snum;
+ }
+
/* check timestamp */
t = GNUNET_TIME_absolute_ntoh (pt->timestamp);
- if (GNUNET_TIME_absolute_get_duration (t).rel_value >
MAX_MESSAGE_AGE.rel_value)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _
- ("Message received far too old (%llu ms). Content
ignored.\n"),
- GNUNET_TIME_absolute_get_duration (t).rel_value);
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# bytes dropped (ancient
message)"),
- size,
- GNUNET_NO);
- return;
- }
+ if (GNUNET_TIME_absolute_get_duration (t).rel_value >
+ MAX_MESSAGE_AGE.rel_value)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _
+ ("Message received far too old (%llu ms). Content ignored.\n"),
+ GNUNET_TIME_absolute_get_duration (t).rel_value);
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# bytes dropped (ancient message)"), size,
+ GNUNET_NO);
+ return;
+ }
/* process decrypted message(s) */
if (n->bw_out_external_limit.value__ != pt->inbound_bw_limit.value__)
- {
+ {
#if DEBUG_CORE_SET_QUOTA
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received %u b/s as new inbound limit for peer `%4s'\n",
- (unsigned int) ntohl (pt->inbound_bw_limit.value__),
- GNUNET_i2s (&n->peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received %u b/s as new inbound limit for peer `%4s'\n",
+ (unsigned int) ntohl (pt->inbound_bw_limit.value__),
+ GNUNET_i2s (&n->peer));
#endif
- n->bw_out_external_limit = pt->inbound_bw_limit;
- n->bw_out = GNUNET_BANDWIDTH_value_min (n->bw_out_external_limit,
- n->bw_out_internal_limit);
- GNUNET_BANDWIDTH_tracker_update_quota (&n->available_send_window,
- n->bw_out);
- GNUNET_TRANSPORT_set_quota (transport,
- &n->peer,
- n->bw_in,
- n->bw_out);
- }
+ n->bw_out_external_limit = pt->inbound_bw_limit;
+ n->bw_out = GNUNET_BANDWIDTH_value_min (n->bw_out_external_limit,
+ n->bw_out_internal_limit);
+ GNUNET_BANDWIDTH_tracker_update_quota (&n->available_send_window,
+ n->bw_out);
+ GNUNET_TRANSPORT_set_quota (transport, &n->peer, n->bw_in, n->bw_out);
+ }
n->last_activity = GNUNET_TIME_absolute_get ();
if (n->keep_alive_task != GNUNET_SCHEDULER_NO_TASK)
GNUNET_SCHEDULER_cancel (n->keep_alive_task);
- n->keep_alive_task
- = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide
(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 2),
- &send_keep_alive,
- n);
+ n->keep_alive_task
+ =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide
+ (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
+ 2), &send_keep_alive, n);
GNUNET_STATISTICS_update (stats,
gettext_noop ("# bytes of payload decrypted"),
- size - sizeof (struct EncryptedMessage),
- GNUNET_NO);
+ size - sizeof (struct EncryptedMessage),
GNUNET_NO);
handle_peer_status_change (n);
update_neighbour_performance (n, ats, ats_count);
- if (GNUNET_OK != GNUNET_SERVER_mst_receive (mst,
- n,
- &buf[sizeof (struct
EncryptedMessage)],
- size - sizeof (struct
EncryptedMessage),
- GNUNET_YES, GNUNET_NO))
+ if (GNUNET_OK != GNUNET_SERVER_mst_receive (mst,
+ n,
+ &buf[sizeof
+ (struct EncryptedMessage)],
+ size -
+ sizeof (struct EncryptedMessage),
+ GNUNET_YES, GNUNET_NO))
GNUNET_break_op (0);
}
@@ -4314,8 +4179,8 @@
handle_transport_receive (void *cls,
const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_TRANSPORT_ATS_Information *ats,
- uint32_t ats_count)
+ const struct GNUNET_TRANSPORT_ATS_Information *ats,
+ uint32_t ats_count)
{
struct Neighbour *n;
struct GNUNET_TIME_Absolute now;
@@ -4327,134 +4192,130 @@
#if DEBUG_CORE > 1
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received message of type %u from `%4s', demultiplexing.\n",
- (unsigned int) ntohs (message->type),
- GNUNET_i2s (peer));
+ (unsigned int) ntohs (message->type), GNUNET_i2s (peer));
#endif
if (0 == memcmp (peer, &my_identity, sizeof (struct GNUNET_PeerIdentity)))
- {
- GNUNET_break (0);
- return;
- }
+ {
+ GNUNET_break (0);
+ return;
+ }
n = find_neighbour (peer);
- if ( (n == NULL) || (GNUNET_NO == n->is_connected) )
- {
- /* received message from peer that is not connected!? */
- GNUNET_break (0);
- return;
- }
+ if ((n == NULL) || (GNUNET_NO == n->is_connected))
+ {
+ /* received message from peer that is not connected!? */
+ GNUNET_break (0);
+ return;
+ }
changed = GNUNET_NO;
up = (n->status == PEER_STATE_KEY_CONFIRMED);
type = ntohs (message->type);
size = ntohs (message->size);
switch (type)
+ {
+ case GNUNET_MESSAGE_TYPE_CORE_SET_KEY:
+ if (size != sizeof (struct SetKeyMessage))
{
- case GNUNET_MESSAGE_TYPE_CORE_SET_KEY:
- if (size != sizeof (struct SetKeyMessage))
- {
- GNUNET_break_op (0);
- return;
- }
+ GNUNET_break_op (0);
+ return;
+ }
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# session keys received"),
+ 1, GNUNET_NO);
+ handle_set_key (n, (const struct SetKeyMessage *) message, ats, ats_count);
+ break;
+ case GNUNET_MESSAGE_TYPE_CORE_ENCRYPTED_MESSAGE:
+ if (size < sizeof (struct EncryptedMessage) +
+ sizeof (struct GNUNET_MessageHeader))
+ {
+ GNUNET_break_op (0);
+ return;
+ }
+ if ((n->status != PEER_STATE_KEY_RECEIVED) &&
+ (n->status != PEER_STATE_KEY_CONFIRMED))
+ {
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# session keys received"),
- 1,
- GNUNET_NO);
- handle_set_key (n,
- (const struct SetKeyMessage *) message,
- ats, ats_count);
- break;
- case GNUNET_MESSAGE_TYPE_CORE_ENCRYPTED_MESSAGE:
- if (size < sizeof (struct EncryptedMessage) +
- sizeof (struct GNUNET_MessageHeader))
- {
- GNUNET_break_op (0);
- return;
- }
- if ((n->status != PEER_STATE_KEY_RECEIVED) &&
- (n->status != PEER_STATE_KEY_CONFIRMED))
- {
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# failed to decrypt message
(no session key)"),
- 1,
- GNUNET_NO);
- send_key (n);
- return;
- }
- handle_encrypted_message (n,
- (const struct EncryptedMessage *) message,
- ats, ats_count);
- break;
- case GNUNET_MESSAGE_TYPE_CORE_PING:
- if (size != sizeof (struct PingMessage))
- {
- GNUNET_break_op (0);
- return;
- }
- GNUNET_STATISTICS_update (stats, gettext_noop ("# PING messages
received"), 1, GNUNET_NO);
- if ((n->status != PEER_STATE_KEY_RECEIVED) &&
- (n->status != PEER_STATE_KEY_CONFIRMED))
- {
+ gettext_noop
+ ("# failed to decrypt message (no session
key)"),
+ 1, GNUNET_NO);
+ send_key (n);
+ return;
+ }
+ handle_encrypted_message (n,
+ (const struct EncryptedMessage *) message,
+ ats, ats_count);
+ break;
+ case GNUNET_MESSAGE_TYPE_CORE_PING:
+ if (size != sizeof (struct PingMessage))
+ {
+ GNUNET_break_op (0);
+ return;
+ }
+ GNUNET_STATISTICS_update (stats, gettext_noop ("# PING messages received"),
+ 1, GNUNET_NO);
+ if ((n->status != PEER_STATE_KEY_RECEIVED) &&
+ (n->status != PEER_STATE_KEY_CONFIRMED))
+ {
#if DEBUG_CORE > 1
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Core service receives `%s' request from `%4s' but have
not processed key; marking as pending.\n",
- "PING", GNUNET_i2s (&n->peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Core service receives `%s' request from `%4s' but have not
processed key; marking as pending.\n",
+ "PING", GNUNET_i2s (&n->peer));
#endif
- GNUNET_free_non_null (n->pending_ping);
- n->pending_ping = GNUNET_malloc (sizeof (struct PingMessage));
- memcpy (n->pending_ping, message, sizeof (struct PingMessage));
- return;
- }
- handle_ping (n, (const struct PingMessage *) message,
- ats, ats_count);
- break;
- case GNUNET_MESSAGE_TYPE_CORE_PONG:
- if (size != sizeof (struct PongMessage))
- {
- GNUNET_break_op (0);
- return;
- }
- GNUNET_STATISTICS_update (stats, gettext_noop ("# PONG messages
received"), 1, GNUNET_NO);
- if ( (n->status != PEER_STATE_KEY_RECEIVED) &&
- (n->status != PEER_STATE_KEY_CONFIRMED) )
- {
+ GNUNET_free_non_null (n->pending_ping);
+ n->pending_ping = GNUNET_malloc (sizeof (struct PingMessage));
+ memcpy (n->pending_ping, message, sizeof (struct PingMessage));
+ return;
+ }
+ handle_ping (n, (const struct PingMessage *) message, ats, ats_count);
+ break;
+ case GNUNET_MESSAGE_TYPE_CORE_PONG:
+ if (size != sizeof (struct PongMessage))
+ {
+ GNUNET_break_op (0);
+ return;
+ }
+ GNUNET_STATISTICS_update (stats, gettext_noop ("# PONG messages received"),
+ 1, GNUNET_NO);
+ if ((n->status != PEER_STATE_KEY_RECEIVED) &&
+ (n->status != PEER_STATE_KEY_CONFIRMED))
+ {
#if DEBUG_CORE > 1
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Core service receives `%s' request from `%4s' but have
not processed key; marking as pending.\n",
- "PONG", GNUNET_i2s (&n->peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Core service receives `%s' request from `%4s' but have not
processed key; marking as pending.\n",
+ "PONG", GNUNET_i2s (&n->peer));
#endif
- GNUNET_free_non_null (n->pending_pong);
- n->pending_pong = GNUNET_malloc (sizeof (struct PongMessage));
- memcpy (n->pending_pong, message, sizeof (struct PongMessage));
- return;
- }
- handle_pong (n, (const struct PongMessage *) message,
- ats, ats_count);
- break;
- default:
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Unsupported message of type %u received.\n"),
- (unsigned int) type);
+ GNUNET_free_non_null (n->pending_pong);
+ n->pending_pong = GNUNET_malloc (sizeof (struct PongMessage));
+ memcpy (n->pending_pong, message, sizeof (struct PongMessage));
return;
}
+ handle_pong (n, (const struct PongMessage *) message, ats, ats_count);
+ break;
+ default:
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Unsupported message of type %u received.\n"),
+ (unsigned int) type);
+ return;
+ }
if (n->status == PEER_STATE_KEY_CONFIRMED)
+ {
+ now = GNUNET_TIME_absolute_get ();
+ n->last_activity = now;
+ changed = GNUNET_YES;
+ if (!up)
{
- now = GNUNET_TIME_absolute_get ();
- n->last_activity = now;
- changed = GNUNET_YES;
- if (!up)
- {
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# established sessions"),
- 1,
- GNUNET_NO);
- n->time_established = now;
- }
- if (n->keep_alive_task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel (n->keep_alive_task);
- n->keep_alive_task
- = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide
(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 2),
- &send_keep_alive,
- n);
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# established sessions"),
+ 1, GNUNET_NO);
+ n->time_established = now;
}
+ if (n->keep_alive_task != GNUNET_SCHEDULER_NO_TASK)
+ GNUNET_SCHEDULER_cancel (n->keep_alive_task);
+ n->keep_alive_task
+ =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide
+
(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
+ 2), &send_keep_alive, n);
+ }
if (changed)
handle_peer_status_change (n);
}
@@ -4469,7 +4330,7 @@
*/
static void
neighbour_quota_update (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct Neighbour *n = cls;
struct GNUNET_BANDWIDTH_Value32NBO q_in;
@@ -4484,27 +4345,28 @@
#if DEBUG_CORE > 1
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Neighbour quota update calculation running for peer `%4s'\n",
- GNUNET_i2s (&n->peer));
+ "Neighbour quota update calculation running for peer `%4s'\n",
+ GNUNET_i2s (&n->peer));
#endif
n->quota_update_task = GNUNET_SCHEDULER_NO_TASK;
/* calculate relative preference among all neighbours;
- divides by a bit more to avoid division by zero AND to
- account for possibility of new neighbours joining any time
- AND to convert to double... */
+ * divides by a bit more to avoid division by zero AND to
+ * account for possibility of new neighbours joining any time
+ * AND to convert to double... */
neighbour_count = GNUNET_CONTAINER_multihashmap_size (neighbours);
if (neighbour_count == 0)
return;
if (preference_sum == 0)
- {
- pref_rel = 1.0 / (double) neighbour_count;
- }
+ {
+ pref_rel = 1.0 / (double) neighbour_count;
+ }
else
- {
- pref_rel = (double) n->current_preference / preference_sum;
- }
- need_per_peer = GNUNET_BANDWIDTH_value_get_available_until
(MIN_BANDWIDTH_PER_PEER,
-
GNUNET_TIME_UNIT_SECONDS);
+ {
+ pref_rel = (double) n->current_preference / preference_sum;
+ }
+ need_per_peer =
+ GNUNET_BANDWIDTH_value_get_available_until (MIN_BANDWIDTH_PER_PEER,
+ GNUNET_TIME_UNIT_SECONDS);
need_per_second = need_per_peer * neighbour_count;
/* calculate inbound bandwidth per peer */
@@ -4528,43 +4390,45 @@
q_out = GNUNET_BANDWIDTH_value_init (need_per_peer + (uint32_t) share);
n->bw_out_internal_limit = q_out;
- q_out_min = GNUNET_BANDWIDTH_value_min (n->bw_out_external_limit,
n->bw_out_internal_limit);
+ q_out_min =
+ GNUNET_BANDWIDTH_value_min (n->bw_out_external_limit,
+ n->bw_out_internal_limit);
GNUNET_BANDWIDTH_tracker_update_quota (&n->available_send_window, n->bw_out);
/* check if we want to disconnect for good due to inactivity */
- if ( (GNUNET_TIME_absolute_get_duration (get_neighbour_timeout
(n)).rel_value > 0) &&
- (GNUNET_TIME_absolute_get_duration (n->time_established).rel_value >
GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value) )
- {
+ if ((GNUNET_TIME_absolute_get_duration (get_neighbour_timeout (n)).rel_value
>
+ 0) &&
+ (GNUNET_TIME_absolute_get_duration (n->time_established).rel_value >
+ GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value))
+ {
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Forcing disconnect of `%4s' due to inactivity\n",
- GNUNET_i2s (&n->peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Forcing disconnect of `%4s' due to inactivity\n",
+ GNUNET_i2s (&n->peer));
#endif
- q_in = GNUNET_BANDWIDTH_value_init (0); /* force disconnect */
- }
+ q_in = GNUNET_BANDWIDTH_value_init (0); /* force disconnect */
+ }
#if DEBUG_CORE_QUOTA
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Current quota for `%4s' is %u/%llu b/s in (old: %u b/s) / %u out
(%u internal)\n",
- GNUNET_i2s (&n->peer),
- (unsigned int) ntohl (q_in.value__),
- bandwidth_target_out_bps,
- (unsigned int) ntohl (n->bw_in.value__),
- (unsigned int) ntohl (n->bw_out.value__),
- (unsigned int) ntohl (n->bw_out_internal_limit.value__));
- #endif
- if ((n->bw_in.value__ != q_in.value__) || (n->bw_out.value__ !=
q_out_min.value__))
- {
- if (n->bw_in.value__ != q_in.value__)
- n->bw_in = q_in;
- if (n->bw_out.value__ != q_out_min.value__)
- n->bw_out = q_out_min;
- if (GNUNET_YES == n->is_connected)
- GNUNET_TRANSPORT_set_quota (transport,
- &n->peer,
- n->bw_in,
- n->bw_out);
- handle_peer_status_change (n);
- }
+ "Current quota for `%4s' is %u/%llu b/s in (old: %u b/s) / %u
out (%u internal)\n",
+ GNUNET_i2s (&n->peer),
+ (unsigned int) ntohl (q_in.value__),
+ bandwidth_target_out_bps,
+ (unsigned int) ntohl (n->bw_in.value__),
+ (unsigned int) ntohl (n->bw_out.value__),
+ (unsigned int) ntohl (n->bw_out_internal_limit.value__));
+#endif
+ if ((n->bw_in.value__ != q_in.value__) ||
+ (n->bw_out.value__ != q_out_min.value__))
+ {
+ if (n->bw_in.value__ != q_in.value__)
+ n->bw_in = q_in;
+ if (n->bw_out.value__ != q_out_min.value__)
+ n->bw_out = q_out_min;
+ if (GNUNET_YES == n->is_connected)
+ GNUNET_TRANSPORT_set_quota (transport, &n->peer, n->bw_in, n->bw_out);
+ handle_peer_status_change (n);
+ }
schedule_quota_update (n);
}
@@ -4581,52 +4445,45 @@
static void
handle_transport_notify_connect (void *cls,
const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_TRANSPORT_ATS_Information
*ats,
- uint32_t ats_count)
+ const struct GNUNET_TRANSPORT_ATS_Information
+ *ats, uint32_t ats_count)
{
struct Neighbour *n;
if (0 == memcmp (peer, &my_identity, sizeof (struct GNUNET_PeerIdentity)))
+ {
+ GNUNET_break (0);
+ return;
+ }
+ n = find_neighbour (peer);
+ if (n != NULL)
+ {
+ if (GNUNET_YES == n->is_connected)
{
+ /* duplicate connect notification!? */
GNUNET_break (0);
return;
}
- n = find_neighbour (peer);
- if (n != NULL)
- {
- if (GNUNET_YES == n->is_connected)
- {
- /* duplicate connect notification!? */
- GNUNET_break (0);
- return;
- }
- }
+ }
else
- {
- n = create_neighbour (peer);
- }
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# peers connected (transport)"),
- 1,
- GNUNET_NO);
- n->is_connected = GNUNET_YES;
+ {
+ n = create_neighbour (peer);
+ }
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# peers connected (transport)"),
+ 1, GNUNET_NO);
+ n->is_connected = GNUNET_YES;
update_neighbour_performance (n, ats, ats_count);
GNUNET_BANDWIDTH_tracker_init (&n->available_send_window,
- n->bw_out,
- MAX_WINDOW_TIME_S);
+ n->bw_out, MAX_WINDOW_TIME_S);
GNUNET_BANDWIDTH_tracker_init (&n->available_recv_window,
- n->bw_in,
- MAX_WINDOW_TIME_S);
+ n->bw_in, MAX_WINDOW_TIME_S);
#if DEBUG_CORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received connection from `%4s'.\n",
- GNUNET_i2s (&n->peer));
+ "Received connection from `%4s'.\n", GNUNET_i2s (&n->peer));
#endif
- GNUNET_TRANSPORT_set_quota (transport,
- &n->peer,
- n->bw_in,
- n->bw_out);
- send_key (n);
+ GNUNET_TRANSPORT_set_quota (transport, &n->peer, n->bw_in, n->bw_out);
+ send_key (n);
}
@@ -4648,67 +4505,65 @@
#if DEBUG_CORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peer `%4s' disconnected from us; received notification from
transport.\n",
- GNUNET_i2s (peer));
+ "Peer `%4s' disconnected from us; received notification from
transport.\n",
+ GNUNET_i2s (peer));
#endif
n = find_neighbour (peer);
if (n == NULL)
- {
- GNUNET_break (0);
- return;
- }
+ {
+ GNUNET_break (0);
+ return;
+ }
GNUNET_break (n->is_connected == GNUNET_YES);
if (n->status == PEER_STATE_KEY_CONFIRMED)
- {
- cnm.header.size = htons (sizeof (struct DisconnectNotifyMessage));
- cnm.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT);
- cnm.reserved = htonl (0);
- cnm.peer = *peer;
- send_to_all_clients (&cnm.header, GNUNET_NO,
GNUNET_CORE_OPTION_SEND_DISCONNECT);
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# established sessions"),
- -1,
- GNUNET_NO);
- }
+ {
+ cnm.header.size = htons (sizeof (struct DisconnectNotifyMessage));
+ cnm.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT);
+ cnm.reserved = htonl (0);
+ cnm.peer = *peer;
+ send_to_all_clients (&cnm.header, GNUNET_NO,
+ GNUNET_CORE_OPTION_SEND_DISCONNECT);
+ GNUNET_STATISTICS_update (stats, gettext_noop ("# established sessions"),
+ -1, GNUNET_NO);
+ }
/* On transport disconnect transport doesn't cancel requests, so must do so
here. */
if (n->th != NULL)
- {
- GNUNET_TRANSPORT_notify_transmit_ready_cancel (n->th);
- n->th = NULL;
- }
+ {
+ GNUNET_TRANSPORT_notify_transmit_ready_cancel (n->th);
+ n->th = NULL;
+ }
if (GNUNET_SCHEDULER_NO_TASK != n->keep_alive_task)
- {
- GNUNET_SCHEDULER_cancel (n->keep_alive_task);
- n->keep_alive_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (n->keep_alive_task);
+ n->keep_alive_task = GNUNET_SCHEDULER_NO_TASK;
+ }
n->is_connected = GNUNET_NO;
n->status = PEER_STATE_DOWN;
while (NULL != (car = n->active_client_request_head))
- {
- GNUNET_CONTAINER_DLL_remove (n->active_client_request_head,
- n->active_client_request_tail,
- car);
- GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove
(car->client->requests,
- &n->peer.hashPubKey,
- car));
- GNUNET_free (car);
- }
+ {
+ GNUNET_CONTAINER_DLL_remove (n->active_client_request_head,
+ n->active_client_request_tail, car);
+ GNUNET_assert (GNUNET_YES ==
+ GNUNET_CONTAINER_multihashmap_remove (car->client->requests,
+ &n->peer.hashPubKey,
+ car));
+ GNUNET_free (car);
+ }
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# peers connected (transport)"),
- -1,
- GNUNET_NO);
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# peers connected (transport)"),
+ -1, GNUNET_NO);
if (n->dead_clean_task != GNUNET_SCHEDULER_NO_TASK)
GNUNET_SCHEDULER_cancel (n->dead_clean_task);
- left = GNUNET_TIME_relative_subtract
(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
-
GNUNET_CONSTANTS_DISCONNECT_SESSION_TIMEOUT);
- n->last_activity = GNUNET_TIME_absolute_subtract (GNUNET_TIME_absolute_get
(),
- left);
- n->dead_clean_task = GNUNET_SCHEDULER_add_delayed
(GNUNET_CONSTANTS_DISCONNECT_SESSION_TIMEOUT,
- &consider_free_task,
- n);
+ left =
+ GNUNET_TIME_relative_subtract (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
+
GNUNET_CONSTANTS_DISCONNECT_SESSION_TIMEOUT);
+ n->last_activity =
+ GNUNET_TIME_absolute_subtract (GNUNET_TIME_absolute_get (), left);
+ n->dead_clean_task =
+ GNUNET_SCHEDULER_add_delayed
(GNUNET_CONSTANTS_DISCONNECT_SESSION_TIMEOUT,
+ &consider_free_task, n);
}
@@ -4716,9 +4571,7 @@
* Wrapper around 'free_neighbour'; helper for 'cleaning_task'.
*/
static int
-free_neighbour_helper (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+free_neighbour_helper (void *cls, const GNUNET_HashCode * key, void *value)
{
struct Neighbour *n = value;
@@ -4737,18 +4590,17 @@
struct Client *c;
#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
GNUNET_assert (transport != NULL);
GNUNET_TRANSPORT_disconnect (transport);
transport = NULL;
GNUNET_CONTAINER_multihashmap_iterate (neighbours,
- &free_neighbour_helper,
- NULL);
+ &free_neighbour_helper, NULL);
GNUNET_CONTAINER_multihashmap_destroy (neighbours);
neighbours = NULL;
- GNUNET_STATISTICS_set (stats, gettext_noop ("# neighbour entries
allocated"), 0, GNUNET_NO);
+ GNUNET_STATISTICS_set (stats, gettext_noop ("# neighbour entries allocated"),
+ 0, GNUNET_NO);
GNUNET_SERVER_notification_context_destroy (notifier);
notifier = NULL;
while (NULL != (c = clients))
@@ -4784,7 +4636,8 @@
sizeof (struct GNUNET_MessageHeader)},
{&handle_client_have_peer, NULL,
GNUNET_MESSAGE_TYPE_CORE_PEER_CONNECTED,
- sizeof (struct GNUNET_MessageHeader) + sizeof(struct
GNUNET_PeerIdentity)},
+ sizeof (struct GNUNET_MessageHeader) +
+ sizeof (struct GNUNET_PeerIdentity)},
{&handle_client_request_info, NULL,
GNUNET_MESSAGE_TYPE_CORE_REQUEST_INFO,
sizeof (struct RequestInfoMessage)},
@@ -4800,49 +4653,48 @@
};
char *keyfile;
- cfg = c;
+ cfg = c;
/* parse configuration */
- if (
- (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (c,
- "CORE",
- "TOTAL_QUOTA_IN",
- &bandwidth_target_in_bps)) ||
- (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (c,
- "CORE",
- "TOTAL_QUOTA_OUT",
- &bandwidth_target_out_bps)) ||
- (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (c,
- "GNUNETD",
- "HOSTKEY", &keyfile)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _
- ("Core service is lacking key configuration settings.
Exiting.\n"));
- GNUNET_SCHEDULER_shutdown ();
- return;
- }
+ if ((GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_number (c,
+ "CORE",
+ "TOTAL_QUOTA_IN",
+ &bandwidth_target_in_bps)) ||
+ (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_number (c,
+ "CORE",
+ "TOTAL_QUOTA_OUT",
+ &bandwidth_target_out_bps)) ||
+ (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_filename (c,
+ "GNUNETD",
+ "HOSTKEY", &keyfile)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _
+ ("Core service is lacking key configuration settings.
Exiting.\n"));
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
peerinfo = GNUNET_PEERINFO_connect (cfg);
if (NULL == peerinfo)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Could not access PEERINFO service. Exiting.\n"));
- GNUNET_SCHEDULER_shutdown ();
- GNUNET_free (keyfile);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Could not access PEERINFO service. Exiting.\n"));
+ GNUNET_SCHEDULER_shutdown ();
+ GNUNET_free (keyfile);
+ return;
+ }
my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
GNUNET_free (keyfile);
if (my_private_key == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Core service could not access hostkey. Exiting.\n"));
- GNUNET_PEERINFO_disconnect (peerinfo);
- GNUNET_SCHEDULER_shutdown ();
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Core service could not access hostkey. Exiting.\n"));
+ GNUNET_PEERINFO_disconnect (peerinfo);
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
neighbours = GNUNET_CONTAINER_multihashmap_create (128);
GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key);
GNUNET_CRYPTO_hash (&my_public_key,
@@ -4853,12 +4705,12 @@
self.status = PEER_STATE_KEY_CONFIRMED;
self.is_connected = GNUNET_YES;
/* setup notification */
- notifier = GNUNET_SERVER_notification_context_create (server,
- MAX_NOTIFY_QUEUE);
+ notifier = GNUNET_SERVER_notification_context_create (server,
+ MAX_NOTIFY_QUEUE);
GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL);
/* setup transport connection */
transport = GNUNET_TRANSPORT_connect (cfg,
- &my_identity,
+ &my_identity,
NULL,
&handle_transport_receive,
&handle_transport_notify_connect,
@@ -4866,15 +4718,15 @@
GNUNET_assert (NULL != transport);
stats = GNUNET_STATISTICS_create ("core", cfg);
- GNUNET_STATISTICS_set (stats,
- gettext_noop ("# discarded CORE_SEND requests"),
- 0, GNUNET_NO);
- GNUNET_STATISTICS_set (stats,
- gettext_noop ("# discarded lower priority CORE_SEND
requests"),
- 0, GNUNET_NO);
+ GNUNET_STATISTICS_set (stats,
+ gettext_noop ("# discarded CORE_SEND requests"),
+ 0, GNUNET_NO);
+ GNUNET_STATISTICS_set (stats,
+ gettext_noop
+ ("# discarded lower priority CORE_SEND requests"), 0,
+ GNUNET_NO);
- mst = GNUNET_SERVER_mst_create (&deliver_message,
- NULL);
+ mst = GNUNET_SERVER_mst_create (&deliver_message, NULL);
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
&cleaning_task, NULL);
/* process client requests */
@@ -4899,8 +4751,7 @@
GNUNET_SERVICE_run (argc,
argv,
"core",
- GNUNET_SERVICE_OPTION_NONE,
- &run, NULL)) ? 0 : 1;
+ GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
}
/* end of gnunet-service-core.c */
Modified: gnunet/src/core/test_core_api.c
===================================================================
--- gnunet/src/core/test_core_api.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/core/test_core_api.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -44,7 +44,7 @@
{
struct GNUNET_CONFIGURATION_Handle *cfg;
struct GNUNET_CORE_Handle *ch;
- struct GNUNET_PeerIdentity id;
+ struct GNUNET_PeerIdentity id;
struct GNUNET_TRANSPORT_Handle *th;
struct GNUNET_MessageHeader *hello;
int connect_status;
@@ -71,14 +71,12 @@
static void
-process_hello (void *cls,
- const struct GNUNET_MessageHeader *message)
+process_hello (void *cls, const struct GNUNET_MessageHeader *message)
{
struct PeerContext *p = cls;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received (my) `%s' from transport service\n",
- "HELLO");
+ "Received (my) `%s' from transport service\n", "HELLO");
GNUNET_assert (message != NULL);
if ((p == &p1) && (p2.th != NULL))
GNUNET_TRANSPORT_offer_hello (p2.th, message, NULL, NULL);
@@ -105,31 +103,31 @@
terminate_task_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
#if VERBOSE
- fprintf(stderr, "ENDING ANGRILY %u\n", ok);
+ fprintf (stderr, "ENDING ANGRILY %u\n", ok);
#endif
GNUNET_break (0);
if (NULL != p1.ch)
- {
- GNUNET_CORE_disconnect (p1.ch);
- p1.ch = NULL;
- }
+ {
+ GNUNET_CORE_disconnect (p1.ch);
+ p1.ch = NULL;
+ }
if (NULL != p2.ch)
- {
- GNUNET_CORE_disconnect (p2.ch);
- p2.ch = NULL;
- }
+ {
+ GNUNET_CORE_disconnect (p2.ch);
+ p2.ch = NULL;
+ }
if (p1.th != NULL)
- {
- GNUNET_TRANSPORT_get_hello_cancel (p1.th, &process_hello, &p1);
- GNUNET_TRANSPORT_disconnect (p1.th);
- p1.th = NULL;
- }
+ {
+ GNUNET_TRANSPORT_get_hello_cancel (p1.th, &process_hello, &p1);
+ GNUNET_TRANSPORT_disconnect (p1.th);
+ p1.th = NULL;
+ }
if (p2.th != NULL)
- {
- GNUNET_TRANSPORT_get_hello_cancel (p2.th, &process_hello, &p2);
- GNUNET_TRANSPORT_disconnect (p2.th);
- p2.th = NULL;
- }
+ {
+ GNUNET_TRANSPORT_get_hello_cancel (p2.th, &process_hello, &p2);
+ GNUNET_TRANSPORT_disconnect (p2.th);
+ p2.th = NULL;
+ }
ok = 42;
}
@@ -154,54 +152,51 @@
static void
connect_notify (void *cls,
const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
struct PeerContext *pc = cls;
- if (0 == memcmp (&pc->id,
- peer,
- sizeof (struct GNUNET_PeerIdentity)))
+ if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity)))
return;
GNUNET_assert (pc->connect_status == 0);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Encrypted connection established to peer `%4s'\n",
- GNUNET_i2s (peer));
+ "Encrypted connection established to peer `%4s'\n",
+ GNUNET_i2s (peer));
if (GNUNET_SCHEDULER_NO_TASK != con_task)
- {
- GNUNET_SCHEDULER_cancel (con_task);
- con_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (con_task);
+ con_task = GNUNET_SCHEDULER_NO_TASK;
+ }
pc->connect_status = 1;
if (pc == &p1)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Asking core (1) for transmission to peer `%4s'\n",
+ GNUNET_i2s (&p2.id));
+ if (NULL == GNUNET_CORE_notify_transmit_ready (p1.ch,
+ GNUNET_YES,
+ 0,
+
GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS,
+ 45), &p2.id,
+ sizeof (struct
+
GNUNET_MessageHeader),
+ &transmit_ready, &p1))
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Asking core (1) for transmission to peer `%4s'\n",
- GNUNET_i2s (&p2.id));
- if (NULL == GNUNET_CORE_notify_transmit_ready (p1.ch,
- GNUNET_YES,
- 0,
-
GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 45),
- &p2.id,
- sizeof (struct
GNUNET_MessageHeader),
- &transmit_ready, &p1))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "RECEIVED NULL when asking core (1) for transmission to
peer `%4s'\n",
- GNUNET_i2s (&p2.id));
- }
+ "RECEIVED NULL when asking core (1) for transmission to peer
`%4s'\n",
+ GNUNET_i2s (&p2.id));
}
+ }
}
static void
-disconnect_notify (void *cls,
- const struct GNUNET_PeerIdentity *peer)
+disconnect_notify (void *cls, const struct GNUNET_PeerIdentity *peer)
{
struct PeerContext *pc = cls;
- if (0 == memcmp (&pc->id,
- peer,
- sizeof (struct GNUNET_PeerIdentity)))
+ if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity)))
return;
pc->connect_status = 0;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -213,7 +208,7 @@
inbound_notify (void *cls,
const struct GNUNET_PeerIdentity *other,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Core provides inbound data from `%4s'.\n", GNUNET_i2s (other));
@@ -225,7 +220,7 @@
outbound_notify (void *cls,
const struct GNUNET_PeerIdentity *other,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Core notifies about outbound data for `%4s'.\n",
@@ -239,7 +234,7 @@
process_mtype (void *cls,
const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Receiving message from `%4s'.\n", GNUNET_i2s (peer));
@@ -258,23 +253,19 @@
static void
-connect_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+connect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- {
- con_task = GNUNET_SCHEDULER_NO_TASK;
- return;
- }
+ {
+ con_task = GNUNET_SCHEDULER_NO_TASK;
+ return;
+ }
con_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
- &connect_task,
- NULL);
+ &connect_task, NULL);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Asking core (1) to connect to peer `%4s'\n",
- GNUNET_i2s (&p2.id));
- GNUNET_CORE_peer_request_connect (p1.ch,
- &p2.id,
- NULL, NULL);
+ "Asking core (1) to connect to peer `%4s'\n",
+ GNUNET_i2s (&p2.id));
+ GNUNET_CORE_peer_request_connect (p1.ch, &p2.id, NULL, NULL);
}
static void
@@ -292,28 +283,27 @@
p->id = *my_identity;
p->ch = server;
if (cls == &p1)
- {
- GNUNET_assert (ok == 2);
- OKPP;
- /* connect p2 */
- p2.ch = GNUNET_CORE_connect (p2.cfg, 1,
- &p2,
- &init_notify,
- &connect_notify,
- &disconnect_notify,
- NULL,
- &inbound_notify,
- GNUNET_YES,
- &outbound_notify, GNUNET_YES, handlers);
- }
+ {
+ GNUNET_assert (ok == 2);
+ OKPP;
+ /* connect p2 */
+ p2.ch = GNUNET_CORE_connect (p2.cfg, 1,
+ &p2,
+ &init_notify,
+ &connect_notify,
+ &disconnect_notify,
+ NULL,
+ &inbound_notify,
+ GNUNET_YES,
+ &outbound_notify, GNUNET_YES, handlers);
+ }
else
- {
- GNUNET_assert (ok == 3);
- OKPP;
- GNUNET_assert (cls == &p2);
- con_task = GNUNET_SCHEDULER_add_now (&connect_task,
- NULL);
- }
+ {
+ GNUNET_assert (ok == 3);
+ OKPP;
+ GNUNET_assert (cls == &p2);
+ con_task = GNUNET_SCHEDULER_add_now (&connect_task, NULL);
+ }
}
@@ -323,11 +313,11 @@
p->cfg = GNUNET_CONFIGURATION_create ();
#if START_ARM
p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
- "gnunet-service-arm",
+ "gnunet-service-arm",
#if VERBOSE
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", cfgname, NULL);
+ "-c", cfgname, NULL);
#endif
GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, NULL, NULL);
@@ -339,24 +329,20 @@
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
GNUNET_assert (ok == 1);
OKPP;
setup_peer (&p1, "test_core_api_peer1.conf");
setup_peer (&p2, "test_core_api_peer2.conf");
- err_task =
- GNUNET_SCHEDULER_add_delayed
(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120),
- &terminate_task_error, NULL);
- p1.ch = GNUNET_CORE_connect (p1.cfg, 1,
- &p1,
- &init_notify,
- &connect_notify,
- &disconnect_notify,
- NULL,
- &inbound_notify,
- GNUNET_YES, &outbound_notify, GNUNET_YES,
handlers);
+ err_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 120),
+ &terminate_task_error, NULL);
+ p1.ch =
+ GNUNET_CORE_connect (p1.cfg, 1, &p1, &init_notify, &connect_notify,
+ &disconnect_notify, NULL, &inbound_notify,
+ GNUNET_YES, &outbound_notify, GNUNET_YES, handlers);
}
static void
@@ -365,10 +351,11 @@
#if START_ARM
if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
- if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK)
+ if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "ARM process %u stopped\n", GNUNET_OS_process_get_pid
(p->arm_proc));
+ "ARM process %u stopped\n",
+ GNUNET_OS_process_get_pid (p->arm_proc));
GNUNET_OS_process_close (p->arm_proc);
p->arm_proc = NULL;
#endif
@@ -410,7 +397,7 @@
#endif
NULL);
ret = check ();
- GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-1");
+ GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-1");
GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-2");
return ret;
Modified: gnunet/src/core/test_core_api_preferences.c
===================================================================
--- gnunet/src/core/test_core_api_preferences.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/core/test_core_api_preferences.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -41,7 +41,7 @@
{
struct GNUNET_CONFIGURATION_Handle *cfg;
struct GNUNET_CORE_Handle *ch;
- struct GNUNET_PeerIdentity id;
+ struct GNUNET_PeerIdentity id;
struct GNUNET_TRANSPORT_Handle *th;
struct GNUNET_MessageHeader *hello;
int connect_status;
@@ -75,13 +75,14 @@
static unsigned int total_reserve = 5;
-static void process_hello (void *cls, const struct GNUNET_MessageHeader
*message);
+static void process_hello (void *cls,
+ const struct GNUNET_MessageHeader *message);
static void
terminate_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
#if VERBOSE
- fprintf(stderr, "Regular shutdown\n");
+ fprintf (stderr, "Regular shutdown\n");
#endif
GNUNET_assert (ok == 6);
GNUNET_assert (NULL == irc);
@@ -100,24 +101,24 @@
{
err_task = GNUNET_SCHEDULER_NO_TASK;
#if VERBOSE
- fprintf(stderr, "ENDING ANGRILY %u\n", ok);
+ fprintf (stderr, "ENDING ANGRILY %u\n", ok);
#endif
GNUNET_break (0);
if (NULL != irc)
- {
- GNUNET_CORE_peer_change_preference_cancel (irc);
- irc = NULL;
- }
+ {
+ GNUNET_CORE_peer_change_preference_cancel (irc);
+ irc = NULL;
+ }
if (GNUNET_SCHEDULER_NO_TASK != irc_task)
- {
- GNUNET_SCHEDULER_cancel (irc_task);
- irc_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (irc_task);
+ irc_task = GNUNET_SCHEDULER_NO_TASK;
+ }
if (GNUNET_SCHEDULER_NO_TASK != ask_task)
- {
- GNUNET_SCHEDULER_cancel (ask_task);
- ask_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (ask_task);
+ ask_task = GNUNET_SCHEDULER_NO_TASK;
+ }
GNUNET_TRANSPORT_get_hello_cancel (p1.th, &process_hello, &p1);
GNUNET_TRANSPORT_get_hello_cancel (p2.th, &process_hello, &p2);
GNUNET_CORE_disconnect (p1.ch);
@@ -142,160 +143,151 @@
m = (struct GNUNET_MessageHeader *) buf;
m->type = htons (MTYPE);
m->size = htons (sizeof (struct GNUNET_MessageHeader));
- err_task =
- GNUNET_SCHEDULER_add_delayed
(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120),
- &terminate_task_error, NULL);
+ err_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 120),
+ &terminate_task_error, NULL);
return sizeof (struct GNUNET_MessageHeader);
}
static void
preference_cb (void *cls,
- const struct
- GNUNET_PeerIdentity *peer,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
- int32_t amount,
- struct GNUNET_TIME_Relative res_delay,
- uint64_t preference);
+ const struct
+ GNUNET_PeerIdentity *peer,
+ struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
+ int32_t amount,
+ struct GNUNET_TIME_Relative res_delay, uint64_t preference);
static void
-do_reserve (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_reserve (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct PeerContext *pc = cls;
irc_task = GNUNET_SCHEDULER_NO_TASK;
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Aborted during attempt to request reservation\n");
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Aborted during attempt to request reservation\n");
+ return;
+ }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Requesting reservatin of 32k from core in 1s!\n");
+ "Requesting reservatin of 32k from core in 1s!\n");
irc = GNUNET_CORE_peer_change_preference (p1.ch,
- &p2.id,
- GNUNET_TIME_UNIT_SECONDS,
- GNUNET_BANDWIDTH_VALUE_MAX,
- 1000000 /* bandwidth for 1s */,
- 0,
- &preference_cb,
- pc);
+ &p2.id,
+ GNUNET_TIME_UNIT_SECONDS,
+ GNUNET_BANDWIDTH_VALUE_MAX,
+ 1000000 /* bandwidth for 1s */ ,
+ 0, &preference_cb, pc);
}
static void
preference_cb (void *cls,
- const struct
- GNUNET_PeerIdentity *peer,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
- int32_t amount,
- struct GNUNET_TIME_Relative res_delay,
- uint64_t preference)
+ const struct
+ GNUNET_PeerIdentity *peer,
+ struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
+ int32_t amount,
+ struct GNUNET_TIME_Relative res_delay, uint64_t preference)
{
struct PeerContext *pc = cls;
irc = NULL;
if (0 == amount)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Delaying reservation request by %llu ms!\n",
- (unsigned long long) res_delay.rel_value);
- irc_task = GNUNET_SCHEDULER_add_delayed (res_delay,
- &do_reserve, pc);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Delaying reservation request by %llu ms!\n",
+ (unsigned long long) res_delay.rel_value);
+ irc_task = GNUNET_SCHEDULER_add_delayed (res_delay, &do_reserve, pc);
+ return;
+ }
total_reserve--;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Reservation done!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Reservation done!\n");
if (total_reserve > 0)
- {
- irc_task = GNUNET_SCHEDULER_add_now (&do_reserve, pc);
- return;
- }
+ {
+ irc_task = GNUNET_SCHEDULER_add_now (&do_reserve, pc);
+ return;
+ }
GNUNET_SCHEDULER_cancel (err_task);
err_task = GNUNET_SCHEDULER_NO_TASK;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Asking core (1) for transmission to peer `%4s'\n",
- GNUNET_i2s (&p2.id));
+ "Asking core (1) for transmission to peer `%4s'\n",
+ GNUNET_i2s (&p2.id));
if (NULL == (th = GNUNET_CORE_notify_transmit_ready (p1.ch,
- GNUNET_YES,
- 0,
-
GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 45),
- &p2.id,
- sizeof (struct
GNUNET_MessageHeader),
- &transmit_ready, &p1)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "RECEIVED NULL when asking core (1) for transmission to peer
`%4s'\n",
- GNUNET_i2s (&p2.id));
- }
+ GNUNET_YES,
+ 0,
+
GNUNET_TIME_relative_multiply
+
(GNUNET_TIME_UNIT_SECONDS,
+ 45), &p2.id,
+ sizeof (struct
+
GNUNET_MessageHeader),
+ &transmit_ready, &p1)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "RECEIVED NULL when asking core (1) for transmission to peer
`%4s'\n",
+ GNUNET_i2s (&p2.id));
+ }
}
static void
connect_notify (void *cls,
const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
struct PeerContext *pc = cls;
- if (0 == memcmp (&pc->id,
- peer,
- sizeof (struct GNUNET_PeerIdentity)))
+ if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity)))
return;
GNUNET_assert (pc->connect_status == 0);
pc->connect_status = 1;
if (pc == &p1)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Encrypted connection established to peer `%4s'\n",
+ GNUNET_i2s (peer));
+ if (GNUNET_SCHEDULER_NO_TASK != ask_task)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Encrypted connection established to peer `%4s'\n",
- GNUNET_i2s (peer));
- if (GNUNET_SCHEDULER_NO_TASK != ask_task)
- {
- GNUNET_SCHEDULER_cancel (ask_task);
- ask_task = GNUNET_SCHEDULER_NO_TASK;
- }
- GNUNET_SCHEDULER_cancel (err_task);
- err_task =
- GNUNET_SCHEDULER_add_delayed
(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120),
- &terminate_task_error, NULL);
- irc_task = GNUNET_SCHEDULER_add_now (&do_reserve, pc);
+ GNUNET_SCHEDULER_cancel (ask_task);
+ ask_task = GNUNET_SCHEDULER_NO_TASK;
}
+ GNUNET_SCHEDULER_cancel (err_task);
+ err_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 120),
+ &terminate_task_error, NULL);
+ irc_task = GNUNET_SCHEDULER_add_now (&do_reserve, pc);
+ }
}
static void
-disconnect_notify (void *cls,
- const struct GNUNET_PeerIdentity *peer)
+disconnect_notify (void *cls, const struct GNUNET_PeerIdentity *peer)
{
struct PeerContext *pc = cls;
- if (0 == memcmp (&pc->id,
- peer,
- sizeof (struct GNUNET_PeerIdentity)))
+ if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity)))
return;
pc->connect_status = 0;
if (GNUNET_SCHEDULER_NO_TASK != irc_task)
+ {
+ GNUNET_SCHEDULER_cancel (irc_task);
+ irc_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ if (0 == memcmp (peer, &p1.id, sizeof (struct GNUNET_PeerIdentity)))
+ {
+ if (irc != NULL)
{
- GNUNET_SCHEDULER_cancel (irc_task);
- irc_task = GNUNET_SCHEDULER_NO_TASK;
+ GNUNET_CORE_peer_change_preference_cancel (irc);
+ irc = NULL;
}
- if (0 == memcmp (peer, &p1.id, sizeof (struct GNUNET_PeerIdentity)))
+ if (th != NULL)
{
- if (irc != NULL)
- {
- GNUNET_CORE_peer_change_preference_cancel (irc);
- irc = NULL;
- }
- if (th != NULL)
- {
- GNUNET_CORE_notify_transmit_ready_cancel (th);
- th = NULL;
- }
+ GNUNET_CORE_notify_transmit_ready_cancel (th);
+ th = NULL;
}
+ }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Encrypted connection to `%4s' cut\n",
- GNUNET_i2s (peer));
+ "Encrypted connection to `%4s' cut\n", GNUNET_i2s (peer));
}
@@ -303,7 +295,7 @@
inbound_notify (void *cls,
const struct GNUNET_PeerIdentity *other,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Core provides inbound data from `%4s'.\n", GNUNET_i2s (other));
@@ -315,7 +307,7 @@
outbound_notify (void *cls,
const struct GNUNET_PeerIdentity *other,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Core notifies about outbound data for `%4s'.\n",
@@ -329,7 +321,7 @@
process_mtype (void *cls,
const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Receiving message from `%4s'.\n", GNUNET_i2s (peer));
@@ -349,19 +341,16 @@
-static void
-ask_connect_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+static void
+ask_connect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
ask_task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
- &ask_connect_task, NULL);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &ask_connect_task, NULL);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Asking core (1) AGAIN to connect to peer `%4s'\n",
- GNUNET_i2s (&p2.id));
- GNUNET_CORE_peer_request_connect (p1.ch,
- &p2.id,
- NULL, NULL);
+ "Asking core (1) AGAIN to connect to peer `%4s'\n",
+ GNUNET_i2s (&p2.id));
+ GNUNET_CORE_peer_request_connect (p1.ch, &p2.id, NULL, NULL);
}
@@ -380,52 +369,48 @@
p->id = *my_identity;
p->ch = server;
if (cls == &p1)
- {
- GNUNET_assert (ok == 2);
- OKPP;
- /* connect p2 */
- GNUNET_CORE_connect (p2.cfg, 1,
- &p2,
- &init_notify,
- &connect_notify,
- &disconnect_notify,
- NULL,
- &inbound_notify,
- GNUNET_YES,
- &outbound_notify, GNUNET_YES, handlers);
- }
+ {
+ GNUNET_assert (ok == 2);
+ OKPP;
+ /* connect p2 */
+ GNUNET_CORE_connect (p2.cfg, 1,
+ &p2,
+ &init_notify,
+ &connect_notify,
+ &disconnect_notify,
+ NULL,
+ &inbound_notify,
+ GNUNET_YES, &outbound_notify, GNUNET_YES, handlers);
+ }
else
- {
- GNUNET_assert (ok == 3);
- OKPP;
- GNUNET_assert (cls == &p2);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Asking core (1) to connect to peer `%4s'\n",
- GNUNET_i2s (&p2.id));
- err_task =
- GNUNET_SCHEDULER_add_delayed
(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60),
- &terminate_task_error, NULL);
- if (GNUNET_SCHEDULER_NO_TASK != ask_task)
- GNUNET_SCHEDULER_cancel (ask_task);
- ask_task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
- &ask_connect_task, NULL);
- GNUNET_CORE_peer_request_connect (p1.ch,
- &p2.id,
- NULL, NULL);
- }
+ {
+ GNUNET_assert (ok == 3);
+ OKPP;
+ GNUNET_assert (cls == &p2);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Asking core (1) to connect to peer `%4s'\n",
+ GNUNET_i2s (&p2.id));
+ err_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 60),
+ &terminate_task_error, NULL);
+ if (GNUNET_SCHEDULER_NO_TASK != ask_task)
+ GNUNET_SCHEDULER_cancel (ask_task);
+ ask_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &ask_connect_task, NULL);
+ GNUNET_CORE_peer_request_connect (p1.ch, &p2.id, NULL, NULL);
+ }
}
static void
-process_hello (void *cls,
- const struct GNUNET_MessageHeader *message)
+process_hello (void *cls, const struct GNUNET_MessageHeader *message)
{
struct PeerContext *p = cls;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received (my) `%s' from transport service\n",
- "HELLO");
+ "Received (my) `%s' from transport service\n", "HELLO");
GNUNET_assert (message != NULL);
p->hello = GNUNET_malloc (ntohs (message->size));
memcpy (p->hello, message, ntohs (message->size));
@@ -448,11 +433,11 @@
p->cfg = GNUNET_CONFIGURATION_create ();
#if START_ARM
p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
- "gnunet-service-arm",
+ "gnunet-service-arm",
#if VERBOSE
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", cfgname, NULL);
+ "-c", cfgname, NULL);
#endif
GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, NULL, NULL);
@@ -464,8 +449,7 @@
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
GNUNET_assert (ok == 1);
OKPP;
@@ -474,9 +458,9 @@
GNUNET_CORE_connect (p1.cfg, 1,
&p1,
&init_notify,
- &connect_notify,
+ &connect_notify,
&disconnect_notify,
- NULL,
+ NULL,
&inbound_notify,
GNUNET_YES, &outbound_notify, GNUNET_YES, handlers);
}
@@ -487,10 +471,11 @@
#if START_ARM
if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
- if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK)
+ if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "ARM process %u stopped\n", GNUNET_OS_process_get_pid
(p->arm_proc));
+ "ARM process %u stopped\n",
+ GNUNET_OS_process_get_pid (p->arm_proc));
GNUNET_OS_process_close (p->arm_proc);
p->arm_proc = NULL;
#endif
@@ -513,7 +498,8 @@
};
ok = 1;
GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
- argv, "test-core-api-preferences", "nohelp", options,
&run, &ok);
+ argv, "test-core-api-preferences", "nohelp", options,
+ &run, &ok);
stop_arm (&p1);
stop_arm (&p2);
return ok;
@@ -532,7 +518,7 @@
#endif
NULL);
ret = check ();
- GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-1");
+ GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-1");
GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-2");
return ret;
Modified: gnunet/src/core/test_core_api_reliability.c
===================================================================
--- gnunet/src/core/test_core_api_reliability.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/core/test_core_api_reliability.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -71,7 +71,7 @@
{
struct GNUNET_CONFIGURATION_Handle *cfg;
struct GNUNET_CORE_Handle *ch;
- struct GNUNET_PeerIdentity id;
+ struct GNUNET_PeerIdentity id;
struct GNUNET_TRANSPORT_Handle *th;
struct GNUNET_MessageHeader *hello;
int connect_status;
@@ -95,7 +95,7 @@
#define OKPP do { ok++; } while (0)
#endif
-struct TestMessage
+struct TestMessage
{
struct GNUNET_MessageHeader header;
uint32_t num;
@@ -106,13 +106,15 @@
get_size (unsigned int iter)
{
unsigned int ret;
+
if (iter < 60000)
return iter + sizeof (struct TestMessage);
ret = (iter * iter * iter);
return sizeof (struct TestMessage) + (ret % 60000);
}
-static void process_hello (void *cls, const struct GNUNET_MessageHeader
*message);
+static void process_hello (void *cls,
+ const struct GNUNET_MessageHeader *message);
static void
terminate_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
@@ -131,9 +133,9 @@
p2.th = NULL;
delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value;
fprintf (stderr,
- "\nThroughput was %llu kb/s\n",
- total_bytes * 1000 / 1024 / delta);
- GAUGER ("CORE", "Core throughput/s", total_bytes * 1000 / 1024 / delta,
"kb/s");
+ "\nThroughput was %llu kb/s\n", total_bytes * 1000 / 1024 / delta);
+ GAUGER ("CORE", "Core throughput/s", total_bytes * 1000 / 1024 / delta,
+ "kb/s");
ok = 0;
}
@@ -143,27 +145,27 @@
{
GNUNET_break (0);
if (p1.ch != NULL)
- {
- GNUNET_CORE_disconnect (p1.ch);
- p1.ch = NULL;
- }
+ {
+ GNUNET_CORE_disconnect (p1.ch);
+ p1.ch = NULL;
+ }
if (p2.ch != NULL)
- {
- GNUNET_CORE_disconnect (p2.ch);
- p2.ch = NULL;
- }
+ {
+ GNUNET_CORE_disconnect (p2.ch);
+ p2.ch = NULL;
+ }
if (p1.th != NULL)
- {
- GNUNET_TRANSPORT_get_hello_cancel (p1.th, &process_hello, &p1);
- GNUNET_TRANSPORT_disconnect (p1.th);
- p1.th = NULL;
- }
+ {
+ GNUNET_TRANSPORT_get_hello_cancel (p1.th, &process_hello, &p1);
+ GNUNET_TRANSPORT_disconnect (p1.th);
+ p1.th = NULL;
+ }
if (p2.th != NULL)
- {
- GNUNET_TRANSPORT_get_hello_cancel (p2.th, &process_hello, &p2);
- GNUNET_TRANSPORT_disconnect (p2.th);
- p2.th = NULL;
- }
+ {
+ GNUNET_TRANSPORT_get_hello_cancel (p2.th, &process_hello, &p2);
+ GNUNET_TRANSPORT_disconnect (p2.th);
+ p2.th = NULL;
+ }
ok = 42;
}
@@ -176,20 +178,20 @@
unsigned int s;
unsigned int ret;
- GNUNET_assert (size <= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE);
+ GNUNET_assert (size <= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE);
if (buf == NULL)
- {
- if (p1.ch != NULL)
- GNUNET_break (NULL !=
- GNUNET_CORE_notify_transmit_ready (p1.ch,
- GNUNET_NO,
- 0,
- FAST_TIMEOUT,
- &p2.id,
- get_size(tr_n),
- &transmit_ready, &p1));
- return 0;
- }
+ {
+ if (p1.ch != NULL)
+ GNUNET_break (NULL !=
+ GNUNET_CORE_notify_transmit_ready (p1.ch,
+ GNUNET_NO,
+ 0,
+ FAST_TIMEOUT,
+ &p2.id,
+ get_size (tr_n),
+ &transmit_ready, &p1));
+ return 0;
+ }
GNUNET_assert (tr_n < TOTAL_MSGS);
ret = 0;
s = get_size (tr_n);
@@ -197,35 +199,29 @@
GNUNET_assert (buf != NULL);
cbuf = buf;
do
- {
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending message %u of size %u at offset %u\n",
- tr_n,
- s,
- ret);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending message %u of size %u at offset %u\n", tr_n, s, ret);
#endif
- hdr.header.size = htons (s);
- hdr.header.type = htons (MTYPE);
- hdr.num = htonl (tr_n);
- memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage));
- ret += sizeof (struct TestMessage);
- memset (&cbuf[ret], tr_n, s - sizeof (struct TestMessage));
- ret += s - sizeof (struct TestMessage);
- tr_n++;
- s = get_size (tr_n);
- if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16))
- break; /* sometimes pack buffer full, sometimes not */
- }
+ hdr.header.size = htons (s);
+ hdr.header.type = htons (MTYPE);
+ hdr.num = htonl (tr_n);
+ memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage));
+ ret += sizeof (struct TestMessage);
+ memset (&cbuf[ret], tr_n, s - sizeof (struct TestMessage));
+ ret += s - sizeof (struct TestMessage);
+ tr_n++;
+ s = get_size (tr_n);
+ if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16))
+ break; /* sometimes pack buffer full, sometimes not */
+ }
while (size - ret >= s);
GNUNET_SCHEDULER_cancel (err_task);
- err_task =
- GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &terminate_task_error,
- NULL);
+ err_task =
+ GNUNET_SCHEDULER_add_delayed (TIMEOUT, &terminate_task_error, NULL);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Returning total message block of size %u\n",
- ret);
+ "Returning total message block of size %u\n", ret);
total_bytes += ret;
return ret;
}
@@ -235,51 +231,44 @@
static void
connect_notify (void *cls,
const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
struct PeerContext *pc = cls;
- if (0 == memcmp (&pc->id,
- peer,
- sizeof (struct GNUNET_PeerIdentity)))
+ if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity)))
return;
GNUNET_assert (pc->connect_status == 0);
pc->connect_status = 1;
if (pc == &p1)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Encrypted connection established to peer `%4s'\n",
- GNUNET_i2s (peer));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Asking core (1) for transmission to peer `%4s'\n",
- GNUNET_i2s (&p2.id));
- GNUNET_SCHEDULER_cancel (err_task);
- err_task =
- GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &terminate_task_error,
- NULL);
- start_time = GNUNET_TIME_absolute_get ();
- GNUNET_break (NULL !=
- GNUNET_CORE_notify_transmit_ready (p1.ch,
- GNUNET_NO,
- 0,
- TIMEOUT,
- &p2.id,
- get_size (0),
- &transmit_ready, &p1));
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Encrypted connection established to peer `%4s'\n",
+ GNUNET_i2s (peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Asking core (1) for transmission to peer `%4s'\n",
+ GNUNET_i2s (&p2.id));
+ GNUNET_SCHEDULER_cancel (err_task);
+ err_task =
+ GNUNET_SCHEDULER_add_delayed (TIMEOUT, &terminate_task_error, NULL);
+ start_time = GNUNET_TIME_absolute_get ();
+ GNUNET_break (NULL !=
+ GNUNET_CORE_notify_transmit_ready (p1.ch,
+ GNUNET_NO,
+ 0,
+ TIMEOUT,
+ &p2.id,
+ get_size (0),
+ &transmit_ready, &p1));
+ }
}
static void
-disconnect_notify (void *cls,
- const struct GNUNET_PeerIdentity *peer)
+disconnect_notify (void *cls, const struct GNUNET_PeerIdentity *peer)
{
struct PeerContext *pc = cls;
- if (0 == memcmp (&pc->id,
- peer,
- sizeof (struct GNUNET_PeerIdentity)))
+ if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity)))
return;
pc->connect_status = 0;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -291,7 +280,7 @@
inbound_notify (void *cls,
const struct GNUNET_PeerIdentity *other,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -305,7 +294,7 @@
outbound_notify (void *cls,
const struct GNUNET_PeerIdentity *other,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -316,71 +305,65 @@
}
-static size_t
-transmit_ready (void *cls, size_t size, void *buf);
+static size_t 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_TRANSPORT_ATS_Information *atsi)
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
static int n;
unsigned int s;
const struct TestMessage *hdr;
- hdr = (const struct TestMessage*) message;
+ hdr = (const struct TestMessage *) message;
s = get_size (n);
if (MTYPE != ntohs (message->type))
return GNUNET_SYSERR;
if (ntohs (message->size) != s)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Expected message %u of size %u, got %u bytes of message
%u\n",
- n, s,
- ntohs (message->size),
- ntohl (hdr->num));
- GNUNET_SCHEDULER_cancel (err_task);
- err_task = GNUNET_SCHEDULER_add_now (&terminate_task_error, NULL);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Expected message %u of size %u, got %u bytes of message %u\n",
+ n, s, ntohs (message->size), ntohl (hdr->num));
+ GNUNET_SCHEDULER_cancel (err_task);
+ err_task = GNUNET_SCHEDULER_add_now (&terminate_task_error, NULL);
+ return GNUNET_SYSERR;
+ }
if (ntohl (hdr->num) != n)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Expected message %u of size %u, got %u bytes of message
%u\n",
- n, s,
- ntohs (message->size),
- ntohl (hdr->num));
- GNUNET_SCHEDULER_cancel (err_task);
- err_task = GNUNET_SCHEDULER_add_now (&terminate_task_error, NULL);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Expected message %u of size %u, got %u bytes of message %u\n",
+ n, s, ntohs (message->size), ntohl (hdr->num));
+ GNUNET_SCHEDULER_cancel (err_task);
+ err_task = GNUNET_SCHEDULER_add_now (&terminate_task_error, NULL);
+ return GNUNET_SYSERR;
+ }
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Got message %u of size %u\n",
- ntohl (hdr->num),
- ntohs (message->size));
+ "Got message %u of size %u\n",
+ ntohl (hdr->num), ntohs (message->size));
#endif
n++;
- if (0 == (n % (TOTAL_MSGS/100)))
+ if (0 == (n % (TOTAL_MSGS / 100)))
fprintf (stderr, ".");
if (n == TOTAL_MSGS)
- {
- GNUNET_SCHEDULER_cancel (err_task);
- GNUNET_SCHEDULER_add_now (&terminate_task, NULL);
- }
+ {
+ GNUNET_SCHEDULER_cancel (err_task);
+ GNUNET_SCHEDULER_add_now (&terminate_task, NULL);
+ }
else
- {
- if (n == tr_n)
- GNUNET_break (NULL !=
- GNUNET_CORE_notify_transmit_ready (p1.ch,
- GNUNET_NO,
- 0,
- FAST_TIMEOUT,
- &p2.id,
- get_size(tr_n),
- &transmit_ready, &p1));
- }
+ {
+ if (n == tr_n)
+ GNUNET_break (NULL !=
+ GNUNET_CORE_notify_transmit_ready (p1.ch,
+ GNUNET_NO,
+ 0,
+ FAST_TIMEOUT,
+ &p2.id,
+ get_size (tr_n),
+ &transmit_ready, &p1));
+ }
return GNUNET_OK;
}
@@ -407,44 +390,39 @@
p->id = *my_identity;
p->ch = server;
if (cls == &p1)
- {
- GNUNET_assert (ok == 2);
- OKPP;
- /* connect p2 */
- GNUNET_CORE_connect (p2.cfg, 1,
- &p2,
- &init_notify,
- &connect_notify,
- &disconnect_notify,
- NULL,
- &inbound_notify,
- GNUNET_YES,
- &outbound_notify, GNUNET_YES, handlers);
- }
+ {
+ GNUNET_assert (ok == 2);
+ OKPP;
+ /* connect p2 */
+ GNUNET_CORE_connect (p2.cfg, 1,
+ &p2,
+ &init_notify,
+ &connect_notify,
+ &disconnect_notify,
+ NULL,
+ &inbound_notify,
+ GNUNET_YES, &outbound_notify, GNUNET_YES, handlers);
+ }
else
- {
- GNUNET_assert (ok == 3);
- OKPP;
- GNUNET_assert (cls == &p2);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Asking core (1) to connect to peer `%4s'\n",
- GNUNET_i2s (&p2.id));
- GNUNET_CORE_peer_request_connect (p1.ch,
- &p2.id,
- NULL, NULL);
- }
+ {
+ GNUNET_assert (ok == 3);
+ OKPP;
+ GNUNET_assert (cls == &p2);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Asking core (1) to connect to peer `%4s'\n",
+ GNUNET_i2s (&p2.id));
+ GNUNET_CORE_peer_request_connect (p1.ch, &p2.id, NULL, NULL);
+ }
}
static void
-process_hello (void *cls,
- const struct GNUNET_MessageHeader *message)
+process_hello (void *cls, const struct GNUNET_MessageHeader *message)
{
struct PeerContext *p = cls;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received (my) `%s' from transport service\n",
- "HELLO");
+ "Received (my) `%s' from transport service\n", "HELLO");
GNUNET_assert (message != NULL);
p->hello = GNUNET_malloc (ntohs (message->size));
memcpy (p->hello, message, ntohs (message->size));
@@ -467,11 +445,11 @@
p->cfg = GNUNET_CONFIGURATION_create ();
#if START_ARM
p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
- "gnunet-service-arm",
+ "gnunet-service-arm",
#if VERBOSE
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", cfgname, NULL);
+ "-c", cfgname, NULL);
#endif
GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, NULL, NULL);
@@ -483,23 +461,20 @@
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
GNUNET_assert (ok == 1);
OKPP;
setup_peer (&p1, "test_core_api_peer1.conf");
setup_peer (&p2, "test_core_api_peer2.conf");
- err_task =
- GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &terminate_task_error,
- NULL);
+ err_task =
+ GNUNET_SCHEDULER_add_delayed (TIMEOUT, &terminate_task_error, NULL);
GNUNET_CORE_connect (p1.cfg, 1,
&p1,
&init_notify,
- &connect_notify,
+ &connect_notify,
&disconnect_notify,
- NULL,
+ NULL,
&inbound_notify,
GNUNET_YES, &outbound_notify, GNUNET_YES, handlers);
}
@@ -511,10 +486,11 @@
#if START_ARM
if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
- if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK)
+ if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "ARM process %u stopped\n", GNUNET_OS_process_get_pid
(p->arm_proc));
+ "ARM process %u stopped\n",
+ GNUNET_OS_process_get_pid (p->arm_proc));
GNUNET_OS_process_close (p->arm_proc);
p->arm_proc = NULL;
#endif
@@ -537,7 +513,8 @@
};
ok = 1;
GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
- argv, "test-core-api-reliability", "nohelp", options,
&run, &ok);
+ argv, "test-core-api-reliability", "nohelp", options,
+ &run, &ok);
stop_arm (&p1);
stop_arm (&p2);
return ok;
@@ -556,7 +533,7 @@
#endif
NULL);
ret = check ();
- GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-1");
+ GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-1");
GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-2");
return ret;
Modified: gnunet/src/core/test_core_api_send_to_self.c
===================================================================
--- gnunet/src/core/test_core_api_send_to_self.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/core/test_core_api_send_to_self.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -66,18 +66,17 @@
die_task = GNUNET_SCHEDULER_NO_TASK;
if (core != NULL)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Disconnecting core.\n");
- GNUNET_CORE_disconnect (core);
- core = NULL;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting core.\n");
+ GNUNET_CORE_disconnect (core);
+ core = NULL;
+ }
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Stopping peer\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peer\n");
if (0 != GNUNET_OS_process_kill (arm_proc, SIGTERM))
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
- if (GNUNET_OS_process_wait(arm_proc) != GNUNET_OK)
+ if (GNUNET_OS_process_wait (arm_proc) != GNUNET_OK)
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -85,33 +84,37 @@
GNUNET_OS_process_close (arm_proc);
arm_proc = NULL;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Ending test.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ending test.\n");
}
static int
-receive(void* cls, const struct GNUNET_PeerIdentity* other, const struct
GNUNET_MessageHeader* message, const struct GNUNET_TRANSPORT_ATS_Information*
atsi)
+receive (void *cls, const struct GNUNET_PeerIdentity *other,
+ const struct GNUNET_MessageHeader *message,
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
if (die_task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel(die_task);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received message from peer %s\n",
GNUNET_i2s(other));
- GNUNET_SCHEDULER_add_now(&cleanup, NULL);
+ GNUNET_SCHEDULER_cancel (die_task);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received message from peer %s\n",
+ GNUNET_i2s (other));
+ GNUNET_SCHEDULER_add_now (&cleanup, NULL);
ret = 0;
return GNUNET_OK;
}
static size_t
-send_message (void* cls, size_t size, void* buf)
+send_message (void *cls, size_t size, void *buf)
{
if (size == 0 || buf == NULL)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Could not send; got 0 buffer\n");
- return 0;
- }
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending!\n");
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Could not send; got 0 buffer\n");
+ return 0;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending!\n");
struct GNUNET_MessageHeader *hdr = buf;
- hdr->size = htons(sizeof(struct GNUNET_MessageHeader));
- hdr->type = htons(GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP);
- return ntohs(hdr->size);
+
+ hdr->size = htons (sizeof (struct GNUNET_MessageHeader));
+ hdr->type = htons (GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP);
+ return ntohs (hdr->size);
}
static void
@@ -120,33 +123,33 @@
const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pk)
{
if (core == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Could NOT connect to CORE;\n");
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Could NOT connect to CORE;\n");
+ return;
+ }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Correctly connected to CORE; we are the peer %s.\n",
- GNUNET_i2s (my_identity));
+ "Correctly connected to CORE; we are the peer %s.\n",
+ GNUNET_i2s (my_identity));
memcpy (&myself, my_identity, sizeof (struct GNUNET_PeerIdentity));
}
static void
connect_cb (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected to peer %s.\n",
- GNUNET_i2s (peer));
+ GNUNET_i2s (peer));
if (0 == memcmp (peer, &myself, sizeof (struct GNUNET_PeerIdentity)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connected to myself; sending message!\n");
- GNUNET_CORE_notify_transmit_ready (core,
- GNUNET_YES,
- 0, GNUNET_TIME_UNIT_FOREVER_REL,
- peer,
- sizeof (struct GNUNET_MessageHeader),
- send_message, NULL);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Connected to myself; sending message!\n");
+ GNUNET_CORE_notify_transmit_ready (core,
+ GNUNET_YES,
+ 0, GNUNET_TIME_UNIT_FOREVER_REL,
+ peer,
+ sizeof (struct GNUNET_MessageHeader),
+ send_message, NULL);
+ }
}
@@ -161,8 +164,7 @@
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
const static struct GNUNET_CORE_MessageHandler handlers[] = {
{&receive, GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP, 0},
@@ -172,22 +174,27 @@
core_cfg = GNUNET_CONFIGURATION_create ();
arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
- "gnunet-service-arm",
+ "gnunet-service-arm",
#if VERBOSE
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", "test_core_api_peer1.conf",
NULL);
+ "-c", "test_core_api_peer1.conf", NULL);
- GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_load (core_cfg,
"test_core_api_peer1.conf"));
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONFIGURATION_load (core_cfg,
+ "test_core_api_peer1.conf"));
core = GNUNET_CORE_connect (core_cfg,
- 42,
- NULL,
- &init,
- &connect_cb,
- NULL, NULL, NULL, 0, NULL, 0, handlers);
+ 42,
+ NULL,
+ &init,
+ &connect_cb,
+ NULL, NULL, NULL, 0, NULL, 0, handlers);
- die_task =
GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
60), &cleanup, cls);
+ die_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 60), &cleanup,
+ cls);
}
@@ -210,11 +217,11 @@
ret = 1;
return (GNUNET_OK ==
- GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
- argv,
- "test_core_api_send_to_self",
- gettext_noop ("help text"),
- options, &run, NULL)) ? ret : 1;
+ GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
+ argv,
+ "test_core_api_send_to_self",
+ gettext_noop ("help text"),
+ options, &run, NULL)) ? ret : 1;
}
/**
Modified: gnunet/src/core/test_core_api_start_only.c
===================================================================
--- gnunet/src/core/test_core_api_start_only.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/core/test_core_api_start_only.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -68,14 +68,13 @@
static void
connect_notify (void *cls,
const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
}
static void
-disconnect_notify (void *cls,
- const struct GNUNET_PeerIdentity *peer)
+disconnect_notify (void *cls, const struct GNUNET_PeerIdentity *peer)
{
}
@@ -84,7 +83,7 @@
inbound_notify (void *cls,
const struct GNUNET_PeerIdentity *other,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
return GNUNET_OK;
}
@@ -94,7 +93,7 @@
outbound_notify (void *cls,
const struct GNUNET_PeerIdentity *other,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
return GNUNET_OK;
}
@@ -106,8 +105,7 @@
static void
-shutdown_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GNUNET_CORE_disconnect (p1.ch);
p1.ch = NULL;
@@ -130,24 +128,24 @@
GNUNET_assert (server != NULL);
GNUNET_assert (p->ch == server);
if (cls == &p1)
- {
- /* connect p2 */
- p2.ch = GNUNET_CORE_connect (p2.cfg, 1,
- &p2,
- &init_notify,
- &connect_notify,
- &disconnect_notify,
- NULL,
- &inbound_notify,
- GNUNET_YES,
- &outbound_notify, GNUNET_YES, handlers);
- }
+ {
+ /* connect p2 */
+ p2.ch = GNUNET_CORE_connect (p2.cfg, 1,
+ &p2,
+ &init_notify,
+ &connect_notify,
+ &disconnect_notify,
+ NULL,
+ &inbound_notify,
+ GNUNET_YES,
+ &outbound_notify, GNUNET_YES, handlers);
+ }
else
- {
- GNUNET_assert (cls == &p2);
- GNUNET_SCHEDULER_cancel (timeout_task_id);
- GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
- }
+ {
+ GNUNET_assert (cls == &p2);
+ GNUNET_SCHEDULER_cancel (timeout_task_id);
+ GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
+ }
}
@@ -157,31 +155,30 @@
p->cfg = GNUNET_CONFIGURATION_create ();
#if START_ARM
p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
- "gnunet-service-arm",
+ "gnunet-service-arm",
#if VERBOSE
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", cfgname, NULL);
+ "-c", cfgname, NULL);
#endif
GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
}
static void
-timeout_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+timeout_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
fprintf (stderr, "Timeout.\n");
if (p1.ch != NULL)
- {
- GNUNET_CORE_disconnect (p1.ch);
- p1.ch = NULL;
- }
+ {
+ GNUNET_CORE_disconnect (p1.ch);
+ p1.ch = NULL;
+ }
if (p2.ch != NULL)
- {
- GNUNET_CORE_disconnect (p2.ch);
- p2.ch = NULL;
- }
+ {
+ GNUNET_CORE_disconnect (p2.ch);
+ p2.ch = NULL;
+ }
ok = 42;
}
@@ -190,39 +187,35 @@
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
GNUNET_assert (ok == 1);
OKPP;
setup_peer (&p1, "test_core_api_peer1.conf");
setup_peer (&p2, "test_core_api_peer2.conf");
- timeout_task_id = GNUNET_SCHEDULER_add_delayed
(GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, TIMEOUT),
- &timeout_task,
- NULL);
- p1.ch = GNUNET_CORE_connect (p1.cfg, 1,
- &p1,
- &init_notify,
- &connect_notify,
- &disconnect_notify,
- NULL,
- &inbound_notify,
- GNUNET_YES, &outbound_notify, GNUNET_YES,
handlers);
+ timeout_task_id =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MINUTES, TIMEOUT),
+ &timeout_task, NULL);
+ p1.ch =
+ GNUNET_CORE_connect (p1.cfg, 1, &p1, &init_notify, &connect_notify,
+ &disconnect_notify, NULL, &inbound_notify,
+ GNUNET_YES, &outbound_notify, GNUNET_YES, handlers);
}
static void
stop_arm (struct PeerContext *p)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Stopping peer\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peer\n");
#if START_ARM
if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
- if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK)
+ if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "ARM process %u stopped\n", GNUNET_OS_process_get_pid
(p->arm_proc));
+ "ARM process %u stopped\n",
+ GNUNET_OS_process_get_pid (p->arm_proc));
GNUNET_OS_process_close (p->arm_proc);
p->arm_proc = NULL;
#endif
@@ -249,9 +242,9 @@
ok = 1;
GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
- argv, "test-core-api-start-only", "nohelp", options,
&run, &ok);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Test finished\n");
+ argv, "test-core-api-start-only", "nohelp", options,
&run,
+ &ok);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test finished\n");
stop_arm (&p1);
stop_arm (&p2);
return ok;
Modified: gnunet/src/core/test_core_quota_compliance.c
===================================================================
--- gnunet/src/core/test_core_quota_compliance.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/core/test_core_quota_compliance.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -77,7 +77,7 @@
{
struct GNUNET_CONFIGURATION_Handle *cfg;
struct GNUNET_CORE_Handle *ch;
- struct GNUNET_PeerIdentity id;
+ struct GNUNET_PeerIdentity id;
struct GNUNET_TRANSPORT_Handle *th;
struct GNUNET_MessageHeader *hello;
struct GNUNET_STATISTICS_Handle *stats;
@@ -108,13 +108,14 @@
#define OKPP do { ok++; } while (0)
#endif
-struct TestMessage
+struct TestMessage
{
struct GNUNET_MessageHeader header;
uint32_t num;
};
-static void process_hello (void *cls, const struct GNUNET_MessageHeader
*message);
+static void process_hello (void *cls,
+ const struct GNUNET_MessageHeader *message);
static void
terminate_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
@@ -140,11 +141,11 @@
terminate_task_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Testcase failed!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Testcase failed!\n");
//GNUNET_break (0);
if (measure_task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel(measure_task);
+ GNUNET_SCHEDULER_cancel (measure_task);
GNUNET_TRANSPORT_get_hello_cancel (p1.th, &process_hello, &p1);
GNUNET_TRANSPORT_get_hello_cancel (p2.th, &process_hello, &p2);
@@ -173,21 +174,15 @@
*/
static int
print_stat (void *cls,
- const char *subsystem,
- const char *name,
- uint64_t value,
- int is_persistent)
+ const char *subsystem,
+ const char *name, uint64_t value, int is_persistent)
{
- if (cls==&p1)
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peer1 %50s = %12llu\n",
- name,
- (unsigned long long) value);
- if (cls==&p2)
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peer2 %50s = %12llu\n",
- name,
- (unsigned long long) value);
+ if (cls == &p1)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Peer1 %50s = %12llu\n", name, (unsigned long long) value);
+ if (cls == &p2)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Peer2 %50s = %12llu\n", name, (unsigned long long) value);
return GNUNET_OK;
}
@@ -202,7 +197,7 @@
unsigned long long int quota_delta;
measure_task = GNUNET_SCHEDULER_NO_TASK;
- fprintf(stdout,"\n");
+ fprintf (stdout, "\n");
running = GNUNET_NO;
delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value;
@@ -211,96 +206,91 @@
throughput_in = total_bytes_recv * 1000 / 1024 / delta;
if (current_quota_p1_in < current_quota_p2_in)
- max_quota_in = current_quota_p1_in;
+ max_quota_in = current_quota_p1_in;
else
- max_quota_in = current_quota_p2_in;
+ max_quota_in = current_quota_p2_in;
if (current_quota_p1_out < current_quota_p2_out)
- max_quota_out = current_quota_p1_out;
+ max_quota_out = current_quota_p1_out;
else
- max_quota_out = current_quota_p2_out;
+ max_quota_out = current_quota_p2_out;
if (max_quota_out < max_quota_in)
- quota_delta = max_quota_in / 10;
+ quota_delta = max_quota_in / 10;
else
- quota_delta = max_quota_out / 10;
+ quota_delta = max_quota_out / 10;
- if ((throughput_out > (max_quota_out+quota_delta)/1024) || (throughput_in >
(max_quota_in+quota_delta)/1024))
- ok = 1;
+ if ((throughput_out > (max_quota_out + quota_delta) / 1024) ||
+ (throughput_in > (max_quota_in + quota_delta) / 1024))
+ ok = 1;
else
- ok = 0;
+ ok = 0;
GNUNET_STATISTICS_get (p1.stats,
- "core",
- "# discarded CORE_SEND requests",
- GNUNET_TIME_UNIT_FOREVER_REL,
- NULL,
- &print_stat, &p1);
+ "core",
+ "# discarded CORE_SEND requests",
+ GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p1);
GNUNET_STATISTICS_get (p1.stats,
- "core",
- "# discarded CORE_SEND request bytes",
- GNUNET_TIME_UNIT_FOREVER_REL,
- NULL,
- &print_stat, &p1);
+ "core",
+ "# discarded CORE_SEND request bytes",
+ GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p1);
GNUNET_STATISTICS_get (p1.stats,
- "core",
- "# discarded lower priority CORE_SEND requests",
- GNUNET_TIME_UNIT_FOREVER_REL,
- NULL,
- &print_stat, NULL);
+ "core",
+ "# discarded lower priority CORE_SEND requests",
+ GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat,
NULL);
GNUNET_STATISTICS_get (p1.stats,
- "core",
- "# discarded lower priority CORE_SEND request bytes",
- GNUNET_TIME_UNIT_FOREVER_REL,
- NULL,
- &print_stat, &p1);
+ "core",
+ "# discarded lower priority CORE_SEND request bytes",
+ GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p1);
GNUNET_STATISTICS_get (p2.stats,
- "core",
- "# discarded CORE_SEND requests",
- GNUNET_TIME_UNIT_FOREVER_REL,
- NULL,
- &print_stat, &p2);
+ "core",
+ "# discarded CORE_SEND requests",
+ GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p2);
GNUNET_STATISTICS_get (p2.stats,
- "core",
- "# discarded CORE_SEND request bytes",
- GNUNET_TIME_UNIT_FOREVER_REL,
- NULL,
- &print_stat, &p2);
+ "core",
+ "# discarded CORE_SEND request bytes",
+ GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p2);
GNUNET_STATISTICS_get (p2.stats,
- "core",
- "# discarded lower priority CORE_SEND requests",
- GNUNET_TIME_UNIT_FOREVER_REL,
- NULL,
- &print_stat, &p2);
+ "core",
+ "# discarded lower priority CORE_SEND requests",
+ GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p2);
GNUNET_STATISTICS_get (p2.stats,
- "core",
- "# discarded lower priority CORE_SEND request bytes",
- GNUNET_TIME_UNIT_FOREVER_REL,
- NULL,
- &print_stat, &p2);
+ "core",
+ "# discarded lower priority CORE_SEND request bytes",
+ GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p2);
enum GNUNET_ErrorType kind = GNUNET_ERROR_TYPE_DEBUG;
- if (ok==1)
+
+ if (ok == 1)
{
- kind = GNUNET_ERROR_TYPE_ERROR;
+ kind = GNUNET_ERROR_TYPE_ERROR;
}
switch (test)
{
case SYMMETRIC:
- GNUNET_log (kind,"Core quota compliance test with symmetric quotas:
%s\n", (ok==0)?"PASSED":"FAILED");
- break;
+ GNUNET_log (kind, "Core quota compliance test with symmetric quotas: %s\n",
+ (ok == 0) ? "PASSED" : "FAILED");
+ break;
case ASYMMETRIC_SEND_LIMITED:
- GNUNET_log (kind,"Core quota compliance test with limited sender
quota: %s\n", (ok==0)?"PASSED":"FAILED");
- break;
+ GNUNET_log (kind,
+ "Core quota compliance test with limited sender quota: %s\n",
+ (ok == 0) ? "PASSED" : "FAILED");
+ break;
case ASYMMETRIC_RECV_LIMITED:
- GNUNET_log (kind,"Core quota compliance test with limited receiver
quota: %s\n", (ok==0)?"PASSED":"FAILED");
- break;
+ GNUNET_log (kind,
+ "Core quota compliance test with limited receiver quota: %s\n",
+ (ok == 0) ? "PASSED" : "FAILED");
+ break;
};
- GNUNET_log (kind,"Peer 1 send rate: %llu kB/s (%llu Bytes in %u
sec.)\n",throughput_out,total_bytes_sent, delta/1000);
- GNUNET_log (kind,"Peer 1 send quota: %llu kB/s\n",current_quota_p1_out /
1024);
- GNUNET_log (kind,"Peer 2 receive rate: %llu kB/s (%llu Bytes in %u
sec.)\n",throughput_in,total_bytes_recv, delta/1000);
- GNUNET_log (kind,"Peer 2 receive quota: %llu kB/s\n",current_quota_p2_in /
1024);
+ GNUNET_log (kind, "Peer 1 send rate: %llu kB/s (%llu Bytes in %u sec.)\n",
+ throughput_out, total_bytes_sent, delta / 1000);
+ GNUNET_log (kind, "Peer 1 send quota: %llu kB/s\n",
+ current_quota_p1_out / 1024);
+ GNUNET_log (kind, "Peer 2 receive rate: %llu kB/s (%llu Bytes in %u
sec.)\n",
+ throughput_in, total_bytes_recv, delta / 1000);
+ GNUNET_log (kind, "Peer 2 receive quota: %llu kB/s\n",
+ current_quota_p2_in / 1024);
/*
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. inbound quota allowed: %llu
kB/s\n",max_quota_in /1024);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. outbound quota allowed: %llu
kB/s\n",max_quota_out/1024);
@@ -319,49 +309,45 @@
GNUNET_assert (size <= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE);
if (buf == NULL)
- {
- if ( (p1.ch != NULL) &&
- (p1.connect_status == 1) )
- GNUNET_break (NULL !=
- GNUNET_CORE_notify_transmit_ready (p1.ch,
- GNUNET_NO,
- 0,
- FAST_TIMEOUT,
- &p2.id,
- MESSAGESIZE,
- &transmit_ready, &p1));
- return 0;
- }
+ {
+ if ((p1.ch != NULL) && (p1.connect_status == 1))
+ GNUNET_break (NULL !=
+ 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);
ret = 0;
GNUNET_assert (size >= MESSAGESIZE);
GNUNET_assert (buf != NULL);
cbuf = buf;
do
- {
+ {
#if DEBUG_TRANSMISSION
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending message %u of size %u at offset %u\n",
- tr_n,
- MESSAGESIZE,
- ret);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending message %u of size %u at offset %u\n",
+ tr_n, MESSAGESIZE, ret);
#endif
- hdr.header.size = htons (MESSAGESIZE);
- hdr.header.type = htons (MTYPE);
- hdr.num = htonl (tr_n);
- memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage));
- ret += sizeof (struct TestMessage);
- memset (&cbuf[ret], tr_n, MESSAGESIZE - sizeof (struct TestMessage));
- ret += MESSAGESIZE - sizeof (struct TestMessage);
- tr_n++;
- if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16))
- break; /* sometimes pack buffer full, sometimes not */
- }
+ hdr.header.size = htons (MESSAGESIZE);
+ hdr.header.type = htons (MTYPE);
+ hdr.num = htonl (tr_n);
+ memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage));
+ ret += sizeof (struct TestMessage);
+ memset (&cbuf[ret], tr_n, MESSAGESIZE - sizeof (struct TestMessage));
+ ret += MESSAGESIZE - sizeof (struct TestMessage);
+ tr_n++;
+ if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16))
+ break; /* sometimes pack buffer full, sometimes not */
+ }
while (size - ret >= MESSAGESIZE);
GNUNET_SCHEDULER_cancel (err_task);
err_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &terminate_task_error,
- NULL);
+ &terminate_task_error, NULL);
total_bytes_sent += ret;
return ret;
@@ -376,50 +362,48 @@
{
struct PeerContext *pc = cls;
- if (0 == memcmp (&pc->id,
- peer,
- sizeof (struct GNUNET_PeerIdentity)))
+ if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity)))
return;
GNUNET_assert (pc->connect_status == 0);
pc->connect_status = 1;
if (pc == &p1)
- {
+ {
#if DEBUG_TRANSMISSION
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Encrypted connection established to peer `%4s'\n",
- GNUNET_i2s (peer));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Asking core (1) for transmission to peer `%4s'\n",
- GNUNET_i2s (&p2.id));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Encrypted connection established to peer `%4s'\n",
+ GNUNET_i2s (peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Asking core (1) for transmission to peer `%4s'\n",
+ GNUNET_i2s (&p2.id));
#endif
- if (err_task != GNUNET_SCHEDULER_NO_TASK) GNUNET_SCHEDULER_cancel
(err_task);
- err_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &terminate_task_error,
- NULL);
- start_time = GNUNET_TIME_absolute_get ();
- running = GNUNET_YES;
- measure_task = GNUNET_SCHEDULER_add_delayed(MEASUREMENT_LENGTH,
&measurement_stop, NULL);
+ if (err_task != GNUNET_SCHEDULER_NO_TASK)
+ GNUNET_SCHEDULER_cancel (err_task);
+ err_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+ &terminate_task_error, NULL);
+ start_time = GNUNET_TIME_absolute_get ();
+ running = GNUNET_YES;
+ measure_task =
+ GNUNET_SCHEDULER_add_delayed (MEASUREMENT_LENGTH, &measurement_stop,
+ NULL);
- GNUNET_break (NULL != GNUNET_CORE_notify_transmit_ready (p1.ch,
- GNUNET_NO,
- 0,
- TIMEOUT,
- &p2.id,
- MESSAGESIZE,
- &transmit_ready,
&p1));
- }
+ GNUNET_break (NULL != GNUNET_CORE_notify_transmit_ready (p1.ch,
+ GNUNET_NO,
+ 0,
+ TIMEOUT,
+ &p2.id,
+ MESSAGESIZE,
+ &transmit_ready,
+ &p1));
+ }
}
static void
-disconnect_notify (void *cls,
- const struct GNUNET_PeerIdentity *peer)
+disconnect_notify (void *cls, const struct GNUNET_PeerIdentity *peer)
{
struct PeerContext *pc = cls;
- if (0 == memcmp (&pc->id,
- peer,
- sizeof (struct GNUNET_PeerIdentity)))
+ if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity)))
return;
pc->connect_status = 0;
#if DEBUG_TRANSMISSION
@@ -433,13 +417,14 @@
inbound_notify (void *cls,
const struct GNUNET_PeerIdentity *other,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
#if DEBUG_TRANSMISSION
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Core provides inbound data from `%4s' %llu.\n", GNUNET_i2s
(other), ntohs(message->size));
+ "Core provides inbound data from `%4s' %llu.\n",
+ GNUNET_i2s (other), ntohs (message->size));
#endif
- total_bytes_recv += ntohs(message->size);
+ total_bytes_recv += ntohs (message->size);
return GNUNET_OK;
}
@@ -448,7 +433,7 @@
outbound_notify (void *cls,
const struct GNUNET_PeerIdentity *other,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
#if DEBUG_TRANSMISSION
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -459,48 +444,42 @@
}
-static size_t
-transmit_ready (void *cls, size_t size, void *buf);
+static size_t 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_TRANSPORT_ATS_Information *atsi)
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
static int n;
const struct TestMessage *hdr;
- hdr = (const struct TestMessage*) message;
+ hdr = (const struct TestMessage *) message;
if (MTYPE != ntohs (message->type))
return GNUNET_SYSERR;
if (ntohs (message->size) != MESSAGESIZE)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Expected message %u of size %u, got %u bytes of message
%u\n",
- n, MESSAGESIZE,
- ntohs (message->size),
- ntohl (hdr->num));
- GNUNET_SCHEDULER_cancel (err_task);
- err_task = GNUNET_SCHEDULER_add_now (&terminate_task_error, NULL);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Expected message %u of size %u, got %u bytes of message %u\n",
+ n, MESSAGESIZE, ntohs (message->size), ntohl (hdr->num));
+ GNUNET_SCHEDULER_cancel (err_task);
+ err_task = GNUNET_SCHEDULER_add_now (&terminate_task_error, NULL);
+ return GNUNET_SYSERR;
+ }
if (ntohl (hdr->num) != n)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Expected message %u of size %u, got %u bytes of message
%u\n",
- n, MESSAGESIZE,
- ntohs (message->size),
- ntohl (hdr->num));
- GNUNET_SCHEDULER_cancel (err_task);
- err_task = GNUNET_SCHEDULER_add_now (&terminate_task_error, NULL);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Expected message %u of size %u, got %u bytes of message %u\n",
+ n, MESSAGESIZE, ntohs (message->size), ntohl (hdr->num));
+ GNUNET_SCHEDULER_cancel (err_task);
+ err_task = GNUNET_SCHEDULER_add_now (&terminate_task_error, NULL);
+ return GNUNET_SYSERR;
+ }
#if DEBUG_TRANSMISSION
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Got message %u of size %u\n",
- ntohl (hdr->num),
- ntohs (message->size));
+ "Got message %u of size %u\n",
+ ntohl (hdr->num), ntohs (message->size));
#endif
n++;
if (0 == (n % 10))
@@ -508,14 +487,14 @@
if (running == GNUNET_YES)
- GNUNET_break (NULL !=
- GNUNET_CORE_notify_transmit_ready (p1.ch,
- GNUNET_NO,
- 0,
- FAST_TIMEOUT,
- &p2.id,
- MESSAGESIZE,
- &transmit_ready, &p1));
+ GNUNET_break (NULL !=
+ GNUNET_CORE_notify_transmit_ready (p1.ch,
+ GNUNET_NO,
+ 0,
+ FAST_TIMEOUT,
+ &p2.id,
+ MESSAGESIZE,
+ &transmit_ready, &p1));
return GNUNET_OK;
}
@@ -542,48 +521,43 @@
p->id = *my_identity;
p->ch = server;
if (cls == &p1)
- {
- GNUNET_assert (ok == 2);
- OKPP;
- /* connect p2 */
- GNUNET_CORE_connect (p2.cfg, 1,
- &p2,
- &init_notify,
- &connect_notify,
- &disconnect_notify,
- NULL,
- &inbound_notify,
- GNUNET_YES,
- &outbound_notify, GNUNET_YES, handlers);
- }
+ {
+ GNUNET_assert (ok == 2);
+ OKPP;
+ /* connect p2 */
+ GNUNET_CORE_connect (p2.cfg, 1,
+ &p2,
+ &init_notify,
+ &connect_notify,
+ &disconnect_notify,
+ NULL,
+ &inbound_notify,
+ GNUNET_YES, &outbound_notify, GNUNET_YES, handlers);
+ }
else
- {
- GNUNET_assert (ok == 3);
- OKPP;
- GNUNET_assert (cls == &p2);
+ {
+ GNUNET_assert (ok == 3);
+ OKPP;
+ GNUNET_assert (cls == &p2);
#if DEBUG_TRANSMISSION
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Asking core (1) to connect to peer `%4s'\n",
- GNUNET_i2s (&p2.id));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Asking core (1) to connect to peer `%4s'\n",
+ GNUNET_i2s (&p2.id));
#endif
- GNUNET_CORE_peer_request_connect (p1.ch,
- &p2.id,
- NULL, NULL);
- }
+ GNUNET_CORE_peer_request_connect (p1.ch, &p2.id, NULL, NULL);
+ }
}
static void
-process_hello (void *cls,
- const struct GNUNET_MessageHeader *message)
+process_hello (void *cls, const struct GNUNET_MessageHeader *message)
{
struct PeerContext *p = cls;
#if DEBUG_TRANSMISSION
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received (my) `%s' from transport service\n",
- "HELLO");
+ "Received (my) `%s' from transport service\n", "HELLO");
#endif
GNUNET_assert (message != NULL);
p->hello = GNUNET_malloc (ntohs (message->size));
@@ -607,15 +581,15 @@
p->cfg = GNUNET_CONFIGURATION_create ();
#if START_ARM
p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
- "gnunet-service-arm",
+ "gnunet-service-arm",
#if VERBOSE
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", cfgname, NULL);
+ "-c", cfgname, NULL);
#endif
GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
- p->stats = GNUNET_STATISTICS_create ("core",p->cfg);
- GNUNET_assert (p->stats!=NULL);
+ p->stats = GNUNET_STATISTICS_create ("core", p->cfg);
+ GNUNET_assert (p->stats != NULL);
p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, NULL, NULL);
GNUNET_assert (p->th != NULL);
GNUNET_TRANSPORT_get_hello (p->th, &process_hello, p);
@@ -625,47 +599,45 @@
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
GNUNET_assert (ok == 1);
OKPP;
err_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &terminate_task_error,
- NULL);
+ &terminate_task_error, NULL);
if (test == SYMMETRIC)
- {
- setup_peer (&p1, "test_core_quota_peer1.conf");
- setup_peer (&p2, "test_core_quota_peer2.conf");
- }
+ {
+ setup_peer (&p1, "test_core_quota_peer1.conf");
+ setup_peer (&p2, "test_core_quota_peer2.conf");
+ }
else if (test == ASYMMETRIC_SEND_LIMITED)
- {
- setup_peer (&p1, "test_core_quota_asymmetric_send_limit_peer1.conf");
- setup_peer (&p2, "test_core_quota_asymmetric_send_limit_peer2.conf");
- }
+ {
+ setup_peer (&p1, "test_core_quota_asymmetric_send_limit_peer1.conf");
+ setup_peer (&p2, "test_core_quota_asymmetric_send_limit_peer2.conf");
+ }
else if (test == ASYMMETRIC_RECV_LIMITED)
- {
- setup_peer (&p1, "test_core_quota_asymmetric_recv_limited_peer1.conf");
- setup_peer (&p2, "test_core_quota_asymmetric_recv_limited_peer2.conf");
- }
+ {
+ setup_peer (&p1, "test_core_quota_asymmetric_recv_limited_peer1.conf");
+ setup_peer (&p2, "test_core_quota_asymmetric_recv_limited_peer2.conf");
+ }
GNUNET_assert (test != -1);
GNUNET_assert (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_number
(p1.cfg,
- "CORE",
- "TOTAL_QUOTA_IN",
- ¤t_quota_p1_in));
+
"CORE",
+
"TOTAL_QUOTA_IN",
+
¤t_quota_p1_in));
GNUNET_assert (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_number
(p2.cfg,
- "CORE",
- "TOTAL_QUOTA_IN",
- ¤t_quota_p2_in));
+
"CORE",
+
"TOTAL_QUOTA_IN",
+
¤t_quota_p2_in));
GNUNET_assert (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_number
(p1.cfg,
- "CORE",
- "TOTAL_QUOTA_OUT",
- ¤t_quota_p1_out));
+
"CORE",
+
"TOTAL_QUOTA_OUT",
+
¤t_quota_p1_out));
GNUNET_assert (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_number
(p2.cfg,
- "CORE",
- "TOTAL_QUOTA_OUT",
- ¤t_quota_p2_out));
+
"CORE",
+
"TOTAL_QUOTA_OUT",
+
¤t_quota_p2_out));
GNUNET_CORE_connect (p1.cfg, 1,
&p1,
@@ -684,10 +656,11 @@
#if START_ARM
if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
- if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK)
+ if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "ARM process %u stopped\n", GNUNET_OS_process_get_pid
(p->arm_proc));
+ "ARM process %u stopped\n",
+ GNUNET_OS_process_get_pid (p->arm_proc));
GNUNET_OS_process_close (p->arm_proc);
p->arm_proc = NULL;
#endif
@@ -712,7 +685,8 @@
};
ok = 1;
GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
- argv, "test-core-quota-compliance", "nohelp", options,
&run, &ok);
+ argv, "test-core-quota-compliance", "nohelp", options,
+ &run, &ok);
stop_arm (&p1);
stop_arm (&p2);
return ok;
@@ -724,34 +698,38 @@
int ret;
test = -1;
- if (strstr(argv[0], "_symmetric") != NULL)
- {
- test = SYMMETRIC;
- }
- else if (strstr(argv[0], "_asymmetric_send") != NULL)
- {
- test = ASYMMETRIC_SEND_LIMITED;
- }
- else if (strstr(argv[0], "_asymmetric_recv") != NULL)
- {
- test = ASYMMETRIC_RECV_LIMITED;
- }
+ if (strstr (argv[0], "_symmetric") != NULL)
+ {
+ test = SYMMETRIC;
+ }
+ else if (strstr (argv[0], "_asymmetric_send") != NULL)
+ {
+ test = ASYMMETRIC_SEND_LIMITED;
+ }
+ else if (strstr (argv[0], "_asymmetric_recv") != NULL)
+ {
+ test = ASYMMETRIC_RECV_LIMITED;
+ }
GNUNET_assert (test != -1);
if (test == SYMMETRIC)
- {
- GNUNET_DISK_directory_remove
("/tmp/test-gnunet-core-quota-sym-peer-1/");
- GNUNET_DISK_directory_remove
("/tmp/test-gnunet-core-quota-sym-peer-2/");
- }
+ {
+ GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-quota-sym-peer-1/");
+ GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-quota-sym-peer-2/");
+ }
else if (test == ASYMMETRIC_SEND_LIMITED)
- {
- GNUNET_DISK_directory_remove
("/tmp/test-gnunet-core-quota-asym-send-lim-peer-1/");
- GNUNET_DISK_directory_remove
("/tmp/test-gnunet-core-quota-asym-send-lim-peer-2/");
- }
+ {
+ GNUNET_DISK_directory_remove
+ ("/tmp/test-gnunet-core-quota-asym-send-lim-peer-1/");
+ GNUNET_DISK_directory_remove
+ ("/tmp/test-gnunet-core-quota-asym-send-lim-peer-2/");
+ }
else if (test == ASYMMETRIC_RECV_LIMITED)
- {
- GNUNET_DISK_directory_remove
("/tmp/test-gnunet-core-quota-asym-recv-lim-peer-1/");
- GNUNET_DISK_directory_remove
("/tmp/test-gnunet-core-quota-asym-recv-lim-peer-2/");
- }
+ {
+ GNUNET_DISK_directory_remove
+ ("/tmp/test-gnunet-core-quota-asym-recv-lim-peer-1/");
+ GNUNET_DISK_directory_remove
+ ("/tmp/test-gnunet-core-quota-asym-recv-lim-peer-2/");
+ }
GNUNET_log_setup ("test-core-quota-compliance",
#if VERBOSE
@@ -762,23 +740,28 @@
NULL);
ret = check ();
if (test == SYMMETRIC)
- {
- GNUNET_DISK_directory_remove
("/tmp/test-gnunet-core-quota-sym-peer-1/");
- GNUNET_DISK_directory_remove
("/tmp/test-gnunet-core-quota-sym-peer-2/");
- }
+ {
+ GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-quota-sym-peer-1/");
+ GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-quota-sym-peer-2/");
+ }
else if (test == ASYMMETRIC_SEND_LIMITED)
- {
- GNUNET_DISK_directory_remove
("/tmp/test-gnunet-core-quota-asym-send-lim-peer-1/");
- GNUNET_DISK_directory_remove
("/tmp/test-gnunet-core-quota-asym-send-lim-peer-2/");
- }
+ {
+ GNUNET_DISK_directory_remove
+ ("/tmp/test-gnunet-core-quota-asym-send-lim-peer-1/");
+ GNUNET_DISK_directory_remove
+ ("/tmp/test-gnunet-core-quota-asym-send-lim-peer-2/");
+ }
else if (test == ASYMMETRIC_RECV_LIMITED)
- {
- GNUNET_DISK_directory_remove
("/tmp/test-gnunet-core-quota-asym-recv-lim-peer-1/");
- GNUNET_DISK_directory_remove
("/tmp/test-gnunet-core-quota-asym-recv-lim-peer-2/");
- }
+ {
+ GNUNET_DISK_directory_remove
+ ("/tmp/test-gnunet-core-quota-asym-recv-lim-peer-1/");
+ GNUNET_DISK_directory_remove
+ ("/tmp/test-gnunet-core-quota-asym-recv-lim-peer-2/");
+ }
return ret;
}
+
/* end of test_core_api_reliability.c */
Modified: gnunet/src/datacache/datacache.c
===================================================================
--- gnunet/src/datacache/datacache.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/datacache/datacache.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -70,7 +70,7 @@
* Name of the library (i.e. "gnunet_plugin_datacache_sqlite").
*/
char *lib_name;
-
+
/**
* Name for the bloom filter file.
*/
@@ -97,19 +97,16 @@
* @param key key of the content that was deleted
* @param size number of bytes that were made available
*/
-static void
-env_delete_notify (void *cls,
- const GNUNET_HashCode *key,
- size_t size)
+static void
+env_delete_notify (void *cls, const GNUNET_HashCode * key, size_t size)
{
- struct GNUNET_DATACACHE_Handle * h = cls;
+ struct GNUNET_DATACACHE_Handle *h = cls;
+
GNUNET_assert (h->utilization >= size);
h->utilization -= size;
GNUNET_CONTAINER_bloomfilter_remove (h->filter, key);
GNUNET_STATISTICS_update (h->stats,
- gettext_noop ("# bytes stored"),
- -size,
- GNUNET_NO);
+ gettext_noop ("# bytes stored"), -size, GNUNET_NO);
}
@@ -122,7 +119,7 @@
*/
struct GNUNET_DATACACHE_Handle *
GNUNET_DATACACHE_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *section)
+ const char *section)
{
unsigned int bf_size;
unsigned long long quota;
@@ -131,45 +128,38 @@
char *name;
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (cfg,
- section, "QUOTA", "a))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("No `%s' specified for `%s' in configuration!\n"),
- "QUOTA",
- section);
- return NULL;
- }
+ GNUNET_CONFIGURATION_get_value_number (cfg, section, "QUOTA", "a))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("No `%s' specified for `%s' in configuration!\n"),
+ "QUOTA", section);
+ return NULL;
+ }
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- section,
- "DATABASE", &name))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("No `%s' specified for `%s' in configuration!\n"),
- "DATABASE",
- section);
- return NULL;
- }
- bf_size = quota / 32; /* 8 bit per entry, 1 bit per 32 kb in DB */
+ GNUNET_CONFIGURATION_get_value_string (cfg, section, "DATABASE", &name))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("No `%s' specified for `%s' in configuration!\n"),
+ "DATABASE", section);
+ return NULL;
+ }
+ bf_size = quota / 32; /* 8 bit per entry, 1 bit per 32 kb in DB */
- ret = GNUNET_malloc (sizeof(struct GNUNET_DATACACHE_Handle));
+ ret = GNUNET_malloc (sizeof (struct GNUNET_DATACACHE_Handle));
ret->bloom_name = GNUNET_DISK_mktemp ("gnunet-datacachebloom");
if (NULL != ret->bloom_name)
- {
- ret->filter = GNUNET_CONTAINER_bloomfilter_load (ret->bloom_name,
- quota / 1024, /* 8
bit per entry in DB, expect 1k entries */
- 5);
- }
+ {
+ ret->filter = GNUNET_CONTAINER_bloomfilter_load (ret->bloom_name, quota /
1024, /* 8 bit per entry in DB, expect 1k entries */
+ 5);
+ }
else
- {
- ret->filter = GNUNET_CONTAINER_bloomfilter_init (NULL, bf_size, 5); /*
approx. 3% false positives at max use */
- }
- ret->stats = GNUNET_STATISTICS_create ("datacache",
- cfg);
+ {
+ ret->filter = GNUNET_CONTAINER_bloomfilter_init (NULL, bf_size, 5); /*
approx. 3% false positives at max use */
+ }
+ ret->stats = GNUNET_STATISTICS_create ("datacache", cfg);
ret->section = GNUNET_strdup (section);
ret->env.cfg = cfg;
- ret->env.delete_notify = &env_delete_notify;
+ ret->env.delete_notify = &env_delete_notify;
ret->env.section = ret->section;
ret->env.cls = ret;
ret->env.delete_notify = &env_delete_notify;
@@ -181,12 +171,12 @@
ret->lib_name = libname;
ret->api = GNUNET_PLUGIN_load (libname, &ret->env);
if (ret->api == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to load datacache plugin for `%s'\n"), name);
- GNUNET_DATACACHE_destroy (ret);
- return NULL;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to load datacache plugin for `%s'\n"), name);
+ GNUNET_DATACACHE_destroy (ret);
+ return NULL;
+ }
return ret;
}
@@ -196,7 +186,8 @@
*
* @param h handle to the datastore
*/
-void GNUNET_DATACACHE_destroy (struct GNUNET_DATACACHE_Handle *h)
+void
+GNUNET_DATACACHE_destroy (struct GNUNET_DATACACHE_Handle *h)
{
if (h->filter != NULL)
GNUNET_CONTAINER_bloomfilter_free (h->filter);
@@ -206,15 +197,13 @@
GNUNET_free (h->short_name);
GNUNET_free (h->section);
if (h->bloom_name != NULL)
- {
- if (0 != UNLINK (h->bloom_name))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
- "unlink",
- h->bloom_name);
- GNUNET_free (h->bloom_name);
- }
- GNUNET_STATISTICS_destroy (h->stats,
- GNUNET_NO);
+ {
+ if (0 != UNLINK (h->bloom_name))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
+ "unlink", h->bloom_name);
+ GNUNET_free (h->bloom_name);
+ }
+ GNUNET_STATISTICS_destroy (h->stats, GNUNET_NO);
GNUNET_free (h);
}
@@ -230,31 +219,24 @@
* @param discard_time when to discard the value in any case
* @return GNUNET_OK on success, GNUNET_SYSERR on error (full, etc.)
*/
-int
+int
GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h,
- const GNUNET_HashCode * key,
- size_t size,
- const char *data,
- enum GNUNET_BLOCK_Type type,
- struct GNUNET_TIME_Absolute discard_time)
+ const GNUNET_HashCode * key,
+ size_t size,
+ const char *data,
+ enum GNUNET_BLOCK_Type type,
+ struct GNUNET_TIME_Absolute discard_time)
{
uint32_t used;
- used = h->api->put (h->api->cls,
- key,
- size,
- data,
- type,
- discard_time);
+ used = h->api->put (h->api->cls, key, size, data, type, discard_time);
if (used == 0)
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
GNUNET_STATISTICS_update (h->stats,
- gettext_noop ("# bytes stored"),
- size,
- GNUNET_NO);
+ gettext_noop ("# bytes stored"), size, GNUNET_NO);
GNUNET_CONTAINER_bloomfilter_add (h->filter, key);
while (h->utilization + used > h->env.quota)
GNUNET_assert (GNUNET_OK == h->api->del (h->api->cls));
@@ -274,31 +256,23 @@
* @param iter_cls closure for iter
* @return the number of results found
*/
-unsigned int
+unsigned int
GNUNET_DATACACHE_get (struct GNUNET_DATACACHE_Handle *h,
- const GNUNET_HashCode * key,
- enum GNUNET_BLOCK_Type type,
- GNUNET_DATACACHE_Iterator iter,
- void *iter_cls)
+ const GNUNET_HashCode * key,
+ enum GNUNET_BLOCK_Type type,
+ GNUNET_DATACACHE_Iterator iter, void *iter_cls)
{
GNUNET_STATISTICS_update (h->stats,
- gettext_noop ("# requests received"),
- 1,
- GNUNET_NO);
- if (GNUNET_OK != GNUNET_CONTAINER_bloomfilter_test (h->filter,
- key))
- {
- GNUNET_STATISTICS_update (h->stats,
- gettext_noop ("# requests filtered by bloom
filter"),
- 1,
- GNUNET_NO);
- return 0; /* can not be present */
- }
- return h->api->get (h->api->cls,
- key,
- type,
- iter,
- iter_cls);
+ gettext_noop ("# requests received"), 1,
GNUNET_NO);
+ if (GNUNET_OK != GNUNET_CONTAINER_bloomfilter_test (h->filter, key))
+ {
+ GNUNET_STATISTICS_update (h->stats,
+ gettext_noop
+ ("# requests filtered by bloom filter"), 1,
+ GNUNET_NO);
+ return 0; /* can not be present */
+ }
+ return h->api->get (h->api->cls, key, type, iter, iter_cls);
}
Modified: gnunet/src/datacache/perf_datacache.c
===================================================================
--- gnunet/src/datacache/perf_datacache.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/datacache/perf_datacache.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -45,14 +45,11 @@
static int
checkIt (void *cls,
- struct GNUNET_TIME_Absolute exp,
- const GNUNET_HashCode * key,
- size_t size,
- const char *data,
- enum GNUNET_BLOCK_Type type)
+ struct GNUNET_TIME_Absolute exp,
+ const GNUNET_HashCode * key,
+ size_t size, const char *data, enum GNUNET_BLOCK_Type type)
{
- if ( (size == sizeof (GNUNET_HashCode)) &&
- (0 == memcmp (data, cls, size)) )
+ if ((size == sizeof (GNUNET_HashCode)) && (0 == memcmp (data, cls, size)))
found++;
return GNUNET_OK;
}
@@ -61,8 +58,7 @@
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
struct GNUNET_DATACACHE_Handle *h;
GNUNET_HashCode k;
@@ -71,66 +67,64 @@
struct GNUNET_TIME_Absolute start;
unsigned int i;
char gstr[128];
-
+
ok = 0;
- h = GNUNET_DATACACHE_create (cfg,
- "perfcache");
+ h = GNUNET_DATACACHE_create (cfg, "perfcache");
if (h == NULL)
- {
- fprintf (stderr,
- "Failed to initialize datacache. Database likely not setup,
skipping test.\n");
- return;
- }
+ {
+ fprintf (stderr,
+ "Failed to initialize datacache. Database likely not setup,
skipping test.\n");
+ return;
+ }
exp = GNUNET_TIME_absolute_get ();
start = exp;
exp.abs_value += 5 * 60 * 1000;
memset (&k, 0, sizeof (GNUNET_HashCode));
for (i = 0; i < ITERATIONS; i++)
- {
- if (0 == i % (ITERATIONS / 80))
- fprintf (stderr, ".");
- GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n);
- ASSERT (GNUNET_OK == GNUNET_DATACACHE_put (h,
- &k,
- sizeof (GNUNET_HashCode),
- (const char *) &n,
- 1+i%16,
- exp));
- k = n;
- }
+ {
+ if (0 == i % (ITERATIONS / 80))
+ fprintf (stderr, ".");
+ GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n);
+ ASSERT (GNUNET_OK == GNUNET_DATACACHE_put (h,
+ &k,
+ sizeof (GNUNET_HashCode),
+ (const char *) &n,
+ 1 + i % 16, exp));
+ k = n;
+ }
fprintf (stderr, "\n");
fprintf (stdout, "Stored %u items in %llums\n",
- ITERATIONS,
- (unsigned long long)
GNUNET_TIME_absolute_get_duration(start).rel_value);
- GNUNET_snprintf (gstr, sizeof (gstr),
- "DATACACHE-%s",
- plugin_name);
+ ITERATIONS,
+ (unsigned long long)
+ GNUNET_TIME_absolute_get_duration (start).rel_value);
+ GNUNET_snprintf (gstr, sizeof (gstr), "DATACACHE-%s", plugin_name);
GAUGER (gstr,
- "Time to PUT item in datacache",
- GNUNET_TIME_absolute_get_duration(start).rel_value / ITERATIONS,
- "ms/item");
+ "Time to PUT item in datacache",
+ GNUNET_TIME_absolute_get_duration (start).rel_value / ITERATIONS,
+ "ms/item");
start = GNUNET_TIME_absolute_get ();
memset (&k, 0, sizeof (GNUNET_HashCode));
for (i = 0; i < ITERATIONS; i++)
- {
- if (0 == i % (ITERATIONS / 80))
- fprintf (stderr, ".");
- GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n);
- GNUNET_DATACACHE_get (h, &k, 1+i%16,
- &checkIt, &n);
- k = n;
- }
+ {
+ if (0 == i % (ITERATIONS / 80))
+ fprintf (stderr, ".");
+ GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n);
+ GNUNET_DATACACHE_get (h, &k, 1 + i % 16, &checkIt, &n);
+ k = n;
+ }
fprintf (stderr, "\n");
- fprintf (stdout,
- "Found %u/%u items in %llums (%u were deleted during storage
processing)\n",
- found, ITERATIONS,
- (unsigned long long)
GNUNET_TIME_absolute_get_duration(start).rel_value,
- ITERATIONS - found);
+ fprintf (stdout,
+ "Found %u/%u items in %llums (%u were deleted during storage
processing)\n",
+ found, ITERATIONS,
+ (unsigned long long)
+ GNUNET_TIME_absolute_get_duration (start).rel_value,
+ ITERATIONS - found);
if (found > 0)
GAUGER (gstr,
- "Time to GET item from datacache",
- GNUNET_TIME_absolute_get_duration(start).rel_value / found,
"ms/item");
+ "Time to GET item from datacache",
+ GNUNET_TIME_absolute_get_duration (start).rel_value / found,
+ "ms/item");
GNUNET_DATACACHE_destroy (h);
ASSERT (ok == 0);
return;
@@ -146,7 +140,8 @@
{
char *pos;
char cfg_name[128];
- char *const xargv[] = {
+
+ char *const xargv[] = {
"perf-datacache",
"-c",
cfg_name,
@@ -158,7 +153,7 @@
struct GNUNET_GETOPT_CommandLineOption options[] = {
GNUNET_GETOPT_OPTION_END
};
-
+
GNUNET_log_setup ("perf-datacache",
#if VERBOSE
"DEBUG",
@@ -168,22 +163,20 @@
NULL);
/* determine name of plugin to use */
plugin_name = argv[0];
- while (NULL != (pos = strstr(plugin_name, "_")))
- plugin_name = pos+1;
- if (NULL != (pos = strstr(plugin_name, ".")))
+ while (NULL != (pos = strstr (plugin_name, "_")))
+ plugin_name = pos + 1;
+ if (NULL != (pos = strstr (plugin_name, ".")))
pos[0] = 0;
else
pos = (char *) plugin_name;
-
+
GNUNET_snprintf (cfg_name,
- sizeof (cfg_name),
- "perf_datacache_data_%s.conf",
- plugin_name);
+ sizeof (cfg_name),
+ "perf_datacache_data_%s.conf", plugin_name);
if (pos != plugin_name)
pos[0] = '.';
GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1,
- xargv, "perf-datacache", "nohelp",
- options, &run, NULL);
+ xargv, "perf-datacache", "nohelp", options, &run, NULL);
if (ok != 0)
fprintf (stderr, "Missed some perfcases: %d\n", ok);
return ok;
Modified: gnunet/src/datacache/plugin_datacache_mysql.c
===================================================================
--- gnunet/src/datacache/plugin_datacache_mysql.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/datacache/plugin_datacache_mysql.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -127,7 +127,7 @@
/**
* Context for all functions in this plugin.
*/
-struct Plugin
+struct Plugin
{
/**
* Our execution environment.
@@ -183,6 +183,7 @@
char *cnffile;
char *home_dir;
struct stat st;
+
#ifndef WINDOWS
struct passwd *pw;
#endif
@@ -191,44 +192,46 @@
#ifndef WINDOWS
pw = getpwuid (getuid ());
if (!pw)
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
- "getpwuid");
- return NULL;
- }
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "getpwuid");
+ return NULL;
+ }
if (GNUNET_YES ==
- GNUNET_CONFIGURATION_have_value (cfg,
- "datacache-mysql", "CONFIG"))
- {
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_filename (cfg,
-
"datacache-mysql", "CONFIG", &cnffile));
- configured = GNUNET_YES;
- }
+ GNUNET_CONFIGURATION_have_value (cfg, "datacache-mysql", "CONFIG"))
+ {
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_filename (cfg,
+ "datacache-mysql",
+ "CONFIG",
+ &cnffile));
+ configured = GNUNET_YES;
+ }
else
- {
- home_dir = GNUNET_strdup (pw->pw_dir);
+ {
+ home_dir = GNUNET_strdup (pw->pw_dir);
+ GNUNET_asprintf (&cnffile, "%s/.my.cnf", home_dir);
+ GNUNET_free (home_dir);
+ configured = GNUNET_NO;
+ }
#else
- home_dir = (char *) GNUNET_malloc (_MAX_PATH + 1);
- plibc_conv_to_win_path ("~/", home_dir);
+ home_dir = (char *) GNUNET_malloc (_MAX_PATH + 1);
+ plibc_conv_to_win_path ("~/", home_dir);
+ GNUNET_asprintf (&cnffile, "%s/.my.cnf", home_dir);
+ GNUNET_free (home_dir);
+ configured = GNUNET_NO;
#endif
- GNUNET_asprintf (&cnffile, "%s/.my.cnf", home_dir);
- GNUNET_free (home_dir);
- configured = GNUNET_NO;
- }
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Trying to use file `%s' for MySQL configuration.\n"),
- cnffile);
+ _("Trying to use file `%s' for MySQL configuration.\n"),
cnffile);
if ((0 != STAT (cnffile, &st)) ||
(0 != ACCESS (cnffile, R_OK)) || (!S_ISREG (st.st_mode)))
- {
- if (configured == GNUNET_YES)
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Could not access file `%s': %s\n"), cnffile,
- STRERROR (errno));
- GNUNET_free (cnffile);
- return NULL;
- }
+ {
+ if (configured == GNUNET_YES)
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Could not access file `%s': %s\n"), cnffile,
+ STRERROR (errno));
+ GNUNET_free (cnffile);
+ return NULL;
+ }
return cnffile;
}
@@ -240,13 +243,10 @@
* @param s prepared statement
*/
static void
-prepared_statement_destroy (struct Plugin *plugin,
- struct GNUNET_MysqlStatementHandle
- *s)
+prepared_statement_destroy (struct Plugin *plugin,
+ struct GNUNET_MysqlStatementHandle *s)
{
- GNUNET_CONTAINER_DLL_remove (plugin->shead,
- plugin->stail,
- s);
+ GNUNET_CONTAINER_DLL_remove (plugin->shead, plugin->stail, s);
if (s->valid)
mysql_stmt_close (s->statement);
GNUNET_free (s->query);
@@ -262,13 +262,12 @@
iclose (struct Plugin *plugin)
{
while (NULL != plugin->shead)
- prepared_statement_destroy (plugin,
- plugin->shead);
+ prepared_statement_destroy (plugin, plugin->shead);
if (plugin->dbf != NULL)
- {
- mysql_close (plugin->dbf);
- plugin->dbf = NULL;
- }
+ {
+ mysql_close (plugin->dbf);
+ plugin->dbf = NULL;
+ }
return GNUNET_OK;
}
@@ -298,71 +297,75 @@
mysql_options (ret->dbf, MYSQL_READ_DEFAULT_GROUP, "client");
reconnect = 0;
mysql_options (ret->dbf, MYSQL_OPT_RECONNECT, &reconnect);
- mysql_options (ret->dbf,
- MYSQL_OPT_CONNECT_TIMEOUT, (const void *) &timeout);
- mysql_options(ret->dbf, MYSQL_SET_CHARSET_NAME, "UTF8");
- timeout = 60; /* in seconds */
+ mysql_options (ret->dbf, MYSQL_OPT_CONNECT_TIMEOUT, (const void *) &timeout);
+ mysql_options (ret->dbf, MYSQL_SET_CHARSET_NAME, "UTF8");
+ timeout = 60; /* in seconds */
mysql_options (ret->dbf, MYSQL_OPT_READ_TIMEOUT, (const void *) &timeout);
mysql_options (ret->dbf, MYSQL_OPT_WRITE_TIMEOUT, (const void *) &timeout);
mysql_dbname = NULL;
if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (ret->env->cfg,
- "datacache-mysql",
"DATABASE"))
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (ret->env->cfg,
- "datacache-mysql",
"DATABASE",
- &mysql_dbname));
+ "datacache-mysql",
+ "DATABASE"))
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_string (ret->env->cfg,
+ "datacache-mysql",
+ "DATABASE",
+ &mysql_dbname));
else
mysql_dbname = GNUNET_strdup ("gnunet");
mysql_user = NULL;
if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (ret->env->cfg,
- "datacache-mysql", "USER"))
- {
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (ret->env->cfg,
- "datacache-mysql",
"USER",
- &mysql_user));
- }
+ "datacache-mysql",
"USER"))
+ {
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_string (ret->env->cfg,
+ "datacache-mysql",
+ "USER",
&mysql_user));
+ }
mysql_password = NULL;
if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (ret->env->cfg,
- "datacache-mysql",
"PASSWORD"))
- {
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (ret->env->cfg,
- "datacache-mysql",
"PASSWORD",
- &mysql_password));
- }
+ "datacache-mysql",
+ "PASSWORD"))
+ {
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_string (ret->env->cfg,
+ "datacache-mysql",
+ "PASSWORD",
+ &mysql_password));
+ }
mysql_server = NULL;
if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (ret->env->cfg,
- "datacache-mysql", "HOST"))
- {
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (ret->env->cfg,
- "datacache-mysql",
"HOST",
- &mysql_server));
- }
+ "datacache-mysql",
"HOST"))
+ {
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_string (ret->env->cfg,
+ "datacache-mysql",
+ "HOST",
+ &mysql_server));
+ }
mysql_port = 0;
if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (ret->env->cfg,
- "datacache-mysql", "PORT"))
- {
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_number (ret->env->cfg,
"datacache-mysql",
- "PORT",
&mysql_port));
- }
+ "datacache-mysql",
"PORT"))
+ {
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_number (ret->env->cfg,
+ "datacache-mysql",
+ "PORT",
&mysql_port));
+ }
GNUNET_assert (mysql_dbname != NULL);
mysql_real_connect (ret->dbf, mysql_server, mysql_user, mysql_password,
mysql_dbname, (unsigned int) mysql_port, NULL,
- CLIENT_IGNORE_SIGPIPE);
+ CLIENT_IGNORE_SIGPIPE);
GNUNET_free_non_null (mysql_server);
GNUNET_free_non_null (mysql_user);
GNUNET_free_non_null (mysql_password);
GNUNET_free (mysql_dbname);
if (mysql_error (ret->dbf)[0])
- {
- LOG_MYSQL (GNUNET_ERROR_TYPE_ERROR,
- "mysql_real_connect", ret);
- return GNUNET_SYSERR;
- }
+ {
+ LOG_MYSQL (GNUNET_ERROR_TYPE_ERROR, "mysql_real_connect", ret);
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
}
@@ -373,19 +376,17 @@
* @return GNUNET_OK on success, GNUNET_SYSERR on error
*/
static int
-run_statement (struct Plugin *plugin,
- const char *statement)
+run_statement (struct Plugin *plugin, const char *statement)
{
if ((NULL == plugin->dbf) && (GNUNET_OK != iopen (plugin)))
return GNUNET_SYSERR;
mysql_query (plugin->dbf, statement);
if (mysql_error (plugin->dbf)[0])
- {
- LOG_MYSQL (GNUNET_ERROR_TYPE_ERROR,
- "mysql_query", plugin);
- iclose (plugin);
- return GNUNET_SYSERR;
- }
+ {
+ LOG_MYSQL (GNUNET_ERROR_TYPE_ERROR, "mysql_query", plugin);
+ iclose (plugin);
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
}
@@ -395,16 +396,13 @@
* @return NULL on error
*/
static struct GNUNET_MysqlStatementHandle *
-prepared_statement_create (struct Plugin *plugin,
- const char *statement)
+prepared_statement_create (struct Plugin *plugin, const char *statement)
{
struct GNUNET_MysqlStatementHandle *ret;
ret = GNUNET_malloc (sizeof (struct GNUNET_MysqlStatementHandle));
ret->query = GNUNET_strdup (statement);
- GNUNET_CONTAINER_DLL_insert (plugin->shead,
- plugin->stail,
- ret);
+ GNUNET_CONTAINER_DLL_insert (plugin->shead, plugin->stail, ret);
return ret;
}
@@ -415,32 +413,27 @@
* @return GNUNET_OK on success
*/
static int
-prepare_statement (struct Plugin *plugin,
- struct GNUNET_MysqlStatementHandle *ret)
+prepare_statement (struct Plugin *plugin,
+ struct GNUNET_MysqlStatementHandle *ret)
{
if (GNUNET_YES == ret->valid)
return GNUNET_OK;
- if ((NULL == plugin->dbf) &&
- (GNUNET_OK != iopen (plugin)))
+ if ((NULL == plugin->dbf) && (GNUNET_OK != iopen (plugin)))
return GNUNET_SYSERR;
ret->statement = mysql_stmt_init (plugin->dbf);
if (ret->statement == NULL)
- {
- iclose (plugin);
- return GNUNET_SYSERR;
- }
- if (mysql_stmt_prepare (ret->statement,
- ret->query,
- strlen (ret->query)))
- {
- LOG_MYSQL (GNUNET_ERROR_TYPE_ERROR,
- "mysql_stmt_prepare",
- plugin);
- mysql_stmt_close (ret->statement);
- ret->statement = NULL;
- iclose (plugin);
- return GNUNET_SYSERR;
- }
+ {
+ iclose (plugin);
+ return GNUNET_SYSERR;
+ }
+ if (mysql_stmt_prepare (ret->statement, ret->query, strlen (ret->query)))
+ {
+ LOG_MYSQL (GNUNET_ERROR_TYPE_ERROR, "mysql_stmt_prepare", plugin);
+ mysql_stmt_close (ret->statement);
+ ret->statement = NULL;
+ iclose (plugin);
+ return GNUNET_SYSERR;
+ }
ret->valid = GNUNET_YES;
return GNUNET_OK;
@@ -458,8 +451,7 @@
*/
static int
init_params (struct Plugin *plugin,
- struct GNUNET_MysqlStatementHandle *s,
- va_list ap)
+ struct GNUNET_MysqlStatementHandle *s, va_list ap)
{
MYSQL_BIND qbind[MAX_PARAM];
unsigned int pc;
@@ -468,68 +460,72 @@
pc = mysql_stmt_param_count (s->statement);
if (pc > MAX_PARAM)
- {
- /* increase internal constant! */
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
+ {
+ /* increase internal constant! */
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
memset (qbind, 0, sizeof (qbind));
off = 0;
ft = 0;
- while ( (pc > 0) && (-1 != (int) (ft = va_arg (ap, enum enum_field_types))) )
+ while ((pc > 0) && (-1 != (int) (ft = va_arg (ap, enum enum_field_types))))
+ {
+ qbind[off].buffer_type = ft;
+ switch (ft)
{
- qbind[off].buffer_type = ft;
- switch (ft)
- {
- case MYSQL_TYPE_FLOAT:
- qbind[off].buffer = va_arg (ap, float *);
- break;
- case MYSQL_TYPE_LONGLONG:
- qbind[off].buffer = va_arg (ap, unsigned long long *);
- qbind[off].is_unsigned = va_arg (ap, int);
- break;
- case MYSQL_TYPE_LONG:
- qbind[off].buffer = va_arg (ap, unsigned int *);
- qbind[off].is_unsigned = va_arg (ap, int);
- break;
- case MYSQL_TYPE_VAR_STRING:
- case MYSQL_TYPE_STRING:
- case MYSQL_TYPE_BLOB:
- qbind[off].buffer = va_arg (ap, void *);
- qbind[off].buffer_length = va_arg (ap, unsigned long);
- qbind[off].length = va_arg (ap, unsigned long *);
- break;
- default:
- /* unsupported type */
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
- pc--;
- off++;
- }
- if (! ( (pc == 0) && (-1 != (int) ft) && (va_arg (ap, int) == -1)) )
- {
+ case MYSQL_TYPE_FLOAT:
+ qbind[off].buffer = va_arg (ap, float *);
+
+ break;
+ case MYSQL_TYPE_LONGLONG:
+ qbind[off].buffer = va_arg (ap, unsigned long long *);
+ qbind[off].is_unsigned = va_arg (ap, int);
+
+ break;
+ case MYSQL_TYPE_LONG:
+ qbind[off].buffer = va_arg (ap, unsigned int *);
+ qbind[off].is_unsigned = va_arg (ap, int);
+
+ break;
+ case MYSQL_TYPE_VAR_STRING:
+ case MYSQL_TYPE_STRING:
+ case MYSQL_TYPE_BLOB:
+ qbind[off].buffer = va_arg (ap, void *);
+ qbind[off].buffer_length = va_arg (ap, unsigned long);
+ qbind[off].length = va_arg (ap, unsigned long *);
+
+ break;
+ default:
+ /* unsupported type */
GNUNET_break (0);
return GNUNET_SYSERR;
}
+ pc--;
+ off++;
+ }
+ if (!((pc == 0) && (-1 != (int) ft) && (va_arg (ap, int) == -1)))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
if (mysql_stmt_bind_param (s->statement, qbind))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("`%s' failed at %s:%d with error: %s\n"),
- "mysql_stmt_bind_param",
- __FILE__, __LINE__, mysql_stmt_error (s->statement));
- iclose (plugin);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("`%s' failed at %s:%d with error: %s\n"),
+ "mysql_stmt_bind_param",
+ __FILE__, __LINE__, mysql_stmt_error (s->statement));
+ iclose (plugin);
+ return GNUNET_SYSERR;
+ }
if (mysql_stmt_execute (s->statement))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("`%s' failed at %s:%d with error: %s\n"),
- "mysql_stmt_execute",
- __FILE__, __LINE__, mysql_stmt_error (s->statement));
- iclose (plugin);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("`%s' failed at %s:%d with error: %s\n"),
+ "mysql_stmt_execute",
+ __FILE__, __LINE__, mysql_stmt_error (s->statement));
+ iclose (plugin);
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
}
@@ -565,13 +561,12 @@
*/
static int
prepared_statement_run_select (struct Plugin *plugin,
- struct GNUNET_MysqlStatementHandle
- *s,
- unsigned int result_size,
- MYSQL_BIND * results,
- GNUNET_MysqlDataProcessor
- processor, void *processor_cls,
- ...)
+ struct GNUNET_MysqlStatementHandle
+ *s,
+ unsigned int result_size,
+ MYSQL_BIND * results,
+ GNUNET_MysqlDataProcessor
+ processor, void *processor_cls, ...)
{
va_list ap;
int ret;
@@ -579,54 +574,54 @@
int total;
if (GNUNET_OK != prepare_statement (plugin, s))
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
va_start (ap, processor_cls);
if (GNUNET_OK != init_params (plugin, s, ap))
- {
- GNUNET_break (0);
- va_end (ap);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_break (0);
+ va_end (ap);
+ return GNUNET_SYSERR;
+ }
va_end (ap);
rsize = mysql_stmt_field_count (s->statement);
if (rsize > result_size)
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
if (mysql_stmt_bind_result (s->statement, results))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("`%s' failed at %s:%d with error: %s\n"),
+ "mysql_stmt_bind_result",
+ __FILE__, __LINE__, mysql_stmt_error (s->statement));
+ iclose (plugin);
+ return GNUNET_SYSERR;
+ }
+
+ total = 0;
+ while (1)
+ {
+ ret = mysql_stmt_fetch (s->statement);
+ if (ret == MYSQL_NO_DATA)
+ break;
+ if (ret != 0)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("`%s' failed at %s:%d with error: %s\n"),
- "mysql_stmt_bind_result",
- __FILE__, __LINE__, mysql_stmt_error (s->statement));
+ _("`%s' failed at %s:%d with error: %s\n"),
+ "mysql_stmt_fetch",
+ __FILE__, __LINE__, mysql_stmt_error (s->statement));
iclose (plugin);
return GNUNET_SYSERR;
}
-
- total = 0;
- while (1)
- {
- ret = mysql_stmt_fetch (s->statement);
- if (ret == MYSQL_NO_DATA)
+ if (processor != NULL)
+ if (GNUNET_OK != processor (processor_cls, rsize, results))
break;
- if (ret != 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("`%s' failed at %s:%d with error: %s\n"),
- "mysql_stmt_fetch",
- __FILE__, __LINE__, mysql_stmt_error (s->statement));
- iclose (plugin);
- return GNUNET_SYSERR;
- }
- if (processor != NULL)
- if (GNUNET_OK != processor (processor_cls, rsize, results))
- break;
- total++;
- }
+ total++;
+ }
mysql_stmt_reset (s->statement);
return total;
}
@@ -648,8 +643,8 @@
*/
static int
prepared_statement_run (struct Plugin *plugin,
- struct GNUNET_MysqlStatementHandle *s,
- unsigned long long *insert_id, ...)
+ struct GNUNET_MysqlStatementHandle *s,
+ unsigned long long *insert_id, ...)
{
va_list ap;
int affected;
@@ -658,10 +653,10 @@
return GNUNET_SYSERR;
va_start (ap, insert_id);
if (GNUNET_OK != init_params (plugin, s, ap))
- {
- va_end (ap);
- return GNUNET_SYSERR;
- }
+ {
+ va_end (ap);
+ return GNUNET_SYSERR;
+ }
va_end (ap);
affected = mysql_stmt_affected_rows (s->statement);
if (NULL != insert_id)
@@ -718,13 +713,13 @@
* @param discard_time when to discard the value in any case
* @return 0 on error, number of bytes used otherwise
*/
-static size_t
+static size_t
mysql_plugin_put (void *cls,
- const GNUNET_HashCode * key,
- size_t size,
- const char *data,
- enum GNUNET_BLOCK_Type type,
- struct GNUNET_TIME_Absolute discard_time)
+ const GNUNET_HashCode * key,
+ size_t size,
+ const char *data,
+ enum GNUNET_BLOCK_Type type,
+ struct GNUNET_TIME_Absolute discard_time)
{
struct Plugin *plugin = cls;
struct GNUNET_TIME_Absolute now;
@@ -751,25 +746,23 @@
v_discard_time = (unsigned long long) discard_time.abs_value;
if (GNUNET_OK ==
prepared_statement_run (plugin,
- plugin->update_value,
- NULL,
- MYSQL_TYPE_LONGLONG,
- &v_now,
- GNUNET_YES,
- MYSQL_TYPE_LONGLONG,
- &v_discard_time,
- GNUNET_YES,
- MYSQL_TYPE_BLOB,
- key,
- sizeof (GNUNET_HashCode),
- &k_length,
- MYSQL_TYPE_BLOB,
- &vhash,
- sizeof (GNUNET_HashCode),
- &h_length,
- MYSQL_TYPE_LONG,
- &v_type,
- GNUNET_YES, -1))
+ plugin->update_value,
+ NULL,
+ MYSQL_TYPE_LONGLONG,
+ &v_now,
+ GNUNET_YES,
+ MYSQL_TYPE_LONGLONG,
+ &v_discard_time,
+ GNUNET_YES,
+ MYSQL_TYPE_BLOB,
+ key,
+ sizeof (GNUNET_HashCode),
+ &k_length,
+ MYSQL_TYPE_BLOB,
+ &vhash,
+ sizeof (GNUNET_HashCode),
+ &h_length,
+ MYSQL_TYPE_LONG, &v_type, GNUNET_YES, -1))
return GNUNET_OK;
/* now try INSERT */
@@ -778,34 +771,33 @@
v_length = size;
if (GNUNET_OK !=
(ret = prepared_statement_run (plugin,
- plugin->insert_value,
- NULL,
- MYSQL_TYPE_LONG,
- &type,
- GNUNET_YES,
- MYSQL_TYPE_LONGLONG,
- &v_now,
- GNUNET_YES,
- MYSQL_TYPE_LONGLONG,
- &v_discard_time,
- GNUNET_YES,
- MYSQL_TYPE_BLOB,
- key,
- sizeof (GNUNET_HashCode),
- &k_length,
- MYSQL_TYPE_BLOB,
- &vhash,
- sizeof (GNUNET_HashCode),
- &h_length,
- MYSQL_TYPE_BLOB,
- data,
- (unsigned long) size,
- &v_length, -1)))
- {
- if (ret == GNUNET_SYSERR)
- itable (plugin);
- return GNUNET_SYSERR;
- }
+ plugin->insert_value,
+ NULL,
+ MYSQL_TYPE_LONG,
+ &type,
+ GNUNET_YES,
+ MYSQL_TYPE_LONGLONG,
+ &v_now,
+ GNUNET_YES,
+ MYSQL_TYPE_LONGLONG,
+ &v_discard_time,
+ GNUNET_YES,
+ MYSQL_TYPE_BLOB,
+ key,
+ sizeof (GNUNET_HashCode),
+ &k_length,
+ MYSQL_TYPE_BLOB,
+ &vhash,
+ sizeof (GNUNET_HashCode),
+ &h_length,
+ MYSQL_TYPE_BLOB,
+ data,
+ (unsigned long) size, &v_length, -1)))
+ {
+ if (ret == GNUNET_SYSERR)
+ itable (plugin);
+ return GNUNET_SYSERR;
+ }
return size + OVERHEAD;
}
@@ -828,12 +820,11 @@
* @param iter_cls closure for iter
* @return the number of results found
*/
-static unsigned int
+static unsigned int
mysql_plugin_get (void *cls,
- const GNUNET_HashCode * key,
- enum GNUNET_BLOCK_Type type,
- GNUNET_DATACACHE_Iterator iter,
- void *iter_cls)
+ const GNUNET_HashCode * key,
+ enum GNUNET_BLOCK_Type type,
+ GNUNET_DATACACHE_Iterator iter, void *iter_cls)
{
struct Plugin *plugin = cls;
MYSQL_BIND rbind[3];
@@ -862,79 +853,72 @@
v_now = (unsigned long long) now.abs_value;
if ((GNUNET_OK !=
(ret = prepared_statement_run_select (plugin,
- plugin->count_value,
- 1,
- rbind,
- return_ok,
- NULL,
- MYSQL_TYPE_BLOB,
- key,
- sizeof
- (GNUNET_HashCode),
- &h_length,
- MYSQL_TYPE_LONG,
- &v_type, GNUNET_YES,
- MYSQL_TYPE_LONGLONG,
- &v_now, GNUNET_YES,
- -1)))
- || (-1 == total))
- {
- if (ret == GNUNET_SYSERR)
- itable (plugin);
- return GNUNET_SYSERR;
- }
+ plugin->count_value,
+ 1,
+ rbind,
+ return_ok,
+ NULL,
+ MYSQL_TYPE_BLOB,
+ key,
+ sizeof
+ (GNUNET_HashCode),
+ &h_length,
+ MYSQL_TYPE_LONG,
+ &v_type, GNUNET_YES,
+ MYSQL_TYPE_LONGLONG,
+ &v_now, GNUNET_YES,
+ -1))) || (-1 == total))
+ {
+ if (ret == GNUNET_SYSERR)
+ itable (plugin);
+ return GNUNET_SYSERR;
+ }
if ((iter == NULL) || (total == 0))
return (int) total;
off = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, total);
cnt = 0;
while (cnt < total)
+ {
+ memset (rbind, 0, sizeof (rbind));
+ rbind[0].buffer_type = MYSQL_TYPE_BLOB;
+ rbind[0].buffer_length = sizeof (buffer);
+ rbind[0].length = &v_length;
+ rbind[0].buffer = buffer;
+ rbind[1].buffer_type = MYSQL_TYPE_LONGLONG;
+ rbind[1].is_unsigned = 1;
+ rbind[1].buffer = &v_expire;
+ off = (off + 1) % total;
+ if (GNUNET_OK !=
+ (ret = prepared_statement_run_select (plugin,
+ plugin->select_value,
+ 2,
+ rbind,
+ return_ok,
+ NULL,
+ MYSQL_TYPE_BLOB,
+ key,
+ sizeof
+ (GNUNET_HashCode),
+ &h_length,
+ MYSQL_TYPE_LONG,
+ &v_type,
+ GNUNET_YES,
+ MYSQL_TYPE_LONGLONG,
+ &v_now,
+ GNUNET_YES,
+ MYSQL_TYPE_LONG,
+ &off, GNUNET_YES, -1)))
{
- memset (rbind, 0, sizeof (rbind));
- rbind[0].buffer_type = MYSQL_TYPE_BLOB;
- rbind[0].buffer_length = sizeof (buffer);
- rbind[0].length = &v_length;
- rbind[0].buffer = buffer;
- rbind[1].buffer_type = MYSQL_TYPE_LONGLONG;
- rbind[1].is_unsigned = 1;
- rbind[1].buffer = &v_expire;
- off = (off + 1) % total;
- if (GNUNET_OK !=
- (ret = prepared_statement_run_select (plugin,
- plugin->select_value,
- 2,
- rbind,
- return_ok,
- NULL,
- MYSQL_TYPE_BLOB,
- key,
- sizeof
- (GNUNET_HashCode),
- &h_length,
- MYSQL_TYPE_LONG,
- &v_type,
- GNUNET_YES,
- MYSQL_TYPE_LONGLONG,
- &v_now,
- GNUNET_YES,
- MYSQL_TYPE_LONG,
- &off,
- GNUNET_YES,
- -1)))
- {
- if (ret == GNUNET_SYSERR)
- itable (plugin);
- return GNUNET_SYSERR;
- }
- cnt++;
- expire.abs_value = v_expire;
- if (GNUNET_OK != iter (iter_cls,
- expire,
- key,
- v_length, buffer,
- type))
- break;
+ if (ret == GNUNET_SYSERR)
+ itable (plugin);
+ return GNUNET_SYSERR;
}
+ cnt++;
+ expire.abs_value = v_expire;
+ if (GNUNET_OK != iter (iter_cls, expire, key, v_length, buffer, type))
+ break;
+ }
return cnt;
}
@@ -945,8 +929,8 @@
*
* @param cls closure (our "struct Plugin")
* @return GNUNET_OK on success, GNUNET_SYSERR on error
- */
-static int
+ */
+static int
mysql_plugin_del (void *cls)
{
struct Plugin *plugin = cls;
@@ -982,40 +966,37 @@
rbind[3].buffer = buffer;
if ((GNUNET_OK !=
(ret = prepared_statement_run_select (plugin,
- plugin->select_old_value,
- 4,
- rbind,
- return_ok,
- NULL,
- -1))) ||
+ plugin->select_old_value,
+ 4,
+ rbind,
+ return_ok,
+ NULL,
+ -1))) ||
(GNUNET_OK !=
(ret = prepared_statement_run (plugin,
- plugin->delete_value,
- NULL,
- MYSQL_TYPE_BLOB,
- &v_key,
- sizeof (GNUNET_HashCode),
- &k_length,
- MYSQL_TYPE_BLOB,
- &vhash,
- sizeof (GNUNET_HashCode),
- &h_length,
- MYSQL_TYPE_LONG,
- &v_type,
- GNUNET_YES,
- MYSQL_TYPE_BLOB,
- buffer,
- (unsigned long)
- sizeof (buffer),
- &v_length, -1))))
- {
- if (ret == GNUNET_SYSERR)
- itable (plugin);
- return GNUNET_SYSERR;
- }
- plugin->env->delete_notify (plugin->env->cls,
- &v_key,
- v_length + OVERHEAD);
+ plugin->delete_value,
+ NULL,
+ MYSQL_TYPE_BLOB,
+ &v_key,
+ sizeof (GNUNET_HashCode),
+ &k_length,
+ MYSQL_TYPE_BLOB,
+ &vhash,
+ sizeof (GNUNET_HashCode),
+ &h_length,
+ MYSQL_TYPE_LONG,
+ &v_type,
+ GNUNET_YES,
+ MYSQL_TYPE_BLOB,
+ buffer,
+ (unsigned long)
+ sizeof (buffer), &v_length, -1))))
+ {
+ if (ret == GNUNET_SYSERR)
+ itable (plugin);
+ return GNUNET_SYSERR;
+ }
+ plugin->env->delete_notify (plugin->env->cls, &v_key, v_length + OVERHEAD);
return GNUNET_OK;
}
@@ -1037,21 +1018,19 @@
plugin = GNUNET_malloc (sizeof (struct Plugin));
plugin->env = env;
plugin->cnffile = get_my_cnf_path (env->cfg);
- if (GNUNET_OK !=
- iopen (plugin))
- {
- GNUNET_free_non_null (plugin->cnffile);
- GNUNET_free (plugin);
- return NULL;
- }
- if (GNUNET_OK !=
- itable (plugin))
- {
- iclose (plugin);
- GNUNET_free_non_null (plugin->cnffile);
- GNUNET_free (plugin);
- return NULL;
- }
+ if (GNUNET_OK != iopen (plugin))
+ {
+ GNUNET_free_non_null (plugin->cnffile);
+ GNUNET_free (plugin);
+ return NULL;
+ }
+ if (GNUNET_OK != itable (plugin))
+ {
+ iclose (plugin);
+ GNUNET_free_non_null (plugin->cnffile);
+ GNUNET_free (plugin);
+ return NULL;
+ }
api = GNUNET_malloc (sizeof (struct GNUNET_DATACACHE_PluginFunctions));
api->cls = plugin;
api->get = &mysql_plugin_get;
Modified: gnunet/src/datacache/plugin_datacache_postgres.c
===================================================================
--- gnunet/src/datacache/plugin_datacache_postgres.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/datacache/plugin_datacache_postgres.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -38,7 +38,7 @@
/**
* Context for all functions in this plugin.
*/
-struct Plugin
+struct Plugin
{
/**
* Our execution environment.
@@ -62,27 +62,28 @@
*/
static int
check_result (struct Plugin *plugin,
- PGresult * ret,
+ PGresult * ret,
int expected_status,
const char *command, const char *args, int line)
{
if (ret == NULL)
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "datastore-postgres",
- "Postgres failed to allocate result for `%s:%s' at %d\n",
- command, args, line);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "datastore-postgres",
+ "Postgres failed to allocate result for `%s:%s' at %d\n",
+ command, args, line);
+ return GNUNET_SYSERR;
+ }
if (PQresultStatus (ret) != expected_status)
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "datastore-postgres",
- _("`%s:%s' failed at %s:%d with error: %s"),
- command, args, __FILE__, line, PQerrorMessage
(plugin->dbh));
- PQclear (ret);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "datastore-postgres",
+ _("`%s:%s' failed at %s:%d with error: %s"),
+ command, args, __FILE__, line,
+ PQerrorMessage (plugin->dbh));
+ PQclear (ret);
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
}
@@ -91,14 +92,13 @@
* Run simple SQL statement (without results).
*/
static int
-pq_exec (struct Plugin *plugin,
- const char *sql, int line)
+pq_exec (struct Plugin *plugin, const char *sql, int line)
{
PGresult *ret;
+
ret = PQexec (plugin->dbh, sql);
if (GNUNET_OK != check_result (plugin,
- ret,
- PGRES_COMMAND_OK, "PQexec", sql, line))
+ ret, PGRES_COMMAND_OK, "PQexec", sql, line))
return GNUNET_SYSERR;
PQclear (ret);
return GNUNET_OK;
@@ -110,13 +110,13 @@
*/
static int
pq_prepare (struct Plugin *plugin,
- const char *name, const char *sql, int nparms, int line)
+ const char *name, const char *sql, int nparms, int line)
{
PGresult *ret;
+
ret = PQprepare (plugin->dbh, name, sql, nparms, NULL);
if (GNUNET_OK !=
- check_result (plugin,
- ret, PGRES_COMMAND_OK, "PQprepare", sql, line))
+ check_result (plugin, ret, PGRES_COMMAND_OK, "PQprepare", sql, line))
return GNUNET_SYSERR;
PQclear (ret);
return GNUNET_OK;
@@ -134,128 +134,121 @@
PGresult *ret;
/* Open database and precompile statements */
- if (GNUNET_OK !=
+ if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
- "datacache-postgres",
- "CONFIG",
- &conninfo))
+ "datacache-postgres",
+ "CONFIG", &conninfo))
conninfo = NULL;
plugin->dbh = PQconnectdb (conninfo == NULL ? "" : conninfo);
GNUNET_free_non_null (conninfo);
if (NULL == plugin->dbh)
- {
- /* FIXME: warn about out-of-memory? */
- return GNUNET_SYSERR;
- }
+ {
+ /* FIXME: warn about out-of-memory? */
+ return GNUNET_SYSERR;
+ }
if (PQstatus (plugin->dbh) != CONNECTION_OK)
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
- "datacache-postgres",
- _("Unable to initialize Postgres: %s"),
- PQerrorMessage (plugin->dbh));
- PQfinish (plugin->dbh);
- plugin->dbh = NULL;
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
+ "datacache-postgres",
+ _("Unable to initialize Postgres: %s"),
+ PQerrorMessage (plugin->dbh));
+ PQfinish (plugin->dbh);
+ plugin->dbh = NULL;
+ return GNUNET_SYSERR;
+ }
ret = PQexec (plugin->dbh,
"CREATE TEMPORARY TABLE gn090dc ("
" type INTEGER NOT NULL DEFAULT 0,"
" discard_time BIGINT NOT NULL DEFAULT 0,"
" key BYTEA NOT NULL DEFAULT '',"
" value BYTEA NOT NULL DEFAULT '')" "WITH OIDS");
- if ( (ret == NULL) ||
- ( (PQresultStatus (ret) != PGRES_COMMAND_OK) &&
- (0 != strcmp ("42P07", /* duplicate table */
- PQresultErrorField
- (ret,
- PG_DIAG_SQLSTATE)))))
+ if ((ret == NULL) || ((PQresultStatus (ret) != PGRES_COMMAND_OK) && (0 !=
strcmp ("42P07", /* duplicate table */
+
PQresultErrorField
+
(ret,
+
PG_DIAG_SQLSTATE)))))
+ {
+ (void) check_result (plugin,
+ ret, PGRES_COMMAND_OK, "CREATE TABLE", "gn090dc",
+ __LINE__);
+ PQfinish (plugin->dbh);
+ plugin->dbh = NULL;
+ return GNUNET_SYSERR;
+ }
+ if (PQresultStatus (ret) == PGRES_COMMAND_OK)
+ {
+ if ((GNUNET_OK !=
+ pq_exec (plugin, "CREATE INDEX idx_key ON gn090dc (key)", __LINE__))
||
+ (GNUNET_OK !=
+ pq_exec (plugin, "CREATE INDEX idx_dt ON gn090dc (discard_time)",
+ __LINE__)))
{
- (void) check_result (plugin,
- ret, PGRES_COMMAND_OK, "CREATE TABLE", "gn090dc",
__LINE__);
+ PQclear (ret);
PQfinish (plugin->dbh);
plugin->dbh = NULL;
return GNUNET_SYSERR;
}
- if (PQresultStatus (ret) == PGRES_COMMAND_OK)
- {
- if ((GNUNET_OK !=
- pq_exec (plugin, "CREATE INDEX idx_key ON gn090dc (key)",
__LINE__)) ||
- (GNUNET_OK !=
- pq_exec (plugin, "CREATE INDEX idx_dt ON gn090dc (discard_time)",
- __LINE__)) )
- {
- PQclear (ret);
- PQfinish (plugin->dbh);
- plugin->dbh = NULL;
- return GNUNET_SYSERR;
- }
- }
+ }
PQclear (ret);
#if 1
ret = PQexec (plugin->dbh,
"ALTER TABLE gn090dc ALTER value SET STORAGE EXTERNAL");
- if (GNUNET_OK !=
+ if (GNUNET_OK !=
check_result (plugin,
- ret, PGRES_COMMAND_OK,
- "ALTER TABLE", "gn090dc", __LINE__))
- {
- PQfinish (plugin->dbh);
- plugin->dbh = NULL;
- return GNUNET_SYSERR;
- }
+ ret, PGRES_COMMAND_OK, "ALTER TABLE", "gn090dc", __LINE__))
+ {
+ PQfinish (plugin->dbh);
+ plugin->dbh = NULL;
+ return GNUNET_SYSERR;
+ }
PQclear (ret);
- ret = PQexec (plugin->dbh,
- "ALTER TABLE gn090dc ALTER key SET STORAGE PLAIN");
+ ret = PQexec (plugin->dbh, "ALTER TABLE gn090dc ALTER key SET STORAGE
PLAIN");
if (GNUNET_OK !=
check_result (plugin,
- ret, PGRES_COMMAND_OK,
- "ALTER TABLE", "gn090dc", __LINE__))
- {
- PQfinish (plugin->dbh);
- plugin->dbh = NULL;
- return GNUNET_SYSERR;
- }
+ ret, PGRES_COMMAND_OK, "ALTER TABLE", "gn090dc", __LINE__))
+ {
+ PQfinish (plugin->dbh);
+ plugin->dbh = NULL;
+ return GNUNET_SYSERR;
+ }
PQclear (ret);
#endif
if ((GNUNET_OK !=
pq_prepare (plugin,
- "getkt",
+ "getkt",
"SELECT discard_time,type,value FROM gn090dc "
"WHERE key=$1 AND type=$2 ",
2,
__LINE__)) ||
(GNUNET_OK !=
pq_prepare (plugin,
- "getk",
+ "getk",
"SELECT discard_time,type,value FROM gn090dc "
"WHERE key=$1",
1,
__LINE__)) ||
(GNUNET_OK !=
pq_prepare (plugin,
- "getm",
+ "getm",
"SELECT length(value),oid,key FROM gn090dc "
"ORDER BY discard_time ASC LIMIT 1",
0,
__LINE__)) ||
(GNUNET_OK !=
pq_prepare (plugin,
- "delrow",
+ "delrow",
"DELETE FROM gn090dc WHERE oid=$1",
1,
__LINE__)) ||
(GNUNET_OK !=
pq_prepare (plugin,
- "put",
+ "put",
"INSERT INTO gn090dc (type, discard_time, key, value) "
- "VALUES ($1, $2, $3, $4)",
- 4,
- __LINE__)) )
- {
- PQfinish (plugin->dbh);
- plugin->dbh = NULL;
- return GNUNET_SYSERR;
- }
+ "VALUES ($1, $2, $3, $4)", 4, __LINE__)))
+ {
+ PQfinish (plugin->dbh);
+ plugin->dbh = NULL;
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
}
@@ -267,8 +260,7 @@
* @return GNUNET_OK on success
*/
static int
-delete_by_rowid (struct Plugin *plugin,
- uint32_t rowid)
+delete_by_rowid (struct Plugin *plugin, uint32_t rowid)
{
uint32_t brow = htonl (rowid);
const char *paramValues[] = { (const char *) &brow };
@@ -281,11 +273,11 @@
1, paramValues, paramLengths, paramFormats, 1);
if (GNUNET_OK !=
check_result (plugin,
- ret, PGRES_COMMAND_OK, "PQexecPrepared", "delrow",
+ ret, PGRES_COMMAND_OK, "PQexecPrepared", "delrow",
__LINE__))
- {
- return GNUNET_SYSERR;
- }
+ {
+ return GNUNET_SYSERR;
+ }
PQclear (ret);
return GNUNET_OK;
}
@@ -302,18 +294,19 @@
* @param discard_time when to discard the value in any case
* @return 0 on error, number of bytes used otherwise
*/
-static size_t
+static size_t
postgres_plugin_put (void *cls,
- const GNUNET_HashCode * key,
- size_t size,
- const char *data,
- enum GNUNET_BLOCK_Type type,
- struct GNUNET_TIME_Absolute discard_time)
+ const GNUNET_HashCode * key,
+ size_t size,
+ const char *data,
+ enum GNUNET_BLOCK_Type type,
+ struct GNUNET_TIME_Absolute discard_time)
{
struct Plugin *plugin = cls;
PGresult *ret;
uint32_t btype = htonl (type);
uint64_t bexpi = GNUNET_TIME_absolute_hton (discard_time).abs_value__;
+
const char *paramValues[] = {
(const char *) &btype,
(const char *) &bexpi,
@@ -350,15 +343,15 @@
* @param iter_cls closure for iter
* @return the number of results found
*/
-static unsigned int
+static unsigned int
postgres_plugin_get (void *cls,
- const GNUNET_HashCode * key,
- enum GNUNET_BLOCK_Type type,
- GNUNET_DATACACHE_Iterator iter,
- void *iter_cls)
+ const GNUNET_HashCode * key,
+ enum GNUNET_BLOCK_Type type,
+ GNUNET_DATACACHE_Iterator iter, void *iter_cls)
{
struct Plugin *plugin = cls;
uint32_t btype = htonl (type);
+
const char *paramValues[] = {
(const char *) key,
(const char *) &btype,
@@ -376,80 +369,73 @@
cnt = 0;
res = PQexecPrepared (plugin->dbh,
- (type == 0) ? "getk" : "getkt",
- (type == 0) ? 1 : 2,
- paramValues,
- paramLengths,
- paramFormats,
- 1);
+ (type == 0) ? "getk" : "getkt",
+ (type == 0) ? 1 : 2,
+ paramValues, paramLengths, paramFormats, 1);
if (GNUNET_OK != check_result (plugin,
- res,
- PGRES_TUPLES_OK,
- "PQexecPrepared",
- (type == 0) ? "getk" : "getkt",
- __LINE__))
- {
+ res,
+ PGRES_TUPLES_OK,
+ "PQexecPrepared",
+ (type == 0) ? "getk" : "getkt", __LINE__))
+ {
#if DEBUG_POSTGRES
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "datacache-postgres",
- "Ending iteration (postgres error)\n");
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ "datacache-postgres",
+ "Ending iteration (postgres error)\n");
#endif
- return 0;
- }
+ return 0;
+ }
if (0 == (cnt = PQntuples (res)))
- {
- /* no result */
+ {
+ /* no result */
#if DEBUG_POSTGRES
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "datacache-postgres",
- "Ending iteration (no more results)\n");
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ "datacache-postgres",
+ "Ending iteration (no more results)\n");
#endif
- PQclear (res);
- return 0;
- }
+ PQclear (res);
+ return 0;
+ }
if (iter == NULL)
+ {
+ PQclear (res);
+ return cnt;
+ }
+ if ((3 != PQnfields (res)) ||
+ (sizeof (uint64_t) != PQfsize (res, 0)) ||
+ (sizeof (uint32_t) != PQfsize (res, 1)))
+ {
+ GNUNET_break (0);
+ PQclear (res);
+ return 0;
+ }
+ for (i = 0; i < cnt; i++)
+ {
+ expiration_time.abs_value =
+ GNUNET_ntohll (*(uint64_t *) PQgetvalue (res, i, 0));
+ type = ntohl (*(uint32_t *) PQgetvalue (res, i, 1));
+ size = PQgetlength (res, i, 2);
+#if DEBUG_POSTGRES
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ "datacache-postgres",
+ "Found result of size %u bytes and type %u in database\n",
+ (unsigned int) size, (unsigned int) type);
+#endif
+ if (GNUNET_SYSERR ==
+ iter (iter_cls,
+ expiration_time,
+ key, size, PQgetvalue (res, i, 2), (enum GNUNET_BLOCK_Type)
type))
{
- PQclear (res);
- return cnt;
- }
- if ( (3 != PQnfields (res)) ||
- (sizeof (uint64_t) != PQfsize (res, 0)) ||
- (sizeof (uint32_t) != PQfsize (res, 1)))
- {
- GNUNET_break (0);
- PQclear (res);
- return 0;
- }
- for (i=0;i<cnt;i++)
- {
- expiration_time.abs_value = GNUNET_ntohll (*(uint64_t *) PQgetvalue
(res, i, 0));
- type = ntohl (*(uint32_t *) PQgetvalue (res, i, 1));
- size = PQgetlength (res, i, 2);
#if DEBUG_POSTGRES
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "datacache-postgres",
- "Found result of size %u bytes and type %u in
database\n",
- (unsigned int) size,
- (unsigned int) type);
+ "datacache-postgres",
+ "Ending iteration (client error)\n");
#endif
- if (GNUNET_SYSERR ==
- iter (iter_cls,
- expiration_time,
- key,
- size,
- PQgetvalue (res, i, 2),
- (enum GNUNET_BLOCK_Type) type))
- {
-#if DEBUG_POSTGRES
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "datacache-postgres",
- "Ending iteration (client error)\n");
-#endif
- PQclear (res);
- return cnt;
- }
- }
+ PQclear (res);
+ return cnt;
+ }
+ }
PQclear (res);
return cnt;
}
@@ -461,8 +447,8 @@
*
* @param cls closure (our "struct Plugin")
* @return GNUNET_OK on success, GNUNET_SYSERR on error
- */
-static int
+ */
+static int
postgres_plugin_del (void *cls)
{
struct Plugin *plugin = cls;
@@ -471,55 +457,46 @@
GNUNET_HashCode key;
PGresult *res;
- res = PQexecPrepared (plugin->dbh,
- "getm",
- 0, NULL, NULL, NULL,
- 1);
+ res = PQexecPrepared (plugin->dbh, "getm", 0, NULL, NULL, NULL, 1);
if (GNUNET_OK != check_result (plugin,
- res,
- PGRES_TUPLES_OK,
- "PQexecPrepared",
- "getm",
- __LINE__))
- {
+ res,
+ PGRES_TUPLES_OK,
+ "PQexecPrepared", "getm", __LINE__))
+ {
#if DEBUG_POSTGRES
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "datacache-postgres",
- "Ending iteration (postgres error)\n");
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ "datacache-postgres",
+ "Ending iteration (postgres error)\n");
#endif
- return 0;
- }
+ return 0;
+ }
if (0 == PQntuples (res))
- {
- /* no result */
+ {
+ /* no result */
#if DEBUG_POSTGRES
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "datacache-postgres",
- "Ending iteration (no more results)\n");
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ "datacache-postgres",
+ "Ending iteration (no more results)\n");
#endif
- PQclear (res);
- return GNUNET_SYSERR;
- }
- if ( (3 != PQnfields (res)) ||
- (sizeof (size) != PQfsize (res, 0)) ||
- (sizeof (oid) != PQfsize (res, 1)) ||
- (sizeof (GNUNET_HashCode) != PQgetlength (res, 0, 2)) )
- {
- GNUNET_break (0);
- PQclear (res);
- return 0;
- }
+ PQclear (res);
+ return GNUNET_SYSERR;
+ }
+ if ((3 != PQnfields (res)) ||
+ (sizeof (size) != PQfsize (res, 0)) ||
+ (sizeof (oid) != PQfsize (res, 1)) ||
+ (sizeof (GNUNET_HashCode) != PQgetlength (res, 0, 2)))
+ {
+ GNUNET_break (0);
+ PQclear (res);
+ return 0;
+ }
size = ntohl (*(uint32_t *) PQgetvalue (res, 0, 0));
oid = ntohl (*(uint32_t *) PQgetvalue (res, 0, 1));
- memcpy (&key,
- PQgetvalue (res, 0, 2),
- sizeof (GNUNET_HashCode));
+ memcpy (&key, PQgetvalue (res, 0, 2), sizeof (GNUNET_HashCode));
PQclear (res);
if (GNUNET_OK != delete_by_rowid (plugin, oid))
return GNUNET_SYSERR;
- plugin->env->delete_notify (plugin->env->cls,
- &key,
- size + OVERHEAD);
+ plugin->env->delete_notify (plugin->env->cls, &key, size + OVERHEAD);
return GNUNET_OK;
}
@@ -540,12 +517,11 @@
plugin = GNUNET_malloc (sizeof (struct Plugin));
plugin->env = env;
- if (GNUNET_OK !=
- init_connection (plugin))
- {
- GNUNET_free (plugin);
- return NULL;
- }
+ if (GNUNET_OK != init_connection (plugin))
+ {
+ GNUNET_free (plugin);
+ return NULL;
+ }
api = GNUNET_malloc (sizeof (struct GNUNET_DATACACHE_PluginFunctions));
api->cls = plugin;
@@ -553,8 +529,7 @@
api->put = &postgres_plugin_put;
api->del = &postgres_plugin_del;
GNUNET_log_from (GNUNET_ERROR_TYPE_INFO,
- "datacache-postgres",
- _("Postgres datacache running\n"));
+ "datacache-postgres", _("Postgres datacache running\n"));
return api;
}
@@ -580,4 +555,3 @@
/* end of plugin_datacache_postgres.c */
-
Modified: gnunet/src/datacache/plugin_datacache_sqlite.c
===================================================================
--- gnunet/src/datacache/plugin_datacache_sqlite.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/datacache/plugin_datacache_sqlite.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -39,7 +39,7 @@
/**
* Context for all functions in this plugin.
*/
-struct Plugin
+struct Plugin
{
/**
* Our execution environment.
@@ -53,7 +53,7 @@
/**
* Filename used for the DB.
- */
+ */
char *fn;
};
@@ -77,9 +77,9 @@
sqlite3_stmt ** ppStmt)
{ /* OUT: Statement handle */
char *dummy;
+
return sqlite3_prepare (dbh,
- zSql,
- strlen (zSql), ppStmt, (const char **) &dummy);
+ zSql, strlen (zSql), ppStmt, (const char **) &dummy);
}
@@ -94,13 +94,13 @@
* @param discard_time when to discard the value in any case
* @return 0 on error, number of bytes used otherwise
*/
-static size_t
+static size_t
sqlite_plugin_put (void *cls,
- const GNUNET_HashCode * key,
- size_t size,
- const char *data,
- enum GNUNET_BLOCK_Type type,
- struct GNUNET_TIME_Absolute discard_time)
+ const GNUNET_HashCode * key,
+ size_t size,
+ const char *data,
+ enum GNUNET_BLOCK_Type type,
+ struct GNUNET_TIME_Absolute discard_time)
{
struct Plugin *plugin = cls;
sqlite3_stmt *stmt;
@@ -108,50 +108,50 @@
#if DEBUG_DATACACHE_SQLITE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Processing `%s' of %u bytes with key `%4s' and expiration
%llums\n",
- "PUT",
- (unsigned int) size,
- GNUNET_h2s (key),
- (unsigned long long) GNUNET_TIME_absolute_get_remaining
(discard_time).rel_value);
+ "Processing `%s' of %u bytes with key `%4s' and expiration
%llums\n",
+ "PUT",
+ (unsigned int) size,
+ GNUNET_h2s (key),
+ (unsigned long long)
+ GNUNET_TIME_absolute_get_remaining (discard_time).rel_value);
#endif
dval = (int64_t) discard_time.abs_value;
- if (dval < 0)
- dval = INT64_MAX;
+ if (dval < 0)
+ dval = INT64_MAX;
if (sq_prepare (plugin->dbh,
"INSERT INTO ds090 "
"(type, expire, key, value) "
"VALUES (?, ?, ?, ?)", &stmt) != SQLITE_OK)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- _("`%s' failed at %s:%d with error: %s\n"),
- "sq_prepare", __FILE__, __LINE__,
- sqlite3_errmsg (plugin->dbh));
- return 0;
- }
- if ( (SQLITE_OK != sqlite3_bind_int (stmt, 1, type)) ||
- (SQLITE_OK != sqlite3_bind_int64 (stmt, 2, dval)) ||
- (SQLITE_OK != sqlite3_bind_blob (stmt, 3, key, sizeof (GNUNET_HashCode),
- SQLITE_TRANSIENT)) ||
- (SQLITE_OK != sqlite3_bind_blob (stmt, 4, data, size,
SQLITE_TRANSIENT)))
- {
- LOG_SQLITE (plugin->dbh,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "sqlite3_bind_xxx");
- sqlite3_finalize (stmt);
- return 0;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ _("`%s' failed at %s:%d with error: %s\n"),
+ "sq_prepare", __FILE__, __LINE__, sqlite3_errmsg
(plugin->dbh));
+ return 0;
+ }
+ if ((SQLITE_OK != sqlite3_bind_int (stmt, 1, type)) ||
+ (SQLITE_OK != sqlite3_bind_int64 (stmt, 2, dval)) ||
+ (SQLITE_OK != sqlite3_bind_blob (stmt, 3, key, sizeof (GNUNET_HashCode),
+ SQLITE_TRANSIENT)) ||
+ (SQLITE_OK != sqlite3_bind_blob (stmt, 4, data, size, SQLITE_TRANSIENT)))
+ {
+ LOG_SQLITE (plugin->dbh,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_bind_xxx");
+ sqlite3_finalize (stmt);
+ return 0;
+ }
if (SQLITE_DONE != sqlite3_step (stmt))
- {
- LOG_SQLITE (plugin->dbh,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "sqlite3_step");
- sqlite3_finalize (stmt);
- return 0;
- }
+ {
+ LOG_SQLITE (plugin->dbh,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_step");
+ sqlite3_finalize (stmt);
+ return 0;
+ }
if (SQLITE_OK != sqlite3_finalize (stmt))
LOG_SQLITE (plugin->dbh,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "sqlite3_finalize");
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_finalize");
return size + OVERHEAD;
}
@@ -167,12 +167,11 @@
* @param iter_cls closure for iter
* @return the number of results found
*/
-static unsigned int
+static unsigned int
sqlite_plugin_get (void *cls,
- const GNUNET_HashCode * key,
- enum GNUNET_BLOCK_Type type,
- GNUNET_DATACACHE_Iterator iter,
- void *iter_cls)
+ const GNUNET_HashCode * key,
+ enum GNUNET_BLOCK_Type type,
+ GNUNET_DATACACHE_Iterator iter, void *iter_cls)
{
struct Plugin *plugin = cls;
sqlite3_stmt *stmt;
@@ -189,102 +188,92 @@
now = GNUNET_TIME_absolute_get ();
#if DEBUG_DATACACHE_SQLITE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Processing `%s' for key `%4s'\n",
- "GET",
- GNUNET_h2s (key));
+ "Processing `%s' for key `%4s'\n", "GET", GNUNET_h2s (key));
#endif
if (sq_prepare (plugin->dbh,
"SELECT count(*) FROM ds090 WHERE key=? AND type=? AND
expire >= ?",
&stmt) != SQLITE_OK)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- _("`%s' failed at %s:%d with error: %s\n"),
- "sq_prepare", __FILE__, __LINE__,
- sqlite3_errmsg (plugin->dbh));
- return 0;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ _("`%s' failed at %s:%d with error: %s\n"),
+ "sq_prepare", __FILE__, __LINE__, sqlite3_errmsg
(plugin->dbh));
+ return 0;
+ }
ntime = (int64_t) now.abs_value;
GNUNET_assert (ntime >= 0);
- if ( (SQLITE_OK !=
- sqlite3_bind_blob (stmt, 1, key, sizeof (GNUNET_HashCode),
- SQLITE_TRANSIENT)) ||
- (SQLITE_OK !=
- sqlite3_bind_int (stmt, 2, type)) ||
- (SQLITE_OK !=
- sqlite3_bind_int64 (stmt, 3, now.abs_value)) )
- {
- LOG_SQLITE (plugin->dbh,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "sqlite3_bind_xxx");
- sqlite3_finalize (stmt);
- return 0;
- }
+ if ((SQLITE_OK !=
+ sqlite3_bind_blob (stmt, 1, key, sizeof (GNUNET_HashCode),
+ SQLITE_TRANSIENT)) ||
+ (SQLITE_OK !=
+ sqlite3_bind_int (stmt, 2, type)) ||
+ (SQLITE_OK != sqlite3_bind_int64 (stmt, 3, now.abs_value)))
+ {
+ LOG_SQLITE (plugin->dbh,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_bind_xxx");
+ sqlite3_finalize (stmt);
+ return 0;
+ }
if (SQLITE_ROW != sqlite3_step (stmt))
- {
- LOG_SQLITE (plugin->dbh,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "sqlite_step");
- sqlite3_finalize (stmt);
- return 0;
- }
+ {
+ LOG_SQLITE (plugin->dbh,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite_step");
+ sqlite3_finalize (stmt);
+ return 0;
+ }
total = sqlite3_column_int (stmt, 0);
sqlite3_finalize (stmt);
- if ( (total == 0) || (iter == NULL) )
- return total;
+ if ((total == 0) || (iter == NULL))
+ return total;
cnt = 0;
off = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, total);
while (cnt < total)
+ {
+ off = (off + 1) % total;
+ GNUNET_snprintf (scratch,
+ sizeof (scratch),
+ "SELECT value,expire FROM ds090 WHERE key=? AND type=?
AND expire >= ? LIMIT 1 OFFSET %u",
+ off);
+ if (sq_prepare (plugin->dbh, scratch, &stmt) != SQLITE_OK)
{
- off = (off + 1) % total;
- GNUNET_snprintf (scratch,
- sizeof(scratch),
- "SELECT value,expire FROM ds090 WHERE key=? AND type=?
AND expire >= ? LIMIT 1 OFFSET %u",
- off);
- if (sq_prepare (plugin->dbh, scratch, &stmt) != SQLITE_OK)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- _("`%s' failed at %s:%d with error: %s\n"),
- "sq_prepare", __FILE__, __LINE__,
- sqlite3_errmsg (plugin->dbh));
- return cnt;
- }
- if ( (SQLITE_OK !=
- sqlite3_bind_blob (stmt, 1, key, sizeof (GNUNET_HashCode),
- SQLITE_TRANSIENT)) ||
- (SQLITE_OK !=
- sqlite3_bind_int (stmt, 2, type)) ||
- (SQLITE_OK !=
- sqlite3_bind_int64 (stmt, 3, now.abs_value)) )
- {
- LOG_SQLITE (plugin->dbh,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "sqlite3_bind_xxx");
- sqlite3_finalize (stmt);
- return cnt;
- }
- if (sqlite3_step (stmt) != SQLITE_ROW)
- break;
- size = sqlite3_column_bytes (stmt, 0);
- dat = sqlite3_column_blob (stmt, 0);
- exp.abs_value = sqlite3_column_int64 (stmt, 1);
- ntime = (int64_t) exp.abs_value;
- if (ntime == INT64_MAX)
- exp = GNUNET_TIME_UNIT_FOREVER_ABS;
- cnt++;
- if (GNUNET_OK != iter (iter_cls,
- exp,
- key,
- size,
- dat,
- type))
- {
- sqlite3_finalize (stmt);
- break;
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ _("`%s' failed at %s:%d with error: %s\n"),
+ "sq_prepare", __FILE__, __LINE__,
+ sqlite3_errmsg (plugin->dbh));
+ return cnt;
+ }
+ if ((SQLITE_OK !=
+ sqlite3_bind_blob (stmt, 1, key, sizeof (GNUNET_HashCode),
+ SQLITE_TRANSIENT)) ||
+ (SQLITE_OK !=
+ sqlite3_bind_int (stmt, 2, type)) ||
+ (SQLITE_OK != sqlite3_bind_int64 (stmt, 3, now.abs_value)))
+ {
+ LOG_SQLITE (plugin->dbh,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_bind_xxx");
sqlite3_finalize (stmt);
+ return cnt;
}
+ if (sqlite3_step (stmt) != SQLITE_ROW)
+ break;
+ size = sqlite3_column_bytes (stmt, 0);
+ dat = sqlite3_column_blob (stmt, 0);
+ exp.abs_value = sqlite3_column_int64 (stmt, 1);
+ ntime = (int64_t) exp.abs_value;
+ if (ntime == INT64_MAX)
+ exp = GNUNET_TIME_UNIT_FOREVER_ABS;
+ cnt++;
+ if (GNUNET_OK != iter (iter_cls, exp, key, size, dat, type))
+ {
+ sqlite3_finalize (stmt);
+ break;
+ }
+ sqlite3_finalize (stmt);
+ }
return cnt;
}
@@ -295,8 +284,8 @@
*
* @param cls closure (our "struct Plugin")
* @return GNUNET_OK on success, GNUNET_SYSERR on error
- */
-static int
+ */
+static int
sqlite_plugin_del (void *cls)
{
struct Plugin *plugin = cls;
@@ -308,32 +297,30 @@
GNUNET_HashCode hc;
#if DEBUG_DATACACHE_SQLITE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Processing `%s'\n",
- "DEL");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing `%s'\n", "DEL");
#endif
stmt = NULL;
dstmt = NULL;
if (sq_prepare (plugin->dbh,
- "SELECT type, key, value FROM ds090 ORDER BY expire ASC
LIMIT 1",
- &stmt) != SQLITE_OK)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- _("`%s' failed at %s:%d with error: %s\n"),
- "sq_prepare", __FILE__, __LINE__, sqlite3_errmsg
(plugin->dbh));
- if (stmt != NULL)
- (void) sqlite3_finalize (stmt);
- return GNUNET_SYSERR;
- }
- if (SQLITE_ROW != sqlite3_step (stmt))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- _("`%s' failed at %s:%d with error: %s\n"),
- "sqlite3_step", __FILE__, __LINE__,
- sqlite3_errmsg (plugin->dbh));
+ "SELECT type, key, value FROM ds090 ORDER BY expire ASC
LIMIT 1",
+ &stmt) != SQLITE_OK)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ _("`%s' failed at %s:%d with error: %s\n"),
+ "sq_prepare", __FILE__, __LINE__, sqlite3_errmsg
(plugin->dbh));
+ if (stmt != NULL)
(void) sqlite3_finalize (stmt);
- return GNUNET_SYSERR;
- }
+ return GNUNET_SYSERR;
+ }
+ if (SQLITE_ROW != sqlite3_step (stmt))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ _("`%s' failed at %s:%d with error: %s\n"),
+ "sqlite3_step", __FILE__, __LINE__,
+ sqlite3_errmsg (plugin->dbh));
+ (void) sqlite3_finalize (stmt);
+ return GNUNET_SYSERR;
+ }
dtype = sqlite3_column_int (stmt, 0);
GNUNET_break (sqlite3_column_bytes (stmt, 1) == sizeof (GNUNET_HashCode));
dsize = sqlite3_column_bytes (stmt, 2);
@@ -342,58 +329,54 @@
memcpy (&hc, sqlite3_column_blob (stmt, 1), sizeof (GNUNET_HashCode));
if (SQLITE_OK != sqlite3_finalize (stmt))
GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- _("`%s' failed at %s:%d with error: %s\n"),
- "sqlite3_step", __FILE__, __LINE__,
- sqlite3_errmsg (plugin->dbh));
+ _("`%s' failed at %s:%d with error: %s\n"),
+ "sqlite3_step", __FILE__, __LINE__,
+ sqlite3_errmsg (plugin->dbh));
if (sq_prepare (plugin->dbh,
- "DELETE FROM ds090 "
- "WHERE key=? AND value=? AND type=?",
- &dstmt) != SQLITE_OK)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- _("`%s' failed at %s:%d with error: %s\n"),
- "sq_prepare", __FILE__, __LINE__, sqlite3_errmsg
(plugin->dbh));
- if (stmt != NULL)
- (void) sqlite3_finalize (stmt);
- return GNUNET_SYSERR;
- }
- if ( (SQLITE_OK !=
- sqlite3_bind_blob (dstmt,
- 1, &hc,
- sizeof (GNUNET_HashCode),
- SQLITE_TRANSIENT)) ||
- (SQLITE_OK !=
- sqlite3_bind_blob (dstmt,
- 2, blob,
- dsize,
- SQLITE_TRANSIENT)) ||
- (SQLITE_OK !=
- sqlite3_bind_int (dstmt, 3, dtype)) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- _("`%s' failed at %s:%d with error: %s\n"),
- "sqlite3_bind", __FILE__, __LINE__,
- sqlite3_errmsg (plugin->dbh));
- (void) sqlite3_finalize (dstmt);
- return GNUNET_SYSERR;
- }
+ "DELETE FROM ds090 "
+ "WHERE key=? AND value=? AND type=?", &dstmt) != SQLITE_OK)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ _("`%s' failed at %s:%d with error: %s\n"),
+ "sq_prepare", __FILE__, __LINE__, sqlite3_errmsg
(plugin->dbh));
+ if (stmt != NULL)
+ (void) sqlite3_finalize (stmt);
+ return GNUNET_SYSERR;
+ }
+ if ((SQLITE_OK !=
+ sqlite3_bind_blob (dstmt,
+ 1, &hc,
+ sizeof (GNUNET_HashCode),
+ SQLITE_TRANSIENT)) ||
+ (SQLITE_OK !=
+ sqlite3_bind_blob (dstmt,
+ 2, blob,
+ dsize,
+ SQLITE_TRANSIENT)) ||
+ (SQLITE_OK != sqlite3_bind_int (dstmt, 3, dtype)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ _("`%s' failed at %s:%d with error: %s\n"),
+ "sqlite3_bind", __FILE__, __LINE__,
+ sqlite3_errmsg (plugin->dbh));
+ (void) sqlite3_finalize (dstmt);
+ return GNUNET_SYSERR;
+ }
if (sqlite3_step (dstmt) != SQLITE_DONE)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- _("`%s' failed at %s:%d with error: %s\n"),
- "sqlite3_step", __FILE__, __LINE__,
- sqlite3_errmsg (plugin->dbh));
- (void) sqlite3_finalize (dstmt);
- return GNUNET_SYSERR;
- }
- plugin->env->delete_notify (plugin->env->cls,
- &hc,
- dsize + OVERHEAD);
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ _("`%s' failed at %s:%d with error: %s\n"),
+ "sqlite3_step", __FILE__, __LINE__,
+ sqlite3_errmsg (plugin->dbh));
+ (void) sqlite3_finalize (dstmt);
+ return GNUNET_SYSERR;
+ }
+ plugin->env->delete_notify (plugin->env->cls, &hc, dsize + OVERHEAD);
if (SQLITE_OK != sqlite3_finalize (dstmt))
GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- _("`%s' failed at %s:%d with error: %s\n"),
- "sqlite3_finalize", __FILE__, __LINE__,
- sqlite3_errmsg (plugin->dbh));
+ _("`%s' failed at %s:%d with error: %s\n"),
+ "sqlite3_finalize", __FILE__, __LINE__,
+ sqlite3_errmsg (plugin->dbh));
return GNUNET_OK;
}
@@ -417,10 +400,10 @@
fn = GNUNET_DISK_mktemp ("gnunet-datacache");
if (fn == NULL)
- {
- GNUNET_break (0);
- return NULL;
- }
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
#ifdef ENABLE_NLS
fn_utf8 = GNUNET_STRINGS_to_utf8 (fn, strlen (fn), nl_langinfo (CODESET));
#else
@@ -428,11 +411,11 @@
fn_utf8 = GNUNET_STRINGS_to_utf8 (fn, strlen (fn), "UTF-8");
#endif
if (SQLITE_OK != sqlite3_open (fn_utf8, &dbh))
- {
- GNUNET_free (fn);
- GNUNET_free (fn_utf8);
- return NULL;
- }
+ {
+ GNUNET_free (fn);
+ GNUNET_free (fn_utf8);
+ return NULL;
+ }
GNUNET_free (fn);
SQLITE3_EXEC (dbh, "PRAGMA temp_store=MEMORY");
@@ -461,6 +444,7 @@
"sqlite", _("Sqlite datacache running\n"));
return api;
}
+
// explain SELECT type FROM gn090 WHERE NOT EXISTS (SELECT 1 from gn090 WHERE
expire < 42 LIMIT 1) OR expire < 42 ORDER BY repl DESC, Random() LIMIT 1;
@@ -476,53 +460,49 @@
struct GNUNET_DATACACHE_PluginFunctions *api = cls;
struct Plugin *plugin = api->cls;
int result;
+
#if SQLITE_VERSION_NUMBER >= 3007000
sqlite3_stmt *stmt;
#endif
#if !WINDOWS || defined(__CYGWIN__)
if (0 != UNLINK (plugin->fn))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
- "unlink",
- plugin->fn);
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", plugin->fn);
GNUNET_free (plugin->fn);
#endif
result = sqlite3_close (plugin->dbh);
#if SQLITE_VERSION_NUMBER >= 3007000
if (result == SQLITE_BUSY)
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
+ "sqlite",
+ _
+ ("Tried to close sqlite without finalizing all prepared
statements.\n"));
+ stmt = sqlite3_next_stmt (plugin->dbh, NULL);
+ while (stmt != NULL)
{
- GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
- "sqlite",
- _("Tried to close sqlite without finalizing all prepared
statements.\n"));
- stmt = sqlite3_next_stmt(plugin->dbh, NULL);
- while (stmt != NULL)
- {
#if DEBUG_SQLITE
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "sqlite", "Closing statement %p\n", stmt);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ "sqlite", "Closing statement %p\n", stmt);
#endif
- result = sqlite3_finalize(stmt);
+ result = sqlite3_finalize (stmt);
#if DEBUG_SQLITE
- if (result != SQLITE_OK)
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "sqlite",
- "Failed to close statement %p: %d\n", stmt,
result);
+ if (result != SQLITE_OK)
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ "sqlite",
+ "Failed to close statement %p: %d\n", stmt, result);
#endif
- stmt = sqlite3_next_stmt(plugin->dbh, NULL);
- }
- result = sqlite3_close(plugin->dbh);
+ stmt = sqlite3_next_stmt (plugin->dbh, NULL);
}
+ result = sqlite3_close (plugin->dbh);
+ }
#endif
if (SQLITE_OK != result)
- LOG_SQLITE (plugin->dbh,
- GNUNET_ERROR_TYPE_ERROR,
- "sqlite3_close");
+ LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR, "sqlite3_close");
#if WINDOWS && !defined(__CYGWIN__)
if (0 != UNLINK (plugin->fn))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
- "unlink",
- plugin->fn);
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", plugin->fn);
GNUNET_free (plugin->fn);
#endif
GNUNET_free (plugin);
@@ -533,4 +513,3 @@
/* end of plugin_datacache_sqlite.c */
-
Modified: gnunet/src/datacache/plugin_datacache_template.c
===================================================================
--- gnunet/src/datacache/plugin_datacache_template.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/datacache/plugin_datacache_template.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -31,7 +31,7 @@
/**
* Context for all functions in this plugin.
*/
-struct Plugin
+struct Plugin
{
/**
* Our execution environment.
@@ -51,13 +51,13 @@
* @param discard_time when to discard the value in any case
* @return 0 on error, number of bytes used otherwise
*/
-static size_t
+static size_t
template_plugin_put (void *cls,
- const GNUNET_HashCode * key,
- size_t size,
- const char *data,
- enum GNUNET_BLOCK_Type type,
- struct GNUNET_TIME_Absolute discard_time)
+ const GNUNET_HashCode * key,
+ size_t size,
+ const char *data,
+ enum GNUNET_BLOCK_Type type,
+ struct GNUNET_TIME_Absolute discard_time)
{
GNUNET_break (0);
return 0;
@@ -75,12 +75,11 @@
* @param iter_cls closure for iter
* @return the number of results found
*/
-static unsigned int
+static unsigned int
template_plugin_get (void *cls,
- const GNUNET_HashCode * key,
- enum GNUNET_BLOCK_Type type,
- GNUNET_DATACACHE_Iterator iter,
- void *iter_cls)
+ const GNUNET_HashCode * key,
+ enum GNUNET_BLOCK_Type type,
+ GNUNET_DATACACHE_Iterator iter, void *iter_cls)
{
GNUNET_break (0);
return 0;
@@ -93,8 +92,8 @@
*
* @param cls closure (our "struct Plugin")
* @return GNUNET_OK on success, GNUNET_SYSERR on error
- */
-static int
+ */
+static int
template_plugin_del (void *cls)
{
GNUNET_break (0);
@@ -148,4 +147,3 @@
/* end of plugin_datacache_template.c */
-
Modified: gnunet/src/datacache/test_datacache.c
===================================================================
--- gnunet/src/datacache/test_datacache.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/datacache/test_datacache.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -40,22 +40,20 @@
static int
checkIt (void *cls,
- struct GNUNET_TIME_Absolute exp,
- const GNUNET_HashCode * key,
- size_t size,
- const char *data,
- enum GNUNET_BLOCK_Type type)
+ struct GNUNET_TIME_Absolute exp,
+ const GNUNET_HashCode * key,
+ size_t size, const char *data, enum GNUNET_BLOCK_Type type)
{
if (size != sizeof (GNUNET_HashCode))
- {
- printf ("ERROR: Invalid size\n");
- ok = 2;
- }
+ {
+ printf ("ERROR: Invalid size\n");
+ ok = 2;
+ }
if (0 != memcmp (data, cls, size))
- {
- printf ("ERROR: Invalid data\n");
- ok = 3;
- }
+ {
+ printf ("ERROR: Invalid data\n");
+ ok = 3;
+ }
return GNUNET_OK;
}
@@ -63,8 +61,7 @@
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
struct GNUNET_DATACACHE_Handle *h;
GNUNET_HashCode k;
@@ -73,39 +70,35 @@
unsigned int i;
ok = 0;
- h = GNUNET_DATACACHE_create (cfg,
- "testcache");
+ h = GNUNET_DATACACHE_create (cfg, "testcache");
if (h == NULL)
- {
- fprintf (stderr,
- "Failed to initialize datacache. Database likely not setup,
skipping test.\n");
- return;
- }
+ {
+ fprintf (stderr,
+ "Failed to initialize datacache. Database likely not setup,
skipping test.\n");
+ return;
+ }
exp = GNUNET_TIME_absolute_get ();
exp.abs_value += 5 * 60 * 1000;
memset (&k, 0, sizeof (GNUNET_HashCode));
for (i = 0; i < 100; i++)
- {
- GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n);
- ASSERT (GNUNET_OK == GNUNET_DATACACHE_put (h,
- &k,
- sizeof (GNUNET_HashCode),
- (const char *) &n,
- 1+i%16,
- exp));
- k = n;
- }
+ {
+ GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n);
+ ASSERT (GNUNET_OK == GNUNET_DATACACHE_put (h,
+ &k,
+ sizeof (GNUNET_HashCode),
+ (const char *) &n,
+ 1 + i % 16, exp));
+ k = n;
+ }
memset (&k, 0, sizeof (GNUNET_HashCode));
for (i = 0; i < 100; i++)
- {
- GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n);
- ASSERT (1 ==
- GNUNET_DATACACHE_get (h, &k, 1+i%16,
- &checkIt, &n));
- k = n;
- }
+ {
+ GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n);
+ ASSERT (1 == GNUNET_DATACACHE_get (h, &k, 1 + i % 16, &checkIt, &n));
+ k = n;
+ }
- memset(&k, 42, sizeof(GNUNET_HashCode));
+ memset (&k, 42, sizeof (GNUNET_HashCode));
GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n);
ASSERT (GNUNET_OK == GNUNET_DATACACHE_put (h,
&k,
@@ -113,9 +106,7 @@
(const char *) &n,
792,
GNUNET_TIME_UNIT_FOREVER_ABS));
- ASSERT (0 !=
- GNUNET_DATACACHE_get (h, &k, 792,
- &checkIt, &n));
+ ASSERT (0 != GNUNET_DATACACHE_get (h, &k, 792, &checkIt, &n));
GNUNET_DATACACHE_destroy (h);
ASSERT (ok == 0);
@@ -132,7 +123,8 @@
{
char *pos;
char cfg_name[128];
- char *const xargv[] = {
+
+ char *const xargv[] = {
"test-datacache",
"-c",
cfg_name,
@@ -154,22 +146,20 @@
NULL);
/* determine name of plugin to use */
plugin_name = argv[0];
- while (NULL != (pos = strstr(plugin_name, "_")))
- plugin_name = pos+1;
- if (NULL != (pos = strstr(plugin_name, ".")))
+ while (NULL != (pos = strstr (plugin_name, "_")))
+ plugin_name = pos + 1;
+ if (NULL != (pos = strstr (plugin_name, ".")))
pos[0] = 0;
else
pos = (char *) plugin_name;
-
+
GNUNET_snprintf (cfg_name,
- sizeof (cfg_name),
- "test_datacache_data_%s.conf",
- plugin_name);
+ sizeof (cfg_name),
+ "test_datacache_data_%s.conf", plugin_name);
if (pos != plugin_name)
pos[0] = '.';
GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1,
- xargv, "test-datacache", "nohelp",
- options, &run, NULL);
+ xargv, "test-datacache", "nohelp", options, &run, NULL);
if (ok != 0)
fprintf (stderr, "Missed some testcases: %d\n", ok);
return ok;
Modified: gnunet/src/datacache/test_datacache_quota.c
===================================================================
--- gnunet/src/datacache/test_datacache_quota.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/datacache/test_datacache_quota.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -46,8 +46,7 @@
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
struct GNUNET_DATACACHE_Handle *h;
GNUNET_HashCode k;
@@ -58,56 +57,43 @@
struct GNUNET_TIME_Absolute exp;
ok = 0;
- h = GNUNET_DATACACHE_create (cfg,
- "testcache");
+ h = GNUNET_DATACACHE_create (cfg, "testcache");
if (h == NULL)
- {
- fprintf (stderr,
- "Failed to initialize datacache. Database likely not setup,
skipping test.\n");
- return;
- }
+ {
+ fprintf (stderr,
+ "Failed to initialize datacache. Database likely not setup,
skipping test.\n");
+ return;
+ }
exp = GNUNET_TIME_absolute_get ();
exp.abs_value += 20 * 60 * 1000;
memset (buf, 1, sizeof (buf));
memset (&k, 0, sizeof (GNUNET_HashCode));
for (i = 0; i < 10; i++)
+ {
+ fprintf (stderr, ".");
+ GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n);
+ for (j = i; j < sizeof (buf); j += 10)
{
- fprintf (stderr, ".");
- GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n);
- for (j = i; j < sizeof (buf); j += 10)
- {
- exp.abs_value++;
- buf[j] = i;
- ASSERT (GNUNET_OK ==
- GNUNET_DATACACHE_put (h,
- &k,
- j,
- buf,
- 1+i,
- exp));
- ASSERT (0 < GNUNET_DATACACHE_get (h,
- &k, 1+i,
- NULL, NULL));
- }
- k = n;
+ exp.abs_value++;
+ buf[j] = i;
+ ASSERT (GNUNET_OK == GNUNET_DATACACHE_put (h, &k, j, buf, 1 + i, exp));
+ ASSERT (0 < GNUNET_DATACACHE_get (h, &k, 1 + i, NULL, NULL));
}
+ k = n;
+ }
fprintf (stderr, "\n");
memset (&k, 0, sizeof (GNUNET_HashCode));
for (i = 0; i < 10; i++)
- {
- fprintf (stderr, ".");
- GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n);
- if (i < 2)
- ASSERT (0 == GNUNET_DATACACHE_get (h,
- &k, 1+i,
- NULL, NULL));
- if (i == 9)
- ASSERT (0 < GNUNET_DATACACHE_get (h,
- &k, 1+i,
- NULL, NULL));
- k = n;
- }
+ {
+ fprintf (stderr, ".");
+ GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n);
+ if (i < 2)
+ ASSERT (0 == GNUNET_DATACACHE_get (h, &k, 1 + i, NULL, NULL));
+ if (i == 9)
+ ASSERT (0 < GNUNET_DATACACHE_get (h, &k, 1 + i, NULL, NULL));
+ k = n;
+ }
fprintf (stderr, "\n");
GNUNET_DATACACHE_destroy (h);
return;
@@ -123,7 +109,8 @@
{
char *pos;
char cfg_name[128];
- char *const xargv[] = {
+
+ char *const xargv[] = {
"test-datacache-quota",
"-c",
cfg_name,
@@ -135,7 +122,7 @@
struct GNUNET_GETOPT_CommandLineOption options[] = {
GNUNET_GETOPT_OPTION_END
};
-
+
GNUNET_log_setup ("test-datacache-quota",
#if VERBOSE
"DEBUG",
@@ -146,17 +133,16 @@
/* determine name of plugin to use */
plugin_name = argv[0];
- while (NULL != (pos = strstr(plugin_name, "_")))
- plugin_name = pos+1;
- if (NULL != (pos = strstr(plugin_name, ".")))
+ while (NULL != (pos = strstr (plugin_name, "_")))
+ plugin_name = pos + 1;
+ if (NULL != (pos = strstr (plugin_name, ".")))
pos[0] = 0;
else
pos = (char *) plugin_name;
-
+
GNUNET_snprintf (cfg_name,
- sizeof (cfg_name),
- "test_datacache_data_%s.conf",
- plugin_name);
+ sizeof (cfg_name),
+ "test_datacache_data_%s.conf", plugin_name);
if (pos != plugin_name)
pos[0] = '.';
GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1,
Modified: gnunet/src/datastore/datastore.h
===================================================================
--- gnunet/src/datastore/datastore.h 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/datastore/datastore.h 2011-08-15 21:46:35 UTC (rev 16581)
@@ -213,7 +213,7 @@
* Priority of the item (NBO), zero for remove.
*/
uint32_t priority GNUNET_PACKED;
-
+
/**
* Desired anonymity level (NBO), zero for remove.
*/
@@ -236,7 +236,7 @@
* the key and content).
*/
uint64_t uid;
-
+
/**
* Expiration time (NBO); zero for remove.
*/
Modified: gnunet/src/datastore/datastore_api.c
===================================================================
--- gnunet/src/datastore/datastore_api.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/datastore/datastore_api.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -82,7 +82,7 @@
{
struct StatusContext sc;
-
+
struct ResultContext rc;
};
@@ -121,7 +121,7 @@
* Function to call after transmission of the request.
*/
GNUNET_DATASTORE_ContinuationWithStatus cont;
-
+
/**
* Closure for 'cont'.
*/
@@ -167,7 +167,7 @@
* multiple of 64 bits.
*/
int was_transmitted;
-
+
};
/**
@@ -250,22 +250,19 @@
* @return handle to use to access the service
*/
struct GNUNET_DATASTORE_Handle *
-GNUNET_DATASTORE_connect (const struct
- GNUNET_CONFIGURATION_Handle
- *cfg)
+GNUNET_DATASTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
{
struct GNUNET_CLIENT_Connection *c;
struct GNUNET_DATASTORE_Handle *h;
-
+
c = GNUNET_CLIENT_connect ("datastore", cfg);
if (c == NULL)
- return NULL; /* oops */
- h = GNUNET_malloc (sizeof(struct GNUNET_DATASTORE_Handle) +
- GNUNET_SERVER_MAX_MESSAGE_SIZE - 1);
+ return NULL; /* oops */
+ h = GNUNET_malloc (sizeof (struct GNUNET_DATASTORE_Handle) +
+ GNUNET_SERVER_MAX_MESSAGE_SIZE - 1);
h->client = c;
h->cfg = cfg;
- h->stats = GNUNET_STATISTICS_create ("datastore-api",
- cfg);
+ h->stats = GNUNET_STATISTICS_create ("datastore-api", cfg);
return h;
}
@@ -279,26 +276,24 @@
* @return number of bytes written to buf
*/
static size_t
-transmit_drop (void *cls,
- size_t size,
- void *buf)
+transmit_drop (void *cls, size_t size, void *buf)
{
struct GNUNET_DATASTORE_Handle *h = cls;
struct GNUNET_MessageHeader *hdr;
-
+
if (buf == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to transmit request to drop database.\n"));
- GNUNET_DATASTORE_disconnect (h, GNUNET_NO);
- return 0;
- }
- GNUNET_assert (size >= sizeof(struct GNUNET_MessageHeader));
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Failed to transmit request to drop database.\n"));
+ GNUNET_DATASTORE_disconnect (h, GNUNET_NO);
+ return 0;
+ }
+ GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader));
hdr = buf;
- hdr->size = htons(sizeof(struct GNUNET_MessageHeader));
- hdr->type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_DROP);
+ hdr->size = htons (sizeof (struct GNUNET_MessageHeader));
+ hdr->type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_DROP);
GNUNET_DATASTORE_disconnect (h, GNUNET_NO);
- return sizeof(struct GNUNET_MessageHeader);
+ return sizeof (struct GNUNET_MessageHeader);
}
@@ -310,55 +305,51 @@
* @param drop set to GNUNET_YES to delete all data in datastore (!)
*/
void
-GNUNET_DATASTORE_disconnect (struct GNUNET_DATASTORE_Handle *h,
- int drop)
+GNUNET_DATASTORE_disconnect (struct GNUNET_DATASTORE_Handle *h, int drop)
{
struct GNUNET_DATASTORE_QueueEntry *qe;
#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Datastore disconnect\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Datastore disconnect\n");
#endif
if (NULL != h->th)
- {
- GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
- h->th = NULL;
- }
+ {
+ GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
+ h->th = NULL;
+ }
if (h->client != NULL)
+ {
+ GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
+ h->client = NULL;
+ }
+ if (h->reconnect_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (h->reconnect_task);
+ h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ while (NULL != (qe = h->queue_head))
+ {
+ GNUNET_assert (NULL != qe->response_proc);
+ qe->response_proc (h, NULL);
+ }
+ if (GNUNET_YES == drop)
+ {
+ h->client = GNUNET_CLIENT_connect ("datastore", h->cfg);
+ if (h->client != NULL)
{
+ if (NULL !=
+ GNUNET_CLIENT_notify_transmit_ready (h->client,
+ sizeof (struct
+ GNUNET_MessageHeader),
+ GNUNET_TIME_UNIT_MINUTES,
+ GNUNET_YES, &transmit_drop, h))
+ return;
GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
h->client = NULL;
}
- if (h->reconnect_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (h->reconnect_task);
- h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
- }
- while (NULL != (qe = h->queue_head))
- {
- GNUNET_assert (NULL != qe->response_proc);
- qe->response_proc (h, NULL);
- }
- if (GNUNET_YES == drop)
- {
- h->client = GNUNET_CLIENT_connect ("datastore", h->cfg);
- if (h->client != NULL)
- {
- if (NULL !=
- GNUNET_CLIENT_notify_transmit_ready (h->client,
- sizeof(struct
GNUNET_MessageHeader),
- GNUNET_TIME_UNIT_MINUTES,
- GNUNET_YES,
- &transmit_drop,
- h))
- return;
- GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
- h->client = NULL;
- }
- GNUNET_break (0);
- }
- GNUNET_STATISTICS_destroy (h->stats,
- GNUNET_NO);
+ GNUNET_break (0);
+ }
+ GNUNET_STATISTICS_destroy (h->stats, GNUNET_NO);
h->stats = NULL;
GNUNET_free (h);
}
@@ -371,20 +362,18 @@
* @param tc scheduler context
*/
static void
-timeout_queue_entry (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+timeout_queue_entry (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_DATASTORE_QueueEntry *qe = cls;
GNUNET_STATISTICS_update (qe->h->stats,
- gettext_noop ("# queue entry timeouts"),
- 1,
- GNUNET_NO);
+ gettext_noop ("# queue entry timeouts"),
+ 1, GNUNET_NO);
qe->task = GNUNET_SCHEDULER_NO_TASK;
- GNUNET_assert (qe->was_transmitted == GNUNET_NO);
+ GNUNET_assert (qe->was_transmitted == GNUNET_NO);
#if DEBUG_DATASTORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Timeout of request in datastore queue\n");
+ "Timeout of request in datastore queue\n");
#endif
qe->response_proc (qe->h, NULL);
}
@@ -406,12 +395,12 @@
*/
static struct GNUNET_DATASTORE_QueueEntry *
make_queue_entry (struct GNUNET_DATASTORE_Handle *h,
- size_t msize,
- unsigned int queue_priority,
- unsigned int max_queue_size,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_CLIENT_MessageHandler response_proc,
- const union QueueContext *qc)
+ size_t msize,
+ unsigned int queue_priority,
+ unsigned int max_queue_size,
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_CLIENT_MessageHandler response_proc,
+ const union QueueContext *qc)
{
struct GNUNET_DATASTORE_QueueEntry *ret;
struct GNUNET_DATASTORE_QueueEntry *pos;
@@ -419,21 +408,18 @@
c = 0;
pos = h->queue_head;
- while ( (pos != NULL) &&
- (c < max_queue_size) &&
- (pos->priority >= queue_priority) )
- {
- c++;
- pos = pos->next;
- }
+ while ((pos != NULL) &&
+ (c < max_queue_size) && (pos->priority >= queue_priority))
+ {
+ c++;
+ pos = pos->next;
+ }
if (c >= max_queue_size)
- {
- GNUNET_STATISTICS_update (h->stats,
- gettext_noop ("# queue overflows"),
- 1,
- GNUNET_NO);
- return NULL;
- }
+ {
+ GNUNET_STATISTICS_update (h->stats,
+ gettext_noop ("# queue overflows"), 1,
GNUNET_NO);
+ return NULL;
+ }
ret = GNUNET_malloc (sizeof (struct GNUNET_DATASTORE_QueueEntry) + msize);
ret->h = h;
ret->response_proc = response_proc;
@@ -444,61 +430,49 @@
ret->message_size = msize;
ret->was_transmitted = GNUNET_NO;
if (pos == NULL)
- {
- /* append at the tail */
- pos = h->queue_tail;
- }
+ {
+ /* append at the tail */
+ pos = h->queue_tail;
+ }
else
- {
- pos = pos->prev;
- /* do not insert at HEAD if HEAD query was already
- transmitted and we are still receiving replies! */
- if ( (pos == NULL) &&
- (h->queue_head->was_transmitted) )
- pos = h->queue_head;
- }
+ {
+ pos = pos->prev;
+ /* do not insert at HEAD if HEAD query was already
+ * transmitted and we are still receiving replies! */
+ if ((pos == NULL) && (h->queue_head->was_transmitted))
+ pos = h->queue_head;
+ }
c++;
GNUNET_STATISTICS_update (h->stats,
- gettext_noop ("# queue entries created"),
- 1,
- GNUNET_NO);
- GNUNET_CONTAINER_DLL_insert_after (h->queue_head,
- h->queue_tail,
- pos,
- ret);
+ gettext_noop ("# queue entries created"),
+ 1, GNUNET_NO);
+ GNUNET_CONTAINER_DLL_insert_after (h->queue_head, h->queue_tail, pos, ret);
h->queue_size++;
- ret->task = GNUNET_SCHEDULER_add_delayed (timeout,
- &timeout_queue_entry,
- ret);
+ ret->task = GNUNET_SCHEDULER_add_delayed (timeout, &timeout_queue_entry,
ret);
pos = ret->next;
- while (pos != NULL)
+ while (pos != NULL)
+ {
+ if ((pos->max_queue < h->queue_size) && (pos->was_transmitted ==
GNUNET_NO))
{
- if ( (pos->max_queue < h->queue_size) &&
- (pos->was_transmitted == GNUNET_NO) )
- {
- GNUNET_assert (pos->response_proc != NULL);
- /* move 'pos' element to head so that it will be
- killed on 'NULL' call below */
+ GNUNET_assert (pos->response_proc != NULL);
+ /* move 'pos' element to head so that it will be
+ * killed on 'NULL' call below */
#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Dropping request from datastore queue\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Dropping request from datastore queue\n");
#endif
- GNUNET_CONTAINER_DLL_remove (h->queue_head,
- h->queue_tail,
- pos);
- GNUNET_CONTAINER_DLL_insert (h->queue_head,
- h->queue_tail,
- pos);
- GNUNET_STATISTICS_update (h->stats,
- gettext_noop ("# Requests dropped from
datastore queue"),
- 1,
- GNUNET_NO);
- GNUNET_assert (h->queue_head == pos);
- pos->response_proc (h, NULL);
- break;
- }
- pos = pos->next;
+ GNUNET_CONTAINER_DLL_remove (h->queue_head, h->queue_tail, pos);
+ GNUNET_CONTAINER_DLL_insert (h->queue_head, h->queue_tail, pos);
+ GNUNET_STATISTICS_update (h->stats,
+ gettext_noop
+ ("# Requests dropped from datastore queue"), 1,
+ GNUNET_NO);
+ GNUNET_assert (h->queue_head == pos);
+ pos->response_proc (h, NULL);
+ break;
}
+ pos = pos->next;
+ }
return ret;
}
@@ -509,8 +483,7 @@
*
* @param h handle to the datastore
*/
-static void
-process_queue (struct GNUNET_DATASTORE_Handle *h);
+static void process_queue (struct GNUNET_DATASTORE_Handle *h);
/**
@@ -520,8 +493,7 @@
* @param tc scheduler context
*/
static void
-try_reconnect (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+try_reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_DATASTORE_Handle *h = cls;
@@ -534,18 +506,17 @@
h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
h->client = GNUNET_CLIENT_connect ("datastore", h->cfg);
if (h->client == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "DATASTORE reconnect failed (fatally)\n");
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "DATASTORE reconnect failed (fatally)\n");
+ return;
+ }
GNUNET_STATISTICS_update (h->stats,
- gettext_noop ("# datastore connections
(re)created"),
- 1,
- GNUNET_NO);
+ gettext_noop
+ ("# datastore connections (re)created"), 1,
+ GNUNET_NO);
#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Reconnected to DATASTORE\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Reconnected to DATASTORE\n");
#endif
process_queue (h);
}
@@ -561,25 +532,23 @@
do_disconnect (struct GNUNET_DATASTORE_Handle *h)
{
if (h->client == NULL)
- {
+ {
#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "client NULL in disconnect, will not try to reconnect\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "client NULL in disconnect, will not try to reconnect\n");
#endif
- return;
- }
+ return;
+ }
#if 0
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# reconnected to DATASTORE"),
- 1,
- GNUNET_NO);
+ gettext_noop ("# reconnected to DATASTORE"),
+ 1, GNUNET_NO);
#endif
GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
h->skip_next_messages = 0;
h->client = NULL;
h->reconnect_task = GNUNET_SCHEDULER_add_delayed (h->retry_time,
- &try_reconnect,
- h);
+ &try_reconnect, h);
}
@@ -590,30 +559,28 @@
* @param cls the 'struct GNUNET_DATASTORE_Handle'
* @param msg the received message
*/
-static void
-receive_cb (void *cls,
- const struct GNUNET_MessageHeader *msg)
+static void
+receive_cb (void *cls, const struct GNUNET_MessageHeader *msg)
{
struct GNUNET_DATASTORE_Handle *h = cls;
struct GNUNET_DATASTORE_QueueEntry *qe;
h->in_receive = GNUNET_NO;
#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Receiving reply from datastore\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving reply from datastore\n");
#endif
if (h->skip_next_messages > 0)
- {
- h->skip_next_messages--;
- process_queue (h);
- return;
- }
+ {
+ h->skip_next_messages--;
+ process_queue (h);
+ return;
+ }
if (NULL == (qe = h->queue_head))
- {
- GNUNET_break (0);
- process_queue (h);
- return;
- }
+ {
+ GNUNET_break (0);
+ process_queue (h);
+ return;
+ }
qe->response_proc (h, msg);
}
@@ -627,9 +594,7 @@
* @return number of bytes written to buf
*/
static size_t
-transmit_request (void *cls,
- size_t size,
- void *buf)
+transmit_request (void *cls, size_t size, void *buf)
{
struct GNUNET_DATASTORE_Handle *h = cls;
struct GNUNET_DATASTORE_QueueEntry *qe;
@@ -637,27 +602,25 @@
h->th = NULL;
if (NULL == (qe = h->queue_head))
- return 0; /* no entry in queue */
+ return 0; /* no entry in queue */
if (buf == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to transmit request to DATASTORE.\n"));
- GNUNET_STATISTICS_update (h->stats,
- gettext_noop ("# transmission request
failures"),
- 1,
- GNUNET_NO);
- do_disconnect (h);
- return 0;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Failed to transmit request to DATASTORE.\n"));
+ GNUNET_STATISTICS_update (h->stats,
+ gettext_noop ("# transmission request failures"),
+ 1, GNUNET_NO);
+ do_disconnect (h);
+ return 0;
+ }
if (size < (msize = qe->message_size))
- {
- process_queue (h);
- return 0;
- }
- #if DEBUG_DATASTORE
+ {
+ process_queue (h);
+ return 0;
+ }
+#if DEBUG_DATASTORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitting %u byte request to DATASTORE\n",
- msize);
+ "Transmitting %u byte request to DATASTORE\n", msize);
#endif
memcpy (buf, &qe[1], msize);
qe->was_transmitted = GNUNET_YES;
@@ -666,13 +629,11 @@
GNUNET_assert (GNUNET_NO == h->in_receive);
h->in_receive = GNUNET_YES;
GNUNET_CLIENT_receive (h->client,
- &receive_cb,
- h,
- GNUNET_TIME_absolute_get_remaining (qe->timeout));
+ &receive_cb,
+ h, GNUNET_TIME_absolute_get_remaining (qe->timeout));
GNUNET_STATISTICS_update (h->stats,
- gettext_noop ("# bytes sent to datastore"),
- 1,
- GNUNET_NO);
+ gettext_noop ("# bytes sent to datastore"),
+ 1, GNUNET_NO);
return msize;
}
@@ -689,53 +650,47 @@
struct GNUNET_DATASTORE_QueueEntry *qe;
if (NULL == (qe = h->queue_head))
- {
+ {
#if DEBUG_DATASTORE > 1
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Queue empty\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Queue empty\n");
#endif
- return; /* no entry in queue */
- }
+ return; /* no entry in queue */
+ }
if (qe->was_transmitted == GNUNET_YES)
- {
+ {
#if DEBUG_DATASTORE > 1
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Head request already transmitted\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Head request already transmitted\n");
#endif
- return; /* waiting for replies */
- }
+ return; /* waiting for replies */
+ }
if (h->th != NULL)
- {
+ {
#if DEBUG_DATASTORE > 1
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Pending transmission request\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Pending transmission request\n");
#endif
- return; /* request pending */
- }
+ return; /* request pending */
+ }
if (h->client == NULL)
- {
+ {
#if DEBUG_DATASTORE > 1
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Not connected\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Not connected\n");
#endif
- return; /* waiting for reconnect */
- }
+ return; /* waiting for reconnect */
+ }
if (GNUNET_YES == h->in_receive)
- {
- /* wait for response to previous query */
- return;
- }
+ {
+ /* wait for response to previous query */
+ return;
+ }
#if DEBUG_DATASTORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Queueing %u byte request to DATASTORE\n",
- qe->message_size);
+ "Queueing %u byte request to DATASTORE\n", qe->message_size);
#endif
h->th = GNUNET_CLIENT_notify_transmit_ready (h->client,
- qe->message_size,
-
GNUNET_TIME_absolute_get_remaining (qe->timeout),
- GNUNET_YES,
- &transmit_request,
- h);
+ qe->message_size,
+
GNUNET_TIME_absolute_get_remaining
+ (qe->timeout), GNUNET_YES,
+ &transmit_request, h);
GNUNET_assert (GNUNET_NO == h->in_receive);
GNUNET_break (NULL != h->th);
}
@@ -767,16 +722,14 @@
{
struct GNUNET_DATASTORE_Handle *h = qe->h;
- GNUNET_CONTAINER_DLL_remove (h->queue_head,
- h->queue_tail,
- qe);
+ GNUNET_CONTAINER_DLL_remove (h->queue_head, h->queue_tail, qe);
if (qe->task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (qe->task);
- qe->task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (qe->task);
+ qe->task = GNUNET_SCHEDULER_NO_TASK;
+ }
h->queue_size--;
- qe->was_transmitted = GNUNET_SYSERR; /* use-after-free warning */
+ qe->was_transmitted = GNUNET_SYSERR; /* use-after-free warning */
GNUNET_free (qe);
}
@@ -788,10 +741,8 @@
* @param cls closure
* @param msg message received, NULL on timeout or fatal error
*/
-static void
-process_status_message (void *cls,
- const struct
- GNUNET_MessageHeader * msg)
+static void
+process_status_message (void *cls, const struct GNUNET_MessageHeader *msg)
{
struct GNUNET_DATASTORE_Handle *h = cls;
struct GNUNET_DATASTORE_QueueEntry *qe;
@@ -802,74 +753,68 @@
int was_transmitted;
if (NULL == (qe = h->queue_head))
- {
- GNUNET_break (0);
- do_disconnect (h);
- return;
- }
+ {
+ GNUNET_break (0);
+ do_disconnect (h);
+ return;
+ }
rc = qe->qc.sc;
if (msg == NULL)
- {
- was_transmitted = qe->was_transmitted;
- free_queue_entry (qe);
- if (was_transmitted == GNUNET_YES)
- do_disconnect (h);
- else
- process_queue (h);
- if (rc.cont != NULL)
- rc.cont (rc.cont_cls,
- GNUNET_SYSERR,
- _("Failed to receive status response from database."));
- return;
- }
+ {
+ was_transmitted = qe->was_transmitted;
+ free_queue_entry (qe);
+ if (was_transmitted == GNUNET_YES)
+ do_disconnect (h);
+ else
+ process_queue (h);
+ if (rc.cont != NULL)
+ rc.cont (rc.cont_cls,
+ GNUNET_SYSERR,
+ _("Failed to receive status response from database."));
+ return;
+ }
GNUNET_assert (GNUNET_YES == qe->was_transmitted);
free_queue_entry (qe);
- if ( (ntohs(msg->size) < sizeof(struct StatusMessage)) ||
- (ntohs(msg->type) != GNUNET_MESSAGE_TYPE_DATASTORE_STATUS) )
- {
- GNUNET_break (0);
- h->retry_time = GNUNET_TIME_UNIT_ZERO;
- do_disconnect (h);
- if (rc.cont != NULL)
- rc.cont (rc.cont_cls,
- GNUNET_SYSERR,
- _("Error reading response from datastore service"));
- return;
- }
- sm = (const struct StatusMessage*) msg;
- status = ntohl(sm->status);
+ if ((ntohs (msg->size) < sizeof (struct StatusMessage)) ||
+ (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_DATASTORE_STATUS))
+ {
+ GNUNET_break (0);
+ h->retry_time = GNUNET_TIME_UNIT_ZERO;
+ do_disconnect (h);
+ if (rc.cont != NULL)
+ rc.cont (rc.cont_cls,
+ GNUNET_SYSERR,
+ _("Error reading response from datastore service"));
+ return;
+ }
+ sm = (const struct StatusMessage *) msg;
+ status = ntohl (sm->status);
emsg = NULL;
- if (ntohs(msg->size) > sizeof(struct StatusMessage))
+ if (ntohs (msg->size) > sizeof (struct StatusMessage))
+ {
+ emsg = (const char *) &sm[1];
+ if (emsg[ntohs (msg->size) - sizeof (struct StatusMessage) - 1] != '\0')
{
- emsg = (const char*) &sm[1];
- if (emsg[ntohs(msg->size) - sizeof(struct StatusMessage) - 1] != '\0')
- {
- GNUNET_break (0);
- emsg = _("Invalid error message received from datastore service");
- }
- }
- if ( (status == GNUNET_SYSERR) &&
- (emsg == NULL) )
- {
GNUNET_break (0);
emsg = _("Invalid error message received from datastore service");
}
+ }
+ if ((status == GNUNET_SYSERR) && (emsg == NULL))
+ {
+ GNUNET_break (0);
+ emsg = _("Invalid error message received from datastore service");
+ }
#if DEBUG_DATASTORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received status %d/%s\n",
- (int) status,
- emsg);
+ "Received status %d/%s\n", (int) status, emsg);
#endif
GNUNET_STATISTICS_update (h->stats,
- gettext_noop ("# status messages received"),
- 1,
- GNUNET_NO);
+ gettext_noop ("# status messages received"),
+ 1, GNUNET_NO);
h->retry_time.rel_value = 0;
process_queue (h);
if (rc.cont != NULL)
- rc.cont (rc.cont_cls,
- status,
- emsg);
+ rc.cont (rc.cont_cls, status, emsg);
}
@@ -901,20 +846,20 @@
*/
struct GNUNET_DATASTORE_QueueEntry *
GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h,
- uint32_t rid,
+ uint32_t rid,
const GNUNET_HashCode * key,
size_t size,
const void *data,
enum GNUNET_BLOCK_Type type,
uint32_t priority,
uint32_t anonymity,
- uint32_t replication,
+ uint32_t replication,
struct GNUNET_TIME_Absolute expiration,
- unsigned int queue_priority,
- unsigned int max_queue_size,
+ unsigned int queue_priority,
+ unsigned int max_queue_size,
struct GNUNET_TIME_Relative timeout,
- GNUNET_DATASTORE_ContinuationWithStatus cont,
- void *cont_cls)
+ GNUNET_DATASTORE_ContinuationWithStatus cont,
+ void *cont_cls)
{
struct GNUNET_DATASTORE_QueueEntry *qe;
struct DataMessage *dm;
@@ -923,42 +868,41 @@
#if DEBUG_DATASTORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Asked to put %u bytes of data under key `%s' for %llu ms\n",
- size,
- GNUNET_h2s (key),
- GNUNET_TIME_absolute_get_remaining (expiration).rel_value);
+ "Asked to put %u bytes of data under key `%s' for %llu ms\n",
+ size,
+ GNUNET_h2s (key),
+ GNUNET_TIME_absolute_get_remaining (expiration).rel_value);
#endif
- msize = sizeof(struct DataMessage) + size;
+ msize = sizeof (struct DataMessage) + size;
GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE);
qc.sc.cont = cont;
qc.sc.cont_cls = cont_cls;
qe = make_queue_entry (h, msize,
- queue_priority, max_queue_size, timeout,
- &process_status_message, &qc);
+ queue_priority, max_queue_size, timeout,
+ &process_status_message, &qc);
if (qe == NULL)
- {
+ {
#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Could not create queue entry for PUT\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Could not create queue entry for PUT\n");
#endif
- return NULL;
- }
+ return NULL;
+ }
GNUNET_STATISTICS_update (h->stats,
- gettext_noop ("# PUT requests executed"),
- 1,
- GNUNET_NO);
- dm = (struct DataMessage* ) &qe[1];
- dm->header.type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_PUT);
- dm->header.size = htons(msize);
- dm->rid = htonl(rid);
- dm->size = htonl( (uint32_t) size);
- dm->type = htonl(type);
- dm->priority = htonl(priority);
- dm->anonymity = htonl(anonymity);
+ gettext_noop ("# PUT requests executed"),
+ 1, GNUNET_NO);
+ dm = (struct DataMessage *) &qe[1];
+ dm->header.type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_PUT);
+ dm->header.size = htons (msize);
+ dm->rid = htonl (rid);
+ dm->size = htonl ((uint32_t) size);
+ dm->type = htonl (type);
+ dm->priority = htonl (priority);
+ dm->anonymity = htonl (anonymity);
dm->replication = htonl (replication);
dm->reserved = htonl (0);
- dm->uid = GNUNET_htonll(0);
- dm->expiration = GNUNET_TIME_absolute_hton(expiration);
+ dm->uid = GNUNET_htonll (0);
+ dm->expiration = GNUNET_TIME_absolute_hton (expiration);
dm->key = *key;
memcpy (&dm[1], data, size);
process_queue (h);
@@ -987,13 +931,13 @@
*/
struct GNUNET_DATASTORE_QueueEntry *
GNUNET_DATASTORE_reserve (struct GNUNET_DATASTORE_Handle *h,
- uint64_t amount,
- uint32_t entries,
- unsigned int queue_priority,
- unsigned int max_queue_size,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_DATASTORE_ContinuationWithStatus cont,
- void *cont_cls)
+ uint64_t amount,
+ uint32_t entries,
+ unsigned int queue_priority,
+ unsigned int max_queue_size,
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_DATASTORE_ContinuationWithStatus cont,
+ void *cont_cls)
{
struct GNUNET_DATASTORE_QueueEntry *qe;
struct ReserveMessage *rm;
@@ -1003,32 +947,30 @@
cont = &drop_status_cont;
#if DEBUG_DATASTORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Asked to reserve %llu bytes of data and %u entries\n",
- (unsigned long long) amount,
- (unsigned int) entries);
+ "Asked to reserve %llu bytes of data and %u entries\n",
+ (unsigned long long) amount, (unsigned int) entries);
#endif
qc.sc.cont = cont;
qc.sc.cont_cls = cont_cls;
- qe = make_queue_entry (h, sizeof(struct ReserveMessage),
- queue_priority, max_queue_size, timeout,
- &process_status_message, &qc);
+ qe = make_queue_entry (h, sizeof (struct ReserveMessage),
+ queue_priority, max_queue_size, timeout,
+ &process_status_message, &qc);
if (qe == NULL)
- {
+ {
#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Could not create queue entry to reserve\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Could not create queue entry to reserve\n");
#endif
- return NULL;
- }
+ return NULL;
+ }
GNUNET_STATISTICS_update (h->stats,
- gettext_noop ("# RESERVE requests executed"),
- 1,
- GNUNET_NO);
- rm = (struct ReserveMessage*) &qe[1];
- rm->header.type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_RESERVE);
- rm->header.size = htons(sizeof (struct ReserveMessage));
- rm->entries = htonl(entries);
- rm->amount = GNUNET_htonll(amount);
+ gettext_noop ("# RESERVE requests executed"),
+ 1, GNUNET_NO);
+ rm = (struct ReserveMessage *) &qe[1];
+ rm->header.type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_RESERVE);
+ rm->header.size = htons (sizeof (struct ReserveMessage));
+ rm->entries = htonl (entries);
+ rm->amount = GNUNET_htonll (amount);
process_queue (h);
return qe;
}
@@ -1057,12 +999,12 @@
*/
struct GNUNET_DATASTORE_QueueEntry *
GNUNET_DATASTORE_release_reserve (struct GNUNET_DATASTORE_Handle *h,
- uint32_t rid,
- unsigned int queue_priority,
- unsigned int max_queue_size,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_DATASTORE_ContinuationWithStatus cont,
- void *cont_cls)
+ uint32_t rid,
+ unsigned int queue_priority,
+ unsigned int max_queue_size,
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_DATASTORE_ContinuationWithStatus cont,
+ void *cont_cls)
{
struct GNUNET_DATASTORE_QueueEntry *qe;
struct ReleaseReserveMessage *rrm;
@@ -1071,31 +1013,29 @@
if (cont == NULL)
cont = &drop_status_cont;
#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Asked to release reserve %d\n",
- rid);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asked to release reserve %d\n", rid);
#endif
qc.sc.cont = cont;
qc.sc.cont_cls = cont_cls;
- qe = make_queue_entry (h, sizeof(struct ReleaseReserveMessage),
- queue_priority, max_queue_size, timeout,
- &process_status_message, &qc);
+ qe = make_queue_entry (h, sizeof (struct ReleaseReserveMessage),
+ queue_priority, max_queue_size, timeout,
+ &process_status_message, &qc);
if (qe == NULL)
- {
+ {
#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Could not create queue entry to release reserve\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Could not create queue entry to release reserve\n");
#endif
- return NULL;
- }
+ return NULL;
+ }
GNUNET_STATISTICS_update (h->stats,
- gettext_noop ("# RELEASE RESERVE requests
executed"),
- 1,
- GNUNET_NO);
- rrm = (struct ReleaseReserveMessage*) &qe[1];
- rrm->header.type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_RELEASE_RESERVE);
- rrm->header.size = htons(sizeof (struct ReleaseReserveMessage));
- rrm->rid = htonl(rid);
+ gettext_noop
+ ("# RELEASE RESERVE requests executed"), 1,
+ GNUNET_NO);
+ rrm = (struct ReleaseReserveMessage *) &qe[1];
+ rrm->header.type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_RELEASE_RESERVE);
+ rrm->header.size = htons (sizeof (struct ReleaseReserveMessage));
+ rrm->rid = htonl (rid);
process_queue (h);
return qe;
}
@@ -1120,14 +1060,14 @@
*/
struct GNUNET_DATASTORE_QueueEntry *
GNUNET_DATASTORE_update (struct GNUNET_DATASTORE_Handle *h,
- uint64_t uid,
- uint32_t priority,
- struct GNUNET_TIME_Absolute expiration,
- unsigned int queue_priority,
- unsigned int max_queue_size,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_DATASTORE_ContinuationWithStatus cont,
- void *cont_cls)
+ uint64_t uid,
+ uint32_t priority,
+ struct GNUNET_TIME_Absolute expiration,
+ unsigned int queue_priority,
+ unsigned int max_queue_size,
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_DATASTORE_ContinuationWithStatus cont,
+ void *cont_cls)
{
struct GNUNET_DATASTORE_QueueEntry *qe;
struct UpdateMessage *um;
@@ -1137,34 +1077,33 @@
cont = &drop_status_cont;
#if DEBUG_DATASTORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Asked to update entry %llu raising priority by %u and expiration
to %llu\n",
- uid,
- (unsigned int) priority,
- (unsigned long long) expiration.abs_value);
+ "Asked to update entry %llu raising priority by %u and
expiration to %llu\n",
+ uid,
+ (unsigned int) priority,
+ (unsigned long long) expiration.abs_value);
#endif
qc.sc.cont = cont;
qc.sc.cont_cls = cont_cls;
- qe = make_queue_entry (h, sizeof(struct UpdateMessage),
- queue_priority, max_queue_size, timeout,
- &process_status_message, &qc);
+ qe = make_queue_entry (h, sizeof (struct UpdateMessage),
+ queue_priority, max_queue_size, timeout,
+ &process_status_message, &qc);
if (qe == NULL)
- {
+ {
#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Could not create queue entry for UPDATE\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Could not create queue entry for UPDATE\n");
#endif
- return NULL;
- }
+ return NULL;
+ }
GNUNET_STATISTICS_update (h->stats,
- gettext_noop ("# UPDATE requests executed"),
- 1,
- GNUNET_NO);
- um = (struct UpdateMessage*) &qe[1];
- um->header.type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_UPDATE);
- um->header.size = htons(sizeof (struct UpdateMessage));
- um->priority = htonl(priority);
- um->expiration = GNUNET_TIME_absolute_hton(expiration);
- um->uid = GNUNET_htonll(uid);
+ gettext_noop ("# UPDATE requests executed"),
+ 1, GNUNET_NO);
+ um = (struct UpdateMessage *) &qe[1];
+ um->header.type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_UPDATE);
+ um->header.size = htons (sizeof (struct UpdateMessage));
+ um->priority = htonl (priority);
+ um->expiration = GNUNET_TIME_absolute_hton (expiration);
+ um->uid = GNUNET_htonll (uid);
process_queue (h);
return qe;
}
@@ -1193,14 +1132,14 @@
*/
struct GNUNET_DATASTORE_QueueEntry *
GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h,
- const GNUNET_HashCode *key,
- size_t size,
- const void *data,
- unsigned int queue_priority,
- unsigned int max_queue_size,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_DATASTORE_ContinuationWithStatus cont,
- void *cont_cls)
+ const GNUNET_HashCode * key,
+ size_t size,
+ const void *data,
+ unsigned int queue_priority,
+ unsigned int max_queue_size,
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_DATASTORE_ContinuationWithStatus cont,
+ void *cont_cls)
{
struct GNUNET_DATASTORE_QueueEntry *qe;
struct DataMessage *dm;
@@ -1211,39 +1150,37 @@
cont = &drop_status_cont;
#if DEBUG_DATASTORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Asked to remove %u bytes under key `%s'\n",
- size,
- GNUNET_h2s (key));
+ "Asked to remove %u bytes under key `%s'\n",
+ size, GNUNET_h2s (key));
#endif
qc.sc.cont = cont;
qc.sc.cont_cls = cont_cls;
- msize = sizeof(struct DataMessage) + size;
+ msize = sizeof (struct DataMessage) + size;
GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE);
qe = make_queue_entry (h, msize,
- queue_priority, max_queue_size, timeout,
- &process_status_message, &qc);
+ queue_priority, max_queue_size, timeout,
+ &process_status_message, &qc);
if (qe == NULL)
- {
+ {
#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Could not create queue entry for REMOVE\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Could not create queue entry for REMOVE\n");
#endif
- return NULL;
- }
+ return NULL;
+ }
GNUNET_STATISTICS_update (h->stats,
- gettext_noop ("# REMOVE requests executed"),
- 1,
- GNUNET_NO);
- dm = (struct DataMessage*) &qe[1];
- dm->header.type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_REMOVE);
- dm->header.size = htons(msize);
- dm->rid = htonl(0);
- dm->size = htonl(size);
- dm->type = htonl(0);
- dm->priority = htonl(0);
- dm->anonymity = htonl(0);
- dm->uid = GNUNET_htonll(0);
- dm->expiration = GNUNET_TIME_absolute_hton(GNUNET_TIME_UNIT_ZERO_ABS);
+ gettext_noop ("# REMOVE requests executed"),
+ 1, GNUNET_NO);
+ dm = (struct DataMessage *) &qe[1];
+ dm->header.type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_REMOVE);
+ dm->header.size = htons (msize);
+ dm->rid = htonl (0);
+ dm->size = htonl (size);
+ dm->type = htonl (0);
+ dm->priority = htonl (0);
+ dm->anonymity = htonl (0);
+ dm->uid = GNUNET_htonll (0);
+ dm->expiration = GNUNET_TIME_absolute_hton (GNUNET_TIME_UNIT_ZERO_ABS);
dm->key = *key;
memcpy (&dm[1], data, size);
process_queue (h);
@@ -1258,9 +1195,8 @@
* @param cls closure
* @param msg message received, NULL on timeout or fatal error
*/
-static void
-process_result_message (void *cls,
- const struct GNUNET_MessageHeader *msg)
+static void
+process_result_message (void *cls, const struct GNUNET_MessageHeader *msg)
{
struct GNUNET_DATASTORE_Handle *h = cls;
struct GNUNET_DATASTORE_QueueEntry *qe;
@@ -1269,104 +1205,98 @@
int was_transmitted;
if (msg == NULL)
+ {
+ qe = h->queue_head;
+ GNUNET_assert (NULL != qe);
+ rc = qe->qc.rc;
+ was_transmitted = qe->was_transmitted;
+ free_queue_entry (qe);
+ if (was_transmitted == GNUNET_YES)
{
- qe = h->queue_head;
- GNUNET_assert (NULL != qe);
- rc = qe->qc.rc;
- was_transmitted = qe->was_transmitted;
- free_queue_entry (qe);
- if (was_transmitted == GNUNET_YES)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to receive response from database.\n"));
- do_disconnect (h);
- }
- else
- {
- process_queue (h);
- }
- if (rc.proc != NULL)
- rc.proc (rc.proc_cls,
- NULL, 0, NULL, 0, 0, 0,
- GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Failed to receive response from database.\n"));
+ do_disconnect (h);
}
- if (ntohs(msg->type) == GNUNET_MESSAGE_TYPE_DATASTORE_DATA_END)
+ else
{
- GNUNET_break (ntohs(msg->size) == sizeof(struct GNUNET_MessageHeader));
- qe = h->queue_head;
- rc = qe->qc.rc;
- GNUNET_assert (GNUNET_YES == qe->was_transmitted);
- free_queue_entry (qe);
-#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received end of result set, new queue size is %u\n",
- h->queue_size);
-#endif
- if (rc.proc != NULL)
- rc.proc (rc.proc_cls,
- NULL, 0, NULL, 0, 0, 0,
- GNUNET_TIME_UNIT_ZERO_ABS, 0);
- h->retry_time.rel_value = 0;
- h->result_count = 0;
process_queue (h);
- return;
}
+ if (rc.proc != NULL)
+ rc.proc (rc.proc_cls,
+ NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ return;
+ }
+ if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_DATASTORE_DATA_END)
+ {
+ GNUNET_break (ntohs (msg->size) == sizeof (struct GNUNET_MessageHeader));
+ qe = h->queue_head;
+ rc = qe->qc.rc;
+ GNUNET_assert (GNUNET_YES == qe->was_transmitted);
+ free_queue_entry (qe);
+#if DEBUG_DATASTORE
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received end of result set, new queue size is %u\n",
+ h->queue_size);
+#endif
+ if (rc.proc != NULL)
+ rc.proc (rc.proc_cls,
+ NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ h->retry_time.rel_value = 0;
+ h->result_count = 0;
+ process_queue (h);
+ return;
+ }
qe = h->queue_head;
GNUNET_assert (NULL != qe);
rc = qe->qc.rc;
if (GNUNET_YES != qe->was_transmitted)
- {
- GNUNET_break (0);
- free_queue_entry (qe);
- h->retry_time = GNUNET_TIME_UNIT_ZERO;
- do_disconnect (h);
- if (rc.proc != NULL)
- rc.proc (rc.proc_cls,
- NULL, 0, NULL, 0, 0, 0,
- GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
- }
- if ( (ntohs(msg->size) < sizeof(struct DataMessage)) ||
- (ntohs(msg->type) != GNUNET_MESSAGE_TYPE_DATASTORE_DATA) ||
- (ntohs(msg->size) != sizeof(struct DataMessage) + ntohl (((const struct
DataMessage*)msg)->size)) )
- {
- GNUNET_break (0);
- free_queue_entry (qe);
- h->retry_time = GNUNET_TIME_UNIT_ZERO;
- do_disconnect (h);
- if (rc.proc != NULL)
- rc.proc (rc.proc_cls,
- NULL, 0, NULL, 0, 0, 0,
- GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
- }
+ {
+ GNUNET_break (0);
+ free_queue_entry (qe);
+ h->retry_time = GNUNET_TIME_UNIT_ZERO;
+ do_disconnect (h);
+ if (rc.proc != NULL)
+ rc.proc (rc.proc_cls,
+ NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ return;
+ }
+ if ((ntohs (msg->size) < sizeof (struct DataMessage)) ||
+ (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_DATASTORE_DATA) ||
+ (ntohs (msg->size) !=
+ sizeof (struct DataMessage) +
+ ntohl (((const struct DataMessage *) msg)->size)))
+ {
+ GNUNET_break (0);
+ free_queue_entry (qe);
+ h->retry_time = GNUNET_TIME_UNIT_ZERO;
+ do_disconnect (h);
+ if (rc.proc != NULL)
+ rc.proc (rc.proc_cls,
+ NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ return;
+ }
GNUNET_STATISTICS_update (h->stats,
- gettext_noop ("# Results received"),
- 1,
- GNUNET_NO);
- dm = (const struct DataMessage*) msg;
+ gettext_noop ("# Results received"), 1, GNUNET_NO);
+ dm = (const struct DataMessage *) msg;
#if DEBUG_DATASTORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received result %llu with type %u and size %u with key %s\n",
- (unsigned long long) GNUNET_ntohll(dm->uid),
- ntohl(dm->type),
- ntohl(dm->size),
- GNUNET_h2s(&dm->key));
+ "Received result %llu with type %u and size %u with key %s\n",
+ (unsigned long long) GNUNET_ntohll (dm->uid),
+ ntohl (dm->type), ntohl (dm->size), GNUNET_h2s (&dm->key));
#endif
free_queue_entry (qe);
h->retry_time.rel_value = 0;
process_queue (h);
if (rc.proc != NULL)
rc.proc (rc.proc_cls,
- &dm->key,
- ntohl(dm->size),
- &dm[1],
- ntohl(dm->type),
- ntohl(dm->priority),
- ntohl(dm->anonymity),
- GNUNET_TIME_absolute_ntoh(dm->expiration),
- GNUNET_ntohll(dm->uid));
+ &dm->key,
+ ntohl (dm->size),
+ &dm[1],
+ ntohl (dm->type),
+ ntohl (dm->priority),
+ ntohl (dm->anonymity),
+ GNUNET_TIME_absolute_ntoh (dm->expiration),
+ GNUNET_ntohll (dm->uid));
}
@@ -1391,11 +1321,11 @@
*/
struct GNUNET_DATASTORE_QueueEntry *
GNUNET_DATASTORE_get_for_replication (struct GNUNET_DATASTORE_Handle *h,
- unsigned int queue_priority,
- unsigned int max_queue_size,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_DATASTORE_DatumProcessor proc,
- void *proc_cls)
+ unsigned int queue_priority,
+ unsigned int max_queue_size,
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_DATASTORE_DatumProcessor proc,
+ void *proc_cls)
{
struct GNUNET_DATASTORE_QueueEntry *qe;
struct GNUNET_MessageHeader *m;
@@ -1404,29 +1334,29 @@
GNUNET_assert (NULL != proc);
#if DEBUG_DATASTORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Asked to get replication entry in %llu ms\n",
- (unsigned long long) timeout.rel_value);
+ "Asked to get replication entry in %llu ms\n",
+ (unsigned long long) timeout.rel_value);
#endif
qc.rc.proc = proc;
qc.rc.proc_cls = proc_cls;
- qe = make_queue_entry (h, sizeof(struct GNUNET_MessageHeader),
- queue_priority, max_queue_size, timeout,
- &process_result_message, &qc);
+ qe = make_queue_entry (h, sizeof (struct GNUNET_MessageHeader),
+ queue_priority, max_queue_size, timeout,
+ &process_result_message, &qc);
if (qe == NULL)
- {
+ {
#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Could not create queue entry for GET REPLICATION\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Could not create queue entry for GET REPLICATION\n");
#endif
- return NULL;
- }
+ return NULL;
+ }
GNUNET_STATISTICS_update (h->stats,
- gettext_noop ("# GET REPLICATION requests
executed"),
- 1,
- GNUNET_NO);
- m = (struct GNUNET_MessageHeader*) &qe[1];
- m->type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_GET_REPLICATION);
- m->size = htons(sizeof (struct GNUNET_MessageHeader));
+ gettext_noop
+ ("# GET REPLICATION requests executed"), 1,
+ GNUNET_NO);
+ m = (struct GNUNET_MessageHeader *) &qe[1];
+ m->type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_GET_REPLICATION);
+ m->size = htons (sizeof (struct GNUNET_MessageHeader));
process_queue (h);
return qe;
}
@@ -1454,13 +1384,13 @@
*/
struct GNUNET_DATASTORE_QueueEntry *
GNUNET_DATASTORE_get_zero_anonymity (struct GNUNET_DATASTORE_Handle *h,
- uint64_t offset,
- unsigned int queue_priority,
- unsigned int max_queue_size,
- struct GNUNET_TIME_Relative timeout,
- enum GNUNET_BLOCK_Type type,
- GNUNET_DATASTORE_DatumProcessor proc,
- void *proc_cls)
+ uint64_t offset,
+ unsigned int queue_priority,
+ unsigned int max_queue_size,
+ struct GNUNET_TIME_Relative timeout,
+ enum GNUNET_BLOCK_Type type,
+ GNUNET_DATASTORE_DatumProcessor proc,
+ void *proc_cls)
{
struct GNUNET_DATASTORE_QueueEntry *qe;
struct GetZeroAnonymityMessage *m;
@@ -1470,31 +1400,30 @@
GNUNET_assert (type != GNUNET_BLOCK_TYPE_ANY);
#if DEBUG_DATASTORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Asked to get %llu-th zero-anonymity entry of type %d in %llu
ms\n",
- (unsigned long long) offset,
- type,
- (unsigned long long) timeout.rel_value);
+ "Asked to get %llu-th zero-anonymity entry of type %d in %llu
ms\n",
+ (unsigned long long) offset,
+ type, (unsigned long long) timeout.rel_value);
#endif
qc.rc.proc = proc;
qc.rc.proc_cls = proc_cls;
- qe = make_queue_entry (h, sizeof(struct GetZeroAnonymityMessage),
- queue_priority, max_queue_size, timeout,
- &process_result_message, &qc);
+ qe = make_queue_entry (h, sizeof (struct GetZeroAnonymityMessage),
+ queue_priority, max_queue_size, timeout,
+ &process_result_message, &qc);
if (qe == NULL)
- {
+ {
#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Could not create queue entry for zero-anonymity
procation\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Could not create queue entry for zero-anonymity procation\n");
#endif
- return NULL;
- }
+ return NULL;
+ }
GNUNET_STATISTICS_update (h->stats,
- gettext_noop ("# GET ZERO ANONYMITY requests
executed"),
- 1,
- GNUNET_NO);
- m = (struct GetZeroAnonymityMessage*) &qe[1];
- m->header.type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_GET_ZERO_ANONYMITY);
- m->header.size = htons(sizeof (struct GetZeroAnonymityMessage));
+ gettext_noop
+ ("# GET ZERO ANONYMITY requests executed"), 1,
+ GNUNET_NO);
+ m = (struct GetZeroAnonymityMessage *) &qe[1];
+ m->header.type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_GET_ZERO_ANONYMITY);
+ m->header.size = htons (sizeof (struct GetZeroAnonymityMessage));
m->type = htonl ((uint32_t) type);
m->offset = GNUNET_htonll (offset);
process_queue (h);
@@ -1525,14 +1454,13 @@
*/
struct GNUNET_DATASTORE_QueueEntry *
GNUNET_DATASTORE_get_key (struct GNUNET_DATASTORE_Handle *h,
- uint64_t offset,
- const GNUNET_HashCode * key,
- enum GNUNET_BLOCK_Type type,
- unsigned int queue_priority,
- unsigned int max_queue_size,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_DATASTORE_DatumProcessor proc,
- void *proc_cls)
+ uint64_t offset,
+ const GNUNET_HashCode * key,
+ enum GNUNET_BLOCK_Type type,
+ unsigned int queue_priority,
+ unsigned int max_queue_size,
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_DATASTORE_DatumProcessor proc, void *proc_cls)
{
struct GNUNET_DATASTORE_QueueEntry *qe;
struct GetMessage *gm;
@@ -1541,41 +1469,39 @@
GNUNET_assert (NULL != proc);
#if DEBUG_DATASTORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Asked to look for data of type %u under key `%s'\n",
- (unsigned int) type,
- GNUNET_h2s (key));
+ "Asked to look for data of type %u under key `%s'\n",
+ (unsigned int) type, GNUNET_h2s (key));
#endif
qc.rc.proc = proc;
qc.rc.proc_cls = proc_cls;
- qe = make_queue_entry (h, sizeof(struct GetMessage),
- queue_priority, max_queue_size, timeout,
- &process_result_message, &qc);
+ qe = make_queue_entry (h, sizeof (struct GetMessage),
+ queue_priority, max_queue_size, timeout,
+ &process_result_message, &qc);
if (qe == NULL)
- {
+ {
#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Could not queue request for `%s'\n",
- GNUNET_h2s (key));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Could not queue request for `%s'\n", GNUNET_h2s (key));
#endif
- return NULL;
- }
+ return NULL;
+ }
GNUNET_STATISTICS_update (h->stats,
- gettext_noop ("# GET requests executed"),
- 1,
- GNUNET_NO);
- gm = (struct GetMessage*) &qe[1];
- gm->header.type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_GET);
- gm->type = htonl(type);
+ gettext_noop ("# GET requests executed"),
+ 1, GNUNET_NO);
+ gm = (struct GetMessage *) &qe[1];
+ gm->header.type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_GET);
+ gm->type = htonl (type);
gm->offset = GNUNET_htonll (offset);
if (key != NULL)
- {
- gm->header.size = htons(sizeof (struct GetMessage));
- gm->key = *key;
- }
+ {
+ gm->header.size = htons (sizeof (struct GetMessage));
+ gm->key = *key;
+ }
else
- {
- gm->header.size = htons(sizeof (struct GetMessage) -
sizeof(GNUNET_HashCode));
- }
+ {
+ gm->header.size =
+ htons (sizeof (struct GetMessage) - sizeof (GNUNET_HashCode));
+ }
process_queue (h);
return qe;
}
@@ -1595,18 +1521,16 @@
GNUNET_assert (GNUNET_SYSERR != qe->was_transmitted);
h = qe->h;
#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Pending DATASTORE request %p cancelled (%d, %d)\n",
- qe,
- qe->was_transmitted,
- h->queue_head == qe);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Pending DATASTORE request %p cancelled (%d, %d)\n",
+ qe, qe->was_transmitted, h->queue_head == qe);
#endif
- if (GNUNET_YES == qe->was_transmitted)
- {
- free_queue_entry (qe);
- h->skip_next_messages++;
- return;
- }
+ if (GNUNET_YES == qe->was_transmitted)
+ {
+ free_queue_entry (qe);
+ h->skip_next_messages++;
+ return;
+ }
free_queue_entry (qe);
process_queue (h);
}
Modified: gnunet/src/datastore/gnunet-service-datastore.c
===================================================================
--- gnunet/src/datastore/gnunet-service-datastore.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/datastore/gnunet-service-datastore.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -92,7 +92,7 @@
/**
* Linked list of active reservations.
*/
-struct ReservationList
+struct ReservationList
{
/**
@@ -161,7 +161,7 @@
* How much space have we currently reserved?
*/
static unsigned long long reserved;
-
+
/**
* How much data are we currently storing
* in the database?
@@ -202,13 +202,10 @@
* Synchronize our utilization statistics with the
* statistics service.
*/
-static void
+static void
sync_stats ()
{
- GNUNET_STATISTICS_set (stats,
- QUOTA_STAT_NAME,
- payload,
- GNUNET_YES);
+ GNUNET_STATISTICS_set (stats, QUOTA_STAT_NAME, payload, GNUNET_YES);
lastSync = 0;
}
@@ -217,24 +214,24 @@
/**
* Context for transmitting replies to clients.
*/
-struct TransmitCallbackContext
+struct TransmitCallbackContext
{
-
+
/**
* We keep these in a doubly-linked list (for cleanup).
*/
struct TransmitCallbackContext *next;
-
+
/**
* We keep these in a doubly-linked list (for cleanup).
*/
struct TransmitCallbackContext *prev;
-
+
/**
* The message that we're asked to transmit.
*/
struct GNUNET_MessageHeader *msg;
-
+
/**
* Handle for the transmission request.
*/
@@ -247,7 +244,7 @@
};
-
+
/**
* Head of the doubly-linked list (for cleanup).
*/
@@ -278,10 +275,9 @@
*
* @param cls not used
* @param tc task context
- */
+ */
static void
-delete_expired (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+delete_expired (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
/**
@@ -304,55 +300,46 @@
* (continue on call to "next", of course),
* GNUNET_NO to delete the item and continue (if supported)
*/
-static int
+static int
expired_processor (void *cls,
- const GNUNET_HashCode * key,
- uint32_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- struct GNUNET_TIME_Absolute
- expiration,
- uint64_t uid)
+ const GNUNET_HashCode * key,
+ uint32_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute expiration, uint64_t uid)
{
struct GNUNET_TIME_Absolute now;
- if (key == NULL)
- {
- expired_kill_task
- = GNUNET_SCHEDULER_add_delayed (MAX_EXPIRE_DELAY,
- &delete_expired,
- NULL);
- return GNUNET_SYSERR;
- }
+ if (key == NULL)
+ {
+ expired_kill_task
+ = GNUNET_SCHEDULER_add_delayed (MAX_EXPIRE_DELAY,
+ &delete_expired, NULL);
+ return GNUNET_SYSERR;
+ }
now = GNUNET_TIME_absolute_get ();
if (expiration.abs_value > now.abs_value)
- {
- /* finished processing */
- expired_kill_task
- = GNUNET_SCHEDULER_add_delayed (MAX_EXPIRE_DELAY,
- &delete_expired,
- NULL);
- return GNUNET_SYSERR;
- }
+ {
+ /* finished processing */
+ expired_kill_task
+ = GNUNET_SCHEDULER_add_delayed (MAX_EXPIRE_DELAY,
+ &delete_expired, NULL);
+ return GNUNET_SYSERR;
+ }
#if DEBUG_DATASTORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Deleting content `%s' of type %u that expired %llu ms ago\n",
- GNUNET_h2s (key),
- type,
- (unsigned long long) (now.abs_value - expiration.abs_value));
+ "Deleting content `%s' of type %u that expired %llu ms ago\n",
+ GNUNET_h2s (key),
+ type,
+ (unsigned long long) (now.abs_value - expiration.abs_value));
#endif
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# bytes expired"),
- size,
- GNUNET_YES);
- GNUNET_CONTAINER_bloomfilter_remove (filter,
- key);
- expired_kill_task
- = GNUNET_SCHEDULER_add_delayed (MIN_EXPIRE_DELAY,
- &delete_expired,
- NULL);
+ gettext_noop ("# bytes expired"), size,
GNUNET_YES);
+ GNUNET_CONTAINER_bloomfilter_remove (filter, key);
+ expired_kill_task
+ = GNUNET_SCHEDULER_add_delayed (MIN_EXPIRE_DELAY, &delete_expired, NULL);
return GNUNET_NO;
}
@@ -365,15 +352,12 @@
*
* @param cls not used
* @param tc task context
- */
+ */
static void
-delete_expired (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+delete_expired (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
expired_kill_task = GNUNET_SCHEDULER_NO_TASK;
- plugin->api->get_expiration (plugin->api->cls,
- &expired_processor,
- NULL);
+ plugin->api->get_expiration (plugin->api->cls, &expired_processor, NULL);
}
@@ -396,39 +380,34 @@
* (continue on call to "next", of course),
* GNUNET_NO to delete the item and continue (if supported)
*/
-static int
+static int
quota_processor (void *cls,
- const GNUNET_HashCode * key,
- uint32_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- struct GNUNET_TIME_Absolute expiration,
- uint64_t uid)
+ const GNUNET_HashCode * key,
+ uint32_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute expiration, uint64_t uid)
{
unsigned long long *need = cls;
if (NULL == key)
- return GNUNET_SYSERR;
+ return GNUNET_SYSERR;
#if DEBUG_DATASTORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Deleting %llu bytes of low-priority content `%s' of type %u
(still trying to free another %llu bytes)\n",
- (unsigned long long) (size + GNUNET_DATASTORE_ENTRY_OVERHEAD),
- GNUNET_h2s (key),
- type,
- *need);
+ "Deleting %llu bytes of low-priority content `%s' of type %u
(still trying to free another %llu bytes)\n",
+ (unsigned long long) (size + GNUNET_DATASTORE_ENTRY_OVERHEAD),
+ GNUNET_h2s (key), type, *need);
#endif
if (size + GNUNET_DATASTORE_ENTRY_OVERHEAD > *need)
*need = 0;
else
*need -= size + GNUNET_DATASTORE_ENTRY_OVERHEAD;
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# bytes purged (low-priority)"),
- size,
- GNUNET_YES);
- GNUNET_CONTAINER_bloomfilter_remove (filter,
- key);
+ gettext_noop ("# bytes purged (low-priority)"),
+ size, GNUNET_YES);
+ GNUNET_CONTAINER_bloomfilter_remove (filter, key);
return GNUNET_NO;
}
@@ -452,18 +431,14 @@
#if DEBUG_DATASTORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Asked to free up %llu bytes of cache space\n",
- need);
+ "Asked to free up %llu bytes of cache space\n", need);
#endif
last = 0;
- while ( (need > 0) &&
- (last != need) )
- {
- last = need;
- plugin->api->get_expiration (plugin->api->cls,
- "a_processor,
- &need);
- }
+ while ((need > 0) && (last != need))
+ {
+ last = need;
+ plugin->api->get_expiration (plugin->api->cls, "a_processor, &need);
+ }
}
@@ -479,27 +454,24 @@
* @return number of bytes written to buf
*/
static size_t
-transmit_callback (void *cls,
- size_t size, void *buf)
+transmit_callback (void *cls, size_t size, void *buf)
{
struct TransmitCallbackContext *tcc = cls;
size_t msize;
-
+
tcc->th = NULL;
- GNUNET_CONTAINER_DLL_remove (tcc_head,
- tcc_tail,
- tcc);
- msize = ntohs(tcc->msg->size);
+ GNUNET_CONTAINER_DLL_remove (tcc_head, tcc_tail, tcc);
+ msize = ntohs (tcc->msg->size);
if (size == 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Transmission to client failed!\n"));
- GNUNET_SERVER_receive_done (tcc->client, GNUNET_SYSERR);
- GNUNET_SERVER_client_drop (tcc->client);
- GNUNET_free (tcc->msg);
- GNUNET_free (tcc);
- return 0;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Transmission to client failed!\n"));
+ GNUNET_SERVER_receive_done (tcc->client, GNUNET_SYSERR);
+ GNUNET_SERVER_client_drop (tcc->client);
+ GNUNET_free (tcc->msg);
+ GNUNET_free (tcc);
+ return 0;
+ }
GNUNET_assert (size >= msize);
memcpy (buf, tcc->msg, msize);
GNUNET_SERVER_receive_done (tcc->client, GNUNET_OK);
@@ -517,41 +489,37 @@
* @param msg message to transmit, will be freed!
*/
static void
-transmit (struct GNUNET_SERVER_Client *client,
- struct GNUNET_MessageHeader *msg)
+transmit (struct GNUNET_SERVER_Client *client, struct GNUNET_MessageHeader
*msg)
{
struct TransmitCallbackContext *tcc;
if (GNUNET_YES == cleaning_done)
- {
+ {
#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Shutdown in progress, aborting transmission.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Shutdown in progress, aborting transmission.\n");
#endif
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- GNUNET_free (msg);
- return;
- }
- tcc = GNUNET_malloc (sizeof(struct TransmitCallbackContext));
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ GNUNET_free (msg);
+ return;
+ }
+ tcc = GNUNET_malloc (sizeof (struct TransmitCallbackContext));
tcc->msg = msg;
tcc->client = client;
if (NULL ==
(tcc->th = GNUNET_SERVER_notify_transmit_ready (client,
- ntohs(msg->size),
-
GNUNET_TIME_UNIT_FOREVER_REL,
- &transmit_callback,
- tcc)))
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- GNUNET_free (msg);
- GNUNET_free (tcc);
- return;
- }
+ ntohs (msg->size),
+
GNUNET_TIME_UNIT_FOREVER_REL,
+ &transmit_callback,
tcc)))
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ GNUNET_free (msg);
+ GNUNET_free (tcc);
+ return;
+ }
GNUNET_SERVER_client_keep (client);
- GNUNET_CONTAINER_DLL_insert (tcc_head,
- tcc_tail,
- tcc);
+ GNUNET_CONTAINER_DLL_insert (tcc_head, tcc_tail, tcc);
}
@@ -563,27 +531,23 @@
* @param msg optional error message (can be NULL)
*/
static void
-transmit_status (struct GNUNET_SERVER_Client *client,
- int code,
- const char *msg)
+transmit_status (struct GNUNET_SERVER_Client *client, int code, const char
*msg)
{
struct StatusMessage *sm;
size_t slen;
#if DEBUG_DATASTORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitting `%s' message with value %d and message `%s'\n",
- "STATUS",
- code,
- msg != NULL ? msg : "(none)");
+ "Transmitting `%s' message with value %d and message `%s'\n",
+ "STATUS", code, msg != NULL ? msg : "(none)");
#endif
- slen = (msg == NULL) ? 0 : strlen(msg) + 1;
- sm = GNUNET_malloc (sizeof(struct StatusMessage) + slen);
- sm->header.size = htons(sizeof(struct StatusMessage) + slen);
- sm->header.type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_STATUS);
- sm->status = htonl(code);
+ slen = (msg == NULL) ? 0 : strlen (msg) + 1;
+ sm = GNUNET_malloc (sizeof (struct StatusMessage) + slen);
+ sm->header.size = htons (sizeof (struct StatusMessage) + slen);
+ sm->header.type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_STATUS);
+ sm->status = htonl (code);
if (slen > 0)
- memcpy (&sm[1], msg, slen);
+ memcpy (&sm[1], msg, slen);
transmit (client, &sm->header);
}
@@ -609,62 +573,59 @@
*/
static int
transmit_item (void *cls,
- const GNUNET_HashCode * key,
- uint32_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- struct GNUNET_TIME_Absolute
- expiration, uint64_t uid)
+ const GNUNET_HashCode * key,
+ uint32_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute expiration, uint64_t uid)
{
struct GNUNET_SERVER_Client *client = cls;
struct GNUNET_MessageHeader *end;
struct DataMessage *dm;
if (key == NULL)
- {
- /* transmit 'DATA_END' */
+ {
+ /* transmit 'DATA_END' */
#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitting `%s' message\n",
- "DATA_END");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Transmitting `%s' message\n", "DATA_END");
#endif
- end = GNUNET_malloc (sizeof(struct GNUNET_MessageHeader));
- end->size = htons(sizeof(struct GNUNET_MessageHeader));
- end->type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_DATA_END);
- transmit (client, end);
- GNUNET_SERVER_client_drop (client);
- return GNUNET_OK;
- }
- GNUNET_assert (sizeof (struct DataMessage) + size <
GNUNET_SERVER_MAX_MESSAGE_SIZE);
- dm = GNUNET_malloc (sizeof(struct DataMessage) + size);
- dm->header.size = htons(sizeof(struct DataMessage) + size);
- dm->header.type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_DATA);
- dm->rid = htonl(0);
- dm->size = htonl(size);
- dm->type = htonl(type);
- dm->priority = htonl(priority);
- dm->anonymity = htonl(anonymity);
+ end = GNUNET_malloc (sizeof (struct GNUNET_MessageHeader));
+ end->size = htons (sizeof (struct GNUNET_MessageHeader));
+ end->type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_DATA_END);
+ transmit (client, end);
+ GNUNET_SERVER_client_drop (client);
+ return GNUNET_OK;
+ }
+ GNUNET_assert (sizeof (struct DataMessage) + size <
+ GNUNET_SERVER_MAX_MESSAGE_SIZE);
+ dm = GNUNET_malloc (sizeof (struct DataMessage) + size);
+ dm->header.size = htons (sizeof (struct DataMessage) + size);
+ dm->header.type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_DATA);
+ dm->rid = htonl (0);
+ dm->size = htonl (size);
+ dm->type = htonl (type);
+ dm->priority = htonl (priority);
+ dm->anonymity = htonl (anonymity);
dm->replication = htonl (0);
dm->reserved = htonl (0);
- dm->expiration = GNUNET_TIME_absolute_hton(expiration);
- dm->uid = GNUNET_htonll(uid);
+ dm->expiration = GNUNET_TIME_absolute_hton (expiration);
+ dm->uid = GNUNET_htonll (uid);
dm->key = *key;
memcpy (&dm[1], data, size);
#if DEBUG_DATASTORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitting `%s' message for `%s' of type %u with expiration
%llu (now: %llu)\n",
- "DATA",
- GNUNET_h2s (key),
- type,
- (unsigned long long) expiration.abs_value,
- (unsigned long long) GNUNET_TIME_absolute_get ().abs_value);
+ "Transmitting `%s' message for `%s' of type %u with expiration
%llu (now: %llu)\n",
+ "DATA",
+ GNUNET_h2s (key),
+ type,
+ (unsigned long long) expiration.abs_value,
+ (unsigned long long) GNUNET_TIME_absolute_get ().abs_value);
#endif
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# results found"),
- 1,
- GNUNET_NO);
+ gettext_noop ("# results found"), 1, GNUNET_NO);
transmit (client, &dm->header);
GNUNET_SERVER_client_drop (client);
return GNUNET_OK;
@@ -680,15 +641,15 @@
*/
static void
handle_reserve (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
/**
* Static counter to produce reservation identifiers.
*/
static int reservation_gen;
- const struct ReserveMessage *msg = (const struct ReserveMessage*) message;
+ const struct ReserveMessage *msg = (const struct ReserveMessage *) message;
struct ReservationList *e;
unsigned long long used;
unsigned long long req;
@@ -696,51 +657,48 @@
uint32_t entries;
#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Processing `%s' request\n",
- "RESERVE");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing `%s' request\n", "RESERVE");
#endif
- amount = GNUNET_ntohll(msg->amount);
- entries = ntohl(msg->entries);
+ amount = GNUNET_ntohll (msg->amount);
+ entries = ntohl (msg->entries);
used = payload + reserved;
- req = amount + ((unsigned long long) GNUNET_DATASTORE_ENTRY_OVERHEAD) *
entries;
+ req =
+ amount + ((unsigned long long) GNUNET_DATASTORE_ENTRY_OVERHEAD) *
entries;
if (used + req > quota)
+ {
+ if (quota < used)
+ used = quota; /* cheat a bit for error message (to avoid
negative numbers) */
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Insufficient space (%llu bytes are available) to satisfy
`%s' request for %llu bytes\n"),
+ quota - used, "RESERVE", req);
+ if (cache_size < req)
{
- if (quota < used)
- used = quota; /* cheat a bit for error message (to avoid negative
numbers) */
+ /* TODO: document this in the FAQ; essentially, if this
+ * message happens, the insertion request could be blocked
+ * by less-important content from migration because it is
+ * larger than 1/8th of the overall available space, and
+ * we only reserve 1/8th for "fresh" insertions */
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Insufficient space (%llu bytes are available) to satisfy
`%s' request for %llu bytes\n"),
- quota - used,
- "RESERVE",
- req);
- if (cache_size < req)
- {
- /* TODO: document this in the FAQ; essentially, if this
- message happens, the insertion request could be blocked
- by less-important content from migration because it is
- larger than 1/8th of the overall available space, and
- we only reserve 1/8th for "fresh" insertions */
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("The requested amount (%llu bytes) is larger than the
cache size (%llu bytes)\n"),
- req,
- cache_size);
- transmit_status (client, 0,
- gettext_noop ("Insufficient space to satisfy request
and "
- "requested amount is larger than cache
size"));
- }
- else
- {
- transmit_status (client, 0,
- gettext_noop ("Insufficient space to satisfy
request"));
- }
- return;
+ _
+ ("The requested amount (%llu bytes) is larger than the cache
size (%llu bytes)\n"),
+ req, cache_size);
+ transmit_status (client, 0,
+ gettext_noop
+ ("Insufficient space to satisfy request and "
+ "requested amount is larger than cache size"));
}
+ else
+ {
+ transmit_status (client, 0,
+ gettext_noop ("Insufficient space to satisfy request"));
+ }
+ return;
+ }
reserved += req;
GNUNET_STATISTICS_set (stats,
- gettext_noop ("# reserved"),
- reserved,
- GNUNET_NO);
- e = GNUNET_malloc (sizeof(struct ReservationList));
+ gettext_noop ("# reserved"), reserved, GNUNET_NO);
+ e = GNUNET_malloc (sizeof (struct ReservationList));
e->next = reservations;
reservations = e;
e->client = client;
@@ -748,7 +706,7 @@
e->entries = entries;
e->rid = ++reservation_gen;
if (reservation_gen < 0)
- reservation_gen = 0; /* wrap around */
+ reservation_gen = 0; /* wrap around */
transmit_status (client, e->rid, NULL);
}
@@ -762,52 +720,53 @@
*/
static void
handle_release_reserve (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
- const struct ReleaseReserveMessage *msg = (const struct
ReleaseReserveMessage*) message;
+ const struct ReleaseReserveMessage *msg =
+ (const struct ReleaseReserveMessage *) message;
struct ReservationList *pos;
struct ReservationList *prev;
struct ReservationList *next;
- int rid = ntohl(msg->rid);
+ int rid = ntohl (msg->rid);
unsigned long long rem;
#if DEBUG_DATASTORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Processing `%s' request\n",
- "RELEASE_RESERVE");
+ "Processing `%s' request\n", "RELEASE_RESERVE");
#endif
next = reservations;
prev = NULL;
while (NULL != (pos = next))
+ {
+ next = pos->next;
+ if (rid == pos->rid)
{
- next = pos->next;
- if (rid == pos->rid)
- {
- if (prev == NULL)
- reservations = next;
- else
- prev->next = next;
- rem = pos->amount + ((unsigned long long)
GNUNET_DATASTORE_ENTRY_OVERHEAD) * pos->entries;
- GNUNET_assert (reserved >= rem);
- reserved -= rem;
- GNUNET_STATISTICS_set (stats,
- gettext_noop ("# reserved"),
- reserved,
- GNUNET_NO);
+ if (prev == NULL)
+ reservations = next;
+ else
+ prev->next = next;
+ rem =
+ pos->amount +
+ ((unsigned long long) GNUNET_DATASTORE_ENTRY_OVERHEAD) *
pos->entries;
+ GNUNET_assert (reserved >= rem);
+ reserved -= rem;
+ GNUNET_STATISTICS_set (stats,
+ gettext_noop ("# reserved"), reserved, GNUNET_NO);
#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Returning %llu remaining reserved bytes to storage
pool\n",
- rem);
-#endif
- GNUNET_free (pos);
- transmit_status (client, GNUNET_OK, NULL);
- return;
- }
- prev = pos;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Returning %llu remaining reserved bytes to storage pool\n",
+ rem);
+#endif
+ GNUNET_free (pos);
+ transmit_status (client, GNUNET_OK, NULL);
+ return;
}
+ prev = pos;
+ }
GNUNET_break (0);
- transmit_status (client, GNUNET_SYSERR, gettext_noop ("Could not find
matching reservation"));
+ transmit_status (client, GNUNET_SYSERR,
+ gettext_noop ("Could not find matching reservation"));
}
@@ -823,19 +782,19 @@
uint32_t dsize;
const struct DataMessage *dm;
- size = ntohs(message->size);
- if (size < sizeof(struct DataMessage))
- {
- GNUNET_break (0);
- return NULL;
- }
+ size = ntohs (message->size);
+ if (size < sizeof (struct DataMessage))
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
dm = (const struct DataMessage *) message;
- dsize = ntohl(dm->size);
- if (size != dsize + sizeof(struct DataMessage))
- {
- GNUNET_break (0);
- return NULL;
- }
+ dsize = ntohl (dm->size);
+ if (size != dsize + sizeof (struct DataMessage))
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
return dm;
}
@@ -853,8 +812,8 @@
#if ! HAVE_UNALIGNED_64_ACCESS
void *reserved;
-#endif
-
+#endif
+
/* followed by the 'struct DataMessage' */
};
@@ -863,54 +822,46 @@
* Actually put the data message.
*/
static void
-execute_put (struct GNUNET_SERVER_Client *client,
- const struct DataMessage *dm)
+execute_put (struct GNUNET_SERVER_Client *client, const struct DataMessage *dm)
{
uint32_t size;
char *msg;
int ret;
- size = ntohl(dm->size);
+ size = ntohl (dm->size);
msg = NULL;
ret = plugin->api->put (plugin->api->cls,
- &dm->key,
- size,
- &dm[1],
- ntohl(dm->type),
- ntohl(dm->priority),
- ntohl(dm->anonymity),
- ntohl(dm->replication),
- GNUNET_TIME_absolute_ntoh(dm->expiration),
- &msg);
+ &dm->key,
+ size,
+ &dm[1],
+ ntohl (dm->type),
+ ntohl (dm->priority),
+ ntohl (dm->anonymity),
+ ntohl (dm->replication),
+ GNUNET_TIME_absolute_ntoh (dm->expiration), &msg);
if (GNUNET_OK == ret)
- {
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# bytes stored"),
- size,
- GNUNET_YES);
- GNUNET_CONTAINER_bloomfilter_add (filter,
- &dm->key);
+ {
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# bytes stored"),
+ size, GNUNET_YES);
+ GNUNET_CONTAINER_bloomfilter_add (filter, &dm->key);
#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Successfully stored %u bytes of type %u under key `%s'\n",
- size,
- ntohl(dm->type),
- GNUNET_h2s (&dm->key));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Successfully stored %u bytes of type %u under key `%s'\n",
+ size, ntohl (dm->type), GNUNET_h2s (&dm->key));
#endif
- }
- transmit_status (client,
- ret,
- msg);
+ }
+ transmit_status (client, ret, msg);
GNUNET_free_non_null (msg);
if (quota - reserved - cache_size < payload)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Need %llu bytes more space (%llu allowed, using %llu)\n"),
- (unsigned long long) size + GNUNET_DATASTORE_ENTRY_OVERHEAD,
- (unsigned long long) (quota - reserved - cache_size),
- (unsigned long long) payload);
- manage_space (size + GNUNET_DATASTORE_ENTRY_OVERHEAD);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Need %llu bytes more space (%llu allowed, using %llu)\n"),
+ (unsigned long long) size + GNUNET_DATASTORE_ENTRY_OVERHEAD,
+ (unsigned long long) (quota - reserved - cache_size),
+ (unsigned long long) payload);
+ manage_space (size + GNUNET_DATASTORE_ENTRY_OVERHEAD);
+ }
}
@@ -934,56 +885,51 @@
*/
static int
check_present (void *cls,
- const GNUNET_HashCode * key,
- uint32_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- struct GNUNET_TIME_Absolute
- expiration, uint64_t uid)
+ const GNUNET_HashCode * key,
+ uint32_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute expiration, uint64_t uid)
{
struct PutContext *pc = cls;
const struct DataMessage *dm;
- dm = (const struct DataMessage*) &pc[1];
+ dm = (const struct DataMessage *) &pc[1];
if (key == NULL)
- {
- execute_put (pc->client, dm);
- GNUNET_SERVER_client_drop (pc->client);
- GNUNET_free (pc);
- return GNUNET_OK;
- }
- if ( (GNUNET_BLOCK_TYPE_FS_DBLOCK == type) ||
- (GNUNET_BLOCK_TYPE_FS_IBLOCK == type) ||
- ( (size == ntohl(dm->size)) &&
- (0 == memcmp (&dm[1],
- data,
- size)) ) )
- {
+ {
+ execute_put (pc->client, dm);
+ GNUNET_SERVER_client_drop (pc->client);
+ GNUNET_free (pc);
+ return GNUNET_OK;
+ }
+ if ((GNUNET_BLOCK_TYPE_FS_DBLOCK == type) ||
+ (GNUNET_BLOCK_TYPE_FS_IBLOCK == type) ||
+ ((size == ntohl (dm->size)) && (0 == memcmp (&dm[1], data, size))))
+ {
#if DEBUG_MYSQL
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Result already present in datastore\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Result already present in datastore\n");
#endif
- /* FIXME: change API to allow increasing 'replication' counter */
- if ( (ntohl (dm->priority) > 0) ||
- (GNUNET_TIME_absolute_ntoh(dm->expiration).abs_value >
- expiration.abs_value) )
- plugin->api->update (plugin->api->cls,
- uid,
- (int32_t) ntohl(dm->priority),
- GNUNET_TIME_absolute_ntoh(dm->expiration),
- NULL);
- transmit_status (pc->client, GNUNET_NO, NULL);
- GNUNET_SERVER_client_drop (pc->client);
- GNUNET_free (pc);
- }
+ /* FIXME: change API to allow increasing 'replication' counter */
+ if ((ntohl (dm->priority) > 0) ||
+ (GNUNET_TIME_absolute_ntoh (dm->expiration).abs_value >
+ expiration.abs_value))
+ plugin->api->update (plugin->api->cls,
+ uid,
+ (int32_t) ntohl (dm->priority),
+ GNUNET_TIME_absolute_ntoh (dm->expiration), NULL);
+ transmit_status (pc->client, GNUNET_NO, NULL);
+ GNUNET_SERVER_client_drop (pc->client);
+ GNUNET_free (pc);
+ }
else
- {
- execute_put (pc->client, dm);
- GNUNET_SERVER_client_drop (pc->client);
- GNUNET_free (pc);
- }
+ {
+ execute_put (pc->client, dm);
+ GNUNET_SERVER_client_drop (pc->client);
+ GNUNET_free (pc);
+ }
return GNUNET_OK;
}
@@ -997,8 +943,8 @@
*/
static void
handle_put (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
const struct DataMessage *dm = check_data (message);
int rid;
@@ -1007,59 +953,50 @@
GNUNET_HashCode vhash;
uint32_t size;
- if ( (dm == NULL) ||
- (ntohl(dm->type) == 0) )
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ if ((dm == NULL) || (ntohl (dm->type) == 0))
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
#if DEBUG_DATASTORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Processing `%s' request for `%s' of type %u\n",
- "PUT",
- GNUNET_h2s (&dm->key),
- ntohl (dm->type));
+ "Processing `%s' request for `%s' of type %u\n",
+ "PUT", GNUNET_h2s (&dm->key), ntohl (dm->type));
#endif
- rid = ntohl(dm->rid);
- size = ntohl(dm->size);
+ rid = ntohl (dm->rid);
+ size = ntohl (dm->size);
if (rid > 0)
+ {
+ pos = reservations;
+ while ((NULL != pos) && (rid != pos->rid))
+ pos = pos->next;
+ GNUNET_break (pos != NULL);
+ if (NULL != pos)
{
- pos = reservations;
- while ( (NULL != pos) &&
- (rid != pos->rid) )
- pos = pos->next;
- GNUNET_break (pos != NULL);
- if (NULL != pos)
- {
- GNUNET_break (pos->entries > 0);
- GNUNET_break (pos->amount >= size);
- pos->entries--;
- pos->amount -= size;
- reserved -= (size + GNUNET_DATASTORE_ENTRY_OVERHEAD);
- GNUNET_STATISTICS_set (stats,
- gettext_noop ("# reserved"),
- reserved,
- GNUNET_NO);
- }
+ GNUNET_break (pos->entries > 0);
+ GNUNET_break (pos->amount >= size);
+ pos->entries--;
+ pos->amount -= size;
+ reserved -= (size + GNUNET_DATASTORE_ENTRY_OVERHEAD);
+ GNUNET_STATISTICS_set (stats,
+ gettext_noop ("# reserved"), reserved, GNUNET_NO);
}
- if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (filter,
- &dm->key))
- {
- GNUNET_CRYPTO_hash (&dm[1], size, &vhash);
- pc = GNUNET_malloc (sizeof (struct PutContext) + size + sizeof (struct
DataMessage));
- pc->client = client;
- GNUNET_SERVER_client_keep (client);
- memcpy (&pc[1], dm, size + sizeof (struct DataMessage));
- plugin->api->get_key (plugin->api->cls,
- 0,
- &dm->key,
- &vhash,
- ntohl (dm->type),
- &check_present,
- pc);
- return;
- }
+ }
+ if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (filter, &dm->key))
+ {
+ GNUNET_CRYPTO_hash (&dm[1], size, &vhash);
+ pc = GNUNET_malloc (sizeof (struct PutContext) + size +
+ sizeof (struct DataMessage));
+ pc->client = client;
+ GNUNET_SERVER_client_keep (client);
+ memcpy (&pc[1], dm, size + sizeof (struct DataMessage));
+ plugin->api->get_key (plugin->api->cls,
+ 0,
+ &dm->key,
+ &vhash, ntohl (dm->type), &check_present, pc);
+ return;
+ }
execute_put (client, dm);
}
@@ -1073,60 +1010,52 @@
*/
static void
handle_get (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
const struct GetMessage *msg;
uint16_t size;
- size = ntohs(message->size);
- if ( (size != sizeof(struct GetMessage)) &&
- (size != sizeof(struct GetMessage) - sizeof(GNUNET_HashCode)) )
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
- msg = (const struct GetMessage*) message;
+ size = ntohs (message->size);
+ if ((size != sizeof (struct GetMessage)) &&
+ (size != sizeof (struct GetMessage) - sizeof (GNUNET_HashCode)))
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
+ msg = (const struct GetMessage *) message;
#if DEBUG_DATASTORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Processing `%s' request for `%s' of type %u\n",
- "GET",
- GNUNET_h2s (&msg->key),
- ntohl (msg->type));
+ "Processing `%s' request for `%s' of type %u\n",
+ "GET", GNUNET_h2s (&msg->key), ntohl (msg->type));
#endif
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# GET requests received"),
- 1,
- GNUNET_NO);
+ gettext_noop ("# GET requests received"),
+ 1, GNUNET_NO);
GNUNET_SERVER_client_keep (client);
- if ( (size == sizeof(struct GetMessage)) &&
- (GNUNET_YES != GNUNET_CONTAINER_bloomfilter_test (filter,
- &msg->key)) )
- {
- /* don't bother database... */
+ if ((size == sizeof (struct GetMessage)) &&
+ (GNUNET_YES != GNUNET_CONTAINER_bloomfilter_test (filter, &msg->key)))
+ {
+ /* don't bother database... */
#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Empty result set for `%s' request for `%s' (bloomfilter).\n",
- "GET",
- GNUNET_h2s (&msg->key));
-#endif
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# requests filtered by
bloomfilter"),
- 1,
- GNUNET_NO);
- transmit_item (client,
- NULL, 0, NULL, 0, 0, 0,
- GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Empty result set for `%s' request for `%s' (bloomfilter).\n",
+ "GET", GNUNET_h2s (&msg->key));
+#endif
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# requests filtered by bloomfilter"), 1,
+ GNUNET_NO);
+ transmit_item (client, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS,
+ 0);
+ return;
+ }
plugin->api->get_key (plugin->api->cls,
- GNUNET_ntohll (msg->offset),
- ((size == sizeof(struct GetMessage)) ? &msg->key :
NULL),
- NULL,
- ntohl(msg->type),
- &transmit_item,
- client);
+ GNUNET_ntohll (msg->offset),
+ ((size ==
+ sizeof (struct GetMessage)) ? &msg->key : NULL),
NULL,
+ ntohl (msg->type), &transmit_item, client);
}
@@ -1139,30 +1068,28 @@
*/
static void
handle_update (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
const struct UpdateMessage *msg;
int ret;
char *emsg;
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# UPDATE requests received"),
- 1,
- GNUNET_NO);
- msg = (const struct UpdateMessage*) message;
+ gettext_noop ("# UPDATE requests received"),
+ 1, GNUNET_NO);
+ msg = (const struct UpdateMessage *) message;
emsg = NULL;
#if DEBUG_DATASTORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Processing `%s' request for %llu\n",
- "UPDATE",
- (unsigned long long) GNUNET_ntohll (msg->uid));
+ "Processing `%s' request for %llu\n",
+ "UPDATE", (unsigned long long) GNUNET_ntohll (msg->uid));
#endif
ret = plugin->api->update (plugin->api->cls,
- GNUNET_ntohll(msg->uid),
- (int32_t) ntohl(msg->priority),
- GNUNET_TIME_absolute_ntoh(msg->expiration),
- &emsg);
+ GNUNET_ntohll (msg->uid),
+ (int32_t) ntohl (msg->priority),
+ GNUNET_TIME_absolute_ntoh (msg->expiration),
+ &emsg);
transmit_status (client, ret, emsg);
GNUNET_free_non_null (emsg);
}
@@ -1177,22 +1104,19 @@
*/
static void
handle_get_replication (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
#if DEBUG_DATASTORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Processing `%s' request\n",
- "GET_REPLICATION");
+ "Processing `%s' request\n", "GET_REPLICATION");
#endif
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# GET REPLICATION requests
received"),
- 1,
- GNUNET_NO);
+ gettext_noop
+ ("# GET REPLICATION requests received"), 1,
+ GNUNET_NO);
GNUNET_SERVER_client_keep (client);
- plugin->api->get_replication (plugin->api->cls,
- &transmit_item,
- client);
+ plugin->api->get_replication (plugin->api->cls, &transmit_item, client);
}
@@ -1205,34 +1129,32 @@
*/
static void
handle_get_zero_anonymity (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
- const struct GetZeroAnonymityMessage * msg = (const struct
GetZeroAnonymityMessage*) message;
+ const struct GetZeroAnonymityMessage *msg =
+ (const struct GetZeroAnonymityMessage *) message;
enum GNUNET_BLOCK_Type type;
type = (enum GNUNET_BLOCK_Type) ntohl (msg->type);
if (type == GNUNET_BLOCK_TYPE_ANY)
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
#if DEBUG_DATASTORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Processing `%s' request\n",
- "GET_ZERO_ANONYMITY");
+ "Processing `%s' request\n", "GET_ZERO_ANONYMITY");
#endif
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# GET ZERO ANONYMITY requests
received"),
- 1,
- GNUNET_NO);
+ gettext_noop
+ ("# GET ZERO ANONYMITY requests received"), 1,
+ GNUNET_NO);
GNUNET_SERVER_client_keep (client);
plugin->api->get_zero_anonymity (plugin->api->cls,
- GNUNET_ntohll (msg->offset),
- type,
- &transmit_item,
- client);
+ GNUNET_ntohll (msg->offset),
+ type, &transmit_item, client);
}
@@ -1242,43 +1164,36 @@
*/
static int
remove_callback (void *cls,
- const GNUNET_HashCode * key,
- uint32_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- struct GNUNET_TIME_Absolute
- expiration, uint64_t uid)
+ const GNUNET_HashCode * key,
+ uint32_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute expiration, uint64_t uid)
{
struct GNUNET_SERVER_Client *client = cls;
if (key == NULL)
- {
+ {
#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "No further matches for `%s' request.\n",
- "REMOVE");
-#endif
- transmit_status (client, GNUNET_NO, _("Content not found"));
- GNUNET_SERVER_client_drop (client);
- return GNUNET_OK; /* last item */
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "No further matches for `%s' request.\n", "REMOVE");
+#endif
+ transmit_status (client, GNUNET_NO, _("Content not found"));
+ GNUNET_SERVER_client_drop (client);
+ return GNUNET_OK; /* last item */
+ }
#if DEBUG_DATASTORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Item %llu matches `%s' request for key `%s' and type %u.\n",
- (unsigned long long) uid,
- "REMOVE",
- GNUNET_h2s (key),
- type);
-#endif
+ "Item %llu matches `%s' request for key `%s' and type %u.\n",
+ (unsigned long long) uid, "REMOVE", GNUNET_h2s (key), type);
+#endif
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# bytes removed (explicit request)"),
- size,
- GNUNET_YES);
- GNUNET_CONTAINER_bloomfilter_remove (filter,
- key);
- transmit_status (client, GNUNET_OK, NULL);
+ gettext_noop ("# bytes removed (explicit
request)"),
+ size, GNUNET_YES);
+ GNUNET_CONTAINER_bloomfilter_remove (filter, key);
+ transmit_status (client, GNUNET_OK, NULL);
GNUNET_SERVER_client_drop (client);
return GNUNET_NO;
}
@@ -1293,40 +1208,34 @@
*/
static void
handle_remove (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
const struct DataMessage *dm = check_data (message);
GNUNET_HashCode vhash;
if (dm == NULL)
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
#if DEBUG_DATASTORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Processing `%s' request for `%s' of type %u\n",
- "REMOVE",
- GNUNET_h2s (&dm->key),
- ntohl (dm->type));
+ "Processing `%s' request for `%s' of type %u\n",
+ "REMOVE", GNUNET_h2s (&dm->key), ntohl (dm->type));
#endif
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# REMOVE requests received"),
- 1,
- GNUNET_NO);
+ gettext_noop ("# REMOVE requests received"),
+ 1, GNUNET_NO);
GNUNET_SERVER_client_keep (client);
- GNUNET_CRYPTO_hash (&dm[1],
- ntohl(dm->size),
- &vhash);
+ GNUNET_CRYPTO_hash (&dm[1], ntohl (dm->size), &vhash);
plugin->api->get_key (plugin->api->cls,
- 0,
- &dm->key,
- &vhash,
- (enum GNUNET_BLOCK_Type) ntohl(dm->type),
- &remove_callback,
- client);
+ 0,
+ &dm->key,
+ &vhash,
+ (enum GNUNET_BLOCK_Type) ntohl (dm->type),
+ &remove_callback, client);
}
@@ -1339,13 +1248,11 @@
*/
static void
handle_drop (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Processing `%s' request\n",
- "DROP");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing `%s' request\n", "DROP");
#endif
do_drop = GNUNET_YES;
GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -1361,20 +1268,18 @@
* 0 for "reset to empty"
*/
static void
-disk_utilization_change_cb (void *cls,
- int delta)
+disk_utilization_change_cb (void *cls, int delta)
{
- if ( (delta < 0) &&
- (payload < -delta) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Datastore payload inaccurate (%lld < %lld). Trying to
fix.\n"),
- (long long) payload,
- (long long) -delta);
- payload = plugin->api->estimate_size (plugin->api->cls);
- sync_stats ();
- return;
- }
+ if ((delta < 0) && (payload < -delta))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Datastore payload inaccurate (%lld < %lld). Trying to
fix.\n"),
+ (long long) payload, (long long) -delta);
+ payload = plugin->api->estimate_size (plugin->api->cls);
+ sync_stats ();
+ return;
+ }
payload += delta;
lastSync++;
if (lastSync >= MAX_STAT_SYNC_LAG)
@@ -1394,32 +1299,28 @@
*/
static int
process_stat_in (void *cls,
- const char *subsystem,
- const char *name,
- uint64_t value,
- int is_persistent)
+ const char *subsystem,
+ const char *name, uint64_t value, int is_persistent)
{
GNUNET_assert (stats_worked == GNUNET_NO);
stats_worked = GNUNET_YES;
payload += value;
#if DEBUG_SQLITE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Notification from statistics about existing payload (%llu), new
payload is %llu\n",
- abs_value,
- payload);
+ "Notification from statistics about existing payload (%llu), new
payload is %llu\n",
+ abs_value, payload);
#endif
return GNUNET_OK;
}
static void
-process_stat_done (void *cls,
- int success)
+process_stat_done (void *cls, int success)
{
struct DatastorePlugin *plugin = cls;
stat_get = NULL;
- if (stats_worked == GNUNET_NO)
+ if (stats_worked == GNUNET_NO)
payload = plugin->api->estimate_size (plugin->api->cls);
}
@@ -1428,7 +1329,7 @@
* Load the datastore plugin.
*/
static struct DatastorePlugin *
-load_plugin ()
+load_plugin ()
{
struct DatastorePlugin *ret;
char *libname;
@@ -1437,14 +1338,13 @@
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
"DATASTORE", "DATABASE", &name))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("No `%s' specified for `%s' in configuration!\n"),
- "DATABASE",
- "DATASTORE");
- return NULL;
- }
- ret = GNUNET_malloc (sizeof(struct DatastorePlugin));
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("No `%s' specified for `%s' in configuration!\n"),
+ "DATABASE", "DATASTORE");
+ return NULL;
+ }
+ ret = GNUNET_malloc (sizeof (struct DatastorePlugin));
ret->env.cfg = cfg;
ret->env.duc = &disk_utilization_change_cb;
ret->env.cls = NULL;
@@ -1455,14 +1355,14 @@
ret->lib_name = libname;
ret->api = GNUNET_PLUGIN_load (libname, &ret->env);
if (ret->api == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to load datastore plugin for `%s'\n"), name);
- GNUNET_free (ret->short_name);
- GNUNET_free (libname);
- GNUNET_free (ret);
- return NULL;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to load datastore plugin for `%s'\n"), name);
+ GNUNET_free (ret->short_name);
+ GNUNET_free (libname);
+ GNUNET_free (ret);
+ return NULL;
+ }
return ret;
}
@@ -1492,30 +1392,29 @@
* statistics.
*/
static void
-unload_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+unload_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
if (GNUNET_YES == do_drop)
plugin->api->drop (plugin->api->cls);
unload_plugin (plugin);
plugin = NULL;
if (filter != NULL)
- {
- GNUNET_CONTAINER_bloomfilter_free (filter);
- filter = NULL;
- }
+ {
+ GNUNET_CONTAINER_bloomfilter_free (filter);
+ filter = NULL;
+ }
if (lastSync > 0)
sync_stats ();
if (stat_get != NULL)
- {
- GNUNET_STATISTICS_get_cancel (stat_get);
- stat_get = NULL;
- }
+ {
+ GNUNET_STATISTICS_get_cancel (stat_get);
+ stat_get = NULL;
+ }
if (stats != NULL)
- {
- GNUNET_STATISTICS_destroy (stats, GNUNET_YES);
- stats = NULL;
- }
+ {
+ GNUNET_STATISTICS_destroy (stats, GNUNET_YES);
+ stats = NULL;
+ }
}
@@ -1524,33 +1423,29 @@
* the transport and core.
*/
static void
-cleaning_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct TransmitCallbackContext *tcc;
cleaning_done = GNUNET_YES;
while (NULL != (tcc = tcc_head))
+ {
+ GNUNET_CONTAINER_DLL_remove (tcc_head, tcc_tail, tcc);
+ if (tcc->th != NULL)
{
- GNUNET_CONTAINER_DLL_remove (tcc_head,
- tcc_tail,
- tcc);
- if (tcc->th != NULL)
- {
- GNUNET_CONNECTION_notify_transmit_ready_cancel (tcc->th);
- GNUNET_SERVER_client_drop (tcc->client);
- }
- GNUNET_free (tcc->msg);
- GNUNET_free (tcc);
+ GNUNET_CONNECTION_notify_transmit_ready_cancel (tcc->th);
+ GNUNET_SERVER_client_drop (tcc->client);
}
+ GNUNET_free (tcc->msg);
+ GNUNET_free (tcc);
+ }
if (expired_kill_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (expired_kill_task);
- expired_kill_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (expired_kill_task);
+ expired_kill_task = GNUNET_SCHEDULER_NO_TASK;
+ }
GNUNET_SCHEDULER_add_continuation (&unload_task,
- NULL,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ NULL,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
}
@@ -1563,8 +1458,7 @@
* @param client identification of the client
*/
static void
-cleanup_reservations (void *cls,
- struct GNUNET_SERVER_Client *client)
+cleanup_reservations (void *cls, struct GNUNET_SERVER_Client *client)
{
struct ReservationList *pos;
struct ReservationList *prev;
@@ -1575,27 +1469,25 @@
prev = NULL;
pos = reservations;
while (NULL != pos)
+ {
+ next = pos->next;
+ if (pos->client == client)
{
- next = pos->next;
- if (pos->client == client)
- {
- if (prev == NULL)
- reservations = next;
- else
- prev->next = next;
- reserved -= pos->amount + pos->entries *
GNUNET_DATASTORE_ENTRY_OVERHEAD;
- GNUNET_free (pos);
- }
+ if (prev == NULL)
+ reservations = next;
else
- {
- prev = pos;
- }
- pos = next;
+ prev->next = next;
+ reserved -= pos->amount + pos->entries * GNUNET_DATASTORE_ENTRY_OVERHEAD;
+ GNUNET_free (pos);
}
+ else
+ {
+ prev = pos;
+ }
+ pos = next;
+ }
GNUNET_STATISTICS_set (stats,
- gettext_noop ("# reserved"),
- reserved,
- GNUNET_NO);
+ gettext_noop ("# reserved"), reserved, GNUNET_NO);
}
@@ -1612,21 +1504,24 @@
const struct GNUNET_CONFIGURATION_Handle *c)
{
static const struct GNUNET_SERVER_MessageHandler handlers[] = {
- {&handle_reserve, NULL, GNUNET_MESSAGE_TYPE_DATASTORE_RESERVE,
- sizeof(struct ReserveMessage) },
- {&handle_release_reserve, NULL,
GNUNET_MESSAGE_TYPE_DATASTORE_RELEASE_RESERVE,
- sizeof(struct ReleaseReserveMessage) },
- {&handle_put, NULL, GNUNET_MESSAGE_TYPE_DATASTORE_PUT, 0 },
- {&handle_update, NULL, GNUNET_MESSAGE_TYPE_DATASTORE_UPDATE,
- sizeof (struct UpdateMessage) },
- {&handle_get, NULL, GNUNET_MESSAGE_TYPE_DATASTORE_GET, 0 },
- {&handle_get_replication, NULL,
GNUNET_MESSAGE_TYPE_DATASTORE_GET_REPLICATION,
- sizeof(struct GNUNET_MessageHeader) },
- {&handle_get_zero_anonymity, NULL,
GNUNET_MESSAGE_TYPE_DATASTORE_GET_ZERO_ANONYMITY,
- sizeof(struct GetZeroAnonymityMessage) },
- {&handle_remove, NULL, GNUNET_MESSAGE_TYPE_DATASTORE_REMOVE, 0 },
- {&handle_drop, NULL, GNUNET_MESSAGE_TYPE_DATASTORE_DROP,
- sizeof(struct GNUNET_MessageHeader) },
+ {&handle_reserve, NULL, GNUNET_MESSAGE_TYPE_DATASTORE_RESERVE,
+ sizeof (struct ReserveMessage)},
+ {&handle_release_reserve, NULL,
+ GNUNET_MESSAGE_TYPE_DATASTORE_RELEASE_RESERVE,
+ sizeof (struct ReleaseReserveMessage)},
+ {&handle_put, NULL, GNUNET_MESSAGE_TYPE_DATASTORE_PUT, 0},
+ {&handle_update, NULL, GNUNET_MESSAGE_TYPE_DATASTORE_UPDATE,
+ sizeof (struct UpdateMessage)},
+ {&handle_get, NULL, GNUNET_MESSAGE_TYPE_DATASTORE_GET, 0},
+ {&handle_get_replication, NULL,
+ GNUNET_MESSAGE_TYPE_DATASTORE_GET_REPLICATION,
+ sizeof (struct GNUNET_MessageHeader)},
+ {&handle_get_zero_anonymity, NULL,
+ GNUNET_MESSAGE_TYPE_DATASTORE_GET_ZERO_ANONYMITY,
+ sizeof (struct GetZeroAnonymityMessage)},
+ {&handle_remove, NULL, GNUNET_MESSAGE_TYPE_DATASTORE_REMOVE, 0},
+ {&handle_drop, NULL, GNUNET_MESSAGE_TYPE_DATASTORE_DROP,
+ sizeof (struct GNUNET_MessageHeader)},
{NULL, NULL, 0, 0}
};
char *fn;
@@ -1634,81 +1529,72 @@
cfg = c;
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (cfg,
- "DATASTORE", "QUOTA", "a))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("No `%s' specified for `%s' in configuration!\n"),
- "QUOTA",
- "DATASTORE");
- return;
- }
+ GNUNET_CONFIGURATION_get_value_number (cfg, "DATASTORE", "QUOTA",
"a))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("No `%s' specified for `%s' in configuration!\n"),
+ "QUOTA", "DATASTORE");
+ return;
+ }
stats = GNUNET_STATISTICS_create ("datastore", cfg);
+ GNUNET_STATISTICS_set (stats, gettext_noop ("# quota"), quota, GNUNET_NO);
+ cache_size = quota / 8; /* Or should we make this an option? */
GNUNET_STATISTICS_set (stats,
- gettext_noop ("# quota"),
- quota,
- GNUNET_NO);
- cache_size = quota / 8; /* Or should we make this an option? */
- GNUNET_STATISTICS_set (stats,
- gettext_noop ("# cache size"),
- cache_size,
- GNUNET_NO);
- bf_size = quota / 32; /* 8 bit per entry, 1 bit per 32 kb in DB */
+ gettext_noop ("# cache size"), cache_size, GNUNET_NO);
+ bf_size = quota / 32; /* 8 bit per entry, 1 bit per 32 kb in DB */
fn = NULL;
- if ( (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (cfg,
- "DATASTORE",
- "BLOOMFILTER",
- &fn)) ||
- (GNUNET_OK !=
- GNUNET_DISK_directory_create_for_file (fn)) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Could not use specified filename `%s' for bloomfilter.\n"),
- fn != NULL ? fn : "");
- GNUNET_free_non_null (fn);
- fn = NULL;
- }
+ if ((GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_filename (cfg,
+ "DATASTORE",
+ "BLOOMFILTER",
+ &fn)) ||
+ (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Could not use specified filename `%s' for bloomfilter.\n"),
+ fn != NULL ? fn : "");
+ GNUNET_free_non_null (fn);
+ fn = NULL;
+ }
if (fn != NULL)
- filter = GNUNET_CONTAINER_bloomfilter_load (fn, bf_size, 5); /* approx.
3% false positives at max use */
+ filter = GNUNET_CONTAINER_bloomfilter_load (fn, bf_size, 5); /*
approx. 3% false positives at max use */
else
- filter = GNUNET_CONTAINER_bloomfilter_init (NULL, bf_size, 5); /* approx.
3% false positives at max use */
+ filter = GNUNET_CONTAINER_bloomfilter_init (NULL, bf_size, 5); /*
approx. 3% false positives at max use */
GNUNET_free_non_null (fn);
if (filter == NULL)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to initialize bloomfilter.\n"));
+ if (stats != NULL)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to initialize bloomfilter.\n"));
- if (stats != NULL)
- {
- GNUNET_STATISTICS_destroy (stats, GNUNET_YES);
- stats = NULL;
- }
- return;
+ GNUNET_STATISTICS_destroy (stats, GNUNET_YES);
+ stats = NULL;
}
+ return;
+ }
plugin = load_plugin ();
if (NULL == plugin)
+ {
+ GNUNET_CONTAINER_bloomfilter_free (filter);
+ filter = NULL;
+ if (stats != NULL)
{
- GNUNET_CONTAINER_bloomfilter_free (filter);
- filter = NULL;
- if (stats != NULL)
- {
- GNUNET_STATISTICS_destroy (stats, GNUNET_YES);
- stats = NULL;
- }
- return;
+ GNUNET_STATISTICS_destroy (stats, GNUNET_YES);
+ stats = NULL;
}
+ return;
+ }
stat_get = GNUNET_STATISTICS_get (stats,
- "datastore",
- QUOTA_STAT_NAME,
- GNUNET_TIME_UNIT_SECONDS,
- &process_stat_done,
- &process_stat_in,
- plugin);
+ "datastore",
+ QUOTA_STAT_NAME,
+ GNUNET_TIME_UNIT_SECONDS,
+ &process_stat_done,
+ &process_stat_in, plugin);
GNUNET_SERVER_disconnect_notify (server, &cleanup_reservations, NULL);
GNUNET_SERVER_add_handlers (server, handlers);
expired_kill_task
- = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
- &delete_expired, NULL);
+ = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
+ &delete_expired, NULL);
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
&cleaning_task, NULL);
}
@@ -1730,8 +1616,7 @@
GNUNET_SERVICE_run (argc,
argv,
"datastore",
- GNUNET_SERVICE_OPTION_NONE,
- &run, NULL)) ? 0 : 1;
+ GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
return ret;
}
Modified: gnunet/src/datastore/perf_datastore_api.c
===================================================================
--- gnunet/src/datastore/perf_datastore_api.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/datastore/perf_datastore_api.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -84,13 +84,13 @@
static int ok;
enum RunPhase
- {
- RP_DONE = 0,
- RP_PUT,
- RP_CUT,
- RP_REPORT,
- RP_ERROR
- };
+{
+ RP_DONE = 0,
+ RP_PUT,
+ RP_CUT,
+ RP_REPORT,
+ RP_ERROR
+};
struct CpsRunContext
@@ -105,28 +105,23 @@
static void
-run_continuation (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
static void
-check_success (void *cls,
- int success,
- const char *msg)
+check_success (void *cls, int success, const char *msg)
{
struct CpsRunContext *crc = cls;
if (GNUNET_OK != success)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Check success failed: `%s'\n", msg);
- crc->phase = RP_ERROR;
- GNUNET_SCHEDULER_add_now (&run_continuation,
- crc);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Check success failed: `%s'\n", msg);
+ crc->phase = RP_ERROR;
+ GNUNET_SCHEDULER_add_now (&run_continuation, crc);
+ return;
+ }
#if REPORT_ID
fprintf (stderr, "I");
#endif
@@ -135,17 +130,16 @@
stored_entries++;
crc->j++;
if (crc->j >= PUT_10)
- {
- crc->j = 0;
- crc->i++;
- if (crc->i == ITERATIONS)
- crc->phase = RP_DONE;
- else
- crc->phase = RP_CUT;
- }
+ {
+ crc->j = 0;
+ crc->i++;
+ if (crc->i == ITERATIONS)
+ crc->phase = RP_DONE;
+ else
+ crc->phase = RP_CUT;
+ }
GNUNET_SCHEDULER_add_continuation (&run_continuation,
- crc,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
}
@@ -157,41 +151,35 @@
* @param success GNUNET_SYSERR on failure
* @param msg NULL on success, otherwise an error message
*/
-static void
-remove_next(void *cls,
- int success,
- const char *msg)
+static void
+remove_next (void *cls, int success, const char *msg)
{
struct CpsRunContext *crc = cls;
if (GNUNET_OK != success)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "remove_next failed: `%s'\n", msg);
- crc->phase = RP_ERROR;
- GNUNET_SCHEDULER_add_now (&run_continuation,
- crc);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "remove_next failed: `%s'\n", msg);
+ crc->phase = RP_ERROR;
+ GNUNET_SCHEDULER_add_now (&run_continuation, crc);
+ return;
+ }
#if REPORT_ID
fprintf (stderr, "D");
#endif
GNUNET_assert (GNUNET_OK == success);
- GNUNET_SCHEDULER_add_now (&run_continuation,
- crc);
+ GNUNET_SCHEDULER_add_now (&run_continuation, crc);
}
-static void
+static void
delete_value (void *cls,
- const GNUNET_HashCode *key,
- size_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- struct GNUNET_TIME_Absolute
- expiration, uint64_t uid)
+ const GNUNET_HashCode * key,
+ size_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute expiration, uint64_t uid)
{
struct CpsRunContext *crc = cls;
@@ -203,19 +191,16 @@
if (stored_bytes < MAX_SIZE)
crc->phase = RP_PUT;
GNUNET_assert (NULL !=
- GNUNET_DATASTORE_remove (datastore,
- key,
- size,
- data,
- 1, 1, TIMEOUT,
- &remove_next,
- crc));
+ GNUNET_DATASTORE_remove (datastore,
+ key,
+ size,
+ data,
+ 1, 1, TIMEOUT, &remove_next, crc));
}
static void
-run_continuation (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct CpsRunContext *crc = cls;
size_t size;
@@ -227,133 +212,127 @@
ok = (int) crc->phase;
switch (crc->phase)
- {
- case RP_PUT:
- memset (&key, 256 - crc->i, sizeof (GNUNET_HashCode));
- i = crc->j;
- k = crc->i;
- /* most content is 32k */
- size = 32 * 1024;
- if (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16) == 0) /*
but some of it is less! */
- size = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 32 * 1024);
- crc->size = size = size - (size & 7); /* always multiple of 8 */
- GNUNET_CRYPTO_hash (&key, sizeof (GNUNET_HashCode), &key);
- memset (data, i, size);
- if (i > 255)
- memset (data, i - 255, size / 2);
- data[0] = k;
- GNUNET_assert (NULL !=
- GNUNET_DATASTORE_put (datastore,
- 0,
- &key,
- size,
- data,
- i+1,
- GNUNET_CRYPTO_random_u32
(GNUNET_CRYPTO_QUALITY_WEAK, 100),
- i, 0,
- GNUNET_TIME_relative_to_absolute
- (GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_SECONDS,
-
GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1000))),
- 1, 1, TIMEOUT,
- &check_success,
- crc));
- break;
- case RP_CUT:
- /* trim down below MAX_SIZE again */
- GNUNET_assert (NULL !=
- GNUNET_DATASTORE_get_for_replication (datastore,
- 1, 1, TIMEOUT,
- &delete_value,
- crc));
- break;
- case RP_REPORT:
- printf (
+ {
+ case RP_PUT:
+ memset (&key, 256 - crc->i, sizeof (GNUNET_HashCode));
+ i = crc->j;
+ k = crc->i;
+ /* most content is 32k */
+ size = 32 * 1024;
+ if (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16) == 0) /* but
some of it is less! */
+ size = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 32 * 1024);
+ crc->size = size = size - (size & 7); /* always multiple of 8 */
+ GNUNET_CRYPTO_hash (&key, sizeof (GNUNET_HashCode), &key);
+ memset (data, i, size);
+ if (i > 255)
+ memset (data, i - 255, size / 2);
+ data[0] = k;
+ GNUNET_assert (NULL !=
+ GNUNET_DATASTORE_put (datastore,
+ 0,
+ &key,
+ size,
+ data,
+ i + 1,
+ GNUNET_CRYPTO_random_u32
+ (GNUNET_CRYPTO_QUALITY_WEAK, 100), i,
+ 0,
+ GNUNET_TIME_relative_to_absolute
+ (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS,
+ GNUNET_CRYPTO_random_u32
+ (GNUNET_CRYPTO_QUALITY_WEAK,
1000))),
+ 1, 1, TIMEOUT, &check_success, crc));
+ break;
+ case RP_CUT:
+ /* trim down below MAX_SIZE again */
+ GNUNET_assert (NULL !=
+ GNUNET_DATASTORE_get_for_replication (datastore,
+ 1, 1, TIMEOUT,
+ &delete_value, crc));
+ break;
+ case RP_REPORT:
+ printf (
#if REPORT_ID
- "\n"
+ "\n"
#endif
- "Stored %llu kB / %lluk ops / %llu ops/s\n",
- stored_bytes / 1024, /* used size in k */
- stored_ops / 1024, /* total operations (in k) */
- 1000 * stored_ops / (1 +
GNUNET_TIME_absolute_get_duration(start_time).rel_value));
- crc->phase = RP_PUT;
- crc->j = 0;
- GNUNET_SCHEDULER_add_continuation (&run_continuation,
- crc,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- break;
- case RP_DONE:
- GNUNET_snprintf (gstr, sizeof (gstr),
- "DATASTORE-%s",
- plugin_name);
- if ( (crc->i == ITERATIONS) &&
- (stored_ops > 0) )
- GAUGER (gstr,
- "PUT operation duration",
- GNUNET_TIME_absolute_get_duration(start_time).rel_value /
stored_ops,
- "ms/operation");
- GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES);
- GNUNET_free (crc);
- ok = 0;
- break;
- case RP_ERROR:
- GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES);
- GNUNET_free (crc);
- ok = 1;
- break;
- default:
- GNUNET_assert (0);
- }
+ "Stored %llu kB / %lluk ops / %llu ops/s\n", stored_bytes / 1024,
/* used size in k */
+ stored_ops / 1024, /* total operations (in k) */
+ 1000 * stored_ops / (1 +
+ GNUNET_TIME_absolute_get_duration
+ (start_time).rel_value));
+ crc->phase = RP_PUT;
+ crc->j = 0;
+ GNUNET_SCHEDULER_add_continuation (&run_continuation,
+ crc,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ break;
+ case RP_DONE:
+ GNUNET_snprintf (gstr, sizeof (gstr), "DATASTORE-%s", plugin_name);
+ if ((crc->i == ITERATIONS) && (stored_ops > 0))
+ GAUGER (gstr,
+ "PUT operation duration",
+ GNUNET_TIME_absolute_get_duration (start_time).rel_value /
+ stored_ops, "ms/operation");
+ GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES);
+ GNUNET_free (crc);
+ ok = 0;
+ break;
+ case RP_ERROR:
+ GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES);
+ GNUNET_free (crc);
+ ok = 1;
+ break;
+ default:
+ GNUNET_assert (0);
+ }
}
static void
-run_tests (void *cls,
- int success,
- const char *msg)
+run_tests (void *cls, int success, const char *msg)
{
struct CpsRunContext *crc = cls;
if (success != GNUNET_YES)
- {
- fprintf (stderr,
- "Test 'put' operation failed with error `%s' database likely not
setup, skipping test.",
- msg);
- GNUNET_free (crc);
- return;
- }
+ {
+ fprintf (stderr,
+ "Test 'put' operation failed with error `%s' database likely not
setup, skipping test.",
+ msg);
+ GNUNET_free (crc);
+ return;
+ }
GNUNET_SCHEDULER_add_continuation (&run_continuation,
- crc,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
}
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
struct CpsRunContext *crc;
static GNUNET_HashCode zkey;
datastore = GNUNET_DATASTORE_connect (cfg);
start_time = GNUNET_TIME_absolute_get ();
- crc = GNUNET_malloc(sizeof(struct CpsRunContext));
+ crc = GNUNET_malloc (sizeof (struct CpsRunContext));
crc->cfg = cfg;
crc->phase = RP_PUT;
if (NULL ==
GNUNET_DATASTORE_put (datastore, 0,
- &zkey, 4, "TEST",
- GNUNET_BLOCK_TYPE_TEST,
- 0, 0, 0, GNUNET_TIME_relative_to_absolute
(GNUNET_TIME_UNIT_SECONDS),
- 0, 1, GNUNET_TIME_UNIT_MINUTES,
- &run_tests, crc))
- {
- fprintf (stderr,
- "Test 'put' operation failed.\n");
- ok = 1;
- GNUNET_free (crc);
- }
+ &zkey, 4, "TEST",
+ GNUNET_BLOCK_TYPE_TEST,
+ 0, 0, 0,
+ GNUNET_TIME_relative_to_absolute
+ (GNUNET_TIME_UNIT_SECONDS), 0, 1,
+ GNUNET_TIME_UNIT_MINUTES, &run_tests, crc))
+ {
+ fprintf (stderr, "Test 'put' operation failed.\n");
+ ok = 1;
+ GNUNET_free (crc);
+ }
}
@@ -362,7 +341,8 @@
{
struct GNUNET_OS_Process *proc;
char cfg_name[128];
- char *const argv[] = {
+
+ char *const argv[] = {
"perf-datastore-api",
"-c",
cfg_name,
@@ -376,25 +356,24 @@
};
GNUNET_snprintf (cfg_name,
- sizeof (cfg_name),
- "test_datastore_api_data_%s.conf",
- plugin_name);
+ sizeof (cfg_name),
+ "test_datastore_api_data_%s.conf", plugin_name);
proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
- "gnunet-service-arm",
+ "gnunet-service-arm",
#if VERBOSE
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", cfg_name, NULL);
+ "-c", cfg_name, NULL);
GNUNET_assert (NULL != proc);
GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
argv, "perf-datastore-api", "nohelp",
options, &run, NULL);
- sleep (1); /* give datastore chance to process 'DROP' */
+ sleep (1); /* give datastore chance to process 'DROP' */
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;
@@ -412,21 +391,20 @@
sleep (1);
/* determine name of plugin to use */
plugin_name = argv[0];
- while (NULL != (pos = strstr(plugin_name, "_")))
- plugin_name = pos+1;
- if (NULL != (pos = strstr(plugin_name, ".")))
+ while (NULL != (pos = strstr (plugin_name, "_")))
+ plugin_name = pos + 1;
+ if (NULL != (pos = strstr (plugin_name, ".")))
pos[0] = 0;
else
pos = (char *) plugin_name;
GNUNET_snprintf (dir_name,
- sizeof (dir_name),
- "/tmp/test-gnunet-datastore-%s",
- plugin_name);
+ sizeof (dir_name),
+ "/tmp/test-gnunet-datastore-%s", plugin_name);
GNUNET_DISK_directory_remove (dir_name);
GNUNET_log_setup ("perf-datastore-api",
#if VERBOSE
- "DEBUG",
+ "DEBUG",
#else
"WARNING",
#endif
Modified: gnunet/src/datastore/perf_plugin_datastore.c
===================================================================
--- gnunet/src/datastore/perf_plugin_datastore.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/datastore/perf_plugin_datastore.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -61,14 +61,14 @@
static int ok;
enum RunPhase
- {
- RP_ERROR = 0,
- RP_PUT,
- RP_REP_GET,
- RP_ZA_GET,
- RP_EXP_GET,
- RP_DONE
- };
+{
+ RP_ERROR = 0,
+ RP_PUT,
+ RP_REP_GET,
+ RP_ZA_GET,
+ RP_EXP_GET,
+ RP_DONE
+};
struct CpsRunContext
@@ -77,7 +77,7 @@
struct GNUNET_TIME_Absolute start;
struct GNUNET_TIME_Absolute end;
const struct GNUNET_CONFIGURATION_Handle *cfg;
- struct GNUNET_DATASTORE_PluginFunctions * api;
+ struct GNUNET_DATASTORE_PluginFunctions *api;
enum RunPhase phase;
unsigned int cnt;
unsigned int iter;
@@ -94,15 +94,13 @@
* 0 for "reset to empty"
*/
static void
-disk_utilization_change_cb (void *cls,
- int delta)
+disk_utilization_change_cb (void *cls, int delta)
{
}
-
+
static void
-putValue (struct GNUNET_DATASTORE_PluginFunctions * api,
- int i, int k)
+putValue (struct GNUNET_DATASTORE_PluginFunctions *api, int i, int k)
{
char value[65536];
size_t size;
@@ -113,7 +111,7 @@
/* most content is 32k */
size = 32 * 1024;
- if (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16) == 0) /* but
some of it is less! */
+ if (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16) == 0) /* but
some of it is less! */
size = 8 + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 32 *
1024);
size = size - (size & 7); /* always multiple of 8 */
@@ -127,46 +125,38 @@
memcpy (&value[4], &i, sizeof (i));
msg = NULL;
prio = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100);
- if (GNUNET_OK != api->put (api->cls,
- &key,
- size,
- value,
- 1 + i % 4 /* type */,
- prio,
- i % 4 /* anonymity */,
- 0 /* replication */,
- GNUNET_TIME_relative_to_absolute
- (GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_MILLISECONDS,
- 60 * 60 * 60 *
1000 +
-
GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1000))),
- &msg))
- {
- fprintf (stderr, "ERROR: `%s'\n", msg);
- GNUNET_free_non_null (msg);
- return;
- }
+ if (GNUNET_OK != api->put (api->cls, &key, size, value, 1 + i % 4 /* type */
,
+ prio, i % 4 /* anonymity */ ,
+ 0 /* replication */ ,
+ GNUNET_TIME_relative_to_absolute
+ (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MILLISECONDS,
+ 60 * 60 * 60 * 1000 +
+ GNUNET_CRYPTO_random_u32
+ (GNUNET_CRYPTO_QUALITY_WEAK, 1000))), &msg))
+ {
+ fprintf (stderr, "ERROR: `%s'\n", msg);
+ GNUNET_free_non_null (msg);
+ return;
+ }
ic++;
stored_bytes += size;
stored_ops++;
stored_entries++;
}
-static void
-test (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+static void test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
static int
iterate_zeros (void *cls,
- const GNUNET_HashCode * key,
- uint32_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- struct GNUNET_TIME_Absolute
- expiration,
- uint64_t uid)
+ const GNUNET_HashCode * key,
+ uint32_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute expiration, uint64_t uid)
{
struct CpsRunContext *crc = cls;
int i;
@@ -175,38 +165,37 @@
GNUNET_assert (key != NULL);
GNUNET_assert (size >= 8);
memcpy (&i, &cdata[4], sizeof (i));
- hits[i/8] |= (1 << (i % 8));
+ hits[i / 8] |= (1 << (i % 8));
-#if VERBOSE
+#if VERBOSE
fprintf (stderr, "Found result type=%u, priority=%u, size=%u, expire=%llu\n",
- type, priority, size,
- (unsigned long long) expiration.abs_value);
+ type, priority, size, (unsigned long long) expiration.abs_value);
#endif
crc->cnt++;
if (crc->cnt == PUT_10 / 4 - 1)
- {
- unsigned int bc;
+ {
+ unsigned int bc;
- bc = 0;
- for (i = 0;i<PUT_10;i++)
- if (0 != (hits[i/8] & (1 << (i % 8))))
- bc++;
-
- crc->end = GNUNET_TIME_absolute_get();
- printf ("%s took %llu ms yielding %u/%u items\n",
- "Select random zero-anonymity item",
- (unsigned long long) (crc->end.abs_value - crc->start.abs_value),
- bc,
- crc->cnt);
- if (crc->cnt > 0)
- GAUGER (category,
- "Select random zero-anonymity item",
- (crc->end.abs_value - crc->start.abs_value) / crc->cnt,
"ms/item");
- memset (hits, 0, sizeof (hits));
- crc->phase++;
- crc->cnt = 0;
- crc->start = GNUNET_TIME_absolute_get ();
- }
+ bc = 0;
+ for (i = 0; i < PUT_10; i++)
+ if (0 != (hits[i / 8] & (1 << (i % 8))))
+ bc++;
+
+ crc->end = GNUNET_TIME_absolute_get ();
+ printf ("%s took %llu ms yielding %u/%u items\n",
+ "Select random zero-anonymity item",
+ (unsigned long long) (crc->end.abs_value - crc->start.abs_value),
+ bc, crc->cnt);
+ if (crc->cnt > 0)
+ GAUGER (category,
+ "Select random zero-anonymity item",
+ (crc->end.abs_value - crc->start.abs_value) / crc->cnt,
+ "ms/item");
+ memset (hits, 0, sizeof (hits));
+ crc->phase++;
+ crc->cnt = 0;
+ crc->start = GNUNET_TIME_absolute_get ();
+ }
GNUNET_SCHEDULER_add_now (&test, crc);
return GNUNET_OK;
}
@@ -214,15 +203,13 @@
static int
expiration_get (void *cls,
- const GNUNET_HashCode * key,
- uint32_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- struct GNUNET_TIME_Absolute
- expiration,
- uint64_t uid)
+ const GNUNET_HashCode * key,
+ uint32_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute expiration, uint64_t uid)
{
struct CpsRunContext *crc = cls;
int i;
@@ -230,36 +217,35 @@
GNUNET_assert (size >= 8);
memcpy (&i, &cdata[4], sizeof (i));
- hits[i/8] |= (1 << (i % 8));
+ hits[i / 8] |= (1 << (i % 8));
crc->cnt++;
if (PUT_10 <= crc->cnt)
- {
- unsigned int bc;
+ {
+ unsigned int bc;
- bc = 0;
- for (i = 0;i<PUT_10;i++)
- if (0 != (hits[i/8] & (1 << (i % 8))))
- bc++;
-
- crc->end = GNUNET_TIME_absolute_get();
- printf ("%s took %llu ms yielding %u/%u items\n",
- "Selecting and deleting by expiration",
- (unsigned long long) (crc->end.abs_value - crc->start.abs_value),
- bc,
- (unsigned int) PUT_10);
- if (crc->cnt > 0)
- GAUGER (category,
- "Selecting and deleting by expiration",
- (crc->end.abs_value - crc->start.abs_value) / crc->cnt,
- "ms/item");
- memset (hits, 0, sizeof (hits));
- if (++crc->iter == ITERATIONS)
- crc->phase++;
- else
- crc->phase = RP_PUT;
- crc->cnt = 0;
- crc->start = GNUNET_TIME_absolute_get ();
- }
+ bc = 0;
+ for (i = 0; i < PUT_10; i++)
+ if (0 != (hits[i / 8] & (1 << (i % 8))))
+ bc++;
+
+ crc->end = GNUNET_TIME_absolute_get ();
+ printf ("%s took %llu ms yielding %u/%u items\n",
+ "Selecting and deleting by expiration",
+ (unsigned long long) (crc->end.abs_value - crc->start.abs_value),
+ bc, (unsigned int) PUT_10);
+ if (crc->cnt > 0)
+ GAUGER (category,
+ "Selecting and deleting by expiration",
+ (crc->end.abs_value - crc->start.abs_value) / crc->cnt,
+ "ms/item");
+ memset (hits, 0, sizeof (hits));
+ if (++crc->iter == ITERATIONS)
+ crc->phase++;
+ else
+ crc->phase = RP_PUT;
+ crc->cnt = 0;
+ crc->start = GNUNET_TIME_absolute_get ();
+ }
GNUNET_SCHEDULER_add_now (&test, crc);
return GNUNET_NO;
}
@@ -267,15 +253,13 @@
static int
replication_get (void *cls,
- const GNUNET_HashCode * key,
- uint32_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- struct GNUNET_TIME_Absolute
- expiration,
- uint64_t uid)
+ const GNUNET_HashCode * key,
+ uint32_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute expiration, uint64_t uid)
{
struct CpsRunContext *crc = cls;
int i;
@@ -284,35 +268,34 @@
GNUNET_assert (NULL != key);
GNUNET_assert (size >= 8);
memcpy (&i, &cdata[4], sizeof (i));
- hits[i/8] |= (1 << (i % 8));
+ hits[i / 8] |= (1 << (i % 8));
crc->cnt++;
if (PUT_10 <= crc->cnt)
- {
- unsigned int bc;
+ {
+ unsigned int bc;
- bc = 0;
- for (i = 0;i<PUT_10;i++)
- if (0 != (hits[i/8] & (1 << (i % 8))))
- bc++;
-
- crc->end = GNUNET_TIME_absolute_get();
- printf ("%s took %llu ms yielding %u/%u items\n",
- "Selecting random item for replication",
- (unsigned long long) (crc->end.abs_value - crc->start.abs_value),
- bc,
- (unsigned int) PUT_10);
- if (crc->cnt > 0)
- GAUGER (category,
- "Selecting random item for replication",
- (crc->end.abs_value - crc->start.abs_value) / crc->cnt,
- "ms/item");
- memset (hits, 0, sizeof (hits));
- crc->phase++;
- crc->offset = 0;
- crc->cnt = 0;
- crc->start = GNUNET_TIME_absolute_get ();
- }
-
+ bc = 0;
+ for (i = 0; i < PUT_10; i++)
+ if (0 != (hits[i / 8] & (1 << (i % 8))))
+ bc++;
+
+ crc->end = GNUNET_TIME_absolute_get ();
+ printf ("%s took %llu ms yielding %u/%u items\n",
+ "Selecting random item for replication",
+ (unsigned long long) (crc->end.abs_value - crc->start.abs_value),
+ bc, (unsigned int) PUT_10);
+ if (crc->cnt > 0)
+ GAUGER (category,
+ "Selecting random item for replication",
+ (crc->end.abs_value - crc->start.abs_value) / crc->cnt,
+ "ms/item");
+ memset (hits, 0, sizeof (hits));
+ crc->phase++;
+ crc->offset = 0;
+ crc->cnt = 0;
+ crc->start = GNUNET_TIME_absolute_get ();
+ }
+
GNUNET_SCHEDULER_add_now (&test, crc);
return GNUNET_OK;
}
@@ -326,8 +309,8 @@
* @param cfg configuration to use
*/
static void
-unload_plugin (struct GNUNET_DATASTORE_PluginFunctions * api,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+unload_plugin (struct GNUNET_DATASTORE_PluginFunctions *api,
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
{
char *name;
char *libname;
@@ -335,13 +318,12 @@
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
"DATASTORE", "DATABASE", &name))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("No `%s' specified for `%s' in configuration!\n"),
- "DATABASE",
- "DATASTORE");
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("No `%s' specified for `%s' in configuration!\n"),
+ "DATABASE", "DATASTORE");
+ return;
+ }
GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name);
GNUNET_break (NULL == GNUNET_PLUGIN_unload (libname, api));
GNUNET_free (libname);
@@ -365,76 +347,66 @@
static void
-test (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
+test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
struct CpsRunContext *crc = cls;
int j;
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- {
- GNUNET_break (0);
- crc->phase = RP_ERROR;
- }
+ {
+ GNUNET_break (0);
+ crc->phase = RP_ERROR;
+ }
#if VERBOSE
- fprintf (stderr, "In phase %d, iteration %u\n",
- crc->phase,
- crc->cnt);
+ fprintf (stderr, "In phase %d, iteration %u\n", crc->phase, crc->cnt);
#endif
switch (crc->phase)
+ {
+ case RP_ERROR:
+ GNUNET_break (0);
+ crc->api->drop (crc->api->cls);
+ ok = 1;
+ GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
+ &cleaning_task, crc);
+ break;
+ case RP_PUT:
+ crc->start = GNUNET_TIME_absolute_get ();
+ for (j = 0; j < PUT_10; j++)
+ putValue (crc->api, j, crc->i);
+ crc->end = GNUNET_TIME_absolute_get ();
{
- case RP_ERROR:
- GNUNET_break (0);
- crc->api->drop (crc->api->cls);
- ok = 1;
- GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
- &cleaning_task, crc);
- break;
- case RP_PUT:
- crc->start = GNUNET_TIME_absolute_get ();
- for (j=0;j<PUT_10;j++)
- putValue (crc->api, j, crc->i);
- crc->end = GNUNET_TIME_absolute_get ();
- {
- printf ("%s took %llu ms for %llu items\n",
- "Storing an item",
- (unsigned long long) (crc->end.abs_value -
crc->start.abs_value),
- PUT_10);
- if (PUT_10 > 0)
- GAUGER (category,
- "Storing an item",
- (crc->end.abs_value - crc->start.abs_value) / PUT_10,
- "ms/item");
- }
- crc->i++;
- crc->start = GNUNET_TIME_absolute_get ();
- crc->phase++;
- GNUNET_SCHEDULER_add_now (&test, crc);
- break;
- case RP_REP_GET:
- crc->api->get_replication (crc->api->cls,
- &replication_get,
- crc);
- break;
- case RP_ZA_GET:
- crc->api->get_zero_anonymity (crc->api->cls,
- crc->offset++,
- 1,
- &iterate_zeros,
- crc);
- break;
- case RP_EXP_GET:
- crc->api->get_expiration (crc->api->cls,
- &expiration_get,
- crc);
- break;
- case RP_DONE:
- crc->api->drop (crc->api->cls);
- ok = 0;
- GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
- &cleaning_task, crc);
- break;
+ printf ("%s took %llu ms for %llu items\n",
+ "Storing an item",
+ (unsigned long long) (crc->end.abs_value - crc->start.abs_value),
+ PUT_10);
+ if (PUT_10 > 0)
+ GAUGER (category,
+ "Storing an item",
+ (crc->end.abs_value - crc->start.abs_value) / PUT_10,
+ "ms/item");
}
+ crc->i++;
+ crc->start = GNUNET_TIME_absolute_get ();
+ crc->phase++;
+ GNUNET_SCHEDULER_add_now (&test, crc);
+ break;
+ case RP_REP_GET:
+ crc->api->get_replication (crc->api->cls, &replication_get, crc);
+ break;
+ case RP_ZA_GET:
+ crc->api->get_zero_anonymity (crc->api->cls,
+ crc->offset++, 1, &iterate_zeros, crc);
+ break;
+ case RP_EXP_GET:
+ crc->api->get_expiration (crc->api->cls, &expiration_get, crc);
+ break;
+ case RP_DONE:
+ crc->api->drop (crc->api->cls);
+ ok = 0;
+ GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
+ &cleaning_task, crc);
+ break;
+ }
}
@@ -445,20 +417,19 @@
load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg)
{
static struct GNUNET_DATASTORE_PluginEnvironment env;
- struct GNUNET_DATASTORE_PluginFunctions * ret;
+ struct GNUNET_DATASTORE_PluginFunctions *ret;
char *name;
char *libname;
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
"DATASTORE", "DATABASE", &name))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("No `%s' specified for `%s' in configuration!\n"),
- "DATABASE",
- "DATASTORE");
- return NULL;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("No `%s' specified for `%s' in configuration!\n"),
+ "DATABASE", "DATASTORE");
+ return NULL;
+ }
env.cfg = cfg;
env.duc = &disk_utilization_change_cb;
env.cls = NULL;
@@ -466,12 +437,10 @@
_("Loading `%s' datastore plugin\n"), name);
GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name);
if (NULL == (ret = GNUNET_PLUGIN_load (libname, &env)))
- {
- fprintf (stderr,
- "Failed to load plugin `%s'!\n",
- name);
- return NULL;
- }
+ {
+ fprintf (stderr, "Failed to load plugin `%s'!\n", name);
+ return NULL;
+ }
GNUNET_free (libname);
GNUNET_free (name);
return ret;
@@ -481,20 +450,19 @@
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *c)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
{
struct GNUNET_DATASTORE_PluginFunctions *api;
struct CpsRunContext *crc;
api = load_plugin (c);
if (api == NULL)
- {
- fprintf (stderr,
- "Could not initialize plugin, assuming database not configured.
Test not run!\n");
- return;
- }
- crc = GNUNET_malloc(sizeof(struct CpsRunContext));
+ {
+ fprintf (stderr,
+ "Could not initialize plugin, assuming database not configured.
Test not run!\n");
+ return;
+ }
+ crc = GNUNET_malloc (sizeof (struct CpsRunContext));
crc->api = api;
crc->cfg = c;
crc->phase = RP_PUT;
@@ -507,7 +475,8 @@
check ()
{
char cfg_name[128];
- char *const argv[] = {
+
+ char *const argv[] = {
"perf-plugin-datastore",
"-c",
cfg_name,
@@ -520,13 +489,10 @@
GNUNET_GETOPT_OPTION_END
};
- GNUNET_snprintf (category, sizeof (category),
- "DATASTORE-%s",
- plugin_name);
+ GNUNET_snprintf (category, sizeof (category), "DATASTORE-%s", plugin_name);
GNUNET_snprintf (cfg_name,
- sizeof (cfg_name),
- "perf_plugin_datastore_data_%s.conf",
- plugin_name);
+ sizeof (cfg_name),
+ "perf_plugin_datastore_data_%s.conf", plugin_name);
GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
argv, "perf-plugin-datastore", "nohelp",
options, &run, NULL);
@@ -546,17 +512,16 @@
sleep (1);
/* determine name of plugin to use */
plugin_name = argv[0];
- while (NULL != (pos = strstr(plugin_name, "_")))
- plugin_name = pos+1;
- if (NULL != (pos = strstr(plugin_name, ".")))
+ while (NULL != (pos = strstr (plugin_name, "_")))
+ plugin_name = pos + 1;
+ if (NULL != (pos = strstr (plugin_name, ".")))
pos[0] = 0;
else
pos = (char *) plugin_name;
GNUNET_snprintf (dir_name,
- sizeof (dir_name),
- "/tmp/perf-gnunet-datastore-%s",
- plugin_name);
+ sizeof (dir_name),
+ "/tmp/perf-gnunet-datastore-%s", plugin_name);
GNUNET_DISK_directory_remove (dir_name);
GNUNET_log_setup ("perf-plugin-datastore",
#if VERBOSE
@@ -574,5 +539,3 @@
}
/* end of perf_plugin_datastore.c */
-
-
Modified: gnunet/src/datastore/plugin_datastore_mysql.c
===================================================================
--- gnunet/src/datastore/plugin_datastore_mysql.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/datastore/plugin_datastore_mysql.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -164,7 +164,7 @@
/**
* Context for all functions in this plugin.
*/
-struct Plugin
+struct Plugin
{
/**
* Our execution environment.
@@ -175,7 +175,7 @@
* Handle to talk to MySQL.
*/
MYSQL *dbf;
-
+
/**
* We keep all prepared statements in a DLL. This is the head.
*/
@@ -196,13 +196,13 @@
*/
#define INSERT_ENTRY "INSERT INTO gn090
(repl,type,prio,anonLevel,expire,rvalue,hash,vhash,value) VALUES
(?,?,?,?,?,?,?,?,?)"
struct GNUNET_MysqlStatementHandle *insert_entry;
-
+
#define DELETE_ENTRY_BY_UID "DELETE FROM gn090 WHERE uid=?"
struct GNUNET_MysqlStatementHandle *delete_entry_by_uid;
#define COUNT_ENTRY_BY_HASH "SELECT count(*) FROM gn090 FORCE INDEX (idx_hash)
WHERE hash=?"
struct GNUNET_MysqlStatementHandle *count_entry_by_hash;
-
+
#define SELECT_ENTRY_BY_HASH "SELECT type,prio,anonLevel,expire,hash,value,uid
FROM gn090 FORCE INDEX (idx_hash) WHERE hash=? ORDER BY uid LIMIT 1 OFFSET ?"
struct GNUNET_MysqlStatementHandle *select_entry_by_hash;
@@ -211,16 +211,16 @@
#define SELECT_ENTRY_BY_HASH_AND_VHASH "SELECT
type,prio,anonLevel,expire,hash,value,uid FROM gn090 FORCE INDEX
(idx_hash_vhash) WHERE hash=? AND vhash=? ORDER BY uid LIMIT 1 OFFSET ?"
struct GNUNET_MysqlStatementHandle *select_entry_by_hash_and_vhash;
-
+
#define COUNT_ENTRY_BY_HASH_AND_TYPE "SELECT count(*) FROM gn090 FORCE INDEX
(idx_hash_type_uid) WHERE hash=? AND type=?"
struct GNUNET_MysqlStatementHandle *count_entry_by_hash_and_type;
#define SELECT_ENTRY_BY_HASH_AND_TYPE "SELECT
type,prio,anonLevel,expire,hash,value,uid FROM gn090 FORCE INDEX
(idx_hash_type_uid) WHERE hash=? AND type=? ORDER BY uid LIMIT 1 OFFSET ?"
struct GNUNET_MysqlStatementHandle *select_entry_by_hash_and_type;
-
+
#define COUNT_ENTRY_BY_HASH_VHASH_AND_TYPE "SELECT count(*) FROM gn090 FORCE
INDEX (idx_hash_vhash) WHERE hash=? AND vhash=? AND type=?"
struct GNUNET_MysqlStatementHandle *count_entry_by_hash_vhash_and_type;
-
+
#define SELECT_ENTRY_BY_HASH_VHASH_AND_TYPE "SELECT
type,prio,anonLevel,expire,hash,value,uid FROM gn090 FORCE INDEX
(idx_hash_vhash) WHERE hash=? AND vhash=? AND type=? ORDER BY uid ASC LIMIT 1
OFFSET ?"
struct GNUNET_MysqlStatementHandle *select_entry_by_hash_vhash_and_type;
@@ -274,6 +274,7 @@
char *cnffile;
char *home_dir;
struct stat st;
+
#ifndef WINDOWS
struct passwd *pw;
#endif
@@ -282,44 +283,47 @@
#ifndef WINDOWS
pw = getpwuid (getuid ());
if (!pw)
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
- "getpwuid");
- return NULL;
- }
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "getpwuid");
+ return NULL;
+ }
if (GNUNET_YES ==
- GNUNET_CONFIGURATION_have_value (cfg,
- "datastore-mysql", "CONFIG"))
- {
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_filename (cfg,
-
"datastore-mysql", "CONFIG", &cnffile));
- configured = GNUNET_YES;
- }
+ GNUNET_CONFIGURATION_have_value (cfg, "datastore-mysql", "CONFIG"))
+ {
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_filename (cfg,
+ "datastore-mysql",
+ "CONFIG",
+ &cnffile));
+ configured = GNUNET_YES;
+ }
else
- {
- home_dir = GNUNET_strdup (pw->pw_dir);
+ {
+ home_dir = GNUNET_strdup (pw->pw_dir);
+ GNUNET_asprintf (&cnffile, "%s/.my.cnf", home_dir);
+ GNUNET_free (home_dir);
+ configured = GNUNET_NO;
+ }
#else
- home_dir = (char *) GNUNET_malloc (_MAX_PATH + 1);
- plibc_conv_to_win_path ("~/", home_dir);
+ home_dir = (char *) GNUNET_malloc (_MAX_PATH + 1);
+ plibc_conv_to_win_path ("~/", home_dir);
+ GNUNET_asprintf (&cnffile, "%s/.my.cnf", home_dir);
+ GNUNET_free (home_dir);
+ configured = GNUNET_NO;
#endif
- GNUNET_asprintf (&cnffile, "%s/.my.cnf", home_dir);
- GNUNET_free (home_dir);
- configured = GNUNET_NO;
- }
+
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Trying to use file `%s' for MySQL configuration.\n"),
- cnffile);
+ _("Trying to use file `%s' for MySQL configuration.\n"),
cnffile);
if ((0 != STAT (cnffile, &st)) ||
(0 != ACCESS (cnffile, R_OK)) || (!S_ISREG (st.st_mode)))
- {
- if (configured == GNUNET_YES)
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Could not access file `%s': %s\n"), cnffile,
- STRERROR (errno));
- GNUNET_free (cnffile);
- return NULL;
- }
+ {
+ if (configured == GNUNET_YES)
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Could not access file `%s': %s\n"), cnffile,
+ STRERROR (errno));
+ GNUNET_free (cnffile);
+ return NULL;
+ }
return cnffile;
}
@@ -336,18 +340,18 @@
struct GNUNET_MysqlStatementHandle *s;
for (s = plugin->shead; s != NULL; s = s->next)
+ {
+ if (s->valid)
{
- if (s->valid)
- {
- mysql_stmt_close (s->statement);
- s->valid = GNUNET_NO;
- }
+ mysql_stmt_close (s->statement);
+ s->valid = GNUNET_NO;
}
+ }
if (plugin->dbf != NULL)
- {
- mysql_close (plugin->dbf);
- plugin->dbf = NULL;
- }
+ {
+ mysql_close (plugin->dbf);
+ plugin->dbf = NULL;
+ }
return GNUNET_OK;
}
@@ -378,75 +382,79 @@
mysql_options (plugin->dbf, MYSQL_READ_DEFAULT_GROUP, "client");
reconnect = 0;
mysql_options (plugin->dbf, MYSQL_OPT_RECONNECT, &reconnect);
- timeout = 120; /* in seconds */
+ timeout = 120; /* in seconds */
mysql_options (plugin->dbf,
MYSQL_OPT_CONNECT_TIMEOUT, (const void *) &timeout);
- mysql_options(plugin->dbf, MYSQL_SET_CHARSET_NAME, "UTF8");
- timeout = 60; /* in seconds */
+ mysql_options (plugin->dbf, MYSQL_SET_CHARSET_NAME, "UTF8");
+ timeout = 60; /* in seconds */
mysql_options (plugin->dbf, MYSQL_OPT_READ_TIMEOUT, (const void *) &timeout);
mysql_options (plugin->dbf, MYSQL_OPT_WRITE_TIMEOUT, (const void *)
&timeout);
mysql_dbname = NULL;
if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (plugin->env->cfg,
- "datastore-mysql",
"DATABASE"))
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
- "datastore-mysql",
"DATABASE",
- &mysql_dbname));
+ "datastore-mysql",
+ "DATABASE"))
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
+ "datastore-mysql",
+ "DATABASE",
+ &mysql_dbname));
else
mysql_dbname = GNUNET_strdup ("gnunet");
mysql_user = NULL;
if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (plugin->env->cfg,
- "datastore-mysql", "USER"))
- {
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
- "datastore-mysql",
"USER",
- &mysql_user));
- }
+ "datastore-mysql",
"USER"))
+ {
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
+ "datastore-mysql",
+ "USER",
&mysql_user));
+ }
mysql_password = NULL;
if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (plugin->env->cfg,
- "datastore-mysql",
"PASSWORD"))
- {
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
- "datastore-mysql",
"PASSWORD",
- &mysql_password));
- }
+ "datastore-mysql",
+ "PASSWORD"))
+ {
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
+ "datastore-mysql",
+ "PASSWORD",
+ &mysql_password));
+ }
mysql_server = NULL;
if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (plugin->env->cfg,
- "datastore-mysql", "HOST"))
- {
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
- "datastore-mysql",
"HOST",
- &mysql_server));
- }
+ "datastore-mysql",
"HOST"))
+ {
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
+ "datastore-mysql",
+ "HOST",
+ &mysql_server));
+ }
mysql_port = 0;
if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (plugin->env->cfg,
- "datastore-mysql", "PORT"))
- {
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_number (plugin->env->cfg,
"datastore-mysql",
- "PORT",
&mysql_port));
- }
+ "datastore-mysql",
"PORT"))
+ {
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_number (plugin->env->cfg,
+ "datastore-mysql",
+ "PORT",
&mysql_port));
+ }
GNUNET_assert (mysql_dbname != NULL);
- mysql_real_connect (plugin->dbf,
- mysql_server,
- mysql_user, mysql_password,
- mysql_dbname,
- (unsigned int) mysql_port, NULL,
- CLIENT_IGNORE_SIGPIPE);
+ mysql_real_connect (plugin->dbf,
+ mysql_server,
+ mysql_user, mysql_password,
+ mysql_dbname,
+ (unsigned int) mysql_port, NULL, CLIENT_IGNORE_SIGPIPE);
GNUNET_free_non_null (mysql_server);
GNUNET_free_non_null (mysql_user);
GNUNET_free_non_null (mysql_password);
GNUNET_free (mysql_dbname);
if (mysql_error (plugin->dbf)[0])
- {
- LOG_MYSQL (GNUNET_ERROR_TYPE_ERROR,
- "mysql_real_connect", plugin);
- return GNUNET_SYSERR;
- }
+ {
+ LOG_MYSQL (GNUNET_ERROR_TYPE_ERROR, "mysql_real_connect", plugin);
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
}
@@ -459,19 +467,17 @@
* @return GNUNET_OK on success, GNUNET_SYSERR on error
*/
static int
-run_statement (struct Plugin *plugin,
- const char *statement)
+run_statement (struct Plugin *plugin, const char *statement)
{
if ((NULL == plugin->dbf) && (GNUNET_OK != iopen (plugin)))
return GNUNET_SYSERR;
mysql_query (plugin->dbf, statement);
if (mysql_error (plugin->dbf)[0])
- {
- LOG_MYSQL (GNUNET_ERROR_TYPE_ERROR,
- "mysql_query", plugin);
- iclose (plugin);
- return GNUNET_SYSERR;
- }
+ {
+ LOG_MYSQL (GNUNET_ERROR_TYPE_ERROR, "mysql_query", plugin);
+ iclose (plugin);
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
}
@@ -484,16 +490,13 @@
* @return NULL on error
*/
static struct GNUNET_MysqlStatementHandle *
-prepared_statement_create (struct Plugin *plugin,
- const char *statement)
+prepared_statement_create (struct Plugin *plugin, const char *statement)
{
struct GNUNET_MysqlStatementHandle *ret;
ret = GNUNET_malloc (sizeof (struct GNUNET_MysqlStatementHandle));
ret->query = GNUNET_strdup (statement);
- GNUNET_CONTAINER_DLL_insert (plugin->shead,
- plugin->stail,
- ret);
+ GNUNET_CONTAINER_DLL_insert (plugin->shead, plugin->stail, ret);
return ret;
}
@@ -506,36 +509,30 @@
* @return GNUNET_OK on success
*/
static int
-prepare_statement (struct Plugin *plugin,
- struct GNUNET_MysqlStatementHandle *ret)
+prepare_statement (struct Plugin *plugin,
+ struct GNUNET_MysqlStatementHandle *ret)
{
if (GNUNET_YES == ret->valid)
return GNUNET_OK;
- if ((NULL == plugin->dbf) &&
- (GNUNET_OK != iopen (plugin)))
+ if ((NULL == plugin->dbf) && (GNUNET_OK != iopen (plugin)))
return GNUNET_SYSERR;
ret->statement = mysql_stmt_init (plugin->dbf);
if (ret->statement == NULL)
- {
- iclose (plugin);
- return GNUNET_SYSERR;
- }
- if (mysql_stmt_prepare (ret->statement,
- ret->query,
- strlen (ret->query)))
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
- "mysql",
- _("Failed to prepare statement `%s'\n"),
- ret->query);
- LOG_MYSQL (GNUNET_ERROR_TYPE_ERROR,
- "mysql_stmt_prepare",
- plugin);
- mysql_stmt_close (ret->statement);
- ret->statement = NULL;
- iclose (plugin);
- return GNUNET_SYSERR;
- }
+ {
+ iclose (plugin);
+ return GNUNET_SYSERR;
+ }
+ if (mysql_stmt_prepare (ret->statement, ret->query, strlen (ret->query)))
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
+ "mysql",
+ _("Failed to prepare statement `%s'\n"), ret->query);
+ LOG_MYSQL (GNUNET_ERROR_TYPE_ERROR, "mysql_stmt_prepare", plugin);
+ mysql_stmt_close (ret->statement);
+ ret->statement = NULL;
+ iclose (plugin);
+ return GNUNET_SYSERR;
+ }
ret->valid = GNUNET_YES;
return GNUNET_OK;
@@ -553,8 +550,7 @@
*/
static int
init_params (struct Plugin *plugin,
- struct GNUNET_MysqlStatementHandle *s,
- va_list ap)
+ struct GNUNET_MysqlStatementHandle *s, va_list ap)
{
MYSQL_BIND qbind[MAX_PARAM];
unsigned int pc;
@@ -563,69 +559,72 @@
pc = mysql_stmt_param_count (s->statement);
if (pc > MAX_PARAM)
- {
- /* increase internal constant! */
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
+ {
+ /* increase internal constant! */
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
memset (qbind, 0, sizeof (qbind));
off = 0;
ft = 0;
while ((pc > 0) && (-1 != (int) (ft = va_arg (ap, enum enum_field_types))))
+ {
+ qbind[off].buffer_type = ft;
+ switch (ft)
{
- qbind[off].buffer_type = ft;
- switch (ft)
- {
- case MYSQL_TYPE_FLOAT:
- qbind[off].buffer = va_arg (ap, float *);
- break;
- case MYSQL_TYPE_LONGLONG:
- qbind[off].buffer = va_arg (ap, unsigned long long *);
- qbind[off].is_unsigned = va_arg (ap, int);
- break;
- case MYSQL_TYPE_LONG:
- qbind[off].buffer = va_arg (ap, unsigned int *);
- qbind[off].is_unsigned = va_arg (ap, int);
- break;
- case MYSQL_TYPE_VAR_STRING:
- case MYSQL_TYPE_STRING:
- case MYSQL_TYPE_BLOB:
- qbind[off].buffer = va_arg (ap, void *);
- qbind[off].buffer_length = va_arg (ap, unsigned long);
- qbind[off].length = va_arg (ap, unsigned long *);
- break;
- default:
- /* unsupported type */
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
- pc--;
- off++;
- }
- if (! ( (pc == 0) && (-1 != (int) ft) && (va_arg (ap, int) == -1) ) )
- {
- GNUNET_assert (0);
+ case MYSQL_TYPE_FLOAT:
+ qbind[off].buffer = va_arg (ap, float *);
+
+ break;
+ case MYSQL_TYPE_LONGLONG:
+ qbind[off].buffer = va_arg (ap, unsigned long long *);
+ qbind[off].is_unsigned = va_arg (ap, int);
+
+ break;
+ case MYSQL_TYPE_LONG:
+ qbind[off].buffer = va_arg (ap, unsigned int *);
+ qbind[off].is_unsigned = va_arg (ap, int);
+
+ break;
+ case MYSQL_TYPE_VAR_STRING:
+ case MYSQL_TYPE_STRING:
+ case MYSQL_TYPE_BLOB:
+ qbind[off].buffer = va_arg (ap, void *);
+ qbind[off].buffer_length = va_arg (ap, unsigned long);
+ qbind[off].length = va_arg (ap, unsigned long *);
+
+ break;
+ default:
+ /* unsupported type */
+ GNUNET_break (0);
return GNUNET_SYSERR;
}
+ pc--;
+ off++;
+ }
+ if (!((pc == 0) && (-1 != (int) ft) && (va_arg (ap, int) == -1)))
+ {
+ GNUNET_assert (0);
+ return GNUNET_SYSERR;
+ }
if (mysql_stmt_bind_param (s->statement, qbind))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("`%s' failed at %s:%d with error: %s\n"),
- "mysql_stmt_bind_param",
- __FILE__, __LINE__, mysql_stmt_error (s->statement));
- iclose (plugin);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("`%s' failed at %s:%d with error: %s\n"),
+ "mysql_stmt_bind_param",
+ __FILE__, __LINE__, mysql_stmt_error (s->statement));
+ iclose (plugin);
+ return GNUNET_SYSERR;
+ }
if (mysql_stmt_execute (s->statement))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("`%s' for `%s' failed at %s:%d with error: %s\n"),
- "mysql_stmt_execute",
- s->query,
- __FILE__, __LINE__, mysql_stmt_error (s->statement));
- iclose (plugin);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("`%s' for `%s' failed at %s:%d with error: %s\n"),
+ "mysql_stmt_execute",
+ s->query, __FILE__, __LINE__, mysql_stmt_error (s->statement));
+ iclose (plugin);
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
}
@@ -645,51 +644,50 @@
*/
static int
prepared_statement_run_select_va (struct Plugin *plugin,
- struct GNUNET_MysqlStatementHandle *s,
- unsigned int result_size,
- MYSQL_BIND *results,
- va_list ap)
+ struct GNUNET_MysqlStatementHandle *s,
+ unsigned int result_size,
+ MYSQL_BIND * results, va_list ap)
{
int ret;
unsigned int rsize;
if (GNUNET_OK != prepare_statement (plugin, s))
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
if (GNUNET_OK != init_params (plugin, s, ap))
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
rsize = mysql_stmt_field_count (s->statement);
if (rsize > result_size)
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
if (mysql_stmt_bind_result (s->statement, results))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("`%s' failed at %s:%d with error: %s\n"),
- "mysql_stmt_bind_result",
- __FILE__, __LINE__, mysql_stmt_error (s->statement));
- iclose (plugin);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("`%s' failed at %s:%d with error: %s\n"),
+ "mysql_stmt_bind_result",
+ __FILE__, __LINE__, mysql_stmt_error (s->statement));
+ iclose (plugin);
+ return GNUNET_SYSERR;
+ }
ret = mysql_stmt_fetch (s->statement);
if (ret == MYSQL_NO_DATA)
return GNUNET_NO;
if (ret != 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("`%s' failed at %s:%d with error: %s\n"),
- "mysql_stmt_fetch",
- __FILE__, __LINE__, mysql_stmt_error (s->statement));
- iclose (plugin);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("`%s' failed at %s:%d with error: %s\n"),
+ "mysql_stmt_fetch",
+ __FILE__, __LINE__, mysql_stmt_error (s->statement));
+ iclose (plugin);
+ return GNUNET_SYSERR;
+ }
mysql_stmt_reset (s->statement);
return GNUNET_OK;
}
@@ -711,18 +709,15 @@
*/
static int
prepared_statement_run_select (struct Plugin *plugin,
- struct GNUNET_MysqlStatementHandle *s,
- unsigned int result_size,
- MYSQL_BIND *results,
- ...)
+ struct GNUNET_MysqlStatementHandle *s,
+ unsigned int result_size,
+ MYSQL_BIND * results, ...)
{
va_list ap;
int ret;
va_start (ap, results);
- ret = prepared_statement_run_select_va (plugin, s,
- result_size, results,
- ap);
+ ret = prepared_statement_run_select_va (plugin, s, result_size, results, ap);
va_end (ap);
return ret;
}
@@ -743,8 +738,8 @@
*/
static int
prepared_statement_run (struct Plugin *plugin,
- struct GNUNET_MysqlStatementHandle *s,
- unsigned long long *insert_id, ...)
+ struct GNUNET_MysqlStatementHandle *s,
+ unsigned long long *insert_id, ...)
{
va_list ap;
int affected;
@@ -753,10 +748,10 @@
return GNUNET_SYSERR;
va_start (ap, insert_id);
if (GNUNET_OK != init_params (plugin, s, ap))
- {
- va_end (ap);
- return GNUNET_SYSERR;
- }
+ {
+ va_end (ap);
+ return GNUNET_SYSERR;
+ }
va_end (ap);
affected = mysql_stmt_affected_rows (s->statement);
if (NULL != insert_id)
@@ -774,26 +769,22 @@
* @return GNUNET_OK on success, GNUNET_NO if no such value exists,
GNUNET_SYSERR on error
*/
static int
-do_delete_entry (struct Plugin *plugin,
- unsigned long long uid)
+do_delete_entry (struct Plugin *plugin, unsigned long long uid)
{
int ret;
-
+
#if DEBUG_MYSQL
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Deleting value %llu from gn090 table\n",
- uid);
+ "Deleting value %llu from gn090 table\n", uid);
#endif
ret = prepared_statement_run (plugin,
- plugin->delete_entry_by_uid,
- NULL,
- MYSQL_TYPE_LONGLONG, &uid, GNUNET_YES,
- -1);
+ plugin->delete_entry_by_uid,
+ NULL,
+ MYSQL_TYPE_LONGLONG, &uid, GNUNET_YES, -1);
if (ret >= 0)
return GNUNET_OK;
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Deleting value %llu from gn090 table failed\n",
- uid);
+ "Deleting value %llu from gn090 table failed\n", uid);
return ret;
}
@@ -817,11 +808,8 @@
cbind[0].buffer_type = MYSQL_TYPE_LONGLONG;
cbind[0].buffer = &total;
cbind[0].is_unsigned = GNUNET_NO;
- if (GNUNET_OK !=
- prepared_statement_run_select (plugin,
- plugin->get_size,
- 1, cbind,
- -1))
+ if (GNUNET_OK !=
+ prepared_statement_run_select (plugin, plugin->get_size, 1, cbind, -1))
return 0;
return total;
}
@@ -844,61 +832,58 @@
*/
static int
mysql_plugin_put (void *cls,
- const GNUNET_HashCode * key,
- uint32_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- uint32_t replication,
- struct GNUNET_TIME_Absolute expiration,
- char **msg)
+ const GNUNET_HashCode * key,
+ uint32_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ uint32_t replication,
+ struct GNUNET_TIME_Absolute expiration, char **msg)
{
struct Plugin *plugin = cls;
unsigned int irepl = replication;
unsigned int ipriority = priority;
unsigned int ianonymity = anonymity;
unsigned long long lexpiration = expiration.abs_value;
- unsigned long long lrvalue = (unsigned long long) GNUNET_CRYPTO_random_u64
(GNUNET_CRYPTO_QUALITY_WEAK,
-
UINT64_MAX);
+ unsigned long long lrvalue =
+ (unsigned long long) GNUNET_CRYPTO_random_u64
(GNUNET_CRYPTO_QUALITY_WEAK,
+ UINT64_MAX);
unsigned long hashSize;
unsigned long hashSize2;
unsigned long lsize;
GNUNET_HashCode vhash;
if (size > MAX_DATUM_SIZE)
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
hashSize = sizeof (GNUNET_HashCode);
hashSize2 = sizeof (GNUNET_HashCode);
lsize = size;
GNUNET_CRYPTO_hash (data, size, &vhash);
if (GNUNET_OK !=
prepared_statement_run (plugin,
- plugin->insert_entry,
- NULL,
- MYSQL_TYPE_LONG, &irepl, GNUNET_YES,
- MYSQL_TYPE_LONG, &type, GNUNET_YES,
- MYSQL_TYPE_LONG, &ipriority, GNUNET_YES,
- MYSQL_TYPE_LONG, &ianonymity, GNUNET_YES,
- MYSQL_TYPE_LONGLONG, &lexpiration, GNUNET_YES,
- MYSQL_TYPE_LONGLONG, &lrvalue, GNUNET_YES,
- MYSQL_TYPE_BLOB, key, hashSize, &hashSize,
- MYSQL_TYPE_BLOB, &vhash, hashSize2, &hashSize2,
- MYSQL_TYPE_BLOB, data, lsize, &lsize,
- -1))
- return GNUNET_SYSERR;
+ plugin->insert_entry,
+ NULL,
+ MYSQL_TYPE_LONG, &irepl, GNUNET_YES,
+ MYSQL_TYPE_LONG, &type, GNUNET_YES,
+ MYSQL_TYPE_LONG, &ipriority, GNUNET_YES,
+ MYSQL_TYPE_LONG, &ianonymity, GNUNET_YES,
+ MYSQL_TYPE_LONGLONG, &lexpiration, GNUNET_YES,
+ MYSQL_TYPE_LONGLONG, &lrvalue, GNUNET_YES,
+ MYSQL_TYPE_BLOB, key, hashSize, &hashSize,
+ MYSQL_TYPE_BLOB, &vhash, hashSize2, &hashSize2,
+ MYSQL_TYPE_BLOB, data, lsize, &lsize, -1))
+ return GNUNET_SYSERR;
#if DEBUG_MYSQL
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Inserted value `%s' with size %u into gn090 table\n",
- GNUNET_h2s (key),
- (unsigned int) size);
+ "Inserted value `%s' with size %u into gn090 table\n",
+ GNUNET_h2s (key), (unsigned int) size);
#endif
if (size > 0)
- plugin->env->duc (plugin->env->cls,
- size);
+ plugin->env->duc (plugin->env->cls, size);
return GNUNET_OK;
}
@@ -928,10 +913,8 @@
*/
static int
mysql_plugin_update (void *cls,
- uint64_t uid,
- int delta,
- struct GNUNET_TIME_Absolute expire,
- char **msg)
+ uint64_t uid,
+ int delta, struct GNUNET_TIME_Absolute expire, char **msg)
{
struct Plugin *plugin = cls;
unsigned long long vkey = uid;
@@ -940,25 +923,21 @@
#if DEBUG_MYSQL
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Updating value %llu adding %d to priority and maxing exp at
%llu\n",
- vkey,
- delta,
- lexpire);
+ "Updating value %llu adding %d to priority and maxing exp at
%llu\n",
+ vkey, delta, lexpire);
#endif
ret = prepared_statement_run (plugin,
- plugin->update_entry,
- NULL,
- MYSQL_TYPE_LONG, &delta, GNUNET_NO,
- MYSQL_TYPE_LONGLONG, &lexpire, GNUNET_YES,
- MYSQL_TYPE_LONGLONG, &lexpire, GNUNET_YES,
- MYSQL_TYPE_LONGLONG, &vkey, GNUNET_YES,
- -1);
+ plugin->update_entry,
+ NULL,
+ MYSQL_TYPE_LONG, &delta, GNUNET_NO,
+ MYSQL_TYPE_LONGLONG, &lexpire, GNUNET_YES,
+ MYSQL_TYPE_LONGLONG, &lexpire, GNUNET_YES,
+ MYSQL_TYPE_LONGLONG, &vkey, GNUNET_YES, -1);
if (ret != GNUNET_OK)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Failed to update value %llu\n",
- vkey);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to update value %llu\n", vkey);
+ }
return ret;
}
@@ -973,11 +952,10 @@
* @param proc_cls closure for proc
* @param ... arguments to initialize stmt
*/
-static void
+static void
execute_select (struct Plugin *plugin,
- struct GNUNET_MysqlStatementHandle *stmt,
- PluginDatumProcessor proc, void *proc_cls,
- ...)
+ struct GNUNET_MysqlStatementHandle *stmt,
+ PluginDatumProcessor proc, void *proc_cls, ...)
{
va_list ap;
int ret;
@@ -1020,51 +998,36 @@
rbind[6].is_unsigned = 1;
va_start (ap, proc_cls);
- ret = prepared_statement_run_select_va (plugin,
- stmt,
- 7, rbind,
- ap);
+ ret = prepared_statement_run_select_va (plugin, stmt, 7, rbind, ap);
va_end (ap);
if (ret <= 0)
- {
- proc (proc_cls,
- NULL, 0, NULL, 0, 0, 0,
- GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
- }
- GNUNET_assert (size <= sizeof(value));
- if ( (rbind[4].buffer_length != sizeof (GNUNET_HashCode)) ||
- (hashSize != sizeof (GNUNET_HashCode)) )
- {
- GNUNET_break (0);
- proc (proc_cls,
- NULL, 0, NULL, 0, 0, 0,
- GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
- }
+ {
+ proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ return;
+ }
+ GNUNET_assert (size <= sizeof (value));
+ if ((rbind[4].buffer_length != sizeof (GNUNET_HashCode)) ||
+ (hashSize != sizeof (GNUNET_HashCode)))
+ {
+ GNUNET_break (0);
+ proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ return;
+ }
#if DEBUG_MYSQL
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Found %u-byte value under key `%s' with prio %u, anon %u, expire
%llu selecting from gn090 table\n",
- (unsigned int) size,
- GNUNET_h2s (&key),
- priority,
- anonymity,
- exp);
+ "Found %u-byte value under key `%s' with prio %u, anon %u,
expire %llu selecting from gn090 table\n",
+ (unsigned int) size, GNUNET_h2s (&key), priority, anonymity,
exp);
#endif
GNUNET_assert (size < MAX_DATUM_SIZE);
expiration.abs_value = exp;
- ret = proc (proc_cls,
- &key,
- size, value,
- type, priority, anonymity, expiration,
- uid);
+ ret = proc (proc_cls,
+ &key, size, value, type, priority, anonymity, expiration, uid);
if (ret == GNUNET_NO)
- {
- do_delete_entry (plugin, uid);
- if (size != 0)
- plugin->env->duc (plugin->env->cls,
- - size);
- }
+ {
+ do_delete_entry (plugin, uid);
+ if (size != 0)
+ plugin->env->duc (plugin->env->cls, -size);
+ }
}
@@ -1089,11 +1052,11 @@
*/
static void
mysql_plugin_get_key (void *cls,
- uint64_t offset,
- const GNUNET_HashCode *key,
- const GNUNET_HashCode *vhash,
- enum GNUNET_BLOCK_Type type,
- PluginDatumProcessor proc, void *proc_cls)
+ uint64_t offset,
+ const GNUNET_HashCode * key,
+ const GNUNET_HashCode * vhash,
+ enum GNUNET_BLOCK_Type type,
+ PluginDatumProcessor proc, void *proc_cls)
{
struct Plugin *plugin = cls;
int ret;
@@ -1113,115 +1076,107 @@
cbind[0].buffer = &total;
cbind[0].is_unsigned = GNUNET_NO;
if (type != 0)
+ {
+ if (vhash != NULL)
{
- if (vhash != NULL)
- {
- ret =
- prepared_statement_run_select (plugin,
-
plugin->count_entry_by_hash_vhash_and_type,
- 1, cbind,
- MYSQL_TYPE_BLOB, key, hashSize,
&hashSize,
- MYSQL_TYPE_BLOB, vhash, hashSize2,
&hashSize2,
- MYSQL_TYPE_LONG, &type, GNUNET_YES,
- -1);
- }
- else
- {
- ret =
- prepared_statement_run_select (plugin,
-
plugin->count_entry_by_hash_and_type,
- 1, cbind,
- MYSQL_TYPE_BLOB, key, hashSize,
&hashSize,
- MYSQL_TYPE_LONG, &type, GNUNET_YES,
- -1);
- }
+ ret =
+ prepared_statement_run_select (plugin,
+ plugin->
+ count_entry_by_hash_vhash_and_type, 1,
+ cbind, MYSQL_TYPE_BLOB, key, hashSize,
+ &hashSize, MYSQL_TYPE_BLOB, vhash,
+ hashSize2, &hashSize2,
MYSQL_TYPE_LONG,
+ &type, GNUNET_YES, -1);
}
+ else
+ {
+ ret =
+ prepared_statement_run_select (plugin,
+ plugin->count_entry_by_hash_and_type,
+ 1, cbind,
+ MYSQL_TYPE_BLOB, key, hashSize,
+ &hashSize, MYSQL_TYPE_LONG, &type,
+ GNUNET_YES, -1);
+ }
+ }
else
+ {
+ if (vhash != NULL)
{
- if (vhash != NULL)
- {
- ret =
- prepared_statement_run_select (plugin,
-
plugin->count_entry_by_hash_and_vhash,
- 1, cbind,
- MYSQL_TYPE_BLOB, key, hashSize,
&hashSize,
- MYSQL_TYPE_BLOB, vhash, hashSize2,
&hashSize2,
- -1);
+ ret =
+ prepared_statement_run_select (plugin,
+ plugin->count_entry_by_hash_and_vhash,
+ 1, cbind,
+ MYSQL_TYPE_BLOB, key, hashSize,
+ &hashSize, MYSQL_TYPE_BLOB, vhash,
+ hashSize2, &hashSize2, -1);
- }
- else
- {
- ret =
- prepared_statement_run_select (plugin,
- plugin->count_entry_by_hash,
- 1, cbind,
- MYSQL_TYPE_BLOB, key, hashSize,
&hashSize,
- -1);
- }
}
- if ((ret != GNUNET_OK) || (0 >= total))
+ else
{
- proc (proc_cls,
- NULL, 0, NULL, 0, 0, 0,
- GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
+ ret =
+ prepared_statement_run_select (plugin,
+ plugin->count_entry_by_hash,
+ 1, cbind,
+ MYSQL_TYPE_BLOB, key, hashSize,
+ &hashSize, -1);
}
+ }
+ if ((ret != GNUNET_OK) || (0 >= total))
+ {
+ proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ return;
+ }
offset = offset % total;
off = (unsigned long long) offset;
#if DEBUG_MYSQL
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Obtaining %llu/%lld result for GET `%s'\n",
- off,
- total,
- GNUNET_h2s (key));
+ "Obtaining %llu/%lld result for GET `%s'\n",
+ off, total, GNUNET_h2s (key));
#endif
if (type != GNUNET_BLOCK_TYPE_ANY)
+ {
+ if (NULL != vhash)
{
- if (NULL != vhash)
- {
- execute_select (plugin,
- plugin->select_entry_by_hash_vhash_and_type,
- proc, proc_cls,
- MYSQL_TYPE_BLOB, key, hashSize, &hashSize,
- MYSQL_TYPE_BLOB, vhash, hashSize, &hashSize,
- MYSQL_TYPE_LONG, &type, GNUNET_YES,
- MYSQL_TYPE_LONGLONG, &off, GNUNET_YES,
- -1);
- }
- else
- {
- execute_select (plugin,
- plugin->select_entry_by_hash_and_type,
- proc, proc_cls,
- MYSQL_TYPE_BLOB, key, hashSize, &hashSize,
- MYSQL_TYPE_LONG, &type, GNUNET_YES,
- MYSQL_TYPE_LONGLONG, &off, GNUNET_YES,
- -1);
- }
+ execute_select (plugin,
+ plugin->select_entry_by_hash_vhash_and_type,
+ proc, proc_cls,
+ MYSQL_TYPE_BLOB, key, hashSize, &hashSize,
+ MYSQL_TYPE_BLOB, vhash, hashSize, &hashSize,
+ MYSQL_TYPE_LONG, &type, GNUNET_YES,
+ MYSQL_TYPE_LONGLONG, &off, GNUNET_YES, -1);
}
+ else
+ {
+ execute_select (plugin,
+ plugin->select_entry_by_hash_and_type,
+ proc, proc_cls,
+ MYSQL_TYPE_BLOB, key, hashSize, &hashSize,
+ MYSQL_TYPE_LONG, &type, GNUNET_YES,
+ MYSQL_TYPE_LONGLONG, &off, GNUNET_YES, -1);
+ }
+ }
else
+ {
+ if (NULL != vhash)
{
- if (NULL != vhash)
- {
- execute_select (plugin,
- plugin->select_entry_by_hash_and_vhash,
- proc, proc_cls,
- MYSQL_TYPE_BLOB, key, hashSize, &hashSize,
- MYSQL_TYPE_BLOB, vhash, hashSize, &hashSize,
- MYSQL_TYPE_LONGLONG, &off, GNUNET_YES,
- -1);
- }
- else
- {
- execute_select (plugin,
- plugin->select_entry_by_hash,
- proc, proc_cls,
- MYSQL_TYPE_BLOB, key, hashSize, &hashSize,
- MYSQL_TYPE_LONGLONG, &off, GNUNET_YES,
- -1);
- }
+ execute_select (plugin,
+ plugin->select_entry_by_hash_and_vhash,
+ proc, proc_cls,
+ MYSQL_TYPE_BLOB, key, hashSize, &hashSize,
+ MYSQL_TYPE_BLOB, vhash, hashSize, &hashSize,
+ MYSQL_TYPE_LONGLONG, &off, GNUNET_YES, -1);
}
+ else
+ {
+ execute_select (plugin,
+ plugin->select_entry_by_hash,
+ proc, proc_cls,
+ MYSQL_TYPE_BLOB, key, hashSize, &hashSize,
+ MYSQL_TYPE_LONGLONG, &off, GNUNET_YES, -1);
+ }
+ }
}
@@ -1237,21 +1192,22 @@
*/
static void
mysql_plugin_get_zero_anonymity (void *cls,
- uint64_t offset,
- enum GNUNET_BLOCK_Type type,
- PluginDatumProcessor proc, void *proc_cls)
+ uint64_t offset,
+ enum GNUNET_BLOCK_Type type,
+ PluginDatumProcessor proc, void *proc_cls)
{
struct Plugin *plugin = cls;
- unsigned long long rvalue = (unsigned long long) GNUNET_CRYPTO_random_u64
(GNUNET_CRYPTO_QUALITY_WEAK,
-
UINT64_MAX);
+ unsigned long long rvalue =
+ (unsigned long long) GNUNET_CRYPTO_random_u64
(GNUNET_CRYPTO_QUALITY_WEAK,
+ UINT64_MAX);
+
execute_select (plugin,
- plugin->zero_iter,
- proc, proc_cls,
- MYSQL_TYPE_LONG, &type, GNUNET_YES,
- MYSQL_TYPE_LONGLONG, &rvalue, GNUNET_YES,
- MYSQL_TYPE_LONG, &type, GNUNET_YES,
- MYSQL_TYPE_LONGLONG, &rvalue, GNUNET_YES,
- -1);
+ plugin->zero_iter,
+ proc, proc_cls,
+ MYSQL_TYPE_LONG, &type, GNUNET_YES,
+ MYSQL_TYPE_LONGLONG, &rvalue, GNUNET_YES,
+ MYSQL_TYPE_LONG, &type, GNUNET_YES,
+ MYSQL_TYPE_LONGLONG, &rvalue, GNUNET_YES, -1);
}
@@ -1260,17 +1216,17 @@
*/
struct ReplCtx
{
-
+
/**
* Plugin handle.
*/
struct Plugin *plugin;
-
+
/**
* Function to call for the result (or the NULL).
*/
PluginDatumProcessor proc;
-
+
/**
* Closure for proc.
*/
@@ -1300,14 +1256,13 @@
*/
static int
repl_proc (void *cls,
- const GNUNET_HashCode *key,
- uint32_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- struct GNUNET_TIME_Absolute expiration,
- uint64_t uid)
+ const GNUNET_HashCode * key,
+ uint32_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute expiration, uint64_t uid)
{
struct ReplCtx *rc = cls;
struct Plugin *plugin = rc->plugin;
@@ -1316,25 +1271,21 @@
int iret;
ret = rc->proc (rc->proc_cls,
- key,
- size, data,
- type, priority, anonymity, expiration,
- uid);
+ key, size, data, type, priority, anonymity, expiration, uid);
if (NULL != key)
+ {
+ oid = (unsigned long long) uid;
+ iret = prepared_statement_run (plugin,
+ plugin->dec_repl,
+ NULL,
+ MYSQL_TYPE_LONGLONG, &oid, GNUNET_YES, -1);
+ if (iret == GNUNET_SYSERR)
{
- oid = (unsigned long long) uid;
- iret = prepared_statement_run (plugin,
- plugin->dec_repl,
- NULL,
- MYSQL_TYPE_LONGLONG, &oid, GNUNET_YES,
- -1);
- if (iret == GNUNET_SYSERR)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Failed to reduce replication counter\n");
- return GNUNET_SYSERR;
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to reduce replication counter\n");
+ return GNUNET_SYSERR;
}
+ }
return ret;
}
@@ -1352,14 +1303,14 @@
*/
static void
mysql_plugin_get_replication (void *cls,
- PluginDatumProcessor proc, void *proc_cls)
+ PluginDatumProcessor proc, void *proc_cls)
{
struct Plugin *plugin = cls;
struct ReplCtx rc;
unsigned long long rvalue;
unsigned long repl;
MYSQL_BIND results;
-
+
rc.plugin = plugin;
rc.proc = proc;
rc.proc_cls = proc_cls;
@@ -1369,28 +1320,19 @@
results.is_unsigned = GNUNET_YES;
if (1 !=
- prepared_statement_run_select (plugin,
- plugin->max_repl,
- 1,
- &results,
- -1))
- {
- proc (proc_cls,
- NULL, 0, NULL, 0, 0, 0,
- GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
- }
+ prepared_statement_run_select (plugin, plugin->max_repl, 1, &results,
-1))
+ {
+ proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ return;
+ }
- rvalue = (unsigned long long) GNUNET_CRYPTO_random_u64
(GNUNET_CRYPTO_QUALITY_WEAK,
- UINT64_MAX);
- execute_select (plugin,
- plugin->select_replication,
- &repl_proc, &rc,
- MYSQL_TYPE_LONG, &repl, GNUNET_YES,
- MYSQL_TYPE_LONGLONG, &rvalue, GNUNET_YES,
- MYSQL_TYPE_LONG, &repl, GNUNET_YES,
- MYSQL_TYPE_LONGLONG, &rvalue, GNUNET_YES,
- -1);
+ rvalue =
+ (unsigned long long) GNUNET_CRYPTO_random_u64
(GNUNET_CRYPTO_QUALITY_WEAK,
+ UINT64_MAX);
+ execute_select (plugin, plugin->select_replication, &repl_proc, &rc,
+ MYSQL_TYPE_LONG, &repl, GNUNET_YES, MYSQL_TYPE_LONGLONG,
+ &rvalue, GNUNET_YES, MYSQL_TYPE_LONG, &repl, GNUNET_YES,
+ MYSQL_TYPE_LONGLONG, &rvalue, GNUNET_YES, -1);
}
@@ -1400,17 +1342,17 @@
*/
struct ExpiCtx
{
-
+
/**
* Plugin handle.
*/
struct Plugin *plugin;
-
+
/**
* Function to call for the result (or the NULL).
*/
PluginDatumProcessor proc;
-
+
/**
* Closure for proc.
*/
@@ -1441,31 +1383,25 @@
*/
static int
expi_proc (void *cls,
- const GNUNET_HashCode *key,
- uint32_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- struct GNUNET_TIME_Absolute expiration,
- uint64_t uid)
+ const GNUNET_HashCode * key,
+ uint32_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute expiration, uint64_t uid)
{
struct ExpiCtx *rc = cls;
struct Plugin *plugin = rc->plugin;
-
+
if (NULL == key)
- {
- execute_select (plugin,
- plugin->select_priority,
- rc->proc, rc->proc_cls,
- -1);
- return GNUNET_SYSERR;
- }
+ {
+ execute_select (plugin,
+ plugin->select_priority, rc->proc, rc->proc_cls, -1);
+ return GNUNET_SYSERR;
+ }
return rc->proc (rc->proc_cls,
- key,
- size, data,
- type, priority, anonymity, expiration,
- uid);
+ key, size, data, type, priority, anonymity, expiration,
uid);
}
@@ -1479,21 +1415,19 @@
*/
static void
mysql_plugin_get_expiration (void *cls,
- PluginDatumProcessor proc, void *proc_cls)
+ PluginDatumProcessor proc, void *proc_cls)
{
struct Plugin *plugin = cls;
long long nt;
struct ExpiCtx rc;
-
+
rc.plugin = plugin;
rc.proc = proc;
rc.proc_cls = proc_cls;
- nt = (long long) GNUNET_TIME_absolute_get().abs_value;
+ nt = (long long) GNUNET_TIME_absolute_get ().abs_value;
execute_select (plugin,
- plugin->select_expiration,
- expi_proc, &rc,
- MYSQL_TYPE_LONGLONG, &nt, GNUNET_YES,
- -1);
+ plugin->select_expiration,
+ expi_proc, &rc, MYSQL_TYPE_LONGLONG, &nt, GNUNET_YES, -1);
}
@@ -1503,14 +1437,13 @@
*
* @param cls the "struct Plugin*"
*/
-static void
+static void
mysql_plugin_drop (void *cls)
{
struct Plugin *plugin = cls;
- if (GNUNET_OK != run_statement (plugin,
- "DROP TABLE gn090"))
- return; /* error */
+ if (GNUNET_OK != run_statement (plugin, "DROP TABLE gn090"))
+ return; /* error */
plugin->env->duc (plugin->env->cls, 0);
}
@@ -1532,12 +1465,12 @@
plugin->env = env;
plugin->cnffile = get_my_cnf_path (env->cfg);
if (GNUNET_OK != iopen (plugin))
- {
- iclose (plugin);
- GNUNET_free_non_null (plugin->cnffile);
- GNUNET_free (plugin);
- return NULL;
- }
+ {
+ iclose (plugin);
+ GNUNET_free_non_null (plugin->cnffile);
+ GNUNET_free (plugin);
+ return NULL;
+ }
#define MRUNS(a) (GNUNET_OK != run_statement (plugin, a) )
#define PINIT(a,b) (NULL == (a = prepared_statement_create(plugin, b)))
if (MRUNS ("CREATE TABLE IF NOT EXISTS gn090 ("
@@ -1565,29 +1498,32 @@
PINIT (plugin->insert_entry, INSERT_ENTRY) ||
PINIT (plugin->delete_entry_by_uid, DELETE_ENTRY_BY_UID) ||
PINIT (plugin->select_entry_by_hash, SELECT_ENTRY_BY_HASH) ||
- PINIT (plugin->select_entry_by_hash_and_vhash,
SELECT_ENTRY_BY_HASH_AND_VHASH)
- || PINIT (plugin->select_entry_by_hash_and_type,
SELECT_ENTRY_BY_HASH_AND_TYPE)
- || PINIT (plugin->select_entry_by_hash_vhash_and_type,
- SELECT_ENTRY_BY_HASH_VHASH_AND_TYPE)
- || PINIT (plugin->count_entry_by_hash, COUNT_ENTRY_BY_HASH)
- || PINIT (plugin->get_size, SELECT_SIZE)
- || PINIT (plugin->count_entry_by_hash_and_vhash,
COUNT_ENTRY_BY_HASH_AND_VHASH)
- || PINIT (plugin->count_entry_by_hash_and_type,
COUNT_ENTRY_BY_HASH_AND_TYPE)
+ PINIT (plugin->select_entry_by_hash_and_vhash,
+ SELECT_ENTRY_BY_HASH_AND_VHASH) ||
+ PINIT (plugin->select_entry_by_hash_and_type,
+ SELECT_ENTRY_BY_HASH_AND_TYPE) ||
+ PINIT (plugin->select_entry_by_hash_vhash_and_type,
+ SELECT_ENTRY_BY_HASH_VHASH_AND_TYPE) ||
+ PINIT (plugin->count_entry_by_hash, COUNT_ENTRY_BY_HASH) ||
+ PINIT (plugin->get_size, SELECT_SIZE) ||
+ PINIT (plugin->count_entry_by_hash_and_vhash,
+ COUNT_ENTRY_BY_HASH_AND_VHASH) ||
+ PINIT (plugin->count_entry_by_hash_and_type,
COUNT_ENTRY_BY_HASH_AND_TYPE)
|| PINIT (plugin->count_entry_by_hash_vhash_and_type,
- COUNT_ENTRY_BY_HASH_VHASH_AND_TYPE)
- || PINIT (plugin->update_entry, UPDATE_ENTRY)
- || PINIT (plugin->dec_repl, DEC_REPL)
- || PINIT (plugin->zero_iter, SELECT_IT_NON_ANONYMOUS)
- || PINIT (plugin->select_expiration, SELECT_IT_EXPIRATION)
- || PINIT (plugin->select_priority, SELECT_IT_PRIORITY)
- || PINIT (plugin->max_repl, SELECT_MAX_REPL)
- || PINIT (plugin->select_replication, SELECT_IT_REPLICATION) )
- {
- iclose (plugin);
- GNUNET_free_non_null (plugin->cnffile);
- GNUNET_free (plugin);
- return NULL;
- }
+ COUNT_ENTRY_BY_HASH_VHASH_AND_TYPE) ||
+ PINIT (plugin->update_entry, UPDATE_ENTRY) ||
+ PINIT (plugin->dec_repl, DEC_REPL) ||
+ PINIT (plugin->zero_iter, SELECT_IT_NON_ANONYMOUS) ||
+ PINIT (plugin->select_expiration, SELECT_IT_EXPIRATION) ||
+ PINIT (plugin->select_priority, SELECT_IT_PRIORITY) ||
+ PINIT (plugin->max_repl, SELECT_MAX_REPL) ||
+ PINIT (plugin->select_replication, SELECT_IT_REPLICATION))
+ {
+ iclose (plugin);
+ GNUNET_free_non_null (plugin->cnffile);
+ GNUNET_free (plugin);
+ return NULL;
+ }
#undef PINIT
#undef MRUNS
@@ -1621,13 +1557,11 @@
iclose (plugin);
while (NULL != (s = plugin->shead))
- {
- GNUNET_CONTAINER_DLL_remove (plugin->shead,
- plugin->stail,
- s);
- GNUNET_free (s->query);
- GNUNET_free (s);
- }
+ {
+ GNUNET_CONTAINER_DLL_remove (plugin->shead, plugin->stail, s);
+ GNUNET_free (s->query);
+ GNUNET_free (s);
+ }
GNUNET_free_non_null (plugin->cnffile);
GNUNET_free (plugin);
GNUNET_free (api);
Modified: gnunet/src/datastore/plugin_datastore_postgres.c
===================================================================
--- gnunet/src/datastore/plugin_datastore_postgres.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/datastore/plugin_datastore_postgres.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -46,7 +46,7 @@
/**
* Context for all functions in this plugin.
*/
-struct Plugin
+struct Plugin
{
/**
* Our execution environment.
@@ -76,27 +76,28 @@
*/
static int
check_result (struct Plugin *plugin,
- PGresult * ret,
+ PGresult * ret,
int expected_status,
const char *command, const char *args, int line)
{
if (ret == NULL)
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "datastore-postgres",
- "Postgres failed to allocate result for `%s:%s' at %d\n",
- command, args, line);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "datastore-postgres",
+ "Postgres failed to allocate result for `%s:%s' at %d\n",
+ command, args, line);
+ return GNUNET_SYSERR;
+ }
if (PQresultStatus (ret) != expected_status)
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "datastore-postgres",
- _("`%s:%s' failed at %s:%d with error: %s"),
- command, args, __FILE__, line, PQerrorMessage
(plugin->dbh));
- PQclear (ret);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "datastore-postgres",
+ _("`%s:%s' failed at %s:%d with error: %s"),
+ command, args, __FILE__, line,
+ PQerrorMessage (plugin->dbh));
+ PQclear (ret);
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
}
@@ -108,14 +109,13 @@
* @param line code line for error reporting
*/
static int
-pq_exec (struct Plugin *plugin,
- const char *sql, int line)
+pq_exec (struct Plugin *plugin, const char *sql, int line)
{
PGresult *ret;
+
ret = PQexec (plugin->dbh, sql);
if (GNUNET_OK != check_result (plugin,
- ret,
- PGRES_COMMAND_OK, "PQexec", sql, line))
+ ret, PGRES_COMMAND_OK, "PQexec", sql, line))
return GNUNET_SYSERR;
PQclear (ret);
return GNUNET_OK;
@@ -133,13 +133,13 @@
*/
static int
pq_prepare (struct Plugin *plugin,
- const char *name, const char *sql, int nparams, int line)
+ const char *name, const char *sql, int nparams, int line)
{
PGresult *ret;
+
ret = PQprepare (plugin->dbh, name, sql, nparams, NULL);
if (GNUNET_OK !=
- check_result (plugin,
- ret, PGRES_COMMAND_OK, "PQprepare", sql, line))
+ check_result (plugin, ret, PGRES_COMMAND_OK, "PQprepare", sql, line))
return GNUNET_SYSERR;
PQclear (ret);
return GNUNET_OK;
@@ -160,28 +160,27 @@
/* Open database and precompile statements */
conninfo = NULL;
(void) GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
- "datastore-postgres",
- "CONFIG",
- &conninfo);
+ "datastore-postgres",
+ "CONFIG", &conninfo);
plugin->dbh = PQconnectdb (conninfo == NULL ? "" : conninfo);
if (NULL == plugin->dbh)
- {
- /* FIXME: warn about out-of-memory? */
- GNUNET_free_non_null (conninfo);
- return GNUNET_SYSERR;
- }
+ {
+ /* FIXME: warn about out-of-memory? */
+ GNUNET_free_non_null (conninfo);
+ return GNUNET_SYSERR;
+ }
if (PQstatus (plugin->dbh) != CONNECTION_OK)
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
- "datastore-postgres",
- _("Unable to initialize Postgres with configuration
`%s': %s"),
- conninfo,
- PQerrorMessage (plugin->dbh));
- PQfinish (plugin->dbh);
- plugin->dbh = NULL;
- GNUNET_free_non_null (conninfo);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
+ "datastore-postgres",
+ _
+ ("Unable to initialize Postgres with configuration `%s':
%s"),
+ conninfo, PQerrorMessage (plugin->dbh));
+ PQfinish (plugin->dbh);
+ plugin->dbh = NULL;
+ GNUNET_free_non_null (conninfo);
+ return GNUNET_SYSERR;
+ }
GNUNET_free_non_null (conninfo);
ret = PQexec (plugin->dbh,
"CREATE TABLE gn090 ("
@@ -194,176 +193,169 @@
" hash BYTEA NOT NULL DEFAULT '',"
" vhash BYTEA NOT NULL DEFAULT '',"
" value BYTEA NOT NULL DEFAULT '')" "WITH OIDS");
- if ( (ret == NULL) ||
- ( (PQresultStatus (ret) != PGRES_COMMAND_OK) &&
- (0 != strcmp ("42P07", /* duplicate table */
- PQresultErrorField
- (ret,
- PG_DIAG_SQLSTATE)))))
+ if ((ret == NULL) || ((PQresultStatus (ret) != PGRES_COMMAND_OK) && (0 !=
strcmp ("42P07", /* duplicate table */
+
PQresultErrorField
+
(ret,
+
PG_DIAG_SQLSTATE)))))
+ {
+ (void) check_result (plugin,
+ ret, PGRES_COMMAND_OK, "CREATE TABLE", "gn090",
+ __LINE__);
+ PQfinish (plugin->dbh);
+ plugin->dbh = NULL;
+ return GNUNET_SYSERR;
+ }
+ if (PQresultStatus (ret) == PGRES_COMMAND_OK)
+ {
+ if ((GNUNET_OK !=
+ pq_exec (plugin, "CREATE INDEX idx_hash ON gn090 (hash)", __LINE__))
||
+ (GNUNET_OK !=
+ pq_exec (plugin, "CREATE INDEX idx_hash_vhash ON gn090 (hash,vhash)",
+ __LINE__))
+ || (GNUNET_OK !=
+ pq_exec (plugin, "CREATE INDEX idx_prio ON gn090 (prio)",
__LINE__))
+ || (GNUNET_OK !=
+ pq_exec (plugin, "CREATE INDEX idx_expire ON gn090 (expire)",
+ __LINE__)) ||
+ (GNUNET_OK !=
+ pq_exec (plugin,
+ "CREATE INDEX idx_prio_anon ON gn090 (prio,anonLevel)",
+ __LINE__)) ||
+ (GNUNET_OK !=
+ pq_exec (plugin,
+ "CREATE INDEX idx_prio_hash_anon ON gn090
(prio,hash,anonLevel)",
+ __LINE__)) ||
+ (GNUNET_OK !=
+ pq_exec (plugin, "CREATE INDEX idx_repl_rvalue ON gn090
(repl,rvalue)",
+ __LINE__)) ||
+ (GNUNET_OK !=
+ pq_exec (plugin, "CREATE INDEX idx_expire_hash ON gn090
(expire,hash)",
+ __LINE__)))
{
- (void) check_result (plugin,
- ret, PGRES_COMMAND_OK, "CREATE TABLE", "gn090",
__LINE__);
+ PQclear (ret);
PQfinish (plugin->dbh);
plugin->dbh = NULL;
return GNUNET_SYSERR;
}
- if (PQresultStatus (ret) == PGRES_COMMAND_OK)
- {
- if ((GNUNET_OK !=
- pq_exec (plugin, "CREATE INDEX idx_hash ON gn090 (hash)",
__LINE__)) ||
- (GNUNET_OK !=
- pq_exec (plugin, "CREATE INDEX idx_hash_vhash ON gn090
(hash,vhash)",
- __LINE__))
- || (GNUNET_OK !=
- pq_exec (plugin, "CREATE INDEX idx_prio ON gn090 (prio)",
__LINE__))
- || (GNUNET_OK !=
- pq_exec (plugin, "CREATE INDEX idx_expire ON gn090 (expire)",
__LINE__))
- || (GNUNET_OK !=
- pq_exec (plugin, "CREATE INDEX idx_prio_anon ON gn090
(prio,anonLevel)",
- __LINE__))
- || (GNUNET_OK !=
- pq_exec
- (plugin, "CREATE INDEX idx_prio_hash_anon ON gn090
(prio,hash,anonLevel)",
- __LINE__))
- || (GNUNET_OK !=
- pq_exec
- (plugin, "CREATE INDEX idx_repl_rvalue ON gn090 (repl,rvalue)",
- __LINE__))
- || (GNUNET_OK !=
- pq_exec (plugin, "CREATE INDEX idx_expire_hash ON gn090
(expire,hash)",
- __LINE__)))
- {
- PQclear (ret);
- PQfinish (plugin->dbh);
- plugin->dbh = NULL;
- return GNUNET_SYSERR;
- }
- }
+ }
PQclear (ret);
ret = PQexec (plugin->dbh,
"ALTER TABLE gn090 ALTER value SET STORAGE EXTERNAL");
- if (GNUNET_OK !=
+ if (GNUNET_OK !=
check_result (plugin,
- ret, PGRES_COMMAND_OK,
- "ALTER TABLE", "gn090", __LINE__))
- {
- PQfinish (plugin->dbh);
- plugin->dbh = NULL;
- return GNUNET_SYSERR;
- }
+ ret, PGRES_COMMAND_OK, "ALTER TABLE", "gn090", __LINE__))
+ {
+ PQfinish (plugin->dbh);
+ plugin->dbh = NULL;
+ return GNUNET_SYSERR;
+ }
PQclear (ret);
- ret = PQexec (plugin->dbh,
- "ALTER TABLE gn090 ALTER hash SET STORAGE PLAIN");
+ ret = PQexec (plugin->dbh, "ALTER TABLE gn090 ALTER hash SET STORAGE PLAIN");
if (GNUNET_OK !=
check_result (plugin,
- ret, PGRES_COMMAND_OK,
- "ALTER TABLE", "gn090", __LINE__))
- {
- PQfinish (plugin->dbh);
- plugin->dbh = NULL;
- return GNUNET_SYSERR;
- }
+ ret, PGRES_COMMAND_OK, "ALTER TABLE", "gn090", __LINE__))
+ {
+ PQfinish (plugin->dbh);
+ plugin->dbh = NULL;
+ return GNUNET_SYSERR;
+ }
PQclear (ret);
- ret = PQexec (plugin->dbh,
- "ALTER TABLE gn090 ALTER vhash SET STORAGE PLAIN");
+ ret = PQexec (plugin->dbh, "ALTER TABLE gn090 ALTER vhash SET STORAGE
PLAIN");
if (GNUNET_OK !=
check_result (plugin,
- ret, PGRES_COMMAND_OK, "ALTER TABLE", "gn090", __LINE__))
- {
- PQfinish (plugin->dbh);
- plugin->dbh = NULL;
- return GNUNET_SYSERR;
- }
+ ret, PGRES_COMMAND_OK, "ALTER TABLE", "gn090", __LINE__))
+ {
+ PQfinish (plugin->dbh);
+ plugin->dbh = NULL;
+ return GNUNET_SYSERR;
+ }
PQclear (ret);
if ((GNUNET_OK !=
pq_prepare (plugin,
- "getvt",
+ "getvt",
"SELECT type, prio, anonLevel, expire, hash, value, oid
FROM gn090 "
"WHERE hash=$1 AND vhash=$2 AND type=$3 "
- "ORDER BY oid ASC LIMIT 1 OFFSET $4",
+ "ORDER BY oid ASC LIMIT 1 OFFSET $4",
4,
__LINE__)) ||
(GNUNET_OK !=
pq_prepare (plugin,
- "gett",
+ "gett",
"SELECT type, prio, anonLevel, expire, hash, value, oid
FROM gn090 "
"WHERE hash=$1 AND type=$2 "
- "ORDER BY oid ASC LIMIT 1 OFFSET $3",
+ "ORDER BY oid ASC LIMIT 1 OFFSET $3",
3,
__LINE__)) ||
(GNUNET_OK !=
pq_prepare (plugin,
- "getv",
+ "getv",
"SELECT type, prio, anonLevel, expire, hash, value, oid
FROM gn090 "
"WHERE hash=$1 AND vhash=$2 "
- "ORDER BY oid ASC LIMIT 1 OFFSET $3",
+ "ORDER BY oid ASC LIMIT 1 OFFSET $3",
3,
__LINE__)) ||
(GNUNET_OK !=
pq_prepare (plugin,
- "get",
+ "get",
"SELECT type, prio, anonLevel, expire, hash, value, oid
FROM gn090 "
"WHERE hash=$1 "
- "ORDER BY oid ASC LIMIT 1 OFFSET $2",
+ "ORDER BY oid ASC LIMIT 1 OFFSET $2",
2,
__LINE__)) ||
(GNUNET_OK !=
pq_prepare (plugin,
- "put",
+ "put",
"INSERT INTO gn090 (repl, type, prio, anonLevel, expire,
rvalue, hash, vhash, value) "
"VALUES ($1, $2, $3, $4, $5, RANDOM(), $6, $7, $8)",
9,
__LINE__)) ||
(GNUNET_OK !=
pq_prepare (plugin,
- "update",
+ "update",
"UPDATE gn090 SET prio = prio + $1, expire = CASE WHEN
expire < $2 THEN $2 ELSE expire END "
"WHERE oid = $3",
3,
__LINE__)) ||
(GNUNET_OK !=
pq_prepare (plugin,
- "decrepl",
+ "decrepl",
"UPDATE gn090 SET repl = GREATEST (repl - 1, 0) "
"WHERE oid = $1",
1,
__LINE__)) ||
(GNUNET_OK !=
pq_prepare (plugin,
- "select_non_anonymous",
- "SELECT type, prio, anonLevel, expire, hash, value, oid FROM
gn090 "
- "WHERE anonLevel = 0 AND type = $1 ORDER BY oid DESC LIMIT 1
OFFSET $2",
+ "select_non_anonymous",
+ "SELECT type, prio, anonLevel, expire, hash, value, oid
FROM gn090 "
+ "WHERE anonLevel = 0 AND type = $1 ORDER BY oid DESC LIMIT
1 OFFSET $2",
1,
__LINE__)) ||
(GNUNET_OK !=
pq_prepare (plugin,
- "select_expiration_order",
- "(SELECT type, prio, anonLevel, expire, hash, value, oid
FROM gn090 "
- "WHERE expire < $1 ORDER BY prio ASC LIMIT 1) "
- "UNION "
- "(SELECT type, prio, anonLevel, expire, hash, value, oid
FROM gn090 "
- "ORDER BY prio ASC LIMIT 1) "
- "ORDER BY expire ASC LIMIT 1",
+ "select_expiration_order",
+ "(SELECT type, prio, anonLevel, expire, hash, value, oid
FROM gn090 "
+ "WHERE expire < $1 ORDER BY prio ASC LIMIT 1) "
+ "UNION "
+ "(SELECT type, prio, anonLevel, expire, hash, value, oid
FROM gn090 "
+ "ORDER BY prio ASC LIMIT 1) "
+ "ORDER BY expire ASC LIMIT 1",
1,
__LINE__)) ||
(GNUNET_OK !=
pq_prepare (plugin,
- "select_replication_order",
- "SELECT type, prio, anonLevel, expire, hash, value, oid FROM
gn090 " \
- "ORDER BY repl DESC,RANDOM() LIMIT 1",
+ "select_replication_order",
+ "SELECT type, prio, anonLevel, expire, hash, value, oid
FROM gn090 "
+ "ORDER BY repl DESC,RANDOM() LIMIT 1",
0,
__LINE__)) ||
(GNUNET_OK !=
pq_prepare (plugin,
- "delrow",
- "DELETE FROM gn090 " "WHERE oid=$1",
- 1,
- __LINE__)))
- {
- PQfinish (plugin->dbh);
- plugin->dbh = NULL;
- return GNUNET_SYSERR;
- }
+ "delrow", "DELETE FROM gn090 " "WHERE oid=$1", 1,
__LINE__)))
+ {
+ PQfinish (plugin->dbh);
+ plugin->dbh = NULL;
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
}
@@ -377,8 +369,7 @@
* @return GNUNET_OK on success
*/
static int
-delete_by_rowid (struct Plugin *plugin,
- unsigned int rowid)
+delete_by_rowid (struct Plugin *plugin, unsigned int rowid)
{
uint32_t browid;
const char *paramValues[] = { (const char *) &browid };
@@ -392,11 +383,11 @@
1, paramValues, paramLengths, paramFormats, 1);
if (GNUNET_OK !=
check_result (plugin,
- ret, PGRES_COMMAND_OK, "PQexecPrepared", "delrow",
+ ret, PGRES_COMMAND_OK, "PQexecPrepared", "delrow",
__LINE__))
- {
- return GNUNET_SYSERR;
- }
+ {
+ return GNUNET_SYSERR;
+ }
PQclear (ret);
return GNUNET_OK;
}
@@ -417,25 +408,23 @@
PGresult *ret;
ret = PQexecParams (plugin->dbh,
- "SELECT SUM(LENGTH(value))+256*COUNT(*) FROM gn090",
- 0, NULL, NULL, NULL, NULL, 1);
+ "SELECT SUM(LENGTH(value))+256*COUNT(*) FROM gn090",
+ 0, NULL, NULL, NULL, NULL, 1);
if (GNUNET_OK != check_result (plugin,
- ret,
+ ret,
PGRES_TUPLES_OK,
- "PQexecParams",
- "get_size",
- __LINE__))
- {
- return 0;
- }
+ "PQexecParams", "get_size", __LINE__))
+ {
+ return 0;
+ }
if ((PQntuples (ret) != 1) ||
(PQnfields (ret) != 1) ||
(PQgetlength (ret, 0, 0) != sizeof (unsigned long long)))
- {
- GNUNET_break (0);
- PQclear (ret);
- return 0;
- }
+ {
+ GNUNET_break (0);
+ PQclear (ret);
+ return 0;
+ }
total = GNUNET_ntohll (*(const unsigned long long *) PQgetvalue (ret, 0, 0));
PQclear (ret);
return total;
@@ -459,15 +448,14 @@
*/
static int
postgres_plugin_put (void *cls,
- const GNUNET_HashCode * key,
- uint32_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- uint32_t replication,
- struct GNUNET_TIME_Absolute expiration,
- char **msg)
+ const GNUNET_HashCode * key,
+ uint32_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ uint32_t replication,
+ struct GNUNET_TIME_Absolute expiration, char **msg)
{
struct Plugin *plugin = cls;
GNUNET_HashCode vhash;
@@ -477,6 +465,7 @@
uint32_t banon = htonl (anonymity);
uint32_t brepl = htonl (replication);
uint64_t bexpi = GNUNET_TIME_absolute_hton (expiration).abs_value__;
+
const char *paramValues[] = {
(const char *) &brepl,
(const char *) &btype,
@@ -510,9 +499,8 @@
plugin->env->duc (plugin->env->cls, size + GNUNET_DATASTORE_ENTRY_OVERHEAD);
#if DEBUG_POSTGRES
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "datastore-postgres",
- "Stored %u bytes in database\n",
- (unsigned int) size);
+ "datastore-postgres",
+ "Stored %u bytes in database\n", (unsigned int) size);
#endif
return GNUNET_OK;
}
@@ -528,11 +516,10 @@
* @param res result from exec
* @param line line number for error messages
*/
-static void
+static void
process_result (struct Plugin *plugin,
- PluginDatumProcessor proc, void *proc_cls,
- PGresult *res,
- int line)
+ PluginDatumProcessor proc, void *proc_cls,
+ PGresult * res, int line)
{
int iret;
enum GNUNET_BLOCK_Type type;
@@ -544,115 +531,98 @@
GNUNET_HashCode key;
if (GNUNET_OK != check_result (plugin,
- res,
- PGRES_TUPLES_OK,
- "PQexecPrepared",
- "select",
- line))
- {
+ res,
+ PGRES_TUPLES_OK,
+ "PQexecPrepared", "select", line))
+ {
#if DEBUG_POSTGRES
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "datastore-postgres",
- "Ending iteration (postgres error)\n");
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ "datastore-postgres",
+ "Ending iteration (postgres error)\n");
#endif
- proc (proc_cls,
- NULL, 0, NULL, 0, 0, 0,
- GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
- }
+ proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ return;
+ }
if (0 == PQntuples (res))
- {
- /* no result */
+ {
+ /* no result */
#if DEBUG_POSTGRES
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "datastore-postgres",
- "Ending iteration (no more results)\n");
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ "datastore-postgres",
+ "Ending iteration (no more results)\n");
#endif
- proc (proc_cls,
- NULL, 0, NULL, 0, 0, 0,
- GNUNET_TIME_UNIT_ZERO_ABS, 0);
- PQclear (res);
- return;
- }
+ proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ PQclear (res);
+ return;
+ }
if ((1 != PQntuples (res)) ||
(7 != PQnfields (res)) ||
(sizeof (uint32_t) != PQfsize (res, 0)) ||
(sizeof (uint32_t) != PQfsize (res, 6)))
- {
- GNUNET_break (0);
- proc (proc_cls,
- NULL, 0, NULL, 0, 0, 0,
- GNUNET_TIME_UNIT_ZERO_ABS, 0);
- PQclear (res);
- return;
- }
+ {
+ GNUNET_break (0);
+ proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ PQclear (res);
+ return;
+ }
rowid = ntohl (*(uint32_t *) PQgetvalue (res, 0, 6));
if ((sizeof (uint32_t) != PQfsize (res, 0)) ||
(sizeof (uint32_t) != PQfsize (res, 1)) ||
(sizeof (uint32_t) != PQfsize (res, 2)) ||
(sizeof (uint64_t) != PQfsize (res, 3)) ||
- (sizeof (GNUNET_HashCode) != PQgetlength (res, 0, 4)) )
- {
- GNUNET_break (0);
- PQclear (res);
- delete_by_rowid (plugin, rowid);
- proc (proc_cls,
- NULL, 0, NULL, 0, 0, 0,
- GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
- }
+ (sizeof (GNUNET_HashCode) != PQgetlength (res, 0, 4)))
+ {
+ GNUNET_break (0);
+ PQclear (res);
+ delete_by_rowid (plugin, rowid);
+ proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ return;
+ }
type = ntohl (*(uint32_t *) PQgetvalue (res, 0, 0));
priority = ntohl (*(uint32_t *) PQgetvalue (res, 0, 1));
- anonymity = ntohl ( *(uint32_t *) PQgetvalue (res, 0, 2));
- expiration_time.abs_value = GNUNET_ntohll (*(uint64_t *) PQgetvalue (res, 0,
3));
- memcpy (&key,
- PQgetvalue (res, 0, 4),
- sizeof (GNUNET_HashCode));
+ anonymity = ntohl (*(uint32_t *) PQgetvalue (res, 0, 2));
+ expiration_time.abs_value =
+ GNUNET_ntohll (*(uint64_t *) PQgetvalue (res, 0, 3));
+ memcpy (&key, PQgetvalue (res, 0, 4), sizeof (GNUNET_HashCode));
size = PQgetlength (res, 0, 5);
#if DEBUG_POSTGRES
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "datastore-postgres",
- "Found result of size %u bytes and type %u in database\n",
- (unsigned int) size,
- (unsigned int) type);
+ "datastore-postgres",
+ "Found result of size %u bytes and type %u in database\n",
+ (unsigned int) size, (unsigned int) type);
#endif
iret = proc (proc_cls,
- &key,
- size,
- PQgetvalue (res, 0, 5),
- (enum GNUNET_BLOCK_Type) type,
- priority,
- anonymity,
- expiration_time,
- rowid);
+ &key,
+ size,
+ PQgetvalue (res, 0, 5),
+ (enum GNUNET_BLOCK_Type) type,
+ priority, anonymity, expiration_time, rowid);
PQclear (res);
if (iret == GNUNET_NO)
- {
+ {
#if DEBUG_POSTGRES
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Processor asked for item %u to be removed.\n",
- rowid);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Processor asked for item %u to be removed.\n", rowid);
#endif
- if (GNUNET_OK == delete_by_rowid (plugin, rowid))
- {
+ if (GNUNET_OK == delete_by_rowid (plugin, rowid))
+ {
#if DEBUG_POSTGRES
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "datastore-postgres",
- "Deleting %u bytes from database\n",
- (unsigned int) size);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ "datastore-postgres",
+ "Deleting %u bytes from database\n",
+ (unsigned int) size);
#endif
- plugin->env->duc (plugin->env->cls,
- - (size + GNUNET_DATASTORE_ENTRY_OVERHEAD));
+ plugin->env->duc (plugin->env->cls,
+ -(size + GNUNET_DATASTORE_ENTRY_OVERHEAD));
#if DEBUG_POSTGRES
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "datastore-postgres",
- "Deleted %u bytes from database\n",
- (unsigned int) size);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ "datastore-postgres",
+ "Deleted %u bytes from database\n", (unsigned int)
size);
#endif
- }
}
+ }
}
@@ -677,11 +647,11 @@
*/
static void
postgres_plugin_get_key (void *cls,
- uint64_t offset,
- const GNUNET_HashCode *key,
- const GNUNET_HashCode *vhash,
- enum GNUNET_BLOCK_Type type,
- PluginDatumProcessor proc, void *proc_cls)
+ uint64_t offset,
+ const GNUNET_HashCode * key,
+ const GNUNET_HashCode * vhash,
+ enum GNUNET_BLOCK_Type type,
+ PluginDatumProcessor proc, void *proc_cls)
{
struct Plugin *plugin = cls;
const int paramFormats[] = { 1, 1, 1, 1, 1 };
@@ -695,121 +665,92 @@
uint32_t btype;
GNUNET_assert (key != NULL);
- paramValues[0] = (const char*) key;
+ paramValues[0] = (const char *) key;
paramLengths[0] = sizeof (GNUNET_HashCode);
btype = htonl (type);
if (type != 0)
+ {
+ if (vhash != NULL)
{
- if (vhash != NULL)
- {
- paramValues[1] = (const char *) vhash;
- paramLengths[1] = sizeof (GNUNET_HashCode);
- paramValues[2] = (const char *) &btype;
- paramLengths[2] = sizeof (btype);
- paramValues[3] = (const char *) &blimit_off;
- paramLengths[3] = sizeof (blimit_off);
- nparams = 4;
- pname = "getvt";
- ret = PQexecParams (plugin->dbh,
- "SELECT count(*) FROM gn090 WHERE hash=$1 AND
vhash=$2 AND type=$3",
- 3,
- NULL,
- paramValues,
- paramLengths,
- paramFormats, 1);
- }
- else
- {
- paramValues[1] = (const char *) &btype;
- paramLengths[1] = sizeof (btype);
- paramValues[2] = (const char *) &blimit_off;
- paramLengths[2] = sizeof (blimit_off);
- nparams = 3;
- pname = "gett";
- ret = PQexecParams (plugin->dbh,
- "SELECT count(*) FROM gn090 WHERE hash=$1 AND
type=$2",
- 2,
- NULL,
- paramValues,
- paramLengths,
- paramFormats, 1);
- }
+ paramValues[1] = (const char *) vhash;
+ paramLengths[1] = sizeof (GNUNET_HashCode);
+ paramValues[2] = (const char *) &btype;
+ paramLengths[2] = sizeof (btype);
+ paramValues[3] = (const char *) &blimit_off;
+ paramLengths[3] = sizeof (blimit_off);
+ nparams = 4;
+ pname = "getvt";
+ ret = PQexecParams (plugin->dbh,
+ "SELECT count(*) FROM gn090 WHERE hash=$1 AND
vhash=$2 AND type=$3",
+ 3, NULL, paramValues, paramLengths, paramFormats, 1);
}
+ else
+ {
+ paramValues[1] = (const char *) &btype;
+ paramLengths[1] = sizeof (btype);
+ paramValues[2] = (const char *) &blimit_off;
+ paramLengths[2] = sizeof (blimit_off);
+ nparams = 3;
+ pname = "gett";
+ ret = PQexecParams (plugin->dbh,
+ "SELECT count(*) FROM gn090 WHERE hash=$1 AND
type=$2",
+ 2, NULL, paramValues, paramLengths, paramFormats, 1);
+ }
+ }
else
+ {
+ if (vhash != NULL)
{
- if (vhash != NULL)
- {
- paramValues[1] = (const char *) vhash;
- paramLengths[1] = sizeof (GNUNET_HashCode);
- paramValues[2] = (const char *) &blimit_off;
- paramLengths[2] = sizeof (blimit_off);
- nparams = 3;
- pname = "getv";
- ret = PQexecParams (plugin->dbh,
- "SELECT count(*) FROM gn090 WHERE hash=$1 AND
vhash=$2",
- 2,
- NULL,
- paramValues,
- paramLengths,
- paramFormats, 1);
- }
- else
- {
- paramValues[1] = (const char *) &blimit_off;
- paramLengths[1] = sizeof (blimit_off);
- nparams = 2;
- pname = "get";
- ret = PQexecParams (plugin->dbh,
- "SELECT count(*) FROM gn090 WHERE hash=$1",
- 1,
- NULL,
- paramValues,
- paramLengths,
- paramFormats, 1);
- }
+ paramValues[1] = (const char *) vhash;
+ paramLengths[1] = sizeof (GNUNET_HashCode);
+ paramValues[2] = (const char *) &blimit_off;
+ paramLengths[2] = sizeof (blimit_off);
+ nparams = 3;
+ pname = "getv";
+ ret = PQexecParams (plugin->dbh,
+ "SELECT count(*) FROM gn090 WHERE hash=$1 AND
vhash=$2",
+ 2, NULL, paramValues, paramLengths, paramFormats, 1);
}
- if (GNUNET_OK != check_result (plugin,
- ret,
- PGRES_TUPLES_OK,
- "PQexecParams",
- pname,
- __LINE__))
+ else
{
- proc (proc_cls,
- NULL, 0, NULL, 0, 0, 0,
- GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
+ paramValues[1] = (const char *) &blimit_off;
+ paramLengths[1] = sizeof (blimit_off);
+ nparams = 2;
+ pname = "get";
+ ret = PQexecParams (plugin->dbh,
+ "SELECT count(*) FROM gn090 WHERE hash=$1",
+ 1, NULL, paramValues, paramLengths, paramFormats, 1);
}
+ }
+ if (GNUNET_OK != check_result (plugin,
+ ret,
+ PGRES_TUPLES_OK,
+ "PQexecParams", pname, __LINE__))
+ {
+ proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ return;
+ }
if ((PQntuples (ret) != 1) ||
(PQnfields (ret) != 1) ||
(PQgetlength (ret, 0, 0) != sizeof (unsigned long long)))
- {
- GNUNET_break (0);
- PQclear (ret);
- proc (proc_cls,
- NULL, 0, NULL, 0, 0, 0,
- GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
- }
+ {
+ GNUNET_break (0);
+ PQclear (ret);
+ proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ return;
+ }
total = GNUNET_ntohll (*(const unsigned long long *) PQgetvalue (ret, 0, 0));
PQclear (ret);
if (total == 0)
- {
- proc (proc_cls,
- NULL, 0, NULL, 0, 0, 0,
- GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
- }
+ {
+ proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ return;
+ }
blimit_off = GNUNET_htonll (offset % total);
ret = PQexecPrepared (plugin->dbh,
- pname,
- nparams,
- paramValues,
- paramLengths,
- paramFormats, 1);
- process_result (plugin,
- proc, proc_cls,
- ret, __LINE__);
+ pname,
+ nparams, paramValues, paramLengths, paramFormats, 1);
+ process_result (plugin, proc, proc_cls, ret, __LINE__);
}
@@ -826,29 +767,24 @@
*/
static void
postgres_plugin_get_zero_anonymity (void *cls,
- uint64_t offset,
- enum GNUNET_BLOCK_Type type,
- PluginDatumProcessor proc, void *proc_cls)
+ uint64_t offset,
+ enum GNUNET_BLOCK_Type type,
+ PluginDatumProcessor proc, void *proc_cls)
{
struct Plugin *plugin = cls;
uint32_t btype;
uint64_t boff;
const int paramFormats[] = { 1, 1 };
int paramLengths[] = { sizeof (btype), sizeof (boff) };
- const char *paramValues[] = { (const char*) &btype, (const char*) &boff };
+ const char *paramValues[] = { (const char *) &btype, (const char *) &boff };
PGresult *ret;
btype = htonl ((uint32_t) type);
boff = GNUNET_htonll (offset);
ret = PQexecPrepared (plugin->dbh,
- "select_non_anonymous",
- 2,
- paramValues,
- paramLengths,
- paramFormats, 1);
- process_result (plugin,
- proc, proc_cls,
- ret, __LINE__);
+ "select_non_anonymous",
+ 2, paramValues, paramLengths, paramFormats, 1);
+ process_result (plugin, proc, proc_cls, ret, __LINE__);
}
@@ -857,17 +793,17 @@
*/
struct ReplCtx
{
-
+
/**
* Plugin handle.
*/
struct Plugin *plugin;
-
+
/**
* Function to call for the result (or the NULL).
*/
PluginDatumProcessor proc;
-
+
/**
* Closure for proc.
*/
@@ -898,14 +834,13 @@
*/
static int
repl_proc (void *cls,
- const GNUNET_HashCode *key,
- uint32_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- struct GNUNET_TIME_Absolute expiration,
- uint64_t uid)
+ const GNUNET_HashCode * key,
+ uint32_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute expiration, uint64_t uid)
{
struct ReplCtx *rc = cls;
struct Plugin *plugin = rc->plugin;
@@ -914,31 +849,27 @@
uint32_t boid;
ret = rc->proc (rc->proc_cls,
- key,
- size, data,
- type, priority, anonymity, expiration,
- uid);
+ key, size, data, type, priority, anonymity, expiration, uid);
if (NULL != key)
- {
- boid = htonl ( (uint32_t) uid);
- const char *paramValues[] = {
- (const char *) &boid,
- };
- int paramLengths[] = {
- sizeof (boid),
- };
- const int paramFormats[] = { 1 };
- qret = PQexecPrepared (plugin->dbh,
- "decrepl",
- 1, paramValues, paramLengths, paramFormats, 1);
- if (GNUNET_OK != check_result (plugin,
- qret,
- PGRES_COMMAND_OK,
- "PQexecPrepared",
- "decrepl", __LINE__))
- return GNUNET_SYSERR;
- PQclear (qret);
- }
+ {
+ boid = htonl ((uint32_t) uid);
+ const char *paramValues[] = {
+ (const char *) &boid,
+ };
+ int paramLengths[] = {
+ sizeof (boid),
+ };
+ const int paramFormats[] = { 1 };
+ qret = PQexecPrepared (plugin->dbh,
+ "decrepl",
+ 1, paramValues, paramLengths, paramFormats, 1);
+ if (GNUNET_OK != check_result (plugin,
+ qret,
+ PGRES_COMMAND_OK,
+ "PQexecPrepared", "decrepl", __LINE__))
+ return GNUNET_SYSERR;
+ PQclear (qret);
+ }
return ret;
}
@@ -955,7 +886,7 @@
*/
static void
postgres_plugin_get_replication (void *cls,
- PluginDatumProcessor proc, void *proc_cls)
+ PluginDatumProcessor proc, void *proc_cls)
{
struct Plugin *plugin = cls;
struct ReplCtx rc;
@@ -965,12 +896,8 @@
rc.proc = proc;
rc.proc_cls = proc_cls;
ret = PQexecPrepared (plugin->dbh,
- "select_replication_order",
- 0,
- NULL, NULL, NULL, 1);
- process_result (plugin,
- &repl_proc, &rc,
- ret, __LINE__);
+ "select_replication_order", 0, NULL, NULL, NULL, 1);
+ process_result (plugin, &repl_proc, &rc, ret, __LINE__);
}
@@ -984,26 +911,20 @@
*/
static void
postgres_plugin_get_expiration (void *cls,
- PluginDatumProcessor proc, void *proc_cls)
+ PluginDatumProcessor proc, void *proc_cls)
{
struct Plugin *plugin = cls;
uint64_t btime;
const int paramFormats[] = { 1 };
int paramLengths[] = { sizeof (btime) };
- const char *paramValues[] = { (const char*) &btime };
+ const char *paramValues[] = { (const char *) &btime };
PGresult *ret;
-
+
btime = GNUNET_htonll (GNUNET_TIME_absolute_get ().abs_value);
ret = PQexecPrepared (plugin->dbh,
- "select_expiration_order",
- 1,
- paramValues,
- paramLengths,
- paramFormats,
- 1);
- process_result (plugin,
- proc, proc_cls,
- ret, __LINE__);
+ "select_expiration_order",
+ 1, paramValues, paramLengths, paramFormats, 1);
+ process_result (plugin, proc, proc_cls, ret, __LINE__);
}
@@ -1032,15 +953,16 @@
*/
static int
postgres_plugin_update (void *cls,
- uint64_t uid,
- int delta, struct GNUNET_TIME_Absolute expire,
- char **msg)
+ uint64_t uid,
+ int delta, struct GNUNET_TIME_Absolute expire,
+ char **msg)
{
struct Plugin *plugin = cls;
PGresult *ret;
int32_t bdelta = (int32_t) htonl ((uint32_t) delta);
- uint32_t boid = htonl ( (uint32_t) uid);
+ uint32_t boid = htonl ((uint32_t) uid);
uint64_t bexpire = GNUNET_TIME_absolute_hton (expire).abs_value__;
+
const char *paramValues[] = {
(const char *) &bdelta,
(const char *) &bexpire,
@@ -1057,7 +979,7 @@
"update",
3, paramValues, paramLengths, paramFormats, 1);
if (GNUNET_OK != check_result (plugin,
- ret,
+ ret,
PGRES_COMMAND_OK,
"PQexecPrepared", "update", __LINE__))
return GNUNET_SYSERR;
@@ -1069,7 +991,7 @@
/**
* Drop database.
*/
-static void
+static void
postgres_plugin_drop (void *cls)
{
struct Plugin *plugin = cls;
@@ -1094,10 +1016,10 @@
plugin = GNUNET_malloc (sizeof (struct Plugin));
plugin->env = env;
if (GNUNET_OK != init_connection (plugin))
- {
- GNUNET_free (plugin);
- return NULL;
- }
+ {
+ GNUNET_free (plugin);
+ return NULL;
+ }
api = GNUNET_malloc (sizeof (struct GNUNET_DATASTORE_PluginFunctions));
api->cls = plugin;
api->estimate_size = &postgres_plugin_estimate_size;
@@ -1109,8 +1031,7 @@
api->get_zero_anonymity = &postgres_plugin_get_zero_anonymity;
api->drop = &postgres_plugin_drop;
GNUNET_log_from (GNUNET_ERROR_TYPE_INFO,
- "datastore-postgres",
- _("Postgres database running\n"));
+ "datastore-postgres", _("Postgres database running\n"));
return api;
}
@@ -1125,7 +1046,7 @@
{
struct GNUNET_DATASTORE_PluginFunctions *api = cls;
struct Plugin *plugin = api->cls;
-
+
PQfinish (plugin->dbh);
GNUNET_free (plugin);
GNUNET_free (api);
Modified: gnunet/src/datastore/plugin_datastore_sqlite.c
===================================================================
--- gnunet/src/datastore/plugin_datastore_sqlite.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/datastore/plugin_datastore_sqlite.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -1,23 +1,23 @@
/*
- This file is part of GNUnet
- (C) 2009, 2011 Christian Grothoff (and other contributing authors)
+ * This file is part of GNUnet
+ * (C) 2009, 2011 Christian Grothoff (and other contributing authors)
+ *
+ * GNUnet is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 3, or (at your
+ * option) any later version.
+ *
+ * GNUnet is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNUnet; see the file COPYING. If not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
- GNUnet is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 3, or (at your
- option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
-*/
-
/**
* @file datastore/plugin_datastore_sqlite.c
* @brief sqlite-based datastore backend
@@ -65,7 +65,7 @@
/**
* Context for all functions in this plugin.
*/
-struct Plugin
+struct Plugin
{
/**
* Our execution environment.
@@ -139,25 +139,17 @@
* @return 0 on success
*/
static int
-sq_prepare (sqlite3 * dbh,
- const char *zSql,
- sqlite3_stmt ** ppStmt)
+sq_prepare (sqlite3 * dbh, const char *zSql, sqlite3_stmt ** ppStmt)
{
char *dummy;
int result;
result = sqlite3_prepare_v2 (dbh,
- zSql,
- strlen (zSql),
- ppStmt,
- (const char **) &dummy);
+ zSql,
+ strlen (zSql), ppStmt, (const char **) &dummy);
#if DEBUG_SQLITE && 0
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "sqlite",
- "Prepared `%s' / %p: %d\n",
- zSql,
- *ppStmt,
- result);
+ "sqlite", "Prepared `%s' / %p: %d\n", zSql, *ppStmt,
result);
#endif
return result;
}
@@ -172,35 +164,40 @@
create_indices (sqlite3 * dbh)
{
/* create indices */
- if ( (SQLITE_OK !=
- sqlite3_exec (dbh,
- "CREATE INDEX IF NOT EXISTS idx_hash ON gn090 (hash)",
NULL, NULL, NULL)) ||
- (SQLITE_OK !=
- sqlite3_exec (dbh,
- "CREATE INDEX IF NOT EXISTS idx_hash_vhash ON gn090
(hash,vhash)", NULL,
- NULL, NULL)) ||
- (SQLITE_OK !=
- sqlite3_exec (dbh, "CREATE INDEX IF NOT EXISTS idx_expire_repl ON gn090
(expire ASC,repl DESC)", NULL, NULL,
- NULL)) ||
- (SQLITE_OK !=
- sqlite3_exec (dbh, "CREATE INDEX IF NOT EXISTS idx_comb ON gn090
(anonLevel ASC,expire ASC,prio,type,hash)",
- NULL, NULL, NULL)) ||
- (SQLITE_OK !=
- sqlite3_exec (dbh, "CREATE INDEX IF NOT EXISTS idx_anon_type_hash ON
gn090 (anonLevel ASC,type,hash)",
- NULL, NULL, NULL)) ||
- (SQLITE_OK !=
- sqlite3_exec (dbh, "CREATE INDEX IF NOT EXISTS idx_expire ON gn090
(expire ASC)",
- NULL, NULL, NULL)) ||
- (SQLITE_OK !=
- sqlite3_exec (dbh, "CREATE INDEX IF NOT EXISTS idx_repl_rvalue ON gn090
(repl,rvalue)",
- NULL, NULL, NULL)) ||
- (SQLITE_OK !=
- sqlite3_exec (dbh, "CREATE INDEX IF NOT EXISTS idx_repl ON gn090 (repl
DESC)",
- NULL, NULL, NULL)) )
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
- "sqlite",
- "Failed to create indices: %s\n",
- sqlite3_errmsg (dbh));
+ if ((SQLITE_OK !=
+ sqlite3_exec (dbh,
+ "CREATE INDEX IF NOT EXISTS idx_hash ON gn090 (hash)",
+ NULL, NULL, NULL)) ||
+ (SQLITE_OK !=
+ sqlite3_exec (dbh,
+ "CREATE INDEX IF NOT EXISTS idx_hash_vhash ON gn090
(hash,vhash)",
+ NULL, NULL, NULL)) ||
+ (SQLITE_OK !=
+ sqlite3_exec (dbh,
+ "CREATE INDEX IF NOT EXISTS idx_expire_repl ON gn090
(expire ASC,repl DESC)",
+ NULL, NULL, NULL)) ||
+ (SQLITE_OK !=
+ sqlite3_exec (dbh,
+ "CREATE INDEX IF NOT EXISTS idx_comb ON gn090 (anonLevel
ASC,expire ASC,prio,type,hash)",
+ NULL, NULL, NULL)) ||
+ (SQLITE_OK !=
+ sqlite3_exec (dbh,
+ "CREATE INDEX IF NOT EXISTS idx_anon_type_hash ON gn090
(anonLevel ASC,type,hash)",
+ NULL, NULL, NULL)) ||
+ (SQLITE_OK !=
+ sqlite3_exec (dbh,
+ "CREATE INDEX IF NOT EXISTS idx_expire ON gn090 (expire
ASC)",
+ NULL, NULL, NULL)) ||
+ (SQLITE_OK !=
+ sqlite3_exec (dbh,
+ "CREATE INDEX IF NOT EXISTS idx_repl_rvalue ON gn090
(repl,rvalue)",
+ NULL, NULL, NULL)) ||
+ (SQLITE_OK !=
+ sqlite3_exec (dbh,
+ "CREATE INDEX IF NOT EXISTS idx_repl ON gn090 (repl
DESC)",
+ NULL, NULL, NULL)))
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "sqlite",
+ "Failed to create indices: %s\n", sqlite3_errmsg (dbh));
}
@@ -225,56 +222,55 @@
*/
static int
database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg,
- struct Plugin *plugin)
+ struct Plugin *plugin)
{
sqlite3_stmt *stmt;
char *afsdir;
+
#if ENULL_DEFINED
char *e;
#endif
-
- if (GNUNET_OK !=
+
+ if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_filename (cfg,
- "datastore-sqlite",
- "FILENAME",
- &afsdir))
+ "datastore-sqlite",
+ "FILENAME", &afsdir))
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
+ "sqlite",
+ _
+ ("Option `%s' in section `%s' missing in
configuration!\n"),
+ "FILENAME", "datastore-sqlite");
+ return GNUNET_SYSERR;
+ }
+ if (GNUNET_OK != GNUNET_DISK_file_test (afsdir))
+ {
+ if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (afsdir))
{
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
- "sqlite",
- _("Option `%s' in section `%s' missing in
configuration!\n"),
- "FILENAME",
- "datastore-sqlite");
+ GNUNET_break (0);
+ GNUNET_free (afsdir);
return GNUNET_SYSERR;
}
- if (GNUNET_OK != GNUNET_DISK_file_test (afsdir))
- {
- if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (afsdir))
- {
- GNUNET_break (0);
- GNUNET_free (afsdir);
- return GNUNET_SYSERR;
- }
- /* database is new or got deleted, reset payload to zero! */
- plugin->env->duc (plugin->env->cls, 0);
- }
+ /* database is new or got deleted, reset payload to zero! */
+ plugin->env->duc (plugin->env->cls, 0);
+ }
#ifdef ENABLE_NLS
plugin->fn = GNUNET_STRINGS_to_utf8 (afsdir, strlen (afsdir),
- nl_langinfo (CODESET));
+ nl_langinfo (CODESET));
#else
- plugin->fn = GNUNET_STRINGS_to_utf8 (afsdir, strlen (afsdir),
- "UTF-8"); /* good luck */
+ plugin->fn = GNUNET_STRINGS_to_utf8 (afsdir, strlen (afsdir), "UTF-8");
/* good luck */
#endif
GNUNET_free (afsdir);
-
+
/* Open database and precompile statements */
if (sqlite3_open (plugin->fn, &plugin->dbh) != SQLITE_OK)
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
- "sqlite",
- _("Unable to initialize SQLite: %s.\n"),
- sqlite3_errmsg (plugin->dbh));
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
+ "sqlite",
+ _("Unable to initialize SQLite: %s.\n"),
+ sqlite3_errmsg (plugin->dbh));
+ return GNUNET_SYSERR;
+ }
CHECK (SQLITE_OK ==
sqlite3_exec (plugin->dbh,
"PRAGMA temp_store=MEMORY", NULL, NULL, ENULL));
@@ -294,8 +290,8 @@
sqlite3_exec (plugin->dbh,
"PRAGMA count_changes=OFF", NULL, NULL, ENULL));
CHECK (SQLITE_OK ==
- sqlite3_exec (plugin->dbh,
- "PRAGMA page_size=4092", NULL, NULL, ENULL));
+ sqlite3_exec (plugin->dbh,
+ "PRAGMA page_size=4092", NULL, NULL, ENULL));
CHECK (SQLITE_OK == sqlite3_busy_timeout (plugin->dbh, BUSY_TIMEOUT_MS));
@@ -305,63 +301,61 @@
sq_prepare (plugin->dbh,
"SELECT 1 FROM sqlite_master WHERE tbl_name = 'gn090'",
&stmt));
- if ( (sqlite3_step (stmt) == SQLITE_DONE) &&
- (sqlite3_exec (plugin->dbh,
- "CREATE TABLE gn090 ("
- " repl INT4 NOT NULL DEFAULT 0,"
- " type INT4 NOT NULL DEFAULT 0,"
- " prio INT4 NOT NULL DEFAULT 0,"
- " anonLevel INT4 NOT NULL DEFAULT 0,"
- " expire INT8 NOT NULL DEFAULT 0,"
- " rvalue INT8 NOT NULL,"
- " hash TEXT NOT NULL DEFAULT '',"
- " vhash TEXT NOT NULL DEFAULT '',"
- " value BLOB NOT NULL DEFAULT '')", NULL, NULL,
- NULL) != SQLITE_OK) )
- {
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR,
- "sqlite3_exec");
- sqlite3_finalize (stmt);
- return GNUNET_SYSERR;
- }
+ if ((sqlite3_step (stmt) == SQLITE_DONE) &&
+ (sqlite3_exec (plugin->dbh,
+ "CREATE TABLE gn090 ("
+ " repl INT4 NOT NULL DEFAULT 0,"
+ " type INT4 NOT NULL DEFAULT 0,"
+ " prio INT4 NOT NULL DEFAULT 0,"
+ " anonLevel INT4 NOT NULL DEFAULT 0,"
+ " expire INT8 NOT NULL DEFAULT 0,"
+ " rvalue INT8 NOT NULL,"
+ " hash TEXT NOT NULL DEFAULT '',"
+ " vhash TEXT NOT NULL DEFAULT '',"
+ " value BLOB NOT NULL DEFAULT '')", NULL, NULL,
+ NULL) != SQLITE_OK))
+ {
+ LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_exec");
+ sqlite3_finalize (stmt);
+ return GNUNET_SYSERR;
+ }
sqlite3_finalize (stmt);
create_indices (plugin->dbh);
if ((sq_prepare (plugin->dbh,
"UPDATE gn090 "
- "SET prio = prio + ?, expire = MAX(expire,?) WHERE _ROWID_ =
?",
+ "SET prio = prio + ?, expire = MAX(expire,?) WHERE _ROWID_
= ?",
&plugin->updPrio) != SQLITE_OK) ||
(sq_prepare (plugin->dbh,
"UPDATE gn090 "
- "SET repl = MAX (0, repl - 1) WHERE _ROWID_ = ?",
+ "SET repl = MAX (0, repl - 1) WHERE _ROWID_ = ?",
&plugin->updRepl) != SQLITE_OK) ||
(sq_prepare (plugin->dbh,
- "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ "
- "FROM gn090 INDEXED BY idx_repl_rvalue "
- "WHERE repl=?2 AND"
- " (rvalue>=?1 OR"
- " NOT EXISTS (SELECT 1 FROM gn090 INDEXED BY
idx_repl_rvalue WHERE repl=?2 AND rvalue>=?1 LIMIT 1))"
- " ORDER BY rvalue ASC"
- " LIMIT 1",
+ "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ "
+ "FROM gn090 INDEXED BY idx_repl_rvalue "
+ "WHERE repl=?2 AND"
+ " (rvalue>=?1 OR"
+ " NOT EXISTS (SELECT 1 FROM gn090 INDEXED BY
idx_repl_rvalue 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 INDEXED BY idx_repl_rvalue",
+ "SELECT MAX(repl) "
+ "FROM gn090 INDEXED BY idx_repl_rvalue",
&plugin->maxRepl) != SQLITE_OK) ||
(sq_prepare (plugin->dbh,
- "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ "
- "FROM gn090 INDEXED BY idx_expire"
- " WHERE NOT EXISTS (SELECT 1 FROM gn090 WHERE expire < ?1
LIMIT 1) OR (expire < ?1) "
- " ORDER BY expire ASC LIMIT 1",
+ "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ "
+ "FROM gn090 INDEXED BY idx_expire"
+ " 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 INDEXED BY idx_anon_type_hash "
- "WHERE (anonLevel = 0 AND type=?1) "
- "ORDER BY hash DESC LIMIT 1 OFFSET ?2",
- &plugin->selZeroAnon) != SQLITE_OK) ||
(sq_prepare (plugin->dbh,
+ "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ "
+ "FROM gn090 INDEXED BY idx_anon_type_hash "
+ "WHERE (anonLevel = 0 AND type=?1) "
+ "ORDER BY hash DESC LIMIT 1 OFFSET ?2",
+ &plugin->selZeroAnon) != SQLITE_OK) ||
+ (sq_prepare (plugin->dbh,
"INSERT INTO gn090 (repl, type, prio, "
"anonLevel, expire, rvalue, hash, vhash, value) "
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
@@ -369,11 +363,10 @@
(sq_prepare (plugin->dbh,
"DELETE FROM gn090 WHERE _ROWID_ = ?",
&plugin->delRow) != SQLITE_OK))
- {
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR, "precompiling");
- return GNUNET_SYSERR;
- }
+ {
+ LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR, "precompiling");
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
}
@@ -388,6 +381,7 @@
database_shutdown (struct Plugin *plugin)
{
int result;
+
#if SQLITE_VERSION_NUMBER >= 3007000
sqlite3_stmt *stmt;
#endif
@@ -408,36 +402,35 @@
sqlite3_finalize (plugin->selZeroAnon);
if (plugin->insertContent != NULL)
sqlite3_finalize (plugin->insertContent);
- result = sqlite3_close(plugin->dbh);
+ result = sqlite3_close (plugin->dbh);
#if SQLITE_VERSION_NUMBER >= 3007000
if (result == SQLITE_BUSY)
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
+ "sqlite",
+ _
+ ("Tried to close sqlite without finalizing all prepared
statements.\n"));
+ stmt = sqlite3_next_stmt (plugin->dbh, NULL);
+ while (stmt != NULL)
{
- GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
- "sqlite",
- _("Tried to close sqlite without finalizing all prepared
statements.\n"));
- stmt = sqlite3_next_stmt(plugin->dbh, NULL);
- while (stmt != NULL)
- {
#if DEBUG_SQLITE
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "sqlite", "Closing statement %p\n", stmt);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ "sqlite", "Closing statement %p\n", stmt);
#endif
- result = sqlite3_finalize(stmt);
+ result = sqlite3_finalize (stmt);
#if DEBUG_SQLITE
- if (result != SQLITE_OK)
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "sqlite",
- "Failed to close statement %p: %d\n", stmt,
result);
+ if (result != SQLITE_OK)
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ "sqlite",
+ "Failed to close statement %p: %d\n", stmt, result);
#endif
- stmt = sqlite3_next_stmt(plugin->dbh, NULL);
- }
- result = sqlite3_close(plugin->dbh);
+ stmt = sqlite3_next_stmt (plugin->dbh, NULL);
}
+ result = sqlite3_close (plugin->dbh);
+ }
#endif
if (SQLITE_OK != result)
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR,
- "sqlite3_close");
+ LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_close");
GNUNET_free_non_null (plugin->fn);
}
@@ -451,34 +444,34 @@
* @param rid the ID of the row to delete
*/
static int
-delete_by_rowid (struct Plugin* plugin,
- unsigned long long rid)
+delete_by_rowid (struct Plugin *plugin, unsigned long long rid)
{
- if (SQLITE_OK !=
- sqlite3_bind_int64 (plugin->delRow, 1, rid))
- {
+ if (SQLITE_OK != sqlite3_bind_int64 (plugin->delRow, 1, rid))
+ {
+ LOG_SQLITE (plugin, NULL,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_bind_XXXX");
+ if (SQLITE_OK != sqlite3_reset (plugin->delRow))
LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"sqlite3_bind_XXXX");
- if (SQLITE_OK != sqlite3_reset (plugin->delRow))
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"sqlite3_reset");
- return GNUNET_SYSERR;
- }
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_reset");
+ return GNUNET_SYSERR;
+ }
if (SQLITE_DONE != sqlite3_step (plugin->delRow))
- {
+ {
+ LOG_SQLITE (plugin, NULL,
+ GNUNET_ERROR_TYPE_ERROR |
+ GNUNET_ERROR_TYPE_BULK, "sqlite3_step");
+ if (SQLITE_OK != sqlite3_reset (plugin->delRow))
LOG_SQLITE (plugin, NULL,
GNUNET_ERROR_TYPE_ERROR |
- GNUNET_ERROR_TYPE_BULK, "sqlite3_step");
- if (SQLITE_OK != sqlite3_reset (plugin->delRow))
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR |
- GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
- return GNUNET_SYSERR;
- }
+ GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
+ return GNUNET_SYSERR;
+ }
if (SQLITE_OK != sqlite3_reset (plugin->delRow))
LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR |
- GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
+ GNUNET_ERROR_TYPE_ERROR |
+ GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
return GNUNET_OK;
}
@@ -500,15 +493,14 @@
*/
static int
sqlite_plugin_put (void *cls,
- const GNUNET_HashCode *key,
- uint32_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- uint32_t replication,
- struct GNUNET_TIME_Absolute expiration,
- char ** msg)
+ const GNUNET_HashCode * key,
+ uint32_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ uint32_t replication,
+ struct GNUNET_TIME_Absolute expiration, char **msg)
{
struct Plugin *plugin = cls;
int n;
@@ -521,13 +513,14 @@
return GNUNET_SYSERR;
#if DEBUG_SQLITE
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "sqlite",
- "Storing in database block with type %u/key `%s'/priority
%u/expiration in %llu ms (%lld).\n",
- type,
- GNUNET_h2s(key),
- priority,
- (unsigned long long) GNUNET_TIME_absolute_get_remaining
(expiration).rel_value,
- (long long) expiration.abs_value);
+ "sqlite",
+ "Storing in database block with type %u/key `%s'/priority
%u/expiration in %llu ms (%lld).\n",
+ type,
+ GNUNET_h2s (key),
+ priority,
+ (unsigned long long)
+ GNUNET_TIME_absolute_get_remaining (expiration).rel_value,
+ (long long) expiration.abs_value);
#endif
GNUNET_CRYPTO_hash (data, size, &vhash);
stmt = plugin->insertContent;
@@ -545,55 +538,54 @@
sqlite3_bind_blob (stmt, 8, &vhash, sizeof (GNUNET_HashCode),
SQLITE_TRANSIENT))
|| (SQLITE_OK !=
- sqlite3_bind_blob (stmt, 9, data, size,
- SQLITE_TRANSIENT)))
- {
- LOG_SQLITE (plugin,
- msg,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"sqlite3_bind_XXXX");
- if (SQLITE_OK != sqlite3_reset (stmt))
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"sqlite3_reset");
- return GNUNET_SYSERR;
- }
+ sqlite3_bind_blob (stmt, 9, data, size, SQLITE_TRANSIENT)))
+ {
+ LOG_SQLITE (plugin,
+ msg,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_bind_XXXX");
+ if (SQLITE_OK != sqlite3_reset (stmt))
+ LOG_SQLITE (plugin, NULL,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_reset");
+ return GNUNET_SYSERR;
+ }
n = sqlite3_step (stmt);
switch (n)
- {
- case SQLITE_DONE:
- plugin->env->duc (plugin->env->cls,
- size + GNUNET_DATASTORE_ENTRY_OVERHEAD);
+ {
+ case SQLITE_DONE:
+ plugin->env->duc (plugin->env->cls, size +
GNUNET_DATASTORE_ENTRY_OVERHEAD);
#if DEBUG_SQLITE
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "sqlite",
- "Stored new entry (%u bytes)\n",
- size + GNUNET_DATASTORE_ENTRY_OVERHEAD);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ "sqlite",
+ "Stored new entry (%u bytes)\n",
+ size + GNUNET_DATASTORE_ENTRY_OVERHEAD);
#endif
- ret = GNUNET_OK;
- break;
- case SQLITE_BUSY:
- GNUNET_break (0);
- LOG_SQLITE (plugin, msg,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "sqlite3_step");
- ret = GNUNET_SYSERR;
- break;
- default:
- LOG_SQLITE (plugin, msg,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "sqlite3_step");
- if (SQLITE_OK != sqlite3_reset (stmt))
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR |
- GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
- database_shutdown (plugin);
- database_setup (plugin->env->cfg,
- plugin);
- return GNUNET_SYSERR;
- }
+ ret = GNUNET_OK;
+ break;
+ case SQLITE_BUSY:
+ GNUNET_break (0);
+ LOG_SQLITE (plugin, msg,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_step");
+ ret = GNUNET_SYSERR;
+ break;
+ default:
+ LOG_SQLITE (plugin, msg,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_step");
+ if (SQLITE_OK != sqlite3_reset (stmt))
+ LOG_SQLITE (plugin, NULL,
+ GNUNET_ERROR_TYPE_ERROR |
+ GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
+ database_shutdown (plugin);
+ database_setup (plugin->env->cfg, plugin);
+ return GNUNET_SYSERR;
+ }
if (SQLITE_OK != sqlite3_reset (stmt))
LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR |
- GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
+ GNUNET_ERROR_TYPE_ERROR |
+ GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
return ret;
}
@@ -623,52 +615,51 @@
*/
static int
sqlite_plugin_update (void *cls,
- uint64_t uid,
- int delta, struct GNUNET_TIME_Absolute expire,
- char **msg)
+ uint64_t uid,
+ int delta, struct GNUNET_TIME_Absolute expire, char
**msg)
{
struct Plugin *plugin = cls;
int n;
- if ( (SQLITE_OK !=
- sqlite3_bind_int (plugin->updPrio, 1, delta)) ||
- (SQLITE_OK !=
- sqlite3_bind_int64 (plugin->updPrio, 2, expire.abs_value)) ||
- (SQLITE_OK !=
- sqlite3_bind_int64 (plugin->updPrio, 3, uid)) )
- {
- LOG_SQLITE (plugin, msg,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"sqlite3_bind_XXXX");
- if (SQLITE_OK != sqlite3_reset (plugin->updPrio))
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"sqlite3_reset");
- return GNUNET_SYSERR;
+ if ((SQLITE_OK !=
+ sqlite3_bind_int (plugin->updPrio, 1, delta)) ||
+ (SQLITE_OK !=
+ sqlite3_bind_int64 (plugin->updPrio, 2, expire.abs_value)) ||
+ (SQLITE_OK != sqlite3_bind_int64 (plugin->updPrio, 3, uid)))
+ {
+ LOG_SQLITE (plugin, msg,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_bind_XXXX");
+ if (SQLITE_OK != sqlite3_reset (plugin->updPrio))
+ LOG_SQLITE (plugin, NULL,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_reset");
+ return GNUNET_SYSERR;
- }
+ }
n = sqlite3_step (plugin->updPrio);
if (SQLITE_OK != sqlite3_reset (plugin->updPrio))
LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"sqlite3_reset");
- switch (n)
- {
- case SQLITE_DONE:
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_reset");
+ switch (n)
+ {
+ case SQLITE_DONE:
#if DEBUG_SQLITE
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "sqlite",
- "Block updated\n");
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite", "Block updated\n");
#endif
- return GNUNET_OK;
- case SQLITE_BUSY:
- LOG_SQLITE (plugin, msg,
- GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
- "sqlite3_step");
- return GNUNET_NO;
- default:
- LOG_SQLITE (plugin, msg,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "sqlite3_step");
- return GNUNET_SYSERR;
- }
+ return GNUNET_OK;
+ case SQLITE_BUSY:
+ LOG_SQLITE (plugin, msg,
+ GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_step");
+ return GNUNET_NO;
+ default:
+ LOG_SQLITE (plugin, msg,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_step");
+ return GNUNET_SYSERR;
+ }
}
@@ -683,8 +674,7 @@
*/
static void
execute_get (struct Plugin *plugin,
- sqlite3_stmt *stmt,
- PluginDatumProcessor proc, void *proc_cls)
+ sqlite3_stmt * stmt, PluginDatumProcessor proc, void *proc_cls)
{
int n;
struct GNUNET_TIME_Absolute expiration;
@@ -694,80 +684,74 @@
n = sqlite3_step (stmt);
switch (n)
+ {
+ case SQLITE_ROW:
+ size = sqlite3_column_bytes (stmt, 5);
+ rowid = sqlite3_column_int64 (stmt, 6);
+ if (sqlite3_column_bytes (stmt, 4) != sizeof (GNUNET_HashCode))
{
- case SQLITE_ROW:
- size = sqlite3_column_bytes (stmt, 5);
- rowid = sqlite3_column_int64 (stmt, 6);
- if (sqlite3_column_bytes (stmt, 4) != sizeof (GNUNET_HashCode))
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
- "sqlite",
- _("Invalid data in database. Trying to fix (by
deletion).\n"));
- if (SQLITE_OK != sqlite3_reset (stmt))
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR |
- GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
- if (GNUNET_OK == delete_by_rowid (plugin, rowid))
- plugin->env->duc (plugin->env->cls,
- - (size + GNUNET_DATASTORE_ENTRY_OVERHEAD));
- break;
- }
- expiration.abs_value = sqlite3_column_int64 (stmt, 3);
-#if DEBUG_SQLITE
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "sqlite",
- "Found reply in database with expiration %llu\n",
- (unsigned long long) expiration.abs_value);
-#endif
- ret = proc (proc_cls,
- sqlite3_column_blob (stmt, 4) /* key */,
- size,
- sqlite3_column_blob (stmt, 5) /* data */,
- sqlite3_column_int (stmt, 0) /* type */,
- sqlite3_column_int (stmt, 1) /* priority */,
- sqlite3_column_int (stmt, 2) /* anonymity */,
- expiration,
- rowid);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
+ "sqlite",
+ _
+ ("Invalid data in database. Trying to fix (by
deletion).\n"));
if (SQLITE_OK != sqlite3_reset (stmt))
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR |
- GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
- if ( (GNUNET_NO == ret) &&
- (GNUNET_OK == delete_by_rowid (plugin, rowid)) )
- plugin->env->duc (plugin->env->cls,
- - (size + GNUNET_DATASTORE_ENTRY_OVERHEAD));
- return;
- case SQLITE_DONE:
- /* database must be empty */
- if (SQLITE_OK != sqlite3_reset (stmt))
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR |
- GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
+ LOG_SQLITE (plugin, NULL,
+ GNUNET_ERROR_TYPE_ERROR |
+ GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
+ if (GNUNET_OK == delete_by_rowid (plugin, rowid))
+ plugin->env->duc (plugin->env->cls,
+ -(size + GNUNET_DATASTORE_ENTRY_OVERHEAD));
break;
- case SQLITE_BUSY:
- case SQLITE_ERROR:
- case SQLITE_MISUSE:
- default:
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "sqlite3_step");
- if (SQLITE_OK != sqlite3_reset (stmt))
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR |
- GNUNET_ERROR_TYPE_BULK,
- "sqlite3_reset");
- GNUNET_break (0);
- database_shutdown (plugin);
- database_setup (plugin->env->cfg,
- plugin);
- break;
}
+ expiration.abs_value = sqlite3_column_int64 (stmt, 3);
+#if DEBUG_SQLITE
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ "sqlite",
+ "Found reply in database with expiration %llu\n",
+ (unsigned long long) expiration.abs_value);
+#endif
+ ret = proc (proc_cls, sqlite3_column_blob (stmt, 4) /* key */ ,
+ size, sqlite3_column_blob (stmt, 5) /* data */ ,
+ sqlite3_column_int (stmt, 0) /* type */ ,
+ sqlite3_column_int (stmt, 1) /* priority */ ,
+ sqlite3_column_int (stmt, 2) /* anonymity */ ,
+ expiration, rowid);
+ if (SQLITE_OK != sqlite3_reset (stmt))
+ LOG_SQLITE (plugin, NULL,
+ GNUNET_ERROR_TYPE_ERROR |
+ GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
+ if ((GNUNET_NO == ret) && (GNUNET_OK == delete_by_rowid (plugin, rowid)))
+ plugin->env->duc (plugin->env->cls,
+ -(size + GNUNET_DATASTORE_ENTRY_OVERHEAD));
+ return;
+ case SQLITE_DONE:
+ /* database must be empty */
+ if (SQLITE_OK != sqlite3_reset (stmt))
+ LOG_SQLITE (plugin, NULL,
+ GNUNET_ERROR_TYPE_ERROR |
+ GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
+ break;
+ case SQLITE_BUSY:
+ case SQLITE_ERROR:
+ case SQLITE_MISUSE:
+ default:
+ LOG_SQLITE (plugin, NULL,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_step");
+ if (SQLITE_OK != sqlite3_reset (stmt))
+ LOG_SQLITE (plugin, NULL,
+ GNUNET_ERROR_TYPE_ERROR |
+ GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
+ GNUNET_break (0);
+ database_shutdown (plugin);
+ database_setup (plugin->env->cfg, plugin);
+ break;
+ }
if (SQLITE_OK != sqlite3_reset (stmt))
LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR |
- GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
- proc (proc_cls, NULL, 0, NULL, 0, 0, 0,
- GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ GNUNET_ERROR_TYPE_ERROR |
+ GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
+ proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
}
@@ -787,31 +771,28 @@
*/
static void
sqlite_plugin_get_zero_anonymity (void *cls,
- uint64_t offset,
- enum GNUNET_BLOCK_Type type,
- PluginDatumProcessor proc,
- void *proc_cls)
+ uint64_t offset,
+ enum GNUNET_BLOCK_Type type,
+ PluginDatumProcessor proc, void *proc_cls)
{
struct Plugin *plugin = cls;
sqlite3_stmt *stmt;
GNUNET_assert (type != GNUNET_BLOCK_TYPE_ANY);
stmt = plugin->selZeroAnon;
- if ( (SQLITE_OK != sqlite3_bind_int (stmt, 1, type)) ||
- (SQLITE_OK != sqlite3_bind_int64 (stmt, 2, offset)) )
- {
+ if ((SQLITE_OK != sqlite3_bind_int (stmt, 1, type)) ||
+ (SQLITE_OK != sqlite3_bind_int64 (stmt, 2, offset)))
+ {
+ LOG_SQLITE (plugin, NULL,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_bind_XXXX");
+ if (SQLITE_OK != sqlite3_reset (stmt))
LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "sqlite3_bind_XXXX");
- if (SQLITE_OK != sqlite3_reset (stmt))
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR |
- GNUNET_ERROR_TYPE_BULK,
- "sqlite3_reset");
- proc (proc_cls, NULL, 0, NULL, 0, 0, 0,
- GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
- }
+ GNUNET_ERROR_TYPE_ERROR |
+ GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
+ proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ return;
+ }
execute_get (plugin, stmt, proc, proc_cls);
}
@@ -836,11 +817,11 @@
*/
static void
sqlite_plugin_get_key (void *cls,
- uint64_t offset,
- const GNUNET_HashCode *key,
- const GNUNET_HashCode *vhash,
- enum GNUNET_BLOCK_Type type,
- PluginDatumProcessor proc, void *proc_cls)
+ uint64_t offset,
+ const GNUNET_HashCode * key,
+ const GNUNET_HashCode * vhash,
+ enum GNUNET_BLOCK_Type type,
+ PluginDatumProcessor proc, void *proc_cls)
{
struct Plugin *plugin = cls;
int ret;
@@ -855,48 +836,47 @@
GNUNET_snprintf (scratch, sizeof (scratch),
"SELECT count(*) FROM gn090 WHERE hash=?%s%s",
vhash == NULL ? "" : " AND vhash=?",
- type == 0 ? "" : " AND type=?");
+ type == 0 ? "" : " AND type=?");
if (sq_prepare (plugin->dbh, scratch, &stmt) != SQLITE_OK)
- {
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"sqlite_prepare");
- proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
- }
+ {
+ LOG_SQLITE (plugin, NULL,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite_prepare");
+ proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ return;
+ }
sqoff = 1;
ret = sqlite3_bind_blob (stmt, sqoff++,
key, sizeof (GNUNET_HashCode), SQLITE_TRANSIENT);
if ((vhash != NULL) && (ret == SQLITE_OK))
ret = sqlite3_bind_blob (stmt, sqoff++,
- vhash,
- sizeof (GNUNET_HashCode), SQLITE_TRANSIENT);
+ vhash, sizeof (GNUNET_HashCode),
SQLITE_TRANSIENT);
if ((type != 0) && (ret == SQLITE_OK))
ret = sqlite3_bind_int (stmt, sqoff++, type);
if (SQLITE_OK != ret)
- {
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR, "sqlite_bind");
- sqlite3_finalize (stmt);
- proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
- }
+ {
+ LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite_bind");
+ sqlite3_finalize (stmt);
+ proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ return;
+ }
ret = sqlite3_step (stmt);
if (ret != SQLITE_ROW)
- {
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR| GNUNET_ERROR_TYPE_BULK,
- "sqlite_step");
- sqlite3_finalize (stmt);
- proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
- }
+ {
+ LOG_SQLITE (plugin, NULL,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite_step");
+ sqlite3_finalize (stmt);
+ proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ return;
+ }
total = sqlite3_column_int (stmt, 0);
sqlite3_finalize (stmt);
if (0 == total)
- {
- proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
- }
+ {
+ proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ return;
+ }
limit_off = (int) (offset % total);
if (limit_off < 0)
limit_off += total;
@@ -907,36 +887,33 @@
vhash == NULL ? "" : " AND vhash=?",
type == 0 ? "" : " AND type=?");
if (sq_prepare (plugin->dbh, scratch, &stmt) != SQLITE_OK)
- {
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR |
- GNUNET_ERROR_TYPE_BULK, "sqlite_prepare");
- proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
- }
+ {
+ LOG_SQLITE (plugin, NULL,
+ GNUNET_ERROR_TYPE_ERROR |
+ GNUNET_ERROR_TYPE_BULK, "sqlite_prepare");
+ proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ return;
+ }
sqoff = 1;
ret = sqlite3_bind_blob (stmt,
- sqoff++,
- key,
- sizeof (GNUNET_HashCode),
- SQLITE_TRANSIENT);
+ sqoff++,
+ key, sizeof (GNUNET_HashCode), SQLITE_TRANSIENT);
if ((vhash != NULL) && (ret == SQLITE_OK))
ret = sqlite3_bind_blob (stmt,
- sqoff++,
- vhash,
- sizeof (GNUNET_HashCode), SQLITE_TRANSIENT);
+ sqoff++,
+ vhash, sizeof (GNUNET_HashCode),
SQLITE_TRANSIENT);
if ((type != 0) && (ret == SQLITE_OK))
ret = sqlite3_bind_int (stmt, sqoff++, type);
if (ret == SQLITE_OK)
ret = sqlite3_bind_int64 (stmt, sqoff++, limit_off);
if (ret != SQLITE_OK)
- {
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR |
- GNUNET_ERROR_TYPE_BULK, "sqlite_bind");
- proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
- }
+ {
+ LOG_SQLITE (plugin, NULL,
+ GNUNET_ERROR_TYPE_ERROR |
+ GNUNET_ERROR_TYPE_BULK, "sqlite_bind");
+ proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ return;
+ }
execute_get (plugin, stmt, proc, proc_cls);
sqlite3_finalize (stmt);
}
@@ -948,12 +925,12 @@
*/
struct ReplCtx
{
-
+
/**
* Function to call for the result (or the NULL).
*/
PluginDatumProcessor proc;
-
+
/**
* Closure for proc.
*/
@@ -992,28 +969,24 @@
*/
static int
repl_proc (void *cls,
- const GNUNET_HashCode *key,
- uint32_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- struct GNUNET_TIME_Absolute expiration,
- uint64_t uid)
+ const GNUNET_HashCode * key,
+ uint32_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute expiration, uint64_t uid)
{
struct ReplCtx *rc = cls;
int ret;
ret = rc->proc (rc->proc_cls,
- key,
- size, data,
- type, priority, anonymity, expiration,
- uid);
+ key, size, data, type, priority, anonymity, expiration, uid);
if (key != NULL)
- {
- rc->uid = uid;
- rc->have_uid = GNUNET_YES;
- }
+ {
+ rc->uid = uid;
+ rc->have_uid = GNUNET_YES;
+ }
return ret;
}
@@ -1030,7 +1003,7 @@
*/
static void
sqlite_plugin_get_replication (void *cls,
- PluginDatumProcessor proc, void *proc_cls)
+ PluginDatumProcessor proc, void *proc_cls)
{
struct Plugin *plugin = cls;
struct ReplCtx rc;
@@ -1040,76 +1013,77 @@
#if DEBUG_SQLITE
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "sqlite",
- "Getting random block based on replication order.\n");
+ "sqlite",
+ "Getting random block based on replication order.\n");
#endif
rc.have_uid = GNUNET_NO;
rc.proc = proc;
rc.proc_cls = proc_cls;
stmt = plugin->maxRepl;
if (SQLITE_ROW != sqlite3_step (stmt))
- {
- if (SQLITE_OK != sqlite3_reset (stmt))
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR |
- GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
- /* DB empty */
- proc (proc_cls, NULL, 0, NULL, 0, 0, 0,
- GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
- }
+ {
+ if (SQLITE_OK != sqlite3_reset (stmt))
+ LOG_SQLITE (plugin, NULL,
+ GNUNET_ERROR_TYPE_ERROR |
+ GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
+ /* DB empty */
+ proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ return;
+ }
repl = sqlite3_column_int (stmt, 0);
if (SQLITE_OK != sqlite3_reset (stmt))
LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR |
- GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
+ GNUNET_ERROR_TYPE_ERROR |
+ GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
stmt = plugin->selRepl;
rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX);
if (SQLITE_OK != sqlite3_bind_int64 (stmt, 1, rvalue))
- {
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"sqlite3_bind_XXXX");
- if (SQLITE_OK != sqlite3_reset (stmt))
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"sqlite3_reset");
- proc (proc_cls, NULL, 0, NULL, 0, 0, 0,
- GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
- }
+ {
+ LOG_SQLITE (plugin, NULL,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_bind_XXXX");
+ if (SQLITE_OK != sqlite3_reset (stmt))
+ LOG_SQLITE (plugin, NULL,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_reset");
+ proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ return;
+ }
if (SQLITE_OK != sqlite3_bind_int (stmt, 2, repl))
+ {
+ LOG_SQLITE (plugin, NULL,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_bind_XXXX");
+ if (SQLITE_OK != sqlite3_reset (stmt))
+ LOG_SQLITE (plugin, NULL,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_reset");
+ proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ return;
+ }
+ execute_get (plugin, stmt, &repl_proc, &rc);
+ if (GNUNET_YES == rc.have_uid)
+ {
+ if (SQLITE_OK != sqlite3_bind_int64 (plugin->updRepl, 1, rc.uid))
{
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"sqlite3_bind_XXXX");
- if (SQLITE_OK != sqlite3_reset (stmt))
+ LOG_SQLITE (plugin, NULL,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_bind_XXXX");
+ if (SQLITE_OK != sqlite3_reset (plugin->updRepl))
LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"sqlite3_reset");
- proc (proc_cls, NULL, 0, NULL, 0, 0, 0,
- GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ GNUNET_ERROR_TYPE_ERROR |
+ GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
return;
}
- execute_get (plugin, stmt, &repl_proc, &rc);
- if (GNUNET_YES == rc.have_uid)
- {
- if (SQLITE_OK !=
- sqlite3_bind_int64 (plugin->updRepl, 1, rc.uid))
- {
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"sqlite3_bind_XXXX");
- if (SQLITE_OK != sqlite3_reset (plugin->updRepl))
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR |
- GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
- return;
- }
- if (SQLITE_DONE != sqlite3_step (plugin->updRepl))
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR |
- GNUNET_ERROR_TYPE_BULK, "sqlite3_step");
- if (SQLITE_OK != sqlite3_reset (plugin->updRepl))
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR |
- GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
- }
+ if (SQLITE_DONE != sqlite3_step (plugin->updRepl))
+ LOG_SQLITE (plugin, NULL,
+ GNUNET_ERROR_TYPE_ERROR |
+ GNUNET_ERROR_TYPE_BULK, "sqlite3_step");
+ if (SQLITE_OK != sqlite3_reset (plugin->updRepl))
+ LOG_SQLITE (plugin, NULL,
+ GNUNET_ERROR_TYPE_ERROR |
+ GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
+ }
}
@@ -1124,7 +1098,7 @@
*/
static void
sqlite_plugin_get_expiration (void *cls,
- PluginDatumProcessor proc, void *proc_cls)
+ PluginDatumProcessor proc, void *proc_cls)
{
struct Plugin *plugin = cls;
sqlite3_stmt *stmt;
@@ -1132,22 +1106,23 @@
#if DEBUG_SQLITE
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "sqlite",
- "Getting random block based on expiration and priority
order.\n");
+ "sqlite",
+ "Getting random block based on expiration and priority
order.\n");
#endif
now = GNUNET_TIME_absolute_get ();
stmt = plugin->selExpi;
if (SQLITE_OK != sqlite3_bind_int64 (stmt, 1, now.abs_value))
- {
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"sqlite3_bind_XXXX");
- if (SQLITE_OK != sqlite3_reset (stmt))
- LOG_SQLITE (plugin, NULL,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"sqlite3_reset");
- proc (proc_cls, NULL, 0, NULL, 0, 0, 0,
- GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
- }
+ {
+ LOG_SQLITE (plugin, NULL,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_bind_XXXX");
+ if (SQLITE_OK != sqlite3_reset (stmt))
+ LOG_SQLITE (plugin, NULL,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_reset");
+ proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
+ return;
+ }
execute_get (plugin, stmt, proc, proc_cls);
}
@@ -1157,10 +1132,11 @@
*
* @param cls our plugin context
*/
-static void
+static void
sqlite_plugin_drop (void *cls)
{
struct Plugin *plugin = cls;
+
plugin->drop_on_shutdown = GNUNET_YES;
}
@@ -1179,49 +1155,41 @@
sqlite3_stmt *stmt;
uint64_t pages;
uint64_t page_size;
+
#if ENULL_DEFINED
char *e;
#endif
if (SQLITE_VERSION_NUMBER < 3006000)
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
- "datastore-sqlite",
- _("sqlite version to old to determine size, assuming
zero\n"));
- return 0;
- }
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
+ "datastore-sqlite",
+ _
+ ("sqlite version to old to determine size, assuming
zero\n"));
+ return 0;
+ }
+ CHECK (SQLITE_OK == sqlite3_exec (plugin->dbh, "VACUUM", NULL, NULL, ENULL));
CHECK (SQLITE_OK ==
- sqlite3_exec (plugin->dbh,
- "VACUUM", NULL, NULL, ENULL));
- CHECK (SQLITE_OK ==
- sqlite3_exec (plugin->dbh,
- "PRAGMA auto_vacuum=INCREMENTAL", NULL, NULL, ENULL));
- CHECK (SQLITE_OK ==
- sq_prepare (plugin->dbh,
- "PRAGMA page_count",
- &stmt));
- if (SQLITE_ROW ==
- sqlite3_step (stmt))
+ sqlite3_exec (plugin->dbh,
+ "PRAGMA auto_vacuum=INCREMENTAL", NULL, NULL, ENULL));
+ CHECK (SQLITE_OK == sq_prepare (plugin->dbh, "PRAGMA page_count", &stmt));
+ if (SQLITE_ROW == sqlite3_step (stmt))
pages = sqlite3_column_int64 (stmt, 0);
else
pages = 0;
sqlite3_finalize (stmt);
- CHECK (SQLITE_OK ==
- sq_prepare (plugin->dbh,
- "PRAGMA page_size",
- &stmt));
- CHECK (SQLITE_ROW ==
- sqlite3_step (stmt));
+ CHECK (SQLITE_OK == sq_prepare (plugin->dbh, "PRAGMA page_size", &stmt));
+ CHECK (SQLITE_ROW == sqlite3_step (stmt));
page_size = sqlite3_column_int64 (stmt, 0);
sqlite3_finalize (stmt);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Using sqlite page utilization to estimate payload (%llu pages
of size %llu bytes)\n"),
- (unsigned long long) pages,
- (unsigned long long) page_size);
- return pages * page_size;
+ _
+ ("Using sqlite page utilization to estimate payload (%llu pages
of size %llu bytes)\n"),
+ (unsigned long long) pages, (unsigned long long) page_size);
+ return pages * page_size;
}
-
+
/**
* Entry point for the plugin.
*
@@ -1236,15 +1204,14 @@
struct GNUNET_DATASTORE_PluginFunctions *api;
if (plugin.env != NULL)
- return NULL; /* can only initialize once! */
- memset (&plugin, 0, sizeof(struct Plugin));
+ return NULL; /* can only initialize once! */
+ memset (&plugin, 0, sizeof (struct Plugin));
plugin.env = env;
- if (GNUNET_OK !=
- database_setup (env->cfg, &plugin))
- {
- database_shutdown (&plugin);
- return NULL;
- }
+ if (GNUNET_OK != database_setup (env->cfg, &plugin))
+ {
+ database_shutdown (&plugin);
+ return NULL;
+ }
api = GNUNET_malloc (sizeof (struct GNUNET_DATASTORE_PluginFunctions));
api->cls = &plugin;
api->estimate_size = &sqlite_plugin_estimate_size;
@@ -1276,8 +1243,7 @@
#if DEBUG_SQLITE
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "sqlite",
- "sqlite plugin is done\n");
+ "sqlite", "sqlite plugin is done\n");
#endif
fn = NULL;
@@ -1285,24 +1251,20 @@
fn = GNUNET_strdup (plugin->fn);
#if DEBUG_SQLITE
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "sqlite",
- "Shutting down database\n");
+ "sqlite", "Shutting down database\n");
#endif
database_shutdown (plugin);
- plugin->env = NULL;
+ plugin->env = NULL;
GNUNET_free (api);
if (fn != NULL)
- {
- if (0 != UNLINK(fn))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
- "unlink",
- fn);
- GNUNET_free (fn);
- }
+ {
+ if (0 != UNLINK (fn))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn);
+ GNUNET_free (fn);
+ }
#if DEBUG_SQLITE
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "sqlite",
- "sqlite plugin is finished\n");
+ "sqlite", "sqlite plugin is finished\n");
#endif
return NULL;
}
Modified: gnunet/src/datastore/plugin_datastore_template.c
===================================================================
--- gnunet/src/datastore/plugin_datastore_template.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/datastore/plugin_datastore_template.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -31,7 +31,7 @@
/**
* Context for all functions in this plugin.
*/
-struct Plugin
+struct Plugin
{
/**
* Our execution environment.
@@ -47,7 +47,7 @@
* @param cls our "struct Plugin*"
* @return number of bytes used on disk
*/
-static unsigned long long
+static unsigned long long
template_plugin_estimate_size (void *cls)
{
GNUNET_break (0);
@@ -72,15 +72,14 @@
*/
static int
template_plugin_put (void *cls,
- const GNUNET_HashCode * key,
- uint32_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- uint32_t replication,
- struct GNUNET_TIME_Absolute expiration,
- char **msg)
+ const GNUNET_HashCode * key,
+ uint32_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ uint32_t replication,
+ struct GNUNET_TIME_Absolute expiration, char **msg)
{
GNUNET_break (0);
*msg = GNUNET_strdup ("not implemented");
@@ -108,11 +107,11 @@
*/
static void
template_plugin_get_key (void *cls,
- uint64_t offset,
- const GNUNET_HashCode * key,
- const GNUNET_HashCode * vhash,
- enum GNUNET_BLOCK_Type type,
- PluginDatumProcessor proc, void *proc_cls)
+ uint64_t offset,
+ const GNUNET_HashCode * key,
+ const GNUNET_HashCode * vhash,
+ enum GNUNET_BLOCK_Type type,
+ PluginDatumProcessor proc, void *proc_cls)
{
GNUNET_break (0);
}
@@ -132,7 +131,7 @@
*/
static void
template_plugin_get_replication (void *cls,
- PluginDatumProcessor proc, void *proc_cls)
+ PluginDatumProcessor proc, void *proc_cls)
{
GNUNET_break (0);
}
@@ -148,7 +147,7 @@
*/
static void
template_plugin_get_expiration (void *cls,
- PluginDatumProcessor proc, void *proc_cls)
+ PluginDatumProcessor proc, void *proc_cls)
{
GNUNET_break (0);
}
@@ -179,10 +178,9 @@
*/
static int
template_plugin_update (void *cls,
- uint64_t uid,
- int delta,
- struct GNUNET_TIME_Absolute expire,
- char **msg)
+ uint64_t uid,
+ int delta,
+ struct GNUNET_TIME_Absolute expire, char **msg)
{
GNUNET_break (0);
*msg = GNUNET_strdup ("not implemented");
@@ -204,10 +202,9 @@
*/
static void
template_plugin_get_zero_anonymity (void *cls,
- uint64_t offset,
- enum GNUNET_BLOCK_Type type,
- PluginDatumProcessor proc,
- void *proc_cls)
+ uint64_t offset,
+ enum GNUNET_BLOCK_Type type,
+ PluginDatumProcessor proc, void *proc_cls)
{
GNUNET_break (0);
}
@@ -216,7 +213,7 @@
/**
* Drop database.
*/
-static void
+static void
template_plugin_drop (void *cls)
{
GNUNET_break (0);
Modified: gnunet/src/datastore/test_datastore_api.c
===================================================================
--- gnunet/src/datastore/test_datastore_api.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/datastore/test_datastore_api.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -63,34 +63,35 @@
static const void *
get_data (int i)
{
- static char buf[60000];
+ static char buf[60000];
+
memset (buf, i, 8 * i);
return buf;
}
static int
-get_type(int i)
+get_type (int i)
{
- return i+1;
+ return i + 1;
}
-static int
+static int
get_priority (int i)
{
- return i+1;
+ return i + 1;
}
static int
-get_anonymity(int i)
+get_anonymity (int i)
{
return i;
}
-static struct GNUNET_TIME_Absolute
+static struct GNUNET_TIME_Absolute
get_expiration (int i)
{
struct GNUNET_TIME_Absolute av;
@@ -100,22 +101,22 @@
}
enum RunPhase
- {
- RP_DONE = 0,
- RP_PUT = 1,
- RP_GET = 2,
- RP_DEL = 3,
- RP_DO_DEL = 4,
- RP_DELVALIDATE = 5,
- RP_RESERVE = 6,
- RP_PUT_MULTIPLE = 7,
- RP_PUT_MULTIPLE_NEXT = 8,
- RP_GET_MULTIPLE = 9,
- RP_GET_MULTIPLE_NEXT = 10,
- RP_UPDATE = 11,
- RP_UPDATE_VALIDATE = 12,
- RP_ERROR
- };
+{
+ RP_DONE = 0,
+ RP_PUT = 1,
+ RP_GET = 2,
+ RP_DEL = 3,
+ RP_DO_DEL = 4,
+ RP_DELVALIDATE = 5,
+ RP_RESERVE = 6,
+ RP_PUT_MULTIPLE = 7,
+ RP_PUT_MULTIPLE_NEXT = 8,
+ RP_GET_MULTIPLE = 9,
+ RP_GET_MULTIPLE_NEXT = 10,
+ RP_UPDATE = 11,
+ RP_UPDATE_VALIDATE = 12,
+ RP_ERROR
+};
struct CpsRunContext
@@ -134,62 +135,52 @@
static void
-run_continuation (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
static void
-check_success (void *cls,
- int success,
- const char *msg)
+check_success (void *cls, int success, const char *msg)
{
struct CpsRunContext *crc = cls;
if (GNUNET_OK != success)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Operation %d/%d not successfull: `%s'\n",
- crc->phase,
- crc->i,
- msg);
- crc->phase = RP_ERROR;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Operation %d/%d not successfull: `%s'\n",
+ crc->phase, crc->i, msg);
+ crc->phase = RP_ERROR;
+ }
GNUNET_free_non_null (crc->data);
crc->data = NULL;
GNUNET_SCHEDULER_add_continuation (&run_continuation,
- crc,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
}
static void
-get_reserved (void *cls,
- int success,
- const char *msg)
+get_reserved (void *cls, int success, const char *msg)
{
struct CpsRunContext *crc = cls;
+
if (0 >= success)
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Error obtaining reservation: `%s'\n",
- msg);
+ "Error obtaining reservation: `%s'\n", msg);
GNUNET_assert (0 < success);
crc->rid = success;
GNUNET_SCHEDULER_add_continuation (&run_continuation,
- crc,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
}
-static void
+static void
check_value (void *cls,
- const GNUNET_HashCode * key,
- size_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- struct GNUNET_TIME_Absolute expiration,
- uint64_t uid)
+ const GNUNET_HashCode * key,
+ size_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute expiration, uint64_t uid)
{
struct CpsRunContext *crc = cls;
int i;
@@ -197,46 +188,42 @@
i = crc->i;
#if 0
fprintf (stderr,
- "Check value got `%s' of size %u, type %d, expire %llu\n",
- GNUNET_h2s (key),
- (unsigned int) size,
- type,
- (unsigned long long) expiration.abs_value);
+ "Check value got `%s' of size %u, type %d, expire %llu\n",
+ GNUNET_h2s (key),
+ (unsigned int) size,
+ type, (unsigned long long) expiration.abs_value);
fprintf (stderr,
- "Check value iteration %d wants size %u, type %d, expire %llu\n",
- i,
- (unsigned int) get_size (i),
- get_type (i),
- (unsigned long long) get_expiration(i).abs_value);
+ "Check value iteration %d wants size %u, type %d, expire %llu\n",
+ i,
+ (unsigned int) get_size (i),
+ get_type (i), (unsigned long long) get_expiration (i).abs_value);
#endif
GNUNET_assert (size == get_size (i));
- GNUNET_assert (0 == memcmp (data, get_data(i), size));
+ GNUNET_assert (0 == memcmp (data, get_data (i), size));
GNUNET_assert (type == get_type (i));
GNUNET_assert (priority == get_priority (i));
- GNUNET_assert (anonymity == get_anonymity(i));
- GNUNET_assert (expiration.abs_value == get_expiration(i).abs_value);
+ GNUNET_assert (anonymity == get_anonymity (i));
+ GNUNET_assert (expiration.abs_value == get_expiration (i).abs_value);
crc->offset++;
if (crc->i == 0)
- {
- crc->phase = RP_DEL;
- crc->i = ITERATIONS;
- }
+ {
+ crc->phase = RP_DEL;
+ crc->i = ITERATIONS;
+ }
GNUNET_SCHEDULER_add_continuation (&run_continuation,
- crc,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
}
-static void
+static void
delete_value (void *cls,
- const GNUNET_HashCode *key,
- size_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- struct GNUNET_TIME_Absolute
- expiration, uint64_t uid)
+ const GNUNET_HashCode * key,
+ size_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute expiration, uint64_t uid)
{
struct CpsRunContext *crc = cls;
@@ -248,21 +235,19 @@
memcpy (crc->data, data, size);
crc->phase = RP_DO_DEL;
GNUNET_SCHEDULER_add_continuation (&run_continuation,
- crc,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
}
-static void
+static void
check_nothing (void *cls,
- const GNUNET_HashCode *key,
- size_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- struct GNUNET_TIME_Absolute
- expiration, uint64_t uid)
+ const GNUNET_HashCode * key,
+ size_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute expiration, uint64_t uid)
{
struct CpsRunContext *crc = cls;
@@ -270,352 +255,310 @@
if (crc->i == 0)
crc->phase = RP_RESERVE;
GNUNET_SCHEDULER_add_continuation (&run_continuation,
- crc,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
}
-static void
+static void
check_multiple (void *cls,
- const GNUNET_HashCode * key,
- size_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- struct GNUNET_TIME_Absolute
- expiration, uint64_t uid)
+ const GNUNET_HashCode * key,
+ size_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute expiration, uint64_t uid)
{
struct CpsRunContext *crc = cls;
GNUNET_assert (key != NULL);
switch (crc->phase)
- {
- case RP_GET_MULTIPLE:
- crc->phase = RP_GET_MULTIPLE_NEXT;
- crc->first_uid = uid;
- crc->offset++;
- break;
- case RP_GET_MULTIPLE_NEXT:
- GNUNET_assert (uid != crc->first_uid);
- crc->phase = RP_UPDATE;
- break;
- default:
- GNUNET_break (0);
- crc->phase = RP_ERROR;
- break;
- }
+ {
+ case RP_GET_MULTIPLE:
+ crc->phase = RP_GET_MULTIPLE_NEXT;
+ crc->first_uid = uid;
+ crc->offset++;
+ break;
+ case RP_GET_MULTIPLE_NEXT:
+ GNUNET_assert (uid != crc->first_uid);
+ crc->phase = RP_UPDATE;
+ break;
+ default:
+ GNUNET_break (0);
+ crc->phase = RP_ERROR;
+ break;
+ }
if (priority == get_priority (42))
crc->uid = uid;
GNUNET_SCHEDULER_add_continuation (&run_continuation,
- crc,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
}
-static void
+static void
check_update (void *cls,
- const GNUNET_HashCode * key,
- size_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- struct GNUNET_TIME_Absolute
- expiration, uint64_t uid)
+ const GNUNET_HashCode * key,
+ size_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute expiration, uint64_t uid)
{
struct CpsRunContext *crc = cls;
GNUNET_assert (key != NULL);
- if ( (anonymity == get_anonymity (42)) &&
- (size == get_size (42)) &&
- (priority == get_priority (42) + 100) )
- crc->phase = RP_DONE;
+ if ((anonymity == get_anonymity (42)) &&
+ (size == get_size (42)) && (priority == get_priority (42) + 100))
+ crc->phase = RP_DONE;
else
- {
- GNUNET_assert (size == get_size (43));
- crc->offset++;
- }
+ {
+ GNUNET_assert (size == get_size (43));
+ crc->offset++;
+ }
GNUNET_SCHEDULER_add_continuation (&run_continuation,
- crc,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
}
static void
-run_continuation (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct CpsRunContext *crc = cls;
+
ok = (int) crc->phase;
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Test in phase %u\n", crc->phase);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test in phase %u\n", crc->phase);
#endif
switch (crc->phase)
- {
- case RP_PUT:
+ {
+ case RP_PUT:
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Executing `%s' number %u\n",
- "PUT",
- crc->i);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Executing `%s' number %u\n", "PUT", crc->i);
#endif
- GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
- GNUNET_DATASTORE_put (datastore,
- 0,
- &crc->key,
- get_size (crc->i),
- get_data (crc->i),
- get_type (crc->i),
- get_priority (crc->i),
- get_anonymity (crc->i),
- 0,
- get_expiration (crc->i),
- 1, 1, TIMEOUT,
- &check_success,
- crc);
- crc->i++;
- if (crc->i == ITERATIONS)
- crc->phase = RP_GET;
- break;
- case RP_GET:
- crc->i--;
+ GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
+ GNUNET_DATASTORE_put (datastore,
+ 0,
+ &crc->key,
+ get_size (crc->i),
+ get_data (crc->i),
+ get_type (crc->i),
+ get_priority (crc->i),
+ get_anonymity (crc->i),
+ 0,
+ get_expiration (crc->i),
+ 1, 1, TIMEOUT, &check_success, crc);
+ crc->i++;
+ if (crc->i == ITERATIONS)
+ crc->phase = RP_GET;
+ break;
+ case RP_GET:
+ crc->i--;
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Executing `%s' number %u\n",
- "GET",
- crc->i);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Executing `%s' number %u\n", "GET", crc->i);
#endif
- GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
- GNUNET_DATASTORE_get_key (datastore,
- crc->offset,
- &crc->key,
- get_type (crc->i),
- 1, 1, TIMEOUT,
- &check_value,
- crc);
- break;
- case RP_DEL:
- crc->i--;
+ GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
+ GNUNET_DATASTORE_get_key (datastore,
+ crc->offset,
+ &crc->key,
+ get_type (crc->i),
+ 1, 1, TIMEOUT, &check_value, crc);
+ break;
+ case RP_DEL:
+ crc->i--;
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Executing `%s' number %u\n",
- "DEL",
- crc->i);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Executing `%s' number %u\n", "DEL", crc->i);
#endif
- crc->data = NULL;
- GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
- GNUNET_assert (NULL !=
- GNUNET_DATASTORE_get_key (datastore,
- crc->offset,
- &crc->key,
- get_type (crc->i),
- 1, 1, TIMEOUT,
- &delete_value,
- crc));
- break;
- case RP_DO_DEL:
+ crc->data = NULL;
+ GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
+ GNUNET_assert (NULL !=
+ GNUNET_DATASTORE_get_key (datastore,
+ crc->offset,
+ &crc->key,
+ get_type (crc->i),
+ 1, 1, TIMEOUT,
+ &delete_value, crc));
+ break;
+ case RP_DO_DEL:
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Executing `%s' number %u\n",
- "DO_DEL",
- crc->i);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Executing `%s' number %u\n", "DO_DEL", crc->i);
#endif
- if (crc->i == 0)
- {
- crc->i = ITERATIONS;
- crc->phase = RP_DELVALIDATE;
- }
- else
- {
- crc->phase = RP_DEL;
- }
- GNUNET_assert (NULL !=
- GNUNET_DATASTORE_remove (datastore,
- &crc->key,
- crc->size,
- crc->data,
- 1, 1, TIMEOUT,
- &check_success,
- crc));
- break;
- case RP_DELVALIDATE:
- crc->i--;
+ if (crc->i == 0)
+ {
+ crc->i = ITERATIONS;
+ crc->phase = RP_DELVALIDATE;
+ }
+ else
+ {
+ crc->phase = RP_DEL;
+ }
+ GNUNET_assert (NULL !=
+ GNUNET_DATASTORE_remove (datastore,
+ &crc->key,
+ crc->size,
+ crc->data,
+ 1, 1, TIMEOUT,
+ &check_success, crc));
+ break;
+ case RP_DELVALIDATE:
+ crc->i--;
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Executing `%s' number %u\n",
- "DEL-VALIDATE",
- crc->i);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Executing `%s' number %u\n", "DEL-VALIDATE", crc->i);
#endif
- GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
- GNUNET_assert (NULL !=
- GNUNET_DATASTORE_get_key (datastore,
- crc->offset,
- &crc->key,
- get_type (crc->i),
- 1, 1, TIMEOUT,
- &check_nothing,
- crc));
- break;
- case RP_RESERVE:
- crc->phase = RP_PUT_MULTIPLE;
- GNUNET_DATASTORE_reserve (datastore,
- 128*1024,
- 2,
- 1, 1, TIMEOUT,
- &get_reserved,
- crc);
- break;
- case RP_PUT_MULTIPLE:
- crc->phase = RP_PUT_MULTIPLE_NEXT;
- GNUNET_DATASTORE_put (datastore,
- crc->rid,
- &crc->key,
- get_size (42),
- get_data (42),
- get_type (42),
- get_priority (42),
- get_anonymity (42),
- 0,
- get_expiration (42),
- 1, 1, TIMEOUT,
- &check_success,
- crc);
- break;
- case RP_PUT_MULTIPLE_NEXT:
- crc->phase = RP_GET_MULTIPLE;
- GNUNET_DATASTORE_put (datastore,
- crc->rid,
- &crc->key,
- get_size (43),
- get_data (43),
- get_type (42),
- get_priority (43),
- get_anonymity (43),
- 0,
- get_expiration (43),
- 1, 1, TIMEOUT,
- &check_success,
- crc);
- break;
- case RP_GET_MULTIPLE:
- GNUNET_assert (NULL !=
- GNUNET_DATASTORE_get_key (datastore,
- crc->offset,
- &crc->key,
- get_type (42),
- 1, 1, TIMEOUT,
- &check_multiple,
- crc));
- break;
- case RP_GET_MULTIPLE_NEXT:
- GNUNET_assert (NULL !=
- GNUNET_DATASTORE_get_key (datastore,
- crc->offset,
- &crc->key,
- get_type (42),
- 1, 1, TIMEOUT,
- &check_multiple,
- crc));
- break;
- case RP_UPDATE:
- GNUNET_assert (crc->uid > 0);
- crc->phase = RP_UPDATE_VALIDATE;
- GNUNET_DATASTORE_update (datastore,
- crc->uid,
- 100,
- get_expiration (42),
- 1, 1, TIMEOUT,
- &check_success,
- crc);
- break;
- case RP_UPDATE_VALIDATE:
- GNUNET_assert (NULL !=
- GNUNET_DATASTORE_get_key (datastore,
- crc->offset,
- &crc->key,
- get_type (42),
- 1, 1, TIMEOUT,
- &check_update,
- crc));
- break;
- case RP_DONE:
+ GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
+ GNUNET_assert (NULL !=
+ GNUNET_DATASTORE_get_key (datastore,
+ crc->offset,
+ &crc->key,
+ get_type (crc->i),
+ 1, 1, TIMEOUT,
+ &check_nothing, crc));
+ break;
+ case RP_RESERVE:
+ crc->phase = RP_PUT_MULTIPLE;
+ GNUNET_DATASTORE_reserve (datastore,
+ 128 * 1024, 2, 1, 1, TIMEOUT, &get_reserved,
crc);
+ break;
+ case RP_PUT_MULTIPLE:
+ crc->phase = RP_PUT_MULTIPLE_NEXT;
+ GNUNET_DATASTORE_put (datastore,
+ crc->rid,
+ &crc->key,
+ get_size (42),
+ get_data (42),
+ get_type (42),
+ get_priority (42),
+ get_anonymity (42),
+ 0,
+ get_expiration (42),
+ 1, 1, TIMEOUT, &check_success, crc);
+ break;
+ case RP_PUT_MULTIPLE_NEXT:
+ crc->phase = RP_GET_MULTIPLE;
+ GNUNET_DATASTORE_put (datastore,
+ crc->rid,
+ &crc->key,
+ get_size (43),
+ get_data (43),
+ get_type (42),
+ get_priority (43),
+ get_anonymity (43),
+ 0,
+ get_expiration (43),
+ 1, 1, TIMEOUT, &check_success, crc);
+ break;
+ case RP_GET_MULTIPLE:
+ GNUNET_assert (NULL !=
+ GNUNET_DATASTORE_get_key (datastore,
+ crc->offset,
+ &crc->key,
+ get_type (42),
+ 1, 1, TIMEOUT,
+ &check_multiple, crc));
+ break;
+ case RP_GET_MULTIPLE_NEXT:
+ GNUNET_assert (NULL !=
+ GNUNET_DATASTORE_get_key (datastore,
+ crc->offset,
+ &crc->key,
+ get_type (42),
+ 1, 1, TIMEOUT,
+ &check_multiple, crc));
+ break;
+ case RP_UPDATE:
+ GNUNET_assert (crc->uid > 0);
+ crc->phase = RP_UPDATE_VALIDATE;
+ GNUNET_DATASTORE_update (datastore,
+ crc->uid,
+ 100,
+ get_expiration (42),
+ 1, 1, TIMEOUT, &check_success, crc);
+ break;
+ case RP_UPDATE_VALIDATE:
+ GNUNET_assert (NULL !=
+ GNUNET_DATASTORE_get_key (datastore,
+ crc->offset,
+ &crc->key,
+ get_type (42),
+ 1, 1, TIMEOUT,
+ &check_update, crc));
+ break;
+ case RP_DONE:
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Finished, disconnecting\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Finished, disconnecting\n");
#endif
- GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES);
- GNUNET_free (crc);
- ok = 0;
- break;
- case RP_ERROR:
- GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES);
- GNUNET_free (crc);
- ok = 43;
- break;
- }
+ GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES);
+ GNUNET_free (crc);
+ ok = 0;
+ break;
+ case RP_ERROR:
+ GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES);
+ GNUNET_free (crc);
+ ok = 43;
+ break;
+ }
}
static void
-run_tests (void *cls,
- int32_t success,
- const char *msg)
+run_tests (void *cls, int32_t success, const char *msg)
{
struct CpsRunContext *crc = cls;
switch (success)
- {
- case GNUNET_YES:
- GNUNET_SCHEDULER_add_continuation (&run_continuation,
- crc,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- return;
- case GNUNET_NO:
- fprintf (stderr,
- "Test 'put' operation failed, key already exists (!?)\n");
- GNUNET_free (crc);
- return;
- case GNUNET_SYSERR:
- fprintf (stderr,
- "Test 'put' operation failed with error `%s' database likely not
setup, skipping test.\n",
- msg);
- GNUNET_free (crc);
- return;
- default:
- GNUNET_assert (0);
- }
+ {
+ case GNUNET_YES:
+ GNUNET_SCHEDULER_add_continuation (&run_continuation,
+ crc,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ return;
+ case GNUNET_NO:
+ fprintf (stderr, "Test 'put' operation failed, key already exists (!?)\n");
+ GNUNET_free (crc);
+ return;
+ case GNUNET_SYSERR:
+ fprintf (stderr,
+ "Test 'put' operation failed with error `%s' database likely not
setup, skipping test.\n",
+ msg);
+ GNUNET_free (crc);
+ return;
+ default:
+ GNUNET_assert (0);
+ }
}
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
struct CpsRunContext *crc;
static GNUNET_HashCode zkey;
- crc = GNUNET_malloc(sizeof(struct CpsRunContext));
+ crc = GNUNET_malloc (sizeof (struct CpsRunContext));
crc->cfg = cfg;
crc->phase = RP_PUT;
now = GNUNET_TIME_absolute_get ();
datastore = GNUNET_DATASTORE_connect (cfg);
if (NULL ==
GNUNET_DATASTORE_put (datastore, 0,
- &zkey, 4, "TEST",
- GNUNET_BLOCK_TYPE_TEST,
- 0, 0, 0, GNUNET_TIME_relative_to_absolute
(GNUNET_TIME_UNIT_SECONDS),
- 0, 1, GNUNET_TIME_UNIT_MINUTES,
- &run_tests, crc))
- {
- fprintf (stderr,
- "Test 'put' operation failed.\n");
- ok = 1;
- GNUNET_free (crc);
- }
+ &zkey, 4, "TEST",
+ GNUNET_BLOCK_TYPE_TEST,
+ 0, 0, 0,
+ GNUNET_TIME_relative_to_absolute
+ (GNUNET_TIME_UNIT_SECONDS), 0, 1,
+ GNUNET_TIME_UNIT_MINUTES, &run_tests, crc))
+ {
+ fprintf (stderr, "Test 'put' operation failed.\n");
+ ok = 1;
+ GNUNET_free (crc);
+ }
}
@@ -623,6 +566,7 @@
check ()
{
char cfg_name[128];
+
#if START_DATASTORE
struct GNUNET_OS_Process *proc;
#endif
@@ -639,28 +583,27 @@
GNUNET_GETOPT_OPTION_END
};
GNUNET_snprintf (cfg_name,
- sizeof (cfg_name),
- "test_datastore_api_data_%s.conf",
- plugin_name);
+ sizeof (cfg_name),
+ "test_datastore_api_data_%s.conf", plugin_name);
#if START_DATASTORE
proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
- "gnunet-service-arm",
+ "gnunet-service-arm",
#if VERBOSE
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", cfg_name, NULL);
+ "-c", cfg_name, NULL);
#endif
GNUNET_assert (NULL != proc);
GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
argv, "test-datastore-api", "nohelp",
options, &run, NULL);
#if START_DATASTORE
- sleep (1); /* give datastore chance to receive 'DROP' request */
+ sleep (1); /* give datastore chance to receive 'DROP'
request */
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;
@@ -680,17 +623,16 @@
sleep (1);
/* determine name of plugin to use */
plugin_name = argv[0];
- while (NULL != (pos = strstr(plugin_name, "_")))
- plugin_name = pos+1;
- if (NULL != (pos = strstr(plugin_name, ".")))
+ while (NULL != (pos = strstr (plugin_name, "_")))
+ plugin_name = pos + 1;
+ if (NULL != (pos = strstr (plugin_name, ".")))
pos[0] = 0;
else
pos = (char *) plugin_name;
GNUNET_snprintf (dir_name,
- sizeof (dir_name),
- "/tmp/test-gnunet-datastore-%s",
- plugin_name);
+ sizeof (dir_name),
+ "/tmp/test-gnunet-datastore-%s", plugin_name);
GNUNET_DISK_directory_remove (dir_name);
GNUNET_log_setup ("test-datastore-api",
#if VERBOSE
Modified: gnunet/src/datastore/test_datastore_api_management.c
===================================================================
--- gnunet/src/datastore/test_datastore_api_management.c 2011-08-15
21:40:08 UTC (rev 16580)
+++ gnunet/src/datastore/test_datastore_api_management.c 2011-08-15
21:46:35 UTC (rev 16581)
@@ -47,7 +47,7 @@
static int ok;
-static const char* plugin_name;
+static const char *plugin_name;
static size_t
get_size (int i)
@@ -59,34 +59,35 @@
static const void *
get_data (int i)
{
- static char buf[60000];
+ static char buf[60000];
+
memset (buf, i, 8 + 8 * (i % 256));
return buf;
}
static int
-get_type(int i)
+get_type (int i)
{
return 1;
}
-static int
+static int
get_priority (int i)
{
- return i+1;
+ return i + 1;
}
static int
-get_anonymity(int i)
+get_anonymity (int i)
{
return i;
}
-static struct GNUNET_TIME_Absolute
+static struct GNUNET_TIME_Absolute
get_expiration (int i)
{
struct GNUNET_TIME_Absolute av;
@@ -96,12 +97,12 @@
}
enum RunPhase
- {
- RP_PUT,
- RP_GET,
- RP_DONE,
- RP_GET_FAIL
- };
+{
+ RP_PUT,
+ RP_GET,
+ RP_DONE,
+ RP_GET_FAIL
+};
struct CpsRunContext
@@ -117,77 +118,70 @@
static void
-run_continuation (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
static void
-check_success (void *cls,
- int success,
- const char *msg)
+check_success (void *cls, int success, const char *msg)
{
struct CpsRunContext *crc = cls;
+
if (GNUNET_OK != success)
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "%s\n", msg);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s\n", msg);
GNUNET_assert (GNUNET_OK == success);
GNUNET_free_non_null (crc->data);
crc->data = NULL;
GNUNET_SCHEDULER_add_continuation (&run_continuation,
- crc,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
}
-static void
+static void
check_value (void *cls,
- const GNUNET_HashCode * key,
- size_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- struct GNUNET_TIME_Absolute expiration,
- uint64_t uid)
+ const GNUNET_HashCode * key,
+ size_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute expiration, uint64_t uid)
{
struct CpsRunContext *crc = cls;
int i;
if (NULL == key)
- {
- crc->phase = RP_GET_FAIL;
- GNUNET_SCHEDULER_add_continuation (&run_continuation,
- crc,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- return;
- }
+ {
+ crc->phase = RP_GET_FAIL;
+ GNUNET_SCHEDULER_add_continuation (&run_continuation,
+ crc,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ return;
+ }
i = crc->i;
GNUNET_assert (size == get_size (i));
- GNUNET_assert (0 == memcmp (data, get_data(i), size));
+ GNUNET_assert (0 == memcmp (data, get_data (i), size));
GNUNET_assert (type == get_type (i));
GNUNET_assert (priority == get_priority (i));
- GNUNET_assert (anonymity == get_anonymity(i));
- GNUNET_assert (expiration.abs_value == get_expiration(i).abs_value);
+ GNUNET_assert (anonymity == get_anonymity (i));
+ GNUNET_assert (expiration.abs_value == get_expiration (i).abs_value);
crc->offset++;
crc->i--;
if (crc->i == 0)
crc->phase = RP_DONE;
GNUNET_SCHEDULER_add_continuation (&run_continuation,
- crc,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
}
-static void
+static void
check_nothing (void *cls,
- const GNUNET_HashCode * key,
- size_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- struct GNUNET_TIME_Absolute
- expiration, uint64_t uid)
+ const GNUNET_HashCode * key,
+ size_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute expiration, uint64_t uid)
{
struct CpsRunContext *crc = cls;
@@ -195,143 +189,125 @@
if (0 == --crc->i)
crc->phase = RP_DONE;
GNUNET_SCHEDULER_add_continuation (&run_continuation,
- crc,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
}
static void
-run_continuation (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct CpsRunContext *crc = cls;
+
ok = (int) crc->phase;
switch (crc->phase)
- {
- case RP_PUT:
+ {
+ case RP_PUT:
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Executing `%s' number %u\n",
- "PUT",
- crc->i);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Executing `%s' number %u\n", "PUT", crc->i);
#endif
- GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
- GNUNET_DATASTORE_put (datastore,
- 0,
- &crc->key,
- get_size (crc->i),
- get_data (crc->i),
- get_type (crc->i),
- get_priority (crc->i),
- get_anonymity (crc->i),
- 0,
- get_expiration (crc->i),
- 1, 1, TIMEOUT,
- &check_success,
- crc);
- crc->i++;
- if (crc->i == ITERATIONS)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Sleeping to give datastore time to clean up\n");
- sleep (1);
- crc->phase = RP_GET;
- crc->i--;
- }
- break;
- case RP_GET:
+ GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
+ GNUNET_DATASTORE_put (datastore,
+ 0,
+ &crc->key,
+ get_size (crc->i),
+ get_data (crc->i),
+ get_type (crc->i),
+ get_priority (crc->i),
+ get_anonymity (crc->i),
+ 0,
+ get_expiration (crc->i),
+ 1, 1, TIMEOUT, &check_success, crc);
+ crc->i++;
+ if (crc->i == ITERATIONS)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Sleeping to give datastore time to clean up\n");
+ sleep (1);
+ crc->phase = RP_GET;
+ crc->i--;
+ }
+ break;
+ case RP_GET:
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Executing `%s' number %u\n",
- "GET",
- crc->i);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Executing `%s' number %u\n", "GET", crc->i);
#endif
- GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
- GNUNET_DATASTORE_get_key (datastore,
- crc->offset++,
- &crc->key,
- get_type (crc->i),
- 1, 1, TIMEOUT,
- &check_value,
- crc);
- break;
- case RP_GET_FAIL:
+ GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
+ GNUNET_DATASTORE_get_key (datastore,
+ crc->offset++,
+ &crc->key,
+ get_type (crc->i),
+ 1, 1, TIMEOUT, &check_value, crc);
+ break;
+ case RP_GET_FAIL:
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Executing `%s' number %u\n",
- "GET(f)",
- crc->i);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Executing `%s' number %u\n", "GET(f)", crc->i);
#endif
- GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
- GNUNET_DATASTORE_get_key (datastore,
- crc->offset++,
- &crc->key,
- get_type (crc->i),
- 1, 1, TIMEOUT,
- &check_nothing,
- crc);
- break;
- case RP_DONE:
- GNUNET_assert (0 == crc->i);
+ GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
+ GNUNET_DATASTORE_get_key (datastore,
+ crc->offset++,
+ &crc->key,
+ get_type (crc->i),
+ 1, 1, TIMEOUT, &check_nothing, crc);
+ break;
+ case RP_DONE:
+ GNUNET_assert (0 == crc->i);
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Finished, disconnecting\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Finished, disconnecting\n");
#endif
- GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES);
- GNUNET_free (crc);
- ok = 0;
- }
+ GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES);
+ GNUNET_free (crc);
+ ok = 0;
+ }
}
static void
-run_tests (void *cls,
- int success,
- const char *msg)
+run_tests (void *cls, int success, const char *msg)
{
struct CpsRunContext *crc = cls;
if (success != GNUNET_YES)
- {
- fprintf (stderr,
- "Test 'put' operation failed with error `%s' database likely not
setup, skipping test.",
- msg);
- GNUNET_free (crc);
- return;
- }
+ {
+ fprintf (stderr,
+ "Test 'put' operation failed with error `%s' database likely not
setup, skipping test.",
+ msg);
+ GNUNET_free (crc);
+ return;
+ }
GNUNET_SCHEDULER_add_continuation (&run_continuation,
- crc,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
}
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
struct CpsRunContext *crc;
static GNUNET_HashCode zkey;
- crc = GNUNET_malloc(sizeof(struct CpsRunContext));
+ crc = GNUNET_malloc (sizeof (struct CpsRunContext));
crc->cfg = cfg;
crc->phase = RP_PUT;
now = GNUNET_TIME_absolute_get ();
datastore = GNUNET_DATASTORE_connect (cfg);
if (NULL ==
GNUNET_DATASTORE_put (datastore, 0,
- &zkey, 4, "TEST",
- GNUNET_BLOCK_TYPE_TEST,
- 0, 0, 0, GNUNET_TIME_relative_to_absolute
(GNUNET_TIME_UNIT_SECONDS),
- 0, 1, GNUNET_TIME_UNIT_MINUTES,
- &run_tests, crc))
- {
- fprintf (stderr,
- "Test 'put' operation failed.\n");
- GNUNET_free (crc);
- ok = 1;
- }
+ &zkey, 4, "TEST",
+ GNUNET_BLOCK_TYPE_TEST,
+ 0, 0, 0,
+ GNUNET_TIME_relative_to_absolute
+ (GNUNET_TIME_UNIT_SECONDS), 0, 1,
+ GNUNET_TIME_UNIT_MINUTES, &run_tests, crc))
+ {
+ fprintf (stderr, "Test 'put' operation failed.\n");
+ GNUNET_free (crc);
+ ok = 1;
+ }
}
@@ -341,7 +317,8 @@
{
struct GNUNET_OS_Process *proc;
char cfg_name[128];
- char *const argv[] = {
+
+ char *const argv[] = {
"test-datastore-api-management",
"-c",
cfg_name,
@@ -354,25 +331,24 @@
GNUNET_GETOPT_OPTION_END
};
GNUNET_snprintf (cfg_name,
- sizeof (cfg_name),
- "test_datastore_api_data_%s.conf",
- plugin_name);
+ sizeof (cfg_name),
+ "test_datastore_api_data_%s.conf", plugin_name);
proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
- "gnunet-service-arm",
+ "gnunet-service-arm",
#if VERBOSE
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", cfg_name, NULL);
+ "-c", cfg_name, NULL);
GNUNET_assert (NULL != proc);
GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
argv, "test-datastore-api-management", "nohelp",
options, &run, NULL);
- sleep (1); /* give datastore chance to process 'DROP' request */
+ sleep (1); /* give datastore chance to process 'DROP'
request */
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;
@@ -385,24 +361,23 @@
main (int argc, char *argv[])
{
int ret;
-
+
char *pos;
char dir_name[128];
sleep (1);
/* determine name of plugin to use */
plugin_name = argv[0];
- while (NULL != (pos = strstr(plugin_name, "_")))
- plugin_name = pos+1;
- if (NULL != (pos = strstr(plugin_name, ".")))
+ while (NULL != (pos = strstr (plugin_name, "_")))
+ plugin_name = pos + 1;
+ if (NULL != (pos = strstr (plugin_name, ".")))
pos[0] = 0;
else
pos = (char *) plugin_name;
GNUNET_snprintf (dir_name,
- sizeof (dir_name),
- "/tmp/test-gnunet-datastore-%s",
- plugin_name);
+ sizeof (dir_name),
+ "/tmp/test-gnunet-datastore-%s", plugin_name);
GNUNET_DISK_directory_remove (dir_name);
GNUNET_log_setup ("test-datastore-api-management",
#if VERBOSE
Modified: gnunet/src/datastore/test_plugin_datastore.c
===================================================================
--- gnunet/src/datastore/test_plugin_datastore.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/datastore/test_plugin_datastore.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -46,22 +46,22 @@
static int ok;
enum RunPhase
- {
- RP_ERROR = 0,
- RP_PUT,
- RP_GET,
- RP_UPDATE,
- RP_ITER_ZERO,
- RP_REPL_GET,
- RP_EXPI_GET,
- RP_DROP
- };
+{
+ RP_ERROR = 0,
+ RP_PUT,
+ RP_GET,
+ RP_UPDATE,
+ RP_ITER_ZERO,
+ RP_REPL_GET,
+ RP_EXPI_GET,
+ RP_DROP
+};
struct CpsRunContext
{
const struct GNUNET_CONFIGURATION_Handle *cfg;
- struct GNUNET_DATASTORE_PluginFunctions * api;
+ struct GNUNET_DATASTORE_PluginFunctions *api;
enum RunPhase phase;
unsigned int cnt;
unsigned int i;
@@ -78,27 +78,23 @@
* 0 for "reset to empty"
*/
static void
-disk_utilization_change_cb (void *cls,
- int delta)
+disk_utilization_change_cb (void *cls, int delta)
{
/* do nothing */
}
static void
-gen_key (int i,
- GNUNET_HashCode *key)
+gen_key (int i, GNUNET_HashCode * key)
{
memset (key, 0, sizeof (GNUNET_HashCode));
key->bits[0] = (unsigned int) i;
GNUNET_CRYPTO_hash (key, sizeof (GNUNET_HashCode), key);
}
-
+
static void
-put_value (struct GNUNET_DATASTORE_PluginFunctions * api,
- int i,
- int k)
+put_value (struct GNUNET_DATASTORE_PluginFunctions *api, int i, int k)
{
char value[65536];
size_t size;
@@ -109,7 +105,7 @@
/* most content is 32k */
size = 32 * 1024;
- if (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16) == 0) /* but
some of it is less! */
+ if (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16) == 0) /* but
some of it is less! */
size = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 32 * 1024);
size = size - (size & 7); /* always multiple of 8 */
@@ -122,37 +118,31 @@
msg = NULL;
prio = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100);
#if VERBOSE
- fprintf (stderr,
- "putting type %u, anon %u under key %s\n",
- i+1, i, GNUNET_h2s (&key));
+ fprintf (stderr,
+ "putting type %u, anon %u under key %s\n",
+ i + 1, i, GNUNET_h2s (&key));
#endif
- if (GNUNET_OK != api->put (api->cls,
- &key,
- size,
- value,
- i + 1 /* type */,
- prio,
- i /* anonymity */,
- 0 /* replication */,
- GNUNET_TIME_relative_to_absolute
- (GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_MILLISECONDS,
- 60 * 60 * 60 *
1000 +
-
GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1000))),
- &msg))
- {
- fprintf (stderr, "ERROR: `%s'\n", msg);
- GNUNET_free_non_null (msg);
- return;
- }
+ if (GNUNET_OK != api->put (api->cls, &key, size, value, i + 1 /* type */ ,
+ prio, i /* anonymity */ ,
+ 0 /* replication */ ,
+ GNUNET_TIME_relative_to_absolute
+ (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MILLISECONDS,
+ 60 * 60 * 60 * 1000 +
+ GNUNET_CRYPTO_random_u32
+ (GNUNET_CRYPTO_QUALITY_WEAK, 1000))), &msg))
+ {
+ fprintf (stderr, "ERROR: `%s'\n", msg);
+ GNUNET_free_non_null (msg);
+ return;
+ }
stored_bytes += size;
stored_ops++;
stored_entries++;
}
-static void
-test (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+static void test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
static uint64_t guid;
@@ -160,28 +150,25 @@
static int
iterate_one_shot (void *cls,
- const GNUNET_HashCode * key,
- uint32_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- struct GNUNET_TIME_Absolute
- expiration,
- uint64_t uid)
+ const GNUNET_HashCode * key,
+ uint32_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute expiration, uint64_t uid)
{
struct CpsRunContext *crc = cls;
-
+
GNUNET_assert (key != NULL);
guid = uid;
crc->phase++;
#if VERBOSE
fprintf (stderr,
- "Found result type=%u, priority=%u, size=%u, expire=%llu, key %s\n",
- type, priority, size,
- (unsigned long long) expiration.abs_value,
- GNUNET_h2s (key));
-#endif
+ "Found result type=%u, priority=%u, size=%u, expire=%llu, key %s\n",
+ type, priority, size,
+ (unsigned long long) expiration.abs_value, GNUNET_h2s (key));
+#endif
GNUNET_SCHEDULER_add_now (&test, crc);
return GNUNET_OK;
}
@@ -195,8 +182,8 @@
* @param cfg configuration to use
*/
static void
-unload_plugin (struct GNUNET_DATASTORE_PluginFunctions * api,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+unload_plugin (struct GNUNET_DATASTORE_PluginFunctions *api,
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
{
char *name;
char *libname;
@@ -204,13 +191,12 @@
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
"DATASTORE", "DATABASE", &name))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("No `%s' specified for `%s' in configuration!\n"),
- "DATABASE",
- "DATASTORE");
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("No `%s' specified for `%s' in configuration!\n"),
+ "DATABASE", "DATASTORE");
+ return;
+ }
GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name);
GNUNET_break (NULL == GNUNET_PLUGIN_unload (libname, api));
GNUNET_free (libname);
@@ -224,8 +210,7 @@
* the transport and core.
*/
static void
-cleaning_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct CpsRunContext *crc = cls;
@@ -235,9 +220,8 @@
static void
-test (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
+test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
struct CpsRunContext *crc = cls;
int j;
unsigned long long os;
@@ -245,91 +229,76 @@
GNUNET_HashCode key;
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Test aborted.\n");
- crc->phase = RP_ERROR;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Test aborted.\n");
+ crc->phase = RP_ERROR;
+ }
#if VERBOSE
- fprintf (stderr, "In phase %d, iteration %u\n",
- crc->phase,
- crc->cnt);
+ fprintf (stderr, "In phase %d, iteration %u\n", crc->phase, crc->cnt);
#endif
switch (crc->phase)
+ {
+ case RP_ERROR:
+ ok = 1;
+ GNUNET_break (0);
+ crc->api->drop (crc->api->cls);
+ GNUNET_SCHEDULER_add_now (&cleaning_task, crc);
+ break;
+ case RP_PUT:
+ os = 0;
+ for (j = 0; j < PUT_10; j++)
{
- case RP_ERROR:
- ok = 1;
- GNUNET_break (0);
- crc->api->drop (crc->api->cls);
- GNUNET_SCHEDULER_add_now (&cleaning_task, crc);
- break;
- case RP_PUT:
- os = 0;
- for (j=0;j<PUT_10;j++)
- {
- put_value (crc->api, j, crc->i);
- cs = crc->api->estimate_size (crc->api->cls);
- GNUNET_assert (os <= cs);
- os = cs;
- }
+ put_value (crc->api, j, crc->i);
+ cs = crc->api->estimate_size (crc->api->cls);
+ GNUNET_assert (os <= cs);
+ os = cs;
+ }
+ crc->phase++;
+ GNUNET_SCHEDULER_add_now (&test, crc);
+ break;
+ case RP_GET:
+ if (crc->cnt == 1)
+ {
+ crc->cnt = 0;
crc->phase++;
GNUNET_SCHEDULER_add_now (&test, crc);
break;
- case RP_GET:
- if (crc->cnt == 1)
- {
- crc->cnt = 0;
- crc->phase++;
- GNUNET_SCHEDULER_add_now (&test, crc);
- break;
- }
- gen_key (5, &key);
- crc->api->get_key (crc->api->cls,
- crc->offset++,
- &key, NULL,
- GNUNET_BLOCK_TYPE_ANY,
- &iterate_one_shot,
- crc);
- break;
- case RP_UPDATE:
- GNUNET_assert (GNUNET_OK ==
- crc->api->update (crc->api->cls,
- guid, 1,
- GNUNET_TIME_UNIT_ZERO_ABS,
- NULL));
+ }
+ gen_key (5, &key);
+ crc->api->get_key (crc->api->cls,
+ crc->offset++,
+ &key, NULL,
+ GNUNET_BLOCK_TYPE_ANY, &iterate_one_shot, crc);
+ break;
+ case RP_UPDATE:
+ GNUNET_assert (GNUNET_OK ==
+ crc->api->update (crc->api->cls,
+ guid, 1, GNUNET_TIME_UNIT_ZERO_ABS,
NULL));
+ crc->phase++;
+ GNUNET_SCHEDULER_add_now (&test, crc);
+ break;
+
+ case RP_ITER_ZERO:
+ if (crc->cnt == 1)
+ {
+ crc->cnt = 0;
crc->phase++;
GNUNET_SCHEDULER_add_now (&test, crc);
break;
-
- case RP_ITER_ZERO:
- if (crc->cnt == 1)
- {
- crc->cnt = 0;
- crc->phase++;
- GNUNET_SCHEDULER_add_now (&test, crc);
- break;
- }
- crc->api->get_zero_anonymity (crc->api->cls,
- 0,
- 1,
- &iterate_one_shot,
- crc);
- break;
- case RP_REPL_GET:
- crc->api->get_replication (crc->api->cls,
- &iterate_one_shot,
- crc);
- break;
- case RP_EXPI_GET:
- crc->api->get_expiration (crc->api->cls,
- &iterate_one_shot,
- crc);
- break;
- case RP_DROP:
- crc->api->drop (crc->api->cls);
- GNUNET_SCHEDULER_add_now (&cleaning_task, crc);
- break;
}
+ crc->api->get_zero_anonymity (crc->api->cls, 0, 1, &iterate_one_shot, crc);
+ break;
+ case RP_REPL_GET:
+ crc->api->get_replication (crc->api->cls, &iterate_one_shot, crc);
+ break;
+ case RP_EXPI_GET:
+ crc->api->get_expiration (crc->api->cls, &iterate_one_shot, crc);
+ break;
+ case RP_DROP:
+ crc->api->drop (crc->api->cls);
+ GNUNET_SCHEDULER_add_now (&cleaning_task, crc);
+ break;
+ }
}
@@ -340,20 +309,19 @@
load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg)
{
static struct GNUNET_DATASTORE_PluginEnvironment env;
- struct GNUNET_DATASTORE_PluginFunctions * ret;
+ struct GNUNET_DATASTORE_PluginFunctions *ret;
char *name;
char *libname;
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
"DATASTORE", "DATABASE", &name))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("No `%s' specified for `%s' in configuration!\n"),
- "DATABASE",
- "DATASTORE");
- return NULL;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("No `%s' specified for `%s' in configuration!\n"),
+ "DATABASE", "DATASTORE");
+ return NULL;
+ }
env.cfg = cfg;
env.duc = &disk_utilization_change_cb;
env.cls = NULL;
@@ -361,12 +329,10 @@
_("Loading `%s' datastore plugin\n"), name);
GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name);
if (NULL == (ret = GNUNET_PLUGIN_load (libname, &env)))
- {
- fprintf (stderr,
- "Failed to load plugin `%s'!\n",
- name);
- return NULL;
- }
+ {
+ fprintf (stderr, "Failed to load plugin `%s'!\n", name);
+ return NULL;
+ }
GNUNET_free (libname);
GNUNET_free (name);
return ret;
@@ -376,20 +342,19 @@
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *c)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
{
struct GNUNET_DATASTORE_PluginFunctions *api;
struct CpsRunContext *crc;
api = load_plugin (c);
if (api == NULL)
- {
- fprintf (stderr,
- "Could not initialize plugin, assuming database not configured.
Test not run!\n");
- return;
- }
- crc = GNUNET_malloc(sizeof(struct CpsRunContext));
+ {
+ fprintf (stderr,
+ "Could not initialize plugin, assuming database not configured.
Test not run!\n");
+ return;
+ }
+ crc = GNUNET_malloc (sizeof (struct CpsRunContext));
crc->api = api;
crc->cfg = c;
crc->phase = RP_PUT;
@@ -401,7 +366,8 @@
check ()
{
char cfg_name[128];
- char *const argv[] = {
+
+ char *const argv[] = {
"test-plugin-datastore",
"-c",
cfg_name,
@@ -415,9 +381,8 @@
};
GNUNET_snprintf (cfg_name,
- sizeof (cfg_name),
- "test_plugin_datastore_data_%s.conf",
- plugin_name);
+ sizeof (cfg_name),
+ "test_plugin_datastore_data_%s.conf", plugin_name);
GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
argv, "test-plugin-datastore", "nohelp",
options, &run, NULL);
@@ -437,17 +402,16 @@
sleep (1);
/* determine name of plugin to use */
plugin_name = argv[0];
- while (NULL != (pos = strstr(plugin_name, "_")))
- plugin_name = pos+1;
- if (NULL != (pos = strstr(plugin_name, ".")))
+ while (NULL != (pos = strstr (plugin_name, "_")))
+ plugin_name = pos + 1;
+ if (NULL != (pos = strstr (plugin_name, ".")))
pos[0] = 0;
else
pos = (char *) plugin_name;
GNUNET_snprintf (dir_name,
- sizeof (dir_name),
- "/tmp/test-gnunet-datastore-plugin-%s",
- plugin_name);
+ sizeof (dir_name),
+ "/tmp/test-gnunet-datastore-plugin-%s", plugin_name);
GNUNET_DISK_directory_remove (dir_name);
GNUNET_log_setup ("test-plugin-datastore",
#if VERBOSE
@@ -465,5 +429,3 @@
}
/* end of test_plugin_datastore.c */
-
-
Modified: gnunet/src/dht/dht.h
===================================================================
--- gnunet/src/dht/dht.h 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/dht/dht.h 2011-08-15 21:46:35 UTC (rev 16581)
@@ -90,8 +90,8 @@
* FIXME: document.
*/
typedef void (*GNUNET_DHT_MessageReceivedHandler) (void *cls,
- const struct
GNUNET_MessageHeader
- *msg);
+ const struct
+ GNUNET_MessageHeader * msg);
/**
Modified: gnunet/src/dht/dht_api.c
===================================================================
--- gnunet/src/dht/dht_api.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/dht/dht_api.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -60,12 +60,12 @@
* of this struct.
*/
const struct GNUNET_MessageHeader *msg;
-
+
/**
* Handle to the DHT API context.
*/
struct GNUNET_DHT_Handle *handle;
-
+
/**
* Continuation to call when the request has been
* transmitted (for the first time) to the service; can be NULL.
@@ -203,10 +203,7 @@
/**
* Transmit the next pending message, called by notify_transmit_ready
*/
-static size_t
-transmit_pending (void *cls,
- size_t size,
- void *buf);
+static size_t transmit_pending (void *cls, size_t size, void *buf);
/**
@@ -215,8 +212,7 @@
*
*/
static void
-service_message_handler (void *cls,
- const struct GNUNET_MessageHeader *msg);
+service_message_handler (void *cls, const struct GNUNET_MessageHeader *msg);
@@ -233,19 +229,18 @@
return GNUNET_OK;
handle->client = GNUNET_CLIENT_connect ("dht", handle->cfg);
if (handle->client == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to connect to the DHT service!\n"));
- return GNUNET_NO;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Failed to connect to the DHT service!\n"));
+ return GNUNET_NO;
+ }
#if DEBUG_DHT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Starting to process replies from DHT\n");
+ "Starting to process replies from DHT\n");
#endif
GNUNET_CLIENT_receive (handle->client,
&service_message_handler,
- handle,
- GNUNET_TIME_UNIT_FOREVER_REL);
+ handle, GNUNET_TIME_UNIT_FOREVER_REL);
return GNUNET_YES;
}
@@ -260,20 +255,17 @@
* @return GNUNET_YES (always)
*/
static int
-add_request_to_pending (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+add_request_to_pending (void *cls, const GNUNET_HashCode * key, void *value)
{
struct GNUNET_DHT_Handle *handle = cls;
struct GNUNET_DHT_RouteHandle *rh = value;
if (GNUNET_NO == rh->message->in_pending_queue)
- {
- GNUNET_CONTAINER_DLL_insert (handle->pending_head,
- handle->pending_tail,
- rh->message);
- rh->message->in_pending_queue = GNUNET_YES;
- }
+ {
+ GNUNET_CONTAINER_DLL_insert (handle->pending_head,
+ handle->pending_tail, rh->message);
+ rh->message->in_pending_queue = GNUNET_YES;
+ }
return GNUNET_YES;
}
@@ -282,8 +274,7 @@
* Try to send messages from list of messages to send
* @param handle DHT_Handle
*/
-static void
-process_pending_messages (struct GNUNET_DHT_Handle *handle);
+static void process_pending_messages (struct GNUNET_DHT_Handle *handle);
/**
@@ -293,8 +284,7 @@
* @param tc scheduler context
*/
static void
-try_reconnect (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+try_reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_DHT_Handle *handle = cls;
@@ -308,14 +298,12 @@
handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
handle->client = GNUNET_CLIENT_connect ("dht", handle->cfg);
if (handle->client == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "dht reconnect failed(!)\n");
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "dht reconnect failed(!)\n");
+ return;
+ }
GNUNET_CONTAINER_multihashmap_iterate (handle->active_requests,
- &add_request_to_pending,
- handle);
+ &add_request_to_pending, handle);
process_pending_messages (handle);
}
@@ -330,7 +318,7 @@
{
if (handle->client == NULL)
return;
- GNUNET_assert(handle->reconnect_task == GNUNET_SCHEDULER_NO_TASK);
+ GNUNET_assert (handle->reconnect_task == GNUNET_SCHEDULER_NO_TASK);
GNUNET_CLIENT_disconnect (handle->client, GNUNET_NO);
handle->client = NULL;
handle->reconnect_task = GNUNET_SCHEDULER_add_delayed (handle->retry_time,
@@ -348,25 +336,24 @@
struct PendingMessage *head;
if (handle->client == NULL)
- {
- do_disconnect(handle);
- return;
- }
+ {
+ do_disconnect (handle);
+ return;
+ }
if (handle->th != NULL)
return;
if (NULL == (head = handle->pending_head))
return;
handle->th = GNUNET_CLIENT_notify_transmit_ready (handle->client,
- ntohs (head->msg->size),
-
GNUNET_TIME_UNIT_FOREVER_REL,
- GNUNET_YES,
- &transmit_pending,
- handle);
- if (NULL == handle->th)
- {
- do_disconnect (handle);
- return;
- }
+ ntohs (head->msg->size),
+
GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_YES,
+ &transmit_pending, handle);
+ if (NULL == handle->th)
+ {
+ do_disconnect (handle);
+ return;
+ }
}
@@ -374,9 +361,7 @@
* Transmit the next pending message, called by notify_transmit_ready
*/
static size_t
-transmit_pending (void *cls,
- size_t size,
- void *buf)
+transmit_pending (void *cls, size_t size, void *buf)
{
struct GNUNET_DHT_Handle *handle = cls;
struct PendingMessage *head;
@@ -384,44 +369,44 @@
handle->th = NULL;
if (buf == NULL)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Transmission to DHT service failed!
Reconnecting!\n");
- do_disconnect (handle);
- return 0;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Transmission to DHT service failed! Reconnecting!\n");
+ do_disconnect (handle);
+ return 0;
+ }
if (NULL == (head = handle->pending_head))
return 0;
-
+
tsize = ntohs (head->msg->size);
if (size < tsize)
- {
- process_pending_messages (handle);
- return 0;
- }
+ {
+ process_pending_messages (handle);
+ return 0;
+ }
memcpy (buf, head->msg, tsize);
GNUNET_CONTAINER_DLL_remove (handle->pending_head,
- handle->pending_tail,
- head);
+ handle->pending_tail, head);
if (head->timeout_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (head->timeout_task);
- head->timeout_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (head->timeout_task);
+ head->timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ }
if (NULL != head->cont)
- {
- GNUNET_SCHEDULER_add_continuation (head->cont,
- head->cont_cls,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- head->cont = NULL;
- head->cont_cls = NULL;
- }
+ {
+ GNUNET_SCHEDULER_add_continuation (head->cont,
+ head->cont_cls,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ head->cont = NULL;
+ head->cont_cls = NULL;
+ }
head->in_pending_queue = GNUNET_NO;
if (GNUNET_YES == head->free_on_send)
GNUNET_free (head);
process_pending_messages (handle);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Forwarded request of %u bytes to DHT service\n",
- (unsigned int) tsize);
+ "Forwarded request of %u bytes to DHT service\n",
+ (unsigned int) tsize);
return tsize;
}
@@ -431,9 +416,7 @@
* request.
*/
static int
-process_reply (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+process_reply (void *cls, const GNUNET_HashCode * key, void *value)
{
const struct GNUNET_DHT_RouteResultMessage *dht_msg = cls;
struct GNUNET_DHT_RouteHandle *rh = value;
@@ -448,47 +431,46 @@
uid = GNUNET_ntohll (dht_msg->unique_id);
if (uid != rh->uid)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Reply UID did not match request UID\n");
- return GNUNET_YES;
- }
- enc_msg = (const struct GNUNET_MessageHeader *)&dht_msg[1];
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Reply UID did not match request UID\n");
+ return GNUNET_YES;
+ }
+ enc_msg = (const struct GNUNET_MessageHeader *) &dht_msg[1];
enc_size = ntohs (enc_msg->size);
if (enc_size < sizeof (struct GNUNET_MessageHeader))
- {
- GNUNET_break (0);
- return GNUNET_NO;
- }
- path_offset = (char *)&dht_msg[1];
+ {
+ GNUNET_break (0);
+ return GNUNET_NO;
+ }
+ path_offset = (char *) &dht_msg[1];
path_offset += enc_size;
pos = (const struct GNUNET_PeerIdentity *) path_offset;
outgoing_path_length = ntohl (dht_msg->outgoing_path_length);
- if (outgoing_path_length * sizeof (struct GNUNET_PeerIdentity) >
ntohs(dht_msg->header.size) - enc_size)
- {
- GNUNET_break (0);
- return GNUNET_NO;
- }
+ if (outgoing_path_length * sizeof (struct GNUNET_PeerIdentity) >
+ ntohs (dht_msg->header.size) - enc_size)
+ {
+ GNUNET_break (0);
+ return GNUNET_NO;
+ }
if (outgoing_path_length > 0)
+ {
+ outgoing_path =
+ GNUNET_malloc ((outgoing_path_length +
+ 1) * sizeof (struct GNUNET_PeerIdentity *));
+ for (i = 0; i < outgoing_path_length; i++)
{
- outgoing_path = GNUNET_malloc ((outgoing_path_length + 1) * sizeof
(struct GNUNET_PeerIdentity*));
- for (i = 0; i < outgoing_path_length; i++)
- {
- outgoing_path[i] = pos;
- pos++;
- }
- outgoing_path[outgoing_path_length] = NULL;
+ outgoing_path[i] = pos;
+ pos++;
}
+ outgoing_path[outgoing_path_length] = NULL;
+ }
else
outgoing_path = NULL;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Processing reply.\n");
- rh->iter (rh->iter_cls,
- &rh->key,
- outgoing_path,
- enc_msg);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing reply.\n");
+ rh->iter (rh->iter_cls, &rh->key, outgoing_path, enc_msg);
GNUNET_free_non_null (outgoing_path);
return GNUNET_YES;
}
@@ -502,42 +484,40 @@
* @param msg the incoming message
*/
static void
-service_message_handler (void *cls,
- const struct GNUNET_MessageHeader *msg)
+service_message_handler (void *cls, const struct GNUNET_MessageHeader *msg)
{
struct GNUNET_DHT_Handle *handle = cls;
const struct GNUNET_DHT_RouteResultMessage *dht_msg;
if (msg == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Error receiving data from DHT service, reconnecting\n");
- do_disconnect (handle);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Error receiving data from DHT service, reconnecting\n");
+ do_disconnect (handle);
+ return;
+ }
if (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_DHT_LOCAL_ROUTE_RESULT)
- {
- GNUNET_break (0);
- do_disconnect (handle);
- return;
- }
+ {
+ GNUNET_break (0);
+ do_disconnect (handle);
+ return;
+ }
if (ntohs (msg->size) < sizeof (struct GNUNET_DHT_RouteResultMessage))
- {
- GNUNET_break (0);
- do_disconnect (handle);
- return;
- }
+ {
+ GNUNET_break (0);
+ do_disconnect (handle);
+ return;
+ }
dht_msg = (const struct GNUNET_DHT_RouteResultMessage *) msg;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Comparing reply `%s' against %u pending requests.\n",
- GNUNET_h2s (&dht_msg->key),
- GNUNET_CONTAINER_multihashmap_size (handle->active_requests));
+ "Comparing reply `%s' against %u pending requests.\n",
+ GNUNET_h2s (&dht_msg->key),
+ GNUNET_CONTAINER_multihashmap_size (handle->active_requests));
GNUNET_CONTAINER_multihashmap_get_multiple (handle->active_requests,
- &dht_msg->key,
- &process_reply,
- (void*) dht_msg);
+ &dht_msg->key,
+ &process_reply, (void *)
dht_msg);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Continuing to process replies from DHT\n");
+ "Continuing to process replies from DHT\n");
GNUNET_CLIENT_receive (handle->client,
&service_message_handler,
handle, GNUNET_TIME_UNIT_FOREVER_REL);
@@ -562,13 +542,14 @@
handle = GNUNET_malloc (sizeof (struct GNUNET_DHT_Handle));
handle->cfg = cfg;
- handle->uid_gen = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK,
UINT64_MAX);
+ handle->uid_gen =
+ GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX);
handle->active_requests = GNUNET_CONTAINER_multihashmap_create (ht_len);
if (GNUNET_NO == try_connect (handle))
- {
- GNUNET_DHT_disconnect (handle);
- return NULL;
- }
+ {
+ GNUNET_DHT_disconnect (handle);
+ return NULL;
+ }
return handle;
}
@@ -582,36 +563,37 @@
GNUNET_DHT_disconnect (struct GNUNET_DHT_Handle *handle)
{
struct PendingMessage *pm;
- GNUNET_assert(handle != NULL);
- GNUNET_assert (0 ==
GNUNET_CONTAINER_multihashmap_size(handle->active_requests));
+
+ GNUNET_assert (handle != NULL);
+ GNUNET_assert (0 ==
+ GNUNET_CONTAINER_multihashmap_size (handle->active_requests));
if (handle->th != NULL)
- {
- GNUNET_CLIENT_notify_transmit_ready_cancel (handle->th);
- handle->th = NULL;
- }
+ {
+ GNUNET_CLIENT_notify_transmit_ready_cancel (handle->th);
+ handle->th = NULL;
+ }
while (NULL != (pm = handle->pending_head))
- {
- GNUNET_CONTAINER_DLL_remove (handle->pending_head,
- handle->pending_tail,
- pm);
- GNUNET_assert (GNUNET_YES == pm->free_on_send);
- if (GNUNET_SCHEDULER_NO_TASK != pm->timeout_task)
- GNUNET_SCHEDULER_cancel (pm->timeout_task);
- if (NULL != pm->cont)
- GNUNET_SCHEDULER_add_continuation (pm->cont,
- pm->cont_cls,
- GNUNET_SCHEDULER_REASON_TIMEOUT);
- pm->in_pending_queue = GNUNET_NO;
- GNUNET_free (pm);
- }
+ {
+ GNUNET_CONTAINER_DLL_remove (handle->pending_head,
+ handle->pending_tail, pm);
+ GNUNET_assert (GNUNET_YES == pm->free_on_send);
+ if (GNUNET_SCHEDULER_NO_TASK != pm->timeout_task)
+ GNUNET_SCHEDULER_cancel (pm->timeout_task);
+ if (NULL != pm->cont)
+ GNUNET_SCHEDULER_add_continuation (pm->cont,
+ pm->cont_cls,
+ GNUNET_SCHEDULER_REASON_TIMEOUT);
+ pm->in_pending_queue = GNUNET_NO;
+ GNUNET_free (pm);
+ }
if (handle->client != NULL)
- {
- GNUNET_CLIENT_disconnect (handle->client, GNUNET_YES);
- handle->client = NULL;
- }
+ {
+ GNUNET_CLIENT_disconnect (handle->client, GNUNET_YES);
+ handle->client = NULL;
+ }
if (handle->reconnect_task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel(handle->reconnect_task);
- GNUNET_CONTAINER_multihashmap_destroy(handle->active_requests);
+ GNUNET_SCHEDULER_cancel (handle->reconnect_task);
+ GNUNET_CONTAINER_multihashmap_destroy (handle->active_requests);
GNUNET_free (handle);
}
@@ -628,25 +610,22 @@
* @param tc scheduler context
*/
static void
-timeout_route_request (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+timeout_route_request (void *cls, const struct GNUNET_SCHEDULER_TaskContext
*tc)
{
struct PendingMessage *pending = cls;
struct GNUNET_DHT_Handle *handle;
if (pending->free_on_send != GNUNET_YES)
- {
- /* timeouts should only apply to fire & forget requests! */
- GNUNET_break (0);
- return;
- }
+ {
+ /* timeouts should only apply to fire & forget requests! */
+ GNUNET_break (0);
+ return;
+ }
handle = pending->handle;
GNUNET_CONTAINER_DLL_remove (handle->pending_head,
- handle->pending_tail,
- pending);
+ handle->pending_tail, pending);
if (pending->cont != NULL)
- pending->cont (pending->cont_cls,
- tc);
+ pending->cont (pending->cont_cls, tc);
GNUNET_free (pending);
}
@@ -674,15 +653,14 @@
*/
struct GNUNET_DHT_RouteHandle *
GNUNET_DHT_route_start (struct GNUNET_DHT_Handle *handle,
- const GNUNET_HashCode *key,
+ const GNUNET_HashCode * key,
uint32_t desired_replication_level,
enum GNUNET_DHT_RouteOption options,
const struct GNUNET_MessageHeader *enc,
struct GNUNET_TIME_Relative timeout,
GNUNET_DHT_ReplyProcessor iter,
void *iter_cls,
- GNUNET_SCHEDULER_Task cont,
- void *cont_cls)
+ GNUNET_SCHEDULER_Task cont, void *cont_cls)
{
struct PendingMessage *pending;
struct GNUNET_DHT_RouteMessage *message;
@@ -691,19 +669,20 @@
uint16_t esize;
esize = ntohs (enc->size);
- if (sizeof (struct GNUNET_DHT_RouteMessage) + esize >=
GNUNET_SERVER_MAX_MESSAGE_SIZE)
- {
- GNUNET_break (0);
- return NULL;
- }
+ if (sizeof (struct GNUNET_DHT_RouteMessage) + esize >=
+ GNUNET_SERVER_MAX_MESSAGE_SIZE)
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
msize = sizeof (struct GNUNET_DHT_RouteMessage) + esize;
pending = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
- message = (struct GNUNET_DHT_RouteMessage*) &pending[1];
+ message = (struct GNUNET_DHT_RouteMessage *) &pending[1];
pending->msg = &message->header;
pending->handle = handle;
pending->cont = cont;
pending->cont_cls = cont_cls;
-
+
message->header.size = htons (msize);
message->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_LOCAL_ROUTE);
message->options = htonl ((uint32_t) options);
@@ -715,35 +694,34 @@
memcpy (&message[1], enc, esize);
if (iter != NULL)
- {
- route_handle = GNUNET_malloc (sizeof (struct GNUNET_DHT_RouteHandle));
- route_handle->key = *key;
- route_handle->iter = iter;
- route_handle->iter_cls = iter_cls;
- route_handle->dht_handle = handle;
- route_handle->uid = handle->uid_gen;
- route_handle->message = pending;
- GNUNET_CONTAINER_multihashmap_put (handle->active_requests,
- key,
- route_handle,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
- }
+ {
+ route_handle = GNUNET_malloc (sizeof (struct GNUNET_DHT_RouteHandle));
+ route_handle->key = *key;
+ route_handle->iter = iter;
+ route_handle->iter_cls = iter_cls;
+ route_handle->dht_handle = handle;
+ route_handle->uid = handle->uid_gen;
+ route_handle->message = pending;
+ GNUNET_CONTAINER_multihashmap_put (handle->active_requests,
+ key,
+ route_handle,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
+ }
else
- {
- route_handle = NULL;
- pending->free_on_send = GNUNET_YES;
- pending->timeout_task = GNUNET_SCHEDULER_add_delayed (timeout,
-
&timeout_route_request,
- pending);
- }
+ {
+ route_handle = NULL;
+ pending->free_on_send = GNUNET_YES;
+ pending->timeout_task = GNUNET_SCHEDULER_add_delayed (timeout,
+
&timeout_route_request,
+ pending);
+ }
GNUNET_CONTAINER_DLL_insert (handle->pending_head,
- handle->pending_tail,
- pending);
+ handle->pending_tail, pending);
pending->in_pending_queue = GNUNET_YES;
process_pending_messages (handle);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "DHT route start request processed, returning %p\n",
- route_handle);
+ "DHT route start request processed, returning %p\n",
+ route_handle);
return route_handle;
}
@@ -763,42 +741,38 @@
handle = route_handle->dht_handle;
if (GNUNET_NO == route_handle->message->in_pending_queue)
- {
- /* need to send stop message */
- msize = sizeof (struct GNUNET_DHT_StopMessage);
- pending = GNUNET_malloc (sizeof (struct PendingMessage) +
- msize);
- message = (struct GNUNET_DHT_StopMessage*) &pending[1];
- pending->msg = &message->header;
- message->header.size = htons (msize);
- message->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_LOCAL_ROUTE_STOP);
- message->reserved = 0;
- message->unique_id = GNUNET_htonll (route_handle->uid);
- message->key = route_handle->key;
- pending->handle = handle;
- pending->free_on_send = GNUNET_YES;
- pending->in_pending_queue = GNUNET_YES;
- GNUNET_CONTAINER_DLL_insert (handle->pending_head,
- handle->pending_tail,
- pending);
- process_pending_messages (handle);
- }
+ {
+ /* need to send stop message */
+ msize = sizeof (struct GNUNET_DHT_StopMessage);
+ pending = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
+ message = (struct GNUNET_DHT_StopMessage *) &pending[1];
+ pending->msg = &message->header;
+ message->header.size = htons (msize);
+ message->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_LOCAL_ROUTE_STOP);
+ message->reserved = 0;
+ message->unique_id = GNUNET_htonll (route_handle->uid);
+ message->key = route_handle->key;
+ pending->handle = handle;
+ pending->free_on_send = GNUNET_YES;
+ pending->in_pending_queue = GNUNET_YES;
+ GNUNET_CONTAINER_DLL_insert (handle->pending_head,
+ handle->pending_tail, pending);
+ process_pending_messages (handle);
+ }
else
- {
- /* simply remove pending request from message queue before
- transmission, no need to transmit STOP request! */
- GNUNET_CONTAINER_DLL_remove (handle->pending_head,
- handle->pending_tail,
- route_handle->message);
- }
+ {
+ /* simply remove pending request from message queue before
+ * transmission, no need to transmit STOP request! */
+ GNUNET_CONTAINER_DLL_remove (handle->pending_head,
+ handle->pending_tail, route_handle->message);
+ }
GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove
(route_handle->dht_handle->active_requests,
- &route_handle->key,
- route_handle));
- GNUNET_free(route_handle->message);
- GNUNET_free(route_handle);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "DHT route stop request processed\n");
+ GNUNET_CONTAINER_multihashmap_remove
+ (route_handle->dht_handle->active_requests,
&route_handle->key,
+ route_handle));
+ GNUNET_free (route_handle->message);
+ GNUNET_free (route_handle);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "DHT route stop request processed\n");
}
@@ -817,29 +791,27 @@
*/
static void
send_control_message (struct GNUNET_DHT_Handle *handle,
- uint16_t command,
- uint16_t variable,
- GNUNET_SCHEDULER_Task cont,
- void *cont_cls)
+ uint16_t command,
+ uint16_t variable,
+ GNUNET_SCHEDULER_Task cont, void *cont_cls)
{
struct GNUNET_DHT_ControlMessage *msg;
struct PendingMessage *pending;
- pending = GNUNET_malloc (sizeof (struct PendingMessage) +
- sizeof(struct GNUNET_DHT_ControlMessage));
- msg = (struct GNUNET_DHT_ControlMessage*) &pending[1];
+ pending = GNUNET_malloc (sizeof (struct PendingMessage) +
+ sizeof (struct GNUNET_DHT_ControlMessage));
+ msg = (struct GNUNET_DHT_ControlMessage *) &pending[1];
pending->msg = &msg->header;
- msg->header.size = htons (sizeof(struct GNUNET_DHT_ControlMessage));
+ msg->header.size = htons (sizeof (struct GNUNET_DHT_ControlMessage));
msg->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_CONTROL);
msg->command = htons (command);
msg->variable = htons (variable);
pending->free_on_send = GNUNET_YES;
pending->cont = cont;
pending->cont_cls = cont_cls;
- pending->in_pending_queue = GNUNET_YES;
+ pending->in_pending_queue = GNUNET_YES;
GNUNET_CONTAINER_DLL_insert (handle->pending_head,
- handle->pending_tail,
- pending);
+ handle->pending_tail, pending);
process_pending_messages (handle);
}
@@ -857,12 +829,10 @@
*/
void
GNUNET_DHT_find_peers (struct GNUNET_DHT_Handle *handle,
- GNUNET_SCHEDULER_Task cont,
- void *cont_cls)
+ GNUNET_SCHEDULER_Task cont, void *cont_cls)
{
send_control_message (handle,
- GNUNET_MESSAGE_TYPE_DHT_FIND_PEER, 0,
- cont, cont_cls);
+ GNUNET_MESSAGE_TYPE_DHT_FIND_PEER, 0, cont, cont_cls);
}
@@ -880,17 +850,17 @@
*/
void
GNUNET_DHT_set_malicious_getter (struct GNUNET_DHT_Handle *handle,
- struct GNUNET_TIME_Relative frequency,
GNUNET_SCHEDULER_Task cont,
- void *cont_cls)
+ struct GNUNET_TIME_Relative frequency,
+ GNUNET_SCHEDULER_Task cont, void *cont_cls)
{
if (frequency.rel_value > UINT16_MAX)
- {
- GNUNET_break (0);
- return;
- }
+ {
+ GNUNET_break (0);
+ return;
+ }
send_control_message (handle,
- GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_GET,
frequency.rel_value,
- cont, cont_cls);
+ GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_GET,
+ frequency.rel_value, cont, cont_cls);
}
/**
@@ -902,20 +872,20 @@
* @param cont continuation to call when done (transmitting request to service)
* @param cont_cls closure for cont
*/
-void
-GNUNET_DHT_set_malicious_putter (struct GNUNET_DHT_Handle *handle,
- struct GNUNET_TIME_Relative frequency,
GNUNET_SCHEDULER_Task cont,
- void *cont_cls)
+void
+GNUNET_DHT_set_malicious_putter (struct GNUNET_DHT_Handle *handle,
+ struct GNUNET_TIME_Relative frequency,
+ GNUNET_SCHEDULER_Task cont, void *cont_cls)
{
if (frequency.rel_value > UINT16_MAX)
- {
- GNUNET_break (0);
- return;
- }
+ {
+ GNUNET_break (0);
+ return;
+ }
send_control_message (handle,
- GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_PUT,
frequency.rel_value,
- cont, cont_cls);
+ GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_PUT,
+ frequency.rel_value, cont, cont_cls);
}
@@ -928,9 +898,9 @@
* @param cont_cls closure for cont
*
*/
-void
-GNUNET_DHT_set_malicious_dropper (struct GNUNET_DHT_Handle *handle,
GNUNET_SCHEDULER_Task cont,
- void *cont_cls)
+void
+GNUNET_DHT_set_malicious_dropper (struct GNUNET_DHT_Handle *handle,
+ GNUNET_SCHEDULER_Task cont, void *cont_cls)
{
send_control_message (handle,
GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_DROP, 0,
Modified: gnunet/src/dht/dht_api_find_peer.c
===================================================================
--- gnunet/src/dht/dht_api_find_peer.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/dht/dht_api_find_peer.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -71,28 +71,29 @@
* @param reply response
*/
static void
-find_peer_reply_iterator (void *cls,
- const GNUNET_HashCode *key,
- const struct GNUNET_PeerIdentity * const
*outgoing_path,
- const struct GNUNET_MessageHeader *reply)
+find_peer_reply_iterator (void *cls,
+ const GNUNET_HashCode * key,
+ const struct GNUNET_PeerIdentity *const
+ *outgoing_path,
+ const struct GNUNET_MessageHeader *reply)
{
struct GNUNET_DHT_FindPeerHandle *find_peer_handle = cls;
const struct GNUNET_MessageHeader *hello;
if (ntohs (reply->type) != GNUNET_MESSAGE_TYPE_DHT_FIND_PEER_RESULT)
- {
- GNUNET_break (0);
- return;
- }
+ {
+ GNUNET_break (0);
+ return;
+ }
GNUNET_assert (ntohs (reply->size) >= sizeof (struct GNUNET_MessageHeader));
- hello = (const struct GNUNET_MessageHeader *)&reply[1];
- if (ntohs(hello->type) != GNUNET_MESSAGE_TYPE_HELLO)
- {
- GNUNET_break (0);
- return;
- }
+ hello = (const struct GNUNET_MessageHeader *) &reply[1];
+ if (ntohs (hello->type) != GNUNET_MESSAGE_TYPE_HELLO)
+ {
+ GNUNET_break (0);
+ return;
+ }
find_peer_handle->proc (find_peer_handle->proc_cls,
- (const struct GNUNET_HELLO_Message *)hello);
+ (const struct GNUNET_HELLO_Message *) hello);
}
@@ -112,27 +113,26 @@
struct GNUNET_DHT_FindPeerHandle *
GNUNET_DHT_find_peer_start (struct GNUNET_DHT_Handle *handle,
struct GNUNET_TIME_Relative timeout,
- const GNUNET_HashCode *key,
+ const GNUNET_HashCode * key,
enum GNUNET_DHT_RouteOption options,
- GNUNET_DHT_FindPeerProcessor proc,
- void *proc_cls)
+ GNUNET_DHT_FindPeerProcessor proc, void *proc_cls)
{
struct GNUNET_DHT_FindPeerHandle *find_peer_handle;
struct GNUNET_DHT_FindPeerMessage find_peer_msg;
- find_peer_handle =
- GNUNET_malloc (sizeof (struct GNUNET_DHT_FindPeerHandle));
+ find_peer_handle = GNUNET_malloc (sizeof (struct GNUNET_DHT_FindPeerHandle));
find_peer_handle->proc = proc;
find_peer_handle->proc_cls = proc_cls;
- find_peer_msg.header.size = htons(sizeof(struct GNUNET_DHT_FindPeerMessage));
- find_peer_msg.header.type = htons(GNUNET_MESSAGE_TYPE_DHT_FIND_PEER);
+ find_peer_msg.header.size =
+ htons (sizeof (struct GNUNET_DHT_FindPeerMessage));
+ find_peer_msg.header.type = htons (GNUNET_MESSAGE_TYPE_DHT_FIND_PEER);
find_peer_handle->route_handle =
- GNUNET_DHT_route_start (handle, key,
- 0, options,
- &find_peer_msg.header,
- timeout,
- &find_peer_reply_iterator, find_peer_handle,
- NULL, NULL);
+ GNUNET_DHT_route_start (handle, key,
+ 0, options,
+ &find_peer_msg.header,
+ timeout,
+ &find_peer_reply_iterator, find_peer_handle,
+ NULL, NULL);
GNUNET_break (find_peer_handle->route_handle != NULL);
return find_peer_handle;
}
Modified: gnunet/src/dht/dht_api_get_put.c
===================================================================
--- gnunet/src/dht/dht_api_get_put.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/dht/dht_api_get_put.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -55,41 +55,38 @@
GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle,
const GNUNET_HashCode * key,
uint32_t desired_replication_level,
- enum GNUNET_DHT_RouteOption options,
+ enum GNUNET_DHT_RouteOption options,
enum GNUNET_BLOCK_Type type,
size_t size,
const char *data,
struct GNUNET_TIME_Absolute exp,
struct GNUNET_TIME_Relative timeout,
- GNUNET_SCHEDULER_Task cont,
- void *cont_cls)
+ GNUNET_SCHEDULER_Task cont, void *cont_cls)
{
char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE];
struct GNUNET_DHT_PutMessage *put_msg;
if (size >= sizeof (buf) - sizeof (struct GNUNET_DHT_PutMessage))
- {
- GNUNET_break (0);
- return;
- }
- put_msg = (struct GNUNET_DHT_PutMessage*) buf;
+ {
+ GNUNET_break (0);
+ return;
+ }
+ put_msg = (struct GNUNET_DHT_PutMessage *) buf;
put_msg->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_PUT);
put_msg->header.size = htons (sizeof (struct GNUNET_DHT_PutMessage) + size);
- put_msg->type = htonl ((uint32_t)type);
+ put_msg->type = htonl ((uint32_t) type);
put_msg->expiration = GNUNET_TIME_absolute_hton (exp);
memcpy (&put_msg[1], data, size);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Starting route for %u byte `%s' message of type %u \n",
- (unsigned int) (sizeof (struct GNUNET_DHT_PutMessage) + size),
- "PUT", type);
+ "Starting route for %u byte `%s' message of type %u \n",
+ (unsigned int) (sizeof (struct GNUNET_DHT_PutMessage) + size),
+ "PUT", type);
GNUNET_break (NULL ==
- GNUNET_DHT_route_start (handle,
- key,
- desired_replication_level, options,
- &put_msg->header,
- timeout,
- NULL, NULL,
- cont, cont_cls));
+ GNUNET_DHT_route_start (handle,
+ key,
+ desired_replication_level, options,
+ &put_msg->header,
+ timeout, NULL, NULL, cont, cont_cls));
}
@@ -129,10 +126,10 @@
* @param reply response
*/
static void
-get_reply_iterator (void *cls,
- const GNUNET_HashCode *key,
- const struct GNUNET_PeerIdentity * const *outgoing_path,
- const struct GNUNET_MessageHeader *reply)
+get_reply_iterator (void *cls,
+ const GNUNET_HashCode * key,
+ const struct GNUNET_PeerIdentity *const *outgoing_path,
+ const struct GNUNET_MessageHeader *reply)
{
struct GNUNET_DHT_GetHandle *get_handle = cls;
const struct GNUNET_DHT_GetResultMessage *result;
@@ -145,44 +142,46 @@
uint16_t data_size;
if (ntohs (reply->type) != GNUNET_MESSAGE_TYPE_DHT_GET_RESULT)
- {
- GNUNET_break (0);
- return;
- }
+ {
+ GNUNET_break (0);
+ return;
+ }
GNUNET_assert (ntohs (reply->size) >=
sizeof (struct GNUNET_DHT_GetResultMessage));
result = (const struct GNUNET_DHT_GetResultMessage *) reply;
put_path = NULL;
- put_path_length = ntohs(result->put_path_length);
+ put_path_length = ntohs (result->put_path_length);
if (put_path_length > 0)
+ {
+ data_size =
+ ntohs (result->header.size) -
+ (put_path_length * sizeof (struct GNUNET_PeerIdentity)) -
+ sizeof (struct GNUNET_DHT_GetResultMessage);
+ path_offset = (char *) &result[1];
+ //GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "In get_reply_iterator,
result->header.size is %d, put_path_length %d, offset is %d, data_size is
%d\n", ntohs(result->header.size), put_path_length, ntohs(result->header.size)
- (put_path_length * sizeof(struct GNUNET_PeerIdentity)), data_size);
+ path_offset += data_size;
+ pos = (const struct GNUNET_PeerIdentity *) path_offset;
+ //GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Found put peer %s\n",
GNUNET_i2s((const struct GNUNET_PeerIdentity *)path_offset));
+ put_path =
+ GNUNET_malloc ((put_path_length +
+ 1) * sizeof (struct GNUNET_PeerIdentity *));
+ for (i = 0; i < put_path_length; i++)
{
- data_size = ntohs(result->header.size) - (put_path_length *
sizeof(struct GNUNET_PeerIdentity)) - sizeof(struct
GNUNET_DHT_GetResultMessage);
- path_offset = (char *)&result[1];
- //GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "In get_reply_iterator,
result->header.size is %d, put_path_length %d, offset is %d, data_size is
%d\n", ntohs(result->header.size), put_path_length, ntohs(result->header.size)
- (put_path_length * sizeof(struct GNUNET_PeerIdentity)), data_size);
- path_offset += data_size;
- pos = (const struct GNUNET_PeerIdentity *)path_offset;
- //GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Found put peer %s\n",
GNUNET_i2s((const struct GNUNET_PeerIdentity *)path_offset));
- put_path = GNUNET_malloc ((put_path_length + 1) * sizeof (struct
GNUNET_PeerIdentity*));
- for (i = 0; i < put_path_length; i++)
- {
- put_path[i] = pos;
- pos++;
- }
- put_path[put_path_length] = NULL;
+ put_path[i] = pos;
+ pos++;
}
+ put_path[put_path_length] = NULL;
+ }
- payload = ntohs (reply->size) - sizeof(struct GNUNET_DHT_GetResultMessage);
+ payload = ntohs (reply->size) - sizeof (struct GNUNET_DHT_GetResultMessage);
get_handle->iter (get_handle->iter_cls,
- GNUNET_TIME_absolute_ntoh (result->expiration),
- key,
- outgoing_path,
- put_path,
- ntohs (result->type),
- payload,
- &result[1]);
- GNUNET_free_non_null(put_path);
+ GNUNET_TIME_absolute_ntoh (result->expiration),
+ key,
+ outgoing_path,
+ put_path, ntohs (result->type), payload, &result[1]);
+ GNUNET_free_non_null (put_path);
}
@@ -213,61 +212,55 @@
enum GNUNET_BLOCK_Type type,
const GNUNET_HashCode * key,
uint32_t desired_replication_level,
- enum GNUNET_DHT_RouteOption options,
- const struct GNUNET_CONTAINER_BloomFilter *bf,
- int32_t bf_mutator,
- const void *xquery,
- size_t xquery_size,
- GNUNET_DHT_GetIterator iter,
- void *iter_cls)
+ enum GNUNET_DHT_RouteOption options,
+ const struct GNUNET_CONTAINER_BloomFilter *bf,
+ int32_t bf_mutator,
+ const void *xquery,
+ size_t xquery_size,
+ GNUNET_DHT_GetIterator iter, void *iter_cls)
{
struct GNUNET_DHT_GetHandle *get_handle;
char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1];
struct GNUNET_DHT_GetMessage *get_msg;
size_t bf_size;
-
+
bf_size = GNUNET_CONTAINER_bloomfilter_get_size (bf);
- if ( (sizeof (buf) <=
- sizeof (struct GNUNET_DHT_GetMessage) + xquery_size + bf_size) ||
- (sizeof (buf) <= bf_size))
- {
- GNUNET_break (0);
- return NULL;
- }
+ if ((sizeof (buf) <=
+ sizeof (struct GNUNET_DHT_GetMessage) + xquery_size + bf_size) ||
+ (sizeof (buf) <= bf_size))
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
get_handle = GNUNET_malloc (sizeof (struct GNUNET_DHT_GetHandle));
get_handle->iter = iter;
get_handle->iter_cls = iter_cls;
- get_msg = (struct GNUNET_DHT_GetMessage*) buf;
+ get_msg = (struct GNUNET_DHT_GetMessage *) buf;
get_msg->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_GET);
- get_msg->header.size = htons (sizeof (struct GNUNET_DHT_GetMessage) +
- xquery_size +
- bf_size);
+ get_msg->header.size = htons (sizeof (struct GNUNET_DHT_GetMessage) +
+ xquery_size + bf_size);
get_msg->type = htonl ((uint32_t) type);
get_msg->bf_mutator = bf_mutator;
get_msg->xquery_size = htons ((uint16_t) xquery_size);
get_msg->bf_size = htons (bf_size);
if (xquery != NULL)
- memcpy (&buf[sizeof(struct GNUNET_DHT_GetMessage)],
- xquery,
- xquery_size);
+ memcpy (&buf[sizeof (struct GNUNET_DHT_GetMessage)], xquery, xquery_size);
else
GNUNET_assert (xquery_size == 0);
(void) GNUNET_CONTAINER_bloomfilter_get_raw_data (bf,
- &buf[sizeof(struct
GNUNET_DHT_GetMessage) + xquery_size],
- bf_size);
+ &buf[sizeof
+ (struct
+
GNUNET_DHT_GetMessage)
+ + xquery_size],
+ bf_size);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Starting route for %u byte `%s' message\n",
- (unsigned int) (sizeof (struct GNUNET_DHT_GetMessage) +
xquery_size + bf_size) ,
- "GET");
+ "Starting route for %u byte `%s' message\n",
+ (unsigned int) (sizeof (struct GNUNET_DHT_GetMessage) +
+ xquery_size + bf_size), "GET");
get_handle->route_handle =
- GNUNET_DHT_route_start (handle,
- key,
- desired_replication_level,
- options,
- &get_msg->header,
- timeout,
- &get_reply_iterator, get_handle,
- NULL, NULL);
+ GNUNET_DHT_route_start (handle, key, desired_replication_level, options,
+ &get_msg->header, timeout, &get_reply_iterator,
+ get_handle, NULL, NULL);
GNUNET_break (NULL != get_handle->route_handle);
return get_handle;
}
Modified: gnunet/src/dht/dhtlog.c
===================================================================
--- gnunet/src/dht/dhtlog.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/dht/dhtlog.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -47,26 +47,26 @@
struct GNUNET_DHTLOG_Handle *api;
char *plugin_name;
- plugin = GNUNET_malloc(sizeof(struct GNUNET_DHTLOG_Plugin));
+ plugin = GNUNET_malloc (sizeof (struct GNUNET_DHTLOG_Plugin));
plugin->cfg = c;
if (GNUNET_OK ==
GNUNET_CONFIGURATION_get_value_string (c,
"DHTLOG", "PLUGIN", &plugin_name))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
_("Loading `%s' dhtlog plugin\n"), plugin_name);
- GNUNET_asprintf (&libname, "libgnunet_plugin_dhtlog_%s", plugin_name);
- GNUNET_PLUGIN_load (libname, plugin);
- }
+ GNUNET_asprintf (&libname, "libgnunet_plugin_dhtlog_%s", plugin_name);
+ GNUNET_PLUGIN_load (libname, plugin);
+ }
if (plugin->dhtlog_api == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to load dhtlog plugin for `%s'\n"), plugin_name);
- GNUNET_free (plugin_name);
- GNUNET_free (plugin);
- return NULL;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to load dhtlog plugin for `%s'\n"), plugin_name);
+ GNUNET_free (plugin_name);
+ GNUNET_free (plugin);
+ return NULL;
+ }
api = plugin->dhtlog_api;
GNUNET_free (plugin_name);
@@ -81,14 +81,13 @@
GNUNET_DHTLOG_disconnect (struct GNUNET_DHTLOG_Handle *api)
{
#if DEBUG_DHTLOG
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "MySQL DHT Logger: database shutdown\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MySQL DHT Logger: database
shutdown\n");
#endif
if (api != NULL)
- {
- GNUNET_PLUGIN_unload(libname, api);
- }
- GNUNET_free_non_null(libname);
+ {
+ GNUNET_PLUGIN_unload (libname, api);
+ }
+ GNUNET_free_non_null (libname);
}
/* end of dhtlog.c */
Modified: gnunet/src/dht/dhtlog.h
===================================================================
--- gnunet/src/dht/dhtlog.h 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/dht/dhtlog.h 2011-08-15 21:46:35 UTC (rev 16581)
@@ -178,7 +178,7 @@
*
* @return GNUNET_OK on success, GNUNET_SYSERR on failure
*/
- int (*insert_trial) (struct GNUNET_DHTLOG_TrialInfo *trial_info);
+ int (*insert_trial) (struct GNUNET_DHTLOG_TrialInfo * trial_info);
/*
* Inserts the specified stats into the dhttests.node_statistics table
@@ -204,15 +204,15 @@
* @return GNUNET_OK on success, GNUNET_SYSERR on failure
*/
int (*insert_stat)
- (const struct GNUNET_PeerIdentity *peer, unsigned int route_requests,
- unsigned int route_forwards, unsigned int result_requests,
- unsigned int client_requests, unsigned int result_forwards,
- unsigned int gets, unsigned int puts,
- unsigned int data_inserts, unsigned int find_peer_requests,
- unsigned int find_peers_started, unsigned int gets_started,
- unsigned int puts_started, unsigned int find_peer_responses_received,
- unsigned int get_responses_received, unsigned int
find_peer_responses_sent,
- unsigned int get_responses_sent);
+ (const struct GNUNET_PeerIdentity * peer, unsigned int route_requests,
+ unsigned int route_forwards, unsigned int result_requests,
+ unsigned int client_requests, unsigned int result_forwards,
+ unsigned int gets, unsigned int puts,
+ unsigned int data_inserts, unsigned int find_peer_requests,
+ unsigned int find_peers_started, unsigned int gets_started,
+ unsigned int puts_started, unsigned int find_peer_responses_received,
+ unsigned int get_responses_received,
+ unsigned int find_peer_responses_sent, unsigned int get_responses_sent);
/*
* Update dhttests.trials table with current server time as end time
@@ -231,7 +231,7 @@
*
* @return GNUNET_OK on success, GNUNET_SYSERR on failure.
*/
- int (*set_malicious) (struct GNUNET_PeerIdentity *peer);
+ int (*set_malicious) (struct GNUNET_PeerIdentity * peer);
/*
* Records the current topology (number of connections, time, trial)
@@ -250,7 +250,8 @@
*
* @return GNUNET_OK on success, GNUNET_SYSERR on failure
*/
- int (*insert_extended_topology) (const struct GNUNET_PeerIdentity *first,
const struct GNUNET_PeerIdentity *second);
+ int (*insert_extended_topology) (const struct GNUNET_PeerIdentity * first,
+ const struct GNUNET_PeerIdentity * second);
/*
* Inserts the specified stats into the dhttests.generic_stats table
@@ -262,10 +263,9 @@
*
* @return GNUNET_OK on success, GNUNET_SYSERR on failure
*/
- int
- (*add_generic_stat) (const struct GNUNET_PeerIdentity *peer,
- const char *name,
- const char *section, uint64_t value);
+ int (*add_generic_stat) (const struct GNUNET_PeerIdentity * peer,
+ const char *name,
+ const char *section, uint64_t value);
/*
* Inserts the specified round into the dhttests.rounds table
@@ -288,8 +288,10 @@
*
* @return GNUNET_OK on success, GNUNET_SYSERR on failure
*/
- int (*insert_round_details) (unsigned int round_type, unsigned int
round_count,
- unsigned int num_messages, unsigned int
num_messages_succeeded);
+ int (*insert_round_details) (unsigned int round_type,
+ unsigned int round_count,
+ unsigned int num_messages,
+ unsigned int num_messages_succeeded);
/*
* Update dhttests.trials table with total connections information
@@ -371,14 +373,14 @@
*
* @param c a configuration to use
*/
-struct GNUNET_DHTLOG_Handle *
-GNUNET_DHTLOG_connect (const struct GNUNET_CONFIGURATION_Handle *c);
+struct GNUNET_DHTLOG_Handle *GNUNET_DHTLOG_connect (const struct
+ GNUNET_CONFIGURATION_Handle
+ *c);
/**
* Shutdown the module.
*/
-void
-GNUNET_DHTLOG_disconnect (struct GNUNET_DHTLOG_Handle *api);
+void GNUNET_DHTLOG_disconnect (struct GNUNET_DHTLOG_Handle *api);
#if 0 /* keep Emacsens' auto-indent happy */
Modified: gnunet/src/dht/gnunet-dht-driver.c
===================================================================
--- gnunet/src/dht/gnunet-dht-driver.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/dht/gnunet-dht-driver.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -778,11 +778,9 @@
static enum GNUNET_TESTING_Topology topology;
-static enum GNUNET_TESTING_Topology blacklist_topology =
- GNUNET_TESTING_TOPOLOGY_NONE; /* Don't do any blacklisting */
+static enum GNUNET_TESTING_Topology blacklist_topology =
GNUNET_TESTING_TOPOLOGY_NONE; /* Don't do any blacklisting */
-static enum GNUNET_TESTING_Topology connect_topology =
- GNUNET_TESTING_TOPOLOGY_NONE; /* NONE actually means connect all allowed
peers */
+static enum GNUNET_TESTING_Topology connect_topology =
GNUNET_TESTING_TOPOLOGY_NONE; /* NONE actually means connect all allowed
peers */
static enum GNUNET_TESTING_TopologyOption connect_topology_option =
GNUNET_TESTING_TOPOLOGY_OPTION_ALL;
@@ -815,18 +813,19 @@
* @return the progress meter
*/
static struct ProgressMeter *
-create_meter(unsigned int total, char * start_string, int print)
+create_meter (unsigned int total, char *start_string, int print)
{
struct ProgressMeter *ret;
- ret = GNUNET_malloc(sizeof(struct ProgressMeter));
+
+ ret = GNUNET_malloc (sizeof (struct ProgressMeter));
ret->print = print;
ret->total = total;
ret->modnum = total / 4;
ret->dotnum = (total / 50) + 1;
if (start_string != NULL)
- ret->startup_string = GNUNET_strdup(start_string);
+ ret->startup_string = GNUNET_strdup (start_string);
else
- ret->startup_string = GNUNET_strdup("");
+ ret->startup_string = GNUNET_strdup ("");
return ret;
}
@@ -840,27 +839,27 @@
* GNUNET_NO if more items expected
*/
static int
-update_meter(struct ProgressMeter *meter)
+update_meter (struct ProgressMeter *meter)
{
if (meter->print == GNUNET_YES)
+ {
+ if (meter->completed % meter->modnum == 0)
{
- if (meter->completed % meter->modnum == 0)
- {
- if (meter->completed == 0)
- {
- fprintf (stdout, "%sProgress: [0%%", meter->startup_string);
- }
- else
- fprintf (stdout, "%d%%", (int) (((float) meter->completed
- / meter->total) * 100));
- }
- else if (meter->completed % meter->dotnum == 0)
- fprintf (stdout, ".");
-
- if (meter->completed + 1 == meter->total)
- fprintf (stdout, "%d%%]\n", 100);
- fflush (stdout);
+ if (meter->completed == 0)
+ {
+ fprintf (stdout, "%sProgress: [0%%", meter->startup_string);
+ }
+ else
+ fprintf (stdout, "%d%%", (int) (((float) meter->completed
+ / meter->total) * 100));
}
+ else if (meter->completed % meter->dotnum == 0)
+ fprintf (stdout, ".");
+
+ if (meter->completed + 1 == meter->total)
+ fprintf (stdout, "%d%%]\n", 100);
+ fflush (stdout);
+ }
meter->completed++;
if (meter->completed == meter->total)
@@ -877,7 +876,7 @@
* GNUNET_SYSERR on error
*/
static int
-reset_meter(struct ProgressMeter *meter)
+reset_meter (struct ProgressMeter *meter)
{
if (meter == NULL)
return GNUNET_SYSERR;
@@ -892,7 +891,7 @@
* @param meter the meter to free
*/
static void
-free_meter(struct ProgressMeter *meter)
+free_meter (struct ProgressMeter *meter)
{
GNUNET_free_non_null (meter->startup_string);
GNUNET_free (meter);
@@ -902,32 +901,31 @@
* Check whether peers successfully shut down.
*/
static void
-shutdown_callback(void *cls, const char *emsg)
+shutdown_callback (void *cls, const char *emsg)
{
if (emsg != NULL)
- {
- if (ok == 0)
- ok = 2;
- }
+ {
+ if (ok == 0)
+ ok = 2;
+ }
}
/**
* Task to release DHT handles for PUT
*/
static void
-put_disconnect_task(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
+put_disconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct TestPutContext *test_put = cls;
+
test_put->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
GNUNET_DHT_disconnect (test_put->dht_handle);
test_put->dht_handle = NULL;
if (replicate_same == GNUNET_NO)
test_put->daemon
- = GNUNET_TESTING_daemon_get (
- pg,
- GNUNET_CRYPTO_random_u32 (
-
GNUNET_CRYPTO_QUALITY_WEAK,
- num_peers));
+ = GNUNET_TESTING_daemon_get (pg,
+ GNUNET_CRYPTO_random_u32
+ (GNUNET_CRYPTO_QUALITY_WEAK, num_peers));
}
/**
@@ -935,7 +933,7 @@
* testcase.
*/
static void
-finish_testing(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
+finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Ending test normally!\n",
(char *) cls);
@@ -946,34 +944,34 @@
char *revision_str;
while (test_put != NULL)
- {
- if (test_put->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel (test_put->disconnect_task);
- if (test_put->dht_handle != NULL)
- GNUNET_DHT_disconnect (test_put->dht_handle);
- test_put = test_put->next;
- }
+ {
+ if (test_put->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
+ GNUNET_SCHEDULER_cancel (test_put->disconnect_task);
+ if (test_put->dht_handle != NULL)
+ GNUNET_DHT_disconnect (test_put->dht_handle);
+ test_put = test_put->next;
+ }
while (test_get != NULL)
- {
- if (test_get->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel (test_get->disconnect_task);
- if (test_get->get_handle != NULL)
- GNUNET_DHT_get_stop (test_get->get_handle);
- if (test_get->dht_handle != NULL)
- GNUNET_DHT_disconnect (test_get->dht_handle);
- test_get = test_get->next;
- }
+ {
+ if (test_get->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
+ GNUNET_SCHEDULER_cancel (test_get->disconnect_task);
+ if (test_get->get_handle != NULL)
+ GNUNET_DHT_get_stop (test_get->get_handle);
+ if (test_get->dht_handle != NULL)
+ GNUNET_DHT_disconnect (test_get->dht_handle);
+ test_get = test_get->next;
+ }
GNUNET_TESTING_daemons_stop (pg, DEFAULT_TIMEOUT, &shutdown_callback, NULL);
if (dhtlog_handle != NULL)
- {
- fprintf (stderr, "Update trial endtime\n");
- dhtlog_handle->update_trial (cumulative_successful_gets);
- GNUNET_DHTLOG_disconnect (dhtlog_handle);
- dhtlog_handle = NULL;
- }
+ {
+ fprintf (stderr, "Update trial endtime\n");
+ dhtlog_handle->update_trial (cumulative_successful_gets);
+ GNUNET_DHTLOG_disconnect (dhtlog_handle);
+ dhtlog_handle = NULL;
+ }
if (hostkey_meter != NULL)
free_meter (hostkey_meter);
@@ -989,13 +987,14 @@
GNUNET_asprintf (&temp_get_string, "DHT Successful GETs", trial_to_run);
GNUNET_asprintf (&revision_str, "%llu", revision);
if (GNUNET_YES == insert_gauger_data)
- GAUGER_ID("DHT_TESTING", temp_get_string, cumulative_successful_gets /
(double)cumulative_num_gets, "percent successful", revision_str);
- fprintf (
- stderr,
+ GAUGER_ID ("DHT_TESTING", temp_get_string,
+ cumulative_successful_gets / (double) cumulative_num_gets,
+ "percent successful", revision_str);
+ fprintf (stderr,
"Finished trial, had %llu successful gets out of %llu total, %.2f
percent succeeded\n",
cumulative_successful_gets, cumulative_num_gets,
cumulative_successful_gets / (double) cumulative_num_gets);
- GNUNET_free(temp_get_string);
+ GNUNET_free (temp_get_string);
ok = 0;
}
@@ -1004,40 +1003,42 @@
* Callback for iterating over all the peer connections of a peer group.
*/
static void
-log_topology_cb(void *cls, const struct GNUNET_PeerIdentity *first,
- const struct GNUNET_PeerIdentity *second, const char *emsg)
+log_topology_cb (void *cls, const struct GNUNET_PeerIdentity *first,
+ const struct GNUNET_PeerIdentity *second, const char *emsg)
{
struct TopologyIteratorContext *topo_ctx = cls;
+
if ((first != NULL) && (second != NULL))
+ {
+ if ((topo_ctx->peers_seen != NULL) && (GNUNET_NO
+ ==
+
GNUNET_CONTAINER_multihashmap_contains
+ (topo_ctx->peers_seen,
+ &first->hashPubKey)))
{
- if ((topo_ctx->peers_seen != NULL) && (GNUNET_NO
- == GNUNET_CONTAINER_multihashmap_contains (topo_ctx->peers_seen,
- &first->hashPubKey)))
- {
- GNUNET_CONTAINER_multihashmap_put (topo_ctx->peers_seen,
- &first->hashPubKey, NULL,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
- topo_ctx->total_peers++;
- }
- topo_ctx->total_connections++;
- if ((GNUNET_NO == dhtlog_minimal) && (dhtlog_handle != NULL))
- dhtlog_handle->insert_extended_topology (first, second);
+ GNUNET_CONTAINER_multihashmap_put (topo_ctx->peers_seen,
+ &first->hashPubKey, NULL,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+ topo_ctx->total_peers++;
}
+ topo_ctx->total_connections++;
+ if ((GNUNET_NO == dhtlog_minimal) && (dhtlog_handle != NULL))
+ dhtlog_handle->insert_extended_topology (first, second);
+ }
else
- {
- GNUNET_assert(dhtlog_handle != NULL);
- GNUNET_log (
- GNUNET_ERROR_TYPE_WARNING,
- "Topology iteration (%u/%u) finished (%u connections, %u
peers)\n",
- topo_ctx->current_iteration, topo_ctx->total_iterations,
- topo_ctx->total_connections, topo_ctx->total_peers);
- dhtlog_handle->update_topology (topo_ctx->total_connections);
- if (topo_ctx->cont != NULL)
- GNUNET_SCHEDULER_add_now (topo_ctx->cont, topo_ctx->cls);
- if (topo_ctx->peers_seen != NULL)
- GNUNET_CONTAINER_multihashmap_destroy (topo_ctx->peers_seen);
- GNUNET_free(topo_ctx);
- }
+ {
+ GNUNET_assert (dhtlog_handle != NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Topology iteration (%u/%u) finished (%u connections, %u
peers)\n",
+ topo_ctx->current_iteration, topo_ctx->total_iterations,
+ topo_ctx->total_connections, topo_ctx->total_peers);
+ dhtlog_handle->update_topology (topo_ctx->total_connections);
+ if (topo_ctx->cont != NULL)
+ GNUNET_SCHEDULER_add_now (topo_ctx->cont, topo_ctx->cls);
+ if (topo_ctx->peers_seen != NULL)
+ GNUNET_CONTAINER_multihashmap_destroy (topo_ctx->peers_seen);
+ GNUNET_free (topo_ctx);
+ }
}
/**
@@ -1051,9 +1052,10 @@
* GNUNET_NO if not.
*/
static int
-stats_iterate(void *cls, const GNUNET_HashCode * key, void *value)
+stats_iterate (void *cls, const GNUNET_HashCode * key, void *value)
{
struct StatisticsIteratorContext *stats_ctx;
+
if (value == NULL)
return GNUNET_NO;
stats_ctx = value;
@@ -1072,12 +1074,12 @@
stats_ctx->stat_get_reply,
stats_ctx->stat_find_peer_answer,
stats_ctx->stat_get_response_start);
- GNUNET_free(stats_ctx);
+ GNUNET_free (stats_ctx);
return GNUNET_YES;
}
static void
-stats_finished(void *cls, int result)
+stats_finished (void *cls, int result)
{
fprintf (stderr, "Finished getting all peers statistics, iterating!\n");
GNUNET_CONTAINER_multihashmap_iterate (stats_map, &stats_iterate, NULL);
@@ -1097,28 +1099,28 @@
* @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
*/
static int
-stats_handle(void *cls, const struct GNUNET_PeerIdentity *peer,
- const char *subsystem, const char *name, uint64_t value,
- int is_persistent)
+stats_handle (void *cls, const struct GNUNET_PeerIdentity *peer,
+ const char *subsystem, const char *name, uint64_t value,
+ int is_persistent)
{
struct StatisticsIteratorContext *stats_ctx;
if (dhtlog_handle != NULL)
dhtlog_handle->add_generic_stat (peer, name, subsystem, value);
if (GNUNET_CONTAINER_multihashmap_contains (stats_map, &peer->hashPubKey))
- {
- stats_ctx = GNUNET_CONTAINER_multihashmap_get (stats_map,
- &peer->hashPubKey);
- }
+ {
+ stats_ctx = GNUNET_CONTAINER_multihashmap_get (stats_map,
+ &peer->hashPubKey);
+ }
else
- {
- stats_ctx = GNUNET_malloc(sizeof(struct StatisticsIteratorContext));
- stats_ctx->peer = peer;
- GNUNET_CONTAINER_multihashmap_put (stats_map, &peer->hashPubKey,
- stats_ctx,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
- }
- GNUNET_assert(stats_ctx != NULL);
+ {
+ stats_ctx = GNUNET_malloc (sizeof (struct StatisticsIteratorContext));
+ stats_ctx->peer = peer;
+ GNUNET_CONTAINER_multihashmap_put (stats_map, &peer->hashPubKey,
+ stats_ctx,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+ }
+ GNUNET_assert (stats_ctx != NULL);
if (strcmp (name, STAT_ROUTES) == 0)
stats_ctx->stat_routes = value;
@@ -1161,7 +1163,7 @@
* dht statistics for safe keeping.
*/
static void
-log_dht_statistics(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
+log_dht_statistics (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
stats_map = GNUNET_CONTAINER_multihashmap_create (num_peers);
fprintf (stderr, "Starting statistics logging\n");
@@ -1173,10 +1175,11 @@
* connections.
*/
static void
-capture_current_topology(void *cls,
- const struct GNUNET_SCHEDULER_TaskContext * tc)
+capture_current_topology (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct TopologyIteratorContext *topo_ctx = cls;
+
dhtlog_handle->insert_topology (0);
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Called capture_current_topology\n");
GNUNET_TESTING_get_topology (pg, &log_topology_cb, topo_ctx);
@@ -1188,7 +1191,7 @@
* test.
*/
static void
-end_badly(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
+end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failing test with error: `%s'!\n",
(char *) cls);
@@ -1197,34 +1200,34 @@
struct TestGetContext *test_get = all_gets;
while (test_put != NULL)
- {
- if (test_put->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel (test_put->disconnect_task);
- if (test_put->dht_handle != NULL)
- GNUNET_DHT_disconnect (test_put->dht_handle);
- test_put = test_put->next;
- }
+ {
+ if (test_put->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
+ GNUNET_SCHEDULER_cancel (test_put->disconnect_task);
+ if (test_put->dht_handle != NULL)
+ GNUNET_DHT_disconnect (test_put->dht_handle);
+ test_put = test_put->next;
+ }
while (test_get != NULL)
- {
- if (test_get->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel (test_get->disconnect_task);
- if (test_get->get_handle != NULL)
- GNUNET_DHT_get_stop (test_get->get_handle);
- if (test_get->dht_handle != NULL)
- GNUNET_DHT_disconnect (test_get->dht_handle);
- test_get = test_get->next;
- }
+ {
+ if (test_get->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
+ GNUNET_SCHEDULER_cancel (test_get->disconnect_task);
+ if (test_get->get_handle != NULL)
+ GNUNET_DHT_get_stop (test_get->get_handle);
+ if (test_get->dht_handle != NULL)
+ GNUNET_DHT_disconnect (test_get->dht_handle);
+ test_get = test_get->next;
+ }
GNUNET_TESTING_daemons_stop (pg, DEFAULT_TIMEOUT, &shutdown_callback, NULL);
if (dhtlog_handle != NULL)
- {
- fprintf (stderr, "Update trial endtime\n");
- dhtlog_handle->update_trial (gets_completed);
- GNUNET_DHTLOG_disconnect (dhtlog_handle);
- dhtlog_handle = NULL;
- }
+ {
+ fprintf (stderr, "Update trial endtime\n");
+ dhtlog_handle->update_trial (gets_completed);
+ GNUNET_DHTLOG_disconnect (dhtlog_handle);
+ dhtlog_handle = NULL;
+ }
if (hostkey_meter != NULL)
free_meter (hostkey_meter);
@@ -1243,14 +1246,12 @@
/**
* Forward declaration.
*/
-static void
-do_put(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc);
+static void do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
/**
* Forward declaration.
*/
-static void
-do_get(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc);
+static void do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
/**
* Iterator over hash map entries.
@@ -1263,11 +1264,12 @@
* GNUNET_NO if not.
*/
static int
-remove_peer_count(void *cls, const GNUNET_HashCode * key, void *value)
+remove_peer_count (void *cls, const GNUNET_HashCode * key, void *value)
{
struct PeerCount *peer_count = value;
+
GNUNET_CONTAINER_heap_remove_node (peer_count->heap_node);
- GNUNET_free(peer_count);
+ GNUNET_free (peer_count);
return GNUNET_YES;
}
@@ -1277,9 +1279,10 @@
* connections.
*/
static void
-count_new_peers(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
+count_new_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct FindPeerContext *find_peer_context = cls;
+
find_peer_context->previous_peers = find_peer_context->current_peers;
find_peer_context->current_peers = 0;
GNUNET_TESTING_get_topology (pg, find_peer_context->count_peers_cb,
@@ -1287,18 +1290,19 @@
}
static void
-decrement_find_peers(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
+decrement_find_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct TestFindPeer *test_find_peer = cls;
- GNUNET_assert(test_find_peer->find_peer_context->outstanding > 0);
+
+ GNUNET_assert (test_find_peer->find_peer_context->outstanding > 0);
test_find_peer->find_peer_context->outstanding--;
test_find_peer->find_peer_context->total--;
if (0 == test_find_peer->find_peer_context->total)
- {
- GNUNET_SCHEDULER_add_now (&count_new_peers,
- test_find_peer->find_peer_context);
- }
- GNUNET_free(test_find_peer);
+ {
+ GNUNET_SCHEDULER_add_now (&count_new_peers,
+ test_find_peer->find_peer_context);
+ }
+ GNUNET_free (test_find_peer);
}
/**
@@ -1309,42 +1313,41 @@
* @param tc context the task is being called with
*/
static void
-handle_find_peer_sent(void *cls, const struct GNUNET_SCHEDULER_TaskContext *
tc)
+handle_find_peer_sent (void *cls, const struct GNUNET_SCHEDULER_TaskContext
*tc)
{
struct TestFindPeer *test_find_peer = cls;
GNUNET_DHT_disconnect (test_find_peer->dht_handle);
- GNUNET_SCHEDULER_add_delayed (
- GNUNET_TIME_relative_divide (find_peer_delay,
2),
- &decrement_find_peers, test_find_peer);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide
+ (find_peer_delay, 2), &decrement_find_peers,
+ test_find_peer);
}
static void
-send_find_peer_request(void *cls,
- const struct GNUNET_SCHEDULER_TaskContext * tc)
+send_find_peer_request (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct TestFindPeer *test_find_peer = cls;
if (test_find_peer->find_peer_context->outstanding
> max_outstanding_find_peers)
- {
- GNUNET_SCHEDULER_add_delayed (find_peer_offset, &send_find_peer_request,
- test_find_peer);
- return;
- }
+ {
+ GNUNET_SCHEDULER_add_delayed (find_peer_offset, &send_find_peer_request,
+ test_find_peer);
+ return;
+ }
test_find_peer->find_peer_context->outstanding++;
- if (GNUNET_TIME_absolute_get_remaining (
-
test_find_peer->find_peer_context->endtime).rel_value
- == 0)
- {
- GNUNET_SCHEDULER_add_now (&decrement_find_peers, test_find_peer);
- return;
- }
+ if (GNUNET_TIME_absolute_get_remaining
+ (test_find_peer->find_peer_context->endtime).rel_value == 0)
+ {
+ GNUNET_SCHEDULER_add_now (&decrement_find_peers, test_find_peer);
+ return;
+ }
test_find_peer->dht_handle = GNUNET_DHT_connect (test_find_peer->daemon->cfg,
1);
- GNUNET_assert(test_find_peer->dht_handle != NULL);
+ GNUNET_assert (test_find_peer->dht_handle != NULL);
GNUNET_DHT_find_peers (test_find_peer->dht_handle, &handle_find_peer_sent,
test_find_peer);
}
@@ -1355,63 +1358,63 @@
* the least connections to initiate find peer requests from.
*/
static void
-add_new_connection(struct FindPeerContext *find_peer_context,
- const struct GNUNET_PeerIdentity *first,
- const struct GNUNET_PeerIdentity *second)
+add_new_connection (struct FindPeerContext *find_peer_context,
+ const struct GNUNET_PeerIdentity *first,
+ const struct GNUNET_PeerIdentity *second)
{
struct PeerCount *first_count;
struct PeerCount *second_count;
if (GNUNET_CONTAINER_multihashmap_contains (find_peer_context->peer_hash,
&first->hashPubKey))
- {
- first_count
- = GNUNET_CONTAINER_multihashmap_get (find_peer_context->peer_hash,
- &first->hashPubKey);
- GNUNET_assert(first_count != NULL);
- first_count->count++;
- GNUNET_CONTAINER_heap_update_cost (find_peer_context->peer_min_heap,
- first_count->heap_node,
- first_count->count);
- }
+ {
+ first_count
+ = GNUNET_CONTAINER_multihashmap_get (find_peer_context->peer_hash,
+ &first->hashPubKey);
+ GNUNET_assert (first_count != NULL);
+ first_count->count++;
+ GNUNET_CONTAINER_heap_update_cost (find_peer_context->peer_min_heap,
+ first_count->heap_node,
+ first_count->count);
+ }
else
- {
- first_count = GNUNET_malloc(sizeof(struct PeerCount));
- first_count->count = 1;
- memcpy (&first_count->peer_id, first, sizeof(struct
GNUNET_PeerIdentity));
- first_count->heap_node
- = GNUNET_CONTAINER_heap_insert (find_peer_context->peer_min_heap,
- first_count, first_count->count);
- GNUNET_CONTAINER_multihashmap_put (find_peer_context->peer_hash,
- &first->hashPubKey, first_count,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
- }
+ {
+ first_count = GNUNET_malloc (sizeof (struct PeerCount));
+ first_count->count = 1;
+ memcpy (&first_count->peer_id, first, sizeof (struct GNUNET_PeerIdentity));
+ first_count->heap_node
+ = GNUNET_CONTAINER_heap_insert (find_peer_context->peer_min_heap,
+ first_count, first_count->count);
+ GNUNET_CONTAINER_multihashmap_put (find_peer_context->peer_hash,
+ &first->hashPubKey, first_count,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+ }
if (GNUNET_CONTAINER_multihashmap_contains (find_peer_context->peer_hash,
&second->hashPubKey))
- {
- second_count
- = GNUNET_CONTAINER_multihashmap_get (find_peer_context->peer_hash,
- &second->hashPubKey);
- GNUNET_assert(second_count != NULL);
- second_count->count++;
- GNUNET_CONTAINER_heap_update_cost (find_peer_context->peer_min_heap,
- second_count->heap_node,
- second_count->count);
- }
+ {
+ second_count
+ = GNUNET_CONTAINER_multihashmap_get (find_peer_context->peer_hash,
+ &second->hashPubKey);
+ GNUNET_assert (second_count != NULL);
+ second_count->count++;
+ GNUNET_CONTAINER_heap_update_cost (find_peer_context->peer_min_heap,
+ second_count->heap_node,
+ second_count->count);
+ }
else
- {
- second_count = GNUNET_malloc(sizeof(struct PeerCount));
- second_count->count = 1;
- memcpy (&second_count->peer_id, second,
- sizeof(struct GNUNET_PeerIdentity));
- second_count->heap_node
- = GNUNET_CONTAINER_heap_insert (find_peer_context->peer_min_heap,
- second_count, second_count->count);
- GNUNET_CONTAINER_multihashmap_put (find_peer_context->peer_hash,
- &second->hashPubKey, second_count,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
- }
+ {
+ second_count = GNUNET_malloc (sizeof (struct PeerCount));
+ second_count->count = 1;
+ memcpy (&second_count->peer_id, second,
+ sizeof (struct GNUNET_PeerIdentity));
+ second_count->heap_node
+ = GNUNET_CONTAINER_heap_insert (find_peer_context->peer_min_heap,
+ second_count, second_count->count);
+ GNUNET_CONTAINER_multihashmap_put (find_peer_context->peer_hash,
+ &second->hashPubKey, second_count,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+ }
}
/**
@@ -1427,46 +1430,43 @@
* GNUNET_NO if not.
*/
static int
-iterate_min_heap_peers(void *cls, struct GNUNET_CONTAINER_HeapNode *node,
- void *element, GNUNET_CONTAINER_HeapCostType cost)
+iterate_min_heap_peers (void *cls, struct GNUNET_CONTAINER_HeapNode *node,
+ void *element, GNUNET_CONTAINER_HeapCostType cost)
{
struct FindPeerContext *find_peer_context = cls;
struct PeerCount *peer_count = element;
struct GNUNET_TESTING_Daemon *d1;
struct GNUNET_TESTING_Daemon *d2;
struct GNUNET_TIME_Relative timeout;
+
if (cost == 0)
+ {
+ d1 = GNUNET_TESTING_daemon_get_by_id (pg, &peer_count->peer_id);
+ GNUNET_assert (d1 != NULL);
+ d2 = d1;
+ while ((d2 == d1) || (GNUNET_YES != GNUNET_TESTING_daemon_running (d2)))
{
- d1 = GNUNET_TESTING_daemon_get_by_id (pg, &peer_count->peer_id);
- GNUNET_assert(d1 != NULL);
- d2 = d1;
- while ((d2 == d1) || (GNUNET_YES != GNUNET_TESTING_daemon_running (d2)))
- {
- d2
- = GNUNET_TESTING_daemon_get (
- pg,
- GNUNET_CRYPTO_random_u32 (
-
GNUNET_CRYPTO_QUALITY_WEAK,
-
num_peers));
- GNUNET_assert(d2 != NULL);
- }
+ d2 = GNUNET_TESTING_daemon_get (pg,
+ GNUNET_CRYPTO_random_u32
+ (GNUNET_CRYPTO_QUALITY_WEAK, num_peers));
+ GNUNET_assert (d2 != NULL);
+ }
/** Just try to connect the peers, don't worry about callbacks, etc. **/
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Peer %s has 0 connections. Trying to connect to %s...\n",
- GNUNET_i2s (&peer_count->peer_id), d2->shortname);
- timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
- DEFAULT_CONNECT_TIMEOUT);
- if (GNUNET_TIME_relative_to_absolute (timeout).abs_value
- > find_peer_context->endtime.abs_value)
- {
- timeout
- = GNUNET_TIME_absolute_get_remaining
(find_peer_context->endtime);
- }
- GNUNET_TESTING_daemons_connect (d1, d2, timeout,
- DEFAULT_RECONNECT_ATTEMPTS, GNUNET_YES,
- NULL, NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Peer %s has 0 connections. Trying to connect to %s...\n",
+ GNUNET_i2s (&peer_count->peer_id), d2->shortname);
+ timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
+ DEFAULT_CONNECT_TIMEOUT);
+ if (GNUNET_TIME_relative_to_absolute (timeout).abs_value
+ > find_peer_context->endtime.abs_value)
+ {
+ timeout = GNUNET_TIME_absolute_get_remaining
(find_peer_context->endtime);
}
+ GNUNET_TESTING_daemons_connect (d1, d2, timeout,
+ DEFAULT_RECONNECT_ATTEMPTS, GNUNET_YES,
+ NULL, NULL);
+ }
if (GNUNET_TIME_absolute_get_remaining (find_peer_context->endtime).rel_value
> 0)
return GNUNET_YES;
@@ -1478,9 +1478,9 @@
* Forward declaration.
*/
static void
- schedule_churn_find_peer_requests(
- void *cls,
- const struct
GNUNET_SCHEDULER_TaskContext * tc);
+schedule_churn_find_peer_requests (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext
+ *tc);
/**
* Callback for iterating over all the peer connections of a peer group.
@@ -1488,39 +1488,39 @@
* connections so we can make them issue find peer requests.
*/
static void
-count_peers_churn_cb(void *cls, const struct GNUNET_PeerIdentity *first,
- const struct GNUNET_PeerIdentity *second, const char
*emsg)
+count_peers_churn_cb (void *cls, const struct GNUNET_PeerIdentity *first,
+ const struct GNUNET_PeerIdentity *second,
+ const char *emsg)
{
struct FindPeerContext *find_peer_context = cls;
struct TopologyIteratorContext *topo_ctx;
struct PeerCount *peer_count;
if ((first != NULL) && (second != NULL))
- {
- add_new_connection (find_peer_context, first, second);
- find_peer_context->current_peers++;
- }
+ {
+ add_new_connection (find_peer_context, first, second);
+ find_peer_context->current_peers++;
+ }
else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Peer count finished (%u connections)\n",
- find_peer_context->current_peers);
- peer_count
- = GNUNET_CONTAINER_heap_peek (find_peer_context->peer_min_heap);
- GNUNET_assert(peer_count != NULL);
- /* WAIT. When peers are churned they will come back with their peers (at
least in peerinfo), because the HOSTS file doesn't likely get removed. CRAP. */
- /* NO they won't, because we have disabled peerinfo writing to disk
(remember?) so we WILL have to give them new connections */
- /* Best course of action: have DHT automatically try to add peers from
peerinfo on startup. This way IF peerinfo writes to file
- * then some peers will end up connected.
- *
- * Also, find any peers that have zero connections here and set up a
task to choose at random another peer in the network to
- * connect to. Of course, if they are blacklisted from that peer they
won't be able to connect, so we will have to keep trying
- * until they get a peer.
- */
- /* However, they won't automatically be connected to any of their
previous peers... How can we handle that? */
- /* So now we have choices: do we want them to come back with all their
connections? Probably not, but it solves this mess. */
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Peer count finished (%u connections)\n",
+ find_peer_context->current_peers);
+ peer_count = GNUNET_CONTAINER_heap_peek (find_peer_context->peer_min_heap);
+ GNUNET_assert (peer_count != NULL);
+ /* WAIT. When peers are churned they will come back with their peers (at
least in peerinfo), because the HOSTS file doesn't likely get removed. CRAP. */
+ /* NO they won't, because we have disabled peerinfo writing to disk
(remember?) so we WILL have to give them new connections */
+ /* Best course of action: have DHT automatically try to add peers from
peerinfo on startup. This way IF peerinfo writes to file
+ * then some peers will end up connected.
+ *
+ * Also, find any peers that have zero connections here and set up a task
to choose at random another peer in the network to
+ * connect to. Of course, if they are blacklisted from that peer they
won't be able to connect, so we will have to keep trying
+ * until they get a peer.
+ */
+ /* However, they won't automatically be connected to any of their previous
peers... How can we handle that? */
+ /* So now we have choices: do we want them to come back with all their
connections? Probably not, but it solves this mess. */
- /* Second problem, which is still a problem, is that a FIND_PEER request
won't work when a peer has no connections */
+ /* Second problem, which is still a problem, is that a FIND_PEER request
won't work when a peer has no connections */
/**
* Okay, so here's how this *should* work now.
@@ -1555,77 +1555,73 @@
* into the general testing churn options seems like overkill
because
* these are very specialized cases.
*/
- GNUNET_log (
- GNUNET_ERROR_TYPE_WARNING,
- "Out of %u peers, fewest connections is %d\n",
- GNUNET_CONTAINER_heap_get_size (
-
find_peer_context->peer_min_heap),
- peer_count->count);
- if ((peer_count->count == 0)
- && (GNUNET_TIME_absolute_get_remaining
(find_peer_context->endtime).rel_value
- > 0))
- {
- GNUNET_log (
- GNUNET_ERROR_TYPE_WARNING,
- "Found peer with no connections, will choose some
peer(s) at random to connect to!\n");
- GNUNET_CONTAINER_heap_iterate (find_peer_context->peer_min_heap,
- &iterate_min_heap_peers,
- find_peer_context);
- GNUNET_SCHEDULER_add_now (&schedule_churn_find_peer_requests,
- find_peer_context);
- }
- else if ((GNUNET_TIME_absolute_get_remaining
(find_peer_context->endtime).rel_value
- > 0) && (find_peer_context->last_sent != 0))
- {
- GNUNET_SCHEDULER_add_now (&schedule_churn_find_peer_requests,
- find_peer_context);
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Out of %u peers, fewest connections is %d\n",
+ GNUNET_CONTAINER_heap_get_size
+ (find_peer_context->peer_min_heap), peer_count->count);
+ if ((peer_count->count == 0) &&
+ (GNUNET_TIME_absolute_get_remaining
+ (find_peer_context->endtime).rel_value > 0))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Found peer with no connections, will choose some peer(s) at
random to connect to!\n");
+ GNUNET_CONTAINER_heap_iterate (find_peer_context->peer_min_heap,
+ &iterate_min_heap_peers,
+ find_peer_context);
+ GNUNET_SCHEDULER_add_now (&schedule_churn_find_peer_requests,
+ find_peer_context);
+ }
+ else if ((GNUNET_TIME_absolute_get_remaining
+ (find_peer_context->endtime).rel_value > 0) &&
+ (find_peer_context->last_sent != 0))
+ {
+ GNUNET_SCHEDULER_add_now (&schedule_churn_find_peer_requests,
+ find_peer_context);
+ }
+ else
+ {
+ GNUNET_CONTAINER_multihashmap_iterate (find_peer_context->peer_hash,
+ &remove_peer_count,
+ find_peer_context);
+ GNUNET_CONTAINER_multihashmap_destroy (find_peer_context->peer_hash);
+ GNUNET_CONTAINER_heap_destroy (find_peer_context->peer_min_heap);
+ GNUNET_free (find_peer_context);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Churn round %u of %llu finished, scheduling next GET
round.\n",
+ current_churn_round, churn_rounds);
+ if (dhtlog_handle != NULL)
+ {
+ topo_ctx = GNUNET_malloc (sizeof (struct TopologyIteratorContext));
+ topo_ctx->cont = &do_get;
+ topo_ctx->cls = all_gets;
+ topo_ctx->timeout = DEFAULT_GET_TIMEOUT;
+ topo_ctx->peers_seen = GNUNET_CONTAINER_multihashmap_create
(num_peers);
+ die_task
+ =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_add
+ (GNUNET_TIME_relative_add
+ (DEFAULT_GET_TIMEOUT,
+ all_get_timeout),
+ DEFAULT_TOPOLOGY_CAPTURE_TIMEOUT),
+ &end_badly,
+ "from do gets
(count_peers_churn_cb)");
+ GNUNET_SCHEDULER_add_now (&capture_current_topology, topo_ctx);
+ }
else
- {
- GNUNET_CONTAINER_multihashmap_iterate (find_peer_context->peer_hash,
- &remove_peer_count,
- find_peer_context);
- GNUNET_CONTAINER_multihashmap_destroy (find_peer_context->peer_hash);
- GNUNET_CONTAINER_heap_destroy (find_peer_context->peer_min_heap);
- GNUNET_free(find_peer_context);
- GNUNET_log (
- GNUNET_ERROR_TYPE_WARNING,
- "Churn round %u of %llu finished, scheduling next GET
round.\n",
- current_churn_round, churn_rounds);
- if (dhtlog_handle != NULL)
- {
- topo_ctx = GNUNET_malloc(sizeof(struct TopologyIteratorContext));
- topo_ctx->cont = &do_get;
- topo_ctx->cls = all_gets;
- topo_ctx->timeout = DEFAULT_GET_TIMEOUT;
- topo_ctx->peers_seen
- = GNUNET_CONTAINER_multihashmap_create (num_peers);
- die_task
- = GNUNET_SCHEDULER_add_delayed (
- GNUNET_TIME_relative_add (
-
GNUNET_TIME_relative_add (
-
DEFAULT_GET_TIMEOUT,
-
all_get_timeout),
-
DEFAULT_TOPOLOGY_CAPTURE_TIMEOUT),
- &end_badly,
- "from do gets
(count_peers_churn_cb)");
- GNUNET_SCHEDULER_add_now (&capture_current_topology, topo_ctx);
- }
- else
- {
- die_task
- = GNUNET_SCHEDULER_add_delayed (
- GNUNET_TIME_relative_add (
-
GNUNET_TIME_relative_add (
-
DEFAULT_GET_TIMEOUT,
-
all_get_timeout),
-
DEFAULT_TOPOLOGY_CAPTURE_TIMEOUT),
- &end_badly,
- "from do gets
(count_peers_churn_cb)");
- GNUNET_SCHEDULER_add_now (&do_get, all_gets);
- }
- }
+ {
+ die_task
+ =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_add
+ (GNUNET_TIME_relative_add
+ (DEFAULT_GET_TIMEOUT,
+ all_get_timeout),
+ DEFAULT_TOPOLOGY_CAPTURE_TIMEOUT),
+ &end_badly,
+ "from do gets
(count_peers_churn_cb)");
+ GNUNET_SCHEDULER_add_now (&do_get, all_gets);
+ }
}
+ }
}
/**
@@ -1634,24 +1630,23 @@
* and the time allowed for each one!
*/
static void
-schedule_churn_find_peer_requests(
- void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *
tc)
+schedule_churn_find_peer_requests (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext
+ *tc)
{
struct FindPeerContext *find_peer_ctx = cls;
struct TestFindPeer *test_find_peer;
struct PeerCount *peer_count;
uint32_t i;
- if (find_peer_ctx->previous_peers == 0) /* First time, go slowly */
+ if (find_peer_ctx->previous_peers == 0) /* First time, go slowly */
find_peer_ctx->total = 1;
else if (find_peer_ctx->current_peers - find_peer_ctx->previous_peers
- < MIN_FIND_PEER_CUTOFF)
+ < MIN_FIND_PEER_CUTOFF)
find_peer_ctx->total = find_peer_ctx->total / 2;
- else if (find_peer_ctx->current_peers - find_peer_ctx->previous_peers
- > MAX_FIND_PEER_CUTOFF) /* Found LOTS of peers, still go slowly */
+ else if (find_peer_ctx->current_peers - find_peer_ctx->previous_peers >
MAX_FIND_PEER_CUTOFF) /* Found LOTS of peers, still go slowly */
find_peer_ctx->total = find_peer_ctx->last_sent - (find_peer_ctx->last_sent
- / 4);
+ / 4);
else
find_peer_ctx->total = find_peer_ctx->last_sent * 4;
@@ -1667,62 +1662,61 @@
find_peer_offset = GNUNET_TIME_relative_divide (find_peer_delay,
find_peer_ctx->total);
else
- {
- find_peer_ctx->previous_peers = find_peer_ctx->current_peers;
- find_peer_ctx->current_peers = 0;
- GNUNET_TESTING_get_topology (pg, &count_peers_churn_cb, find_peer_ctx);
- }
+ {
+ find_peer_ctx->previous_peers = find_peer_ctx->current_peers;
+ find_peer_ctx->current_peers = 0;
+ GNUNET_TESTING_get_topology (pg, &count_peers_churn_cb, find_peer_ctx);
+ }
for (i = 0; i < find_peer_ctx->total; i++)
- {
- test_find_peer = GNUNET_malloc(sizeof(struct TestFindPeer));
- /* If we have sent requests, choose peers with a low number of
connections to send requests from */
- peer_count
- = GNUNET_CONTAINER_heap_remove_root (find_peer_ctx->peer_min_heap);
- GNUNET_assert(peer_count != NULL);
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Sending find peer request from peer with %u connections\n",
- peer_count->count);
- GNUNET_CONTAINER_multihashmap_remove (find_peer_ctx->peer_hash,
- &peer_count->peer_id.hashPubKey,
- peer_count);
- test_find_peer->daemon
- = GNUNET_TESTING_daemon_get_by_id (pg, &peer_count->peer_id);
- GNUNET_assert(test_find_peer->daemon != NULL);
- test_find_peer->find_peer_context = find_peer_ctx;
- GNUNET_SCHEDULER_add_delayed (
- GNUNET_TIME_relative_multiply (
-
find_peer_offset,
- i),
- &send_find_peer_request, test_find_peer);
- }
+ {
+ test_find_peer = GNUNET_malloc (sizeof (struct TestFindPeer));
+ /* If we have sent requests, choose peers with a low number of connections
to send requests from */
+ peer_count
+ = GNUNET_CONTAINER_heap_remove_root (find_peer_ctx->peer_min_heap);
+ GNUNET_assert (peer_count != NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Sending find peer request from peer with %u connections\n",
+ peer_count->count);
+ GNUNET_CONTAINER_multihashmap_remove (find_peer_ctx->peer_hash,
+ &peer_count->peer_id.hashPubKey,
+ peer_count);
+ test_find_peer->daemon
+ = GNUNET_TESTING_daemon_get_by_id (pg, &peer_count->peer_id);
+ GNUNET_assert (test_find_peer->daemon != NULL);
+ test_find_peer->find_peer_context = find_peer_ctx;
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (find_peer_offset, i),
+ &send_find_peer_request, test_find_peer);
+ }
if ((find_peer_ctx->peer_hash == NULL) && (find_peer_ctx->peer_min_heap
- == NULL))
- {
- find_peer_ctx->peer_hash
- = GNUNET_CONTAINER_multihashmap_create (num_peers);
- find_peer_ctx->peer_min_heap
- = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
- }
+ == NULL))
+ {
+ find_peer_ctx->peer_hash = GNUNET_CONTAINER_multihashmap_create
(num_peers);
+ find_peer_ctx->peer_min_heap
+ = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
+ }
else
- {
- GNUNET_CONTAINER_multihashmap_iterate (find_peer_ctx->peer_hash,
- &remove_peer_count,
find_peer_ctx);
- GNUNET_CONTAINER_multihashmap_destroy (find_peer_ctx->peer_hash);
- find_peer_ctx->peer_hash
- = GNUNET_CONTAINER_multihashmap_create (num_peers);
- }
+ {
+ GNUNET_CONTAINER_multihashmap_iterate (find_peer_ctx->peer_hash,
+ &remove_peer_count, find_peer_ctx);
+ GNUNET_CONTAINER_multihashmap_destroy (find_peer_ctx->peer_hash);
+ find_peer_ctx->peer_hash = GNUNET_CONTAINER_multihashmap_create
(num_peers);
+ }
- GNUNET_assert(0 ==
GNUNET_CONTAINER_multihashmap_size(find_peer_ctx->peer_hash));
- GNUNET_assert(0 ==
GNUNET_CONTAINER_heap_get_size(find_peer_ctx->peer_min_heap));
+ GNUNET_assert (0 ==
+ GNUNET_CONTAINER_multihashmap_size
(find_peer_ctx->peer_hash));
+ GNUNET_assert (0 ==
+ GNUNET_CONTAINER_heap_get_size
(find_peer_ctx->peer_min_heap));
}
static void
-schedule_churn_get_topology(void *cls,
- const struct GNUNET_SCHEDULER_TaskContext * tc)
+schedule_churn_get_topology (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct FindPeerContext *find_peer_context = cls;
+
GNUNET_TESTING_get_topology (pg, &count_peers_churn_cb, find_peer_context);
}
@@ -1733,7 +1727,7 @@
* @param emsg NULL on success, or a printable error on failure
*/
static void
-churn_complete(void *cls, const char *emsg)
+churn_complete (void *cls, const char *emsg)
{
struct FindPeerContext *find_peer_context = cls;
struct PeerCount *peer_count;
@@ -1744,12 +1738,12 @@
int count_added;
if (emsg != NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Ending test, churning of peers failed with error `%s'",
emsg);
- GNUNET_SCHEDULER_add_now (&end_badly, (void *) emsg);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Ending test, churning of peers failed with error `%s'", emsg);
+ GNUNET_SCHEDULER_add_now (&end_badly, (void *) emsg);
+ return;
+ }
/**
* If we switched any peers on, we have to somehow force connect the new
peer to
@@ -1757,83 +1751,78 @@
* with no connections, then choose a random peer for each and connect them.
*/
if (find_peer_context != NULL)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "We have churned on some peers, so we must schedule find peer
requests for them!\n");
+ count_added = 0;
+ for (i = 0; i < num_peers; i++)
{
- GNUNET_log (
- GNUNET_ERROR_TYPE_WARNING,
- "We have churned on some peers, so we must schedule find
peer requests for them!\n");
- count_added = 0;
- for (i = 0; i < num_peers; i++)
- {
- temp_daemon = GNUNET_TESTING_daemon_get (pg, i);
- if (GNUNET_YES == GNUNET_TESTING_daemon_running (temp_daemon))
- {
- peer_count = GNUNET_malloc (sizeof(struct PeerCount));
- memcpy (&peer_count->peer_id, &temp_daemon->id,
- sizeof(struct GNUNET_PeerIdentity));
- GNUNET_assert(peer_count->count == 0);
- peer_count->heap_node
- = GNUNET_CONTAINER_heap_insert (
-
find_peer_context->peer_min_heap,
- peer_count,
peer_count->count);
- GNUNET_CONTAINER_multihashmap_put (find_peer_context->peer_hash,
- &temp_daemon->id.hashPubKey,
- peer_count,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
- count_added++;
- }
- }
- GNUNET_log (
- GNUNET_ERROR_TYPE_WARNING,
- "Added %d peers to heap, total size %d\n",
- count_added,
- GNUNET_CONTAINER_heap_get_size (
-
find_peer_context->peer_min_heap));
- GNUNET_SCHEDULER_add_delayed (DEFAULT_PEER_DISCONNECT_TIMEOUT,
- &schedule_churn_get_topology,
- find_peer_context);
+ temp_daemon = GNUNET_TESTING_daemon_get (pg, i);
+ if (GNUNET_YES == GNUNET_TESTING_daemon_running (temp_daemon))
+ {
+ peer_count = GNUNET_malloc (sizeof (struct PeerCount));
+ memcpy (&peer_count->peer_id, &temp_daemon->id,
+ sizeof (struct GNUNET_PeerIdentity));
+ GNUNET_assert (peer_count->count == 0);
+ peer_count->heap_node
+ = GNUNET_CONTAINER_heap_insert (find_peer_context->peer_min_heap,
+ peer_count, peer_count->count);
+ GNUNET_CONTAINER_multihashmap_put (find_peer_context->peer_hash,
+ &temp_daemon->id.hashPubKey,
+ peer_count,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+ count_added++;
+ }
}
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Added %d peers to heap, total size %d\n",
+ count_added,
+ GNUNET_CONTAINER_heap_get_size
+ (find_peer_context->peer_min_heap));
+ GNUNET_SCHEDULER_add_delayed (DEFAULT_PEER_DISCONNECT_TIMEOUT,
+ &schedule_churn_get_topology,
+ find_peer_context);
+ }
else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Only churned off peers, no find peer requests, scheduling
more gets (after allowing time for peers to disconnect properly!)...\n");
+ if (dhtlog_handle != NULL)
{
- GNUNET_log (
- GNUNET_ERROR_TYPE_WARNING,
- "Only churned off peers, no find peer requests, scheduling
more gets (after allowing time for peers to disconnect properly!)...\n");
- if (dhtlog_handle != NULL)
- {
- topo_ctx = GNUNET_malloc(sizeof(struct TopologyIteratorContext));
- topo_ctx->cont = &do_get;
- topo_ctx->cls = all_gets;
- topo_ctx->timeout = DEFAULT_GET_TIMEOUT;
- topo_ctx->peers_seen
- = GNUNET_CONTAINER_multihashmap_create (num_peers);
- calc_timeout = GNUNET_TIME_relative_add (DEFAULT_GET_TIMEOUT,
- all_get_timeout);
- calc_timeout
- = GNUNET_TIME_relative_add (calc_timeout,
- DEFAULT_TOPOLOGY_CAPTURE_TIMEOUT);
- calc_timeout
- = GNUNET_TIME_relative_add (calc_timeout,
- DEFAULT_PEER_DISCONNECT_TIMEOUT);
- die_task
- = GNUNET_SCHEDULER_add_delayed (calc_timeout, &end_badly,
- "from do gets (churn_complete)");
- GNUNET_SCHEDULER_add_delayed (DEFAULT_PEER_DISCONNECT_TIMEOUT,
- &capture_current_topology, topo_ctx);
- dhtlog_handle->insert_round (DHT_ROUND_GET, rounds_finished);
- }
- else
- {
- calc_timeout = GNUNET_TIME_relative_add (DEFAULT_GET_TIMEOUT,
- all_get_timeout);
- calc_timeout
- = GNUNET_TIME_relative_add (calc_timeout,
- DEFAULT_PEER_DISCONNECT_TIMEOUT);
- die_task
- = GNUNET_SCHEDULER_add_delayed (calc_timeout, &end_badly,
- "from do gets (churn_complete)");
- GNUNET_SCHEDULER_add_delayed (DEFAULT_PEER_DISCONNECT_TIMEOUT,
- &do_get, all_gets);
- }
+ topo_ctx = GNUNET_malloc (sizeof (struct TopologyIteratorContext));
+ topo_ctx->cont = &do_get;
+ topo_ctx->cls = all_gets;
+ topo_ctx->timeout = DEFAULT_GET_TIMEOUT;
+ topo_ctx->peers_seen = GNUNET_CONTAINER_multihashmap_create (num_peers);
+ calc_timeout = GNUNET_TIME_relative_add (DEFAULT_GET_TIMEOUT,
+ all_get_timeout);
+ calc_timeout
+ = GNUNET_TIME_relative_add (calc_timeout,
+ DEFAULT_TOPOLOGY_CAPTURE_TIMEOUT);
+ calc_timeout
+ = GNUNET_TIME_relative_add (calc_timeout,
+ DEFAULT_PEER_DISCONNECT_TIMEOUT);
+ die_task
+ = GNUNET_SCHEDULER_add_delayed (calc_timeout, &end_badly,
+ "from do gets (churn_complete)");
+ GNUNET_SCHEDULER_add_delayed (DEFAULT_PEER_DISCONNECT_TIMEOUT,
+ &capture_current_topology, topo_ctx);
+ dhtlog_handle->insert_round (DHT_ROUND_GET, rounds_finished);
}
+ else
+ {
+ calc_timeout = GNUNET_TIME_relative_add (DEFAULT_GET_TIMEOUT,
+ all_get_timeout);
+ calc_timeout
+ = GNUNET_TIME_relative_add (calc_timeout,
+ DEFAULT_PEER_DISCONNECT_TIMEOUT);
+ die_task
+ = GNUNET_SCHEDULER_add_delayed (calc_timeout, &end_badly,
+ "from do gets (churn_complete)");
+ GNUNET_SCHEDULER_add_delayed (DEFAULT_PEER_DISCONNECT_TIMEOUT,
+ &do_get, all_gets);
+ }
+ }
}
/**
@@ -1846,7 +1835,7 @@
* @param tc task context (unused)
*/
static void
-churn_peers(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
+churn_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
unsigned int count_running;
unsigned int churn_up;
@@ -1865,39 +1854,38 @@
"Not churning any peers, topology unchanged.\n");
if (churn_up > num_peers - count_running)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Churn file specified %u peers (up); only have %u!",
- churn_array[current_churn_round], num_peers);
- churn_up = num_peers - count_running;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Churn file specified %u peers (up); only have %u!",
+ churn_array[current_churn_round], num_peers);
+ churn_up = num_peers - count_running;
+ }
else if (churn_down > count_running)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Churn file specified %u peers (down); only have %u!",
- churn_array[current_churn_round], count_running);
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "This will leave NO peers running (mistake in churn
configuration?)!");
- churn_down = count_running;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Churn file specified %u peers (down); only have %u!",
+ churn_array[current_churn_round], count_running);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "This will leave NO peers running (mistake in churn
configuration?)!");
+ churn_down = count_running;
+ }
//timeout = GNUNET_TIME_relative_multiply(seconds_per_peer_start, churn_up >
0 ? churn_up : churn_down);
//timeout = GNUNET_TIME_relative_multiply (seconds_per_peer_start, churn_up
> 0 ? churn_up : churn_down);
timeout = GNUNET_TIME_relative_multiply (DEFAULT_TIMEOUT, 2); /* FIXME: Lack
of intelligent choice here */
find_peer_context = NULL;
- if (churn_up > 0) /* Only need to do find peer requests if we turned new
peers on */
- {
- find_peer_context = GNUNET_malloc(sizeof(struct FindPeerContext));
- find_peer_context->count_peers_cb = &count_peers_churn_cb;
- find_peer_context->previous_peers = 0;
- find_peer_context->current_peers = 0;
- find_peer_context->endtime = GNUNET_TIME_relative_to_absolute (timeout);
- find_peer_context->peer_hash
- = GNUNET_CONTAINER_multihashmap_create (num_peers);
- find_peer_context->peer_min_heap
- = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
- }
- GNUNET_log (
- GNUNET_ERROR_TYPE_WARNING,
+ if (churn_up > 0) /* Only need to do find peer requests if we
turned new peers on */
+ {
+ find_peer_context = GNUNET_malloc (sizeof (struct FindPeerContext));
+ find_peer_context->count_peers_cb = &count_peers_churn_cb;
+ find_peer_context->previous_peers = 0;
+ find_peer_context->current_peers = 0;
+ find_peer_context->endtime = GNUNET_TIME_relative_to_absolute (timeout);
+ find_peer_context->peer_hash
+ = GNUNET_CONTAINER_multihashmap_create (num_peers);
+ find_peer_context->peer_min_heap
+ = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"churn_peers: want %u total, %u running, starting %u, stopping
%u\n",
churn_array[current_churn_round], count_running, churn_up,
churn_down);
@@ -1910,147 +1898,135 @@
* Task to release DHT handle associated with GET request.
*/
static void
-get_stop_finished(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
+get_stop_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct TestGetContext *test_get = cls;
struct TopologyIteratorContext *topo_ctx;
/* The dht_handle may be null if this get was scheduled from a down peer */
if (test_get->dht_handle != NULL)
- {
- GNUNET_DHT_disconnect (test_get->dht_handle);
- outstanding_gets--; /* GET is really finished */
- test_get->dht_handle = NULL;
- }
+ {
+ GNUNET_DHT_disconnect (test_get->dht_handle);
+ outstanding_gets--; /* GET is really finished */
+ test_get->dht_handle = NULL;
+ }
/* Reset the uid (which item to search for) and the daemon (which peer to
search from) for later get request iterations */
if (get_from_same == GNUNET_NO)
- {
- test_get->uid = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
- num_puts);
- test_get->daemon
- = GNUNET_TESTING_daemon_get (
- pg,
- GNUNET_CRYPTO_random_u32 (
-
GNUNET_CRYPTO_QUALITY_WEAK,
- num_peers));
- }
+ {
+ test_get->uid = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
+ num_puts);
+ test_get->daemon
+ = GNUNET_TESTING_daemon_get (pg,
+ GNUNET_CRYPTO_random_u32
+ (GNUNET_CRYPTO_QUALITY_WEAK, num_peers));
+ }
#if VERBOSE > 1
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%d gets succeeded, %d gets failed!\n",
gets_completed, gets_failed);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%d gets succeeded, %d gets failed!\n",
+ gets_completed, gets_failed);
#endif
update_meter (get_meter);
if ((gets_completed + gets_failed == num_gets) && (outstanding_gets == 0))
- {
- fprintf (
- stderr,
- "Canceling die task (get_stop_finished) %llu gets completed,
%llu gets failed\n",
- gets_completed, gets_failed);
- if ((GNUNET_YES == dhtlog_minimal) && (NULL != dhtlog_handle))
- dhtlog_handle->insert_round_details (DHT_ROUND_GET, rounds_finished,
- num_gets, gets_completed);
- GNUNET_SCHEDULER_cancel (die_task);
- reset_meter (put_meter);
- reset_meter (get_meter);
- if ((target_completions > 0)
- && (gets_completed > target_completions))
- fprintf(stderr, "Ending test early due to GET success!\n");
+ {
+ fprintf (stderr,
+ "Canceling die task (get_stop_finished) %llu gets completed, %llu
gets failed\n",
+ gets_completed, gets_failed);
+ if ((GNUNET_YES == dhtlog_minimal) && (NULL != dhtlog_handle))
+ dhtlog_handle->insert_round_details (DHT_ROUND_GET, rounds_finished,
+ num_gets, gets_completed);
+ GNUNET_SCHEDULER_cancel (die_task);
+ reset_meter (put_meter);
+ reset_meter (get_meter);
+ if ((target_completions > 0) && (gets_completed > target_completions))
+ fprintf (stderr, "Ending test early due to GET success!\n");
/**
* Handle all cases:
* 1) Testing is completely finished, call the topology iteration
dealy and die
* 2) Testing is not finished, churn the network and do gets again
(current_churn_round < churn_rounds)
* 3) Testing is not finished, reschedule all the PUTS *and* GETS
again (num_rounds > 1)
*/
- if ((rounds_finished == total_rounds - 1) || ((target_completions > 0)
- && (gets_completed > target_completions))) /* Everything is
finished, end testing */
- {
- if ((dhtlog_handle != NULL) && (GNUNET_NO == dhtlog_minimal))
- {
- topo_ctx = GNUNET_malloc(sizeof(struct TopologyIteratorContext));
- topo_ctx->cont = &log_dht_statistics;
- topo_ctx->peers_seen
- = GNUNET_CONTAINER_multihashmap_create (num_peers);
- GNUNET_SCHEDULER_add_now (&capture_current_topology, topo_ctx);
- }
- else
- GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
- }
- else if (current_churn_round < churns_per_round * (rounds_finished + 1))
/* Do next round of churn */
- {
- GNUNET_log (
- GNUNET_ERROR_TYPE_WARNING,
- "Current churn round %u, real round %u, scheduling next
round of churn.\n",
- current_churn_round, rounds_finished + 1);
- gets_completed = 0;
- gets_failed = 0;
+ if ((rounds_finished == total_rounds - 1) || ((target_completions > 0) &&
(gets_completed > target_completions))) /* Everything is finished, end
testing */
+ {
+ if ((dhtlog_handle != NULL) && (GNUNET_NO == dhtlog_minimal))
+ {
+ topo_ctx = GNUNET_malloc (sizeof (struct TopologyIteratorContext));
+ topo_ctx->cont = &log_dht_statistics;
+ topo_ctx->peers_seen = GNUNET_CONTAINER_multihashmap_create
(num_peers);
+ GNUNET_SCHEDULER_add_now (&capture_current_topology, topo_ctx);
+ }
+ else
+ GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
+ }
+ else if (current_churn_round < churns_per_round * (rounds_finished + 1))
/* Do next round of churn */
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Current churn round %u, real round %u, scheduling next
round of churn.\n",
+ current_churn_round, rounds_finished + 1);
+ gets_completed = 0;
+ gets_failed = 0;
- if (dhtlog_handle != NULL)
- dhtlog_handle->insert_round (DHT_ROUND_CHURN, rounds_finished);
+ if (dhtlog_handle != NULL)
+ dhtlog_handle->insert_round (DHT_ROUND_CHURN, rounds_finished);
- GNUNET_SCHEDULER_add_now (&churn_peers, NULL);
- }
- else if (rounds_finished < total_rounds - 1) /* Start a new complete
round */
- {
- rounds_finished++;
- gets_completed = 0;
- gets_failed = 0;
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Round %u of %llu finished, scheduling next round.\n",
- rounds_finished, total_rounds);
+ GNUNET_SCHEDULER_add_now (&churn_peers, NULL);
+ }
+ else if (rounds_finished < total_rounds - 1) /* Start a new
complete round */
+ {
+ rounds_finished++;
+ gets_completed = 0;
+ gets_failed = 0;
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Round %u of %llu finished, scheduling next round.\n",
+ rounds_finished, total_rounds);
/** We reset the peer daemon for puts and gets on each disconnect,
so all we need to do is start another round! */
- if (GNUNET_YES == in_dht_replication) /* Replication done in DHT,
don't redo puts! */
- {
- if (dhtlog_handle != NULL)
- dhtlog_handle->insert_round (DHT_ROUND_GET, rounds_finished);
+ if (GNUNET_YES == in_dht_replication) /* Replication done in DHT,
don't redo puts! */
+ {
+ if (dhtlog_handle != NULL)
+ dhtlog_handle->insert_round (DHT_ROUND_GET, rounds_finished);
- die_task
- = GNUNET_SCHEDULER_add_delayed (
- GNUNET_TIME_relative_add (
-
GNUNET_TIME_relative_add (
-
GNUNET_TIME_relative_multiply (
-
GNUNET_TIME_UNIT_SECONDS,
-
round_delay),
-
all_get_timeout),
-
DEFAULT_TOPOLOGY_CAPTURE_TIMEOUT),
- &end_badly,
- "from do gets (next round)");
- GNUNET_SCHEDULER_add_delayed (
- GNUNET_TIME_relative_multiply (
-
GNUNET_TIME_UNIT_SECONDS,
-
round_delay),
- &do_get, all_gets);
- }
- else
- {
- if (dhtlog_handle != NULL)
- dhtlog_handle->insert_round (DHT_ROUND_NORMAL,
rounds_finished);
- die_task
- = GNUNET_SCHEDULER_add_delayed (
- GNUNET_TIME_relative_add (
-
GNUNET_TIME_relative_multiply (
-
GNUNET_TIME_UNIT_SECONDS,
-
round_delay),
-
GNUNET_TIME_relative_multiply (
-
GNUNET_TIME_UNIT_SECONDS,
-
num_puts
-
* 2)),
- &end_badly, "from do puts");
- GNUNET_SCHEDULER_add_delayed (
- GNUNET_TIME_relative_multiply (
-
GNUNET_TIME_UNIT_SECONDS,
-
round_delay),
- &do_put, all_puts);
- }
- }
+ die_task
+ =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_add
+ (GNUNET_TIME_relative_add
+ (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS,
+ round_delay), all_get_timeout),
+ DEFAULT_TOPOLOGY_CAPTURE_TIMEOUT),
+ &end_badly,
+ "from do gets (next round)");
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, round_delay),
+ &do_get, all_gets);
+ }
+ else
+ {
+ if (dhtlog_handle != NULL)
+ dhtlog_handle->insert_round (DHT_ROUND_NORMAL, rounds_finished);
+ die_task
+ =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_add
+ (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS,
+ round_delay),
+ GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS,
+ num_puts * 2)), &end_badly,
+ "from do puts");
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, round_delay),
+ &do_put, all_puts);
+ }
}
+ }
}
/**
* Task to release get handle.
*/
static void
-get_stop_task(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
+get_stop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct TestGetContext *test_get = cls;
@@ -2059,7 +2035,7 @@
else
cumulative_successful_gets++;
- GNUNET_assert(test_get->get_handle != NULL);
+ GNUNET_assert (test_get->get_handle != NULL);
GNUNET_DHT_get_stop (test_get->get_handle);
test_get->get_handle = NULL;
test_get->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
@@ -2081,28 +2057,28 @@
* @param data pointer to the result data
*/
static void
-get_result_iterator(void *cls, struct GNUNET_TIME_Absolute exp,
- const GNUNET_HashCode * key,
- const struct GNUNET_PeerIdentity * const *get_path,
- const struct GNUNET_PeerIdentity * const *put_path,
- enum GNUNET_BLOCK_Type type, size_t size, const void *data)
+get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
+ const GNUNET_HashCode * key,
+ const struct GNUNET_PeerIdentity *const *get_path,
+ const struct GNUNET_PeerIdentity *const *put_path,
+ enum GNUNET_BLOCK_Type type, size_t size, const void
*data)
{
struct TestGetContext *test_get = cls;
if (test_get->succeeded == GNUNET_YES)
- return; /* Get has already been successful, probably ending now */
+ return; /* Get has already been successful, probably
ending now */
- if (0 != memcmp (&known_keys[test_get->uid], key, sizeof(GNUNET_HashCode)))
/* || (0 != memcmp(original_data, data, sizeof(original_data))))*/
- {
- gets_completed++;
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Key or data is not the same as was inserted!\n");
- }
+ if (0 != memcmp (&known_keys[test_get->uid], key, sizeof (GNUNET_HashCode)))
/* || (0 != memcmp(original_data, data, sizeof(original_data)))) */
+ {
+ gets_completed++;
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Key or data is not the same as was inserted!\n");
+ }
else
- {
- gets_completed++;
- test_get->succeeded = GNUNET_YES;
- }
+ {
+ gets_completed++;
+ test_get->succeeded = GNUNET_YES;
+ }
#if VERBOSE > 1
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct GET response!\n");
#endif
@@ -2115,46 +2091,44 @@
* Set up some data, and call API PUT function
*/
static void
-do_get(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
+do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct TestGetContext *test_get = cls;
if (num_gets == 0)
- {
- GNUNET_SCHEDULER_cancel (die_task);
- GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
- }
+ {
+ GNUNET_SCHEDULER_cancel (die_task);
+ GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
+ }
if (test_get == NULL)
- return; /* End of the list */
+ return; /* End of the list */
/* Set this here in case we are re-running gets */
test_get->succeeded = GNUNET_NO;
- if (GNUNET_YES != GNUNET_TESTING_daemon_running (test_get->daemon)) /* If
the peer has been churned off, don't try issuing request from it! */
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peer we should issue get request from is down,
skipping.\n");
- gets_failed++;
- GNUNET_SCHEDULER_add_now (&get_stop_finished, test_get);
- GNUNET_SCHEDULER_add_now (&do_get, test_get->next);
- return;
- }
+ if (GNUNET_YES != GNUNET_TESTING_daemon_running (test_get->daemon)) /* If
the peer has been churned off, don't try issuing request from it! */
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Peer we should issue get request from is down, skipping.\n");
+ gets_failed++;
+ GNUNET_SCHEDULER_add_now (&get_stop_finished, test_get);
+ GNUNET_SCHEDULER_add_now (&do_get, test_get->next);
+ return;
+ }
/* Check if more gets are outstanding than should be */
if (outstanding_gets > max_outstanding_gets)
- {
- GNUNET_SCHEDULER_add_delayed (
- GNUNET_TIME_relative_multiply (
-
GNUNET_TIME_UNIT_MILLISECONDS,
- 200),
- &do_get, test_get);
- return;
- }
+ {
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MILLISECONDS, 200),
&do_get,
+ test_get);
+ return;
+ }
/* Connect to the first peer's DHT */
test_get->dht_handle = GNUNET_DHT_connect (test_get->daemon->cfg, 10);
- GNUNET_assert(test_get->dht_handle != NULL);
+ GNUNET_assert (test_get->dht_handle != NULL);
outstanding_gets++;
cumulative_num_gets++;
@@ -2169,8 +2143,7 @@
#if VERBOSE > 1
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting get for uid %u from peer
%s\n",
- test_get->uid,
- test_get->daemon->shortname);
+ test_get->uid, test_get->daemon->shortname);
#endif
test_get->disconnect_task = GNUNET_SCHEDULER_add_delayed (get_timeout,
&get_stop_task,
@@ -2185,10 +2158,11 @@
* Schedule the GET request for some time in the future.
*/
static void
-put_finished(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
+put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct TestPutContext *test_put = cls;
struct TopologyIteratorContext *topo_ctx;
+
outstanding_puts--;
puts_completed++;
@@ -2198,125 +2172,115 @@
/* Reset the daemon (which peer to insert at) for later put request
iterations */
if (replicate_same == GNUNET_NO)
test_put->daemon
- = GNUNET_TESTING_daemon_get (
- pg,
- GNUNET_CRYPTO_random_u32 (
-
GNUNET_CRYPTO_QUALITY_WEAK,
- num_peers));
+ = GNUNET_TESTING_daemon_get (pg,
+ GNUNET_CRYPTO_random_u32
+ (GNUNET_CRYPTO_QUALITY_WEAK, num_peers));
GNUNET_SCHEDULER_cancel (test_put->disconnect_task);
test_put->disconnect_task = GNUNET_SCHEDULER_add_now (&put_disconnect_task,
test_put);
if (GNUNET_YES == update_meter (put_meter))
+ {
+ GNUNET_assert (outstanding_puts == 0);
+ GNUNET_SCHEDULER_cancel (die_task);
+ if ((dhtlog_handle != NULL) && (GNUNET_NO == dhtlog_minimal))
{
- GNUNET_assert(outstanding_puts == 0);
- GNUNET_SCHEDULER_cancel (die_task);
- if ((dhtlog_handle != NULL) && (GNUNET_NO == dhtlog_minimal))
- {
- topo_ctx = GNUNET_malloc(sizeof(struct TopologyIteratorContext));
- topo_ctx->cont = &do_get;
- topo_ctx->cls = all_gets;
- topo_ctx->timeout = DEFAULT_GET_TIMEOUT;
- topo_ctx->peers_seen
- = GNUNET_CONTAINER_multihashmap_create (num_peers);
- die_task
- = GNUNET_SCHEDULER_add_delayed (
- GNUNET_TIME_relative_add (
-
GNUNET_TIME_relative_add (
-
DEFAULT_GET_TIMEOUT,
-
all_get_timeout),
-
DEFAULT_TOPOLOGY_CAPTURE_TIMEOUT),
- &end_badly,
- "from do gets (put finished)");
- GNUNET_SCHEDULER_add_now (&capture_current_topology, topo_ctx);
- }
- else
- {
- fprintf (stderr, "Scheduling die task (put finished)\n");
- die_task
- = GNUNET_SCHEDULER_add_delayed (
- GNUNET_TIME_relative_add (
-
DEFAULT_GET_TIMEOUT,
-
all_get_timeout),
- &end_badly,
- "from do gets (put finished)");
- GNUNET_SCHEDULER_add_delayed (DEFAULT_GET_TIMEOUT, &do_get,
all_gets);
- }
- return;
+ topo_ctx = GNUNET_malloc (sizeof (struct TopologyIteratorContext));
+ topo_ctx->cont = &do_get;
+ topo_ctx->cls = all_gets;
+ topo_ctx->timeout = DEFAULT_GET_TIMEOUT;
+ topo_ctx->peers_seen = GNUNET_CONTAINER_multihashmap_create (num_peers);
+ die_task
+ =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_add
+ (GNUNET_TIME_relative_add
+ (DEFAULT_GET_TIMEOUT,
all_get_timeout),
+ DEFAULT_TOPOLOGY_CAPTURE_TIMEOUT),
+ &end_badly,
+ "from do gets (put finished)");
+ GNUNET_SCHEDULER_add_now (&capture_current_topology, topo_ctx);
}
+ else
+ {
+ fprintf (stderr, "Scheduling die task (put finished)\n");
+ die_task
+ =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_add
+ (DEFAULT_GET_TIMEOUT, all_get_timeout),
+ &end_badly,
+ "from do gets (put finished)");
+ GNUNET_SCHEDULER_add_delayed (DEFAULT_GET_TIMEOUT, &do_get, all_gets);
+ }
+ return;
+ }
}
/**
* Set up some data, and call API PUT function
*/
static void
-do_put(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
+do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct TestPutContext *test_put = cls;
- char data[test_data_size]; /* Made up data to store */
+ char data[test_data_size]; /* Made up data to store */
uint32_t rand;
int i;
if (test_put == NULL)
- return; /* End of list */
+ return; /* End of list */
- if (GNUNET_YES != GNUNET_TESTING_daemon_running (test_put->daemon)) /* If
the peer has been churned off, don't try issuing request from it! */
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peer we should issue put request at is down, skipping.\n");
- update_meter (put_meter);
- GNUNET_SCHEDULER_add_now (&do_put, test_put->next);
- return;
- }
+ if (GNUNET_YES != GNUNET_TESTING_daemon_running (test_put->daemon)) /* If
the peer has been churned off, don't try issuing request from it! */
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Peer we should issue put request at is down, skipping.\n");
+ update_meter (put_meter);
+ GNUNET_SCHEDULER_add_now (&do_put, test_put->next);
+ return;
+ }
- for (i = 0; i < sizeof(data); i++)
- {
- memset (&data[i], GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
- UINT32_MAX), 1);
- }
+ for (i = 0; i < sizeof (data); i++)
+ {
+ memset (&data[i], GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
+ UINT32_MAX), 1);
+ }
if (outstanding_puts > max_outstanding_puts)
- {
- GNUNET_SCHEDULER_add_delayed (
- GNUNET_TIME_relative_multiply (
-
GNUNET_TIME_UNIT_MILLISECONDS,
- 200),
- &do_put, test_put);
- return;
- }
+ {
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MILLISECONDS, 200),
&do_put,
+ test_put);
+ return;
+ }
#if VERBOSE > 1
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting put for uid %u from peer
%s\n",
- test_put->uid,
- test_put->daemon->shortname);
+ test_put->uid, test_put->daemon->shortname);
#endif
test_put->dht_handle = GNUNET_DHT_connect (test_put->daemon->cfg, 10);
- GNUNET_assert(test_put->dht_handle != NULL);
+ GNUNET_assert (test_put->dht_handle != NULL);
outstanding_puts++;
GNUNET_DHT_put (test_put->dht_handle, &known_keys[test_put->uid],
put_replication, GNUNET_DHT_RO_NONE, GNUNET_BLOCK_TYPE_TEST,
- sizeof(data), data, GNUNET_TIME_UNIT_FOREVER_ABS, put_delay,
+ sizeof (data), data, GNUNET_TIME_UNIT_FOREVER_ABS, put_delay,
&put_finished, test_put);
test_put->disconnect_task
= GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_get_forever (),
&put_disconnect_task, test_put);
rand = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 2);
- GNUNET_SCHEDULER_add_delayed (
- GNUNET_TIME_relative_multiply (
-
GNUNET_TIME_UNIT_SECONDS,
- rand), &do_put,
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, rand), &do_put,
test_put->next);
}
static void
-schedule_find_peer_requests(void *cls,
- const struct GNUNET_SCHEDULER_TaskContext * tc);
+schedule_find_peer_requests (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc);
#if HAVE_MALICIOUS
static void
-setup_malicious_peers(void *cls,
- const struct GNUNET_SCHEDULER_TaskContext * tc);
+setup_malicious_peers (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc);
#endif
/**
@@ -2324,19 +2288,20 @@
* connections in a perfect kademlia topology.
*/
static unsigned int
-connection_estimate(unsigned int peer_count, unsigned int bucket_size)
+connection_estimate (unsigned int peer_count, unsigned int bucket_size)
{
unsigned int i;
unsigned int filled;
+
i = num_peers;
filled = 0;
while (i >= bucket_size)
- {
- filled++;
- i = i / 2;
- }
- filled++; /* Add one filled bucket to account for one "half full" and some
miscellaneous */
+ {
+ filled++;
+ i = i / 2;
+ }
+ filled++; /* Add one filled bucket to account for one
"half full" and some miscellaneous */
return filled * bucket_size * peer_count;
}
@@ -2345,56 +2310,57 @@
* Callback for iterating over all the peer connections of a peer group.
*/
static void
-count_peers_cb(void *cls, const struct GNUNET_PeerIdentity *first,
- const struct GNUNET_PeerIdentity *second, const char *emsg)
+count_peers_cb (void *cls, const struct GNUNET_PeerIdentity *first,
+ const struct GNUNET_PeerIdentity *second, const char *emsg)
{
struct FindPeerContext *find_peer_context = cls;
+
if ((first != NULL) && (second != NULL))
+ {
+ add_new_connection (find_peer_context, first, second);
+ find_peer_context->current_peers++;
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Peer count finished (%u connections), %u new peers,
connection estimate %u (target %u)\n",
+ find_peer_context->current_peers,
+ find_peer_context->current_peers
+ - find_peer_context->previous_peers,
+ connection_estimate (num_peers, DEFAULT_BUCKET_SIZE),
+ target_total_connections);
+
+ if ((find_peer_context->last_sent < 8)
+ || ((find_peer_context->current_peers < 2
+ * connection_estimate (num_peers, DEFAULT_BUCKET_SIZE))
+ &&
+ (GNUNET_TIME_absolute_get_remaining
+ (find_peer_context->endtime).rel_value > 0) &&
+ (find_peer_context->current_peers < target_total_connections)))
{
- add_new_connection (find_peer_context, first, second);
- find_peer_context->current_peers++;
+ GNUNET_SCHEDULER_add_now (&schedule_find_peer_requests,
+ find_peer_context);
}
- else
+ else
{
- GNUNET_log (
- GNUNET_ERROR_TYPE_WARNING,
- "Peer count finished (%u connections), %u new peers,
connection estimate %u (target %u)\n",
- find_peer_context->current_peers,
- find_peer_context->current_peers
- - find_peer_context->previous_peers,
- connection_estimate (num_peers, DEFAULT_BUCKET_SIZE),
- target_total_connections);
+ GNUNET_CONTAINER_multihashmap_iterate (find_peer_context->peer_hash,
+ &remove_peer_count,
+ find_peer_context);
+ GNUNET_CONTAINER_multihashmap_destroy (find_peer_context->peer_hash);
+ GNUNET_CONTAINER_heap_destroy (find_peer_context->peer_min_heap);
+ GNUNET_free (find_peer_context);
+ fprintf (stderr, "Not sending any more find peer requests.\n");
- if ((find_peer_context->last_sent < 8)
- || ((find_peer_context->current_peers < 2
- * connection_estimate (num_peers, DEFAULT_BUCKET_SIZE))
- && (GNUNET_TIME_absolute_get_remaining (
-
find_peer_context->endtime).rel_value
- > 0) && (find_peer_context->current_peers
- < target_total_connections)))
- {
- GNUNET_SCHEDULER_add_now (&schedule_find_peer_requests,
- find_peer_context);
- }
- else
- {
- GNUNET_CONTAINER_multihashmap_iterate (find_peer_context->peer_hash,
- &remove_peer_count,
- find_peer_context);
- GNUNET_CONTAINER_multihashmap_destroy (find_peer_context->peer_hash);
- GNUNET_CONTAINER_heap_destroy (find_peer_context->peer_min_heap);
- GNUNET_free(find_peer_context);
- fprintf (stderr, "Not sending any more find peer requests.\n");
-
#if HAVE_MALICIOUS
- if (GNUNET_YES == malicious_after_settle)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "calling
setup_malicious_peers\n");
- GNUNET_SCHEDULER_add_now(&setup_malicious_peers, NULL);
- }
+ if (GNUNET_YES == malicious_after_settle)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "calling setup_malicious_peers\n");
+ GNUNET_SCHEDULER_add_now (&setup_malicious_peers, NULL);
+ }
#endif
- }
}
+ }
}
/**
@@ -2403,8 +2369,8 @@
* and the time allowed for each one!
*/
static void
-schedule_find_peer_requests(void *cls,
- const struct GNUNET_SCHEDULER_TaskContext * tc)
+schedule_find_peer_requests (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct FindPeerContext *find_peer_ctx = cls;
struct TestFindPeer *test_find_peer;
@@ -2412,12 +2378,11 @@
uint32_t i;
uint32_t random;
- if (find_peer_ctx->previous_peers == 0) /* First time, go slowly */
+ if (find_peer_ctx->previous_peers == 0) /* First time, go slowly */
find_peer_ctx->total = 1;
- else if (find_peer_ctx->current_peers - find_peer_ctx->previous_peers
- > MAX_FIND_PEER_CUTOFF) /* Found LOTS of peers, still go slowly */
+ else if (find_peer_ctx->current_peers - find_peer_ctx->previous_peers >
MAX_FIND_PEER_CUTOFF) /* Found LOTS of peers, still go slowly */
find_peer_ctx->total = find_peer_ctx->last_sent - (find_peer_ctx->last_sent
- / 8);
+ / 8);
else
find_peer_ctx->total = find_peer_ctx->last_sent * 2;
@@ -2435,15 +2400,15 @@
find_peer_offset = GNUNET_TIME_relative_divide (find_peer_delay,
find_peer_ctx->total);
for (i = 0; i < find_peer_ctx->total; i++)
+ {
+ test_find_peer = GNUNET_malloc (sizeof (struct TestFindPeer));
+ /* If we haven't sent any requests yet, choose random peers */
+ /* Also choose random in _half_ of all cases, so we don't
+ * get stuck choosing topologically restricted peers with
+ * few connections that will never be able to find any new
+ * peers! */
+ if ((find_peer_ctx->previous_peers == 0) || (i % 2 == 0))
{
- test_find_peer = GNUNET_malloc(sizeof(struct TestFindPeer));
- /* If we haven't sent any requests yet, choose random peers */
- /* Also choose random in _half_ of all cases, so we don't
- * get stuck choosing topologically restricted peers with
- * few connections that will never be able to find any new
- * peers! */
- if ((find_peer_ctx->previous_peers == 0) || (i % 2 == 0))
- {
/**
* Attempt to spread find peer requests across even sections of the
peer address
* space. Choose basically 1 peer in every num_peers /
max_outstanding_requests
@@ -2452,56 +2417,57 @@
* For instance, if num_peers is 100 and max_outstanding is 10,
first chosen peer
* will be between 0 - 10, second between 10 - 20, etc.
*/
- random = (num_peers / find_peer_ctx->total) * i;
- random = random
- + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
- (num_peers / find_peer_ctx->total));
- if (random >= num_peers)
- {
- random = random - num_peers;
- }
+ random = (num_peers / find_peer_ctx->total) * i;
+ random = random
+ + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
+ (num_peers / find_peer_ctx->total));
+ if (random >= num_peers)
+ {
+ random = random - num_peers;
+ }
#if REAL_RANDOM
- random = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK,
num_peers);
+ random = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
num_peers);
#endif
- test_find_peer->daemon = GNUNET_TESTING_daemon_get (pg, random);
- }
- else /* If we have sent requests, choose peers with a low number of
connections to send requests from */
- {
- peer_count
- = GNUNET_CONTAINER_heap_remove_root
(find_peer_ctx->peer_min_heap);
- GNUNET_assert(GNUNET_YES ==
GNUNET_CONTAINER_multihashmap_remove(find_peer_ctx->peer_hash,
&peer_count->peer_id.hashPubKey, peer_count));
- test_find_peer->daemon
- = GNUNET_TESTING_daemon_get_by_id (pg, &peer_count->peer_id);
- GNUNET_assert(test_find_peer->daemon != NULL);
- }
-
- test_find_peer->find_peer_context = find_peer_ctx;
- GNUNET_SCHEDULER_add_delayed (
- GNUNET_TIME_relative_multiply (
-
find_peer_offset,
- i),
- &send_find_peer_request, test_find_peer);
+ test_find_peer->daemon = GNUNET_TESTING_daemon_get (pg, random);
}
-
- if ((find_peer_ctx->peer_hash == NULL) && (find_peer_ctx->peer_min_heap
- == NULL))
+ else /* If we have sent requests, choose peers with
a low number of connections to send requests from */
{
- find_peer_ctx->peer_hash
- = GNUNET_CONTAINER_multihashmap_create (num_peers);
- find_peer_ctx->peer_min_heap
- = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
+ peer_count
+ = GNUNET_CONTAINER_heap_remove_root (find_peer_ctx->peer_min_heap);
+ GNUNET_assert (GNUNET_YES ==
+ GNUNET_CONTAINER_multihashmap_remove
+ (find_peer_ctx->peer_hash,
&peer_count->peer_id.hashPubKey,
+ peer_count));
+ test_find_peer->daemon =
+ GNUNET_TESTING_daemon_get_by_id (pg, &peer_count->peer_id);
+ GNUNET_assert (test_find_peer->daemon != NULL);
}
+
+ test_find_peer->find_peer_context = find_peer_ctx;
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (find_peer_offset, i),
+ &send_find_peer_request, test_find_peer);
+ }
+
+ if ((find_peer_ctx->peer_hash == NULL) && (find_peer_ctx->peer_min_heap
+ == NULL))
+ {
+ find_peer_ctx->peer_hash = GNUNET_CONTAINER_multihashmap_create
(num_peers);
+ find_peer_ctx->peer_min_heap
+ = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
+ }
else
- {
- GNUNET_CONTAINER_multihashmap_iterate (find_peer_ctx->peer_hash,
- &remove_peer_count,
find_peer_ctx);
- GNUNET_CONTAINER_multihashmap_destroy (find_peer_ctx->peer_hash);
- find_peer_ctx->peer_hash
- = GNUNET_CONTAINER_multihashmap_create (num_peers);
- }
+ {
+ GNUNET_CONTAINER_multihashmap_iterate (find_peer_ctx->peer_hash,
+ &remove_peer_count, find_peer_ctx);
+ GNUNET_CONTAINER_multihashmap_destroy (find_peer_ctx->peer_hash);
+ find_peer_ctx->peer_hash = GNUNET_CONTAINER_multihashmap_create
(num_peers);
+ }
- GNUNET_assert(0 ==
GNUNET_CONTAINER_multihashmap_size(find_peer_ctx->peer_hash));
- GNUNET_assert(0 ==
GNUNET_CONTAINER_heap_get_size(find_peer_ctx->peer_min_heap));
+ GNUNET_assert (0 ==
+ GNUNET_CONTAINER_multihashmap_size
(find_peer_ctx->peer_hash));
+ GNUNET_assert (0 ==
+ GNUNET_CONTAINER_heap_get_size
(find_peer_ctx->peer_min_heap));
}
@@ -2512,9 +2478,9 @@
* @param hash set to uid (extended with zeros)
*/
static void
-hash_from_uid(uint32_t uid, GNUNET_HashCode *hash)
+hash_from_uid (uint32_t uid, GNUNET_HashCode * hash)
{
- memset (hash, 0, sizeof(GNUNET_HashCode));
+ memset (hash, 0, sizeof (GNUNET_HashCode));
*((uint32_t *) hash) = uid;
}
@@ -2524,7 +2490,7 @@
* add to list, then schedule the actual PUT operations.
*/
static void
-setup_puts_and_gets(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
+setup_puts_and_gets (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
int i;
struct TestPutContext *test_put;
@@ -2532,98 +2498,99 @@
uint32_t temp_peer;
GNUNET_HashCode uid_hash;
int count;
+
#if REMEMBER
int remember[num_puts][num_peers];
- memset(&remember, 0, sizeof(int) * num_puts * num_peers);
+
+ memset (&remember, 0, sizeof (int) * num_puts * num_peers);
#endif
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "in setup_puts_and_gets\n");
- known_keys = GNUNET_malloc(sizeof(GNUNET_HashCode) * num_puts);
+ known_keys = GNUNET_malloc (sizeof (GNUNET_HashCode) * num_puts);
for (i = 0; i < num_puts; i++)
+ {
+ test_put = GNUNET_malloc (sizeof (struct TestPutContext));
+ test_put->uid = i;
+ GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
+ &known_keys[i]);
+ /* Set first X bits to match the chosen sybil location if we want to do
the sybil attack! */
+ if (GNUNET_YES == malicious_sybil)
{
- test_put = GNUNET_malloc(sizeof(struct TestPutContext));
- test_put->uid = i;
- GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
- &known_keys[i]);
- /* Set first X bits to match the chosen sybil location if we want to do
the sybil attack! */
- if (GNUNET_YES == malicious_sybil)
- {
- memcpy (&known_keys[i], &sybil_target, sizeof(GNUNET_HashCode) / 2);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Distance between sybil location and key is %d\n",
- GNUNET_CRYPTO_hash_matching_bits (&known_keys[i],
- &sybil_target));
- }
- temp_peer = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
- num_peers);
- test_put->daemon = GNUNET_TESTING_daemon_get (pg, temp_peer);
- /* Don't start PUTs at malicious peers! */
- if (malicious_bloom != NULL)
- {
- count = 0;
- hash_from_uid (temp_peer, &uid_hash);
- while ((GNUNET_YES
+ memcpy (&known_keys[i], &sybil_target, sizeof (GNUNET_HashCode) / 2);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Distance between sybil location and key is %d\n",
+ GNUNET_CRYPTO_hash_matching_bits (&known_keys[i],
+ &sybil_target));
+ }
+ temp_peer = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
+ num_peers);
+ test_put->daemon = GNUNET_TESTING_daemon_get (pg, temp_peer);
+ /* Don't start PUTs at malicious peers! */
+ if (malicious_bloom != NULL)
+ {
+ count = 0;
+ hash_from_uid (temp_peer, &uid_hash);
+ while ((GNUNET_YES
== GNUNET_CONTAINER_bloomfilter_test (malicious_bloom,
&uid_hash))
- && (count < num_peers))
- {
- temp_peer = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
- num_peers);
- hash_from_uid (temp_peer, &uid_hash);
- test_put->daemon = GNUNET_TESTING_daemon_get (pg, temp_peer);
- count++;
- }
- if (count == num_peers)
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Couldn't find peer not in malicious bloom to
select!\n");
- }
-
- test_put->next = all_puts;
- all_puts = test_put;
+ && (count < num_peers))
+ {
+ temp_peer = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
+ num_peers);
+ hash_from_uid (temp_peer, &uid_hash);
+ test_put->daemon = GNUNET_TESTING_daemon_get (pg, temp_peer);
+ count++;
+ }
+ if (count == num_peers)
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Couldn't find peer not in malicious bloom to select!\n");
}
+ test_put->next = all_puts;
+ all_puts = test_put;
+ }
+
for (i = 0; i < num_gets; i++)
- {
- test_get = GNUNET_malloc(sizeof(struct TestGetContext));
- test_get->uid = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
- num_puts);
+ {
+ test_get = GNUNET_malloc (sizeof (struct TestGetContext));
+ test_get->uid = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
+ num_puts);
#if REMEMBER
- while (remember[test_get->uid][temp_daemon] == 1)
- temp_daemon = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK,
num_peers);
- remember[test_get->uid][temp_daemon] = 1;
+ while (remember[test_get->uid][temp_daemon] == 1)
+ temp_daemon =
+ GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
+ remember[test_get->uid][temp_daemon] = 1;
#endif
- temp_peer = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
- num_peers);
- test_get->daemon = GNUNET_TESTING_daemon_get (pg, temp_peer);
- /* Don't start GETs at malicious peers! */
- if (malicious_bloom != NULL)
- {
- hash_from_uid (temp_peer, &uid_hash);
- count = 0;
- while ((GNUNET_YES
+ temp_peer = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
+ num_peers);
+ test_get->daemon = GNUNET_TESTING_daemon_get (pg, temp_peer);
+ /* Don't start GETs at malicious peers! */
+ if (malicious_bloom != NULL)
+ {
+ hash_from_uid (temp_peer, &uid_hash);
+ count = 0;
+ while ((GNUNET_YES
== GNUNET_CONTAINER_bloomfilter_test (malicious_bloom,
&uid_hash))
- && (count < num_peers))
- {
- temp_peer = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
- num_peers);
- hash_from_uid (temp_peer, &uid_hash);
- test_get->daemon = GNUNET_TESTING_daemon_get (pg, temp_peer);
- count++;
- }
- if (count == num_peers)
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Couldn't find peer not in malicious bloom to
select!\n");
- }
- test_get->next = all_gets;
- all_gets = test_get;
+ && (count < num_peers))
+ {
+ temp_peer = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
+ num_peers);
+ hash_from_uid (temp_peer, &uid_hash);
+ test_get->daemon = GNUNET_TESTING_daemon_get (pg, temp_peer);
+ count++;
+ }
+ if (count == num_peers)
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Couldn't find peer not in malicious bloom to select!\n");
}
+ test_get->next = all_gets;
+ all_gets = test_get;
+ }
- /*GNUNET_SCHEDULER_cancel (die_task);*/
+ /*GNUNET_SCHEDULER_cancel (die_task); */
die_task
- = GNUNET_SCHEDULER_add_delayed (
- GNUNET_TIME_relative_multiply (
-
GNUNET_TIME_UNIT_SECONDS,
- num_puts
- * 2),
- &end_badly, "from do puts");
+ =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, num_puts * 2),
+ &end_badly, "from do puts");
GNUNET_SCHEDULER_add_now (&do_put, all_puts);
}
@@ -2634,105 +2601,100 @@
* then call actual insert functions.
*/
static void
-continue_puts_and_gets(void *cls,
- const struct GNUNET_SCHEDULER_TaskContext * tc)
+continue_puts_and_gets (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
int i;
int max;
struct TopologyIteratorContext *topo_ctx;
struct FindPeerContext *find_peer_context;
+
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "In continue_puts_and_gets\n");
if ((dhtlog_handle != NULL) && (GNUNET_NO == dhtlog_minimal))
+ {
+ if (settle_time >= 180 * 2)
+ max = (settle_time / 180) - 2;
+ else
+ max = 1;
+ for (i = 1; i < max; i++)
{
- if (settle_time >= 180 * 2)
- max = (settle_time / 180) - 2;
- else
- max = 1;
- for (i = 1; i < max; i++)
- {
- topo_ctx = GNUNET_malloc(sizeof(struct TopologyIteratorContext));
- topo_ctx->current_iteration = i;
- topo_ctx->total_iterations = max;
- topo_ctx->peers_seen
- = GNUNET_CONTAINER_multihashmap_create (num_peers);
- //fprintf(stderr, "scheduled topology iteration in %d minutes\n", i);
- GNUNET_SCHEDULER_add_delayed (
- GNUNET_TIME_relative_multiply (
-
GNUNET_TIME_UNIT_MINUTES,
- i * 3),
- &capture_current_topology, topo_ctx);
- }
- topo_ctx = GNUNET_malloc(sizeof(struct TopologyIteratorContext));
- topo_ctx->cont = &setup_puts_and_gets;
+ topo_ctx = GNUNET_malloc (sizeof (struct TopologyIteratorContext));
+ topo_ctx->current_iteration = i;
+ topo_ctx->total_iterations = max;
topo_ctx->peers_seen = GNUNET_CONTAINER_multihashmap_create (num_peers);
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "setting setup_puts_and_gets for %d seconds in the future\n",
- settle_time + 10);
- GNUNET_SCHEDULER_add_delayed (
- GNUNET_TIME_relative_multiply (
-
GNUNET_TIME_UNIT_SECONDS,
- (settle_time
- + 10)),
+ //fprintf(stderr, "scheduled topology iteration in %d minutes\n", i);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MINUTES, i * 3),
&capture_current_topology, topo_ctx);
}
+ topo_ctx = GNUNET_malloc (sizeof (struct TopologyIteratorContext));
+ topo_ctx->cont = &setup_puts_and_gets;
+ topo_ctx->peers_seen = GNUNET_CONTAINER_multihashmap_create (num_peers);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "setting setup_puts_and_gets for %d seconds in the future\n",
+ settle_time + 10);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS,
+ (settle_time + 10)),
+ &capture_current_topology, topo_ctx);
+ }
else
- GNUNET_SCHEDULER_add_delayed (
- GNUNET_TIME_relative_multiply (
-
GNUNET_TIME_UNIT_SECONDS,
- (settle_time
- + 10)),
- &setup_puts_and_gets, NULL);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS,
+ (settle_time + 10)), &setup_puts_and_gets,
+ NULL);
if (dhtlog_handle != NULL)
dhtlog_handle->insert_round (DHT_ROUND_NORMAL, rounds_finished);
#if HAVE_MALICIOUS
if ((GNUNET_YES != malicious_after_settle) || (settle_time == 0))
- {
- GNUNET_SCHEDULER_add_now(&setup_malicious_peers, NULL);
- }
+ {
+ GNUNET_SCHEDULER_add_now (&setup_malicious_peers, NULL);
+ }
#endif
if ((GNUNET_YES == do_find_peer) && (settle_time > 0))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Scheduling find peer requests during \"settle\" time.\n");
- find_peer_context = GNUNET_malloc(sizeof(struct FindPeerContext));
- find_peer_context->count_peers_cb = &count_peers_cb;
- find_peer_context->endtime
- = GNUNET_TIME_relative_to_absolute (
- GNUNET_TIME_relative_multiply (
-
GNUNET_TIME_UNIT_SECONDS,
-
settle_time));
- GNUNET_SCHEDULER_add_now (&schedule_find_peer_requests,
find_peer_context);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Scheduling find peer requests during \"settle\" time.\n");
+ find_peer_context = GNUNET_malloc (sizeof (struct FindPeerContext));
+ find_peer_context->count_peers_cb = &count_peers_cb;
+ find_peer_context->endtime
+ =
+ GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS,
+ settle_time));
+ GNUNET_SCHEDULER_add_now (&schedule_find_peer_requests, find_peer_context);
+ }
else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Assuming automatic DHT find peer requests.\n");
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Assuming automatic DHT find peer requests.\n");
+ }
}
/**
* Task to release DHT handles
*/
static void
-malicious_disconnect_task(void *cls,
- const struct GNUNET_SCHEDULER_TaskContext * tc)
+malicious_disconnect_task (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct MaliciousContext *ctx = cls;
+
outstanding_malicious--;
malicious_completed++;
ctx->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
GNUNET_DHT_disconnect (ctx->dht_handle);
ctx->dht_handle = NULL;
- GNUNET_free(ctx);
+ GNUNET_free (ctx);
if (malicious_completed == malicious_getters + malicious_putters
+ malicious_droppers)
- {
- fprintf (stderr, "Finished setting all malicious peers up!\n");
- }
+ {
+ fprintf (stderr, "Finished setting all malicious peers up!\n");
+ }
}
#if HAVE_MALICIOUS
@@ -2740,64 +2702,66 @@
* Task to release DHT handles
*/
static void
-malicious_done_task(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
- {
- struct MaliciousContext *ctx = cls;
- GNUNET_SCHEDULER_cancel (ctx->disconnect_task);
- GNUNET_SCHEDULER_add_now (&malicious_disconnect_task, ctx);
- }
+malicious_done_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ struct MaliciousContext *ctx = cls;
+ GNUNET_SCHEDULER_cancel (ctx->disconnect_task);
+ GNUNET_SCHEDULER_add_now (&malicious_disconnect_task, ctx);
+}
+
/**
* Set up some data, and call API PUT function
*/
static void
-set_malicious(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
+set_malicious (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ struct MaliciousContext *ctx = cls;
+
+ if (outstanding_malicious > DEFAULT_MAX_OUTSTANDING_GETS)
{
- struct MaliciousContext *ctx = cls;
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MILLISECONDS, 100),
+ &set_malicious, ctx);
+ return;
+ }
- if (outstanding_malicious > DEFAULT_MAX_OUTSTANDING_GETS)
- {
- GNUNET_SCHEDULER_add_delayed (
- GNUNET_TIME_relative_multiply (
- GNUNET_TIME_UNIT_MILLISECONDS,
- 100),
- &set_malicious, ctx);
- return;
- }
+ if (ctx->dht_handle == NULL)
+ {
+ ctx->dht_handle = GNUNET_DHT_connect (ctx->daemon->cfg, 1);
+ outstanding_malicious++;
+ }
- if (ctx->dht_handle == NULL)
- {
- ctx->dht_handle = GNUNET_DHT_connect (ctx->daemon->cfg, 1);
- outstanding_malicious++;
- }
+ GNUNET_assert (ctx->dht_handle != NULL);
- GNUNET_assert(ctx->dht_handle != NULL);
-
#if VERBOSE > 1
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Setting peer %s malicious type %d\n",
- ctx->daemon->shortname, ctx->malicious_type);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Setting peer %s malicious type %d\n",
+ ctx->daemon->shortname, ctx->malicious_type);
#endif
- switch (ctx->malicious_type)
- {
- case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_GET:
- GNUNET_DHT_set_malicious_getter (ctx->dht_handle,
malicious_get_frequency, &malicious_done_task, ctx);
- break;
- case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_PUT:
- GNUNET_DHT_set_malicious_putter (ctx->dht_handle,
malicious_put_frequency, &malicious_done_task, ctx);
- break;
- case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_DROP:
- GNUNET_DHT_set_malicious_dropper (ctx->dht_handle,
&malicious_done_task, ctx);
- break;
- default:
- break;
- }
-
- ctx->disconnect_task
- = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &malicious_disconnect_task, ctx);
+ switch (ctx->malicious_type)
+ {
+ case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_GET:
+ GNUNET_DHT_set_malicious_getter (ctx->dht_handle, malicious_get_frequency,
+ &malicious_done_task, ctx);
+ break;
+ case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_PUT:
+ GNUNET_DHT_set_malicious_putter (ctx->dht_handle, malicious_put_frequency,
+ &malicious_done_task, ctx);
+ break;
+ case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_DROP:
+ GNUNET_DHT_set_malicious_dropper (ctx->dht_handle, &malicious_done_task,
+ ctx);
+ break;
+ default:
+ break;
}
+ ctx->disconnect_task
+ = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
+ &malicious_disconnect_task, ctx);
+}
+
/**
* Choose the next peer from the peer group to set as malicious.
* If we are doing a sybil attack, find the nearest peer to the
@@ -2809,120 +2773,133 @@
* chosen to be malicious
*/
static uint32_t
-choose_next_malicious (struct GNUNET_TESTING_PeerGroup *pg, struct
GNUNET_CONTAINER_BloomFilter *bloom)
- {
- int i;
- int nearest;
- int bits_match;
- int curr_distance;
- int count;
- struct GNUNET_TESTING_Daemon *temp_daemon;
- GNUNET_HashCode uid_hash;
+choose_next_malicious (struct GNUNET_TESTING_PeerGroup *pg,
+ struct GNUNET_CONTAINER_BloomFilter *bloom)
+{
+ int i;
+ int nearest;
+ int bits_match;
+ int curr_distance;
+ int count;
+ struct GNUNET_TESTING_Daemon *temp_daemon;
+ GNUNET_HashCode uid_hash;
- curr_distance = 0;
- nearest = 0;
- GNUNET_assert (bloom != NULL);
+ curr_distance = 0;
+ nearest = 0;
+ GNUNET_assert (bloom != NULL);
- if (GNUNET_YES == malicious_sybil)
- {
- for (i = 0; i < num_peers; i++)
- {
- temp_daemon = GNUNET_TESTING_daemon_get(pg, i);
- hash_from_uid(i, &uid_hash);
- /* Check if this peer matches the bloomfilter */
- if ((GNUNET_NO == GNUNET_TESTING_daemon_running(temp_daemon)) ||
(GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (bloom, &uid_hash)))
- continue;
+ if (GNUNET_YES == malicious_sybil)
+ {
+ for (i = 0; i < num_peers; i++)
+ {
+ temp_daemon = GNUNET_TESTING_daemon_get (pg, i);
+ hash_from_uid (i, &uid_hash);
+ /* Check if this peer matches the bloomfilter */
+ if ((GNUNET_NO == GNUNET_TESTING_daemon_running (temp_daemon)) ||
+ (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (bloom, &uid_hash)))
+ continue;
- bits_match = GNUNET_CRYPTO_hash_matching_bits
(&temp_daemon->id.hashPubKey, &sybil_target);
- if (bits_match >= curr_distance)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Found nearer peer %s to
%s, old matching bits %d, new %d\n", GNUNET_i2s(&temp_daemon->id),
GNUNET_h2s(&sybil_target), curr_distance, bits_match);
- nearest = i;
- curr_distance = bits_match;
- }
- }
- }
- else
+ bits_match =
+ GNUNET_CRYPTO_hash_matching_bits (&temp_daemon->id.hashPubKey,
+ &sybil_target);
+ if (bits_match >= curr_distance)
{
- nearest = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK,
num_peers);
- hash_from_uid(nearest, &uid_hash);
- count = 0;
- while ((GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (bloom,
&uid_hash)) && (count < num_peers))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Peer %d already in bloom
(tried %d times)\n", nearest, count);
- nearest = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK,
num_peers);
- hash_from_uid(nearest, &uid_hash);
- count++;
- }
- if (count == num_peers)
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Tried %d times to find a peer,
selecting %d at random!!\n", count, nearest);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Found nearer peer %s to %s, old matching bits %d, new
%d\n",
+ GNUNET_i2s (&temp_daemon->id), GNUNET_h2s (&sybil_target),
+ curr_distance, bits_match);
+ nearest = i;
+ curr_distance = bits_match;
}
-
- return nearest;
+ }
}
+ else
+ {
+ nearest = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
+ hash_from_uid (nearest, &uid_hash);
+ count = 0;
+ while ((GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (bloom, &uid_hash))
+ && (count < num_peers))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Peer %d already in bloom (tried %d times)\n", nearest,
+ count);
+ nearest =
+ GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
+ hash_from_uid (nearest, &uid_hash);
+ count++;
+ }
+ if (count == num_peers)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Tried %d times to find a peer, selecting %d at random!!\n",
+ count, nearest);
+ }
+ return nearest;
+}
+
/**
* Select randomly from set of known peers,
* set the desired number of peers to the
* proper malicious types.
*/
static void
-setup_malicious_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *
tc)
+setup_malicious_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext
*tc)
+{
+ struct MaliciousContext *ctx;
+ int i;
+ uint32_t temp_daemon;
+ GNUNET_HashCode uid_hash;
+
+ for (i = 0; i < malicious_getters; i++)
{
- struct MaliciousContext *ctx;
- int i;
- uint32_t temp_daemon;
- GNUNET_HashCode uid_hash;
+ ctx = GNUNET_malloc (sizeof (struct MaliciousContext));
+ temp_daemon = choose_next_malicious (pg, malicious_bloom);
+ ctx->daemon = GNUNET_TESTING_daemon_get (pg, temp_daemon);
+ hash_from_uid (temp_daemon, &uid_hash);
+ GNUNET_CONTAINER_bloomfilter_add (malicious_bloom, &uid_hash);
+ ctx->malicious_type = GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_GET;
+ GNUNET_SCHEDULER_add_now (&set_malicious, ctx);
- for (i = 0; i < malicious_getters; i++)
- {
- ctx = GNUNET_malloc(sizeof(struct MaliciousContext));
- temp_daemon = choose_next_malicious(pg, malicious_bloom);
- ctx->daemon = GNUNET_TESTING_daemon_get(pg, temp_daemon);
- hash_from_uid(temp_daemon, &uid_hash);
- GNUNET_CONTAINER_bloomfilter_add(malicious_bloom, &uid_hash);
- ctx->malicious_type = GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_GET;
- GNUNET_SCHEDULER_add_now (&set_malicious, ctx);
+ }
- }
+ for (i = 0; i < malicious_putters; i++)
+ {
+ ctx = GNUNET_malloc (sizeof (struct MaliciousContext));
+ temp_daemon = choose_next_malicious (pg, malicious_bloom);
+ ctx->daemon = GNUNET_TESTING_daemon_get (pg, temp_daemon);
+ hash_from_uid (temp_daemon, &uid_hash);
+ GNUNET_CONTAINER_bloomfilter_add (malicious_bloom, &uid_hash);
+ ctx->malicious_type = GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_PUT;
+ GNUNET_SCHEDULER_add_now (&set_malicious, ctx);
- for (i = 0; i < malicious_putters; i++)
- {
- ctx = GNUNET_malloc(sizeof(struct MaliciousContext));
- temp_daemon = choose_next_malicious(pg, malicious_bloom);
- ctx->daemon = GNUNET_TESTING_daemon_get(pg, temp_daemon);
- hash_from_uid(temp_daemon, &uid_hash);
- GNUNET_CONTAINER_bloomfilter_add(malicious_bloom, &uid_hash);
- ctx->malicious_type = GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_PUT;
- GNUNET_SCHEDULER_add_now (&set_malicious, ctx);
+ }
- }
-
- for (i = 0; i < malicious_droppers; i++)
- {
- ctx = GNUNET_malloc(sizeof(struct MaliciousContext));
- temp_daemon = choose_next_malicious(pg, malicious_bloom);
- ctx->daemon = GNUNET_TESTING_daemon_get(pg, temp_daemon);
- hash_from_uid(temp_daemon, &uid_hash);
- GNUNET_CONTAINER_bloomfilter_add(malicious_bloom, &uid_hash);
- ctx->malicious_type = GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_DROP;
- GNUNET_SCHEDULER_add_now (&set_malicious, ctx);
- }
+ for (i = 0; i < malicious_droppers; i++)
+ {
+ ctx = GNUNET_malloc (sizeof (struct MaliciousContext));
+ temp_daemon = choose_next_malicious (pg, malicious_bloom);
+ ctx->daemon = GNUNET_TESTING_daemon_get (pg, temp_daemon);
+ hash_from_uid (temp_daemon, &uid_hash);
+ GNUNET_CONTAINER_bloomfilter_add (malicious_bloom, &uid_hash);
+ ctx->malicious_type = GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_DROP;
+ GNUNET_SCHEDULER_add_now (&set_malicious, ctx);
}
+}
#endif
#if ONLY_TESTING
/* Forward declaration */
static void
topology_callback (void *cls,
- const struct GNUNET_PeerIdentity *first,
- const struct GNUNET_PeerIdentity *second,
- uint32_t distance,
- const struct GNUNET_CONFIGURATION_Handle *first_cfg,
- const struct GNUNET_CONFIGURATION_Handle *second_cfg,
- struct GNUNET_TESTING_Daemon *first_daemon,
- struct GNUNET_TESTING_Daemon *second_daemon,
- const char *emsg);
+ const struct GNUNET_PeerIdentity *first,
+ const struct GNUNET_PeerIdentity *second,
+ uint32_t distance,
+ const struct GNUNET_CONFIGURATION_Handle *first_cfg,
+ const struct GNUNET_CONFIGURATION_Handle *second_cfg,
+ struct GNUNET_TESTING_Daemon *first_daemon,
+ struct GNUNET_TESTING_Daemon *second_daemon,
+ const char *emsg);
/**
* Retry connecting two specific peers until they connect,
@@ -2931,19 +2908,24 @@
* debug the reason they are having issues.
*/
static void
-repeat_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
- {
+repeat_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Repeating connect attempt between
%s and %s.\n", repeat_connect_peer1->shortname,
repeat_connect_peer2->shortname);
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Peer 1 configuration `%s'\n",
repeat_connect_peer1->cfgfile);
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Peer 2 configuration `%s'\n",
repeat_connect_peer2->cfgfile);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Repeating connect attempt between %s and %s.\n",
+ repeat_connect_peer1->shortname,
repeat_connect_peer2->shortname);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Peer 1 configuration `%s'\n",
+ repeat_connect_peer1->cfgfile);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Peer 2 configuration `%s'\n",
+ repeat_connect_peer2->cfgfile);
- repeat_connect_task = GNUNET_SCHEDULER_NO_TASK;
- GNUNET_TESTING_daemons_connect(repeat_connect_peer1,
- repeat_connect_peer2,
- GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60),
- 2, &topology_callback, NULL);
- }
+ repeat_connect_task = GNUNET_SCHEDULER_NO_TASK;
+ GNUNET_TESTING_daemons_connect (repeat_connect_peer1,
+ repeat_connect_peer2,
+ GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 60), 2,
+ &topology_callback, NULL);
+}
#endif
/**
@@ -2956,12 +2938,13 @@
* failure (peers failed to connect).
*/
static void
-topology_callback(void *cls, const struct GNUNET_PeerIdentity *first,
- const struct GNUNET_PeerIdentity *second, uint32_t distance,
- const struct GNUNET_CONFIGURATION_Handle *first_cfg,
- const struct GNUNET_CONFIGURATION_Handle *second_cfg,
- struct GNUNET_TESTING_Daemon *first_daemon,
- struct GNUNET_TESTING_Daemon *second_daemon, const char
*emsg)
+topology_callback (void *cls, const struct GNUNET_PeerIdentity *first,
+ const struct GNUNET_PeerIdentity *second, uint32_t distance,
+ const struct GNUNET_CONFIGURATION_Handle *first_cfg,
+ const struct GNUNET_CONFIGURATION_Handle *second_cfg,
+ struct GNUNET_TESTING_Daemon *first_daemon,
+ struct GNUNET_TESTING_Daemon *second_daemon,
+ const char *emsg)
{
struct TopologyIteratorContext *topo_ctx;
uint64_t duration;
@@ -2978,314 +2961,318 @@
#if ONLY_TESTING
if (repeat_connect_mode == GNUNET_YES)
+ {
+ if ((first_daemon == repeat_connect_peer1) &&
+ (second_daemon == repeat_connect_peer2))
{
- if ((first_daemon == repeat_connect_peer1) &&
- (second_daemon == repeat_connect_peer2))
- {
- if (emsg != NULL) /* Peers failed to connect again! */
- {
- GNUNET_assert(repeat_connect_task == GNUNET_SCHEDULER_NO_TASK);
- repeat_connect_task =
GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
60), &repeat_connect, NULL);
- return;
- }
- else /* Repeat peers actually connected! */
- {
- if (repeat_connect_task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel(repeat_connect_task);
- repeat_connect_peer1 = NULL;
- repeat_connect_peer2 = NULL;
- repeat_connect_mode = GNUNET_NO;
- GNUNET_TESTING_resume_connections(pg);
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Resuming normal
connection mode, debug connection was successful!\n");
- }
- }
+ if (emsg != NULL) /* Peers failed to connect again! */
+ {
+ GNUNET_assert (repeat_connect_task == GNUNET_SCHEDULER_NO_TASK);
+ repeat_connect_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 60),
+ &repeat_connect, NULL);
+ return;
+ }
+ else /* Repeat peers actually connected! */
+ {
+ if (repeat_connect_task != GNUNET_SCHEDULER_NO_TASK)
+ GNUNET_SCHEDULER_cancel (repeat_connect_task);
+ repeat_connect_peer1 = NULL;
+ repeat_connect_peer2 = NULL;
+ repeat_connect_mode = GNUNET_NO;
+ GNUNET_TESTING_resume_connections (pg);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Resuming normal connection mode, debug connection was
successful!\n");
+ }
}
+ }
#endif
if (GNUNET_TIME_absolute_get_difference (connect_last_time,
- GNUNET_TIME_absolute_get
()).rel_value
- > GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
- CONN_UPDATE_DURATION).rel_value)
- {
- /* Get number of new connections */
- new_connections = total_connections - previous_connections;
+ GNUNET_TIME_absolute_get
+ ()).rel_value >
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
+ CONN_UPDATE_DURATION).rel_value)
+ {
+ /* Get number of new connections */
+ new_connections = total_connections - previous_connections;
- /* Get number of new FAILED connections */
- new_failed_connections = failed_connections -
previous_failed_connections;
+ /* Get number of new FAILED connections */
+ new_failed_connections = failed_connections - previous_failed_connections;
- /* Get duration in seconds */
- duration
- = GNUNET_TIME_absolute_get_difference (connect_last_time,
- GNUNET_TIME_absolute_get
()).rel_value
- / 1000;
- total_duration
- = GNUNET_TIME_absolute_get_difference (connect_start_time,
- GNUNET_TIME_absolute_get
()).rel_value
- / 1000;
+ /* Get duration in seconds */
+ duration
+ = GNUNET_TIME_absolute_get_difference (connect_last_time,
+ GNUNET_TIME_absolute_get
+ ()).rel_value / 1000;
+ total_duration =
+ GNUNET_TIME_absolute_get_difference (connect_start_time,
+ GNUNET_TIME_absolute_get
+ ()).rel_value / 1000;
- failed_conns_per_sec_recent = (double) new_failed_connections
- / (double) duration;
- failed_conns_per_sec_total = (double) failed_connections
- / (double) total_duration;
- conns_per_sec_recent = (double) new_connections / (double) duration;
- conns_per_sec_total = (double) total_connections
- / (double) total_duration;
- GNUNET_log (
- GNUNET_ERROR_TYPE_WARNING,
- "Recent: %.2f/s, Total: %.2f/s, Recent failed: %.2f/s, total
failed %.2f/s\n",
- conns_per_sec_recent, conns_per_sec_total,
- failed_conns_per_sec_recent, failed_conns_per_sec_total);
- connect_last_time = GNUNET_TIME_absolute_get ();
- previous_connections = total_connections;
- previous_failed_connections = failed_connections;
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "have %llu total_connections, %llu failed\n",
- total_connections, failed_connections);
+ failed_conns_per_sec_recent = (double) new_failed_connections
+ / (double) duration;
+ failed_conns_per_sec_total = (double) failed_connections
+ / (double) total_duration;
+ conns_per_sec_recent = (double) new_connections / (double) duration;
+ conns_per_sec_total = (double) total_connections / (double) total_duration;
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Recent: %.2f/s, Total: %.2f/s, Recent failed: %.2f/s, total
failed %.2f/s\n",
+ conns_per_sec_recent, conns_per_sec_total,
+ failed_conns_per_sec_recent, failed_conns_per_sec_total);
+ connect_last_time = GNUNET_TIME_absolute_get ();
+ previous_connections = total_connections;
+ previous_failed_connections = failed_connections;
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "have %llu total_connections, %llu failed\n",
+ total_connections, failed_connections);
#if ONLY_TESTING
- /* These conditions likely mean we've entered the death spiral of doom */
- if ((total_connections > 20000) &&
- (conns_per_sec_recent < 5.0) &&
- (conns_per_sec_total > 10.0) &&
- (emsg != NULL) &&
- (repeat_connect_mode == GNUNET_NO))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Entering repeat connection
attempt mode!\n");
- repeat_connect_peer1 = first_daemon;
- repeat_connect_peer2 = second_daemon;
- repeat_connect_mode = GNUNET_YES;
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Stopping NEW connections from
being scheduled!\n");
- GNUNET_TESTING_stop_connections(pg);
- repeat_connect_task =
GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
60), &repeat_connect, NULL);
- }
-#endif
+ /* These conditions likely mean we've entered the death spiral of doom */
+ if ((total_connections > 20000) &&
+ (conns_per_sec_recent < 5.0) &&
+ (conns_per_sec_total > 10.0) &&
+ (emsg != NULL) && (repeat_connect_mode == GNUNET_NO))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Entering repeat connection attempt mode!\n");
+ repeat_connect_peer1 = first_daemon;
+ repeat_connect_peer2 = second_daemon;
+ repeat_connect_mode = GNUNET_YES;
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Stopping NEW connections from being scheduled!\n");
+ GNUNET_TESTING_stop_connections (pg);
+ repeat_connect_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 60),
+ &repeat_connect, NULL);
}
+#endif
+ }
if (emsg == NULL)
- {
- total_connections++;
+ {
+ total_connections++;
#if VERBOSE > 1
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s,
distance %u\n",
- first_daemon->shortname,
- second_daemon->shortname,
- distance);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "connected peer %s to peer %s, distance %u\n",
+ first_daemon->shortname, second_daemon->shortname, distance);
#endif
- }
+ }
else
- {
- failed_connections++;
+ {
+ failed_connections++;
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to connect peer %s to
peer %s with error :\n%s\n",
- first_daemon->shortname,
- second_daemon->shortname, emsg);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to connect peer %s to peer %s with error :\n%s\n",
+ first_daemon->shortname, second_daemon->shortname, emsg);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to connect peer %s to peer
%s with error :\n%s\n",
- first_daemon->shortname,
- second_daemon->shortname, emsg);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to connect peer %s to peer %s with error :\n%s\n",
+ first_daemon->shortname, second_daemon->shortname, emsg);
#endif
- }
+ }
#if ONLY_TESTING
- if ((repeat_connect_mode == GNUNET_YES) )
- return;
+ if ((repeat_connect_mode == GNUNET_YES))
+ return;
#endif
- GNUNET_assert(peer_connect_meter != NULL);
+ GNUNET_assert (peer_connect_meter != NULL);
if (GNUNET_YES == update_meter (peer_connect_meter))
- {
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Created %d total connections, which is our target number! Starting
next phase of testing.\n",
- total_connections);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Created %d total connections, which is our target number!
Starting next phase of testing.\n",
+ total_connections);
#endif
- if (failed_connections > 0)
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "While connecting, had %u failed connections.\n",
- failed_connections);
- if (dhtlog_handle != NULL)
- {
- dhtlog_handle->update_connections (total_connections);
- dhtlog_handle->insert_topology (expected_connections);
- }
-
- total_duration
- = GNUNET_TIME_absolute_get_difference (connect_start_time,
- GNUNET_TIME_absolute_get
()).rel_value
- / 1000;
- failed_conns_per_sec_total = (long double) failed_connections
- / total_duration;
- conns_per_sec_total = (long double) total_connections / total_duration;
+ if (failed_connections > 0)
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Overall connection info --- Total: %u, Total Failed %u/s\n",
- total_connections, failed_connections);
- GNUNET_log (
- GNUNET_ERROR_TYPE_WARNING,
- "Overall connection info --- Total: %.2f/s, Total Failed
%.2f/s\n",
- conns_per_sec_total, failed_conns_per_sec_total);
+ "While connecting, had %u failed connections.\n",
+ failed_connections);
+ if (dhtlog_handle != NULL)
+ {
+ dhtlog_handle->update_connections (total_connections);
+ dhtlog_handle->insert_topology (expected_connections);
+ }
- GNUNET_asprintf (&temp_conn_string, "DHT Profiler Connection/s",
- trial_to_run);
- GNUNET_asprintf (&temp_conn_failed_string,
- "DHT Profiler Connection/s failed", trial_to_run);
- GNUNET_asprintf (&revision_str, "%llu", revision);
+ total_duration
+ = GNUNET_TIME_absolute_get_difference (connect_start_time,
+ GNUNET_TIME_absolute_get
+ ()).rel_value / 1000;
+ failed_conns_per_sec_total =
+ (long double) failed_connections / total_duration;
+ conns_per_sec_total = (long double) total_connections / total_duration;
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Overall connection info --- Total: %u, Total Failed %u/s\n",
+ total_connections, failed_connections);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Overall connection info --- Total: %.2f/s, Total Failed
%.2f/s\n",
+ conns_per_sec_total, failed_conns_per_sec_total);
- if (GNUNET_YES == insert_gauger_data)
- GAUGER_ID("DHT_TESTING", temp_conn_string, (long
double)conns_per_sec_total, "conns/s", revision_str);
- if (GNUNET_YES == insert_gauger_data)
- GAUGER_ID("DHT_TESTING", temp_conn_failed_string, (long
double)failed_conns_per_sec_total, "failed_conns", revision_str);
+ GNUNET_asprintf (&temp_conn_string, "DHT Profiler Connection/s",
+ trial_to_run);
+ GNUNET_asprintf (&temp_conn_failed_string,
+ "DHT Profiler Connection/s failed", trial_to_run);
+ GNUNET_asprintf (&revision_str, "%llu", revision);
- GNUNET_free(temp_conn_string);
- GNUNET_free(temp_conn_failed_string);
- GNUNET_asprintf (&temp_conn_string, "DHT Profiler Total Connections",
- trial_to_run);
- GNUNET_asprintf (&temp_conn_failed_string,
- "DHT Profiler Total Connections failed", trial_to_run);
- if (GNUNET_YES == insert_gauger_data)
- GAUGER_ID("DHT_TESTING", temp_conn_string, (double)total_connections,
"conns", revision_str);
- if (GNUNET_YES == insert_gauger_data)
- GAUGER_ID("DHT_TESTING", temp_conn_failed_string,
(double)failed_connections, "failed conns", revision_str);
- GNUNET_free(temp_conn_string);
- GNUNET_free(temp_conn_failed_string);
- GNUNET_free(revision_str);
+ if (GNUNET_YES == insert_gauger_data)
+ GAUGER_ID ("DHT_TESTING", temp_conn_string,
+ (long double) conns_per_sec_total, "conns/s", revision_str);
+ if (GNUNET_YES == insert_gauger_data)
+ GAUGER_ID ("DHT_TESTING", temp_conn_failed_string,
+ (long double) failed_conns_per_sec_total, "failed_conns",
+ revision_str);
- GNUNET_SCHEDULER_cancel (die_task);
+ GNUNET_free (temp_conn_string);
+ GNUNET_free (temp_conn_failed_string);
+ GNUNET_asprintf (&temp_conn_string, "DHT Profiler Total Connections",
+ trial_to_run);
+ GNUNET_asprintf (&temp_conn_failed_string,
+ "DHT Profiler Total Connections failed", trial_to_run);
+ if (GNUNET_YES == insert_gauger_data)
+ GAUGER_ID ("DHT_TESTING", temp_conn_string, (double) total_connections,
+ "conns", revision_str);
+ if (GNUNET_YES == insert_gauger_data)
+ GAUGER_ID ("DHT_TESTING", temp_conn_failed_string,
+ (double) failed_connections, "failed conns", revision_str);
+ GNUNET_free (temp_conn_string);
+ GNUNET_free (temp_conn_failed_string);
+ GNUNET_free (revision_str);
- if ((GNUNET_YES == dhtlog_minimal) && (NULL != dhtlog_handle))
- {
- topo_ctx = GNUNET_malloc(sizeof(struct TopologyIteratorContext));
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Setting continue gets and puts as topo_cont\n");
- topo_ctx->cont = &continue_puts_and_gets;
- topo_ctx->peers_seen
- = GNUNET_CONTAINER_multihashmap_create (num_peers);
- GNUNET_SCHEDULER_add_now (&capture_current_topology, topo_ctx);
- }
- else
- {
- GNUNET_log (
- GNUNET_ERROR_TYPE_WARNING,
- "For some reason, NOT scheduling final topology capture
(settle_time %d, dhtlog_handle %s)!\n",
- settle_time, dhtlog_handle);
- GNUNET_SCHEDULER_add_now (&continue_puts_and_gets, NULL);
- }
+ GNUNET_SCHEDULER_cancel (die_task);
+
+ if ((GNUNET_YES == dhtlog_minimal) && (NULL != dhtlog_handle))
+ {
+ topo_ctx = GNUNET_malloc (sizeof (struct TopologyIteratorContext));
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Setting continue gets and puts as topo_cont\n");
+ topo_ctx->cont = &continue_puts_and_gets;
+ topo_ctx->peers_seen = GNUNET_CONTAINER_multihashmap_create (num_peers);
+ GNUNET_SCHEDULER_add_now (&capture_current_topology, topo_ctx);
}
- else if (total_connections + failed_connections == expected_connections)
+ else
{
- GNUNET_SCHEDULER_cancel (die_task);
- die_task
- = GNUNET_SCHEDULER_add_now (&end_badly,
- "from topology_callback (too many failed
connections)");
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "For some reason, NOT scheduling final topology capture
(settle_time %d, dhtlog_handle %s)!\n",
+ settle_time, dhtlog_handle);
+ GNUNET_SCHEDULER_add_now (&continue_puts_and_gets, NULL);
}
+ }
+ else if (total_connections + failed_connections == expected_connections)
+ {
+ GNUNET_SCHEDULER_cancel (die_task);
+ die_task
+ = GNUNET_SCHEDULER_add_now (&end_badly,
+ "from topology_callback (too many failed
connections)");
+ }
}
static void
-peers_started_callback(void *cls, const struct GNUNET_PeerIdentity *id,
- const struct GNUNET_CONFIGURATION_Handle *cfg,
- struct GNUNET_TESTING_Daemon *d, const char *emsg)
+peers_started_callback (void *cls, const struct GNUNET_PeerIdentity *id,
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ struct GNUNET_TESTING_Daemon *d, const char *emsg)
{
char *revision_str;
+
if (emsg != NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Failed to start daemon with error: `%s'\n", emsg);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to start daemon with error: `%s'\n", emsg);
+ return;
+ }
GNUNET_assert (id != NULL);
#if VERBOSE > 1
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n",
- (num_peers - peers_left) + 1, num_peers);
+ (num_peers - peers_left) + 1, num_peers);
#endif
peers_left--;
if (GNUNET_YES == update_meter (peer_start_meter))
- {
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "All %d daemons started, now connecting peers!\n",
- num_peers);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "All %d daemons started, now connecting peers!\n", num_peers);
#endif
- GNUNET_SCHEDULER_cancel (die_task);
+ GNUNET_SCHEDULER_cancel (die_task);
- GNUNET_asprintf (&revision_str, "%llu", revision);
- if (GNUNET_YES == insert_gauger_data)
- GAUGER_ID("DHT_TESTING",
- "peer_startup_time",
- GNUNET_TIME_absolute_get_duration(peer_start_time).rel_value /
(double)num_peers,
- "ms/peer", revision_str);
- GNUNET_free(revision_str);
+ GNUNET_asprintf (&revision_str, "%llu", revision);
+ if (GNUNET_YES == insert_gauger_data)
+ GAUGER_ID ("DHT_TESTING",
+ "peer_startup_time",
+ GNUNET_TIME_absolute_get_duration (peer_start_time).rel_value
/
+ (double) num_peers, "ms/peer", revision_str);
+ GNUNET_free (revision_str);
- expected_connections = UINT_MAX;
- if ((pg != NULL) && (peers_left == 0))
- {
- connect_start_time = GNUNET_TIME_absolute_get ();
- expected_connections
- = GNUNET_TESTING_connect_topology (
- pg,
- connect_topology,
- connect_topology_option,
-
connect_topology_option_modifier,
- connect_timeout,
- connect_attempts, NULL, NULL);
+ expected_connections = UINT_MAX;
+ if ((pg != NULL) && (peers_left == 0))
+ {
+ connect_start_time = GNUNET_TIME_absolute_get ();
+ expected_connections
+ = GNUNET_TESTING_connect_topology (pg,
+ connect_topology,
+ connect_topology_option,
+ connect_topology_option_modifier,
+ connect_timeout,
+ connect_attempts, NULL, NULL);
- peer_connect_meter = create_meter (expected_connections,
- "Peer connection ", GNUNET_YES);
- fprintf (stderr, "Have %d expected connections\n",
- expected_connections);
- }
+ peer_connect_meter = create_meter (expected_connections,
+ "Peer connection ", GNUNET_YES);
+ fprintf (stderr, "Have %d expected connections\n", expected_connections);
+ }
- if (expected_connections == 0)
- {
- die_task
- = GNUNET_SCHEDULER_add_now (&end_badly,
- "from connect topology (bad
return)");
- }
-
+ if (expected_connections == 0)
+ {
die_task
- = GNUNET_SCHEDULER_add_delayed (
- GNUNET_TIME_relative_multiply (
-
GNUNET_TIME_UNIT_SECONDS,
-
DEFAULT_CONNECT_TIMEOUT
- *
expected_connections),
- &end_badly,
- "from connect topology (timeout)");
-
- ok = 0;
+ = GNUNET_SCHEDULER_add_now (&end_badly,
+ "from connect topology (bad return)");
}
+
+ die_task
+ =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS,
+ DEFAULT_CONNECT_TIMEOUT *
+ expected_connections), &end_badly,
+ "from connect topology (timeout)");
+
+ ok = 0;
+ }
}
static void
-create_topology()
+create_topology ()
{
unsigned int create_expected_connections;
- peers_left = num_peers; /* Reset counter */
+
+ peers_left = num_peers; /* Reset counter */
create_expected_connections
= GNUNET_TESTING_create_topology (pg, topology, blacklist_topology,
blacklist_transports);
if (create_expected_connections > 0)
- {
- GNUNET_log (
- GNUNET_ERROR_TYPE_WARNING,
- "Topology set up, have %u expected connections, now starting
peers!\n",
- create_expected_connections);
- GNUNET_TESTING_daemons_continue_startup (pg);
- peer_start_time = GNUNET_TIME_absolute_get ();
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Topology set up, have %u expected connections, now starting
peers!\n",
+ create_expected_connections);
+ GNUNET_TESTING_daemons_continue_startup (pg);
+ peer_start_time = GNUNET_TIME_absolute_get ();
+ }
else
- {
- GNUNET_SCHEDULER_cancel (die_task);
- die_task = GNUNET_SCHEDULER_add_now (&end_badly,
- "from create topology (bad
return)");
- }
- GNUNET_free_non_null(blacklist_transports);
+ {
+ GNUNET_SCHEDULER_cancel (die_task);
+ die_task = GNUNET_SCHEDULER_add_now (&end_badly,
+ "from create topology (bad return)");
+ }
+ GNUNET_free_non_null (blacklist_transports);
GNUNET_SCHEDULER_cancel (die_task);
die_task
- = GNUNET_SCHEDULER_add_delayed (
- GNUNET_TIME_relative_multiply (
-
seconds_per_peer_start,
-
num_peers),
- &end_badly,
- "from continue startup (timeout)");
+ =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (seconds_per_peer_start, num_peers),
+ &end_badly,
+ "from continue startup (timeout)");
}
/**
@@ -3297,64 +3284,66 @@
* @param emsg non-null on failure
*/
static void
-hostkey_callback(void *cls, const struct GNUNET_PeerIdentity *id,
- struct GNUNET_TESTING_Daemon *d, const char *emsg)
+hostkey_callback (void *cls, const struct GNUNET_PeerIdentity *id,
+ struct GNUNET_TESTING_Daemon *d, const char *emsg)
{
- char * revision_str;
+ char *revision_str;
+
if (emsg != NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Hostkey callback received error: %s\n", emsg);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Hostkey callback received error: %s\n", emsg);
+ }
#if VERBOSE > 1
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Hostkey (%d/%d) created for peer `%s'\n",
- num_peers - peers_left, num_peers, GNUNET_i2s(id));
+ "Hostkey (%d/%d) created for peer `%s'\n",
+ num_peers - peers_left, num_peers, GNUNET_i2s (id));
#endif
peers_left--;
if (GNUNET_YES == update_meter (hostkey_meter))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "All %d hostkeys created, now creating topology!\n",
num_peers);
+
+ GNUNET_asprintf (&revision_str, "%llu", revision);
+ if (GNUNET_YES == insert_gauger_data)
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "All %d hostkeys created, now creating topology!\n",
- num_peers);
+ if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (config, "TESTING",
+ "HOSTKEYSFILE"))
+ {
+ GAUGER_ID ("DHT_TESTING",
+ "HOSTKEY_GENERATION",
+ GNUNET_TIME_absolute_get_duration
+ (hostkey_start_time).rel_value / (double) num_peers,
+ "ms/hostkey", revision_str);
+ }
+ else
+ {
+ GAUGER_ID ("DHT_TESTING",
+ "HOSTKEY_GENERATION_REAL",
+ GNUNET_TIME_absolute_get_duration
+ (hostkey_start_time).rel_value / (double) num_peers,
+ "ms/hostkey", revision_str);
+ }
+ }
- GNUNET_asprintf (&revision_str, "%llu", revision);
- if (GNUNET_YES == insert_gauger_data)
- {
- if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (config, "TESTING",
- "HOSTKEYSFILE"))
- {
- GAUGER_ID("DHT_TESTING",
- "HOSTKEY_GENERATION",
-
GNUNET_TIME_absolute_get_duration(hostkey_start_time).rel_value /
(double)num_peers,
- "ms/hostkey", revision_str);
- }
- else
- {
- GAUGER_ID("DHT_TESTING",
- "HOSTKEY_GENERATION_REAL",
-
GNUNET_TIME_absolute_get_duration(hostkey_start_time).rel_value /
(double)num_peers,
- "ms/hostkey", revision_str);
- }
- }
+ GNUNET_free (revision_str);
- GNUNET_free(revision_str);
-
- GNUNET_SCHEDULER_cancel (die_task);
- /* Set up task in case topology creation doesn't finish
- * within a reasonable amount of time */
- die_task = GNUNET_SCHEDULER_add_delayed (DEFAULT_TOPOLOGY_TIMEOUT,
- &end_badly,
- "from create_topology");
- GNUNET_SCHEDULER_add_now (&create_topology, NULL);
- ok = 0;
- }
+ GNUNET_SCHEDULER_cancel (die_task);
+ /* Set up task in case topology creation doesn't finish
+ * within a reasonable amount of time */
+ die_task = GNUNET_SCHEDULER_add_delayed (DEFAULT_TOPOLOGY_TIMEOUT,
+ &end_badly,
+ "from create_topology");
+ GNUNET_SCHEDULER_add_now (&create_topology, NULL);
+ ok = 0;
+ }
}
static void
-run (void *cls, char * const *args, const char *cfgfile,
+run (void *cls, char *const *args, const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *cfg)
{
struct stat frstat;
@@ -3388,27 +3377,26 @@
config = cfg;
rounds_finished = 0;
- memset (&trial_info, 0, sizeof(struct GNUNET_DHTLOG_TrialInfo));
+ memset (&trial_info, 0, sizeof (struct GNUNET_DHTLOG_TrialInfo));
/* Get path from configuration file */
if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string (cfg, "paths",
"servicehome",
&test_directory))
- {
- ok = 404;
- return;
- }
+ {
+ ok = 404;
+ return;
+ }
/* Get number of peers to start from configuration */
if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, "testing",
"num_peers",
&num_peers))
- {
- GNUNET_log (
- GNUNET_ERROR_TYPE_WARNING,
- "Number of peers must be specified in section %s option
%s\n",
- "TESTING", "NUM_PEERS");
- }
- GNUNET_assert(num_peers > 0 && num_peers < ULONG_MAX);
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Number of peers must be specified in section %s option %s\n",
+ "TESTING", "NUM_PEERS");
+ }
+ GNUNET_assert (num_peers > 0 && num_peers < ULONG_MAX);
if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "testing",
"connect_timeout",
@@ -3416,39 +3404,39 @@
connect_timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
temp_config_number);
else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
- "testing", "connect_timeout");
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
+ "testing", "connect_timeout");
+ return;
+ }
if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "testing",
"connect_attempts",
&connect_attempts))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
- "testing", "connect_attempts");
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
+ "testing", "connect_attempts");
+ return;
+ }
if (GNUNET_OK
!= GNUNET_CONFIGURATION_get_value_number (cfg, "testing",
"max_outstanding_connections",
&max_outstanding_connections))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
- "testing", "max_outstanding_connections");
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
+ "testing", "max_outstanding_connections");
+ return;
+ }
if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "testing",
"max_concurrent_ssh",
&max_concurrent_ssh))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
- "testing", "max_concurrent_ssh");
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
+ "testing", "max_concurrent_ssh");
+ return;
+ }
/**
* Get DHT specific testing options.
@@ -3461,21 +3449,21 @@
|| (GNUNET_YES
== GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht_testing",
"mysql_logging_minimal")))
- {
- if (GNUNET_YES
- == GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht_testing",
- "mysql_logging_minimal"))
- dhtlog_minimal = GNUNET_YES;
+ {
+ if (GNUNET_YES
+ == GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht_testing",
+ "mysql_logging_minimal"))
+ dhtlog_minimal = GNUNET_YES;
- dhtlog_handle = GNUNET_DHTLOG_connect (cfg);
- if (dhtlog_handle == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Could not connect to mysql server for logging, will NOT
log dht operations!");
- ok = 3306;
- return;
- }
+ dhtlog_handle = GNUNET_DHTLOG_connect (cfg);
+ if (dhtlog_handle == NULL)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Could not connect to mysql server for logging, will NOT log
dht operations!");
+ ok = 3306;
+ return;
}
+ }
stop_closest = GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht",
"stop_on_closest");
@@ -3501,107 +3489,106 @@
if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, "dht_testing",
"churn_file",
&churn_filename))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Reading churn data from %s\n",
+ churn_filename);
+ if (GNUNET_OK != GNUNET_DISK_file_test (churn_filename))
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Reading churn data from %s\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Error reading churn file!\n");
+ GNUNET_free_non_null (trialmessage);
+ GNUNET_free (churn_filename);
+ return;
+ }
+ if ((0 != STAT (churn_filename, &frstat)) || (frstat.st_size == 0))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Could not open file specified for churn data, ending
test!");
+ ok = 1119;
+ GNUNET_free_non_null (trialmessage);
+ GNUNET_free (churn_filename);
+ return;
+ }
+
+ churn_data = GNUNET_malloc_large (frstat.st_size);
+ GNUNET_assert (churn_data != NULL);
+ if (frstat.st_size != GNUNET_DISK_fn_read (churn_filename, churn_data,
+ frstat.st_size))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Could not read file %s specified for churn, ending test!",
churn_filename);
- if (GNUNET_OK != GNUNET_DISK_file_test (churn_filename))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Error reading churn
file!\n");
- GNUNET_free_non_null(trialmessage);
- GNUNET_free(churn_filename);
- return;
- }
- if ((0 != STAT (churn_filename, &frstat)) || (frstat.st_size == 0))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Could not open file specified for churn data, ending
test!");
- ok = 1119;
- GNUNET_free_non_null(trialmessage);
- GNUNET_free(churn_filename);
- return;
- }
+ GNUNET_free (churn_filename);
+ GNUNET_free (churn_data);
+ GNUNET_free_non_null (trialmessage);
+ return;
+ }
- churn_data = GNUNET_malloc_large (frstat.st_size);
- GNUNET_assert(churn_data != NULL);
- if (frstat.st_size != GNUNET_DISK_fn_read (churn_filename, churn_data,
- frstat.st_size))
+ GNUNET_free_non_null (churn_filename);
+
+ buf = churn_data;
+ count = 0;
+ /* Read the first line */
+ while (count < frstat.st_size)
+ {
+ count++;
+ if (((churn_data[count] == '\n')) && (buf != &churn_data[count]))
+ {
+ churn_data[count] = '\0';
+ if (1 != sscanf (buf, "%u", &churn_rounds))
{
- GNUNET_log (
- GNUNET_ERROR_TYPE_ERROR,
- "Could not read file %s specified for churn, ending
test!",
- churn_filename);
- GNUNET_free (churn_filename);
- GNUNET_free (churn_data);
- GNUNET_free_non_null(trialmessage);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to read number of rounds from churn file, ending
test!\n");
+ ret = 4200;
+ GNUNET_free_non_null (trialmessage);
+ GNUNET_free_non_null (churn_data);
return;
}
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Read %u rounds from churn file\n", churn_rounds);
+ buf = &churn_data[count + 1];
+ churn_array = GNUNET_malloc (sizeof (unsigned int) * churn_rounds);
+ break; /* Done with this part */
+ }
+ }
- GNUNET_free_non_null(churn_filename);
+ if (GNUNET_OK
+ != GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing",
+ "churns_per_round",
+ &churns_per_round))
+ {
+ churns_per_round = (unsigned long long) churn_rounds;
+ }
- buf = churn_data;
- count = 0;
- /* Read the first line */
- while (count < frstat.st_size)
- {
- count++;
- if (((churn_data[count] == '\n')) && (buf != &churn_data[count]))
- {
- churn_data[count] = '\0';
- if (1 != sscanf (buf, "%u", &churn_rounds))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Failed to read number of rounds from churn
file, ending test!\n");
- ret = 4200;
- GNUNET_free_non_null(trialmessage);
- GNUNET_free_non_null(churn_data);
- return;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Read %u rounds from churn file\n", churn_rounds);
- buf = &churn_data[count + 1];
- churn_array = GNUNET_malloc(sizeof(unsigned int) * churn_rounds);
- break; /* Done with this part */
- }
- }
+ line_number = 0;
+ while ((count < frstat.st_size) && (line_number < churn_rounds))
+ {
+ count++;
+ if (((churn_data[count] == '\n')) && (buf != &churn_data[count]))
+ {
+ churn_data[count] = '\0';
- if (GNUNET_OK
- != GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing",
- "churns_per_round",
- &churns_per_round))
+ ret = sscanf (buf, "%u", &churn_array[line_number]);
+ if (1 == ret)
{
- churns_per_round = (unsigned long long) churn_rounds;
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Read %u peers in round %u\n",
+ churn_array[line_number], line_number);
+ line_number++;
}
-
- line_number = 0;
- while ((count < frstat.st_size) && (line_number < churn_rounds))
+ else
{
- count++;
- if (((churn_data[count] == '\n')) && (buf != &churn_data[count]))
- {
- churn_data[count] = '\0';
-
- ret = sscanf (buf, "%u", &churn_array[line_number]);
- if (1 == ret)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Read %u peers in round %u\n",
- churn_array[line_number], line_number);
- line_number++;
- }
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Error reading line `%s' in hostfile\n", buf);
- buf = &churn_data[count + 1];
- continue;
- }
- buf = &churn_data[count + 1];
- }
- else if (churn_data[count] == '\n') /* Blank line */
- buf = &churn_data[count + 1];
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Error reading line `%s' in hostfile\n", buf);
+ buf = &churn_data[count + 1];
+ continue;
}
+ buf = &churn_data[count + 1];
+ }
+ else if (churn_data[count] == '\n') /* Blank line */
+ buf = &churn_data[count + 1];
}
- GNUNET_free_non_null(churn_data);
+ }
+ GNUNET_free_non_null (churn_data);
/* Check for a hostfile containing address@hidden:port triples */
if (GNUNET_OK
@@ -3613,74 +3600,70 @@
temphost = NULL;
data = NULL;
if (hostfile != NULL)
+ {
+ if (GNUNET_OK != GNUNET_DISK_file_test (hostfile))
+ GNUNET_DISK_fn_write (hostfile, NULL, 0, GNUNET_DISK_PERM_USER_READ
+ | GNUNET_DISK_PERM_USER_WRITE);
+ if ((0 != STAT (hostfile, &frstat)) || (frstat.st_size == 0))
{
- if (GNUNET_OK != GNUNET_DISK_file_test (hostfile))
- GNUNET_DISK_fn_write (hostfile, NULL, 0, GNUNET_DISK_PERM_USER_READ
- | GNUNET_DISK_PERM_USER_WRITE);
- if ((0 != STAT (hostfile, &frstat)) || (frstat.st_size == 0))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Could not open file specified for host list, ending
test!");
- ok = 1119;
- GNUNET_free_non_null(trialmessage);
- GNUNET_free(hostfile);
- return;
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Could not open file specified for host list, ending test!");
+ ok = 1119;
+ GNUNET_free_non_null (trialmessage);
+ GNUNET_free (hostfile);
+ return;
+ }
- data = GNUNET_malloc_large (frstat.st_size);
- GNUNET_assert(data != NULL);
- if (frstat.st_size
- != GNUNET_DISK_fn_read (hostfile, data, frstat.st_size))
- {
- GNUNET_log (
- GNUNET_ERROR_TYPE_ERROR,
- "Could not read file %s specified for host list, ending
test!",
- hostfile);
- GNUNET_free (hostfile);
- GNUNET_free (data);
- GNUNET_free_non_null(trialmessage);
- return;
- }
+ data = GNUNET_malloc_large (frstat.st_size);
+ GNUNET_assert (data != NULL);
+ if (frstat.st_size != GNUNET_DISK_fn_read (hostfile, data, frstat.st_size))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Could not read file %s specified for host list, ending
test!",
+ hostfile);
+ GNUNET_free (hostfile);
+ GNUNET_free (data);
+ GNUNET_free_non_null (trialmessage);
+ return;
+ }
- GNUNET_free_non_null(hostfile);
+ GNUNET_free_non_null (hostfile);
- buf = data;
- count = 0;
- while (count < frstat.st_size - 1)
+ buf = data;
+ count = 0;
+ while (count < frstat.st_size - 1)
+ {
+ count++;
+ if (((data[count] == '\n')) && (buf != &data[count]))
+ {
+ data[count] = '\0';
+ temphost = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Host));
+ ret = sscanf (buf, "address@hidden:%hd",
+ &temphost->username, &temphost->hostname,
+ &temphost->port);
+ if (3 == ret)
{
- count++;
- if (((data[count] == '\n')) && (buf != &data[count]))
- {
- data[count] = '\0';
- temphost = GNUNET_malloc(sizeof(struct GNUNET_TESTING_Host));
- ret = sscanf (buf, "address@hidden:%hd",
- &temphost->username, &temphost->hostname,
- &temphost->port);
- if (3 == ret)
- {
- GNUNET_log (
- GNUNET_ERROR_TYPE_DEBUG,
- "Successfully read host %s, port %d and user %s
from file\n",
- temphost->hostname, temphost->port,
- temphost->username);
- }
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Error reading line `%s' in hostfile\n", buf);
- GNUNET_free(temphost);
- buf = &data[count + 1];
- continue;
- }
- temphost->next = hosts;
- hosts = temphost;
- buf = &data[count + 1];
- }
- else if ((data[count] == '\n') || (data[count] == '\0'))
- buf = &data[count + 1];
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Successfully read host %s, port %d and user %s from
file\n",
+ temphost->hostname, temphost->port, temphost->username);
}
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Error reading line `%s' in hostfile\n", buf);
+ GNUNET_free (temphost);
+ buf = &data[count + 1];
+ continue;
+ }
+ temphost->next = hosts;
+ hosts = temphost;
+ buf = &data[count + 1];
+ }
+ else if ((data[count] == '\n') || (data[count] == '\0'))
+ buf = &data[count + 1];
}
- GNUNET_free_non_null(data);
+ }
+ GNUNET_free_non_null (data);
if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing",
"malicious_getters",
&malicious_getters))
@@ -3814,7 +3797,7 @@
== GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing",
"target_completions",
&target_completions))
- target_completions = 0; /* Not required, on stack */
+ target_completions = 0; /* Not required, on stack */
if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (cfg, "DHT_TESTING",
"GET_FROM_SAME"))
@@ -3839,12 +3822,12 @@
if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (cfg, "DHT_TESTING",
"MALICIOUS_SYBIL"))
- {
- /* Set up the malicious target at random for this round */
- GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
- &sybil_target);
- malicious_sybil = GNUNET_YES;
- }
+ {
+ /* Set up the malicious target at random for this round */
+ GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
+ &sybil_target);
+ malicious_sybil = GNUNET_YES;
+ }
/* Create the bloomfilter for choosing which peers to set malicious */
@@ -3916,9 +3899,9 @@
total_rounds = 1;
if ((GNUNET_SYSERR
- == GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing",
- "target_total_connections",
- &target_total_connections))
+ == GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing",
+ "target_total_connections",
+ &target_total_connections))
|| (target_total_connections == 0))
target_total_connections = connection_estimate (num_peers,
DEFAULT_BUCKET_SIZE);
@@ -3928,82 +3911,79 @@
"topology",
&topology_str))
&& (GNUNET_NO == GNUNET_TESTING_topology_get (&topology, topology_str)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Invalid topology `%s' given for section %s option %s\n",
- topology_str, "TESTING", "TOPOLOGY");
- topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set
better default here */
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Invalid topology `%s' given for section %s option %s\n",
+ topology_str, "TESTING", "TOPOLOGY");
+ topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set
better default here */
+ }
if (GNUNET_OK
!= GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "percentage",
&topology_percentage_str))
topology_percentage = 0.5;
else
- {
- topology_percentage = atof (topology_percentage_str);
- GNUNET_free(topology_percentage_str);
- }
+ {
+ topology_percentage = atof (topology_percentage_str);
+ GNUNET_free (topology_percentage_str);
+ }
if (GNUNET_OK
!= GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "probability",
&topology_probability_str))
topology_probability = 0.5;
else
- {
- topology_probability = atof (topology_probability_str);
- GNUNET_free(topology_probability_str);
- }
+ {
+ topology_probability = atof (topology_probability_str);
+ GNUNET_free (topology_probability_str);
+ }
if ((GNUNET_YES
- == GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
- "connect_topology",
- &connect_topology_str))
+ == GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
+ "connect_topology",
+ &connect_topology_str))
&& (GNUNET_NO == GNUNET_TESTING_topology_get (&connect_topology,
connect_topology_str)))
- {
- GNUNET_log (
- GNUNET_ERROR_TYPE_WARNING,
- "Invalid connect topology `%s' given for section %s option
%s\n",
- connect_topology_str, "TESTING", "CONNECT_TOPOLOGY");
- }
- GNUNET_free_non_null(connect_topology_str);
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Invalid connect topology `%s' given for section %s option
%s\n",
+ connect_topology_str, "TESTING", "CONNECT_TOPOLOGY");
+ }
+ GNUNET_free_non_null (connect_topology_str);
if ((GNUNET_YES
- == GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
- "connect_topology_option",
- &connect_topology_option_str))
+ == GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
+ "connect_topology_option",
+ &connect_topology_option_str))
&& (GNUNET_NO
== GNUNET_TESTING_topology_option_get (&connect_topology_option,
connect_topology_option_str)))
- {
- GNUNET_log (
- GNUNET_ERROR_TYPE_WARNING,
- "Invalid connect topology option `%s' given for section %s
option %s\n",
- connect_topology_option_str, "TESTING",
- "CONNECT_TOPOLOGY_OPTION");
- connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /*
Defaults to NONE, set to ALL */
- }
- GNUNET_free_non_null(connect_topology_option_str);
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Invalid connect topology option `%s' given for section %s
option %s\n",
+ connect_topology_option_str, "TESTING",
+ "CONNECT_TOPOLOGY_OPTION");
+ connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /*
Defaults to NONE, set to ALL */
+ }
+ GNUNET_free_non_null (connect_topology_option_str);
if (GNUNET_YES
- == GNUNET_CONFIGURATION_get_value_string (
- cfg,
+ == GNUNET_CONFIGURATION_get_value_string (cfg,
"testing",
"connect_topology_option_modifier",
&connect_topology_option_modifier_string))
+ {
+ if (sscanf (connect_topology_option_modifier_string, "%lf",
+ &connect_topology_option_modifier) != 1)
{
- if (sscanf (connect_topology_option_modifier_string, "%lf",
- &connect_topology_option_modifier) != 1)
- {
- GNUNET_log (
- GNUNET_ERROR_TYPE_WARNING,
- _("Invalid value `%s' for option `%s' in section `%s':
expected float\n"),
- connect_topology_option_modifier_string,
- "connect_topology_option_modifier", "TESTING");
- }
- GNUNET_free (connect_topology_option_modifier_string);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Invalid value `%s' for option `%s' in section `%s':
expected float\n"),
+ connect_topology_option_modifier_string,
+ "connect_topology_option_modifier", "TESTING");
}
+ GNUNET_free (connect_topology_option_modifier_string);
+ }
if (GNUNET_YES
!= GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
@@ -4012,30 +3992,29 @@
blacklist_transports = NULL;
if ((GNUNET_YES
- == GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
- "blacklist_topology",
- &blacklist_topology_str))
+ == GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
+ "blacklist_topology",
+ &blacklist_topology_str))
&& (GNUNET_NO == GNUNET_TESTING_topology_get (&blacklist_topology,
blacklist_topology_str)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Invalid topology `%s' given for section %s option %s\n",
- topology_str, "TESTING", "BLACKLIST_TOPOLOGY");
- }
- GNUNET_free_non_null(topology_str);
- GNUNET_free_non_null(blacklist_topology_str);
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Invalid topology `%s' given for section %s option %s\n",
+ topology_str, "TESTING", "BLACKLIST_TOPOLOGY");
+ }
+ GNUNET_free_non_null (topology_str);
+ GNUNET_free_non_null (blacklist_topology_str);
/* Set peers_left so we know when all peers started */
peers_left = num_peers;
/* Set up a task to end testing if peer start fails */
die_task
- = GNUNET_SCHEDULER_add_delayed (
- GNUNET_TIME_relative_multiply (
-
seconds_per_peer_start,
-
num_peers),
- &end_badly,
- "didn't generate all hostkeys within
allowed startup time!");
+ =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (seconds_per_peer_start, num_peers),
+ &end_badly,
+ "didn't generate all hostkeys within
allowed startup time!");
if (dhtlog_handle == NULL)
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "dhtlog_handle is NULL!");
@@ -4072,7 +4051,7 @@
if (dhtlog_handle != NULL)
dhtlog_handle->insert_trial (&trial_info);
- GNUNET_free_non_null(trialmessage);
+ GNUNET_free_non_null (trialmessage);
hostkey_meter = create_meter (peers_left, "Hostkeys created ", GNUNET_YES);
peer_start_meter = create_meter (peers_left, "Peers started ", GNUNET_YES);
@@ -4080,37 +4059,35 @@
put_meter = create_meter (num_puts, "Puts completed ", GNUNET_YES);
get_meter = create_meter (num_gets, "Gets completed ", GNUNET_YES);
hostkey_start_time = GNUNET_TIME_absolute_get ();
- pg
- = GNUNET_TESTING_daemons_start (
- cfg,
- peers_left,
- max_outstanding_connections,
- max_concurrent_ssh,
- GNUNET_TIME_relative_multiply (
-
seconds_per_peer_start,
-
num_peers),
- &hostkey_callback, NULL,
- &peers_started_callback, NULL,
- &topology_callback, NULL, hosts);
+ pg = GNUNET_TESTING_daemons_start (cfg,
+ peers_left,
+ max_outstanding_connections,
+ max_concurrent_ssh,
+ GNUNET_TIME_relative_multiply
+ (seconds_per_peer_start, num_peers),
+ &hostkey_callback, NULL,
+ &peers_started_callback, NULL,
+ &topology_callback, NULL, hosts);
temphost = hosts;
while (temphost != NULL)
- {
- tempnext = temphost->next;
- GNUNET_free (temphost->username);
- GNUNET_free (temphost->hostname);
- GNUNET_free (temphost);
- temphost = tempnext;
- }
+ {
+ tempnext = temphost->next;
+ GNUNET_free (temphost->username);
+ GNUNET_free (temphost->hostname);
+ GNUNET_free (temphost);
+ temphost = tempnext;
+ }
}
int
-main(int argc, char *argv[])
+main (int argc, char *argv[])
{
int ret;
- struct GNUNET_GETOPT_CommandLineOption options[] =
- {
- GNUNET_GETOPT_OPTION_END };
+ struct GNUNET_GETOPT_CommandLineOption options[] = {
+ GNUNET_GETOPT_OPTION_END
+ };
+
ret = GNUNET_PROGRAM_run (argc, argv, "gnunet-dht-driver", "nohelp", options,
&run, &ok);
@@ -4118,20 +4095,20 @@
GNUNET_CONTAINER_bloomfilter_free (malicious_bloom);
if (ret != GNUNET_OK)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "`gnunet-dht-driver': Failed with error code %d\n", ret);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "`gnunet-dht-driver': Failed with error code %d\n", ret);
+ }
/**
* Need to remove base directory, subdirectories taken care
* of by the testing framework.
*/
if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Failed to remove testing directory %s\n", test_directory);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to remove testing directory %s\n", test_directory);
+ }
return ret;
}
Modified: gnunet/src/dht/gnunet-dht-get-peer.c
===================================================================
--- gnunet/src/dht/gnunet-dht-get-peer.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/dht/gnunet-dht-get-peer.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -74,29 +74,25 @@
static int ret;
static void
-shutdown_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
if (dht_handle != NULL)
- {
- GNUNET_DHT_disconnect (dht_handle);
- dht_handle = NULL;
- }
- fprintf (stderr,
- _("Found %u peers\n"),
- result_count);
+ {
+ GNUNET_DHT_disconnect (dht_handle);
+ dht_handle = NULL;
+ }
+ fprintf (stderr, _("Found %u peers\n"), result_count);
}
static void
-cleanup_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
if (find_peer_handle != NULL)
- {
- GNUNET_DHT_find_peer_stop (find_peer_handle);
- find_peer_handle = NULL;
- }
+ {
+ GNUNET_DHT_find_peer_stop (find_peer_handle);
+ find_peer_handle = NULL;
+ }
GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
}
@@ -107,20 +103,17 @@
* @param cls closure (NULL)
* @param hello the response message, a HELLO
*/
-static void
-find_peer_processor (void *cls,
- const struct GNUNET_HELLO_Message *hello)
+static void
+find_peer_processor (void *cls, const struct GNUNET_HELLO_Message *hello)
{
struct GNUNET_PeerIdentity peer;
- if (GNUNET_OK == GNUNET_HELLO_get_id(hello, &peer))
- {
- result_count++;
- if (verbose)
- fprintf (stderr,
- _("Found peer `%s'\n"),
- GNUNET_i2s (&peer));
- }
+ if (GNUNET_OK == GNUNET_HELLO_get_id (hello, &peer))
+ {
+ result_count++;
+ if (verbose)
+ fprintf (stderr, _("Found peer `%s'\n"), GNUNET_i2s (&peer));
+ }
}
@@ -139,32 +132,33 @@
{
struct GNUNET_TIME_Relative timeout;
GNUNET_HashCode key;
+
cfg = c;
if (query_key == NULL)
- {
- if (verbose)
- fprintf (stderr, "Must provide key for DHT GET!\n");
- ret = 1;
- return;
- }
+ {
+ if (verbose)
+ fprintf (stderr, "Must provide key for DHT GET!\n");
+ ret = 1;
+ return;
+ }
dht_handle = GNUNET_DHT_connect (cfg, 1);
if (dht_handle == NULL)
- {
- if (verbose)
- fprintf (stderr, "Couldn't connect to DHT service!\n");
- ret = 1;
- return;
- }
+ {
+ if (verbose)
+ fprintf (stderr, "Couldn't connect to DHT service!\n");
+ ret = 1;
+ return;
+ }
else if (verbose)
fprintf (stderr, "Connected to DHT service!\n");
GNUNET_CRYPTO_hash (query_key, strlen (query_key), &key);
timeout =
- GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, timeout_request);
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
timeout_request);
absolute_timeout = GNUNET_TIME_relative_to_absolute (timeout);
if (verbose)
@@ -173,17 +167,15 @@
find_peer_handle = GNUNET_DHT_find_peer_start (dht_handle,
timeout,
&key,
- GNUNET_DHT_RO_NONE,
- &find_peer_processor,
- NULL);
+ GNUNET_DHT_RO_NONE,
+ &find_peer_processor, NULL);
if (NULL == find_peer_handle)
- {
- GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
- return;
- }
+ {
+ GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
+ return;
+ }
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
- (absolute_timeout),
- &cleanup_task, NULL);
+ (absolute_timeout), &cleanup_task, NULL);
}
Modified: gnunet/src/dht/gnunet-dht-get.c
===================================================================
--- gnunet/src/dht/gnunet-dht-get.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/dht/gnunet-dht-get.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -82,10 +82,10 @@
shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
if (dht_handle != NULL)
- {
- GNUNET_DHT_disconnect (dht_handle);
- dht_handle = NULL;
- }
+ {
+ GNUNET_DHT_disconnect (dht_handle);
+ dht_handle = NULL;
+ }
}
@@ -93,10 +93,10 @@
cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
if (get_handle != NULL)
- {
- GNUNET_DHT_get_stop (get_handle);
- get_handle = NULL;
- }
+ {
+ GNUNET_DHT_get_stop (get_handle);
+ get_handle = NULL;
+ }
GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
}
@@ -120,16 +120,12 @@
get_result_iterator (void *cls,
struct GNUNET_TIME_Absolute exp,
const GNUNET_HashCode * key,
- const struct GNUNET_PeerIdentity * const *get_path,
- const struct GNUNET_PeerIdentity * const *put_path,
- enum GNUNET_BLOCK_Type type,
- size_t size,
- const void *data)
+ const struct GNUNET_PeerIdentity *const *get_path,
+ const struct GNUNET_PeerIdentity *const *put_path,
+ 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);
+ result_count, type, (unsigned int) size, (char *) data);
result_count++;
}
@@ -149,50 +145,50 @@
{
struct GNUNET_TIME_Relative timeout;
GNUNET_HashCode key;
+
cfg = c;
if (query_key == NULL)
- {
- if (verbose)
- fprintf (stderr, "Must provide key for DHT GET!\n");
- ret = 1;
- return;
- }
+ {
+ if (verbose)
+ fprintf (stderr, "Must provide key for DHT GET!\n");
+ ret = 1;
+ return;
+ }
dht_handle = GNUNET_DHT_connect (cfg, 1);
if (dht_handle == NULL)
- {
- if (verbose)
- fprintf (stderr, "Couldn't connect to DHT service!\n");
- ret = 1;
- return;
- }
+ {
+ if (verbose)
+ fprintf (stderr, "Couldn't connect to DHT service!\n");
+ ret = 1;
+ return;
+ }
else if (verbose)
fprintf (stderr, "Connected to DHT service!\n");
- if (query_type == GNUNET_BLOCK_TYPE_ANY) /* Type of data not set */
+ if (query_type == GNUNET_BLOCK_TYPE_ANY) /* Type of data not set */
query_type = GNUNET_BLOCK_TYPE_TEST;
GNUNET_CRYPTO_hash (query_key, strlen (query_key), &key);
timeout =
- GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, timeout_request);
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
timeout_request);
absolute_timeout = GNUNET_TIME_relative_to_absolute (timeout);
if (verbose)
fprintf (stderr, "Issuing GET request for %s!\n", query_key);
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
- (absolute_timeout), &cleanup_task, NULL);
+ (absolute_timeout), &cleanup_task, NULL);
get_handle = GNUNET_DHT_get_start (dht_handle,
- timeout,
- query_type,
- &key,
- DEFAULT_GET_REPLICATION,
- GNUNET_DHT_RO_NONE,
- NULL, 0,
- NULL, 0,
- &get_result_iterator, NULL);
+ timeout,
+ query_type,
+ &key,
+ DEFAULT_GET_REPLICATION,
+ GNUNET_DHT_RO_NONE,
+ NULL, 0,
+ NULL, 0, &get_result_iterator, NULL);
}
Modified: gnunet/src/dht/gnunet-dht-put.c
===================================================================
--- gnunet/src/dht/gnunet-dht-put.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/dht/gnunet-dht-put.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -76,10 +76,10 @@
shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
if (dht_handle != NULL)
- {
- GNUNET_DHT_disconnect (dht_handle);
- dht_handle = NULL;
- }
+ {
+ GNUNET_DHT_disconnect (dht_handle);
+ dht_handle = NULL;
+ }
}
/**
@@ -92,8 +92,7 @@
message_sent_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
if (verbose)
- fprintf (stderr,
- _("PUT request sent!\n"));
+ fprintf (stderr, _("PUT request sent!\n"));
GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
}
@@ -113,40 +112,37 @@
struct GNUNET_TIME_Relative timeout;
struct GNUNET_TIME_Absolute expiration;
GNUNET_HashCode key;
+
cfg = c;
- if ( (query_key == NULL) || (data == NULL) )
- {
- fprintf (stderr,
- _("Must provide KEY and DATA for DHT put!\n"));
- ret = 1;
- return;
- }
+ if ((query_key == NULL) || (data == NULL))
+ {
+ fprintf (stderr, _("Must provide KEY and DATA for DHT put!\n"));
+ ret = 1;
+ return;
+ }
dht_handle = GNUNET_DHT_connect (cfg, 1);
if (dht_handle == NULL)
- {
- fprintf (stderr,
- _("Could not connect to %s service!\n"),
- "DHT");
- ret = 1;
- return;
- }
+ {
+ fprintf (stderr, _("Could not connect to %s service!\n"), "DHT");
+ ret = 1;
+ return;
+ }
else if (verbose)
- fprintf (stderr,
- _("Connected to %s service!\n"), "DHT");
+ fprintf (stderr, _("Connected to %s service!\n"), "DHT");
- if (query_type == GNUNET_BLOCK_TYPE_ANY) /* Type of data not set */
+ if (query_type == GNUNET_BLOCK_TYPE_ANY) /* Type of data not set */
query_type = GNUNET_BLOCK_TYPE_TEST;
GNUNET_CRYPTO_hash (query_key, strlen (query_key), &key);
timeout =
- GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, timeout_request);
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
timeout_request);
expiration =
- GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS,
- expiration_seconds));
+ GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS,
+ expiration_seconds));
if (verbose)
fprintf (stderr, _("Issuing put request for `%s' with data `%s'!\n"),
Modified: gnunet/src/dht/gnunet-service-dht.c
===================================================================
--- gnunet/src/dht/gnunet-service-dht.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/dht/gnunet-service-dht.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -967,20 +967,21 @@
unsigned int i;
unsigned int divisor;
struct GNUNET_TIME_Relative average_time;
+
average_time = GNUNET_TIME_relative_get_zero ();
divisor = 0;
for (i = 0; i < MAX_REPLY_TIMES; i++)
- {
- average_time = GNUNET_TIME_relative_add (average_time, reply_times[i]);
- if (reply_times[i].abs_value == (uint64_t) 0)
- continue;
- else
- divisor++;
- }
+ {
+ average_time = GNUNET_TIME_relative_add (average_time, reply_times[i]);
+ if (reply_times[i].abs_value == (uint64_t) 0)
+ continue;
+ else
+ divisor++;
+ }
if (divisor == 0)
- {
- return average_time;
- }
+ {
+ return average_time;
+ }
average_time = GNUNET_TIME_relative_divide (average_time, divisor);
fprintf (stderr,
@@ -999,14 +1000,15 @@
decrease_max_send_delay (struct GNUNET_TIME_Relative max_time)
{
unsigned int i;
+
for (i = 0; i < MAX_REPLY_TIMES; i++)
+ {
+ if (reply_times[i].rel_value == max_time.rel_value)
{
- if (reply_times[i].rel_value == max_time.rel_value)
- {
- reply_times[i].rel_value = reply_times[i].rel_value / 2;
- return;
- }
+ reply_times[i].rel_value = reply_times[i].rel_value / 2;
+ return;
}
+ }
}
/**
@@ -1020,13 +1022,14 @@
{
unsigned int i;
struct GNUNET_TIME_Relative max_time;
+
max_time = GNUNET_TIME_relative_get_zero ();
for (i = 0; i < MAX_REPLY_TIMES; i++)
- {
- if (reply_times[i].rel_value > max_time.rel_value)
- max_time.rel_value = reply_times[i].rel_value;
- }
+ {
+ if (reply_times[i].rel_value > max_time.rel_value)
+ max_time.rel_value = reply_times[i].rel_value;
+ }
#if DEBUG_DHT
if (max_time.rel_value > MAX_REQUEST_TIME.rel_value)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Max send delay was %llu\n",
@@ -1039,18 +1042,18 @@
increment_stats (const char *value)
{
if (stats != NULL)
- {
- GNUNET_STATISTICS_update (stats, value, 1, GNUNET_NO);
- }
+ {
+ GNUNET_STATISTICS_update (stats, value, 1, GNUNET_NO);
+ }
}
static void
decrement_stats (const char *value)
{
if (stats != NULL)
- {
- GNUNET_STATISTICS_update (stats, value, -1, GNUNET_NO);
- }
+ {
+ GNUNET_STATISTICS_update (stats, value, -1, GNUNET_NO);
+ }
}
/**
@@ -1065,7 +1068,7 @@
peer->send_task = GNUNET_SCHEDULER_NO_TASK;
- if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
+ if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
return;
if (peer->th != NULL)
@@ -1073,26 +1076,26 @@
pending = peer->head;
if (pending != NULL)
- {
- ssize = ntohs (pending->msg->size);
+ {
+ ssize = ntohs (pending->msg->size);
#if DEBUG_DHT > 1
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "`%s:%s': Calling notify_transmit_ready with size %d for
peer %s\n",
- my_short_id, "DHT", ssize, GNUNET_i2s (&peer->id));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "`%s:%s': Calling notify_transmit_ready with size %d for peer
%s\n",
+ my_short_id, "DHT", ssize, GNUNET_i2s (&peer->id));
#endif
- pending->scheduled = GNUNET_TIME_absolute_get ();
- reply_counter++;
- if (reply_counter >= MAX_REPLY_TIMES)
- reply_counter = 0;
- peer->th =
- GNUNET_CORE_notify_transmit_ready (coreAPI,
- GNUNET_YES,
- pending->importance,
+ pending->scheduled = GNUNET_TIME_absolute_get ();
+ reply_counter++;
+ if (reply_counter >= MAX_REPLY_TIMES)
+ reply_counter = 0;
+ peer->th =
+ GNUNET_CORE_notify_transmit_ready (coreAPI,
+ GNUNET_YES,
+ pending->importance,
pending->timeout, &peer->id, ssize,
&core_transmit_notify, peer);
- if (peer->th == NULL)
- increment_stats ("# notify transmit ready failed");
- }
+ if (peer->th == NULL)
+ increment_stats ("# notify transmit ready failed");
+ }
}
/**
@@ -1115,13 +1118,15 @@
size_t psize;
char *path_start;
char *path_offset;
+
#if DEBUG_PATH
unsigned int i;
#endif
increment_stats (STAT_RESULT_FORWARDS);
msize =
- sizeof (struct GNUNET_DHT_P2PRouteResultMessage) + ntohs (msg->size) +
(sizeof(struct GNUNET_PeerIdentity) * msg_ctx->path_history_len);
+ sizeof (struct GNUNET_DHT_P2PRouteResultMessage) + ntohs (msg->size) +
+ (sizeof (struct GNUNET_PeerIdentity) * msg_ctx->path_history_len);
GNUNET_assert (msize <= GNUNET_SERVER_MAX_MESSAGE_SIZE);
psize = sizeof (struct P2PPendingMessage) + msize;
pending = GNUNET_malloc (psize);
@@ -1131,23 +1136,28 @@
result_message = (struct GNUNET_DHT_P2PRouteResultMessage *) pending->msg;
result_message->header.size = htons (msize);
result_message->header.type =
- htons (GNUNET_MESSAGE_TYPE_DHT_P2P_ROUTE_RESULT);
+ htons (GNUNET_MESSAGE_TYPE_DHT_P2P_ROUTE_RESULT);
result_message->outgoing_path_length = htonl (msg_ctx->path_history_len);
if (msg_ctx->path_history_len > 0)
+ {
+ /* End of pending is where enc_msg starts */
+ path_start = (char *) &pending[1];
+ /* Offset by the size of the enc_msg */
+ path_start += ntohs (msg->size);
+ memcpy (path_start, msg_ctx->path_history,
+ msg_ctx->path_history_len * (sizeof (struct GNUNET_PeerIdentity)));
+#if DEBUG_PATH
+ for (i = 0; i < msg_ctx->path_history_len; i++)
{
- /* End of pending is where enc_msg starts */
- path_start = (char *)&pending[1];
- /* Offset by the size of the enc_msg */
- path_start += ntohs (msg->size);
- memcpy(path_start, msg_ctx->path_history, msg_ctx->path_history_len *
(sizeof(struct GNUNET_PeerIdentity)));
-#if DEBUG_PATH
- for (i = 0; i < msg_ctx->path_history_len; i++)
- {
- path_offset = &msg_ctx->path_history[i * sizeof(struct
GNUNET_PeerIdentity)];
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "(forward_result) Key %s Found
peer %d:%s\n", GNUNET_h2s(&msg_ctx->key), i, GNUNET_i2s((struct
GNUNET_PeerIdentity *)path_offset));
- }
+ path_offset =
+ &msg_ctx->path_history[i * sizeof (struct GNUNET_PeerIdentity)];
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "(forward_result) Key %s Found peer %d:%s\n",
+ GNUNET_h2s (&msg_ctx->key), i,
+ GNUNET_i2s ((struct GNUNET_PeerIdentity *) path_offset));
+ }
#endif
- }
+ }
result_message->options = htonl (msg_ctx->msg_options);
result_message->hop_count = htonl (msg_ctx->hop_count + 1);
GNUNET_assert (GNUNET_OK ==
@@ -1159,11 +1169,12 @@
memcpy (&result_message->key, &msg_ctx->key, sizeof (GNUNET_HashCode));
/* Copy the enc_msg, then the path history as well! */
memcpy (&result_message[1], msg, ntohs (msg->size));
- path_offset = (char *)&result_message[1];
+ path_offset = (char *) &result_message[1];
path_offset += ntohs (msg->size);
/* If we have path history, copy it to the end of the whole thing */
if (msg_ctx->path_history_len > 0)
- memcpy(path_offset, msg_ctx->path_history, msg_ctx->path_history_len *
(sizeof(struct GNUNET_PeerIdentity)));
+ memcpy (path_offset, msg_ctx->path_history,
+ msg_ctx->path_history_len * (sizeof (struct GNUNET_PeerIdentity)));
#if DEBUG_DHT > 1
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"%s:%s Adding pending message size %d for peer %s\n",
@@ -1196,16 +1207,17 @@
size_t off;
size_t msize;
+
peer->th = NULL;
if (buf == NULL)
- {
- /* client disconnected */
+ {
+ /* client disconnected */
#if DEBUG_DHT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s:%s': buffer was NULL\n",
- my_short_id, "DHT");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s:%s': buffer was NULL\n",
+ my_short_id, "DHT");
#endif
- return 0;
- }
+ return 0;
+ }
if (peer->head == NULL)
return 0;
@@ -1214,31 +1226,31 @@
pending = peer->head;
#if DUMB
reply_times[reply_counter] =
- GNUNET_TIME_absolute_get_difference (pending->scheduled,
- GNUNET_TIME_absolute_get ());
+ GNUNET_TIME_absolute_get_difference (pending->scheduled,
+ GNUNET_TIME_absolute_get ());
msize = ntohs (pending->msg->size);
if (msize <= size)
- {
- off = msize;
- memcpy (cbuf, pending->msg, msize);
- peer->pending_count--;
- increment_stats ("# pending messages sent");
- GNUNET_assert (peer->pending_count >= 0);
- GNUNET_CONTAINER_DLL_remove (peer->head, peer->tail, pending);
- GNUNET_free (pending);
- }
+ {
+ off = msize;
+ memcpy (cbuf, pending->msg, msize);
+ peer->pending_count--;
+ increment_stats ("# pending messages sent");
+ GNUNET_assert (peer->pending_count >= 0);
+ GNUNET_CONTAINER_DLL_remove (peer->head, peer->tail, pending);
+ GNUNET_free (pending);
+ }
#else
while (NULL != pending &&
(size - off >= (msize = ntohs (pending->msg->size))))
- {
- memcpy (&cbuf[off], pending->msg, msize);
- off += msize;
- peer->pending_count--;
- increment_stats ("# pending messages sent");
- GNUNET_CONTAINER_DLL_remove (peer->head, peer->tail, pending);
- GNUNET_free (pending);
- pending = peer->head;
- }
+ {
+ memcpy (&cbuf[off], pending->msg, msize);
+ off += msize;
+ peer->pending_count--;
+ increment_stats ("# pending messages sent");
+ GNUNET_CONTAINER_DLL_remove (peer->head, peer->tail, pending);
+ GNUNET_free (pending);
+ pending = peer->head;
+ }
#endif
if ((peer->head != NULL) && (peer->send_task == GNUNET_SCHEDULER_NO_TASK))
peer->send_task = GNUNET_SCHEDULER_add_now (&try_core_send, peer);
@@ -1265,43 +1277,43 @@
unsigned int i;
/* We have to represent the distance between two 2^9 (=512)-bit
- numbers as a 2^5 (=32)-bit number with "0" being used for the
- two numbers being identical; furthermore, we need to
- guarantee that a difference in the number of matching
- bits is always represented in the result.
+ * numbers as a 2^5 (=32)-bit number with "0" being used for the
+ * two numbers being identical; furthermore, we need to
+ * guarantee that a difference in the number of matching
+ * bits is always represented in the result.
+ *
+ * We use 2^32/2^9 numerical values to distinguish between
+ * hash codes that have the same LSB bit distance and
+ * use the highest 2^9 bits of the result to signify the
+ * number of (mis)matching LSB bits; if we have 0 matching
+ * and hence 512 mismatching LSB bits we return -1 (since
+ * 512 itself cannot be represented with 9 bits) */
- We use 2^32/2^9 numerical values to distinguish between
- hash codes that have the same LSB bit distance and
- use the highest 2^9 bits of the result to signify the
- number of (mis)matching LSB bits; if we have 0 matching
- and hence 512 mismatching LSB bits we return -1 (since
- 512 itself cannot be represented with 9 bits) */
-
/* first, calculate the most significant 9 bits of our
- result, aka the number of LSBs */
+ * result, aka the number of LSBs */
bucket = GNUNET_CRYPTO_hash_matching_bits (target, have);
/* bucket is now a value between 0 and 512 */
if (bucket == 512)
return 0; /* perfect match */
if (bucket == 0)
return (unsigned int) -1; /* LSB differs; use max (if we did the
bit-shifting
- below, we'd end up with max+1 (overflow)) */
+ * below, we'd end up with max+1 (overflow)) */
/* calculate the most significant bits of the final result */
msb = (512 - bucket) << (32 - 9);
/* calculate the 32-9 least significant bits of the final result by
- looking at the differences in the 32-9 bits following the
- mismatching bit at 'bucket' */
+ * looking at the differences in the 32-9 bits following the
+ * mismatching bit at 'bucket' */
lsb = 0;
for (i = bucket + 1;
(i < sizeof (GNUNET_HashCode) * 8) && (i < bucket + 1 + 32 - 9); i++)
- {
- if (GNUNET_CRYPTO_hash_get_bit (target, i) !=
- GNUNET_CRYPTO_hash_get_bit (have, i))
- lsb |= (1 << (bucket + 32 - 9 - i)); /* first bit set will be 10,
- last bit set will be 31 --
if
- i does not reach 512
first... */
- }
+ {
+ if (GNUNET_CRYPTO_hash_get_bit (target, i) !=
+ GNUNET_CRYPTO_hash_get_bit (have, i))
+ lsb |= (1 << (bucket + 32 - 9 - i)); /* first bit set will be 10,
+ * last bit set will be 31 --
if
+ * i does not reach 512
first... */
+ }
return msb | lsb;
}
@@ -1313,8 +1325,7 @@
* Must fudge the value if NO bits match.
*/
static unsigned int
-inverse_distance (const GNUNET_HashCode * target,
- const GNUNET_HashCode * have)
+inverse_distance (const GNUNET_HashCode * target, const GNUNET_HashCode * have)
{
if (GNUNET_CRYPTO_hash_matching_bits (target, have) == 0)
return 1; /* Never return 0! */
@@ -1359,11 +1370,11 @@
find_current_bucket (const GNUNET_HashCode * hc)
{
int actual_bucket;
-
+
actual_bucket = find_bucket (hc);
if (actual_bucket == GNUNET_SYSERR) /* hc and our peer identity match! */
return lowest_bucket;
- if (actual_bucket < lowest_bucket) /* actual_bucket not yet used */
+ if (actual_bucket < lowest_bucket) /* actual_bucket not yet used */
return lowest_bucket;
return actual_bucket;
}
@@ -1383,15 +1394,15 @@
struct PeerInfo *pos;
for (bucket = lowest_bucket; bucket < MAX_BUCKETS - 1; bucket++)
+ {
+ pos = k_buckets[bucket].head;
+ while (pos != NULL)
{
- pos = k_buckets[bucket].head;
- while (pos != NULL)
- {
- if (peer == pos)
- return bucket;
- pos = pos->next;
- }
+ if (peer == pos)
+ return bucket;
+ pos = pos->next;
}
+ }
return GNUNET_SYSERR; /* No such peer. */
}
@@ -1408,30 +1419,30 @@
struct PeerInfo *pos;
char char_buf[30000];
int char_pos;
+
memset (char_buf, 0, sizeof (char_buf));
char_pos = 0;
char_pos +=
- sprintf (&char_buf[char_pos], "Printing routing table for peer %s\n",
- my_short_id);
+ sprintf (&char_buf[char_pos], "Printing routing table for peer %s\n",
+ my_short_id);
//fprintf(stderr, "Printing routing table for peer %s\n", my_short_id);
for (bucket = lowest_bucket; bucket < MAX_BUCKETS; bucket++)
+ {
+ pos = k_buckets[bucket].head;
+ char_pos += sprintf (&char_buf[char_pos], "Bucket %d:\n", bucket);
+ //fprintf(stderr, "Bucket %d:\n", bucket);
+ while (pos != NULL)
{
- pos = k_buckets[bucket].head;
- char_pos += sprintf (&char_buf[char_pos], "Bucket %d:\n", bucket);
- //fprintf(stderr, "Bucket %d:\n", bucket);
- while (pos != NULL)
- {
- //fprintf(stderr, "\tPeer %s, best bucket %d, %d bits match\n",
GNUNET_i2s(&pos->id), find_bucket(&pos->id.hashPubKey),
GNUNET_CRYPTO_hash_matching_bits(&pos->id.hashPubKey, &my_identity.hashPubKey));
- char_pos +=
- sprintf (&char_buf[char_pos],
- "\tPeer %s, best bucket %d, %d bits match\n",
- GNUNET_i2s (&pos->id), find_bucket (&pos->id.hashPubKey),
- GNUNET_CRYPTO_hash_matching_bits (&pos->id.hashPubKey,
- &my_identity.
- hashPubKey));
- pos = pos->next;
- }
+ //fprintf(stderr, "\tPeer %s, best bucket %d, %d bits match\n",
GNUNET_i2s(&pos->id), find_bucket(&pos->id.hashPubKey),
GNUNET_CRYPTO_hash_matching_bits(&pos->id.hashPubKey, &my_identity.hashPubKey));
+ char_pos +=
+ sprintf (&char_buf[char_pos],
+ "\tPeer %s, best bucket %d, %d bits match\n",
+ GNUNET_i2s (&pos->id), find_bucket (&pos->id.hashPubKey),
+ GNUNET_CRYPTO_hash_matching_bits (&pos->id.hashPubKey,
+ &my_identity.hashPubKey));
+ pos = pos->next;
}
+ }
fprintf (stderr, "%s", char_buf);
fflush (stderr);
}
@@ -1449,6 +1460,7 @@
{
int bucket;
struct PeerInfo *pos;
+
bucket = find_current_bucket (&peer->hashPubKey);
if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity)))
@@ -1456,11 +1468,11 @@
pos = k_buckets[bucket].head;
while (pos != NULL)
- {
- if (0 == memcmp (&pos->id, peer, sizeof (struct GNUNET_PeerIdentity)))
- return pos;
- pos = pos->next;
- }
+ {
+ if (0 == memcmp (&pos->id, peer, sizeof (struct GNUNET_PeerIdentity)))
+ return pos;
+ pos = pos->next;
+ }
return NULL; /* No such peer. */
}
@@ -1484,9 +1496,9 @@
update_core_preference_finish (void *cls,
const struct GNUNET_PeerIdentity *peer,
struct GNUNET_BANDWIDTH_Value32NBO bpm_out,
- int32_t amount,
- struct GNUNET_TIME_Relative res_delay,
- uint64_t preference)
+ int32_t amount,
+ struct GNUNET_TIME_Relative res_delay,
+ uint64_t preference)
{
struct PeerInfo *peer_info = cls;
@@ -1502,28 +1514,29 @@
struct PeerInfo *peer = cls;
uint64_t preference;
unsigned int matching;
- if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- {
- return;
- }
+
+ if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
+ {
+ 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)
- {
+ {
#if DEBUG_DHT
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Peer identifier matches by %u bits, only shifting as much
as we can!\n",
- matching);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Peer identifier matches by %u bits, only shifting as much as
we can!\n",
+ matching);
#endif
- matching = 63;
- }
+ matching = 63;
+ }
preference = 1LL << matching;
peer->info_ctx = GNUNET_CORE_peer_change_preference (coreAPI,
&peer->id,
GNUNET_TIME_UNIT_FOREVER_REL,
-
GNUNET_BANDWIDTH_VALUE_MAX,
- 0,
+
GNUNET_BANDWIDTH_VALUE_MAX,
+ 0,
preference,
&update_core_preference_finish,
peer);
@@ -1566,6 +1579,7 @@
{
struct P2PPendingMessage *pos;
struct P2PPendingMessage *next;
+
#if EXTRA_CHECKS
struct PeerInfo *peer_pos;
@@ -1573,16 +1587,16 @@
while ((peer_pos != NULL) && (peer_pos != peer))
peer_pos = peer_pos->next;
if (peer_pos == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "%s:%s: Expected peer `%s' in bucket %d\n", my_short_id,
- "DHT", GNUNET_i2s (&peer->id), bucket);
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "%s:%s: Lowest bucket: %d, find_current_bucket: %d, peer
resides in bucket: %d\n",
- my_short_id, "DHT", lowest_bucket,
- find_current_bucket (&peer->id.hashPubKey),
- find_bucket_by_peer (peer));
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "%s:%s: Expected peer `%s' in bucket %d\n", my_short_id,
+ "DHT", GNUNET_i2s (&peer->id), bucket);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "%s:%s: Lowest bucket: %d, find_current_bucket: %d, peer
resides in bucket: %d\n",
+ my_short_id, "DHT", lowest_bucket,
+ find_current_bucket (&peer->id.hashPubKey),
+ find_bucket_by_peer (peer));
+ }
GNUNET_assert (peer_pos != NULL);
#endif
remove_peer (peer, bucket); /* First remove the peer from its bucket */
@@ -1594,13 +1608,13 @@
pos = peer->head;
while (pos != NULL) /* Remove any pending messages for this peer */
- {
- increment_stats
+ {
+ increment_stats
("# dht pending messages discarded (due to disconnect/shutdown)");
- next = pos->next;
- GNUNET_free (pos);
- pos = next;
- }
+ next = pos->next;
+ GNUNET_free (pos);
+ pos = next;
+ }
GNUNET_assert (GNUNET_CONTAINER_multihashmap_contains
(all_known_peers, &peer->id.hashPubKey));
@@ -1609,7 +1623,7 @@
&peer->id.hashPubKey,
peer));
GNUNET_free (peer);
- decrement_stats(STAT_PEERS_KNOWN);
+ decrement_stats (STAT_PEERS_KNOWN);
}
@@ -1650,6 +1664,7 @@
{
struct GNUNET_CONTAINER_MultiHashMap *to_remove;
struct PeerInfo *pos;
+
GNUNET_assert (lowest_bucket > 0);
to_remove = GNUNET_CONTAINER_multihashmap_create (bucket_size);
pos = k_buckets[lowest_bucket].head;
@@ -1660,17 +1675,16 @@
#endif
/* Populate the array of peers which should be in the next lowest bucket */
while (pos != NULL)
- {
- if (find_bucket (&pos->id.hashPubKey) < lowest_bucket)
- GNUNET_CONTAINER_multihashmap_put (to_remove, &pos->id.hashPubKey,
- pos,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
- pos = pos->next;
- }
+ {
+ if (find_bucket (&pos->id.hashPubKey) < lowest_bucket)
+ GNUNET_CONTAINER_multihashmap_put (to_remove, &pos->id.hashPubKey,
+ pos,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+ pos = pos->next;
+ }
/* Remove peers from lowest bucket, insert into next lowest bucket */
- GNUNET_CONTAINER_multihashmap_iterate (to_remove, &move_lowest_bucket,
- NULL);
+ GNUNET_CONTAINER_multihashmap_iterate (to_remove, &move_lowest_bucket, NULL);
GNUNET_CONTAINER_multihashmap_destroy (to_remove);
lowest_bucket = lowest_bucket - 1;
#if PRINT_TABLES
@@ -1703,21 +1717,21 @@
current_closest = NULL;
for (bucket = lowest_bucket; bucket < MAX_BUCKETS; bucket++)
+ {
+ pos = k_buckets[bucket].head;
+ count = 0;
+ while ((pos != NULL) && (count < bucket_size))
{
- pos = k_buckets[bucket].head;
- count = 0;
- while ((pos != NULL) && (count < bucket_size))
- {
- temp_distance = distance (&pos->id.hashPubKey, hc);
- if (temp_distance <= lowest_distance)
- {
- lowest_distance = temp_distance;
- current_closest = pos;
- }
- pos = pos->next;
- count++;
- }
+ temp_distance = distance (&pos->id.hashPubKey, hc);
+ if (temp_distance <= lowest_distance)
+ {
+ lowest_distance = temp_distance;
+ current_closest = pos;
+ }
+ pos = pos->next;
+ count++;
}
+ }
GNUNET_assert (current_closest != NULL);
return current_closest;
}
@@ -1748,7 +1762,9 @@
&& (peer == find_closest_peer (&msg_ctx->key)))
increment_stats (STAT_ROUTE_FORWARDS_CLOSEST);
- msize = sizeof (struct GNUNET_DHT_P2PRouteMessage) + ntohs (msg->size) +
(msg_ctx->path_history_len * sizeof(struct GNUNET_PeerIdentity));
+ msize =
+ sizeof (struct GNUNET_DHT_P2PRouteMessage) + ntohs (msg->size) +
+ (msg_ctx->path_history_len * sizeof (struct GNUNET_PeerIdentity));
GNUNET_assert (msize <= GNUNET_SERVER_MAX_MESSAGE_SIZE);
psize = sizeof (struct P2PPendingMessage) + msize;
pending = GNUNET_malloc (psize);
@@ -1771,16 +1787,18 @@
DHT_BLOOM_SIZE));
memcpy (&route_message->key, &msg_ctx->key, sizeof (GNUNET_HashCode));
memcpy (&route_message[1], msg, ntohs (msg->size));
- if (GNUNET_DHT_RO_RECORD_ROUTE == (msg_ctx->msg_options &
GNUNET_DHT_RO_RECORD_ROUTE))
- {
- route_message->outgoing_path_length = htonl(msg_ctx->path_history_len);
- /* Set pointer to start of enc_msg */
- route_path = (char *)&route_message[1];
- /* Offset to the end of the enc_msg */
- route_path += ntohs (msg->size);
- /* Copy the route_path after enc_msg */
- memcpy (route_path, msg_ctx->path_history, msg_ctx->path_history_len *
sizeof(struct GNUNET_PeerIdentity));
- }
+ if (GNUNET_DHT_RO_RECORD_ROUTE ==
+ (msg_ctx->msg_options & GNUNET_DHT_RO_RECORD_ROUTE))
+ {
+ route_message->outgoing_path_length = htonl (msg_ctx->path_history_len);
+ /* Set pointer to start of enc_msg */
+ route_path = (char *) &route_message[1];
+ /* Offset to the end of the enc_msg */
+ route_path += ntohs (msg->size);
+ /* Copy the route_path after enc_msg */
+ memcpy (route_path, msg_ctx->path_history,
+ msg_ctx->path_history_len * sizeof (struct GNUNET_PeerIdentity));
+ }
#if DEBUG_DHT > 1
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"%s:%s Adding pending message size %d for peer %s\n",
@@ -1809,7 +1827,7 @@
struct GNUNET_MessageHeader ping_message;
struct DHT_MessageContext msg_ctx;
- if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
+ if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
return;
ping_message.size = htons (sizeof (struct GNUNET_MessageHeader));
@@ -1823,8 +1841,8 @@
#endif
forward_message (&ping_message, peer, &msg_ctx);
peer->ping_task =
- GNUNET_SCHEDULER_add_delayed (DHT_DEFAULT_PING_DELAY, &periodic_ping_task,
- peer);
+ GNUNET_SCHEDULER_add_delayed (DHT_DEFAULT_PING_DELAY,
&periodic_ping_task,
+ peer);
}
/**
@@ -1837,25 +1855,25 @@
unsigned int bucket;
unsigned int count;
struct PeerInfo *pos;
+
for (bucket = lowest_bucket; bucket < MAX_BUCKETS; bucket++)
+ {
+ pos = k_buckets[bucket].head;
+ count = 0;
+ while (pos != NULL)
{
- pos = k_buckets[bucket].head;
- count = 0;
- while (pos != NULL)
- {
- if ((count < bucket_size)
- && (pos->ping_task == GNUNET_SCHEDULER_NO_TASK))
- GNUNET_SCHEDULER_add_now (&periodic_ping_task, pos);
- else if ((count >= bucket_size)
- && (pos->ping_task != GNUNET_SCHEDULER_NO_TASK))
- {
- GNUNET_SCHEDULER_cancel (pos->ping_task);
- pos->ping_task = GNUNET_SCHEDULER_NO_TASK;
- }
- pos = pos->next;
- count++;
- }
+ if ((count < bucket_size) && (pos->ping_task ==
GNUNET_SCHEDULER_NO_TASK))
+ GNUNET_SCHEDULER_add_now (&periodic_ping_task, pos);
+ else if ((count >= bucket_size)
+ && (pos->ping_task != GNUNET_SCHEDULER_NO_TASK))
+ {
+ GNUNET_SCHEDULER_cancel (pos->ping_task);
+ pos->ping_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ pos = pos->next;
+ count++;
}
+ }
}
#endif
@@ -1874,11 +1892,11 @@
return;
client->transmit_handle =
- GNUNET_SERVER_notify_transmit_ready (client->client_handle,
- ntohs (client->pending_head->
- msg->size),
- GNUNET_TIME_UNIT_FOREVER_REL,
- &send_generic_reply, client);
+ GNUNET_SERVER_notify_transmit_ready (client->client_handle,
+ ntohs (client->pending_head->
+ msg->size),
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &send_generic_reply, client);
}
/**
@@ -1904,20 +1922,20 @@
client->transmit_handle = NULL;
if (buf == NULL)
- {
- /* client disconnected */
- return 0;
- }
+ {
+ /* client disconnected */
+ return 0;
+ }
off = 0;
while ((NULL != (reply = client->pending_head)) &&
(size >= off + (msize = ntohs (reply->msg->size))))
- {
- GNUNET_CONTAINER_DLL_remove (client->pending_head,
- client->pending_tail, reply);
- memcpy (&cbuf[off], reply->msg, msize);
- GNUNET_free (reply);
- off += msize;
- }
+ {
+ GNUNET_CONTAINER_DLL_remove (client->pending_head,
+ client->pending_tail, reply);
+ memcpy (&cbuf[off], reply->msg, msize);
+ GNUNET_free (reply);
+ off += msize;
+ }
process_pending_messages (client);
#if DEBUG_DHT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1963,6 +1981,7 @@
uint16_t msize;
size_t tsize;
char *reply_offset;
+
#if DEBUG_PATH
char *path_offset;
unsigned int i;
@@ -1972,34 +1991,41 @@
"`%s:%s': Sending reply to client.\n", my_short_id, "DHT");
#endif
msize = ntohs (message->size);
- tsize = sizeof (struct GNUNET_DHT_RouteResultMessage) + msize +
(msg_ctx->path_history_len * sizeof(struct GNUNET_PeerIdentity));
+ tsize =
+ sizeof (struct GNUNET_DHT_RouteResultMessage) + msize +
+ (msg_ctx->path_history_len * sizeof (struct GNUNET_PeerIdentity));
if (tsize >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
- {
- GNUNET_break_op (0);
- return;
- }
+ {
+ GNUNET_break_op (0);
+ return;
+ }
pending_message = GNUNET_malloc (sizeof (struct PendingMessage) + tsize);
pending_message->msg = (struct GNUNET_MessageHeader *) &pending_message[1];
reply = (struct GNUNET_DHT_RouteResultMessage *) &pending_message[1];
reply->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_LOCAL_ROUTE_RESULT);
reply->header.size = htons (tsize);
- reply->outgoing_path_length = htonl(msg_ctx->path_history_len);
+ reply->outgoing_path_length = htonl (msg_ctx->path_history_len);
reply->unique_id = GNUNET_htonll (msg_ctx->unique_id);
memcpy (&reply->key, &msg_ctx->key, sizeof (GNUNET_HashCode));
- reply_offset = (char *)&reply[1];
+ reply_offset = (char *) &reply[1];
memcpy (&reply[1], message, msize);
if (msg_ctx->path_history_len > 0)
- {
- reply_offset += msize;
- memcpy(reply_offset, msg_ctx->path_history, msg_ctx->path_history_len *
sizeof(struct GNUNET_PeerIdentity));
- }
+ {
+ reply_offset += msize;
+ memcpy (reply_offset, msg_ctx->path_history,
+ msg_ctx->path_history_len * sizeof (struct GNUNET_PeerIdentity));
+ }
#if DEBUG_PATH
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Returning message with outgoing path
length %d\n", msg_ctx->path_history_len);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Returning message with outgoing path length %d\n",
+ msg_ctx->path_history_len);
for (i = 0; i < msg_ctx->path_history_len; i++)
- {
- path_offset = &msg_ctx->path_history[i * sizeof(struct
GNUNET_PeerIdentity)];
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Found peer %d:%s\n", i,
GNUNET_i2s((struct GNUNET_PeerIdentity *)path_offset));
- }
+ {
+ path_offset =
+ &msg_ctx->path_history[i * sizeof (struct GNUNET_PeerIdentity)];
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found peer %d:%s\n", i,
+ GNUNET_i2s ((struct GNUNET_PeerIdentity *) path_offset));
+ }
#endif
add_pending_message (client, pending_message);
}
@@ -2045,23 +2071,22 @@
* @param tc context, reason, etc.
*/
static void
-remove_forward_entry (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+remove_forward_entry (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct DHTRouteSource *source_info = cls;
struct DHTQueryRecord *record;
- source_info =
- GNUNET_CONTAINER_heap_remove_node (source_info->hnode);
+
+ source_info = GNUNET_CONTAINER_heap_remove_node (source_info->hnode);
record = source_info->record;
GNUNET_CONTAINER_DLL_remove (record->head, record->tail, source_info);
if (record->head == NULL) /* No more entries in DLL */
- {
- GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove
- (forward_list.hashmap, &record->key, record));
- GNUNET_free (record);
- }
+ {
+ GNUNET_assert (GNUNET_YES ==
+ GNUNET_CONTAINER_multihashmap_remove
+ (forward_list.hashmap, &record->key, record));
+ GNUNET_free (record);
+ }
if (source_info->find_peers_responded != NULL)
GNUNET_CONTAINER_bloomfilter_free (source_info->find_peers_responded);
GNUNET_free (source_info);
@@ -2086,6 +2111,7 @@
struct DHTRouteSource *pos;
struct PeerInfo *peer_info;
const struct GNUNET_MessageHeader *hello_msg;
+
#if DEBUG_DHT > 1
unsigned int i;
#endif
@@ -2096,188 +2122,186 @@
* HELLO for another peer, offer it to the transport service.
*/
if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_DHT_FIND_PEER_RESULT)
+ {
+ if (ntohs (msg->size) <= sizeof (struct GNUNET_MessageHeader))
+ GNUNET_break_op (0);
+
+ hello_msg = &msg[1];
+ if ((ntohs (hello_msg->type) != GNUNET_MESSAGE_TYPE_HELLO)
+ || (GNUNET_SYSERR ==
+ GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
+ hello_msg, &new_peer)))
{
- if (ntohs (msg->size) <= sizeof (struct GNUNET_MessageHeader))
- GNUNET_break_op (0);
-
- hello_msg = &msg[1];
- if ((ntohs (hello_msg->type) != GNUNET_MESSAGE_TYPE_HELLO)
- || (GNUNET_SYSERR ==
- GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
- hello_msg, &new_peer)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "%s:%s Received non-HELLO message type in find peer
result message!\n",
- my_short_id, "DHT");
- GNUNET_break_op (0);
- return GNUNET_NO;
- }
- else /* We have a valid hello, and peer id stored
in new_peer */
- {
- find_peer_context.count++;
- increment_stats (STAT_FIND_PEER_REPLY);
- if (GNUNET_YES == consider_peer (&new_peer))
- {
- increment_stats (STAT_HELLOS_PROVIDED);
- GNUNET_TRANSPORT_offer_hello (transport_handle, hello_msg, NULL,
NULL);
- GNUNET_CORE_peer_request_connect (coreAPI,
- &new_peer, NULL, NULL);
- }
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "%s:%s Received non-HELLO message type in find peer result
message!\n",
+ my_short_id, "DHT");
+ GNUNET_break_op (0);
+ return GNUNET_NO;
}
+ else /* We have a valid hello, and peer id stored
in new_peer */
+ {
+ find_peer_context.count++;
+ increment_stats (STAT_FIND_PEER_REPLY);
+ if (GNUNET_YES == consider_peer (&new_peer))
+ {
+ increment_stats (STAT_HELLOS_PROVIDED);
+ GNUNET_TRANSPORT_offer_hello (transport_handle, hello_msg, NULL, NULL);
+ GNUNET_CORE_peer_request_connect (coreAPI, &new_peer, NULL, NULL);
+ }
+ }
+ }
if (malicious_dropper == GNUNET_YES)
record = NULL;
else
record =
- GNUNET_CONTAINER_multihashmap_get (forward_list.hashmap, &msg_ctx->key);
+ GNUNET_CONTAINER_multihashmap_get (forward_list.hashmap,
&msg_ctx->key);
if (record == NULL) /* No record of this message! */
- {
+ {
#if DEBUG_DHT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "`%s:%s': Have no record of response key %s uid %llu\n",
- my_short_id, "DHT", GNUNET_h2s (&msg_ctx->key),
- msg_ctx->unique_id);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "`%s:%s': Have no record of response key %s uid %llu\n",
+ my_short_id, "DHT", GNUNET_h2s (&msg_ctx->key),
+ msg_ctx->unique_id);
#endif
#if DEBUG_DHT_ROUTING
- if ((debug_routes_extended) && (dhtlog_handle != NULL))
- {
- dhtlog_handle->insert_route (NULL,
- msg_ctx->unique_id,
- DHTLOG_RESULT,
- msg_ctx->hop_count,
- GNUNET_SYSERR,
- &my_identity,
- &msg_ctx->key, msg_ctx->peer, NULL);
- }
+ if ((debug_routes_extended) && (dhtlog_handle != NULL))
+ {
+ dhtlog_handle->insert_route (NULL,
+ msg_ctx->unique_id,
+ DHTLOG_RESULT,
+ msg_ctx->hop_count,
+ GNUNET_SYSERR,
+ &my_identity,
+ &msg_ctx->key, msg_ctx->peer, NULL);
+ }
#endif
- if (msg_ctx->bloom != NULL)
- {
- GNUNET_CONTAINER_bloomfilter_free (msg_ctx->bloom);
- msg_ctx->bloom = NULL;
- }
- return 0;
+ if (msg_ctx->bloom != NULL)
+ {
+ GNUNET_CONTAINER_bloomfilter_free (msg_ctx->bloom);
+ msg_ctx->bloom = NULL;
}
+ return 0;
+ }
pos = record->head;
while (pos != NULL)
+ {
+#if STRICT_FORWARDING
+ if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_DHT_FIND_PEER_RESULT) /* If
we have already forwarded this peer id, don't do it again! */
{
-#if STRICT_FORWARDING
- if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_DHT_FIND_PEER_RESULT)
/* If we have already forwarded this peer id, don't do it again! */
- {
- if (GNUNET_YES ==
- GNUNET_CONTAINER_bloomfilter_test (pos->find_peers_responded,
- &new_peer.hashPubKey))
- {
- increment_stats
- ("# find peer responses NOT forwarded (bloom match)");
- pos = pos->next;
- continue;
- }
- else
- GNUNET_CONTAINER_bloomfilter_add (pos->find_peers_responded,
- &new_peer.hashPubKey);
- }
+ if (GNUNET_YES ==
+ GNUNET_CONTAINER_bloomfilter_test (pos->find_peers_responded,
+ &new_peer.hashPubKey))
+ {
+ increment_stats ("# find peer responses NOT forwarded (bloom match)");
+ pos = pos->next;
+ continue;
+ }
+ else
+ GNUNET_CONTAINER_bloomfilter_add (pos->find_peers_responded,
+ &new_peer.hashPubKey);
+ }
#endif
- if (0 == memcmp (&pos->source, &my_identity, sizeof (struct
GNUNET_PeerIdentity))) /* Local client (or DHT) initiated request! */
- {
+ if (0 == memcmp (&pos->source, &my_identity, sizeof (struct
GNUNET_PeerIdentity))) /* Local client (or DHT) initiated request! */
+ {
#if DEBUG_DHT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "`%s:%s': Sending response key %s uid %llu to client\n",
- my_short_id, "DHT", GNUNET_h2s (&msg_ctx->key),
- msg_ctx->unique_id);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "`%s:%s': Sending response key %s uid %llu to client\n",
+ my_short_id, "DHT", GNUNET_h2s (&msg_ctx->key),
+ msg_ctx->unique_id);
#endif
#if DEBUG_DHT_ROUTING
- if ((debug_routes_extended) && (dhtlog_handle != NULL))
- {
- dhtlog_handle->insert_route (NULL, msg_ctx->unique_id,
- DHTLOG_RESULT, msg_ctx->hop_count,
- GNUNET_YES, &my_identity,
- &msg_ctx->key, msg_ctx->peer,
- NULL);
- }
+ if ((debug_routes_extended) && (dhtlog_handle != NULL))
+ {
+ dhtlog_handle->insert_route (NULL, msg_ctx->unique_id,
+ DHTLOG_RESULT, msg_ctx->hop_count,
+ GNUNET_YES, &my_identity,
+ &msg_ctx->key, msg_ctx->peer, NULL);
+ }
#endif
- increment_stats (STAT_RESULTS_TO_CLIENT);
- if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_DHT_GET_RESULT)
- increment_stats (STAT_GET_REPLY);
+ increment_stats (STAT_RESULTS_TO_CLIENT);
+ if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_DHT_GET_RESULT)
+ increment_stats (STAT_GET_REPLY);
#if DEBUG_DHT > 1
- for (i = 0; i < msg_ctx->path_history_len; i++)
- {
- char *path_offset;
+ for (i = 0; i < msg_ctx->path_history_len; i++)
+ {
+ char *path_offset;
- path_offset = &msg_ctx->path_history[i * sizeof(struct
GNUNET_PeerIdentity)];
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "(before client) Key %s Found peer %d:%s\n",
- GNUNET_h2s(&msg_ctx->key), i,
- GNUNET_i2s((struct GNUNET_PeerIdentity *)path_offset));
- }
+ path_offset =
+ &msg_ctx->path_history[i * sizeof (struct GNUNET_PeerIdentity)];
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "(before client) Key %s Found peer %d:%s\n",
+ GNUNET_h2s (&msg_ctx->key), i,
+ GNUNET_i2s ((struct GNUNET_PeerIdentity *) path_offset));
+ }
#endif
- send_reply_to_client (pos->client, msg, msg_ctx);
- }
- else /* Send to peer */
- {
- peer_info = find_peer_by_id (&pos->source);
- if (peer_info == NULL) /* Didn't find the peer in our routing
table, perhaps peer disconnected! */
- {
- pos = pos->next;
- continue;
- }
+ send_reply_to_client (pos->client, msg, msg_ctx);
+ }
+ else /* Send to peer */
+ {
+ peer_info = find_peer_by_id (&pos->source);
+ if (peer_info == NULL) /* Didn't find the peer in our routing table,
perhaps peer disconnected! */
+ {
+ pos = pos->next;
+ continue;
+ }
- if (msg_ctx->bloom == NULL)
- msg_ctx->bloom =
- GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE,
- DHT_BLOOM_K);
- GNUNET_CONTAINER_bloomfilter_add (msg_ctx->bloom,
- &my_identity.hashPubKey);
- if ((GNUNET_NO ==
- GNUNET_CONTAINER_bloomfilter_test (msg_ctx->bloom,
- &peer_info->id.hashPubKey)))
- {
+ if (msg_ctx->bloom == NULL)
+ msg_ctx->bloom =
+ GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE,
+ DHT_BLOOM_K);
+ GNUNET_CONTAINER_bloomfilter_add (msg_ctx->bloom,
+ &my_identity.hashPubKey);
+ if ((GNUNET_NO ==
+ GNUNET_CONTAINER_bloomfilter_test (msg_ctx->bloom,
+ &peer_info->id.hashPubKey)))
+ {
#if DEBUG_DHT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "`%s:%s': Forwarding response key %s uid %llu to
peer %s\n",
- my_short_id, "DHT", GNUNET_h2s (&msg_ctx->key),
- msg_ctx->unique_id, GNUNET_i2s (&peer_info->id));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "`%s:%s': Forwarding response key %s uid %llu to peer
%s\n",
+ my_short_id, "DHT", GNUNET_h2s (&msg_ctx->key),
+ msg_ctx->unique_id, GNUNET_i2s (&peer_info->id));
#endif
#if DEBUG_DHT_ROUTING
- if ((debug_routes_extended) && (dhtlog_handle != NULL))
- {
- dhtlog_handle->insert_route (NULL, msg_ctx->unique_id,
- DHTLOG_RESULT,
- msg_ctx->hop_count,
- GNUNET_NO, &my_identity,
- &msg_ctx->key, msg_ctx->peer,
- &pos->source);
- }
+ if ((debug_routes_extended) && (dhtlog_handle != NULL))
+ {
+ dhtlog_handle->insert_route (NULL, msg_ctx->unique_id,
+ DHTLOG_RESULT,
+ msg_ctx->hop_count,
+ GNUNET_NO, &my_identity,
+ &msg_ctx->key, msg_ctx->peer,
+ &pos->source);
+ }
#endif
- forward_result_message (msg, peer_info, msg_ctx);
- /* Try removing forward entries after sending once, only allows
ONE response per request */
- if (pos->delete_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (pos->delete_task);
- pos->delete_task =
- GNUNET_SCHEDULER_add_now (&remove_forward_entry, pos);
- }
- }
- else
- {
+ forward_result_message (msg, peer_info, msg_ctx);
+ /* Try removing forward entries after sending once, only allows ONE
response per request */
+ if (pos->delete_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (pos->delete_task);
+ pos->delete_task =
+ GNUNET_SCHEDULER_add_now (&remove_forward_entry, pos);
+ }
+ }
+ else
+ {
#if DEBUG_DHT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "`%s:%s': NOT Forwarding response (bloom match) key
%s uid %llu to peer %s\n",
- my_short_id, "DHT", GNUNET_h2s (&msg_ctx->key),
- msg_ctx->unique_id, GNUNET_i2s (&peer_info->id));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "`%s:%s': NOT Forwarding response (bloom match) key %s uid
%llu to peer %s\n",
+ my_short_id, "DHT", GNUNET_h2s (&msg_ctx->key),
+ msg_ctx->unique_id, GNUNET_i2s (&peer_info->id));
#endif
- }
- }
- pos = pos->next;
+ }
}
+ pos = pos->next;
+ }
if (msg_ctx->bloom != NULL)
- {
- GNUNET_CONTAINER_bloomfilter_free (msg_ctx->bloom);
- msg_ctx->bloom = NULL;
- }
+ {
+ GNUNET_CONTAINER_bloomfilter_free (msg_ctx->bloom);
+ msg_ctx->bloom = NULL;
+ }
return 0;
}
@@ -2309,6 +2333,7 @@
const struct DHTPutEntry *put_entry;
int get_size;
char *path_offset;
+
#if DEBUG_PATH
unsigned int i;
#endif
@@ -2319,114 +2344,129 @@
"DHT", "GET");
#endif
- put_entry = (const struct DHTPutEntry *)data;
+ put_entry = (const struct DHTPutEntry *) data;
- if (size != sizeof(struct DHTPutEntry) +
- put_entry->data_size +
- (put_entry->path_length * sizeof(struct GNUNET_PeerIdentity)))
- {
- GNUNET_log(
- GNUNET_ERROR_TYPE_WARNING,
- "Path + data size doesn't add up for data inserted into
datacache!\nData size %d, path length %d, expected %d, got %d\n",
- put_entry->data_size, put_entry->path_length,
- sizeof(struct DHTPutEntry) + put_entry->data_size
- + (put_entry->path_length * sizeof(struct GNUNET_PeerIdentity)),
- size);
- msg_ctx->do_forward = GNUNET_NO;
- return GNUNET_OK;
- }
+ if (size != sizeof (struct DHTPutEntry) +
+ put_entry->data_size +
+ (put_entry->path_length * sizeof (struct GNUNET_PeerIdentity)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Path + data size doesn't add up for data inserted into
datacache!\nData size %d, path length %d, expected %d, got %d\n",
+ put_entry->data_size, put_entry->path_length,
+ sizeof (struct DHTPutEntry) + put_entry->data_size
+ +
+ (put_entry->path_length * sizeof (struct GNUNET_PeerIdentity)),
+ size);
+ msg_ctx->do_forward = GNUNET_NO;
+ return GNUNET_OK;
+ }
- eval = GNUNET_BLOCK_evaluate (block_context,
- type,
- key,
- &msg_ctx->reply_bf,
- msg_ctx->reply_bf_mutator,
- msg_ctx->xquery,
- msg_ctx->xquery_size, &put_entry[1],
put_entry->data_size);
+ eval = GNUNET_BLOCK_evaluate (block_context,
+ type,
+ key,
+ &msg_ctx->reply_bf,
+ msg_ctx->reply_bf_mutator,
+ msg_ctx->xquery,
+ msg_ctx->xquery_size, &put_entry[1],
+ put_entry->data_size);
switch (eval)
+ {
+ case GNUNET_BLOCK_EVALUATION_OK_LAST:
+ msg_ctx->do_forward = GNUNET_NO;
+ case GNUNET_BLOCK_EVALUATION_OK_MORE:
+ new_msg_ctx = GNUNET_malloc (sizeof (struct DHT_MessageContext));
+ memcpy (new_msg_ctx, msg_ctx, sizeof (struct DHT_MessageContext));
+ if (GNUNET_DHT_RO_RECORD_ROUTE ==
+ (msg_ctx->msg_options & GNUNET_DHT_RO_RECORD_ROUTE))
{
- case GNUNET_BLOCK_EVALUATION_OK_LAST:
- msg_ctx->do_forward = GNUNET_NO;
- case GNUNET_BLOCK_EVALUATION_OK_MORE:
- new_msg_ctx = GNUNET_malloc (sizeof (struct DHT_MessageContext));
- memcpy (new_msg_ctx, msg_ctx, sizeof (struct DHT_MessageContext));
- if (GNUNET_DHT_RO_RECORD_ROUTE == (msg_ctx->msg_options &
GNUNET_DHT_RO_RECORD_ROUTE))
- {
- new_msg_ctx->msg_options = GNUNET_DHT_RO_RECORD_ROUTE;
- new_msg_ctx->path_history_len = msg_ctx->path_history_len;
- /* Assign to previous msg_ctx path history, caller should free after
our return */
- new_msg_ctx->path_history = msg_ctx->path_history;
+ new_msg_ctx->msg_options = GNUNET_DHT_RO_RECORD_ROUTE;
+ new_msg_ctx->path_history_len = msg_ctx->path_history_len;
+ /* Assign to previous msg_ctx path history, caller should free after our
return */
+ new_msg_ctx->path_history = msg_ctx->path_history;
#if DEBUG_PATH
- for (i = 0; i < new_msg_ctx->path_history_len; i++)
- {
- path_offset = &new_msg_ctx->path_history[i * sizeof(struct
GNUNET_PeerIdentity)];
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "(get_iterator) Key %s Found
peer %d:%s\n", GNUNET_h2s(&msg_ctx->key), i, GNUNET_i2s((struct
GNUNET_PeerIdentity *)path_offset));
- }
+ for (i = 0; i < new_msg_ctx->path_history_len; i++)
+ {
+ path_offset =
+ &new_msg_ctx->path_history[i * sizeof (struct
GNUNET_PeerIdentity)];
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "(get_iterator) Key %s Found peer %d:%s\n",
+ GNUNET_h2s (&msg_ctx->key), i,
+ GNUNET_i2s ((struct GNUNET_PeerIdentity *) path_offset));
+ }
#endif
- }
+ }
- get_size = sizeof (struct GNUNET_DHT_GetResultMessage) +
put_entry->data_size + (put_entry->path_length * sizeof(struct
GNUNET_PeerIdentity));
- get_result = GNUNET_malloc (get_size);
- get_result->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_GET_RESULT);
- get_result->header.size = htons (get_size);
- get_result->expiration = GNUNET_TIME_absolute_hton (exp);
- get_result->type = htons (type);
- get_result->put_path_length = htons(put_entry->path_length);
- path_offset = (char *)&put_entry[1];
- path_offset += put_entry->data_size;
+ get_size =
+ sizeof (struct GNUNET_DHT_GetResultMessage) + put_entry->data_size +
+ (put_entry->path_length * sizeof (struct GNUNET_PeerIdentity));
+ get_result = GNUNET_malloc (get_size);
+ get_result->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_GET_RESULT);
+ get_result->header.size = htons (get_size);
+ get_result->expiration = GNUNET_TIME_absolute_hton (exp);
+ get_result->type = htons (type);
+ get_result->put_path_length = htons (put_entry->path_length);
+ path_offset = (char *) &put_entry[1];
+ path_offset += put_entry->data_size;
#if DEBUG_PATH
- for (i = 0; i < put_entry->path_length; i++)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "(get_iterator PUT path) Key %s
Found peer %d:%s\n", GNUNET_h2s(&msg_ctx->key), i, GNUNET_i2s((struct
GNUNET_PeerIdentity *)&path_offset[i * sizeof(struct GNUNET_PeerIdentity)]));
- }
+ for (i = 0; i < put_entry->path_length; i++)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "(get_iterator PUT path) Key %s Found peer %d:%s\n",
+ GNUNET_h2s (&msg_ctx->key), i,
+ GNUNET_i2s ((struct GNUNET_PeerIdentity *)
+ &path_offset[i *
+ sizeof (struct
+ GNUNET_PeerIdentity)]));
+ }
#endif
- /* Copy the actual data and the path_history to the end of the get
result */
- memcpy (&get_result[1], &put_entry[1], put_entry->data_size +
(put_entry->path_length * sizeof(struct GNUNET_PeerIdentity)));
- new_msg_ctx->peer = &my_identity;
- new_msg_ctx->bloom =
+ /* Copy the actual data and the path_history to the end of the get result
*/
+ memcpy (&get_result[1], &put_entry[1],
+ put_entry->data_size +
+ (put_entry->path_length * sizeof (struct GNUNET_PeerIdentity)));
+ new_msg_ctx->peer = &my_identity;
+ new_msg_ctx->bloom =
GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K);
- new_msg_ctx->hop_count = 0;
- new_msg_ctx->importance = DHT_DEFAULT_P2P_IMPORTANCE + 2; /* Make result
routing a higher priority */
- new_msg_ctx->timeout = DHT_DEFAULT_P2P_TIMEOUT;
- increment_stats (STAT_GET_RESPONSE_START);
- route_result_message (&get_result->header, new_msg_ctx);
- GNUNET_free (new_msg_ctx);
- GNUNET_free (get_result);
- break;
- case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE:
+ new_msg_ctx->hop_count = 0;
+ new_msg_ctx->importance = DHT_DEFAULT_P2P_IMPORTANCE + 2; /* Make result
routing a higher priority */
+ new_msg_ctx->timeout = DHT_DEFAULT_P2P_TIMEOUT;
+ increment_stats (STAT_GET_RESPONSE_START);
+ route_result_message (&get_result->header, new_msg_ctx);
+ GNUNET_free (new_msg_ctx);
+ GNUNET_free (get_result);
+ break;
+ case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE:
#if DEBUG_DHT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "`%s:%s': Duplicate block error\n", my_short_id, "DHT");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "`%s:%s': Duplicate block error\n", my_short_id, "DHT");
#endif
- break;
- case GNUNET_BLOCK_EVALUATION_RESULT_INVALID:
+ break;
+ case GNUNET_BLOCK_EVALUATION_RESULT_INVALID:
#if DEBUG_DHT
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "`%s:%s': Invalid request error\n", my_short_id, "DHT");
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "`%s:%s': Invalid request error\n", my_short_id, "DHT");
#endif
- break;
- case GNUNET_BLOCK_EVALUATION_REQUEST_VALID:
+ break;
+ case GNUNET_BLOCK_EVALUATION_REQUEST_VALID:
#if DEBUG_DHT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "`%s:%s': Valid request, no results.\n", my_short_id,
- "DHT");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "`%s:%s': Valid request, no results.\n", my_short_id, "DHT");
#endif
- GNUNET_break (0);
- break;
- case GNUNET_BLOCK_EVALUATION_REQUEST_INVALID:
- GNUNET_break_op (0);
- msg_ctx->do_forward = GNUNET_NO;
- break;
- case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED:
+ GNUNET_break (0);
+ break;
+ case GNUNET_BLOCK_EVALUATION_REQUEST_INVALID:
+ GNUNET_break_op (0);
+ msg_ctx->do_forward = GNUNET_NO;
+ break;
+ case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED:
#if DEBUG_DHT
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "`%s:%s': Unsupported block type (%u) in response!\n",
- my_short_id, "DHT", type);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "`%s:%s': Unsupported block type (%u) in response!\n",
+ my_short_id, "DHT", type);
#endif
- /* msg_ctx->do_forward = GNUNET_NO; // not sure... */
- break;
- }
+ /* msg_ctx->do_forward = GNUNET_NO; // not sure... */
+ break;
+ }
return GNUNET_OK;
}
@@ -2465,40 +2505,40 @@
msize = ntohs (msg->size);
if (msize < sizeof (struct GNUNET_DHT_GetMessage))
- {
- GNUNET_break (0);
- return 0;
- }
+ {
+ GNUNET_break (0);
+ return 0;
+ }
get_msg = (const struct GNUNET_DHT_GetMessage *) msg;
bf_size = ntohs (get_msg->bf_size);
msg_ctx->xquery_size = ntohs (get_msg->xquery_size);
msg_ctx->reply_bf_mutator = get_msg->bf_mutator; /* FIXME: ntohl? */
if (msize !=
sizeof (struct GNUNET_DHT_GetMessage) + bf_size + msg_ctx->xquery_size)
- {
- GNUNET_break (0);
- return 0;
- }
+ {
+ GNUNET_break (0);
+ return 0;
+ }
end = (const char *) &get_msg[1];
if (msg_ctx->xquery_size == 0)
- {
- msg_ctx->xquery = NULL;
- }
+ {
+ msg_ctx->xquery = NULL;
+ }
else
- {
- msg_ctx->xquery = (const void *) end;
- end += msg_ctx->xquery_size;
- }
+ {
+ msg_ctx->xquery = (const void *) end;
+ end += msg_ctx->xquery_size;
+ }
if (bf_size == 0)
- {
- msg_ctx->reply_bf = NULL;
- }
+ {
+ msg_ctx->reply_bf = NULL;
+ }
else
- {
- msg_ctx->reply_bf = GNUNET_CONTAINER_bloomfilter_init (end,
- bf_size,
-
GNUNET_DHT_GET_BLOOMFILTER_K);
- }
+ {
+ msg_ctx->reply_bf = GNUNET_CONTAINER_bloomfilter_init (end,
+ bf_size,
+
GNUNET_DHT_GET_BLOOMFILTER_K);
+ }
type = (enum GNUNET_BLOCK_Type) ntohl (get_msg->type);
#if DEBUG_DHT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -2511,69 +2551,69 @@
results = 0;
#if HAVE_MALICIOUS
if (type == GNUNET_BLOCK_DHT_MALICIOUS_MESSAGE_TYPE)
- {
- GNUNET_CONTAINER_bloomfilter_free (msg_ctx->reply_bf);
- return results;
- }
+ {
+ GNUNET_CONTAINER_bloomfilter_free (msg_ctx->reply_bf);
+ return results;
+ }
#endif
msg_ctx->do_forward = GNUNET_YES;
if (datacache != NULL)
results
- = GNUNET_DATACACHE_get (datacache,
- &msg_ctx->key, type,
- &datacache_get_iterator, msg_ctx);
+ = GNUNET_DATACACHE_get (datacache,
+ &msg_ctx->key, type,
+ &datacache_get_iterator, msg_ctx);
#if DEBUG_DHT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"`%s:%s': Found %d results for `%s' request uid %llu\n",
my_short_id, "DHT", results, "GET", msg_ctx->unique_id);
#endif
if (results >= 1)
+ {
+#if DEBUG_DHT_ROUTING
+ if ((debug_routes) && (dhtlog_handle != NULL))
{
-#if DEBUG_DHT_ROUTING
- if ((debug_routes) && (dhtlog_handle != NULL))
- {
- dhtlog_handle->insert_query (NULL, msg_ctx->unique_id, DHTLOG_GET,
- msg_ctx->hop_count, GNUNET_YES,
- &my_identity, &msg_ctx->key);
- }
+ dhtlog_handle->insert_query (NULL, msg_ctx->unique_id, DHTLOG_GET,
+ msg_ctx->hop_count, GNUNET_YES,
+ &my_identity, &msg_ctx->key);
+ }
- if ((debug_routes_extended) && (dhtlog_handle != NULL))
- {
- dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE,
- msg_ctx->hop_count, GNUNET_YES,
- &my_identity, &msg_ctx->key,
- msg_ctx->peer, NULL);
- }
+ if ((debug_routes_extended) && (dhtlog_handle != NULL))
+ {
+ dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE,
+ msg_ctx->hop_count, GNUNET_YES,
+ &my_identity, &msg_ctx->key,
+ msg_ctx->peer, NULL);
+ }
#endif
- }
+ }
else
+ {
+ /* check query valid */
+ if (GNUNET_BLOCK_EVALUATION_REQUEST_INVALID
+ == GNUNET_BLOCK_evaluate (block_context,
+ type,
+ &msg_ctx->key,
+ &msg_ctx->reply_bf,
+ msg_ctx->reply_bf_mutator,
+ msg_ctx->xquery,
+ msg_ctx->xquery_size, NULL, 0))
{
- /* check query valid */
- if (GNUNET_BLOCK_EVALUATION_REQUEST_INVALID
- == GNUNET_BLOCK_evaluate (block_context,
- type,
- &msg_ctx->key,
- &msg_ctx->reply_bf,
- msg_ctx->reply_bf_mutator,
- msg_ctx->xquery,
- msg_ctx->xquery_size, NULL, 0))
- {
- GNUNET_break_op (0);
- msg_ctx->do_forward = GNUNET_NO;
- }
+ GNUNET_break_op (0);
+ msg_ctx->do_forward = GNUNET_NO;
}
+ }
if (msg_ctx->hop_count == 0) /* Locally initiated request */
+ {
+#if DEBUG_DHT_ROUTING
+ if ((debug_routes) && (dhtlog_handle != NULL))
{
-#if DEBUG_DHT_ROUTING
- if ((debug_routes) && (dhtlog_handle != NULL))
- {
- dhtlog_handle->insert_query (NULL, msg_ctx->unique_id, DHTLOG_GET,
- msg_ctx->hop_count, GNUNET_NO,
- &my_identity, &msg_ctx->key);
- }
+ dhtlog_handle->insert_query (NULL, msg_ctx->unique_id, DHTLOG_GET,
+ msg_ctx->hop_count, GNUNET_NO,
+ &my_identity, &msg_ctx->key);
+ }
#endif
- }
+ }
if (msg_ctx->do_forward == GNUNET_YES)
route_message (msg, msg_ctx);
GNUNET_CONTAINER_bloomfilter_free (msg_ctx->reply_bf);
@@ -2622,41 +2662,40 @@
other_hello = NULL;
other_hello_size = 0;
if (ntohs (find_msg->size) > sizeof (struct GNUNET_DHT_FindPeerMessage))
+ {
+ other_hello_size =
+ ntohs (find_msg->size) - sizeof (struct GNUNET_DHT_FindPeerMessage);
+ other_hello = GNUNET_malloc (other_hello_size);
+ memcpy (other_hello, &find_peer_message[1], other_hello_size);
+ if ((GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) other_hello) ==
+ 0)
+ || (GNUNET_OK !=
+ GNUNET_HELLO_get_id ((struct GNUNET_HELLO_Message *)
+ other_hello, &peer_id)))
{
- other_hello_size =
- ntohs (find_msg->size) - sizeof (struct GNUNET_DHT_FindPeerMessage);
- other_hello = GNUNET_malloc (other_hello_size);
- memcpy (other_hello, &find_peer_message[1], other_hello_size);
- if ((GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) other_hello) ==
- 0)
- || (GNUNET_OK !=
- GNUNET_HELLO_get_id ((struct GNUNET_HELLO_Message *)
- other_hello, &peer_id)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Received invalid HELLO message in find peer
request!\n");
- GNUNET_free (other_hello);
- return;
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Received invalid HELLO message in find peer request!\n");
+ GNUNET_free (other_hello);
+ return;
+ }
#if FIND_PEER_WITH_HELLO
- if (GNUNET_YES == consider_peer (&peer_id))
- {
- increment_stats (STAT_HELLOS_PROVIDED);
- GNUNET_TRANSPORT_offer_hello (transport_handle, other_hello, NULL,
NULL);
- GNUNET_CORE_peer_request_connect (coreAPI,
- &peer_id, NULL, NULL);
- route_message (find_msg, msg_ctx);
- GNUNET_free (other_hello);
- return;
- }
- else /* We don't want this peer! */
- {
- route_message (find_msg, msg_ctx);
- GNUNET_free (other_hello);
- return;
- }
+ if (GNUNET_YES == consider_peer (&peer_id))
+ {
+ increment_stats (STAT_HELLOS_PROVIDED);
+ GNUNET_TRANSPORT_offer_hello (transport_handle, other_hello, NULL, NULL);
+ GNUNET_CORE_peer_request_connect (coreAPI, &peer_id, NULL, NULL);
+ route_message (find_msg, msg_ctx);
+ GNUNET_free (other_hello);
+ return;
+ }
+ else /* We don't want this peer! */
+ {
+ route_message (find_msg, msg_ctx);
+ GNUNET_free (other_hello);
+ return;
+ }
#endif
- }
+ }
#if DEBUG_DHT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -2665,29 +2704,29 @@
ntohs (find_msg->size), sizeof (struct GNUNET_MessageHeader));
#endif
if (my_hello == NULL)
- {
+ {
#if DEBUG_DHT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "`%s': Our HELLO is null, can't return.\n", "DHT");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "`%s': Our HELLO is null, can't return.\n", "DHT");
#endif
- GNUNET_free_non_null (other_hello);
- route_message (find_msg, msg_ctx);
- return;
- }
+ GNUNET_free_non_null (other_hello);
+ route_message (find_msg, msg_ctx);
+ return;
+ }
incoming_bloom =
- GNUNET_CONTAINER_bloomfilter_init (find_peer_message->bloomfilter,
- DHT_BLOOM_SIZE, DHT_BLOOM_K);
+ GNUNET_CONTAINER_bloomfilter_init (find_peer_message->bloomfilter,
+ DHT_BLOOM_SIZE, DHT_BLOOM_K);
if (GNUNET_YES ==
GNUNET_CONTAINER_bloomfilter_test (incoming_bloom,
&my_identity.hashPubKey))
- {
- increment_stats (STAT_BLOOM_FIND_PEER);
- GNUNET_CONTAINER_bloomfilter_free (incoming_bloom);
- GNUNET_free_non_null (other_hello);
- route_message (find_msg, msg_ctx);
- return; /* We match the bloomfilter, do not send a
response to this peer (they likely already know us!) */
- }
+ {
+ increment_stats (STAT_BLOOM_FIND_PEER);
+ GNUNET_CONTAINER_bloomfilter_free (incoming_bloom);
+ GNUNET_free_non_null (other_hello);
+ route_message (find_msg, msg_ctx);
+ return; /* We match the bloomfilter, do not send a
response to this peer (they likely already know us!) */
+ }
GNUNET_CONTAINER_bloomfilter_free (incoming_bloom);
#if RESTRICT_FIND_PEER
@@ -2696,11 +2735,11 @@
* Ignore any find peer requests from a peer we have seen very recently.
*/
if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains
(recent_find_peer_requests, &msg_ctx->key)) /* We have recently responded to a
find peer request for this peer! */
- {
- increment_stats ("# dht find peer requests ignored (recently seen!)");
- GNUNET_free_non_null (other_hello);
- return;
- }
+ {
+ increment_stats ("# dht find peer requests ignored (recently seen!)");
+ GNUNET_free_non_null (other_hello);
+ return;
+ }
/**
* Use this check to only allow the peer to respond to find peer requests if
@@ -2712,12 +2751,12 @@
*/
memcpy (&peer_id.hashPubKey, &msg_ctx->key, sizeof (GNUNET_HashCode));
if (GNUNET_NO == consider_peer (&peer_id))
- {
- increment_stats ("# dht find peer requests ignored (do not need!)");
- GNUNET_free_non_null (other_hello);
- route_message (find_msg, msg_ctx);
- return;
- }
+ {
+ increment_stats ("# dht find peer requests ignored (do not need!)");
+ GNUNET_free_non_null (other_hello);
+ route_message (find_msg, msg_ctx);
+ return;
+ }
#endif
recent_hash = GNUNET_malloc (sizeof (GNUNET_HashCode));
@@ -2726,36 +2765,36 @@
GNUNET_CONTAINER_multihashmap_put (recent_find_peer_requests,
&msg_ctx->key, NULL,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
- {
+ {
#if DEBUG_DHT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Adding recent remove task for key `%s`!\n",
- GNUNET_h2s (&msg_ctx->key));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Adding recent remove task for key `%s`!\n",
+ GNUNET_h2s (&msg_ctx->key));
#endif
- /* Only add a task if there wasn't one for this key already! */
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS, 30),
- &remove_recent_find_peer, recent_hash);
- }
+ /* Only add a task if there wasn't one for this key already! */
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 30),
+ &remove_recent_find_peer, recent_hash);
+ }
else
- {
- GNUNET_free (recent_hash);
+ {
+ GNUNET_free (recent_hash);
#if DEBUG_DHT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received duplicate find peer request too soon!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received duplicate find peer request too soon!\n");
#endif
- }
+ }
/* Simplistic find_peer functionality, always return our hello */
hello_size = ntohs (my_hello->size);
tsize = hello_size + sizeof (struct GNUNET_MessageHeader);
if (tsize >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
- {
- GNUNET_break_op (0);
- GNUNET_free_non_null (other_hello);
- return;
- }
+ {
+ GNUNET_break_op (0);
+ GNUNET_free_non_null (other_hello);
+ return;
+ }
find_peer_result = GNUNET_malloc (tsize);
find_peer_result->type = htons (GNUNET_MESSAGE_TYPE_DHT_FIND_PEER_RESULT);
@@ -2771,27 +2810,28 @@
memcpy (new_msg_ctx, msg_ctx, sizeof (struct DHT_MessageContext));
new_msg_ctx->peer = &my_identity;
new_msg_ctx->bloom =
- GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K);
+ GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K);
new_msg_ctx->hop_count = 0;
new_msg_ctx->importance = DHT_DEFAULT_P2P_IMPORTANCE + 2; /* Make find
peer requests a higher priority */
new_msg_ctx->timeout = DHT_DEFAULT_P2P_TIMEOUT;
increment_stats (STAT_FIND_PEER_ANSWER);
- if (GNUNET_DHT_RO_RECORD_ROUTE == (msg_ctx->msg_options &
GNUNET_DHT_RO_RECORD_ROUTE))
- {
- new_msg_ctx->msg_options = GNUNET_DHT_RO_RECORD_ROUTE;
- new_msg_ctx->path_history_len = msg_ctx->path_history_len;
- /* Assign to previous msg_ctx path history, caller should free after our
return */
- new_msg_ctx->path_history = msg_ctx->path_history;
- }
+ if (GNUNET_DHT_RO_RECORD_ROUTE ==
+ (msg_ctx->msg_options & GNUNET_DHT_RO_RECORD_ROUTE))
+ {
+ new_msg_ctx->msg_options = GNUNET_DHT_RO_RECORD_ROUTE;
+ new_msg_ctx->path_history_len = msg_ctx->path_history_len;
+ /* Assign to previous msg_ctx path history, caller should free after our
return */
+ new_msg_ctx->path_history = msg_ctx->path_history;
+ }
route_result_message (find_peer_result, new_msg_ctx);
GNUNET_free (new_msg_ctx);
#if DEBUG_DHT_ROUTING
if ((debug_routes) && (dhtlog_handle != NULL))
- {
- dhtlog_handle->insert_query (NULL, msg_ctx->unique_id, DHTLOG_FIND_PEER,
- msg_ctx->hop_count, GNUNET_YES,
- &my_identity, &msg_ctx->key);
- }
+ {
+ dhtlog_handle->insert_query (NULL, msg_ctx->unique_id, DHTLOG_FIND_PEER,
+ msg_ctx->hop_count, GNUNET_YES,
+ &my_identity, &msg_ctx->key);
+ }
#endif
GNUNET_free_non_null (other_hello);
GNUNET_free (find_peer_result);
@@ -2834,58 +2874,58 @@
put_type = (enum GNUNET_BLOCK_Type) ntohl (put_msg->type);
#if HAVE_MALICIOUS
if (put_type == GNUNET_BLOCK_DHT_MALICIOUS_MESSAGE_TYPE)
+ {
+#if DEBUG_DHT_ROUTING
+ if ((debug_routes_extended) && (dhtlog_handle != NULL))
{
-#if DEBUG_DHT_ROUTING
- if ((debug_routes_extended) && (dhtlog_handle != NULL))
- {
/** Log routes that die due to high load! */
- dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE,
- msg_ctx->hop_count, GNUNET_SYSERR,
- &my_identity, &msg_ctx->key,
- msg_ctx->peer, NULL);
- }
-#endif
- return;
+ dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE,
+ msg_ctx->hop_count, GNUNET_SYSERR,
+ &my_identity, &msg_ctx->key,
+ msg_ctx->peer, NULL);
}
#endif
+ return;
+ }
+#endif
data_size =
- ntohs (put_msg->header.size) - sizeof (struct GNUNET_DHT_PutMessage);
+ ntohs (put_msg->header.size) - sizeof (struct GNUNET_DHT_PutMessage);
ret =
- GNUNET_BLOCK_get_key (block_context, put_type, &put_msg[1], data_size,
- &key);
+ GNUNET_BLOCK_get_key (block_context, put_type, &put_msg[1], data_size,
+ &key);
if (GNUNET_NO == ret)
+ {
+#if DEBUG_DHT_ROUTING
+ if ((debug_routes_extended) && (dhtlog_handle != NULL))
{
-#if DEBUG_DHT_ROUTING
- if ((debug_routes_extended) && (dhtlog_handle != NULL))
- {
- dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE,
- msg_ctx->hop_count, GNUNET_SYSERR,
- &my_identity, &msg_ctx->key,
- msg_ctx->peer, NULL);
- }
+ dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE,
+ msg_ctx->hop_count, GNUNET_SYSERR,
+ &my_identity, &msg_ctx->key,
+ msg_ctx->peer, NULL);
+ }
#endif
- /* invalid reply */
- GNUNET_break_op (0);
- return;
- }
+ /* invalid reply */
+ GNUNET_break_op (0);
+ return;
+ }
if ((GNUNET_YES == ret) &&
(0 != memcmp (&key, &msg_ctx->key, sizeof (GNUNET_HashCode))))
+ {
+#if DEBUG_DHT_ROUTING
+ if ((debug_routes_extended) && (dhtlog_handle != NULL))
{
-#if DEBUG_DHT_ROUTING
- if ((debug_routes_extended) && (dhtlog_handle != NULL))
- {
- dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE,
- msg_ctx->hop_count, GNUNET_SYSERR,
- &my_identity, &msg_ctx->key,
- msg_ctx->peer, NULL);
- }
+ dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE,
+ msg_ctx->hop_count, GNUNET_SYSERR,
+ &my_identity, &msg_ctx->key,
+ msg_ctx->peer, NULL);
+ }
#endif
- /* invalid wrapper: key mismatch! */
- GNUNET_break_op (0);
- return;
- }
+ /* invalid wrapper: key mismatch! */
+ GNUNET_break_op (0);
+ return;
+ }
/* ret == GNUNET_SYSERR means that there is no known relationship between
- data and the key, so we cannot check it */
+ * data and the key, so we cannot check it */
#if DEBUG_DHT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"`%s:%s': Received `%s' request (inserting data!), message type
%d, key %s, uid %llu\n",
@@ -2894,21 +2934,21 @@
#endif
#if DEBUG_DHT_ROUTING
if (msg_ctx->hop_count == 0) /* Locally initiated request */
+ {
+ if ((debug_routes) && (dhtlog_handle != NULL))
{
- if ((debug_routes) && (dhtlog_handle != NULL))
- {
- dhtlog_handle->insert_query (NULL, msg_ctx->unique_id, DHTLOG_PUT,
- msg_ctx->hop_count, GNUNET_NO,
- &my_identity, &msg_ctx->key);
- }
+ dhtlog_handle->insert_query (NULL, msg_ctx->unique_id, DHTLOG_PUT,
+ msg_ctx->hop_count, GNUNET_NO,
+ &my_identity, &msg_ctx->key);
}
+ }
#endif
if (msg_ctx->closest != GNUNET_YES)
- {
- route_message (msg, msg_ctx);
- return;
- }
+ {
+ route_message (msg, msg_ctx);
+ return;
+ }
#if DEBUG_DHT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -2919,54 +2959,57 @@
#if DEBUG_DHT_ROUTING
if ((debug_routes_extended) && (dhtlog_handle != NULL))
- {
- dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE,
- msg_ctx->hop_count, GNUNET_YES,
- &my_identity, &msg_ctx->key, msg_ctx->peer,
- NULL);
- }
+ {
+ dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE,
+ msg_ctx->hop_count, GNUNET_YES,
+ &my_identity, &msg_ctx->key, msg_ctx->peer,
+ NULL);
+ }
if ((debug_routes) && (dhtlog_handle != NULL))
- {
- dhtlog_handle->insert_query (NULL, msg_ctx->unique_id, DHTLOG_PUT,
- msg_ctx->hop_count, GNUNET_YES,
- &my_identity, &msg_ctx->key);
- }
+ {
+ dhtlog_handle->insert_query (NULL, msg_ctx->unique_id, DHTLOG_PUT,
+ msg_ctx->hop_count, GNUNET_YES,
+ &my_identity, &msg_ctx->key);
+ }
#endif
increment_stats (STAT_PUTS_INSERTED);
if (datacache != NULL)
+ {
+ /* Put size is actual data size plus struct overhead plus path length (if
any) */
+ put_size =
+ data_size + sizeof (struct DHTPutEntry) +
+ (msg_ctx->path_history_len * sizeof (struct GNUNET_PeerIdentity));
+ put_entry = GNUNET_malloc (put_size);
+ put_entry->data_size = data_size;
+ put_entry->path_length = msg_ctx->path_history_len;
+ /* Copy data to end of put entry */
+ memcpy (&put_entry[1], &put_msg[1], data_size);
+ if (msg_ctx->path_history_len > 0)
{
- /* Put size is actual data size plus struct overhead plus path length
(if any) */
- put_size = data_size + sizeof(struct DHTPutEntry) +
(msg_ctx->path_history_len * sizeof(struct GNUNET_PeerIdentity));
- put_entry = GNUNET_malloc(put_size);
- put_entry->data_size = data_size;
- put_entry->path_length = msg_ctx->path_history_len;
- /* Copy data to end of put entry */
- memcpy(&put_entry[1], &put_msg[1], data_size);
- if (msg_ctx->path_history_len > 0)
- {
- /* Copy path after data */
- path_offset = (char *)&put_entry[1];
- path_offset += data_size;
- memcpy(path_offset, msg_ctx->path_history, msg_ctx->path_history_len
* sizeof(struct GNUNET_PeerIdentity));
- }
+ /* Copy path after data */
+ path_offset = (char *) &put_entry[1];
+ path_offset += data_size;
+ memcpy (path_offset, msg_ctx->path_history,
+ msg_ctx->path_history_len * sizeof (struct GNUNET_PeerIdentity));
+ }
- ret = GNUNET_DATACACHE_put (datacache, &msg_ctx->key, put_size,
- (const char *) put_entry, put_type,
- GNUNET_TIME_absolute_ntoh
- (put_msg->expiration));
- GNUNET_free (put_entry);
+ ret = GNUNET_DATACACHE_put (datacache, &msg_ctx->key, put_size,
+ (const char *) put_entry, put_type,
+ GNUNET_TIME_absolute_ntoh
+ (put_msg->expiration));
+ GNUNET_free (put_entry);
- if ((ret == GNUNET_YES) && (do_republish == GNUNET_YES))
- {
- put_context = GNUNET_malloc (sizeof (struct RepublishContext));
- memcpy (&put_context->key, &msg_ctx->key, sizeof (GNUNET_HashCode));
- put_context->type = put_type;
- GNUNET_SCHEDULER_add_delayed (dht_republish_frequency,
- &republish_content, put_context);
- }
+ if ((ret == GNUNET_YES) && (do_republish == GNUNET_YES))
+ {
+ put_context = GNUNET_malloc (sizeof (struct RepublishContext));
+ memcpy (&put_context->key, &msg_ctx->key, sizeof (GNUNET_HashCode));
+ put_context->type = put_type;
+ GNUNET_SCHEDULER_add_delayed (dht_republish_frequency,
+ &republish_content, put_context);
}
+ }
else
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"`%s:%s': %s request received, but have no datacache!\n",
@@ -3027,70 +3070,75 @@
* but then only send to 1 or 0 peers based strictly on the number of hops.
*/
if (strict_kademlia == GNUNET_YES)
- {
- if (hop_count == 0)
- return kademlia_replication;
- else if (hop_count < max_hops)
- return 1;
- else
- return 0;
- }
+ {
+ if (hop_count == 0)
+ return kademlia_replication;
+ else if (hop_count < max_hops)
+ return 1;
+ else
+ return 0;
+ }
/* FIXME: the smaller we think the network is the more lenient we should be
for
* routing right? The estimation below only works if we think we have
reasonably
* full routing tables, which for our RR topologies may not be the case!
*/
if (hop_count > max_hops)
- {
+ {
#if DEBUG_DHT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "`%s:%s': Hop count too high (est %d, lowest %d), NOT
Forwarding request\n",
- my_short_id, "DHT", estimate_diameter (), lowest_bucket);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "`%s:%s': Hop count too high (est %d, lowest %d), NOT
Forwarding request\n",
+ my_short_id, "DHT", estimate_diameter (), lowest_bucket);
#endif
- /* FIXME: does this work as intended, isn't the decision to forward or
not made based on closeness as well? */
- if (GNUNET_YES == paper_forwarding) /* Once we have reached our ideal
number of hops, don't stop forwarding! */
- {
- return 1;
- }
-
- return 0;
+ /* FIXME: does this work as intended, isn't the decision to forward or not
made based on closeness as well? */
+ if (GNUNET_YES == paper_forwarding) /* Once we have reached our ideal
number of hops, don't stop forwarding! */
+ {
+ return 1;
}
-
+
+ return 0;
+ }
+
if (GNUNET_YES == paper_forwarding)
+ {
+ /* FIXME: re-run replication trials with this formula */
+ target_value = 1 + (target_replication - 1.0) / (diameter
+ +
+ ((float)
+ (target_replication -
+ 1.0) * hop_count));
+ /* Set forward count to floor of target_value */
+ forward_count = (unsigned int) 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_STRONG,
+ UINT32_MAX);
+
+ if (random_value < (target_value * UINT32_MAX))
+ forward_count += 1;
+ }
+ else
+ {
+ random_value = 0;
+ forward_count = 1;
+ target_value = target_replication / (diameter
+ +
+ ((float) target_replication *
+ hop_count));
+ if (target_value > 1)
{
- /* FIXME: re-run replication trials with this formula */
- target_value = 1 + (target_replication - 1.0) / (diameter
- + ((float) (target_replication - 1.0) * hop_count));
/* Set forward count to floor of target_value */
forward_count = (unsigned int) 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_STRONG,
- UINT32_MAX);
-
- if (random_value < (target_value * UINT32_MAX))
- forward_count += 1;
}
- else
- {
- random_value = 0;
- forward_count = 1;
- target_value = target_replication / (diameter
- + ((float) target_replication * hop_count));
- if (target_value > 1)
- {
- /* Set forward count to floor of target_value */
- forward_count = (unsigned int) target_value;
- /* Subtract forward_count (floor) from target_value (yields value
between 0 and 1) */
- target_value = target_value - forward_count;
- }
- else
- random_value = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG,
- UINT32_MAX);
+ else
+ random_value = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG,
+ UINT32_MAX);
- if (random_value < (target_value * UINT32_MAX))
- forward_count += 1;
- }
+ if (random_value < (target_value * UINT32_MAX))
+ forward_count += 1;
+ }
return forward_count;
}
@@ -3127,28 +3175,27 @@
pos = k_buckets[bucket_num].head;
count = 0;
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; /* Skip already checked entries */
- }
+ pos = pos->next;
+ continue; /* Skip already checked entries */
+ }
- other_bits =
- GNUNET_CRYPTO_hash_matching_bits (&pos->id.hashPubKey, target);
- if (other_bits > bits)
+ other_bits = GNUNET_CRYPTO_hash_matching_bits (&pos->id.hashPubKey,
target);
+ if (other_bits > bits)
+ return GNUNET_NO;
+ else if (other_bits == bits) /* We match the same number of bits */
+ {
+ if (strict_kademlia != GNUNET_YES) /* Return that we at as close
as any other peer */
+ return GNUNET_YES;
+ else if (distance (&pos->id.hashPubKey, target) < my_distance) /*
Check all known peers, only return if we are the true closest */
return GNUNET_NO;
- else if (other_bits == bits) /* We match the same number of bits */
- {
- if (strict_kademlia != GNUNET_YES) /* Return that we at as close
as any other peer */
- return GNUNET_YES;
- else if (distance (&pos->id.hashPubKey, target) < my_distance)
/* Check all known peers, only return if we are the true closest */
- return GNUNET_NO;
- }
- pos = pos->next;
}
+ pos = pos->next;
+ }
/* No peers closer, we are the closest! */
return GNUNET_YES;
@@ -3188,42 +3235,42 @@
if (converge_modifier > 0)
temp_modifier = converge_modifier * base_converge_modifier;
else
- {
- temp_modifier = base_converge_modifier;
- base_converge_modifier = 0.0;
- }
+ {
+ temp_modifier = base_converge_modifier;
+ base_converge_modifier = 0.0;
+ }
GNUNET_assert (temp_modifier > 0);
other_matching_bits =
- GNUNET_CRYPTO_hash_matching_bits (target, &peer->id.hashPubKey);
+ GNUNET_CRYPTO_hash_matching_bits (target, &peer->id.hashPubKey);
switch (converge_option)
- {
- case DHT_CONVERGE_RANDOM:
- return 1; /* Always return 1, choose equally among all
peers */
- case DHT_CONVERGE_LINEAR:
- calc_value = hops * curr_max_hops * temp_modifier;
- break;
- case DHT_CONVERGE_SQUARE:
+ {
+ case DHT_CONVERGE_RANDOM:
+ return 1; /* Always return 1, choose equally among all
peers */
+ case DHT_CONVERGE_LINEAR:
+ calc_value = hops * curr_max_hops * temp_modifier;
+ break;
+ case DHT_CONVERGE_SQUARE:
/**
* Simple square based curve.
*/
- calc_value =
+ calc_value =
(sqrt (hops) / sqrt (curr_max_hops)) * (curr_max_hops /
(curr_max_hops *
temp_modifier));
- break;
- case DHT_CONVERGE_EXPONENTIAL:
+ break;
+ case DHT_CONVERGE_EXPONENTIAL:
/**
* Simple exponential curve.
*/
- if (base_converge_modifier > 0)
- calc_value = (temp_modifier * hops * hops) / curr_max_hops;
- else
- calc_value = (hops * hops) / curr_max_hops;
- break;
- case DHT_CONVERGE_BINARY:
+ if (base_converge_modifier > 0)
+ calc_value = (temp_modifier * hops * hops) / curr_max_hops;
+ else
+ calc_value = (hops * hops) / curr_max_hops;
+ break;
+ case DHT_CONVERGE_BINARY:
/**
* If below the cutoff, route randomly (return 1),
* If above the cutoff, return the maximum possible
@@ -3231,14 +3278,14 @@
* they are sorted.)
*/
- if (hops >= converge_modifier) /* Past cutoff */
- {
- return ULLONG_MAX;
- }
- /* Fall through */
- default:
- return 1;
+ if (hops >= converge_modifier) /* Past cutoff */
+ {
+ return ULLONG_MAX;
}
+ /* Fall through */
+ default:
+ return 1;
+ }
/* Take the log (base e) of the number of bits matching the other peer */
exponent = log (other_matching_bits);
@@ -3253,15 +3300,15 @@
ret = (unsigned long long) pow (other_matching_bits, calc_value);
if ((errno != 0) || fetestexcept (FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW |
FE_UNDERFLOW))
- {
- if (0 != fetestexcept (FE_OVERFLOW))
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "FE_OVERFLOW\n");
- if (0 != fetestexcept (FE_INVALID))
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "FE_INVALID\n");
- if (0 != fetestexcept (FE_UNDERFLOW))
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "FE_UNDERFLOW\n");
- return 0;
- }
+ {
+ if (0 != fetestexcept (FE_OVERFLOW))
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "FE_OVERFLOW\n");
+ if (0 != fetestexcept (FE_INVALID))
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "FE_INVALID\n");
+ if (0 != fetestexcept (FE_UNDERFLOW))
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "FE_UNDERFLOW\n");
+ return 0;
+ }
else
return ret;
}
@@ -3322,6 +3369,7 @@
unsigned long long temp_converge_distance;
unsigned long long total_distance;
unsigned long long selected;
+
#if DEBUG_DHT > 1
unsigned long long stats_total_distance;
double sum;
@@ -3334,44 +3382,42 @@
total_distance = 0;
/** If we are doing kademlia routing, or converge is binary (saves some
cycles) */
if ((strict_kademlia == GNUNET_YES) ||
- ((converge_option == DHT_CONVERGE_BINARY)
- && (hops >= converge_modifier)))
+ ((converge_option == DHT_CONVERGE_BINARY) && (hops >=
converge_modifier)))
+ {
+ largest_distance = 0;
+ chosen = NULL;
+ for (bc = lowest_bucket; bc < MAX_BUCKETS; bc++)
{
- largest_distance = 0;
- chosen = NULL;
- for (bc = lowest_bucket; bc < MAX_BUCKETS; bc++)
+ pos = k_buckets[bc].head;
+ count = 0;
+ while ((pos != NULL) && (count < bucket_size))
+ {
+ /* If we are doing strict Kademlia routing, then checking the
bloomfilter is basically cheating! */
+ if (GNUNET_NO ==
+ GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey))
{
- pos = k_buckets[bc].head;
- count = 0;
- while ((pos != NULL) && (count < bucket_size))
- {
- /* If we are doing strict Kademlia routing, then checking the
bloomfilter is basically cheating! */
- if (GNUNET_NO ==
- GNUNET_CONTAINER_bloomfilter_test (bloom,
- &pos->id.hashPubKey))
- {
- distance = inverse_distance (target, &pos->id.hashPubKey);
- if (distance > largest_distance)
- {
- chosen = pos;
- largest_distance = distance;
- }
- }
- count++;
- pos = pos->next;
- }
+ distance = inverse_distance (target, &pos->id.hashPubKey);
+ if (distance > largest_distance)
+ {
+ chosen = pos;
+ largest_distance = distance;
+ }
}
+ count++;
+ pos = pos->next;
+ }
+ }
- if ((largest_distance > 0) && (chosen != NULL))
- {
- GNUNET_CONTAINER_bloomfilter_add (bloom, &chosen->id.hashPubKey);
- return chosen;
- }
- else
- {
- return NULL;
- }
+ if ((largest_distance > 0) && (chosen != NULL))
+ {
+ GNUNET_CONTAINER_bloomfilter_add (bloom, &chosen->id.hashPubKey);
+ return chosen;
}
+ else
+ {
+ return NULL;
+ }
+ }
/* GNUnet-style */
total_distance = 0;
@@ -3388,21 +3434,21 @@
memset (sorted_closest, 0, sizeof (sorted_closest));
/* Put any peers in the closest bucket in the sorting array */
while ((pos != NULL) && (count < bucket_size))
+ {
+ if (GNUNET_YES ==
+ GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey))
{
- if (GNUNET_YES ==
- GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey))
- {
- count++;
- pos = pos->next;
- continue; /* Ignore bloomfiltered peers */
- }
- pos->matching_bits =
- GNUNET_CRYPTO_hash_matching_bits (&pos->id.hashPubKey, target);
- sorted_closest[offset] = pos;
+ count++;
pos = pos->next;
- offset++;
- count++;
+ continue; /* Ignore bloomfiltered peers */
}
+ pos->matching_bits =
+ GNUNET_CRYPTO_hash_matching_bits (&pos->id.hashPubKey, target);
+ sorted_closest[offset] = pos;
+ pos = pos->next;
+ offset++;
+ count++;
+ }
/* Sort the peers in descending order */
qsort (&sorted_closest[0], offset, sizeof (struct PeerInfo *),
@@ -3410,73 +3456,72 @@
/* Put the sorted closest peers into the possible bins first, in case of
overflow. */
for (i = 0; i < offset; i++)
+ {
+ temp_converge_distance =
+ converge_distance (target, sorted_closest[i], hops);
+ if (GNUNET_YES ==
+ GNUNET_CONTAINER_bloomfilter_test (bloom,
+ &sorted_closest[i]->id.hashPubKey))
+ break; /* Ignore bloomfiltered peers */
+ if (total_distance + temp_converge_distance > total_distance) /*
Handle largest case and overflow */
+ total_distance += temp_converge_distance;
+ else
+ break; /* overflow case */
+ }
+
+ /* Now handle peers in lower buckets (matches same # of bits as target) */
+ for (bc = lowest_bucket; bc < closest_bucket; bc++)
+ {
+ pos = k_buckets[bc].head;
+ count = 0;
+ while ((pos != NULL) && (count < bucket_size))
{
- temp_converge_distance =
- converge_distance (target, sorted_closest[i], hops);
if (GNUNET_YES ==
- GNUNET_CONTAINER_bloomfilter_test (bloom,
- &sorted_closest[i]->id.
- hashPubKey))
- break; /* Ignore bloomfiltered peers */
- if (total_distance + temp_converge_distance > total_distance) /* Handle
largest case and overflow */
+ GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey))
+ {
+ count++;
+ pos = pos->next;
+ continue; /* Ignore bloomfiltered peers */
+ }
+ temp_converge_distance = converge_distance (target, pos, hops);
+ if (total_distance + temp_converge_distance > total_distance) /*
Handle largest case and overflow */
total_distance += temp_converge_distance;
else
break; /* overflow case */
+ pos = pos->next;
+ count++;
}
+ }
- /* Now handle peers in lower buckets (matches same # of bits as target) */
- for (bc = lowest_bucket; bc < closest_bucket; bc++)
- {
- pos = k_buckets[bc].head;
- count = 0;
- while ((pos != NULL) && (count < bucket_size))
- {
- if (GNUNET_YES ==
- GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey))
- {
- count++;
- pos = pos->next;
- continue; /* Ignore bloomfiltered peers */
- }
- temp_converge_distance = converge_distance (target, pos, hops);
- if (total_distance + temp_converge_distance > total_distance) /*
Handle largest case and overflow */
- total_distance += temp_converge_distance;
- else
- break; /* overflow case */
- pos = pos->next;
- count++;
- }
- }
-
/* Now handle all the further away peers */
for (bc = closest_bucket + 1; bc < MAX_BUCKETS; bc++)
+ {
+ pos = k_buckets[bc].head;
+ count = 0;
+ while ((pos != NULL) && (count < bucket_size))
{
- pos = k_buckets[bc].head;
- count = 0;
- while ((pos != NULL) && (count < bucket_size))
- {
- if (GNUNET_YES ==
- GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey))
- {
- count++;
- pos = pos->next;
- continue; /* Ignore bloomfiltered peers */
- }
- temp_converge_distance = converge_distance (target, pos, hops);
- if (total_distance + temp_converge_distance > total_distance) /*
Handle largest case and overflow */
- total_distance += temp_converge_distance;
- else
- break; /* overflow case */
- pos = pos->next;
- count++;
- }
+ if (GNUNET_YES ==
+ GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey))
+ {
+ count++;
+ pos = pos->next;
+ continue; /* Ignore bloomfiltered peers */
+ }
+ temp_converge_distance = converge_distance (target, pos, hops);
+ if (total_distance + temp_converge_distance > total_distance) /*
Handle largest case and overflow */
+ total_distance += temp_converge_distance;
+ else
+ break; /* overflow case */
+ pos = pos->next;
+ count++;
}
+ }
if (total_distance == 0) /* No peers to select from! */
- {
- increment_stats ("# failed to select peer");
- return NULL;
- }
+ {
+ increment_stats ("# failed to select peer");
+ return NULL;
+ }
#if DEBUG_DHT_ROUTING > 1
sum = 0.0;
@@ -3484,164 +3529,160 @@
/* Put the sorted closest peers into the possible bins first, in case of
overflow. */
stats_total_distance = 0;
for (i = 0; i < offset; i++)
+ {
+ if (GNUNET_YES ==
+ GNUNET_CONTAINER_bloomfilter_test (bloom,
+ &sorted_closest[i]->id.hashPubKey))
+ break; /* Ignore bloomfiltered peers */
+ temp_converge_distance =
+ converge_distance (target, sorted_closest[i], hops);
+ if (stats_total_distance + temp_converge_distance > stats_total_distance)
/* Handle largest case and overflow */
+ stats_total_distance += temp_converge_distance;
+ else
+ break; /* overflow case */
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Choose %d matching bits (%d bits match me) (%.2f percent)
converge ret %llu\n",
+ GNUNET_CRYPTO_hash_matching_bits (&sorted_closest[i]->id.
+ hashPubKey, target),
+ GNUNET_CRYPTO_hash_matching_bits (&sorted_closest[i]->id.
+ hashPubKey,
+ &my_identity.hashPubKey),
+ (temp_converge_distance / (double) total_distance) * 100,
+ temp_converge_distance);
+ }
+
+ /* Now handle peers in lower buckets (matches same # of bits as target) */
+ for (bc = lowest_bucket; bc < closest_bucket; bc++)
+ {
+ pos = k_buckets[bc].head;
+ count = 0;
+ while ((pos != NULL) && (count < bucket_size))
{
if (GNUNET_YES ==
- GNUNET_CONTAINER_bloomfilter_test (bloom,
- &sorted_closest[i]->id.
- hashPubKey))
- break; /* Ignore bloomfiltered peers */
- temp_converge_distance =
- converge_distance (target, sorted_closest[i], hops);
- if (stats_total_distance + temp_converge_distance >
stats_total_distance) /* Handle largest case and overflow */
+ GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey))
+ {
+ count++;
+ pos = pos->next;
+ continue; /* Ignore bloomfiltered peers */
+ }
+ temp_converge_distance = converge_distance (target, pos, hops);
+ if (stats_total_distance + temp_converge_distance >
stats_total_distance) /* Handle largest case and overflow */
stats_total_distance += temp_converge_distance;
else
break; /* overflow case */
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Choose %d matching bits (%d bits match me) (%.2f percent)
converge ret %llu\n",
- GNUNET_CRYPTO_hash_matching_bits (&sorted_closest[i]->id.
- hashPubKey, target),
- GNUNET_CRYPTO_hash_matching_bits (&sorted_closest[i]->id.
- hashPubKey,
+ GNUNET_CRYPTO_hash_matching_bits (&pos->id.hashPubKey,
+ target),
+ GNUNET_CRYPTO_hash_matching_bits (&pos->id.hashPubKey,
&my_identity.hashPubKey),
- (temp_converge_distance / (double) total_distance) * 100,
- temp_converge_distance);
+ (temp_converge_distance / (double) total_distance) *
+ 100, temp_converge_distance);
+ pos = pos->next;
+ count++;
}
+ }
- /* Now handle peers in lower buckets (matches same # of bits as target) */
- for (bc = lowest_bucket; bc < closest_bucket; bc++)
- {
- pos = k_buckets[bc].head;
- count = 0;
- while ((pos != NULL) && (count < bucket_size))
- {
- if (GNUNET_YES ==
- GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey))
- {
- count++;
- pos = pos->next;
- continue; /* Ignore bloomfiltered peers */
- }
- temp_converge_distance = converge_distance (target, pos, hops);
- if (stats_total_distance + temp_converge_distance >
stats_total_distance) /* Handle largest case and overflow */
- stats_total_distance += temp_converge_distance;
- else
- break; /* overflow case */
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Choose %d matching bits (%d bits match me) (%.2f
percent) converge ret %llu\n",
- GNUNET_CRYPTO_hash_matching_bits (&pos->id.hashPubKey,
- target),
- GNUNET_CRYPTO_hash_matching_bits (&pos->id.hashPubKey,
- &my_identity.
- hashPubKey),
- (temp_converge_distance / (double) total_distance) *
- 100, temp_converge_distance);
- pos = pos->next;
- count++;
- }
- }
-
/* Now handle all the further away peers */
for (bc = closest_bucket + 1; bc < MAX_BUCKETS; bc++)
+ {
+ pos = k_buckets[bc].head;
+ count = 0;
+ while ((pos != NULL) && (count < bucket_size))
{
- pos = k_buckets[bc].head;
- count = 0;
- while ((pos != NULL) && (count < bucket_size))
- {
- if (GNUNET_YES ==
- GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey))
- {
- count++;
- pos = pos->next;
- continue; /* Ignore bloomfiltered peers */
- }
- temp_converge_distance = converge_distance (target, pos, hops);
- if (stats_total_distance + temp_converge_distance >
stats_total_distance) /* Handle largest case and overflow */
- stats_total_distance += temp_converge_distance;
- else
- break; /* overflow case */
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Choose %d matching bits (%d bits match me) (%.2f
percent) converge ret %llu\n",
- GNUNET_CRYPTO_hash_matching_bits (&pos->id.hashPubKey,
- target),
- GNUNET_CRYPTO_hash_matching_bits (&pos->id.hashPubKey,
- &my_identity.
- hashPubKey),
- (temp_converge_distance / (double) total_distance) *
- 100, temp_converge_distance);
- pos = pos->next;
- count++;
- }
+ if (GNUNET_YES ==
+ GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey))
+ {
+ count++;
+ pos = pos->next;
+ continue; /* Ignore bloomfiltered peers */
+ }
+ temp_converge_distance = converge_distance (target, pos, hops);
+ if (stats_total_distance + temp_converge_distance >
stats_total_distance) /* Handle largest case and overflow */
+ stats_total_distance += temp_converge_distance;
+ else
+ break; /* overflow case */
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Choose %d matching bits (%d bits match me) (%.2f percent)
converge ret %llu\n",
+ GNUNET_CRYPTO_hash_matching_bits (&pos->id.hashPubKey,
+ target),
+ GNUNET_CRYPTO_hash_matching_bits (&pos->id.hashPubKey,
+ &my_identity.hashPubKey),
+ (temp_converge_distance / (double) total_distance) *
+ 100, temp_converge_distance);
+ pos = pos->next;
+ count++;
}
+ }
/* END PRINT STATS */
#endif
/* Now actually choose a peer */
selected =
- GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, total_distance);
+ GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, total_distance);
/* Go over closest sorted peers. */
for (i = 0; i < offset; i++)
+ {
+ if (GNUNET_YES ==
+ GNUNET_CONTAINER_bloomfilter_test (bloom,
+ &sorted_closest[i]->id.hashPubKey))
+ break; /* Ignore bloomfiltered peers */
+ temp_converge_distance =
+ converge_distance (target, sorted_closest[i], hops);
+ if (temp_converge_distance >= selected)
+ return sorted_closest[i];
+ else
+ selected -= temp_converge_distance;
+ }
+
+ /* Now handle peers in lower buckets (matches same # of bits as target) */
+ for (bc = lowest_bucket; bc < closest_bucket; bc++)
+ {
+ pos = k_buckets[bc].head;
+ count = 0;
+ while ((pos != NULL) && (count < bucket_size))
{
if (GNUNET_YES ==
- GNUNET_CONTAINER_bloomfilter_test (bloom,
- &sorted_closest[i]->id.
- hashPubKey))
- break; /* Ignore bloomfiltered peers */
- temp_converge_distance =
- converge_distance (target, sorted_closest[i], hops);
+ GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey))
+ {
+ count++;
+ pos = pos->next;
+ continue; /* Ignore bloomfiltered peers */
+ }
+ temp_converge_distance = converge_distance (target, pos, hops);
if (temp_converge_distance >= selected)
- return sorted_closest[i];
+ return pos;
else
selected -= temp_converge_distance;
+ pos = pos->next;
+ count++;
}
+ }
- /* Now handle peers in lower buckets (matches same # of bits as target) */
- for (bc = lowest_bucket; bc < closest_bucket; bc++)
- {
- pos = k_buckets[bc].head;
- count = 0;
- while ((pos != NULL) && (count < bucket_size))
- {
- if (GNUNET_YES ==
- GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey))
- {
- count++;
- pos = pos->next;
- continue; /* Ignore bloomfiltered peers */
- }
- temp_converge_distance = converge_distance (target, pos, hops);
- if (temp_converge_distance >= selected)
- return pos;
- else
- selected -= temp_converge_distance;
- pos = pos->next;
- count++;
- }
- }
-
/* Now handle all the further away peers */
for (bc = closest_bucket + 1; bc < MAX_BUCKETS; bc++)
+ {
+ pos = k_buckets[bc].head;
+ count = 0;
+ while ((pos != NULL) && (count < bucket_size))
{
- pos = k_buckets[bc].head;
- count = 0;
- while ((pos != NULL) && (count < bucket_size))
- {
- if (GNUNET_YES ==
- GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey))
- {
- count++;
- pos = pos->next;
- continue; /* Ignore bloomfiltered peers */
- }
- temp_converge_distance = converge_distance (target, pos, hops);
- if (temp_converge_distance >= selected)
- return pos;
- else
- selected -= temp_converge_distance;
- pos = pos->next;
- count++;
- }
+ if (GNUNET_YES ==
+ GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey))
+ {
+ count++;
+ pos = pos->next;
+ continue; /* Ignore bloomfiltered peers */
+ }
+ temp_converge_distance = converge_distance (target, pos, hops);
+ if (temp_converge_distance >= selected)
+ return pos;
+ else
+ selected -= temp_converge_distance;
+ pos = pos->next;
+ count++;
}
+ }
increment_stats ("# failed to select peer");
return NULL;
@@ -3671,11 +3712,11 @@
GNUNET_free (req);
/*
- if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) && (0 ==
GNUNET_CONTAINER_multihashmap_size(recent.hashmap)) && (0 ==
GNUNET_CONTAINER_heap_get_size(recent.minHeap)))
- {
- GNUNET_CONTAINER_multihashmap_destroy(recent.hashmap);
- GNUNET_CONTAINER_heap_destroy(recent.minHeap);
- }
+ * if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) && (0 ==
GNUNET_CONTAINER_multihashmap_size(recent.hashmap)) && (0 ==
GNUNET_CONTAINER_heap_get_size(recent.minHeap)))
+ * {
+ * GNUNET_CONTAINER_multihashmap_destroy(recent.hashmap);
+ * GNUNET_CONTAINER_heap_destroy(recent.minHeap);
+ * }
*/
}
@@ -3701,29 +3742,28 @@
#if DELETE_WHEN_FULL
while (current_size >= MAX_OUTSTANDING_FORWARDS)
+ {
+ source_info = GNUNET_CONTAINER_heap_remove_root (forward_list.minHeap);
+ GNUNET_assert (source_info != NULL);
+ record = source_info->record;
+ GNUNET_CONTAINER_DLL_remove (record->head, record->tail, source_info);
+ if (record->head == NULL) /* No more entries in DLL */
{
- source_info = GNUNET_CONTAINER_heap_remove_root (forward_list.minHeap);
- GNUNET_assert (source_info != NULL);
- record = source_info->record;
- GNUNET_CONTAINER_DLL_remove (record->head, record->tail, source_info);
- if (record->head == NULL) /* No more entries in DLL */
- {
- GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove
- (forward_list.hashmap, &record->key, record));
- GNUNET_free (record);
- }
- if (source_info->delete_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (source_info->delete_task);
- source_info->delete_task = GNUNET_SCHEDULER_NO_TASK;
- }
- if (source_info->find_peers_responded != NULL)
- GNUNET_CONTAINER_bloomfilter_free (source_info->find_peers_responded);
- GNUNET_free (source_info);
- current_size =
- GNUNET_CONTAINER_multihashmap_size (forward_list.hashmap);
+ GNUNET_assert (GNUNET_YES ==
+ GNUNET_CONTAINER_multihashmap_remove
+ (forward_list.hashmap, &record->key, record));
+ GNUNET_free (record);
}
+ if (source_info->delete_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (source_info->delete_task);
+ source_info->delete_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ if (source_info->find_peers_responded != NULL)
+ GNUNET_CONTAINER_bloomfilter_free (source_info->find_peers_responded);
+ GNUNET_free (source_info);
+ current_size = GNUNET_CONTAINER_multihashmap_size (forward_list.hashmap);
+ }
#endif
/** Non-local request and have too many outstanding forwards, discard! */
if ((current_size >= MAX_OUTSTANDING_FORWARDS) && (msg_ctx->client == NULL))
@@ -3731,54 +3771,54 @@
now = GNUNET_TIME_absolute_get ();
record =
- GNUNET_CONTAINER_multihashmap_get (forward_list.hashmap, &msg_ctx->key);
+ GNUNET_CONTAINER_multihashmap_get (forward_list.hashmap, &msg_ctx->key);
if (record != NULL) /* Already know this request! */
+ {
+ pos = record->head;
+ while (pos != NULL)
{
- pos = record->head;
- while (pos != NULL)
- {
- if (0 ==
- memcmp (msg_ctx->peer, &pos->source,
- sizeof (struct GNUNET_PeerIdentity)))
- break; /* Already have this peer in reply list! */
- pos = pos->next;
- }
- if ((pos != NULL) && (pos->client == msg_ctx->client)) /* Seen this
already */
- {
- GNUNET_CONTAINER_heap_update_cost (forward_list.minHeap, pos->hnode,
- now.abs_value);
- return GNUNET_NO;
- }
+ if (0 ==
+ memcmp (msg_ctx->peer, &pos->source,
+ sizeof (struct GNUNET_PeerIdentity)))
+ break; /* Already have this peer in reply list! */
+ pos = pos->next;
}
- else
+ if ((pos != NULL) && (pos->client == msg_ctx->client)) /* Seen this
already */
{
- record = GNUNET_malloc (sizeof (struct DHTQueryRecord));
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_put (forward_list.hashmap,
- &msg_ctx->key, record,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
- memcpy (&record->key, &msg_ctx->key, sizeof (GNUNET_HashCode));
+ GNUNET_CONTAINER_heap_update_cost (forward_list.minHeap, pos->hnode,
+ now.abs_value);
+ return GNUNET_NO;
}
+ }
+ else
+ {
+ record = GNUNET_malloc (sizeof (struct DHTQueryRecord));
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONTAINER_multihashmap_put (forward_list.hashmap,
+ &msg_ctx->key, record,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+ memcpy (&record->key, &msg_ctx->key, sizeof (GNUNET_HashCode));
+ }
source_info = GNUNET_malloc (sizeof (struct DHTRouteSource));
source_info->record = record;
source_info->delete_task =
- GNUNET_SCHEDULER_add_delayed (DHT_FORWARD_TIMEOUT, &remove_forward_entry,
- source_info);
+ GNUNET_SCHEDULER_add_delayed (DHT_FORWARD_TIMEOUT, &remove_forward_entry,
+ source_info);
source_info->find_peers_responded =
- GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K);
+ GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K);
memcpy (&source_info->source, msg_ctx->peer,
sizeof (struct GNUNET_PeerIdentity));
GNUNET_CONTAINER_DLL_insert_after (record->head, record->tail, record->tail,
source_info);
if (msg_ctx->client != NULL) /* For local request, set timeout so high it
effectively never gets pushed out */
- {
- source_info->client = msg_ctx->client;
- now = GNUNET_TIME_absolute_get_forever ();
- }
+ {
+ source_info->client = msg_ctx->client;
+ now = GNUNET_TIME_absolute_get_forever ();
+ }
source_info->hnode =
- GNUNET_CONTAINER_heap_insert (forward_list.minHeap, source_info,
- now.abs_value);
+ GNUNET_CONTAINER_heap_insert (forward_list.minHeap, source_info,
+ now.abs_value);
#if DEBUG_DHT > 1
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"`%s:%s': Created new forward source info for %s uid %llu\n",
@@ -3802,6 +3842,7 @@
{
int i;
struct PeerInfo *selected;
+
#if DEBUG_DHT_ROUTING > 1
struct PeerInfo *nearest;
#endif
@@ -3811,39 +3852,40 @@
GNUNET_HashCode unique_hash;
char *stat_forward_count;
char *temp_stat_str;
+
#if DEBUG_DHT_ROUTING
int ret;
#endif
if (malicious_dropper == GNUNET_YES)
+ {
+#if DEBUG_DHT_ROUTING
+ if ((debug_routes_extended) && (dhtlog_handle != NULL))
{
-#if DEBUG_DHT_ROUTING
- if ((debug_routes_extended) && (dhtlog_handle != NULL))
- {
- dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE,
- msg_ctx->hop_count, GNUNET_SYSERR,
- &my_identity, &msg_ctx->key,
- msg_ctx->peer, NULL);
- }
+ dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE,
+ msg_ctx->hop_count, GNUNET_SYSERR,
+ &my_identity, &msg_ctx->key,
+ msg_ctx->peer, NULL);
+ }
#endif
- if (msg_ctx->bloom != NULL)
- {
- GNUNET_CONTAINER_bloomfilter_free (msg_ctx->bloom);
- msg_ctx->bloom = NULL;
- }
- return;
+ if (msg_ctx->bloom != NULL)
+ {
+ GNUNET_CONTAINER_bloomfilter_free (msg_ctx->bloom);
+ msg_ctx->bloom = NULL;
}
+ return;
+ }
increment_stats (STAT_ROUTES);
target_forward_count =
- get_forward_count (msg_ctx->hop_count, msg_ctx->replication);
+ get_forward_count (msg_ctx->hop_count, msg_ctx->replication);
GNUNET_asprintf (&stat_forward_count, "# forward counts of %d",
target_forward_count);
increment_stats (stat_forward_count);
GNUNET_free (stat_forward_count);
if (msg_ctx->bloom == NULL)
msg_ctx->bloom =
- GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K);
+ GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K);
if ((stop_on_closest == GNUNET_YES) && (msg_ctx->closest == GNUNET_YES)
&& (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_DHT_PUT))
@@ -3874,109 +3916,106 @@
hash_from_uid (msg_ctx->unique_id, &unique_hash);
if (GNUNET_YES ==
GNUNET_CONTAINER_multihashmap_contains (recent.hashmap, &unique_hash))
+ {
+ recent_req =
+ GNUNET_CONTAINER_multihashmap_get (recent.hashmap, &unique_hash);
+ GNUNET_assert (recent_req != NULL);
+ if (0 != memcmp (&recent_req->key, &msg_ctx->key, sizeof
(GNUNET_HashCode)))
+ increment_stats (STAT_DUPLICATE_UID);
+ else
{
- recent_req =
- GNUNET_CONTAINER_multihashmap_get (recent.hashmap, &unique_hash);
- GNUNET_assert (recent_req != NULL);
- if (0 !=
- memcmp (&recent_req->key, &msg_ctx->key, sizeof (GNUNET_HashCode)))
- increment_stats (STAT_DUPLICATE_UID);
- else
- {
- increment_stats (STAT_RECENT_SEEN);
- GNUNET_CONTAINER_bloomfilter_or2 (msg_ctx->bloom, recent_req->bloom,
- DHT_BLOOM_SIZE);
- }
+ increment_stats (STAT_RECENT_SEEN);
+ GNUNET_CONTAINER_bloomfilter_or2 (msg_ctx->bloom, recent_req->bloom,
+ DHT_BLOOM_SIZE);
}
+ }
else
- {
- recent_req = GNUNET_malloc (sizeof (struct RecentRequest));
- recent_req->uid = msg_ctx->unique_id;
- memcpy (&recent_req->key, &msg_ctx->key, sizeof (GNUNET_HashCode));
- recent_req->remove_task =
+ {
+ recent_req = GNUNET_malloc (sizeof (struct RecentRequest));
+ recent_req->uid = msg_ctx->unique_id;
+ memcpy (&recent_req->key, &msg_ctx->key, sizeof (GNUNET_HashCode));
+ recent_req->remove_task =
GNUNET_SCHEDULER_add_delayed (DEFAULT_RECENT_REMOVAL, &remove_recent,
recent_req);
- recent_req->heap_node =
+ recent_req->heap_node =
GNUNET_CONTAINER_heap_insert (recent.minHeap, recent_req,
GNUNET_TIME_absolute_get ().abs_value);
- recent_req->bloom =
+ recent_req->bloom =
GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K);
- GNUNET_CONTAINER_multihashmap_put (recent.hashmap, &unique_hash,
- recent_req,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
- }
+ GNUNET_CONTAINER_multihashmap_put (recent.hashmap, &unique_hash,
+ recent_req,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+ }
if (GNUNET_CONTAINER_multihashmap_size (recent.hashmap) > DHT_MAX_RECENT)
- {
- recent_req = GNUNET_CONTAINER_heap_peek (recent.minHeap);
- GNUNET_assert (recent_req != NULL);
- GNUNET_SCHEDULER_cancel (recent_req->remove_task);
- GNUNET_SCHEDULER_add_now (&remove_recent, recent_req);
- }
+ {
+ recent_req = GNUNET_CONTAINER_heap_peek (recent.minHeap);
+ GNUNET_assert (recent_req != NULL);
+ GNUNET_SCHEDULER_cancel (recent_req->remove_task);
+ GNUNET_SCHEDULER_add_now (&remove_recent, recent_req);
+ }
forward_count = 0;
for (i = 0; i < target_forward_count; i++)
+ {
+ selected = select_peer (&msg_ctx->key, msg_ctx->bloom, msg_ctx->hop_count);
+
+ if (selected != NULL)
{
- selected =
- select_peer (&msg_ctx->key, msg_ctx->bloom, msg_ctx->hop_count);
-
- if (selected != NULL)
- {
- forward_count++;
- if (GNUNET_CRYPTO_hash_matching_bits
- (&selected->id.hashPubKey,
- &msg_ctx->key) >=
- GNUNET_CRYPTO_hash_matching_bits (&my_identity.hashPubKey,
- &msg_ctx->key))
- GNUNET_asprintf (&temp_stat_str,
- "# requests routed to close(r) peer hop %u",
- msg_ctx->hop_count);
- else
- GNUNET_asprintf (&temp_stat_str,
- "# requests routed to less close peer hop %u",
- msg_ctx->hop_count);
- if (temp_stat_str != NULL)
- {
- increment_stats (temp_stat_str);
- GNUNET_free (temp_stat_str);
- }
- GNUNET_CONTAINER_bloomfilter_add (msg_ctx->bloom,
- &selected->id.hashPubKey);
+ forward_count++;
+ if (GNUNET_CRYPTO_hash_matching_bits
+ (&selected->id.hashPubKey,
+ &msg_ctx->key) >=
+ GNUNET_CRYPTO_hash_matching_bits (&my_identity.hashPubKey,
+ &msg_ctx->key))
+ GNUNET_asprintf (&temp_stat_str,
+ "# requests routed to close(r) peer hop %u",
+ msg_ctx->hop_count);
+ else
+ GNUNET_asprintf (&temp_stat_str,
+ "# requests routed to less close peer hop %u",
+ msg_ctx->hop_count);
+ if (temp_stat_str != NULL)
+ {
+ increment_stats (temp_stat_str);
+ GNUNET_free (temp_stat_str);
+ }
+ GNUNET_CONTAINER_bloomfilter_add (msg_ctx->bloom,
+ &selected->id.hashPubKey);
#if DEBUG_DHT_ROUTING > 1
- nearest = find_closest_peer (&msg_ctx->key);
- nearest_buf = GNUNET_strdup (GNUNET_i2s (&nearest->id));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "`%s:%s': Forwarding request key %s uid %llu to peer %s
(closest %s, bits %d, distance %u)\n",
- my_short_id, "DHT", GNUNET_h2s (&msg_ctx->key),
- msg_ctx->unique_id, GNUNET_i2s (&selected->id),
- nearest_buf,
- GNUNET_CRYPTO_hash_matching_bits (&nearest->id.
- hashPubKey,
- msg_ctx->key),
- distance (&nearest->id.hashPubKey, msg_ctx->key));
- GNUNET_free (nearest_buf);
+ nearest = find_closest_peer (&msg_ctx->key);
+ nearest_buf = GNUNET_strdup (GNUNET_i2s (&nearest->id));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "`%s:%s': Forwarding request key %s uid %llu to peer %s
(closest %s, bits %d, distance %u)\n",
+ my_short_id, "DHT", GNUNET_h2s (&msg_ctx->key),
+ msg_ctx->unique_id, GNUNET_i2s (&selected->id),
+ nearest_buf,
+ GNUNET_CRYPTO_hash_matching_bits (&nearest->id.hashPubKey,
+ msg_ctx->key),
+ distance (&nearest->id.hashPubKey, msg_ctx->key));
+ GNUNET_free (nearest_buf);
#endif
#if DEBUG_DHT_ROUTING
- if ((debug_routes_extended) && (dhtlog_handle != NULL))
- {
- dhtlog_handle->insert_route (NULL, msg_ctx->unique_id,
- DHTLOG_ROUTE, msg_ctx->hop_count,
- GNUNET_NO, &my_identity,
- &msg_ctx->key, msg_ctx->peer,
- &selected->id);
- }
+ if ((debug_routes_extended) && (dhtlog_handle != NULL))
+ {
+ dhtlog_handle->insert_route (NULL, msg_ctx->unique_id,
+ DHTLOG_ROUTE, msg_ctx->hop_count,
+ GNUNET_NO, &my_identity,
+ &msg_ctx->key, msg_ctx->peer,
+ &selected->id);
+ }
#endif
- forward_message (msg, selected, msg_ctx);
- }
+ forward_message (msg, selected, msg_ctx);
}
+ }
if (msg_ctx->bloom != NULL)
- {
- GNUNET_CONTAINER_bloomfilter_or2 (recent_req->bloom, msg_ctx->bloom,
- DHT_BLOOM_SIZE);
- GNUNET_CONTAINER_bloomfilter_free (msg_ctx->bloom);
- msg_ctx->bloom = NULL;
- }
+ {
+ GNUNET_CONTAINER_bloomfilter_or2 (recent_req->bloom, msg_ctx->bloom,
+ DHT_BLOOM_SIZE);
+ GNUNET_CONTAINER_bloomfilter_free (msg_ctx->bloom);
+ msg_ctx->bloom = NULL;
+ }
#if DEBUG_DHT_ROUTING
if (forward_count == 0)
@@ -3985,12 +4024,12 @@
ret = GNUNET_NO;
if ((debug_routes_extended) && (dhtlog_handle != NULL))
- {
- dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE,
- msg_ctx->hop_count, ret,
- &my_identity, &msg_ctx->key, msg_ctx->peer,
- NULL);
- }
+ {
+ dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE,
+ msg_ctx->hop_count, ret,
+ &my_identity, &msg_ctx->key, msg_ctx->peer,
+ NULL);
+ }
#endif
}
@@ -4011,51 +4050,50 @@
msg_ctx->closest = am_closest_peer (&msg_ctx->key, msg_ctx->bloom);
switch (ntohs (msg->type))
+ {
+ case GNUNET_MESSAGE_TYPE_DHT_GET: /* Add to hashmap of requests seen,
search for data (always) */
+ cache_response (msg_ctx);
+ handle_dht_get (msg, msg_ctx);
+ break;
+ case GNUNET_MESSAGE_TYPE_DHT_PUT: /* Check if closest, if so insert data.
*/
+ increment_stats (STAT_PUTS);
+ handle_dht_put (msg, msg_ctx);
+ break;
+ case GNUNET_MESSAGE_TYPE_DHT_FIND_PEER: /* Check if closest and not
started by us, check options, add to requests seen */
+ increment_stats (STAT_FIND_PEER);
+ if (((msg_ctx->hop_count > 0)
+ && (0 !=
+ memcmp (msg_ctx->peer, &my_identity,
+ sizeof (struct GNUNET_PeerIdentity))))
+ || (msg_ctx->client != NULL))
{
- case GNUNET_MESSAGE_TYPE_DHT_GET: /* Add to hashmap of requests seen,
search for data (always) */
cache_response (msg_ctx);
- handle_dht_get (msg, msg_ctx);
- break;
- case GNUNET_MESSAGE_TYPE_DHT_PUT: /* Check if closest, if so insert data.
*/
- increment_stats (STAT_PUTS);
- handle_dht_put (msg, msg_ctx);
- break;
- case GNUNET_MESSAGE_TYPE_DHT_FIND_PEER: /* Check if closest and not
started by us, check options, add to requests seen */
- increment_stats (STAT_FIND_PEER);
- if (((msg_ctx->hop_count > 0)
- && (0 !=
- memcmp (msg_ctx->peer, &my_identity,
- sizeof (struct GNUNET_PeerIdentity))))
- || (msg_ctx->client != NULL))
- {
- cache_response (msg_ctx);
- if ((msg_ctx->closest == GNUNET_YES)
- || (msg_ctx->msg_options ==
- GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE))
- handle_dht_find_peer (msg, msg_ctx);
- }
- else
- route_message (msg, msg_ctx);
+ if ((msg_ctx->closest == GNUNET_YES)
+ || (msg_ctx->msg_options == GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE))
+ handle_dht_find_peer (msg, msg_ctx);
+ }
+ else
+ route_message (msg, msg_ctx);
#if DEBUG_DHT_ROUTING
- if (msg_ctx->hop_count == 0) /* Locally initiated request */
- {
- if ((debug_routes) && (dhtlog_handle != NULL))
- {
- dhtlog_handle->insert_dhtkey (NULL, &msg_ctx->key);
- dhtlog_handle->insert_query (NULL, msg_ctx->unique_id,
- DHTLOG_FIND_PEER,
- msg_ctx->hop_count, GNUNET_NO,
- &my_identity, &msg_ctx->key);
- }
- }
+ if (msg_ctx->hop_count == 0) /* Locally initiated request */
+ {
+ if ((debug_routes) && (dhtlog_handle != NULL))
+ {
+ dhtlog_handle->insert_dhtkey (NULL, &msg_ctx->key);
+ dhtlog_handle->insert_query (NULL, msg_ctx->unique_id,
+ DHTLOG_FIND_PEER,
+ msg_ctx->hop_count, GNUNET_NO,
+ &my_identity, &msg_ctx->key);
+ }
+ }
#endif
- break;
- default:
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "`%s': Message type (%d) not handled, forwarding anyway!\n",
- "DHT", ntohs (msg->type));
- route_message (msg, msg_ctx);
- }
+ break;
+ default:
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "`%s': Message type (%d) not handled, forwarding anyway!\n",
+ "DHT", ntohs (msg->type));
+ route_message (msg, msg_ctx);
+ }
}
@@ -4083,6 +4121,7 @@
struct DHT_MessageContext *new_msg_ctx;
struct GNUNET_DHT_PutMessage *put_msg;
+
#if DEBUG_DHT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"`%s:%s': Received `%s' response from datacache\n", my_short_id,
@@ -4097,14 +4136,14 @@
put_msg->type = htons (type);
memcpy (&put_msg[1], data, size);
new_msg_ctx->unique_id =
- GNUNET_ntohll (GNUNET_CRYPTO_random_u64
- (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX));
+ GNUNET_ntohll (GNUNET_CRYPTO_random_u64
+ (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX));
new_msg_ctx->replication = ntohl (DEFAULT_PUT_REPLICATION);
new_msg_ctx->msg_options = ntohl (0);
new_msg_ctx->network_size = estimate_diameter ();
new_msg_ctx->peer = &my_identity;
new_msg_ctx->bloom =
- GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K);
+ GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K);
new_msg_ctx->hop_count = 0;
new_msg_ctx->importance = DHT_DEFAULT_P2P_IMPORTANCE;
new_msg_ctx->timeout = DHT_DEFAULT_P2P_TIMEOUT;
@@ -4129,16 +4168,16 @@
unsigned int results;
- if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- {
- GNUNET_free (put_context);
- return;
- }
+ if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
+ {
+ GNUNET_free (put_context);
+ return;
+ }
GNUNET_assert (datacache != NULL); /* If we have no datacache we never
should have scheduled this! */
results =
- GNUNET_DATACACHE_get (datacache, &put_context->key, put_context->type,
- &republish_content_iterator, NULL);
+ GNUNET_DATACACHE_get (datacache, &put_context->key, put_context->type,
+ &republish_content_iterator, NULL);
if (results == 0) /* Data must have expired */
GNUNET_free (put_context);
else /* Reschedule task for next time period */
@@ -4164,33 +4203,34 @@
struct ClientList *client = cls;
struct DHTQueryRecord *record = value;
struct DHTRouteSource *pos;
+
pos = record->head;
while (pos != NULL)
- {
- if (pos->client == client)
- break;
- pos = pos->next;
- }
+ {
+ if (pos->client == client)
+ break;
+ pos = pos->next;
+ }
if (pos != NULL)
+ {
+ GNUNET_CONTAINER_DLL_remove (record->head, record->tail, pos);
+ GNUNET_CONTAINER_heap_remove_node (pos->hnode);
+ if (pos->delete_task != GNUNET_SCHEDULER_NO_TASK)
{
- GNUNET_CONTAINER_DLL_remove (record->head, record->tail, pos);
- GNUNET_CONTAINER_heap_remove_node (pos->hnode);
- if (pos->delete_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (pos->delete_task);
- pos->delete_task = GNUNET_SCHEDULER_NO_TASK;
- }
- if (pos->find_peers_responded != NULL)
- GNUNET_CONTAINER_bloomfilter_free (pos->find_peers_responded);
- GNUNET_free (pos);
+ GNUNET_SCHEDULER_cancel (pos->delete_task);
+ pos->delete_task = GNUNET_SCHEDULER_NO_TASK;
}
+ if (pos->find_peers_responded != NULL)
+ GNUNET_CONTAINER_bloomfilter_free (pos->find_peers_responded);
+ GNUNET_free (pos);
+ }
if (record->head == NULL) /* No more entries in DLL */
- {
- GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove
- (forward_list.hashmap, &record->key, record));
- GNUNET_free (record);
- }
+ {
+ GNUNET_assert (GNUNET_YES ==
+ GNUNET_CONTAINER_multihashmap_remove
+ (forward_list.hashmap, &record->key, record));
+ GNUNET_free (record);
+ }
return GNUNET_YES;
}
@@ -4213,36 +4253,35 @@
prev = NULL;
found = NULL;
while (pos != NULL)
+ {
+ if (pos->client_handle == client)
{
- if (pos->client_handle == client)
- {
- if (prev != NULL)
- prev->next = pos->next;
- else
- client_list = pos->next;
- found = pos;
- break;
- }
- prev = pos;
- pos = pos->next;
+ if (prev != NULL)
+ prev->next = pos->next;
+ else
+ client_list = pos->next;
+ found = pos;
+ break;
}
+ prev = pos;
+ pos = pos->next;
+ }
if (found != NULL)
+ {
+ if (found->transmit_handle != NULL)
+ GNUNET_CONNECTION_notify_transmit_ready_cancel (found->transmit_handle);
+
+ while (NULL != (reply = found->pending_head))
{
- if (found->transmit_handle != NULL)
- GNUNET_CONNECTION_notify_transmit_ready_cancel
- (found->transmit_handle);
-
- while (NULL != (reply = found->pending_head))
- {
- GNUNET_CONTAINER_DLL_remove (found->pending_head,
- found->pending_tail, reply);
- GNUNET_free (reply);
- }
- GNUNET_CONTAINER_multihashmap_iterate (forward_list.hashmap,
- &find_client_records, found);
- GNUNET_free (found);
+ GNUNET_CONTAINER_DLL_remove (found->pending_head,
+ found->pending_tail, reply);
+ GNUNET_free (reply);
}
+ GNUNET_CONTAINER_multihashmap_iterate (forward_list.hashmap,
+ &find_client_records, found);
+ GNUNET_free (found);
+ }
}
/**
@@ -4259,11 +4298,11 @@
struct ClientList *ret;
while (pos != NULL)
- {
- if (pos->client_handle == client)
- return pos;
- pos = pos->next;
- }
+ {
+ if (pos->client_handle == client)
+ return pos;
+ pos = pos->next;
+ }
ret = GNUNET_malloc (sizeof (struct ClientList));
ret->client_handle = client;
@@ -4288,21 +4327,21 @@
static GNUNET_HashCode key;
uint32_t random_key;
- if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
+ if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
return;
put_message.header.size = htons (sizeof (struct GNUNET_DHT_PutMessage));
put_message.header.type = htons (GNUNET_MESSAGE_TYPE_DHT_PUT);
put_message.type = htonl (GNUNET_BLOCK_DHT_MALICIOUS_MESSAGE_TYPE);
put_message.expiration =
- GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get_forever ());
+ GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get_forever ());
memset (&msg_ctx, 0, sizeof (struct DHT_MessageContext));
random_key =
- GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX);
+ GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX);
GNUNET_CRYPTO_hash (&random_key, sizeof (uint32_t), &key);
memcpy (&msg_ctx.key, &key, sizeof (GNUNET_HashCode));
msg_ctx.unique_id =
- GNUNET_ntohll (GNUNET_CRYPTO_random_u64
- (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX));
+ GNUNET_ntohll (GNUNET_CRYPTO_random_u64
+ (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX));
msg_ctx.replication = ntohl (DHT_DEFAULT_FIND_PEER_REPLICATION);
msg_ctx.msg_options = ntohl (0);
msg_ctx.network_size = estimate_diameter ();
@@ -4339,7 +4378,7 @@
static GNUNET_HashCode key;
uint32_t random_key;
- if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
+ if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
return;
get_message.header.size = htons (sizeof (struct GNUNET_DHT_GetMessage));
@@ -4347,12 +4386,12 @@
get_message.type = htonl (GNUNET_BLOCK_DHT_MALICIOUS_MESSAGE_TYPE);
memset (&msg_ctx, 0, sizeof (struct DHT_MessageContext));
random_key =
- GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX);
+ GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX);
GNUNET_CRYPTO_hash (&random_key, sizeof (uint32_t), &key);
memcpy (&msg_ctx.key, &key, sizeof (GNUNET_HashCode));
msg_ctx.unique_id =
- GNUNET_ntohll (GNUNET_CRYPTO_random_u64
- (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX));
+ GNUNET_ntohll (GNUNET_CRYPTO_random_u64
+ (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX));
msg_ctx.replication = ntohl (DHT_DEFAULT_FIND_PEER_REPLICATION);
msg_ctx.msg_options = ntohl (0);
msg_ctx.network_size = estimate_diameter ();
@@ -4390,6 +4429,7 @@
add_known_to_bloom (void *cls, const GNUNET_HashCode * key, void *value)
{
struct GNUNET_CONTAINER_BloomFilter *bloom = cls;
+
GNUNET_CONTAINER_bloomfilter_add (bloom, key);
return GNUNET_YES;
}
@@ -4410,62 +4450,63 @@
struct DHT_MessageContext msg_ctx;
struct GNUNET_TIME_Relative next_send_time;
struct GNUNET_CONTAINER_BloomFilter *temp_bloom;
+
#if COUNT_INTERVAL
struct GNUNET_TIME_Relative time_diff;
struct GNUNET_TIME_Absolute end;
double multiplier;
double count_per_interval;
#endif
- if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
+ if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
return;
if ((newly_found_peers > bucket_size) && (GNUNET_YES == do_find_peer))
/* If we are finding peers already, no need to send out our request right now!
*/
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Have %d newly found peers since last find peer message
sent!\n",
- newly_found_peers);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
- &send_find_peer_message, NULL);
- newly_found_peers = 0;
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Have %d newly found peers since last find peer message
sent!\n",
+ newly_found_peers);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
+ &send_find_peer_message, NULL);
+ newly_found_peers = 0;
+ return;
+ }
increment_stats (STAT_FIND_PEER_START);
#if COUNT_INTERVAL
end = GNUNET_TIME_absolute_get ();
time_diff =
- GNUNET_TIME_absolute_get_difference (find_peer_context.start, end);
+ GNUNET_TIME_absolute_get_difference (find_peer_context.start, end);
if (time_diff.abs_value > FIND_PEER_CALC_INTERVAL.abs_value)
- {
- multiplier = time_diff.abs_value / FIND_PEER_CALC_INTERVAL.abs_value;
- count_per_interval = find_peer_context.count / multiplier;
- }
+ {
+ multiplier = time_diff.abs_value / FIND_PEER_CALC_INTERVAL.abs_value;
+ count_per_interval = find_peer_context.count / multiplier;
+ }
else
- {
- multiplier = FIND_PEER_CALC_INTERVAL.abs_value / time_diff.abs_value;
- count_per_interval = find_peer_context.count * multiplier;
- }
+ {
+ multiplier = FIND_PEER_CALC_INTERVAL.abs_value / time_diff.abs_value;
+ count_per_interval = find_peer_context.count * multiplier;
+ }
#endif
#if FIND_PEER_WITH_HELLO
find_peer_msg =
- GNUNET_malloc (sizeof (struct GNUNET_DHT_FindPeerMessage) +
- GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *)
- my_hello));
+ GNUNET_malloc (sizeof (struct GNUNET_DHT_FindPeerMessage) +
+ GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *)
+ my_hello));
find_peer_msg->header.size =
- htons (sizeof (struct GNUNET_DHT_FindPeerMessage) +
- GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) my_hello));
+ htons (sizeof (struct GNUNET_DHT_FindPeerMessage) +
+ GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) my_hello));
memcpy (&find_peer_msg[1], my_hello,
GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) my_hello));
#else
find_peer_msg = GNUNET_malloc (sizeof (struct GNUNET_DHT_FindPeerMessage));
find_peer_msg->header.size =
- htons (sizeof (struct GNUNET_DHT_FindPeerMessage));
+ htons (sizeof (struct GNUNET_DHT_FindPeerMessage));
#endif
find_peer_msg->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_FIND_PEER);
temp_bloom =
- GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K);
+ GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K);
GNUNET_CONTAINER_multihashmap_iterate (all_known_peers, &add_known_to_bloom,
temp_bloom);
GNUNET_assert (GNUNET_OK ==
@@ -4477,8 +4518,8 @@
memset (&msg_ctx, 0, sizeof (struct DHT_MessageContext));
memcpy (&msg_ctx.key, &my_identity.hashPubKey, sizeof (GNUNET_HashCode));
msg_ctx.unique_id =
- GNUNET_ntohll (GNUNET_CRYPTO_random_u64
- (GNUNET_CRYPTO_QUALITY_STRONG, UINT64_MAX));
+ GNUNET_ntohll (GNUNET_CRYPTO_random_u64
+ (GNUNET_CRYPTO_QUALITY_STRONG, UINT64_MAX));
msg_ctx.replication = DHT_DEFAULT_FIND_PEER_REPLICATION;
msg_ctx.msg_options = DHT_DEFAULT_FIND_PEER_OPTIONS;
msg_ctx.network_size = estimate_diameter ();
@@ -4492,30 +4533,29 @@
"`%s:%s': Sent `%s' request to some (?) peers\n", my_short_id,
"DHT", "FIND PEER");
if (newly_found_peers < bucket_size)
- {
- next_send_time.rel_value =
+ {
+ next_send_time.rel_value =
(DHT_MAXIMUM_FIND_PEER_INTERVAL.rel_value / 2) +
GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG,
- DHT_MAXIMUM_FIND_PEER_INTERVAL.rel_value /
- 2);
- }
+ DHT_MAXIMUM_FIND_PEER_INTERVAL.rel_value /
2);
+ }
else
- {
- next_send_time.rel_value = DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value +
+ {
+ next_send_time.rel_value = DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value +
GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG,
DHT_MAXIMUM_FIND_PEER_INTERVAL.rel_value -
DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value);
- }
+ }
GNUNET_assert (next_send_time.rel_value != 0);
find_peer_context.count = 0;
newly_found_peers = 0;
find_peer_context.start = GNUNET_TIME_absolute_get ();
if (GNUNET_YES == do_find_peer)
- {
- GNUNET_SCHEDULER_add_delayed (next_send_time,
- &send_find_peer_message, NULL);
- }
+ {
+ GNUNET_SCHEDULER_add_delayed (next_send_time,
+ &send_find_peer_message, NULL);
+ }
}
/**
@@ -4533,7 +4573,7 @@
const struct GNUNET_MessageHeader *message)
{
const struct GNUNET_DHT_RouteMessage *dht_msg =
- (const struct GNUNET_DHT_RouteMessage *) message;
+ (const struct GNUNET_DHT_RouteMessage *) message;
const struct GNUNET_MessageHeader *enc_msg;
struct DHT_MessageContext msg_ctx;
@@ -4558,12 +4598,14 @@
msg_ctx.unique_id = GNUNET_ntohll (dht_msg->unique_id);
msg_ctx.replication = ntohl (dht_msg->desired_replication_level);
msg_ctx.msg_options = ntohl (dht_msg->options);
- if (GNUNET_DHT_RO_RECORD_ROUTE == (msg_ctx.msg_options &
GNUNET_DHT_RO_RECORD_ROUTE))
- {
- msg_ctx.path_history = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity));
- memcpy(msg_ctx.path_history, &my_identity, sizeof(struct
GNUNET_PeerIdentity));
- msg_ctx.path_history_len = 1;
- }
+ if (GNUNET_DHT_RO_RECORD_ROUTE ==
+ (msg_ctx.msg_options & GNUNET_DHT_RO_RECORD_ROUTE))
+ {
+ msg_ctx.path_history = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
+ memcpy (msg_ctx.path_history, &my_identity,
+ sizeof (struct GNUNET_PeerIdentity));
+ msg_ctx.path_history_len = 1;
+ }
msg_ctx.network_size = estimate_diameter ();
msg_ctx.peer = &my_identity;
msg_ctx.importance = DHT_DEFAULT_P2P_IMPORTANCE + 4; /* Make local routing
a higher priority */
@@ -4577,35 +4619,33 @@
increment_stats (STAT_FIND_PEER_START);
if (GNUNET_YES == malicious_dropper)
+ {
+ if (ntohs (enc_msg->type) == GNUNET_MESSAGE_TYPE_DHT_GET)
{
- if (ntohs (enc_msg->type) == GNUNET_MESSAGE_TYPE_DHT_GET)
- {
#if DEBUG_DHT_ROUTING
- if ((debug_routes) && (dhtlog_handle != NULL))
- {
- dhtlog_handle->insert_query (NULL, msg_ctx.unique_id,
- DHTLOG_GET, msg_ctx.hop_count,
- GNUNET_NO, &my_identity,
- &msg_ctx.key);
- }
+ if ((debug_routes) && (dhtlog_handle != NULL))
+ {
+ dhtlog_handle->insert_query (NULL, msg_ctx.unique_id,
+ DHTLOG_GET, msg_ctx.hop_count,
+ GNUNET_NO, &my_identity, &msg_ctx.key);
+ }
#endif
- }
- else if (ntohs (enc_msg->type) == GNUNET_MESSAGE_TYPE_DHT_PUT)
- {
+ }
+ else if (ntohs (enc_msg->type) == GNUNET_MESSAGE_TYPE_DHT_PUT)
+ {
#if DEBUG_DHT_ROUTING
- if ((debug_routes) && (dhtlog_handle != NULL))
- {
- dhtlog_handle->insert_query (NULL, msg_ctx.unique_id,
- DHTLOG_PUT, msg_ctx.hop_count,
- GNUNET_NO, &my_identity,
- &msg_ctx.key);
- }
+ if ((debug_routes) && (dhtlog_handle != NULL))
+ {
+ dhtlog_handle->insert_query (NULL, msg_ctx.unique_id,
+ DHTLOG_PUT, msg_ctx.hop_count,
+ GNUNET_NO, &my_identity, &msg_ctx.key);
+ }
#endif
- }
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
- GNUNET_free_non_null(msg_ctx.path_history);
- return;
}
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ GNUNET_free_non_null (msg_ctx.path_history);
+ return;
+ }
demultiplex_message (enc_msg, &msg_ctx);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -4626,64 +4666,63 @@
const struct GNUNET_MessageHeader *message)
{
const struct GNUNET_DHT_ControlMessage *dht_control_msg =
- (const struct GNUNET_DHT_ControlMessage *) message;
+ (const struct GNUNET_DHT_ControlMessage *) message;
#if DEBUG_DHT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"`%s:%s': Received `%s' request from client, command %d\n",
- my_short_id, "DHT", "CONTROL",
- ntohs (dht_control_msg->command));
+ my_short_id, "DHT", "CONTROL", ntohs (dht_control_msg->command));
#endif
switch (ntohs (dht_control_msg->command))
- {
- case GNUNET_MESSAGE_TYPE_DHT_FIND_PEER:
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending self seeking find peer request!\n");
- GNUNET_SCHEDULER_add_now (&send_find_peer_message, NULL);
- break;
+ {
+ case GNUNET_MESSAGE_TYPE_DHT_FIND_PEER:
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending self seeking find peer request!\n");
+ GNUNET_SCHEDULER_add_now (&send_find_peer_message, NULL);
+ break;
#if HAVE_MALICIOUS
- case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_GET:
- if (ntohs (dht_control_msg->variable) > 0)
- malicious_get_frequency = ntohs (dht_control_msg->variable);
- if (malicious_get_frequency == 0)
- malicious_get_frequency = DEFAULT_MALICIOUS_GET_FREQUENCY;
- if (malicious_getter != GNUNET_YES)
- GNUNET_SCHEDULER_add_now (&malicious_get_task, NULL);
- malicious_getter = GNUNET_YES;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "%s:%s Initiating malicious GET behavior, frequency %d\n",
- my_short_id, "DHT", malicious_get_frequency);
- break;
- case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_PUT:
- if (ntohs (dht_control_msg->variable) > 0)
- malicious_put_frequency = ntohs (dht_control_msg->variable);
- if (malicious_put_frequency == 0)
- malicious_put_frequency = DEFAULT_MALICIOUS_PUT_FREQUENCY;
- if (malicious_putter != GNUNET_YES)
- GNUNET_SCHEDULER_add_now (&malicious_put_task, NULL);
- malicious_putter = GNUNET_YES;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "%s:%s Initiating malicious PUT behavior, frequency %d\n",
- my_short_id, "DHT", malicious_put_frequency);
- break;
- case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_DROP:
+ case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_GET:
+ if (ntohs (dht_control_msg->variable) > 0)
+ malicious_get_frequency = ntohs (dht_control_msg->variable);
+ if (malicious_get_frequency == 0)
+ malicious_get_frequency = DEFAULT_MALICIOUS_GET_FREQUENCY;
+ if (malicious_getter != GNUNET_YES)
+ GNUNET_SCHEDULER_add_now (&malicious_get_task, NULL);
+ malicious_getter = GNUNET_YES;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "%s:%s Initiating malicious GET behavior, frequency %d\n",
+ my_short_id, "DHT", malicious_get_frequency);
+ break;
+ case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_PUT:
+ if (ntohs (dht_control_msg->variable) > 0)
+ malicious_put_frequency = ntohs (dht_control_msg->variable);
+ if (malicious_put_frequency == 0)
+ malicious_put_frequency = DEFAULT_MALICIOUS_PUT_FREQUENCY;
+ if (malicious_putter != GNUNET_YES)
+ GNUNET_SCHEDULER_add_now (&malicious_put_task, NULL);
+ malicious_putter = GNUNET_YES;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "%s:%s Initiating malicious PUT behavior, frequency %d\n",
+ my_short_id, "DHT", malicious_put_frequency);
+ break;
+ case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_DROP:
#if DEBUG_DHT_ROUTING
- if ((malicious_dropper != GNUNET_YES) && (dhtlog_handle != NULL))
- dhtlog_handle->set_malicious (&my_identity);
+ if ((malicious_dropper != GNUNET_YES) && (dhtlog_handle != NULL))
+ dhtlog_handle->set_malicious (&my_identity);
#endif
- malicious_dropper = GNUNET_YES;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "%s:%s Initiating malicious DROP behavior\n", my_short_id,
- "DHT");
- break;
+ malicious_dropper = GNUNET_YES;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "%s:%s Initiating malicious DROP behavior\n", my_short_id,
+ "DHT");
+ break;
#endif
- default:
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "%s:%s Unknown control command type `%d'!\n",
- my_short_id, "DHT", ntohs (dht_control_msg->command));
- break;
- }
+ default:
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "%s:%s Unknown control command type `%d'!\n",
+ my_short_id, "DHT", ntohs (dht_control_msg->command));
+ break;
+ }
GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
@@ -4703,9 +4742,10 @@
{
const struct GNUNET_DHT_StopMessage *dht_stop_msg =
- (const struct GNUNET_DHT_StopMessage *) message;
+ (const struct GNUNET_DHT_StopMessage *) message;
struct DHTQueryRecord *record;
struct DHTRouteSource *pos;
+
#if DEBUG_DHT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"`%s:%s': Received `%s' request from client, uid %llu\n",
@@ -4713,24 +4753,25 @@
GNUNET_ntohll (dht_stop_msg->unique_id));
#endif
record =
- GNUNET_CONTAINER_multihashmap_get (forward_list.hashmap,
- &dht_stop_msg->key);
+ GNUNET_CONTAINER_multihashmap_get (forward_list.hashmap,
+ &dht_stop_msg->key);
if (record != NULL)
+ {
+ pos = record->head;
+
+ while (pos != NULL)
{
- pos = record->head;
-
- while (pos != NULL)
- {
- /* If the client is non-null (local request) and the client matches
the requesting client, remove the entry. */
- if ((pos->client != NULL) && (pos->client->client_handle == client))
- {
- if (pos->delete_task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel (pos->delete_task);
- pos->delete_task = GNUNET_SCHEDULER_add_now
(&remove_forward_entry, pos);
- }
- pos = pos->next;
- }
+ /* If the client is non-null (local request) and the client matches the
requesting client, remove the entry. */
+ if ((pos->client != NULL) && (pos->client->client_handle == client))
+ {
+ if (pos->delete_task != GNUNET_SCHEDULER_NO_TASK)
+ GNUNET_SCHEDULER_cancel (pos->delete_task);
+ pos->delete_task =
+ GNUNET_SCHEDULER_add_now (&remove_forward_entry, pos);
+ }
+ pos = pos->next;
}
+ }
GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
@@ -4758,99 +4799,103 @@
"DHT", GNUNET_i2s (peer));
#endif
struct GNUNET_DHT_P2PRouteMessage *incoming =
- (struct GNUNET_DHT_P2PRouteMessage *) message;
+ (struct GNUNET_DHT_P2PRouteMessage *) message;
struct GNUNET_MessageHeader *enc_msg =
- (struct GNUNET_MessageHeader *) &incoming[1];
+ (struct GNUNET_MessageHeader *) &incoming[1];
struct DHT_MessageContext *msg_ctx;
char *route_path;
int path_size;
if (ntohs (enc_msg->type) == GNUNET_MESSAGE_TYPE_DHT_P2P_PING) /*
Throw these away. FIXME: Don't throw these away? (reply) */
- {
+ {
#if DEBUG_PING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "%s:%s Received P2P Ping message.\n", my_short_id, "DHT");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "%s:%s Received P2P Ping message.\n", my_short_id, "DHT");
#endif
- return GNUNET_YES;
- }
+ return GNUNET_YES;
+ }
if (ntohs (enc_msg->size) >= GNUNET_SERVER_MAX_MESSAGE_SIZE - 1)
- {
- GNUNET_break_op (0);
- return GNUNET_YES;
- }
+ {
+ GNUNET_break_op (0);
+ return GNUNET_YES;
+ }
if (malicious_dropper == GNUNET_YES)
+ {
+#if DEBUG_DHT_ROUTING
+ if ((debug_routes_extended) && (dhtlog_handle != NULL))
{
-#if DEBUG_DHT_ROUTING
- if ((debug_routes_extended) && (dhtlog_handle != NULL))
- {
/** Log routes that die due to high load! */
- dhtlog_handle->insert_route (NULL,
- GNUNET_ntohll (incoming->unique_id),
- DHTLOG_ROUTE,
- ntohl (incoming->hop_count),
- GNUNET_SYSERR, &my_identity,
- &incoming->key, peer, NULL);
- }
+ dhtlog_handle->insert_route (NULL,
+ GNUNET_ntohll (incoming->unique_id),
+ DHTLOG_ROUTE,
+ ntohl (incoming->hop_count),
+ GNUNET_SYSERR, &my_identity,
+ &incoming->key, peer, NULL);
+ }
#endif
- return GNUNET_YES;
- }
+ return GNUNET_YES;
+ }
if (get_max_send_delay ().rel_value > MAX_REQUEST_TIME.rel_value)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending of previous replies took too long, backing off!\n");
+ increment_stats ("# route requests dropped due to high load");
+ decrease_max_send_delay (get_max_send_delay ());
+#if DEBUG_DHT_ROUTING
+ if ((debug_routes_extended) && (dhtlog_handle != NULL))
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending of previous replies took too long, backing off!\n");
- increment_stats ("# route requests dropped due to high load");
- decrease_max_send_delay (get_max_send_delay ());
-#if DEBUG_DHT_ROUTING
- if ((debug_routes_extended) && (dhtlog_handle != NULL))
- {
/** Log routes that die due to high load! */
- dhtlog_handle->insert_route (NULL,
- GNUNET_ntohll (incoming->unique_id),
- DHTLOG_ROUTE,
- ntohl (incoming->hop_count),
- GNUNET_SYSERR, &my_identity,
- &incoming->key, peer, NULL);
- }
+ dhtlog_handle->insert_route (NULL,
+ GNUNET_ntohll (incoming->unique_id),
+ DHTLOG_ROUTE,
+ ntohl (incoming->hop_count),
+ GNUNET_SYSERR, &my_identity,
+ &incoming->key, peer, NULL);
+ }
#endif
- return GNUNET_YES;
- }
+ return GNUNET_YES;
+ }
msg_ctx = GNUNET_malloc (sizeof (struct DHT_MessageContext));
msg_ctx->bloom =
- GNUNET_CONTAINER_bloomfilter_init (incoming->bloomfilter, DHT_BLOOM_SIZE,
- DHT_BLOOM_K);
+ GNUNET_CONTAINER_bloomfilter_init (incoming->bloomfilter, DHT_BLOOM_SIZE,
+ DHT_BLOOM_K);
GNUNET_assert (msg_ctx->bloom != NULL);
msg_ctx->hop_count = ntohl (incoming->hop_count);
memcpy (&msg_ctx->key, &incoming->key, sizeof (GNUNET_HashCode));
msg_ctx->replication = ntohl (incoming->desired_replication_level);
msg_ctx->unique_id = GNUNET_ntohll (incoming->unique_id);
msg_ctx->msg_options = ntohl (incoming->options);
- if (GNUNET_DHT_RO_RECORD_ROUTE == (msg_ctx->msg_options &
GNUNET_DHT_RO_RECORD_ROUTE))
- {
- path_size = ntohl(incoming->outgoing_path_length) * sizeof(struct
GNUNET_PeerIdentity);
- GNUNET_assert(ntohs(message->size) ==
- (sizeof(struct GNUNET_DHT_P2PRouteMessage) +
- ntohs(enc_msg->size) +
- path_size));
- route_path = (char *)&incoming[1];
- route_path = route_path + ntohs(enc_msg->size);
- msg_ctx->path_history = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity)
+ path_size);
- memcpy(msg_ctx->path_history, route_path, path_size);
- memcpy(&msg_ctx->path_history[path_size], &my_identity, sizeof(struct
GNUNET_PeerIdentity));
- msg_ctx->path_history_len = ntohl(incoming->outgoing_path_length) + 1;
- }
+ if (GNUNET_DHT_RO_RECORD_ROUTE ==
+ (msg_ctx->msg_options & GNUNET_DHT_RO_RECORD_ROUTE))
+ {
+ path_size =
+ ntohl (incoming->outgoing_path_length) *
+ sizeof (struct GNUNET_PeerIdentity);
+ GNUNET_assert (ntohs (message->size) ==
+ (sizeof (struct GNUNET_DHT_P2PRouteMessage) +
+ ntohs (enc_msg->size) + path_size));
+ route_path = (char *) &incoming[1];
+ route_path = route_path + ntohs (enc_msg->size);
+ msg_ctx->path_history =
+ GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) + path_size);
+ memcpy (msg_ctx->path_history, route_path, path_size);
+ memcpy (&msg_ctx->path_history[path_size], &my_identity,
+ sizeof (struct GNUNET_PeerIdentity));
+ msg_ctx->path_history_len = ntohl (incoming->outgoing_path_length) + 1;
+ }
msg_ctx->network_size = ntohl (incoming->network_size);
msg_ctx->peer = peer;
msg_ctx->importance = DHT_DEFAULT_P2P_IMPORTANCE;
msg_ctx->timeout = DHT_DEFAULT_P2P_TIMEOUT;
demultiplex_message (enc_msg, msg_ctx);
if (msg_ctx->bloom != NULL)
- {
- GNUNET_CONTAINER_bloomfilter_free (msg_ctx->bloom);
- msg_ctx->bloom = NULL;
- }
+ {
+ GNUNET_CONTAINER_bloomfilter_free (msg_ctx->bloom);
+ msg_ctx->bloom = NULL;
+ }
GNUNET_free (msg_ctx);
return GNUNET_YES;
}
@@ -4878,36 +4923,37 @@
GNUNET_i2s (peer));
#endif
struct GNUNET_DHT_P2PRouteResultMessage *incoming =
- (struct GNUNET_DHT_P2PRouteResultMessage *) message;
+ (struct GNUNET_DHT_P2PRouteResultMessage *) message;
struct GNUNET_MessageHeader *enc_msg =
- (struct GNUNET_MessageHeader *) &incoming[1];
+ (struct GNUNET_MessageHeader *) &incoming[1];
struct DHT_MessageContext msg_ctx;
+
#if DEBUG_PATH
char *path_offset;
unsigned int i;
#endif
if (ntohs (enc_msg->size) >= GNUNET_SERVER_MAX_MESSAGE_SIZE - 1)
- {
- GNUNET_break_op (0);
- return GNUNET_YES;
- }
+ {
+ GNUNET_break_op (0);
+ return GNUNET_YES;
+ }
if (malicious_dropper == GNUNET_YES)
+ {
+#if DEBUG_DHT_ROUTING
+ if ((debug_routes_extended) && (dhtlog_handle != NULL))
{
-#if DEBUG_DHT_ROUTING
- if ((debug_routes_extended) && (dhtlog_handle != NULL))
- {
/** Log routes that die due to high load! */
- dhtlog_handle->insert_route (NULL,
- GNUNET_ntohll (incoming->unique_id),
- DHTLOG_ROUTE,
- ntohl (incoming->hop_count),
- GNUNET_SYSERR, &my_identity,
- &incoming->key, peer, NULL);
- }
+ dhtlog_handle->insert_route (NULL,
+ GNUNET_ntohll (incoming->unique_id),
+ DHTLOG_ROUTE,
+ ntohl (incoming->hop_count),
+ GNUNET_SYSERR, &my_identity,
+ &incoming->key, peer, NULL);
+ }
#endif
- return GNUNET_YES;
- }
+ return GNUNET_YES;
+ }
memset (&msg_ctx, 0, sizeof (struct DHT_MessageContext));
// FIXME: call GNUNET_BLOCK_evaluate (...) -- instead of doing your own
bloomfilter!
@@ -4918,40 +4964,48 @@
msg_ctx.peer = peer;
msg_ctx.importance = DHT_DEFAULT_P2P_IMPORTANCE + 2; /* Make result routing
a higher priority */
msg_ctx.timeout = DHT_DEFAULT_P2P_TIMEOUT;
- if ((GNUNET_DHT_RO_RECORD_ROUTE == (msg_ctx.msg_options &
GNUNET_DHT_RO_RECORD_ROUTE)) && (ntohl (incoming->outgoing_path_length) > 0))
+ if ((GNUNET_DHT_RO_RECORD_ROUTE ==
+ (msg_ctx.msg_options & GNUNET_DHT_RO_RECORD_ROUTE)) &&
+ (ntohl (incoming->outgoing_path_length) > 0))
+ {
+ if (ntohs (message->size) -
+ sizeof (struct GNUNET_DHT_P2PRouteResultMessage) -
+ ntohs (enc_msg->size) !=
+ ntohl (incoming->outgoing_path_length) *
+ sizeof (struct GNUNET_PeerIdentity))
{
- if (ntohs(message->size) - sizeof(struct
GNUNET_DHT_P2PRouteResultMessage) - ntohs(enc_msg->size) !=
- ntohl (incoming->outgoing_path_length) * sizeof(struct
GNUNET_PeerIdentity))
- {
#if DEBUG_DHT
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Return message indicated a path was included, but sizes
are wrong: Total size %d, enc size %d, left %d, expected %d\n",
- ntohs(message->size),
- ntohs(enc_msg->size),
- ntohs(message->size) - sizeof(struct
GNUNET_DHT_P2PRouteResultMessage) - ntohs(enc_msg->size),
- ntohl(incoming->outgoing_path_length) * sizeof(struct
GNUNET_PeerIdentity));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Return message indicated a path was included, but sizes are
wrong: Total size %d, enc size %d, left %d, expected %d\n",
+ ntohs (message->size),
+ ntohs (enc_msg->size),
+ ntohs (message->size) -
+ sizeof (struct GNUNET_DHT_P2PRouteResultMessage) -
+ ntohs (enc_msg->size),
+ ntohl (incoming->outgoing_path_length) *
+ sizeof (struct GNUNET_PeerIdentity));
#endif
- GNUNET_break_op (0);
- return GNUNET_NO;
- }
- msg_ctx.path_history = (char *)&incoming[1];
- msg_ctx.path_history += ntohs(enc_msg->size);
- msg_ctx.path_history_len = ntohl (incoming->outgoing_path_length);
+ GNUNET_break_op (0);
+ return GNUNET_NO;
+ }
+ msg_ctx.path_history = (char *) &incoming[1];
+ msg_ctx.path_history += ntohs (enc_msg->size);
+ msg_ctx.path_history_len = ntohl (incoming->outgoing_path_length);
#if DEBUG_PATH
- for (i = 0; i < msg_ctx.path_history_len; i++)
- {
- path_offset = &msg_ctx.path_history[i * sizeof(struct
GNUNET_PeerIdentity)];
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "(handle_p2p_route_result) Key %s Found peer %d:%s\n",
- GNUNET_h2s(&msg_ctx.key),
- i,
- GNUNET_i2s((struct GNUNET_PeerIdentity *)path_offset));
- }
+ for (i = 0; i < msg_ctx.path_history_len; i++)
+ {
+ path_offset =
+ &msg_ctx.path_history[i * sizeof (struct GNUNET_PeerIdentity)];
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "(handle_p2p_route_result) Key %s Found peer %d:%s\n",
+ GNUNET_h2s (&msg_ctx.key), i,
+ GNUNET_i2s ((struct GNUNET_PeerIdentity *) path_offset));
+ }
#endif
- }
+ }
msg_ctx.bloom =
- GNUNET_CONTAINER_bloomfilter_init (incoming->bloomfilter, DHT_BLOOM_SIZE,
- DHT_BLOOM_K);
+ GNUNET_CONTAINER_bloomfilter_init (incoming->bloomfilter, DHT_BLOOM_SIZE,
+ DHT_BLOOM_K);
GNUNET_assert (msg_ctx.bloom != NULL);
route_result_message (enc_msg, &msg_ctx);
return GNUNET_YES;
@@ -4993,59 +5047,57 @@
struct PeerInfo *pos;
if (transport_handle != NULL)
- {
- GNUNET_free_non_null (my_hello);
- GNUNET_TRANSPORT_get_hello_cancel (transport_handle, &process_hello,
- NULL);
- GNUNET_TRANSPORT_disconnect (transport_handle);
- }
+ {
+ GNUNET_free_non_null (my_hello);
+ GNUNET_TRANSPORT_get_hello_cancel (transport_handle, &process_hello, NULL);
+ GNUNET_TRANSPORT_disconnect (transport_handle);
+ }
if (coreAPI != NULL)
- {
+ {
#if DEBUG_DHT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "%s:%s Disconnecting core!\n", my_short_id, "DHT");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "%s:%s Disconnecting core!\n", my_short_id, "DHT");
#endif
- GNUNET_CORE_disconnect (coreAPI);
- coreAPI = NULL;
- }
- for (bucket_count = lowest_bucket; bucket_count < MAX_BUCKETS;
- bucket_count++)
+ GNUNET_CORE_disconnect (coreAPI);
+ coreAPI = NULL;
+ }
+ for (bucket_count = lowest_bucket; bucket_count < MAX_BUCKETS;
bucket_count++)
+ {
+ while (k_buckets[bucket_count].head != NULL)
{
- while (k_buckets[bucket_count].head != NULL)
- {
- pos = k_buckets[bucket_count].head;
+ pos = k_buckets[bucket_count].head;
#if DEBUG_DHT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "%s:%s Removing peer %s from bucket %d!\n", my_short_id,
- "DHT", GNUNET_i2s (&pos->id), bucket_count);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "%s:%s Removing peer %s from bucket %d!\n", my_short_id,
+ "DHT", GNUNET_i2s (&pos->id), bucket_count);
#endif
- delete_peer (pos, bucket_count);
- }
+ delete_peer (pos, bucket_count);
}
+ }
if (datacache != NULL)
- {
+ {
#if DEBUG_DHT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "%s:%s Destroying datacache!\n", my_short_id, "DHT");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "%s:%s Destroying datacache!\n", my_short_id, "DHT");
#endif
- GNUNET_DATACACHE_destroy (datacache);
- datacache = NULL;
- }
+ GNUNET_DATACACHE_destroy (datacache);
+ datacache = NULL;
+ }
if (stats != NULL)
- {
- GNUNET_STATISTICS_destroy (stats, GNUNET_YES);
- stats = NULL;
- }
+ {
+ GNUNET_STATISTICS_destroy (stats, GNUNET_YES);
+ stats = NULL;
+ }
if (dhtlog_handle != NULL)
- {
- GNUNET_DHTLOG_disconnect (dhtlog_handle);
- dhtlog_handle = NULL;
- }
+ {
+ GNUNET_DHTLOG_disconnect (dhtlog_handle);
+ dhtlog_handle = NULL;
+ }
if (block_context != NULL)
- {
- GNUNET_BLOCK_context_destroy (block_context);
- block_context = NULL;
- }
+ {
+ GNUNET_BLOCK_context_destroy (block_context);
+ block_context = NULL;
+ }
GNUNET_free_non_null (my_short_id);
my_short_id = NULL;
}
@@ -5067,16 +5119,16 @@
{
if (server == NULL)
- {
+ {
#if DEBUG_DHT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "%s: Connection to core FAILED!\n", "dht",
- GNUNET_i2s (identity));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "%s: Connection to core FAILED!\n", "dht",
+ GNUNET_i2s (identity));
#endif
- GNUNET_SCHEDULER_cancel (cleanup_task);
- GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
- return;
- }
+ GNUNET_SCHEDULER_cancel (cleanup_task);
+ GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
+ return;
+ }
#if DEBUG_DHT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"%s: Core connection initialized, I am peer: %s\n", "dht",
@@ -5132,7 +5184,7 @@
int peer_bucket;
/* Check for connect to self message */
- if (0 == memcmp(&my_identity, peer, sizeof(struct GNUNET_PeerIdentity)))
+ if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity)))
return;
#if DEBUG_DHT
@@ -5144,30 +5196,34 @@
if (GNUNET_YES ==
GNUNET_CONTAINER_multihashmap_contains (all_known_peers,
&peer->hashPubKey))
- {
+ {
#if DEBUG_DHT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "%s:%s Received %s message for peer %s, but already have
peer in RT!",
- my_short_id, "DHT", "CORE CONNECT", GNUNET_i2s (peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "%s:%s Received %s message for peer %s, but already have peer
in RT!",
+ my_short_id, "DHT", "CORE CONNECT", GNUNET_i2s (peer));
#endif
- GNUNET_break (0);
- return;
- }
+ GNUNET_break (0);
+ return;
+ }
if ((datacache != NULL) && (GNUNET_YES == put_peer_identities))
- {
- put_entry = GNUNET_malloc(sizeof(struct DHTPutEntry) + sizeof (struct
GNUNET_PeerIdentity));
- put_entry->path_length = 0;
- put_entry->data_size = sizeof (struct GNUNET_PeerIdentity);
- memcpy(&put_entry[1], peer, sizeof (struct GNUNET_PeerIdentity));
- GNUNET_DATACACHE_put (datacache, &peer->hashPubKey,
- sizeof(struct DHTPutEntry) + sizeof (struct
GNUNET_PeerIdentity),
- (char *)put_entry, GNUNET_BLOCK_TYPE_DHT_HELLO,
- GNUNET_TIME_absolute_get_forever ());
- GNUNET_free (put_entry);
- }
+ {
+ put_entry =
+ GNUNET_malloc (sizeof (struct DHTPutEntry) +
+ sizeof (struct GNUNET_PeerIdentity));
+ put_entry->path_length = 0;
+ put_entry->data_size = sizeof (struct GNUNET_PeerIdentity);
+ memcpy (&put_entry[1], peer, sizeof (struct GNUNET_PeerIdentity));
+ GNUNET_DATACACHE_put (datacache, &peer->hashPubKey,
+ sizeof (struct DHTPutEntry) +
+ sizeof (struct GNUNET_PeerIdentity),
+ (char *) put_entry, GNUNET_BLOCK_TYPE_DHT_HELLO,
+ GNUNET_TIME_absolute_get_forever ());
+ GNUNET_free (put_entry);
+ }
else if (datacache == NULL)
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "DHT has no connection to
datacache!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "DHT has no connection to datacache!\n");
peer_bucket = find_current_bucket (&peer->hashPubKey);
GNUNET_assert (peer_bucket >= lowest_bucket);
@@ -5180,15 +5236,14 @@
ret->id = *peer;
GNUNET_CONTAINER_DLL_insert_after (k_buckets[peer_bucket].head,
k_buckets[peer_bucket].tail,
- k_buckets[peer_bucket].tail,
- ret);
+ k_buckets[peer_bucket].tail, ret);
k_buckets[peer_bucket].peers_size++;
#if DO_UPDATE_PREFERENCE
- if ( (GNUNET_CRYPTO_hash_matching_bits
- (&my_identity.hashPubKey, &peer->hashPubKey) > 0) &&
- (k_buckets[peer_bucket].peers_size <= bucket_size) )
- ret->preference_task = GNUNET_SCHEDULER_add_now (&update_core_preference,
- ret);
+ if ((GNUNET_CRYPTO_hash_matching_bits
+ (&my_identity.hashPubKey, &peer->hashPubKey) > 0) &&
+ (k_buckets[peer_bucket].peers_size <= bucket_size))
+ ret->preference_task = GNUNET_SCHEDULER_add_now (&update_core_preference,
+ ret);
#endif
if ((k_buckets[lowest_bucket].peers_size) >= bucket_size)
enable_next_bucket ();
@@ -5197,9 +5252,9 @@
#endif
newly_found_peers++;
GNUNET_CONTAINER_multihashmap_put (all_known_peers, &peer->hashPubKey,
- ret,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
- increment_stats (STAT_PEERS_KNOWN);
+ ret,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+ increment_stats (STAT_PEERS_KNOWN);
#if DEBUG_DHT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -5222,7 +5277,7 @@
int current_bucket;
/* Check for disconnect from self message */
- if (0 == memcmp(&my_identity, peer, sizeof(struct GNUNET_PeerIdentity)))
+ if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity)))
return;
#if DEBUG_DHT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -5233,26 +5288,26 @@
if (GNUNET_YES !=
GNUNET_CONTAINER_multihashmap_contains (all_known_peers,
&peer->hashPubKey))
- {
- GNUNET_break (0);
+ {
+ GNUNET_break (0);
#if DEBUG_DHT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "%s:%s: do not have peer `%s' in RT, can't disconnect!\n",
- my_short_id, "DHT", GNUNET_i2s (peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "%s:%s: do not have peer `%s' in RT, can't disconnect!\n",
+ my_short_id, "DHT", GNUNET_i2s (peer));
#endif
- return;
- }
+ return;
+ }
increment_stats (STAT_DISCONNECTS);
GNUNET_assert (GNUNET_CONTAINER_multihashmap_contains
(all_known_peers, &peer->hashPubKey));
to_remove =
- GNUNET_CONTAINER_multihashmap_get (all_known_peers, &peer->hashPubKey);
+ GNUNET_CONTAINER_multihashmap_get (all_known_peers, &peer->hashPubKey);
GNUNET_assert (to_remove != NULL);
if (NULL != to_remove->info_ctx)
- {
- GNUNET_CORE_peer_change_preference_cancel (to_remove->info_ctx);
- to_remove->info_ctx = NULL;
- }
+ {
+ GNUNET_CORE_peer_change_preference_cancel (to_remove->info_ctx);
+ to_remove->info_ctx = NULL;
+ }
GNUNET_assert (0 ==
memcmp (peer, &to_remove->id,
sizeof (struct GNUNET_PeerIdentity)));
@@ -5306,101 +5361,101 @@
block_context = GNUNET_BLOCK_context_create (cfg);
lowest_bucket = MAX_BUCKETS - 1;
forward_list.hashmap =
- GNUNET_CONTAINER_multihashmap_create (MAX_OUTSTANDING_FORWARDS / 10);
+ GNUNET_CONTAINER_multihashmap_create (MAX_OUTSTANDING_FORWARDS / 10);
forward_list.minHeap =
- GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
+ GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
all_known_peers = GNUNET_CONTAINER_multihashmap_create (MAX_BUCKETS / 8);
recent_find_peer_requests =
- GNUNET_CONTAINER_multihashmap_create (MAX_BUCKETS / 8);
+ GNUNET_CONTAINER_multihashmap_create (MAX_BUCKETS / 8);
GNUNET_assert (all_known_peers != NULL);
if (GNUNET_YES ==
GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht_testing",
"mysql_logging"))
- {
- debug_routes = GNUNET_YES;
- }
+ {
+ debug_routes = GNUNET_YES;
+ }
if (GNUNET_YES ==
GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", "strict_kademlia"))
- {
- strict_kademlia = GNUNET_YES;
- }
+ {
+ strict_kademlia = GNUNET_YES;
+ }
if (GNUNET_YES ==
GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", "stop_on_closest"))
- {
- stop_on_closest = GNUNET_YES;
- }
+ {
+ stop_on_closest = GNUNET_YES;
+ }
if (GNUNET_YES ==
GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", "stop_found"))
- {
- stop_on_found = GNUNET_YES;
- }
+ {
+ stop_on_found = GNUNET_YES;
+ }
if (GNUNET_YES ==
GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", "malicious_getter"))
- {
- malicious_getter = GNUNET_YES;
- if (GNUNET_NO == GNUNET_CONFIGURATION_get_value_number (cfg, "DHT",
-
"MALICIOUS_GET_FREQUENCY",
-
&malicious_get_frequency))
- malicious_get_frequency = DEFAULT_MALICIOUS_GET_FREQUENCY;
- }
+ {
+ malicious_getter = GNUNET_YES;
+ if (GNUNET_NO == GNUNET_CONFIGURATION_get_value_number (cfg, "DHT",
+
"MALICIOUS_GET_FREQUENCY",
+
&malicious_get_frequency))
+ malicious_get_frequency = DEFAULT_MALICIOUS_GET_FREQUENCY;
+ }
if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_number (cfg, "DHT",
"MAX_HOPS",
&max_hops))
- {
- max_hops = DEFAULT_MAX_HOPS;
- }
+ {
+ max_hops = DEFAULT_MAX_HOPS;
+ }
if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (cfg, "DHT",
"USE_MAX_HOPS"))
- {
- use_max_hops = GNUNET_YES;
- }
+ {
+ use_max_hops = GNUNET_YES;
+ }
if (GNUNET_YES ==
GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", "malicious_putter"))
- {
- malicious_putter = GNUNET_YES;
- if (GNUNET_NO == GNUNET_CONFIGURATION_get_value_number (cfg, "DHT",
-
"MALICIOUS_PUT_FREQUENCY",
-
&malicious_put_frequency))
- malicious_put_frequency = DEFAULT_MALICIOUS_PUT_FREQUENCY;
- }
+ {
+ malicious_putter = GNUNET_YES;
+ if (GNUNET_NO == GNUNET_CONFIGURATION_get_value_number (cfg, "DHT",
+
"MALICIOUS_PUT_FREQUENCY",
+
&malicious_put_frequency))
+ malicious_put_frequency = DEFAULT_MALICIOUS_PUT_FREQUENCY;
+ }
dht_republish_frequency = GNUNET_DHT_DEFAULT_REPUBLISH_FREQUENCY;
if (GNUNET_OK ==
GNUNET_CONFIGURATION_get_value_number (cfg, "DHT",
"REPLICATION_FREQUENCY",
&temp_config_num))
- {
- dht_republish_frequency =
+ {
+ dht_republish_frequency =
GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES,
temp_config_num);
- }
+ }
if (GNUNET_OK ==
GNUNET_CONFIGURATION_get_value_number (cfg, "DHT", "bucket_size",
&temp_config_num))
- {
- bucket_size = (unsigned int) temp_config_num;
- }
+ {
+ bucket_size = (unsigned int) temp_config_num;
+ }
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_number (cfg, "DHT", "kad_alpha",
&kademlia_replication))
- {
- kademlia_replication = DEFAULT_KADEMLIA_REPLICATION;
- }
+ {
+ kademlia_replication = DEFAULT_KADEMLIA_REPLICATION;
+ }
if (GNUNET_YES ==
GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", "malicious_dropper"))
- {
- malicious_dropper = GNUNET_YES;
- }
+ {
+ malicious_dropper = GNUNET_YES;
+ }
if (GNUNET_YES ==
GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", "republish"))
@@ -5408,9 +5463,9 @@
if (GNUNET_NO ==
GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", "do_find_peer"))
- {
- do_find_peer = GNUNET_NO;
- }
+ {
+ do_find_peer = GNUNET_NO;
+ }
else
do_find_peer = GNUNET_YES;
@@ -5421,113 +5476,109 @@
if (GNUNET_YES ==
GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht_testing",
"mysql_logging_extended"))
- {
- debug_routes = GNUNET_YES;
- debug_routes_extended = GNUNET_YES;
- }
+ {
+ debug_routes = GNUNET_YES;
+ debug_routes_extended = GNUNET_YES;
+ }
#if DEBUG_DHT_ROUTING
if (GNUNET_YES == debug_routes)
+ {
+ dhtlog_handle = GNUNET_DHTLOG_connect (cfg);
+ if (dhtlog_handle == NULL)
{
- dhtlog_handle = GNUNET_DHTLOG_connect (cfg);
- if (dhtlog_handle == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Could not connect to mysql logging server, logging will
not happen!");
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Could not connect to mysql logging server, logging will not
happen!");
}
+ }
#endif
converge_option = DHT_CONVERGE_BINARY;
if (GNUNET_YES ==
GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", "converge_linear"))
- {
- converge_option = DHT_CONVERGE_LINEAR;
- }
+ {
+ converge_option = DHT_CONVERGE_LINEAR;
+ }
else if (GNUNET_YES ==
GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht",
"converge_exponential"))
- {
- converge_option = DHT_CONVERGE_EXPONENTIAL;
- }
+ {
+ converge_option = DHT_CONVERGE_EXPONENTIAL;
+ }
else if (GNUNET_YES ==
- GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht",
- "converge_random"))
- {
- converge_option = DHT_CONVERGE_RANDOM;
- }
+ GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht",
"converge_random"))
+ {
+ converge_option = DHT_CONVERGE_RANDOM;
+ }
else if (GNUNET_YES ==
- GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht",
- "converge_binary"))
- {
- converge_option = DHT_CONVERGE_BINARY;
- }
+ GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht",
"converge_binary"))
+ {
+ converge_option = DHT_CONVERGE_BINARY;
+ }
converge_modifier = 4.0;
if (GNUNET_OK ==
GNUNET_CONFIGURATION_get_value_string (cfg, "dht", "converge_modifier",
&converge_modifier_buf))
+ {
+ if (1 != sscanf (converge_modifier_buf, "%f", &converge_modifier))
{
- if (1 != sscanf (converge_modifier_buf, "%f", &converge_modifier))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Failed to read decimal value for %s from `%s'\n",
- "CONVERGE_MODIFIER", converge_modifier_buf);
- converge_modifier = 0.0;
- }
- GNUNET_free (converge_modifier_buf);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to read decimal value for %s from `%s'\n",
+ "CONVERGE_MODIFIER", converge_modifier_buf);
+ converge_modifier = 0.0;
}
+ GNUNET_free (converge_modifier_buf);
+ }
if (GNUNET_YES ==
GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", "paper_forwarding"))
- paper_forwarding = GNUNET_YES;
+ paper_forwarding = GNUNET_YES;
if (GNUNET_YES ==
GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", "put_peer_identities"))
- put_peer_identities = GNUNET_YES;
+ put_peer_identities = GNUNET_YES;
stats = GNUNET_STATISTICS_create ("dht", cfg);
if (stats != NULL)
- {
- GNUNET_STATISTICS_set (stats, STAT_ROUTES, 0, GNUNET_NO);
- GNUNET_STATISTICS_set (stats, STAT_ROUTE_FORWARDS, 0, GNUNET_NO);
- GNUNET_STATISTICS_set (stats, STAT_ROUTE_FORWARDS_CLOSEST, 0,
- GNUNET_NO);
- GNUNET_STATISTICS_set (stats, STAT_RESULTS, 0, GNUNET_NO);
- GNUNET_STATISTICS_set (stats, STAT_RESULTS_TO_CLIENT, 0, GNUNET_NO);
- GNUNET_STATISTICS_set (stats, STAT_RESULT_FORWARDS, 0, GNUNET_NO);
- GNUNET_STATISTICS_set (stats, STAT_GETS, 0, GNUNET_NO);
- GNUNET_STATISTICS_set (stats, STAT_PUTS, 0, GNUNET_NO);
- GNUNET_STATISTICS_set (stats, STAT_PUTS_INSERTED, 0, GNUNET_NO);
- GNUNET_STATISTICS_set (stats, STAT_FIND_PEER, 0, GNUNET_NO);
- GNUNET_STATISTICS_set (stats, STAT_FIND_PEER_START, 0, GNUNET_NO);
- GNUNET_STATISTICS_set (stats, STAT_GET_START, 0, GNUNET_NO);
- GNUNET_STATISTICS_set (stats, STAT_PUT_START, 0, GNUNET_NO);
- GNUNET_STATISTICS_set (stats, STAT_FIND_PEER_REPLY, 0, GNUNET_NO);
- GNUNET_STATISTICS_set (stats, STAT_FIND_PEER_ANSWER, 0, GNUNET_NO);
- GNUNET_STATISTICS_set (stats, STAT_BLOOM_FIND_PEER, 0, GNUNET_NO);
- GNUNET_STATISTICS_set (stats, STAT_GET_REPLY, 0, GNUNET_NO);
- GNUNET_STATISTICS_set (stats, STAT_GET_RESPONSE_START, 0, GNUNET_NO);
- GNUNET_STATISTICS_set (stats, STAT_HELLOS_PROVIDED, 0, GNUNET_NO);
- GNUNET_STATISTICS_set (stats, STAT_DISCONNECTS, 0, GNUNET_NO);
- }
+ {
+ GNUNET_STATISTICS_set (stats, STAT_ROUTES, 0, GNUNET_NO);
+ GNUNET_STATISTICS_set (stats, STAT_ROUTE_FORWARDS, 0, GNUNET_NO);
+ GNUNET_STATISTICS_set (stats, STAT_ROUTE_FORWARDS_CLOSEST, 0, GNUNET_NO);
+ GNUNET_STATISTICS_set (stats, STAT_RESULTS, 0, GNUNET_NO);
+ GNUNET_STATISTICS_set (stats, STAT_RESULTS_TO_CLIENT, 0, GNUNET_NO);
+ GNUNET_STATISTICS_set (stats, STAT_RESULT_FORWARDS, 0, GNUNET_NO);
+ GNUNET_STATISTICS_set (stats, STAT_GETS, 0, GNUNET_NO);
+ GNUNET_STATISTICS_set (stats, STAT_PUTS, 0, GNUNET_NO);
+ GNUNET_STATISTICS_set (stats, STAT_PUTS_INSERTED, 0, GNUNET_NO);
+ GNUNET_STATISTICS_set (stats, STAT_FIND_PEER, 0, GNUNET_NO);
+ GNUNET_STATISTICS_set (stats, STAT_FIND_PEER_START, 0, GNUNET_NO);
+ GNUNET_STATISTICS_set (stats, STAT_GET_START, 0, GNUNET_NO);
+ GNUNET_STATISTICS_set (stats, STAT_PUT_START, 0, GNUNET_NO);
+ GNUNET_STATISTICS_set (stats, STAT_FIND_PEER_REPLY, 0, GNUNET_NO);
+ GNUNET_STATISTICS_set (stats, STAT_FIND_PEER_ANSWER, 0, GNUNET_NO);
+ GNUNET_STATISTICS_set (stats, STAT_BLOOM_FIND_PEER, 0, GNUNET_NO);
+ GNUNET_STATISTICS_set (stats, STAT_GET_REPLY, 0, GNUNET_NO);
+ GNUNET_STATISTICS_set (stats, STAT_GET_RESPONSE_START, 0, GNUNET_NO);
+ GNUNET_STATISTICS_set (stats, STAT_HELLOS_PROVIDED, 0, GNUNET_NO);
+ GNUNET_STATISTICS_set (stats, STAT_DISCONNECTS, 0, GNUNET_NO);
+ }
/* FIXME: if there are no recent requests then these never get freed, but
alternative is _annoying_! */
recent.hashmap = GNUNET_CONTAINER_multihashmap_create (DHT_MAX_RECENT / 2);
recent.minHeap =
- GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
+ GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
if (GNUNET_YES == do_find_peer)
- {
- next_send_time.rel_value = DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value +
+ {
+ next_send_time.rel_value = DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value +
GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG,
(DHT_MAXIMUM_FIND_PEER_INTERVAL.rel_value /
2) -
DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value);
- find_peer_context.start = GNUNET_TIME_absolute_get ();
- GNUNET_SCHEDULER_add_delayed (next_send_time,
- &send_find_peer_message,
- &find_peer_context);
- }
+ find_peer_context.start = GNUNET_TIME_absolute_get ();
+ GNUNET_SCHEDULER_add_delayed (next_send_time,
+ &send_find_peer_message, &find_peer_context);
+ }
/* Scheduled the task to clean up when shutdown is called */
cleanup_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
@@ -5552,21 +5603,21 @@
"dht",
GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
if (NULL != recent.hashmap)
- {
- GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (recent.hashmap));
- GNUNET_CONTAINER_multihashmap_destroy (recent.hashmap);
- recent.hashmap = NULL;
- }
+ {
+ GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (recent.hashmap));
+ GNUNET_CONTAINER_multihashmap_destroy (recent.hashmap);
+ recent.hashmap = NULL;
+ }
if (NULL != recent.minHeap)
- {
- GNUNET_assert (0 == GNUNET_CONTAINER_heap_get_size (recent.minHeap));
- GNUNET_CONTAINER_heap_destroy (recent.minHeap);
- recent.minHeap = NULL;
- }
+ {
+ GNUNET_assert (0 == GNUNET_CONTAINER_heap_get_size (recent.minHeap));
+ GNUNET_CONTAINER_heap_destroy (recent.minHeap);
+ recent.minHeap = NULL;
+ }
if (NULL != recent_find_peer_requests)
- {
- GNUNET_CONTAINER_multihashmap_destroy (recent_find_peer_requests);
- recent_find_peer_requests = NULL;
- }
- return ret;
+ {
+ GNUNET_CONTAINER_multihashmap_destroy (recent_find_peer_requests);
+ recent_find_peer_requests = NULL;
+ }
+ return ret;
}
Modified: gnunet/src/dht/plugin_dhtlog_dummy.c
===================================================================
--- gnunet/src/dht/plugin_dhtlog_dummy.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/dht/plugin_dhtlog_dummy.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -39,7 +39,8 @@
*
* @return GNUNET_OK on success, GNUNET_SYSERR on failure
*/
-int add_trial (struct GNUNET_DHTLOG_TrialInfo *trial_info)
+int
+add_trial (struct GNUNET_DHTLOG_TrialInfo *trial_info)
{
return GNUNET_OK;
}
@@ -52,7 +53,8 @@
*
* @return GNUNET_OK on success, GNUNET_SYSERR on failure
*/
-int add_round (unsigned int round_type, unsigned int round_count)
+int
+add_round (unsigned int round_type, unsigned int round_count)
{
return GNUNET_OK;
}
@@ -68,8 +70,10 @@
*
* @return GNUNET_OK on success, GNUNET_SYSERR on failure
*/
-int add_round_details (unsigned int round_type, unsigned int round_count,
- unsigned int num_messages, unsigned int
num_messages_succeded)
+int
+add_round_details (unsigned int round_type, unsigned int round_count,
+ unsigned int num_messages,
+ unsigned int num_messages_succeded)
{
return GNUNET_OK;
}
@@ -100,7 +104,7 @@
* @return GNUNET_OK on success, GNUNET_SYSERR on failure
*/
int
-add_node (unsigned long long *nodeuid, struct GNUNET_PeerIdentity * node)
+add_node (unsigned long long *nodeuid, struct GNUNET_PeerIdentity *node)
{
*nodeuid = 1337;
return GNUNET_OK;
@@ -132,8 +136,7 @@
*/
int
add_generic_stat (const struct GNUNET_PeerIdentity *peer,
- const char *name,
- const char *section, uint64_t value)
+ const char *name, const char *section, uint64_t value)
{
return GNUNET_OK;
}
@@ -167,7 +170,7 @@
int
add_query (unsigned long long *sqlqueryuid, unsigned long long queryid,
unsigned int type, unsigned int hops, int succeeded,
- const struct GNUNET_PeerIdentity * node, const GNUNET_HashCode *
key)
+ const struct GNUNET_PeerIdentity *node, const GNUNET_HashCode * key)
{
*sqlqueryuid = 17;
return GNUNET_OK;
@@ -191,9 +194,10 @@
int
add_route (unsigned long long *sqlqueryuid, unsigned long long queryid,
unsigned int type, unsigned int hops,
- int succeeded, const struct GNUNET_PeerIdentity * node,
- const GNUNET_HashCode * key, const struct GNUNET_PeerIdentity *
from_node,
- const struct GNUNET_PeerIdentity * to_node)
+ int succeeded, const struct GNUNET_PeerIdentity *node,
+ const GNUNET_HashCode * key,
+ const struct GNUNET_PeerIdentity *from_node,
+ const struct GNUNET_PeerIdentity *to_node)
{
*sqlqueryuid = 18;
return GNUNET_OK;
@@ -222,7 +226,8 @@
* @return GNUNET_OK on success, GNUNET_SYSERR on failure
*/
int
-add_extended_topology (const struct GNUNET_PeerIdentity *first, const struct
GNUNET_PeerIdentity *second)
+add_extended_topology (const struct GNUNET_PeerIdentity *first,
+ const struct GNUNET_PeerIdentity *second)
{
return GNUNET_OK;
}
@@ -278,15 +283,15 @@
* @return GNUNET_OK on success, GNUNET_SYSERR on failure
*/
int insert_stat
- (const struct GNUNET_PeerIdentity *peer, unsigned int route_requests,
- unsigned int route_forwards, unsigned int result_requests,
- unsigned int client_requests, unsigned int result_forwards,
- unsigned int gets, unsigned int puts,
- unsigned int data_inserts, unsigned int find_peer_requests,
- unsigned int find_peers_started, unsigned int gets_started,
- unsigned int puts_started, unsigned int find_peer_responses_received,
- unsigned int get_responses_received, unsigned int find_peer_responses_sent,
- unsigned int get_responses_sent)
+ (const struct GNUNET_PeerIdentity *peer, unsigned int route_requests,
+ unsigned int route_forwards, unsigned int result_requests,
+ unsigned int client_requests, unsigned int result_forwards,
+ unsigned int gets, unsigned int puts,
+ unsigned int data_inserts, unsigned int find_peer_requests,
+ unsigned int find_peers_started, unsigned int gets_started,
+ unsigned int puts_started, unsigned int find_peer_responses_received,
+ unsigned int get_responses_received, unsigned int
find_peer_responses_sent,
+ unsigned int get_responses_sent)
{
return GNUNET_OK;
}
@@ -299,14 +304,15 @@
* @return the handle to the server, or NULL on error
*/
void *
-libgnunet_plugin_dhtlog_dummy_init (void * cls)
+libgnunet_plugin_dhtlog_dummy_init (void *cls)
{
struct GNUNET_DHTLOG_Plugin *plugin = cls;
+
#if DEBUG_DHTLOG
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "DUMMY DHT Logger: initializing.\n");
#endif
- GNUNET_assert(plugin->dhtlog_api == NULL);
- plugin->dhtlog_api = GNUNET_malloc(sizeof(struct GNUNET_DHTLOG_Handle));
+ GNUNET_assert (plugin->dhtlog_api == NULL);
+ plugin->dhtlog_api = GNUNET_malloc (sizeof (struct GNUNET_DHTLOG_Handle));
plugin->dhtlog_api->add_generic_stat = &add_generic_stat;
plugin->dhtlog_api->insert_round = &add_round;
plugin->dhtlog_api->insert_round_details = &add_round_details;
@@ -329,11 +335,10 @@
* Shutdown the plugin.
*/
void *
-libgnunet_plugin_dhtlog_dummy_done (void * cls)
+libgnunet_plugin_dhtlog_dummy_done (void *cls)
{
#if DEBUG_DHTLOG
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "DUMMY DHT Logger: shutdown\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "DUMMY DHT Logger: shutdown\n");
#endif
return NULL;
}
Modified: gnunet/src/dht/plugin_dhtlog_mysql.c
===================================================================
--- gnunet/src/dht/plugin_dhtlog_mysql.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/dht/plugin_dhtlog_mysql.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -188,11 +188,10 @@
{
mysql_query (conn, statement);
if (mysql_error (conn)[0])
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "mysql_query");
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "mysql_query");
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
}
@@ -253,46 +252,46 @@
return GNUNET_SYSERR;
if (MRUNS ("CREATE TABLE IF NOT EXISTS `trials` ("
- "`trialuid` int(10) unsigned NOT NULL auto_increment,"
- "`other_trial_identifier` int(10) unsigned NOT NULL default '0',"
- "`numnodes` int(10) unsigned NOT NULL,"
- "`topology` int(10) NOT NULL,"
- "`blacklist_topology` int(11) NOT NULL,"
- "`connect_topology` int(11) NOT NULL,"
- "`connect_topology_option` int(11) NOT NULL,"
- "`topology_percentage` float NOT NULL,"
- "`topology_probability` float NOT NULL,"
- "`connect_topology_option_modifier` float NOT NULL,"
- "`starttime` datetime NOT NULL,"
- "`endtime` datetime NOT NULL,"
- "`puts` int(10) unsigned NOT NULL,"
- "`gets` int(10) unsigned NOT NULL,"
- "`concurrent` int(10) unsigned NOT NULL,"
- "`settle_time` int(10) unsigned NOT NULL,"
- "`totalConnections` int(10) unsigned NOT NULL,"
- "`message` text NOT NULL,"
- "`num_rounds` int(10) unsigned NOT NULL,"
- "`malicious_getters` int(10) unsigned NOT NULL,"
- "`malicious_putters` int(10) unsigned NOT NULL,"
- "`malicious_droppers` int(10) unsigned NOT NULL,"
- "`topology_modifier` double NOT NULL,"
- "`malicious_get_frequency` int(10) unsigned NOT NULL,"
- "`malicious_put_frequency` int(10) unsigned NOT NULL,"
- "`stop_closest` int(10) unsigned NOT NULL,"
- "`stop_found` int(10) unsigned NOT NULL,"
- "`strict_kademlia` int(10) unsigned NOT NULL,"
- "`gets_succeeded` int(10) unsigned NOT NULL,"
- "PRIMARY KEY (`trialuid`),"
- "UNIQUE KEY `trialuid` (`trialuid`)"
- ") ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1"))
+ "`trialuid` int(10) unsigned NOT NULL auto_increment,"
+ "`other_trial_identifier` int(10) unsigned NOT NULL default '0',"
+ "`numnodes` int(10) unsigned NOT NULL,"
+ "`topology` int(10) NOT NULL,"
+ "`blacklist_topology` int(11) NOT NULL,"
+ "`connect_topology` int(11) NOT NULL,"
+ "`connect_topology_option` int(11) NOT NULL,"
+ "`topology_percentage` float NOT NULL,"
+ "`topology_probability` float NOT NULL,"
+ "`connect_topology_option_modifier` float NOT NULL,"
+ "`starttime` datetime NOT NULL,"
+ "`endtime` datetime NOT NULL,"
+ "`puts` int(10) unsigned NOT NULL,"
+ "`gets` int(10) unsigned NOT NULL,"
+ "`concurrent` int(10) unsigned NOT NULL,"
+ "`settle_time` int(10) unsigned NOT NULL,"
+ "`totalConnections` int(10) unsigned NOT NULL,"
+ "`message` text NOT NULL,"
+ "`num_rounds` int(10) unsigned NOT NULL,"
+ "`malicious_getters` int(10) unsigned NOT NULL,"
+ "`malicious_putters` int(10) unsigned NOT NULL,"
+ "`malicious_droppers` int(10) unsigned NOT NULL,"
+ "`topology_modifier` double NOT NULL,"
+ "`malicious_get_frequency` int(10) unsigned NOT NULL,"
+ "`malicious_put_frequency` int(10) unsigned NOT NULL,"
+ "`stop_closest` int(10) unsigned NOT NULL,"
+ "`stop_found` int(10) unsigned NOT NULL,"
+ "`strict_kademlia` int(10) unsigned NOT NULL,"
+ "`gets_succeeded` int(10) unsigned NOT NULL,"
+ "PRIMARY KEY (`trialuid`),"
+ "UNIQUE KEY `trialuid` (`trialuid`)"
+ ") ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1"))
return GNUNET_SYSERR;
if (MRUNS ("CREATE TABLE IF NOT EXISTS `topology` ("
- "`topology_uid` int(10) unsigned NOT NULL AUTO_INCREMENT,"
- "`trialuid` int(10) unsigned NOT NULL,"
- "`date` datetime NOT NULL,"
- "`connections` int(10) unsigned NOT NULL,"
- "PRIMARY KEY (`topology_uid`)) ENGINE=MyISAM DEFAULT
CHARSET=utf8 AUTO_INCREMENT=1"))
+ "`topology_uid` int(10) unsigned NOT NULL AUTO_INCREMENT,"
+ "`trialuid` int(10) unsigned NOT NULL,"
+ "`date` datetime NOT NULL,"
+ "`connections` int(10) unsigned NOT NULL,"
+ "PRIMARY KEY (`topology_uid`)) ENGINE=MyISAM DEFAULT
CHARSET=utf8 AUTO_INCREMENT=1"))
return GNUNET_SYSERR;
if (MRUNS ("CREATE TABLE IF NOT EXISTS `extended_topology` ("
@@ -305,27 +304,27 @@
return GNUNET_SYSERR;
if (MRUNS ("CREATE TABLE IF NOT EXISTS `node_statistics` ("
- "`stat_uid` int(10) unsigned NOT NULL AUTO_INCREMENT,"
- "`trialuid` int(10) unsigned NOT NULL,"
- "`nodeuid` int(10) unsigned NOT NULL,"
- "`route_requests` int(10) unsigned NOT NULL,"
- "`route_forwards` int(10) unsigned NOT NULL,"
- "`result_requests` int(10) unsigned NOT NULL,"
- "`client_results` int(10) unsigned NOT NULL,"
- "`result_forwards` int(10) unsigned NOT NULL,"
- "`gets` int(10) unsigned NOT NULL,"
- "`puts` int(10) unsigned NOT NULL,"
- "`data_inserts` int(10) unsigned NOT NULL,"
- "`find_peer_requests` int(10) unsigned NOT NULL,"
- "`find_peers_started` int(10) unsigned NOT NULL,"
- "`gets_started` int(10) unsigned NOT NULL,"
- "`puts_started` int(10) unsigned NOT NULL,"
- "`find_peer_responses_received` int(10) unsigned NOT NULL,"
- "`get_responses_received` int(10) unsigned NOT NULL,"
- "`find_peer_responses_sent` int(10) unsigned NOT NULL,"
- "`get_responses_sent` int(10) unsigned NOT NULL,"
+ "`stat_uid` int(10) unsigned NOT NULL AUTO_INCREMENT,"
+ "`trialuid` int(10) unsigned NOT NULL,"
+ "`nodeuid` int(10) unsigned NOT NULL,"
+ "`route_requests` int(10) unsigned NOT NULL,"
+ "`route_forwards` int(10) unsigned NOT NULL,"
+ "`result_requests` int(10) unsigned NOT NULL,"
+ "`client_results` int(10) unsigned NOT NULL,"
+ "`result_forwards` int(10) unsigned NOT NULL,"
+ "`gets` int(10) unsigned NOT NULL,"
+ "`puts` int(10) unsigned NOT NULL,"
+ "`data_inserts` int(10) unsigned NOT NULL,"
+ "`find_peer_requests` int(10) unsigned NOT NULL,"
+ "`find_peers_started` int(10) unsigned NOT NULL,"
+ "`gets_started` int(10) unsigned NOT NULL,"
+ "`puts_started` int(10) unsigned NOT NULL,"
+ "`find_peer_responses_received` int(10) unsigned NOT NULL,"
+ "`get_responses_received` int(10) unsigned NOT NULL,"
+ "`find_peer_responses_sent` int(10) unsigned NOT NULL,"
+ "`get_responses_sent` int(10) unsigned NOT NULL,"
"PRIMARY KEY (`stat_uid`)"
- ") ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;"))
+ ") ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;"))
return GNUNET_SYSERR;
if (MRUNS ("SET AUTOCOMMIT = 1"))
@@ -359,15 +358,15 @@
prepared_statement_close (struct StatementHandle *s)
{
if (s == NULL)
- {
- return;
- }
+ {
+ return;
+ }
- GNUNET_free_non_null(s->query);
+ GNUNET_free_non_null (s->query);
if (s->valid == GNUNET_YES)
- mysql_stmt_close(s->statement);
- GNUNET_free(s);
+ mysql_stmt_close (s->statement);
+ GNUNET_free (s);
}
/*
@@ -390,61 +389,65 @@
return GNUNET_SYSERR;
if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (plugin->cfg,
- "MYSQL", "DATABASE",
- &database))
- {
- database = GNUNET_strdup("gnunet");
- }
+ "MYSQL", "DATABASE",
+ &database))
+ {
+ database = GNUNET_strdup ("gnunet");
+ }
if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (plugin->cfg,
- "MYSQL", "USER",
&user))
- {
- user = GNUNET_strdup("dht");
- }
+ "MYSQL", "USER",
+ &user))
+ {
+ user = GNUNET_strdup ("dht");
+ }
if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (plugin->cfg,
- "MYSQL", "PASSWORD",
&password))
- {
- password = GNUNET_strdup("dhttest**");
- }
+ "MYSQL", "PASSWORD",
+ &password))
+ {
+ password = GNUNET_strdup ("dhttest**");
+ }
if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (plugin->cfg,
- "MYSQL", "SERVER",
&server))
- {
- server = GNUNET_strdup("localhost");
- }
+ "MYSQL", "SERVER",
+ &server))
+ {
+ server = GNUNET_strdup ("localhost");
+ }
if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (plugin->cfg,
- "MYSQL",
"MYSQL_PORT", &port))
- {
- port = 0;
- }
+ "MYSQL",
"MYSQL_PORT",
+ &port))
+ {
+ port = 0;
+ }
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting to mysql with: user %s,
pass %s, server %s, database %s, port %d\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Connecting to mysql with: user %s, pass %s, server %s, database
%s, port %d\n",
user, password, server, database, port);
reconnect = 0;
- timeout = 60; /* in seconds */
+ timeout = 60; /* in seconds */
mysql_options (conn, MYSQL_OPT_RECONNECT, &reconnect);
- mysql_options (conn,
- MYSQL_OPT_CONNECT_TIMEOUT, (const void *) &timeout);
- mysql_options(conn, MYSQL_SET_CHARSET_NAME, "UTF8");
+ mysql_options (conn, MYSQL_OPT_CONNECT_TIMEOUT, (const void *) &timeout);
+ mysql_options (conn, MYSQL_SET_CHARSET_NAME, "UTF8");
mysql_options (conn, MYSQL_OPT_READ_TIMEOUT, (const void *) &timeout);
mysql_options (conn, MYSQL_OPT_WRITE_TIMEOUT, (const void *) &timeout);
mysql_real_connect (conn, server, user, password,
- database, (unsigned int) port, NULL,
CLIENT_IGNORE_SIGPIPE);
+ database, (unsigned int) port, NULL,
+ CLIENT_IGNORE_SIGPIPE);
- GNUNET_free_non_null(server);
- GNUNET_free_non_null(password);
- GNUNET_free_non_null(user);
- GNUNET_free_non_null(database);
+ GNUNET_free_non_null (server);
+ GNUNET_free_non_null (password);
+ GNUNET_free_non_null (user);
+ GNUNET_free_non_null (database);
if (mysql_error (conn)[0])
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "mysql_real_connect");
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "mysql_real_connect");
+ return GNUNET_SYSERR;
+ }
#if OLD
db = GNUNET_MYSQL_database_open (coreAPI->ectx, coreAPI->cfg);
@@ -473,10 +476,10 @@
PINIT (insert_topology, INSERT_TOPOLOGY_STMT) ||
PINIT (update_topology, UPDATE_TOPOLOGY_STMT) ||
PINIT (extend_topology, EXTEND_TOPOLOGY_STMT) ||
- PINIT (update_node_malicious, SET_MALICIOUS_STMT) )
- {
- return GNUNET_SYSERR;
- }
+ PINIT (update_node_malicious, SET_MALICIOUS_STMT))
+ {
+ return GNUNET_SYSERR;
+ }
#undef PINIT
return ret;
@@ -504,13 +507,13 @@
return GNUNET_SYSERR;
if (mysql_stmt_prepare (ret->statement, ret->query, strlen (ret->query)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "mysql_stmt_prepare `%s', %s", ret->query, mysql_error(conn));
- mysql_stmt_close (ret->statement);
- ret->statement = NULL;
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "mysql_stmt_prepare `%s', %s", ret->query, mysql_error (conn));
+ mysql_stmt_close (ret->statement);
+ ret->statement = NULL;
+ return GNUNET_SYSERR;
+ }
ret->valid = GNUNET_YES;
return GNUNET_OK;
}
@@ -533,67 +536,71 @@
pc = mysql_stmt_param_count (s->statement);
if (pc > MAX_PARAM)
- {
- /* increase internal constant! */
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
+ {
+ /* increase internal constant! */
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
memset (qbind, 0, sizeof (qbind));
off = 0;
ft = 0;
while ((pc > 0) && (-1 != (ft = va_arg (ap, enum enum_field_types))))
+ {
+ qbind[off].buffer_type = ft;
+ switch (ft)
{
- qbind[off].buffer_type = ft;
- switch (ft)
- {
- case MYSQL_TYPE_FLOAT:
- qbind[off].buffer = va_arg (ap, float *);
- break;
- case MYSQL_TYPE_LONGLONG:
- qbind[off].buffer = va_arg (ap, unsigned long long *);
- qbind[off].is_unsigned = va_arg (ap, int);
- break;
- case MYSQL_TYPE_LONG:
- qbind[off].buffer = va_arg (ap, unsigned int *);
- qbind[off].is_unsigned = va_arg (ap, int);
- break;
- case MYSQL_TYPE_VAR_STRING:
- case MYSQL_TYPE_STRING:
- case MYSQL_TYPE_BLOB:
- qbind[off].buffer = va_arg (ap, void *);
- qbind[off].buffer_length = va_arg (ap, unsigned long);
- qbind[off].length = va_arg (ap, unsigned long *);
- break;
- default:
- /* unsupported type */
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
- pc--;
- off++;
- }
- if (!((pc == 0) && (ft != -1) && (va_arg (ap, int) == -1)))
- {
+ case MYSQL_TYPE_FLOAT:
+ qbind[off].buffer = va_arg (ap, float *);
+
+ break;
+ case MYSQL_TYPE_LONGLONG:
+ qbind[off].buffer = va_arg (ap, unsigned long long *);
+ qbind[off].is_unsigned = va_arg (ap, int);
+
+ break;
+ case MYSQL_TYPE_LONG:
+ qbind[off].buffer = va_arg (ap, unsigned int *);
+ qbind[off].is_unsigned = va_arg (ap, int);
+
+ break;
+ case MYSQL_TYPE_VAR_STRING:
+ case MYSQL_TYPE_STRING:
+ case MYSQL_TYPE_BLOB:
+ qbind[off].buffer = va_arg (ap, void *);
+ qbind[off].buffer_length = va_arg (ap, unsigned long);
+ qbind[off].length = va_arg (ap, unsigned long *);
+
+ break;
+ default:
+ /* unsupported type */
GNUNET_break (0);
return GNUNET_SYSERR;
}
+ pc--;
+ off++;
+ }
+ if (!((pc == 0) && (ft != -1) && (va_arg (ap, int) == -1)))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
if (mysql_stmt_bind_param (s->statement, qbind))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("`%s' failed at %s:%d with error: %s\n"),
- "mysql_stmt_bind_param",
- __FILE__, __LINE__, mysql_stmt_error (s->statement));
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("`%s' failed at %s:%d with error: %s\n"),
+ "mysql_stmt_bind_param",
+ __FILE__, __LINE__, mysql_stmt_error (s->statement));
+ return GNUNET_SYSERR;
+ }
if (mysql_stmt_execute (s->statement))
- {
+ {
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("`%s' failed at %s:%d with error: %s\n"),
- "mysql_stmt_execute",
- __FILE__, __LINE__, mysql_stmt_error (s->statement));
- return GNUNET_SYSERR;
- }
+ _("`%s' failed at %s:%d with error: %s\n"),
+ "mysql_stmt_execute",
+ __FILE__, __LINE__, mysql_stmt_error (s->statement));
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
}
@@ -619,8 +626,7 @@
unsigned int result_size,
MYSQL_BIND * results,
GNUNET_MysqlDataProcessor
- processor, void *processor_cls,
- ...)
+ processor, void *processor_cls, ...)
{
va_list ap;
int ret;
@@ -628,52 +634,52 @@
int total;
if (GNUNET_OK != prepare_statement (s))
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
va_start (ap, processor_cls);
if (GNUNET_OK != init_params (s, ap))
- {
- GNUNET_break (0);
- va_end (ap);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_break (0);
+ va_end (ap);
+ return GNUNET_SYSERR;
+ }
va_end (ap);
rsize = mysql_stmt_field_count (s->statement);
if (rsize > result_size)
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
if (mysql_stmt_bind_result (s->statement, results))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("`%s' failed at %s:%d with error: %s\n"),
+ "mysql_stmt_bind_result",
+ __FILE__, __LINE__, mysql_stmt_error (s->statement));
+ return GNUNET_SYSERR;
+ }
+
+ total = 0;
+ while (1)
+ {
+ ret = mysql_stmt_fetch (s->statement);
+ if (ret == MYSQL_NO_DATA)
+ break;
+ if (ret != 0)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("`%s' failed at %s:%d with error: %s\n"),
- "mysql_stmt_bind_result",
+ "mysql_stmt_fetch",
__FILE__, __LINE__, mysql_stmt_error (s->statement));
return GNUNET_SYSERR;
}
-
- total = 0;
- while (1)
- {
- ret = mysql_stmt_fetch (s->statement);
- if (ret == MYSQL_NO_DATA)
+ if (processor != NULL)
+ if (GNUNET_OK != processor (processor_cls, rsize, results))
break;
- if (ret != 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("`%s' failed at %s:%d with error: %s\n"),
- "mysql_stmt_fetch",
- __FILE__, __LINE__, mysql_stmt_error (s->statement));
- return GNUNET_SYSERR;
- }
- if (processor != NULL)
- if (GNUNET_OK != processor (processor_cls, rsize, results))
- break;
- total++;
- }
+ total++;
+ }
mysql_stmt_reset (s->statement);
return total;
}
@@ -695,23 +701,22 @@
p_len = strlen ((char *) &encPeer);
if (1 != prepared_statement_run_select (get_nodeuid,
- 1,
- rbind,
- return_ok,
- NULL,
-
MYSQL_TYPE_LONGLONG,
- ¤t_trial,
- GNUNET_YES,
-
MYSQL_TYPE_VAR_STRING,
- &encPeer,
- max_varchar_len,
- &p_len, -1))
- {
+ 1,
+ rbind,
+ return_ok,
+ NULL,
+ MYSQL_TYPE_LONGLONG,
+ ¤t_trial,
+ GNUNET_YES,
+ MYSQL_TYPE_VAR_STRING,
+ &encPeer,
+ max_varchar_len, &p_len, -1))
+ {
#if DEBUG_DHTLOG
- fprintf (stderr, "FAILED\n");
+ fprintf (stderr, "FAILED\n");
#endif
- return GNUNET_SYSERR;
- }
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
}
@@ -727,12 +732,10 @@
if ((GNUNET_OK !=
prepared_statement_run_select (get_trial,
- 1,
- rbind,
- return_ok, NULL, -1)))
- {
- return GNUNET_SYSERR;
- }
+ 1, rbind, return_ok, NULL, -1)))
+ {
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
}
@@ -749,12 +752,10 @@
if ((GNUNET_OK !=
prepared_statement_run_select (get_topology,
- 1,
- rbind,
- return_ok, NULL, -1)))
- {
- return GNUNET_SYSERR;
- }
+ 1, rbind, return_ok, NULL, -1)))
+ {
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
}
@@ -765,6 +766,7 @@
MYSQL_BIND rbind[1];
struct GNUNET_CRYPTO_HashAsciiEncoded encKey;
unsigned long long k_len;
+
memset (rbind, 0, sizeof (rbind));
rbind[0].buffer_type = MYSQL_TYPE_LONG;
rbind[0].is_unsigned = 1;
@@ -772,7 +774,9 @@
GNUNET_CRYPTO_hash_to_enc (key, &encKey);
k_len = strlen ((char *) &encKey);
#if DEBUG_DHTLOG
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Searching for dhtkey `%s' in trial
%llu\n", GNUNET_h2s(key), current_trial);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Searching for dhtkey `%s' in trial %llu\n", GNUNET_h2s (key),
+ current_trial);
#endif
if ((GNUNET_OK !=
prepared_statement_run_select (get_dhtkeyuid,
@@ -784,11 +788,10 @@
max_varchar_len,
&k_len,
MYSQL_TYPE_LONGLONG,
- ¤t_trial,
- GNUNET_YES, -1)))
- {
- return GNUNET_SYSERR;
- }
+ ¤t_trial, GNUNET_YES, -1)))
+ {
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
}
@@ -813,22 +816,22 @@
va_list ap;
int affected;
- if (GNUNET_OK != prepare_statement(s))
- {
- GNUNET_break(0);
- return GNUNET_SYSERR;
- }
- GNUNET_assert(s->valid == GNUNET_YES);
+ if (GNUNET_OK != prepare_statement (s))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ GNUNET_assert (s->valid == GNUNET_YES);
if (s->statement == NULL)
return GNUNET_SYSERR;
va_start (ap, insert_id);
if (GNUNET_OK != init_params (s, ap))
- {
- va_end (ap);
- return GNUNET_SYSERR;
- }
+ {
+ va_end (ap);
+ return GNUNET_SYSERR;
+ }
va_end (ap);
affected = mysql_stmt_affected_rows (s->statement);
@@ -846,53 +849,73 @@
*
* @return GNUNET_OK on success, GNUNET_SYSERR on failure
*/
-int add_trial (struct GNUNET_DHTLOG_TrialInfo *trial_info)
+int
+add_trial (struct GNUNET_DHTLOG_TrialInfo *trial_info)
{
MYSQL_STMT *stmt;
int ret;
unsigned long long m_len;
+
m_len = strlen (trial_info->message);
- stmt = mysql_stmt_init(conn);
+ stmt = mysql_stmt_init (conn);
if (GNUNET_OK !=
(ret = prepared_statement_run (insert_trial, ¤t_trial,
- MYSQL_TYPE_LONG,
&trial_info->other_identifier, GNUNET_YES,
- MYSQL_TYPE_LONG, &trial_info->num_nodes,
GNUNET_YES,
- MYSQL_TYPE_LONG, &trial_info->topology,
GNUNET_YES,
- MYSQL_TYPE_FLOAT,
&trial_info->topology_percentage,
- MYSQL_TYPE_FLOAT,
&trial_info->topology_probability,
- MYSQL_TYPE_LONG,
&trial_info->blacklist_topology, GNUNET_YES,
- MYSQL_TYPE_LONG,
&trial_info->connect_topology, GNUNET_YES,
- MYSQL_TYPE_LONG,
&trial_info->connect_topology_option, GNUNET_YES,
- MYSQL_TYPE_FLOAT,
&trial_info->connect_topology_option_modifier,
- MYSQL_TYPE_LONG, &trial_info->puts,
GNUNET_YES,
- MYSQL_TYPE_LONG, &trial_info->gets,
GNUNET_YES,
- MYSQL_TYPE_LONG, &trial_info->concurrent,
GNUNET_YES,
- MYSQL_TYPE_LONG,
&trial_info->settle_time, GNUNET_YES,
- MYSQL_TYPE_LONG, &trial_info->num_rounds,
GNUNET_YES,
- MYSQL_TYPE_LONG,
&trial_info->malicious_getters, GNUNET_YES,
- MYSQL_TYPE_LONG,
&trial_info->malicious_putters, GNUNET_YES,
- MYSQL_TYPE_LONG,
&trial_info->malicious_droppers, GNUNET_YES,
- MYSQL_TYPE_LONG,
&trial_info->malicious_get_frequency, GNUNET_YES,
- MYSQL_TYPE_LONG,
&trial_info->malicious_put_frequency, GNUNET_YES,
- MYSQL_TYPE_LONG,
&trial_info->stop_closest, GNUNET_YES,
- MYSQL_TYPE_LONG, &trial_info->stop_found,
GNUNET_YES,
- MYSQL_TYPE_LONG,
&trial_info->strict_kademlia, GNUNET_YES,
- MYSQL_TYPE_LONG,
&trial_info->gets_succeeded, GNUNET_YES,
- MYSQL_TYPE_BLOB, trial_info->message,
max_varchar_len +
- max_varchar_len, &m_len,
- -1)))
+ MYSQL_TYPE_LONG,
+ &trial_info->other_identifier, GNUNET_YES,
+ MYSQL_TYPE_LONG, &trial_info->num_nodes,
+ GNUNET_YES, MYSQL_TYPE_LONG,
+ &trial_info->topology, GNUNET_YES,
+ MYSQL_TYPE_FLOAT,
+ &trial_info->topology_percentage,
+ MYSQL_TYPE_FLOAT,
+ &trial_info->topology_probability,
+ MYSQL_TYPE_LONG,
+ &trial_info->blacklist_topology,
+ GNUNET_YES, MYSQL_TYPE_LONG,
+ &trial_info->connect_topology, GNUNET_YES,
+ MYSQL_TYPE_LONG,
+ &trial_info->connect_topology_option,
+ GNUNET_YES, MYSQL_TYPE_FLOAT,
+
&trial_info->connect_topology_option_modifier,
+ MYSQL_TYPE_LONG, &trial_info->puts,
+ GNUNET_YES, MYSQL_TYPE_LONG,
+ &trial_info->gets, GNUNET_YES,
+ MYSQL_TYPE_LONG, &trial_info->concurrent,
+ GNUNET_YES, MYSQL_TYPE_LONG,
+ &trial_info->settle_time, GNUNET_YES,
+ MYSQL_TYPE_LONG, &trial_info->num_rounds,
+ GNUNET_YES, MYSQL_TYPE_LONG,
+ &trial_info->malicious_getters,
GNUNET_YES,
+ MYSQL_TYPE_LONG,
+ &trial_info->malicious_putters,
GNUNET_YES,
+ MYSQL_TYPE_LONG,
+ &trial_info->malicious_droppers,
+ GNUNET_YES, MYSQL_TYPE_LONG,
+ &trial_info->malicious_get_frequency,
+ GNUNET_YES, MYSQL_TYPE_LONG,
+ &trial_info->malicious_put_frequency,
+ GNUNET_YES, MYSQL_TYPE_LONG,
+ &trial_info->stop_closest, GNUNET_YES,
+ MYSQL_TYPE_LONG, &trial_info->stop_found,
+ GNUNET_YES, MYSQL_TYPE_LONG,
+ &trial_info->strict_kademlia, GNUNET_YES,
+ MYSQL_TYPE_LONG,
+ &trial_info->gets_succeeded, GNUNET_YES,
+ MYSQL_TYPE_BLOB, trial_info->message,
+ max_varchar_len + max_varchar_len, &m_len,
+ -1)))
+ {
+ if (ret == GNUNET_SYSERR)
{
- if (ret == GNUNET_SYSERR)
- {
- mysql_stmt_close(stmt);
- return GNUNET_SYSERR;
- }
+ mysql_stmt_close (stmt);
+ return GNUNET_SYSERR;
}
+ }
get_current_trial (¤t_trial);
- mysql_stmt_close(stmt);
+ mysql_stmt_close (stmt);
return GNUNET_OK;
}
@@ -904,19 +927,20 @@
*
* @return GNUNET_OK on success, GNUNET_SYSERR on failure
*/
-int add_round (unsigned int round_type, unsigned int round_count)
+int
+add_round (unsigned int round_type, unsigned int round_count)
{
MYSQL_STMT *stmt;
int ret;
- stmt = mysql_stmt_init(conn);
+ stmt = mysql_stmt_init (conn);
ret = prepared_statement_run (insert_round,
NULL,
MYSQL_TYPE_LONGLONG, ¤t_trial,
GNUNET_YES,
MYSQL_TYPE_LONG, &round_type, GNUNET_YES,
MYSQL_TYPE_LONG, &round_count, GNUNET_YES, -1);
- mysql_stmt_close(stmt);
+ mysql_stmt_close (stmt);
if (ret != GNUNET_OK)
return GNUNET_SYSERR;
return ret;
@@ -933,22 +957,24 @@
*
* @return GNUNET_OK on success, GNUNET_SYSERR on failure
*/
-int add_round_details (unsigned int round_type, unsigned int round_count,
- unsigned int num_messages, unsigned int
num_messages_succeeded)
+int
+add_round_details (unsigned int round_type, unsigned int round_count,
+ unsigned int num_messages,
+ unsigned int num_messages_succeeded)
{
MYSQL_STMT *stmt;
int ret;
- stmt = mysql_stmt_init(conn);
+ stmt = mysql_stmt_init (conn);
ret = prepared_statement_run (insert_round_details,
NULL,
MYSQL_TYPE_LONGLONG, ¤t_trial,
GNUNET_YES,
MYSQL_TYPE_LONG, &round_type, GNUNET_YES,
MYSQL_TYPE_LONG, &round_count, GNUNET_YES,
MYSQL_TYPE_LONG, &num_messages, GNUNET_YES,
- MYSQL_TYPE_LONG, &num_messages_succeeded,
GNUNET_YES,
- -1);
- mysql_stmt_close(stmt);
+ MYSQL_TYPE_LONG, &num_messages_succeeded,
+ GNUNET_YES, -1);
+ mysql_stmt_close (stmt);
if (ret != GNUNET_OK)
return GNUNET_SYSERR;
return ret;
@@ -985,53 +1011,61 @@
unsigned int data_inserts, unsigned int find_peer_requests,
unsigned int find_peers_started, unsigned int gets_started,
unsigned int puts_started, unsigned int find_peer_responses_received,
- unsigned int get_responses_received, unsigned int
find_peer_responses_sent,
+ unsigned int get_responses_received,
+ unsigned int find_peer_responses_sent,
unsigned int get_responses_sent)
{
MYSQL_STMT *stmt;
int ret;
unsigned long long peer_uid;
unsigned long long return_uid;
+
if (peer == NULL)
return GNUNET_SYSERR;
if (GNUNET_OK != get_node_uid (&peer_uid, &peer->hashPubKey))
- {
- return GNUNET_SYSERR;
- }
+ {
+ return GNUNET_SYSERR;
+ }
- stmt = mysql_stmt_init(conn);
+ stmt = mysql_stmt_init (conn);
if (GNUNET_OK !=
(ret = prepared_statement_run (insert_stat,
&return_uid,
- MYSQL_TYPE_LONGLONG, ¤t_trial,
GNUNET_YES,
- MYSQL_TYPE_LONGLONG, &peer_uid,
GNUNET_YES,
- MYSQL_TYPE_LONG, &route_requests,
GNUNET_YES,
- MYSQL_TYPE_LONG, &route_forwards,
GNUNET_YES,
- MYSQL_TYPE_LONG, &result_requests,
GNUNET_YES,
- MYSQL_TYPE_LONG, &client_requests,
GNUNET_YES,
- MYSQL_TYPE_LONG, &result_forwards,
GNUNET_YES,
+ MYSQL_TYPE_LONGLONG, ¤t_trial,
+ GNUNET_YES, MYSQL_TYPE_LONGLONG,
&peer_uid,
+ GNUNET_YES, MYSQL_TYPE_LONG,
+ &route_requests, GNUNET_YES,
+ MYSQL_TYPE_LONG, &route_forwards,
+ GNUNET_YES, MYSQL_TYPE_LONG,
+ &result_requests, GNUNET_YES,
+ MYSQL_TYPE_LONG, &client_requests,
+ GNUNET_YES, MYSQL_TYPE_LONG,
+ &result_forwards, GNUNET_YES,
MYSQL_TYPE_LONG, &gets, GNUNET_YES,
MYSQL_TYPE_LONG, &puts, GNUNET_YES,
MYSQL_TYPE_LONG, &data_inserts,
GNUNET_YES,
- MYSQL_TYPE_LONG, &find_peer_requests,
GNUNET_YES,
- MYSQL_TYPE_LONG, &find_peers_started,
GNUNET_YES,
+ MYSQL_TYPE_LONG, &find_peer_requests,
+ GNUNET_YES, MYSQL_TYPE_LONG,
+ &find_peers_started, GNUNET_YES,
MYSQL_TYPE_LONG, &gets_started,
GNUNET_YES,
MYSQL_TYPE_LONG, &puts_started,
GNUNET_YES,
- MYSQL_TYPE_LONG,
&find_peer_responses_received, GNUNET_YES,
- MYSQL_TYPE_LONG, &get_responses_received,
GNUNET_YES,
- MYSQL_TYPE_LONG,
&find_peer_responses_sent, GNUNET_YES,
- MYSQL_TYPE_LONG, &get_responses_sent,
GNUNET_YES,
- -1)))
+ MYSQL_TYPE_LONG,
+ &find_peer_responses_received, GNUNET_YES,
+ MYSQL_TYPE_LONG, &get_responses_received,
+ GNUNET_YES, MYSQL_TYPE_LONG,
+ &find_peer_responses_sent, GNUNET_YES,
+ MYSQL_TYPE_LONG, &get_responses_sent,
+ GNUNET_YES, -1)))
+ {
+ if (ret == GNUNET_SYSERR)
{
- if (ret == GNUNET_SYSERR)
- {
- mysql_stmt_close(stmt);
- return GNUNET_SYSERR;
- }
+ mysql_stmt_close (stmt);
+ return GNUNET_SYSERR;
}
+ }
- mysql_stmt_close(stmt);
+ mysql_stmt_close (stmt);
return GNUNET_OK;
}
@@ -1047,39 +1081,41 @@
*/
int
add_generic_stat (const struct GNUNET_PeerIdentity *peer,
- const char *name,
- const char *section, uint64_t value)
+ const char *name, const char *section, uint64_t value)
{
unsigned long long peer_uid;
unsigned long long section_len;
unsigned long long name_len;
int ret;
+
if (peer == NULL)
return GNUNET_SYSERR;
if (GNUNET_OK != get_node_uid (&peer_uid, &peer->hashPubKey))
- {
- return GNUNET_SYSERR;
- }
+ {
+ return GNUNET_SYSERR;
+ }
- section_len = strlen(section);
- name_len = strlen(name);
+ section_len = strlen (section);
+ name_len = strlen (name);
if (GNUNET_OK !=
(ret = prepared_statement_run (insert_generic_stat,
NULL,
- MYSQL_TYPE_LONGLONG, ¤t_trial,
GNUNET_YES,
- MYSQL_TYPE_LONGLONG, &peer_uid,
GNUNET_YES,
- MYSQL_TYPE_VAR_STRING, §ion,
max_varchar_len, §ion_len,
- MYSQL_TYPE_VAR_STRING, &name,
max_varchar_len, &name_len,
+ MYSQL_TYPE_LONGLONG, ¤t_trial,
+ GNUNET_YES, MYSQL_TYPE_LONGLONG,
&peer_uid,
+ GNUNET_YES, MYSQL_TYPE_VAR_STRING,
+ §ion, max_varchar_len, §ion_len,
+ MYSQL_TYPE_VAR_STRING, &name,
+ max_varchar_len, &name_len,
MYSQL_TYPE_LONGLONG, &value, GNUNET_YES,
-1)))
+ {
+ if (ret == GNUNET_SYSERR)
{
- if (ret == GNUNET_SYSERR)
- {
- return GNUNET_SYSERR;
- }
+ return GNUNET_SYSERR;
}
+ }
return GNUNET_OK;
}
@@ -1101,23 +1137,24 @@
unsigned long long k_len;
unsigned long long h_len;
unsigned long long curr_dhtkeyuid;
+
GNUNET_CRYPTO_hash_to_enc (dhtkey, &encKey);
k_len = strlen ((char *) &encKey);
h_len = sizeof (GNUNET_HashCode);
curr_dhtkeyuid = 0;
- ret = get_dhtkey_uid(&curr_dhtkeyuid, dhtkey);
- if (curr_dhtkeyuid != 0) /* dhtkey already exists */
- {
- if (dhtkeyuid != NULL)
- *dhtkeyuid = curr_dhtkeyuid;
- return GNUNET_OK;
- }
+ ret = get_dhtkey_uid (&curr_dhtkeyuid, dhtkey);
+ if (curr_dhtkeyuid != 0) /* dhtkey already exists */
+ {
+ if (dhtkeyuid != NULL)
+ *dhtkeyuid = curr_dhtkeyuid;
+ return GNUNET_OK;
+ }
else if (ret == GNUNET_SYSERR)
- {
+ {
#if DEBUG_DHTLOG
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Failed to get dhtkeyuid!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to get dhtkeyuid!\n");
#endif
- }
+ }
if (GNUNET_OK !=
(ret = prepared_statement_run (insert_dhtkey,
@@ -1131,14 +1168,13 @@
GNUNET_YES,
MYSQL_TYPE_BLOB,
dhtkey,
- sizeof (GNUNET_HashCode),
- &h_len, -1)))
+ sizeof (GNUNET_HashCode), &h_len, -1)))
+ {
+ if (ret == GNUNET_SYSERR)
{
- if (ret == GNUNET_SYSERR)
- {
- return GNUNET_SYSERR;
- }
+ return GNUNET_SYSERR;
}
+ }
return GNUNET_OK;
}
@@ -1154,7 +1190,7 @@
* @return GNUNET_OK on success, GNUNET_SYSERR on failure
*/
int
-add_node (unsigned long long *nodeuid, struct GNUNET_PeerIdentity * node)
+add_node (unsigned long long *nodeuid, struct GNUNET_PeerIdentity *node)
{
struct GNUNET_CRYPTO_HashAsciiEncoded encPeer;
unsigned long p_len;
@@ -1170,16 +1206,17 @@
if (GNUNET_OK !=
(ret = prepared_statement_run (insert_node,
nodeuid,
- MYSQL_TYPE_LONGLONG, ¤t_trial,
GNUNET_YES,
- MYSQL_TYPE_VAR_STRING, &encPeer,
max_varchar_len, &p_len,
- MYSQL_TYPE_BLOB, &node->hashPubKey,
sizeof (GNUNET_HashCode),
- &h_len, -1)))
+ MYSQL_TYPE_LONGLONG, ¤t_trial,
+ GNUNET_YES, MYSQL_TYPE_VAR_STRING,
+ &encPeer, max_varchar_len, &p_len,
+ MYSQL_TYPE_BLOB, &node->hashPubKey,
+ sizeof (GNUNET_HashCode), &h_len, -1)))
+ {
+ if (ret == GNUNET_SYSERR)
{
- if (ret == GNUNET_SYSERR)
- {
- return GNUNET_SYSERR;
- }
+ return GNUNET_SYSERR;
}
+ }
return GNUNET_OK;
}
@@ -1197,16 +1234,16 @@
if (GNUNET_OK !=
(ret = prepared_statement_run (update_trial,
- NULL,
- MYSQL_TYPE_LONG, &gets_succeeded,
GNUNET_YES,
- MYSQL_TYPE_LONGLONG, ¤t_trial,
GNUNET_YES,
- -1)))
+ NULL,
+ MYSQL_TYPE_LONG, &gets_succeeded,
+ GNUNET_YES, MYSQL_TYPE_LONGLONG,
+ ¤t_trial, GNUNET_YES, -1)))
+ {
+ if (ret == GNUNET_SYSERR)
{
- if (ret == GNUNET_SYSERR)
- {
- return GNUNET_SYSERR;
- }
+ return GNUNET_SYSERR;
}
+ }
if (ret > 0)
return GNUNET_OK;
else
@@ -1222,27 +1259,28 @@
*
* @return GNUNET_OK on success, GNUNET_SYSERR on failure.
*/
-int set_malicious (struct GNUNET_PeerIdentity *peer)
+int
+set_malicious (struct GNUNET_PeerIdentity *peer)
{
unsigned long long p_len;
int ret;
char *temp_str;
- temp_str = GNUNET_strdup(GNUNET_h2s_full(&peer->hashPubKey));
- p_len = strlen(temp_str);
+ temp_str = GNUNET_strdup (GNUNET_h2s_full (&peer->hashPubKey));
+ p_len = strlen (temp_str);
if (GNUNET_OK !=
(ret = prepared_statement_run (update_node_malicious,
- NULL,
- MYSQL_TYPE_LONGLONG, ¤t_trial,
GNUNET_YES,
- MYSQL_TYPE_VAR_STRING, temp_str,
max_varchar_len, &p_len,
- -1)))
+ NULL,
+ MYSQL_TYPE_LONGLONG, ¤t_trial,
+ GNUNET_YES, MYSQL_TYPE_VAR_STRING,
+ temp_str, max_varchar_len, &p_len, -1)))
+ {
+ if (ret == GNUNET_SYSERR)
{
- if (ret == GNUNET_SYSERR)
- {
- return GNUNET_SYSERR;
- }
+ return GNUNET_SYSERR;
}
+ }
return GNUNET_OK;
}
@@ -1261,18 +1299,18 @@
if (GNUNET_OK !=
(ret = prepared_statement_run (update_connection,
- NULL,
- MYSQL_TYPE_LONG,
- &totalConnections,
- GNUNET_YES,
- MYSQL_TYPE_LONGLONG,
- ¤t_trial, GNUNET_YES,
-1)))
+ NULL,
+ MYSQL_TYPE_LONG,
+ &totalConnections,
+ GNUNET_YES,
+ MYSQL_TYPE_LONGLONG,
+ ¤t_trial, GNUNET_YES, -1)))
+ {
+ if (ret == GNUNET_SYSERR)
{
- if (ret == GNUNET_SYSERR)
- {
- return GNUNET_SYSERR;
- }
+ return GNUNET_SYSERR;
}
+ }
if (ret > 0)
return GNUNET_OK;
else
@@ -1295,65 +1333,66 @@
int
add_query (unsigned long long *sqlqueryuid, unsigned long long queryid,
unsigned int type, unsigned int hops, int succeeded,
- const struct GNUNET_PeerIdentity * node, const GNUNET_HashCode *
key)
+ const struct GNUNET_PeerIdentity *node, const GNUNET_HashCode * key)
{
int ret;
unsigned long long peer_uid, key_uid;
+
peer_uid = 0;
key_uid = 0;
if ((node != NULL)
&& (GNUNET_OK == get_node_uid (&peer_uid, &node->hashPubKey)))
- {
+ {
- }
+ }
else
- {
- return GNUNET_SYSERR;
- }
+ {
+ return GNUNET_SYSERR;
+ }
if ((key != NULL) && (GNUNET_OK == get_dhtkey_uid (&key_uid, key)))
- {
+ {
- }
+ }
else if ((key != NULL) && (key->bits[(512 / 8 / sizeof (unsigned int)) - 1]
== 42)) /* Malicious marker */
- {
- key_uid = 0;
- }
+ {
+ key_uid = 0;
+ }
else
- {
- return GNUNET_SYSERR;
- }
+ {
+ return GNUNET_SYSERR;
+ }
if (GNUNET_OK !=
(ret = prepared_statement_run (insert_query,
- sqlqueryuid,
- MYSQL_TYPE_LONGLONG,
- ¤t_trial,
- GNUNET_YES,
- MYSQL_TYPE_LONG,
- &type,
- GNUNET_NO,
- MYSQL_TYPE_LONG,
- &hops,
- GNUNET_YES,
- MYSQL_TYPE_LONGLONG,
- &key_uid,
- GNUNET_YES,
- MYSQL_TYPE_LONGLONG,
- &queryid,
- GNUNET_YES,
- MYSQL_TYPE_LONG,
- &succeeded,
- GNUNET_NO,
- MYSQL_TYPE_LONGLONG,
- &peer_uid, GNUNET_YES, -1)))
+ sqlqueryuid,
+ MYSQL_TYPE_LONGLONG,
+ ¤t_trial,
+ GNUNET_YES,
+ MYSQL_TYPE_LONG,
+ &type,
+ GNUNET_NO,
+ MYSQL_TYPE_LONG,
+ &hops,
+ GNUNET_YES,
+ MYSQL_TYPE_LONGLONG,
+ &key_uid,
+ GNUNET_YES,
+ MYSQL_TYPE_LONGLONG,
+ &queryid,
+ GNUNET_YES,
+ MYSQL_TYPE_LONG,
+ &succeeded,
+ GNUNET_NO,
+ MYSQL_TYPE_LONGLONG,
+ &peer_uid, GNUNET_YES, -1)))
+ {
+ if (ret == GNUNET_SYSERR)
{
- if (ret == GNUNET_SYSERR)
- {
- return GNUNET_SYSERR;
- }
+ return GNUNET_SYSERR;
}
+ }
if (ret > 0)
return GNUNET_OK;
else
@@ -1378,9 +1417,10 @@
int
add_route (unsigned long long *sqlqueryuid, unsigned long long queryid,
unsigned int type, unsigned int hops,
- int succeeded, const struct GNUNET_PeerIdentity * node,
- const GNUNET_HashCode * key, const struct GNUNET_PeerIdentity *
from_node,
- const struct GNUNET_PeerIdentity * to_node)
+ int succeeded, const struct GNUNET_PeerIdentity *node,
+ const GNUNET_HashCode * key,
+ const struct GNUNET_PeerIdentity *from_node,
+ const struct GNUNET_PeerIdentity *to_node)
{
unsigned long long peer_uid = 0;
unsigned long long key_uid = 0;
@@ -1397,60 +1437,60 @@
to_uid = 0;
if ((node != NULL))
+ {
+ if (1 != get_node_uid (&peer_uid, &node->hashPubKey))
{
- if (1 != get_node_uid (&peer_uid, &node->hashPubKey))
- {
- return GNUNET_SYSERR;
- }
+ return GNUNET_SYSERR;
}
+ }
else
return GNUNET_SYSERR;
if ((key != NULL))
+ {
+ if (1 != get_dhtkey_uid (&key_uid, key))
{
- if (1 != get_dhtkey_uid (&key_uid, key))
- {
- return GNUNET_SYSERR;
- }
+ return GNUNET_SYSERR;
}
+ }
else
return GNUNET_SYSERR;
if (GNUNET_OK !=
(ret = prepared_statement_run (insert_route,
- sqlqueryuid,
- MYSQL_TYPE_LONGLONG,
- ¤t_trial,
- GNUNET_YES,
- MYSQL_TYPE_LONG,
- &type,
- GNUNET_NO,
- MYSQL_TYPE_LONG,
- &hops,
- GNUNET_YES,
- MYSQL_TYPE_LONGLONG,
- &key_uid,
- GNUNET_YES,
- MYSQL_TYPE_LONGLONG,
- &queryid,
- GNUNET_YES,
- MYSQL_TYPE_LONG,
- &succeeded,
- GNUNET_NO,
- MYSQL_TYPE_LONGLONG,
- &peer_uid,
- GNUNET_YES,
- MYSQL_TYPE_LONGLONG,
- &from_uid,
- GNUNET_YES,
- MYSQL_TYPE_LONGLONG,
- &to_uid, GNUNET_YES, -1)))
+ sqlqueryuid,
+ MYSQL_TYPE_LONGLONG,
+ ¤t_trial,
+ GNUNET_YES,
+ MYSQL_TYPE_LONG,
+ &type,
+ GNUNET_NO,
+ MYSQL_TYPE_LONG,
+ &hops,
+ GNUNET_YES,
+ MYSQL_TYPE_LONGLONG,
+ &key_uid,
+ GNUNET_YES,
+ MYSQL_TYPE_LONGLONG,
+ &queryid,
+ GNUNET_YES,
+ MYSQL_TYPE_LONG,
+ &succeeded,
+ GNUNET_NO,
+ MYSQL_TYPE_LONGLONG,
+ &peer_uid,
+ GNUNET_YES,
+ MYSQL_TYPE_LONGLONG,
+ &from_uid,
+ GNUNET_YES,
+ MYSQL_TYPE_LONGLONG,
+ &to_uid, GNUNET_YES, -1)))
+ {
+ if (ret == GNUNET_SYSERR)
{
- if (ret == GNUNET_SYSERR)
- {
- return GNUNET_SYSERR;
- }
+ return GNUNET_SYSERR;
}
+ }
if (ret > 0)
return GNUNET_OK;
else
@@ -1470,7 +1510,7 @@
int ret;
unsigned long long topologyuid;
- get_current_topology(&topologyuid);
+ get_current_topology (&topologyuid);
if (GNUNET_OK !=
(ret = prepared_statement_run (update_topology,
@@ -1480,12 +1520,12 @@
GNUNET_YES,
MYSQL_TYPE_LONGLONG,
&topologyuid, GNUNET_YES, -1)))
+ {
+ if (ret == GNUNET_SYSERR)
{
- if (ret == GNUNET_SYSERR)
- {
- return GNUNET_SYSERR;
- }
+ return GNUNET_SYSERR;
}
+ }
if (ret > 0)
return GNUNET_OK;
return GNUNET_SYSERR;
@@ -1507,15 +1547,15 @@
if (GNUNET_OK !=
(ret = prepared_statement_run (insert_topology,
NULL,
- MYSQL_TYPE_LONGLONG, ¤t_trial,
GNUNET_YES,
- MYSQL_TYPE_LONG, &num_connections,
GNUNET_YES,
- -1)))
+ MYSQL_TYPE_LONGLONG, ¤t_trial,
+ GNUNET_YES, MYSQL_TYPE_LONG,
+ &num_connections, GNUNET_YES, -1)))
+ {
+ if (ret == GNUNET_SYSERR)
{
- if (ret == GNUNET_SYSERR)
- {
- return GNUNET_SYSERR;
- }
+ return GNUNET_SYSERR;
}
+ }
if (ret > 0)
return GNUNET_OK;
return GNUNET_SYSERR;
@@ -1530,18 +1570,19 @@
* @return GNUNET_OK on success, GNUNET_SYSERR on failure
*/
int
-add_extended_topology (const struct GNUNET_PeerIdentity *first, const struct
GNUNET_PeerIdentity *second)
+add_extended_topology (const struct GNUNET_PeerIdentity *first,
+ const struct GNUNET_PeerIdentity *second)
{
int ret;
unsigned long long first_uid;
unsigned long long second_uid;
unsigned long long topologyuid;
- if (GNUNET_OK != get_current_topology(&topologyuid))
+ if (GNUNET_OK != get_current_topology (&topologyuid))
return GNUNET_SYSERR;
- if (GNUNET_OK != get_node_uid(&first_uid, &first->hashPubKey))
+ if (GNUNET_OK != get_node_uid (&first_uid, &first->hashPubKey))
return GNUNET_SYSERR;
- if (GNUNET_OK != get_node_uid(&second_uid, &second->hashPubKey))
+ if (GNUNET_OK != get_node_uid (&second_uid, &second->hashPubKey))
return GNUNET_SYSERR;
if (GNUNET_OK !=
@@ -1554,14 +1595,13 @@
&first_uid,
GNUNET_YES,
MYSQL_TYPE_LONGLONG,
- &second_uid,
- GNUNET_YES,-1)))
+ &second_uid, GNUNET_YES, -1)))
+ {
+ if (ret == GNUNET_SYSERR)
{
- if (ret == GNUNET_SYSERR)
- {
- return GNUNET_SYSERR;
- }
+ return GNUNET_SYSERR;
}
+ }
if (ret > 0)
return GNUNET_OK;
return GNUNET_SYSERR;
@@ -1576,25 +1616,27 @@
* @return the handle to the server, or NULL on error
*/
void *
-libgnunet_plugin_dhtlog_mysql_init (void * cls)
+libgnunet_plugin_dhtlog_mysql_init (void *cls)
{
struct GNUNET_DHTLOG_Plugin *plugin = cls;
cfg = plugin->cfg;
max_varchar_len = 255;
#if DEBUG_DHTLOG
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MySQL DHT Logger: initializing
database\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "MySQL DHT Logger: initializing database\n");
#endif
if (iopen (plugin) != GNUNET_OK)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to initialize MySQL database connection for
dhtlog.\n"));
- return NULL;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Failed to initialize MySQL database connection for
dhtlog.\n"));
+ return NULL;
+ }
- GNUNET_assert(plugin->dhtlog_api == NULL);
- plugin->dhtlog_api = GNUNET_malloc(sizeof(struct GNUNET_DHTLOG_Handle));
+ GNUNET_assert (plugin->dhtlog_api == NULL);
+ plugin->dhtlog_api = GNUNET_malloc (sizeof (struct GNUNET_DHTLOG_Handle));
plugin->dhtlog_api->insert_trial = &add_trial;
plugin->dhtlog_api->insert_stat = &add_stat;
plugin->dhtlog_api->insert_round = &add_round;
@@ -1619,36 +1661,35 @@
* Shutdown the plugin.
*/
void *
-libgnunet_plugin_dhtlog_mysql_done (void * cls)
+libgnunet_plugin_dhtlog_mysql_done (void *cls)
{
struct GNUNET_DHTLOG_Handle *dhtlog_api = cls;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "MySQL DHT Logger: database shutdown\n");
- GNUNET_assert(dhtlog_api != NULL);
- prepared_statement_close(insert_query);
- prepared_statement_close(insert_route);
- prepared_statement_close(insert_trial);
- prepared_statement_close(insert_round);
- prepared_statement_close(insert_round_details);
- prepared_statement_close(insert_node);
- prepared_statement_close(insert_dhtkey);
- prepared_statement_close(update_trial);
- prepared_statement_close(get_dhtkeyuid);
- prepared_statement_close(get_nodeuid);
- prepared_statement_close(update_connection);
- prepared_statement_close(get_trial);
- prepared_statement_close(get_topology);
- prepared_statement_close(insert_topology);
- prepared_statement_close(update_topology);
- prepared_statement_close(extend_topology);
- prepared_statement_close(update_node_malicious);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MySQL DHT Logger: database
shutdown\n");
+ GNUNET_assert (dhtlog_api != NULL);
+ prepared_statement_close (insert_query);
+ prepared_statement_close (insert_route);
+ prepared_statement_close (insert_trial);
+ prepared_statement_close (insert_round);
+ prepared_statement_close (insert_round_details);
+ prepared_statement_close (insert_node);
+ prepared_statement_close (insert_dhtkey);
+ prepared_statement_close (update_trial);
+ prepared_statement_close (get_dhtkeyuid);
+ prepared_statement_close (get_nodeuid);
+ prepared_statement_close (update_connection);
+ prepared_statement_close (get_trial);
+ prepared_statement_close (get_topology);
+ prepared_statement_close (insert_topology);
+ prepared_statement_close (update_topology);
+ prepared_statement_close (extend_topology);
+ prepared_statement_close (update_node_malicious);
if (conn != NULL)
mysql_close (conn);
conn = NULL;
- mysql_library_end();
- GNUNET_free(dhtlog_api);
+ mysql_library_end ();
+ GNUNET_free (dhtlog_api);
return NULL;
}
Modified: gnunet/src/dht/plugin_dhtlog_mysql_dump.c
===================================================================
--- gnunet/src/dht/plugin_dhtlog_mysql_dump.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/dht/plugin_dhtlog_mysql_dump.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -124,7 +124,7 @@
static char *
-get_sql_time()
+get_sql_time ()
{
static char date[DATE_STR_SIZE];
time_t timetmp;
@@ -149,7 +149,7 @@
static int
prepared_statement_create (const char *statement)
{
- if (fprintf(outfile, "%s;\n", statement) > 0)
+ if (fprintf (outfile, "%s;\n", statement) > 0)
return GNUNET_OK;
return GNUNET_SYSERR;
@@ -179,11 +179,10 @@
PINIT (INSERT_TOPOLOGY_STMT) ||
PINIT (EXTEND_TOPOLOGY_STMT) ||
PINIT (UPDATE_TOPOLOGY_STMT) ||
- PINIT (GET_TRIAL_STMT) ||
- PINIT (GET_TOPOLOGY_STMT))
- {
- return GNUNET_SYSERR;
- }
+ PINIT (GET_TRIAL_STMT) || PINIT (GET_TOPOLOGY_STMT))
+ {
+ return GNUNET_SYSERR;
+ }
#undef PINIT
return GNUNET_OK;
@@ -197,17 +196,22 @@
*
* @return GNUNET_OK on success, GNUNET_SYSERR on failure
*/
-int add_round (unsigned int round_type, unsigned int round_count)
+int
+add_round (unsigned int round_type, unsigned int round_count)
{
int ret;
+
if (outfile == NULL)
return GNUNET_SYSERR;
- ret = fprintf(outfile, "set @curr_time = \"%s\", @rtype = \"%u\", @rcount =
\"%u\";\n", get_sql_time(), round_type, round_count);
+ ret =
+ fprintf (outfile,
+ "set @curr_time = \"%s\", @rtype = \"%u\", @rcount = \"%u\";\n",
+ get_sql_time (), round_type, round_count);
if (ret < 0)
return GNUNET_SYSERR;
- ret = fprintf(outfile, "execute insert_round;\n");
+ ret = fprintf (outfile, "execute insert_round;\n");
if (ret >= 0)
return GNUNET_OK;
@@ -225,19 +229,25 @@
*
* @return GNUNET_OK on success, GNUNET_SYSERR on failure
*/
-int add_round_details (unsigned int round_type, unsigned int round_count,
- unsigned int num_messages, unsigned int
num_messages_succeeded)
+int
+add_round_details (unsigned int round_type, unsigned int round_count,
+ unsigned int num_messages,
+ unsigned int num_messages_succeeded)
{
int ret;
+
if (outfile == NULL)
return GNUNET_SYSERR;
- ret = fprintf(outfile, "set @curr_time = \"%s\", @rtype = \"%u\", @rcount =
\"%u\", @totalmsgs = \"%u\", @msgssucceeded = \"%u\";\n",
- get_sql_time(), round_type, round_count,
num_messages, num_messages_succeeded);
+ ret =
+ fprintf (outfile,
+ "set @curr_time = \"%s\", @rtype = \"%u\", @rcount = \"%u\",
@totalmsgs = \"%u\", @msgssucceeded = \"%u\";\n",
+ get_sql_time (), round_type, round_count, num_messages,
+ num_messages_succeeded);
if (ret < 0)
return GNUNET_SYSERR;
- ret = fprintf(outfile, "execute insert_round_details;\n");
+ ret = fprintf (outfile, "execute insert_round_details;\n");
if (ret >= 0)
return GNUNET_OK;
@@ -255,19 +265,21 @@
add_topology (int num_connections)
{
int ret;
+
if (outfile == NULL)
return GNUNET_SYSERR;
- ret = fprintf(outfile, "set @date = \"%s\", @num = %d;\n", get_sql_time(),
num_connections);
+ ret =
+ fprintf (outfile, "set @date = \"%s\", @num = %d;\n", get_sql_time (),
+ num_connections);
if (ret < 0)
return GNUNET_SYSERR;
- ret = fprintf(outfile, "execute insert_topology using "
- "@date, @num;\n");
+ ret = fprintf (outfile, "execute insert_topology using " "@date, @num;\n");
if (ret < 0)
return GNUNET_SYSERR;
- ret = fprintf(outfile, "execute select_topology;\n");
+ ret = fprintf (outfile, "execute select_topology;\n");
if (ret >= 0)
return GNUNET_OK;
@@ -283,30 +295,38 @@
* @return GNUNET_OK on success, GNUNET_SYSERR on failure
*/
int
-add_extended_topology (const struct GNUNET_PeerIdentity *first, const struct
GNUNET_PeerIdentity *second)
+add_extended_topology (const struct GNUNET_PeerIdentity *first,
+ const struct GNUNET_PeerIdentity *second)
{
int ret;
+
if (outfile == NULL)
return GNUNET_SYSERR;
if (first != NULL)
- ret = fprintf(outfile, "select nodeuid from nodes where trialuid =
@temp_trial and nodeid = \"%s\" into @temp_first_node;\n",
GNUNET_h2s_full(&first->hashPubKey));
+ ret =
+ fprintf (outfile,
+ "select nodeuid from nodes where trialuid = @temp_trial and
nodeid = \"%s\" into @temp_first_node;\n",
+ GNUNET_h2s_full (&first->hashPubKey));
else
- ret = fprintf(outfile, "set @temp_first_node = 0;\n");
+ ret = fprintf (outfile, "set @temp_first_node = 0;\n");
if (ret < 0)
return GNUNET_SYSERR;
if (second != NULL)
- ret = fprintf(outfile, "select nodeuid from nodes where trialuid =
@temp_trial and nodeid = \"%s\" into @temp_second_node;\n",
GNUNET_h2s_full(&second->hashPubKey));
+ ret =
+ fprintf (outfile,
+ "select nodeuid from nodes where trialuid = @temp_trial and
nodeid = \"%s\" into @temp_second_node;\n",
+ GNUNET_h2s_full (&second->hashPubKey));
else
- ret = fprintf(outfile, "set @temp_second_node = 0;\n");
+ ret = fprintf (outfile, "set @temp_second_node = 0;\n");
if (ret < 0)
return GNUNET_SYSERR;
- ret = fprintf(outfile, "execute extend_topology using "
- "@temp_first_node, @temp_second_node;\n");
+ ret = fprintf (outfile, "execute extend_topology using "
+ "@temp_first_node, @temp_second_node;\n");
if (ret >= 0)
return GNUNET_OK;
@@ -321,42 +341,51 @@
*
* @return GNUNET_OK on success, GNUNET_SYSERR on failure
*/
-int add_trial (struct GNUNET_DHTLOG_TrialInfo *trial_info)
+int
+add_trial (struct GNUNET_DHTLOG_TrialInfo *trial_info)
{
int ret;
if (outfile == NULL)
return GNUNET_SYSERR;
- ret = fprintf(outfile, "set @date = \"%s\", @oid = %u, @num = %u, @topology
= %u, @bl = %u, "
- "@connect = %u, @c_t_o = %u, @c_t_o_m = %f, @t_p = %f, "
- "@t_pr = %f, @puts = %u, @gets = %u, "
- "@concurrent = %u, @settle = %u, @rounds = %u, "
- "@m_gets = %u, @m_puts = %u, @m_drops = %u, "
- "@m_g_f = %u, @m_p_f = %u, @s_c = %u, @s_f = %u,"
- "@s_k = %u, @g_s = %u, @message = \"%s\";\n",
- get_sql_time(), trial_info->other_identifier,
trial_info->num_nodes, trial_info->topology,
- trial_info->blacklist_topology,
trial_info->connect_topology,
- trial_info->connect_topology_option,
trial_info->connect_topology_option_modifier,
- trial_info->topology_percentage,
trial_info->topology_probability,
- trial_info->puts, trial_info->gets, trial_info->concurrent,
trial_info->settle_time,
- trial_info->num_rounds, trial_info->malicious_getters,
trial_info->malicious_putters,
- trial_info->malicious_droppers,
trial_info->malicious_get_frequency, trial_info->malicious_put_frequency,
- trial_info->stop_closest, trial_info->stop_found,
trial_info->strict_kademlia, trial_info->gets_succeeded, trial_info->message);
+ ret =
+ fprintf (outfile,
+ "set @date = \"%s\", @oid = %u, @num = %u, @topology = %u, @bl
= %u, "
+ "@connect = %u, @c_t_o = %u, @c_t_o_m = %f, @t_p = %f, "
+ "@t_pr = %f, @puts = %u, @gets = %u, "
+ "@concurrent = %u, @settle = %u, @rounds = %u, "
+ "@m_gets = %u, @m_puts = %u, @m_drops = %u, "
+ "@m_g_f = %u, @m_p_f = %u, @s_c = %u, @s_f = %u,"
+ "@s_k = %u, @g_s = %u, @message = \"%s\";\n", get_sql_time (),
+ trial_info->other_identifier, trial_info->num_nodes,
+ trial_info->topology, trial_info->blacklist_topology,
+ trial_info->connect_topology,
+ trial_info->connect_topology_option,
+ trial_info->connect_topology_option_modifier,
+ trial_info->topology_percentage,
+ trial_info->topology_probability, trial_info->puts,
+ trial_info->gets, trial_info->concurrent,
+ trial_info->settle_time, trial_info->num_rounds,
+ trial_info->malicious_getters, trial_info->malicious_putters,
+ trial_info->malicious_droppers,
+ trial_info->malicious_get_frequency,
+ trial_info->malicious_put_frequency, trial_info->stop_closest,
+ trial_info->stop_found, trial_info->strict_kademlia,
+ trial_info->gets_succeeded, trial_info->message);
if (ret < 0)
return GNUNET_SYSERR;
- ret = fprintf(outfile, "execute insert_trial using "
- "@date, @oid, @num, @topology, @t_p, @t_pr,"
- " @bl, @connect, @c_t_o,"
- "@c_t_o_m, @puts, @gets,"
- "@concurrent, @settle, @rounds,"
- "@m_gets, @m_puts, @m_drops,"
- "@m_g_f, @m_p_f, @s_c, @s_f,"
- "@s_k, @g_s, @message;\n");
+ ret = fprintf (outfile, "execute insert_trial using "
+ "@date, @oid, @num, @topology, @t_p, @t_pr,"
+ " @bl, @connect, @c_t_o,"
+ "@c_t_o_m, @puts, @gets,"
+ "@concurrent, @settle, @rounds,"
+ "@m_gets, @m_puts, @m_drops,"
+ "@m_g_f, @m_p_f, @s_c, @s_f," "@s_k, @g_s, @message;\n");
if (ret < 0)
return GNUNET_SYSERR;
- ret = fprintf(outfile, "execute select_trial;\n");
+ ret = fprintf (outfile, "execute select_trial;\n");
if (ret >= 0)
return GNUNET_OK;
@@ -376,28 +405,33 @@
*/
int
add_generic_stat (const struct GNUNET_PeerIdentity *peer,
- const char *name,
- const char *section, uint64_t value)
+ const char *name, const char *section, uint64_t value)
{
int ret;
+
if (outfile == NULL)
return GNUNET_SYSERR;
if (peer != NULL)
- ret = fprintf(outfile, "select nodeuid from nodes where trialuid =
@temp_trial and nodeid = \"%s\" into @temp_node;\n",
GNUNET_h2s_full(&peer->hashPubKey));
+ ret =
+ fprintf (outfile,
+ "select nodeuid from nodes where trialuid = @temp_trial and
nodeid = \"%s\" into @temp_node;\n",
+ GNUNET_h2s_full (&peer->hashPubKey));
else
- ret = fprintf(outfile, "set @temp_node = 0;\n");
+ ret = fprintf (outfile, "set @temp_node = 0;\n");
if (ret < 0)
return GNUNET_SYSERR;
- ret = fprintf(outfile, "set @temp_section = \"%s\", @temp_stat = \"%s\",
@temp_value = %llu;\n",
- section, name, (unsigned long long)value);
+ ret =
+ fprintf (outfile,
+ "set @temp_section = \"%s\", @temp_stat = \"%s\", @temp_value =
%llu;\n",
+ section, name, (unsigned long long) value);
if (ret < 0)
return GNUNET_SYSERR;
- ret = fprintf(outfile, "execute insert_generic_stat;\n");
+ ret = fprintf (outfile, "execute insert_generic_stat;\n");
if (ret < 0)
return GNUNET_SYSERR;
@@ -436,43 +470,49 @@
unsigned int data_inserts, unsigned int find_peer_requests,
unsigned int find_peers_started, unsigned int gets_started,
unsigned int puts_started, unsigned int find_peer_responses_received,
- unsigned int get_responses_received, unsigned int
find_peer_responses_sent,
+ unsigned int get_responses_received,
+ unsigned int find_peer_responses_sent,
unsigned int get_responses_sent)
{
int ret;
+
if (outfile == NULL)
return GNUNET_SYSERR;
if (peer != NULL)
- ret = fprintf(outfile, "select nodeuid from nodes where trialuid =
@temp_trial and nodeid = \"%s\" into @temp_node;\n",
GNUNET_h2s_full(&peer->hashPubKey));
+ ret =
+ fprintf (outfile,
+ "select nodeuid from nodes where trialuid = @temp_trial and
nodeid = \"%s\" into @temp_node;\n",
+ GNUNET_h2s_full (&peer->hashPubKey));
else
- ret = fprintf(outfile, "set @temp_node = 0;\n");
+ ret = fprintf (outfile, "set @temp_node = 0;\n");
if (ret < 0)
return GNUNET_SYSERR;
- ret = fprintf(outfile, "set @r_r = %u, @r_f = %u, @res_r = %u, @c_r = %u, "
- "@res_f = %u, @gets = %u, @puts = %u, @d_i = %u, "
- "@f_p_r = %u, @f_p_s = %u, @g_s = %u, @p_s = %u, "
- "@f_p_r_r = %u, @g_r_r = %u, @f_p_r_s = %u, @g_r_s =
%u;\n",
- route_requests, route_forwards, result_requests,
- client_requests, result_forwards, gets, puts,
- data_inserts, find_peer_requests, find_peers_started,
- gets_started, puts_started,
find_peer_responses_received,
- get_responses_received, find_peer_responses_sent,
- get_responses_sent);
+ ret = fprintf (outfile, "set @r_r = %u, @r_f = %u, @res_r = %u, @c_r = %u, "
+ "@res_f = %u, @gets = %u, @puts = %u, @d_i = %u, "
+ "@f_p_r = %u, @f_p_s = %u, @g_s = %u, @p_s = %u, "
+ "@f_p_r_r = %u, @g_r_r = %u, @f_p_r_s = %u, @g_r_s = %u;\n",
+ route_requests, route_forwards, result_requests,
+ client_requests, result_forwards, gets, puts,
+ data_inserts, find_peer_requests, find_peers_started,
+ gets_started, puts_started, find_peer_responses_received,
+ get_responses_received, find_peer_responses_sent,
+ get_responses_sent);
if (ret < 0)
return GNUNET_SYSERR;
- ret = fprintf(outfile, "execute insert_stat using "
- "@temp_trial, @temp_node, @r_r, @r_f, @res_r, @c_r, "
- "@res_f, @gets, @puts, @d_i, "
- "@f_p_r, @f_p_s, @g_s, @p_s, "
- "@f_p_r_r, @g_r_r, @f_p_r_s, @g_r_s;\n");
+ ret = fprintf (outfile, "execute insert_stat using "
+ "@temp_trial, @temp_node, @r_r, @r_f, @res_r, @c_r, "
+ "@res_f, @gets, @puts, @d_i, "
+ "@f_p_r, @f_p_s, @g_s, @p_s, "
+ "@f_p_r_r, @g_r_r, @f_p_r_s, @g_r_s;\n");
if (ret < 0)
return GNUNET_SYSERR;
return GNUNET_OK;
}
+
/*
* Inserts the specified dhtkey into the dhttests.dhtkeys table,
* stores return value of dhttests.dhtkeys.dhtkeyuid into dhtkeyuid
@@ -486,6 +526,7 @@
add_dhtkey (unsigned long long *dhtkeyuid, const GNUNET_HashCode * dhtkey)
{
int ret;
+
if (dhtkeyuid != NULL)
*dhtkeyuid = 0;
@@ -493,13 +534,14 @@
return GNUNET_SYSERR;
if (dhtkey != NULL)
- ret = fprintf(outfile, "set @dhtkey = \"%s\";\n", GNUNET_h2s_full(dhtkey));
+ ret =
+ fprintf (outfile, "set @dhtkey = \"%s\";\n", GNUNET_h2s_full (dhtkey));
else
- ret = fprintf(outfile, "set @dhtkey = XXXXX;\n");
+ ret = fprintf (outfile, "set @dhtkey = XXXXX;\n");
if (ret < 0)
return GNUNET_SYSERR;
- ret = fprintf(outfile, "execute insert_dhtkey using @dhtkey;\n");
+ ret = fprintf (outfile, "execute insert_dhtkey using @dhtkey;\n");
if (ret >= 0)
return GNUNET_OK;
@@ -515,7 +557,7 @@
* @return GNUNET_OK on success, GNUNET_SYSERR on failure
*/
int
-add_node (unsigned long long *nodeuid, struct GNUNET_PeerIdentity * node)
+add_node (unsigned long long *nodeuid, struct GNUNET_PeerIdentity *node)
{
int ret;
@@ -525,12 +567,14 @@
if (outfile == NULL)
return GNUNET_SYSERR;
- ret = fprintf(outfile, "set @node = \"%s\";\n",
GNUNET_h2s_full(&node->hashPubKey));
+ ret =
+ fprintf (outfile, "set @node = \"%s\";\n",
+ GNUNET_h2s_full (&node->hashPubKey));
if (ret < 0)
return GNUNET_SYSERR;
- ret = fprintf(outfile, "execute insert_node using @node;\n");
+ ret = fprintf (outfile, "execute insert_node using @node;\n");
if (ret >= 0)
return GNUNET_OK;
@@ -552,12 +596,14 @@
if (outfile == NULL)
return GNUNET_SYSERR;
- ret = fprintf(outfile, "set @date = \"%s\", @g_s = %u;\n", get_sql_time(),
gets_succeeded);
+ ret =
+ fprintf (outfile, "set @date = \"%s\", @g_s = %u;\n", get_sql_time (),
+ gets_succeeded);
if (ret < 0)
return GNUNET_SYSERR;
- ret = fprintf(outfile, "execute update_trial using @date, @g_s;\n");
+ ret = fprintf (outfile, "execute update_trial using @date, @g_s;\n");
if (ret >= 0)
return GNUNET_OK;
@@ -582,12 +628,14 @@
if (outfile == NULL)
return GNUNET_SYSERR;
- ret = fprintf(outfile, "set @temp_node = \"%s\";\n",
GNUNET_h2s_full(&peer->hashPubKey));
+ ret =
+ fprintf (outfile, "set @temp_node = \"%s\";\n",
+ GNUNET_h2s_full (&peer->hashPubKey));
if (ret < 0)
return GNUNET_SYSERR;
- ret = fprintf(outfile, "execute set_malicious;\n");
+ ret = fprintf (outfile, "execute set_malicious;\n");
if (ret >= 0)
return GNUNET_OK;
@@ -611,12 +659,12 @@
if (outfile == NULL)
return GNUNET_SYSERR;
- ret = fprintf(outfile, "set @conns = %u;\n", totalConnections);
+ ret = fprintf (outfile, "set @conns = %u;\n", totalConnections);
if (ret < 0)
return GNUNET_SYSERR;
- ret = fprintf(outfile, "execute update_conn using @conns;\n");
+ ret = fprintf (outfile, "execute update_conn using @conns;\n");
if (ret >= 0)
return GNUNET_OK;
@@ -636,15 +684,16 @@
update_topology (unsigned int connections)
{
int ret;
+
if (outfile == NULL)
return GNUNET_SYSERR;
- ret = fprintf(outfile, "set @temp_conns = %u;\n", connections);
+ ret = fprintf (outfile, "set @temp_conns = %u;\n", connections);
if (ret < 0)
return GNUNET_SYSERR;
- ret = fprintf(outfile, "execute update_topology using @temp_conns;\n");
+ ret = fprintf (outfile, "execute update_topology using @temp_conns;\n");
if (ret >= 0)
return GNUNET_OK;
@@ -668,7 +717,7 @@
int
add_query (unsigned long long *sqlqueryuid, unsigned long long queryid,
unsigned int type, unsigned int hops, int succeeded,
- const struct GNUNET_PeerIdentity * node, const GNUNET_HashCode *
key)
+ const struct GNUNET_PeerIdentity *node, const GNUNET_HashCode * key)
{
int ret;
@@ -679,27 +728,38 @@
*sqlqueryuid = 0;
if (key != NULL)
- ret = fprintf(outfile, "select dhtkeyuid from dhtkeys where trialuid =
@temp_trial and dhtkey = \"%s\" into @temp_dhtkey;\n", GNUNET_h2s_full(key));
+ ret =
+ fprintf (outfile,
+ "select dhtkeyuid from dhtkeys where trialuid = @temp_trial
and dhtkey = \"%s\" into @temp_dhtkey;\n",
+ GNUNET_h2s_full (key));
else
- ret = fprintf(outfile, "set @temp_dhtkey = 0;\n");
+ ret = fprintf (outfile, "set @temp_dhtkey = 0;\n");
if (ret < 0)
return GNUNET_SYSERR;
if (node != NULL)
- ret = fprintf(outfile, "select nodeuid from nodes where trialuid =
@temp_trial and nodeid = \"%s\" into @temp_node;\n",
GNUNET_h2s_full(&node->hashPubKey));
+ ret =
+ fprintf (outfile,
+ "select nodeuid from nodes where trialuid = @temp_trial and
nodeid = \"%s\" into @temp_node;\n",
+ GNUNET_h2s_full (&node->hashPubKey));
else
- ret = fprintf(outfile, "set @temp_node = 0;\n");
+ ret = fprintf (outfile, "set @temp_node = 0;\n");
if (ret < 0)
return GNUNET_SYSERR;
- ret = fprintf(outfile, "set @qid = %llu, @type = %u, @hops = %u, @succ = %d,
@time = \"%s\";\n", queryid, type, hops, succeeded, get_sql_time());
+ ret =
+ fprintf (outfile,
+ "set @qid = %llu, @type = %u, @hops = %u, @succ = %d, @time =
\"%s\";\n",
+ queryid, type, hops, succeeded, get_sql_time ());
if (ret < 0)
return GNUNET_SYSERR;
- ret = fprintf(outfile, "execute insert_query using @type, @hops,
@temp_dhtkey, @qid, @succ, @temp_node, @time;\n");
+ ret =
+ fprintf (outfile,
+ "execute insert_query using @type, @hops, @temp_dhtkey, @qid,
@succ, @temp_node, @time;\n");
if (ret >= 0)
return GNUNET_OK;
@@ -725,9 +785,10 @@
int
add_route (unsigned long long *sqlqueryuid, unsigned long long queryid,
unsigned int type, unsigned int hops,
- int succeeded, const struct GNUNET_PeerIdentity * node,
- const GNUNET_HashCode * key, const struct GNUNET_PeerIdentity *
from_node,
- const struct GNUNET_PeerIdentity * to_node)
+ int succeeded, const struct GNUNET_PeerIdentity *node,
+ const GNUNET_HashCode * key,
+ const struct GNUNET_PeerIdentity *from_node,
+ const struct GNUNET_PeerIdentity *to_node)
{
int ret;
@@ -738,43 +799,60 @@
*sqlqueryuid = 0;
if (key != NULL)
- ret = fprintf(outfile, "select dhtkeyuid from dhtkeys where trialuid =
@temp_trial and dhtkey = \"%s\" into @temp_dhtkey;\n", GNUNET_h2s_full(key));
+ ret =
+ fprintf (outfile,
+ "select dhtkeyuid from dhtkeys where trialuid = @temp_trial
and dhtkey = \"%s\" into @temp_dhtkey;\n",
+ GNUNET_h2s_full (key));
else
- ret = fprintf(outfile, "set @temp_dhtkey = 0;\n");
+ ret = fprintf (outfile, "set @temp_dhtkey = 0;\n");
if (ret < 0)
return GNUNET_SYSERR;
if (node != NULL)
- ret = fprintf(outfile, "select nodeuid from nodes where trialuid =
@temp_trial and nodeid = \"%s\" into @temp_node;\n",
GNUNET_h2s_full(&node->hashPubKey));
+ ret =
+ fprintf (outfile,
+ "select nodeuid from nodes where trialuid = @temp_trial and
nodeid = \"%s\" into @temp_node;\n",
+ GNUNET_h2s_full (&node->hashPubKey));
else
- ret = fprintf(outfile, "set @temp_node = 0;\n");
+ ret = fprintf (outfile, "set @temp_node = 0;\n");
if (ret < 0)
return GNUNET_SYSERR;
if (from_node != NULL)
- ret = fprintf(outfile, "select nodeuid from nodes where trialuid =
@temp_trial and nodeid = \"%s\" into @temp_from_node;\n",
GNUNET_h2s_full(&from_node->hashPubKey));
+ ret =
+ fprintf (outfile,
+ "select nodeuid from nodes where trialuid = @temp_trial and
nodeid = \"%s\" into @temp_from_node;\n",
+ GNUNET_h2s_full (&from_node->hashPubKey));
else
- ret = fprintf(outfile, "set @temp_from_node = 0;\n");
+ ret = fprintf (outfile, "set @temp_from_node = 0;\n");
if (ret < 0)
return GNUNET_SYSERR;
if (to_node != NULL)
- ret = fprintf(outfile, "select nodeuid from nodes where trialuid =
@temp_trial and nodeid = \"%s\" into @temp_to_node;\n",
GNUNET_h2s_full(&to_node->hashPubKey));
+ ret =
+ fprintf (outfile,
+ "select nodeuid from nodes where trialuid = @temp_trial and
nodeid = \"%s\" into @temp_to_node;\n",
+ GNUNET_h2s_full (&to_node->hashPubKey));
else
- ret = fprintf(outfile, "set @temp_to_node = 0;\n");
+ ret = fprintf (outfile, "set @temp_to_node = 0;\n");
if (ret < 0)
return GNUNET_SYSERR;
- ret = fprintf(outfile, "set @qid = %llu, @type = %u, @hops = %u, @succ =
%d;\n", queryid, type, hops, succeeded);
+ ret =
+ fprintf (outfile,
+ "set @qid = %llu, @type = %u, @hops = %u, @succ = %d;\n",
+ queryid, type, hops, succeeded);
if (ret < 0)
return GNUNET_SYSERR;
- ret = fprintf(outfile, "execute insert_route using @type, @hops,
@temp_dhtkey, @qid, @succ, @temp_node, @temp_from_node, @temp_to_node;\n");
+ ret =
+ fprintf (outfile,
+ "execute insert_route using @type, @hops, @temp_dhtkey, @qid,
@succ, @temp_node, @temp_from_node, @temp_to_node;\n");
if (ret >= 0)
return GNUNET_OK;
@@ -790,7 +868,7 @@
* @return the handle to the server, or NULL on error
*/
void *
-libgnunet_plugin_dhtlog_mysql_dump_init (void * cls)
+libgnunet_plugin_dhtlog_mysql_dump_init (void *cls)
{
struct GNUNET_DHTLOG_Plugin *plugin = cls;
char *outfile_name;
@@ -801,60 +879,59 @@
cfg = plugin->cfg;
max_varchar_len = 255;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MySQL (DUMP) DHT Logger:
initializing\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "MySQL (DUMP) DHT Logger: initializing\n");
if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (plugin->cfg,
- "MYSQLDUMP", "PATH",
- &outfile_path))
- {
- outfile_path = GNUNET_strdup("");
- }
+ "MYSQLDUMP", "PATH",
+ &outfile_path))
+ {
+ outfile_path = GNUNET_strdup ("");
+ }
GNUNET_asprintf (&outfile_name,
- "%s%s-%d",
- outfile_path,
- "mysqldump",
- getpid());
+ "%s%s-%d", outfile_path, "mysqldump", getpid ());
fn = GNUNET_STRINGS_filename_expand (outfile_name);
if (fn == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Failed to get full path for
`%s'\n"), outfile_name);
- GNUNET_free(outfile_path);
- GNUNET_free(outfile_name);
- return NULL;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Failed to get full path for `%s'\n"), outfile_name);
+ GNUNET_free (outfile_path);
+ GNUNET_free (outfile_name);
+ return NULL;
+ }
- dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn));
+ dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn));
outfile = FOPEN (fn, "w");
if (outfile == 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(outfile_path);
- GNUNET_free(outfile_name);
- GNUNET_free (fn);
- return 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 (outfile_path);
+ GNUNET_free (outfile_name);
+ GNUNET_free (fn);
+ return NULL;
+ }
GNUNET_free (outfile_path);
GNUNET_free (outfile_name);
GNUNET_free (fn);
if (iopen () != GNUNET_OK)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to create file for dhtlog.\n"));
- fclose (outfile);
- return NULL;
- }
- GNUNET_assert(plugin->dhtlog_api == NULL);
- plugin->dhtlog_api = GNUNET_malloc(sizeof(struct GNUNET_DHTLOG_Handle));
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Failed to create file for dhtlog.\n"));
+ fclose (outfile);
+ return NULL;
+ }
+ GNUNET_assert (plugin->dhtlog_api == NULL);
+ plugin->dhtlog_api = GNUNET_malloc (sizeof (struct GNUNET_DHTLOG_Handle));
plugin->dhtlog_api->insert_trial = &add_trial;
plugin->dhtlog_api->insert_round = &add_round;
plugin->dhtlog_api->insert_round_details = &add_round_details;
@@ -878,14 +955,14 @@
* Shutdown the plugin.
*/
void *
-libgnunet_plugin_dhtlog_mysql_dump_done (void * cls)
+libgnunet_plugin_dhtlog_mysql_dump_done (void *cls)
{
struct GNUNET_DHTLOG_Handle *dhtlog_api = cls;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "MySQL DHT Logger: database shutdown\n");
- GNUNET_assert(dhtlog_api != NULL);
- GNUNET_free(dhtlog_api);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MySQL DHT Logger: database
shutdown\n");
+ GNUNET_assert (dhtlog_api != NULL);
+
+ GNUNET_free (dhtlog_api);
return NULL;
}
Modified: gnunet/src/dht/plugin_dhtlog_mysql_dump_load.c
===================================================================
--- gnunet/src/dht/plugin_dhtlog_mysql_dump_load.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/dht/plugin_dhtlog_mysql_dump_load.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -69,7 +69,7 @@
FILE *extended_topology_outfile;
static char *
-get_sql_time()
+get_sql_time ()
{
static char date[DATE_STR_SIZE];
time_t timetmp;
@@ -97,13 +97,19 @@
add_topology (int num_connections)
{
int ret;
+
if (outfile == NULL)
return GNUNET_SYSERR;
- ret = fprintf(outfile, "insert into topology (trialuid, date, connections)
values (@temp_trial, \"%s\", %d);\n", get_sql_time(), num_connections);
+ ret =
+ fprintf (outfile,
+ "insert into topology (trialuid, date, connections) values
(@temp_trial, \"%s\", %d);\n",
+ get_sql_time (), num_connections);
if (ret < 0)
return GNUNET_SYSERR;
- ret = fprintf(outfile, "select max(topology_uid) from topology into
@temp_topology;\n");
+ ret =
+ fprintf (outfile,
+ "select max(topology_uid) from topology into
@temp_topology;\n");
if (ret >= 0)
return GNUNET_OK;
return GNUNET_SYSERR;
@@ -117,13 +123,18 @@
*
* @return GNUNET_OK on success, GNUNET_SYSERR on failure
*/
-int add_round (unsigned int round_type, unsigned int round_count)
+int
+add_round (unsigned int round_type, unsigned int round_count)
{
int ret;
+
if (outfile == NULL)
return GNUNET_SYSERR;
- ret = fprintf(outfile, "insert into rounds (trialuid, round_type,
round_count, starttime) values (@temp_trial, \"%u\", \"%u\", \"%s\");\n",
round_type, round_count, get_sql_time());
+ ret =
+ fprintf (outfile,
+ "insert into rounds (trialuid, round_type, round_count,
starttime) values (@temp_trial, \"%u\", \"%u\", \"%s\");\n",
+ round_type, round_count, get_sql_time ());
if (ret >= 0)
return GNUNET_OK;
@@ -142,15 +153,21 @@
*
* @return GNUNET_OK on success, GNUNET_SYSERR on failure
*/
-int add_round_details (unsigned int round_type, unsigned int round_count,
- unsigned int num_messages, unsigned int
num_messages_succeeded)
+int
+add_round_details (unsigned int round_type, unsigned int round_count,
+ unsigned int num_messages,
+ unsigned int num_messages_succeeded)
{
int ret;
+
if (outfile == NULL)
return GNUNET_SYSERR;
- ret = fprintf(outfile, "insert into processed_trial_rounds (trialuid,
round_type, round_count, starttime, endtime, num_messages,
num_messages_succeeded) values (@temp_trial, \"%u\", \"%u\", \"%s\", \"%s\",
\"%u\", \"%u\");\n",
- round_type,
round_count, get_sql_time(), get_sql_time(), num_messages,
num_messages_succeeded);
+ ret =
+ fprintf (outfile,
+ "insert into processed_trial_rounds (trialuid, round_type,
round_count, starttime, endtime, num_messages, num_messages_succeeded) values
(@temp_trial, \"%u\", \"%u\", \"%s\", \"%s\", \"%u\", \"%u\");\n",
+ round_type, round_count, get_sql_time (), get_sql_time (),
+ num_messages, num_messages_succeeded);
if (ret >= 0)
return GNUNET_OK;
@@ -166,16 +183,23 @@
* @return GNUNET_OK on success, GNUNET_SYSERR on failure
*/
int
-add_extended_topology (const struct GNUNET_PeerIdentity *first, const struct
GNUNET_PeerIdentity *second)
+add_extended_topology (const struct GNUNET_PeerIdentity *first,
+ const struct GNUNET_PeerIdentity *second)
{
int ret;
+
if (outfile == NULL)
return GNUNET_SYSERR;
- ret = fprintf(extended_topology_outfile, "insert into extended_topology
(topology_uid, uid_first, uid_second) values (%u, %s,", topology_count,
GNUNET_h2s_full(&first->hashPubKey));
+ ret =
+ fprintf (extended_topology_outfile,
+ "insert into extended_topology (topology_uid, uid_first,
uid_second) values (%u, %s,",
+ topology_count, GNUNET_h2s_full (&first->hashPubKey));
if (ret < 0)
return GNUNET_SYSERR;
- ret = fprintf(extended_topology_outfile, "%s);\n",
GNUNET_h2s_full(&second->hashPubKey));
+ ret =
+ fprintf (extended_topology_outfile, "%s);\n",
+ GNUNET_h2s_full (&second->hashPubKey));
if (ret >= 0)
return GNUNET_OK;
@@ -190,35 +214,46 @@
*
* @return GNUNET_OK on success, GNUNET_SYSERR on failure
*/
-int add_trial (struct GNUNET_DHTLOG_TrialInfo *trial_info)
+int
+add_trial (struct GNUNET_DHTLOG_TrialInfo *trial_info)
{
int ret;
+
if (outfile == NULL)
return GNUNET_SYSERR;
- ret = fprintf(outfile, "INSERT INTO trials "
- "(starttime, other_trial_identifier, numnodes,
topology,"
- "blacklist_topology, connect_topology,
connect_topology_option,"
- "connect_topology_option_modifier,
topology_percentage, topology_probability,"
- "puts, gets, "
- "concurrent, settle_time, num_rounds,
malicious_getters,"
- "malicious_putters, malicious_droppers,
malicious_get_frequency,"
- "malicious_put_frequency, stop_closest, stop_found,
strict_kademlia, "
- "gets_succeeded, message) "
- "VALUES (\"%s\", %u, %u, %u, %u, %u, %u, %f, %f,
%f, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, \"%s\");\n",
- get_sql_time(), trial_info->other_identifier,
trial_info->num_nodes, trial_info->topology,
- trial_info->blacklist_topology,
trial_info->connect_topology,
- trial_info->connect_topology_option,
trial_info->connect_topology_option_modifier,
- trial_info->topology_percentage,
trial_info->topology_probability,
- trial_info->puts, trial_info->gets,
trial_info->concurrent, trial_info->settle_time,
- trial_info->num_rounds,
trial_info->malicious_getters, trial_info->malicious_putters,
- trial_info->malicious_droppers,
trial_info->malicious_get_frequency, trial_info->malicious_put_frequency,
- trial_info->stop_closest, trial_info->stop_found,
trial_info->strict_kademlia, trial_info->gets_succeeded, trial_info->message);
+ ret = fprintf (outfile, "INSERT INTO trials "
+ "(starttime, other_trial_identifier, numnodes, topology,"
+ "blacklist_topology, connect_topology,
connect_topology_option,"
+ "connect_topology_option_modifier, topology_percentage,
topology_probability,"
+ "puts, gets, "
+ "concurrent, settle_time, num_rounds, malicious_getters,"
+ "malicious_putters, malicious_droppers,
malicious_get_frequency,"
+ "malicious_put_frequency, stop_closest, stop_found,
strict_kademlia, "
+ "gets_succeeded, message) "
+ "VALUES (\"%s\", %u, %u, %u, %u, %u, %u, %f, %f, %f, %u, %u,
%u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, \"%s\");\n",
+ get_sql_time (), trial_info->other_identifier,
+ trial_info->num_nodes, trial_info->topology,
+ trial_info->blacklist_topology, trial_info->connect_topology,
+ trial_info->connect_topology_option,
+ trial_info->connect_topology_option_modifier,
+ trial_info->topology_percentage,
+ trial_info->topology_probability, trial_info->puts,
+ trial_info->gets, trial_info->concurrent,
+ trial_info->settle_time, trial_info->num_rounds,
+ trial_info->malicious_getters, trial_info->malicious_putters,
+ trial_info->malicious_droppers,
+ trial_info->malicious_get_frequency,
+ trial_info->malicious_put_frequency, trial_info->stop_closest,
+ trial_info->stop_found, trial_info->strict_kademlia,
+ trial_info->gets_succeeded, trial_info->message);
if (ret < 0)
return GNUNET_SYSERR;
- ret = fprintf(outfile, "SELECT MAX( trialuid ) FROM trials into
@temp_trial;\n");
+ ret =
+ fprintf (outfile,
+ "SELECT MAX( trialuid ) FROM trials into @temp_trial;\n");
if (ret >= 0)
return GNUNET_OK;
@@ -239,14 +274,15 @@
*/
int
add_generic_stat (const struct GNUNET_PeerIdentity *peer,
- const char *name,
- const char *section, uint64_t value)
+ const char *name, const char *section, uint64_t value)
{
if (outfile == NULL)
return GNUNET_SYSERR;
if (peer != NULL)
- fprintf(generic_stat_outfile, "TRIALUID\t%s\t%s\t%s\t%llu\n",
GNUNET_h2s_full(&peer->hashPubKey), section, name, (unsigned long long)value);
+ fprintf (generic_stat_outfile, "TRIALUID\t%s\t%s\t%s\t%llu\n",
+ GNUNET_h2s_full (&peer->hashPubKey), section, name,
+ (unsigned long long) value);
return GNUNET_OK;
}
@@ -283,22 +319,25 @@
unsigned int data_inserts, unsigned int find_peer_requests,
unsigned int find_peers_started, unsigned int gets_started,
unsigned int puts_started, unsigned int find_peer_responses_received,
- unsigned int get_responses_received, unsigned int
find_peer_responses_sent,
+ unsigned int get_responses_received,
+ unsigned int find_peer_responses_sent,
unsigned int get_responses_sent)
{
int ret;
+
if (outfile == NULL)
return GNUNET_SYSERR;
if (peer != NULL)
- ret = fprintf(stat_outfile,
"TRIALUID\t%s\t%u\t%u\t%u\t%u\t%u\t%u\t%u\t%u\t%u\t%u\t%u\t%u\t%u\t%u\t%u\t%u\n",
- GNUNET_h2s_full(&peer->hashPubKey),
- route_requests, route_forwards,
result_requests,
- client_requests, result_forwards, gets, puts,
- data_inserts, find_peer_requests,
find_peers_started,
- gets_started, puts_started,
find_peer_responses_received,
- get_responses_received,
find_peer_responses_sent,
- get_responses_sent);
+ ret =
+ fprintf (stat_outfile,
+
"TRIALUID\t%s\t%u\t%u\t%u\t%u\t%u\t%u\t%u\t%u\t%u\t%u\t%u\t%u\t%u\t%u\t%u\t%u\n",
+ GNUNET_h2s_full (&peer->hashPubKey), route_requests,
+ route_forwards, result_requests, client_requests,
+ result_forwards, gets, puts, data_inserts, find_peer_requests,
+ find_peers_started, gets_started, puts_started,
+ find_peer_responses_received, get_responses_received,
+ find_peer_responses_sent, get_responses_sent);
else
return GNUNET_SYSERR;
@@ -308,6 +347,7 @@
else
return GNUNET_SYSERR;
}
+
/*
* Inserts the specified dhtkey into the dhttests.dhtkeys table,
* stores return value of dhttests.dhtkeys.dhtkeyuid into dhtkeyuid
@@ -321,13 +361,14 @@
add_dhtkey (unsigned long long *dhtkeyuid, const GNUNET_HashCode * dhtkey)
{
int ret;
+
if (dhtkeyuid != NULL)
*dhtkeyuid = 0;
if ((dhtkey_outfile == NULL) || (dhtkey == NULL))
return GNUNET_SYSERR;
- ret = fprintf(dhtkey_outfile, "TRIALUID\t%s\n", GNUNET_h2s_full(dhtkey));
+ ret = fprintf (dhtkey_outfile, "TRIALUID\t%s\n", GNUNET_h2s_full (dhtkey));
if (ret >= 0)
return GNUNET_OK;
@@ -344,15 +385,17 @@
* @return GNUNET_OK on success, GNUNET_SYSERR on failure
*/
int
-add_node (unsigned long long *nodeuid, struct GNUNET_PeerIdentity * node)
+add_node (unsigned long long *nodeuid, struct GNUNET_PeerIdentity *node)
{
int ret;
if ((node == NULL) || (node_outfile == NULL))
return GNUNET_SYSERR;
- ret = fprintf(node_outfile, "TRIALUID\t%s\n",
GNUNET_h2s_full(&node->hashPubKey));
- fflush(node_outfile);
+ ret =
+ fprintf (node_outfile, "TRIALUID\t%s\n",
+ GNUNET_h2s_full (&node->hashPubKey));
+ fflush (node_outfile);
if (ret >= 0)
return GNUNET_OK;
return GNUNET_SYSERR;
@@ -373,8 +416,11 @@
if (outfile == NULL)
return GNUNET_SYSERR;
- ret = fprintf(outfile, "update trials set endtime=\"%s\", gets_succeeded=%u
where trialuid = @temp_trial;\n", get_sql_time(), gets_succeeded);
- fflush(node_outfile);
+ ret =
+ fprintf (outfile,
+ "update trials set endtime=\"%s\", gets_succeeded=%u where
trialuid = @temp_trial;\n",
+ get_sql_time (), gets_succeeded);
+ fflush (node_outfile);
if (ret >= 0)
return GNUNET_OK;
else
@@ -398,8 +444,11 @@
if (outfile == NULL)
return GNUNET_SYSERR;
- ret = fprintf(outfile, "update nodes set malicious_dropper = 1 where
trialuid = @temp_trial and nodeid = \"%s\";\n",
GNUNET_h2s_full(&peer->hashPubKey));
- fflush(node_outfile);
+ ret =
+ fprintf (outfile,
+ "update nodes set malicious_dropper = 1 where trialuid =
@temp_trial and nodeid = \"%s\";\n",
+ GNUNET_h2s_full (&peer->hashPubKey));
+ fflush (node_outfile);
if (ret >= 0)
return GNUNET_OK;
else
@@ -422,8 +471,11 @@
if (outfile == NULL)
return GNUNET_SYSERR;
- ret = fprintf(outfile, "update trials set totalConnections = %u where
trialuid = @temp_trial;\n", totalConnections);
- fflush(node_outfile);
+ ret =
+ fprintf (outfile,
+ "update trials set totalConnections = %u where trialuid =
@temp_trial;\n",
+ totalConnections);
+ fflush (node_outfile);
if (ret >= 0)
return GNUNET_OK;
else
@@ -442,10 +494,14 @@
update_topology (unsigned int connections)
{
int ret;
+
if (outfile == NULL)
return GNUNET_SYSERR;
- ret = fprintf(outfile, "update topology set connections = %u where
topology_uid = @temp_topology;\n", connections);
+ ret =
+ fprintf (outfile,
+ "update topology set connections = %u where topology_uid =
@temp_topology;\n",
+ connections);
topology_count++;
if (ret >= 0)
return GNUNET_OK;
@@ -469,7 +525,7 @@
int
add_query (unsigned long long *sqlqueryuid, unsigned long long queryid,
unsigned int type, unsigned int hops, int succeeded,
- const struct GNUNET_PeerIdentity * node, const GNUNET_HashCode *
key)
+ const struct GNUNET_PeerIdentity *node, const GNUNET_HashCode * key)
{
int ret;
@@ -479,12 +535,15 @@
if (sqlqueryuid != NULL)
*sqlqueryuid = 0;
- ret = fprintf(query_outfile, "TRIALUID\t%s\t", GNUNET_h2s_full(key));
+ ret = fprintf (query_outfile, "TRIALUID\t%s\t", GNUNET_h2s_full (key));
if (ret < 0)
return GNUNET_SYSERR;
- ret = fprintf(query_outfile, "%s\t%llu\t%u\t%u\t%u\t%s\n",
GNUNET_h2s_full(&node->hashPubKey), queryid, type, hops, succeeded,
get_sql_time());
+ ret =
+ fprintf (query_outfile, "%s\t%llu\t%u\t%u\t%u\t%s\n",
+ GNUNET_h2s_full (&node->hashPubKey), queryid, type, hops,
+ succeeded, get_sql_time ());
if (ret >= 0)
return GNUNET_OK;
@@ -510,9 +569,10 @@
int
add_route (unsigned long long *sqlqueryuid, unsigned long long queryid,
unsigned int type, unsigned int hops,
- int succeeded, const struct GNUNET_PeerIdentity * node,
- const GNUNET_HashCode * key, const struct GNUNET_PeerIdentity *
from_node,
- const struct GNUNET_PeerIdentity * to_node)
+ int succeeded, const struct GNUNET_PeerIdentity *node,
+ const GNUNET_HashCode * key,
+ const struct GNUNET_PeerIdentity *from_node,
+ const struct GNUNET_PeerIdentity *to_node)
{
int ret;
@@ -522,24 +582,31 @@
if (sqlqueryuid != NULL)
*sqlqueryuid = 0;
- ret = fprintf(route_outfile, "TRIALUID\t%s\t", GNUNET_h2s_full(key));
+ ret = fprintf (route_outfile, "TRIALUID\t%s\t", GNUNET_h2s_full (key));
if (ret < 0)
return GNUNET_SYSERR;
- ret = fprintf(route_outfile, "%s\t", GNUNET_h2s_full(&node->hashPubKey));
+ ret = fprintf (route_outfile, "%s\t", GNUNET_h2s_full (&node->hashPubKey));
if (ret < 0)
return GNUNET_SYSERR;
if (from_node == NULL)
- ret = fprintf(route_outfile, "0\t");
+ ret = fprintf (route_outfile, "0\t");
else
- ret = fprintf(route_outfile, "%s\t",
GNUNET_h2s_full(&from_node->hashPubKey));
+ ret =
+ fprintf (route_outfile, "%s\t",
+ GNUNET_h2s_full (&from_node->hashPubKey));
if (ret < 0)
return GNUNET_SYSERR;
if (to_node == NULL)
- ret = fprintf(route_outfile, "0\t%llu\t%u\t%u\t%d\n", queryid, type, hops,
succeeded);
+ ret =
+ fprintf (route_outfile, "0\t%llu\t%u\t%u\t%d\n", queryid, type, hops,
+ succeeded);
else
- ret = fprintf(route_outfile, "%s\t%llu\t%u\t%u\t%d\n",
GNUNET_h2s_full(&to_node->hashPubKey), queryid, type, hops, succeeded);
+ ret =
+ fprintf (route_outfile, "%s\t%llu\t%u\t%u\t%d\n",
+ GNUNET_h2s_full (&to_node->hashPubKey), queryid, type, hops,
+ succeeded);
if (ret >= 0)
return GNUNET_OK;
@@ -555,7 +622,7 @@
* @return the handle to the server, or NULL on error
*/
void *
-libgnunet_plugin_dhtlog_mysql_dump_load_init (void * cls)
+libgnunet_plugin_dhtlog_mysql_dump_load_init (void *cls)
{
struct GNUNET_DHTLOG_Plugin *plugin = cls;
char *outfile_name;
@@ -566,287 +633,274 @@
cfg = plugin->cfg;
max_varchar_len = 255;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MySQL (DUMP) DHT Logger:
initializing\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "MySQL (DUMP) DHT Logger: initializing\n");
if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (plugin->cfg,
- "MYSQLDUMP", "PATH",
- &outfile_path))
- {
- outfile_path = GNUNET_strdup("");
- }
+ "MYSQLDUMP", "PATH",
+ &outfile_path))
+ {
+ outfile_path = GNUNET_strdup ("");
+ }
GNUNET_asprintf (&outfile_name,
- "%s%s-%d",
- outfile_path,
- "mysqldump",
- getpid());
+ "%s%s-%d", outfile_path, "mysqldump", getpid ());
fn = GNUNET_STRINGS_filename_expand (outfile_name);
if (fn == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Failed to get full path for
`%s'\n"), outfile_name);
- GNUNET_free(outfile_path);
- GNUNET_free(outfile_name);
- return NULL;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Failed to get full path for `%s'\n"), outfile_name);
+ GNUNET_free (outfile_path);
+ GNUNET_free (outfile_name);
+ return NULL;
+ }
- dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn));
+ dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn));
outfile = FOPEN (fn, "w");
if (outfile == 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(outfile_path);
- GNUNET_free(outfile_name);
- GNUNET_free (fn);
- return 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 (outfile_path);
+ GNUNET_free (outfile_name);
+ GNUNET_free (fn);
+ return NULL;
+ }
- GNUNET_free(outfile_name);
+ GNUNET_free (outfile_name);
GNUNET_asprintf (&outfile_name,
- "%s%s-%d",
- outfile_path,
- "mysqldump_nodes",
- getpid());
- GNUNET_free(fn);
+ "%s%s-%d", outfile_path, "mysqldump_nodes", getpid ());
+ GNUNET_free (fn);
fn = GNUNET_STRINGS_filename_expand (outfile_name);
if (fn == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Failed to get full path for
`%s'\n"), outfile_name);
- GNUNET_free(outfile_path);
- GNUNET_free(outfile_name);
- return NULL;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Failed to get full path for `%s'\n"), outfile_name);
+ GNUNET_free (outfile_path);
+ GNUNET_free (outfile_name);
+ return NULL;
+ }
- dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn));
+ dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn));
node_outfile = FOPEN (fn, "w");
if (node_outfile == 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(outfile_path);
- GNUNET_free(outfile_name);
- GNUNET_free (fn);
- return 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 (outfile_path);
+ GNUNET_free (outfile_name);
+ GNUNET_free (fn);
+ return NULL;
+ }
- GNUNET_free(outfile_name);
+ GNUNET_free (outfile_name);
GNUNET_asprintf (&outfile_name,
- "%s%s-%d",
- outfile_path,
- "mysqldump_routes",
- getpid());
+ "%s%s-%d", outfile_path, "mysqldump_routes", getpid ());
- GNUNET_free(fn);
+ GNUNET_free (fn);
fn = GNUNET_STRINGS_filename_expand (outfile_name);
if (fn == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Failed to get full path for
`%s'\n"), outfile_name);
- GNUNET_free(outfile_path);
- GNUNET_free(outfile_name);
- return NULL;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Failed to get full path for `%s'\n"), outfile_name);
+ GNUNET_free (outfile_path);
+ GNUNET_free (outfile_name);
+ return NULL;
+ }
- dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn));
+ dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn));
route_outfile = FOPEN (fn, "w");
if (route_outfile == 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(outfile_path);
- GNUNET_free(outfile_name);
- GNUNET_free (fn);
- return 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 (outfile_path);
+ GNUNET_free (outfile_name);
+ GNUNET_free (fn);
+ return NULL;
+ }
- GNUNET_free(outfile_name);
+ GNUNET_free (outfile_name);
GNUNET_asprintf (&outfile_name,
- "%s%s-%d",
- outfile_path,
- "mysqldump_queries",
- getpid());
+ "%s%s-%d", outfile_path, "mysqldump_queries", getpid ());
- GNUNET_free(fn);
+ GNUNET_free (fn);
fn = GNUNET_STRINGS_filename_expand (outfile_name);
if (fn == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Failed to get full path for
`%s'\n"), outfile_name);
- GNUNET_free(outfile_path);
- GNUNET_free(outfile_name);
- return NULL;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Failed to get full path for `%s'\n"), outfile_name);
+ GNUNET_free (outfile_path);
+ GNUNET_free (outfile_name);
+ return NULL;
+ }
- dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn));
+ dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn));
query_outfile = FOPEN (fn, "w");
if (query_outfile == 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(outfile_path);
- GNUNET_free(outfile_name);
- GNUNET_free (fn);
- return 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 (outfile_path);
+ GNUNET_free (outfile_name);
+ GNUNET_free (fn);
+ return NULL;
+ }
- GNUNET_free(outfile_name);
+ GNUNET_free (outfile_name);
GNUNET_asprintf (&outfile_name,
- "%s%s-%d",
- outfile_path,
- "mysqldump_stats",
- getpid());
+ "%s%s-%d", outfile_path, "mysqldump_stats", getpid ());
- GNUNET_free(fn);
+ GNUNET_free (fn);
fn = GNUNET_STRINGS_filename_expand (outfile_name);
if (fn == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Failed to get full path for
`%s'\n"), outfile_name);
- GNUNET_free(outfile_path);
- GNUNET_free(outfile_name);
- return NULL;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Failed to get full path for `%s'\n"), outfile_name);
+ GNUNET_free (outfile_path);
+ GNUNET_free (outfile_name);
+ return NULL;
+ }
- dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn));
+ dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn));
stat_outfile = FOPEN (fn, "w");
if (stat_outfile == 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(outfile_path);
- GNUNET_free(outfile_name);
- GNUNET_free (fn);
- return 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 (outfile_path);
+ GNUNET_free (outfile_name);
+ GNUNET_free (fn);
+ return NULL;
+ }
- GNUNET_free(outfile_name);
+ GNUNET_free (outfile_name);
GNUNET_asprintf (&outfile_name,
"%s%s-%d",
- outfile_path,
- "mysqldump_generic_stats",
- getpid());
- GNUNET_free(fn);
+ outfile_path, "mysqldump_generic_stats", getpid ());
+ GNUNET_free (fn);
fn = GNUNET_STRINGS_filename_expand (outfile_name);
if (fn == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Failed to get full path for
`%s'\n"), outfile_name);
- GNUNET_free(outfile_path);
- GNUNET_free(outfile_name);
- return NULL;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Failed to get full path for `%s'\n"), outfile_name);
+ GNUNET_free (outfile_path);
+ GNUNET_free (outfile_name);
+ return NULL;
+ }
- dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn));
+ dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn));
generic_stat_outfile = FOPEN (fn, "w");
if (generic_stat_outfile == 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(outfile_path);
- GNUNET_free(outfile_name);
- GNUNET_free (fn);
- return 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 (outfile_path);
+ GNUNET_free (outfile_name);
+ GNUNET_free (fn);
+ return NULL;
+ }
- GNUNET_free(outfile_name);
+ GNUNET_free (outfile_name);
GNUNET_asprintf (&outfile_name,
- "%s%s-%d",
- outfile_path,
- "mysqldump_dhtkey",
- getpid());
- GNUNET_free(fn);
+ "%s%s-%d", outfile_path, "mysqldump_dhtkey", getpid ());
+ GNUNET_free (fn);
fn = GNUNET_STRINGS_filename_expand (outfile_name);
if (fn == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Failed to get full path for
`%s'\n"), outfile_name);
- GNUNET_free(outfile_path);
- GNUNET_free(outfile_name);
- return NULL;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Failed to get full path for `%s'\n"), outfile_name);
+ GNUNET_free (outfile_path);
+ GNUNET_free (outfile_name);
+ return NULL;
+ }
- dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn));
+ dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn));
dhtkey_outfile = FOPEN (fn, "w");
if (dhtkey_outfile == 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(outfile_path);
- GNUNET_free(outfile_name);
- GNUNET_free (fn);
- return 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 (outfile_path);
+ GNUNET_free (outfile_name);
+ GNUNET_free (fn);
+ return NULL;
+ }
- GNUNET_free(outfile_name);
+ GNUNET_free (outfile_name);
GNUNET_asprintf (&outfile_name,
"%s%s-%d",
- outfile_path,
- "mysqldump_extended_topology",
- getpid());
- GNUNET_free(fn);
+ outfile_path, "mysqldump_extended_topology", getpid ());
+ GNUNET_free (fn);
fn = GNUNET_STRINGS_filename_expand (outfile_name);
if (fn == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Failed to get full path for
`%s'\n"), outfile_name);
- GNUNET_free(outfile_path);
- GNUNET_free(outfile_name);
- return NULL;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Failed to get full path for `%s'\n"), outfile_name);
+ GNUNET_free (outfile_path);
+ GNUNET_free (outfile_name);
+ return NULL;
+ }
- dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn));
+ dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn));
extended_topology_outfile = FOPEN (fn, "w");
if (extended_topology_outfile == 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(outfile_path);
- GNUNET_free(outfile_name);
- GNUNET_free (fn);
- return 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 (outfile_path);
+ GNUNET_free (outfile_name);
+ GNUNET_free (fn);
+ return NULL;
+ }
GNUNET_free (outfile_path);
GNUNET_free (outfile_name);
GNUNET_free (fn);
- GNUNET_assert(plugin->dhtlog_api == NULL);
- plugin->dhtlog_api = GNUNET_malloc(sizeof(struct GNUNET_DHTLOG_Handle));
+ GNUNET_assert (plugin->dhtlog_api == NULL);
+ plugin->dhtlog_api = GNUNET_malloc (sizeof (struct GNUNET_DHTLOG_Handle));
plugin->dhtlog_api->insert_trial = &add_trial;
plugin->dhtlog_api->insert_stat = &add_stat;
plugin->dhtlog_api->insert_round = &add_round;
@@ -870,21 +924,21 @@
* Shutdown the plugin.
*/
void *
-libgnunet_plugin_dhtlog_mysql_dump_load_done (void * cls)
+libgnunet_plugin_dhtlog_mysql_dump_load_done (void *cls)
{
struct GNUNET_DHTLOG_Handle *dhtlog_api = cls;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "MySQL DHT Logger: database shutdown\n");
- GNUNET_assert(dhtlog_api != NULL);
- fclose(outfile);
- fclose(node_outfile);
- fclose(query_outfile);
- fclose(route_outfile);
- fclose(stat_outfile);
- fclose(generic_stat_outfile);
- fclose(extended_topology_outfile);
- GNUNET_free(dhtlog_api);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MySQL DHT Logger: database
shutdown\n");
+ GNUNET_assert (dhtlog_api != NULL);
+
+ fclose (outfile);
+ fclose (node_outfile);
+ fclose (query_outfile);
+ fclose (route_outfile);
+ fclose (stat_outfile);
+ fclose (generic_stat_outfile);
+ fclose (extended_topology_outfile);
+ GNUNET_free (dhtlog_api);
return NULL;
}
Modified: gnunet/src/dht/test_dht_api.c
===================================================================
--- gnunet/src/dht/test_dht_api.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/dht/test_dht_api.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -112,7 +112,7 @@
die_task = GNUNET_SCHEDULER_NO_TASK;
GNUNET_DHT_disconnect (p1.dht_handle);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "DHT disconnected, returning success!\n");
+ "DHT disconnected, returning success!\n");
ok = 0;
}
@@ -138,20 +138,20 @@
fprintf (stderr, "Ending on an unhappy note.\n");
#endif
- if ( (retry_context.peer_ctx != NULL) &&
- (retry_context.peer_ctx->find_peer_handle != NULL) )
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Stopping find peer request!\n");
- GNUNET_DHT_find_peer_stop(retry_context.peer_ctx->find_peer_handle);
- }
- if ( (retry_context.peer_ctx != NULL) &&
- (retry_context.peer_ctx->get_handle != NULL) )
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Stopping get request!\n");
- GNUNET_DHT_get_stop (retry_context.peer_ctx->get_handle);
- }
+ if ((retry_context.peer_ctx != NULL) &&
+ (retry_context.peer_ctx->find_peer_handle != NULL))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping find peer request!\n");
+ GNUNET_DHT_find_peer_stop (retry_context.peer_ctx->find_peer_handle);
+ }
+ if ((retry_context.peer_ctx != NULL) &&
+ (retry_context.peer_ctx->get_handle != NULL))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping get request!\n");
+ GNUNET_DHT_get_stop (retry_context.peer_ctx->get_handle);
+ }
if (retry_context.retry_task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel(retry_context.retry_task);
+ GNUNET_SCHEDULER_cancel (retry_context.retry_task);
GNUNET_DHT_disconnect (p1.dht_handle);
ok = 1;
}
@@ -169,13 +169,13 @@
struct PeerContext *peer = cls;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_find_peer_stop!\n");
- if ( (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT) != 0)
- {
- GNUNET_break (0);
- GNUNET_SCHEDULER_cancel (die_task);
- GNUNET_SCHEDULER_add_now (&end_badly, NULL);
- return;
- }
+ if ((tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT) != 0)
+ {
+ GNUNET_break (0);
+ GNUNET_SCHEDULER_cancel (die_task);
+ GNUNET_SCHEDULER_add_now (&end_badly, NULL);
+ return;
+ }
GNUNET_assert (peer->dht_handle != NULL);
@@ -183,12 +183,14 @@
peer->find_peer_handle = NULL;
#if HAVE_MALICIOUS
- GNUNET_DHT_set_malicious_getter (peer->dht_handle, GNUNET_TIME_UNIT_SECONDS,
NULL, NULL);
- GNUNET_DHT_set_malicious_putter (peer->dht_handle, GNUNET_TIME_UNIT_SECONDS,
NULL, NULL);
+ GNUNET_DHT_set_malicious_getter (peer->dht_handle, GNUNET_TIME_UNIT_SECONDS,
+ NULL, NULL);
+ GNUNET_DHT_set_malicious_putter (peer->dht_handle, GNUNET_TIME_UNIT_SECONDS,
+ NULL, NULL);
GNUNET_DHT_set_malicious_dropper (peer->dht_handle, NULL, NULL);
#endif
-
GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
1),
- &end, &p1);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 1), &end, &p1);
}
@@ -200,32 +202,33 @@
* @param peer the peer we learned about
* @param reply response
*/
-void test_find_peer_processor (void *cls,
- const struct GNUNET_HELLO_Message *hello)
+void
+test_find_peer_processor (void *cls, const struct GNUNET_HELLO_Message *hello)
{
struct RetryContext *retry_ctx = cls;
struct GNUNET_PeerIdentity peer;
- if (GNUNET_OK == GNUNET_HELLO_get_id(hello, &peer))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "test_find_peer_processor called (peer `%s'), stopping find
peer request!\n", GNUNET_i2s(&peer));
+ if (GNUNET_OK == GNUNET_HELLO_get_id (hello, &peer))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "test_find_peer_processor called (peer `%s'), stopping find
peer request!\n",
+ GNUNET_i2s (&peer));
- if (retry_ctx->retry_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel(retry_ctx->retry_task);
- retry_ctx->retry_task = GNUNET_SCHEDULER_NO_TASK;
- }
-
- GNUNET_SCHEDULER_add_continuation (&test_find_peer_stop, &p1,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- }
- else
+ if (retry_ctx->retry_task != GNUNET_SCHEDULER_NO_TASK)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "received find peer request, but hello_get_id failed!\n");
+ GNUNET_SCHEDULER_cancel (retry_ctx->retry_task);
+ retry_ctx->retry_task = GNUNET_SCHEDULER_NO_TASK;
}
+ GNUNET_SCHEDULER_add_continuation (&test_find_peer_stop, &p1,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "received find peer request, but hello_get_id failed!\n");
+ }
+
}
/**
@@ -248,35 +251,40 @@
{
struct RetryContext *retry_ctx = cls;
GNUNET_HashCode hash;
+
memset (&hash, 42, sizeof (GNUNET_HashCode));
- if (GNUNET_TIME_absolute_get_remaining(retry_ctx->real_timeout).rel_value >
0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "test_find_peer timed out, retrying!\n");
- retry_ctx->next_timeout =
GNUNET_TIME_relative_multiply(retry_ctx->next_timeout, 2);
- retry_ctx->peer_ctx->find_peer_handle
- = GNUNET_DHT_find_peer_start (retry_ctx->peer_ctx->dht_handle,
- retry_ctx->next_timeout, &hash,
- GNUNET_DHT_RO_NONE,
- &test_find_peer_processor, retry_ctx);
- }
+ if (GNUNET_TIME_absolute_get_remaining (retry_ctx->real_timeout).rel_value >
+ 0)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "test_find_peer timed out, retrying!\n");
+ retry_ctx->next_timeout =
+ GNUNET_TIME_relative_multiply (retry_ctx->next_timeout, 2);
+ retry_ctx->peer_ctx->find_peer_handle =
+ GNUNET_DHT_find_peer_start (retry_ctx->peer_ctx->dht_handle,
+ retry_ctx->next_timeout, &hash,
+ GNUNET_DHT_RO_NONE,
+ &test_find_peer_processor, retry_ctx);
+ }
else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "test_find_peer timed out for good, failing!\n");
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "test_find_peer timed out for good, failing!\n");
- retry_ctx->peer_ctx->find_peer_handle = NULL;
- }
+ retry_ctx->peer_ctx->find_peer_handle = NULL;
+ }
if (retry_ctx->peer_ctx->find_peer_handle == NULL)
- {
- GNUNET_break (0);
- GNUNET_SCHEDULER_cancel (die_task);
- GNUNET_SCHEDULER_add_now (&end_badly, &p1);
- return;
- }
- retry_ctx->retry_task =
GNUNET_SCHEDULER_add_delayed(retry_ctx->next_timeout, &retry_find_peer_stop,
retry_ctx);
+ {
+ GNUNET_break (0);
+ GNUNET_SCHEDULER_cancel (die_task);
+ GNUNET_SCHEDULER_add_now (&end_badly, &p1);
+ return;
+ }
+ retry_ctx->retry_task =
+ GNUNET_SCHEDULER_add_delayed (retry_ctx->next_timeout,
+ &retry_find_peer_stop, retry_ctx);
}
/**
@@ -290,13 +298,14 @@
{
struct RetryContext *retry_ctx = cls;
GNUNET_HashCode hash;
+
memset (&hash, 42, sizeof (GNUNET_HashCode));
if (retry_ctx->peer_ctx->find_peer_handle != NULL)
- {
- GNUNET_DHT_find_peer_stop(retry_ctx->peer_ctx->find_peer_handle);
- retry_ctx->peer_ctx->find_peer_handle = NULL;
- }
+ {
+ GNUNET_DHT_find_peer_stop (retry_ctx->peer_ctx->find_peer_handle);
+ retry_ctx->peer_ctx->find_peer_handle = NULL;
+ }
GNUNET_SCHEDULER_add_now (&retry_find_peer, retry_ctx);
}
@@ -311,29 +320,32 @@
{
struct PeerContext *peer = cls;
GNUNET_HashCode hash;
+
memset (&hash, 42, sizeof (GNUNET_HashCode));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_find_peer!\n");
GNUNET_assert (peer->dht_handle != NULL);
- retry_context.real_timeout = GNUNET_TIME_relative_to_absolute(TOTAL_TIMEOUT);
+ retry_context.real_timeout = GNUNET_TIME_relative_to_absolute
(TOTAL_TIMEOUT);
retry_context.next_timeout = BASE_TIMEOUT;
retry_context.peer_ctx = peer;
peer->find_peer_handle
- = GNUNET_DHT_find_peer_start (peer->dht_handle,
retry_context.next_timeout,
- &hash,
- GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
- &test_find_peer_processor, &retry_context);
+ =
+ GNUNET_DHT_find_peer_start (peer->dht_handle, retry_context.next_timeout,
+ &hash, GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
+ &test_find_peer_processor, &retry_context);
if (peer->find_peer_handle == NULL)
- {
- GNUNET_break (0);
- GNUNET_SCHEDULER_cancel (die_task);
- GNUNET_SCHEDULER_add_now (&end_badly, &p1);
- return;
- }
- retry_context.retry_task =
GNUNET_SCHEDULER_add_delayed(retry_context.next_timeout, &retry_find_peer_stop,
&retry_context);
+ {
+ GNUNET_break (0);
+ GNUNET_SCHEDULER_cancel (die_task);
+ GNUNET_SCHEDULER_add_now (&end_badly, &p1);
+ return;
+ }
+ retry_context.retry_task =
+ GNUNET_SCHEDULER_add_delayed (retry_context.next_timeout,
+ &retry_find_peer_stop, &retry_context);
}
/**
@@ -348,28 +360,26 @@
struct PeerContext *peer = cls;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_get_stop!\n");
- if ( (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT) != 0)
- {
- GNUNET_break (0);
- GNUNET_SCHEDULER_cancel (die_task);
- GNUNET_SCHEDULER_add_now (&end_badly, NULL);
- return;
- }
+ if ((tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT) != 0)
+ {
+ GNUNET_break (0);
+ GNUNET_SCHEDULER_cancel (die_task);
+ GNUNET_SCHEDULER_add_now (&end_badly, NULL);
+ return;
+ }
GNUNET_assert (peer->dht_handle != NULL);
GNUNET_DHT_get_stop (peer->get_handle);
peer->get_handle = NULL;
- GNUNET_SCHEDULER_add_now(&test_find_peer,
- &p1);
+ GNUNET_SCHEDULER_add_now (&test_find_peer, &p1);
}
void
test_get_iterator (void *cls,
struct GNUNET_TIME_Absolute exp,
const GNUNET_HashCode * key,
- const struct GNUNET_PeerIdentity * const *get_path,
- const struct GNUNET_PeerIdentity * const *put_path,
- enum GNUNET_BLOCK_Type type,
- size_t size, const void *data)
+ const struct GNUNET_PeerIdentity *const *get_path,
+ const struct GNUNET_PeerIdentity *const *put_path,
+ 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");
@@ -389,32 +399,31 @@
{
struct PeerContext *peer = cls;
GNUNET_HashCode hash;
+
memset (&hash, 42, sizeof (GNUNET_HashCode));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_get!\n");
GNUNET_assert (peer->dht_handle != NULL);
- retry_context.real_timeout = GNUNET_TIME_relative_to_absolute(TOTAL_TIMEOUT);
+ retry_context.real_timeout = GNUNET_TIME_relative_to_absolute
(TOTAL_TIMEOUT);
retry_context.next_timeout = BASE_TIMEOUT;
peer->get_handle =
- GNUNET_DHT_get_start (peer->dht_handle,
- TOTAL_TIMEOUT,
- GNUNET_BLOCK_TYPE_TEST,
- &hash,
- DEFAULT_GET_REPLICATION,
- GNUNET_DHT_RO_NONE,
- NULL, 0,
- NULL, 0,
- &test_get_iterator, NULL);
+ GNUNET_DHT_get_start (peer->dht_handle,
+ TOTAL_TIMEOUT,
+ GNUNET_BLOCK_TYPE_TEST,
+ &hash,
+ DEFAULT_GET_REPLICATION,
+ GNUNET_DHT_RO_NONE,
+ NULL, 0, NULL, 0, &test_get_iterator, NULL);
if (peer->get_handle == NULL)
- {
- GNUNET_break (0);
- GNUNET_SCHEDULER_cancel (die_task);
- GNUNET_SCHEDULER_add_now (&end_badly, &p1);
- return;
- }
+ {
+ GNUNET_break (0);
+ GNUNET_SCHEDULER_cancel (die_task);
+ GNUNET_SCHEDULER_add_now (&end_badly, &p1);
+ return;
+ }
retry_context.peer_ctx = peer;
}
@@ -432,6 +441,7 @@
GNUNET_HashCode hash;
char *data;
size_t data_size = 42;
+
memset (&hash, 42, sizeof (GNUNET_HashCode));
data = GNUNET_malloc (data_size);
memset (data, 43, data_size);
@@ -440,15 +450,14 @@
GNUNET_assert (peer->dht_handle != NULL);
- GNUNET_DHT_put (peer->dht_handle, &hash,
+ GNUNET_DHT_put (peer->dht_handle, &hash,
DEFAULT_PUT_REPLICATION,
- GNUNET_DHT_RO_NONE,
- GNUNET_BLOCK_TYPE_TEST,
- data_size, data,
+ 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);
+ TOTAL_TIMEOUT, &test_get, &p1);
+ GNUNET_free (data);
}
static void
@@ -457,11 +466,11 @@
p->cfg = GNUNET_CONFIGURATION_create ();
#if START_ARM
p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
- "gnunet-service-arm",
+ "gnunet-service-arm",
#if VERBOSE_ARM
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", cfgname, NULL);
+ "-c", cfgname, NULL);
#endif
GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
@@ -482,8 +491,7 @@
setup_peer (&p1, "test_dht_api_peer1.conf");
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS, 1), &test_put,
- &p1);
+ (GNUNET_TIME_UNIT_SECONDS, 1), &test_put, &p1);
}
static int
Modified: gnunet/src/dht/test_dht_multipeer.c
===================================================================
--- gnunet/src/dht/test_dht_multipeer.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/dht/test_dht_multipeer.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -217,11 +217,12 @@
static enum GNUNET_TESTING_Topology topology;
-static enum GNUNET_TESTING_Topology blacklist_topology =
GNUNET_TESTING_TOPOLOGY_NONE; /* Don't do any blacklisting */
+static enum GNUNET_TESTING_Topology blacklist_topology =
GNUNET_TESTING_TOPOLOGY_NONE; /* Don't do any blacklisting */
static enum GNUNET_TESTING_Topology connection_topology =
GNUNET_TESTING_TOPOLOGY_NONE; /* NONE actually means connect all allowed peers
*/
-static enum GNUNET_TESTING_TopologyOption connect_topology_option =
GNUNET_TESTING_TOPOLOGY_OPTION_ALL;
+static enum GNUNET_TESTING_TopologyOption connect_topology_option =
+ GNUNET_TESTING_TOPOLOGY_OPTION_ALL;
static double connect_topology_option_modifier = 0.0;
@@ -231,25 +232,26 @@
/**
* Check whether peers successfully shut down.
*/
-void shutdown_callback (void *cls,
- const char *emsg)
+void
+shutdown_callback (void *cls, const char *emsg)
{
if (emsg != NULL)
- {
- if (ok == 0)
- ok = 2;
- }
+ {
+ if (ok == 0)
+ ok = 2;
+ }
}
/**
* Task to release DHT handles for PUT
*/
static void
-put_disconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
+put_disconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct TestPutContext *test_put = cls;
+
test_put->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
- GNUNET_DHT_disconnect(test_put->dht_handle);
+ GNUNET_DHT_disconnect (test_put->dht_handle);
test_put->dht_handle = NULL;
}
@@ -258,31 +260,31 @@
* testcase.
*/
static void
-finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
+finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GNUNET_assert (pg != NULL);
struct TestPutContext *test_put = all_puts;
struct TestGetContext *test_get = all_gets;
while (test_put != NULL)
- {
- if (test_put->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel(test_put->disconnect_task);
- if (test_put->dht_handle != NULL)
- GNUNET_DHT_disconnect(test_put->dht_handle);
- test_put = test_put->next;
- }
+ {
+ if (test_put->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
+ GNUNET_SCHEDULER_cancel (test_put->disconnect_task);
+ if (test_put->dht_handle != NULL)
+ GNUNET_DHT_disconnect (test_put->dht_handle);
+ test_put = test_put->next;
+ }
while (test_get != NULL)
- {
- if (test_get->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel(test_get->disconnect_task);
- if (test_get->get_handle != NULL)
- GNUNET_DHT_get_stop(test_get->get_handle);
- if (test_get->dht_handle != NULL)
- GNUNET_DHT_disconnect(test_get->dht_handle);
- test_get = test_get->next;
- }
+ {
+ if (test_get->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
+ GNUNET_SCHEDULER_cancel (test_get->disconnect_task);
+ if (test_get->get_handle != NULL)
+ GNUNET_DHT_get_stop (test_get->get_handle);
+ if (test_get->dht_handle != NULL)
+ GNUNET_DHT_disconnect (test_get->dht_handle);
+ test_get = test_get->next;
+ }
GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
ok = 0;
@@ -295,32 +297,33 @@
* test.
*/
static void
-end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
+end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failing test with error: `%s'!\n",
(char *)cls);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failing test with error: `%s'!\n",
+ (char *) cls);
struct TestPutContext *test_put = all_puts;
struct TestGetContext *test_get = all_gets;
while (test_put != NULL)
- {
- if (test_put->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel(test_put->disconnect_task);
- if (test_put->dht_handle != NULL)
- GNUNET_DHT_disconnect(test_put->dht_handle);
- test_put = test_put->next;
- }
+ {
+ if (test_put->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
+ GNUNET_SCHEDULER_cancel (test_put->disconnect_task);
+ if (test_put->dht_handle != NULL)
+ GNUNET_DHT_disconnect (test_put->dht_handle);
+ test_put = test_put->next;
+ }
while (test_get != NULL)
- {
- if (test_get->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel(test_get->disconnect_task);
- if (test_get->get_handle != NULL)
- GNUNET_DHT_get_stop(test_get->get_handle);
- if (test_get->dht_handle != NULL)
- GNUNET_DHT_disconnect(test_get->dht_handle);
- test_get = test_get->next;
- }
+ {
+ if (test_get->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
+ GNUNET_SCHEDULER_cancel (test_get->disconnect_task);
+ if (test_get->get_handle != NULL)
+ GNUNET_DHT_get_stop (test_get->get_handle);
+ if (test_get->dht_handle != NULL)
+ GNUNET_DHT_disconnect (test_get->dht_handle);
+ test_get = test_get->next;
+ }
GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
ok = 1;
@@ -330,47 +333,51 @@
* Task to release DHT handle associated with GET request.
*/
static void
-get_stop_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
+get_stop_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct TestGetContext *test_get = cls;
- outstanding_gets--; /* GET is really finished */
- GNUNET_DHT_disconnect(test_get->dht_handle);
+
+ outstanding_gets--; /* GET is really finished */
+ GNUNET_DHT_disconnect (test_get->dht_handle);
test_get->dht_handle = NULL;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%d gets succeeded, %d gets failed!\n",
gets_completed, gets_failed);
- if ((gets_completed == num_gets) && (outstanding_gets == 0))/* All gets
successful */
- {
- GNUNET_SCHEDULER_cancel (die_task);
- //GNUNET_SCHEDULER_add_delayed
(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5), &get_topology,
NULL);
- GNUNET_SCHEDULER_add_now(&finish_testing, NULL);
- }
- else if ((gets_completed + gets_failed == num_gets) && (outstanding_gets ==
0)) /* Had some failures */
- {
- GNUNET_SCHEDULER_cancel(die_task);
- GNUNET_SCHEDULER_add_now(&end_badly, "not all gets succeeded!\n");
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%d gets succeeded, %d gets failed!\n",
+ gets_completed, gets_failed);
+ if ((gets_completed == num_gets) && (outstanding_gets == 0)) /* All gets
successful */
+ {
+ GNUNET_SCHEDULER_cancel (die_task);
+ //GNUNET_SCHEDULER_add_delayed
(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5), &get_topology,
NULL);
+ GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
+ }
+ else if ((gets_completed + gets_failed == num_gets) && (outstanding_gets ==
0)) /* Had some failures */
+ {
+ GNUNET_SCHEDULER_cancel (die_task);
+ GNUNET_SCHEDULER_add_now (&end_badly, "not all gets succeeded!\n");
+ }
}
/**
* Task to release get handle.
*/
static void
-get_stop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
+get_stop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct TestGetContext *test_get = cls;
- GNUNET_HashCode search_key; /* Key stored under */
- char original_data[TEST_DATA_SIZE]; /* Made up data to store */
+ GNUNET_HashCode search_key; /* Key stored under */
+ char original_data[TEST_DATA_SIZE]; /* Made up data to store */
- memset(original_data, test_get->uid, sizeof(original_data));
- GNUNET_CRYPTO_hash(original_data, TEST_DATA_SIZE, &search_key);
+ memset (original_data, test_get->uid, sizeof (original_data));
+ GNUNET_CRYPTO_hash (original_data, TEST_DATA_SIZE, &search_key);
- if ( (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT) != 0)
- {
- gets_failed++;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Get from peer %s for key %s
failed!\n", test_get->daemon->shortname, GNUNET_h2s(&search_key));
- }
- GNUNET_assert(test_get->get_handle != NULL);
- GNUNET_DHT_get_stop(test_get->get_handle);
+ if ((tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT) != 0)
+ {
+ gets_failed++;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Get from peer %s for key %s failed!\n",
+ test_get->daemon->shortname, GNUNET_h2s (&search_key));
+ }
+ GNUNET_assert (test_get->get_handle != NULL);
+ GNUNET_DHT_get_stop (test_get->get_handle);
GNUNET_SCHEDULER_add_now (&get_stop_finished, test_get);
test_get->get_handle = NULL;
test_get->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
@@ -386,55 +393,58 @@
* @param size number of bytes in data
* @param data pointer to the result data
*/
-void get_result_iterator (void *cls,
- struct GNUNET_TIME_Absolute exp,
- const GNUNET_HashCode * key,
- const struct GNUNET_PeerIdentity * const *get_path,
- const struct GNUNET_PeerIdentity * const *put_path,
- enum GNUNET_BLOCK_Type type,
- size_t size,
- const void *data)
+void
+get_result_iterator (void *cls,
+ struct GNUNET_TIME_Absolute exp,
+ const GNUNET_HashCode * key,
+ const struct GNUNET_PeerIdentity *const *get_path,
+ const struct GNUNET_PeerIdentity *const *put_path,
+ enum GNUNET_BLOCK_Type type, size_t size, const void
*data)
{
struct TestGetContext *test_get = cls;
- GNUNET_HashCode search_key; /* Key stored under */
- char original_data[TEST_DATA_SIZE]; /* Made up data to store */
+ GNUNET_HashCode search_key; /* Key stored under */
+ char original_data[TEST_DATA_SIZE]; /* Made up data to store */
unsigned int i;
- memset(original_data, test_get->uid, sizeof(original_data));
- GNUNET_CRYPTO_hash(original_data, TEST_DATA_SIZE, &search_key);
+ memset (original_data, test_get->uid, sizeof (original_data));
+ GNUNET_CRYPTO_hash (original_data, TEST_DATA_SIZE, &search_key);
+
if (test_get->succeeded == GNUNET_YES)
- return; /* Get has already been successful, probably ending now */
+ return; /* Get has already been successful, probably
ending now */
#if PATH_TRACKING
if (put_path != NULL)
- {
- fprintf(stderr, "PUT Path: ");
- for (i = 0; put_path[i] != NULL; i++)
- fprintf(stderr, "%s%s", i == 0 ? "" : "->", GNUNET_i2s(put_path[i]));
- fprintf(stderr, "\n");
- }
+ {
+ fprintf (stderr, "PUT Path: ");
+ for (i = 0; put_path[i] != NULL; i++)
+ fprintf (stderr, "%s%s", i == 0 ? "" : "->", GNUNET_i2s (put_path[i]));
+ fprintf (stderr, "\n");
+ }
if (get_path != NULL)
- {
- fprintf(stderr, "GET Path: ");
- for (i = 0; get_path[i] != NULL; i++)
- fprintf(stderr, "%s%s", i == 0 ? "" : "->", GNUNET_i2s(get_path[i]));
- fprintf(stderr, "\n");
- }
+ {
+ fprintf (stderr, "GET Path: ");
+ for (i = 0; get_path[i] != NULL; i++)
+ fprintf (stderr, "%s%s", i == 0 ? "" : "->", GNUNET_i2s (get_path[i]));
+ fprintf (stderr, "\n");
+ }
#endif
- if ((0 != memcmp(&search_key, key, sizeof (GNUNET_HashCode))) || (0 !=
memcmp(original_data, data, sizeof(original_data))))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Key or data is not the same as was
inserted!\n");
- }
+ if ((0 != memcmp (&search_key, key, sizeof (GNUNET_HashCode))) ||
+ (0 != memcmp (original_data, data, sizeof (original_data))))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Key or data is not the same as was inserted!\n");
+ }
else
- {
- gets_completed++;
- test_get->succeeded = GNUNET_YES;
- }
+ {
+ gets_completed++;
+ test_get->succeeded = GNUNET_YES;
+ }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct GET response!\n");
- GNUNET_SCHEDULER_cancel(test_get->disconnect_task);
- GNUNET_SCHEDULER_add_continuation(&get_stop_task, test_get,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ GNUNET_SCHEDULER_cancel (test_get->disconnect_task);
+ GNUNET_SCHEDULER_add_continuation (&get_stop_task, test_get,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
}
@@ -442,43 +452,42 @@
* Set up some data, and call API PUT function
*/
static void
-do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
+do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct TestGetContext *test_get = cls;
- GNUNET_HashCode key; /* Made up key to store data under */
- char data[TEST_DATA_SIZE]; /* Made up data to store */
+ GNUNET_HashCode key; /* Made up key to store data under */
+ char data[TEST_DATA_SIZE]; /* Made up data to store */
if (test_get == NULL)
- return; /* End of the list */
- memset(data, test_get->uid, sizeof(data));
- GNUNET_CRYPTO_hash(data, TEST_DATA_SIZE, &key);
+ return; /* End of the list */
+ memset (data, test_get->uid, sizeof (data));
+ GNUNET_CRYPTO_hash (data, TEST_DATA_SIZE, &key);
if (outstanding_gets > MAX_OUTSTANDING_GETS)
- {
- GNUNET_SCHEDULER_add_delayed (GET_DELAY, &do_get, test_get);
- return;
- }
+ {
+ GNUNET_SCHEDULER_add_delayed (GET_DELAY, &do_get, test_get);
+ return;
+ }
- test_get->dht_handle = GNUNET_DHT_connect(test_get->daemon->cfg, 10);
+ test_get->dht_handle = GNUNET_DHT_connect (test_get->daemon->cfg, 10);
/* Insert the data at the first peer */
- GNUNET_assert(test_get->dht_handle != NULL);
+ 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,
- DEFAULT_GET_REPLICATION,
- route_option,
- NULL, 0,
- NULL, 0,
- &get_result_iterator,
- test_get);
+ test_get->get_handle = GNUNET_DHT_get_start (test_get->dht_handle,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_BLOCK_TYPE_TEST,
+ &key,
+ DEFAULT_GET_REPLICATION,
+ route_option,
+ NULL, 0,
+ NULL, 0,
+ &get_result_iterator, test_get);
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting get for uid %u from peer
%s\n",
- test_get->uid,
- test_get->daemon->shortname);
+ test_get->uid, test_get->daemon->shortname);
#endif
- test_get->disconnect_task = GNUNET_SCHEDULER_add_delayed(GET_TIMEOUT,
&get_stop_task, test_get);
+ test_get->disconnect_task =
+ GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, &get_stop_task, test_get);
GNUNET_SCHEDULER_add_now (&do_get, test_get->next);
}
@@ -487,64 +496,68 @@
* Schedule the GET request for some time in the future.
*/
static void
-put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
+put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct TestPutContext *test_put = cls;
+
outstanding_puts--;
puts_completed++;
- GNUNET_SCHEDULER_cancel(test_put->disconnect_task);
- test_put->disconnect_task = GNUNET_SCHEDULER_add_now(&put_disconnect_task,
test_put);
+ GNUNET_SCHEDULER_cancel (test_put->disconnect_task);
+ test_put->disconnect_task =
+ GNUNET_SCHEDULER_add_now (&put_disconnect_task, test_put);
if (puts_completed == num_puts)
- {
- GNUNET_assert(outstanding_puts == 0);
-
GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
10), &do_get, all_gets);
- return;
- }
+ {
+ GNUNET_assert (outstanding_puts == 0);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 10), &do_get,
+ all_gets);
+ return;
+ }
}
/**
* Set up some data, and call API PUT function
*/
static void
-do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
+do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct TestPutContext *test_put = cls;
- GNUNET_HashCode key; /* Made up key to store data under */
- char data[TEST_DATA_SIZE]; /* Made up data to store */
+ GNUNET_HashCode key; /* Made up key to store data under */
+ char data[TEST_DATA_SIZE]; /* Made up data to store */
if (test_put == NULL)
- return; /* End of list */
+ return; /* End of list */
- memset(data, test_put->uid, sizeof(data));
- GNUNET_CRYPTO_hash(data, TEST_DATA_SIZE, &key);
+ memset (data, test_put->uid, sizeof (data));
+ GNUNET_CRYPTO_hash (data, TEST_DATA_SIZE, &key);
if (outstanding_puts > MAX_OUTSTANDING_PUTS)
- {
- GNUNET_SCHEDULER_add_delayed (PUT_DELAY, &do_put, test_put);
- return;
- }
+ {
+ GNUNET_SCHEDULER_add_delayed (PUT_DELAY, &do_put, test_put);
+ return;
+ }
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting put for uid %u from peer
%s\n",
- test_put->uid,
- test_put->daemon->shortname);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting put for uid %u from peer
%s\n",
+ test_put->uid, test_put->daemon->shortname);
#endif
- test_put->dht_handle = GNUNET_DHT_connect(test_put->daemon->cfg, 10);
+ test_put->dht_handle = GNUNET_DHT_connect (test_put->daemon->cfg, 10);
- GNUNET_assert(test_put->dht_handle != NULL);
+ GNUNET_assert (test_put->dht_handle != NULL);
outstanding_puts++;
- GNUNET_DHT_put(test_put->dht_handle,
- &key,
- DEFAULT_PUT_REPLICATION,
- 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->disconnect_task =
GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_get_forever(),
&put_disconnect_task, test_put);
- GNUNET_SCHEDULER_add_now(&do_put, test_put->next);
+ GNUNET_DHT_put (test_put->dht_handle,
+ &key,
+ DEFAULT_PUT_REPLICATION,
+ 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->disconnect_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_get_forever (),
+ &put_disconnect_task, test_put);
+ GNUNET_SCHEDULER_add_now (&do_put, test_put->next);
}
@@ -554,7 +567,7 @@
* then call actual insert functions.
*/
static void
-setup_puts_and_gets (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
+setup_puts_and_gets (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
int i;
uint32_t temp_daemon;
@@ -563,27 +576,31 @@
int remember[num_puts][num_peers];
for (i = 0; i < num_puts; i++)
- {
- test_put = GNUNET_malloc(sizeof(struct TestPutContext));
- test_put->uid = i;
- temp_daemon = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK,
num_peers);
- test_put->daemon = GNUNET_TESTING_daemon_get(pg, temp_daemon);
- test_put->next = all_puts;
- all_puts = test_put;
- }
+ {
+ test_put = GNUNET_malloc (sizeof (struct TestPutContext));
+ test_put->uid = i;
+ temp_daemon =
+ GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
+ test_put->daemon = GNUNET_TESTING_daemon_get (pg, temp_daemon);
+ test_put->next = all_puts;
+ all_puts = test_put;
+ }
for (i = 0; i < num_gets; i++)
- {
- test_get = GNUNET_malloc(sizeof(struct TestGetContext));
- test_get->uid = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK,
num_puts);
- temp_daemon = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK,
num_peers);
- while (remember[test_get->uid][temp_daemon] == 1)
- temp_daemon = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK,
num_peers);
- test_get->daemon = GNUNET_TESTING_daemon_get(pg, temp_daemon);
- remember[test_get->uid][temp_daemon] = 1;
- test_get->next = all_gets;
- all_gets = test_get;
- }
+ {
+ test_get = GNUNET_malloc (sizeof (struct TestGetContext));
+ test_get->uid =
+ GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, num_puts);
+ temp_daemon =
+ GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
+ while (remember[test_get->uid][temp_daemon] == 1)
+ temp_daemon =
+ GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
+ test_get->daemon = GNUNET_TESTING_daemon_get (pg, temp_daemon);
+ remember[test_get->uid][temp_daemon] = 1;
+ test_get->next = all_gets;
+ all_gets = test_get;
+ }
GNUNET_SCHEDULER_add_now (&do_put, all_puts);
}
@@ -610,57 +627,61 @@
const char *emsg)
{
if (emsg == NULL)
- {
- total_connections++;
+ {
+ total_connections++;
#if VERBOSE > 1
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s,
distance %u\n",
- first_daemon->shortname,
- second_daemon->shortname,
- distance);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "connected peer %s to peer %s, distance %u\n",
+ first_daemon->shortname, second_daemon->shortname, distance);
#endif
- }
+ }
#if VERBOSE
else
- {
- failed_connections++;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to connect peer %s to peer
%s with error :\n%s\n",
- first_daemon->shortname,
- second_daemon->shortname, emsg);
- }
+ {
+ failed_connections++;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to connect peer %s to peer %s with error :\n%s\n",
+ first_daemon->shortname, second_daemon->shortname, emsg);
+ }
#endif
if (total_connections == expected_connections)
- {
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Created %d total connections, which is our target number!
Starting next phase of testing.\n",
- total_connections);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Created %d total connections, which is our target number!
Starting next phase of testing.\n",
+ total_connections);
#endif
- GNUNET_SCHEDULER_cancel (die_task);
- die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &end_badly, "from setup
puts/gets");
+ GNUNET_SCHEDULER_cancel (die_task);
+ die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+ &end_badly,
+ "from setup puts/gets");
- GNUNET_SCHEDULER_add_delayed
(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2),
&setup_puts_and_gets, NULL);
- }
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 2),
+ &setup_puts_and_gets, NULL);
+ }
else if (total_connections + failed_connections == expected_connections)
- {
- GNUNET_SCHEDULER_cancel (die_task);
- die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from topology_callback
(too many failed connections)");
- }
+ {
+ GNUNET_SCHEDULER_cancel (die_task);
+ die_task =
+ GNUNET_SCHEDULER_add_now (&end_badly,
+ "from topology_callback (too many failed
connections)");
+ }
}
static void
peers_started_callback (void *cls,
- const struct GNUNET_PeerIdentity *id,
- const struct GNUNET_CONFIGURATION_Handle *cfg,
- struct GNUNET_TESTING_Daemon *d, const char *emsg)
+ const struct GNUNET_PeerIdentity *id,
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ struct GNUNET_TESTING_Daemon *d, const char *emsg)
{
if (emsg != NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to start daemon with error:
`%s'\n",
- emsg);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to start daemon with error: `%s'\n", emsg);
+ return;
+ }
GNUNET_assert (id != NULL);
#if VERBOSE
@@ -670,63 +691,69 @@
peers_left--;
if (peers_left == 0)
- {
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "All %d daemons started, now connecting peers!\n",
- num_peers);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "All %d daemons started, now connecting peers!\n", num_peers);
#endif
- GNUNET_SCHEDULER_cancel (die_task);
+ GNUNET_SCHEDULER_cancel (die_task);
- expected_connections = -1;
- if ((pg != NULL) && (peers_left == 0))
- {
- expected_connections = GNUNET_TESTING_connect_topology (pg,
-
connection_topology,
-
connect_topology_option,
-
connect_topology_option_modifier,
- TIMEOUT,
- num_peers,
- NULL, NULL);
+ expected_connections = -1;
+ if ((pg != NULL) && (peers_left == 0))
+ {
+ expected_connections = GNUNET_TESTING_connect_topology (pg,
+
connection_topology,
+
connect_topology_option,
+
connect_topology_option_modifier,
+ TIMEOUT,
+ num_peers,
+ NULL, NULL);
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Have %d expected connections\n", expected_connections);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Have %d expected connections\n", expected_connections);
#endif
- }
+ }
- if (expected_connections == GNUNET_SYSERR)
- {
- die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from connect
topology (bad return)");
- }
+ if (expected_connections == GNUNET_SYSERR)
+ {
+ die_task =
+ GNUNET_SCHEDULER_add_now (&end_badly,
+ "from connect topology (bad return)");
+ }
- die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &end_badly, "from connect
topology (timeout)");
+ die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+ &end_badly,
+ "from connect topology
(timeout)");
- ok = 0;
- }
+ ok = 0;
+ }
}
static void
create_topology ()
{
- peers_left = num_peers; /* Reset counter */
- if (GNUNET_TESTING_create_topology (pg, topology, blacklist_topology,
blacklist_transports) != GNUNET_SYSERR)
- {
+ peers_left = num_peers; /* Reset counter */
+ if (GNUNET_TESTING_create_topology
+ (pg, topology, blacklist_topology, blacklist_transports) !=
GNUNET_SYSERR)
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Topology set up, now starting peers!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Topology set up, now starting peers!\n");
#endif
- GNUNET_TESTING_daemons_continue_startup(pg);
- }
+ GNUNET_TESTING_daemons_continue_startup (pg);
+ }
else
- {
- GNUNET_SCHEDULER_cancel (die_task);
- die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from create topology
(bad return)");
- }
+ {
+ GNUNET_SCHEDULER_cancel (die_task);
+ die_task =
+ GNUNET_SCHEDULER_add_now (&end_badly,
+ "from create topology (bad return)");
+ }
GNUNET_SCHEDULER_cancel (die_task);
die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &end_badly, "from continue startup
(timeout)");
+ &end_badly,
+ "from continue startup (timeout)");
}
/**
@@ -737,39 +764,40 @@
* @param d the daemon handle (pretty useless at this point, remove?)
* @param emsg non-null on failure
*/
-void hostkey_callback (void *cls,
- const struct GNUNET_PeerIdentity *id,
- struct GNUNET_TESTING_Daemon *d,
- const char *emsg)
+void
+hostkey_callback (void *cls,
+ const struct GNUNET_PeerIdentity *id,
+ struct GNUNET_TESTING_Daemon *d, const char *emsg)
{
if (emsg != NULL)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Hostkey callback received error:
%s\n", emsg);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Hostkey callback received error: %s\n", emsg);
+ }
#if VERBOSE > 1
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Hostkey (%d/%d) created for peer `%s'\n",
- num_peers - peers_left, num_peers, GNUNET_i2s(id));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Hostkey (%d/%d) created for peer `%s'\n",
+ num_peers - peers_left, num_peers, GNUNET_i2s (id));
#endif
- peers_left--;
- if (peers_left == 0)
- {
+ peers_left--;
+ if (peers_left == 0)
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "All %d hostkeys created, now creating topology!\n",
- num_peers);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "All %d hostkeys created, now creating topology!\n",
num_peers);
#endif
- GNUNET_SCHEDULER_cancel (die_task);
- /* Set up task in case topology creation doesn't finish
- * within a reasonable amount of time */
- die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &end_badly, "from
create_topology");
- GNUNET_SCHEDULER_add_now(&create_topology, NULL);
- ok = 0;
- }
+ GNUNET_SCHEDULER_cancel (die_task);
+ /* Set up task in case topology creation doesn't finish
+ * within a reasonable amount of time */
+ die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+ &end_badly,
+ "from create_topology");
+ GNUNET_SCHEDULER_add_now (&create_topology, NULL);
+ ok = 0;
+ }
}
@@ -778,11 +806,11 @@
char *const *args,
const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
- char * topology_str;
- char * connect_topology_str;
- char * blacklist_topology_str;
- char * connect_topology_option_str;
- char * connect_topology_option_modifier_string;
+ char *topology_str;
+ char *connect_topology_str;
+ char *blacklist_topology_str;
+ char *connect_topology_option_str;
+ char *connect_topology_option_modifier_string;
#if PATH_TRACKING
route_option = GNUNET_DHT_RO_RECORD_ROUTE;
@@ -791,66 +819,91 @@
#endif
/* Get path from configuration file */
- if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string(cfg, "paths",
"servicehome", &test_directory))
- {
- ok = 404;
- return;
- }
+ if (GNUNET_YES !=
+ GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome",
+ &test_directory))
+ {
+ ok = 404;
+ return;
+ }
if ((GNUNET_YES ==
- GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "topology",
- &topology_str)) && (GNUNET_NO ==
GNUNET_TESTING_topology_get(&topology, topology_str)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Invalid topology `%s' given for section %s option %s\n",
topology_str, "TESTING", "TOPOLOGY");
- topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set
better default here */
- }
+ GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "topology",
+ &topology_str)) &&
+ (GNUNET_NO == GNUNET_TESTING_topology_get (&topology, topology_str)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Invalid topology `%s' given for section %s option %s\n",
+ topology_str, "TESTING", "TOPOLOGY");
+ topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set
better default here */
+ }
if ((GNUNET_YES ==
- GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "connect_topology",
- &connect_topology_str)) &&
(GNUNET_NO == GNUNET_TESTING_topology_get(&connection_topology,
connect_topology_str)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Invalid connect topology `%s' given for section %s option
%s\n", connect_topology_str, "TESTING", "CONNECT_TOPOLOGY");
- }
- GNUNET_free_non_null(connect_topology_str);
+ GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
+ "connect_topology",
+ &connect_topology_str)) &&
+ (GNUNET_NO ==
+ GNUNET_TESTING_topology_get (&connection_topology,
+ connect_topology_str)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Invalid connect topology `%s' given for section %s option
%s\n",
+ connect_topology_str, "TESTING", "CONNECT_TOPOLOGY");
+ }
+ GNUNET_free_non_null (connect_topology_str);
if ((GNUNET_YES ==
- GNUNET_CONFIGURATION_get_value_string(cfg, "testing",
"connect_topology_option",
- &connect_topology_option_str)) &&
(GNUNET_NO == GNUNET_TESTING_topology_option_get(&connect_topology_option,
connect_topology_option_str)))
+ GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
+ "connect_topology_option",
+ &connect_topology_option_str)) &&
+ (GNUNET_NO ==
+ GNUNET_TESTING_topology_option_get (&connect_topology_option,
+ connect_topology_option_str)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Invalid connect topology option `%s' given for section %s
option %s\n",
+ connect_topology_option_str, "TESTING",
+ "CONNECT_TOPOLOGY_OPTION");
+ connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /*
Defaults to NONE, set to ALL */
+ }
+ GNUNET_free_non_null (connect_topology_option_str);
+ if (GNUNET_YES ==
+ GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
+
"connect_topology_option_modifier",
+
&connect_topology_option_modifier_string))
+ {
+ if (sscanf
+ (connect_topology_option_modifier_string, "%lf",
+ &connect_topology_option_modifier) != 1)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Invalid connect topology option `%s' given for section %s
option %s\n", connect_topology_option_str, "TESTING",
"CONNECT_TOPOLOGY_OPTION");
- connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /*
Defaults to NONE, set to ALL */
+ _
+ ("Invalid value `%s' for option `%s' in section `%s':
expected float\n"),
+ connect_topology_option_modifier_string,
+ "connect_topology_option_modifier", "TESTING");
}
- GNUNET_free_non_null(connect_topology_option_str);
- if (GNUNET_YES ==
- GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
"connect_topology_option_modifier",
-
&connect_topology_option_modifier_string))
- {
- if (sscanf(connect_topology_option_modifier_string, "%lf",
&connect_topology_option_modifier) != 1)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Invalid value `%s' for option `%s' in section `%s': expected
float\n"),
- connect_topology_option_modifier_string,
- "connect_topology_option_modifier",
- "TESTING");
- }
- GNUNET_free (connect_topology_option_modifier_string);
- }
+ GNUNET_free (connect_topology_option_modifier_string);
+ }
- if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
"blacklist_transports",
- &blacklist_transports))
+ if (GNUNET_YES !=
+ GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
+ "blacklist_transports",
+ &blacklist_transports))
blacklist_transports = NULL;
if ((GNUNET_YES ==
- GNUNET_CONFIGURATION_get_value_string(cfg, "testing",
"blacklist_topology",
- &blacklist_topology_str)) &&
(GNUNET_NO == GNUNET_TESTING_topology_get(&blacklist_topology,
blacklist_topology_str)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Invalid topology `%s' given for section %s option %s\n",
topology_str, "TESTING", "BLACKLIST_TOPOLOGY");
- }
- GNUNET_free_non_null(topology_str);
- GNUNET_free_non_null(blacklist_topology_str);
+ GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
+ "blacklist_topology",
+ &blacklist_topology_str)) &&
+ (GNUNET_NO ==
+ GNUNET_TESTING_topology_get (&blacklist_topology,
+ blacklist_topology_str)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Invalid topology `%s' given for section %s option %s\n",
+ topology_str, "TESTING", "BLACKLIST_TOPOLOGY");
+ }
+ GNUNET_free_non_null (topology_str);
+ GNUNET_free_non_null (blacklist_topology_str);
/* Get number of peers to start from configuration */
if (GNUNET_SYSERR ==
@@ -872,21 +925,22 @@
peers_left = num_peers;
/* Set up a task to end testing if peer start fails */
- die_task = GNUNET_SCHEDULER_add_delayed
(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, SECONDS_PER_PEER_START
* num_peers),
- &end_badly, "didn't generate all
hostkeys within a reasonable amount of time!!!");
+ die_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS,
+ SECONDS_PER_PEER_START * num_peers),
+ &end_badly,
+ "didn't generate all hostkeys within a
reasonable amount of time!!!");
- pg = GNUNET_TESTING_daemons_start (cfg,
- peers_left, /* Total number of peers */
- peers_left, /* Number of outstanding
connections */
- peers_left, /* Number of parallel ssh
connections, or peers being started at once */
-
GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, SECONDS_PER_PEER_START
* num_peers),
- &hostkey_callback,
- NULL,
- &peers_started_callback,
- NULL,
- &topology_callback,
- NULL,
- NULL);
+ pg = GNUNET_TESTING_daemons_start (cfg, peers_left, /* Total number of
peers */
+ peers_left, /* Number of
outstanding connections */
+ peers_left, /* Number of parallel
ssh connections, or peers being started at once */
+ GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS,
+ SECONDS_PER_PEER_START * num_peers),
+ &hostkey_callback, NULL,
+ &peers_started_callback, NULL,
+ &topology_callback, NULL, NULL);
}
@@ -894,10 +948,11 @@
check ()
{
int ret;
+
/* Arguments for GNUNET_PROGRAM_run */
- char *const argv[] = {"test-dht-multipeer", /* Name to give running binary */
+ char *const argv[] = { "test-dht-multipeer", /* Name to give running binary
*/
"-c",
- "test_dht_multipeer_data.conf", /* Config file to use */
+ "test_dht_multipeer_data.conf", /* Config file to use */
#if VERBOSE
"-L", "DEBUG",
#endif
@@ -908,12 +963,13 @@
};
/* Run the run function as a new program */
ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
- argv, "test-dht-multipeer", "nohelp",
- options, &run, &ok);
+ argv, "test-dht-multipeer", "nohelp",
+ options, &run, &ok);
if (ret != GNUNET_OK)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "`test-dht-multipeer': Failed with
error code %d\n", ret);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "`test-dht-multipeer': Failed with error code %d\n", ret);
+ }
return ok;
}
@@ -935,9 +991,10 @@
* of by the testing framework.
*/
if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to remove testing
directory %s\n", test_directory);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to remove testing directory %s\n", test_directory);
+ }
return ret;
}
Modified: gnunet/src/dht/test_dht_twopeer.c
===================================================================
--- gnunet/src/dht/test_dht_twopeer.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/dht/test_dht_twopeer.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -87,53 +87,53 @@
/**
* Check whether peers successfully shut down.
*/
-void shutdown_callback (void *cls,
- const char *emsg)
+void
+shutdown_callback (void *cls, const char *emsg)
{
if (emsg != NULL)
- {
- if (ok == 0)
- ok = 2;
- }
+ {
+ if (ok == 0)
+ ok = 2;
+ }
}
static void
-finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
+finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GNUNET_assert (pg != NULL);
GNUNET_assert (peer1dht != NULL);
GNUNET_assert (peer2dht != NULL);
- GNUNET_DHT_disconnect(peer1dht);
- GNUNET_DHT_disconnect(peer2dht);
+ GNUNET_DHT_disconnect (peer1dht);
+ GNUNET_DHT_disconnect (peer2dht);
GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
ok = 0;
}
static void
-end_badly_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
+end_badly_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
if (peer1dht != NULL)
- GNUNET_DHT_disconnect(peer1dht);
+ GNUNET_DHT_disconnect (peer1dht);
if (peer2dht != NULL)
- GNUNET_DHT_disconnect(peer2dht);
+ GNUNET_DHT_disconnect (peer2dht);
if (pg != NULL)
GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
if (curr_get_ctx.retry_task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel(curr_get_ctx.retry_task);
+ GNUNET_SCHEDULER_cancel (curr_get_ctx.retry_task);
}
static void
-end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
+end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
if (curr_get_ctx.retry_task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel(curr_get_ctx.retry_task);
+ GNUNET_SCHEDULER_cancel (curr_get_ctx.retry_task);
if (curr_get_ctx.get_handle != NULL)
{
- GNUNET_DHT_get_stop(curr_get_ctx.get_handle);
+ GNUNET_DHT_get_stop (curr_get_ctx.get_handle);
}
GNUNET_SCHEDULER_add_now (&end_badly_cont, NULL);
@@ -141,8 +141,7 @@
}
/* Forward declaration */
-static void
-do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc);
+static void do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
/**
* Iterator called on each result obtained for a DHT
@@ -155,108 +154,122 @@
* @param size number of bytes in data
* @param data pointer to the result data
*/
-void get_result_iterator (void *cls,
- struct GNUNET_TIME_Absolute exp,
- const GNUNET_HashCode * key,
- const struct GNUNET_PeerIdentity * const *get_path,
- const struct GNUNET_PeerIdentity * const *put_path,
- enum GNUNET_BLOCK_Type type,
- size_t size,
- const void *data)
+void
+get_result_iterator (void *cls,
+ struct GNUNET_TIME_Absolute exp,
+ const GNUNET_HashCode * key,
+ const struct GNUNET_PeerIdentity *const *get_path,
+ const struct GNUNET_PeerIdentity *const *put_path,
+ enum GNUNET_BLOCK_Type type, size_t size, const void
*data)
{
struct PeerGetContext *get_context = cls;
- if (0 != memcmp(&get_context->peer->hashPubKey, key, sizeof
(GNUNET_HashCode)))
+ if (0 !=
+ memcmp (&get_context->peer->hashPubKey, key, sizeof (GNUNET_HashCode)))
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Key returned is not the same key
as was searched for!\n");
- GNUNET_SCHEDULER_cancel(die_task);
- GNUNET_SCHEDULER_add_now(&end_badly, "key mismatch in get response!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Key returned is not the same key as was searched for!\n");
+ GNUNET_SCHEDULER_cancel (die_task);
+ GNUNET_SCHEDULER_add_now (&end_badly, "key mismatch in get response!\n");
return;
}
if (get_context->retry_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel(get_context->retry_task);
- get_context->retry_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (get_context->retry_task);
+ get_context->retry_task = GNUNET_SCHEDULER_NO_TASK;
+ }
if (get_context->peer == &peer2id)
{
get_context->peer = &peer1id;
get_context->dht_handle = peer2dht;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received first correct GET request
response!\n");
- GNUNET_DHT_get_stop(get_context->get_handle);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received first correct GET request response!\n");
+ GNUNET_DHT_get_stop (get_context->get_handle);
GNUNET_SCHEDULER_add_now (&do_get, get_context);
}
else
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received second correct GET request
response!\n");
- GNUNET_SCHEDULER_cancel(die_task);
- GNUNET_DHT_get_stop(get_context->get_handle);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received second correct GET request response!\n");
+ GNUNET_SCHEDULER_cancel (die_task);
+ GNUNET_DHT_get_stop (get_context->get_handle);
GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
}
}
static void
-stop_retry_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc);
+stop_retry_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
static void
-get_stop_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
+get_stop_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct PeerGetContext *get_context = cls;
if (get_context->get_attempts < MAX_GET_ATTEMPTS)
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Get attempt %u failed, retrying
request!\n", get_context->get_attempts);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Get attempt %u failed, retrying request!\n",
+ get_context->get_attempts);
else
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Too many attempts failed, ending
test!\n", get_context->get_attempts);
- GNUNET_SCHEDULER_cancel(die_task);
- GNUNET_SCHEDULER_add_now(&end_badly, "key mismatch in get response!\n");
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Too many attempts failed, ending test!\n",
+ get_context->get_attempts);
+ GNUNET_SCHEDULER_cancel (die_task);
+ GNUNET_SCHEDULER_add_now (&end_badly, "key mismatch in get response!\n");
+ return;
+ }
get_context->get_attempts++;
- get_context->retry_task =
GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
10),
- &stop_retry_get,
get_context);
- get_context->get_handle = GNUNET_DHT_get_start(get_context->dht_handle,
-
GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5),
- GNUNET_BLOCK_TYPE_DHT_HELLO,
- &get_context->peer->hashPubKey,
- DEFAULT_GET_REPLICATION,
- GNUNET_DHT_RO_NONE,
- NULL, 0,
- NULL, 0,
- &get_result_iterator,
get_context);
+ get_context->retry_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 10),
+ &stop_retry_get, get_context);
+ get_context->get_handle =
+ GNUNET_DHT_get_start (get_context->dht_handle,
+ GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 5),
+ GNUNET_BLOCK_TYPE_DHT_HELLO,
+ &get_context->peer->hashPubKey,
+ DEFAULT_GET_REPLICATION, GNUNET_DHT_RO_NONE, NULL,
+ 0, NULL, 0, &get_result_iterator, get_context);
}
static void
-stop_retry_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
+stop_retry_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct PeerGetContext *get_context = cls;
+
get_context->retry_task = GNUNET_SCHEDULER_NO_TASK;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Get attempt %u failed, canceling
request!\n", get_context->get_attempts);
- GNUNET_DHT_get_stop(get_context->get_handle);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Get attempt %u failed, canceling request!\n",
+ get_context->get_attempts);
+ GNUNET_DHT_get_stop (get_context->get_handle);
get_context->get_handle = NULL;
- GNUNET_SCHEDULER_add_now(&get_stop_finished, get_context);
+ GNUNET_SCHEDULER_add_now (&get_stop_finished, get_context);
}
static void
-do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
+do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct PeerGetContext *get_context = cls;
- get_context->retry_task =
GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
10),
- &stop_retry_get,
get_context);
+ get_context->retry_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 10),
+ &stop_retry_get, get_context);
- get_context->get_handle = GNUNET_DHT_get_start(get_context->dht_handle,
-
GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5),
- GNUNET_BLOCK_TYPE_DHT_HELLO,
- &get_context->peer->hashPubKey,
- DEFAULT_GET_REPLICATION,
- GNUNET_DHT_RO_NONE,
- NULL, 0,
- NULL, 0,
- &get_result_iterator,
get_context);
+ get_context->get_handle = GNUNET_DHT_get_start (get_context->dht_handle,
+ GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS,
5),
+ GNUNET_BLOCK_TYPE_DHT_HELLO,
+ &get_context->
+ peer->hashPubKey,
+ DEFAULT_GET_REPLICATION,
+ GNUNET_DHT_RO_NONE, NULL, 0,
+ NULL, 0,
&get_result_iterator,
+ get_context);
}
@@ -272,49 +285,52 @@
const char *emsg)
{
if (emsg == NULL)
- {
- total_connections++;
+ {
+ total_connections++;
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s,
distance %u\n",
- first_daemon->shortname,
- second_daemon->shortname,
- distance);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "connected peer %s to peer %s, distance %u\n",
+ first_daemon->shortname, second_daemon->shortname, distance);
#endif
- }
+ }
#if VERBOSE
else
- {
- failed_connections++;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to connect peer %s to peer
%s with error :\n%s\n",
- first_daemon->shortname,
- second_daemon->shortname, emsg);
- }
+ {
+ failed_connections++;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to connect peer %s to peer %s with error :\n%s\n",
+ first_daemon->shortname, second_daemon->shortname, emsg);
+ }
#endif
if (total_connections == expected_connections)
- {
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Created %d total connections, which is our target number!
Starting next phase of testing.\n",
- total_connections);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Created %d total connections, which is our target number!
Starting next phase of testing.\n",
+ total_connections);
#endif
- GNUNET_SCHEDULER_cancel (die_task);
- die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &end_badly, "from test gets");
+ GNUNET_SCHEDULER_cancel (die_task);
+ die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+ &end_badly, "from test gets");
- curr_get_ctx.dht_handle = peer1dht;
- curr_get_ctx.peer = &peer2id;
- GNUNET_SCHEDULER_add_delayed
(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2), &do_get,
&curr_get_ctx);
- }
+ curr_get_ctx.dht_handle = peer1dht;
+ curr_get_ctx.peer = &peer2id;
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 2), &do_get,
+ &curr_get_ctx);
+ }
else if (total_connections + failed_connections == expected_connections)
- {
- GNUNET_SCHEDULER_cancel (die_task);
- die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from topology_callback
(too many failed connections)");
- }
+ {
+ GNUNET_SCHEDULER_cancel (die_task);
+ die_task =
+ GNUNET_SCHEDULER_add_now (&end_badly,
+ "from topology_callback (too many failed
connections)");
+ }
}
static void
-connect_topology (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
+connect_topology (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
expected_connections = -1;
if ((pg != NULL) && (peers_left == 0))
@@ -322,48 +338,52 @@
GNUNET_TESTING_TOPOLOGY_CLIQUE,
GNUNET_TESTING_TOPOLOGY_OPTION_ALL,
0.0,
- TIMEOUT, 12, NULL,
NULL);
+ TIMEOUT, 12, NULL,
+ NULL);
GNUNET_SCHEDULER_cancel (die_task);
if (expected_connections == GNUNET_SYSERR)
- die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from connect topology
(bad return)");
+ die_task =
+ GNUNET_SCHEDULER_add_now (&end_badly,
+ "from connect topology (bad return)");
die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &end_badly, "from connect topology
(timeout)");
+ &end_badly,
+ "from connect topology (timeout)");
}
static void
peers_started_callback (void *cls,
- const struct GNUNET_PeerIdentity *id,
- const struct GNUNET_CONFIGURATION_Handle *cfg,
- struct GNUNET_TESTING_Daemon *d, const char *emsg)
+ const struct GNUNET_PeerIdentity *id,
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ struct GNUNET_TESTING_Daemon *d, const char *emsg)
{
if (emsg != NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to start daemon with
error: `%s'\n",
- emsg);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to start daemon with error: `%s'\n", emsg);
+ return;
+ }
GNUNET_assert (id != NULL);
if (peers_left == num_peers)
{
- memcpy(&peer1id, id, sizeof(struct GNUNET_PeerIdentity));
- peer1dht = GNUNET_DHT_connect(cfg, 100);
+ memcpy (&peer1id, id, sizeof (struct GNUNET_PeerIdentity));
+ peer1dht = GNUNET_DHT_connect (cfg, 100);
if (peer1dht == NULL)
{
GNUNET_SCHEDULER_cancel (die_task);
- GNUNET_SCHEDULER_add_now(&end_badly, "Failed to get dht handle!\n");
+ GNUNET_SCHEDULER_add_now (&end_badly, "Failed to get dht handle!\n");
}
}
else
{
- memcpy(&peer2id, id, sizeof(struct GNUNET_PeerIdentity));
- peer2dht = GNUNET_DHT_connect(cfg, 100);
+ memcpy (&peer2id, id, sizeof (struct GNUNET_PeerIdentity));
+ peer2dht = GNUNET_DHT_connect (cfg, 100);
if (peer2dht == NULL)
{
GNUNET_SCHEDULER_cancel (die_task);
- GNUNET_SCHEDULER_add_now(&end_badly, "Failed to get dht handle!\n");
+ GNUNET_SCHEDULER_add_now (&end_badly, "Failed to get dht handle!\n");
}
}
@@ -371,21 +391,21 @@
peers_left--;
if (peers_left == 0)
- {
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "All %d daemons started, now connecting peers!\n",
- num_peers);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "All %d daemons started, now connecting peers!\n", num_peers);
#endif
- GNUNET_SCHEDULER_cancel (die_task);
- /* Set up task in case topology creation doesn't finish
- * within a reasonable amount of time */
- die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &end_badly, "from
peers_started_callback");
+ GNUNET_SCHEDULER_cancel (die_task);
+ /* Set up task in case topology creation doesn't finish
+ * within a reasonable amount of time */
+ die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+ &end_badly,
+ "from peers_started_callback");
- GNUNET_SCHEDULER_add_now(&connect_topology, NULL);
- ok = 0;
- }
+ GNUNET_SCHEDULER_add_now (&connect_topology, NULL);
+ ok = 0;
+ }
}
static void
@@ -394,11 +414,13 @@
const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
- if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string(cfg, "paths",
"servicehome", &test_directory))
- {
- ok = 404;
- return;
- }
+ if (GNUNET_YES !=
+ GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome",
+ &test_directory))
+ {
+ ok = 404;
+ return;
+ }
if (GNUNET_SYSERR ==
GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers",
@@ -410,7 +432,8 @@
gets_succeeded = 0;
/* Set up a task to end testing if peer start fails */
die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &end_badly, "didn't start all
daemons in reasonable amount of time!!!");
+ &end_badly,
+ "didn't start all daemons in
reasonable amount of time!!!");
pg = GNUNET_TESTING_daemons_start (cfg,
num_peers,
@@ -419,8 +442,7 @@
TIMEOUT,
NULL, NULL,
&peers_started_callback,
- NULL,
- &topology_callback, NULL, NULL);
+ NULL, &topology_callback, NULL, NULL);
}
@@ -428,7 +450,8 @@
check ()
{
int ret;
- char *const argv[] = {"test-dht-twopeer",
+
+ char *const argv[] = { "test-dht-twopeer",
"-c",
"test_dht_twopeer_data.conf",
#if VERBOSE
@@ -440,12 +463,13 @@
GNUNET_GETOPT_OPTION_END
};
ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
- argv, "test-dht-twopeer", "nohelp",
- options, &run, &ok);
+ argv, "test-dht-twopeer", "nohelp",
+ options, &run, &ok);
if (ret != GNUNET_OK)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "`test-dht-twopeer': Failed with
error code %d\n", ret);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "`test-dht-twopeer': Failed with error code %d\n", ret);
+ }
return ok;
}
@@ -467,9 +491,10 @@
* of by the testing framework.
*/
if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to remove testing
directory %s\n", test_directory);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to remove testing directory %s\n", test_directory);
+ }
return ret;
}
Modified: gnunet/src/dht/test_dht_twopeer_path_tracking.c
===================================================================
--- gnunet/src/dht/test_dht_twopeer_path_tracking.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/dht/test_dht_twopeer_path_tracking.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -115,14 +115,14 @@
/**
* Check whether peers successfully shut down.
*/
-void shutdown_callback (void *cls,
- const char *emsg)
+void
+shutdown_callback (void *cls, const char *emsg)
{
if (emsg != NULL)
- {
- if (ok == 0)
- ok = 2;
- }
+ {
+ if (ok == 0)
+ ok = 2;
+ }
}
/**
@@ -130,13 +130,13 @@
* testcase. Specifically, called when our get request completes.
*/
static void
-finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
+finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GNUNET_assert (pg != NULL);
GNUNET_assert (peer1dht != NULL);
GNUNET_assert (peer2dht != NULL);
- GNUNET_DHT_disconnect(peer1dht);
- GNUNET_DHT_disconnect(peer2dht);
+ GNUNET_DHT_disconnect (peer1dht);
+ GNUNET_DHT_disconnect (peer2dht);
GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
ok = 0;
}
@@ -146,13 +146,13 @@
* down the peers without freeing memory associated with GET request.
*/
static void
-end_badly_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
+end_badly_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
if (peer1dht != NULL)
- GNUNET_DHT_disconnect(peer1dht);
+ GNUNET_DHT_disconnect (peer1dht);
if (peer2dht != NULL)
- GNUNET_DHT_disconnect(peer2dht);
+ GNUNET_DHT_disconnect (peer2dht);
if (pg != NULL)
GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
@@ -164,15 +164,16 @@
* test.
*/
static void
-end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
+end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failing test with error: `%s'!\n",
(char *)cls);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failing test with error: `%s'!\n",
+ (char *) cls);
if (global_get_handle != NULL)
- {
- GNUNET_DHT_get_stop(global_get_handle);
- global_get_handle = NULL;
- }
- GNUNET_SCHEDULER_add_now(&end_badly_cont, NULL);
+ {
+ GNUNET_DHT_get_stop (global_get_handle);
+ global_get_handle = NULL;
+ }
+ GNUNET_SCHEDULER_add_now (&end_badly_cont, NULL);
ok = 1;
}
@@ -186,51 +187,54 @@
* @param size number of bytes in data
* @param data pointer to the result data
*/
-void get_result_iterator (void *cls,
- struct GNUNET_TIME_Absolute exp,
- const GNUNET_HashCode * key,
- const struct GNUNET_PeerIdentity * const *get_path,
- const struct GNUNET_PeerIdentity * const *put_path,
- enum GNUNET_BLOCK_Type type,
- size_t size,
- const void *data)
+void
+get_result_iterator (void *cls,
+ struct GNUNET_TIME_Absolute exp,
+ const GNUNET_HashCode * key,
+ const struct GNUNET_PeerIdentity *const *get_path,
+ const struct GNUNET_PeerIdentity *const *put_path,
+ 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 */
- memset(&original_key, 42, sizeof(GNUNET_HashCode)); /* Set the key to what
it was set to previously */
- memset(original_data, 43, sizeof(original_data));
+ char original_data[4]; /* Made up data that was stored */
+
+ memset (&original_key, 42, sizeof (GNUNET_HashCode)); /* Set the key to what
it was set to previously */
+ memset (original_data, 43, sizeof (original_data));
#if VERBOSE
unsigned int i;
#endif
- if ((0 != memcmp(&original_key, key, sizeof (GNUNET_HashCode))) || (0 !=
memcmp(original_data, data, sizeof(original_data))))
+ if ((0 != memcmp (&original_key, key, sizeof (GNUNET_HashCode))) ||
+ (0 != memcmp (original_data, data, sizeof (original_data))))
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Key or data is not the same as was
inserted!\n");
- GNUNET_SCHEDULER_cancel(die_task);
- GNUNET_SCHEDULER_add_now(&end_badly, "key or data mismatch in get
response!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Key or data is not the same as was inserted!\n");
+ GNUNET_SCHEDULER_cancel (die_task);
+ GNUNET_SCHEDULER_add_now (&end_badly,
+ "key or data mismatch in get response!\n");
return;
}
#if VERBOSE
if (put_path != NULL)
- {
- fprintf(stderr, "PUT Path: ");
- for (i = 0; put_path[i] != NULL; i++)
- fprintf(stderr, "%s%s", i == 0 ? "" : "->", GNUNET_i2s(put_path[i]));
- fprintf(stderr, "\n");
- }
+ {
+ fprintf (stderr, "PUT Path: ");
+ for (i = 0; put_path[i] != NULL; i++)
+ fprintf (stderr, "%s%s", i == 0 ? "" : "->", GNUNET_i2s (put_path[i]));
+ fprintf (stderr, "\n");
+ }
if (get_path != NULL)
- {
- fprintf(stderr, "GET Path: ");
- for (i = 0; get_path[i] != NULL; i++)
- fprintf(stderr, "%s%s", i == 0 ? "" : "->", GNUNET_i2s(get_path[i]));
- fprintf(stderr, "\n");
- }
+ {
+ fprintf (stderr, "GET Path: ");
+ for (i = 0; get_path[i] != NULL; i++)
+ fprintf (stderr, "%s%s", i == 0 ? "" : "->", GNUNET_i2s (get_path[i]));
+ fprintf (stderr, "\n");
+ }
#endif
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct GET response!\n");
- GNUNET_SCHEDULER_cancel(die_task);
- GNUNET_DHT_get_stop(global_get_handle);
+ GNUNET_SCHEDULER_cancel (die_task);
+ GNUNET_DHT_get_stop (global_get_handle);
GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
}
@@ -238,18 +242,16 @@
* Start the GET request for the same key/data that was inserted.
*/
static void
-do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
+do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- GNUNET_HashCode key; /* Key for data lookup */
- 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,
- DEFAULT_GET_REPLICATION,
- GNUNET_DHT_RO_RECORD_ROUTE,
- NULL, 0,
- NULL, 0,
- &get_result_iterator, NULL);
+ GNUNET_HashCode key; /* Key for data lookup */
+
+ 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,
+ DEFAULT_GET_REPLICATION,
GNUNET_DHT_RO_RECORD_ROUTE,
+ NULL, 0, NULL, 0, &get_result_iterator, NULL);
}
/**
@@ -257,35 +259,37 @@
* Schedule the GET request for some time in the future.
*/
static void
-put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
+put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GNUNET_SCHEDULER_cancel (die_task);
die_task = GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT,
- &end_badly, "waiting for get
response (data not found)");
-
GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
10), &do_get, NULL);
+ &end_badly,
+ "waiting for get response (data not
found)");
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 10), &do_get, NULL);
}
/**
* Set up some data, and call API PUT function
*/
static void
-do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
+do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- GNUNET_HashCode key; /* Made up key to store data under */
- char data[4]; /* Made up data to store */
- memset(&key, 42, sizeof(GNUNET_HashCode)); /* Set the key to something
simple so we can issue GET request */
- memset(data, 43, sizeof(data));
+ GNUNET_HashCode key; /* Made up key to store data under */
+ char data[4]; /* Made up data to store */
+ memset (&key, 42, sizeof (GNUNET_HashCode)); /* Set the key to something
simple so we can issue GET request */
+ memset (data, 43, sizeof (data));
+
/* Insert the data at the first peer */
- GNUNET_DHT_put(peer1dht,
- &key,
- DEFAULT_PUT_REPLICATION,
- 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,
+ DEFAULT_PUT_REPLICATION,
+ 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);
}
/**
@@ -309,43 +313,45 @@
const char *emsg)
{
if (emsg == NULL)
- {
- total_connections++;
+ {
+ total_connections++;
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s,
distance %u\n",
- first_daemon->shortname,
- second_daemon->shortname,
- distance);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "connected peer %s to peer %s, distance %u\n",
+ first_daemon->shortname, second_daemon->shortname, distance);
#endif
- }
+ }
#if VERBOSE
else
- {
- failed_connections++;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to connect peer %s to peer
%s with error :\n%s\n",
- first_daemon->shortname,
- second_daemon->shortname, emsg);
- }
+ {
+ failed_connections++;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to connect peer %s to peer %s with error :\n%s\n",
+ first_daemon->shortname, second_daemon->shortname, emsg);
+ }
#endif
if (total_connections == expected_connections)
- {
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Created %d total connections, which is our target number!
Starting next phase of testing.\n",
- total_connections);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Created %d total connections, which is our target number!
Starting next phase of testing.\n",
+ total_connections);
#endif
- GNUNET_SCHEDULER_cancel (die_task);
- die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &end_badly, "from test gets");
+ GNUNET_SCHEDULER_cancel (die_task);
+ die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+ &end_badly, "from test gets");
- GNUNET_SCHEDULER_add_delayed
(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2), &do_put, NULL);
- }
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 2), &do_put,
NULL);
+ }
else if (total_connections + failed_connections == expected_connections)
- {
- GNUNET_SCHEDULER_cancel (die_task);
- die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from topology_callback
(too many failed connections)");
- }
+ {
+ GNUNET_SCHEDULER_cancel (die_task);
+ die_task =
+ GNUNET_SCHEDULER_add_now (&end_badly,
+ "from topology_callback (too many failed
connections)");
+ }
}
@@ -362,74 +368,74 @@
*/
static void
peers_started_callback (void *cls,
- const struct GNUNET_PeerIdentity *id,
- const struct GNUNET_CONFIGURATION_Handle *cfg,
- struct GNUNET_TESTING_Daemon *d, const char *emsg)
+ const struct GNUNET_PeerIdentity *id,
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ struct GNUNET_TESTING_Daemon *d, const char *emsg)
{
if (emsg != NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to start daemon with
error: `%s'\n",
- emsg);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to start daemon with error: `%s'\n", emsg);
+ return;
+ }
GNUNET_assert (id != NULL);
/* This is the first peer started */
if (peers_left == num_peers)
{
- memcpy(&peer1id, id, sizeof(struct GNUNET_PeerIdentity)); /* Save the peer
id */
- peer1dht = GNUNET_DHT_connect(cfg, 100); /* Connect to the first peers DHT
service */
- if (peer1dht == NULL) /* If DHT connect failed */
+ memcpy (&peer1id, id, sizeof (struct GNUNET_PeerIdentity)); /* Save the
peer id */
+ peer1dht = GNUNET_DHT_connect (cfg, 100); /* Connect to the first peers
DHT service */
+ if (peer1dht == NULL) /* If DHT connect failed */
{
GNUNET_SCHEDULER_cancel (die_task);
- GNUNET_SCHEDULER_add_now(&end_badly, "Failed to get dht handle!\n");
+ GNUNET_SCHEDULER_add_now (&end_badly, "Failed to get dht handle!\n");
}
}
- else /* This is the second peer started */
+ else /* This is the second peer started */
{
- memcpy(&peer2id, id, sizeof(struct GNUNET_PeerIdentity)); /* Same as for
first peer... */
- peer2dht = GNUNET_DHT_connect(cfg, 100);
+ memcpy (&peer2id, id, sizeof (struct GNUNET_PeerIdentity)); /* Same as for
first peer... */
+ peer2dht = GNUNET_DHT_connect (cfg, 100);
if (peer2dht == NULL)
{
GNUNET_SCHEDULER_cancel (die_task);
- GNUNET_SCHEDULER_add_now(&end_badly, "Failed to get dht handle!\n");
+ GNUNET_SCHEDULER_add_now (&end_badly, "Failed to get dht handle!\n");
}
}
/* Decrement number of peers left to start */
peers_left--;
- if (peers_left == 0) /* Indicates all peers started */
- {
+ if (peers_left == 0) /* Indicates all peers started */
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "All %d daemons started, now connecting peers!\n",
- num_peers);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "All %d daemons started, now connecting peers!\n", num_peers);
#endif
- expected_connections = -1;
- if ((pg != NULL)) /* Sanity check */
- {
- /* Connect peers in a "straight line" topology, return the number of
expected connections */
- expected_connections = GNUNET_TESTING_connect_topology (pg,
-
GNUNET_TESTING_TOPOLOGY_LINE,
-
GNUNET_TESTING_TOPOLOGY_OPTION_ALL,
- 0.0,
- TIMEOUT,
- 2,
- NULL,
- NULL);
- }
+ expected_connections = -1;
+ if ((pg != NULL)) /* Sanity check */
+ {
+ /* Connect peers in a "straight line" topology, return the number of
expected connections */
+ expected_connections = GNUNET_TESTING_connect_topology (pg,
+
GNUNET_TESTING_TOPOLOGY_LINE,
+
GNUNET_TESTING_TOPOLOGY_OPTION_ALL,
+ 0.0,
+ TIMEOUT,
+ 2, NULL, NULL);
+ }
- /* Cancel current timeout fail task */
- GNUNET_SCHEDULER_cancel (die_task);
- if (expected_connections == GNUNET_SYSERR) /* Some error happened */
- die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from connect
topology (bad return)");
+ /* Cancel current timeout fail task */
+ GNUNET_SCHEDULER_cancel (die_task);
+ if (expected_connections == GNUNET_SYSERR) /* Some error happened */
+ die_task =
+ GNUNET_SCHEDULER_add_now (&end_badly,
+ "from connect topology (bad return)");
- /* Schedule timeout on failure task */
- die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &end_badly, "from connect
topology (timeout)");
- ok = 0;
- }
+ /* Schedule timeout on failure task */
+ die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+ &end_badly,
+ "from connect topology
(timeout)");
+ ok = 0;
+ }
}
static void
@@ -439,11 +445,13 @@
{
/* Get path from configuration file */
- if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string(cfg, "paths",
"servicehome", &test_directory))
- {
- ok = 404;
- return;
- }
+ if (GNUNET_YES !=
+ GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome",
+ &test_directory))
+ {
+ ok = 404;
+ return;
+ }
/* Get number of peers to start from configuration (should be two) */
if (GNUNET_SYSERR ==
@@ -456,22 +464,19 @@
/* Set up a task to end testing if peer start fails */
die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &end_badly, "didn't start all
daemons in reasonable amount of time!!!");
+ &end_badly,
+ "didn't start all daemons in
reasonable amount of time!!!");
/* Start num_peers peers, call peers_started_callback on peer start,
topology_callback on peer connect */
/* Read the API documentation for other parameters! */
- pg = GNUNET_TESTING_daemons_start (cfg,
- peers_left, /* Total number of peers */
- peers_left, /* Number of outstanding
connections */
- peers_left, /* Number of parallel ssh
connections, or peers being started at once */
+ pg = GNUNET_TESTING_daemons_start (cfg, peers_left, /* Total number of
peers */
+ peers_left, /* Number of
outstanding connections */
+ peers_left, /* Number of parallel
ssh connections, or peers being started at once */
TIMEOUT,
NULL,
NULL,
&peers_started_callback,
- NULL,
- &topology_callback,
- NULL,
- NULL);
+ NULL, &topology_callback, NULL, NULL);
}
@@ -479,10 +484,11 @@
check ()
{
int ret;
+
/* Arguments for GNUNET_PROGRAM_run */
- char *const argv[] = {"test-dht-twopeer-put-get", /* Name to give running
binary */
+ char *const argv[] = { "test-dht-twopeer-put-get", /* Name to give
running binary */
"-c",
- "test_dht_twopeer_data.conf", /* Config file to use */
+ "test_dht_twopeer_data.conf", /* Config file to use */
#if VERBOSE
"-L", "DEBUG",
#endif
@@ -493,12 +499,13 @@
};
/* Run the run function as a new program */
ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
- argv, "test-dht-twopeer-put-get", "nohelp",
- options, &run, &ok);
+ argv, "test-dht-twopeer-put-get", "nohelp",
+ options, &run, &ok);
if (ret != GNUNET_OK)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "`test-dht-twopeer': Failed with
error code %d\n", ret);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "`test-dht-twopeer': Failed with error code %d\n", ret);
+ }
return ok;
}
@@ -520,9 +527,10 @@
* of by the testing framework.
*/
if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to remove testing
directory %s\n", test_directory);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to remove testing directory %s\n", test_directory);
+ }
return ret;
}
Modified: gnunet/src/dht/test_dht_twopeer_put_get.c
===================================================================
--- gnunet/src/dht/test_dht_twopeer_put_get.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/dht/test_dht_twopeer_put_get.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -137,14 +137,14 @@
/**
* Check whether peers successfully shut down.
*/
-void shutdown_callback (void *cls,
- const char *emsg)
+void
+shutdown_callback (void *cls, const char *emsg)
{
if (emsg != NULL)
- {
- if (ok == 0)
- ok = 2;
- }
+ {
+ if (ok == 0)
+ ok = 2;
+ }
}
/**
@@ -152,13 +152,13 @@
* testcase. Specifically, called when our get request completes.
*/
static void
-finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
+finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GNUNET_assert (pg != NULL);
GNUNET_assert (peer1dht != NULL);
GNUNET_assert (peer2dht != NULL);
- GNUNET_DHT_disconnect(peer1dht);
- GNUNET_DHT_disconnect(peer2dht);
+ GNUNET_DHT_disconnect (peer1dht);
+ GNUNET_DHT_disconnect (peer2dht);
GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
ok = 0;
}
@@ -168,13 +168,13 @@
* down the peers without freeing memory associated with GET request.
*/
static void
-end_badly_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
+end_badly_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
if (peer1dht != NULL)
- GNUNET_DHT_disconnect(peer1dht);
+ GNUNET_DHT_disconnect (peer1dht);
if (peer2dht != NULL)
- GNUNET_DHT_disconnect(peer2dht);
+ GNUNET_DHT_disconnect (peer2dht);
if (pg != NULL)
GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
@@ -186,15 +186,16 @@
* test.
*/
static void
-end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
+end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failing test with error: `%s'!\n",
(char *)cls);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failing test with error: `%s'!\n",
+ (char *) cls);
if (global_get_handle != NULL)
- {
- GNUNET_DHT_get_stop(global_get_handle);
- global_get_handle = NULL;
- }
- GNUNET_SCHEDULER_add_now(&end_badly_cont, NULL);
+ {
+ GNUNET_DHT_get_stop (global_get_handle);
+ global_get_handle = NULL;
+ }
+ GNUNET_SCHEDULER_add_now (&end_badly_cont, NULL);
ok = 1;
}
@@ -208,40 +209,47 @@
* @param size number of bytes in data
* @param data pointer to the result data
*/
-void get_result_iterator (void *cls,
- struct GNUNET_TIME_Absolute exp,
- const GNUNET_HashCode * key,
- const struct GNUNET_PeerIdentity * const *get_path,
- const struct GNUNET_PeerIdentity * const *put_path,
- enum GNUNET_BLOCK_Type type,
- size_t size,
- const void *result_data)
+void
+get_result_iterator (void *cls,
+ struct GNUNET_TIME_Absolute exp,
+ const GNUNET_HashCode * key,
+ const struct GNUNET_PeerIdentity *const *get_path,
+ const struct GNUNET_PeerIdentity *const *put_path,
+ 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 */
- memset(&original_key, 42, sizeof(GNUNET_HashCode)); /* Set the key to what
it was set to previously */
- memset(original_data, 43, sizeof(original_data));
+ char original_data[4]; /* Made up data that was stored */
+ memset (&original_key, 42, sizeof (GNUNET_HashCode)); /* Set the key to what
it was set to previously */
+ memset (original_data, 43, sizeof (original_data));
+
#if DNS
- if ((0 != memcmp(&data.service_descriptor, key, sizeof (GNUNET_HashCode)))
|| (0 != memcmp((char *)&data, result_data, sizeof(original_data))))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Key or data is not the same as
was inserted!\n");
- GNUNET_SCHEDULER_cancel(die_task);
- GNUNET_SCHEDULER_add_now(&end_badly, "key or data mismatch in get
response!\n");
- return;
- }
+ if ((0 != memcmp (&data.service_descriptor, key, sizeof (GNUNET_HashCode)))
||
+ (0 != memcmp ((char *) &data, result_data, sizeof (original_data))))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Key or data is not the same as was inserted!\n");
+ GNUNET_SCHEDULER_cancel (die_task);
+ GNUNET_SCHEDULER_add_now (&end_badly,
+ "key or data mismatch in get response!\n");
+ return;
+ }
#else
- if ((0 != memcmp(&original_key, key, sizeof (GNUNET_HashCode))) || (0 !=
memcmp(original_data, result_data, sizeof(original_data))))
+ if ((0 != memcmp (&original_key, key, sizeof (GNUNET_HashCode))) ||
+ (0 != memcmp (original_data, result_data, sizeof (original_data))))
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Key or data is not the same as was
inserted!\n");
- GNUNET_SCHEDULER_cancel(die_task);
- GNUNET_SCHEDULER_add_now(&end_badly, "key or data mismatch in get
response!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Key or data is not the same as was inserted!\n");
+ GNUNET_SCHEDULER_cancel (die_task);
+ GNUNET_SCHEDULER_add_now (&end_badly,
+ "key or data mismatch in get response!\n");
return;
}
#endif
- GNUNET_SCHEDULER_cancel(die_task);
- GNUNET_DHT_get_stop(global_get_handle);
+ GNUNET_SCHEDULER_cancel (die_task);
+ GNUNET_DHT_get_stop (global_get_handle);
GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
}
@@ -249,26 +257,26 @@
* Start the GET request for the same key/data that was inserted.
*/
static void
-do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
+do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- GNUNET_HashCode key; /* Key for data lookup */
+ GNUNET_HashCode key; /* Key for data lookup */
+
#if DNS
- memcpy(&key, &data.service_descriptor, sizeof(GNUNET_HashCode));
+ memcpy (&key, &data.service_descriptor, sizeof (GNUNET_HashCode));
#else
- memset(&key, 42, sizeof(GNUNET_HashCode)); /* Set the key to the same thing
as when data was inserted */
+ memset (&key, 42, sizeof (GNUNET_HashCode)); /* Set the key to the same
thing as when data was inserted */
#endif
- global_get_handle = GNUNET_DHT_get_start(peer2dht,
GNUNET_TIME_relative_get_forever(),
+ global_get_handle =
+ GNUNET_DHT_get_start (peer2dht, GNUNET_TIME_relative_get_forever (),
#if DNS
- GNUNET_BLOCK_TYPE_DNS,
+ GNUNET_BLOCK_TYPE_DNS,
#else
- GNUNET_BLOCK_TYPE_TEST,
+ GNUNET_BLOCK_TYPE_TEST,
#endif
- &key,
- DEFAULT_GET_REPLICATION,
- GNUNET_DHT_RO_NONE,
- NULL, 0,
- NULL, 0,
- &get_result_iterator, NULL);
+ &key,
+ DEFAULT_GET_REPLICATION,
+ GNUNET_DHT_RO_NONE,
+ NULL, 0, NULL, 0, &get_result_iterator, NULL);
}
/**
@@ -276,12 +284,14 @@
* Schedule the GET request for some time in the future.
*/
static void
-put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
+put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GNUNET_SCHEDULER_cancel (die_task);
die_task = GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT,
- &end_badly, "waiting for get
response (data not found)");
-
GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
10), &do_get, NULL);
+ &end_badly,
+ "waiting for get response (data not
found)");
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 10), &do_get, NULL);
}
@@ -290,23 +300,23 @@
* Set up some data, and call API PUT function
*/
static void
-do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
+do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- GNUNET_HashCode key; /* Made up key to store data under */
- char data[4]; /* Made up data to store */
- memset(&key, 42, sizeof(GNUNET_HashCode)); /* Set the key to something
simple so we can issue GET request */
- memset(data, 43, sizeof(data));
+ GNUNET_HashCode key; /* Made up key to store data under */
+ char data[4]; /* Made up data to store */
+ memset (&key, 42, sizeof (GNUNET_HashCode)); /* Set the key to something
simple so we can issue GET request */
+ memset (data, 43, sizeof (data));
+
/* Insert the data at the first peer */
- GNUNET_DHT_put(peer1dht,
- &key,
- DEFAULT_PUT_REPLICATION,
- 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,
+ DEFAULT_PUT_REPLICATION,
+ 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
@@ -314,55 +324,56 @@
* Set up some data, and call API PUT function
*/
static void
-do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
+do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- char* name = "philipptoelke.gnunet.";
- size_t size = sizeof(struct GNUNET_DNS_Record);
- memset(&data, 0, size);
+ char *name = "philipptoelke.gnunet.";
+ size_t size = sizeof (struct GNUNET_DNS_Record);
- data.purpose.size = htonl(size - sizeof(struct GNUNET_CRYPTO_RsaSignature));
+ memset (&data, 0, size);
+
+ data.purpose.size = htonl (size - sizeof (struct
GNUNET_CRYPTO_RsaSignature));
data.purpose.purpose = GNUNET_SIGNATURE_PURPOSE_DNS_RECORD;
- GNUNET_CRYPTO_hash(name, strlen(name)+1, &data.service_descriptor);
+ GNUNET_CRYPTO_hash (name, strlen (name) + 1, &data.service_descriptor);
- data.service_type = htonl(GNUNET_DNS_SERVICE_TYPE_UDP);
- data.ports = htons(69);
+ data.service_type = htonl (GNUNET_DNS_SERVICE_TYPE_UDP);
+ data.ports = htons (69);
- char* keyfile;
- GNUNET_asprintf(&keyfile, "/tmp/test_dns_data_key");
- struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key =
GNUNET_CRYPTO_rsa_key_create_from_file(keyfile);
- GNUNET_free(keyfile);
- GNUNET_assert(my_private_key != NULL);
+ char *keyfile;
- GNUNET_CRYPTO_rsa_key_get_public(my_private_key, &data.peer);
+ GNUNET_asprintf (&keyfile, "/tmp/test_dns_data_key");
+ struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key =
+ GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
+ GNUNET_free (keyfile);
+ GNUNET_assert (my_private_key != NULL);
- data.expiration_time =
GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_HOURS);
+ GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &data.peer);
+ data.expiration_time =
+ GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS);
+
/* Sign the block */
- if (GNUNET_OK != GNUNET_CRYPTO_rsa_sign(my_private_key,
- &data.purpose,
- &data.signature))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "could not sign DNS_Record\n");
- return;
- }
- GNUNET_CRYPTO_rsa_key_free(my_private_key);
+ if (GNUNET_OK != GNUNET_CRYPTO_rsa_sign (my_private_key,
+ &data.purpose, &data.signature))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "could not sign DNS_Record\n");
+ return;
+ }
+ GNUNET_CRYPTO_rsa_key_free (my_private_key);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Putting with key %08x\n",
- *((unsigned int*)&data.service_descriptor));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Putting with key %08x\n",
+ *((unsigned int *) &data.service_descriptor));
- GNUNET_DHT_put(peer1dht,
- &data.service_descriptor,
- DEFAULT_PUT_REPLICATION,
- GNUNET_DHT_RO_NONE,
- GNUNET_BLOCK_TYPE_DNS,
- size,
- (char*)&data,
- GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_HOURS),
- GNUNET_TIME_UNIT_MINUTES,
- &put_finished,
- NULL);
+ GNUNET_DHT_put (peer1dht,
+ &data.service_descriptor,
+ DEFAULT_PUT_REPLICATION,
+ GNUNET_DHT_RO_NONE,
+ GNUNET_BLOCK_TYPE_DNS,
+ size,
+ (char *) &data,
+ GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS),
+ GNUNET_TIME_UNIT_MINUTES, &put_finished, NULL);
}
#endif
@@ -387,43 +398,45 @@
const char *emsg)
{
if (emsg == NULL)
- {
- total_connections++;
+ {
+ total_connections++;
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s,
distance %u\n",
- first_daemon->shortname,
- second_daemon->shortname,
- distance);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "connected peer %s to peer %s, distance %u\n",
+ first_daemon->shortname, second_daemon->shortname, distance);
#endif
- }
+ }
#if VERBOSE
else
- {
- failed_connections++;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to connect peer %s to peer
%s with error :\n%s\n",
- first_daemon->shortname,
- second_daemon->shortname, emsg);
- }
+ {
+ failed_connections++;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to connect peer %s to peer %s with error :\n%s\n",
+ first_daemon->shortname, second_daemon->shortname, emsg);
+ }
#endif
if (total_connections == expected_connections)
- {
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Created %d total connections, which is our target number!
Starting next phase of testing.\n",
- total_connections);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Created %d total connections, which is our target number!
Starting next phase of testing.\n",
+ total_connections);
#endif
- GNUNET_SCHEDULER_cancel (die_task);
- die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &end_badly, "from test gets");
+ GNUNET_SCHEDULER_cancel (die_task);
+ die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+ &end_badly, "from test gets");
- GNUNET_SCHEDULER_add_delayed
(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2), &do_put, NULL);
- }
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 2), &do_put,
NULL);
+ }
else if (total_connections + failed_connections == expected_connections)
- {
- GNUNET_SCHEDULER_cancel (die_task);
- die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from topology_callback
(too many failed connections)");
- }
+ {
+ GNUNET_SCHEDULER_cancel (die_task);
+ die_task =
+ GNUNET_SCHEDULER_add_now (&end_badly,
+ "from topology_callback (too many failed
connections)");
+ }
}
@@ -440,73 +453,74 @@
*/
static void
peers_started_callback (void *cls,
- const struct GNUNET_PeerIdentity *id,
- const struct GNUNET_CONFIGURATION_Handle *cfg,
- struct GNUNET_TESTING_Daemon *d, const char *emsg)
+ const struct GNUNET_PeerIdentity *id,
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ struct GNUNET_TESTING_Daemon *d, const char *emsg)
{
if (emsg != NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to start daemon with
error: `%s'\n",
- emsg);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to start daemon with error: `%s'\n", emsg);
+ return;
+ }
GNUNET_assert (id != NULL);
/* This is the first peer started */
if (peers_left == num_peers)
{
- memcpy(&peer1id, id, sizeof(struct GNUNET_PeerIdentity)); /* Save the peer
id */
- peer1dht = GNUNET_DHT_connect(cfg, 100); /* Connect to the first peers DHT
service */
- if (peer1dht == NULL) /* If DHT connect failed */
+ memcpy (&peer1id, id, sizeof (struct GNUNET_PeerIdentity)); /* Save the
peer id */
+ peer1dht = GNUNET_DHT_connect (cfg, 100); /* Connect to the first peers
DHT service */
+ if (peer1dht == NULL) /* If DHT connect failed */
{
GNUNET_SCHEDULER_cancel (die_task);
- GNUNET_SCHEDULER_add_now(&end_badly, "Failed to get dht handle!\n");
+ GNUNET_SCHEDULER_add_now (&end_badly, "Failed to get dht handle!\n");
}
}
- else /* This is the second peer started */
+ else /* This is the second peer started */
{
- memcpy(&peer2id, id, sizeof(struct GNUNET_PeerIdentity)); /* Same as for
first peer... */
- peer2dht = GNUNET_DHT_connect(cfg, 100);
+ memcpy (&peer2id, id, sizeof (struct GNUNET_PeerIdentity)); /* Same as for
first peer... */
+ peer2dht = GNUNET_DHT_connect (cfg, 100);
if (peer2dht == NULL)
{
GNUNET_SCHEDULER_cancel (die_task);
- GNUNET_SCHEDULER_add_now(&end_badly, "Failed to get dht handle!\n");
+ GNUNET_SCHEDULER_add_now (&end_badly, "Failed to get dht handle!\n");
}
}
/* Decrement number of peers left to start */
peers_left--;
- if (peers_left == 0) /* Indicates all peers started */
- {
+ if (peers_left == 0) /* Indicates all peers started */
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "All %d daemons started, now connecting peers!\n",
- num_peers);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "All %d daemons started, now connecting peers!\n", num_peers);
#endif
- expected_connections = -1;
- if ((pg != NULL)) /* Sanity check */
- {
- /* Connect peers in a "straight line" topology, return the number of
expected connections */
- expected_connections = GNUNET_TESTING_connect_topology (pg,
-
GNUNET_TESTING_TOPOLOGY_LINE,
-
GNUNET_TESTING_TOPOLOGY_OPTION_ALL,
- 0.0,
- TIMEOUT,
- 12,
- NULL, NULL);
- }
+ expected_connections = -1;
+ if ((pg != NULL)) /* Sanity check */
+ {
+ /* Connect peers in a "straight line" topology, return the number of
expected connections */
+ expected_connections = GNUNET_TESTING_connect_topology (pg,
+
GNUNET_TESTING_TOPOLOGY_LINE,
+
GNUNET_TESTING_TOPOLOGY_OPTION_ALL,
+ 0.0,
+ TIMEOUT,
+ 12, NULL, NULL);
+ }
- /* Cancel current timeout fail task */
- GNUNET_SCHEDULER_cancel (die_task);
- if (expected_connections == GNUNET_SYSERR) /* Some error happened */
- die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from connect
topology (bad return)");
+ /* Cancel current timeout fail task */
+ GNUNET_SCHEDULER_cancel (die_task);
+ if (expected_connections == GNUNET_SYSERR) /* Some error happened */
+ die_task =
+ GNUNET_SCHEDULER_add_now (&end_badly,
+ "from connect topology (bad return)");
- /* Schedule timeout on failure task */
- die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &end_badly, "from connect
topology (timeout)");
- ok = 0;
- }
+ /* Schedule timeout on failure task */
+ die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+ &end_badly,
+ "from connect topology
(timeout)");
+ ok = 0;
+ }
}
static void
@@ -516,11 +530,13 @@
{
/* Get path from configuration file */
- if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string(cfg, "paths",
"servicehome", &test_directory))
- {
- ok = 404;
- return;
- }
+ if (GNUNET_YES !=
+ GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome",
+ &test_directory))
+ {
+ ok = 404;
+ return;
+ }
/* Get number of peers to start from configuration (should be two) */
if (GNUNET_SYSERR ==
@@ -533,7 +549,8 @@
/* Set up a task to end testing if peer start fails */
die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &end_badly, "didn't start all
daemons in reasonable amount of time!!!");
+ &end_badly,
+ "didn't start all daemons in
reasonable amount of time!!!");
/* Start num_peers peers, call peers_started_callback on peer start,
topology_callback on peer connect */
/* Read the API documentation for other parameters! */
@@ -545,10 +562,7 @@
NULL,
NULL,
&peers_started_callback,
- NULL,
- &topology_callback,
- NULL,
- NULL);
+ NULL, &topology_callback, NULL, NULL);
}
@@ -556,10 +570,11 @@
check ()
{
int ret;
+
/* Arguments for GNUNET_PROGRAM_run */
- char *const argv[] = {"test-dht-twopeer-put-get", /* Name to give running
binary */
+ char *const argv[] = { "test-dht-twopeer-put-get", /* Name to give
running binary */
"-c",
- "test_dht_twopeer_data.conf", /* Config file to use */
+ "test_dht_twopeer_data.conf", /* Config file to use */
#if VERBOSE
"-L", "DEBUG",
#endif
@@ -570,12 +585,13 @@
};
/* Run the run function as a new program */
ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
- argv, "test-dht-twopeer-put-get", "nohelp",
- options, &run, &ok);
+ argv, "test-dht-twopeer-put-get", "nohelp",
+ options, &run, &ok);
if (ret != GNUNET_OK)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "`test-dht-twopeer': Failed with
error code %d\n", ret);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "`test-dht-twopeer': Failed with error code %d\n", ret);
+ }
return ok;
}
@@ -597,9 +613,10 @@
* of by the testing framework.
*/
if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to remove testing
directory %s\n", test_directory);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to remove testing directory %s\n", test_directory);
+ }
return ret;
}
Modified: gnunet/src/dht/test_dhtlog.c
===================================================================
--- gnunet/src/dht/test_dhtlog.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/dht/test_dhtlog.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -37,7 +37,7 @@
* Actual test of the service operations
*/
static int
-test (struct GNUNET_DHTLOG_Handle * api)
+test (struct GNUNET_DHTLOG_Handle *api)
{
struct GNUNET_PeerIdentity p1;
struct GNUNET_PeerIdentity p2;
@@ -53,6 +53,7 @@
unsigned long long nodeuid = 0;
unsigned long long internaluid = 1010223344LL;
unsigned long long dhtkeyuid = 0;
+
memset (&p1.hashPubKey, 3, sizeof (GNUNET_HashCode));
memset (&p2.hashPubKey, 4, sizeof (GNUNET_HashCode));
memset (&p3.hashPubKey, 5, sizeof (GNUNET_HashCode));
@@ -60,7 +61,7 @@
memset (&k1, 0, sizeof (GNUNET_HashCode));
memset (&k2, 1, sizeof (GNUNET_HashCode));
- memset(&trial_info, 0, sizeof(struct GNUNET_DHTLOG_TrialInfo));
+ memset (&trial_info, 0, sizeof (struct GNUNET_DHTLOG_TrialInfo));
trial_info.other_identifier = 777;
trial_info.num_nodes = i;
trial_info.topology = 5;
@@ -83,107 +84,110 @@
trial_info.stop_closest = 1;
trial_info.stop_found = 0;
trial_info.strict_kademlia = 1;
- trial_info.message = GNUNET_strdup("TEST INSERT_TRIAL");
- ret =
- api->insert_trial (&trial_info);
- GNUNET_free(trial_info.message);
- CHECK(ret);
+ trial_info.message = GNUNET_strdup ("TEST INSERT_TRIAL");
+ ret = api->insert_trial (&trial_info);
+ GNUNET_free (trial_info.message);
+ CHECK (ret);
#if VERBOSE
- fprintf(stderr, "Insert trial succeeded!\n");
+ fprintf (stderr, "Insert trial succeeded!\n");
#endif
- ret = api->insert_topology(500);
- CHECK(ret);
+ ret = api->insert_topology (500);
+ CHECK (ret);
#if VERBOSE
- fprintf(stderr, "Insert topology succeeded!\n");
+ fprintf (stderr, "Insert topology succeeded!\n");
#endif
ret = api->insert_node (&nodeuid, &p1);
- CHECK(ret);
+ CHECK (ret);
ret = api->insert_node (&nodeuid, &p2);
- CHECK(ret);
+ CHECK (ret);
ret = api->insert_node (&nodeuid, &p3);
- CHECK(ret);
+ CHECK (ret);
ret = api->insert_node (&nodeuid, &p4);
- CHECK(ret);
+ CHECK (ret);
#if VERBOSE
- fprintf(stderr, "Insert node succeeded!\n");
+ fprintf (stderr, "Insert node succeeded!\n");
#endif
- ret = api->set_malicious(&p1);
- CHECK(ret);
+ ret = api->set_malicious (&p1);
+ CHECK (ret);
#if VERBOSE
- fprintf(stderr, "Set malicious succeeded!\n");
+ fprintf (stderr, "Set malicious succeeded!\n");
#endif
- ret = api->insert_topology(0);
- CHECK(ret);
+ ret = api->insert_topology (0);
+ CHECK (ret);
#if VERBOSE
- fprintf(stderr, "Insert topology succeeded!\n");
+ fprintf (stderr, "Insert topology succeeded!\n");
#endif
- ret = api->insert_extended_topology(&p1, &p2);
- CHECK(ret);
- ret = api->insert_extended_topology(&p3, &p4);
- CHECK(ret);
+ ret = api->insert_extended_topology (&p1, &p2);
+ CHECK (ret);
+ ret = api->insert_extended_topology (&p3, &p4);
+ CHECK (ret);
#if VERBOSE
- fprintf(stderr, "Insert extended topology succeeded!\n");
+ fprintf (stderr, "Insert extended topology succeeded!\n");
#endif
- ret = api->update_topology(101);
- CHECK(ret);
+ ret = api->update_topology (101);
+ CHECK (ret);
#if VERBOSE
- fprintf(stderr, "Update topology succeeded!\n");
+ fprintf (stderr, "Update topology succeeded!\n");
#endif
ret = api->insert_dhtkey (&dhtkeyuid, &k1);
- CHECK(ret);
+ CHECK (ret);
ret = api->insert_dhtkey (&dhtkeyuid, &k2);
- CHECK(ret);
+ CHECK (ret);
#if VERBOSE
- fprintf(stderr, "Insert dhtkey succeeded!\n");
+ fprintf (stderr, "Insert dhtkey succeeded!\n");
#endif
ret = api->insert_query (&sqlqueryuid, internaluid, 2, 4, 0, &p2, &k1);
- CHECK(ret);
+ CHECK (ret);
#if VERBOSE
- fprintf(stderr, "Insert query succeeded!\n");
+ fprintf (stderr, "Insert query succeeded!\n");
#endif
ret =
- api->insert_route (&sqlrouteuid, sqlqueryuid, 1, 1, DHTLOG_GET, &p1, &k2,
- &p4, &p3);
- CHECK(ret);
+ api->insert_route (&sqlrouteuid, sqlqueryuid, 1, 1, DHTLOG_GET, &p1, &k2,
+ &p4, &p3);
+ CHECK (ret);
ret =
- api->insert_route (&sqlrouteuid, sqlqueryuid, 2, 0, DHTLOG_PUT, &p3, &k1,
- &p4, &p2);
- CHECK(ret);
+ api->insert_route (&sqlrouteuid, sqlqueryuid, 2, 0, DHTLOG_PUT, &p3, &k1,
+ &p4, &p2);
+ CHECK (ret);
ret =
- api->insert_route (&sqlrouteuid, sqlqueryuid, 3, 1, DHTLOG_ROUTE, &p3, &k2,
- &p2, NULL);
- CHECK(ret);
+ api->insert_route (&sqlrouteuid, sqlqueryuid, 3, 1, DHTLOG_ROUTE, &p3,
+ &k2, &p2, NULL);
+ CHECK (ret);
ret =
- api->insert_route (&sqlrouteuid, sqlqueryuid, 4, 7, DHTLOG_ROUTE, &p3, &k2,
- NULL, NULL);
- CHECK(ret);
+ api->insert_route (&sqlrouteuid, sqlqueryuid, 4, 7, DHTLOG_ROUTE, &p3,
+ &k2, NULL, NULL);
+ CHECK (ret);
#if VERBOSE
- fprintf(stderr, "Insert route succeeded!\n");
+ fprintf (stderr, "Insert route succeeded!\n");
#endif
sleep (1);
- ret = api->insert_stat(&p1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17);
- CHECK(ret);
- ret = api->insert_stat(&p2, 12, 23, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27);
- CHECK(ret);
+ ret =
+ api->insert_stat (&p1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16,
+ 17);
+ CHECK (ret);
+ ret =
+ api->insert_stat (&p2, 12, 23, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
24,
+ 25, 26, 27);
+ CHECK (ret);
#if VERBOSE
- fprintf(stderr, "Insert stat succeeded!\n");
+ fprintf (stderr, "Insert stat succeeded!\n");
#endif
ret = api->update_trial (787);
- CHECK(ret);
+ CHECK (ret);
#if VERBOSE
- fprintf(stderr, "Update trial succeeded!\n");
+ fprintf (stderr, "Update trial succeeded!\n");
#endif
ret = api->add_generic_stat (&p2, "nonsense", "section", 77765);
- CHECK(ret);
+ CHECK (ret);
#if VERBOSE
- fprintf(stderr, "Insert generic stat succeeded!\n");
+ fprintf (stderr, "Insert generic stat succeeded!\n");
#endif
- ret = api->insert_round(401, 507);
- CHECK(ret);
- ret = api->insert_round_details(402, 507, 1123, 985);
- CHECK(ret);
+ ret = api->insert_round (401, 507);
+ CHECK (ret);
+ ret = api->insert_round_details (402, 507, 1123, 985);
+ CHECK (ret);
#if VERBOSE
- fprintf(stderr, "Insert round succeeded!\n");
+ fprintf (stderr, "Insert round succeeded!\n");
#endif
return 0;
}
@@ -193,21 +197,21 @@
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
struct GNUNET_DHTLOG_Handle *api;
+
ok = 0;
api = GNUNET_DHTLOG_connect (cfg);
if (api == NULL)
- {
- ok = 1;
- return;
- }
- ok = test(api);
+ {
+ ok = 1;
+ return;
+ }
+ ok = test (api);
- GNUNET_DHTLOG_disconnect(api);
+ GNUNET_DHTLOG_disconnect (api);
}
@@ -226,8 +230,7 @@
GNUNET_GETOPT_OPTION_END
};
GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
- argv, "test-dhtlog-api", "nohelp",
- options, &run, NULL);
+ argv, "test-dhtlog-api", "nohelp", options, &run, NULL);
if (ok != 0)
fprintf (stderr, "Test failed with error code: %d\n", ok);
return ok;
Modified: gnunet/src/dv/dv.h
===================================================================
--- gnunet/src/dv/dv.h 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/dv/dv.h 2011-08-15 21:46:35 UTC (rev 16581)
@@ -37,8 +37,8 @@
#define DEBUG_MESSAGE_DROP GNUNET_NO
typedef void (*GNUNET_DV_MessageReceivedHandler) (void *cls,
- struct GNUNET_PeerIdentity
*sender,
- char *msg,
+ struct GNUNET_PeerIdentity *
+ sender, char *msg,
size_t msg_len,
uint32_t distance,
char *sender_address,
@@ -257,16 +257,17 @@
} p2p_dv_MESSAGE_Disconnect;
-struct GNUNET_DV_Handle *
-GNUNET_DV_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
- GNUNET_DV_MessageReceivedHandler receive_handler,
- void *receive_handler_cls);
+struct GNUNET_DV_Handle *GNUNET_DV_connect (const struct
+ GNUNET_CONFIGURATION_Handle *cfg,
+ GNUNET_DV_MessageReceivedHandler
+ receive_handler,
+ void *receive_handler_cls);
/**
* Disconnect from the DV service
*
* @param handle the current handle to the service to disconnect
*/
-void GNUNET_DV_disconnect(struct GNUNET_DV_Handle *handle);
+void GNUNET_DV_disconnect (struct GNUNET_DV_Handle *handle);
#endif
Modified: gnunet/src/dv/dv_api.c
===================================================================
--- gnunet/src/dv/dv_api.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/dv/dv_api.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -152,11 +152,10 @@
* @param hash set to uid (extended with zeros)
*/
static void
-hash_from_uid (uint32_t uid,
- GNUNET_HashCode *hash)
+hash_from_uid (uint32_t uid, GNUNET_HashCode * hash)
{
- memset (hash, 0, sizeof(GNUNET_HashCode));
- *((uint32_t*)hash) = uid;
+ memset (hash, 0, sizeof (GNUNET_HashCode));
+ *((uint32_t *) hash) = uid;
}
/**
@@ -181,7 +180,7 @@
return GNUNET_NO;
}
-static void process_pending_message(struct GNUNET_DV_Handle *handle);
+static void process_pending_message (struct GNUNET_DV_Handle *handle);
/**
* Send complete, schedule next
@@ -193,10 +192,11 @@
finish (struct GNUNET_DV_Handle *handle, int code)
{
struct PendingMessages *pos = handle->current;
+
handle->current = NULL;
process_pending_message (handle);
- GNUNET_free(pos->msg);
+ GNUNET_free (pos->msg);
GNUNET_free (pos);
}
@@ -218,31 +218,35 @@
#if DEBUG_DV
if (handle->current != NULL)
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DV API: Transmit pending called with
message type %d\n", ntohs(handle->current->msg->header.type));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "DV API: Transmit pending called with message type %d\n",
+ ntohs (handle->current->msg->header.type));
#endif
if (buf == NULL)
- {
+ {
#if DEBUG_DV
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DV API: Transmit pending
FAILED!\n\n\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "DV API: Transmit pending FAILED!\n\n\n");
#endif
- finish(handle, GNUNET_SYSERR);
- return 0;
- }
+ finish (handle, GNUNET_SYSERR);
+ return 0;
+ }
handle->th = NULL;
ret = 0;
if (handle->current != NULL)
{
- tsize = ntohs(handle->current->msg->header.size);
+ tsize = ntohs (handle->current->msg->header.size);
if (size >= tsize)
{
- memcpy(buf, handle->current->msg, tsize);
+ memcpy (buf, handle->current->msg, tsize);
#if DEBUG_DV
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DV API: Copied %d bytes into
buffer!\n\n\n", tsize);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "DV API: Copied %d bytes into buffer!\n\n\n", tsize);
#endif
- finish(handle, GNUNET_OK);
+ finish (handle, GNUNET_OK);
return tsize;
}
@@ -256,39 +260,44 @@
*
* @param handle handle to the distance vector service
*/
-static void process_pending_message(struct GNUNET_DV_Handle *handle)
+static void
+process_pending_message (struct GNUNET_DV_Handle *handle)
{
if (handle->current != NULL)
return; /* action already pending */
if (GNUNET_YES != try_connect (handle))
- {
- finish (handle, GNUNET_SYSERR);
- return;
- }
+ {
+ finish (handle, GNUNET_SYSERR);
+ return;
+ }
/* schedule next action */
handle->current = handle->pending_list;
if (NULL == handle->current)
- {
- return;
- }
+ {
+ return;
+ }
handle->pending_list = handle->pending_list->next;
handle->current->next = NULL;
if (NULL ==
(handle->th = GNUNET_CLIENT_notify_transmit_ready (handle->client,
-
ntohs(handle->current->msg->header.size),
-
handle->current->msg->timeout,
+ ntohs
+ (handle->current->
+ msg->header.size),
+ handle->current->
+ msg->timeout,
GNUNET_YES,
- &transmit_pending,
handle)))
- {
+ &transmit_pending,
+ handle)))
+ {
#if DEBUG_DV
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Failed to transmit request to dv service.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to transmit request to dv service.\n");
#endif
- finish (handle, GNUNET_SYSERR);
- }
+ finish (handle, GNUNET_SYSERR);
+ }
}
/**
@@ -297,31 +306,32 @@
* @param handle handle to the specified DV api
* @param msg the message to add to the list
*/
-static void add_pending(struct GNUNET_DV_Handle *handle, struct
GNUNET_DV_SendMessage *msg)
+static void
+add_pending (struct GNUNET_DV_Handle *handle, struct GNUNET_DV_SendMessage
*msg)
{
struct PendingMessages *new_message;
struct PendingMessages *pos;
struct PendingMessages *last;
- new_message = GNUNET_malloc(sizeof(struct PendingMessages));
+ new_message = GNUNET_malloc (sizeof (struct PendingMessages));
new_message->msg = msg;
if (handle->pending_list != NULL)
+ {
+ pos = handle->pending_list;
+ while (pos != NULL)
{
- pos = handle->pending_list;
- while(pos != NULL)
- {
- last = pos;
- pos = pos->next;
- }
- last->next = new_message;
+ last = pos;
+ pos = pos->next;
}
+ last->next = new_message;
+ }
else
- {
- handle->pending_list = new_message;
- }
+ {
+ handle->pending_list = new_message;
+ }
- process_pending_message(handle);
+ process_pending_message (handle);
}
/**
@@ -331,8 +341,8 @@
* @param cls the handle to the DV API
* @param msg the message that was received
*/
-void handle_message_receipt (void *cls,
- const struct GNUNET_MessageHeader * msg)
+void
+handle_message_receipt (void *cls, const struct GNUNET_MessageHeader *msg)
{
struct GNUNET_DV_Handle *handle = cls;
struct GNUNET_DV_MessageReceived *received_msg;
@@ -348,65 +358,75 @@
if (msg == NULL)
{
#if DEBUG_DV_MESSAGES
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DV_API receive: connection closed\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "DV_API receive: connection
closed\n");
#endif
- return; /* Connection closed? */
+ return; /* Connection closed? */
}
- GNUNET_assert((ntohs(msg->type) == GNUNET_MESSAGE_TYPE_TRANSPORT_DV_RECEIVE)
|| (ntohs(msg->type) == GNUNET_MESSAGE_TYPE_TRANSPORT_DV_SEND_RESULT));
+ GNUNET_assert ((ntohs (msg->type) ==
GNUNET_MESSAGE_TYPE_TRANSPORT_DV_RECEIVE)
+ || (ntohs (msg->type) ==
+ GNUNET_MESSAGE_TYPE_TRANSPORT_DV_SEND_RESULT));
- switch (ntohs(msg->type))
+ switch (ntohs (msg->type))
{
case GNUNET_MESSAGE_TYPE_TRANSPORT_DV_RECEIVE:
- if (ntohs(msg->size) < sizeof(struct GNUNET_DV_MessageReceived))
+ if (ntohs (msg->size) < sizeof (struct GNUNET_DV_MessageReceived))
return;
- received_msg = (struct GNUNET_DV_MessageReceived *)msg;
- packed_msg_len = ntohl(received_msg->msg_len);
- sender_address_len = ntohs(msg->size) - packed_msg_len - sizeof(struct
GNUNET_DV_MessageReceived);
- GNUNET_assert(sender_address_len > 0);
- sender_address = GNUNET_malloc(sender_address_len);
- memcpy(sender_address, &received_msg[1], sender_address_len);
- packed_msg_start = (char *)&received_msg[1];
- packed_msg = GNUNET_malloc(packed_msg_len);
- memcpy(packed_msg, &packed_msg_start[sender_address_len], packed_msg_len);
+ received_msg = (struct GNUNET_DV_MessageReceived *) msg;
+ packed_msg_len = ntohl (received_msg->msg_len);
+ sender_address_len =
+ ntohs (msg->size) - packed_msg_len -
+ sizeof (struct GNUNET_DV_MessageReceived);
+ GNUNET_assert (sender_address_len > 0);
+ sender_address = GNUNET_malloc (sender_address_len);
+ memcpy (sender_address, &received_msg[1], sender_address_len);
+ packed_msg_start = (char *) &received_msg[1];
+ packed_msg = GNUNET_malloc (packed_msg_len);
+ memcpy (packed_msg, &packed_msg_start[sender_address_len], packed_msg_len);
#if DEBUG_DV_MESSAGES
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DV_API receive: packed message type:
%d or %d\n", ntohs(((struct GNUNET_MessageHeader *)packed_msg)->type), ((struct
GNUNET_MessageHeader *)packed_msg)->type);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DV_API receive: message sender
reported as %s\n", GNUNET_i2s(&received_msg->sender));
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DV_API receive: distance is %u\n",
ntohl(received_msg->distance));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "DV_API receive: packed message type: %d or %d\n",
+ ntohs (((struct GNUNET_MessageHeader *) packed_msg)->type),
+ ((struct GNUNET_MessageHeader *) packed_msg)->type);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "DV_API receive: message sender reported as %s\n",
+ GNUNET_i2s (&received_msg->sender));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "DV_API receive: distance is %u\n",
+ ntohl (received_msg->distance));
#endif
- handle->receive_handler(handle->receive_cls,
- &received_msg->sender,
- packed_msg,
- packed_msg_len,
- ntohl(received_msg->distance),
- sender_address,
- sender_address_len);
+ handle->receive_handler (handle->receive_cls,
+ &received_msg->sender,
+ packed_msg,
+ packed_msg_len,
+ ntohl (received_msg->distance),
+ sender_address, sender_address_len);
- GNUNET_free(sender_address);
+ GNUNET_free (sender_address);
break;
case GNUNET_MESSAGE_TYPE_TRANSPORT_DV_SEND_RESULT:
- if (ntohs(msg->size) < sizeof(struct GNUNET_DV_SendResultMessage))
+ if (ntohs (msg->size) < sizeof (struct GNUNET_DV_SendResultMessage))
return;
- send_result_msg = (struct GNUNET_DV_SendResultMessage *)msg;
- hash_from_uid(ntohl(send_result_msg->uid), &uidhash);
- send_ctx = GNUNET_CONTAINER_multihashmap_get(handle->send_callbacks,
&uidhash);
+ send_result_msg = (struct GNUNET_DV_SendResultMessage *) msg;
+ hash_from_uid (ntohl (send_result_msg->uid), &uidhash);
+ send_ctx =
+ GNUNET_CONTAINER_multihashmap_get (handle->send_callbacks, &uidhash);
if ((send_ctx != NULL) && (send_ctx->cont != NULL))
+ {
+ if (ntohl (send_result_msg->result) == 0)
{
- if (ntohl(send_result_msg->result) == 0)
- {
- send_ctx->cont(send_ctx->cont_cls, &send_ctx->target, GNUNET_OK);
- }
- else
- {
- send_ctx->cont(send_ctx->cont_cls, &send_ctx->target,
GNUNET_SYSERR);
- }
+ send_ctx->cont (send_ctx->cont_cls, &send_ctx->target, GNUNET_OK);
}
- GNUNET_free_non_null(send_ctx);
+ else
+ {
+ send_ctx->cont (send_ctx->cont_cls, &send_ctx->target, GNUNET_SYSERR);
+ }
+ }
+ GNUNET_free_non_null (send_ctx);
break;
default:
break;
@@ -432,48 +452,52 @@
* @param cont_cls closure for continuation
*
*/
-int GNUNET_DV_send (struct GNUNET_DV_Handle *dv_handle,
- const struct GNUNET_PeerIdentity *target,
- const char *msgbuf,
- size_t msgbuf_size,
- unsigned int priority,
- struct GNUNET_TIME_Relative timeout,
- const void *addr,
- size_t addrlen,
- GNUNET_TRANSPORT_TransmitContinuation
- cont, void *cont_cls)
+int
+GNUNET_DV_send (struct GNUNET_DV_Handle *dv_handle,
+ const struct GNUNET_PeerIdentity *target,
+ const char *msgbuf,
+ size_t msgbuf_size,
+ unsigned int priority,
+ struct GNUNET_TIME_Relative timeout,
+ const void *addr,
+ size_t addrlen,
+ GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
{
struct GNUNET_DV_SendMessage *msg;
struct SendCallbackContext *send_ctx;
char *end_of_message;
GNUNET_HashCode uidhash;
int msize;
+
#if DEBUG_DV_MESSAGES
- dv_handle->uid_gen = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG,
UINT32_MAX);
+ dv_handle->uid_gen =
+ GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, UINT32_MAX);
#else
dv_handle->uid_gen++;
#endif
- msize = sizeof(struct GNUNET_DV_SendMessage) + addrlen + msgbuf_size;
- msg = GNUNET_malloc(msize);
- msg->header.size = htons(msize);
- msg->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_DV_SEND);
- memcpy(&msg->target, target, sizeof(struct GNUNET_PeerIdentity));
- msg->priority = htonl(priority);
+ msize = sizeof (struct GNUNET_DV_SendMessage) + addrlen + msgbuf_size;
+ msg = GNUNET_malloc (msize);
+ msg->header.size = htons (msize);
+ msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DV_SEND);
+ memcpy (&msg->target, target, sizeof (struct GNUNET_PeerIdentity));
+ msg->priority = htonl (priority);
msg->timeout = timeout;
- msg->addrlen = htonl(addrlen);
- msg->uid = htonl(dv_handle->uid_gen);
- memcpy(&msg[1], addr, addrlen);
- end_of_message = (char *)&msg[1];
+ msg->addrlen = htonl (addrlen);
+ msg->uid = htonl (dv_handle->uid_gen);
+ memcpy (&msg[1], addr, addrlen);
+ end_of_message = (char *) &msg[1];
end_of_message = &end_of_message[addrlen];
- memcpy(end_of_message, msgbuf, msgbuf_size);
- add_pending(dv_handle, msg);
- send_ctx = GNUNET_malloc(sizeof(struct SendCallbackContext));
+ memcpy (end_of_message, msgbuf, msgbuf_size);
+ add_pending (dv_handle, msg);
+ send_ctx = GNUNET_malloc (sizeof (struct SendCallbackContext));
send_ctx->cont = cont;
send_ctx->cont_cls = cont_cls;
- memcpy(&send_ctx->target, target, sizeof(struct GNUNET_PeerIdentity));
- hash_from_uid(dv_handle->uid_gen, &uidhash);
- GNUNET_CONTAINER_multihashmap_put(dv_handle->send_callbacks, &uidhash,
send_ctx, GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
+ memcpy (&send_ctx->target, target, sizeof (struct GNUNET_PeerIdentity));
+ hash_from_uid (dv_handle->uid_gen, &uidhash);
+ GNUNET_CONTAINER_multihashmap_put (dv_handle->send_callbacks, &uidhash,
+ send_ctx,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
return GNUNET_OK;
}
@@ -494,23 +518,25 @@
struct StartContext *start_context = cls;
struct GNUNET_DV_Handle *handle = start_context->handle;
size_t tsize;
+
#if DEBUG_DV
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DV API: sending start request to
service\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "DV API: sending start request to service\n");
#endif
if (buf == NULL)
- {
- GNUNET_free(start_context->message);
- GNUNET_free(start_context);
- GNUNET_DV_disconnect(handle);
- return 0;
- }
+ {
+ GNUNET_free (start_context->message);
+ GNUNET_free (start_context);
+ GNUNET_DV_disconnect (handle);
+ return 0;
+ }
- tsize = ntohs(start_context->message->size);
+ tsize = ntohs (start_context->message->size);
if (size >= tsize)
{
- memcpy(buf, start_context->message, tsize);
- GNUNET_free(start_context->message);
- GNUNET_free(start_context);
+ memcpy (buf, start_context->message, tsize);
+ GNUNET_free (start_context->message);
+ GNUNET_free (start_context);
GNUNET_CLIENT_receive (handle->client,
&handle_message_receipt,
handle, GNUNET_TIME_UNIT_FOREVER_REL);
@@ -533,42 +559,44 @@
*/
struct GNUNET_DV_Handle *
GNUNET_DV_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
- GNUNET_DV_MessageReceivedHandler receive_handler,
- void *receive_handler_cls)
+ GNUNET_DV_MessageReceivedHandler receive_handler,
+ void *receive_handler_cls)
{
struct GNUNET_DV_Handle *handle;
struct GNUNET_MessageHeader *start_message;
struct StartContext *start_context;
- handle = GNUNET_malloc(sizeof(struct GNUNET_DV_Handle));
+ handle = GNUNET_malloc (sizeof (struct GNUNET_DV_Handle));
+
handle->cfg = cfg;
handle->pending_list = NULL;
handle->current = NULL;
handle->th = NULL;
- handle->client = GNUNET_CLIENT_connect("dv", cfg);
+ handle->client = GNUNET_CLIENT_connect ("dv", cfg);
handle->receive_handler = receive_handler;
handle->receive_cls = receive_handler_cls;
if (handle->client == NULL)
- {
- GNUNET_free(handle);
- return NULL;
- }
+ {
+ GNUNET_free (handle);
+ return NULL;
+ }
- start_message = GNUNET_malloc(sizeof(struct GNUNET_MessageHeader));
- start_message->size = htons(sizeof(struct GNUNET_MessageHeader));
- start_message->type = htons(GNUNET_MESSAGE_TYPE_DV_START);
+ start_message = GNUNET_malloc (sizeof (struct GNUNET_MessageHeader));
+ start_message->size = htons (sizeof (struct GNUNET_MessageHeader));
+ start_message->type = htons (GNUNET_MESSAGE_TYPE_DV_START);
- start_context = GNUNET_malloc(sizeof(struct StartContext));
+ start_context = GNUNET_malloc (sizeof (struct StartContext));
start_context->handle = handle;
start_context->message = start_message;
GNUNET_CLIENT_notify_transmit_ready (handle->client,
- sizeof(struct GNUNET_MessageHeader),
-
GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60),
- GNUNET_YES,
- &transmit_start, start_context);
+ sizeof (struct GNUNET_MessageHeader),
+ GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 60),
+ GNUNET_YES, &transmit_start,
+ start_context);
- handle->send_callbacks = GNUNET_CONTAINER_multihashmap_create(100);
+ handle->send_callbacks = GNUNET_CONTAINER_multihashmap_create (100);
return handle;
}
@@ -578,29 +606,30 @@
*
* @param handle the current handle to the service to disconnect
*/
-void GNUNET_DV_disconnect(struct GNUNET_DV_Handle *handle)
+void
+GNUNET_DV_disconnect (struct GNUNET_DV_Handle *handle)
{
struct PendingMessages *pos;
- GNUNET_assert(handle != NULL);
+ GNUNET_assert (handle != NULL);
- if (handle->th != NULL) /* We have a live transmit request in the Aether */
- {
- GNUNET_CLIENT_notify_transmit_ready_cancel (handle->th);
- handle->th = NULL;
- }
- if (handle->current != NULL) /* We are trying to send something now, clean
it up */
- GNUNET_free(handle->current);
- while (NULL != (pos = handle->pending_list)) /* Remove all pending sends
from the list */
- {
- handle->pending_list = pos->next;
- GNUNET_free(pos);
- }
- if (handle->client != NULL) /* Finally, disconnect from the service */
- {
- GNUNET_CLIENT_disconnect (handle->client, GNUNET_NO);
- handle->client = NULL;
- }
+ if (handle->th != NULL) /* We have a live transmit request in the
Aether */
+ {
+ GNUNET_CLIENT_notify_transmit_ready_cancel (handle->th);
+ handle->th = NULL;
+ }
+ if (handle->current != NULL) /* We are trying to send something now, clean
it up */
+ GNUNET_free (handle->current);
+ while (NULL != (pos = handle->pending_list)) /* Remove all pending sends
from the list */
+ {
+ handle->pending_list = pos->next;
+ GNUNET_free (pos);
+ }
+ if (handle->client != NULL) /* Finally, disconnect from the service */
+ {
+ GNUNET_CLIENT_disconnect (handle->client, GNUNET_NO);
+ handle->client = NULL;
+ }
GNUNET_free (handle);
}
Modified: gnunet/src/dv/gnunet-service-dv.c
===================================================================
--- gnunet/src/dv/gnunet-service-dv.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/dv/gnunet-service-dv.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -158,7 +158,7 @@
/**
* Actual message to be sent; // avoid allocation
*/
- const struct GNUNET_MessageHeader *msg; // msg = (cast) &pm[1]; // memcpy
(&pm[1], data, len);
+ const struct GNUNET_MessageHeader *msg; // msg = (cast) &pm[1]; //
memcpy (&pm[1], data, len);
};
@@ -568,7 +568,7 @@
* this client will never change, although if the plugin dies
* and returns for some reason it may happen.
*/
-static struct GNUNET_SERVER_Client * client_handle;
+static struct GNUNET_SERVER_Client *client_handle;
/**
* Task to run when we shut down, cleaning up all our trash
@@ -582,7 +582,7 @@
/**
* Transmit handle to the plugin.
*/
-static struct GNUNET_CONNECTION_TransmitHandle * plugin_transmit_handle;
+static struct GNUNET_CONNECTION_TransmitHandle *plugin_transmit_handle;
/**
* Head of DLL for client messages
@@ -602,7 +602,7 @@
/**
* Transmit handle to core service.
*/
-static struct GNUNET_CORE_TransmitHandle * core_transmit_handle;
+static struct GNUNET_CORE_TransmitHandle *core_transmit_handle;
/**
* Head of DLL for core messages
@@ -682,18 +682,18 @@
* respective neighbor.
*/
static int
-find_specific_id (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+find_specific_id (void *cls, const GNUNET_HashCode * key, void *value)
{
struct FindIDContext *fdc = cls;
struct DistantNeighbor *dn = value;
- if (memcmp(&dn->referrer->identity, fdc->via, sizeof(struct
GNUNET_PeerIdentity)) == 0)
- {
- fdc->tid = dn->referrer_id;
- return GNUNET_NO;
- }
+ if (memcmp
+ (&dn->referrer->identity, fdc->via,
+ sizeof (struct GNUNET_PeerIdentity)) == 0)
+ {
+ fdc->tid = dn->referrer_id;
+ return GNUNET_NO;
+ }
return GNUNET_YES;
}
@@ -704,18 +704,17 @@
* want to remove those that may be accessible via a different
* route.
*/
-static int find_distant_peer (void *cls,
- const GNUNET_HashCode * key,
- void *value)
+static int
+find_distant_peer (void *cls, const GNUNET_HashCode * key, void *value)
{
struct FindDestinationContext *fdc = cls;
struct DistantNeighbor *distant = value;
if (fdc->tid == distant->referrer_id)
- {
- fdc->dest = distant;
- return GNUNET_NO;
- }
+ {
+ fdc->dest = distant;
+ return GNUNET_NO;
+ }
return GNUNET_YES;
}
@@ -730,8 +729,8 @@
* @param buf where the callee should write the message
* @return number of bytes written to buf
*/
-size_t transmit_to_plugin (void *cls,
- size_t size, void *buf)
+size_t
+transmit_to_plugin (void *cls, size_t size, void *buf)
{
char *cbuf = buf;
struct PendingMessage *reply;
@@ -739,31 +738,35 @@
size_t msize;
if (buf == NULL)
- {
- /* client disconnected */
+ {
+ /* client disconnected */
#if DEBUG_DV_MESSAGES
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s: %s buffer was NULL (client
disconnect?)\n", my_short_id, "transmit_to_plugin");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "%s: %s buffer was NULL (client disconnect?)\n", my_short_id,
+ "transmit_to_plugin");
#endif
- return 0;
- }
+ return 0;
+ }
plugin_transmit_handle = NULL;
off = 0;
- while ( (NULL != (reply = plugin_pending_head)) &&
- (size >= off + (msize = ntohs (reply->msg->size))))
- {
- GNUNET_CONTAINER_DLL_remove (plugin_pending_head,
- plugin_pending_tail,
- reply);
- memcpy (&cbuf[off], reply->msg, msize);
- GNUNET_free (reply);
- off += msize;
- }
+ while ((NULL != (reply = plugin_pending_head)) &&
+ (size >= off + (msize = ntohs (reply->msg->size))))
+ {
+ GNUNET_CONTAINER_DLL_remove (plugin_pending_head,
+ plugin_pending_tail, reply);
+ memcpy (&cbuf[off], reply->msg, msize);
+ GNUNET_free (reply);
+ off += msize;
+ }
if (plugin_pending_head != NULL)
plugin_transmit_handle = GNUNET_SERVER_notify_transmit_ready
(client_handle,
-
ntohs(plugin_pending_head->msg->size),
+ ntohs
+
(plugin_pending_head->msg->
+ size),
GNUNET_TIME_UNIT_FOREVER_REL,
-
&transmit_to_plugin, NULL);
+
&transmit_to_plugin,
+ NULL);
return off;
}
@@ -778,11 +781,11 @@
* @param distant_neighbor the original sender of the message
* @param cost the cost to the original sender of the message
*/
-void send_to_plugin(const struct GNUNET_PeerIdentity * sender,
- const struct GNUNET_MessageHeader *message,
- size_t message_size,
- struct GNUNET_PeerIdentity *distant_neighbor,
- size_t cost)
+void
+send_to_plugin (const struct GNUNET_PeerIdentity *sender,
+ const struct GNUNET_MessageHeader *message,
+ size_t message_size,
+ struct GNUNET_PeerIdentity *distant_neighbor, size_t cost)
{
struct GNUNET_DV_MessageReceived *received_msg;
struct PendingMessage *pending_message;
@@ -792,85 +795,96 @@
int size;
#if DEBUG_DV
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "send_to_plugin called with peer %s as
sender\n", GNUNET_i2s(distant_neighbor));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "send_to_plugin called with peer %s as sender\n",
+ GNUNET_i2s (distant_neighbor));
#endif
- if (memcmp(sender, distant_neighbor, sizeof(struct GNUNET_PeerIdentity)) !=
0)
+ if (memcmp (sender, distant_neighbor, sizeof (struct GNUNET_PeerIdentity)) !=
+ 0)
{
- sender_address_len = sizeof(struct GNUNET_PeerIdentity) * 2;
- sender_address = GNUNET_malloc(sender_address_len);
- memcpy(sender_address, distant_neighbor, sizeof(struct
GNUNET_PeerIdentity));
- memcpy(&sender_address[sizeof(struct GNUNET_PeerIdentity)], sender,
sizeof(struct GNUNET_PeerIdentity));
+ sender_address_len = sizeof (struct GNUNET_PeerIdentity) * 2;
+ sender_address = GNUNET_malloc (sender_address_len);
+ memcpy (sender_address, distant_neighbor,
+ sizeof (struct GNUNET_PeerIdentity));
+ memcpy (&sender_address[sizeof (struct GNUNET_PeerIdentity)], sender,
+ sizeof (struct GNUNET_PeerIdentity));
}
else
{
- sender_address_len = sizeof(struct GNUNET_PeerIdentity);
- sender_address = GNUNET_malloc(sender_address_len);
- memcpy(sender_address, sender, sizeof(struct GNUNET_PeerIdentity));
+ sender_address_len = sizeof (struct GNUNET_PeerIdentity);
+ sender_address = GNUNET_malloc (sender_address_len);
+ memcpy (sender_address, sender, sizeof (struct GNUNET_PeerIdentity));
}
- size = sizeof(struct GNUNET_DV_MessageReceived) + sender_address_len +
message_size;
- received_msg = GNUNET_malloc(size);
- received_msg->header.size = htons(size);
- received_msg->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_DV_RECEIVE);
- received_msg->distance = htonl(cost);
- received_msg->msg_len = htonl(message_size);
+ size =
+ sizeof (struct GNUNET_DV_MessageReceived) + sender_address_len +
+ message_size;
+ received_msg = GNUNET_malloc (size);
+ received_msg->header.size = htons (size);
+ received_msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DV_RECEIVE);
+ received_msg->distance = htonl (cost);
+ received_msg->msg_len = htonl (message_size);
/* Set the sender in this message to be the original sender! */
- memcpy(&received_msg->sender, distant_neighbor, sizeof(struct
GNUNET_PeerIdentity));
+ memcpy (&received_msg->sender, distant_neighbor,
+ sizeof (struct GNUNET_PeerIdentity));
/* Copy the intermediate sender to the end of the message, this is how the
transport identifies this peer */
- memcpy(&received_msg[1], sender_address, sender_address_len);
- GNUNET_free(sender_address);
+ memcpy (&received_msg[1], sender_address, sender_address_len);
+ GNUNET_free (sender_address);
/* Copy the actual message after the sender */
- packed_msg_start = (char *)&received_msg[1];
+ packed_msg_start = (char *) &received_msg[1];
packed_msg_start = &packed_msg_start[sender_address_len];
- memcpy(packed_msg_start, message, message_size);
- pending_message = GNUNET_malloc(sizeof(struct PendingMessage) + size);
- pending_message->msg = (struct GNUNET_MessageHeader *)&pending_message[1];
- memcpy(&pending_message[1], received_msg, size);
- GNUNET_free(received_msg);
+ memcpy (packed_msg_start, message, message_size);
+ pending_message = GNUNET_malloc (sizeof (struct PendingMessage) + size);
+ pending_message->msg = (struct GNUNET_MessageHeader *) &pending_message[1];
+ memcpy (&pending_message[1], received_msg, size);
+ GNUNET_free (received_msg);
- GNUNET_CONTAINER_DLL_insert_after(plugin_pending_head, plugin_pending_tail,
plugin_pending_tail, pending_message);
+ GNUNET_CONTAINER_DLL_insert_after (plugin_pending_head, plugin_pending_tail,
+ plugin_pending_tail, pending_message);
if (client_handle != NULL)
+ {
+ if (plugin_transmit_handle == NULL)
{
- if (plugin_transmit_handle == NULL)
- {
- plugin_transmit_handle = GNUNET_SERVER_notify_transmit_ready
(client_handle,
- size,
GNUNET_TIME_UNIT_FOREVER_REL,
-
&transmit_to_plugin, NULL);
- }
+ plugin_transmit_handle =
+ GNUNET_SERVER_notify_transmit_ready (client_handle, size,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &transmit_to_plugin, NULL);
}
+ }
else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to queue message for
plugin, client_handle not yet set (how?)!\n");
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to queue message for plugin, client_handle not yet set
(how?)!\n");
+ }
}
/* Declare here so retry_core_send is aware of it */
-size_t core_transmit_notify (void *cls,
- size_t size, void *buf);
+size_t core_transmit_notify (void *cls, size_t size, void *buf);
/**
* Try to send another message from our core sending list
*/
static void
-try_core_send (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+try_core_send (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct PendingMessage *pending;
+
pending = core_pending_head;
if (core_transmit_handle != NULL)
- return; /* Message send already in progress */
+ return; /* Message send already in progress */
if ((pending != NULL) && (coreAPI != NULL))
core_transmit_handle = GNUNET_CORE_notify_transmit_ready (coreAPI,
- GNUNET_YES,
-
pending->importance,
- pending->timeout,
-
&pending->recipient,
- pending->msg_size,
-
&core_transmit_notify, NULL);
+ GNUNET_YES,
+
pending->importance,
+ pending->timeout,
+
&pending->recipient,
+
pending->msg_size,
+
&core_transmit_notify,
+ NULL);
}
@@ -885,8 +899,8 @@
* @param buf where the callee should write the message
* @return number of bytes written to buf
*/
-size_t core_transmit_notify (void *cls,
- size_t size, void *buf)
+size_t
+core_transmit_notify (void *cls, size_t size, void *buf)
{
char *cbuf = buf;
struct PendingMessage *pending;
@@ -895,58 +909,65 @@
size_t msize;
if (buf == NULL)
- {
- /* client disconnected */
+ {
+ /* client disconnected */
#if DEBUG_DV
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s': buffer was NULL\n", "DHT");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s': buffer was NULL\n", "DHT");
#endif
- return 0;
- }
+ return 0;
+ }
core_transmit_handle = NULL;
off = 0;
pending = core_pending_head;
- if ( (pending != NULL) &&
- (size >= (msize = ntohs (pending->msg->size))))
- {
+ if ((pending != NULL) && (size >= (msize = ntohs (pending->msg->size))))
+ {
#if DEBUG_DV
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "`%s' : transmit_notify (core)
called with size %d\n", "dv service", msize);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "`%s' : transmit_notify (core) called with size %d\n",
+ "dv service", msize);
#endif
- GNUNET_CONTAINER_DLL_remove (core_pending_head,
- core_pending_tail,
- pending);
- if (pending->send_result != NULL) /* Will only be non-null if a real
client asked for this send */
+ GNUNET_CONTAINER_DLL_remove (core_pending_head, core_pending_tail,
pending);
+ if (pending->send_result != NULL) /* Will only be non-null if a real
client asked for this send */
+ {
+ client_reply =
+ GNUNET_malloc (sizeof (struct PendingMessage) +
+ sizeof (struct GNUNET_DV_SendResultMessage));
+ client_reply->msg = (struct GNUNET_MessageHeader *) &client_reply[1];
+ memcpy (&client_reply[1], pending->send_result,
+ sizeof (struct GNUNET_DV_SendResultMessage));
+ GNUNET_free (pending->send_result);
+
+ GNUNET_CONTAINER_DLL_insert_after (plugin_pending_head,
+ plugin_pending_tail,
+ plugin_pending_tail, client_reply);
+ if (client_handle != NULL)
+ {
+ if (plugin_transmit_handle == NULL)
{
- client_reply = GNUNET_malloc(sizeof(struct PendingMessage) +
sizeof(struct GNUNET_DV_SendResultMessage));
- client_reply->msg = (struct GNUNET_MessageHeader *)&client_reply[1];
- memcpy(&client_reply[1], pending->send_result, sizeof(struct
GNUNET_DV_SendResultMessage));
- GNUNET_free(pending->send_result);
-
- GNUNET_CONTAINER_DLL_insert_after(plugin_pending_head,
plugin_pending_tail, plugin_pending_tail, client_reply);
- if (client_handle != NULL)
- {
- if (plugin_transmit_handle == NULL)
- {
- plugin_transmit_handle = GNUNET_SERVER_notify_transmit_ready
(client_handle,
-
sizeof(struct GNUNET_DV_SendResultMessage),
-
GNUNET_TIME_UNIT_FOREVER_REL,
-
&transmit_to_plugin, NULL);
- }
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to queue
message for plugin, must be one in progress already!!\n");
- }
- }
+ plugin_transmit_handle =
+ GNUNET_SERVER_notify_transmit_ready (client_handle,
+ sizeof (struct
+
GNUNET_DV_SendResultMessage),
+
GNUNET_TIME_UNIT_FOREVER_REL,
+ &transmit_to_plugin, NULL);
}
- memcpy (&cbuf[off], pending->msg, msize);
- GNUNET_free (pending);
- off += msize;
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to queue message for plugin, must be one in
progress already!!\n");
+ }
+ }
}
- /*reply = core_pending_head;*/
+ memcpy (&cbuf[off], pending->msg, msize);
+ GNUNET_free (pending);
+ off += msize;
+ }
+ /*reply = core_pending_head; */
- GNUNET_SCHEDULER_add_now(&try_core_send, NULL);
+ GNUNET_SCHEDULER_add_now (&try_core_send, NULL);
/*if (reply != NULL)
- core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI,
GNUNET_YES, reply->importance, reply->timeout, &reply->recipient,
reply->msg_size, &core_transmit_notify, NULL);*/
+ * core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI,
GNUNET_YES, reply->importance, reply->timeout, &reply->recipient,
reply->msg_size, &core_transmit_notify, NULL); */
return off;
}
@@ -971,6 +992,7 @@
struct DistantNeighbor *source;
struct PendingMessage *pending_message;
struct FindIDContext find_context;
+
#if DEBUG_DV
char shortname[5];
#endif
@@ -980,70 +1002,76 @@
find_context.dest = send_context->distant_peer;
find_context.via = recipient;
find_context.tid = 0;
- GNUNET_CONTAINER_multihashmap_get_multiple (extended_neighbors,
&send_context->distant_peer->hashPubKey,
+ GNUNET_CONTAINER_multihashmap_get_multiple (extended_neighbors,
+ &send_context->
+ distant_peer->hashPubKey,
&find_specific_id,
&find_context);
if (find_context.tid == 0)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s: find_specific_id failed to
find peer!\n", my_short_id);
- /* target unknown to us, drop! */
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "%s: find_specific_id failed to find peer!\n", my_short_id);
+ /* target unknown to us, drop! */
+ return GNUNET_SYSERR;
+ }
recipient_id = find_context.tid;
- if (0 == (memcmp (&my_identity,
- sender, sizeof (struct GNUNET_PeerIdentity))))
+ if (0 == (memcmp (&my_identity, sender, sizeof (struct
GNUNET_PeerIdentity))))
{
sender_id = 0;
source = GNUNET_CONTAINER_multihashmap_get (extended_neighbors,
- &sender->hashPubKey);
+ &sender->hashPubKey);
if (source != NULL)
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s: send_message_via found %s,
myself in extended peer list???\n", my_short_id, GNUNET_i2s(&source->identity));
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "%s: send_message_via found %s, myself in extended peer
list???\n",
+ my_short_id, GNUNET_i2s (&source->identity));
}
else
{
source = GNUNET_CONTAINER_multihashmap_get (extended_neighbors,
&sender->hashPubKey);
if (source == NULL)
- {
- /* sender unknown to us, drop! */
- return GNUNET_SYSERR;
- }
+ {
+ /* sender unknown to us, drop! */
+ return GNUNET_SYSERR;
+ }
sender_id = source->our_id;
}
- pending_message = GNUNET_malloc(sizeof(struct PendingMessage) + msg_size);
- pending_message->msg = (struct GNUNET_MessageHeader *)&pending_message[1];
+ pending_message = GNUNET_malloc (sizeof (struct PendingMessage) + msg_size);
+ pending_message->msg = (struct GNUNET_MessageHeader *) &pending_message[1];
pending_message->send_result = send_context->send_result;
- memcpy(&pending_message->recipient, recipient, sizeof(struct
GNUNET_PeerIdentity));
+ memcpy (&pending_message->recipient, recipient,
+ sizeof (struct GNUNET_PeerIdentity));
pending_message->msg_size = msg_size;
pending_message->importance = send_context->importance;
pending_message->timeout = send_context->timeout;
- toSend = (p2p_dv_MESSAGE_Data *)pending_message->msg;
+ toSend = (p2p_dv_MESSAGE_Data *) pending_message->msg;
toSend->header.size = htons (msg_size);
toSend->header.type = htons (GNUNET_MESSAGE_TYPE_DV_DATA);
toSend->sender = htonl (sender_id);
toSend->recipient = htonl (recipient_id);
#if DEBUG_DV_MESSAGES
- toSend->uid = send_context->uid; /* Still sent around in network byte order
*/
+ toSend->uid = send_context->uid; /* Still sent around in network byte
order */
#else
- toSend->uid = htonl(0);
+ toSend->uid = htonl (0);
#endif
memcpy (&toSend[1], send_context->message, send_context->message_size);
#if DEBUG_DV
- memcpy(&shortname, GNUNET_i2s(send_context->distant_peer), 4);
+ memcpy (&shortname, GNUNET_i2s (send_context->distant_peer), 4);
shortname[4] = '\0';
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: Notifying core of send to
destination `%s' via `%s' size %u\n", "DV", &shortname, GNUNET_i2s(recipient),
msg_size);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "%s: Notifying core of send to destination `%s' via `%s' size
%u\n",
+ "DV", &shortname, GNUNET_i2s (recipient), msg_size);
#endif
GNUNET_CONTAINER_DLL_insert_after (core_pending_head,
core_pending_tail,
- core_pending_tail,
- pending_message);
+ core_pending_tail, pending_message);
- GNUNET_SCHEDULER_add_now(try_core_send, NULL);
+ GNUNET_SCHEDULER_add_now (try_core_send, NULL);
return GNUNET_YES;
}
@@ -1059,17 +1087,15 @@
* @return GNUNET_YES to continue iteration, GNUNET_NO to stop
*/
static int
-find_least_cost_peer (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+find_least_cost_peer (void *cls, const GNUNET_HashCode * key, void *value)
{
struct FindLeastCostContext *find_context = cls;
struct DistantNeighbor *dn = value;
if (dn->cost < find_context->least_cost)
- {
- find_context->target = dn;
- }
+ {
+ find_context->target = dn;
+ }
if (dn->cost == DIRECT_NEIGHBOR_COST)
return GNUNET_NO;
return GNUNET_YES;
@@ -1088,14 +1114,13 @@
* @param timeout how long to possibly delay sending this message
*/
static int
-send_message (const struct GNUNET_PeerIdentity * recipient,
- const struct GNUNET_PeerIdentity * sender,
- const struct DistantNeighbor * specific_neighbor,
- const struct GNUNET_MessageHeader * message,
+send_message (const struct GNUNET_PeerIdentity *recipient,
+ const struct GNUNET_PeerIdentity *sender,
+ const struct DistantNeighbor *specific_neighbor,
+ const struct GNUNET_MessageHeader *message,
size_t message_size,
unsigned int importance,
- unsigned int uid,
- struct GNUNET_TIME_Relative timeout)
+ unsigned int uid, struct GNUNET_TIME_Relative timeout)
{
p2p_dv_MESSAGE_Data *toSend;
unsigned int msg_size;
@@ -1106,6 +1131,7 @@
struct DistantNeighbor *source;
struct PendingMessage *pending_message;
struct FindLeastCostContext find_least_ctx;
+
#if DEBUG_DV_PEER_NUMBERS
struct GNUNET_CRYPTO_HashAsciiEncoded encPeerFrom;
struct GNUNET_CRYPTO_HashAsciiEncoded encPeerTo;
@@ -1122,84 +1148,97 @@
* over all known peers, just those that apply.
*/
GNUNET_CONTAINER_multihashmap_get_multiple (extended_neighbors,
- &recipient->hashPubKey,
&find_least_cost_peer, &find_least_ctx);
+ &recipient->hashPubKey,
+ &find_least_cost_peer,
+ &find_least_ctx);
target = find_least_ctx.target;
if (target == NULL)
- {
- /* target unknown to us, drop! */
- return GNUNET_SYSERR;
- }
+ {
+ /* target unknown to us, drop! */
+ return GNUNET_SYSERR;
+ }
recipient_id = target->referrer_id;
source = GNUNET_CONTAINER_multihashmap_get (extended_neighbors,
&sender->hashPubKey);
if (source == NULL)
+ {
+ if (0 != (memcmp (&my_identity,
+ sender, sizeof (struct GNUNET_PeerIdentity))))
{
- if (0 != (memcmp (&my_identity,
- sender, sizeof (struct GNUNET_PeerIdentity))))
- {
- /* sender unknown to us, drop! */
- return GNUNET_SYSERR;
- }
- sender_id = 0; /* 0 == us */
+ /* sender unknown to us, drop! */
+ return GNUNET_SYSERR;
}
+ sender_id = 0; /* 0 == us */
+ }
else
- {
- /* find out the number that we use when we gossip about
- the sender */
- sender_id = source->our_id;
- }
+ {
+ /* find out the number that we use when we gossip about
+ * the sender */
+ sender_id = source->our_id;
+ }
#if DEBUG_DV_PEER_NUMBERS
GNUNET_CRYPTO_hash_to_enc (&source->identity.hashPubKey, &encPeerFrom);
- GNUNET_CRYPTO_hash_to_enc (&target->referrer->identity.hashPubKey,
&encPeerVia);
+ GNUNET_CRYPTO_hash_to_enc (&target->referrer->identity.hashPubKey,
+ &encPeerVia);
encPeerFrom.encoding[4] = '\0';
encPeerVia.encoding[4] = '\0';
#endif
- if ((sender_id != 0) && (0 == memcmp(&source->identity,
&target->referrer->identity, sizeof(struct GNUNET_PeerIdentity))))
- {
- return 0;
- }
+ if ((sender_id != 0) &&
+ (0 ==
+ memcmp (&source->identity, &target->referrer->identity,
+ sizeof (struct GNUNET_PeerIdentity))))
+ {
+ return 0;
+ }
cost = target->cost;
- pending_message = GNUNET_malloc(sizeof(struct PendingMessage) + msg_size);
- pending_message->msg = (struct GNUNET_MessageHeader *)&pending_message[1];
+ pending_message = GNUNET_malloc (sizeof (struct PendingMessage) + msg_size);
+ pending_message->msg = (struct GNUNET_MessageHeader *) &pending_message[1];
pending_message->send_result = NULL;
pending_message->importance = importance;
pending_message->timeout = timeout;
- memcpy(&pending_message->recipient, &target->referrer->identity,
sizeof(struct GNUNET_PeerIdentity));
+ memcpy (&pending_message->recipient, &target->referrer->identity,
+ sizeof (struct GNUNET_PeerIdentity));
pending_message->msg_size = msg_size;
- toSend = (p2p_dv_MESSAGE_Data *)pending_message->msg;
+ toSend = (p2p_dv_MESSAGE_Data *) pending_message->msg;
toSend->header.size = htons (msg_size);
toSend->header.type = htons (GNUNET_MESSAGE_TYPE_DV_DATA);
toSend->sender = htonl (sender_id);
toSend->recipient = htonl (recipient_id);
#if DEBUG_DV_MESSAGES
- toSend->uid = htonl(uid);
+ toSend->uid = htonl (uid);
#else
- toSend->uid = htonl(0);
+ toSend->uid = htonl (0);
#endif
#if DEBUG_DV_PEER_NUMBERS
GNUNET_CRYPTO_hash_to_enc (&target->identity.hashPubKey, &encPeerTo);
encPeerTo.encoding[4] = '\0';
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: Sending DATA message. Sender id %u,
source %s, destination %s, via %s\n", GNUNET_i2s(&my_identity), sender_id,
&encPeerFrom, &encPeerTo, &encPeerVia);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "%s: Sending DATA message. Sender id %u, source %s, destination
%s, via %s\n",
+ GNUNET_i2s (&my_identity), sender_id, &encPeerFrom, &encPeerTo,
+ &encPeerVia);
#endif
memcpy (&toSend[1], message, message_size);
- if ((source != NULL) && (source->pkey == NULL)) /* Test our hypothesis about
message failures! */
- {
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s: Sending message, but
anticipate recipient will not know sender!!!\n\n\n", my_short_id);
- }
+ if ((source != NULL) && (source->pkey == NULL)) /* Test our hypothesis
about message failures! */
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "%s: Sending message, but anticipate recipient will not know
sender!!!\n\n\n",
+ my_short_id);
+ }
GNUNET_CONTAINER_DLL_insert_after (core_pending_head,
core_pending_tail,
- core_pending_tail,
- pending_message);
+ core_pending_tail, pending_message);
#if DEBUG_DV
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: Notifying core of send size %d to
destination `%s'\n", "DV SEND MESSAGE", msg_size, GNUNET_i2s(recipient));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "%s: Notifying core of send size %d to destination `%s'\n",
+ "DV SEND MESSAGE", msg_size, GNUNET_i2s (recipient));
#endif
- GNUNET_SCHEDULER_add_now(try_core_send, NULL);
+ GNUNET_SCHEDULER_add_now (try_core_send, NULL);
return (int) cost;
}
@@ -1227,14 +1266,13 @@
* iterate,
* GNUNET_NO if not.
*/
-int checkPeerID (void *cls,
- const GNUNET_HashCode * key,
- void *value)
+int
+checkPeerID (void *cls, const GNUNET_HashCode * key, void *value)
{
struct CheckPeerContext *ctx = cls;
struct DistantNeighbor *distant = value;
- if (memcmp(key, &ctx->sender_id, sizeof(unsigned int)) == 0)
+ if (memcmp (key, &ctx->sender_id, sizeof (unsigned int)) == 0)
{
ctx->peer = distant;
return GNUNET_NO;
@@ -1253,22 +1291,30 @@
* @param client the TokenizedMessageContext which contains message information
* @param message the actual message
*/
-void tokenized_message_handler (void *cls,
- void *client,
- const struct GNUNET_MessageHeader *message)
+void
+tokenized_message_handler (void *cls,
+ void *client,
+ const struct GNUNET_MessageHeader *message)
{
struct TokenizedMessageContext *ctx = client;
+
GNUNET_break_op (ntohs (message->type) != GNUNET_MESSAGE_TYPE_DV_GOSSIP);
GNUNET_break_op (ntohs (message->type) != GNUNET_MESSAGE_TYPE_DV_DATA);
- if ( (ntohs (message->type) != GNUNET_MESSAGE_TYPE_DV_GOSSIP) &&
- (ntohs (message->type) != GNUNET_MESSAGE_TYPE_DV_DATA) )
+ if ((ntohs (message->type) != GNUNET_MESSAGE_TYPE_DV_GOSSIP) &&
+ (ntohs (message->type) != GNUNET_MESSAGE_TYPE_DV_DATA))
{
#if DEBUG_DV_MESSAGES
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "%s: Receives %s message for me, uid %u, size %d, type %d cost
%u from %s!\n", my_short_id, "DV DATA", ctx->uid, ntohs(message->size),
ntohs(message->type), ctx->distant->cost, GNUNET_i2s(&ctx->distant->identity));
+ "%s: Receives %s message for me, uid %u, size %d, type %d cost
%u from %s!\n",
+ my_short_id, "DV DATA", ctx->uid, ntohs (message->size),
+ ntohs (message->type), ctx->distant->cost,
+ GNUNET_i2s (&ctx->distant->identity));
#endif
- GNUNET_assert(memcmp(ctx->peer, &ctx->distant->identity, sizeof(struct
GNUNET_PeerIdentity)) != 0);
- send_to_plugin(ctx->peer, message, ntohs(message->size),
&ctx->distant->identity, ctx->distant->cost);
+ GNUNET_assert (memcmp
+ (ctx->peer, &ctx->distant->identity,
+ sizeof (struct GNUNET_PeerIdentity)) != 0);
+ send_to_plugin (ctx->peer, message, ntohs (message->size),
+ &ctx->distant->identity, ctx->distant->cost);
}
}
@@ -1282,23 +1328,23 @@
uint32_t uid;
};
-void send_message_delayed (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+void
+send_message_delayed (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct DelayedMessageContext *msg_ctx = cls;
+
if (msg_ctx != NULL)
- {
- send_message(&msg_ctx->dest,
- &msg_ctx->sender,
- NULL,
- msg_ctx->message,
- msg_ctx->message_size,
- default_dv_priority,
- msg_ctx->uid,
- GNUNET_TIME_relative_get_forever());
- GNUNET_free(msg_ctx->message);
- GNUNET_free(msg_ctx);
- }
+ {
+ send_message (&msg_ctx->dest,
+ &msg_ctx->sender,
+ NULL,
+ msg_ctx->message,
+ msg_ctx->message_size,
+ default_dv_priority,
+ msg_ctx->uid, GNUNET_TIME_relative_get_forever ());
+ GNUNET_free (msg_ctx->message);
+ GNUNET_free (msg_ctx);
+ }
}
#endif
@@ -1311,15 +1357,15 @@
static uint32_t
get_atsi_distance (const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
- while ( (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR) &&
- (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE) )
+ while ((ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR) &&
+ (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE))
atsi++;
if (ntohl (atsi->type) == GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR)
- {
- GNUNET_break (0);
- /* FIXME: we do not have distance data? Assume direct neighbor. */
- return DIRECT_NEIGHBOR_COST;
- }
+ {
+ GNUNET_break (0);
+ /* FIXME: we do not have distance data? Assume direct neighbor. */
+ return DIRECT_NEIGHBOR_COST;
+ }
return ntohl (atsi->value);
}
@@ -1332,17 +1378,18 @@
static struct GNUNET_TIME_Relative
get_atsi_latency (const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
- while ( (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR) &&
- (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY) )
+ while ((ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR) &&
+ (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY))
atsi++;
if (ntohl (atsi->type) == GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR)
- {
- GNUNET_break (0);
- /* how can we not have latency data? */
- return GNUNET_TIME_UNIT_SECONDS;
- }
+ {
+ GNUNET_break (0);
+ /* how can we not have latency data? */
+ return GNUNET_TIME_UNIT_SECONDS;
+ }
/* FIXME: Multiply by GNUNET_TIME_UNIT_MILLISECONDS (1) to get as a
GNUNET_TIME_Relative */
- return GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, ntohl
(atsi->value));
+ return GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
+ ntohl (atsi->value));
}
/**
@@ -1356,11 +1403,11 @@
* @param message the message
* @param atsi transport ATS information (latency, distance, etc.)
*/
-static int
+static int
handle_dv_data_message (void *cls,
- const struct GNUNET_PeerIdentity * peer,
- const struct GNUNET_MessageHeader * message,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+ const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_MessageHeader *message,
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
const p2p_dv_MESSAGE_Data *incoming = (const p2p_dv_MESSAGE_Data *) message;
const struct GNUNET_MessageHeader *packed_message;
@@ -1374,6 +1421,7 @@
struct TokenizedMessageContext tkm_ctx;
int i;
int found_pos;
+
#if DELAY_FORWARDS
struct DelayedMessageContext *delayed_context;
#endif
@@ -1386,29 +1434,35 @@
int ret;
size_t packed_message_size;
char *cbuf;
- uint32_t distance; /* Distance information */
- struct GNUNET_TIME_Relative latency; /* Latency information */
+ uint32_t distance; /* Distance information */
+ struct GNUNET_TIME_Relative latency; /* Latency information */
- packed_message_size = ntohs(incoming->header.size) -
sizeof(p2p_dv_MESSAGE_Data);
+ packed_message_size =
+ ntohs (incoming->header.size) - sizeof (p2p_dv_MESSAGE_Data);
#if DEBUG_DV
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "%s: Receives DATA message from %s size %d, packed size %d!\n",
my_short_id, GNUNET_i2s(peer) , ntohs(incoming->header.size),
packed_message_size);
+ "%s: Receives DATA message from %s size %d, packed size %d!\n",
+ my_short_id, GNUNET_i2s (peer), ntohs (incoming->header.size),
+ packed_message_size);
#endif
- if (ntohs (incoming->header.size) < sizeof (p2p_dv_MESSAGE_Data) + sizeof
(struct GNUNET_MessageHeader))
- {
+ if (ntohs (incoming->header.size) <
+ sizeof (p2p_dv_MESSAGE_Data) + sizeof (struct GNUNET_MessageHeader))
+ {
#if DEBUG_DV
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "`%s': Message sizes don't add up, total size %u, expected at
least %u!\n", "dv service", ntohs(incoming->header.size), sizeof
(p2p_dv_MESSAGE_Data) + sizeof (struct GNUNET_MessageHeader));
+ "`%s': Message sizes don't add up, total size %u, expected at
least %u!\n",
+ "dv service", ntohs (incoming->header.size),
+ sizeof (p2p_dv_MESSAGE_Data) +
+ sizeof (struct GNUNET_MessageHeader));
#endif
- return GNUNET_SYSERR;
- }
+ return GNUNET_SYSERR;
+ }
/* Iterate over ATS_Information to get distance and latency */
- latency = get_atsi_latency(atsi);
- distance = get_atsi_distance(atsi);
- dn = GNUNET_CONTAINER_multihashmap_get (direct_neighbors,
- &peer->hashPubKey);
+ latency = get_atsi_latency (atsi);
+ distance = get_atsi_distance (atsi);
+ dn = GNUNET_CONTAINER_multihashmap_get (direct_neighbors, &peer->hashPubKey);
if (dn == NULL)
return GNUNET_OK;
@@ -1418,7 +1472,8 @@
{
checkPeerCtx.sender_id = sid;
checkPeerCtx.peer = NULL;
- GNUNET_CONTAINER_multihashmap_iterate(extended_neighbors, &checkPeerID,
&checkPeerCtx);
+ GNUNET_CONTAINER_multihashmap_iterate (extended_neighbors, &checkPeerID,
+ &checkPeerCtx);
pos = checkPeerCtx.peer;
}
else
@@ -1433,154 +1488,177 @@
#endif
if (pos == NULL)
+ {
+#if DEBUG_DV_MESSAGES
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "%s: unknown sender (%u), Message uid %u from %s!\n",
+ my_short_id, ntohl (incoming->sender), ntohl (incoming->uid),
+ GNUNET_i2s (&dn->identity));
+ pos = dn->referee_head;
+ while ((NULL != pos) && (pos->referrer_id != sid))
{
-#if DEBUG_DV_MESSAGES
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "%s: unknown sender (%u), Message uid %u from %s!\n",
my_short_id, ntohl(incoming->sender), ntohl(incoming->uid),
GNUNET_i2s(&dn->identity));
- pos = dn->referee_head;
- while ((NULL != pos) && (pos->referrer_id != sid))
+ sender_id = strdup (GNUNET_i2s (&pos->identity));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "I know sender %u %s\n",
+ pos->referrer_id, sender_id);
+ GNUNET_free (sender_id);
+ pos = pos->next;
+ }
+#endif
+
+ found_pos = -1;
+ for (i = 0; i < MAX_OUTSTANDING_MESSAGES; i++)
+ {
+ if (dn->pending_messages[i].sender_id == 0)
{
- sender_id = strdup(GNUNET_i2s(&pos->identity));
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "I know sender %u %s\n",
pos->referrer_id, sender_id);
- GNUNET_free(sender_id);
- pos = pos->next;
+ found_pos = i;
+ break;
}
-#endif
+ }
- found_pos = -1;
- for (i = 0; i< MAX_OUTSTANDING_MESSAGES; i++)
- {
- if (dn->pending_messages[i].sender_id == 0)
- {
- found_pos = i;
- break;
- }
- }
-
- if (found_pos == -1)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "%s: Too many unknown senders (%u), ignoring message!
Message uid %llu from %s!\n", my_short_id, ntohl(incoming->sender),
ntohl(incoming->uid), GNUNET_i2s(&dn->identity));
- }
- else
- {
- dn->pending_messages[found_pos].message = GNUNET_malloc(ntohs
(message->size));
- memcpy(dn->pending_messages[found_pos].message, message,
ntohs(message->size));
- dn->pending_messages[found_pos].distance = distance;
- dn->pending_messages[found_pos].latency = latency;
- memcpy(&dn->pending_messages[found_pos].sender, peer,
sizeof(struct GNUNET_PeerIdentity));
- dn->pending_messages[found_pos].sender_id = sid;
- }
- /* unknown sender */
- return GNUNET_OK;
+ if (found_pos == -1)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "%s: Too many unknown senders (%u), ignoring message!
Message uid %llu from %s!\n",
+ my_short_id, ntohl (incoming->sender), ntohl (incoming->uid),
+ GNUNET_i2s (&dn->identity));
}
+ else
+ {
+ dn->pending_messages[found_pos].message =
+ GNUNET_malloc (ntohs (message->size));
+ memcpy (dn->pending_messages[found_pos].message, message,
+ ntohs (message->size));
+ dn->pending_messages[found_pos].distance = distance;
+ dn->pending_messages[found_pos].latency = latency;
+ memcpy (&dn->pending_messages[found_pos].sender, peer,
+ sizeof (struct GNUNET_PeerIdentity));
+ dn->pending_messages[found_pos].sender_id = sid;
+ }
+ /* unknown sender */
+ return GNUNET_OK;
+ }
original_sender = &pos->identity;
tid = ntohl (incoming->recipient);
if (tid == 0)
+ {
+ /* 0 == us */
+ cbuf = (char *) &incoming[1];
+
+ tkm_ctx.peer = peer;
+ tkm_ctx.distant = pos;
+ tkm_ctx.uid = ntohl (incoming->uid);
+ if (GNUNET_OK != GNUNET_SERVER_mst_receive (coreMST,
+ &tkm_ctx,
+ cbuf,
+ packed_message_size,
+ GNUNET_NO, GNUNET_NO))
{
- /* 0 == us */
- cbuf = (char *)&incoming[1];
-
- tkm_ctx.peer = peer;
- tkm_ctx.distant = pos;
- tkm_ctx.uid = ntohl(incoming->uid);
- if (GNUNET_OK != GNUNET_SERVER_mst_receive (coreMST,
- &tkm_ctx,
- cbuf,
- packed_message_size,
- GNUNET_NO,
- GNUNET_NO))
- {
- GNUNET_break_op(0);
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s: %s Received corrupt data,
discarding!", my_short_id, "DV SERVICE");
- }
- return GNUNET_OK;
+ GNUNET_break_op (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "%s: %s Received corrupt data, discarding!", my_short_id,
+ "DV SERVICE");
}
+ return GNUNET_OK;
+ }
else
- {
- packed_message = (struct GNUNET_MessageHeader *)&incoming[1];
- }
+ {
+ packed_message = (struct GNUNET_MessageHeader *) &incoming[1];
+ }
/* FIXME: this is the *only* per-request operation we have in DV
- that is O(n) in relation to the number of connected peers; a
- hash-table lookup could easily solve this (minor performance
- issue) */
+ * that is O(n) in relation to the number of connected peers; a
+ * hash-table lookup could easily solve this (minor performance
+ * issue) */
fdc.tid = tid;
fdc.dest = NULL;
- GNUNET_CONTAINER_heap_iterate (neighbor_max_heap,
- &find_destination, &fdc);
+ GNUNET_CONTAINER_heap_iterate (neighbor_max_heap, &find_destination, &fdc);
#if DEBUG_DV
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "%s: Receives %s message for someone else!\n", "dv", "DV
DATA");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "%s: Receives %s message for someone else!\n", "dv", "DV DATA");
#endif
if (fdc.dest == NULL)
- {
+ {
#if DEBUG_DV_MESSAGES
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "%s: Receives %s message uid %u for someone we don't know
(id %u)!\n", my_short_id, "DV DATA", ntohl(incoming->uid), tid);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "%s: Receives %s message uid %u for someone we don't know (id
%u)!\n",
+ my_short_id, "DV DATA", ntohl (incoming->uid), tid);
#endif
- return GNUNET_OK;
- }
+ return GNUNET_OK;
+ }
destination = &fdc.dest->identity;
if (0 == memcmp (destination, peer, sizeof (struct GNUNET_PeerIdentity)))
- {
- /* FIXME: create stat: routing loop-discard! */
+ {
+ /* FIXME: create stat: routing loop-discard! */
#if DEBUG_DV_MESSAGES
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "%s: DROPPING MESSAGE uid %u type %d, routing loop! Message
immediately from %s!\n", my_short_id, ntohl(incoming->uid),
ntohs(packed_message->type), GNUNET_i2s(&dn->identity));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "%s: DROPPING MESSAGE uid %u type %d, routing loop! Message
immediately from %s!\n",
+ my_short_id, ntohl (incoming->uid),
+ ntohs (packed_message->type), GNUNET_i2s (&dn->identity));
#endif
- return GNUNET_OK;
- }
+ return GNUNET_OK;
+ }
/* At this point we have a message, and we need to forward it on to the
* next DV hop.
*/
#if DEBUG_DV_MESSAGES
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "%s: FORWARD %s message for %s, uid %u, size %d type %d, cost
%u!\n", my_short_id, "DV DATA", GNUNET_i2s(destination), ntohl(incoming->uid),
ntohs(packed_message->size), ntohs(packed_message->type), pos->cost);
+ "%s: FORWARD %s message for %s, uid %u, size %d type %d, cost
%u!\n",
+ my_short_id, "DV DATA", GNUNET_i2s (destination),
+ ntohl (incoming->uid), ntohs (packed_message->size),
+ ntohs (packed_message->type), pos->cost);
#endif
#if DELAY_FORWARDS
- if (GNUNET_TIME_absolute_get_duration(pos->last_gossip).abs_value <
GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2).abs_value)
- {
- delayed_context = GNUNET_malloc(sizeof(struct DelayedMessageContext));
- memcpy(&delayed_context->dest, destination, sizeof(struct
GNUNET_PeerIdentity));
- memcpy(&delayed_context->sender, original_sender, sizeof(struct
GNUNET_PeerIdentity));
- delayed_context->message = GNUNET_malloc(packed_message_size);
- memcpy(delayed_context->message, packed_message, packed_message_size);
- delayed_context->message_size = packed_message_size;
- delayed_context->uid = ntohl(incoming->uid);
-
GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS,
2500), &send_message_delayed, delayed_context);
- return GNUNET_OK;
- }
+ if (GNUNET_TIME_absolute_get_duration (pos->last_gossip).abs_value <
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2).abs_value)
+ {
+ delayed_context = GNUNET_malloc (sizeof (struct DelayedMessageContext));
+ memcpy (&delayed_context->dest, destination,
+ sizeof (struct GNUNET_PeerIdentity));
+ memcpy (&delayed_context->sender, original_sender,
+ sizeof (struct GNUNET_PeerIdentity));
+ delayed_context->message = GNUNET_malloc (packed_message_size);
+ memcpy (delayed_context->message, packed_message, packed_message_size);
+ delayed_context->message_size = packed_message_size;
+ delayed_context->uid = ntohl (incoming->uid);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MILLISECONDS, 2500),
+ &send_message_delayed, delayed_context);
+ return GNUNET_OK;
+ }
else
#endif
- {
- ret = send_message(destination,
- original_sender,
- NULL,
- packed_message,
- packed_message_size,
- default_dv_priority,
- ntohl(incoming->uid),
- GNUNET_TIME_relative_get_forever());
- }
+ {
+ ret = send_message (destination,
+ original_sender,
+ NULL,
+ packed_message,
+ packed_message_size,
+ default_dv_priority,
+ ntohl (incoming->uid),
+ GNUNET_TIME_relative_get_forever ());
+ }
if (ret != GNUNET_SYSERR)
return GNUNET_OK;
else
- {
+ {
#if DEBUG_MESSAGE_DROP
- char *direct_id = GNUNET_strdup(GNUNET_i2s(&dn->identity));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "%s: DROPPING MESSAGE type %d, forwarding failed! Message
immediately from %s!\n", GNUNET_i2s(&my_identity), ntohs(((struct
GNUNET_MessageHeader *)&incoming[1])->type), direct_id);
- GNUNET_free (direct_id);
+ char *direct_id = GNUNET_strdup (GNUNET_i2s (&dn->identity));
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "%s: DROPPING MESSAGE type %d, forwarding failed! Message
immediately from %s!\n",
+ GNUNET_i2s (&my_identity),
+ ntohs (((struct GNUNET_MessageHeader *) &incoming[1])->type),
+ direct_id);
+ GNUNET_free (direct_id);
#endif
- return GNUNET_SYSERR;
- }
+ return GNUNET_SYSERR;
+ }
}
#if DEBUG_DV
@@ -1594,19 +1672,24 @@
* iterate,
* GNUNET_NO if not.
*/
-int print_neighbors (void *cls,
- const GNUNET_HashCode * key,
- void *abs_value)
+int
+print_neighbors (void *cls, const GNUNET_HashCode * key, void *abs_value)
{
struct DistantNeighbor *distant_neighbor = abs_value;
char my_shortname[5];
char referrer_shortname[5];
- memcpy(&my_shortname, GNUNET_i2s(&my_identity), 4);
+
+ memcpy (&my_shortname, GNUNET_i2s (&my_identity), 4);
my_shortname[4] = '\0';
- memcpy(&referrer_shortname,
GNUNET_i2s(&distant_neighbor->referrer->identity), 4);
+ memcpy (&referrer_shortname,
+ GNUNET_i2s (&distant_neighbor->referrer->identity), 4);
referrer_shortname[4] = '\0';
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "`%s' %s: Peer `%s', distance %d,
referrer `%s' pkey: %s\n", &my_shortname, "DV",
GNUNET_i2s(&distant_neighbor->identity), distant_neighbor->cost,
&referrer_shortname, distant_neighbor->pkey == NULL ? "no" : "yes");
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "`%s' %s: Peer `%s', distance %d, referrer `%s' pkey: %s\n",
+ &my_shortname, "DV", GNUNET_i2s (&distant_neighbor->identity),
+ distant_neighbor->cost, &referrer_shortname,
+ distant_neighbor->pkey == NULL ? "no" : "yes");
return GNUNET_YES;
}
#endif
@@ -1616,13 +1699,13 @@
* peers. Will run until called with reason shutdown.
*/
static void
-neighbor_send_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+neighbor_send_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct NeighborSendContext *send_context = cls;
+
#if DEBUG_DV_GOSSIP_SEND
- char * encPeerAbout;
- char * encPeerTo;
+ char *encPeerAbout;
+ char *encPeerTo;
#endif
struct DistantNeighbor *about;
struct DirectNeighbor *to;
@@ -1631,41 +1714,41 @@
p2p_dv_MESSAGE_NeighborInfo *message;
struct PendingMessage *pending_message;
- if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- {
+ if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
+ {
#if DEBUG_DV_GOSSIP
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "%s: Called with reason shutdown, shutting down!\n",
- GNUNET_i2s(&my_identity));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "%s: Called with reason shutdown, shutting down!\n",
+ GNUNET_i2s (&my_identity));
#endif
- return;
- }
+ return;
+ }
if (send_context->fast_gossip_list_head != NULL)
- {
- about_list = send_context->fast_gossip_list_head;
- about = about_list->about;
- GNUNET_CONTAINER_DLL_remove(send_context->fast_gossip_list_head,
- send_context->fast_gossip_list_tail,
- about_list);
- GNUNET_free(about_list);
- }
+ {
+ about_list = send_context->fast_gossip_list_head;
+ about = about_list->about;
+ GNUNET_CONTAINER_DLL_remove (send_context->fast_gossip_list_head,
+ send_context->fast_gossip_list_tail,
+ about_list);
+ GNUNET_free (about_list);
+ }
else
- {
- /* FIXME: this may become a problem, because the heap walk has only one
internal "walker". This means
- * that if two neighbor_send_tasks are operating in lockstep (which is
quite possible, given default
- * values for all connected peers) there may be a serious bias as to
which peers get gossiped about!
- * Probably the *best* way to fix would be to have an opaque pointer to
the walk position passed as
- * part of the walk_get_next call. Then the heap would have to keep a
list of walks, or reset the walk
- * whenever a modification has been detected. Yuck either way. Perhaps
we could iterate over the heap
- * once to get a list of peers to gossip about and gossip them over
time... But then if one goes away
- * in the mean time that becomes nasty. For now we'll just assume that
the walking is done
- * asynchronously enough to avoid major problems (-;
- *
- * NOTE: probably fixed once we decided send rate based on allowed
bandwidth.
- */
- about = GNUNET_CONTAINER_heap_walk_get_next (neighbor_min_heap);
- }
+ {
+ /* FIXME: this may become a problem, because the heap walk has only one
internal "walker". This means
+ * that if two neighbor_send_tasks are operating in lockstep (which is
quite possible, given default
+ * values for all connected peers) there may be a serious bias as to which
peers get gossiped about!
+ * Probably the *best* way to fix would be to have an opaque pointer to
the walk position passed as
+ * part of the walk_get_next call. Then the heap would have to keep a
list of walks, or reset the walk
+ * whenever a modification has been detected. Yuck either way. Perhaps
we could iterate over the heap
+ * once to get a list of peers to gossip about and gossip them over
time... But then if one goes away
+ * in the mean time that becomes nasty. For now we'll just assume that
the walking is done
+ * asynchronously enough to avoid major problems (-;
+ *
+ * NOTE: probably fixed once we decided send rate based on allowed
bandwidth.
+ */
+ about = GNUNET_CONTAINER_heap_walk_get_next (neighbor_min_heap);
+ }
to = send_context->toNeighbor;
if ((about != NULL) && (to != about->referrer /* split horizon */ ) &&
@@ -1674,61 +1757,69 @@
#endif
(to != NULL) &&
(0 != memcmp (&about->identity,
- &to->identity, sizeof (struct GNUNET_PeerIdentity))) &&
+ &to->identity, sizeof (struct GNUNET_PeerIdentity))) &&
(about->pkey != NULL))
- {
+ {
#if DEBUG_DV_GOSSIP_SEND
- encPeerAbout = GNUNET_strdup(GNUNET_i2s(&about->identity));
- encPeerTo = GNUNET_strdup(GNUNET_i2s(&to->identity));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "%s: Sending info about peer %s id %u to directly connected
peer %s\n",
- GNUNET_i2s(&my_identity),
- encPeerAbout, about->our_id, encPeerTo);
- GNUNET_free(encPeerAbout);
- GNUNET_free(encPeerTo);
+ encPeerAbout = GNUNET_strdup (GNUNET_i2s (&about->identity));
+ encPeerTo = GNUNET_strdup (GNUNET_i2s (&to->identity));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "%s: Sending info about peer %s id %u to directly connected
peer %s\n",
+ GNUNET_i2s (&my_identity),
+ encPeerAbout, about->our_id, encPeerTo);
+ GNUNET_free (encPeerAbout);
+ GNUNET_free (encPeerTo);
#endif
- about->last_gossip = GNUNET_TIME_absolute_get();
- pending_message = GNUNET_malloc(sizeof(struct PendingMessage) +
sizeof(p2p_dv_MESSAGE_NeighborInfo));
- pending_message->msg = (struct GNUNET_MessageHeader
*)&pending_message[1];
- pending_message->importance = default_dv_priority;
- pending_message->timeout = GNUNET_TIME_relative_get_forever();
- memcpy(&pending_message->recipient, &to->identity, sizeof(struct
GNUNET_PeerIdentity));
- pending_message->msg_size = sizeof(p2p_dv_MESSAGE_NeighborInfo);
- message = (p2p_dv_MESSAGE_NeighborInfo *)pending_message->msg;
- message->header.size = htons (sizeof (p2p_dv_MESSAGE_NeighborInfo));
- message->header.type = htons (GNUNET_MESSAGE_TYPE_DV_GOSSIP);
- message->cost = htonl (about->cost);
- message->neighbor_id = htonl (about->our_id);
+ about->last_gossip = GNUNET_TIME_absolute_get ();
+ pending_message =
+ GNUNET_malloc (sizeof (struct PendingMessage) +
+ sizeof (p2p_dv_MESSAGE_NeighborInfo));
+ pending_message->msg = (struct GNUNET_MessageHeader *) &pending_message[1];
+ pending_message->importance = default_dv_priority;
+ pending_message->timeout = GNUNET_TIME_relative_get_forever ();
+ memcpy (&pending_message->recipient, &to->identity,
+ sizeof (struct GNUNET_PeerIdentity));
+ pending_message->msg_size = sizeof (p2p_dv_MESSAGE_NeighborInfo);
+ message = (p2p_dv_MESSAGE_NeighborInfo *) pending_message->msg;
+ message->header.size = htons (sizeof (p2p_dv_MESSAGE_NeighborInfo));
+ message->header.type = htons (GNUNET_MESSAGE_TYPE_DV_GOSSIP);
+ message->cost = htonl (about->cost);
+ message->neighbor_id = htonl (about->our_id);
- memcpy (&message->pkey, about->pkey, sizeof(struct
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
- memcpy (&message->neighbor,
- &about->identity, sizeof (struct GNUNET_PeerIdentity));
+ memcpy (&message->pkey, about->pkey,
+ sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
+ memcpy (&message->neighbor, &about->identity,
+ sizeof (struct GNUNET_PeerIdentity));
- GNUNET_CONTAINER_DLL_insert_after (core_pending_head,
- core_pending_tail,
- core_pending_tail,
- pending_message);
+ GNUNET_CONTAINER_DLL_insert_after (core_pending_head,
+ core_pending_tail,
+ core_pending_tail, pending_message);
- GNUNET_SCHEDULER_add_now(try_core_send, NULL);
- /*if (core_transmit_handle == NULL)
- core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI,
GNUNET_YES, default_dv_priority, GNUNET_TIME_relative_get_forever(),
&to->identity, sizeof(p2p_dv_MESSAGE_NeighborInfo), &core_transmit_notify,
NULL);*/
+ GNUNET_SCHEDULER_add_now (try_core_send, NULL);
+ /*if (core_transmit_handle == NULL)
+ * core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI,
GNUNET_YES, default_dv_priority, GNUNET_TIME_relative_get_forever(),
&to->identity, sizeof(p2p_dv_MESSAGE_NeighborInfo), &core_transmit_notify,
NULL); */
- }
+ }
- if (send_context->fast_gossip_list_head != NULL) /* If there are other peers
in the fast list, schedule right away */
- {
+ if (send_context->fast_gossip_list_head != NULL) /* If there are other
peers in the fast list, schedule right away */
+ {
#if DEBUG_DV_PEER_NUMBERS
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "DV SERVICE: still in fast send
mode\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "DV SERVICE: still in fast send mode\n");
#endif
- send_context->task = GNUNET_SCHEDULER_add_now(&neighbor_send_task,
send_context);
- }
+ send_context->task =
+ GNUNET_SCHEDULER_add_now (&neighbor_send_task, send_context);
+ }
else
- {
+ {
#if DEBUG_DV_PEER_NUMBERS
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "DV SERVICE: entering slow send
mode\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "DV SERVICE: entering slow send mode\n");
#endif
- send_context->task =
GNUNET_SCHEDULER_add_delayed(GNUNET_DV_DEFAULT_SEND_INTERVAL,
&neighbor_send_task, send_context);
- }
+ send_context->task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_DV_DEFAULT_SEND_INTERVAL,
+ &neighbor_send_task, send_context);
+ }
return;
}
@@ -1755,7 +1846,7 @@
client_handle = client;
- GNUNET_SERVER_client_keep(client_handle);
+ GNUNET_SERVER_client_keep (client_handle);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
@@ -1771,18 +1862,17 @@
* iterate,
* GNUNET_NO if not.
*/
-int send_iterator (void *cls,
- const GNUNET_HashCode * key,
- void *abs_value)
+int
+send_iterator (void *cls, const GNUNET_HashCode * key, void *abs_value)
{
struct DV_SendContext *send_context = cls;
struct DistantNeighbor *distant_neighbor = abs_value;
- if (memcmp(distant_neighbor->referrer, send_context->direct_peer,
sizeof(struct GNUNET_PeerIdentity)) == 0) /* They match, send and free */
- {
- send_message_via(&my_identity, distant_neighbor, send_context);
- return GNUNET_NO;
- }
+ if (memcmp (distant_neighbor->referrer, send_context->direct_peer, sizeof
(struct GNUNET_PeerIdentity)) == 0) /* They match, send and free */
+ {
+ send_message_via (&my_identity, distant_neighbor, send_context);
+ return GNUNET_NO;
+ }
return GNUNET_YES;
}
#endif
@@ -1795,9 +1885,10 @@
* @param client identification of the client
* @param message the actual message
*/
-void handle_dv_send_message (void *cls,
- struct GNUNET_SERVER_Client * client,
- const struct GNUNET_MessageHeader * message)
+void
+handle_dv_send_message (void *cls,
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
struct GNUNET_DV_SendMessage *send_msg;
struct GNUNET_DV_SendResultMessage *send_result_msg;
@@ -1811,6 +1902,7 @@
int offset;
static struct GNUNET_CRYPTO_HashAsciiEncoded dest_hash;
struct DV_SendContext *send_context;
+
#if DEBUG_DV_MESSAGES
char *cbuf;
struct GNUNET_MessageHeader *packed_message;
@@ -1820,7 +1912,8 @@
{
client_handle = client;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "%s: Setting initial client handle, never received `%s'
message?\n", "dv", "START");
+ "%s: Setting initial client handle, never received `%s'
message?\n",
+ "dv", "START");
}
else if (client_handle != client)
{
@@ -1832,55 +1925,67 @@
#endif
}
- GNUNET_assert(ntohs(message->size) > sizeof(struct GNUNET_DV_SendMessage));
- send_msg = (struct GNUNET_DV_SendMessage *)message;
+ GNUNET_assert (ntohs (message->size) > sizeof (struct
GNUNET_DV_SendMessage));
+ send_msg = (struct GNUNET_DV_SendMessage *) message;
- address_len = ntohl(send_msg->addrlen);
- GNUNET_assert(address_len == sizeof(struct GNUNET_PeerIdentity) * 2);
- message_size = ntohs(message->size) - sizeof(struct GNUNET_DV_SendMessage) -
address_len;
- destination = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity));
- direct = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity));
- message_buf = GNUNET_malloc(message_size);
+ address_len = ntohl (send_msg->addrlen);
+ GNUNET_assert (address_len == sizeof (struct GNUNET_PeerIdentity) * 2);
+ message_size =
+ ntohs (message->size) - sizeof (struct GNUNET_DV_SendMessage) -
+ address_len;
+ destination = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
+ direct = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
+ message_buf = GNUNET_malloc (message_size);
- temp_pos = (char *)&send_msg[1]; /* Set pointer to end of message */
- offset = 0; /* Offset starts at zero */
+ temp_pos = (char *) &send_msg[1]; /* Set pointer to end of message */
+ offset = 0; /* Offset starts at zero */
- memcpy(destination, &temp_pos[offset], sizeof(struct GNUNET_PeerIdentity));
- offset += sizeof(struct GNUNET_PeerIdentity);
+ memcpy (destination, &temp_pos[offset], sizeof (struct GNUNET_PeerIdentity));
+ offset += sizeof (struct GNUNET_PeerIdentity);
- memcpy(direct, &temp_pos[offset], sizeof(struct GNUNET_PeerIdentity));
- offset += sizeof(struct GNUNET_PeerIdentity);
+ memcpy (direct, &temp_pos[offset], sizeof (struct GNUNET_PeerIdentity));
+ offset += sizeof (struct GNUNET_PeerIdentity);
- memcpy(message_buf, &temp_pos[offset], message_size);
- if (memcmp(&send_msg->target, destination, sizeof(struct
GNUNET_PeerIdentity)) != 0)
- {
- GNUNET_CRYPTO_hash_to_enc (&destination->hashPubKey, &dest_hash); /*
GNUNET_i2s won't properly work, need to hash one ourselves */
- dest_hash.encoding[4] = '\0';
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s: asked to send message to
`%s', but address is for `%s'!", "DV SERVICE", GNUNET_i2s(&send_msg->target),
(const char *)&dest_hash.encoding);
- }
+ memcpy (message_buf, &temp_pos[offset], message_size);
+ if (memcmp
+ (&send_msg->target, destination,
+ sizeof (struct GNUNET_PeerIdentity)) != 0)
+ {
+ GNUNET_CRYPTO_hash_to_enc (&destination->hashPubKey, &dest_hash); /*
GNUNET_i2s won't properly work, need to hash one ourselves */
+ dest_hash.encoding[4] = '\0';
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "%s: asked to send message to `%s', but address is for `%s'!",
+ "DV SERVICE", GNUNET_i2s (&send_msg->target),
+ (const char *) &dest_hash.encoding);
+ }
#if DEBUG_DV_MESSAGES
- cbuf = (char *)message_buf;
+ cbuf = (char *) message_buf;
offset = 0;
- while(offset < message_size)
- {
- packed_message = (struct GNUNET_MessageHeader *)&cbuf[offset];
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: DV PLUGIN SEND uid %u type %d
to %s\n", my_short_id, ntohl(send_msg->uid), ntohs(packed_message->type),
GNUNET_i2s(destination));
- offset += ntohs(packed_message->size);
- }
- /*GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: DV PLUGIN SEND uid %u type %d to
%s\n", my_short_id, ntohl(send_msg->uid), ntohs(message_buf->type),
GNUNET_i2s(destination));*/
+ while (offset < message_size)
+ {
+ packed_message = (struct GNUNET_MessageHeader *) &cbuf[offset];
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "%s: DV PLUGIN SEND uid %u type %d to %s\n", my_short_id,
+ ntohl (send_msg->uid), ntohs (packed_message->type),
+ GNUNET_i2s (destination));
+ offset += ntohs (packed_message->size);
+ }
+ /*GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: DV PLUGIN SEND uid %u type %d to
%s\n", my_short_id, ntohl(send_msg->uid), ntohs(message_buf->type),
GNUNET_i2s(destination)); */
#endif
- GNUNET_CRYPTO_hash_to_enc (&destination->hashPubKey, &dest_hash); /*
GNUNET_i2s won't properly work, need to hash one ourselves */
+ GNUNET_CRYPTO_hash_to_enc (&destination->hashPubKey, &dest_hash); /*
GNUNET_i2s won't properly work, need to hash one ourselves */
dest_hash.encoding[4] = '\0';
- send_context = GNUNET_malloc(sizeof(struct DV_SendContext));
+ send_context = GNUNET_malloc (sizeof (struct DV_SendContext));
- send_result_msg = GNUNET_malloc(sizeof(struct GNUNET_DV_SendResultMessage));
- send_result_msg->header.size = htons(sizeof(struct
GNUNET_DV_SendResultMessage));
- send_result_msg->header.type =
htons(GNUNET_MESSAGE_TYPE_TRANSPORT_DV_SEND_RESULT);
+ send_result_msg = GNUNET_malloc (sizeof (struct
GNUNET_DV_SendResultMessage));
+ send_result_msg->header.size =
+ htons (sizeof (struct GNUNET_DV_SendResultMessage));
+ send_result_msg->header.type =
+ htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DV_SEND_RESULT);
send_result_msg->uid = send_msg->uid; /* No need to ntohl->htonl this */
- send_context->importance = ntohl(send_msg->priority);
+ send_context->importance = ntohl (send_msg->priority);
send_context->timeout = send_msg->timeout;
send_context->direct_peer = direct;
send_context->distant_peer = destination;
@@ -1891,84 +1996,111 @@
send_context->uid = send_msg->uid;
#endif
- if (send_message_via(&my_identity, direct, send_context) != GNUNET_YES)
- {
- send_result_msg->result = htons(1);
- pending_message = GNUNET_malloc(sizeof(struct PendingMessage) +
sizeof(struct GNUNET_DV_SendResultMessage));
- pending_message->msg = (struct GNUNET_MessageHeader
*)&pending_message[1];
- memcpy(&pending_message[1], send_result_msg, sizeof(struct
GNUNET_DV_SendResultMessage));
- GNUNET_free(send_result_msg);
+ if (send_message_via (&my_identity, direct, send_context) != GNUNET_YES)
+ {
+ send_result_msg->result = htons (1);
+ pending_message =
+ GNUNET_malloc (sizeof (struct PendingMessage) +
+ sizeof (struct GNUNET_DV_SendResultMessage));
+ pending_message->msg = (struct GNUNET_MessageHeader *) &pending_message[1];
+ memcpy (&pending_message[1], send_result_msg,
+ sizeof (struct GNUNET_DV_SendResultMessage));
+ GNUNET_free (send_result_msg);
- GNUNET_CONTAINER_DLL_insert_after(plugin_pending_head,
plugin_pending_tail, plugin_pending_tail, pending_message);
+ GNUNET_CONTAINER_DLL_insert_after (plugin_pending_head,
plugin_pending_tail,
+ plugin_pending_tail, pending_message);
- if (client_handle != NULL)
- {
- if (plugin_transmit_handle == NULL)
- {
- plugin_transmit_handle = GNUNET_SERVER_notify_transmit_ready
(client_handle,
-
sizeof(struct GNUNET_DV_SendResultMessage),
-
GNUNET_TIME_UNIT_FOREVER_REL,
-
&transmit_to_plugin, NULL);
- }
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to queue message
for plugin, must be one in progress already!!\n");
- }
- }
- GNUNET_CRYPTO_hash_to_enc (&destination->hashPubKey, &dest_hash); /*
GNUNET_i2s won't properly work, need to hash one ourselves */
- dest_hash.encoding[4] = '\0';
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s DV SEND failed to send message
to destination `%s' via `%s'\n", my_short_id, (const char
*)&dest_hash.encoding, GNUNET_i2s(direct));
+ if (client_handle != NULL)
+ {
+ if (plugin_transmit_handle == NULL)
+ {
+ plugin_transmit_handle =
+ GNUNET_SERVER_notify_transmit_ready (client_handle,
+ sizeof (struct
+
GNUNET_DV_SendResultMessage),
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &transmit_to_plugin, NULL);
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to queue message for plugin, must be one in
progress already!!\n");
+ }
}
+ GNUNET_CRYPTO_hash_to_enc (&destination->hashPubKey, &dest_hash); /*
GNUNET_i2s won't properly work, need to hash one ourselves */
+ dest_hash.encoding[4] = '\0';
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "%s DV SEND failed to send message to destination `%s' via
`%s'\n",
+ my_short_id, (const char *) &dest_hash.encoding,
+ GNUNET_i2s (direct));
+ }
/* In bizarro world GNUNET_SYSERR indicates that we succeeded */
#if UNSIMPLER
- if (GNUNET_SYSERR !=
GNUNET_CONTAINER_multihashmap_get_multiple(extended_neighbors,
&destination->hashPubKey, &send_iterator, send_context))
- {
- send_result_msg->result = htons(1);
- pending_message = GNUNET_malloc(sizeof(struct PendingMessage) +
sizeof(struct GNUNET_DV_SendResultMessage));
- pending_message->msg = (struct GNUNET_MessageHeader
*)&pending_message[1];
- memcpy(&pending_message[1], send_result_msg, sizeof(struct
GNUNET_DV_SendResultMessage));
- GNUNET_free(send_result_msg);
+ if (GNUNET_SYSERR !=
+ GNUNET_CONTAINER_multihashmap_get_multiple (extended_neighbors,
+ &destination->hashPubKey,
+ &send_iterator,
send_context))
+ {
+ send_result_msg->result = htons (1);
+ pending_message =
+ GNUNET_malloc (sizeof (struct PendingMessage) +
+ sizeof (struct GNUNET_DV_SendResultMessage));
+ pending_message->msg = (struct GNUNET_MessageHeader *) &pending_message[1];
+ memcpy (&pending_message[1], send_result_msg,
+ sizeof (struct GNUNET_DV_SendResultMessage));
+ GNUNET_free (send_result_msg);
- GNUNET_CONTAINER_DLL_insert_after(plugin_pending_head,
plugin_pending_tail, plugin_pending_tail, pending_message);
+ GNUNET_CONTAINER_DLL_insert_after (plugin_pending_head,
plugin_pending_tail,
+ plugin_pending_tail, pending_message);
- if (client_handle != NULL)
- {
- if (plugin_transmit_handle == NULL)
- {
- plugin_transmit_handle = GNUNET_SERVER_notify_transmit_ready
(client_handle,
-
sizeof(struct GNUNET_DV_SendResultMessage),
-
GNUNET_TIME_UNIT_FOREVER_REL,
-
&transmit_to_plugin, NULL);
- }
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to queue message
for plugin, must be one in progress already!!\n");
- }
- }
- GNUNET_CRYPTO_hash_to_enc (&destination->hashPubKey, &dest_hash); /*
GNUNET_i2s won't properly work, need to hash one ourselves */
- dest_hash.encoding[4] = '\0';
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s DV SEND failed to send message
to destination `%s' via `%s'\n", my_short_id, (const char
*)&dest_hash.encoding, GNUNET_i2s(direct));
+ if (client_handle != NULL)
+ {
+ if (plugin_transmit_handle == NULL)
+ {
+ plugin_transmit_handle =
+ GNUNET_SERVER_notify_transmit_ready (client_handle,
+ sizeof (struct
+
GNUNET_DV_SendResultMessage),
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &transmit_to_plugin, NULL);
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to queue message for plugin, must be one in
progress already!!\n");
+ }
}
+ GNUNET_CRYPTO_hash_to_enc (&destination->hashPubKey, &dest_hash); /*
GNUNET_i2s won't properly work, need to hash one ourselves */
+ dest_hash.encoding[4] = '\0';
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "%s DV SEND failed to send message to destination `%s' via
`%s'\n",
+ my_short_id, (const char *) &dest_hash.encoding,
+ GNUNET_i2s (direct));
+ }
#endif
- GNUNET_free(message_buf);
- GNUNET_free(send_context);
- GNUNET_free(direct);
- GNUNET_free(destination);
+ GNUNET_free (message_buf);
+ GNUNET_free (send_context);
+ GNUNET_free (direct);
+ GNUNET_free (destination);
- GNUNET_SERVER_receive_done(client, GNUNET_OK);
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
/** Forward declarations **/
static int handle_dv_gossip_message (void *cls,
const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader
*message,
- const struct
GNUNET_TRANSPORT_ATS_Information *atsi);
+ const struct
+ GNUNET_TRANSPORT_ATS_Information *atsi);
static int handle_dv_disconnect_message (void *cls,
const struct GNUNET_PeerIdentity
*peer,
- const struct GNUNET_MessageHeader
*message,
- const struct
GNUNET_TRANSPORT_ATS_Information *atsi);
+ const struct GNUNET_MessageHeader
+ *message,
+ const struct
+ GNUNET_TRANSPORT_ATS_Information
+ *atsi);
/** End forward declarations **/
@@ -2006,14 +2138,14 @@
referrer = referee->referrer;
if (referrer != NULL)
- {
- GNUNET_CONTAINER_DLL_remove (referrer->referee_head,
- referrer->referee_tail, referee);
- }
+ {
+ GNUNET_CONTAINER_DLL_remove (referrer->referee_head,
+ referrer->referee_tail, referee);
+ }
GNUNET_CONTAINER_heap_remove_node (referee->max_loc);
GNUNET_CONTAINER_heap_remove_node (referee->min_loc);
GNUNET_CONTAINER_multihashmap_remove_all (extended_neighbors,
- &referee->identity.hashPubKey);
+ &referee->identity.hashPubKey);
GNUNET_free_non_null (referee->pkey);
GNUNET_free (referee);
}
@@ -2032,18 +2164,20 @@
send_context = direct->send_context;
if (send_context->task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel(send_context->task);
+ GNUNET_SCHEDULER_cancel (send_context->task);
about_list = send_context->fast_gossip_list_head;
while (about_list != NULL)
- {
- GNUNET_CONTAINER_DLL_remove(send_context->fast_gossip_list_head,
send_context->fast_gossip_list_tail, about_list);
- prev_about = about_list;
- about_list = about_list->next;
- GNUNET_free(prev_about);
- }
- GNUNET_free(send_context);
- GNUNET_free(direct);
+ {
+ GNUNET_CONTAINER_DLL_remove (send_context->fast_gossip_list_head,
+ send_context->fast_gossip_list_tail,
+ about_list);
+ prev_about = about_list;
+ about_list = about_list->next;
+ GNUNET_free (prev_about);
+ }
+ GNUNET_free (send_context);
+ GNUNET_free (direct);
}
/**
@@ -2056,9 +2190,9 @@
*
* @return GNUNET_YES to continue iteration, GNUNET_NO to stop
*/
-static int schedule_disconnect_messages (void *cls,
- const GNUNET_HashCode * key,
- void *value)
+static int
+schedule_disconnect_messages (void *cls,
+ const GNUNET_HashCode * key, void *value)
{
struct DisconnectContext *disconnect_context = cls;
struct DirectNeighbor *disconnected = disconnect_context->direct;
@@ -2066,28 +2200,32 @@
struct PendingMessage *pending_message;
p2p_dv_MESSAGE_Disconnect *disconnect_message;
- if (memcmp(¬ify->identity, &disconnected->identity, sizeof(struct
GNUNET_PeerIdentity)) == 0)
- return GNUNET_YES; /* Don't send disconnect message to peer that
disconnected! */
+ if (memcmp
+ (¬ify->identity, &disconnected->identity,
+ sizeof (struct GNUNET_PeerIdentity)) == 0)
+ return GNUNET_YES; /* Don't send disconnect message to peer that
disconnected! */
- pending_message = GNUNET_malloc(sizeof(struct PendingMessage) +
sizeof(p2p_dv_MESSAGE_Disconnect));
- pending_message->msg = (struct GNUNET_MessageHeader *)&pending_message[1];
+ pending_message =
+ GNUNET_malloc (sizeof (struct PendingMessage) +
+ sizeof (p2p_dv_MESSAGE_Disconnect));
+ pending_message->msg = (struct GNUNET_MessageHeader *) &pending_message[1];
pending_message->importance = default_dv_priority;
- pending_message->timeout = GNUNET_TIME_relative_get_forever();
- memcpy(&pending_message->recipient, ¬ify->identity, sizeof(struct
GNUNET_PeerIdentity));
- pending_message->msg_size = sizeof(p2p_dv_MESSAGE_Disconnect);
- disconnect_message = (p2p_dv_MESSAGE_Disconnect *)pending_message->msg;
+ pending_message->timeout = GNUNET_TIME_relative_get_forever ();
+ memcpy (&pending_message->recipient, ¬ify->identity,
+ sizeof (struct GNUNET_PeerIdentity));
+ pending_message->msg_size = sizeof (p2p_dv_MESSAGE_Disconnect);
+ disconnect_message = (p2p_dv_MESSAGE_Disconnect *) pending_message->msg;
disconnect_message->header.size = htons (sizeof (p2p_dv_MESSAGE_Disconnect));
disconnect_message->header.type = htons (GNUNET_MESSAGE_TYPE_DV_DISCONNECT);
- disconnect_message->peer_id = htonl(disconnect_context->distant->our_id);
+ disconnect_message->peer_id = htonl (disconnect_context->distant->our_id);
GNUNET_CONTAINER_DLL_insert_after (core_pending_head,
core_pending_tail,
- core_pending_tail,
- pending_message);
+ core_pending_tail, pending_message);
- GNUNET_SCHEDULER_add_now(try_core_send, NULL);
+ GNUNET_SCHEDULER_add_now (try_core_send, NULL);
/*if (core_transmit_handle == NULL)
- core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI,
GNUNET_YES, default_dv_priority, GNUNET_TIME_relative_get_forever(),
¬ify->identity, sizeof(p2p_dv_MESSAGE_Disconnect), &core_transmit_notify,
NULL);*/
+ * core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI,
GNUNET_YES, default_dv_priority, GNUNET_TIME_relative_get_forever(),
¬ify->identity, sizeof(p2p_dv_MESSAGE_Disconnect), &core_transmit_notify,
NULL); */
return GNUNET_YES;
}
@@ -2101,12 +2239,12 @@
*
* @return GNUNET_YES to continue iteration, GNUNET_NO to stop
*/
-static int free_extended_neighbors (void *cls,
- const GNUNET_HashCode * key,
- void *value)
+static int
+free_extended_neighbors (void *cls, const GNUNET_HashCode * key, void *value)
{
struct DistantNeighbor *distant = value;
- distant_neighbor_free(distant);
+
+ distant_neighbor_free (distant);
return GNUNET_YES;
}
@@ -2119,12 +2257,12 @@
*
* @return GNUNET_YES to continue iteration, GNUNET_NO to stop
*/
-static int free_direct_neighbors (void *cls,
- const GNUNET_HashCode * key,
- void *value)
+static int
+free_direct_neighbors (void *cls, const GNUNET_HashCode * key, void *value)
{
struct DirectNeighbor *direct = value;
- direct_neighbor_free(direct);
+
+ direct_neighbor_free (direct);
return GNUNET_YES;
}
@@ -2136,52 +2274,56 @@
* @param tc unused
*/
static void
-shutdown_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
#if DEBUG_DV
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "calling CORE_DISCONNECT\n");
- GNUNET_CONTAINER_multihashmap_iterate(extended_neighbors, &print_neighbors,
NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "calling CORE_DISCONNECT\n");
+ GNUNET_CONTAINER_multihashmap_iterate (extended_neighbors, &print_neighbors,
+ NULL);
#endif
- GNUNET_CONTAINER_multihashmap_iterate(extended_neighbors,
&free_extended_neighbors, NULL);
- GNUNET_CONTAINER_multihashmap_destroy(extended_neighbors);
- GNUNET_CONTAINER_multihashmap_iterate(direct_neighbors,
&free_direct_neighbors, NULL);
- GNUNET_CONTAINER_multihashmap_destroy(direct_neighbors);
+ GNUNET_CONTAINER_multihashmap_iterate (extended_neighbors,
+ &free_extended_neighbors, NULL);
+ GNUNET_CONTAINER_multihashmap_destroy (extended_neighbors);
+ GNUNET_CONTAINER_multihashmap_iterate (direct_neighbors,
+ &free_direct_neighbors, NULL);
+ GNUNET_CONTAINER_multihashmap_destroy (direct_neighbors);
- GNUNET_CONTAINER_heap_destroy(neighbor_max_heap);
- GNUNET_CONTAINER_heap_destroy(neighbor_min_heap);
+ GNUNET_CONTAINER_heap_destroy (neighbor_max_heap);
+ GNUNET_CONTAINER_heap_destroy (neighbor_min_heap);
GNUNET_CORE_disconnect (coreAPI);
coreAPI = NULL;
- GNUNET_PEERINFO_disconnect(peerinfo_handle);
- GNUNET_SERVER_mst_destroy(coreMST);
- GNUNET_free_non_null(my_short_id);
+ GNUNET_PEERINFO_disconnect (peerinfo_handle);
+ GNUNET_SERVER_mst_destroy (coreMST);
+ GNUNET_free_non_null (my_short_id);
#if DEBUG_DV
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "CORE_DISCONNECT completed\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CORE_DISCONNECT completed\n");
#endif
}
/**
* To be called on core init/fail.
*/
-void core_init (void *cls,
- struct GNUNET_CORE_Handle * server,
- const struct GNUNET_PeerIdentity *identity,
- const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *
publicKey)
+void
+core_init (void *cls,
+ struct GNUNET_CORE_Handle *server,
+ const struct GNUNET_PeerIdentity *identity,
+ const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
{
if (server == NULL)
- {
- GNUNET_SCHEDULER_cancel(cleanup_task);
- GNUNET_SCHEDULER_add_now(&shutdown_task, NULL);
- return;
- }
+ {
+ GNUNET_SCHEDULER_cancel (cleanup_task);
+ GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
+ return;
+ }
#if DEBUG_DV
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "%s: Core connection initialized, I am peer: %s\n", "dv",
GNUNET_i2s(identity));
+ "%s: Core connection initialized, I am peer: %s\n", "dv",
+ GNUNET_i2s (identity));
#endif
- memcpy(&my_identity, identity, sizeof(struct GNUNET_PeerIdentity));
- my_short_id = GNUNET_strdup(GNUNET_i2s(&my_identity));
+ memcpy (&my_identity, identity, sizeof (struct GNUNET_PeerIdentity));
+ my_short_id = GNUNET_strdup (GNUNET_i2s (&my_identity));
coreAPI = server;
}
@@ -2197,17 +2339,18 @@
* iterate,
* GNUNET_NO if not.
*/
-static int add_pkey_to_extended (void *cls,
- const GNUNET_HashCode * key,
- void *abs_value)
+static int
+add_pkey_to_extended (void *cls, const GNUNET_HashCode * key, void *abs_value)
{
struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pkey = cls;
struct DistantNeighbor *distant_neighbor = abs_value;
if (distant_neighbor->pkey == NULL)
{
- distant_neighbor->pkey = GNUNET_malloc(sizeof(struct
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
- memcpy(distant_neighbor->pkey, pkey, sizeof(struct
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
+ distant_neighbor->pkey =
+ GNUNET_malloc (sizeof (struct
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
+ memcpy (distant_neighbor->pkey, pkey,
+ sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
}
return GNUNET_YES;
@@ -2224,20 +2367,21 @@
* iterate,
* GNUNET_NO if not.
*/
-static int update_matching_neighbors (void *cls,
- const GNUNET_HashCode * key,
- void *value)
+static int
+update_matching_neighbors (void *cls, const GNUNET_HashCode * key, void *value)
{
- struct NeighborUpdateInfo * update_info = cls;
+ struct NeighborUpdateInfo *update_info = cls;
struct DistantNeighbor *distant_neighbor = value;
- if (update_info->referrer == distant_neighbor->referrer) /* Direct neighbor
matches, update it's info and return GNUNET_NO */
+ if (update_info->referrer == distant_neighbor->referrer) /* Direct
neighbor matches, update it's info and return GNUNET_NO */
{
/* same referrer, cost change! */
GNUNET_CONTAINER_heap_update_cost (neighbor_max_heap,
- update_info->neighbor->max_loc,
update_info->cost);
+ update_info->neighbor->max_loc,
+ update_info->cost);
GNUNET_CONTAINER_heap_update_cost (neighbor_min_heap,
- update_info->neighbor->min_loc,
update_info->cost);
+ update_info->neighbor->min_loc,
+ update_info->cost);
update_info->neighbor->last_activity = update_info->now;
update_info->neighbor->cost = update_info->cost;
update_info->neighbor->referrer_id = update_info->referrer_peer_id;
@@ -2259,54 +2403,59 @@
*
* @return GNUNET_YES to continue iteration, GNUNET_NO otherwise
*/
-static int add_distant_all_direct_neighbors (void *cls,
- const GNUNET_HashCode * key,
- void *value)
+static int
+add_distant_all_direct_neighbors (void *cls,
+ const GNUNET_HashCode * key, void *value)
{
- struct DirectNeighbor *direct = (struct DirectNeighbor *)value;
- struct DistantNeighbor *distant = (struct DistantNeighbor *)cls;
+ struct DirectNeighbor *direct = (struct DirectNeighbor *) value;
+ struct DistantNeighbor *distant = (struct DistantNeighbor *) cls;
struct NeighborSendContext *send_context = direct->send_context;
struct FastGossipNeighborList *gossip_entry;
+
#if DEBUG_DV
char *encPeerAbout;
char *encPeerTo;
#endif
if (distant == NULL)
- {
- return GNUNET_YES;
- }
+ {
+ return GNUNET_YES;
+ }
- if (memcmp(&direct->identity, &distant->identity, sizeof(struct
GNUNET_PeerIdentity)) == 0)
- {
- return GNUNET_YES; /* Don't gossip to a peer about itself! */
- }
+ if (memcmp
+ (&direct->identity, &distant->identity,
+ sizeof (struct GNUNET_PeerIdentity)) == 0)
+ {
+ return GNUNET_YES; /* Don't gossip to a peer about itself! */
+ }
#if SUPPORT_HIDING
if (distant->hidden == GNUNET_YES)
- return GNUNET_YES; /* This peer should not be gossipped about (hidden) */
+ return GNUNET_YES; /* This peer should not be gossipped about
(hidden) */
#endif
- gossip_entry = GNUNET_malloc(sizeof(struct FastGossipNeighborList));
+ gossip_entry = GNUNET_malloc (sizeof (struct FastGossipNeighborList));
gossip_entry->about = distant;
- GNUNET_CONTAINER_DLL_insert_after(send_context->fast_gossip_list_head,
- send_context->fast_gossip_list_tail,
- send_context->fast_gossip_list_tail,
- gossip_entry);
+ GNUNET_CONTAINER_DLL_insert_after (send_context->fast_gossip_list_head,
+ send_context->fast_gossip_list_tail,
+ send_context->fast_gossip_list_tail,
+ gossip_entry);
#if DEBUG_DV
- encPeerAbout = GNUNET_strdup(GNUNET_i2s(&distant->identity));
- encPeerTo = GNUNET_strdup(GNUNET_i2s(&direct->identity));
+ encPeerAbout = GNUNET_strdup (GNUNET_i2s (&distant->identity));
+ encPeerTo = GNUNET_strdup (GNUNET_i2s (&direct->identity));
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: Fast send info about peer %s id %u
for directly connected peer %s\n",
- GNUNET_i2s(&my_identity),
- encPeerAbout, distant->our_id, encPeerTo);
- GNUNET_free(encPeerAbout);
- GNUNET_free(encPeerTo);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "%s: Fast send info about peer %s id %u for directly connected
peer %s\n",
+ GNUNET_i2s (&my_identity), encPeerAbout, distant->our_id,
+ encPeerTo);
+ GNUNET_free (encPeerAbout);
+ GNUNET_free (encPeerTo);
#endif
/*if (send_context->task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel(send_context->task);*/
+ * GNUNET_SCHEDULER_cancel(send_context->task); */
- send_context->task = GNUNET_SCHEDULER_add_now(&neighbor_send_task,
send_context);
+ send_context->task =
+ GNUNET_SCHEDULER_add_now (&neighbor_send_task, send_context);
return GNUNET_YES;
}
@@ -2333,24 +2482,27 @@
return 0;
/* Hello "address" will be concatenation of distant peer and direct peer
identities */
- size = 2 * sizeof(struct GNUNET_PeerIdentity);
- GNUNET_assert(max >= size);
+ size = 2 * sizeof (struct GNUNET_PeerIdentity);
+ GNUNET_assert (max >= size);
- addr_buffer = GNUNET_malloc(size);
+ addr_buffer = GNUNET_malloc (size);
offset = 0;
/* Copy the distant peer identity to buffer */
- memcpy(addr_buffer, &hello_context->distant_peer, sizeof(struct
GNUNET_PeerIdentity));
- offset += sizeof(struct GNUNET_PeerIdentity);
+ memcpy (addr_buffer, &hello_context->distant_peer,
+ sizeof (struct GNUNET_PeerIdentity));
+ offset += sizeof (struct GNUNET_PeerIdentity);
/* Copy the direct peer identity to buffer */
- memcpy(&addr_buffer[offset], hello_context->direct_peer, sizeof(struct
GNUNET_PeerIdentity));
- ret = GNUNET_HELLO_add_address ("dv",
- GNUNET_TIME_relative_to_absolute
- (GNUNET_TIME_UNIT_HOURS), addr_buffer, size,
- buf, max);
+ memcpy (&addr_buffer[offset], hello_context->direct_peer,
+ sizeof (struct GNUNET_PeerIdentity));
+ ret =
+ GNUNET_HELLO_add_address ("dv",
+ GNUNET_TIME_relative_to_absolute
+ (GNUNET_TIME_UNIT_HOURS), addr_buffer, size,
+ buf, max);
hello_context->addresses_to_add--;
- GNUNET_free(addr_buffer);
+ GNUNET_free (addr_buffer);
return ret;
}
@@ -2370,8 +2522,8 @@
* not added)
*/
static struct DistantNeighbor *
-addUpdateNeighbor (const struct GNUNET_PeerIdentity * peer,
- struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pkey,
+addUpdateNeighbor (const struct GNUNET_PeerIdentity *peer,
+ struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pkey,
unsigned int referrer_peer_id,
struct DirectNeighbor *referrer, unsigned int cost)
{
@@ -2388,6 +2540,7 @@
#if DEBUG_DV_PEER_NUMBERS
char *encAbout;
+
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"%s Received sender id (%u)!\n", "DV SERVICE", referrer_peer_id);
#endif
@@ -2395,7 +2548,7 @@
now = GNUNET_TIME_absolute_get ();
neighbor = GNUNET_CONTAINER_multihashmap_get (extended_neighbors,
&peer->hashPubKey);
- neighbor_update = GNUNET_malloc(sizeof(struct NeighborUpdateInfo));
+ neighbor_update = GNUNET_malloc (sizeof (struct NeighborUpdateInfo));
neighbor_update->neighbor = neighbor;
neighbor_update->cost = cost;
neighbor_update->now = now;
@@ -2403,163 +2556,189 @@
neighbor_update->referrer_peer_id = referrer_peer_id;
if (neighbor != NULL)
- {
+ {
#if USE_PEER_ID
- memcpy(&our_id, &neighbor->identity, sizeof(unsigned int));
+ memcpy (&our_id, &neighbor->identity, sizeof (unsigned int));
#else
- our_id = neighbor->our_id;
+ our_id = neighbor->our_id;
#endif
- }
+ }
else
- {
+ {
#if USE_PEER_ID
- memcpy(&our_id, peer, sizeof(unsigned int));
+ memcpy (&our_id, peer, sizeof (unsigned int));
#else
- our_id = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG,
RAND_MAX - 1) + 1;
+ our_id =
+ GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG,
+ RAND_MAX - 1) + 1;
#endif
- }
+ }
/* Either we do not know this peer, or we already do but via a different
immediate peer */
if ((neighbor == NULL) ||
- (GNUNET_CONTAINER_multihashmap_get_multiple(extended_neighbors,
- &peer->hashPubKey,
- &update_matching_neighbors,
- neighbor_update) !=
GNUNET_SYSERR))
+ (GNUNET_CONTAINER_multihashmap_get_multiple (extended_neighbors,
+ &peer->hashPubKey,
+ &update_matching_neighbors,
+ neighbor_update) !=
+ GNUNET_SYSERR))
+ {
+#if AT_MOST_ONE
+ if ((neighbor != NULL) && (cost < neighbor->cost)) /* New cost is less
than old, remove old */
{
-#if AT_MOST_ONE
- if ((neighbor != NULL) && (cost < neighbor->cost)) /* New cost is less
than old, remove old */
- {
- distant_neighbor_free(neighbor);
- }
- else if (neighbor != NULL) /* Only allow one DV connection to each peer */
- {
- return NULL;
- }
+ distant_neighbor_free (neighbor);
+ }
+ else if (neighbor != NULL) /* Only allow one DV connection to each peer */
+ {
+ return NULL;
+ }
#endif
- /* new neighbor! */
- if (cost > fisheye_depth)
- {
- /* too costly */
- GNUNET_free(neighbor_update);
- return NULL;
- }
+ /* new neighbor! */
+ if (cost > fisheye_depth)
+ {
+ /* too costly */
+ GNUNET_free (neighbor_update);
+ return NULL;
+ }
#if DEBUG_DV_PEER_NUMBERS
- encAbout = GNUNET_strdup(GNUNET_i2s(peer));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "%s: %s Chose NEW id (%u) for peer %s!\n",
GNUNET_i2s(&my_identity), "DV SERVICE", our_id, encAbout);
- GNUNET_free(encAbout);
+ encAbout = GNUNET_strdup (GNUNET_i2s (peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "%s: %s Chose NEW id (%u) for peer %s!\n",
+ GNUNET_i2s (&my_identity), "DV SERVICE", our_id, encAbout);
+ GNUNET_free (encAbout);
#endif
- if (max_table_size <=
- GNUNET_CONTAINER_multihashmap_size (extended_neighbors))
- {
- /* remove most expensive entry */
- max = GNUNET_CONTAINER_heap_peek (neighbor_max_heap);
- GNUNET_assert(max != NULL);
- if (cost > max->cost)
- {
- /* new entry most expensive, don't create */
- GNUNET_free(neighbor_update);
- return NULL;
- }
- if (max->cost > 1)
- {
- /* only free if this is not a direct connection;
- we could theoretically have more direct
- connections than DV entries allowed total! */
- distant_neighbor_free (max);
- }
- }
-
- neighbor = GNUNET_malloc (sizeof (struct DistantNeighbor));
- GNUNET_CONTAINER_DLL_insert (referrer->referee_head,
- referrer->referee_tail, neighbor);
- neighbor->max_loc = GNUNET_CONTAINER_heap_insert (neighbor_max_heap,
- neighbor, cost);
- neighbor->min_loc = GNUNET_CONTAINER_heap_insert (neighbor_min_heap,
- neighbor, cost);
- neighbor->referrer = referrer;
- memcpy (&neighbor->identity, peer, sizeof (struct GNUNET_PeerIdentity));
- if (pkey != NULL) /* pkey will be null on direct neighbor addition */
+ if (max_table_size <=
+ GNUNET_CONTAINER_multihashmap_size (extended_neighbors))
+ {
+ /* remove most expensive entry */
+ max = GNUNET_CONTAINER_heap_peek (neighbor_max_heap);
+ GNUNET_assert (max != NULL);
+ if (cost > max->cost)
{
- neighbor->pkey = GNUNET_malloc(sizeof(struct
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
- memcpy (neighbor->pkey, pkey, sizeof(struct
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
+ /* new entry most expensive, don't create */
+ GNUNET_free (neighbor_update);
+ return NULL;
}
- else
- neighbor->pkey = pkey;
+ if (max->cost > 1)
+ {
+ /* only free if this is not a direct connection;
+ * we could theoretically have more direct
+ * connections than DV entries allowed total! */
+ distant_neighbor_free (max);
+ }
+ }
- neighbor->last_activity = now;
- neighbor->cost = cost;
- neighbor->referrer_id = referrer_peer_id;
- neighbor->our_id = our_id;
- neighbor->hidden =
- (cost == DIRECT_NEIGHBOR_COST) ? (GNUNET_CRYPTO_random_u32
(GNUNET_CRYPTO_QUALITY_WEAK, 4) ==
- 0) : GNUNET_NO;
+ neighbor = GNUNET_malloc (sizeof (struct DistantNeighbor));
+ GNUNET_CONTAINER_DLL_insert (referrer->referee_head,
+ referrer->referee_tail, neighbor);
+ neighbor->max_loc = GNUNET_CONTAINER_heap_insert (neighbor_max_heap,
+ neighbor, cost);
+ neighbor->min_loc = GNUNET_CONTAINER_heap_insert (neighbor_min_heap,
+ neighbor, cost);
+ neighbor->referrer = referrer;
+ memcpy (&neighbor->identity, peer, sizeof (struct GNUNET_PeerIdentity));
+ if (pkey != NULL) /* pkey will be null on direct neighbor
addition */
+ {
+ neighbor->pkey =
+ GNUNET_malloc (sizeof
+ (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
+ memcpy (neighbor->pkey, pkey,
+ sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
+ }
+ else
+ neighbor->pkey = pkey;
- GNUNET_CONTAINER_multihashmap_put (extended_neighbors, &peer->hashPubKey,
- neighbor,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
- if (referrer_peer_id != 0)
+ neighbor->last_activity = now;
+ neighbor->cost = cost;
+ neighbor->referrer_id = referrer_peer_id;
+ neighbor->our_id = our_id;
+ neighbor->hidden =
+ (cost ==
+ DIRECT_NEIGHBOR_COST)
+ ? (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 4) ==
+ 0) : GNUNET_NO;
+
+ GNUNET_CONTAINER_multihashmap_put (extended_neighbors, &peer->hashPubKey,
+ neighbor,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
+ if (referrer_peer_id != 0)
+ {
+ for (i = 0; i < MAX_OUTSTANDING_MESSAGES; i++)
+ {
+ if (referrer->pending_messages[i].sender_id == referrer_peer_id)
/* We have a queued message from just learned about peer! */
{
- for (i = 0; i< MAX_OUTSTANDING_MESSAGES; i++)
- {
- if (referrer->pending_messages[i].sender_id == referrer_peer_id)
/* We have a queued message from just learned about peer! */
- {
#if DEBUG_DV_MESSAGES
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: learned about peer
%llu from which we have a previous unknown message, processing!\n",
my_short_id, referrer_peer_id);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "%s: learned about peer %llu from which we have a
previous unknown message, processing!\n",
+ my_short_id, referrer_peer_id);
#endif
- struct GNUNET_TRANSPORT_ATS_Information atsi[3];
- atsi[0].type = htonl
(GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE);
- atsi[0].value = htonl
(referrer->pending_messages[i].distance);
- atsi[1].type = htonl
(GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY);
- atsi[1].value = htonl
((uint32_t)referrer->pending_messages[i].latency.rel_value);
- atsi[2].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
- atsi[2].value = htonl (0);
- handle_dv_data_message(NULL,
- &referrer->pending_messages[i].sender,
- referrer->pending_messages[i].message,
- (const struct
GNUNET_TRANSPORT_ATS_Information *)&atsi);
- GNUNET_free(referrer->pending_messages[i].message);
- referrer->pending_messages[i].sender_id = 0;
- }
- }
+ struct GNUNET_TRANSPORT_ATS_Information atsi[3];
+
+ atsi[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE);
+ atsi[0].value = htonl (referrer->pending_messages[i].distance);
+ atsi[1].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY);
+ atsi[1].value =
+ htonl ((uint32_t) referrer->pending_messages[i].
+ latency.rel_value);
+ atsi[2].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
+ atsi[2].value = htonl (0);
+ handle_dv_data_message (NULL,
+ &referrer->pending_messages[i].sender,
+ referrer->pending_messages[i].message,
+ (const struct
GNUNET_TRANSPORT_ATS_Information
+ *) &atsi);
+ GNUNET_free (referrer->pending_messages[i].message);
+ referrer->pending_messages[i].sender_id = 0;
}
- if ((cost != DIRECT_NEIGHBOR_COST) && (neighbor->pkey != NULL))
- {
- /* Added neighbor, now send HELLO to transport */
- hello_context = GNUNET_malloc(sizeof(struct HelloContext));
- hello_context->direct_peer = &referrer->identity;
- memcpy(&hello_context->distant_peer, peer, sizeof(struct
GNUNET_PeerIdentity));
- hello_context->addresses_to_add = 1;
- hello_msg = GNUNET_HELLO_create(pkey, &generate_hello_address,
hello_context);
- GNUNET_assert(memcmp(hello_context->direct_peer,
&hello_context->distant_peer, sizeof(struct GNUNET_PeerIdentity)) != 0);
- addr1 = GNUNET_strdup(GNUNET_i2s(hello_context->direct_peer));
- addr2 = GNUNET_strdup(GNUNET_i2s(&hello_context->distant_peer));
+ }
+ }
+ if ((cost != DIRECT_NEIGHBOR_COST) && (neighbor->pkey != NULL))
+ {
+ /* Added neighbor, now send HELLO to transport */
+ hello_context = GNUNET_malloc (sizeof (struct HelloContext));
+ hello_context->direct_peer = &referrer->identity;
+ memcpy (&hello_context->distant_peer, peer,
+ sizeof (struct GNUNET_PeerIdentity));
+ hello_context->addresses_to_add = 1;
+ hello_msg =
+ GNUNET_HELLO_create (pkey, &generate_hello_address, hello_context);
+ GNUNET_assert (memcmp
+ (hello_context->direct_peer, &hello_context->distant_peer,
+ sizeof (struct GNUNET_PeerIdentity)) != 0);
+ addr1 = GNUNET_strdup (GNUNET_i2s (hello_context->direct_peer));
+ addr2 = GNUNET_strdup (GNUNET_i2s (&hello_context->distant_peer));
#if DEBUG_DV
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: GIVING HELLO size %d for %s
via %s to TRANSPORT\n", my_short_id, GNUNET_HELLO_size(hello_msg), addr2,
addr1);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "%s: GIVING HELLO size %d for %s via %s to TRANSPORT\n",
+ my_short_id, GNUNET_HELLO_size (hello_msg), addr2, addr1);
#endif
- GNUNET_free(addr1);
- GNUNET_free(addr2);
- send_to_plugin(hello_context->direct_peer,
GNUNET_HELLO_get_header(hello_msg), GNUNET_HELLO_size(hello_msg),
&hello_context->distant_peer, cost);
- GNUNET_free(hello_context);
- GNUNET_free(hello_msg);
- }
+ GNUNET_free (addr1);
+ GNUNET_free (addr2);
+ send_to_plugin (hello_context->direct_peer,
+ GNUNET_HELLO_get_header (hello_msg),
+ GNUNET_HELLO_size (hello_msg),
+ &hello_context->distant_peer, cost);
+ GNUNET_free (hello_context);
+ GNUNET_free (hello_msg);
+ }
- }
+ }
else
- {
+ {
#if DEBUG_DV_GOSSIP
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "%s: Already know peer %s distance %d, referrer id %d!\n",
"dv", GNUNET_i2s(peer), cost, referrer_peer_id);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "%s: Already know peer %s distance %d, referrer id %d!\n",
"dv",
+ GNUNET_i2s (peer), cost, referrer_peer_id);
#endif
- }
+ }
#if DEBUG_DV
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "%s: Size of extended_neighbors is %d\n", "dv",
GNUNET_CONTAINER_multihashmap_size(extended_neighbors));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "%s: Size of extended_neighbors is %d\n", "dv",
+ GNUNET_CONTAINER_multihashmap_size (extended_neighbors));
#endif
- GNUNET_free(neighbor_update);
+ GNUNET_free (neighbor_update);
return neighbor;
}
@@ -2576,19 +2755,22 @@
* @param message the message
* @param atsi performance data
*/
-static int handle_dv_disconnect_message (void *cls,
- const struct GNUNET_PeerIdentity
*peer,
- const struct GNUNET_MessageHeader
*message,
- const struct
GNUNET_TRANSPORT_ATS_Information *atsi)
+static int
+handle_dv_disconnect_message (void *cls,
+ const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_MessageHeader *message,
+ const struct GNUNET_TRANSPORT_ATS_Information
+ *atsi)
{
struct DirectNeighbor *referrer;
struct DistantNeighbor *distant;
- p2p_dv_MESSAGE_Disconnect *enc_message = (p2p_dv_MESSAGE_Disconnect
*)message;
+ p2p_dv_MESSAGE_Disconnect *enc_message =
+ (p2p_dv_MESSAGE_Disconnect *) message;
if (ntohs (message->size) < sizeof (p2p_dv_MESSAGE_Disconnect))
- {
- return GNUNET_SYSERR; /* invalid message */
- }
+ {
+ return GNUNET_SYSERR; /* invalid message */
+ }
referrer = GNUNET_CONTAINER_multihashmap_get (direct_neighbors,
&peer->hashPubKey);
@@ -2597,15 +2779,15 @@
distant = referrer->referee_head;
while (distant != NULL)
+ {
+ if (distant->referrer_id == ntohl (enc_message->peer_id))
{
- if (distant->referrer_id == ntohl(enc_message->peer_id))
- {
- distant_neighbor_free(distant);
- distant = referrer->referee_head;
- }
- else
- distant = distant->next;
+ distant_neighbor_free (distant);
+ distant = referrer->referee_head;
}
+ else
+ distant = distant->next;
+ }
return GNUNET_OK;
}
@@ -2623,30 +2805,33 @@
* @param message the message
* @param atsi performance data
*/
-static int
+static int
handle_dv_gossip_message (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_MessageHeader *message,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+ const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_MessageHeader *message,
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
struct DirectNeighbor *referrer;
- p2p_dv_MESSAGE_NeighborInfo *enc_message = (p2p_dv_MESSAGE_NeighborInfo
*)message;
+ p2p_dv_MESSAGE_NeighborInfo *enc_message =
+ (p2p_dv_MESSAGE_NeighborInfo *) message;
if (ntohs (message->size) < sizeof (p2p_dv_MESSAGE_NeighborInfo))
- {
- return GNUNET_SYSERR; /* invalid message */
- }
+ {
+ return GNUNET_SYSERR; /* invalid message */
+ }
#if DEBUG_DV_GOSSIP_RECEIPT
- char * encPeerAbout;
- char * encPeerFrom;
+ char *encPeerAbout;
+ char *encPeerFrom;
- encPeerAbout = GNUNET_strdup(GNUNET_i2s(&enc_message->neighbor));
- encPeerFrom = GNUNET_strdup(GNUNET_i2s(peer));
+ encPeerAbout = GNUNET_strdup (GNUNET_i2s (&enc_message->neighbor));
+ encPeerFrom = GNUNET_strdup (GNUNET_i2s (peer));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "%s: Received %s message from peer %s about peer %s id %u
distance %d!\n", GNUNET_i2s(&my_identity), "DV GOSSIP", encPeerFrom,
encPeerAbout, ntohl(enc_message->neighbor_id), ntohl (enc_message->cost) + 1);
- GNUNET_free(encPeerAbout);
- GNUNET_free(encPeerFrom);
+ "%s: Received %s message from peer %s about peer %s id %u
distance %d!\n",
+ GNUNET_i2s (&my_identity), "DV GOSSIP", encPeerFrom,
encPeerAbout,
+ ntohl (enc_message->neighbor_id), ntohl (enc_message->cost) + 1);
+ GNUNET_free (encPeerAbout);
+ GNUNET_free (encPeerFrom);
#endif
referrer = GNUNET_CONTAINER_multihashmap_get (direct_neighbors,
@@ -2673,29 +2858,29 @@
*
* @return GNUNET_YES to continue iteration, GNUNET_NO otherwise
*/
-static int
-add_all_extended_peers (void *cls,
- const GNUNET_HashCode * key,
- void *value)
+static int
+add_all_extended_peers (void *cls, const GNUNET_HashCode * key, void *value)
{
- struct NeighborSendContext *send_context = (struct NeighborSendContext *)cls;
- struct DistantNeighbor *distant = (struct DistantNeighbor *)value;
+ struct NeighborSendContext *send_context = (struct NeighborSendContext *)
cls;
+ struct DistantNeighbor *distant = (struct DistantNeighbor *) value;
struct FastGossipNeighborList *gossip_entry;
- if (memcmp(&send_context->toNeighbor->identity, &distant->identity,
sizeof(struct GNUNET_PeerIdentity)) == 0)
- return GNUNET_YES; /* Don't gossip to a peer about itself! */
+ if (memcmp
+ (&send_context->toNeighbor->identity, &distant->identity,
+ sizeof (struct GNUNET_PeerIdentity)) == 0)
+ return GNUNET_YES; /* Don't gossip to a peer about itself! */
#if SUPPORT_HIDING
if (distant->hidden == GNUNET_YES)
- return GNUNET_YES; /* This peer should not be gossipped about (hidden) */
+ return GNUNET_YES; /* This peer should not be gossipped about
(hidden) */
#endif
- gossip_entry = GNUNET_malloc(sizeof(struct FastGossipNeighborList));
+ gossip_entry = GNUNET_malloc (sizeof (struct FastGossipNeighborList));
gossip_entry->about = distant;
- GNUNET_CONTAINER_DLL_insert_after(send_context->fast_gossip_list_head,
- send_context->fast_gossip_list_tail,
- send_context->fast_gossip_list_tail,
- gossip_entry);
+ GNUNET_CONTAINER_DLL_insert_after (send_context->fast_gossip_list_head,
+ send_context->fast_gossip_list_tail,
+ send_context->fast_gossip_list_tail,
+ gossip_entry);
return GNUNET_YES;
}
@@ -2711,19 +2896,21 @@
* iterate,
* GNUNET_NO if not.
*/
-static int
+static int
gossip_all_to_all_iterator (void *cls,
- const GNUNET_HashCode * key,
- void *abs_value)
+ const GNUNET_HashCode * key, void *abs_value)
{
struct DirectNeighbor *direct = abs_value;
- GNUNET_CONTAINER_multihashmap_iterate (extended_neighbors,
&add_all_extended_peers, direct->send_context);
+ GNUNET_CONTAINER_multihashmap_iterate (extended_neighbors,
+ &add_all_extended_peers,
+ direct->send_context);
if (direct->send_context->task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel(direct->send_context->task);
+ GNUNET_SCHEDULER_cancel (direct->send_context->task);
- direct->send_context->task = GNUNET_SCHEDULER_add_now(&neighbor_send_task,
direct->send_context);
+ direct->send_context->task =
+ GNUNET_SCHEDULER_add_now (&neighbor_send_task, direct->send_context);
return GNUNET_YES;
}
@@ -2734,14 +2921,14 @@
* @param tc unused
*/
static void
-gossip_all_to_all (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+gossip_all_to_all (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- GNUNET_CONTAINER_multihashmap_iterate (direct_neighbors,
&gossip_all_to_all_iterator, NULL);
+ GNUNET_CONTAINER_multihashmap_iterate (direct_neighbors,
+ &gossip_all_to_all_iterator, NULL);
- GNUNET_SCHEDULER_add_delayed
(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5),
- &gossip_all_to_all,
- NULL);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 5),
+ &gossip_all_to_all, NULL);
}
#endif
@@ -2756,50 +2943,55 @@
*
* @return GNUNET_YES to continue iteration, GNUNET_NO otherwise
*/
-static int
-add_all_direct_neighbors (void *cls,
- const GNUNET_HashCode * key,
- void *value)
+static int
+add_all_direct_neighbors (void *cls, const GNUNET_HashCode * key, void *value)
{
- struct DirectNeighbor *direct = (struct DirectNeighbor *)value;
- struct DirectNeighbor *to = (struct DirectNeighbor *)cls;
+ struct DirectNeighbor *direct = (struct DirectNeighbor *) value;
+ struct DirectNeighbor *to = (struct DirectNeighbor *) cls;
struct DistantNeighbor *distant;
struct NeighborSendContext *send_context = direct->send_context;
struct FastGossipNeighborList *gossip_entry;
char *direct_id;
- distant = GNUNET_CONTAINER_multihashmap_get(extended_neighbors,
&to->identity.hashPubKey);
+ distant =
+ GNUNET_CONTAINER_multihashmap_get (extended_neighbors,
+ &to->identity.hashPubKey);
if (distant == NULL)
- {
- return GNUNET_YES;
- }
+ {
+ return GNUNET_YES;
+ }
- if (memcmp(&direct->identity, &to->identity, sizeof(struct
GNUNET_PeerIdentity)) == 0)
- {
- return GNUNET_YES; /* Don't gossip to a peer about itself! */
- }
+ if (memcmp
+ (&direct->identity, &to->identity,
+ sizeof (struct GNUNET_PeerIdentity)) == 0)
+ {
+ return GNUNET_YES; /* Don't gossip to a peer about itself! */
+ }
#if SUPPORT_HIDING
if (distant->hidden == GNUNET_YES)
- return GNUNET_YES; /* This peer should not be gossipped about (hidden) */
+ return GNUNET_YES; /* This peer should not be gossipped about
(hidden) */
#endif
- direct_id = GNUNET_strdup(GNUNET_i2s(&direct->identity));
+ direct_id = GNUNET_strdup (GNUNET_i2s (&direct->identity));
#if DEBUG_DV_GOSSIP
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s: adding peer %s to fast send list
for %s\n", my_short_id, GNUNET_i2s(&distant->identity), direct_id);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "%s: adding peer %s to fast send list for %s\n", my_short_id,
+ GNUNET_i2s (&distant->identity), direct_id);
#endif
- GNUNET_free(direct_id);
- gossip_entry = GNUNET_malloc(sizeof(struct FastGossipNeighborList));
+ GNUNET_free (direct_id);
+ gossip_entry = GNUNET_malloc (sizeof (struct FastGossipNeighborList));
gossip_entry->about = distant;
- GNUNET_CONTAINER_DLL_insert_after(send_context->fast_gossip_list_head,
- send_context->fast_gossip_list_tail,
- send_context->fast_gossip_list_tail,
- gossip_entry);
+ GNUNET_CONTAINER_DLL_insert_after (send_context->fast_gossip_list_head,
+ send_context->fast_gossip_list_tail,
+ send_context->fast_gossip_list_tail,
+ gossip_entry);
if (send_context->task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel(send_context->task);
+ GNUNET_SCHEDULER_cancel (send_context->task);
- send_context->task = GNUNET_SCHEDULER_add_now(&neighbor_send_task,
send_context);
+ send_context->task =
+ GNUNET_SCHEDULER_add_now (&neighbor_send_task, send_context);
//tc.reason = GNUNET_SCHEDULER_REASON_TIMEOUT;
//neighbor_send_task(send_context, &tc);
return GNUNET_YES;
@@ -2817,73 +3009,97 @@
static void
process_peerinfo (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 PeerIteratorContext *peerinfo_iterator = cls;
struct DirectNeighbor *neighbor = peerinfo_iterator->neighbor;
struct DistantNeighbor *distant = peerinfo_iterator->distant;
+
#if DEBUG_DV_PEER_NUMBERS
char *neighbor_pid;
#endif
int sent;
+
if (err_msg != NULL)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Error in communication with PEERINFO service\n"));
- /* return; */
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ _("Error in communication with PEERINFO service\n"));
+ /* return; */
}
if (peer == NULL)
+ {
+ if (distant->pkey == NULL)
{
- if (distant->pkey == NULL)
- {
#if DEBUG_DV
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to get peerinfo
information for this peer, retrying!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to get peerinfo information for this peer,
retrying!\n");
#endif
- peerinfo_iterator->ic = GNUNET_PEERINFO_iterate(peerinfo_handle,
-
&peerinfo_iterator->neighbor->identity,
-
GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3),
- &process_peerinfo,
- peerinfo_iterator);
- }
- else
- {
- GNUNET_free(peerinfo_iterator);
- }
- return;
+ peerinfo_iterator->ic = GNUNET_PEERINFO_iterate (peerinfo_handle,
+
&peerinfo_iterator->neighbor->
+ identity,
+
GNUNET_TIME_relative_multiply
+
(GNUNET_TIME_UNIT_SECONDS,
+ 3), &process_peerinfo,
+ peerinfo_iterator);
}
+ else
+ {
+ GNUNET_free (peerinfo_iterator);
+ }
+ return;
+ }
- if (memcmp(&neighbor->identity, peer, sizeof(struct GNUNET_PeerIdentity) !=
0))
+ if (memcmp
+ (&neighbor->identity, peer, sizeof (struct GNUNET_PeerIdentity) != 0))
return;
- if ((hello != NULL) && (GNUNET_HELLO_get_key (hello, &neighbor->pkey) ==
GNUNET_OK))
+ if ((hello != NULL) &&
+ (GNUNET_HELLO_get_key (hello, &neighbor->pkey) == GNUNET_OK))
+ {
+ if (distant->pkey == NULL)
{
- if (distant->pkey == NULL)
- {
- distant->pkey = GNUNET_malloc(sizeof(struct
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
- memcpy(distant->pkey, &neighbor->pkey, sizeof(struct
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
- }
+ distant->pkey =
+ GNUNET_malloc (sizeof
+ (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
+ memcpy (distant->pkey, &neighbor->pkey,
+ sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
+ }
- sent = GNUNET_CONTAINER_multihashmap_iterate (extended_neighbors,
&add_all_extended_peers, neighbor->send_context);
- if (stats != NULL)
- {
- GNUNET_STATISTICS_update (stats, "# distant peers gossiped to direct
neighbors", sent, GNUNET_NO);
- }
+ sent =
+ GNUNET_CONTAINER_multihashmap_iterate (extended_neighbors,
+ &add_all_extended_peers,
+ neighbor->send_context);
+ if (stats != NULL)
+ {
+ GNUNET_STATISTICS_update (stats,
+ "# distant peers gossiped to direct neighbors",
+ sent, GNUNET_NO);
+ }
#if DEBUG_DV_PEER_NUMBERS
- neighbor_pid = GNUNET_strdup(GNUNET_i2s(&neighbor->identity));
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: Gossipped %d extended peers to
%s\n", GNUNET_i2s(&my_identity), sent, neighbor_pid);
+ neighbor_pid = GNUNET_strdup (GNUNET_i2s (&neighbor->identity));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "%s: Gossipped %d extended peers to %s\n",
+ GNUNET_i2s (&my_identity), sent, neighbor_pid);
#endif
- sent = GNUNET_CONTAINER_multihashmap_iterate (direct_neighbors,
&add_all_direct_neighbors, neighbor);
- if (stats != NULL)
- {
- GNUNET_STATISTICS_update (stats, "# direct peers gossiped to direct
neighbors", sent, GNUNET_NO);
- }
+ sent =
+ GNUNET_CONTAINER_multihashmap_iterate (direct_neighbors,
+ &add_all_direct_neighbors,
+ neighbor);
+ if (stats != NULL)
+ {
+ GNUNET_STATISTICS_update (stats,
+ "# direct peers gossiped to direct neighbors",
+ sent, GNUNET_NO);
+ }
#if DEBUG_DV_PEER_NUMBERS
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: Gossipped about %s to %d direct
peers\n", GNUNET_i2s(&my_identity), neighbor_pid, sent);
- GNUNET_free(neighbor_pid);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "%s: Gossipped about %s to %d direct peers\n",
+ GNUNET_i2s (&my_identity), neighbor_pid, sent);
+ GNUNET_free (neighbor_pid);
#endif
- neighbor->send_context->task =
GNUNET_SCHEDULER_add_now(&neighbor_send_task, neighbor->send_context);
- }
+ neighbor->send_context->task =
+ GNUNET_SCHEDULER_add_now (&neighbor_send_task, neighbor->send_context);
+ }
}
@@ -2894,10 +3110,10 @@
* @param peer peer identity this notification is about
* @param atsi performance data
*/
-static void
+static void
handle_core_connect (void *cls,
- const struct GNUNET_PeerIdentity * peer,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+ const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
struct DirectNeighbor *neighbor;
struct DistantNeighbor *about;
@@ -2907,54 +3123,69 @@
uint32_t distance;
/* Check for connect to self message */
- if (0 == memcmp(&my_identity, peer, sizeof(struct GNUNET_PeerIdentity)))
+ if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity)))
return;
distance = get_atsi_distance (atsi);
if ((distance == DIRECT_NEIGHBOR_COST) &&
- (GNUNET_CONTAINER_multihashmap_get(direct_neighbors, &peer->hashPubKey)
== NULL))
+ (GNUNET_CONTAINER_multihashmap_get (direct_neighbors, &peer->hashPubKey)
+ == NULL))
{
- peerinfo_iterator = GNUNET_malloc(sizeof(struct PeerIteratorContext));
+ peerinfo_iterator = GNUNET_malloc (sizeof (struct PeerIteratorContext));
neighbor = GNUNET_malloc (sizeof (struct DirectNeighbor));
- neighbor->send_context = GNUNET_malloc(sizeof(struct NeighborSendContext));
+ neighbor->send_context =
+ GNUNET_malloc (sizeof (struct NeighborSendContext));
neighbor->send_context->toNeighbor = neighbor;
memcpy (&neighbor->identity, peer, sizeof (struct GNUNET_PeerIdentity));
- GNUNET_assert(GNUNET_SYSERR != GNUNET_CONTAINER_multihashmap_put
(direct_neighbors,
- &peer->hashPubKey,
- neighbor,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+ GNUNET_assert (GNUNET_SYSERR !=
+ GNUNET_CONTAINER_multihashmap_put (direct_neighbors,
+ &peer->hashPubKey,
+ neighbor,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
about = addUpdateNeighbor (peer, NULL, 0, neighbor, DIRECT_NEIGHBOR_COST);
peerinfo_iterator->distant = about;
peerinfo_iterator->neighbor = neighbor;
peerinfo_iterator->ic = GNUNET_PEERINFO_iterate (peerinfo_handle,
peer,
-
GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3),
- &process_peerinfo,
+
GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS,
+ 3), &process_peerinfo,
peerinfo_iterator);
if ((about != NULL) && (about->pkey == NULL))
- {
+ {
#if DEBUG_DV
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Newly added peer %s has NULL
pkey!\n", GNUNET_i2s(peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Newly added peer %s has NULL pkey!\n", GNUNET_i2s (peer));
#endif
- }
+ }
else if (about != NULL)
- {
- GNUNET_free(peerinfo_iterator);
- }
+ {
+ GNUNET_free (peerinfo_iterator);
+ }
}
else
{
- about = GNUNET_CONTAINER_multihashmap_get(extended_neighbors,
&peer->hashPubKey);
- if ((GNUNET_CONTAINER_multihashmap_get(direct_neighbors,
&peer->hashPubKey) == NULL) && (about != NULL))
- {
- sent = GNUNET_CONTAINER_multihashmap_iterate(direct_neighbors,
&add_distant_all_direct_neighbors, about);
- if (stats != NULL)
- GNUNET_STATISTICS_update (stats, "# direct peers gossiped to new
direct neighbors", sent, GNUNET_NO);
- }
+ about =
+ GNUNET_CONTAINER_multihashmap_get (extended_neighbors,
+ &peer->hashPubKey);
+ if ((GNUNET_CONTAINER_multihashmap_get (direct_neighbors,
&peer->hashPubKey)
+ == NULL) && (about != NULL))
+ {
+ sent =
+ GNUNET_CONTAINER_multihashmap_iterate (direct_neighbors,
+
&add_distant_all_direct_neighbors,
+ about);
+ if (stats != NULL)
+ GNUNET_STATISTICS_update (stats,
+ "# direct peers gossiped to new direct
neighbors",
+ sent, GNUNET_NO);
+ }
#if DEBUG_DV
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "%s: Distance (%d) greater than %d or already know about peer
(%s), not re-adding!\n", "dv", distance, DIRECT_NEIGHBOR_COST,
GNUNET_i2s(peer));
+ "%s: Distance (%d) greater than %d or already know about peer
(%s), not re-adding!\n",
+ "dv", distance, DIRECT_NEIGHBOR_COST, GNUNET_i2s (peer));
#endif
return;
}
@@ -2966,8 +3197,8 @@
* @param cls closure
* @param peer peer identity this notification is about
*/
-void handle_core_disconnect (void *cls,
- const struct GNUNET_PeerIdentity * peer)
+void
+handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
{
struct DirectNeighbor *neighbor;
struct DistantNeighbor *referee;
@@ -2981,28 +3212,31 @@
#endif
/* Check for disconnect from self message */
- if (0 == memcmp(&my_identity, peer, sizeof(struct GNUNET_PeerIdentity)))
+ if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity)))
return;
neighbor =
- GNUNET_CONTAINER_multihashmap_get (direct_neighbors, &peer->hashPubKey);
+ GNUNET_CONTAINER_multihashmap_get (direct_neighbors, &peer->hashPubKey);
if (neighbor == NULL)
- {
- return;
- }
+ {
+ return;
+ }
pending_pos = core_pending_head;
while (NULL != pending_pos)
+ {
+ if (0 ==
+ memcmp (&pending_pos->recipient, &neighbor->identity,
+ sizeof (struct GNUNET_PeerIdentity)))
{
- if (0 == memcmp(&pending_pos->recipient, &neighbor->identity,
sizeof(struct GNUNET_PeerIdentity)))
- {
- GNUNET_CONTAINER_DLL_remove(core_pending_head, core_pending_tail,
pending_pos);
- pending_pos = core_pending_head;
- }
- else
- pending_pos = pending_pos->next;
+ GNUNET_CONTAINER_DLL_remove (core_pending_head, core_pending_tail,
+ pending_pos);
+ pending_pos = core_pending_head;
}
+ else
+ pending_pos = pending_pos->next;
+ }
while (NULL != (referee = neighbor->referee_head))
distant_neighbor_free (referee);
@@ -3010,24 +3244,28 @@
fdc.dest = NULL;
fdc.tid = 0;
- GNUNET_CONTAINER_multihashmap_iterate (extended_neighbors,
&find_distant_peer, &fdc);
+ GNUNET_CONTAINER_multihashmap_iterate (extended_neighbors,
&find_distant_peer,
+ &fdc);
if (fdc.dest != NULL)
- {
- disconnect_context.direct = neighbor;
- disconnect_context.distant = fdc.dest;
- GNUNET_CONTAINER_multihashmap_iterate (direct_neighbors,
&schedule_disconnect_messages, &disconnect_context);
- }
+ {
+ disconnect_context.direct = neighbor;
+ disconnect_context.distant = fdc.dest;
+ GNUNET_CONTAINER_multihashmap_iterate (direct_neighbors,
+ &schedule_disconnect_messages,
+ &disconnect_context);
+ }
GNUNET_assert (neighbor->referee_tail == NULL);
if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_remove (direct_neighbors,
- &peer->hashPubKey,
neighbor))
- {
- GNUNET_break(0);
- }
+ &peer->hashPubKey,
+ neighbor))
+ {
+ GNUNET_break (0);
+ }
if ((neighbor->send_context != NULL) &&
(neighbor->send_context->task != GNUNET_SCHEDULER_NO_TASK))
- GNUNET_SCHEDULER_cancel(neighbor->send_context->task);
+ GNUNET_SCHEDULER_cancel (neighbor->send_context->task);
GNUNET_free (neighbor);
}
@@ -3045,6 +3283,7 @@
const struct GNUNET_CONFIGURATION_Handle *c)
{
unsigned long long max_hosts;
+
cfg = c;
/* FIXME: Read from config, or calculate, or something other than this! */
@@ -3052,58 +3291,59 @@
max_table_size = DEFAULT_DV_SIZE;
fisheye_depth = DEFAULT_FISHEYE_DEPTH;
- if (GNUNET_CONFIGURATION_have_value(cfg, "dv", "max_direct_connections"))
- GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(cfg,
"dv", "max_direct_connections", &max_hosts));
+ if (GNUNET_CONFIGURATION_have_value (cfg, "dv", "max_direct_connections"))
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_number (cfg, "dv",
+
"max_direct_connections",
+ &max_hosts));
- if (GNUNET_CONFIGURATION_have_value(cfg, "dv", "max_total_connections"))
- GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(cfg,
"dv", "max_total_connections", &max_table_size));
+ if (GNUNET_CONFIGURATION_have_value (cfg, "dv", "max_total_connections"))
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_number (cfg, "dv",
+
"max_total_connections",
+ &max_table_size));
- if (GNUNET_CONFIGURATION_have_value(cfg, "dv", "fisheye_depth"))
- GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(cfg,
"dv", "fisheye_depth", &fisheye_depth));
+ if (GNUNET_CONFIGURATION_have_value (cfg, "dv", "fisheye_depth"))
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_number (cfg, "dv",
+ "fisheye_depth",
+ &fisheye_depth));
neighbor_min_heap =
- GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
+ GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
neighbor_max_heap =
- GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MAX);
+ GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MAX);
direct_neighbors = GNUNET_CONTAINER_multihashmap_create (max_hosts);
extended_neighbors =
- GNUNET_CONTAINER_multihashmap_create (max_table_size * 3);
+ GNUNET_CONTAINER_multihashmap_create (max_table_size * 3);
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,
- NULL,
- GNUNET_NO,
- NULL,
- GNUNET_NO,
- core_handlers);
+ coreAPI = GNUNET_CORE_connect (cfg, 1, NULL, /* FIXME: anything we want to
pass around? */
+ &core_init,
+ &handle_core_connect,
+ &handle_core_disconnect,
+ NULL,
+ NULL,
+ GNUNET_NO, NULL, GNUNET_NO, core_handlers);
if (coreAPI == NULL)
return;
- coreMST = GNUNET_SERVER_mst_create (&tokenized_message_handler,
- NULL);
+ coreMST = GNUNET_SERVER_mst_create (&tokenized_message_handler, NULL);
- peerinfo_handle = GNUNET_PEERINFO_connect(cfg);
+ peerinfo_handle = GNUNET_PEERINFO_connect (cfg);
- if (peerinfo_handle == NULL)
- {
- GNUNET_CORE_disconnect(coreAPI);
- return;
- }
+ if (peerinfo_handle == NULL)
+ {
+ GNUNET_CORE_disconnect (coreAPI);
+ return;
+ }
/* Scheduled the task to clean up when shutdown is called */
cleanup_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task,
- NULL);
+ &shutdown_task, NULL);
}
@@ -3121,6 +3361,5 @@
GNUNET_SERVICE_run (argc,
argv,
"dv",
- GNUNET_SERVICE_OPTION_NONE,
- &run, NULL)) ? 0 : 1;
+ GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
}
Modified: gnunet/src/dv/plugin_transport_dv.c
===================================================================
--- gnunet/src/dv/plugin_transport_dv.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/dv/plugin_transport_dv.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -144,38 +144,40 @@
/**
* Handler for messages received from the DV service.
*/
-void handle_dv_message_received (void *cls,
- struct GNUNET_PeerIdentity *sender,
- char *msg,
- size_t msg_len,
- uint32_t distance,
- char *sender_address,
- size_t sender_address_len)
+void
+handle_dv_message_received (void *cls,
+ struct GNUNET_PeerIdentity *sender,
+ char *msg,
+ size_t msg_len,
+ uint32_t distance,
+ char *sender_address, size_t sender_address_len)
{
struct Plugin *plugin = cls;
+
#if DEBUG_DV_MESSAGES
char *my_id;
- my_id = GNUNET_strdup(GNUNET_i2s(plugin->env->my_identity));
+
+ my_id = GNUNET_strdup (GNUNET_i2s (plugin->env->my_identity));
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
"plugin_transport_dv",
_("%s Received message from %s of type %d, distance %u!\n"),
- my_id, GNUNET_i2s(sender), ntohs(((struct
GNUNET_MessageHeader *)msg)->type), distance);
- GNUNET_free_non_null(my_id);
+ my_id, GNUNET_i2s (sender),
+ ntohs (((struct GNUNET_MessageHeader *) msg)->type),
+ distance);
+ GNUNET_free_non_null (my_id);
#endif
struct GNUNET_TRANSPORT_ATS_Information ats[2];
+
ats[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE);
ats[0].value = htonl (distance);
ats[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
ats[1].value = htonl (0);
- plugin->env->receive(plugin->env->cls,
- sender,
- (struct GNUNET_MessageHeader *)msg,
- (const struct GNUNET_TRANSPORT_ATS_Information *) &ats,
- 2,
- NULL,
- sender_address,
- sender_address_len);
+ plugin->env->receive (plugin->env->cls,
+ sender,
+ (struct GNUNET_MessageHeader *) msg,
+ (const struct GNUNET_TRANSPORT_ATS_Information *) &ats,
+ 2, NULL, sender_address, sender_address_len);
}
@@ -218,26 +220,20 @@
size_t msgbuf_size,
unsigned int priority,
struct GNUNET_TIME_Relative timeout,
- struct Session *session,
+ struct Session *session,
const void *addr,
size_t addrlen,
int force_address,
- GNUNET_TRANSPORT_TransmitContinuation
- cont, void *cont_cls)
+ GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
{
int ret = 0;
struct Plugin *plugin = cls;
- ret = GNUNET_DV_send(plugin->dv_handle,
- target,
- msgbuf,
- msgbuf_size,
- priority,
- timeout,
- addr,
- addrlen,
- cont,
- cont_cls);
+ ret = GNUNET_DV_send (plugin->dv_handle,
+ target,
+ msgbuf,
+ msgbuf_size,
+ priority, timeout, addr, addrlen, cont, cont_cls);
return ret;
}
@@ -252,8 +248,7 @@
* @param target peer from which to disconnect
*/
static void
-dv_plugin_disconnect (void *cls,
- const struct GNUNET_PeerIdentity *target)
+dv_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
{
// struct Plugin *plugin = cls;
// TODO: Add message type to send to dv service to "disconnect" a peer
@@ -287,23 +282,28 @@
char *dest_peer;
char *via_peer;
char *print_string;
- char *addr_buf = (char *)addr;
+ char *addr_buf = (char *) addr;
- if (addrlen != sizeof(struct GNUNET_PeerIdentity) * 2)
- {
- asc (asc_cls, NULL);
- }
+ if (addrlen != sizeof (struct GNUNET_PeerIdentity) * 2)
+ {
+ asc (asc_cls, NULL);
+ }
else
- {
- dest_peer = GNUNET_strdup(GNUNET_i2s((struct GNUNET_PeerIdentity
*)addr));
- via_peer = GNUNET_strdup(GNUNET_i2s((struct GNUNET_PeerIdentity
*)&addr_buf[sizeof(struct GNUNET_PeerIdentity)]));
- GNUNET_asprintf(&print_string, "DV Peer `%s' via peer`%s'", dest_peer,
via_peer);
- asc (asc_cls, print_string);
- asc (asc_cls, NULL);
- GNUNET_free(via_peer);
- GNUNET_free(dest_peer);
- GNUNET_free(print_string);
- }
+ {
+ dest_peer =
+ GNUNET_strdup (GNUNET_i2s ((struct GNUNET_PeerIdentity *) addr));
+ via_peer =
+ GNUNET_strdup (GNUNET_i2s
+ ((struct GNUNET_PeerIdentity *)
+ &addr_buf[sizeof (struct GNUNET_PeerIdentity)]));
+ GNUNET_asprintf (&print_string, "DV Peer `%s' via peer`%s'", dest_peer,
+ via_peer);
+ asc (asc_cls, print_string);
+ asc (asc_cls, NULL);
+ GNUNET_free (via_peer);
+ GNUNET_free (dest_peer);
+ GNUNET_free (print_string);
+ }
}
/**
@@ -315,9 +315,8 @@
*
* @return string representing the DV address
*/
-static const char *address_to_string (void *cls,
- const void *addr,
- size_t addrlen)
+static const char *
+address_to_string (void *cls, const void *addr, size_t addrlen)
{
static char return_buffer[2 * 4 + 2]; // Two four character peer identity
prefixes a ':' and '\0'
@@ -325,23 +324,22 @@
struct GNUNET_CRYPTO_HashAsciiEncoded via_hash;
struct GNUNET_PeerIdentity *peer;
struct GNUNET_PeerIdentity *via;
- char *addr_buf = (char *)addr;
+ char *addr_buf = (char *) addr;
- if (addrlen == (2 * sizeof(struct GNUNET_PeerIdentity)))
- {
- peer = (struct GNUNET_PeerIdentity *)addr_buf;
- via = (struct GNUNET_PeerIdentity *)&addr_buf[sizeof(struct
GNUNET_PeerIdentity)];
+ if (addrlen == (2 * sizeof (struct GNUNET_PeerIdentity)))
+ {
+ peer = (struct GNUNET_PeerIdentity *) addr_buf;
+ via =
+ (struct GNUNET_PeerIdentity *)
+ &addr_buf[sizeof (struct GNUNET_PeerIdentity)];
- GNUNET_CRYPTO_hash_to_enc (&peer->hashPubKey, &peer_hash);
- peer_hash.encoding[4] = '\0';
- GNUNET_CRYPTO_hash_to_enc (&via->hashPubKey, &via_hash);
- via_hash.encoding[4] = '\0';
- GNUNET_snprintf (return_buffer,
- sizeof (return_buffer),
- "%s:%s",
- &peer_hash,
- &via_hash);
- }
+ GNUNET_CRYPTO_hash_to_enc (&peer->hashPubKey, &peer_hash);
+ peer_hash.encoding[4] = '\0';
+ GNUNET_CRYPTO_hash_to_enc (&via->hashPubKey, &via_hash);
+ via_hash.encoding[4] = '\0';
+ GNUNET_snprintf (return_buffer,
+ sizeof (return_buffer), "%s:%s", &peer_hash, &via_hash);
+ }
else
return NULL;
@@ -365,17 +363,23 @@
*
*/
static int
-dv_plugin_check_address (void *cls,
- const void *addr, size_t addrlen)
+dv_plugin_check_address (void *cls, const void *addr, size_t addrlen)
{
struct Plugin *plugin = cls;
+
/* Verify that the first peer of this address matches our peer id! */
- if ((addrlen != (2 * sizeof(struct GNUNET_PeerIdentity))) || (0 !=
memcmp(addr, plugin->env->my_identity, sizeof(struct GNUNET_PeerIdentity))))
+ if ((addrlen != (2 * sizeof (struct GNUNET_PeerIdentity))) ||
+ (0 !=
+ memcmp (addr, plugin->env->my_identity,
+ sizeof (struct GNUNET_PeerIdentity))))
{
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: Address not correct size or
identity doesn't match ours!\n", GNUNET_i2s(plugin->env->my_identity));
- if (addrlen == (2 * sizeof(struct GNUNET_PeerIdentity)))
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "%s: Address not correct size or identity doesn't match
ours!\n",
+ GNUNET_i2s (plugin->env->my_identity));
+ if (addrlen == (2 * sizeof (struct GNUNET_PeerIdentity)))
{
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Peer in address is %s\n",
GNUNET_i2s(addr));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer in address is %s\n",
+ GNUNET_i2s (addr));
}
return GNUNET_SYSERR;
}
@@ -396,11 +400,12 @@
plugin = GNUNET_malloc (sizeof (struct Plugin));
plugin->env = env;
- plugin->dv_handle = GNUNET_DV_connect(env->cfg, &handle_dv_message_received,
plugin);
+ plugin->dv_handle =
+ GNUNET_DV_connect (env->cfg, &handle_dv_message_received, plugin);
if (plugin->dv_handle == NULL)
{
- GNUNET_free(plugin);
+ GNUNET_free (plugin);
return NULL;
}
@@ -425,7 +430,7 @@
struct Plugin *plugin = api->cls;
if (plugin->dv_handle != NULL)
- GNUNET_DV_disconnect(plugin->dv_handle);
+ GNUNET_DV_disconnect (plugin->dv_handle);
GNUNET_free (plugin);
GNUNET_free (api);
Modified: gnunet/src/dv/test_transport_api_dv.c
===================================================================
--- gnunet/src/dv/test_transport_api_dv.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/dv/test_transport_api_dv.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -93,11 +93,12 @@
static enum GNUNET_TESTING_Topology topology;
-static enum GNUNET_TESTING_Topology blacklist_topology =
GNUNET_TESTING_TOPOLOGY_NONE; /* Don't do any blacklisting */
+static enum GNUNET_TESTING_Topology blacklist_topology =
GNUNET_TESTING_TOPOLOGY_NONE; /* Don't do any blacklisting */
static enum GNUNET_TESTING_Topology connection_topology =
GNUNET_TESTING_TOPOLOGY_NONE; /* NONE actually means connect all allowed peers
*/
-static enum GNUNET_TESTING_TopologyOption connect_topology_option =
GNUNET_TESTING_TOPOLOGY_OPTION_ALL;
+static enum GNUNET_TESTING_TopologyOption connect_topology_option =
+ GNUNET_TESTING_TOPOLOGY_OPTION_ALL;
static double connect_topology_option_modifier = 0.0;
@@ -167,25 +168,23 @@
/**
* Check whether peers successfully shut down.
*/
-void shutdown_callback (void *cls,
- const char *emsg)
+void
+shutdown_callback (void *cls, const char *emsg)
{
if (emsg != NULL)
- {
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Shutdown of peers failed!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n");
#endif
- if (ok == 0)
- ok = 666;
- }
+ if (ok == 0)
+ ok = 666;
+ }
else
- {
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "All peers successfully shut down!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers successfully shut
down!\n");
#endif
- }
+ }
}
static void
@@ -203,100 +202,102 @@
#endif
peer_pos = all_peers;
while (peer_pos != NULL)
- {
- if (peer_pos->peer_handle != NULL)
- GNUNET_CORE_disconnect(peer_pos->peer_handle);
- free_peer_pos = peer_pos;
- peer_pos = peer_pos->next;
- GNUNET_free(free_peer_pos);
- }
+ {
+ if (peer_pos->peer_handle != NULL)
+ GNUNET_CORE_disconnect (peer_pos->peer_handle);
+ free_peer_pos = peer_pos;
+ peer_pos = peer_pos->next;
+ GNUNET_free (free_peer_pos);
+ }
all_peers = NULL;
pos = test_messages;
while (pos != NULL)
+ {
+ if (pos->peer1handle != NULL)
{
- if (pos->peer1handle != NULL)
- {
- GNUNET_CORE_disconnect(pos->peer1handle);
- pos->peer1handle = NULL;
- }
- if (pos->peer2handle != NULL)
- {
- GNUNET_CORE_disconnect(pos->peer2handle);
- pos->peer2handle = NULL;
- }
- free_pos = pos;
- pos = pos->next;
- if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel(free_pos->disconnect_task);
- }
- GNUNET_free(free_pos);
+ GNUNET_CORE_disconnect (pos->peer1handle);
+ pos->peer1handle = NULL;
}
+ if (pos->peer2handle != NULL)
+ {
+ GNUNET_CORE_disconnect (pos->peer2handle);
+ pos->peer2handle = NULL;
+ }
+ free_pos = pos;
+ pos = pos->next;
+ if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (free_pos->disconnect_task);
+ }
+ GNUNET_free (free_pos);
+ }
pos = other_test_messages;
while (pos != NULL)
+ {
+ if (pos->peer1handle != NULL)
{
- if (pos->peer1handle != NULL)
- {
- GNUNET_CORE_disconnect(pos->peer1handle);
- pos->peer1handle = NULL;
- }
- if (pos->peer2handle != NULL)
- {
- GNUNET_CORE_disconnect(pos->peer2handle);
- pos->peer2handle = NULL;
- }
- free_pos = pos;
- pos = pos->next;
- if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel(free_pos->disconnect_task);
- }
- GNUNET_free(free_pos);
+ GNUNET_CORE_disconnect (pos->peer1handle);
+ pos->peer1handle = NULL;
}
+ if (pos->peer2handle != NULL)
+ {
+ GNUNET_CORE_disconnect (pos->peer2handle);
+ pos->peer2handle = NULL;
+ }
+ free_pos = pos;
+ pos = pos->next;
+ if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (free_pos->disconnect_task);
+ }
+ GNUNET_free (free_pos);
+ }
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "transmit_ready's scheduled %d, failed %d,
transmit_ready's called %d\n", transmit_ready_scheduled, transmit_ready_failed,
transmit_ready_called);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "transmit_ready's scheduled %d, failed %d, transmit_ready's
called %d\n",
+ transmit_ready_scheduled, transmit_ready_failed,
+ transmit_ready_called);
#endif
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Calling daemons_stop\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Calling daemons_stop\n");
#endif
GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "daemons_stop finished\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "daemons_stop finished\n");
#endif
if (dotOutFile != NULL)
- {
- fprintf(dotOutFile, "}");
- fclose(dotOutFile);
- }
+ {
+ fprintf (dotOutFile, "}");
+ fclose (dotOutFile);
+ }
ok = 0;
}
static void
-disconnect_cores (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
+disconnect_cores (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct TestMessageContext *pos = cls;
/* Disconnect from the respective cores */
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Disconnecting from peer 1 `%4s'\n", GNUNET_i2s
(&pos->peer1->id));
+ "Disconnecting from peer 1 `%4s'\n",
+ GNUNET_i2s (&pos->peer1->id));
#endif
if (pos->peer1handle != NULL)
- GNUNET_CORE_disconnect(pos->peer1handle);
+ GNUNET_CORE_disconnect (pos->peer1handle);
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Disconnecting from peer 2 `%4s'\n", GNUNET_i2s
(&pos->peer2->id));
+ "Disconnecting from peer 2 `%4s'\n",
+ GNUNET_i2s (&pos->peer2->id));
#endif
if (pos->peer2handle != NULL)
- GNUNET_CORE_disconnect(pos->peer2handle);
+ GNUNET_CORE_disconnect (pos->peer2handle);
/* Set handles to NULL so test case can be ended properly */
pos->peer1handle = NULL;
pos->peer2handle = NULL;
@@ -306,84 +307,85 @@
}
static void
-end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
+end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
char *msg = cls;
+
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"End badly was called (%s)... stopping daemons.\n", msg);
struct TestMessageContext *pos;
struct TestMessageContext *free_pos;
- struct PeerContext * peer_pos;
- struct PeerContext * free_peer_pos;
+ struct PeerContext *peer_pos;
+ struct PeerContext *free_peer_pos;
peer_pos = all_peers;
while (peer_pos != NULL)
- {
- if (peer_pos->peer_handle != NULL)
- GNUNET_CORE_disconnect(peer_pos->peer_handle);
- free_peer_pos = peer_pos;
- peer_pos = peer_pos->next;
- GNUNET_free(free_peer_pos);
- }
+ {
+ if (peer_pos->peer_handle != NULL)
+ GNUNET_CORE_disconnect (peer_pos->peer_handle);
+ free_peer_pos = peer_pos;
+ peer_pos = peer_pos->next;
+ GNUNET_free (free_peer_pos);
+ }
all_peers = NULL;
pos = test_messages;
while (pos != NULL)
+ {
+ if (pos->peer1handle != NULL)
{
- if (pos->peer1handle != NULL)
- {
- GNUNET_CORE_disconnect(pos->peer1handle);
- pos->peer1handle = NULL;
- }
- if (pos->peer2handle != NULL)
- {
- GNUNET_CORE_disconnect(pos->peer2handle);
- pos->peer2handle = NULL;
- }
- free_pos = pos;
- pos = pos->next;
- GNUNET_free(free_pos);
+ GNUNET_CORE_disconnect (pos->peer1handle);
+ pos->peer1handle = NULL;
}
+ if (pos->peer2handle != NULL)
+ {
+ GNUNET_CORE_disconnect (pos->peer2handle);
+ pos->peer2handle = NULL;
+ }
+ free_pos = pos;
+ pos = pos->next;
+ GNUNET_free (free_pos);
+ }
pos = other_test_messages;
while (pos != NULL)
+ {
+ if (pos->peer1handle != NULL)
{
- if (pos->peer1handle != NULL)
- {
- GNUNET_CORE_disconnect(pos->peer1handle);
- pos->peer1handle = NULL;
- }
- if (pos->peer2handle != NULL)
- {
- GNUNET_CORE_disconnect(pos->peer2handle);
- pos->peer2handle = NULL;
- }
- free_pos = pos;
- pos = pos->next;
- if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel(free_pos->disconnect_task);
- }
- GNUNET_free(free_pos);
+ GNUNET_CORE_disconnect (pos->peer1handle);
+ pos->peer1handle = NULL;
}
+ if (pos->peer2handle != NULL)
+ {
+ GNUNET_CORE_disconnect (pos->peer2handle);
+ pos->peer2handle = NULL;
+ }
+ free_pos = pos;
+ pos = pos->next;
+ if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (free_pos->disconnect_task);
+ }
+ GNUNET_free (free_pos);
+ }
if (pg != NULL)
- {
- GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
- ok = 7331; /* Opposite of leet */
- }
+ {
+ GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
+ ok = 7331; /* Opposite of leet */
+ }
else
ok = 401; /* Never got peers started */
if (dotOutFile != NULL)
- {
- fprintf(dotOutFile, "}");
- fclose(dotOutFile);
- }
+ {
+ fprintf (dotOutFile, "}");
+ fclose (dotOutFile);
+ }
}
static void
-send_other_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext *
tc);
+send_other_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
/**
* Get distance information from 'atsi'.
@@ -394,15 +396,15 @@
static uint32_t
get_atsi_distance (const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
- while ( (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR) &&
- (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE) )
+ while ((ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR) &&
+ (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE))
atsi++;
if (ntohl (atsi->type) == GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR)
- {
- GNUNET_break (0);
- /* FIXME: we do not have distance data? Assume direct neighbor. */
- return 1;
- }
+ {
+ GNUNET_break (0);
+ /* FIXME: we do not have distance data? Assume direct neighbor. */
+ return 1;
+ }
return ntohl (atsi->value);
}
@@ -413,62 +415,74 @@
const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
struct TestMessageContext *pos = cls;
- struct GNUNET_TestMessage *msg = (struct GNUNET_TestMessage *)message;
+ struct GNUNET_TestMessage *msg = (struct GNUNET_TestMessage *) message;
+
#if VERBOSE
uint32_t distance;
#endif
- if (pos->uid != ntohl(msg->uid))
+ if (pos->uid != ntohl (msg->uid))
return GNUNET_OK;
#if VERBOSE
- distance = get_atsi_distance(atsi);
+ distance = get_atsi_distance (atsi);
#endif
- GNUNET_assert(0 == memcmp(peer, &pos->peer1->id, sizeof(struct
GNUNET_PeerIdentity)));
+ GNUNET_assert (0 ==
+ memcmp (peer, &pos->peer1->id,
+ sizeof (struct GNUNET_PeerIdentity)));
if (total_other_expected_messages == 0)
- {
- total_messages_received++;
+ {
+ total_messages_received++;
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received message from `%4s', type %d, uid %u, distance
%u.\n", GNUNET_i2s (peer), ntohs(message->type), ntohl(msg->uid), distance);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Total messages received %d, expected %d.\n",
total_messages_received, expected_messages);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received message from `%4s', type %d, uid %u, distance %u.\n",
+ GNUNET_i2s (peer), ntohs (message->type), ntohl (msg->uid),
+ distance);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Total messages received %d, expected %d.\n",
+ total_messages_received, expected_messages);
#endif
- }
+ }
else
- {
- total_other_messages++;
+ {
+ total_other_messages++;
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received message from `%4s', type %d, uid %u, distance
%u.\n", GNUNET_i2s (peer), ntohs(message->type), ntohl(msg->uid), distance);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Total messages received %d, expected %d.\n",
total_other_messages, total_other_expected_messages);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received message from `%4s', type %d, uid %u, distance %u.\n",
+ GNUNET_i2s (peer), ntohs (message->type), ntohl (msg->uid),
+ distance);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Total messages received %d, expected %d.\n",
+ total_other_messages, total_other_expected_messages);
#endif
- }
+ }
- if ((total_messages_received == expected_messages) && (total_other_messages
== 0))
- {
- GNUNET_SCHEDULER_cancel (die_task);
- die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT,
- &end_badly, "waiting for DV
peers to connect!");
- /*
- if ((num_peers == 3) && (total_other_expected_messages == 2))
- {
- GNUNET_SCHEDULER_add_now (&send_other_messages, NULL);
- }
- else
- {
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_SECONDS, 20), &send_other_messages, NULL);
- }*/
- }
- else if ((total_other_expected_messages > 0) && (total_other_messages ==
total_other_expected_messages))
- {
- GNUNET_SCHEDULER_cancel (die_task);
- GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
- }
+ if ((total_messages_received == expected_messages) &&
+ (total_other_messages == 0))
+ {
+ GNUNET_SCHEDULER_cancel (die_task);
+ die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT,
+ &end_badly,
+ "waiting for DV peers to
connect!");
+ /*
+ * if ((num_peers == 3) && (total_other_expected_messages == 2))
+ * {
+ * GNUNET_SCHEDULER_add_now (&send_other_messages, NULL);
+ * }
+ * else
+ * {
+ * GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_SECONDS, 20), &send_other_messages, NULL);
+ * } */
+ }
+ else if ((total_other_expected_messages > 0) &&
+ (total_other_messages == total_other_expected_messages))
+ {
+ GNUNET_SCHEDULER_cancel (die_task);
+ GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
+ }
else
- {
- pos->disconnect_task = GNUNET_SCHEDULER_add_now(&disconnect_cores, pos);
- }
+ {
+ pos->disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cores, pos);
+ }
return GNUNET_OK;
}
@@ -483,11 +497,13 @@
m = (struct GNUNET_TestMessage *) buf;
m->header.type = htons (MTYPE);
m->header.size = htons (sizeof (struct GNUNET_TestMessage));
- m->uid = htonl(pos->uid);
+ m->uid = htonl (pos->uid);
transmit_ready_called++;
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "transmit ready for peer %s\ntransmit_ready's scheduled %d,
transmit_ready's called %d\n", GNUNET_i2s(&pos->peer1->id),
transmit_ready_scheduled, transmit_ready_called);
+ "transmit ready for peer %s\ntransmit_ready's scheduled %d,
transmit_ready's called %d\n",
+ GNUNET_i2s (&pos->peer1->id), transmit_ready_scheduled,
+ transmit_ready_called);
#endif
return sizeof (struct GNUNET_TestMessage);
}
@@ -510,47 +526,50 @@
* @param peer peer identity this notification is about
* @param atsi performance data for the connection
*/
-static void connect_notify_peer2 (void *cls,
- const struct
- GNUNET_PeerIdentity *peer,
- const struct
GNUNET_TRANSPORT_ATS_Information *atsi)
+static void
+connect_notify_peer2 (void *cls,
+ const struct
+ GNUNET_PeerIdentity *peer,
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
struct TestMessageContext *pos = cls;
- if (0 == memcmp(&pos->peer1->id, peer, sizeof(struct GNUNET_PeerIdentity)))
- {
+ if (0 == memcmp (&pos->peer1->id, peer, sizeof (struct GNUNET_PeerIdentity)))
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Core connection from `%s' to `%4s' verfied, sending
message!\n",
- GNUNET_i2s(&pos->peer2->id), GNUNET_h2s (&peer->hashPubKey));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Core connection from `%s' to `%4s' verfied, sending
message!\n",
+ GNUNET_i2s (&pos->peer2->id), GNUNET_h2s (&peer->hashPubKey));
#endif
- if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle,
- GNUNET_YES,
- 0,
- TIMEOUT,
- &pos->peer2->id,
- sizeof (struct
GNUNET_TestMessage),
- &transmit_ready, pos))
- {
- /* This probably shouldn't happen, but it does (timing issue?) */
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "RECEIVED NULL when asking core (1) for transmission to
peer `%4s'\n",
- GNUNET_i2s (&pos->peer2->id));
- transmit_ready_failed++;
- total_other_expected_messages--;
- }
- else
- {
- transmit_ready_scheduled++;
- }
+ if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle,
+ GNUNET_YES,
+ 0,
+ TIMEOUT,
+ &pos->peer2->id,
+ sizeof (struct
+ GNUNET_TestMessage),
+ &transmit_ready, pos))
+ {
+ /* This probably shouldn't happen, but it does (timing issue?) */
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "RECEIVED NULL when asking core (1) for transmission to peer
`%4s'\n",
+ GNUNET_i2s (&pos->peer2->id));
+ transmit_ready_failed++;
+ total_other_expected_messages--;
}
+ else
+ {
+ transmit_ready_scheduled++;
+ }
+ }
}
static void
init_notify_peer2 (void *cls,
struct GNUNET_CORE_Handle *server,
const struct GNUNET_PeerIdentity *my_identity,
- const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
*publicKey)
+ const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
+ *publicKey)
{
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -568,39 +587,42 @@
* @param peer peer identity this notification is about
* @param atsi performance data for the connection
*/
-static void connect_notify_peer1 (void *cls,
- const struct
- GNUNET_PeerIdentity *peer,
- const struct
GNUNET_TRANSPORT_ATS_Information *atsi)
+static void
+connect_notify_peer1 (void *cls,
+ const struct
+ GNUNET_PeerIdentity *peer,
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
struct TestMessageContext *pos = cls;
- if (0 == memcmp(&pos->peer2->id, peer, sizeof(struct GNUNET_PeerIdentity)))
- {
+ if (0 == memcmp (&pos->peer2->id, peer, sizeof (struct GNUNET_PeerIdentity)))
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Core connection from `%s' to `%4s' verified.\n",
- GNUNET_i2s(&pos->peer1->id), GNUNET_h2s (&peer->hashPubKey));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Core connection from `%s' to `%4s' verified.\n",
+ GNUNET_i2s (&pos->peer1->id), GNUNET_h2s (&peer->hashPubKey));
#endif
- /*
- * Connect to the receiving peer
- */
- pos->peer2handle = GNUNET_CORE_connect (pos->peer2->cfg,
- 1,
- pos,
- &init_notify_peer2,
- &connect_notify_peer2,
- NULL,
- NULL, NULL,
- GNUNET_YES, NULL, GNUNET_YES,
handlers);
- }
+ /*
+ * Connect to the receiving peer
+ */
+ pos->peer2handle = GNUNET_CORE_connect (pos->peer2->cfg,
+ 1,
+ pos,
+ &init_notify_peer2,
+ &connect_notify_peer2,
+ NULL,
+ NULL, NULL,
+ GNUNET_YES, NULL, GNUNET_YES,
+ handlers);
+ }
}
static void
init_notify_peer1 (void *cls,
struct GNUNET_CORE_Handle *server,
const struct GNUNET_PeerIdentity *my_identity,
- const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
*publicKey)
+ const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
+ *publicKey)
{
total_server_connections++;
#if VERBOSE
@@ -612,129 +634,142 @@
static void
-send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
+send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct TestMessageContext *pos = cls;
- if (( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) || (cls == NULL))
+ if (((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) || (cls == NULL))
return;
if (die_task == GNUNET_SCHEDULER_NO_TASK)
- {
- die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT,
- &end_badly, "from create
topology (timeout)");
- }
+ {
+ die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT,
+ &end_badly,
+ "from create topology (timeout)");
+ }
if (total_server_connections >= MAX_OUTSTANDING_CONNECTIONS)
- {
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_SECONDS, 1),
- &send_test_messages, pos);
- return; /* Otherwise we'll double schedule messages here! */
- }
+ {
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 1),
+ &send_test_messages, pos);
+ return; /* Otherwise we'll double schedule messages
here! */
+ }
#if VERBOSE
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Attempting to send test message from %s
to %s\n", pos->peer1->shortname, pos->peer2->shortname);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Attempting to send test message from %s to %s\n",
+ pos->peer1->shortname, pos->peer2->shortname);
#endif
/*
* Connect to the sending peer
*/
pos->peer1handle = GNUNET_CORE_connect (pos->peer1->cfg,
- 1,
+ 1,
pos,
&init_notify_peer1,
&connect_notify_peer1,
NULL,
NULL,
NULL,
- GNUNET_NO, NULL, GNUNET_NO,
no_handlers);
+ GNUNET_NO, NULL, GNUNET_NO,
+ no_handlers);
- GNUNET_assert(pos->peer1handle != NULL);
+ GNUNET_assert (pos->peer1handle != NULL);
if (total_server_connections < MAX_OUTSTANDING_CONNECTIONS)
- {
- GNUNET_SCHEDULER_add_now (&send_test_messages, pos->next);
- }
+ {
+ GNUNET_SCHEDULER_add_now (&send_test_messages, pos->next);
+ }
else
- {
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_SECONDS, 1),
- &send_test_messages, pos->next);
- }
+ {
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 1),
+ &send_test_messages, pos->next);
+ }
}
static void
-send_other_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
+send_other_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct TestMessageContext *pos;
struct TestMessageContext *free_pos;
struct PeerContext *peer_pos;
+
#if TEST_ALL
struct PeerContext *inner_peer_pos;
struct TestMessageContext *temp_context;
#endif
peer_pos = all_peers;
while (peer_pos != NULL)
+ {
+ if (peer_pos->peer_handle != NULL)
{
- if (peer_pos->peer_handle != NULL)
- {
- GNUNET_CORE_disconnect(peer_pos->peer_handle);
- peer_pos->peer_handle = NULL;
- }
+ GNUNET_CORE_disconnect (peer_pos->peer_handle);
+ peer_pos->peer_handle = NULL;
+ }
#if TEST_ALL
- inner_peer_pos = all_peers;
- while (inner_peer_pos != NULL)
- {
- if (inner_peer_pos != peer_pos)
- {
- temp_total_other_messages++;
- temp_context = GNUNET_malloc(sizeof(struct TestMessageContext));
- temp_context->peer1 = peer_pos->daemon;
- temp_context->peer2 = inner_peer_pos->daemon;
- temp_context->next = other_test_messages;
- temp_context->uid = total_connections + temp_total_other_messages;
- temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
- other_test_messages = temp_context;
- }
- inner_peer_pos = inner_peer_pos->next;
- }
+ inner_peer_pos = all_peers;
+ while (inner_peer_pos != NULL)
+ {
+ if (inner_peer_pos != peer_pos)
+ {
+ temp_total_other_messages++;
+ temp_context = GNUNET_malloc (sizeof (struct TestMessageContext));
+ temp_context->peer1 = peer_pos->daemon;
+ temp_context->peer2 = inner_peer_pos->daemon;
+ temp_context->next = other_test_messages;
+ temp_context->uid = total_connections + temp_total_other_messages;
+ temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
+ other_test_messages = temp_context;
+ }
+ inner_peer_pos = inner_peer_pos->next;
+ }
#endif
- peer_pos = peer_pos->next;
- }
+ peer_pos = peer_pos->next;
+ }
all_peers = NULL;
pos = test_messages;
while (pos != NULL)
+ {
+ if (pos->peer1handle != NULL)
{
- if (pos->peer1handle != NULL)
- {
- GNUNET_CORE_disconnect(pos->peer1handle);
- pos->peer1handle = NULL;
- }
- if (pos->peer2handle != NULL)
- {
- GNUNET_CORE_disconnect(pos->peer2handle);
- pos->peer2handle = NULL;
- }
- free_pos = pos;
- pos = pos->next;
- if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel(free_pos->disconnect_task);
- }
- GNUNET_free(free_pos);
+ GNUNET_CORE_disconnect (pos->peer1handle);
+ pos->peer1handle = NULL;
}
+ if (pos->peer2handle != NULL)
+ {
+ GNUNET_CORE_disconnect (pos->peer2handle);
+ pos->peer2handle = NULL;
+ }
+ free_pos = pos;
+ pos = pos->next;
+ if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (free_pos->disconnect_task);
+ }
+ GNUNET_free (free_pos);
+ }
test_messages = NULL;
total_other_expected_messages = temp_total_other_messages;
if (total_other_expected_messages == 0)
- {
- GNUNET_SCHEDULER_add_now (&end_badly, "send_other_messages had 0
messages to send, no DV connections made!");
- }
+ {
+ GNUNET_SCHEDULER_add_now (&end_badly,
+ "send_other_messages had 0 messages to send, no
DV connections made!");
+ }
#if VERBOSE
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Preparing to send %d other test
messages\n", total_other_expected_messages);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Preparing to send %d other test messages\n",
+ total_other_expected_messages);
#endif
GNUNET_SCHEDULER_add_now (&send_test_messages, other_test_messages);
- GNUNET_SCHEDULER_cancel(die_task);
- die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_SECONDS, 250), &end_badly, "from send_other_messages");
+ GNUNET_SCHEDULER_cancel (die_task);
+ die_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 250),
&end_badly,
+ "from send_other_messages");
}
static void
@@ -749,68 +784,73 @@
const char *emsg)
{
struct TestMessageContext *temp_context;
+
if (emsg == NULL)
- {
- total_connections++;
+ {
+ total_connections++;
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s,
distance %u\n",
- first_daemon->shortname,
- second_daemon->shortname,
- distance);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "connected peer %s to peer %s, distance %u\n",
+ first_daemon->shortname, second_daemon->shortname, distance);
#endif
- temp_context = GNUNET_malloc(sizeof(struct TestMessageContext));
- temp_context->peer1 = first_daemon;
- temp_context->peer2 = second_daemon;
- temp_context->next = test_messages;
- temp_context->uid = total_connections;
- temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
- test_messages = temp_context;
- expected_messages++;
- }
+ temp_context = GNUNET_malloc (sizeof (struct TestMessageContext));
+ temp_context->peer1 = first_daemon;
+ temp_context->peer2 = second_daemon;
+ temp_context->next = test_messages;
+ temp_context->uid = total_connections;
+ temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
+ test_messages = temp_context;
+ expected_messages++;
+ }
#if VERBOSE
else
- {
- failed_connections++;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to connect peer %s to peer
%s with error :\n%s\n",
- first_daemon->shortname,
- second_daemon->shortname, emsg);
- }
+ {
+ failed_connections++;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to connect peer %s to peer %s with error :\n%s\n",
+ first_daemon->shortname, second_daemon->shortname, emsg);
+ }
#endif
if (total_connections == expected_connections)
- {
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Created %u total connections, which is our target number!
Calling send messages.\n",
- total_connections);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Created %u total connections, which is our target number!
Calling send messages.\n",
+ total_connections);
#endif
+ GNUNET_SCHEDULER_cancel (die_task);
+ die_task = GNUNET_SCHEDULER_NO_TASK;
+ GNUNET_SCHEDULER_add_now (&send_test_messages, test_messages);
+ }
+ else if (total_connections + failed_connections == expected_connections)
+ {
+ if (failed_connections <
+ (unsigned int) (fail_percentage * total_connections))
+ {
GNUNET_SCHEDULER_cancel (die_task);
die_task = GNUNET_SCHEDULER_NO_TASK;
GNUNET_SCHEDULER_add_now (&send_test_messages, test_messages);
}
- else if (total_connections + failed_connections == expected_connections)
+ else
{
- if (failed_connections < (unsigned int)(fail_percentage *
total_connections))
- {
- GNUNET_SCHEDULER_cancel (die_task);
- die_task = GNUNET_SCHEDULER_NO_TASK;
- GNUNET_SCHEDULER_add_now (&send_test_messages, test_messages);
- }
- else
- {
- GNUNET_SCHEDULER_cancel (die_task);
- die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from
topology_callback (too many failed connections)");
- }
+ GNUNET_SCHEDULER_cancel (die_task);
+ die_task =
+ GNUNET_SCHEDULER_add_now (&end_badly,
+ "from topology_callback (too many failed
connections)");
}
+ }
else
- {
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Have %d total connections, %d failed connections, Want %d
(at least %d)\n",
- total_connections, failed_connections, expected_connections,
expected_connections - (unsigned int)(fail_percentage * expected_connections));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Have %d total connections, %d failed connections, Want %d (at
least %d)\n",
+ total_connections, failed_connections, expected_connections,
+ expected_connections -
+ (unsigned int) (fail_percentage * expected_connections));
#endif
- }
+ }
}
static void
@@ -818,50 +858,56 @@
{
expected_connections = -1;
if ((pg != NULL) && (peers_left == 0))
- {
- expected_connections = GNUNET_TESTING_connect_topology (pg,
-
connection_topology,
-
connect_topology_option,
-
connect_topology_option_modifier,
- TIMEOUT,
- 12,
- NULL, NULL);
+ {
+ expected_connections = GNUNET_TESTING_connect_topology (pg,
+
connection_topology,
+
connect_topology_option,
+
connect_topology_option_modifier,
+ TIMEOUT,
+ 12, NULL, NULL);
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Have %d expected connections\n", expected_connections);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Have %d expected connections\n", expected_connections);
#endif
- }
+ }
GNUNET_SCHEDULER_cancel (die_task);
if (expected_connections == GNUNET_SYSERR)
- {
- die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from connect topology
(bad return)");
- }
+ {
+ die_task =
+ GNUNET_SCHEDULER_add_now (&end_badly,
+ "from connect topology (bad return)");
+ }
die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT,
- &end_badly, "from connect topology
(timeout)");
+ &end_badly,
+ "from connect topology (timeout)");
}
static void
create_topology ()
{
- peers_left = num_peers; /* Reset counter */
- if (GNUNET_TESTING_create_topology (pg, topology, blacklist_topology,
blacklist_transports) != GNUNET_SYSERR)
- {
+ peers_left = num_peers; /* Reset counter */
+ if (GNUNET_TESTING_create_topology
+ (pg, topology, blacklist_topology, blacklist_transports) !=
GNUNET_SYSERR)
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Topology set up, now starting peers!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Topology set up, now starting peers!\n");
#endif
- GNUNET_TESTING_daemons_continue_startup(pg);
- }
+ GNUNET_TESTING_daemons_continue_startup (pg);
+ }
else
- {
- GNUNET_SCHEDULER_cancel (die_task);
- die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from create topology
(bad return)");
- }
+ {
+ GNUNET_SCHEDULER_cancel (die_task);
+ die_task =
+ GNUNET_SCHEDULER_add_now (&end_badly,
+ "from create topology (bad return)");
+ }
GNUNET_SCHEDULER_cancel (die_task);
die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT,
- &end_badly, "from continue startup
(timeout)");
+ &end_badly,
+ "from continue startup (timeout)");
}
/**
@@ -872,126 +918,134 @@
* @param latency reported latency of the connection with 'other'
* @param distance reported distance (DV) to 'other'
*/
-static void all_connect_handler (void *cls,
- const struct
- GNUNET_PeerIdentity * peer,
- const struct GNUNET_TRANSPORT_ATS_Information
*atsi)
+static void
+all_connect_handler (void *cls,
+ const struct
+ GNUNET_PeerIdentity *peer,
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
struct GNUNET_TESTING_Daemon *d = cls;
struct GNUNET_TESTING_Daemon *second_daemon;
char *second_shortname;
+
#if !TEST_ALL
struct TestMessageContext *temp_context;
#endif
uint32_t distance;
- if (0 == memcmp(&d->id, peer, sizeof(struct GNUNET_PeerIdentity)))
+ if (0 == memcmp (&d->id, peer, sizeof (struct GNUNET_PeerIdentity)))
return;
- second_shortname = GNUNET_strdup (GNUNET_i2s(peer));
- distance = get_atsi_distance(atsi);
+ second_shortname = GNUNET_strdup (GNUNET_i2s (peer));
+ distance = get_atsi_distance (atsi);
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "connected peer %s to peer %s, distance %u\n",
- d->shortname,
- second_shortname,
- distance);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "connected peer %s to peer %s, distance %u\n",
+ d->shortname, second_shortname, distance);
#endif
- second_daemon = GNUNET_CONTAINER_multihashmap_get(peer_daemon_hash,
&peer->hashPubKey);
+ second_daemon =
+ GNUNET_CONTAINER_multihashmap_get (peer_daemon_hash, &peer->hashPubKey);
if (second_daemon == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Couldn't find second peer!\n");
- GNUNET_free(second_shortname);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Couldn't find second peer!\n");
+ GNUNET_free (second_shortname);
+ return;
+ }
#if !TEST_ALL
if (distance > 1)
- {
- temp_total_other_messages++;
- temp_context = GNUNET_malloc(sizeof(struct TestMessageContext));
- temp_context->peer1 = d;
- temp_context->peer2 = second_daemon;
- temp_context->next = other_test_messages;
- temp_context->uid = total_connections + temp_total_other_messages;
- temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
- other_test_messages = temp_context;
- }
+ {
+ temp_total_other_messages++;
+ temp_context = GNUNET_malloc (sizeof (struct TestMessageContext));
+ temp_context->peer1 = d;
+ temp_context->peer2 = second_daemon;
+ temp_context->next = other_test_messages;
+ temp_context->uid = total_connections + temp_total_other_messages;
+ temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
+ other_test_messages = temp_context;
+ }
#endif
if (dotOutFile != NULL)
- {
- if (distance == 1)
- fprintf(dotOutFile, "\tn%s -- n%s;\n", d->shortname, second_shortname);
- else if (distance == 2)
- fprintf(dotOutFile, "\tn%s -- n%s [color=blue];\n", d->shortname,
second_shortname);
- else if (distance == 3)
- fprintf(dotOutFile, "\tn%s -- n%s [color=red];\n", d->shortname,
second_shortname);
- else if (distance == 4)
- fprintf(dotOutFile, "\tn%s -- n%s [color=green];\n", d->shortname,
second_shortname);
- else
- fprintf(dotOutFile, "\tn%s -- n%s [color=brown];\n", d->shortname,
second_shortname);
- }
- GNUNET_free(second_shortname);
+ {
+ if (distance == 1)
+ fprintf (dotOutFile, "\tn%s -- n%s;\n", d->shortname, second_shortname);
+ else if (distance == 2)
+ fprintf (dotOutFile, "\tn%s -- n%s [color=blue];\n", d->shortname,
+ second_shortname);
+ else if (distance == 3)
+ fprintf (dotOutFile, "\tn%s -- n%s [color=red];\n", d->shortname,
+ second_shortname);
+ else if (distance == 4)
+ fprintf (dotOutFile, "\tn%s -- n%s [color=green];\n", d->shortname,
+ second_shortname);
+ else
+ fprintf (dotOutFile, "\tn%s -- n%s [color=brown];\n", d->shortname,
+ second_shortname);
+ }
+ GNUNET_free (second_shortname);
if (temp_total_other_messages == num_additional_messages)
- {
- GNUNET_SCHEDULER_add_now (&send_other_messages, NULL);
- }
+ {
+ GNUNET_SCHEDULER_add_now (&send_other_messages, NULL);
+ }
}
static void
peers_started_callback (void *cls,
- const struct GNUNET_PeerIdentity *id,
- const struct GNUNET_CONFIGURATION_Handle *cfg,
- struct GNUNET_TESTING_Daemon *d, const char *emsg)
+ const struct GNUNET_PeerIdentity *id,
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ struct GNUNET_TESTING_Daemon *d, const char *emsg)
{
struct PeerContext *new_peer;
+
if (emsg != NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to start daemon with error:
`%s'\n",
- emsg);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to start daemon with error: `%s'\n", emsg);
+ return;
+ }
GNUNET_assert (id != NULL);
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n",
(num_peers - peers_left) + 1, num_peers);
#endif
- GNUNET_assert(GNUNET_SYSERR !=
GNUNET_CONTAINER_multihashmap_put(peer_daemon_hash, &id->hashPubKey, d,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+ GNUNET_assert (GNUNET_SYSERR !=
+ GNUNET_CONTAINER_multihashmap_put (peer_daemon_hash,
+ &id->hashPubKey, d,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
- new_peer = GNUNET_malloc(sizeof(struct PeerContext));
- new_peer->peer_handle = GNUNET_CORE_connect(cfg,
- 1,
- d, NULL,
- &all_connect_handler,
- NULL, NULL, NULL,
- GNUNET_NO, NULL, GNUNET_NO,
- no_handlers);
+ new_peer = GNUNET_malloc (sizeof (struct PeerContext));
+ new_peer->peer_handle = GNUNET_CORE_connect (cfg,
+ 1,
+ d, NULL,
+ &all_connect_handler,
+ NULL, NULL, NULL,
+ GNUNET_NO, NULL, GNUNET_NO,
+ no_handlers);
new_peer->daemon = d;
new_peer->next = all_peers;
all_peers = new_peer;
peers_left--;
if (peers_left == 0)
- {
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "All %d daemons started, now creating topology!\n",
- num_peers);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "All %d daemons started, now creating topology!\n", num_peers);
#endif
- GNUNET_SCHEDULER_cancel (die_task);
- /* Set up task in case topology creation doesn't finish
- * within a reasonable amount of time */
- die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_MINUTES, 5),
- &end_badly, "from
peers_started_callback");
+ GNUNET_SCHEDULER_cancel (die_task);
+ /* Set up task in case topology creation doesn't finish
+ * within a reasonable amount of time */
+ die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MINUTES, 5),
+ &end_badly,
+ "from peers_started_callback");
- connect_topology ();
- ok = 0;
- }
+ connect_topology ();
+ ok = 0;
+ }
}
/**
@@ -1004,37 +1058,36 @@
*/
static void
hostkey_callback (void *cls,
- const struct GNUNET_PeerIdentity *id,
- struct GNUNET_TESTING_Daemon *d,
- const char *emsg)
+ const struct GNUNET_PeerIdentity *id,
+ struct GNUNET_TESTING_Daemon *d, const char *emsg)
{
if (emsg != NULL)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Hostkey callback received error:
%s\n", emsg);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Hostkey callback received error: %s\n", emsg);
+ }
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Hostkey created for peer `%s'\n",
- GNUNET_i2s(id));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Hostkey created for peer `%s'\n", GNUNET_i2s (id));
#endif
- peers_left--;
- if (peers_left == 0)
- {
+ peers_left--;
+ if (peers_left == 0)
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "All %d hostkeys created, now creating topology!\n",
- num_peers);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "All %d hostkeys created, now creating topology!\n",
num_peers);
#endif
- GNUNET_SCHEDULER_cancel (die_task);
- /* Set up task in case topology creation doesn't finish
- * within a reasonable amount of time */
- die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_MINUTES, 5),
- &end_badly, "from
hostkey_callback");
- GNUNET_SCHEDULER_add_now(&create_topology, NULL);
- ok = 0;
- }
+ GNUNET_SCHEDULER_cancel (die_task);
+ /* Set up task in case topology creation doesn't finish
+ * within a reasonable amount of time */
+ die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MINUTES, 5),
+ &end_badly,
+ "from hostkey_callback");
+ GNUNET_SCHEDULER_add_now (&create_topology, NULL);
+ ok = 0;
+ }
}
static void
@@ -1042,117 +1095,141 @@
char *const *args,
const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
- char * topology_str;
- char * connect_topology_str;
- char * blacklist_topology_str;
- char * connect_topology_option_str;
- char * connect_topology_option_modifier_string;
+ char *topology_str;
+ char *connect_topology_str;
+ char *blacklist_topology_str;
+ char *connect_topology_option_str;
+ char *connect_topology_option_modifier_string;
+
ok = 1;
dotOutFile = fopen (dotOutFileName, "w");
if (dotOutFile != NULL)
- {
- fprintf (dotOutFile, "strict graph G {\n");
- }
+ {
+ fprintf (dotOutFile, "strict graph G {\n");
+ }
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Starting daemons based on config file %s\n", cfgfile);
#endif
- if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string(cfg, "paths",
"servicehome", &test_directory))
- {
- ok = 404;
- return;
- }
+ if (GNUNET_YES !=
+ GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome",
+ &test_directory))
+ {
+ ok = 404;
+ return;
+ }
if ((GNUNET_YES ==
- GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "topology",
- &topology_str)) && (GNUNET_NO ==
GNUNET_TESTING_topology_get(&topology, topology_str)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Invalid topology `%s' given for section %s option %s\n",
topology_str, "TESTING", "TOPOLOGY");
- topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set
better default here */
- }
+ GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "topology",
+ &topology_str)) &&
+ (GNUNET_NO == GNUNET_TESTING_topology_get (&topology, topology_str)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Invalid topology `%s' given for section %s option %s\n",
+ topology_str, "TESTING", "TOPOLOGY");
+ topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set
better default here */
+ }
if ((GNUNET_YES ==
- GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "connect_topology",
- &connect_topology_str)) &&
(GNUNET_NO == GNUNET_TESTING_topology_get(&connection_topology,
connect_topology_str)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Invalid connect topology `%s' given for section %s option
%s\n", connect_topology_str, "TESTING", "CONNECT_TOPOLOGY");
- }
- GNUNET_free_non_null(connect_topology_str);
+ GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
+ "connect_topology",
+ &connect_topology_str)) &&
+ (GNUNET_NO ==
+ GNUNET_TESTING_topology_get (&connection_topology,
+ connect_topology_str)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Invalid connect topology `%s' given for section %s option
%s\n",
+ connect_topology_str, "TESTING", "CONNECT_TOPOLOGY");
+ }
+ GNUNET_free_non_null (connect_topology_str);
if ((GNUNET_YES ==
- GNUNET_CONFIGURATION_get_value_string(cfg, "testing",
"connect_topology_option",
- &connect_topology_option_str)) &&
(GNUNET_NO == GNUNET_TESTING_topology_option_get(&connect_topology_option,
connect_topology_option_str)))
+ GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
+ "connect_topology_option",
+ &connect_topology_option_str)) &&
+ (GNUNET_NO ==
+ GNUNET_TESTING_topology_option_get (&connect_topology_option,
+ connect_topology_option_str)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Invalid connect topology option `%s' given for section %s
option %s\n",
+ connect_topology_option_str, "TESTING",
+ "CONNECT_TOPOLOGY_OPTION");
+ connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /*
Defaults to NONE, set to ALL */
+ }
+ GNUNET_free_non_null (connect_topology_option_str);
+ if (GNUNET_YES ==
+ GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
+
"connect_topology_option_modifier",
+
&connect_topology_option_modifier_string))
+ {
+ if (sscanf
+ (connect_topology_option_modifier_string, "%lf",
+ &connect_topology_option_modifier) != 1)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Invalid connect topology option `%s' given for section %s
option %s\n", connect_topology_option_str, "TESTING",
"CONNECT_TOPOLOGY_OPTION");
- connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /*
Defaults to NONE, set to ALL */
+ _
+ ("Invalid value `%s' for option `%s' in section `%s':
expected float\n"),
+ connect_topology_option_modifier_string,
+ "connect_topology_option_modifier", "TESTING");
}
- GNUNET_free_non_null(connect_topology_option_str);
- if (GNUNET_YES ==
- GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
"connect_topology_option_modifier",
-
&connect_topology_option_modifier_string))
- {
- if (sscanf(connect_topology_option_modifier_string, "%lf",
&connect_topology_option_modifier) != 1)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Invalid value `%s' for option `%s' in section `%s': expected
float\n"),
- connect_topology_option_modifier_string,
- "connect_topology_option_modifier",
- "TESTING");
- }
- GNUNET_free (connect_topology_option_modifier_string);
- }
+ GNUNET_free (connect_topology_option_modifier_string);
+ }
- if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
"blacklist_transports",
- &blacklist_transports))
+ if (GNUNET_YES !=
+ GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
+ "blacklist_transports",
+ &blacklist_transports))
blacklist_transports = NULL;
if ((GNUNET_YES ==
- GNUNET_CONFIGURATION_get_value_string(cfg, "testing",
"blacklist_topology",
- &blacklist_topology_str)) &&
(GNUNET_NO == GNUNET_TESTING_topology_get(&blacklist_topology,
blacklist_topology_str)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Invalid topology `%s' given for section %s option %s\n",
topology_str, "TESTING", "BLACKLIST_TOPOLOGY");
- }
- GNUNET_free_non_null(topology_str);
- GNUNET_free_non_null(blacklist_topology_str);
+ GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
+ "blacklist_topology",
+ &blacklist_topology_str)) &&
+ (GNUNET_NO ==
+ GNUNET_TESTING_topology_get (&blacklist_topology,
+ blacklist_topology_str)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Invalid topology `%s' given for section %s option %s\n",
+ topology_str, "TESTING", "BLACKLIST_TOPOLOGY");
+ }
+ GNUNET_free_non_null (topology_str);
+ GNUNET_free_non_null (blacklist_topology_str);
if (GNUNET_SYSERR ==
GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers",
&num_peers))
num_peers = DEFAULT_NUM_PEERS;
if (GNUNET_SYSERR ==
- GNUNET_CONFIGURATION_get_value_number (cfg, "testing",
"additional_messages",
+ GNUNET_CONFIGURATION_get_value_number (cfg, "testing",
+ "additional_messages",
&num_additional_messages))
num_additional_messages = DEFAULT_ADDITIONAL_MESSAGES;
main_cfg = cfg;
- GNUNET_assert(num_peers > 0 && num_peers < (unsigned int)-1);
+ GNUNET_assert (num_peers > 0 && num_peers < (unsigned int) -1);
peers_left = num_peers;
/* Set up a task to end testing if peer start fails */
die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_MINUTES, 5),
- &end_badly, "didn't start all
daemons in reasonable amount of time!!!");
+ &end_badly,
+ "didn't start all daemons in
reasonable amount of time!!!");
- peer_daemon_hash = GNUNET_CONTAINER_multihashmap_create(peers_left);
- pg = GNUNET_TESTING_daemons_start (cfg,
- peers_left, /* Total number of peers */
- peers_left, /* Number of outstanding
connections */
- peers_left, /* Number of parallel ssh
connections, or peers being started at once */
+ peer_daemon_hash = GNUNET_CONTAINER_multihashmap_create (peers_left);
+ pg = GNUNET_TESTING_daemons_start (cfg, peers_left, /* Total number of
peers */
+ peers_left, /* Number of
outstanding connections */
+ peers_left, /* Number of parallel
ssh connections, or peers being started at once */
TIMEOUT,
&hostkey_callback,
NULL,
&peers_started_callback,
- NULL,
- &topology_callback,
- NULL,
- NULL);
+ NULL, &topology_callback, NULL, NULL);
}
@@ -1160,7 +1237,8 @@
check ()
{
int ret;
- char *const argv[] = {"test-transport-dv",
+
+ char *const argv[] = { "test-transport-dv",
"-c",
"test_transport_dv_data.conf",
#if VERBOSE
@@ -1172,12 +1250,13 @@
GNUNET_GETOPT_OPTION_END
};
ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
- argv, "test-transport-dv", "nohelp",
- options, &run, &ok);
+ argv, "test-transport-dv", "nohelp",
+ options, &run, &ok);
if (ret != GNUNET_OK)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "`test-transport-dv': Failed with
error code %d\n", ret);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "`test-transport-dv': Failed with error code %d\n", ret);
+ }
return ok;
}
@@ -1199,9 +1278,10 @@
* of by the testing framework.
*/
if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to remove testing
directory %s\n", test_directory);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to remove testing directory %s\n", test_directory);
+ }
return ret;
}
Modified: gnunet/src/fragmentation/defragmentation.c
===================================================================
--- gnunet/src/fragmentation/defragmentation.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/fragmentation/defragmentation.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -69,7 +69,7 @@
/**
* Pointer to the assembled message, allocated at the
* end of this struct.
- */
+ */
const struct GNUNET_MessageHeader *msg;
/**
@@ -183,7 +183,7 @@
/**
* Maximum message size for each fragment.
- */
+ */
uint16_t mtu;
};
@@ -203,11 +203,11 @@
*/
struct GNUNET_DEFRAGMENT_Context *
GNUNET_DEFRAGMENT_context_create (struct GNUNET_STATISTICS_Handle *stats,
- uint16_t mtu,
- unsigned int num_msgs,
- void *cls,
- GNUNET_FRAGMENT_MessageProcessor proc,
- GNUNET_DEFRAGMENT_AckProcessor ackp)
+ uint16_t mtu,
+ unsigned int num_msgs,
+ void *cls,
+ GNUNET_FRAGMENT_MessageProcessor proc,
+ GNUNET_DEFRAGMENT_AckProcessor ackp)
{
struct GNUNET_DEFRAGMENT_Context *dc;
@@ -218,7 +218,7 @@
dc->ackp = ackp;
dc->num_msgs = num_msgs;
dc->mtu = mtu;
- dc->latency = GNUNET_TIME_UNIT_SECONDS; /* start with likely overestimate */
+ dc->latency = GNUNET_TIME_UNIT_SECONDS; /* start with likely
overestimate */
return dc;
}
@@ -228,24 +228,22 @@
*
* @param dc defragmentation context
*/
-void
+void
GNUNET_DEFRAGMENT_context_destroy (struct GNUNET_DEFRAGMENT_Context *dc)
{
struct MessageContext *mc;
while (NULL != (mc = dc->head))
+ {
+ GNUNET_CONTAINER_DLL_remove (dc->head, dc->tail, mc);
+ dc->list_size--;
+ if (GNUNET_SCHEDULER_NO_TASK != mc->ack_task)
{
- GNUNET_CONTAINER_DLL_remove (dc->head,
- dc->tail,
- mc);
- dc->list_size--;
- if (GNUNET_SCHEDULER_NO_TASK != mc->ack_task)
- {
- GNUNET_SCHEDULER_cancel (mc->ack_task);
- mc->ack_task = GNUNET_SCHEDULER_NO_TASK;
- }
- GNUNET_free (mc);
+ GNUNET_SCHEDULER_cancel (mc->ack_task);
+ mc->ack_task = GNUNET_SCHEDULER_NO_TASK;
}
+ GNUNET_free (mc);
+ }
GNUNET_assert (0 == dc->list_size);
GNUNET_free (dc);
}
@@ -258,8 +256,7 @@
* @param tc the scheduler context
*/
static void
-send_ack (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+send_ack (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct MessageContext *mc = cls;
struct GNUNET_DEFRAGMENT_Context *dc = mc->dc;
@@ -271,9 +268,8 @@
fa.fragment_id = htonl (mc->fragment_id);
fa.bits = GNUNET_htonll (mc->bits);
GNUNET_STATISTICS_update (mc->dc->stats,
- _("# acknowledgements sent for fragment"),
- 1,
- GNUNET_NO);
+ _("# acknowledgements sent for fragment"),
+ 1, GNUNET_NO);
dc->ackp (dc->cls, mc->fragment_id, &fa.header);
}
@@ -285,27 +281,26 @@
static void
gsl_fit_mul (const double *x, const size_t xstride,
const double *y, const size_t ystride,
- const size_t n,
- double *c1, double *cov_11, double *sumsq)
+ const size_t n, double *c1, double *cov_11, double *sumsq)
{
double m_x = 0, m_y = 0, m_dx2 = 0, m_dxdy = 0;
size_t i;
for (i = 0; i < n; i++)
- {
- m_x += (x[i * xstride] - m_x) / (i + 1.0);
- m_y += (y[i * ystride] - m_y) / (i + 1.0);
- }
+ {
+ m_x += (x[i * xstride] - m_x) / (i + 1.0);
+ m_y += (y[i * ystride] - m_y) / (i + 1.0);
+ }
for (i = 0; i < n; i++)
- {
- const double dx = x[i * xstride] - m_x;
- const double dy = y[i * ystride] - m_y;
+ {
+ const double dx = x[i * xstride] - m_x;
+ const double dy = y[i * ystride] - m_y;
- m_dx2 += (dx * dx - m_dx2) / (i + 1.0);
- m_dxdy += (dx * dy - m_dxdy) / (i + 1.0);
- }
+ m_dx2 += (dx * dx - m_dx2) / (i + 1.0);
+ m_dxdy += (dx * dy - m_dxdy) / (i + 1.0);
+ }
/* In terms of y = b x */
@@ -318,13 +313,14 @@
/* Compute chi^2 = \sum (y_i - b * x_i)^2 */
for (i = 0; i < n; i++)
- {
- const double dx = x[i * xstride] - m_x;
- const double dy = y[i * ystride] - m_y;
- const double d = (m_y - b * m_x) + dy - b * dx;
- d2 += d * d;
- }
+ {
+ const double dx = x[i * xstride] - m_x;
+ const double dy = y[i * ystride] - m_y;
+ const double d = (m_y - b * m_x) + dy - b * dx;
+ d2 += d * d;
+ }
+
s2 = d2 / (n - 1.0); /* chisq per degree of freedom */
*cov_11 = s2 * 1.0 / (n * (m_x * m_x + m_dx2));
@@ -356,16 +352,16 @@
first = &mc->frag_times[mc->frag_times_start_offset];
GNUNET_assert (total > 1);
- for (i=0;i<total;i++)
- {
- x[i] = (double) i;
- y[i] = (double) (first[i].time.abs_value - first[0].time.abs_value);
- }
- gsl_fit_mul (x, 1, y, 1, total, &c1, &cov11, &sumsq);
- c1 += sqrt (sumsq); /* add 1 std dev */
+ for (i = 0; i < total; i++)
+ {
+ x[i] = (double) i;
+ y[i] = (double) (first[i].time.abs_value - first[0].time.abs_value);
+ }
+ gsl_fit_mul (x, 1, y, 1, total, &c1, &cov11, &sumsq);
+ c1 += sqrt (sumsq); /* add 1 std dev */
ret.rel_value = (uint64_t) c1;
if (ret.rel_value == 0)
- ret = GNUNET_TIME_UNIT_MILLISECONDS; /* always at least 1 */
+ ret = GNUNET_TIME_UNIT_MILLISECONDS; /* always at least 1 */
return ret;
};
@@ -384,22 +380,20 @@
old = NULL;
pos = dc->head;
while (NULL != pos)
- {
- if ( (old == NULL) ||
- (old->last_update.abs_value > pos->last_update.abs_value) )
- old = pos;
- pos = pos->next;
- }
+ {
+ if ((old == NULL) ||
+ (old->last_update.abs_value > pos->last_update.abs_value))
+ old = pos;
+ pos = pos->next;
+ }
GNUNET_assert (NULL != old);
- GNUNET_CONTAINER_DLL_remove (dc->head,
- dc->tail,
- old);
+ GNUNET_CONTAINER_DLL_remove (dc->head, dc->tail, old);
dc->list_size--;
if (GNUNET_SCHEDULER_NO_TASK != old->ack_task)
- {
- GNUNET_SCHEDULER_cancel (old->ack_task);
- old->ack_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (old->ack_task);
+ old->ack_task = GNUNET_SCHEDULER_NO_TASK;
+ }
GNUNET_free (old);
}
@@ -411,9 +405,9 @@
* @param msg the message that was received
* @return GNUNET_OK on success, GNUNET_NO if this was a duplicate,
GNUNET_SYSERR on error
*/
-int
+int
GNUNET_DEFRAGMENT_process_fragment (struct GNUNET_DEFRAGMENT_Context *dc,
- const struct GNUNET_MessageHeader *msg)
+ const struct GNUNET_MessageHeader *msg)
{
struct MessageContext *mc;
const struct FragmentHeader *fh;
@@ -429,135 +423,122 @@
unsigned int n;
int duplicate;
- if (ntohs(msg->size) < sizeof (struct FragmentHeader))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
+ if (ntohs (msg->size) < sizeof (struct FragmentHeader))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
if (ntohs (msg->size) > dc->mtu)
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- fh = (const struct FragmentHeader*) msg;
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ fh = (const struct FragmentHeader *) msg;
msize = ntohs (fh->total_size);
if (msize < sizeof (struct GNUNET_MessageHeader))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
fid = ntohl (fh->fragment_id);
foff = ntohs (fh->offset);
if (foff >= msize)
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
if (0 != (foff % (dc->mtu - sizeof (struct FragmentHeader))))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- GNUNET_STATISTICS_update (dc->stats,
- _("# fragments received"),
- 1,
- GNUNET_NO);
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ GNUNET_STATISTICS_update (dc->stats, _("# fragments received"), 1,
GNUNET_NO);
mc = dc->head;
- while ( (NULL != mc) &&
- (fid != mc->fragment_id) )
+ while ((NULL != mc) && (fid != mc->fragment_id))
mc = mc->next;
bit = foff / (dc->mtu - sizeof (struct FragmentHeader));
- if (bit * (dc->mtu - sizeof (struct FragmentHeader)) + ntohs (msg->size)
+ if (bit * (dc->mtu - sizeof (struct FragmentHeader)) + ntohs (msg->size)
- sizeof (struct FragmentHeader) > msize)
- {
- /* payload extends past total message size */
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- if ( (NULL != mc) && (msize != mc->total_size) )
- {
- /* inconsistent message size */
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
+ {
+ /* payload extends past total message size */
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ if ((NULL != mc) && (msize != mc->total_size))
+ {
+ /* inconsistent message size */
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
now = GNUNET_TIME_absolute_get ();
if (NULL == mc)
- {
- mc = GNUNET_malloc (sizeof (struct MessageContext) + msize);
- mc->msg = (const struct GNUNET_MessageHeader*) &mc[1];
- mc->dc = dc;
- mc->total_size = msize;
- mc->fragment_id = fid;
- mc->last_update = now;
- n = (msize + dc->mtu - sizeof (struct FragmentHeader) - 1) / (dc->mtu -
sizeof (struct FragmentHeader));
- if (n == 64)
- mc->bits = UINT64_MAX; /* set all 64 bit */
- else
- mc->bits = (1LL << n) - 1; /* set lowest 'bits' bit */
- if (dc->list_size >= dc->num_msgs)
- discard_oldest_mc (dc);
- GNUNET_CONTAINER_DLL_insert (dc->head,
- dc->tail,
- mc);
- dc->list_size++;
- }
+ {
+ mc = GNUNET_malloc (sizeof (struct MessageContext) + msize);
+ mc->msg = (const struct GNUNET_MessageHeader *) &mc[1];
+ mc->dc = dc;
+ mc->total_size = msize;
+ mc->fragment_id = fid;
+ mc->last_update = now;
+ n = (msize + dc->mtu - sizeof (struct FragmentHeader) - 1) / (dc->mtu -
+ sizeof
(struct
+
FragmentHeader));
+ if (n == 64)
+ mc->bits = UINT64_MAX; /* set all 64 bit */
+ else
+ mc->bits = (1LL << n) - 1; /* set lowest 'bits' bit */
+ if (dc->list_size >= dc->num_msgs)
+ discard_oldest_mc (dc);
+ GNUNET_CONTAINER_DLL_insert (dc->head, dc->tail, mc);
+ dc->list_size++;
+ }
/* copy data to 'mc' */
if (0 != (mc->bits & (1LL << bit)))
- {
- mc->bits -= 1LL << bit;
- mbuf = (char* )&mc[1];
- memcpy (&mbuf[bit * (dc->mtu - sizeof (struct FragmentHeader))],
- &fh[1],
- ntohs (msg->size) - sizeof (struct FragmentHeader));
- mc->last_update = now;
- if (bit < mc->last_bit)
- mc->frag_times_start_offset = mc->frag_times_write_offset;
- mc->last_bit = bit;
- mc->frag_times[mc->frag_times_write_offset].time = now;
- mc->frag_times[mc->frag_times_write_offset].bit = bit;
- mc->frag_times_write_offset++;
- duplicate = GNUNET_NO;
- }
+ {
+ mc->bits -= 1LL << bit;
+ mbuf = (char *) &mc[1];
+ memcpy (&mbuf[bit * (dc->mtu - sizeof (struct FragmentHeader))],
+ &fh[1], ntohs (msg->size) - sizeof (struct FragmentHeader));
+ mc->last_update = now;
+ if (bit < mc->last_bit)
+ mc->frag_times_start_offset = mc->frag_times_write_offset;
+ mc->last_bit = bit;
+ mc->frag_times[mc->frag_times_write_offset].time = now;
+ mc->frag_times[mc->frag_times_write_offset].bit = bit;
+ mc->frag_times_write_offset++;
+ duplicate = GNUNET_NO;
+ }
else
- {
- duplicate = GNUNET_YES;
- GNUNET_STATISTICS_update (dc->stats,
- _("# duplicate fragments received"),
- 1,
- GNUNET_NO);
- }
+ {
+ duplicate = GNUNET_YES;
+ GNUNET_STATISTICS_update (dc->stats,
+ _("# duplicate fragments received"),
+ 1, GNUNET_NO);
+ }
/* count number of missing fragments */
bc = 0;
- for (b=0;b<64;b++)
- if (0 != (mc->bits & (1LL << b))) bc++;
+ for (b = 0; b < 64; b++)
+ if (0 != (mc->bits & (1LL << b)))
+ bc++;
if (mc->frag_times_write_offset - mc->frag_times_start_offset > 1)
dc->latency = estimate_latency (mc);
- delay = GNUNET_TIME_relative_multiply (dc->latency,
- bc + 1);
- if ( (0 == mc->bits) || (GNUNET_YES == duplicate) ) /* message complete or
duplicate, ACK now! */
+ delay = GNUNET_TIME_relative_multiply (dc->latency, bc + 1);
+ if ((0 == mc->bits) || (GNUNET_YES == duplicate)) /* message complete or
duplicate, ACK now! */
delay = GNUNET_TIME_UNIT_ZERO;
if (GNUNET_SCHEDULER_NO_TASK != mc->ack_task)
GNUNET_SCHEDULER_cancel (mc->ack_task);
- mc->ack_task = GNUNET_SCHEDULER_add_delayed (delay,
- &send_ack,
- mc);
- if ( (duplicate == GNUNET_NO) &&
- (0 == mc->bits) )
- {
- GNUNET_STATISTICS_update (dc->stats,
- _("# messages defragmented"),
- 1,
- GNUNET_NO);
- /* message complete, notify! */
- dc->proc (dc->cls,
- mc->msg);
- }
+ mc->ack_task = GNUNET_SCHEDULER_add_delayed (delay, &send_ack, mc);
+ if ((duplicate == GNUNET_NO) && (0 == mc->bits))
+ {
+ GNUNET_STATISTICS_update (dc->stats,
+ _("# messages defragmented"), 1, GNUNET_NO);
+ /* message complete, notify! */
+ dc->proc (dc->cls, mc->msg);
+ }
if (duplicate == GNUNET_YES)
return GNUNET_NO;
return GNUNET_YES;
}
/* end of defragmentation.c */
-
Modified: gnunet/src/fragmentation/fragmentation.c
===================================================================
--- gnunet/src/fragmentation/fragmentation.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/fragmentation/fragmentation.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -113,7 +113,7 @@
* Target fragment size.
*/
uint16_t mtu;
-
+
};
@@ -124,8 +124,7 @@
* @param tc scheduler context
*/
static void
-transmit_next (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+transmit_next (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_FRAGMENT_Context *fc = cls;
char msg[fc->mtu];
@@ -140,56 +139,53 @@
fc->task = GNUNET_SCHEDULER_NO_TASK;
GNUNET_assert (GNUNET_NO == fc->proc_busy);
if (0 == fc->acks)
- return; /* all done */
+ return; /* all done */
/* calculate delay */
wrap = 0;
- while (0 == (fc->acks & (1LL << fc->next_transmission)))
- {
- fc->next_transmission = (fc->next_transmission + 1) % 64;
- wrap |= (fc->next_transmission == 0);
- }
+ while (0 == (fc->acks & (1LL << fc->next_transmission)))
+ {
+ fc->next_transmission = (fc->next_transmission + 1) % 64;
+ wrap |= (fc->next_transmission == 0);
+ }
bit = fc->next_transmission;
size = ntohs (fc->msg->size);
if (bit == size / (fc->mtu - sizeof (struct FragmentHeader)))
- fsize = size % (fc->mtu - sizeof (struct FragmentHeader)) + sizeof (struct
FragmentHeader);
+ fsize =
+ size % (fc->mtu - sizeof (struct FragmentHeader)) +
+ sizeof (struct FragmentHeader);
else
fsize = fc->mtu;
if (fc->tracker != NULL)
- delay = GNUNET_BANDWIDTH_tracker_get_delay (fc->tracker,
- fsize);
+ delay = GNUNET_BANDWIDTH_tracker_get_delay (fc->tracker, fsize);
else
delay = GNUNET_TIME_UNIT_ZERO;
if (delay.rel_value > 0)
- {
- fc->task = GNUNET_SCHEDULER_add_delayed (delay,
- &transmit_next,
- fc);
- return;
- }
+ {
+ fc->task = GNUNET_SCHEDULER_add_delayed (delay, &transmit_next, fc);
+ return;
+ }
fc->next_transmission = (fc->next_transmission + 1) % 64;
wrap |= (fc->next_transmission == 0);
/* assemble fragmentation message */
- mbuf = (const char*) &fc[1];
- fh = (struct FragmentHeader*) msg;
+ mbuf = (const char *) &fc[1];
+ fh = (struct FragmentHeader *) msg;
fh->header.size = htons (fsize);
fh->header.type = htons (GNUNET_MESSAGE_TYPE_FRAGMENT);
fh->fragment_id = htonl (fc->fragment_id);
- fh->total_size = fc->msg->size; /* already in big-endian */
+ fh->total_size = fc->msg->size; /* already in big-endian */
fh->offset = htons ((fc->mtu - sizeof (struct FragmentHeader)) * bit);
memcpy (&fh[1],
- &mbuf[bit * (fc->mtu - sizeof (struct FragmentHeader))],
- fsize - sizeof (struct FragmentHeader));
+ &mbuf[bit * (fc->mtu - sizeof (struct FragmentHeader))],
+ fsize - sizeof (struct FragmentHeader));
if (NULL != fc->tracker)
- GNUNET_BANDWIDTH_tracker_consume (fc->tracker, fsize);
+ GNUNET_BANDWIDTH_tracker_consume (fc->tracker, fsize);
GNUNET_STATISTICS_update (fc->stats,
- _("# fragments transmitted"),
- 1, GNUNET_NO);
+ _("# fragments transmitted"), 1, GNUNET_NO);
if (0 != fc->last_round.abs_value)
GNUNET_STATISTICS_update (fc->stats,
- _("# fragments retransmitted"),
- 1, GNUNET_NO);
+ _("# fragments retransmitted"), 1, GNUNET_NO);
/* select next message to calculate delay */
bit = fc->next_transmission;
@@ -199,21 +195,19 @@
else
fsize = fc->mtu;
if (NULL != fc->tracker)
- delay = GNUNET_BANDWIDTH_tracker_get_delay (fc->tracker,
- fsize);
+ delay = GNUNET_BANDWIDTH_tracker_get_delay (fc->tracker, fsize);
else
delay = GNUNET_TIME_UNIT_ZERO;
if (wrap)
- {
- /* full round transmitted wait 2x delay for ACK before going again */
- delay = GNUNET_TIME_relative_max (GNUNET_TIME_relative_multiply (delay,
2),
- fc->delay);
- /* never use zero, need some time for ACK always */
- delay = GNUNET_TIME_relative_max (GNUNET_TIME_UNIT_MILLISECONDS,
- delay);
- fc->last_round = GNUNET_TIME_absolute_get ();
- fc->wack = GNUNET_YES;
- }
+ {
+ /* full round transmitted wait 2x delay for ACK before going again */
+ delay = GNUNET_TIME_relative_max (GNUNET_TIME_relative_multiply (delay, 2),
+ fc->delay);
+ /* never use zero, need some time for ACK always */
+ delay = GNUNET_TIME_relative_max (GNUNET_TIME_UNIT_MILLISECONDS, delay);
+ fc->last_round = GNUNET_TIME_absolute_get ();
+ fc->wack = GNUNET_YES;
+ }
fc->proc_busy = GNUNET_YES;
fc->delay_until = GNUNET_TIME_relative_to_absolute (delay);
fc->proc (fc->proc_cls, &fh->header);
@@ -240,46 +234,46 @@
*/
struct GNUNET_FRAGMENT_Context *
GNUNET_FRAGMENT_context_create (struct GNUNET_STATISTICS_Handle *stats,
- uint16_t mtu,
- struct GNUNET_BANDWIDTH_Tracker *tracker,
- struct GNUNET_TIME_Relative delay,
- const struct GNUNET_MessageHeader *msg,
- GNUNET_FRAGMENT_MessageProcessor proc,
- void *proc_cls)
+ uint16_t mtu,
+ struct GNUNET_BANDWIDTH_Tracker *tracker,
+ struct GNUNET_TIME_Relative delay,
+ const struct GNUNET_MessageHeader *msg,
+ GNUNET_FRAGMENT_MessageProcessor proc,
+ void *proc_cls)
{
struct GNUNET_FRAGMENT_Context *fc;
size_t size;
uint64_t bits;
-
- GNUNET_STATISTICS_update (stats,
- _("# messages fragmented"),
- 1, GNUNET_NO);
+
+ GNUNET_STATISTICS_update (stats, _("# messages fragmented"), 1, GNUNET_NO);
GNUNET_assert (mtu >= 1024 + sizeof (struct FragmentHeader));
- size = ntohs (msg->size);
+ size = ntohs (msg->size);
GNUNET_STATISTICS_update (stats,
- _("# total size of fragmented messages"),
- size, GNUNET_NO);
+ _("# total size of fragmented messages"),
+ size, GNUNET_NO);
GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader));
fc = GNUNET_malloc (sizeof (struct GNUNET_FRAGMENT_Context) + size);
fc->stats = stats;
fc->mtu = mtu;
fc->tracker = tracker;
fc->delay = delay;
- fc->msg = (const struct GNUNET_MessageHeader*)&fc[1];
+ fc->msg = (const struct GNUNET_MessageHeader *) &fc[1];
fc->proc = proc;
fc->proc_cls = proc_cls;
fc->fragment_id = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
- UINT32_MAX);
+ UINT32_MAX);
memcpy (&fc[1], msg, size);
- bits = (size + mtu - sizeof (struct FragmentHeader) - 1) / (mtu - sizeof
(struct FragmentHeader));
+ bits =
+ (size + mtu - sizeof (struct FragmentHeader) - 1) / (mtu -
+ sizeof (struct
+
FragmentHeader));
GNUNET_assert (bits <= 64);
if (bits == 64)
- fc->acks_mask = UINT64_MAX; /* set all 64 bit */
+ fc->acks_mask = UINT64_MAX; /* set all 64 bit */
else
- fc->acks_mask = (1LL << bits) - 1; /* set lowest 'bits' bit */
+ fc->acks_mask = (1LL << bits) - 1; /* set lowest 'bits' bit */
fc->acks = fc->acks_mask;
- fc->task = GNUNET_SCHEDULER_add_now (&transmit_next,
- fc);
+ fc->task = GNUNET_SCHEDULER_add_now (&transmit_next, fc);
return fc;
}
@@ -297,9 +291,9 @@
GNUNET_assert (fc->proc_busy == GNUNET_YES);
fc->proc_busy = GNUNET_NO;
GNUNET_assert (fc->task == GNUNET_SCHEDULER_NO_TASK);
- fc->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
(fc->delay_until),
- &transmit_next,
- fc);
+ fc->task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
+ (fc->delay_until), &transmit_next, fc);
}
@@ -314,72 +308,68 @@
* GNUNET_NO if more messages are pending
* GNUNET_SYSERR if this ack is not valid for this fc
*/
-int
+int
GNUNET_FRAGMENT_process_ack (struct GNUNET_FRAGMENT_Context *fc,
- const struct GNUNET_MessageHeader *msg)
+ const struct GNUNET_MessageHeader *msg)
{
const struct FragmentAcknowledgement *fa;
uint64_t abits;
struct GNUNET_TIME_Relative ndelay;
- if (sizeof (struct FragmentAcknowledgement) !=
- ntohs (msg->size))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
+ if (sizeof (struct FragmentAcknowledgement) != ntohs (msg->size))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
fa = (const struct FragmentAcknowledgement *) msg;
if (ntohl (fa->fragment_id) != fc->fragment_id)
- return GNUNET_SYSERR; /* not our ACK */
+ return GNUNET_SYSERR; /* not our ACK */
abits = GNUNET_ntohll (fa->bits);
if (GNUNET_YES == fc->wack)
- {
- /* normal ACK, can update running average of delay... */
- fc->wack = GNUNET_NO;
- ndelay = GNUNET_TIME_absolute_get_duration (fc->last_round);
- fc->delay.rel_value = (ndelay.rel_value + 3 * fc->delay.rel_value) / 4;
- }
+ {
+ /* normal ACK, can update running average of delay... */
+ fc->wack = GNUNET_NO;
+ ndelay = GNUNET_TIME_absolute_get_duration (fc->last_round);
+ fc->delay.rel_value = (ndelay.rel_value + 3 * fc->delay.rel_value) / 4;
+ }
GNUNET_STATISTICS_update (fc->stats,
- _("# fragment acknowledgements received"),
- 1,
- GNUNET_NO);
+ _("# fragment acknowledgements received"),
+ 1, GNUNET_NO);
if (abits != (fc->acks & abits))
- {
- /* ID collission or message reordering, count! This should be rare! */
- GNUNET_STATISTICS_update (fc->stats,
- _("# bits removed from fragmentation ACKs"),
- 1, GNUNET_NO);
- }
+ {
+ /* ID collission or message reordering, count! This should be rare! */
+ GNUNET_STATISTICS_update (fc->stats,
+ _("# bits removed from fragmentation ACKs"),
+ 1, GNUNET_NO);
+ }
fc->acks = abits & fc->acks_mask;
if (0 != fc->acks)
+ {
+ /* more to transmit, do so right now (if tracker permits...) */
+ if (fc->task != GNUNET_SCHEDULER_NO_TASK)
{
- /* more to transmit, do so right now (if tracker permits...) */
- if (fc->task != GNUNET_SCHEDULER_NO_TASK)
- {
- /* schedule next transmission now, no point in waiting... */
- GNUNET_SCHEDULER_cancel (fc->task);
- fc->task = GNUNET_SCHEDULER_add_now (&transmit_next,
- fc);
- }
- else
- {
- /* only case where there is no task should be if we're waiting
- for the right to transmit again (proc_busy set to YES) */
- GNUNET_assert (GNUNET_YES == fc->proc_busy);
- }
- return GNUNET_NO;
+ /* schedule next transmission now, no point in waiting... */
+ GNUNET_SCHEDULER_cancel (fc->task);
+ fc->task = GNUNET_SCHEDULER_add_now (&transmit_next, fc);
}
+ else
+ {
+ /* only case where there is no task should be if we're waiting
+ * for the right to transmit again (proc_busy set to YES) */
+ GNUNET_assert (GNUNET_YES == fc->proc_busy);
+ }
+ return GNUNET_NO;
+ }
/* all done */
GNUNET_STATISTICS_update (fc->stats,
- _("# fragmentation transmissions completed"),
- 1,
- GNUNET_NO);
+ _("# fragmentation transmissions completed"),
+ 1, GNUNET_NO);
if (fc->task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (fc->task);
- fc->task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (fc->task);
+ fc->task = GNUNET_SCHEDULER_NO_TASK;
+ }
return GNUNET_OK;
}
@@ -406,4 +396,3 @@
/* end of fragmentation.c */
-
Modified: gnunet/src/fragmentation/test_fragmentation.c
===================================================================
--- gnunet/src/fragmentation/test_fragmentation.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/fragmentation/test_fragmentation.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -44,7 +44,7 @@
*/
#define DROPRATE 10
-static int ret = 1;
+static int ret = 1;
static unsigned int dups;
@@ -63,18 +63,17 @@
static struct GNUNET_FRAGMENT_Context *frags[NUM_MSGS];
static void
-proc_msgs (void *cls,
- const struct GNUNET_MessageHeader *hdr)
+proc_msgs (void *cls, const struct GNUNET_MessageHeader *hdr)
{
static unsigned int total;
unsigned int i;
const char *buf;
#if DETAILS
- fprintf (stderr, "!"); /* message complete, good! */
+ fprintf (stderr, "!"); /* message complete, good! */
#endif
- buf = (const char*) hdr;
- for (i=sizeof (struct GNUNET_MessageHeader);i<ntohs(hdr->size);i++)
+ buf = (const char *) hdr;
+ for (i = sizeof (struct GNUNET_MessageHeader); i < ntohs (hdr->size); i++)
GNUNET_assert (buf[i] == (char) i);
total++;
#if ! DETAILS
@@ -83,18 +82,18 @@
#endif
/* tolerate 10% loss, i.e. due to duplicate fragment IDs */
if (total >= NUM_MSGS - (NUM_MSGS / 10))
+ {
+ ret = 0;
+ GNUNET_DEFRAGMENT_context_destroy (defrag);
+ defrag = NULL;
+ for (i = 0; i < NUM_MSGS; i++)
{
- ret = 0;
- GNUNET_DEFRAGMENT_context_destroy (defrag);
- defrag = NULL;
- for (i=0;i<NUM_MSGS;i++)
- {
- if (frags[i] == NULL)
- continue;
- GNUNET_FRAGMENT_context_destroy (frags[i]);
- frags[i] = NULL;
- }
+ if (frags[i] == NULL)
+ continue;
+ GNUNET_FRAGMENT_context_destroy (frags[i]);
+ frags[i] = NULL;
}
+ }
}
@@ -102,45 +101,42 @@
* Process ACK (by passing to fragmenter)
*/
static void
-proc_acks (void *cls,
- uint32_t msg_id,
- const struct GNUNET_MessageHeader *hdr)
+proc_acks (void *cls, uint32_t msg_id, const struct GNUNET_MessageHeader *hdr)
{
unsigned int i;
int ret;
if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, DROPRATE))
- {
- ack_drops++;
- return; /* random drop */
- }
- for (i=0;i<NUM_MSGS;i++)
+ {
+ ack_drops++;
+ return; /* random drop */
+ }
+ for (i = 0; i < NUM_MSGS; i++)
+ {
+ if (frags[i] == NULL)
+ continue;
+ ret = GNUNET_FRAGMENT_process_ack (frags[i], hdr);
+ if (ret == GNUNET_OK)
{
- if (frags[i] == NULL)
- continue;
- ret = GNUNET_FRAGMENT_process_ack (frags[i],
- hdr);
- if (ret == GNUNET_OK)
- {
#if DETAILS
- fprintf (stderr, "@"); /* good ACK */
+ fprintf (stderr, "@"); /* good ACK */
#endif
- GNUNET_FRAGMENT_context_destroy (frags[i]);
- frags[i] = NULL;
- acks++;
- return;
- }
- if (ret == GNUNET_NO)
- {
+ GNUNET_FRAGMENT_context_destroy (frags[i]);
+ frags[i] = NULL;
+ acks++;
+ return;
+ }
+ if (ret == GNUNET_NO)
+ {
#if DETAILS
- fprintf (stderr, "@"); /* good ACK */
+ fprintf (stderr, "@"); /* good ACK */
#endif
- acks++;
- return;
- }
+ acks++;
+ return;
}
+ }
#if DETAILS
- fprintf (stderr, "_"); /* BAD: ack that nobody feels responsible for... */
+ fprintf (stderr, "_"); /* BAD: ack that nobody feels responsible
for... */
#endif
}
@@ -149,38 +145,37 @@
* Process fragment (by passing to defrag).
*/
static void
-proc_frac (void *cls,
- const struct GNUNET_MessageHeader *hdr)
+proc_frac (void *cls, const struct GNUNET_MessageHeader *hdr)
{
struct GNUNET_FRAGMENT_Context **fc = cls;
int ret;
GNUNET_FRAGMENT_context_transmission_done (*fc);
if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, DROPRATE))
- {
- frag_drops++;
- return; /* random drop */
- }
+ {
+ frag_drops++;
+ return; /* random drop */
+ }
if (NULL == defrag)
- {
- fprintf (stderr, "E"); /* Error: frag after shutdown!? */
- return;
- }
+ {
+ fprintf (stderr, "E"); /* Error: frag after shutdown!? */
+ return;
+ }
ret = GNUNET_DEFRAGMENT_process_fragment (defrag, hdr);
if (ret == GNUNET_NO)
- {
+ {
#if DETAILS
- fprintf (stderr, "?"); /* duplicate fragment */
+ fprintf (stderr, "?"); /* duplicate fragment */
#endif
- dups++;
- }
+ dups++;
+ }
else if (ret == GNUNET_OK)
- {
+ {
#if DETAILS
- fprintf (stderr, "."); /* good fragment */
+ fprintf (stderr, "."); /* good fragment */
#endif
- fragc++;
- }
+ fragc++;
+ }
}
@@ -196,27 +191,22 @@
struct GNUNET_MessageHeader *msg;
char buf[MTU + 32 * 1024];
- defrag = GNUNET_DEFRAGMENT_context_create (NULL,
- MTU,
- NUM_MSGS /* enough space for all
*/,
- NULL,
- &proc_msgs,
- &proc_acks);
- for (i=0;i<sizeof(buf);i++)
+ defrag = GNUNET_DEFRAGMENT_context_create (NULL, MTU, NUM_MSGS /*
enough space for all */
+ , NULL, &proc_msgs, &proc_acks);
+ for (i = 0; i < sizeof (buf); i++)
buf[i] = (char) i;
- msg = (struct GNUNET_MessageHeader* ) buf;
- for (i=0;i<NUM_MSGS;i++)
- {
- msg->type = htons ((uint16_t) i);
- msg->size = htons (sizeof (struct GNUNET_MessageHeader) + (17 * i) % (32
* 1024));
- frags[i] = GNUNET_FRAGMENT_context_create (NULL /* no stats */,
- MTU,
- &trackers[i],
- GNUNET_TIME_UNIT_SECONDS,
- msg,
- &proc_frac,
- &frags[i]);
- }
+ msg = (struct GNUNET_MessageHeader *) buf;
+ for (i = 0; i < NUM_MSGS; i++)
+ {
+ msg->type = htons ((uint16_t) i);
+ msg->size =
+ htons (sizeof (struct GNUNET_MessageHeader) + (17 * i) % (32 * 1024));
+ frags[i] = GNUNET_FRAGMENT_context_create (NULL /* no stats */ ,
+ MTU,
+ &trackers[i],
+ GNUNET_TIME_UNIT_SECONDS,
+ msg, &proc_frac, &frags[i]);
+ }
}
@@ -247,16 +237,14 @@
"WARNING",
#endif
NULL);
- for (i=0;i<NUM_MSGS;i++)
+ for (i = 0; i < NUM_MSGS; i++)
GNUNET_BANDWIDTH_tracker_init (&trackers[i],
- GNUNET_BANDWIDTH_value_init ((i+1) * 1024),
- 100);
- GNUNET_PROGRAM_run (5, argv_prog, "test-fragmentation", "nohelp", options,
&run, NULL);
- fprintf (stderr,
- "\nHad %u good fragments, %u duplicate fragments, %u acks and %u
simulated drops of acks\n",
- fragc,
- dups,
- acks,
- ack_drops);
+ GNUNET_BANDWIDTH_value_init ((i + 1) *
1024),
+ 100);
+ GNUNET_PROGRAM_run (5, argv_prog, "test-fragmentation", "nohelp", options,
+ &run, NULL);
+ fprintf (stderr,
+ "\nHad %u good fragments, %u duplicate fragments, %u acks and %u
simulated drops of acks\n",
+ fragc, dups, acks, ack_drops);
return ret;
}
Modified: gnunet/src/fs/fs.c
===================================================================
--- gnunet/src/fs/fs.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/fs/fs.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -43,21 +43,18 @@
GNUNET_assert (NULL == qe->client);
qe->client = GNUNET_CLIENT_connect ("fs", qe->h->cfg);
if (qe->client == NULL)
- {
- GNUNET_break (0);
- return;
- }
+ {
+ GNUNET_break (0);
+ return;
+ }
qe->start (qe->cls, qe->client);
qe->start_times++;
qe->h->active_blocks += qe->blocks;
qe->start_time = GNUNET_TIME_absolute_get ();
- GNUNET_CONTAINER_DLL_remove (qe->h->pending_head,
- qe->h->pending_tail,
- qe);
+ GNUNET_CONTAINER_DLL_remove (qe->h->pending_head, qe->h->pending_tail, qe);
GNUNET_CONTAINER_DLL_insert_after (qe->h->running_head,
- qe->h->running_tail,
- qe->h->running_tail,
- qe);
+ qe->h->running_tail,
+ qe->h->running_tail, qe);
}
@@ -75,14 +72,12 @@
qe->h->active_downloads--;
qe->h->active_blocks -= qe->blocks;
qe->run_time = GNUNET_TIME_relative_add (qe->run_time,
- GNUNET_TIME_absolute_get_duration
(qe->start_time));
- GNUNET_CONTAINER_DLL_remove (qe->h->running_head,
- qe->h->running_tail,
- qe);
+ GNUNET_TIME_absolute_get_duration
+ (qe->start_time));
+ GNUNET_CONTAINER_DLL_remove (qe->h->running_head, qe->h->running_tail, qe);
GNUNET_CONTAINER_DLL_insert_after (qe->h->pending_head,
- qe->h->pending_tail,
- qe->h->pending_tail,
- qe);
+ qe->h->pending_tail,
+ qe->h->pending_tail, qe);
}
@@ -94,8 +89,7 @@
* @param tc scheduler context
*/
static void
-process_job_queue (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+process_job_queue (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_FS_Handle *h = cls;
struct GNUNET_FS_QueueEntry *qe;
@@ -108,40 +102,38 @@
h->queue_job = GNUNET_SCHEDULER_NO_TASK;
next = h->pending_head;
while (NULL != (qe = next))
+ {
+ next = qe->next;
+ if (h->running_head == NULL)
{
- next = qe->next;
- if (h->running_head == NULL)
- {
- start_job (qe);
- continue;
- }
- if ( (qe->blocks + h->active_blocks <= h->max_parallel_requests) &&
- (h->active_downloads + 1 <= h->max_parallel_downloads) )
- {
- start_job (qe);
- continue;
- }
+ start_job (qe);
+ continue;
}
+ if ((qe->blocks + h->active_blocks <= h->max_parallel_requests) &&
+ (h->active_downloads + 1 <= h->max_parallel_downloads))
+ {
+ start_job (qe);
+ continue;
+ }
+ }
if (h->pending_head == NULL)
- return; /* no need to stop anything */
+ return; /* no need to stop anything */
restart_at = GNUNET_TIME_UNIT_FOREVER_REL;
next = h->running_head;
while (NULL != (qe = next))
- {
- next = qe->next;
- run_time = GNUNET_TIME_relative_multiply (h->avg_block_latency,
- qe->blocks * qe->start_times);
- end_time = GNUNET_TIME_absolute_add (qe->start_time,
- run_time);
- rst = GNUNET_TIME_absolute_get_remaining (end_time);
- restart_at = GNUNET_TIME_relative_min (rst, restart_at);
- if (rst.rel_value > 0)
- continue;
- stop_job (qe);
- }
+ {
+ next = qe->next;
+ run_time = GNUNET_TIME_relative_multiply (h->avg_block_latency,
+ qe->blocks * qe->start_times);
+ end_time = GNUNET_TIME_absolute_add (qe->start_time, run_time);
+ rst = GNUNET_TIME_absolute_get_remaining (end_time);
+ restart_at = GNUNET_TIME_relative_min (rst, restart_at);
+ if (rst.rel_value > 0)
+ continue;
+ stop_job (qe);
+ }
h->queue_job = GNUNET_SCHEDULER_add_delayed (restart_at,
- &process_job_queue,
- h);
+ &process_job_queue, h);
}
@@ -157,10 +149,8 @@
*/
struct GNUNET_FS_QueueEntry *
GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h,
- GNUNET_FS_QueueStart start,
- GNUNET_FS_QueueStop stop,
- void *cls,
- unsigned int blocks)
+ GNUNET_FS_QueueStart start,
+ GNUNET_FS_QueueStop stop, void *cls, unsigned int blocks)
{
struct GNUNET_FS_QueueEntry *qe;
@@ -172,14 +162,10 @@
qe->queue_time = GNUNET_TIME_absolute_get ();
qe->blocks = blocks;
GNUNET_CONTAINER_DLL_insert_after (h->pending_head,
- h->pending_tail,
- h->pending_tail,
- qe);
+ h->pending_tail, h->pending_tail, qe);
if (h->queue_job != GNUNET_SCHEDULER_NO_TASK)
GNUNET_SCHEDULER_cancel (h->queue_job);
- h->queue_job
- = GNUNET_SCHEDULER_add_now (&process_job_queue,
- h);
+ h->queue_job = GNUNET_SCHEDULER_add_now (&process_job_queue, h);
return qe;
}
@@ -194,17 +180,13 @@
struct GNUNET_FS_Handle *h;
h = qh->h;
- if (qh->client != NULL)
- stop_job (qh);
- GNUNET_CONTAINER_DLL_remove (h->pending_head,
- h->pending_tail,
- qh);
+ if (qh->client != NULL)
+ stop_job (qh);
+ GNUNET_CONTAINER_DLL_remove (h->pending_head, h->pending_tail, qh);
GNUNET_free (qh);
if (h->queue_job != GNUNET_SCHEDULER_NO_TASK)
GNUNET_SCHEDULER_cancel (h->queue_job);
- h->queue_job
- = GNUNET_SCHEDULER_add_now (&process_job_queue,
- h);
+ h->queue_job = GNUNET_SCHEDULER_add_now (&process_job_queue, h);
}
@@ -218,17 +200,14 @@
*/
struct TopLevelActivity *
GNUNET_FS_make_top (struct GNUNET_FS_Handle *h,
- SuspendSignalFunction ssf,
- void *ssf_cls)
+ SuspendSignalFunction ssf, void *ssf_cls)
{
struct TopLevelActivity *ret;
ret = GNUNET_malloc (sizeof (struct TopLevelActivity));
ret->ssf = ssf;
ret->ssf_cls = ssf_cls;
- GNUNET_CONTAINER_DLL_insert (h->top_head,
- h->top_tail,
- ret);
+ GNUNET_CONTAINER_DLL_insert (h->top_head, h->top_tail, ret);
return ret;
}
@@ -240,12 +219,9 @@
* @param top top level activity entry
*/
void
-GNUNET_FS_end_top (struct GNUNET_FS_Handle *h,
- struct TopLevelActivity *top)
+GNUNET_FS_end_top (struct GNUNET_FS_Handle *h, struct TopLevelActivity *top)
{
- GNUNET_CONTAINER_DLL_remove (h->top_head,
- h->top_tail,
- top);
+ GNUNET_CONTAINER_DLL_remove (h->top_head, h->top_tail, top);
GNUNET_free (top);
}
@@ -285,54 +261,49 @@
* @return number of bytes written, usually "max", 0 on error
*/
size_t
-GNUNET_FS_data_reader_file_(void *cls,
- uint64_t offset,
- size_t max,
- void *buf,
- char **emsg)
+GNUNET_FS_data_reader_file_ (void *cls,
+ uint64_t offset,
+ size_t max, void *buf, char **emsg)
{
struct FileInfo *fi = cls;
ssize_t ret;
if (max == 0)
- {
- if (fi->fd != NULL)
- GNUNET_DISK_file_close (fi->fd);
- GNUNET_free (fi->filename);
- GNUNET_free (fi);
- return 0;
- }
+ {
+ if (fi->fd != NULL)
+ GNUNET_DISK_file_close (fi->fd);
+ GNUNET_free (fi->filename);
+ GNUNET_free (fi);
+ return 0;
+ }
if (fi->fd == NULL)
+ {
+ fi->fd = GNUNET_DISK_file_open (fi->filename,
+ GNUNET_DISK_OPEN_READ,
+ GNUNET_DISK_PERM_NONE);
+ if (fi->fd == NULL)
{
- fi->fd = GNUNET_DISK_file_open (fi->filename,
- GNUNET_DISK_OPEN_READ,
- GNUNET_DISK_PERM_NONE);
- if (fi->fd == NULL)
- {
- GNUNET_asprintf (emsg,
- _("Could not open file `%s': %s"),
- fi->filename,
- STRERROR (errno));
- return 0;
- }
+ GNUNET_asprintf (emsg,
+ _("Could not open file `%s': %s"),
+ fi->filename, STRERROR (errno));
+ return 0;
}
+ }
GNUNET_DISK_file_seek (fi->fd, offset, GNUNET_DISK_SEEK_SET);
ret = GNUNET_DISK_file_read (fi->fd, buf, max);
if (ret == -1)
- {
- GNUNET_asprintf (emsg,
- _("Could not read file `%s': %s"),
- fi->filename,
- STRERROR (errno));
- return 0;
- }
+ {
+ GNUNET_asprintf (emsg,
+ _("Could not read file `%s': %s"),
+ fi->filename, STRERROR (errno));
+ return 0;
+ }
if (ret != max)
- {
- GNUNET_asprintf (emsg,
- _("Short read reading from file `%s'!"),
- fi->filename);
- return 0;
- }
+ {
+ GNUNET_asprintf (emsg,
+ _("Short read reading from file `%s'!"), fi->filename);
+ return 0;
+ }
return max;
}
@@ -348,13 +319,13 @@
{
struct FileInfo *fi;
- fi = GNUNET_malloc (sizeof(struct FileInfo));
+ fi = GNUNET_malloc (sizeof (struct FileInfo));
fi->filename = GNUNET_STRINGS_filename_expand (filename);
if (fi->filename == NULL)
- {
- GNUNET_free (fi);
- return NULL;
- }
+ {
+ GNUNET_free (fi);
+ return NULL;
+ }
return fi;
}
@@ -376,19 +347,17 @@
* @return number of bytes written, usually "max", 0 on error
*/
size_t
-GNUNET_FS_data_reader_copy_ (void *cls,
- uint64_t offset,
- size_t max,
- void *buf,
- char **emsg)
+GNUNET_FS_data_reader_copy_ (void *cls,
+ uint64_t offset,
+ size_t max, void *buf, char **emsg)
{
char *data = cls;
if (max == 0)
- {
- GNUNET_free_non_null (data);
- return 0;
- }
+ {
+ GNUNET_free_non_null (data);
+ return 0;
+ }
memcpy (buf, &data[offset], max);
return max;
}
@@ -405,29 +374,23 @@
*/
static char *
get_serialization_file_name (struct GNUNET_FS_Handle *h,
- const char *ext,
- const char *ent)
+ const char *ext, const char *ent)
{
char *basename;
char *ret;
if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
- return NULL; /* persistence not requested */
+ return NULL; /* persistence not requested */
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_filename (h->cfg,
- "fs",
- "STATE_DIR",
- &basename))
+ "fs", "STATE_DIR", &basename))
return NULL;
GNUNET_asprintf (&ret,
- "%s%s%s%s%s%s%s",
- basename,
- DIR_SEPARATOR_STR,
- h->client_name,
- DIR_SEPARATOR_STR,
- ext,
- DIR_SEPARATOR_STR,
- ent);
+ "%s%s%s%s%s%s%s",
+ basename,
+ DIR_SEPARATOR_STR,
+ h->client_name,
+ DIR_SEPARATOR_STR, ext, DIR_SEPARATOR_STR, ent);
GNUNET_free (basename);
return ret;
}
@@ -446,32 +409,25 @@
*/
static char *
get_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h,
- const char *ext,
- const char *uni,
- const char *ent)
+ const char *ext,
+ const char *uni, const char *ent)
{
char *basename;
char *ret;
if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
- return NULL; /* persistence not requested */
+ return NULL; /* persistence not requested */
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_filename (h->cfg,
- "fs",
- "STATE_DIR",
- &basename))
+ "fs", "STATE_DIR", &basename))
return NULL;
GNUNET_asprintf (&ret,
- "%s%s%s%s%s%s%s.dir%s%s",
- basename,
- DIR_SEPARATOR_STR,
- h->client_name,
- DIR_SEPARATOR_STR,
- ext,
- DIR_SEPARATOR_STR,
- uni,
- DIR_SEPARATOR_STR,
- ent);
+ "%s%s%s%s%s%s%s.dir%s%s",
+ basename,
+ DIR_SEPARATOR_STR,
+ h->client_name,
+ DIR_SEPARATOR_STR,
+ ext, DIR_SEPARATOR_STR, uni, DIR_SEPARATOR_STR, ent);
GNUNET_free (basename);
return ret;
}
@@ -486,9 +442,7 @@
* @return NULL on error
*/
static struct GNUNET_BIO_ReadHandle *
-get_read_handle (struct GNUNET_FS_Handle *h,
- const char *ext,
- const char *ent)
+get_read_handle (struct GNUNET_FS_Handle *h, const char *ext, const char *ent)
{
char *fn;
struct GNUNET_BIO_ReadHandle *ret;
@@ -511,18 +465,16 @@
* @return NULL on error
*/
static struct GNUNET_BIO_WriteHandle *
-get_write_handle (struct GNUNET_FS_Handle *h,
- const char *ext,
- const char *ent)
+get_write_handle (struct GNUNET_FS_Handle *h, const char *ext, const char *ent)
{
char *fn;
struct GNUNET_BIO_WriteHandle *ret;
fn = get_serialization_file_name (h, ext, ent);
if (fn == NULL)
- {
- return NULL;
- }
+ {
+ return NULL;
+ }
ret = GNUNET_BIO_write_open (fn);
if (ret == NULL)
GNUNET_break (0);
@@ -542,9 +494,7 @@
*/
static struct GNUNET_BIO_WriteHandle *
get_write_handle_in_dir (struct GNUNET_FS_Handle *h,
- const char *ext,
- const char *uni,
- const char *ent)
+ const char *ext, const char *uni, const char *ent)
{
char *fn;
struct GNUNET_BIO_WriteHandle *ret;
@@ -567,26 +517,22 @@
*/
void
GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h,
- const char *ext,
- const char *ent)
+ const char *ext, const char *ent)
{
char *filename;
- if ( (NULL == ent) ||
- (0 == strlen (ent)) )
- {
- GNUNET_break (0);
- return;
- }
+ if ((NULL == ent) || (0 == strlen (ent)))
+ {
+ GNUNET_break (0);
+ return;
+ }
filename = get_serialization_file_name (h, ext, ent);
if (filename != NULL)
- {
- if (0 != UNLINK (filename))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
- "unlink",
- filename);
- GNUNET_free (filename);
- }
+ {
+ if (0 != UNLINK (filename))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename);
+ GNUNET_free (filename);
+ }
}
@@ -600,27 +546,22 @@
*/
static void
remove_sync_file_in_dir (struct GNUNET_FS_Handle *h,
- const char *ext,
- const char *uni,
- const char *ent)
+ const char *ext, const char *uni, const char *ent)
{
char *filename;
- if ( (NULL == ent) ||
- (0 == strlen (ent)) )
- {
- GNUNET_break (0);
- return;
- }
+ if ((NULL == ent) || (0 == strlen (ent)))
+ {
+ GNUNET_break (0);
+ return;
+ }
filename = get_serialization_file_name_in_dir (h, ext, uni, ent);
if (filename != NULL)
- {
- if (0 != UNLINK (filename))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
- "unlink",
- filename);
- GNUNET_free (filename);
- }
+ {
+ if (0 != UNLINK (filename))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename);
+ GNUNET_free (filename);
+ }
}
@@ -633,8 +574,7 @@
*/
void
GNUNET_FS_remove_sync_dir_ (struct GNUNET_FS_Handle *h,
- const char *ext,
- const char *uni)
+ const char *ext, const char *uni)
{
char *dn;
@@ -643,11 +583,9 @@
dn = get_serialization_file_name_in_dir (h, ext, uni, "");
if (dn == NULL)
return;
- if ( (GNUNET_OK == GNUNET_DISK_directory_test (dn)) &&
- (GNUNET_OK != GNUNET_DISK_directory_remove (dn)) )
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
- "rmdir",
- dn);
+ if ((GNUNET_OK == GNUNET_DISK_directory_test (dn)) &&
+ (GNUNET_OK != GNUNET_DISK_directory_remove (dn)))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "rmdir", dn);
GNUNET_free (dn);
}
@@ -668,7 +606,7 @@
*/
static int
write_start_time (struct GNUNET_BIO_WriteHandle *wh,
- struct GNUNET_TIME_Absolute timestamp)
+ struct GNUNET_TIME_Absolute timestamp)
{
struct GNUNET_TIME_Relative dur;
@@ -693,14 +631,13 @@
*/
static int
read_start_time (struct GNUNET_BIO_ReadHandle *rh,
- struct GNUNET_TIME_Absolute *timestamp)
+ struct GNUNET_TIME_Absolute *timestamp)
{
struct GNUNET_TIME_Relative dur;
- if (GNUNET_OK !=
- GNUNET_BIO_read_int64 (rh, &dur.rel_value))
+
+ if (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dur.rel_value))
return GNUNET_SYSERR;
- *timestamp = GNUNET_TIME_absolute_subtract (GNUNET_TIME_absolute_get (),
- dur);
+ *timestamp = GNUNET_TIME_absolute_subtract (GNUNET_TIME_absolute_get (),
dur);
return GNUNET_OK;
}
@@ -714,9 +651,12 @@
* the infromation
* @return NULL on error
*/
-static struct GNUNET_FS_FileInformation *
-deserialize_file_information (struct GNUNET_FS_Handle *h,
- const char *filename);
+static struct GNUNET_FS_FileInformation *deserialize_file_information (struct
+
GNUNET_FS_Handle
+ *h,
+ const
+ char
+
*filename);
/**
@@ -731,8 +671,7 @@
*/
static struct GNUNET_FS_FileInformation *
deserialize_fi_node (struct GNUNET_FS_Handle *h,
- const char *fn,
- struct GNUNET_BIO_ReadHandle *rh)
+ const char *fn, struct GNUNET_BIO_ReadHandle *rh)
{
struct GNUNET_FS_FileInformation *ret;
struct GNUNET_FS_FileInformation *nxt;
@@ -742,195 +681,199 @@
char *filename;
uint32_t dsize;
- if (GNUNET_OK !=
- GNUNET_BIO_read (rh, "status flag", &b, sizeof(b)))
- {
- GNUNET_break (0);
- return NULL;
- }
+ if (GNUNET_OK != GNUNET_BIO_read (rh, "status flag", &b, sizeof (b)))
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
ret = GNUNET_malloc (sizeof (struct GNUNET_FS_FileInformation));
ret->h = h;
ksks = NULL;
chks = NULL;
filename = NULL;
- if ( (GNUNET_OK !=
- GNUNET_BIO_read_meta_data (rh, "metadata", &ret->meta)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read_string (rh, "ksk-uri", &ksks, 32*1024)) ||
- ( (ksks != NULL) &&
- (NULL ==
- (ret->keywords = GNUNET_FS_uri_parse (ksks, NULL))) ) ||
- (GNUNET_YES !=
- GNUNET_FS_uri_test_ksk (ret->keywords)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read_string (rh, "chk-uri", &chks, 1024)) ||
- ( (chks != NULL) &&
- ( (NULL ==
- (ret->chk_uri = GNUNET_FS_uri_parse (chks, NULL))) ||
- (GNUNET_YES !=
- GNUNET_FS_uri_test_chk (ret->chk_uri)) ) ) ||
- (GNUNET_OK !=
- read_start_time (rh, &ret->start_time)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read_string (rh, "emsg", &ret->emsg, 16*1024)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read_string (rh, "fn", &ret->filename, 16*1024)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read_int64 (rh, &ret->bo.expiration_time.abs_value)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read_int32 (rh, &ret->bo.anonymity_level)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read_int32 (rh, &ret->bo.content_priority)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read_int32 (rh, &ret->bo.replication_level)) )
+ if ((GNUNET_OK !=
+ GNUNET_BIO_read_meta_data (rh, "metadata", &ret->meta)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_read_string (rh, "ksk-uri", &ksks, 32 * 1024)) ||
+ ((ksks != NULL) &&
+ (NULL ==
+ (ret->keywords = GNUNET_FS_uri_parse (ksks, NULL)))) ||
+ (GNUNET_YES !=
+ GNUNET_FS_uri_test_ksk (ret->keywords)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_read_string (rh, "chk-uri", &chks, 1024)) ||
+ ((chks != NULL) &&
+ ((NULL ==
+ (ret->chk_uri = GNUNET_FS_uri_parse (chks, NULL))) ||
+ (GNUNET_YES !=
+ GNUNET_FS_uri_test_chk (ret->chk_uri)))) ||
+ (GNUNET_OK !=
+ read_start_time (rh, &ret->start_time)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_read_string (rh, "emsg", &ret->emsg, 16 * 1024)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_read_string (rh, "fn", &ret->filename, 16 * 1024)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_read_int64 (rh, &ret->bo.expiration_time.abs_value)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_read_int32 (rh, &ret->bo.anonymity_level)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_read_int32 (rh, &ret->bo.content_priority)) ||
+ (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &ret->bo.replication_level)))
+ {
+ GNUNET_break (0);
+ goto cleanup;
+ }
+ switch (b)
+ {
+ case 0: /* file-insert */
+ if (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size))
{
- GNUNET_break (0);
+ GNUNET_break (0);
goto cleanup;
}
- switch (b)
+ ret->is_directory = GNUNET_NO;
+ ret->data.file.do_index = GNUNET_NO;
+ ret->data.file.have_hash = GNUNET_NO;
+ ret->data.file.index_start_confirmed = GNUNET_NO;
+ if (GNUNET_NO == ret->is_published)
{
- case 0: /* file-insert */
- if (GNUNET_OK !=
- GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size))
- {
- GNUNET_break (0);
- goto cleanup;
- }
- ret->is_directory = GNUNET_NO;
- ret->data.file.do_index = GNUNET_NO;
- ret->data.file.have_hash = GNUNET_NO;
- ret->data.file.index_start_confirmed = GNUNET_NO;
- if (GNUNET_NO == ret->is_published)
- {
- if (NULL == ret->filename)
- {
- ret->data.file.reader = &GNUNET_FS_data_reader_copy_;
- ret->data.file.reader_cls = GNUNET_malloc_large
(ret->data.file.file_size);
- if (ret->data.file.reader_cls == NULL)
- goto cleanup;
- if (GNUNET_OK !=
- GNUNET_BIO_read (rh, "file-data", ret->data.file.reader_cls,
ret->data.file.file_size))
- {
- GNUNET_break (0);
- goto cleanup;
- }
- }
- else
- {
- ret->data.file.reader = &GNUNET_FS_data_reader_file_;
- ret->data.file.reader_cls = GNUNET_FS_make_file_reader_context_
(ret->filename);
- }
- }
- break;
- case 1: /* file-index, no hash */
if (NULL == ret->filename)
- {
- GNUNET_break (0);
- goto cleanup;
- }
- if (GNUNET_OK !=
- GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size))
- {
- GNUNET_break (0);
- goto cleanup;
- }
- ret->is_directory = GNUNET_NO;
- ret->data.file.do_index = GNUNET_YES;
- ret->data.file.have_hash = GNUNET_NO;
- ret->data.file.index_start_confirmed = GNUNET_NO;
- ret->data.file.reader = &GNUNET_FS_data_reader_file_;
- ret->data.file.reader_cls = GNUNET_FS_make_file_reader_context_
(ret->filename);
- break;
- case 2: /* file-index-with-hash */
- if (NULL == ret->filename)
- {
- GNUNET_break (0);
- goto cleanup;
- }
- if ( (GNUNET_OK !=
- GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read (rh, "fileid", &ret->data.file.file_id, sizeof
(GNUNET_HashCode))) )
- {
- GNUNET_break (0);
- goto cleanup;
- }
- ret->is_directory = GNUNET_NO;
- ret->data.file.do_index = GNUNET_YES;
- ret->data.file.have_hash = GNUNET_YES;
- ret->data.file.index_start_confirmed = GNUNET_NO;
- ret->data.file.reader = &GNUNET_FS_data_reader_file_;
- ret->data.file.reader_cls = GNUNET_FS_make_file_reader_context_
(ret->filename);
- break;
- case 3: /* file-index-with-hash-confirmed */
- if (NULL == ret->filename)
- {
- GNUNET_break (0);
- goto cleanup;
- }
- if ( (GNUNET_OK !=
- GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read (rh, "fileid", &ret->data.file.file_id, sizeof
(GNUNET_HashCode))) )
- {
- GNUNET_break (0);
- goto cleanup;
- }
- ret->is_directory = GNUNET_NO;
- ret->data.file.do_index = GNUNET_YES;
- ret->data.file.have_hash = GNUNET_YES;
- ret->data.file.index_start_confirmed = GNUNET_YES;
- ret->data.file.reader = &GNUNET_FS_data_reader_file_;
- ret->data.file.reader_cls = GNUNET_FS_make_file_reader_context_
(ret->filename);
- break;
- case 4: /* directory */
- ret->is_directory = GNUNET_YES;
- if ( (GNUNET_OK !=
- GNUNET_BIO_read_int32 (rh, &dsize)) ||
- (NULL == (ret->data.dir.dir_data = GNUNET_malloc_large (dsize))) ||
- (GNUNET_OK !=
- GNUNET_BIO_read (rh, "dir-data", ret->data.dir.dir_data, dsize)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read_string (rh, "ent-filename", &filename, 16*1024)) )
- {
- GNUNET_break (0);
- goto cleanup;
- }
- ret->data.dir.dir_size = (uint32_t) dsize;
- if (filename != NULL)
- {
- ret->data.dir.entries = deserialize_file_information (h, filename);
- GNUNET_free (filename);
- filename = NULL;
- nxt = ret->data.dir.entries;
- while (nxt != NULL)
- {
- nxt->dir = ret;
- nxt = nxt->next;
- }
- }
- break;
- default:
+ {
+ ret->data.file.reader = &GNUNET_FS_data_reader_copy_;
+ ret->data.file.reader_cls =
+ GNUNET_malloc_large (ret->data.file.file_size);
+ if (ret->data.file.reader_cls == NULL)
+ goto cleanup;
+ if (GNUNET_OK !=
+ GNUNET_BIO_read (rh, "file-data", ret->data.file.reader_cls,
+ ret->data.file.file_size))
+ {
+ GNUNET_break (0);
+ goto cleanup;
+ }
+ }
+ else
+ {
+ ret->data.file.reader = &GNUNET_FS_data_reader_file_;
+ ret->data.file.reader_cls =
+ GNUNET_FS_make_file_reader_context_ (ret->filename);
+ }
+ }
+ break;
+ case 1: /* file-index, no hash */
+ if (NULL == ret->filename)
+ {
GNUNET_break (0);
goto cleanup;
}
- ret->serialization = GNUNET_strdup (fn);
- if (GNUNET_OK !=
- GNUNET_BIO_read_string (rh, "nxt-filename", &filename, 16*1024))
+ if (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size))
{
GNUNET_break (0);
- goto cleanup;
+ goto cleanup;
}
- if (filename != NULL)
+ ret->is_directory = GNUNET_NO;
+ ret->data.file.do_index = GNUNET_YES;
+ ret->data.file.have_hash = GNUNET_NO;
+ ret->data.file.index_start_confirmed = GNUNET_NO;
+ ret->data.file.reader = &GNUNET_FS_data_reader_file_;
+ ret->data.file.reader_cls =
+ GNUNET_FS_make_file_reader_context_ (ret->filename);
+ break;
+ case 2: /* file-index-with-hash */
+ if (NULL == ret->filename)
{
- ret->next = deserialize_file_information (h, filename);
+ GNUNET_break (0);
+ goto cleanup;
+ }
+ if ((GNUNET_OK !=
+ GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_read (rh, "fileid", &ret->data.file.file_id,
+ sizeof (GNUNET_HashCode))))
+ {
+ GNUNET_break (0);
+ goto cleanup;
+ }
+ ret->is_directory = GNUNET_NO;
+ ret->data.file.do_index = GNUNET_YES;
+ ret->data.file.have_hash = GNUNET_YES;
+ ret->data.file.index_start_confirmed = GNUNET_NO;
+ ret->data.file.reader = &GNUNET_FS_data_reader_file_;
+ ret->data.file.reader_cls =
+ GNUNET_FS_make_file_reader_context_ (ret->filename);
+ break;
+ case 3: /* file-index-with-hash-confirmed */
+ if (NULL == ret->filename)
+ {
+ GNUNET_break (0);
+ goto cleanup;
+ }
+ if ((GNUNET_OK !=
+ GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_read (rh, "fileid", &ret->data.file.file_id,
+ sizeof (GNUNET_HashCode))))
+ {
+ GNUNET_break (0);
+ goto cleanup;
+ }
+ ret->is_directory = GNUNET_NO;
+ ret->data.file.do_index = GNUNET_YES;
+ ret->data.file.have_hash = GNUNET_YES;
+ ret->data.file.index_start_confirmed = GNUNET_YES;
+ ret->data.file.reader = &GNUNET_FS_data_reader_file_;
+ ret->data.file.reader_cls =
+ GNUNET_FS_make_file_reader_context_ (ret->filename);
+ break;
+ case 4: /* directory */
+ ret->is_directory = GNUNET_YES;
+ if ((GNUNET_OK !=
+ GNUNET_BIO_read_int32 (rh, &dsize)) ||
+ (NULL == (ret->data.dir.dir_data = GNUNET_malloc_large (dsize))) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_read (rh, "dir-data", ret->data.dir.dir_data, dsize)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_read_string (rh, "ent-filename", &filename, 16 * 1024)))
+ {
+ GNUNET_break (0);
+ goto cleanup;
+ }
+ ret->data.dir.dir_size = (uint32_t) dsize;
+ if (filename != NULL)
+ {
+ ret->data.dir.entries = deserialize_file_information (h, filename);
GNUNET_free (filename);
filename = NULL;
+ nxt = ret->data.dir.entries;
+ while (nxt != NULL)
+ {
+ nxt->dir = ret;
+ nxt = nxt->next;
+ }
}
+ break;
+ default:
+ GNUNET_break (0);
+ goto cleanup;
+ }
+ ret->serialization = GNUNET_strdup (fn);
+ if (GNUNET_OK !=
+ GNUNET_BIO_read_string (rh, "nxt-filename", &filename, 16 * 1024))
+ {
+ GNUNET_break (0);
+ goto cleanup;
+ }
+ if (filename != NULL)
+ {
+ ret->next = deserialize_file_information (h, filename);
+ GNUNET_free (filename);
+ filename = NULL;
+ }
GNUNET_free_non_null (ksks);
GNUNET_free_non_null (chks);
return ret;
- cleanup:
+cleanup:
GNUNET_free_non_null (ksks);
GNUNET_free_non_null (chks);
GNUNET_free_non_null (filename);
@@ -949,8 +892,7 @@
* @return NULL on error
*/
static struct GNUNET_FS_FileInformation *
-deserialize_file_information (struct GNUNET_FS_Handle *h,
- const char *filename)
+deserialize_file_information (struct GNUNET_FS_Handle *h, const char *filename)
{
struct GNUNET_FS_FileInformation *ret;
struct GNUNET_BIO_ReadHandle *rh;
@@ -960,22 +902,18 @@
if (rh == NULL)
return NULL;
ret = deserialize_fi_node (h, filename, rh);
- if (GNUNET_OK !=
- GNUNET_BIO_read_close (rh, &emsg))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to resume publishing information `%s': %s\n"),
- filename,
- emsg);
- GNUNET_free (emsg);
- }
+ if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Failed to resume publishing information `%s': %s\n"),
+ filename, emsg);
+ GNUNET_free (emsg);
+ }
if (ret == NULL)
- {
- if (0 != UNLINK (filename))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
- "unlink",
- filename);
- }
+ {
+ if (0 != UNLINK (filename))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename);
+ }
return ret;
}
@@ -997,21 +935,20 @@
end = NULL;
nxt = fullname;
/* FIXME: we could do this faster since we know
- the length of 'end'... */
+ * the length of 'end'... */
while ('\0' != *nxt)
- {
- if (DIR_SEPARATOR == *nxt)
- end = nxt + 1;
- nxt++;
- }
- if ( (end == NULL) ||
- (strlen (end) == 0) )
- {
- GNUNET_break (0);
- return NULL;
- }
+ {
+ if (DIR_SEPARATOR == *nxt)
+ end = nxt + 1;
+ nxt++;
+ }
+ if ((end == NULL) || (strlen (end) == 0))
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
GNUNET_break (6 == strlen (end));
- return GNUNET_strdup (end);
+ return GNUNET_strdup (end);
}
@@ -1024,28 +961,26 @@
* @return NULL on errror
*/
static char *
-make_serialization_file_name (struct GNUNET_FS_Handle *h,
- const char *ext)
+make_serialization_file_name (struct GNUNET_FS_Handle *h, const char *ext)
{
char *fn;
char *dn;
char *ret;
if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
- return NULL; /* persistence not requested */
+ return NULL; /* persistence not requested */
dn = get_serialization_file_name (h, ext, "");
if (dn == NULL)
return NULL;
- if (GNUNET_OK !=
- GNUNET_DISK_directory_create_for_file (dn))
- {
- GNUNET_free (dn);
- return NULL;
- }
+ if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (dn))
+ {
+ GNUNET_free (dn);
+ return NULL;
+ }
fn = GNUNET_DISK_mktemp (dn);
GNUNET_free (dn);
if (fn == NULL)
- return NULL; /* epic fail */
+ return NULL; /* epic fail */
ret = get_serialization_short_name (fn);
GNUNET_free (fn);
return ret;
@@ -1063,28 +998,26 @@
*/
static char *
make_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h,
- const char *ext,
- const char *uni)
+ const char *ext, const char *uni)
{
char *fn;
char *dn;
char *ret;
if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
- return NULL; /* persistence not requested */
+ return NULL; /* persistence not requested */
dn = get_serialization_file_name_in_dir (h, ext, uni, "");
if (dn == NULL)
return NULL;
- if (GNUNET_OK !=
- GNUNET_DISK_directory_create_for_file (dn))
- {
- GNUNET_free (dn);
- return NULL;
- }
+ if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (dn))
+ {
+ GNUNET_free (dn);
+ return NULL;
+ }
fn = GNUNET_DISK_mktemp (dn);
GNUNET_free (dn);
if (fn == NULL)
- return NULL; /* epic fail */
+ return NULL; /* epic fail */
ret = get_serialization_short_name (fn);
GNUNET_free (fn);
return ret;
@@ -1100,7 +1033,7 @@
*/
static int
copy_from_reader (struct GNUNET_BIO_WriteHandle *wh,
- struct GNUNET_FS_FileInformation * fi)
+ struct GNUNET_FS_FileInformation *fi)
{
char buf[32 * 1024];
uint64_t off;
@@ -1111,22 +1044,19 @@
emsg = NULL;
off = 0;
while (off < fi->data.file.file_size)
+ {
+ left = GNUNET_MIN (sizeof (buf), fi->data.file.file_size - off);
+ ret = fi->data.file.reader (fi->data.file.reader_cls,
+ off, left, buf, &emsg);
+ if (ret == 0)
{
- left = GNUNET_MIN (sizeof(buf), fi->data.file.file_size - off);
- ret = fi->data.file.reader (fi->data.file.reader_cls,
- off, left,
- buf,
- &emsg);
- if (ret == 0)
- {
- GNUNET_free (emsg);
- return GNUNET_SYSERR;
- }
- if (GNUNET_OK !=
- GNUNET_BIO_write (wh, buf, ret))
- return GNUNET_SYSERR;
- off += ret;
+ GNUNET_free (emsg);
+ return GNUNET_SYSERR;
}
+ if (GNUNET_OK != GNUNET_BIO_write (wh, buf, ret))
+ return GNUNET_SYSERR;
+ off += ret;
+ }
return GNUNET_OK;
}
@@ -1138,7 +1068,7 @@
* @param fi file information to sync with disk
*/
void
-GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation * fi)
+GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi)
{
char *fn;
struct GNUNET_BIO_WriteHandle *wh;
@@ -1146,17 +1076,19 @@
char *ksks;
char *chks;
- if (NULL == fi->serialization)
- fi->serialization = make_serialization_file_name (fi->h,
GNUNET_FS_SYNC_PATH_FILE_INFO);
if (NULL == fi->serialization)
+ fi->serialization =
+ make_serialization_file_name (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO);
+ if (NULL == fi->serialization)
return;
- wh = get_write_handle (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO,
fi->serialization);
+ wh = get_write_handle (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO,
+ fi->serialization);
if (wh == NULL)
- {
- GNUNET_free (fi->serialization);
- fi->serialization = NULL;
- return;
- }
+ {
+ GNUNET_free (fi->serialization);
+ fi->serialization = NULL;
+ return;
+ }
if (GNUNET_YES == fi->is_directory)
b = 4;
else if (GNUNET_YES == fi->data.file.index_start_confirmed)
@@ -1175,131 +1107,130 @@
chks = GNUNET_FS_uri_to_string (fi->chk_uri);
else
chks = NULL;
- if ( (GNUNET_OK !=
- GNUNET_BIO_write (wh, &b, sizeof (b))) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_meta_data (wh, fi->meta)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_string (wh, ksks)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_string (wh, chks)) ||
- (GNUNET_OK !=
- write_start_time (wh, fi->start_time)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_string (wh, fi->emsg)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_string (wh, fi->filename)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_int64 (wh, fi->bo.expiration_time.abs_value)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_int32 (wh, fi->bo.anonymity_level)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_int32 (wh, fi->bo.content_priority)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_int32 (wh, fi->bo.replication_level)) )
- {
- GNUNET_break (0);
- goto cleanup;
- }
+ if ((GNUNET_OK !=
+ GNUNET_BIO_write (wh, &b, sizeof (b))) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_write_meta_data (wh, fi->meta)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_write_string (wh, ksks)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_write_string (wh, chks)) ||
+ (GNUNET_OK !=
+ write_start_time (wh, fi->start_time)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_write_string (wh, fi->emsg)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_write_string (wh, fi->filename)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_write_int64 (wh, fi->bo.expiration_time.abs_value)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_write_int32 (wh, fi->bo.anonymity_level)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_write_int32 (wh, fi->bo.content_priority)) ||
+ (GNUNET_OK != GNUNET_BIO_write_int32 (wh, fi->bo.replication_level)))
+ {
+ GNUNET_break (0);
+ goto cleanup;
+ }
GNUNET_free_non_null (chks);
chks = NULL;
GNUNET_free_non_null (ksks);
ksks = NULL;
-
+
switch (b)
+ {
+ case 0: /* file-insert */
+ if (GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.file.file_size))
{
- case 0: /* file-insert */
- if (GNUNET_OK !=
- GNUNET_BIO_write_int64 (wh, fi->data.file.file_size))
- {
- GNUNET_break (0);
- goto cleanup;
- }
- if ( (GNUNET_NO == fi->is_published) &&
- (NULL == fi->filename) )
- if (GNUNET_OK !=
- copy_from_reader (wh, fi))
- {
- GNUNET_break (0);
- goto cleanup;
- }
- break;
- case 1: /* file-index, no hash */
- if (NULL == fi->filename)
- {
- GNUNET_break (0);
- goto cleanup;
- }
- if (GNUNET_OK !=
- GNUNET_BIO_write_int64 (wh, fi->data.file.file_size))
- {
- GNUNET_break (0);
- goto cleanup;
- }
- break;
- case 2: /* file-index-with-hash */
- case 3: /* file-index-with-hash-confirmed */
- if (NULL == fi->filename)
- {
- GNUNET_break (0);
- goto cleanup;
- }
- if ( (GNUNET_OK !=
- GNUNET_BIO_write_int64 (wh, fi->data.file.file_size)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write (wh, &fi->data.file.file_id, sizeof
(GNUNET_HashCode))) )
- {
- GNUNET_break (0);
- goto cleanup;
- }
- break;
- case 4: /* directory */
- if ( (GNUNET_OK !=
- GNUNET_BIO_write_int32 (wh, fi->data.dir.dir_size)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write (wh, fi->data.dir.dir_data, (uint32_t)
fi->data.dir.dir_size)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_string (wh,
- (fi->data.dir.entries == NULL)
- ? NULL
- : fi->data.dir.entries->serialization)) )
- {
- GNUNET_break (0);
- goto cleanup;
- }
- break;
- default:
- GNUNET_assert (0);
+ GNUNET_break (0);
goto cleanup;
}
- if (GNUNET_OK !=
- GNUNET_BIO_write_string (wh, (fi->next != NULL) ?
fi->next->serialization : NULL))
+ if ((GNUNET_NO == fi->is_published) && (NULL == fi->filename))
+ if (GNUNET_OK != copy_from_reader (wh, fi))
+ {
+ GNUNET_break (0);
+ goto cleanup;
+ }
+ break;
+ case 1: /* file-index, no hash */
+ if (NULL == fi->filename)
{
- GNUNET_break (0);
- goto cleanup;
+ GNUNET_break (0);
+ goto cleanup;
}
- if (GNUNET_OK !=
- GNUNET_BIO_write_close (wh))
+ if (GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.file.file_size))
{
- wh = NULL;
GNUNET_break (0);
goto cleanup;
}
- return; /* done! */
- cleanup:
+ break;
+ case 2: /* file-index-with-hash */
+ case 3: /* file-index-with-hash-confirmed */
+ if (NULL == fi->filename)
+ {
+ GNUNET_break (0);
+ goto cleanup;
+ }
+ if ((GNUNET_OK !=
+ GNUNET_BIO_write_int64 (wh, fi->data.file.file_size)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_write (wh, &fi->data.file.file_id,
+ sizeof (GNUNET_HashCode))))
+ {
+ GNUNET_break (0);
+ goto cleanup;
+ }
+ break;
+ case 4: /* directory */
+ if ((GNUNET_OK !=
+ GNUNET_BIO_write_int32 (wh, fi->data.dir.dir_size)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_write (wh, fi->data.dir.dir_data,
+ (uint32_t) fi->data.dir.dir_size)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_write_string (wh,
+ (fi->data.dir.entries ==
+ NULL) ? NULL : fi->data.dir.
+ entries->serialization)))
+ {
+ GNUNET_break (0);
+ goto cleanup;
+ }
+ break;
+ default:
+ GNUNET_assert (0);
+ goto cleanup;
+ }
+ if (GNUNET_OK !=
+ GNUNET_BIO_write_string (wh,
+ (fi->next !=
+ NULL) ? fi->next->serialization : NULL))
+ {
+ GNUNET_break (0);
+ goto cleanup;
+ }
+ if (GNUNET_OK != GNUNET_BIO_write_close (wh))
+ {
+ wh = NULL;
+ GNUNET_break (0);
+ goto cleanup;
+ }
+ return; /* done! */
+cleanup:
if (wh != NULL)
(void) GNUNET_BIO_write_close (wh);
GNUNET_free_non_null (chks);
GNUNET_free_non_null (ksks);
- fn = get_serialization_file_name (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO,
fi->serialization);
+ fn = get_serialization_file_name (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO,
+ fi->serialization);
if (NULL != fn)
- {
- if (0 != UNLINK (fn))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn);
- GNUNET_free (fn);
- }
+ {
+ if (0 != UNLINK (fn))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn);
+ GNUNET_free (fn);
+ }
GNUNET_free (fi->serialization);
- fi->serialization = NULL;
+ fi->serialization = NULL;
}
@@ -1313,25 +1244,22 @@
* @return NULL if srch was not found in this subtree
*/
static struct GNUNET_FS_FileInformation *
-find_file_position (struct GNUNET_FS_FileInformation *pos,
- const char *srch)
+find_file_position (struct GNUNET_FS_FileInformation *pos, const char *srch)
{
struct GNUNET_FS_FileInformation *r;
while (pos != NULL)
+ {
+ if (0 == strcmp (srch, pos->serialization))
+ return pos;
+ if (pos->is_directory)
{
- if (0 == strcmp (srch,
- pos->serialization))
- return pos;
- if (pos->is_directory)
- {
- r = find_file_position (pos->data.dir.entries,
- srch);
- if (r != NULL)
- return r;
- }
- pos = pos->next;
+ r = find_file_position (pos->data.dir.entries, srch);
+ if (r != NULL)
+ return r;
}
+ pos = pos->next;
+ }
return NULL;
}
@@ -1351,14 +1279,13 @@
* @return GNUNET_OK to continue (always)
*/
static int
-fip_signal_resume(void *cls,
- struct GNUNET_FS_FileInformation *fi,
- uint64_t length,
- struct GNUNET_CONTAINER_MetaData *meta,
- struct GNUNET_FS_Uri **uri,
- struct GNUNET_FS_BlockOptions *bo,
- int *do_index,
- void **client_info)
+fip_signal_resume (void *cls,
+ struct GNUNET_FS_FileInformation *fi,
+ uint64_t length,
+ struct GNUNET_CONTAINER_MetaData *meta,
+ struct GNUNET_FS_Uri **uri,
+ struct GNUNET_FS_BlockOptions *bo,
+ int *do_index, void **client_info)
{
struct GNUNET_FS_PublishContext *sc = cls;
struct GNUNET_FS_ProgressInfo pi;
@@ -1380,8 +1307,7 @@
* @return GNUNET_OK (continue to iterate)
*/
static int
-deserialize_publish_file (void *cls,
- const char *filename)
+deserialize_publish_file (void *cls, const char *filename)
{
struct GNUNET_FS_Handle *h = cls;
struct GNUNET_BIO_ReadHandle *rh;
@@ -1401,117 +1327,109 @@
ns = NULL;
rh = GNUNET_BIO_read_open (filename);
if (rh == NULL)
- {
- GNUNET_break (0);
- goto cleanup;
- }
- if ( (GNUNET_OK !=
- GNUNET_BIO_read_string (rh, "publish-nid", &pc->nid, 1024)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read_string (rh, "publish-nuid", &pc->nuid, 1024)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read_int32 (rh, &options)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read_int32 (rh, &all_done)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read_string (rh, "publish-firoot", &fi_root, 128)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read_string (rh, "publish-fipos", &fi_pos, 128)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read_string (rh, "publish-ns", &ns, 1024)) )
- {
- GNUNET_break (0);
- goto cleanup;
- }
+ {
+ GNUNET_break (0);
+ goto cleanup;
+ }
+ if ((GNUNET_OK !=
+ GNUNET_BIO_read_string (rh, "publish-nid", &pc->nid, 1024)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_read_string (rh, "publish-nuid", &pc->nuid, 1024)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_read_int32 (rh, &options)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_read_int32 (rh, &all_done)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_read_string (rh, "publish-firoot", &fi_root, 128)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_read_string (rh, "publish-fipos", &fi_pos, 128)) ||
+ (GNUNET_OK != GNUNET_BIO_read_string (rh, "publish-ns", &ns, 1024)))
+ {
+ GNUNET_break (0);
+ goto cleanup;
+ }
pc->options = options;
pc->all_done = all_done;
if (NULL == fi_root)
- {
- GNUNET_break (0);
- goto cleanup;
- }
+ {
+ GNUNET_break (0);
+ goto cleanup;
+ }
pc->fi = deserialize_file_information (h, fi_root);
if (pc->fi == NULL)
- {
- GNUNET_break (0);
- goto cleanup;
- }
+ {
+ GNUNET_break (0);
+ goto cleanup;
+ }
if (ns != NULL)
+ {
+ pc->namespace = GNUNET_FS_namespace_create (h, ns);
+ if (pc->namespace == NULL)
{
- pc->namespace = GNUNET_FS_namespace_create (h, ns);
- if (pc->namespace == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to recover namespace `%s', cannot resume
publishing operation.\n"),
- ns);
- goto cleanup;
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Failed to recover namespace `%s', cannot resume publishing
operation.\n"),
+ ns);
+ goto cleanup;
}
- if ( (0 == (pc->options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) &&
- (GNUNET_YES != pc->all_done) )
- {
- pc->dsh = GNUNET_DATASTORE_connect (h->cfg);
- if (NULL == pc->dsh)
- goto cleanup;
- }
+ }
+ if ((0 == (pc->options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) &&
+ (GNUNET_YES != pc->all_done))
+ {
+ pc->dsh = GNUNET_DATASTORE_connect (h->cfg);
+ if (NULL == pc->dsh)
+ goto cleanup;
+ }
if (fi_pos != NULL)
+ {
+ pc->fi_pos = find_file_position (pc->fi, fi_pos);
+ GNUNET_free (fi_pos);
+ fi_pos = NULL;
+ if (pc->fi_pos == NULL)
{
- pc->fi_pos = find_file_position (pc->fi,
- fi_pos);
- GNUNET_free (fi_pos);
- fi_pos = NULL;
- if (pc->fi_pos == NULL)
- {
- /* failed to find position for resuming, outch! Will start from root!
*/
- GNUNET_break (0);
- if (pc->all_done != GNUNET_YES)
- pc->fi_pos = pc->fi;
- }
+ /* failed to find position for resuming, outch! Will start from root! */
+ GNUNET_break (0);
+ if (pc->all_done != GNUNET_YES)
+ pc->fi_pos = pc->fi;
}
+ }
GNUNET_free (fi_root);
fi_root = NULL;
/* generate RESUME event(s) */
- GNUNET_FS_file_information_inspect (pc->fi,
- &fip_signal_resume,
- pc);
-
+ GNUNET_FS_file_information_inspect (pc->fi, &fip_signal_resume, pc);
+
/* re-start publishing (if needed)... */
if (pc->all_done != GNUNET_YES)
- {
- GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task);
- pc->upload_task
- = GNUNET_SCHEDULER_add_with_priority
(GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
- &GNUNET_FS_publish_main_,
- pc);
- }
- if (GNUNET_OK !=
- GNUNET_BIO_read_close (rh, &emsg))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failure while resuming publishing operation `%s': %s\n"),
- filename,
- emsg);
- GNUNET_free (emsg);
- }
+ {
+ GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task);
+ pc->upload_task
+ =
+ GNUNET_SCHEDULER_add_with_priority
+ (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, &GNUNET_FS_publish_main_, pc);
+ }
+ if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Failure while resuming publishing operation `%s': %s\n"),
+ filename, emsg);
+ GNUNET_free (emsg);
+ }
GNUNET_free_non_null (ns);
pc->top = GNUNET_FS_make_top (h, &GNUNET_FS_publish_signal_suspend_, pc);
return GNUNET_OK;
- cleanup:
+cleanup:
GNUNET_free_non_null (pc->nid);
GNUNET_free_non_null (pc->nuid);
GNUNET_free_non_null (fi_root);
GNUNET_free_non_null (fi_pos);
GNUNET_free_non_null (ns);
- if ( (rh != NULL) &&
- (GNUNET_OK !=
- GNUNET_BIO_read_close (rh, &emsg)) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to resume publishing operation `%s': %s\n"),
- filename,
- emsg);
- GNUNET_free (emsg);
- }
+ if ((rh != NULL) && (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Failed to resume publishing operation `%s': %s\n"),
+ filename, emsg);
+ GNUNET_free (emsg);
+ }
if (pc->fi != NULL)
GNUNET_FS_file_information_destroy (pc->fi, NULL, NULL);
if (0 != UNLINK (filename))
@@ -1532,59 +1450,64 @@
*/
void
GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc)
-{
+{
struct GNUNET_BIO_WriteHandle *wh;
if (NULL == pc->serialization)
pc->serialization = make_serialization_file_name (pc->h,
-
GNUNET_FS_SYNC_PATH_MASTER_PUBLISH);
+
GNUNET_FS_SYNC_PATH_MASTER_PUBLISH);
if (NULL == pc->serialization)
return;
if (NULL == pc->fi)
return;
if (NULL == pc->fi->serialization)
- {
- GNUNET_break (0);
- return;
- }
- wh = get_write_handle (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH,
pc->serialization);
+ {
+ GNUNET_break (0);
+ return;
+ }
+ wh = get_write_handle (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH,
+ pc->serialization);
if (wh == NULL)
- {
- GNUNET_break (0);
- goto cleanup;
- }
- if ( (GNUNET_OK !=
- GNUNET_BIO_write_string (wh, pc->nid)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_string (wh, pc->nuid)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_int32 (wh, pc->options)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_int32 (wh, pc->all_done)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_string (wh, pc->fi->serialization)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_string (wh, (pc->fi_pos == NULL) ? NULL :
pc->fi_pos->serialization)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_string (wh, (pc->namespace == NULL) ? NULL :
pc->namespace->name)) )
- {
- GNUNET_break (0);
- goto cleanup;
- }
- if (GNUNET_OK !=
- GNUNET_BIO_write_close (wh))
- {
- wh = NULL;
- GNUNET_break (0);
- goto cleanup;
- }
- return;
- cleanup:
- if (wh != NULL)
- (void) GNUNET_BIO_write_close (wh);
- GNUNET_FS_remove_sync_file_ (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH,
pc->serialization);
- GNUNET_free (pc->serialization);
- pc->serialization = NULL;
+ {
+ GNUNET_break (0);
+ goto cleanup;
+ }
+ if ((GNUNET_OK !=
+ GNUNET_BIO_write_string (wh, pc->nid)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_write_string (wh, pc->nuid)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_write_int32 (wh, pc->options)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_write_int32 (wh, pc->all_done)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_write_string (wh, pc->fi->serialization)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_write_string (wh,
+ (pc->fi_pos ==
+ NULL) ? NULL : pc->fi_pos->serialization)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_write_string (wh,
+ (pc->namespace ==
+ NULL) ? NULL : pc->namespace->name)))
+ {
+ GNUNET_break (0);
+ goto cleanup;
+ }
+ if (GNUNET_OK != GNUNET_BIO_write_close (wh))
+ {
+ wh = NULL;
+ GNUNET_break (0);
+ goto cleanup;
+ }
+ return;
+cleanup:
+ if (wh != NULL)
+ (void) GNUNET_BIO_write_close (wh);
+ GNUNET_FS_remove_sync_file_ (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH,
+ pc->serialization);
+ GNUNET_free (pc->serialization);
+ pc->serialization = NULL;
}
@@ -1603,45 +1526,45 @@
if (NULL == uc->serialization)
uc->serialization = make_serialization_file_name (uc->h,
-
GNUNET_FS_SYNC_PATH_MASTER_UNINDEX);
+
GNUNET_FS_SYNC_PATH_MASTER_UNINDEX);
if (NULL == uc->serialization)
return;
- wh = get_write_handle (uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX,
uc->serialization);
+ wh = get_write_handle (uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX,
+ uc->serialization);
if (wh == NULL)
- {
- GNUNET_break (0);
- goto cleanup;
- }
- if ( (GNUNET_OK !=
- GNUNET_BIO_write_string (wh, uc->filename)) ||
+ {
+ GNUNET_break (0);
+ goto cleanup;
+ }
+ if ((GNUNET_OK !=
+ GNUNET_BIO_write_string (wh, uc->filename)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_write_int64 (wh, uc->file_size)) ||
+ (GNUNET_OK !=
+ write_start_time (wh, uc->start_time)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_write_int32 (wh, (uint32_t) uc->state)) ||
+ ((uc->state == UNINDEX_STATE_FS_NOTIFY) &&
(GNUNET_OK !=
- GNUNET_BIO_write_int64 (wh, uc->file_size)) ||
- (GNUNET_OK !=
- write_start_time (wh, uc->start_time)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_int32 (wh, (uint32_t) uc->state)) ||
- ( (uc->state == UNINDEX_STATE_FS_NOTIFY) &&
- (GNUNET_OK !=
- GNUNET_BIO_write (wh, &uc->file_id, sizeof (GNUNET_HashCode))) ) ||
- ( (uc->state == UNINDEX_STATE_ERROR) &&
- (GNUNET_OK !=
- GNUNET_BIO_write_string (wh, uc->emsg)) ) )
- {
- GNUNET_break (0);
- goto cleanup;
- }
- if (GNUNET_OK !=
- GNUNET_BIO_write_close (wh))
- {
- wh = NULL;
- GNUNET_break (0);
- goto cleanup;
- }
+ GNUNET_BIO_write (wh, &uc->file_id, sizeof (GNUNET_HashCode)))) ||
+ ((uc->state == UNINDEX_STATE_ERROR) &&
+ (GNUNET_OK != GNUNET_BIO_write_string (wh, uc->emsg))))
+ {
+ GNUNET_break (0);
+ goto cleanup;
+ }
+ if (GNUNET_OK != GNUNET_BIO_write_close (wh))
+ {
+ wh = NULL;
+ GNUNET_break (0);
+ goto cleanup;
+ }
return;
- cleanup:
+cleanup:
if (wh != NULL)
(void) GNUNET_BIO_write_close (wh);
- GNUNET_FS_remove_sync_file_ (uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX,
uc->serialization);
+ GNUNET_FS_remove_sync_file_ (uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX,
+ uc->serialization);
GNUNET_free (uc->serialization);
uc->serialization = NULL;
}
@@ -1656,26 +1579,24 @@
*/
static int
write_download_request (struct GNUNET_BIO_WriteHandle *wh,
- struct DownloadRequest *dr)
-{
+ struct DownloadRequest *dr)
+{
unsigned int i;
-
- if ( (GNUNET_OK !=
- GNUNET_BIO_write_int32 (wh, dr->state)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_int64 (wh, dr->offset)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_int32 (wh, dr->num_children)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_int32 (wh, dr->depth)) )
- return GNUNET_NO;
- if ( (dr->state == BRS_CHK_SET) &&
- (GNUNET_OK !=
- GNUNET_BIO_write (wh, &dr->chk, sizeof (struct ContentHashKey))) )
+
+ if ((GNUNET_OK !=
+ GNUNET_BIO_write_int32 (wh, dr->state)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_write_int64 (wh, dr->offset)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_write_int32 (wh, dr->num_children)) ||
+ (GNUNET_OK != GNUNET_BIO_write_int32 (wh, dr->depth)))
return GNUNET_NO;
- for (i=0;i<dr->num_children;i++)
- if (GNUNET_NO ==
- write_download_request (wh, dr->children[i]))
+ if ((dr->state == BRS_CHK_SET) &&
+ (GNUNET_OK !=
+ GNUNET_BIO_write (wh, &dr->chk, sizeof (struct ContentHashKey))))
+ return GNUNET_NO;
+ for (i = 0; i < dr->num_children; i++)
+ if (GNUNET_NO == write_download_request (wh, dr->children[i]))
return GNUNET_NO;
return GNUNET_YES;
}
@@ -1689,59 +1610,59 @@
*/
static struct DownloadRequest *
read_download_request (struct GNUNET_BIO_ReadHandle *rh)
-{
+{
struct DownloadRequest *dr;
unsigned int i;
dr = GNUNET_malloc (sizeof (struct DownloadRequest));
- if ( (GNUNET_OK !=
- GNUNET_BIO_read_int32 (rh, &dr->state)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read_int64 (rh, &dr->offset)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read_int32 (rh, &dr->num_children)) ||
- (dr->num_children > CHK_PER_INODE) ||
- (GNUNET_OK !=
- GNUNET_BIO_read_int32 (rh, &dr->depth)) ||
- ( (dr->depth == 0) && (dr->num_children > 0) ) ||
- ( (dr->depth > 0) && (dr->num_children == 0) ) )
- {
- GNUNET_break (0);
- dr->num_children = 0;
- goto cleanup;
- }
+ if ((GNUNET_OK !=
+ GNUNET_BIO_read_int32 (rh, &dr->state)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_read_int64 (rh, &dr->offset)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_read_int32 (rh, &dr->num_children)) ||
+ (dr->num_children > CHK_PER_INODE) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_read_int32 (rh, &dr->depth)) ||
+ ((dr->depth == 0) && (dr->num_children > 0)) ||
+ ((dr->depth > 0) && (dr->num_children == 0)))
+ {
+ GNUNET_break (0);
+ dr->num_children = 0;
+ goto cleanup;
+ }
if (dr->num_children > 0)
dr->children = GNUNET_malloc (dr->num_children *
- sizeof (struct ContentHashKey));
+ sizeof (struct ContentHashKey));
switch (dr->state)
- {
- case BRS_INIT:
- case BRS_RECONSTRUCT_DOWN:
- case BRS_RECONSTRUCT_META_UP:
- case BRS_RECONSTRUCT_UP:
- break;
- case BRS_CHK_SET:
- if (GNUNET_OK !=
- GNUNET_BIO_read (rh, "chk", &dr->chk, sizeof (struct
ContentHashKey)))
- goto cleanup;
- break;
- case BRS_DOWNLOAD_DOWN:
- case BRS_DOWNLOAD_UP:
- case BRS_ERROR:
- break;
- default:
- GNUNET_break (0);
+ {
+ case BRS_INIT:
+ case BRS_RECONSTRUCT_DOWN:
+ case BRS_RECONSTRUCT_META_UP:
+ case BRS_RECONSTRUCT_UP:
+ break;
+ case BRS_CHK_SET:
+ if (GNUNET_OK !=
+ GNUNET_BIO_read (rh, "chk", &dr->chk, sizeof (struct ContentHashKey)))
goto cleanup;
- }
- for (i=0;i<dr->num_children;i++)
- {
- if (NULL == (dr->children[i] = read_download_request (rh)))
- goto cleanup;
- dr->children[i]->parent = dr;
- }
+ break;
+ case BRS_DOWNLOAD_DOWN:
+ case BRS_DOWNLOAD_UP:
+ case BRS_ERROR:
+ break;
+ default:
+ GNUNET_break (0);
+ goto cleanup;
+ }
+ for (i = 0; i < dr->num_children; i++)
+ {
+ if (NULL == (dr->children[i] = read_download_request (rh)))
+ goto cleanup;
+ dr->children[i]->parent = dr;
+ }
return dr;
- cleanup:
+cleanup:
GNUNET_FS_free_download_request_ (dr);
return NULL;
}
@@ -1758,29 +1679,23 @@
*/
static char *
get_download_sync_filename (struct GNUNET_FS_DownloadContext *dc,
- const char *uni,
- const char *ext)
+ const char *uni, const char *ext)
{
char *par;
char *epar;
if (dc->parent == NULL)
return get_serialization_file_name (dc->h,
- (dc->search != NULL) ?
- GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD :
- GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD,
- uni);
+ (dc->search != NULL) ?
+ GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD :
+ GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD,
+ uni);
if (dc->parent->serialization == NULL)
return NULL;
par = get_download_sync_filename (dc->parent, dc->parent->serialization, "");
if (par == NULL)
return NULL;
- GNUNET_asprintf (&epar,
- "%s.dir%s%s%s",
- par,
- DIR_SEPARATOR_STR,
- uni,
- ext);
+ GNUNET_asprintf (&epar, "%s.dir%s%s%s", par, DIR_SEPARATOR_STR, uni, ext);
GNUNET_free (par);
return epar;
}
@@ -1802,97 +1717,93 @@
char *fn;
char *dir;
- if (NULL == dc->serialization)
+ if (NULL == dc->serialization)
+ {
+ dir = get_download_sync_filename (dc, "", "");
+ if (dir == NULL)
+ return;
+ if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (dir))
{
- dir = get_download_sync_filename (dc, "", "");
- if (dir == NULL)
- return;
- if (GNUNET_OK !=
- GNUNET_DISK_directory_create_for_file (dir))
- {
- GNUNET_free (dir);
- return;
- }
- fn = GNUNET_DISK_mktemp (dir);
GNUNET_free (dir);
- if (fn == NULL)
- return;
- dc->serialization = get_serialization_short_name (fn);
+ return;
}
+ fn = GNUNET_DISK_mktemp (dir);
+ GNUNET_free (dir);
+ if (fn == NULL)
+ return;
+ dc->serialization = get_serialization_short_name (fn);
+ }
else
+ {
+ fn = get_download_sync_filename (dc, dc->serialization, "");
+ if (fn == NULL)
{
- fn = get_download_sync_filename (dc, dc->serialization, "");
- if (fn == NULL)
- {
- GNUNET_free (dc->serialization);
- dc->serialization = NULL;
- GNUNET_free (fn);
- return;
- }
- }
- wh = GNUNET_BIO_write_open (fn);
- if (wh == NULL)
- {
GNUNET_free (dc->serialization);
dc->serialization = NULL;
GNUNET_free (fn);
return;
}
- GNUNET_assert ( (GNUNET_YES == GNUNET_FS_uri_test_chk (dc->uri)) ||
- (GNUNET_YES == GNUNET_FS_uri_test_loc (dc->uri)) );
+ }
+ wh = GNUNET_BIO_write_open (fn);
+ if (wh == NULL)
+ {
+ GNUNET_free (dc->serialization);
+ dc->serialization = NULL;
+ GNUNET_free (fn);
+ return;
+ }
+ GNUNET_assert ((GNUNET_YES == GNUNET_FS_uri_test_chk (dc->uri)) ||
+ (GNUNET_YES == GNUNET_FS_uri_test_loc (dc->uri)));
uris = GNUNET_FS_uri_to_string (dc->uri);
- if ( (GNUNET_OK !=
- GNUNET_BIO_write_string (wh, uris)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_meta_data (wh, dc->meta)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_string (wh, dc->emsg)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_string (wh, dc->filename)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_string (wh, dc->temp_filename)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_int64 (wh, dc->old_file_size)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_int64 (wh, dc->offset)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_int64 (wh, dc->length)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_int64 (wh, dc->completed)) ||
- (GNUNET_OK !=
- write_start_time (wh, dc->start_time)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_int32 (wh, dc->anonymity)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_int32 (wh, (uint32_t) dc->options)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_int32 (wh, (uint32_t) dc->has_finished)) )
- {
- GNUNET_break (0);
- goto cleanup;
- }
+ if ((GNUNET_OK !=
+ GNUNET_BIO_write_string (wh, uris)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_write_meta_data (wh, dc->meta)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_write_string (wh, dc->emsg)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_write_string (wh, dc->filename)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_write_string (wh, dc->temp_filename)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_write_int64 (wh, dc->old_file_size)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_write_int64 (wh, dc->offset)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_write_int64 (wh, dc->length)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_write_int64 (wh, dc->completed)) ||
+ (GNUNET_OK !=
+ write_start_time (wh, dc->start_time)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_write_int32 (wh, dc->anonymity)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_write_int32 (wh, (uint32_t) dc->options)) ||
+ (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) dc->has_finished)))
+ {
+ GNUNET_break (0);
+ goto cleanup;
+ }
if (NULL == dc->emsg)
+ {
+ GNUNET_assert (dc->top_request != NULL);
+ if (GNUNET_YES != write_download_request (wh, dc->top_request))
{
- GNUNET_assert (dc->top_request != NULL);
- if (GNUNET_YES !=
- write_download_request (wh, dc->top_request))
- {
- GNUNET_break (0);
- goto cleanup;
- }
- }
- GNUNET_free_non_null (uris);
- uris = NULL;
- if (GNUNET_OK !=
- GNUNET_BIO_write_close (wh))
- {
- wh = NULL;
GNUNET_break (0);
goto cleanup;
}
+ }
+ GNUNET_free_non_null (uris);
+ uris = NULL;
+ if (GNUNET_OK != GNUNET_BIO_write_close (wh))
+ {
+ wh = NULL;
+ GNUNET_break (0);
+ goto cleanup;
+ }
GNUNET_free (fn);
return;
- cleanup:
+cleanup:
if (NULL != wh)
(void) GNUNET_BIO_write_close (wh);
GNUNET_free_non_null (uris);
@@ -1921,65 +1832,65 @@
uris = NULL;
if (NULL == sr->serialization)
sr->serialization = make_serialization_file_name_in_dir (sr->sc->h,
-
(sr->sc->psearch_result == NULL)
- ?
GNUNET_FS_SYNC_PATH_MASTER_SEARCH
- :
GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
-
sr->sc->serialization);
+ (sr->
+
sc->psearch_result
+ ==
+ NULL) ?
+
GNUNET_FS_SYNC_PATH_MASTER_SEARCH
+ :
+
GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
+ sr->
+
sc->serialization);
if (NULL == sr->serialization)
return;
- wh = get_write_handle_in_dir (sr->sc->h,
- (sr->sc->psearch_result == NULL)
- ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
- : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
- sr->sc->serialization,
- sr->serialization);
+ wh = get_write_handle_in_dir (sr->sc->h,
+ (sr->sc->psearch_result == NULL)
+ ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
+ : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
+ sr->sc->serialization, sr->serialization);
if (wh == NULL)
- {
- GNUNET_break (0);
- goto cleanup;
- }
+ {
+ GNUNET_break (0);
+ goto cleanup;
+ }
uris = GNUNET_FS_uri_to_string (sr->uri);
- if ( (GNUNET_OK !=
- GNUNET_BIO_write_string (wh, uris)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_string (wh, sr->download != NULL ?
sr->download->serialization : NULL)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_string (wh, sr->update_search != NULL ?
sr->update_search->serialization : NULL)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_meta_data (wh, sr->meta)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write (wh, &sr->key, sizeof (GNUNET_HashCode))) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_int32 (wh, sr->mandatory_missing)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_int32 (wh, sr->optional_support)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_int32 (wh, sr->availability_success)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_int32 (wh, sr->availability_trials)) )
- {
- GNUNET_break (0);
- goto cleanup;
- }
- if (GNUNET_OK !=
- GNUNET_BIO_write_close (wh))
- {
- wh = NULL;
- GNUNET_break (0);
- goto cleanup;
- }
+ if ((GNUNET_OK !=
+ GNUNET_BIO_write_string (wh, uris)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_write_string (wh,
+ sr->download !=
+ NULL ? sr->download->serialization : NULL)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_write_string (wh,
+ sr->update_search !=
+ NULL ? sr->update_search->serialization :
NULL))
+ || (GNUNET_OK != GNUNET_BIO_write_meta_data (wh, sr->meta)) ||
+ (GNUNET_OK != GNUNET_BIO_write (wh, &sr->key, sizeof (GNUNET_HashCode)))
+ || (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->mandatory_missing)) ||
+ (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->optional_support)) ||
+ (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->availability_success)) ||
+ (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->availability_trials)))
+ {
+ GNUNET_break (0);
+ goto cleanup;
+ }
+ if (GNUNET_OK != GNUNET_BIO_write_close (wh))
+ {
+ wh = NULL;
+ GNUNET_break (0);
+ goto cleanup;
+ }
GNUNET_free_non_null (uris);
return;
- cleanup:
+cleanup:
GNUNET_free_non_null (uris);
if (wh != NULL)
- (void) GNUNET_BIO_write_close (wh);
+ (void) GNUNET_BIO_write_close (wh);
remove_sync_file_in_dir (sr->sc->h,
- (sr->sc->psearch_result == NULL)
- ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
- : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
- sr->sc->serialization,
- sr->serialization);
+ (sr->sc->psearch_result == NULL)
+ ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
+ : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
+ sr->sc->serialization, sr->serialization);
GNUNET_free (sr->serialization);
sr->serialization = NULL;
}
@@ -1995,58 +1906,54 @@
*/
void
GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc)
-{
+{
struct GNUNET_BIO_WriteHandle *wh;
char *uris;
char in_pause;
const char *category;
-
- category = (sc->psearch_result == NULL)
- ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
- : GNUNET_FS_SYNC_PATH_CHILD_SEARCH;
+
+ category = (sc->psearch_result == NULL)
+ ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH : GNUNET_FS_SYNC_PATH_CHILD_SEARCH;
if (NULL == sc->serialization)
- sc->serialization = make_serialization_file_name (sc->h,
- category);
+ sc->serialization = make_serialization_file_name (sc->h, category);
if (NULL == sc->serialization)
return;
uris = NULL;
wh = get_write_handle (sc->h, category, sc->serialization);
if (wh == NULL)
- {
- GNUNET_break (0);
- goto cleanup;
- }
- GNUNET_assert ( (GNUNET_YES == GNUNET_FS_uri_test_ksk (sc->uri)) ||
- (GNUNET_YES == GNUNET_FS_uri_test_sks (sc->uri)) );
+ {
+ GNUNET_break (0);
+ goto cleanup;
+ }
+ GNUNET_assert ((GNUNET_YES == GNUNET_FS_uri_test_ksk (sc->uri)) ||
+ (GNUNET_YES == GNUNET_FS_uri_test_sks (sc->uri)));
uris = GNUNET_FS_uri_to_string (sc->uri);
in_pause = (sc->task != GNUNET_SCHEDULER_NO_TASK) ? 'r' : '\0';
- if ( (GNUNET_OK !=
- GNUNET_BIO_write_string (wh, uris)) ||
- (GNUNET_OK !=
- write_start_time (wh, sc->start_time)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_string (wh, sc->emsg)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_int32 (wh, (uint32_t) sc->options)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write (wh, &in_pause, sizeof (in_pause))) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_int32 (wh, sc->anonymity)) )
- {
- GNUNET_break (0);
- goto cleanup;
- }
+ if ((GNUNET_OK !=
+ GNUNET_BIO_write_string (wh, uris)) ||
+ (GNUNET_OK !=
+ write_start_time (wh, sc->start_time)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_write_string (wh, sc->emsg)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_write_int32 (wh, (uint32_t) sc->options)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_write (wh, &in_pause, sizeof (in_pause))) ||
+ (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sc->anonymity)))
+ {
+ GNUNET_break (0);
+ goto cleanup;
+ }
GNUNET_free (uris);
uris = NULL;
- if (GNUNET_OK !=
- GNUNET_BIO_write_close (wh))
- {
- wh = NULL;
- GNUNET_break (0);
- goto cleanup;
- }
+ if (GNUNET_OK != GNUNET_BIO_write_close (wh))
+ {
+ wh = NULL;
+ GNUNET_break (0);
+ goto cleanup;
+ }
return;
- cleanup:
+cleanup:
if (wh != NULL)
(void) GNUNET_BIO_write_close (wh);
GNUNET_free_non_null (uris);
@@ -2065,8 +1972,7 @@
* @return GNUNET_OK (continue to iterate)
*/
static int
-deserialize_unindex_file (void *cls,
- const char *filename)
+deserialize_unindex_file (void *cls, const char *filename)
{
struct GNUNET_FS_Handle *h = cls;
struct GNUNET_BIO_ReadHandle *rh;
@@ -2080,109 +1986,100 @@
uc->serialization = get_serialization_short_name (filename);
rh = GNUNET_BIO_read_open (filename);
if (rh == NULL)
+ {
+ GNUNET_break (0);
+ goto cleanup;
+ }
+ if ((GNUNET_OK !=
+ GNUNET_BIO_read_string (rh, "unindex-fn", &uc->filename, 10 * 1024)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_read_int64 (rh, &uc->file_size)) ||
+ (GNUNET_OK !=
+ read_start_time (rh, &uc->start_time)) ||
+ (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &state)))
+ {
+ GNUNET_break (0);
+ goto cleanup;
+ }
+ uc->state = (enum UnindexState) state;
+ switch (state)
+ {
+ case UNINDEX_STATE_HASHING:
+ break;
+ case UNINDEX_STATE_FS_NOTIFY:
+ if (GNUNET_OK !=
+ GNUNET_BIO_read (rh, "unindex-hash", &uc->file_id,
+ sizeof (GNUNET_HashCode)))
{
- GNUNET_break (0);
+ GNUNET_break (0);
goto cleanup;
}
- if ( (GNUNET_OK !=
- GNUNET_BIO_read_string (rh, "unindex-fn", &uc->filename, 10*1024)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read_int64 (rh, &uc->file_size)) ||
- (GNUNET_OK !=
- read_start_time (rh, &uc->start_time)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read_int32 (rh, &state)) )
+ break;
+ case UNINDEX_STATE_DS_REMOVE:
+ break;
+ case UNINDEX_STATE_COMPLETE:
+ break;
+ case UNINDEX_STATE_ERROR:
+ if (GNUNET_OK !=
+ GNUNET_BIO_read_string (rh, "unindex-emsg", &uc->emsg, 10 * 1024))
{
- GNUNET_break (0);
- goto cleanup;
- }
- uc->state = (enum UnindexState) state;
- switch (state)
- {
- case UNINDEX_STATE_HASHING:
- break;
- case UNINDEX_STATE_FS_NOTIFY:
- if (GNUNET_OK !=
- GNUNET_BIO_read (rh, "unindex-hash", &uc->file_id, sizeof
(GNUNET_HashCode)))
- {
- GNUNET_break (0);
- goto cleanup;
- }
- break;
- case UNINDEX_STATE_DS_REMOVE:
- break;
- case UNINDEX_STATE_COMPLETE:
- break;
- case UNINDEX_STATE_ERROR:
- if (GNUNET_OK !=
- GNUNET_BIO_read_string (rh, "unindex-emsg", &uc->emsg, 10*1024))
- {
- GNUNET_break (0);
- goto cleanup;
- }
- break;
- default:
GNUNET_break (0);
goto cleanup;
}
- uc->top = GNUNET_FS_make_top (h,
- &GNUNET_FS_unindex_signal_suspend_,
- uc);
+ break;
+ default:
+ GNUNET_break (0);
+ goto cleanup;
+ }
+ uc->top = GNUNET_FS_make_top (h, &GNUNET_FS_unindex_signal_suspend_, uc);
pi.status = GNUNET_FS_STATUS_UNINDEX_RESUME;
pi.value.unindex.specifics.resume.message = uc->emsg;
GNUNET_FS_unindex_make_status_ (&pi,
- uc,
- (uc->state == UNINDEX_STATE_COMPLETE)
- ? uc->file_size
- : 0);
+ uc,
+ (uc->state == UNINDEX_STATE_COMPLETE)
+ ? uc->file_size : 0);
switch (uc->state)
- {
- case UNINDEX_STATE_HASHING:
- uc->fhc = GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE,
- uc->filename,
- HASHING_BLOCKSIZE,
- &GNUNET_FS_unindex_process_hash_,
- uc);
- break;
- case UNINDEX_STATE_FS_NOTIFY:
- uc->state = UNINDEX_STATE_HASHING;
- GNUNET_FS_unindex_process_hash_ (uc,
- &uc->file_id);
- break;
- case UNINDEX_STATE_DS_REMOVE:
- GNUNET_FS_unindex_do_remove_ (uc);
- break;
- case UNINDEX_STATE_COMPLETE:
- case UNINDEX_STATE_ERROR:
- /* no need to resume any operation, we were done */
- break;
- default:
- break;
- }
- if (GNUNET_OK !=
- GNUNET_BIO_read_close (rh, &emsg))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failure while resuming unindexing operation `%s': %s\n"),
- filename,
- emsg);
- GNUNET_free (emsg);
- }
+ {
+ case UNINDEX_STATE_HASHING:
+ uc->fhc = GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE,
+ uc->filename,
+ HASHING_BLOCKSIZE,
+ &GNUNET_FS_unindex_process_hash_, uc);
+ break;
+ case UNINDEX_STATE_FS_NOTIFY:
+ uc->state = UNINDEX_STATE_HASHING;
+ GNUNET_FS_unindex_process_hash_ (uc, &uc->file_id);
+ break;
+ case UNINDEX_STATE_DS_REMOVE:
+ GNUNET_FS_unindex_do_remove_ (uc);
+ break;
+ case UNINDEX_STATE_COMPLETE:
+ case UNINDEX_STATE_ERROR:
+ /* no need to resume any operation, we were done */
+ break;
+ default:
+ break;
+ }
+ if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Failure while resuming unindexing operation `%s': %s\n"),
+ filename, emsg);
+ GNUNET_free (emsg);
+ }
return GNUNET_OK;
- cleanup:
+cleanup:
GNUNET_free_non_null (uc->filename);
- if ( (rh != NULL) &&
- (GNUNET_OK !=
- GNUNET_BIO_read_close (rh, &emsg)) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to resume unindexing operation `%s': %s\n"),
- filename,
- emsg);
- GNUNET_free (emsg);
- }
+ if ((rh != NULL) && (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Failed to resume unindexing operation `%s': %s\n"),
+ filename, emsg);
+ GNUNET_free (emsg);
+ }
if (uc->serialization != NULL)
- GNUNET_FS_remove_sync_file_ (h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX,
uc->serialization);
+ GNUNET_FS_remove_sync_file_ (h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX,
+ uc->serialization);
GNUNET_free_non_null (uc->serialization);
GNUNET_free (uc);
return GNUNET_OK;
@@ -2200,10 +2097,10 @@
*/
static void
deserialize_download (struct GNUNET_FS_Handle *h,
- struct GNUNET_BIO_ReadHandle *rh,
- struct GNUNET_FS_DownloadContext *parent,
- struct GNUNET_FS_SearchResult *search,
- const char *serialization);
+ struct GNUNET_BIO_ReadHandle *rh,
+ struct GNUNET_FS_DownloadContext *parent,
+ struct GNUNET_FS_SearchResult *search,
+ const char *serialization);
/**
@@ -2214,11 +2111,16 @@
* @param psearch_result parent search result
* @param serialization name under which the search was serialized
*/
-static struct GNUNET_FS_SearchContext *
-deserialize_search (struct GNUNET_FS_Handle *h,
- struct GNUNET_BIO_ReadHandle *rh,
- struct GNUNET_FS_SearchResult *psearch_result,
- const char *serialization);
+static struct GNUNET_FS_SearchContext *deserialize_search (struct
+ GNUNET_FS_Handle *h,
+ struct
+
GNUNET_BIO_ReadHandle
+ *rh,
+ struct
+
GNUNET_FS_SearchResult
+ *psearch_result,
+ const char
+ *serialization);
/**
@@ -2230,8 +2132,7 @@
* @return GNUNET_OK (continue to iterate)
*/
static int
-deserialize_search_result (void *cls,
- const char *filename)
+deserialize_search_result (void *cls, const char *filename)
{
struct GNUNET_FS_SearchContext *sc = cls;
char *ser;
@@ -2246,130 +2147,107 @@
ser = get_serialization_short_name (filename);
rh = GNUNET_BIO_read_open (filename);
if (rh == NULL)
+ {
+ if (ser != NULL)
{
- if (ser != NULL)
- {
- remove_sync_file_in_dir (sc->h,
- (sc->psearch_result == NULL)
- ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
- : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
- sc->serialization,
- ser);
- GNUNET_free (ser);
- }
- return GNUNET_OK;
+ remove_sync_file_in_dir (sc->h,
+ (sc->psearch_result == NULL)
+ ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
+ : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
+ sc->serialization, ser);
+ GNUNET_free (ser);
}
+ return GNUNET_OK;
+ }
emsg = NULL;
uris = NULL;
download = NULL;
update_srch = NULL;
sr = GNUNET_malloc (sizeof (struct GNUNET_FS_SearchResult));
- sr->serialization = ser;
- if ( (GNUNET_OK !=
- GNUNET_BIO_read_string (rh, "result-uri", &uris, 10*1024)) ||
- (NULL == (sr->uri = GNUNET_FS_uri_parse (uris, &emsg))) ||
- (GNUNET_OK !=
- GNUNET_BIO_read_string (rh, "download-lnk", &download, 16)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read_string (rh, "search-lnk", &update_srch, 16)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read_meta_data (rh, "result-meta", &sr->meta)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read (rh, "result-key", &sr->key, sizeof (GNUNET_HashCode)))
||
- (GNUNET_OK !=
- GNUNET_BIO_read_int32 (rh, &sr->mandatory_missing)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read_int32 (rh, &sr->optional_support)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read_int32 (rh, &sr->availability_success)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read_int32 (rh, &sr->availability_trials)) )
- {
- GNUNET_break (0);
- goto cleanup;
- }
+ sr->serialization = ser;
+ if ((GNUNET_OK !=
+ GNUNET_BIO_read_string (rh, "result-uri", &uris, 10 * 1024)) ||
+ (NULL == (sr->uri = GNUNET_FS_uri_parse (uris, &emsg))) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_read_string (rh, "download-lnk", &download, 16)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_read_string (rh, "search-lnk", &update_srch, 16)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_read_meta_data (rh, "result-meta", &sr->meta)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_read (rh, "result-key", &sr->key, sizeof (GNUNET_HashCode)))
+ || (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->mandatory_missing)) ||
+ (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->optional_support)) ||
+ (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->availability_success)) ||
+ (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->availability_trials)))
+ {
+ GNUNET_break (0);
+ goto cleanup;
+ }
GNUNET_free (uris);
if (download != NULL)
+ {
+ drh = get_read_handle (sc->h, GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD,
download);
+ if (drh != NULL)
{
- drh = get_read_handle (sc->h,
- GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD,
- download);
- if (drh != NULL)
- {
- deserialize_download (sc->h,
- drh,
- NULL,
- sr,
- download);
- if (GNUNET_OK !=
- GNUNET_BIO_read_close (drh, &emsg))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to resume sub-download `%s': %s\n"),
- download,
- emsg);
- GNUNET_free (emsg);
- }
- }
- GNUNET_free (download);
+ deserialize_download (sc->h, drh, NULL, sr, download);
+ if (GNUNET_OK != GNUNET_BIO_read_close (drh, &emsg))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Failed to resume sub-download `%s': %s\n"),
+ download, emsg);
+ GNUNET_free (emsg);
+ }
}
+ GNUNET_free (download);
+ }
if (update_srch != NULL)
+ {
+ drh = get_read_handle (sc->h,
+ GNUNET_FS_SYNC_PATH_CHILD_SEARCH, update_srch);
+ if (drh != NULL)
{
- drh = get_read_handle (sc->h,
- GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
- update_srch);
- if (drh != NULL)
- {
- deserialize_search (sc->h,
- drh,
- sr,
- update_srch);
- if (GNUNET_OK !=
- GNUNET_BIO_read_close (drh, &emsg))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to resume sub-search `%s': %s\n"),
- update_srch,
- emsg);
- GNUNET_free (emsg);
- }
- }
- GNUNET_free (update_srch);
+ deserialize_search (sc->h, drh, sr, update_srch);
+ if (GNUNET_OK != GNUNET_BIO_read_close (drh, &emsg))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Failed to resume sub-search `%s': %s\n"),
+ update_srch, emsg);
+ GNUNET_free (emsg);
+ }
}
+ GNUNET_free (update_srch);
+ }
GNUNET_CONTAINER_multihashmap_put (sc->master_result_map,
- &sr->key,
- sr,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
- if (GNUNET_OK !=
- GNUNET_BIO_read_close (rh, &emsg))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failure while resuming search operation `%s': %s\n"),
- filename,
- emsg);
- GNUNET_free (emsg);
- }
+ &sr->key,
+ sr,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
+ if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Failure while resuming search operation `%s': %s\n"),
+ filename, emsg);
+ GNUNET_free (emsg);
+ }
return GNUNET_OK;
- cleanup:
+cleanup:
GNUNET_free_non_null (download);
GNUNET_free_non_null (emsg);
GNUNET_free_non_null (uris);
- GNUNET_free_non_null (update_srch);
+ GNUNET_free_non_null (update_srch);
if (sr->uri != NULL)
GNUNET_FS_uri_destroy (sr->uri);
if (sr->meta != NULL)
GNUNET_CONTAINER_meta_data_destroy (sr->meta);
GNUNET_free (sr->serialization);
- GNUNET_free (sr);
- if (GNUNET_OK !=
- GNUNET_BIO_read_close (rh, &emsg))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failure while resuming search operation `%s': %s\n"),
- filename,
- emsg);
- GNUNET_free (emsg);
- }
+ GNUNET_free (sr);
+ if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Failure while resuming search operation `%s': %s\n"),
+ filename, emsg);
+ GNUNET_free (emsg);
+ }
return GNUNET_OK;
}
@@ -2387,18 +2265,17 @@
{
struct GNUNET_FS_DownloadContext *dcc;
struct GNUNET_FS_ProgressInfo pi;
-
+
pi.status = GNUNET_FS_STATUS_DOWNLOAD_RESUME;
pi.value.download.specifics.resume.meta = dc->meta;
pi.value.download.specifics.resume.message = dc->emsg;
- GNUNET_FS_download_make_status_ (&pi,
- dc);
+ GNUNET_FS_download_make_status_ (&pi, dc);
dcc = dc->child_head;
while (NULL != dcc)
- {
- signal_download_resume (dcc);
- dcc = dcc->next;
- }
+ {
+ signal_download_resume (dcc);
+ dcc = dcc->next;
+ }
if (dc->pending_head != NULL)
GNUNET_FS_download_start_downloading_ (dc);
}
@@ -2410,8 +2287,7 @@
*
* @param sc search being resumed
*/
-static void
-signal_search_resume (struct GNUNET_FS_SearchContext *sc);
+static void signal_search_resume (struct GNUNET_FS_SearchContext *sc);
/**
@@ -2424,34 +2300,34 @@
* @return GNUNET_YES (we should continue to iterate)
*/
static int
-signal_result_resume (void *cls,
- const GNUNET_HashCode * key,
- void *value)
+signal_result_resume (void *cls, const GNUNET_HashCode * key, void *value)
{
struct GNUNET_FS_SearchContext *sc = cls;
struct GNUNET_FS_ProgressInfo pi;
struct GNUNET_FS_SearchResult *sr = value;
if (0 == sr->mandatory_missing)
- {
- pi.status = GNUNET_FS_STATUS_SEARCH_RESUME_RESULT;
- pi.value.search.specifics.resume_result.meta = sr->meta;
- pi.value.search.specifics.resume_result.uri = sr->uri;
- pi.value.search.specifics.resume_result.result = sr;
- pi.value.search.specifics.resume_result.availability_rank =
2*sr->availability_success - sr->availability_trials;
- pi.value.search.specifics.resume_result.availability_certainty =
sr->availability_trials;
- pi.value.search.specifics.resume_result.applicability_rank =
sr->optional_support;
- sr->client_info = GNUNET_FS_search_make_status_ (&pi,
- sc);
- }
+ {
+ pi.status = GNUNET_FS_STATUS_SEARCH_RESUME_RESULT;
+ pi.value.search.specifics.resume_result.meta = sr->meta;
+ pi.value.search.specifics.resume_result.uri = sr->uri;
+ pi.value.search.specifics.resume_result.result = sr;
+ pi.value.search.specifics.resume_result.availability_rank =
+ 2 * sr->availability_success - sr->availability_trials;
+ pi.value.search.specifics.resume_result.availability_certainty =
+ sr->availability_trials;
+ pi.value.search.specifics.resume_result.applicability_rank =
+ sr->optional_support;
+ sr->client_info = GNUNET_FS_search_make_status_ (&pi, sc);
+ }
if (sr->download != NULL)
- {
- signal_download_resume (sr->download);
- }
+ {
+ signal_download_resume (sr->download);
+ }
else
- {
- GNUNET_FS_search_start_probe_ (sr);
- }
+ {
+ GNUNET_FS_search_start_probe_ (sr);
+ }
if (sr->update_search != NULL)
signal_search_resume (sr->update_search);
return GNUNET_YES;
@@ -2463,8 +2339,7 @@
*
* @param sc search context to free
*/
-static void
-free_search_context (struct GNUNET_FS_SearchContext *sc);
+static void free_search_context (struct GNUNET_FS_SearchContext *sc);
/**
@@ -2476,17 +2351,15 @@
* @return GNUNET_YES (we should continue to iterate)
*/
static int
-free_result (void *cls,
- const GNUNET_HashCode * key,
- void *value)
+free_result (void *cls, const GNUNET_HashCode * key, void *value)
{
struct GNUNET_FS_SearchResult *sr = value;
if (sr->update_search != NULL)
- {
- free_search_context (sr->update_search);
- GNUNET_assert (NULL == sr->update_search);
- }
+ {
+ free_search_context (sr->update_search);
+ GNUNET_assert (NULL == sr->update_search);
+ }
GNUNET_CONTAINER_meta_data_destroy (sr->meta);
GNUNET_FS_uri_destroy (sr->uri);
GNUNET_free (sr);
@@ -2503,29 +2376,28 @@
free_search_context (struct GNUNET_FS_SearchContext *sc)
{
if (sc->serialization != NULL)
- {
- GNUNET_FS_remove_sync_file_ (sc->h,
- (sc->psearch_result == NULL)
- ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
- : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
- sc->serialization);
- GNUNET_FS_remove_sync_dir_ (sc->h,
- (sc->psearch_result == NULL)
- ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
- : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
- sc->serialization);
- }
+ {
+ GNUNET_FS_remove_sync_file_ (sc->h,
+ (sc->psearch_result == NULL)
+ ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
+ : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
+ sc->serialization);
+ GNUNET_FS_remove_sync_dir_ (sc->h,
+ (sc->psearch_result == NULL)
+ ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
+ : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
+ sc->serialization);
+ }
GNUNET_free_non_null (sc->serialization);
GNUNET_free_non_null (sc->emsg);
if (sc->uri != NULL)
GNUNET_FS_uri_destroy (sc->uri);
if (sc->master_result_map != NULL)
- {
- GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
- &free_result,
- sc);
- GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map);
- }
+ {
+ GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
+ &free_result, sc);
+ GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map);
+ }
GNUNET_free (sc);
}
@@ -2539,8 +2411,7 @@
* @return GNUNET_OK (continue to iterate)
*/
static int
-deserialize_subdownload (void *cls,
- const char *filename)
+deserialize_subdownload (void *cls, const char *filename)
{
struct GNUNET_FS_DownloadContext *parent = cls;
char *ser;
@@ -2550,28 +2421,21 @@
ser = get_serialization_short_name (filename);
rh = GNUNET_BIO_read_open (filename);
if (rh == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to resume sub-download `%s': could not open file
`%s'\n"),
- ser,
- filename);
- GNUNET_free (ser);
- return GNUNET_OK;
- }
- deserialize_download (parent->h,
- rh,
- parent,
- NULL,
- ser);
- if (GNUNET_OK !=
- GNUNET_BIO_read_close (rh, &emsg))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to resume sub-download `%s': %s\n"),
- ser,
- emsg);
- GNUNET_free (emsg);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Failed to resume sub-download `%s': could not open file
`%s'\n"),
+ ser, filename);
+ GNUNET_free (ser);
+ return GNUNET_OK;
+ }
+ deserialize_download (parent->h, rh, parent, NULL, ser);
+ if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Failed to resume sub-download `%s': %s\n"), ser, emsg);
+ GNUNET_free (emsg);
+ }
GNUNET_free (ser);
return GNUNET_OK;
}
@@ -2598,15 +2462,13 @@
GNUNET_free_non_null (dc->filename);
GNUNET_free_non_null (dc->serialization);
while (NULL != (dcc = dc->child_head))
- {
- GNUNET_CONTAINER_DLL_remove (dc->child_head,
- dc->child_tail,
- dcc);
- free_download_context (dcc);
- }
+ {
+ GNUNET_CONTAINER_DLL_remove (dc->child_head, dc->child_tail, dcc);
+ free_download_context (dcc);
+ }
GNUNET_FS_free_download_request_ (dc->top_request);
- if (NULL != dc->active)
- GNUNET_CONTAINER_multihashmap_destroy (dc->active);
+ if (NULL != dc->active)
+ GNUNET_CONTAINER_multihashmap_destroy (dc->active);
GNUNET_free (dc);
}
@@ -2622,10 +2484,10 @@
*/
static void
deserialize_download (struct GNUNET_FS_Handle *h,
- struct GNUNET_BIO_ReadHandle *rh,
- struct GNUNET_FS_DownloadContext *parent,
- struct GNUNET_FS_SearchResult *search,
- const char *serialization)
+ struct GNUNET_BIO_ReadHandle *rh,
+ struct GNUNET_FS_DownloadContext *parent,
+ struct GNUNET_FS_SearchResult *search,
+ const char *serialization)
{
struct GNUNET_FS_DownloadContext *dc;
char *emsg;
@@ -2640,89 +2502,77 @@
dc->parent = parent;
dc->h = h;
dc->serialization = GNUNET_strdup (serialization);
- if ( (GNUNET_OK !=
- GNUNET_BIO_read_string (rh, "download-uri", &uris, 10*1024)) ||
- (NULL == (dc->uri = GNUNET_FS_uri_parse (uris, &emsg))) ||
- ( (GNUNET_YES != GNUNET_FS_uri_test_chk (dc->uri)) &&
- (GNUNET_YES != GNUNET_FS_uri_test_loc (dc->uri)) ) ||
- (GNUNET_OK !=
- GNUNET_BIO_read_meta_data (rh, "download-meta", &dc->meta)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read_string (rh, "download-emsg", &dc->emsg, 10*1024)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read_string (rh, "download-fn", &dc->filename, 10*1024)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read_string (rh, "download-tfn", &dc->temp_filename,
10*1024)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read_int64 (rh, &dc->old_file_size)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read_int64 (rh, &dc->offset)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read_int64 (rh, &dc->length)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read_int64 (rh, &dc->completed)) ||
- (GNUNET_OK !=
- read_start_time (rh, &dc->start_time)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read_int32 (rh, &dc->anonymity)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read_int32 (rh, &options)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read_int32 (rh, &status)) )
- {
- GNUNET_break (0);
- goto cleanup;
- }
+ if ((GNUNET_OK !=
+ GNUNET_BIO_read_string (rh, "download-uri", &uris, 10 * 1024)) ||
+ (NULL == (dc->uri = GNUNET_FS_uri_parse (uris, &emsg))) ||
+ ((GNUNET_YES != GNUNET_FS_uri_test_chk (dc->uri)) &&
+ (GNUNET_YES != GNUNET_FS_uri_test_loc (dc->uri))) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_read_meta_data (rh, "download-meta", &dc->meta)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_read_string (rh, "download-emsg", &dc->emsg, 10 * 1024)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_read_string (rh, "download-fn", &dc->filename, 10 * 1024)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_read_string (rh, "download-tfn", &dc->temp_filename,
+ 10 * 1024)) ||
+ (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->old_file_size)) ||
+ (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->offset)) ||
+ (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->length)) ||
+ (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->completed)) ||
+ (GNUNET_OK != read_start_time (rh, &dc->start_time)) ||
+ (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dc->anonymity)) ||
+ (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &options)) ||
+ (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &status)))
+ {
+ GNUNET_break (0);
+ goto cleanup;
+ }
dc->options = (enum GNUNET_FS_DownloadOptions) options;
- dc->active = GNUNET_CONTAINER_multihashmap_create (1 + 2 * (dc->length /
DBLOCK_SIZE));
+ dc->active =
+ GNUNET_CONTAINER_multihashmap_create (1 + 2 * (dc->length /
DBLOCK_SIZE));
dc->has_finished = (int) status;
- dc->treedepth = GNUNET_FS_compute_depth (GNUNET_FS_uri_chk_get_file_size
(dc->uri));
+ dc->treedepth =
+ GNUNET_FS_compute_depth (GNUNET_FS_uri_chk_get_file_size (dc->uri));
if (GNUNET_FS_uri_test_loc (dc->uri))
GNUNET_assert (GNUNET_OK ==
- GNUNET_FS_uri_loc_get_peer_identity (dc->uri,
- &dc->target));
+ GNUNET_FS_uri_loc_get_peer_identity (dc->uri, &dc->target));
if (dc->emsg == NULL)
+ {
+ dc->top_request = read_download_request (rh);
+ if (dc->top_request == NULL)
{
- dc->top_request = read_download_request (rh);
- if (dc->top_request == NULL)
- {
- GNUNET_break (0);
- goto cleanup;
- }
+ GNUNET_break (0);
+ goto cleanup;
}
+ }
dn = get_download_sync_filename (dc, dc->serialization, ".dir");
if (dn != NULL)
- {
- if (GNUNET_YES ==
- GNUNET_DISK_directory_test (dn))
- GNUNET_DISK_directory_scan (dn, &deserialize_subdownload, dc);
- GNUNET_free (dn);
- }
+ {
+ if (GNUNET_YES == GNUNET_DISK_directory_test (dn))
+ GNUNET_DISK_directory_scan (dn, &deserialize_subdownload, dc);
+ GNUNET_free (dn);
+ }
if (parent != NULL)
- {
- abort (); // for debugging for now
- GNUNET_CONTAINER_DLL_insert (parent->child_head,
- parent->child_tail,
- dc);
- }
+ {
+ abort (); // for debugging for now
+ GNUNET_CONTAINER_DLL_insert (parent->child_head, parent->child_tail, dc);
+ }
if (search != NULL)
- {
- dc->search = search;
- search->download = dc;
- }
- if ( (parent == NULL) &&
- (search == NULL) )
- {
- dc->top = GNUNET_FS_make_top (dc->h,
- &GNUNET_FS_download_signal_suspend_,
- dc);
- signal_download_resume (dc);
- }
+ {
+ dc->search = search;
+ search->download = dc;
+ }
+ if ((parent == NULL) && (search == NULL))
+ {
+ dc->top = GNUNET_FS_make_top (dc->h,
+ &GNUNET_FS_download_signal_suspend_, dc);
+ signal_download_resume (dc);
+ }
GNUNET_free (uris);
- dc->task
- = GNUNET_SCHEDULER_add_now (&GNUNET_FS_download_start_task_, dc);
+ dc->task = GNUNET_SCHEDULER_add_now (&GNUNET_FS_download_start_task_, dc);
return;
- cleanup:
+cleanup:
GNUNET_free_non_null (uris);
GNUNET_free_non_null (emsg);
free_download_context (dc);
@@ -2742,12 +2592,11 @@
pi.status = GNUNET_FS_STATUS_SEARCH_RESUME;
pi.value.search.specifics.resume.message = sc->emsg;
- pi.value.search.specifics.resume.is_paused = (sc->client == NULL) ?
GNUNET_YES : GNUNET_NO;
- sc->client_info = GNUNET_FS_search_make_status_ (&pi,
- sc);
+ pi.value.search.specifics.resume.is_paused =
+ (sc->client == NULL) ? GNUNET_YES : GNUNET_NO;
+ sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc);
GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
- &signal_result_resume,
- sc);
+ &signal_result_resume, sc);
}
@@ -2762,9 +2611,9 @@
*/
static struct GNUNET_FS_SearchContext *
deserialize_search (struct GNUNET_FS_Handle *h,
- struct GNUNET_BIO_ReadHandle *rh,
- struct GNUNET_FS_SearchResult *psearch_result,
- const char *serialization)
+ struct GNUNET_BIO_ReadHandle *rh,
+ struct GNUNET_FS_SearchResult *psearch_result,
+ const char *serialization)
{
struct GNUNET_FS_SearchContext *sc;
char *emsg;
@@ -2773,67 +2622,63 @@
uint32_t options;
char in_pause;
- if ( (psearch_result != NULL) &&
- (psearch_result->update_search != NULL) )
- {
- GNUNET_break (0);
- return NULL;
- }
+ if ((psearch_result != NULL) && (psearch_result->update_search != NULL))
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
uris = NULL;
emsg = NULL;
sc = GNUNET_malloc (sizeof (struct GNUNET_FS_SearchContext));
if (psearch_result != NULL)
- {
- sc->psearch_result = psearch_result;
- psearch_result->update_search = sc;
- }
+ {
+ sc->psearch_result = psearch_result;
+ psearch_result->update_search = sc;
+ }
sc->h = h;
sc->serialization = GNUNET_strdup (serialization);
- if ( (GNUNET_OK !=
- GNUNET_BIO_read_string (rh, "search-uri", &uris, 10*1024)) ||
- (NULL == (sc->uri = GNUNET_FS_uri_parse (uris, &emsg))) ||
- ( (GNUNET_YES != GNUNET_FS_uri_test_ksk (sc->uri)) &&
- (GNUNET_YES != GNUNET_FS_uri_test_sks (sc->uri)) ) ||
- (GNUNET_OK !=
- read_start_time (rh, &sc->start_time)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read_string (rh, "search-emsg", &sc->emsg, 10*1024)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read_int32 (rh, &options)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read (rh, "search-pause", &in_pause, sizeof (in_pause))) ||
- (GNUNET_OK !=
- GNUNET_BIO_read_int32 (rh, &sc->anonymity)) )
- {
- GNUNET_break (0);
- goto cleanup;
- }
+ if ((GNUNET_OK !=
+ GNUNET_BIO_read_string (rh, "search-uri", &uris, 10 * 1024)) ||
+ (NULL == (sc->uri = GNUNET_FS_uri_parse (uris, &emsg))) ||
+ ((GNUNET_YES != GNUNET_FS_uri_test_ksk (sc->uri)) &&
+ (GNUNET_YES != GNUNET_FS_uri_test_sks (sc->uri))) ||
+ (GNUNET_OK !=
+ read_start_time (rh, &sc->start_time)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_read_string (rh, "search-emsg", &sc->emsg, 10 * 1024)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_read_int32 (rh, &options)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_read (rh, "search-pause", &in_pause, sizeof (in_pause))) ||
+ (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sc->anonymity)))
+ {
+ GNUNET_break (0);
+ goto cleanup;
+ }
sc->options = (enum GNUNET_FS_SearchOptions) options;
sc->master_result_map = GNUNET_CONTAINER_multihashmap_create (16);
dn = get_serialization_file_name_in_dir (h,
- (sc->psearch_result == NULL)
- ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
- : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
- sc->serialization,
- "");
+ (sc->psearch_result == NULL)
+ ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
+ : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
+ sc->serialization, "");
if (dn != NULL)
- {
- if (GNUNET_YES ==
- GNUNET_DISK_directory_test (dn))
- GNUNET_DISK_directory_scan (dn, &deserialize_search_result, sc);
- GNUNET_free (dn);
- }
- if ( ('\0' == in_pause) &&
- (GNUNET_OK !=
- GNUNET_FS_search_start_searching_ (sc)) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Could not resume running search, will resume as paused
search\n"));
- }
+ {
+ if (GNUNET_YES == GNUNET_DISK_directory_test (dn))
+ GNUNET_DISK_directory_scan (dn, &deserialize_search_result, sc);
+ GNUNET_free (dn);
+ }
+ if (('\0' == in_pause) &&
+ (GNUNET_OK != GNUNET_FS_search_start_searching_ (sc)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Could not resume running search, will resume as paused
search\n"));
+ }
signal_search_resume (sc);
GNUNET_free (uris);
return sc;
- cleanup:
+cleanup:
GNUNET_free_non_null (emsg);
free_search_context (sc);
GNUNET_free_non_null (uris);
@@ -2850,8 +2695,7 @@
* @return GNUNET_OK (continue to iterate)
*/
static int
-deserialize_search_file (void *cls,
- const char *filename)
+deserialize_search_file (void *cls, const char *filename)
{
struct GNUNET_FS_Handle *h = cls;
char *ser;
@@ -2862,27 +2706,25 @@
ser = get_serialization_short_name (filename);
rh = GNUNET_BIO_read_open (filename);
if (rh == NULL)
+ {
+ if (ser != NULL)
{
- if (ser != NULL)
- {
- GNUNET_FS_remove_sync_file_ (h, GNUNET_FS_SYNC_PATH_MASTER_SEARCH,
ser);
- GNUNET_free (ser);
- }
- return GNUNET_OK;
+ GNUNET_FS_remove_sync_file_ (h, GNUNET_FS_SYNC_PATH_MASTER_SEARCH, ser);
+ GNUNET_free (ser);
}
+ return GNUNET_OK;
+ }
sc = deserialize_search (h, rh, NULL, ser);
if (sc != NULL)
sc->top = GNUNET_FS_make_top (h, &GNUNET_FS_search_signal_suspend_, sc);
GNUNET_free (ser);
- if (GNUNET_OK !=
- GNUNET_BIO_read_close (rh, &emsg))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failure while resuming search operation `%s': %s\n"),
- filename,
- emsg);
- GNUNET_free (emsg);
- }
+ if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Failure while resuming search operation `%s': %s\n"),
+ filename, emsg);
+ GNUNET_free (emsg);
+ }
return GNUNET_OK;
}
@@ -2896,8 +2738,7 @@
* @return GNUNET_OK (continue to iterate)
*/
static int
-deserialize_download_file (void *cls,
- const char *filename)
+deserialize_download_file (void *cls, const char *filename)
{
struct GNUNET_FS_Handle *h = cls;
char *ser;
@@ -2907,25 +2748,21 @@
ser = get_serialization_short_name (filename);
rh = GNUNET_BIO_read_open (filename);
if (rh == NULL)
- {
- if (0 != UNLINK (filename))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
- "unlink",
- filename);
- GNUNET_free (ser);
- return GNUNET_OK;
- }
+ {
+ if (0 != UNLINK (filename))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename);
+ GNUNET_free (ser);
+ return GNUNET_OK;
+ }
deserialize_download (h, rh, NULL, NULL, ser);
GNUNET_free (ser);
- if (GNUNET_OK !=
- GNUNET_BIO_read_close (rh, &emsg))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failure while resuming download operation `%s': %s\n"),
- filename,
- emsg);
- GNUNET_free (emsg);
- }
+ if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Failure while resuming download operation `%s': %s\n"),
+ filename, emsg);
+ GNUNET_free (emsg);
+ }
return GNUNET_OK;
}
@@ -2939,18 +2776,17 @@
*/
static void
deserialization_master (const char *master_path,
- GNUNET_FileNameCallback proc,
- struct GNUNET_FS_Handle *h)
+ GNUNET_FileNameCallback proc,
+ struct GNUNET_FS_Handle *h)
{
char *dn;
dn = get_serialization_file_name (h, master_path, "");
if (dn == NULL)
return;
- if (GNUNET_YES ==
- GNUNET_DISK_directory_test (dn))
+ if (GNUNET_YES == GNUNET_DISK_directory_test (dn))
GNUNET_DISK_directory_scan (dn, proc, h);
- GNUNET_free (dn);
+ GNUNET_free (dn);
}
@@ -2967,11 +2803,9 @@
*/
struct GNUNET_FS_Handle *
GNUNET_FS_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *client_name,
- GNUNET_FS_ProgressCallback upcb,
- void *upcb_cls,
- enum GNUNET_FS_Flags flags,
- ...)
+ const char *client_name,
+ GNUNET_FS_ProgressCallback upcb,
+ void *upcb_cls, enum GNUNET_FS_Flags flags, ...)
{
struct GNUNET_FS_Handle *ret;
enum GNUNET_FS_OPTIONS opt;
@@ -2985,42 +2819,40 @@
ret->flags = flags;
ret->max_parallel_downloads = 1;
ret->max_parallel_requests = 1;
- ret->avg_block_latency = GNUNET_TIME_UNIT_MINUTES; /* conservative starting
point */
- va_start (ap, flags);
+ ret->avg_block_latency = GNUNET_TIME_UNIT_MINUTES; /* conservative
starting point */
+ va_start (ap, flags);
while (GNUNET_FS_OPTIONS_END != (opt = va_arg (ap, enum GNUNET_FS_OPTIONS)))
+ {
+ switch (opt)
{
- switch (opt)
- {
- case GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM:
- ret->max_parallel_downloads = va_arg (ap, unsigned int);
- break;
- case GNUNET_FS_OPTIONS_REQUEST_PARALLELISM:
- ret->max_parallel_requests = va_arg (ap, unsigned int);
- break;
- default:
- GNUNET_break (0);
- GNUNET_free (ret->client_name);
- GNUNET_free (ret);
- va_end (ap);
- return NULL;
- }
+ case GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM:
+ ret->max_parallel_downloads = va_arg (ap, unsigned int);
+
+ break;
+ case GNUNET_FS_OPTIONS_REQUEST_PARALLELISM:
+ ret->max_parallel_requests = va_arg (ap, unsigned int);
+
+ break;
+ default:
+ GNUNET_break (0);
+ GNUNET_free (ret->client_name);
+ GNUNET_free (ret);
+ va_end (ap);
+ return NULL;
}
+ }
va_end (ap);
if (0 != (GNUNET_FS_FLAGS_PERSISTENCE & flags))
- {
- deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_PUBLISH,
- &deserialize_publish_file,
- ret);
- deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_SEARCH,
- &deserialize_search_file,
- ret);
- deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD,
- &deserialize_download_file,
- ret);
- deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_UNINDEX,
- &deserialize_unindex_file,
- ret);
- }
+ {
+ deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_PUBLISH,
+ &deserialize_publish_file, ret);
+ deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_SEARCH,
+ &deserialize_search_file, ret);
+ deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD,
+ &deserialize_download_file, ret);
+ deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_UNINDEX,
+ &deserialize_unindex_file, ret);
+ }
return ret;
}
@@ -3031,8 +2863,8 @@
* called after this function returns.
*
* @param h handle that was returned from GNUNET_FS_start
- */
-void
+ */
+void
GNUNET_FS_stop (struct GNUNET_FS_Handle *h)
{
while (h->top_head != NULL)
Modified: gnunet/src/fs/fs.h
===================================================================
--- gnunet/src/fs/fs.h 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/fs/fs.h 2011-08-15 21:46:35 UTC (rev 16581)
@@ -240,7 +240,7 @@
/**
* @brief content hash key
*/
-struct ContentHashKey
+struct ContentHashKey
{
/**
* Hash of the original content, used for encryption.
@@ -307,27 +307,27 @@
* Types of URIs.
*/
enum uri_types
- {
+{
/**
* Content-hash-key (simple file).
*/
- chk,
+ chk,
/**
* Signed key space (file in namespace).
*/
- sks,
+ sks,
/**
* Keyword search key (query with keywords).
*/
- ksk,
+ ksk,
/**
* Location (chk with identity of hosting peer).
*/
- loc
- };
+ loc
+};
/**
* A Universal Resource Identifier (URI), opaque.
@@ -356,7 +356,7 @@
* (only in URI-strings).
*/
char **keywords;
-
+
/**
* Size of the keywords array.
*/
@@ -453,7 +453,7 @@
* using 'mktemp'.
*/
char *serialization;
-
+
/**
* Encoder being used to publish this file.
*/
@@ -478,7 +478,8 @@
/**
* Data for a file.
*/
- struct {
+ struct
+ {
/**
* Function that can be used to read the data for the file.
@@ -524,8 +525,9 @@
/**
* Data for a directory.
*/
- struct {
-
+ struct
+ {
+
/**
* Linked list of entries in the directory.
*/
@@ -567,15 +569,15 @@
* @param cls closure
* @param client handle to use for FS communication
*/
-typedef void (*GNUNET_FS_QueueStart)(void *cls,
- struct GNUNET_CLIENT_Connection *client);
+typedef void (*GNUNET_FS_QueueStart) (void *cls,
+ struct GNUNET_CLIENT_Connection *
client);
/**
* The job must now stop to run and should destry the client handle as
* soon as possible (ideally prior to returning).
*/
-typedef void (*GNUNET_FS_QueueStop)(void *cls);
+typedef void (*GNUNET_FS_QueueStop) (void *cls);
/**
@@ -610,7 +612,7 @@
/**
* Handle to FS primary context.
- */
+ */
struct GNUNET_FS_Handle *h;
/**
@@ -757,20 +759,17 @@
* @param blocks number of blocks this download has
* @return queue handle
*/
-struct GNUNET_FS_QueueEntry *
-GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h,
- GNUNET_FS_QueueStart start,
- GNUNET_FS_QueueStop stop,
- void *cls,
- unsigned int blocks);
+struct GNUNET_FS_QueueEntry *GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h,
+ GNUNET_FS_QueueStart start,
+ GNUNET_FS_QueueStop stop,
+ void *cls, unsigned int blocks);
/**
* Dequeue a job from the queue.
* @param qh handle for the job
*/
-void
-GNUNET_FS_dequeue_ (struct GNUNET_FS_QueueEntry *qh);
+void GNUNET_FS_dequeue_ (struct GNUNET_FS_QueueEntry *qh);
/**
@@ -790,11 +789,16 @@
* @return number of bytes written, usually "max", 0 on error
*/
size_t
-GNUNET_FS_data_reader_file_(void *cls,
- uint64_t offset,
- size_t max,
- void *buf,
- char **emsg);
+
+
+
+
+
+
+
+GNUNET_FS_data_reader_file_ (void *cls,
+ uint64_t offset,
+ size_t max, void *buf, char **emsg);
/**
@@ -803,8 +807,7 @@
* @param filename file to read
* @return closure to use
*/
-void *
-GNUNET_FS_make_file_reader_context_ (const char *filename);
+void *GNUNET_FS_make_file_reader_context_ (const char *filename);
@@ -825,11 +828,9 @@
* @return number of bytes written, usually "max", 0 on error
*/
size_t
-GNUNET_FS_data_reader_copy_(void *cls,
- uint64_t offset,
- size_t max,
- void *buf,
- char **emsg);
+GNUNET_FS_data_reader_copy_ (void *cls,
+ uint64_t offset,
+ size_t max, void *buf, char **emsg);
/**
* Notification of FS that a search probe has made progress.
@@ -846,9 +847,9 @@
* will be passed to future callbacks in the respective
* field in the GNUNET_FS_ProgressInfo struct.
*/
-void*
-GNUNET_FS_search_probe_progress_ (void *cls,
- const struct GNUNET_FS_ProgressInfo *info);
+void *GNUNET_FS_search_probe_progress_ (void *cls,
+ const struct GNUNET_FS_ProgressInfo
+ *info);
/**
@@ -859,7 +860,7 @@
*/
void
GNUNET_FS_publish_main_ (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+ const struct GNUNET_SCHEDULER_TaskContext *tc);
/**
@@ -869,9 +870,8 @@
* @param cls closure, unindex context
* @param file_id computed hash, NULL on error
*/
-void
-GNUNET_FS_unindex_process_hash_ (void *cls,
- const GNUNET_HashCode *file_id);
+void
+GNUNET_FS_unindex_process_hash_ (void *cls, const GNUNET_HashCode * file_id);
/**
@@ -884,11 +884,10 @@
* @param offset where in the file are we so far
* @return value returned from callback
*/
-void *
-GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
- struct GNUNET_FS_PublishContext *sc,
- const struct GNUNET_FS_FileInformation *p,
- uint64_t offset);
+void *GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
+ struct GNUNET_FS_PublishContext *sc,
+ const struct GNUNET_FS_FileInformation
*p,
+ uint64_t offset);
/**
@@ -900,7 +899,7 @@
*/
void
GNUNET_FS_download_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
- struct GNUNET_FS_DownloadContext *dc);
+ struct GNUNET_FS_DownloadContext *dc);
/**
@@ -912,7 +911,7 @@
*/
void
GNUNET_FS_download_start_task_ (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+ const struct GNUNET_SCHEDULER_TaskContext *tc);
@@ -926,8 +925,8 @@
*/
void
GNUNET_FS_unindex_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
- struct GNUNET_FS_UnindexContext *uc,
- uint64_t offset);
+ struct GNUNET_FS_UnindexContext *uc,
+ uint64_t offset);
/**
* Fill in all of the generic fields for a search event and
@@ -937,9 +936,8 @@
* @param sc overall search context
* @return value returned by the callback
*/
-void *
-GNUNET_FS_search_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
- struct GNUNET_FS_SearchContext *sc);
+void *GNUNET_FS_search_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
+ struct GNUNET_FS_SearchContext *sc);
/**
@@ -947,8 +945,7 @@
*
* @param uc context for the unindex operation.
*/
-void
-GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc);
+void GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc);
/**
* Build the request and actually initiate the search using the
@@ -957,8 +954,7 @@
* @param sc search context
* @return GNUNET_OK on success, GNUNET_SYSERR on error
*/
-int
-GNUNET_FS_search_start_searching_ (struct GNUNET_FS_SearchContext *sc);
+int GNUNET_FS_search_start_searching_ (struct GNUNET_FS_SearchContext *sc);
/**
* Start the downloading process (by entering the queue).
@@ -974,8 +970,7 @@
*
* @param sr the search result
*/
-void
-GNUNET_FS_search_start_probe_ (struct GNUNET_FS_SearchResult *sr);
+void GNUNET_FS_search_start_probe_ (struct GNUNET_FS_SearchResult *sr);
/**
* Remove serialization/deserialization file from disk.
@@ -986,8 +981,7 @@
*/
void
GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h,
- const char *ext,
- const char *ent);
+ const char *ext, const char *ent);
/**
@@ -999,8 +993,7 @@
*/
void
GNUNET_FS_remove_sync_dir_ (struct GNUNET_FS_Handle *h,
- const char *ext,
- const char *uni);
+ const char *ext, const char *uni);
/**
@@ -1011,8 +1004,7 @@
*
* @param fi the struct to sync
*/
-void
-GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *f);
+void GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *f);
/**
* Synchronize this publishing struct with its mirror
@@ -1022,8 +1014,7 @@
*
* @param pc the struct to sync
*/
-void
-GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc);
+void GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc);
/**
* Synchronize this unindex struct with its mirror
@@ -1033,8 +1024,7 @@
*
* @param uc the struct to sync
*/
-void
-GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc);
+void GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc);
/**
* Synchronize this search struct with its mirror
@@ -1044,8 +1034,7 @@
*
* @param sc the struct to sync
*/
-void
-GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc);
+void GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc);
/**
* Synchronize this search result with its mirror
@@ -1055,8 +1044,7 @@
*
* @param sr the struct to sync
*/
-void
-GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr);
+void GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr);
/**
* Synchronize this download struct with its mirror
@@ -1066,8 +1054,7 @@
*
* @param dc the struct to sync
*/
-void
-GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc);
+void GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc);
/**
* Create SUSPEND event for the given publish operation
@@ -1075,8 +1062,7 @@
*
* @param cls the 'struct GNUNET_FS_PublishContext' to signal for
*/
-void
-GNUNET_FS_publish_signal_suspend_ (void *cls);
+void GNUNET_FS_publish_signal_suspend_ (void *cls);
/**
* Create SUSPEND event for the given search operation
@@ -1084,8 +1070,7 @@
*
* @param cls the 'struct GNUNET_FS_SearchContext' to signal for
*/
-void
-GNUNET_FS_search_signal_suspend_ (void *cls);
+void GNUNET_FS_search_signal_suspend_ (void *cls);
/**
* Create SUSPEND event for the given download operation
@@ -1093,8 +1078,7 @@
*
* @param cls the 'struct GNUNET_FS_DownloadContext' to signal for
*/
-void
-GNUNET_FS_download_signal_suspend_ (void *cls);
+void GNUNET_FS_download_signal_suspend_ (void *cls);
/**
* Create SUSPEND event for the given unindex operation
@@ -1102,8 +1086,7 @@
*
* @param cls the 'struct GNUNET_FS_UnindexContext' to signal for
*/
-void
-GNUNET_FS_unindex_signal_suspend_ (void *cls);
+void GNUNET_FS_unindex_signal_suspend_ (void *cls);
/**
* Function signature of the functions that can be called
@@ -1112,7 +1095,7 @@
*
* @param cls closure
*/
-typedef void (*SuspendSignalFunction)(void *cls);
+typedef void (*SuspendSignalFunction) (void *cls);
/**
* We track all of the top-level activities of FS
@@ -1122,12 +1105,12 @@
{
/**
* This is a doubly-linked list.
- */
+ */
struct TopLevelActivity *next;
/**
* This is a doubly-linked list.
- */
+ */
struct TopLevelActivity *prev;
/**
@@ -1150,10 +1133,9 @@
* @param ssf_cls closure for ssf
* @return fresh top-level activity handle
*/
-struct TopLevelActivity *
-GNUNET_FS_make_top (struct GNUNET_FS_Handle *h,
- SuspendSignalFunction ssf,
- void *ssf_cls);
+struct TopLevelActivity *GNUNET_FS_make_top (struct GNUNET_FS_Handle *h,
+ SuspendSignalFunction ssf,
+ void *ssf_cls);
/**
@@ -1163,8 +1145,7 @@
* @param top top level activity entry
*/
void
-GNUNET_FS_end_top (struct GNUNET_FS_Handle *h,
- struct TopLevelActivity *top);
+GNUNET_FS_end_top (struct GNUNET_FS_Handle *h, struct TopLevelActivity *top);
@@ -1270,7 +1251,7 @@
{
/**
* Handle to the global fs context.
- */
+ */
struct GNUNET_FS_Handle *h;
/**
@@ -1378,45 +1359,44 @@
/**
* Phases of unindex processing (state machine).
- */
+ */
enum UnindexState
- {
+{
/**
* We're currently hashing the file.
*/
- UNINDEX_STATE_HASHING = 0,
+ UNINDEX_STATE_HASHING = 0,
/**
* We're telling the datastore to delete
* the respective entries.
*/
- UNINDEX_STATE_DS_REMOVE = 1,
+ UNINDEX_STATE_DS_REMOVE = 1,
/**
* We're notifying the FS service about
* the unindexing.
*/
- UNINDEX_STATE_FS_NOTIFY = 2,
+ UNINDEX_STATE_FS_NOTIFY = 2,
/**
* We're done.
*/
- UNINDEX_STATE_COMPLETE = 3,
+ UNINDEX_STATE_COMPLETE = 3,
/**
* We've encountered a fatal error.
*/
- UNINDEX_STATE_ERROR = 4
+ UNINDEX_STATE_ERROR = 4
+};
- };
-
/**
* Handle for controlling an unindexing operation.
*/
struct GNUNET_FS_UnindexContext
{
-
+
/**
* Global FS context.
*/
@@ -1476,7 +1456,7 @@
/**
* Overall size of the file.
- */
+ */
uint64_t file_size;
/**
@@ -1488,11 +1468,11 @@
* Hash of the file's contents (once computed).
*/
GNUNET_HashCode file_id;
-
+
/**
* Current operatinonal phase.
*/
- enum UnindexState state;
+ enum UnindexState state;
};
@@ -1512,7 +1492,7 @@
/**
* Hash of the public key, also known as the query.
*/
- GNUNET_HashCode query;
+ GNUNET_HashCode query;
/**
* Map that contains a "struct GNUNET_FS_SearchResult" for each result that
@@ -1592,7 +1572,7 @@
* have exactly as many entries as there were keywords.
*/
struct SearchRequestEntry *requests;
-
+
/**
* When did we start?
*/
@@ -1617,7 +1597,7 @@
* map have been passed to the service so far?
*/
unsigned int keyword_offset;
-
+
/**
* Anonymity level for the search.
*/
@@ -1631,7 +1611,7 @@
/**
* Options for the search.
*/
- enum GNUNET_FS_SearchOptions options;
+ enum GNUNET_FS_SearchOptions options;
};
@@ -1641,12 +1621,12 @@
* are documented in the comments.
*/
enum BlockRequestState
- {
+{
/**
* Initial state, block has only been allocated (since it is
* relevant to the overall download request).
*/
- BRS_INIT = 0,
+ BRS_INIT = 0,
/**
* We've checked the block on the path down the tree, and the
@@ -1654,7 +1634,7 @@
* the way down, so at the bottom some blocks will still
* need to be reconstructed).
*/
- BRS_RECONSTRUCT_DOWN = 1,
+ BRS_RECONSTRUCT_DOWN = 1,
/**
* We've calculated the CHK bottom-up based on the meta data.
@@ -1662,7 +1642,7 @@
* disk at the end (and we still need to check against the
* CHK set on top).
*/
- BRS_RECONSTRUCT_META_UP = 2,
+ BRS_RECONSTRUCT_META_UP = 2,
/**
* We've calculated the CHK bottom-up based on what we have on
@@ -1670,7 +1650,7 @@
* reconstructed CHKs match whatever comes from above, we're
* done with the respective subtree.
*/
- BRS_RECONSTRUCT_UP = 3,
+ BRS_RECONSTRUCT_UP = 3,
/**
* We've determined the real, desired CHK for this block
@@ -1679,7 +1659,7 @@
* the top-level request, the state machine for the subtree
* would have moved to BRS_DOWNLOAD_UP.
*/
- BRS_CHK_SET = 4,
+ BRS_CHK_SET = 4,
/**
* We've successfully downloaded this block, but the children
@@ -1688,27 +1668,26 @@
* state machine for this block may move to
* BRS_DOWNLOAD_ERROR instead.
*/
- BRS_DOWNLOAD_DOWN = 5,
+ BRS_DOWNLOAD_DOWN = 5,
/**
* This block and all of its children have been downloaded
* successfully (full completion propagates up).
*/
- BRS_DOWNLOAD_UP = 6,
+ BRS_DOWNLOAD_UP = 6,
/**
* We got a block back that matched the query but did not hash to
* the key (malicious publisher or hash collision); this block
* can never be downloaded (error propagates up).
*/
- BRS_ERROR = 7
-
- };
+ BRS_ERROR = 7
+};
/**
* Information about an active download request.
- */
+ */
struct DownloadRequest
{
/**
@@ -1735,7 +1714,7 @@
* CHK for the request for this block (set during reconstruction
* to what we have on disk, later to what we want to have).
*/
- struct ContentHashKey chk;
+ struct ContentHashKey chk;
/**
* Offset of the corresponding block. Specifically, first (!) byte of
@@ -1772,8 +1751,7 @@
*
* @param dr request to free
*/
-void
-GNUNET_FS_free_download_request_ (struct DownloadRequest *dr);
+void GNUNET_FS_free_download_request_ (struct DownloadRequest *dr);
/**
@@ -1781,17 +1759,17 @@
*/
struct GNUNET_FS_DownloadContext
{
-
+
/**
* Global FS context.
- */
+ */
struct GNUNET_FS_Handle *h;
/**
* Our top-level activity entry (if we are top-level, otherwise NULL).
*/
struct TopLevelActivity *top;
-
+
/**
* Connection to the FS service.
*/
@@ -2019,7 +1997,7 @@
* freshness of the tree_id.
*/
unsigned int nug;
-
+
/**
* TREE this entry belongs to (if nug is current).
*/
@@ -2035,7 +2013,7 @@
* Handle to the FS service context.
*/
struct GNUNET_FS_Handle *h;
-
+
/**
* Array with information about nodes in the namespace.
*/
@@ -2059,7 +2037,7 @@
/**
* Name of the namespace.
- */
+ */
char *name;
/**
@@ -2113,7 +2091,7 @@
* full hash recomputation.
*/
uint64_t device GNUNET_PACKED;
-
+
/**
* Inode of the file on the given device, as seen by the client
* ("st_ino" field from "struct stat"). Use 0 if the OS does not
@@ -2128,8 +2106,8 @@
GNUNET_HashCode file_id;
/* this is followed by a 0-terminated
- filename of a file with the hash
- "file_id" as seen by the client */
+ * filename of a file with the hash
+ * "file_id" as seen by the client */
};
@@ -2157,9 +2135,9 @@
GNUNET_HashCode file_id;
/* this is followed by a 0-terminated
- filename of a file with the hash
- "file_id" as seen by the client */
-
+ * filename of a file with the hash
+ * "file_id" as seen by the client */
+
};
@@ -2245,10 +2223,10 @@
GNUNET_HashCode query;
/* this is followed by the hash codes of already-known
- results (which should hence be excluded from what
- the service returns); naturally, this only applies
- to queries that can have multiple results, such as
- those for KBLOCKS (KSK) and SBLOCKS (SKS) */
+ * results (which should hence be excluded from what
+ * the service returns); naturally, this only applies
+ * to queries that can have multiple results, such as
+ * those for KBLOCKS (KSK) and SBLOCKS (SKS) */
};
@@ -2333,10 +2311,10 @@
GNUNET_HashCode query GNUNET_PACKED;
/* this is followed by hash codes
- as specified in the "hash_bitmap";
- after that, an optional bloomfilter
- (with bits set for replies that should
- be suppressed) can be present */
+ * as specified in the "hash_bitmap";
+ * after that, an optional bloomfilter
+ * (with bits set for replies that should
+ * be suppressed) can be present */
};
Modified: gnunet/src/fs/fs_directory.c
===================================================================
--- gnunet/src/fs/fs_directory.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/fs/fs_directory.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -50,20 +50,22 @@
* @return GNUNET_YES if it is, GNUNET_NO if it is not, GNUNET_SYSERR if
* we have no mime-type information (treat as 'GNUNET_NO')
*/
-int
-GNUNET_FS_meta_data_test_for_directory (const struct GNUNET_CONTAINER_MetaData
*md)
+int
+GNUNET_FS_meta_data_test_for_directory (const struct GNUNET_CONTAINER_MetaData
+ *md)
{
char *mime;
int ret;
-
+
if (NULL == md)
return GNUNET_SYSERR;
- mime = GNUNET_CONTAINER_meta_data_get_by_type (md,
EXTRACTOR_METATYPE_MIMETYPE);
+ mime =
+ GNUNET_CONTAINER_meta_data_get_by_type (md, EXTRACTOR_METATYPE_MIMETYPE);
if (mime == NULL)
return GNUNET_SYSERR;
ret = (0 == strcmp (mime, GNUNET_FS_DIRECTORY_MIME)) ? GNUNET_YES :
GNUNET_NO;
GNUNET_free (mime);
- return ret;
+ return ret;
}
@@ -77,29 +79,29 @@
GNUNET_FS_meta_data_make_directory (struct GNUNET_CONTAINER_MetaData *md)
{
char *mime;
-
- mime = GNUNET_CONTAINER_meta_data_get_by_type (md,
EXTRACTOR_METATYPE_MIMETYPE);
+
+ mime =
+ GNUNET_CONTAINER_meta_data_get_by_type (md, EXTRACTOR_METATYPE_MIMETYPE);
if (mime != NULL)
- {
- GNUNET_break (0 == strcmp (mime,
- GNUNET_FS_DIRECTORY_MIME));
- GNUNET_free (mime);
- return;
- }
- GNUNET_CONTAINER_meta_data_insert (md,
- "<gnunet>",
- EXTRACTOR_METATYPE_MIMETYPE,
- EXTRACTOR_METAFORMAT_UTF8,
- "text/plain",
- GNUNET_FS_DIRECTORY_MIME,
- strlen (GNUNET_FS_DIRECTORY_MIME)+1);
+ {
+ GNUNET_break (0 == strcmp (mime, GNUNET_FS_DIRECTORY_MIME));
+ GNUNET_free (mime);
+ return;
+ }
+ GNUNET_CONTAINER_meta_data_insert (md,
+ "<gnunet>",
+ EXTRACTOR_METATYPE_MIMETYPE,
+ EXTRACTOR_METAFORMAT_UTF8,
+ "text/plain",
+ GNUNET_FS_DIRECTORY_MIME,
+ strlen (GNUNET_FS_DIRECTORY_MIME) + 1);
}
/**
* Closure for 'find_full_data'.
*/
-struct GetFullDataClosure
+struct GetFullDataClosure
{
/**
@@ -130,30 +132,26 @@
* @param data actual meta-data found
* @param data_len number of bytes in data
* @return 0 to continue extracting, 1 to abort
- */
+ */
static int
find_full_data (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)
+ 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 GetFullDataClosure *gfdc = cls;
if (type == EXTRACTOR_METATYPE_GNUNET_FULL_DATA)
+ {
+ gfdc->size = data_len;
+ if (data_len > 0)
{
- gfdc->size = data_len;
- if (data_len > 0)
- {
- gfdc->data = GNUNET_malloc (data_len);
- memcpy (gfdc->data,
- data,
- data_len);
- }
- return 1;
+ gfdc->data = GNUNET_malloc (data_len);
+ memcpy (gfdc->data, data, data_len);
}
+ return 1;
+ }
return 0;
}
@@ -183,12 +181,12 @@
* GNUNET_NO if this could be part of a directory (but not 100% OK)
* GNUNET_SYSERR if 'data' does not represent a directory
*/
-int
+int
GNUNET_FS_directory_list_contents (size_t size,
- const void *data,
- uint64_t offset,
- GNUNET_FS_DirectoryEntryProcessor dep,
- void *dep_cls)
+ const void *data,
+ uint64_t offset,
+ GNUNET_FS_DirectoryEntryProcessor dep,
+ void *dep_cls)
{
struct GetFullDataClosure full_data;
const char *cdata = data;
@@ -201,123 +199,110 @@
struct GNUNET_CONTAINER_MetaData *md;
char *filename;
- if ( (offset == 0) &&
- ( (size < 8 + sizeof (uint32_t)) ||
- (0 != memcmp (cdata, GNUNET_FS_DIRECTORY_MAGIC, 8)) ) )
+ if ((offset == 0) &&
+ ((size < 8 + sizeof (uint32_t)) ||
+ (0 != memcmp (cdata, GNUNET_FS_DIRECTORY_MAGIC, 8))))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("MAGIC mismatch. This is not a GNUnet directory.\n"));
+ return GNUNET_SYSERR;
+ }
+ pos = offset;
+ if (offset == 0)
+ {
+ memcpy (&mdSize, &cdata[8], sizeof (uint32_t));
+ mdSize = ntohl (mdSize);
+ if (mdSize > size - 8 - sizeof (uint32_t))
{
+ /* invalid size */
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("MAGIC mismatch. This is not a GNUnet directory.\n"));
+ _("MAGIC mismatch. This is not a GNUnet directory.\n"));
return GNUNET_SYSERR;
}
- pos = offset;
- if (offset == 0)
+ md = GNUNET_CONTAINER_meta_data_deserialize (&cdata[8 +
+ sizeof (uint32_t)],
+ mdSize);
+ if (md == NULL)
{
- memcpy (&mdSize, &cdata[8], sizeof (uint32_t));
- mdSize = ntohl (mdSize);
- if (mdSize > size - 8 - sizeof (uint32_t))
- {
- /* invalid size */
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("MAGIC mismatch. This is not a GNUnet directory.\n"));
- return GNUNET_SYSERR;
- }
- md = GNUNET_CONTAINER_meta_data_deserialize (&cdata[8 +
- sizeof (uint32_t)],
- mdSize);
- if (md == NULL)
- {
- GNUNET_break (0);
- return GNUNET_SYSERR; /* malformed ! */
- }
- dep (dep_cls,
- NULL,
- NULL,
- md,
- 0,
- NULL);
- GNUNET_CONTAINER_meta_data_destroy (md);
- pos = 8 + sizeof (uint32_t) + mdSize;
+ GNUNET_break (0);
+ return GNUNET_SYSERR; /* malformed ! */
}
+ dep (dep_cls, NULL, NULL, md, 0, NULL);
+ GNUNET_CONTAINER_meta_data_destroy (md);
+ pos = 8 + sizeof (uint32_t) + mdSize;
+ }
while (pos < size)
+ {
+ /* find end of URI */
+ if (cdata[pos] == '\0')
{
- /* find end of URI */
- if (cdata[pos] == '\0')
- {
- /* URI is never empty, must be end of block,
- skip to next alignment */
- align =
- ((pos / DBLOCK_SIZE) + 1) * DBLOCK_SIZE;
- if (align == pos)
- {
- /* if we were already aligned, still skip a block! */
- align += DBLOCK_SIZE;
- }
- pos = align;
- if (pos >= size)
- {
- /* malformed - or partial download... */
- break;
- }
- }
- epos = pos;
- while ((epos < size) && (cdata[epos] != '\0'))
- epos++;
- if (epos >= size)
- return GNUNET_NO; /* malformed - or partial download */
-
- uri = GNUNET_FS_uri_parse (&cdata[pos], &emsg);
- pos = epos + 1;
- if (uri == NULL)
- {
- GNUNET_free (emsg);
- pos--; /* go back to '\0' to force going to next
alignment */
- continue;
- }
- if (GNUNET_FS_uri_test_ksk (uri))
- {
- GNUNET_FS_uri_destroy (uri);
- GNUNET_break (0);
- return GNUNET_NO; /* illegal in directory! */
- }
+ /* URI is never empty, must be end of block,
+ * skip to next alignment */
+ align = ((pos / DBLOCK_SIZE) + 1) * DBLOCK_SIZE;
+ if (align == pos)
+ {
+ /* if we were already aligned, still skip a block! */
+ align += DBLOCK_SIZE;
+ }
+ pos = align;
+ if (pos >= size)
+ {
+ /* malformed - or partial download... */
+ break;
+ }
+ }
+ epos = pos;
+ while ((epos < size) && (cdata[epos] != '\0'))
+ epos++;
+ if (epos >= size)
+ return GNUNET_NO; /* malformed - or partial download */
- memcpy (&mdSize, &cdata[pos], sizeof (uint32_t));
- mdSize = ntohl (mdSize);
- pos += sizeof (uint32_t);
- if (pos + mdSize > size)
- {
- GNUNET_FS_uri_destroy (uri);
- return GNUNET_NO; /* malformed - or partial download */
- }
+ uri = GNUNET_FS_uri_parse (&cdata[pos], &emsg);
+ pos = epos + 1;
+ if (uri == NULL)
+ {
+ GNUNET_free (emsg);
+ pos--; /* go back to '\0' to force going to next
alignment */
+ continue;
+ }
+ if (GNUNET_FS_uri_test_ksk (uri))
+ {
+ GNUNET_FS_uri_destroy (uri);
+ GNUNET_break (0);
+ return GNUNET_NO; /* illegal in directory! */
+ }
- md = GNUNET_CONTAINER_meta_data_deserialize (&cdata[pos], mdSize);
- if (md == NULL)
- {
- GNUNET_FS_uri_destroy (uri);
- GNUNET_break (0);
- return GNUNET_NO; /* malformed ! */
- }
- pos += mdSize;
- filename = GNUNET_CONTAINER_meta_data_get_by_type (md,
-
EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME);
- full_data.size = 0;
- full_data.data = NULL;
- GNUNET_CONTAINER_meta_data_iterate (md,
- &find_full_data,
- &full_data);
- if (dep != NULL)
- {
- dep (dep_cls,
- filename,
- uri,
- md,
- full_data.size,
- full_data.data);
- }
- GNUNET_free_non_null (full_data.data);
- GNUNET_free_non_null (filename);
- GNUNET_CONTAINER_meta_data_destroy (md);
+ memcpy (&mdSize, &cdata[pos], sizeof (uint32_t));
+ mdSize = ntohl (mdSize);
+ pos += sizeof (uint32_t);
+ if (pos + mdSize > size)
+ {
GNUNET_FS_uri_destroy (uri);
+ return GNUNET_NO; /* malformed - or partial download */
}
+
+ md = GNUNET_CONTAINER_meta_data_deserialize (&cdata[pos], mdSize);
+ if (md == NULL)
+ {
+ GNUNET_FS_uri_destroy (uri);
+ GNUNET_break (0);
+ return GNUNET_NO; /* malformed ! */
+ }
+ pos += mdSize;
+ filename = GNUNET_CONTAINER_meta_data_get_by_type (md,
+
EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME);
+ full_data.size = 0;
+ full_data.data = NULL;
+ GNUNET_CONTAINER_meta_data_iterate (md, &find_full_data, &full_data);
+ if (dep != NULL)
+ {
+ dep (dep_cls, filename, uri, md, full_data.size, full_data.data);
+ }
+ GNUNET_free_non_null (full_data.data);
+ GNUNET_free_non_null (filename);
+ GNUNET_CONTAINER_meta_data_destroy (md);
+ GNUNET_FS_uri_destroy (uri);
+ }
return GNUNET_OK;
}
@@ -330,7 +315,7 @@
* This is a linked list.
*/
struct BuilderEntry *next;
-
+
/**
* Length of this entry.
*/
@@ -365,11 +350,12 @@
* @param mdir metadata for the directory
*/
struct GNUNET_FS_DirectoryBuilder *
-GNUNET_FS_directory_builder_create (const struct GNUNET_CONTAINER_MetaData
*mdir)
+GNUNET_FS_directory_builder_create (const struct GNUNET_CONTAINER_MetaData
+ *mdir)
{
struct GNUNET_FS_DirectoryBuilder *ret;
- ret = GNUNET_malloc(sizeof(struct GNUNET_FS_DirectoryBuilder));
+ ret = GNUNET_malloc (sizeof (struct GNUNET_FS_DirectoryBuilder));
if (mdir != NULL)
ret->meta = GNUNET_CONTAINER_meta_data_duplicate (mdir);
else
@@ -391,9 +377,9 @@
*/
void
GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld,
- const struct GNUNET_FS_Uri *uri,
- const struct GNUNET_CONTAINER_MetaData *md,
- const void *data)
+ const struct GNUNET_FS_Uri *uri,
+ const struct GNUNET_CONTAINER_MetaData *md,
+ const void *data)
{
struct GNUNET_FS_Uri *curi;
struct BuilderEntry *e;
@@ -409,68 +395,64 @@
struct GNUNET_CONTAINER_MetaData *meta;
const struct GNUNET_CONTAINER_MetaData *meta_use;
- GNUNET_assert (! GNUNET_FS_uri_test_ksk (uri));
+ GNUNET_assert (!GNUNET_FS_uri_test_ksk (uri));
if (NULL != data)
+ {
+ GNUNET_assert (!GNUNET_FS_uri_test_sks (uri));
+ if (GNUNET_FS_uri_test_chk (uri))
{
- GNUNET_assert (! GNUNET_FS_uri_test_sks (uri));
- if (GNUNET_FS_uri_test_chk (uri))
- {
- fsize = GNUNET_FS_uri_chk_get_file_size (uri);
- }
- else
- {
- curi = GNUNET_FS_uri_loc_get_uri (uri);
- GNUNET_assert (NULL != curi);
- fsize = GNUNET_FS_uri_chk_get_file_size (curi);
- GNUNET_FS_uri_destroy (curi);
- }
+ fsize = GNUNET_FS_uri_chk_get_file_size (uri);
}
- else
+ else
{
- fsize = 0; /* not given */
+ curi = GNUNET_FS_uri_loc_get_uri (uri);
+ GNUNET_assert (NULL != curi);
+ fsize = GNUNET_FS_uri_chk_get_file_size (curi);
+ GNUNET_FS_uri_destroy (curi);
}
+ }
+ else
+ {
+ fsize = 0; /* not given */
+ }
if (fsize > MAX_INLINE_SIZE)
- fsize = 0; /* too large */
+ fsize = 0; /* too large */
uris = GNUNET_FS_uri_to_string (uri);
slen = strlen (uris) + 1;
- mds =
- GNUNET_CONTAINER_meta_data_get_serialized_size (md);
+ mds = GNUNET_CONTAINER_meta_data_get_serialized_size (md);
meta_use = md;
meta = NULL;
if (fsize > 0)
+ {
+ meta = GNUNET_CONTAINER_meta_data_duplicate (md);
+ GNUNET_CONTAINER_meta_data_insert (meta,
+ "<gnunet>",
+ EXTRACTOR_METATYPE_GNUNET_FULL_DATA,
+ EXTRACTOR_METAFORMAT_BINARY,
+ NULL, data, fsize);
+ mdxs = GNUNET_CONTAINER_meta_data_get_serialized_size (meta);
+ if ((slen + sizeof (uint32_t) + mdxs - 1) / DBLOCK_SIZE ==
+ (slen + sizeof (uint32_t) + mds - 1) / DBLOCK_SIZE)
{
- meta = GNUNET_CONTAINER_meta_data_duplicate (md);
- GNUNET_CONTAINER_meta_data_insert (meta,
- "<gnunet>",
- EXTRACTOR_METATYPE_GNUNET_FULL_DATA,
- EXTRACTOR_METAFORMAT_BINARY,
- NULL,
- data,
- fsize);
- mdxs =
- GNUNET_CONTAINER_meta_data_get_serialized_size (meta);
- if ( (slen + sizeof (uint32_t) + mdxs - 1) / DBLOCK_SIZE ==
- (slen + sizeof (uint32_t) + mds - 1) / DBLOCK_SIZE)
- {
- /* adding full data would not cause us to cross
- additional blocks, so add it! */
- meta_use = meta;
- mds = mdxs;
- }
+ /* adding full data would not cause us to cross
+ * additional blocks, so add it! */
+ meta_use = meta;
+ mds = mdxs;
}
+ }
if (mds > GNUNET_MAX_MALLOC_CHECKED / 2)
mds = GNUNET_MAX_MALLOC_CHECKED / 2;
- e = GNUNET_malloc (sizeof(struct BuilderEntry) +
- slen + mds + sizeof (uint32_t));
- ser = (char*) &e[1];
+ e = GNUNET_malloc (sizeof (struct BuilderEntry) +
+ slen + mds + sizeof (uint32_t));
+ ser = (char *) &e[1];
memcpy (ser, uris, slen);
GNUNET_free (uris);
- sptr = &ser[slen + sizeof(uint32_t)];
+ sptr = &ser[slen + sizeof (uint32_t)];
ret = GNUNET_CONTAINER_meta_data_serialize (meta_use,
- &sptr,
- mds,
-
GNUNET_CONTAINER_META_DATA_SERIALIZE_PART);
+ &sptr,
+ mds,
+
GNUNET_CONTAINER_META_DATA_SERIALIZE_PART);
if (NULL != meta)
GNUNET_CONTAINER_meta_data_destroy (meta);
if (ret == -1)
@@ -492,11 +474,10 @@
* after alignment to the DBLOCK_SIZE.
*/
static size_t
-do_align (size_t start_position,
- size_t end_position)
+do_align (size_t start_position, size_t end_position)
{
size_t align;
-
+
align = (end_position / DBLOCK_SIZE) * DBLOCK_SIZE;
if ((start_position < align) && (end_position > align))
return align + end_position - start_position;
@@ -515,9 +496,7 @@
*/
static void
block_align (size_t start,
- unsigned int count,
- const size_t *sizes,
- unsigned int *perm)
+ unsigned int count, const size_t * sizes, unsigned int *perm)
{
unsigned int i;
unsigned int j;
@@ -531,51 +510,46 @@
cpos = start;
for (i = 0; i < count; i++)
+ {
+ start = cpos;
+ badness = 0x7FFFFFFF;
+ best = -1;
+ for (j = i; j < count; j++)
{
- start = cpos;
- badness = 0x7FFFFFFF;
- best = -1;
- for (j = i; j < count; j++)
+ cval = perm[j];
+ cend = cpos + sizes[cval];
+ if (cpos % DBLOCK_SIZE == 0)
+ {
+ /* prefer placing the largest blocks first */
+ cbad = -(cend % DBLOCK_SIZE);
+ }
+ else
+ {
+ if (cpos / DBLOCK_SIZE == cend / DBLOCK_SIZE)
{
- cval = perm[j];
- cend = cpos + sizes[cval];
- if (cpos % DBLOCK_SIZE == 0)
- {
- /* prefer placing the largest blocks first */
- cbad = -(cend % DBLOCK_SIZE);
- }
- else
- {
- if (cpos / DBLOCK_SIZE ==
- cend / DBLOCK_SIZE)
- {
- /* Data fits into the same block! Prefer small left-overs! */
- cbad =
- DBLOCK_SIZE - cend % DBLOCK_SIZE;
- }
- else
- {
- /* Would have to waste space to re-align, add big factor,
this
- case is a real loss (proportional to space wasted)! */
- cbad =
- DBLOCK_SIZE * (DBLOCK_SIZE -
- cpos %
- DBLOCK_SIZE);
- }
- }
- if (cbad < badness)
- {
- best = j;
- badness = cbad;
- }
+ /* Data fits into the same block! Prefer small left-overs! */
+ cbad = DBLOCK_SIZE - cend % DBLOCK_SIZE;
}
- GNUNET_assert (best != -1);
- tmp = perm[i];
- perm[i] = perm[best];
- perm[best] = tmp;
- cpos += sizes[perm[i]];
- cpos = do_align (start, cpos);
+ else
+ {
+ /* Would have to waste space to re-align, add big factor, this
+ * case is a real loss (proportional to space wasted)! */
+ cbad = DBLOCK_SIZE * (DBLOCK_SIZE - cpos % DBLOCK_SIZE);
+ }
+ }
+ if (cbad < badness)
+ {
+ best = j;
+ badness = cbad;
+ }
}
+ GNUNET_assert (best != -1);
+ tmp = perm[i];
+ perm[i] = perm[best];
+ perm[best] = tmp;
+ cpos += sizes[perm[i]];
+ cpos = do_align (start, cpos);
+ }
}
@@ -591,8 +565,7 @@
*/
int
GNUNET_FS_directory_builder_finish (struct GNUNET_FS_DirectoryBuilder *bld,
- size_t *rsize,
- void **rdata)
+ size_t * rsize, void **rdata)
{
char *data;
char *sptr;
@@ -614,71 +587,65 @@
perm = NULL;
bes = NULL;
if (0 < bld->count)
+ {
+ sizes = GNUNET_malloc (bld->count * sizeof (size_t));
+ perm = GNUNET_malloc (bld->count * sizeof (unsigned int));
+ bes = GNUNET_malloc (bld->count * sizeof (struct BuilderEntry *));
+ pos = bld->head;
+ for (i = 0; i < bld->count; i++)
{
- sizes = GNUNET_malloc (bld->count * sizeof (size_t));
- perm = GNUNET_malloc (bld->count * sizeof (unsigned int));
- bes = GNUNET_malloc (bld->count * sizeof (struct BuilderEntry *));
- pos = bld->head;
- for (i = 0; i < bld->count; i++)
- {
- perm[i] = i;
- bes[i] = pos;
- sizes[i] = pos->len;
- pos = pos->next;
- }
- block_align (size,
- bld->count,
- sizes,
- perm);
- /* compute final size with alignment */
- for (i = 0; i < bld->count; i++)
- {
- psize = size;
- size += sizes[perm[i]];
- size = do_align (psize, size);
- }
+ perm[i] = i;
+ bes[i] = pos;
+ sizes[i] = pos->len;
+ pos = pos->next;
}
+ block_align (size, bld->count, sizes, perm);
+ /* compute final size with alignment */
+ for (i = 0; i < bld->count; i++)
+ {
+ psize = size;
+ size += sizes[perm[i]];
+ size = do_align (psize, size);
+ }
+ }
*rsize = size;
data = GNUNET_malloc_large (size);
if (data == NULL)
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
- "malloc");
- *rsize = 0;
- *rdata = NULL;
- GNUNET_free_non_null (sizes);
- GNUNET_free_non_null (perm);
- GNUNET_free_non_null (bes);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "malloc");
+ *rsize = 0;
+ *rdata = NULL;
+ GNUNET_free_non_null (sizes);
+ GNUNET_free_non_null (perm);
+ GNUNET_free_non_null (bes);
+ return GNUNET_SYSERR;
+ }
*rdata = data;
memcpy (data, GNUNET_DIRECTORY_MAGIC, strlen (GNUNET_DIRECTORY_MAGIC));
off = strlen (GNUNET_DIRECTORY_MAGIC);
sptr = &data[off + sizeof (uint32_t)];
ret = GNUNET_CONTAINER_meta_data_serialize (bld->meta,
- &sptr,
- size - off - sizeof (uint32_t),
-
GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL);
+ &sptr,
+ size - off - sizeof (uint32_t),
+
GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL);
GNUNET_assert (ret != -1);
- big = htonl (ret);
+ big = htonl (ret);
memcpy (&data[off], &big, sizeof (uint32_t));
off += sizeof (uint32_t) + ret;
for (j = 0; j < bld->count; j++)
- {
- i = perm[j];
- psize = off;
- off += sizes[i];
- off = do_align (psize, off);
- memcpy (&data[off - sizes[i]],
- &(bes[i])[1],
- sizes[i]);
- GNUNET_free (bes[i]);
- }
+ {
+ i = perm[j];
+ psize = off;
+ off += sizes[i];
+ off = do_align (psize, off);
+ memcpy (&data[off - sizes[i]], &(bes[i])[1], sizes[i]);
+ GNUNET_free (bes[i]);
+ }
GNUNET_free_non_null (sizes);
GNUNET_free_non_null (perm);
GNUNET_free_non_null (bes);
- GNUNET_assert (off == size);
+ GNUNET_assert (off == size);
GNUNET_CONTAINER_meta_data_destroy (bld->meta);
GNUNET_free (bld);
return GNUNET_OK;
Modified: gnunet/src/fs/fs_download.c
===================================================================
--- gnunet/src/fs/fs_download.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/fs/fs_download.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -40,14 +40,15 @@
static int
is_recursive_download (struct GNUNET_FS_DownloadContext *dc)
{
- return (0 != (dc->options & GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE)) &&
- ( (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (dc->meta)) ||
- ( (dc->meta == NULL) &&
- ( (NULL == dc->filename) ||
- ( (strlen (dc->filename) >= strlen (GNUNET_FS_DIRECTORY_EXT)) &&
- (NULL !=
- strstr (dc->filename + strlen(dc->filename) -
strlen(GNUNET_FS_DIRECTORY_EXT),
- GNUNET_FS_DIRECTORY_EXT)) ) ) ) );
+ return (0 != (dc->options & GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE)) &&
+ ((GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (dc->meta)) ||
+ ((dc->meta == NULL) &&
+ ((NULL == dc->filename) ||
+ ((strlen (dc->filename) >= strlen (GNUNET_FS_DIRECTORY_EXT)) &&
+ (NULL !=
+ strstr (dc->filename + strlen (dc->filename) -
+ strlen (GNUNET_FS_DIRECTORY_EXT),
+ GNUNET_FS_DIRECTORY_EXT))))));
}
@@ -68,31 +69,31 @@
* with the range for any other block
*/
static uint64_t
-compute_disk_offset (uint64_t fsize,
- uint64_t off,
- unsigned int depth)
+compute_disk_offset (uint64_t fsize, uint64_t off, unsigned int depth)
{
unsigned int i;
- uint64_t lsize; /* what is the size of all IBlocks for depth "i"? */
- uint64_t loff; /* where do IBlocks for depth "i" start? */
- unsigned int ioff; /* which IBlock corresponds to "off" at depth "i"? */
-
+ uint64_t lsize; /* what is the size of all IBlocks for depth
"i"? */
+ uint64_t loff; /* where do IBlocks for depth "i" start? */
+ unsigned int ioff; /* which IBlock corresponds to "off" at depth
"i"? */
+
if (depth == 0)
return off;
/* first IBlocks start at the end of file, rounded up
- to full DBLOCK_SIZE */
+ * to full DBLOCK_SIZE */
loff = ((fsize + DBLOCK_SIZE - 1) / DBLOCK_SIZE) * DBLOCK_SIZE;
- lsize = ( (fsize + DBLOCK_SIZE - 1) / DBLOCK_SIZE) * sizeof (struct
ContentHashKey);
+ lsize =
+ ((fsize + DBLOCK_SIZE -
+ 1) / DBLOCK_SIZE) * sizeof (struct ContentHashKey);
GNUNET_assert (0 == (off % DBLOCK_SIZE));
ioff = (off / DBLOCK_SIZE);
- for (i=1;i<depth;i++)
- {
- loff += lsize;
- lsize = (lsize + CHK_PER_INODE - 1) / CHK_PER_INODE;
- GNUNET_assert (lsize > 0);
- GNUNET_assert (0 == (ioff % CHK_PER_INODE));
- ioff /= CHK_PER_INODE;
- }
+ for (i = 1; i < depth; i++)
+ {
+ loff += lsize;
+ lsize = (lsize + CHK_PER_INODE - 1) / CHK_PER_INODE;
+ GNUNET_assert (lsize > 0);
+ GNUNET_assert (0 == (ioff % CHK_PER_INODE));
+ ioff /= CHK_PER_INODE;
+ }
return loff + ioff * sizeof (struct ContentHashKey);
}
@@ -106,38 +107,28 @@
*/
void
GNUNET_FS_download_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
- struct GNUNET_FS_DownloadContext *dc)
+ struct GNUNET_FS_DownloadContext *dc)
{
pi->value.download.dc = dc;
- pi->value.download.cctx
- = dc->client_info;
+ pi->value.download.cctx = dc->client_info;
pi->value.download.pctx
- = (dc->parent == NULL) ? NULL : dc->parent->client_info;
+ = (dc->parent == NULL) ? NULL : dc->parent->client_info;
pi->value.download.sctx
- = (dc->search == NULL) ? NULL : dc->search->client_info;
- pi->value.download.uri
- = dc->uri;
- pi->value.download.filename
- = dc->filename;
- pi->value.download.size
- = dc->length;
+ = (dc->search == NULL) ? NULL : dc->search->client_info;
+ pi->value.download.uri = dc->uri;
+ pi->value.download.filename = dc->filename;
+ pi->value.download.size = dc->length;
pi->value.download.duration
- = GNUNET_TIME_absolute_get_duration (dc->start_time);
- pi->value.download.completed
- = dc->completed;
- pi->value.download.anonymity
- = dc->anonymity;
+ = GNUNET_TIME_absolute_get_duration (dc->start_time);
+ pi->value.download.completed = dc->completed;
+ pi->value.download.anonymity = dc->anonymity;
pi->value.download.eta
- = GNUNET_TIME_calculate_eta (dc->start_time,
- dc->completed,
- dc->length);
+ = GNUNET_TIME_calculate_eta (dc->start_time, dc->completed, dc->length);
pi->value.download.is_active = (dc->client == NULL) ? GNUNET_NO : GNUNET_YES;
if (0 == (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE))
- dc->client_info = dc->h->upcb (dc->h->upcb_cls,
- pi);
+ dc->client_info = dc->h->upcb (dc->h->upcb_cls, pi);
else
- dc->client_info = GNUNET_FS_search_probe_progress_ (NULL,
- pi);
+ dc->client_info = GNUNET_FS_search_probe_progress_ (NULL, pi);
}
@@ -152,10 +143,7 @@
* @param buf where the callee should write the message
* @return number of bytes written to buf
*/
-static size_t
-transmit_download_request (void *cls,
- size_t size,
- void *buf);
+static size_t transmit_download_request (void *cls, size_t size, void *buf);
/**
@@ -163,7 +151,7 @@
*/
struct ProcessResultClosure
{
-
+
/**
* Hash of data.
*/
@@ -171,14 +159,14 @@
/**
* Data found in P2P network.
- */
+ */
const void *data;
/**
* Our download context.
*/
struct GNUNET_FS_DownloadContext *dc;
-
+
/**
* Number of bytes in data.
*/
@@ -193,7 +181,7 @@
* Flag to indicate if this block should be stored on disk.
*/
int do_store;
-
+
};
@@ -208,8 +196,7 @@
*/
static int
process_result_with_request (void *cls,
- const GNUNET_HashCode * key,
- void *value);
+ const GNUNET_HashCode * key, void *value);
/**
@@ -227,53 +214,42 @@
*/
static int
encrypt_existing_match (struct GNUNET_FS_DownloadContext *dc,
- const struct ContentHashKey *chk,
- struct DownloadRequest *dr,
- const char * block,
- size_t len,
- int do_store)
+ const struct ContentHashKey *chk,
+ struct DownloadRequest *dr,
+ const char *block, size_t len, int do_store)
{
struct ProcessResultClosure prc;
char enc[len];
struct GNUNET_CRYPTO_AesSessionKey sk;
struct GNUNET_CRYPTO_AesInitializationVector iv;
GNUNET_HashCode query;
-
+
GNUNET_CRYPTO_hash_to_aes_key (&chk->key, &sk, &iv);
- if (-1 == GNUNET_CRYPTO_aes_encrypt (block, len,
- &sk,
- &iv,
- enc))
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
+ if (-1 == GNUNET_CRYPTO_aes_encrypt (block, len, &sk, &iv, enc))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
GNUNET_CRYPTO_hash (enc, len, &query);
- if (0 != memcmp (&query,
- &chk->query,
- sizeof (GNUNET_HashCode)))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
+ if (0 != memcmp (&query, &chk->query, sizeof (GNUNET_HashCode)))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
#if DEBUG_DOWNLOAD
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Matching block for `%s' at offset %llu already present, no need
for download!\n",
- dc->filename,
- (unsigned long long) dr->offset);
+ "Matching block for `%s' at offset %llu already present, no need
for download!\n",
+ dc->filename, (unsigned long long) dr->offset);
#endif
/* already got it! */
prc.dc = dc;
prc.data = enc;
prc.size = len;
- prc.type = (0 == dr->depth)
- ? GNUNET_BLOCK_TYPE_FS_DBLOCK
- : GNUNET_BLOCK_TYPE_FS_IBLOCK;
+ prc.type = (0 == dr->depth)
+ ? GNUNET_BLOCK_TYPE_FS_DBLOCK : GNUNET_BLOCK_TYPE_FS_IBLOCK;
prc.query = chk->query;
prc.do_store = do_store;
- process_result_with_request (&prc,
- &chk->key,
- dr);
+ process_result_with_request (&prc, &chk->key, dr);
return GNUNET_OK;
}
@@ -285,8 +261,7 @@
*
* @param dc download context that is having trouble
*/
-static void
-try_reconnect (struct GNUNET_FS_DownloadContext *dc);
+static void try_reconnect (struct GNUNET_FS_DownloadContext *dc);
/**
@@ -300,13 +275,12 @@
* @param length number of bytes in data
* @param data contents of the file (or NULL if they were not inlined)
*/
-static void
+static void
trigger_recursive_download (void *cls,
- const char *filename,
- const struct GNUNET_FS_Uri *uri,
- const struct GNUNET_CONTAINER_MetaData *meta,
- size_t length,
- const void *data);
+ const char *filename,
+ const struct GNUNET_FS_Uri *uri,
+ const struct GNUNET_CONTAINER_MetaData *meta,
+ size_t length, const void *data);
/**
@@ -323,55 +297,51 @@
void *data;
struct GNUNET_DISK_FileHandle *h;
struct GNUNET_DISK_MapHandle *m;
-
+
size64 = GNUNET_FS_uri_chk_get_file_size (dc->uri);
size = (size_t) size64;
if (size64 != (uint64_t) size)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Recursive downloads of directories larger than 4 GB are
not supported on 32-bit systems\n"));
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _
+ ("Recursive downloads of directories larger than 4 GB are not
supported on 32-bit systems\n"));
+ return;
+ }
if (dc->filename != NULL)
- {
- h = GNUNET_DISK_file_open (dc->filename,
- GNUNET_DISK_OPEN_READ,
- GNUNET_DISK_PERM_NONE);
- }
+ {
+ h = GNUNET_DISK_file_open (dc->filename,
+ GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE);
+ }
else
- {
- GNUNET_assert (dc->temp_filename != NULL);
- h = GNUNET_DISK_file_open (dc->temp_filename,
- GNUNET_DISK_OPEN_READ,
- GNUNET_DISK_PERM_NONE);
- }
+ {
+ GNUNET_assert (dc->temp_filename != NULL);
+ h = GNUNET_DISK_file_open (dc->temp_filename,
+ GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE);
+ }
if (h == NULL)
- return; /* oops */
+ return; /* oops */
data = GNUNET_DISK_file_map (h, &m, GNUNET_DISK_MAP_TYPE_READ, size);
if (data == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Directory too large for system address space\n"));
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Directory too large for system address space\n"));
+ }
else
- {
- GNUNET_FS_directory_list_contents (size,
- data,
- 0,
- &trigger_recursive_download,
- dc);
- GNUNET_DISK_file_unmap (m);
- }
+ {
+ GNUNET_FS_directory_list_contents (size,
+ data,
+ 0, &trigger_recursive_download, dc);
+ GNUNET_DISK_file_unmap (m);
+ }
GNUNET_DISK_file_close (h);
if (dc->filename == NULL)
- {
- if (0 != UNLINK (dc->temp_filename))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
- "unlink",
- dc->temp_filename);
- GNUNET_free (dc->temp_filename);
- dc->temp_filename = NULL;
- }
+ {
+ if (0 != UNLINK (dc->temp_filename))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
+ "unlink", dc->temp_filename);
+ GNUNET_free (dc->temp_filename);
+ dc->temp_filename = NULL;
+ }
}
@@ -392,28 +362,25 @@
struct GNUNET_FS_DownloadContext *pos;
/* first, check if we need to download children */
- if ( (dc->child_head == NULL) &&
- (is_recursive_download (dc)) )
- full_recursive_download (dc);
+ if ((dc->child_head == NULL) && (is_recursive_download (dc)))
+ full_recursive_download (dc);
/* then, check if children are done already */
pos = dc->child_head;
while (pos != NULL)
- {
- if ( (pos->emsg == NULL) &&
- (pos->completed < pos->length) )
- return; /* not done yet */
- if ( (pos->child_head != NULL) &&
- (pos->has_finished != GNUNET_YES) )
- return; /* not transitively done yet */
- pos = pos->next;
- }
+ {
+ if ((pos->emsg == NULL) && (pos->completed < pos->length))
+ return; /* not done yet */
+ if ((pos->child_head != NULL) && (pos->has_finished != GNUNET_YES))
+ return; /* not transitively done yet */
+ pos = pos->next;
+ }
/* All of our children are done, so mark this download done */
dc->has_finished = GNUNET_YES;
if (dc->job_queue != NULL)
- {
- GNUNET_FS_dequeue_ (dc->job_queue);
- dc->job_queue = NULL;
- }
+ {
+ GNUNET_FS_dequeue_ (dc->job_queue);
+ dc->job_queue = NULL;
+ }
GNUNET_FS_download_sync_ (dc);
/* signal completion */
@@ -422,7 +389,7 @@
/* let parent know */
if (dc->parent != NULL)
- check_completed (dc->parent);
+ check_completed (dc->parent);
}
@@ -435,12 +402,10 @@
* @param dr download request to match against
* @param data plaintext data, starting from the beginning of the file
* @param data_len number of bytes in data
- */
+ */
static void
try_match_block (struct GNUNET_FS_DownloadContext *dc,
- struct DownloadRequest *dr,
- const char *data,
- size_t data_len)
+ struct DownloadRequest *dr, const char *data, size_t data_len)
{
struct GNUNET_FS_ProgressInfo pi;
unsigned int i;
@@ -456,134 +421,112 @@
const char *fn;
const char *odata;
size_t odata_len;
-
+
odata = data;
odata_len = data_len;
if (BRS_DOWNLOAD_UP == dr->state)
return;
if (dr->depth > 0)
+ {
+ complete = GNUNET_YES;
+ for (i = 0; i < dr->num_children; i++)
{
- complete = GNUNET_YES;
- for (i=0;i<dr->num_children;i++)
- {
- drc = dr->children[i];
- try_match_block (dc,
- drc,
- data, data_len);
- if (drc->state != BRS_RECONSTRUCT_META_UP)
- complete = GNUNET_NO;
- else
- chks[i] = drc->chk;
- }
- if (GNUNET_YES != complete)
- return;
- data = (const char*) chks;
- dlen = dr->num_children * sizeof (struct ContentHashKey);
+ drc = dr->children[i];
+ try_match_block (dc, drc, data, data_len);
+ if (drc->state != BRS_RECONSTRUCT_META_UP)
+ complete = GNUNET_NO;
+ else
+ chks[i] = drc->chk;
}
+ if (GNUNET_YES != complete)
+ return;
+ data = (const char *) chks;
+ dlen = dr->num_children * sizeof (struct ContentHashKey);
+ }
else
+ {
+ if (dr->offset > data_len)
+ return; /* oops */
+ dlen = GNUNET_MIN (data_len - dr->offset, DBLOCK_SIZE);
+ }
+ GNUNET_CRYPTO_hash (&data[dr->offset], dlen, &in_chk.key);
+ GNUNET_CRYPTO_hash_to_aes_key (&in_chk.key, &sk, &iv);
+ if (-1 == GNUNET_CRYPTO_aes_encrypt (&data[dr->offset], dlen, &sk, &iv, enc))
+ {
+ GNUNET_break (0);
+ return;
+ }
+ GNUNET_CRYPTO_hash (enc, dlen, &in_chk.query);
+ switch (dr->state)
+ {
+ case BRS_INIT:
+ dr->chk = in_chk;
+ dr->state = BRS_RECONSTRUCT_META_UP;
+ break;
+ case BRS_CHK_SET:
+ if (0 != memcmp (&in_chk, &dr->chk, sizeof (struct ContentHashKey)))
{
- if (dr->offset > data_len)
- return; /* oops */
- dlen = GNUNET_MIN (data_len - dr->offset,
- DBLOCK_SIZE);
+ /* other peer provided bogus meta data */
+ GNUNET_break_op (0);
+ break;
}
- GNUNET_CRYPTO_hash (&data[dr->offset],
- dlen,
- &in_chk.key);
- GNUNET_CRYPTO_hash_to_aes_key (&in_chk.key, &sk, &iv);
- if (-1 == GNUNET_CRYPTO_aes_encrypt (&data[dr->offset], dlen,
- &sk,
- &iv,
- enc))
+ /* write block to disk */
+ fn = dc->filename != NULL ? dc->filename : dc->temp_filename;
+ fh = GNUNET_DISK_file_open (fn,
+ GNUNET_DISK_OPEN_READWRITE |
+ GNUNET_DISK_OPEN_CREATE |
+ GNUNET_DISK_OPEN_TRUNCATE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE |
+ GNUNET_DISK_PERM_GROUP_READ |
+ GNUNET_DISK_PERM_OTHER_READ);
+ if (fh == NULL)
{
- GNUNET_break (0);
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", fn);
+ GNUNET_asprintf (&dc->emsg,
+ _("Failed to open file `%s' for writing"), fn);
+ GNUNET_DISK_file_close (fh);
+ dr->state = BRS_ERROR;
+ pi.status = GNUNET_FS_STATUS_DOWNLOAD_ERROR;
+ pi.value.download.specifics.error.message = dc->emsg;
+ GNUNET_FS_download_make_status_ (&pi, dc);
return;
}
- GNUNET_CRYPTO_hash (enc, dlen, &in_chk.query);
- switch (dr->state)
+ if (data_len != GNUNET_DISK_file_write (fh, odata, odata_len))
{
- case BRS_INIT:
- dr->chk = in_chk;
- dr->state = BRS_RECONSTRUCT_META_UP;
- break;
- case BRS_CHK_SET:
- if (0 != memcmp (&in_chk,
- &dr->chk,
- sizeof (struct ContentHashKey)))
- {
- /* other peer provided bogus meta data */
- GNUNET_break_op (0);
- break;
- }
- /* write block to disk */
- fn = dc->filename != NULL
- ? dc->filename
- : dc->temp_filename;
- fh = GNUNET_DISK_file_open (fn,
- GNUNET_DISK_OPEN_READWRITE |
- GNUNET_DISK_OPEN_CREATE |
- GNUNET_DISK_OPEN_TRUNCATE,
- GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE |
- GNUNET_DISK_PERM_GROUP_READ |
- GNUNET_DISK_PERM_OTHER_READ);
- if (fh == NULL)
- {
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
- "open",
- fn);
- GNUNET_asprintf (&dc->emsg,
- _("Failed to open file `%s' for writing"),
- fn);
- GNUNET_DISK_file_close (fh);
- dr->state = BRS_ERROR;
- pi.status = GNUNET_FS_STATUS_DOWNLOAD_ERROR;
- pi.value.download.specifics.error.message = dc->emsg;
- GNUNET_FS_download_make_status_ (&pi, dc);
- return;
- }
- if (data_len !=
- GNUNET_DISK_file_write (fh,
- odata,
- odata_len))
- {
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
- "write",
- fn);
- GNUNET_asprintf (&dc->emsg,
- _("Failed to open file `%s' for writing"),
- fn);
- GNUNET_DISK_file_close (fh);
- dr->state = BRS_ERROR;
- pi.status = GNUNET_FS_STATUS_DOWNLOAD_ERROR;
- pi.value.download.specifics.error.message = dc->emsg;
- GNUNET_FS_download_make_status_ (&pi, dc);
- return;
- }
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", fn);
+ GNUNET_asprintf (&dc->emsg,
+ _("Failed to open file `%s' for writing"), fn);
GNUNET_DISK_file_close (fh);
- /* signal success */
- dr->state = BRS_DOWNLOAD_UP;
- dc->completed = dc->length;
- GNUNET_FS_download_sync_ (dc);
- pi.status = GNUNET_FS_STATUS_DOWNLOAD_PROGRESS;
- pi.value.download.specifics.progress.data = data;
- pi.value.download.specifics.progress.offset = 0;
- pi.value.download.specifics.progress.data_len = dlen;
- pi.value.download.specifics.progress.depth = 0;
+ dr->state = BRS_ERROR;
+ pi.status = GNUNET_FS_STATUS_DOWNLOAD_ERROR;
+ pi.value.download.specifics.error.message = dc->emsg;
GNUNET_FS_download_make_status_ (&pi, dc);
- if ( (NULL != dc->filename) &&
- (0 != truncate (dc->filename,
- GNUNET_ntohll (dc->uri->data.chk.file_length))) )
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
- "truncate",
- dc->filename);
- check_completed (dc);
- break;
- default:
- /* how did we get here? */
- GNUNET_break (0);
- break;
+ return;
}
+ GNUNET_DISK_file_close (fh);
+ /* signal success */
+ dr->state = BRS_DOWNLOAD_UP;
+ dc->completed = dc->length;
+ GNUNET_FS_download_sync_ (dc);
+ pi.status = GNUNET_FS_STATUS_DOWNLOAD_PROGRESS;
+ pi.value.download.specifics.progress.data = data;
+ pi.value.download.specifics.progress.offset = 0;
+ pi.value.download.specifics.progress.data_len = dlen;
+ pi.value.download.specifics.progress.depth = 0;
+ GNUNET_FS_download_make_status_ (&pi, dc);
+ if ((NULL != dc->filename) &&
+ (0 != truncate (dc->filename,
+ GNUNET_ntohll (dc->uri->data.chk.file_length))))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
+ "truncate", dc->filename);
+ check_completed (dc);
+ break;
+ default:
+ /* how did we get here? */
+ GNUNET_break (0);
+ break;
+ }
}
@@ -604,34 +547,28 @@
* @param data actual meta-data found
* @param data_len number of bytes in data
* @return 0 to continue extracting, 1 to abort
- */
+ */
static int
match_full_data (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)
+ 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_FS_DownloadContext *dc = cls;
- if (type != EXTRACTOR_METATYPE_GNUNET_FULL_DATA)
+ if (type != EXTRACTOR_METATYPE_GNUNET_FULL_DATA)
return 0;
#if DEBUG_DOWNLOAD
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Found %u bytes of FD!\n",
- (unsigned int) data_len);
+ "Found %u bytes of FD!\n", (unsigned int) data_len);
#endif
if (GNUNET_FS_uri_chk_get_file_size (dc->uri) != data_len)
- {
- GNUNET_break_op (0);
- return 1; /* bogus meta data */
- }
- try_match_block (dc,
- dc->top_request,
- data,
- data_len);
+ {
+ GNUNET_break_op (0);
+ return 1; /* bogus meta data */
+ }
+ try_match_block (dc, dc->top_request, data, data_len);
return 1;
}
@@ -648,15 +585,15 @@
unsigned int i;
do
- {
- dr->state = BRS_DOWNLOAD_UP;
- dr = dr->parent;
- if (dr == NULL)
- break;
- for (i=0;i<dr->num_children;i++)
- if (dr->children[i]->state != BRS_DOWNLOAD_UP)
- break;
- }
+ {
+ dr->state = BRS_DOWNLOAD_UP;
+ dr = dr->parent;
+ if (dr == NULL)
+ break;
+ for (i = 0; i < dr->num_children; i++)
+ if (dr->children[i]->state != BRS_DOWNLOAD_UP)
+ break;
+ }
while (i == dr->num_children);
}
@@ -673,7 +610,7 @@
*/
static void
try_top_down_reconstruction (struct GNUNET_FS_DownloadContext *dc,
- struct DownloadRequest *dr)
+ struct DownloadRequest *dr)
{
uint64_t off;
char block[DBLOCK_SIZE];
@@ -686,87 +623,66 @@
uint64_t child_block_size;
const struct ContentHashKey *chks;
int up_done;
-
+
GNUNET_assert (dc->rfh != NULL);
GNUNET_assert (dr->state == BRS_CHK_SET);
total = GNUNET_FS_uri_chk_get_file_size (dc->uri);
GNUNET_assert (dr->depth < dc->treedepth);
- len = GNUNET_FS_tree_calculate_block_size (total,
- dr->offset,
- dr->depth);
+ len = GNUNET_FS_tree_calculate_block_size (total, dr->offset, dr->depth);
GNUNET_assert (len <= DBLOCK_SIZE);
- off = compute_disk_offset (total,
- dr->offset,
- dr->depth);
- if (dc->old_file_size < off + len)
- return; /* failure */
- if (off !=
- GNUNET_DISK_file_seek (dc->rfh,
- off,
- GNUNET_DISK_SEEK_SET) )
- {
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
- "seek",
- dc->filename);
- return; /* failure */
- }
- if (len !=
- GNUNET_DISK_file_read (dc->rfh,
- block,
- len))
- {
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
- "read",
- dc->filename);
- return; /* failure */
- }
+ off = compute_disk_offset (total, dr->offset, dr->depth);
+ if (dc->old_file_size < off + len)
+ return; /* failure */
+ if (off != GNUNET_DISK_file_seek (dc->rfh, off, GNUNET_DISK_SEEK_SET))
+ {
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "seek", dc->filename);
+ return; /* failure */
+ }
+ if (len != GNUNET_DISK_file_read (dc->rfh, block, len))
+ {
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "read", dc->filename);
+ return; /* failure */
+ }
GNUNET_CRYPTO_hash (block, len, &key);
- if (0 != memcmp (&key,
- &dr->chk.key,
- sizeof (GNUNET_HashCode)))
- return; /* mismatch */
+ if (0 != memcmp (&key, &dr->chk.key, sizeof (GNUNET_HashCode)))
+ return; /* mismatch */
if (GNUNET_OK !=
- encrypt_existing_match (dc,
- &dr->chk,
- dr,
- block,
- len,
- GNUNET_NO))
+ encrypt_existing_match (dc, &dr->chk, dr, block, len, GNUNET_NO))
+ {
+ /* hash matches but encrypted block does not, really bad */
+ dr->state = BRS_ERROR;
+ /* propagate up */
+ while (dr->parent != NULL)
{
- /* hash matches but encrypted block does not, really bad */
+ dr = dr->parent;
dr->state = BRS_ERROR;
- /* propagate up */
- while (dr->parent != NULL)
- {
- dr = dr->parent;
- dr->state = BRS_ERROR;
- }
- return;
}
+ return;
+ }
/* block matches */
dr->state = BRS_DOWNLOAD_DOWN;
/* set CHKs for children */
up_done = GNUNET_YES;
- chks = (const struct ContentHashKey*) block;
- for (i=0;i<dr->num_children;i++)
+ chks = (const struct ContentHashKey *) block;
+ for (i = 0; i < dr->num_children; i++)
+ {
+ drc = dr->children[i];
+ GNUNET_assert (drc->offset >= dr->offset);
+ child_block_size = GNUNET_FS_tree_compute_tree_size (drc->depth);
+ GNUNET_assert (0 == (drc->offset - dr->offset) % child_block_size);
+ chk_off = (drc->offset - dr->offset) / child_block_size;
+ if (drc->state == BRS_INIT)
{
- drc = dr->children[i];
- GNUNET_assert (drc->offset >= dr->offset);
- child_block_size = GNUNET_FS_tree_compute_tree_size (drc->depth);
- GNUNET_assert (0 == (drc->offset - dr->offset) % child_block_size);
- chk_off = (drc->offset - dr->offset) / child_block_size;
- if (drc->state == BRS_INIT)
- {
- drc->state = BRS_CHK_SET;
- drc->chk = chks[chk_off];
- try_top_down_reconstruction (dc, drc);
- }
- if (drc->state != BRS_DOWNLOAD_UP)
- up_done = GNUNET_NO; /* children not all done */
- }
+ drc->state = BRS_CHK_SET;
+ drc->chk = chks[chk_off];
+ try_top_down_reconstruction (dc, drc);
+ }
+ if (drc->state != BRS_DOWNLOAD_UP)
+ up_done = GNUNET_NO; /* children not all done */
+ }
if (up_done == GNUNET_YES)
- propagate_up (dr); /* children all done (or no children...) */
+ propagate_up (dr); /* children all done (or no children...) */
}
@@ -778,67 +694,63 @@
*/
static void
schedule_block_download (struct GNUNET_FS_DownloadContext *dc,
- struct DownloadRequest *dr)
+ struct DownloadRequest *dr)
{
unsigned int i;
switch (dr->state)
- {
- case BRS_INIT:
- GNUNET_assert (0);
- break;
- case BRS_RECONSTRUCT_DOWN:
- GNUNET_assert (0);
- break;
- case BRS_RECONSTRUCT_META_UP:
- GNUNET_assert (0);
- break;
- case BRS_RECONSTRUCT_UP:
- GNUNET_assert (0);
- break;
- case BRS_CHK_SET:
- /* normal case, start download */
- break;
- case BRS_DOWNLOAD_DOWN:
- for (i=0;i<dr->num_children;i++)
- schedule_block_download (dc, dr->children[i]);
- return;
- case BRS_DOWNLOAD_UP:
- /* We're done! */
- return;
- case BRS_ERROR:
- GNUNET_break (0);
- return;
- }
+ {
+ case BRS_INIT:
+ GNUNET_assert (0);
+ break;
+ case BRS_RECONSTRUCT_DOWN:
+ GNUNET_assert (0);
+ break;
+ case BRS_RECONSTRUCT_META_UP:
+ GNUNET_assert (0);
+ break;
+ case BRS_RECONSTRUCT_UP:
+ GNUNET_assert (0);
+ break;
+ case BRS_CHK_SET:
+ /* normal case, start download */
+ break;
+ case BRS_DOWNLOAD_DOWN:
+ for (i = 0; i < dr->num_children; i++)
+ schedule_block_download (dc, dr->children[i]);
+ return;
+ case BRS_DOWNLOAD_UP:
+ /* We're done! */
+ return;
+ case BRS_ERROR:
+ GNUNET_break (0);
+ return;
+ }
#if DEBUG_DOWNLOAD
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Scheduling download at offset %llu and depth %u for `%s'\n",
- (unsigned long long) dr->offset,
- dr->depth,
- GNUNET_h2s (&dr->chk.query));
+ "Scheduling download at offset %llu and depth %u for `%s'\n",
+ (unsigned long long) dr->offset,
+ dr->depth, GNUNET_h2s (&dr->chk.query));
#endif
if (GNUNET_NO !=
GNUNET_CONTAINER_multihashmap_contains_value (dc->active,
- &dr->chk.query,
- dr))
- return; /* already active */
+ &dr->chk.query, dr))
+ return; /* already active */
GNUNET_CONTAINER_multihashmap_put (dc->active,
- &dr->chk.query,
- dr,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
+ &dr->chk.query,
+ dr,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
if (dc->client == NULL)
- return; /* download not active */
- GNUNET_CONTAINER_DLL_insert (dc->pending_head,
- dc->pending_tail,
- dr);
+ return; /* download not active */
+ GNUNET_CONTAINER_DLL_insert (dc->pending_head, dc->pending_tail, dr);
dr->is_pending = GNUNET_YES;
if (NULL == dc->th)
dc->th = GNUNET_CLIENT_notify_transmit_ready (dc->client,
- sizeof (struct SearchMessage),
-
GNUNET_CONSTANTS_SERVICE_TIMEOUT,
- GNUNET_NO,
- &transmit_download_request,
- dc);
+ sizeof (struct
SearchMessage),
+
GNUNET_CONSTANTS_SERVICE_TIMEOUT,
+ GNUNET_NO,
+ &transmit_download_request,
+ dc);
}
@@ -855,15 +767,14 @@
* @param length number of bytes in data
* @param data contents of the file (or NULL if they were not inlined)
*/
-static void
+static void
trigger_recursive_download (void *cls,
- const char *filename,
- const struct GNUNET_FS_Uri *uri,
- const struct GNUNET_CONTAINER_MetaData *meta,
- size_t length,
- const void *data)
+ const char *filename,
+ const struct GNUNET_FS_Uri *uri,
+ const struct GNUNET_CONTAINER_MetaData *meta,
+ size_t length, const void *data)
{
- struct GNUNET_FS_DownloadContext *dc = cls;
+ struct GNUNET_FS_DownloadContext *dc = cls;
struct GNUNET_FS_DownloadContext *cpos;
char *temp_name;
char *fn;
@@ -875,129 +786,116 @@
char *sfn;
if (NULL == uri)
- return; /* entry for the directory itself */
+ return; /* entry for the directory itself */
cpos = dc->child_head;
while (cpos != NULL)
- {
- if ( (GNUNET_FS_uri_test_equal (uri,
- cpos->uri)) ||
- ( (filename != NULL) &&
- (0 == strcmp (cpos->filename,
- filename)) ) )
- break;
- cpos = cpos->next;
- }
+ {
+ if ((GNUNET_FS_uri_test_equal (uri,
+ cpos->uri)) ||
+ ((filename != NULL) && (0 == strcmp (cpos->filename, filename))))
+ break;
+ cpos = cpos->next;
+ }
if (cpos != NULL)
- return; /* already exists */
+ return; /* already exists */
fn = NULL;
if (NULL == filename)
+ {
+ fn = GNUNET_FS_meta_data_suggest_filename (meta);
+ if (fn == NULL)
{
- fn = GNUNET_FS_meta_data_suggest_filename (meta);
- if (fn == NULL)
- {
- us = GNUNET_FS_uri_to_string (uri);
- fn = GNUNET_strdup (&us [strlen (GNUNET_FS_URI_CHK_PREFIX)]);
- GNUNET_free (us);
- }
- else if (fn[0] == '.')
- {
- ext = fn;
- us = GNUNET_FS_uri_to_string (uri);
- GNUNET_asprintf (&fn,
- "%s%s",
- &us[strlen (GNUNET_FS_URI_CHK_PREFIX)], ext);
- GNUNET_free (ext);
- GNUNET_free (us);
- }
- /* change '\' to '/' (this should have happened
- during insertion, but malicious peers may
- not have done this) */
- while (NULL != (pos = strstr (fn, "\\")))
- *pos = '/';
- /* remove '../' everywhere (again, well-behaved
- peers don't do this, but don't trust that
- we did not get something nasty) */
- while (NULL != (pos = strstr (fn, "../")))
- {
- pos[0] = '_';
- pos[1] = '_';
- pos[2] = '_';
- }
- filename = fn;
+ us = GNUNET_FS_uri_to_string (uri);
+ fn = GNUNET_strdup (&us[strlen (GNUNET_FS_URI_CHK_PREFIX)]);
+ GNUNET_free (us);
}
- if (dc->filename == NULL)
+ else if (fn[0] == '.')
{
- full_name = NULL;
+ ext = fn;
+ us = GNUNET_FS_uri_to_string (uri);
+ GNUNET_asprintf (&fn,
+ "%s%s", &us[strlen (GNUNET_FS_URI_CHK_PREFIX)], ext);
+ GNUNET_free (ext);
+ GNUNET_free (us);
}
+ /* change '\' to '/' (this should have happened
+ * during insertion, but malicious peers may
+ * not have done this) */
+ while (NULL != (pos = strstr (fn, "\\")))
+ *pos = '/';
+ /* remove '../' everywhere (again, well-behaved
+ * peers don't do this, but don't trust that
+ * we did not get something nasty) */
+ while (NULL != (pos = strstr (fn, "../")))
+ {
+ pos[0] = '_';
+ pos[1] = '_';
+ pos[2] = '_';
+ }
+ filename = fn;
+ }
+ if (dc->filename == NULL)
+ {
+ full_name = NULL;
+ }
else
+ {
+ dn = GNUNET_strdup (dc->filename);
+ GNUNET_break ((strlen (dn) >= strlen (GNUNET_FS_DIRECTORY_EXT)) &&
+ (NULL !=
+ strstr (dn + strlen (dn) - strlen (GNUNET_FS_DIRECTORY_EXT),
+ GNUNET_FS_DIRECTORY_EXT)));
+ sfn = GNUNET_strdup (filename);
+ while ((strlen (sfn) > 0) && (filename[strlen (sfn) - 1] == '/'))
+ sfn[strlen (sfn) - 1] = '\0';
+ if ((strlen (dn) >= strlen (GNUNET_FS_DIRECTORY_EXT)) &&
+ (NULL !=
+ strstr (dn + strlen (dn) - strlen (GNUNET_FS_DIRECTORY_EXT),
+ GNUNET_FS_DIRECTORY_EXT)))
+ dn[strlen (dn) - strlen (GNUNET_FS_DIRECTORY_EXT)] = '\0';
+ if ((GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (meta)) &&
+ ((strlen (filename) < strlen (GNUNET_FS_DIRECTORY_EXT)) ||
+ (NULL ==
+ strstr (filename + strlen (filename) -
+ strlen (GNUNET_FS_DIRECTORY_EXT), GNUNET_FS_DIRECTORY_EXT))))
{
- dn = GNUNET_strdup (dc->filename);
- GNUNET_break ( (strlen (dn) >= strlen (GNUNET_FS_DIRECTORY_EXT)) &&
- (NULL !=
- strstr (dn + strlen(dn) - strlen(GNUNET_FS_DIRECTORY_EXT),
- GNUNET_FS_DIRECTORY_EXT)) );
- sfn = GNUNET_strdup (filename);
- while ( (strlen (sfn) > 0) &&
- (filename[strlen(sfn)-1] == '/') )
- sfn[strlen(sfn)-1] = '\0';
- if ( (strlen (dn) >= strlen (GNUNET_FS_DIRECTORY_EXT)) &&
- (NULL !=
- strstr (dn + strlen(dn) - strlen(GNUNET_FS_DIRECTORY_EXT),
- GNUNET_FS_DIRECTORY_EXT)) )
- dn[strlen(dn) - strlen (GNUNET_FS_DIRECTORY_EXT)] = '\0';
- if ( (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (meta)) &&
- ( (strlen (filename) < strlen (GNUNET_FS_DIRECTORY_EXT)) ||
- (NULL ==
- strstr (filename + strlen(filename) -
strlen(GNUNET_FS_DIRECTORY_EXT),
- GNUNET_FS_DIRECTORY_EXT)) ) )
- {
- GNUNET_asprintf (&full_name,
- "%s%s%s%s",
- dn,
- DIR_SEPARATOR_STR,
- sfn,
- GNUNET_FS_DIRECTORY_EXT);
- }
- else
- {
- GNUNET_asprintf (&full_name,
- "%s%s%s",
- dn,
- DIR_SEPARATOR_STR,
- sfn);
- }
- GNUNET_free (sfn);
- GNUNET_free (dn);
+ GNUNET_asprintf (&full_name,
+ "%s%s%s%s",
+ dn, DIR_SEPARATOR_STR, sfn, GNUNET_FS_DIRECTORY_EXT);
}
- if ( (full_name != NULL) &&
- (GNUNET_OK !=
- GNUNET_DISK_directory_create_for_file (full_name)) )
+ else
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to create directory for recursive download of
`%s'\n"),
- full_name);
- GNUNET_free (full_name);
- GNUNET_free_non_null (fn);
- return;
+ GNUNET_asprintf (&full_name, "%s%s%s", dn, DIR_SEPARATOR_STR, sfn);
}
+ GNUNET_free (sfn);
+ GNUNET_free (dn);
+ }
+ if ((full_name != NULL) &&
+ (GNUNET_OK != GNUNET_DISK_directory_create_for_file (full_name)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _
+ ("Failed to create directory for recursive download of
`%s'\n"),
+ full_name);
+ GNUNET_free (full_name);
+ GNUNET_free_non_null (fn);
+ return;
+ }
temp_name = NULL;
#if DEBUG_DOWNLOAD
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Triggering recursive download of size %llu with %u bytes MD\n",
- (unsigned long long) GNUNET_FS_uri_chk_get_file_size (uri),
- (unsigned int) GNUNET_CONTAINER_meta_data_get_serialized_size
(meta));
+ "Triggering recursive download of size %llu with %u bytes MD\n",
+ (unsigned long long) GNUNET_FS_uri_chk_get_file_size (uri),
+ (unsigned int)
+ GNUNET_CONTAINER_meta_data_get_serialized_size (meta));
#endif
GNUNET_FS_download_start (dc->h,
- uri,
- meta,
- full_name, temp_name,
- 0,
- GNUNET_FS_uri_chk_get_file_size (uri),
- dc->anonymity,
- dc->options,
- NULL,
- dc);
+ uri,
+ meta,
+ full_name, temp_name,
+ 0,
+ GNUNET_FS_uri_chk_get_file_size (uri),
+ dc->anonymity, dc->options, NULL, dc);
GNUNET_free_non_null (full_name);
GNUNET_free_non_null (temp_name);
GNUNET_free_non_null (fn);
@@ -1016,7 +914,7 @@
if (dr == NULL)
return;
- for (i=0;i<dr->num_children;i++)
+ for (i = 0; i < dr->num_children; i++)
GNUNET_FS_free_download_request_ (dr->children[i]);
GNUNET_free_non_null (dr->children);
GNUNET_free (dr);
@@ -1034,8 +932,7 @@
*/
static int
process_result_with_request (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+ const GNUNET_HashCode * key, void *value)
{
struct ProcessResultClosure *prc = cls;
struct DownloadRequest *dr = value;
@@ -1054,152 +951,132 @@
#if DEBUG_DOWNLOAD
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received block `%s' matching pending request at depth %u and
offset %llu/%llu\n",
- GNUNET_h2s (key),
- dr->depth,
- (unsigned long long) dr->offset,
- (unsigned long long) GNUNET_ntohll
(dc->uri->data.chk.file_length));
-
+ "Received block `%s' matching pending request at depth %u and
offset %llu/%llu\n",
+ GNUNET_h2s (key),
+ dr->depth,
+ (unsigned long long) dr->offset,
+ (unsigned long long) GNUNET_ntohll (dc->uri->data.
+ chk.file_length));
+
#endif
- bs = GNUNET_FS_tree_calculate_block_size (GNUNET_ntohll
(dc->uri->data.chk.file_length),
- dr->offset,
- dr->depth);
+ bs = GNUNET_FS_tree_calculate_block_size (GNUNET_ntohll
+ (dc->uri->data.chk.file_length),
+ dr->offset, dr->depth);
if (prc->size != bs)
+ {
+ GNUNET_asprintf (&dc->emsg,
+ _
+ ("Internal error or bogus download URI (expected %u bytes
at depth %u and offset %llu/%llu, got %u bytes)\n"),
+ bs, dr->depth, (unsigned long long) dr->offset,
+ (unsigned long long) GNUNET_ntohll (dc->uri->data.
+ chk.file_length),
+ prc->size);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%s", dc->emsg);
+ while (dr->parent != NULL)
{
- GNUNET_asprintf (&dc->emsg,
- _("Internal error or bogus download URI (expected %u
bytes at depth %u and offset %llu/%llu, got %u bytes)\n"),
- bs,
- dr->depth,
- (unsigned long long) dr->offset,
- (unsigned long long) GNUNET_ntohll
(dc->uri->data.chk.file_length),
- prc->size);
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "%s",
- dc->emsg);
- while (dr->parent != NULL)
- {
- dr->state = BRS_ERROR;
- dr = dr->parent;
- }
dr->state = BRS_ERROR;
- goto signal_error;
+ dr = dr->parent;
}
+ dr->state = BRS_ERROR;
+ goto signal_error;
+ }
- (void) GNUNET_CONTAINER_multihashmap_remove (dc->active,
- &prc->query,
- dr);
+ (void) GNUNET_CONTAINER_multihashmap_remove (dc->active, &prc->query, dr);
if (GNUNET_YES == dr->is_pending)
- {
- GNUNET_CONTAINER_DLL_remove (dc->pending_head,
- dc->pending_tail,
- dr);
- dr->is_pending = GNUNET_NO;
- }
+ {
+ GNUNET_CONTAINER_DLL_remove (dc->pending_head, dc->pending_tail, dr);
+ dr->is_pending = GNUNET_NO;
+ }
GNUNET_CRYPTO_hash_to_aes_key (&dr->chk.key, &skey, &iv);
- if (-1 == GNUNET_CRYPTO_aes_decrypt (prc->data,
- prc->size,
- &skey,
- &iv,
- pt))
- {
- GNUNET_break (0);
- dc->emsg = GNUNET_strdup (_("internal error decrypting content"));
- goto signal_error;
- }
+ if (-1 == GNUNET_CRYPTO_aes_decrypt (prc->data, prc->size, &skey, &iv, pt))
+ {
+ GNUNET_break (0);
+ dc->emsg = GNUNET_strdup (_("internal error decrypting content"));
+ goto signal_error;
+ }
off = compute_disk_offset (GNUNET_ntohll (dc->uri->data.chk.file_length),
- dr->offset,
- dr->depth);
+ dr->offset, dr->depth);
/* save to disk */
- if ( ( GNUNET_YES == prc->do_store) &&
- ( (dc->filename != NULL) ||
- (is_recursive_download (dc)) ) &&
- ( (dr->depth == dc->treedepth) ||
- (0 == (dc->options & GNUNET_FS_DOWNLOAD_NO_TEMPORARIES)) ) )
+ if ((GNUNET_YES == prc->do_store) &&
+ ((dc->filename != NULL) ||
+ (is_recursive_download (dc))) &&
+ ((dr->depth == dc->treedepth) ||
+ (0 == (dc->options & GNUNET_FS_DOWNLOAD_NO_TEMPORARIES))))
+ {
+ fh = GNUNET_DISK_file_open (dc->filename != NULL
+ ? dc->filename
+ : dc->temp_filename,
+ GNUNET_DISK_OPEN_READWRITE |
+ GNUNET_DISK_OPEN_CREATE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE |
+ GNUNET_DISK_PERM_GROUP_READ |
+ GNUNET_DISK_PERM_OTHER_READ);
+ if (NULL == fh)
{
- fh = GNUNET_DISK_file_open (dc->filename != NULL
- ? dc->filename
- : dc->temp_filename,
- GNUNET_DISK_OPEN_READWRITE |
- GNUNET_DISK_OPEN_CREATE,
- GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE |
- GNUNET_DISK_PERM_GROUP_READ |
- GNUNET_DISK_PERM_OTHER_READ);
- if (NULL == fh)
- {
- GNUNET_asprintf (&dc->emsg,
- _("Download failed: could not open file `%s': %s\n"),
- dc->filename,
- STRERROR (errno));
- goto signal_error;
- }
+ GNUNET_asprintf (&dc->emsg,
+ _("Download failed: could not open file `%s': %s\n"),
+ dc->filename, STRERROR (errno));
+ goto signal_error;
+ }
#if DEBUG_DOWNLOAD
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Saving decrypted block to disk at offset %llu\n",
- (unsigned long long) off);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Saving decrypted block to disk at offset %llu\n",
+ (unsigned long long) off);
#endif
- if ( (off !=
- GNUNET_DISK_file_seek (fh,
- off,
- GNUNET_DISK_SEEK_SET) ) )
- {
- GNUNET_asprintf (&dc->emsg,
- _("Failed to seek to offset %llu in file `%s':
%s\n"),
- (unsigned long long) off,
- dc->filename,
- STRERROR (errno));
- goto signal_error;
- }
- if (prc->size !=
- GNUNET_DISK_file_write (fh,
- pt,
- prc->size))
- {
- GNUNET_asprintf (&dc->emsg,
- _("Failed to write block of %u bytes at offset %llu
in file `%s': %s\n"),
- (unsigned int) prc->size,
- (unsigned long long) off,
- dc->filename,
- STRERROR (errno));
- goto signal_error;
- }
- GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (fh));
- fh = NULL;
+ if ((off != GNUNET_DISK_file_seek (fh, off, GNUNET_DISK_SEEK_SET)))
+ {
+ GNUNET_asprintf (&dc->emsg,
+ _("Failed to seek to offset %llu in file `%s': %s\n"),
+ (unsigned long long) off,
+ dc->filename, STRERROR (errno));
+ goto signal_error;
}
-
- if (dr->depth == 0)
+ if (prc->size != GNUNET_DISK_file_write (fh, pt, prc->size))
{
- /* DBLOCK, update progress and try recursion if applicable */
- app = prc->size;
- if (dr->offset < dc->offset)
- {
- /* starting offset begins in the middle of pt,
- do not count first bytes as progress */
- GNUNET_assert (app > (dc->offset - dr->offset));
- app -= (dc->offset - dr->offset);
- }
- if (dr->offset + prc->size > dc->offset + dc->length)
- {
- /* end of block is after relevant range,
- do not count last bytes as progress */
- GNUNET_assert (app > (dr->offset + prc->size) - (dc->offset +
dc->length));
- app -= (dr->offset + prc->size) - (dc->offset + dc->length);
- }
- dc->completed += app;
+ GNUNET_asprintf (&dc->emsg,
+ _
+ ("Failed to write block of %u bytes at offset %llu in
file `%s': %s\n"),
+ (unsigned int) prc->size, (unsigned long long) off,
+ dc->filename, STRERROR (errno));
+ goto signal_error;
+ }
+ GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (fh));
+ fh = NULL;
+ }
- /* do recursive download if option is set and either meta data
- says it is a directory or if no meta data is given AND filename
- ends in '.gnd' (top-level case) */
- if (is_recursive_download (dc))
- GNUNET_FS_directory_list_contents (prc->size,
- pt,
- off,
- &trigger_recursive_download,
- dc);
-
+ if (dr->depth == 0)
+ {
+ /* DBLOCK, update progress and try recursion if applicable */
+ app = prc->size;
+ if (dr->offset < dc->offset)
+ {
+ /* starting offset begins in the middle of pt,
+ * do not count first bytes as progress */
+ GNUNET_assert (app > (dc->offset - dr->offset));
+ app -= (dc->offset - dr->offset);
}
+ if (dr->offset + prc->size > dc->offset + dc->length)
+ {
+ /* end of block is after relevant range,
+ * do not count last bytes as progress */
+ GNUNET_assert (app >
+ (dr->offset + prc->size) - (dc->offset + dc->length));
+ app -= (dr->offset + prc->size) - (dc->offset + dc->length);
+ }
+ dc->completed += app;
+
+ /* do recursive download if option is set and either meta data
+ * says it is a directory or if no meta data is given AND filename
+ * ends in '.gnd' (top-level case) */
+ if (is_recursive_download (dc))
+ GNUNET_FS_directory_list_contents (prc->size,
+ pt,
+ off, &trigger_recursive_download, dc);
+
+ }
dr->state = BRS_DOWNLOAD_DOWN;
pi.status = GNUNET_FS_STATUS_DOWNLOAD_PROGRESS;
pi.value.download.specifics.progress.data = pt;
@@ -1208,84 +1085,83 @@
pi.value.download.specifics.progress.depth = dr->depth;
GNUNET_FS_download_make_status_ (&pi, dc);
GNUNET_assert (dc->completed <= dc->length);
- if (dr->depth == 0)
+ if (dr->depth == 0)
propagate_up (dr);
if (dc->completed == dc->length)
- {
- /* download completed, signal */
+ {
+ /* download completed, signal */
#if DEBUG_DOWNLOAD
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Download completed, truncating file to desired length
%llu\n",
- (unsigned long long) GNUNET_ntohll
(dc->uri->data.chk.file_length));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Download completed, truncating file to desired length %llu\n",
+ (unsigned long long) GNUNET_ntohll (dc->uri->data.
+ chk.file_length));
#endif
- /* truncate file to size (since we store IBlocks at the end) */
- if (dc->filename != NULL)
- {
- if (0 != truncate (dc->filename,
- GNUNET_ntohll (dc->uri->data.chk.file_length)))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
- "truncate",
- dc->filename);
- }
- GNUNET_assert (dr->depth == 0);
- check_completed (dc);
- }
- if (dr->depth == 0)
+ /* truncate file to size (since we store IBlocks at the end) */
+ if (dc->filename != NULL)
{
- /* bottom of the tree, no child downloads possible, just sync */
- GNUNET_FS_download_sync_ (dc);
- return GNUNET_YES;
+ if (0 != truncate (dc->filename,
+ GNUNET_ntohll (dc->uri->data.chk.file_length)))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
+ "truncate", dc->filename);
}
+ GNUNET_assert (dr->depth == 0);
+ check_completed (dc);
+ }
+ if (dr->depth == 0)
+ {
+ /* bottom of the tree, no child downloads possible, just sync */
+ GNUNET_FS_download_sync_ (dc);
+ return GNUNET_YES;
+ }
#if DEBUG_DOWNLOAD
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Triggering downloads of children (this block was at depth %u and
offset %llu)\n",
- dr->depth,
- (unsigned long long) dr->offset);
+ "Triggering downloads of children (this block was at depth %u
and offset %llu)\n",
+ dr->depth, (unsigned long long) dr->offset);
#endif
- GNUNET_assert (0 == (prc->size % sizeof(struct ContentHashKey)));
- chkarr = (struct ContentHashKey*) pt;
- for (i=(prc->size / sizeof(struct ContentHashKey))-1;i>=0;i--)
+ GNUNET_assert (0 == (prc->size % sizeof (struct ContentHashKey)));
+ chkarr = (struct ContentHashKey *) pt;
+ for (i = (prc->size / sizeof (struct ContentHashKey)) - 1; i >= 0; i--)
+ {
+ drc = dr->children[i];
+ switch (drc->state)
{
- drc = dr->children[i];
- switch (drc->state)
- {
- case BRS_INIT:
- drc->chk = chkarr[i];
- drc->state = BRS_CHK_SET;
- schedule_block_download (dc, drc);
- break;
- case BRS_RECONSTRUCT_DOWN:
- GNUNET_assert (0);
- break;
- case BRS_RECONSTRUCT_META_UP:
- GNUNET_assert (0);
- break;
- case BRS_RECONSTRUCT_UP:
- GNUNET_assert (0);
- break;
- case BRS_CHK_SET:
- GNUNET_assert (0);
- break;
- case BRS_DOWNLOAD_DOWN:
- GNUNET_assert (0);
- break;
- case BRS_DOWNLOAD_UP:
- GNUNET_assert (0);
- break;
- case BRS_ERROR:
- GNUNET_assert (0);
- break;
- default:
- GNUNET_assert (0);
- break;
- }
+ case BRS_INIT:
+ drc->chk = chkarr[i];
+ drc->state = BRS_CHK_SET;
+ schedule_block_download (dc, drc);
+ break;
+ case BRS_RECONSTRUCT_DOWN:
+ GNUNET_assert (0);
+ break;
+ case BRS_RECONSTRUCT_META_UP:
+ GNUNET_assert (0);
+ break;
+ case BRS_RECONSTRUCT_UP:
+ GNUNET_assert (0);
+ break;
+ case BRS_CHK_SET:
+ GNUNET_assert (0);
+ break;
+ case BRS_DOWNLOAD_DOWN:
+ GNUNET_assert (0);
+ break;
+ case BRS_DOWNLOAD_UP:
+ GNUNET_assert (0);
+ break;
+ case BRS_ERROR:
+ GNUNET_assert (0);
+ break;
+ default:
+ GNUNET_assert (0);
+ break;
}
+ }
GNUNET_FS_download_sync_ (dc);
return GNUNET_YES;
- signal_error:
+signal_error:
if (fh != NULL)
GNUNET_DISK_file_close (fh);
pi.status = GNUNET_FS_STATUS_DOWNLOAD_ERROR;
@@ -1293,10 +1169,10 @@
GNUNET_FS_download_make_status_ (&pi, dc);
/* abort all pending requests */
if (NULL != dc->th)
- {
- GNUNET_CLIENT_notify_transmit_ready_cancel (dc->th);
- dc->th = NULL;
- }
+ {
+ GNUNET_CLIENT_notify_transmit_ready_cancel (dc->th);
+ dc->th = NULL;
+ }
GNUNET_CLIENT_disconnect (dc->client, GNUNET_NO);
dc->in_receive = GNUNET_NO;
dc->client = NULL;
@@ -1321,9 +1197,7 @@
*/
static void
process_result (struct GNUNET_FS_DownloadContext *dc,
- enum GNUNET_BLOCK_Type type,
- const void *data,
- size_t size)
+ enum GNUNET_BLOCK_Type type, const void *data, size_t size)
{
struct ProcessResultClosure prc;
@@ -1335,14 +1209,13 @@
GNUNET_CRYPTO_hash (data, size, &prc.query);
#if DEBUG_DOWNLOAD
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received result for query `%s' from `%s'-service\n",
- GNUNET_h2s (&prc.query),
- "FS");
+ "Received result for query `%s' from `%s'-service\n",
+ GNUNET_h2s (&prc.query), "FS");
#endif
GNUNET_CONTAINER_multihashmap_get_multiple (dc->active,
- &prc.query,
- &process_result_with_request,
- &prc);
+ &prc.query,
+ &process_result_with_request,
+ &prc);
}
@@ -1353,35 +1226,30 @@
* @param cls closure
* @param msg message received, NULL on timeout or fatal error
*/
-static void
-receive_results (void *cls,
- const struct GNUNET_MessageHeader * msg)
+static void
+receive_results (void *cls, const struct GNUNET_MessageHeader *msg)
{
struct GNUNET_FS_DownloadContext *dc = cls;
const struct PutMessage *cm;
uint16_t msize;
- if ( (NULL == msg) ||
- (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_FS_PUT) ||
- (sizeof (struct PutMessage) > ntohs(msg->size)) )
- {
- GNUNET_break (msg == NULL);
- try_reconnect (dc);
- return;
- }
- msize = ntohs(msg->size);
- cm = (const struct PutMessage*) msg;
- process_result (dc,
- ntohl (cm->type),
- &cm[1],
- msize - sizeof (struct PutMessage));
+ if ((NULL == msg) ||
+ (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_FS_PUT) ||
+ (sizeof (struct PutMessage) > ntohs (msg->size)))
+ {
+ GNUNET_break (msg == NULL);
+ try_reconnect (dc);
+ return;
+ }
+ msize = ntohs (msg->size);
+ cm = (const struct PutMessage *) msg;
+ process_result (dc,
+ ntohl (cm->type), &cm[1], msize - sizeof (struct
PutMessage));
if (dc->client == NULL)
- return; /* fatal error */
+ return; /* fatal error */
/* continue receiving */
GNUNET_CLIENT_receive (dc->client,
- &receive_results,
- dc,
- GNUNET_TIME_UNIT_FOREVER_REL);
+ &receive_results, dc, GNUNET_TIME_UNIT_FOREVER_REL);
}
@@ -1398,9 +1266,7 @@
* @return number of bytes written to buf
*/
static size_t
-transmit_download_request (void *cls,
- size_t size,
- void *buf)
+transmit_download_request (void *cls, size_t size, void *buf)
{
struct GNUNET_FS_DownloadContext *dc = cls;
size_t msize;
@@ -1409,65 +1275,60 @@
dc->th = NULL;
if (NULL == buf)
- {
+ {
#if DEBUG_DOWNLOAD
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitting download request failed, trying to
reconnect\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Transmitting download request failed, trying to reconnect\n");
#endif
- try_reconnect (dc);
- return 0;
- }
+ try_reconnect (dc);
+ return 0;
+ }
GNUNET_assert (size >= sizeof (struct SearchMessage));
msize = 0;
sm = buf;
- while ( (NULL != (dr = dc->pending_head)) &&
- (size >= msize + sizeof (struct SearchMessage)) )
- {
+ while ((NULL != (dr = dc->pending_head)) &&
+ (size >= msize + sizeof (struct SearchMessage)))
+ {
#if DEBUG_DOWNLOAD
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitting download request for `%s' to `%s'-service\n",
- GNUNET_h2s (&dr->chk.query),
- "FS");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Transmitting download request for `%s' to `%s'-service\n",
+ GNUNET_h2s (&dr->chk.query), "FS");
#endif
- memset (sm, 0, sizeof (struct SearchMessage));
- sm->header.size = htons (sizeof (struct SearchMessage));
- sm->header.type = htons (GNUNET_MESSAGE_TYPE_FS_START_SEARCH);
- if (0 != (dc->options & GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY))
- sm->options = htonl (1);
- else
- sm->options = htonl (0);
- if (dr->depth == 0)
- sm->type = htonl (GNUNET_BLOCK_TYPE_FS_DBLOCK);
- else
- sm->type = htonl (GNUNET_BLOCK_TYPE_FS_IBLOCK);
- sm->anonymity_level = htonl (dc->anonymity);
- sm->target = dc->target.hashPubKey;
- sm->query = dr->chk.query;
- GNUNET_CONTAINER_DLL_remove (dc->pending_head,
- dc->pending_tail,
- dr);
- dr->is_pending = GNUNET_NO;
- msize += sizeof (struct SearchMessage);
- sm++;
- }
+ memset (sm, 0, sizeof (struct SearchMessage));
+ sm->header.size = htons (sizeof (struct SearchMessage));
+ sm->header.type = htons (GNUNET_MESSAGE_TYPE_FS_START_SEARCH);
+ if (0 != (dc->options & GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY))
+ sm->options = htonl (1);
+ else
+ sm->options = htonl (0);
+ if (dr->depth == 0)
+ sm->type = htonl (GNUNET_BLOCK_TYPE_FS_DBLOCK);
+ else
+ sm->type = htonl (GNUNET_BLOCK_TYPE_FS_IBLOCK);
+ sm->anonymity_level = htonl (dc->anonymity);
+ sm->target = dc->target.hashPubKey;
+ sm->query = dr->chk.query;
+ GNUNET_CONTAINER_DLL_remove (dc->pending_head, dc->pending_tail, dr);
+ dr->is_pending = GNUNET_NO;
+ msize += sizeof (struct SearchMessage);
+ sm++;
+ }
if (dc->pending_head != NULL)
- {
- dc->th = GNUNET_CLIENT_notify_transmit_ready (dc->client,
- sizeof (struct
SearchMessage),
-
GNUNET_CONSTANTS_SERVICE_TIMEOUT,
- GNUNET_NO,
- &transmit_download_request,
- dc);
- GNUNET_assert (dc->th != NULL);
- }
+ {
+ dc->th = GNUNET_CLIENT_notify_transmit_ready (dc->client,
+ sizeof (struct
SearchMessage),
+
GNUNET_CONSTANTS_SERVICE_TIMEOUT,
+ GNUNET_NO,
+ &transmit_download_request,
+ dc);
+ GNUNET_assert (dc->th != NULL);
+ }
if (GNUNET_NO == dc->in_receive)
- {
- dc->in_receive = GNUNET_YES;
- GNUNET_CLIENT_receive (dc->client,
- &receive_results,
- dc,
- GNUNET_TIME_UNIT_FOREVER_REL);
- }
+ {
+ dc->in_receive = GNUNET_YES;
+ GNUNET_CLIENT_receive (dc->client,
+ &receive_results, dc, GNUNET_TIME_UNIT_FOREVER_REL);
+ }
return msize;
}
@@ -1479,34 +1340,31 @@
* @param tc unused
*/
static void
-do_reconnect (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_FS_DownloadContext *dc = cls;
struct GNUNET_CLIENT_Connection *client;
-
+
dc->task = GNUNET_SCHEDULER_NO_TASK;
- client = GNUNET_CLIENT_connect ("fs",
- dc->h->cfg);
+ client = GNUNET_CLIENT_connect ("fs", dc->h->cfg);
if (NULL == client)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Connecting to `%s'-service failed, will try again.\n",
- "FS");
- try_reconnect (dc);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Connecting to `%s'-service failed, will try again.\n", "FS");
+ try_reconnect (dc);
+ return;
+ }
dc->client = client;
if (dc->pending_head != NULL)
- {
- dc->th = GNUNET_CLIENT_notify_transmit_ready (client,
- sizeof (struct
SearchMessage),
-
GNUNET_CONSTANTS_SERVICE_TIMEOUT,
- GNUNET_NO,
- &transmit_download_request,
- dc);
- GNUNET_assert (dc->th != NULL);
- }
+ {
+ dc->th = GNUNET_CLIENT_notify_transmit_ready (client,
+ sizeof (struct
SearchMessage),
+
GNUNET_CONSTANTS_SERVICE_TIMEOUT,
+ GNUNET_NO,
+ &transmit_download_request,
+ dc);
+ GNUNET_assert (dc->th != NULL);
+ }
}
@@ -1519,18 +1377,14 @@
* @return GNUNET_OK
*/
static int
-retry_entry (void *cls,
- const GNUNET_HashCode *key,
- void *entry)
+retry_entry (void *cls, const GNUNET_HashCode * key, void *entry)
{
struct GNUNET_FS_DownloadContext *dc = cls;
struct DownloadRequest *dr = entry;
dr->next = NULL;
dr->prev = NULL;
- GNUNET_CONTAINER_DLL_insert (dc->pending_head,
- dc->pending_tail,
- dr);
+ GNUNET_CONTAINER_DLL_insert (dc->pending_head, dc->pending_tail, dr);
dr->is_pending = GNUNET_YES;
return GNUNET_OK;
}
@@ -1546,36 +1400,32 @@
static void
try_reconnect (struct GNUNET_FS_DownloadContext *dc)
{
-
+
if (NULL != dc->client)
- {
+ {
#if DEBUG_DOWNLOAD
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Moving all requests back to pending list\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Moving all requests back to pending list\n");
#endif
- if (NULL != dc->th)
- {
- GNUNET_CLIENT_notify_transmit_ready_cancel (dc->th);
- dc->th = NULL;
- }
- /* full reset of the pending list */
- dc->pending_head = NULL;
- dc->pending_tail = NULL;
- GNUNET_CONTAINER_multihashmap_iterate (dc->active,
- &retry_entry,
- dc);
- GNUNET_CLIENT_disconnect (dc->client, GNUNET_NO);
- dc->in_receive = GNUNET_NO;
- dc->client = NULL;
+ if (NULL != dc->th)
+ {
+ GNUNET_CLIENT_notify_transmit_ready_cancel (dc->th);
+ dc->th = NULL;
}
+ /* full reset of the pending list */
+ dc->pending_head = NULL;
+ dc->pending_tail = NULL;
+ GNUNET_CONTAINER_multihashmap_iterate (dc->active, &retry_entry, dc);
+ GNUNET_CLIENT_disconnect (dc->client, GNUNET_NO);
+ dc->in_receive = GNUNET_NO;
+ dc->client = NULL;
+ }
#if DEBUG_DOWNLOAD
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Will try to reconnect in 1s\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Will try to reconnect in 1s\n");
#endif
dc->task
- = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
- &do_reconnect,
- dc);
+ = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &do_reconnect, dc);
}
@@ -1586,15 +1436,13 @@
* @param client handle to use for communcation with FS (we must destroy it!)
*/
static void
-activate_fs_download (void *cls,
- struct GNUNET_CLIENT_Connection *client)
+activate_fs_download (void *cls, struct GNUNET_CLIENT_Connection *client)
{
struct GNUNET_FS_DownloadContext *dc = cls;
struct GNUNET_FS_ProgressInfo pi;
#if DEBUG_DOWNLOAD
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Download activated\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download activated\n");
#endif
GNUNET_assert (NULL != client);
GNUNET_assert (dc->client == NULL);
@@ -1604,23 +1452,21 @@
GNUNET_FS_download_make_status_ (&pi, dc);
dc->pending_head = NULL;
dc->pending_tail = NULL;
- GNUNET_CONTAINER_multihashmap_iterate (dc->active,
- &retry_entry,
- dc);
+ GNUNET_CONTAINER_multihashmap_iterate (dc->active, &retry_entry, dc);
#if DEBUG_DOWNLOAD
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Asking for transmission to FS service\n");
+ "Asking for transmission to FS service\n");
#endif
if (dc->pending_head != NULL)
- {
- dc->th = GNUNET_CLIENT_notify_transmit_ready (dc->client,
- sizeof (struct
SearchMessage),
-
GNUNET_CONSTANTS_SERVICE_TIMEOUT,
- GNUNET_NO,
- &transmit_download_request,
- dc);
- GNUNET_assert (dc->th != NULL);
- }
+ {
+ dc->th = GNUNET_CLIENT_notify_transmit_ready (dc->client,
+ sizeof (struct
SearchMessage),
+
GNUNET_CONSTANTS_SERVICE_TIMEOUT,
+ GNUNET_NO,
+ &transmit_download_request,
+ dc);
+ GNUNET_assert (dc->th != NULL);
+ }
}
@@ -1636,20 +1482,19 @@
struct GNUNET_FS_ProgressInfo pi;
#if DEBUG_DOWNLOAD
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Download deactivated\n");
-#endif
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download deactivated\n");
+#endif
if (NULL != dc->th)
- {
- GNUNET_CLIENT_notify_transmit_ready_cancel (dc->th);
- dc->th = NULL;
- }
+ {
+ GNUNET_CLIENT_notify_transmit_ready_cancel (dc->th);
+ dc->th = NULL;
+ }
if (NULL != dc->client)
- {
- GNUNET_CLIENT_disconnect (dc->client, GNUNET_NO);
- dc->in_receive = GNUNET_NO;
- dc->client = NULL;
- }
+ {
+ GNUNET_CLIENT_disconnect (dc->client, GNUNET_NO);
+ dc->in_receive = GNUNET_NO;
+ dc->client = NULL;
+ }
dc->pending_head = NULL;
dc->pending_tail = NULL;
pi.status = GNUNET_FS_STATUS_DOWNLOAD_INACTIVE;
@@ -1677,54 +1522,55 @@
*/
static struct DownloadRequest *
create_download_request (struct DownloadRequest *parent,
- unsigned int depth,
- uint64_t dr_offset,
- uint64_t file_start_offset,
- uint64_t desired_length)
+ unsigned int depth,
+ uint64_t dr_offset,
+ uint64_t file_start_offset, uint64_t desired_length)
{
struct DownloadRequest *dr;
unsigned int i;
unsigned int head_skip;
uint64_t child_block_size;
-
+
dr = GNUNET_malloc (sizeof (struct DownloadRequest));
dr->parent = parent;
dr->depth = depth;
dr->offset = dr_offset;
if (depth > 0)
- {
- child_block_size = GNUNET_FS_tree_compute_tree_size (depth - 1);
-
- /* calculate how many blocks at this level are not interesting
- from the start (rounded down), either because of the requested
- file offset or because this IBlock is further along */
- if (dr_offset < file_start_offset)
- head_skip = file_start_offset / child_block_size;
- else
- head_skip = dr_offset / child_block_size;
+ {
+ child_block_size = GNUNET_FS_tree_compute_tree_size (depth - 1);
- /* calculate index of last block at this level that is interesting
(rounded up) */
- dr->num_children = file_start_offset + desired_length / child_block_size;
- if (dr->num_children * child_block_size < file_start_offset +
desired_length)
- dr->num_children++; /* round up */
+ /* calculate how many blocks at this level are not interesting
+ * from the start (rounded down), either because of the requested
+ * file offset or because this IBlock is further along */
+ if (dr_offset < file_start_offset)
+ head_skip = file_start_offset / child_block_size;
+ else
+ head_skip = dr_offset / child_block_size;
- /* now we can get the total number of children for this block */
- dr->num_children -= head_skip;
- if (dr->num_children > CHK_PER_INODE)
- dr->num_children = CHK_PER_INODE; /* cap at max */
+ /* calculate index of last block at this level that is interesting
(rounded up) */
+ dr->num_children = file_start_offset + desired_length / child_block_size;
+ if (dr->num_children * child_block_size <
+ file_start_offset + desired_length)
+ dr->num_children++; /* round up */
- /* why else would we have gotten here to begin with? (that'd be a bad
logic error) */
- GNUNET_assert (dr->num_children > 0);
+ /* now we can get the total number of children for this block */
+ dr->num_children -= head_skip;
+ if (dr->num_children > CHK_PER_INODE)
+ dr->num_children = CHK_PER_INODE; /* cap at max */
- dr->children = GNUNET_malloc (dr->num_children *
- sizeof (struct DownloadRequest *));
- for (i=0;i<dr->num_children;i++)
- dr->children[i] = create_download_request (dr,
- depth - 1,
- dr_offset + i *
child_block_size,
- file_start_offset,
- desired_length);
- }
+ /* why else would we have gotten here to begin with? (that'd be a bad
logic error) */
+ GNUNET_assert (dr->num_children > 0);
+
+ dr->children = GNUNET_malloc (dr->num_children *
+ sizeof (struct DownloadRequest *));
+ for (i = 0; i < dr->num_children; i++)
+ dr->children[i] = create_download_request (dr,
+ depth - 1,
+ dr_offset +
+ i * child_block_size,
+ file_start_offset,
+ desired_length);
+ }
return dr;
}
@@ -1737,30 +1583,28 @@
* @param tc scheduler context
*/
static void
-reconstruct_cont (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+reconstruct_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_FS_DownloadContext *dc = cls;
/* clean up state from tree encoder */
if (dc->te != NULL)
- {
- GNUNET_FS_tree_encoder_finish (dc->te, NULL, NULL);
- dc->te = NULL;
- }
+ {
+ GNUNET_FS_tree_encoder_finish (dc->te, NULL, NULL);
+ dc->te = NULL;
+ }
if (dc->task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (dc->task);
- dc->task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (dc->task);
+ dc->task = GNUNET_SCHEDULER_NO_TASK;
+ }
if (dc->rfh != NULL)
- {
- GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (dc->rfh));
- dc->rfh = NULL;
- }
+ {
+ GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (dc->rfh));
+ dc->rfh = NULL;
+ }
/* start "normal" download */
- schedule_block_download (dc,
- dc->top_request);
+ schedule_block_download (dc, dc->top_request);
}
@@ -1771,8 +1615,7 @@
* @param tc task context
*/
static void
-get_next_block (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+get_next_block (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_FS_DownloadContext *dc = cls;
@@ -1799,14 +1642,13 @@
* @param block the (encrypted) block
* @param block_size size of block (in bytes)
*/
-static void
+static void
reconstruct_cb (void *cls,
- const struct ContentHashKey *chk,
- uint64_t offset,
- unsigned int depth,
- enum GNUNET_BLOCK_Type type,
- const void *block,
- uint16_t block_size)
+ const struct ContentHashKey *chk,
+ uint64_t offset,
+ unsigned int depth,
+ enum GNUNET_BLOCK_Type type,
+ const void *block, uint16_t block_size)
{
struct GNUNET_FS_DownloadContext *dc = cls;
struct GNUNET_FS_ProgressInfo pi;
@@ -1817,67 +1659,62 @@
/* find corresponding request entry */
dr = dc->top_request;
while (dr->depth > depth)
+ {
+ blen = GNUNET_FS_tree_compute_tree_size (dr->depth);
+ chld = (offset - dr->offset) / blen;
+ GNUNET_assert (chld < dr->num_children);
+ dr = dr->children[chld];
+ }
+ switch (dr->state)
+ {
+ case BRS_INIT:
+ break;
+ case BRS_RECONSTRUCT_DOWN:
+ break;
+ case BRS_RECONSTRUCT_META_UP:
+ break;
+ case BRS_RECONSTRUCT_UP:
+ break;
+ case BRS_CHK_SET:
+ if (0 == memcmp (chk, &dr->chk, sizeof (struct ContentHashKey)))
{
+ /* block matches, hence tree below matches;
+ * this request is done! */
+ dr->state = BRS_DOWNLOAD_UP;
+ /* calculate how many bytes of payload this block
+ * corresponds to */
blen = GNUNET_FS_tree_compute_tree_size (dr->depth);
- chld = (offset - dr->offset) / blen;
- GNUNET_assert (chld < dr->num_children);
- dr = dr->children[chld];
+ /* how many of those bytes are in the requested range? */
+ blen = GNUNET_MIN (blen, dc->length + dc->offset - dr->offset);
+ /* signal progress */
+ dc->completed += blen;
+ pi.status = GNUNET_FS_STATUS_DOWNLOAD_PROGRESS;
+ pi.value.download.specifics.progress.data = NULL;
+ pi.value.download.specifics.progress.offset = offset;
+ pi.value.download.specifics.progress.data_len = 0;
+ pi.value.download.specifics.progress.depth = 0;
+ GNUNET_FS_download_make_status_ (&pi, dc);
}
- switch (dr->state)
+ else
{
- case BRS_INIT:
- break;
- case BRS_RECONSTRUCT_DOWN:
- break;
- case BRS_RECONSTRUCT_META_UP:
- break;
- case BRS_RECONSTRUCT_UP:
- break;
- case BRS_CHK_SET:
- if (0 == memcmp (chk,
- &dr->chk,
- sizeof (struct ContentHashKey)))
- {
- /* block matches, hence tree below matches;
- this request is done! */
- dr->state = BRS_DOWNLOAD_UP;
- /* calculate how many bytes of payload this block
- corresponds to */
- blen = GNUNET_FS_tree_compute_tree_size (dr->depth);
- /* how many of those bytes are in the requested range? */
- blen = GNUNET_MIN (blen,
- dc->length + dc->offset - dr->offset);
- /* signal progress */
- dc->completed += blen;
- pi.status = GNUNET_FS_STATUS_DOWNLOAD_PROGRESS;
- pi.value.download.specifics.progress.data = NULL;
- pi.value.download.specifics.progress.offset = offset;
- pi.value.download.specifics.progress.data_len = 0;
- pi.value.download.specifics.progress.depth = 0;
- GNUNET_FS_download_make_status_ (&pi, dc);
- }
- else
- {
- }
- break;
- case BRS_DOWNLOAD_DOWN:
- break;
- case BRS_DOWNLOAD_UP:
- break;
- case BRS_ERROR:
- break;
- default:
- GNUNET_assert (0);
- break;
}
- if ( (dr == dc->top_request) &&
- (dr->state == BRS_DOWNLOAD_UP) )
- {
- check_completed (dc);
- return;
- }
- dc->task = GNUNET_SCHEDULER_add_now (&get_next_block,
- dc);
+ break;
+ case BRS_DOWNLOAD_DOWN:
+ break;
+ case BRS_DOWNLOAD_UP:
+ break;
+ case BRS_ERROR:
+ break;
+ default:
+ GNUNET_assert (0);
+ break;
+ }
+ if ((dr == dc->top_request) && (dr->state == BRS_DOWNLOAD_UP))
+ {
+ check_completed (dc);
+ return;
+ }
+ dc->task = GNUNET_SCHEDULER_add_now (&get_next_block, dc);
}
@@ -1894,31 +1731,24 @@
* @return number of bytes copied to buf, 0 on error
*/
static size_t
-fh_reader (void *cls,
- uint64_t offset,
- size_t max,
- void *buf,
- char **emsg)
+fh_reader (void *cls, uint64_t offset, size_t max, void *buf, char **emsg)
{
struct GNUNET_FS_DownloadContext *dc = cls;
struct GNUNET_DISK_FileHandle *fh = dc->rfh;
ssize_t ret;
*emsg = NULL;
- if (offset !=
- GNUNET_DISK_file_seek (fh,
- offset,
- GNUNET_DISK_SEEK_SET))
- {
- *emsg = GNUNET_strdup (strerror (errno));
- return 0;
- }
+ if (offset != GNUNET_DISK_file_seek (fh, offset, GNUNET_DISK_SEEK_SET))
+ {
+ *emsg = GNUNET_strdup (strerror (errno));
+ return 0;
+ }
ret = GNUNET_DISK_file_read (fh, buf, max);
if (ret < 0)
- {
- *emsg = GNUNET_strdup (strerror (errno));
- return 0;
- }
+ {
+ *emsg = GNUNET_strdup (strerror (errno));
+ return 0;
+ }
return ret;
}
@@ -1932,149 +1762,141 @@
*/
void
GNUNET_FS_download_start_task_ (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- struct GNUNET_FS_DownloadContext *dc = cls;
+ struct GNUNET_FS_DownloadContext *dc = cls;
struct GNUNET_FS_ProgressInfo pi;
struct GNUNET_DISK_FileHandle *fh;
#if DEBUG_DOWNLOAD
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Start task running...\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Start task running...\n");
#endif
dc->task = GNUNET_SCHEDULER_NO_TASK;
if (dc->length == 0)
+ {
+ /* no bytes required! */
+ if (dc->filename != NULL)
{
- /* no bytes required! */
- if (dc->filename != NULL)
- {
- fh = GNUNET_DISK_file_open (dc->filename,
- GNUNET_DISK_OPEN_READWRITE |
- GNUNET_DISK_OPEN_CREATE |
- ( (0 == GNUNET_FS_uri_chk_get_file_size
(dc->uri))
- ? GNUNET_DISK_OPEN_TRUNCATE : 0),
- GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE |
- GNUNET_DISK_PERM_GROUP_READ |
- GNUNET_DISK_PERM_OTHER_READ);
- GNUNET_DISK_file_close (fh);
- }
- GNUNET_FS_download_sync_ (dc);
- check_completed (dc);
- return;
+ fh = GNUNET_DISK_file_open (dc->filename,
+ GNUNET_DISK_OPEN_READWRITE |
+ GNUNET_DISK_OPEN_CREATE |
+ ((0 ==
+ GNUNET_FS_uri_chk_get_file_size (dc->uri))
?
+ GNUNET_DISK_OPEN_TRUNCATE : 0),
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE |
+ GNUNET_DISK_PERM_GROUP_READ |
+ GNUNET_DISK_PERM_OTHER_READ);
+ GNUNET_DISK_file_close (fh);
}
- if (dc->emsg != NULL)
+ GNUNET_FS_download_sync_ (dc);
+ check_completed (dc);
return;
+ }
+ if (dc->emsg != NULL)
+ return;
if (dc->top_request == NULL)
- {
- dc->top_request = create_download_request (NULL, dc->treedepth - 1, 0,
- dc->offset, dc->length);
- dc->top_request->state = BRS_CHK_SET;
- dc->top_request->chk = (dc->uri->type == chk)
- ? dc->uri->data.chk.chk
- : dc->uri->data.loc.fi.chk;
- /* signal start */
- GNUNET_FS_download_sync_ (dc);
- pi.status = GNUNET_FS_STATUS_DOWNLOAD_START;
- pi.value.download.specifics.start.meta = dc->meta;
- GNUNET_FS_download_make_status_ (&pi, dc);
- }
+ {
+ dc->top_request = create_download_request (NULL, dc->treedepth - 1, 0,
+ dc->offset, dc->length);
+ dc->top_request->state = BRS_CHK_SET;
+ dc->top_request->chk = (dc->uri->type == chk)
+ ? dc->uri->data.chk.chk : dc->uri->data.loc.fi.chk;
+ /* signal start */
+ GNUNET_FS_download_sync_ (dc);
+ pi.status = GNUNET_FS_STATUS_DOWNLOAD_START;
+ pi.value.download.specifics.start.meta = dc->meta;
+ GNUNET_FS_download_make_status_ (&pi, dc);
+ }
GNUNET_FS_download_start_downloading_ (dc);
/* attempt reconstruction from disk */
- if (GNUNET_YES == GNUNET_DISK_file_test (dc->filename))
+ if (GNUNET_YES == GNUNET_DISK_file_test (dc->filename))
dc->rfh = GNUNET_DISK_file_open (dc->filename,
- GNUNET_DISK_OPEN_READ,
- GNUNET_DISK_PERM_NONE);
+ GNUNET_DISK_OPEN_READ,
+ GNUNET_DISK_PERM_NONE);
if (dc->top_request->state == BRS_CHK_SET)
+ {
+ if (dc->rfh != NULL)
{
- if (dc->rfh != NULL)
- {
- /* first, try top-down */
+ /* first, try top-down */
#if DEBUG_DOWNLOAD
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Trying top-down reconstruction for `%s'\n",
- dc->filename);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Trying top-down reconstruction for `%s'\n", dc->filename);
#endif
- try_top_down_reconstruction (dc, dc->top_request);
- switch (dc->top_request->state)
- {
- case BRS_CHK_SET:
- break; /* normal */
- case BRS_DOWNLOAD_DOWN:
- break; /* normal, some blocks already down */
- case BRS_DOWNLOAD_UP:
- /* already done entirely, party! */
- if (dc->rfh != NULL)
- {
- /* avoid hanging on to file handle longer than
- necessary */
- GNUNET_DISK_file_close (dc->rfh);
- dc->rfh = NULL;
- }
- return;
- case BRS_ERROR:
- GNUNET_asprintf (&dc->emsg,
- _("Invalid URI"));
- GNUNET_FS_download_sync_ (dc);
- pi.status = GNUNET_FS_STATUS_DOWNLOAD_ERROR;
- pi.value.download.specifics.error.message = dc->emsg;
- GNUNET_FS_download_make_status_ (&pi, dc);
- return;
- default:
- GNUNET_assert (0);
- break;
- }
- }
+ try_top_down_reconstruction (dc, dc->top_request);
+ switch (dc->top_request->state)
+ {
+ case BRS_CHK_SET:
+ break; /* normal */
+ case BRS_DOWNLOAD_DOWN:
+ break; /* normal, some blocks already down */
+ case BRS_DOWNLOAD_UP:
+ /* already done entirely, party! */
+ if (dc->rfh != NULL)
+ {
+ /* avoid hanging on to file handle longer than
+ * necessary */
+ GNUNET_DISK_file_close (dc->rfh);
+ dc->rfh = NULL;
+ }
+ return;
+ case BRS_ERROR:
+ GNUNET_asprintf (&dc->emsg, _("Invalid URI"));
+ GNUNET_FS_download_sync_ (dc);
+ pi.status = GNUNET_FS_STATUS_DOWNLOAD_ERROR;
+ pi.value.download.specifics.error.message = dc->emsg;
+ GNUNET_FS_download_make_status_ (&pi, dc);
+ return;
+ default:
+ GNUNET_assert (0);
+ break;
+ }
}
+ }
/* attempt reconstruction from meta data */
- if ( (GNUNET_FS_uri_chk_get_file_size (dc->uri) <= MAX_INLINE_SIZE) &&
- (NULL != dc->meta) )
- {
+ if ((GNUNET_FS_uri_chk_get_file_size (dc->uri) <= MAX_INLINE_SIZE) &&
+ (NULL != dc->meta))
+ {
#if DEBUG_DOWNLOAD
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Trying to find embedded meta data for download of size %llu
with %u bytes MD\n",
- (unsigned long long) GNUNET_FS_uri_chk_get_file_size
(dc->uri),
- (unsigned int) GNUNET_CONTAINER_meta_data_get_serialized_size
(dc->meta));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Trying to find embedded meta data for download of size %llu
with %u bytes MD\n",
+ (unsigned long long) GNUNET_FS_uri_chk_get_file_size (dc->uri),
+ (unsigned int)
+ GNUNET_CONTAINER_meta_data_get_serialized_size (dc->meta));
#endif
- GNUNET_CONTAINER_meta_data_iterate (dc->meta,
- &match_full_data,
- dc);
- if (dc->top_request->state == BRS_DOWNLOAD_UP)
- {
- if (dc->rfh != NULL)
- {
- /* avoid hanging on to file handle longer than
- necessary */
- GNUNET_DISK_file_close (dc->rfh);
- dc->rfh = NULL;
- }
- return; /* finished, status update was already done for us */
- }
+ GNUNET_CONTAINER_meta_data_iterate (dc->meta, &match_full_data, dc);
+ if (dc->top_request->state == BRS_DOWNLOAD_UP)
+ {
+ if (dc->rfh != NULL)
+ {
+ /* avoid hanging on to file handle longer than
+ * necessary */
+ GNUNET_DISK_file_close (dc->rfh);
+ dc->rfh = NULL;
+ }
+ return; /* finished, status update was already done
for us */
}
+ }
if (dc->rfh != NULL)
- {
- /* finally, try bottom-up */
+ {
+ /* finally, try bottom-up */
#if DEBUG_DOWNLOAD
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Trying bottom-up reconstruction of file `%s'\n",
- dc->filename);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Trying bottom-up reconstruction of file `%s'\n",
dc->filename);
#endif
- dc->te = GNUNET_FS_tree_encoder_create (dc->h,
- dc->old_file_size,
- dc,
- &fh_reader,
- &reconstruct_cb,
- NULL,
- &reconstruct_cont);
- dc->task = GNUNET_SCHEDULER_add_now (&get_next_block,
- dc);
- }
+ dc->te = GNUNET_FS_tree_encoder_create (dc->h,
+ dc->old_file_size,
+ dc,
+ &fh_reader,
+ &reconstruct_cb,
+ NULL, &reconstruct_cont);
+ dc->task = GNUNET_SCHEDULER_add_now (&get_next_block, dc);
+ }
else
- {
- /* simple, top-level download */
- schedule_block_download (dc,
- dc->top_request);
- }
+ {
+ /* simple, top-level download */
+ schedule_block_download (dc, dc->top_request);
+ }
if (dc->top_request->state == BRS_DOWNLOAD_UP)
check_completed (dc);
}
@@ -2095,44 +1917,43 @@
if (dc->top != NULL)
GNUNET_FS_end_top (dc->h, dc->top);
while (NULL != dc->child_head)
- GNUNET_FS_download_signal_suspend_ (dc->child_head);
+ GNUNET_FS_download_signal_suspend_ (dc->child_head);
if (dc->search != NULL)
- {
- dc->search->download = NULL;
- dc->search = NULL;
- }
+ {
+ dc->search->download = NULL;
+ dc->search = NULL;
+ }
if (dc->job_queue != NULL)
- {
- GNUNET_FS_dequeue_ (dc->job_queue);
- dc->job_queue = NULL;
- }
+ {
+ GNUNET_FS_dequeue_ (dc->job_queue);
+ dc->job_queue = NULL;
+ }
if (dc->parent != NULL)
GNUNET_CONTAINER_DLL_remove (dc->parent->child_head,
- dc->parent->child_tail,
- dc);
+ dc->parent->child_tail, dc);
if (dc->task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (dc->task);
- dc->task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (dc->task);
+ dc->task = GNUNET_SCHEDULER_NO_TASK;
+ }
pi.status = GNUNET_FS_STATUS_DOWNLOAD_SUSPEND;
GNUNET_FS_download_make_status_ (&pi, dc);
if (dc->te != NULL)
- {
- GNUNET_FS_tree_encoder_finish (dc->te, NULL, NULL);
- dc->te = NULL;
- }
+ {
+ GNUNET_FS_tree_encoder_finish (dc->te, NULL, NULL);
+ dc->te = NULL;
+ }
if (dc->rfh != NULL)
- {
- GNUNET_DISK_file_close (dc->rfh);
- dc->rfh = NULL;
- }
+ {
+ GNUNET_DISK_file_close (dc->rfh);
+ dc->rfh = NULL;
+ }
GNUNET_FS_free_download_request_ (dc->top_request);
if (dc->active != NULL)
- {
- GNUNET_CONTAINER_multihashmap_destroy (dc->active);
- dc->active = NULL;
- }
+ {
+ GNUNET_CONTAINER_multihashmap_destroy (dc->active);
+ dc->active = NULL;
+ }
GNUNET_free_non_null (dc->filename);
GNUNET_CONTAINER_meta_data_destroy (dc->meta);
GNUNET_FS_uri_destroy (dc->uri);
@@ -2174,87 +1995,77 @@
*/
struct GNUNET_FS_DownloadContext *
GNUNET_FS_download_start (struct GNUNET_FS_Handle *h,
- const struct GNUNET_FS_Uri *uri,
- const struct GNUNET_CONTAINER_MetaData *meta,
- const char *filename,
- const char *tempname,
- uint64_t offset,
- uint64_t length,
- uint32_t anonymity,
- enum GNUNET_FS_DownloadOptions options,
- void *cctx,
- struct GNUNET_FS_DownloadContext *parent)
+ const struct GNUNET_FS_Uri *uri,
+ const struct GNUNET_CONTAINER_MetaData *meta,
+ const char *filename,
+ const char *tempname,
+ uint64_t offset,
+ uint64_t length,
+ uint32_t anonymity,
+ enum GNUNET_FS_DownloadOptions options,
+ void *cctx, struct GNUNET_FS_DownloadContext *parent)
{
struct GNUNET_FS_DownloadContext *dc;
- GNUNET_assert (GNUNET_FS_uri_test_chk (uri) ||
- GNUNET_FS_uri_test_loc (uri) );
-
- if ( (offset + length < offset) ||
- (offset + length > GNUNET_FS_uri_chk_get_file_size (uri)) )
- {
- GNUNET_break (0);
- return NULL;
- }
+ GNUNET_assert (GNUNET_FS_uri_test_chk (uri) || GNUNET_FS_uri_test_loc (uri));
+
+ if ((offset + length < offset) ||
+ (offset + length > GNUNET_FS_uri_chk_get_file_size (uri)))
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
#if DEBUG_DOWNLOAD
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Starting download `%s' of %llu bytes\n",
- filename,
- (unsigned long long) length);
+ "Starting download `%s' of %llu bytes\n",
+ filename, (unsigned long long) length);
#endif
- dc = GNUNET_malloc (sizeof(struct GNUNET_FS_DownloadContext));
+ dc = GNUNET_malloc (sizeof (struct GNUNET_FS_DownloadContext));
dc->h = h;
dc->parent = parent;
if (parent != NULL)
- {
- GNUNET_CONTAINER_DLL_insert (parent->child_head,
- parent->child_tail,
- dc);
- }
+ {
+ GNUNET_CONTAINER_DLL_insert (parent->child_head, parent->child_tail, dc);
+ }
dc->uri = GNUNET_FS_uri_dup (uri);
dc->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
dc->client_info = cctx;
dc->start_time = GNUNET_TIME_absolute_get ();
if (NULL != filename)
- {
- dc->filename = GNUNET_strdup (filename);
- if (GNUNET_YES == GNUNET_DISK_file_test (filename))
- GNUNET_DISK_file_size (filename,
- &dc->old_file_size,
- GNUNET_YES);
- }
+ {
+ dc->filename = GNUNET_strdup (filename);
+ if (GNUNET_YES == GNUNET_DISK_file_test (filename))
+ GNUNET_DISK_file_size (filename, &dc->old_file_size, GNUNET_YES);
+ }
if (GNUNET_FS_uri_test_loc (dc->uri))
GNUNET_assert (GNUNET_OK ==
- GNUNET_FS_uri_loc_get_peer_identity (dc->uri,
- &dc->target));
+ GNUNET_FS_uri_loc_get_peer_identity (dc->uri, &dc->target));
dc->offset = offset;
dc->length = length;
dc->anonymity = anonymity;
dc->options = options;
- dc->active = GNUNET_CONTAINER_multihashmap_create (1 + 2 * (length /
DBLOCK_SIZE));
- dc->treedepth = GNUNET_FS_compute_depth
(GNUNET_FS_uri_chk_get_file_size(dc->uri));
- if ( (filename == NULL) &&
- (is_recursive_download (dc) ) )
- {
- if (tempname != NULL)
- dc->temp_filename = GNUNET_strdup (tempname);
- else
- dc->temp_filename = GNUNET_DISK_mktemp
("gnunet-directory-download-tmp");
- }
+ dc->active =
+ GNUNET_CONTAINER_multihashmap_create (1 + 2 * (length / DBLOCK_SIZE));
+ dc->treedepth =
+ GNUNET_FS_compute_depth (GNUNET_FS_uri_chk_get_file_size (dc->uri));
+ if ((filename == NULL) && (is_recursive_download (dc)))
+ {
+ if (tempname != NULL)
+ dc->temp_filename = GNUNET_strdup (tempname);
+ else
+ dc->temp_filename = GNUNET_DISK_mktemp ("gnunet-directory-download-tmp");
+ }
#if DEBUG_DOWNLOAD
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Download tree has depth %u\n",
- dc->treedepth);
+ "Download tree has depth %u\n", dc->treedepth);
#endif
if (parent == NULL)
- {
- dc->top = GNUNET_FS_make_top (dc->h,
- &GNUNET_FS_download_signal_suspend_,
- dc);
- }
- dc->task = GNUNET_SCHEDULER_add_now (&GNUNET_FS_download_start_task_,
- dc);
+ {
+ dc->top = GNUNET_FS_make_top (dc->h,
+ &GNUNET_FS_download_signal_suspend_, dc);
+ }
+ dc->task = GNUNET_SCHEDULER_add_now (&GNUNET_FS_download_start_task_, dc);
return dc;
}
@@ -2295,85 +2106,79 @@
*/
struct GNUNET_FS_DownloadContext *
GNUNET_FS_download_start_from_search (struct GNUNET_FS_Handle *h,
- struct GNUNET_FS_SearchResult *sr,
- const char *filename,
- const char *tempname,
- uint64_t offset,
- uint64_t length,
- uint32_t anonymity,
- enum GNUNET_FS_DownloadOptions options,
- void *cctx)
+ struct GNUNET_FS_SearchResult *sr,
+ const char *filename,
+ const char *tempname,
+ uint64_t offset,
+ uint64_t length,
+ uint32_t anonymity,
+ enum GNUNET_FS_DownloadOptions options,
+ void *cctx)
{
struct GNUNET_FS_DownloadContext *dc;
- if ( (sr == NULL) ||
- (sr->download != NULL) )
- {
- GNUNET_break (0);
- return NULL;
- }
+ if ((sr == NULL) || (sr->download != NULL))
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
GNUNET_assert (GNUNET_FS_uri_test_chk (sr->uri) ||
- GNUNET_FS_uri_test_loc (sr->uri) );
- if ( (offset + length < offset) ||
- (offset + length > sr->uri->data.chk.file_length) )
- {
- GNUNET_break (0);
- return NULL;
- }
+ GNUNET_FS_uri_test_loc (sr->uri));
+ if ((offset + length < offset) ||
+ (offset + length > sr->uri->data.chk.file_length))
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
#if DEBUG_DOWNLOAD
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Starting download `%s' of %llu bytes\n",
- filename,
- (unsigned long long) length);
+ "Starting download `%s' of %llu bytes\n",
+ filename, (unsigned long long) length);
#endif
- dc = GNUNET_malloc (sizeof(struct GNUNET_FS_DownloadContext));
+ dc = GNUNET_malloc (sizeof (struct GNUNET_FS_DownloadContext));
dc->h = h;
dc->search = sr;
sr->download = dc;
if (sr->probe_ctx != NULL)
- {
- GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES);
- sr->probe_ctx = NULL;
- }
+ {
+ GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES);
+ sr->probe_ctx = NULL;
+ }
dc->uri = GNUNET_FS_uri_dup (sr->uri);
dc->meta = GNUNET_CONTAINER_meta_data_duplicate (sr->meta);
dc->client_info = cctx;
dc->start_time = GNUNET_TIME_absolute_get ();
if (NULL != filename)
- {
- dc->filename = GNUNET_strdup (filename);
- if (GNUNET_YES == GNUNET_DISK_file_test (filename))
- GNUNET_DISK_file_size (filename,
- &dc->old_file_size,
- GNUNET_YES);
- }
+ {
+ dc->filename = GNUNET_strdup (filename);
+ if (GNUNET_YES == GNUNET_DISK_file_test (filename))
+ GNUNET_DISK_file_size (filename, &dc->old_file_size, GNUNET_YES);
+ }
if (GNUNET_FS_uri_test_loc (dc->uri))
GNUNET_assert (GNUNET_OK ==
- GNUNET_FS_uri_loc_get_peer_identity (dc->uri,
- &dc->target));
+ GNUNET_FS_uri_loc_get_peer_identity (dc->uri, &dc->target));
dc->offset = offset;
dc->length = length;
dc->anonymity = anonymity;
dc->options = options;
- dc->active = GNUNET_CONTAINER_multihashmap_create (1 + 2 * (length /
DBLOCK_SIZE));
- dc->treedepth = GNUNET_FS_compute_depth
(GNUNET_ntohll(dc->uri->data.chk.file_length));
- if ( (filename == NULL) &&
- (is_recursive_download (dc) ) )
- {
- if (tempname != NULL)
- dc->temp_filename = GNUNET_strdup (tempname);
- else
- dc->temp_filename = GNUNET_DISK_mktemp
("gnunet-directory-download-tmp");
- }
+ dc->active =
+ GNUNET_CONTAINER_multihashmap_create (1 + 2 * (length / DBLOCK_SIZE));
+ dc->treedepth =
+ GNUNET_FS_compute_depth (GNUNET_ntohll (dc->uri->data.chk.file_length));
+ if ((filename == NULL) && (is_recursive_download (dc)))
+ {
+ if (tempname != NULL)
+ dc->temp_filename = GNUNET_strdup (tempname);
+ else
+ dc->temp_filename = GNUNET_DISK_mktemp ("gnunet-directory-download-tmp");
+ }
#if DEBUG_DOWNLOAD
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Download tree has depth %u\n",
- dc->treedepth);
+ "Download tree has depth %u\n", dc->treedepth);
#endif
- dc->task = GNUNET_SCHEDULER_add_now (&GNUNET_FS_download_start_task_,
- dc);
- return dc;
+ dc->task = GNUNET_SCHEDULER_add_now (&GNUNET_FS_download_start_task_, dc);
+ return dc;
}
@@ -2388,11 +2193,12 @@
if (dc->completed == dc->length)
return;
GNUNET_assert (dc->job_queue == NULL);
- dc->job_queue = GNUNET_FS_queue_ (dc->h,
- &activate_fs_download,
- &deactivate_fs_download,
- dc,
- (dc->length + DBLOCK_SIZE-1) / DBLOCK_SIZE);
+ dc->job_queue = GNUNET_FS_queue_ (dc->h,
+ &activate_fs_download,
+ &deactivate_fs_download,
+ dc,
+ (dc->length + DBLOCK_SIZE -
+ 1) / DBLOCK_SIZE);
}
@@ -2403,8 +2209,7 @@
* @param do_delete delete files of incomplete downloads
*/
void
-GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc,
- int do_delete)
+GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc, int do_delete)
{
struct GNUNET_FS_ProgressInfo pi;
int have_children;
@@ -2414,77 +2219,71 @@
if (dc->task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (dc->task);
- dc->task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (dc->task);
+ dc->task = GNUNET_SCHEDULER_NO_TASK;
+ }
if (dc->search != NULL)
- {
- dc->search->download = NULL;
- dc->search = NULL;
- }
+ {
+ dc->search->download = NULL;
+ dc->search = NULL;
+ }
if (dc->job_queue != NULL)
- {
- GNUNET_FS_dequeue_ (dc->job_queue);
- dc->job_queue = NULL;
- }
+ {
+ GNUNET_FS_dequeue_ (dc->job_queue);
+ dc->job_queue = NULL;
+ }
if (dc->te != NULL)
- {
- GNUNET_FS_tree_encoder_finish (dc->te, NULL, NULL);
- dc->te = NULL;
- }
+ {
+ GNUNET_FS_tree_encoder_finish (dc->te, NULL, NULL);
+ dc->te = NULL;
+ }
have_children = (NULL != dc->child_head) ? GNUNET_YES : GNUNET_NO;
while (NULL != dc->child_head)
- GNUNET_FS_download_stop (dc->child_head,
- do_delete);
+ GNUNET_FS_download_stop (dc->child_head, do_delete);
if (dc->parent != NULL)
GNUNET_CONTAINER_DLL_remove (dc->parent->child_head,
- dc->parent->child_tail,
- dc);
+ dc->parent->child_tail, dc);
if (dc->serialization != NULL)
GNUNET_FS_remove_sync_file_ (dc->h,
- ( (dc->parent != NULL) || (dc->search !=
NULL) )
- ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD
- : GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD ,
- dc->serialization);
- if ( (GNUNET_YES == have_children) &&
- (dc->parent == NULL) )
- GNUNET_FS_remove_sync_dir_ (dc->h,
- (dc->search != NULL)
- ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD
- : GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD,
- dc->serialization);
+ ((dc->parent != NULL) || (dc->search != NULL))
+ ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD
+ : GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD,
+ dc->serialization);
+ if ((GNUNET_YES == have_children) && (dc->parent == NULL))
+ GNUNET_FS_remove_sync_dir_ (dc->h,
+ (dc->search != NULL)
+ ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD
+ : GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD,
+ dc->serialization);
pi.status = GNUNET_FS_STATUS_DOWNLOAD_STOPPED;
GNUNET_FS_download_make_status_ (&pi, dc);
GNUNET_FS_free_download_request_ (dc->top_request);
dc->top_request = NULL;
if (dc->active != NULL)
- {
- GNUNET_CONTAINER_multihashmap_destroy (dc->active);
- dc->active = NULL;
- }
+ {
+ GNUNET_CONTAINER_multihashmap_destroy (dc->active);
+ dc->active = NULL;
+ }
if (dc->filename != NULL)
+ {
+ if ((dc->completed != dc->length) && (GNUNET_YES == do_delete))
{
- if ( (dc->completed != dc->length) &&
- (GNUNET_YES == do_delete) )
- {
- if (0 != UNLINK (dc->filename))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
- "unlink",
- dc->filename);
- }
- GNUNET_free (dc->filename);
+ if (0 != UNLINK (dc->filename))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
+ "unlink", dc->filename);
}
+ GNUNET_free (dc->filename);
+ }
GNUNET_CONTAINER_meta_data_destroy (dc->meta);
GNUNET_FS_uri_destroy (dc->uri);
if (NULL != dc->temp_filename)
- {
- if (0 != UNLINK (dc->temp_filename))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
- "unlink",
- dc->temp_filename);
- GNUNET_free (dc->temp_filename);
- }
+ {
+ if (0 != UNLINK (dc->temp_filename))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
+ "unlink", dc->temp_filename);
+ GNUNET_free (dc->temp_filename);
+ }
GNUNET_free_non_null (dc->serialization);
GNUNET_free (dc);
}
Modified: gnunet/src/fs/fs_file_information.c
===================================================================
--- gnunet/src/fs/fs_file_information.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/fs/fs_file_information.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -52,22 +52,19 @@
* @return always 0 to continue extracting
*/
static int
-add_to_md(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)
+add_to_md (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);
+ plugin_name,
+ type,
+ format,
+ data_mime_type, data, data_len);
return 0;
}
@@ -80,9 +77,8 @@
*/
int
GNUNET_FS_meta_data_extract_from_file (struct GNUNET_CONTAINER_MetaData
- *md, const char *filename,
- struct EXTRACTOR_PluginList *
- extractors)
+ *md, const char *filename,
+ struct EXTRACTOR_PluginList *extractors)
{
int old;
@@ -92,11 +88,7 @@
return 0;
old = GNUNET_CONTAINER_meta_data_iterate (md, NULL, NULL);
GNUNET_assert (old >= 0);
- EXTRACTOR_extract (extractors,
- filename,
- NULL, 0,
- &add_to_md,
- md);
+ EXTRACTOR_extract (extractors, filename, NULL, 0, &add_to_md, md);
return (GNUNET_CONTAINER_meta_data_iterate (md, NULL, NULL) - old);
}
@@ -137,44 +129,44 @@
*/
struct GNUNET_FS_FileInformation *
GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h,
- void *client_info,
- const char *filename,
- const struct GNUNET_FS_Uri
*keywords,
- const struct
GNUNET_CONTAINER_MetaData *meta,
- int do_index,
- const struct
GNUNET_FS_BlockOptions *bo)
+ void *client_info,
+ const char *filename,
+ const struct GNUNET_FS_Uri
+ *keywords,
+ const struct
+ GNUNET_CONTAINER_MetaData *meta,
+ int do_index,
+ const struct
GNUNET_FS_BlockOptions
+ *bo)
{
struct FileInfo *fi;
struct stat sbuf;
struct GNUNET_FS_FileInformation *ret;
const char *fn;
const char *ss;
+
#if WINDOWS
char fn_conv[MAX_PATH];
#endif
if (0 != STAT (filename, &sbuf))
- {
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
- "stat",
- filename);
- return NULL;
- }
+ {
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", filename);
+ return NULL;
+ }
fi = GNUNET_FS_make_file_reader_context_ (filename);
if (fi == NULL)
- {
- GNUNET_break (0);
- return NULL;
- }
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
ret = GNUNET_FS_file_information_create_from_reader (h,
- client_info,
- sbuf.st_size,
-
&GNUNET_FS_data_reader_file_,
- fi,
- keywords,
- meta,
- do_index,
- bo);
+ client_info,
+ sbuf.st_size,
+
&GNUNET_FS_data_reader_file_,
+ fi,
+ keywords,
+ meta, do_index, bo);
if (ret == NULL)
return NULL;
ret->h = h;
@@ -185,16 +177,13 @@
plibc_conv_to_win_path (filename, fn_conv);
fn = fn_conv;
#endif
- while (NULL != (ss = strstr (fn,
- DIR_SEPARATOR_STR)))
+ while (NULL != (ss = strstr (fn, DIR_SEPARATOR_STR)))
fn = ss + 1;
GNUNET_CONTAINER_meta_data_insert (ret->meta,
- "<gnunet>",
-
EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME,
- EXTRACTOR_METAFORMAT_C_STRING,
- "text/plain",
- fn,
- strlen (fn) + 1);
+ "<gnunet>",
+
EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME,
+ EXTRACTOR_METAFORMAT_C_STRING,
+ "text/plain", fn, strlen (fn) + 1);
return ret;
}
@@ -217,28 +206,29 @@
*/
struct GNUNET_FS_FileInformation *
GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h,
- void *client_info,
- uint64_t length,
- void *data,
- const struct GNUNET_FS_Uri
*keywords,
- const struct
GNUNET_CONTAINER_MetaData *meta,
- int do_index,
- const struct
GNUNET_FS_BlockOptions *bo)
+ void *client_info,
+ uint64_t length,
+ void *data,
+ const struct GNUNET_FS_Uri
+ *keywords,
+ const struct
+ GNUNET_CONTAINER_MetaData *meta,
+ int do_index,
+ const struct
GNUNET_FS_BlockOptions
+ *bo)
{
- if (GNUNET_YES == do_index)
- {
- GNUNET_break (0);
- return NULL;
- }
+ if (GNUNET_YES == do_index)
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
return GNUNET_FS_file_information_create_from_reader (h,
- client_info,
- length,
-
&GNUNET_FS_data_reader_copy_,
- data,
- keywords,
- meta,
- do_index,
- bo);
+ client_info,
+ length,
+
&GNUNET_FS_data_reader_copy_,
+ data,
+ keywords,
+ meta, do_index, bo);
}
@@ -260,31 +250,33 @@
*/
struct GNUNET_FS_FileInformation *
GNUNET_FS_file_information_create_from_reader (struct GNUNET_FS_Handle *h,
- void *client_info,
- uint64_t length,
- GNUNET_FS_DataReader reader,
- void *reader_cls,
- const struct GNUNET_FS_Uri
*keywords,
- const struct
GNUNET_CONTAINER_MetaData *meta,
- int do_index,
- const struct
GNUNET_FS_BlockOptions *bo)
+ void *client_info,
+ uint64_t length,
+ GNUNET_FS_DataReader reader,
+ void *reader_cls,
+ const struct GNUNET_FS_Uri
+ *keywords,
+ const struct
+ GNUNET_CONTAINER_MetaData *meta,
+ int do_index,
+ const struct
+ GNUNET_FS_BlockOptions *bo)
{
struct GNUNET_FS_FileInformation *ret;
- if ( (GNUNET_YES == do_index) &&
- (reader != &GNUNET_FS_data_reader_file_) )
- {
- GNUNET_break (0);
- return NULL;
- }
+ if ((GNUNET_YES == do_index) && (reader != &GNUNET_FS_data_reader_file_))
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
ret = GNUNET_malloc (sizeof (struct GNUNET_FS_FileInformation));
ret->h = h;
- ret->client_info = client_info;
+ ret->client_info = client_info;
ret->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
if (ret->meta == NULL)
ret->meta = GNUNET_CONTAINER_meta_data_create ();
ret->keywords = (keywords == NULL) ? NULL : GNUNET_FS_uri_dup (keywords);
- ret->data.file.reader = reader;
+ ret->data.file.reader = reader;
ret->data.file.reader_cls = reader_cls;
ret->data.file.do_index = do_index;
ret->data.file.file_size = length;
@@ -296,7 +288,7 @@
/**
* Closure for "dir_scan_cb".
*/
-struct DirScanCls
+struct DirScanCls
{
/**
* Metadata extractors to use.
@@ -305,14 +297,14 @@
/**
* Master context.
- */
+ */
struct GNUNET_FS_Handle *h;
/**
* Function to call on each directory entry.
*/
GNUNET_FS_FileProcessor proc;
-
+
/**
* Closure for proc.
*/
@@ -331,7 +323,7 @@
/**
* Set to an error message (if any).
*/
- char *emsg;
+ char *emsg;
/**
* Block options.
@@ -340,7 +332,7 @@
/**
* Should files be indexed?
- */
+ */
int do_index;
};
@@ -354,10 +346,9 @@
* @return GNUNET_OK on success, GNUNET_SYSERR to abort
*/
static int
-dir_scan_cb (void *cls,
- const char *filename)
+dir_scan_cb (void *cls, const char *filename)
{
- struct DirScanCls *dsc = cls;
+ struct DirScanCls *dsc = cls;
struct stat sbuf;
struct GNUNET_FS_FileInformation *fi;
struct GNUNET_FS_Uri *ksk_uri;
@@ -365,52 +356,44 @@
struct GNUNET_CONTAINER_MetaData *meta;
if (0 != STAT (filename, &sbuf))
+ {
+ GNUNET_asprintf (&dsc->emsg,
+ _("`%s' failed on file `%s': %s"),
+ "stat", filename, STRERROR (errno));
+ return GNUNET_SYSERR;
+ }
+ if (S_ISDIR (sbuf.st_mode))
+ {
+ fi = GNUNET_FS_file_information_create_from_directory (dsc->h,
+ NULL,
+ filename,
+ dsc->scanner,
+ dsc->scanner_cls,
+ dsc->do_index,
+ dsc->bo,
&dsc->emsg);
+ if (NULL == fi)
{
- GNUNET_asprintf (&dsc->emsg,
- _("`%s' failed on file `%s': %s"),
- "stat",
- filename,
- STRERROR (errno));
+ GNUNET_assert (NULL != dsc->emsg);
return GNUNET_SYSERR;
}
- if (S_ISDIR (sbuf.st_mode))
- {
- fi = GNUNET_FS_file_information_create_from_directory (dsc->h,
- NULL,
- filename,
- dsc->scanner,
- dsc->scanner_cls,
- dsc->do_index,
- dsc->bo,
- &dsc->emsg);
- if (NULL == fi)
- {
- GNUNET_assert (NULL != dsc->emsg);
- return GNUNET_SYSERR;
- }
- }
+ }
else
- {
- meta = GNUNET_CONTAINER_meta_data_create ();
- GNUNET_FS_meta_data_extract_from_file (meta,
- filename,
- dsc->extractors);
- keywords = GNUNET_FS_uri_ksk_create_from_meta_data (meta);
- ksk_uri = GNUNET_FS_uri_ksk_canonicalize (keywords);
- fi = GNUNET_FS_file_information_create_from_file (dsc->h,
- NULL,
- filename,
- ksk_uri,
- meta,
- dsc->do_index,
- dsc->bo);
- GNUNET_CONTAINER_meta_data_destroy (meta);
- GNUNET_FS_uri_destroy (keywords);
- GNUNET_FS_uri_destroy (ksk_uri);
- }
- dsc->proc (dsc->proc_cls,
- filename,
- fi);
+ {
+ meta = GNUNET_CONTAINER_meta_data_create ();
+ GNUNET_FS_meta_data_extract_from_file (meta, filename, dsc->extractors);
+ keywords = GNUNET_FS_uri_ksk_create_from_meta_data (meta);
+ ksk_uri = GNUNET_FS_uri_ksk_canonicalize (keywords);
+ fi = GNUNET_FS_file_information_create_from_file (dsc->h,
+ NULL,
+ filename,
+ ksk_uri,
+ meta,
+ dsc->do_index, dsc->bo);
+ GNUNET_CONTAINER_meta_data_destroy (meta);
+ GNUNET_FS_uri_destroy (keywords);
+ GNUNET_FS_uri_destroy (ksk_uri);
+ }
+ dsc->proc (dsc->proc_cls, filename, fi);
return GNUNET_OK;
}
@@ -438,13 +421,12 @@
*/
int
GNUNET_FS_directory_scanner_default (void *cls,
- struct GNUNET_FS_Handle *h,
- const char *dirname,
- int do_index,
- const struct GNUNET_FS_BlockOptions *bo,
- GNUNET_FS_FileProcessor proc,
- void *proc_cls,
- char **emsg)
+ struct GNUNET_FS_Handle *h,
+ const char *dirname,
+ int do_index,
+ const struct GNUNET_FS_BlockOptions *bo,
+ GNUNET_FS_FileProcessor proc,
+ void *proc_cls, char **emsg)
{
struct EXTRACTOR_PluginList *ex = cls;
struct DirScanCls dsc;
@@ -457,14 +439,12 @@
dsc.scanner_cls = cls;
dsc.do_index = do_index;
dsc.bo = bo;
- if (-1 == GNUNET_DISK_directory_scan (dirname,
- &dir_scan_cb,
- &dsc))
- {
- GNUNET_assert (NULL != dsc.emsg);
- *emsg = dsc.emsg;
- return GNUNET_SYSERR;
- }
+ if (-1 == GNUNET_DISK_directory_scan (dirname, &dir_scan_cb, &dsc))
+ {
+ GNUNET_assert (NULL != dsc.emsg);
+ *emsg = dsc.emsg;
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
}
@@ -491,9 +471,7 @@
* @param fi information for publishing the file
*/
static void
-dirproc (void *cls,
- const char *filename,
- struct GNUNET_FS_FileInformation *fi)
+dirproc (void *cls, const char *filename, struct GNUNET_FS_FileInformation *fi)
{
struct EntryProcCls *dc = cls;
@@ -526,13 +504,14 @@
*/
struct GNUNET_FS_FileInformation *
GNUNET_FS_file_information_create_from_directory (struct GNUNET_FS_Handle *h,
- void *client_info,
- const char *filename,
- GNUNET_FS_DirectoryScanner
scanner,
- void *scanner_cls,
- int do_index,
- const struct
GNUNET_FS_BlockOptions *bo,
- char **emsg)
+ void *client_info,
+ const char *filename,
+ GNUNET_FS_DirectoryScanner
+ scanner, void *scanner_cls,
+ int do_index,
+ const struct
+ GNUNET_FS_BlockOptions *bo,
+ char **emsg)
{
struct GNUNET_FS_FileInformation *ret;
struct EntryProcCls dc;
@@ -545,43 +524,28 @@
dc.entries = NULL;
meta = GNUNET_CONTAINER_meta_data_create ();
GNUNET_FS_meta_data_make_directory (meta);
- scanner (scanner_cls,
- h,
- filename,
- do_index,
- bo,
- &dirproc,
- &dc,
- emsg);
- ksk = NULL; // FIXME...
+ scanner (scanner_cls, h, filename, do_index, bo, &dirproc, &dc, emsg);
+ ksk = NULL; // FIXME...
// FIXME: create meta!
ret = GNUNET_FS_file_information_create_empty_directory (h,
- client_info,
- ksk,
- meta,
- bo);
+ client_info,
+ ksk, meta, bo);
GNUNET_CONTAINER_meta_data_destroy (meta);
ret->data.dir.entries = dc.entries;
while (dc.entries != NULL)
- {
- dc.entries->dir = ret;
- dc.entries = dc.entries->next;
- }
+ {
+ dc.entries->dir = ret;
+ dc.entries = dc.entries->next;
+ }
fn = filename;
- while ( (NULL != (ss = strstr (fn,
- DIR_SEPARATOR_STR))) &&
- (strlen (ss) > 1) )
+ while ((NULL != (ss = strstr (fn, DIR_SEPARATOR_STR))) && (strlen (ss) > 1))
fn = ss + 1;
- GNUNET_asprintf (&dn,
- "%s/",
- fn);
+ GNUNET_asprintf (&dn, "%s/", fn);
GNUNET_CONTAINER_meta_data_insert (ret->meta,
- "<gnunet>",
-
EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME,
- EXTRACTOR_METAFORMAT_C_STRING,
- "text/plain",
- dn,
- strlen (dn) + 1);
+ "<gnunet>",
+
EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME,
+ EXTRACTOR_METAFORMAT_C_STRING,
+ "text/plain", dn, strlen (dn) + 1);
GNUNET_free (dn);
ret->filename = GNUNET_strdup (filename);
return ret;
@@ -595,7 +559,8 @@
* @return GNUNET_YES if so, GNUNET_NO if not
*/
int
-GNUNET_FS_file_information_is_directory (const struct
GNUNET_FS_FileInformation *ent)
+GNUNET_FS_file_information_is_directory (const struct GNUNET_FS_FileInformation
+ *ent)
{
return ent->is_directory;
}
@@ -617,10 +582,14 @@
*/
struct GNUNET_FS_FileInformation *
GNUNET_FS_file_information_create_empty_directory (struct GNUNET_FS_Handle *h,
- void *client_info,
- const struct GNUNET_FS_Uri
*keywords,
- const struct
GNUNET_CONTAINER_MetaData *meta,
- const struct
GNUNET_FS_BlockOptions *bo)
+ void *client_info,
+ const struct GNUNET_FS_Uri
+ *keywords,
+ const struct
+ GNUNET_CONTAINER_MetaData
+ *meta,
+ const struct
+ GNUNET_FS_BlockOptions *bo)
{
struct GNUNET_FS_FileInformation *ret;
@@ -648,15 +617,13 @@
*/
int
GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir,
- struct GNUNET_FS_FileInformation *ent)
+ struct GNUNET_FS_FileInformation *ent)
{
- if ( (ent->dir != NULL) ||
- (ent->next != NULL) ||
- (! dir->is_directory) )
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
+ if ((ent->dir != NULL) || (ent->next != NULL) || (!dir->is_directory))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
ent->dir = dir;
ent->next = dir->data.dir.entries;
dir->data.dir.entries = ent;
@@ -681,41 +648,37 @@
*/
void
GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir,
- GNUNET_FS_FileInformationProcessor proc,
- void *proc_cls)
+ GNUNET_FS_FileInformationProcessor proc,
+ void *proc_cls)
{
struct GNUNET_FS_FileInformation *pos;
int no;
no = GNUNET_NO;
if (GNUNET_OK !=
- proc (proc_cls,
- dir,
- (dir->is_directory) ? dir->data.dir.dir_size :
dir->data.file.file_size,
- dir->meta,
- &dir->keywords,
- &dir->bo,
- (dir->is_directory) ? &no : &dir->data.file.do_index,
- &dir->client_info))
+ proc (proc_cls,
+ dir,
+ (dir->is_directory) ? dir->data.dir.dir_size : dir->data.
+ file.file_size, dir->meta, &dir->keywords, &dir->bo,
+ (dir->is_directory) ? &no : &dir->data.file.do_index,
+ &dir->client_info))
return;
- if (! dir->is_directory)
+ if (!dir->is_directory)
return;
pos = dir->data.dir.entries;
while (pos != NULL)
- {
- no = GNUNET_NO;
- if (GNUNET_OK !=
- proc (proc_cls,
- pos,
- (pos->is_directory) ? pos->data.dir.dir_size :
pos->data.file.file_size,
- pos->meta,
- &pos->keywords,
- &pos->bo,
- (dir->is_directory) ? &no : &dir->data.file.do_index,
- &pos->client_info))
- break;
- pos = pos->next;
- }
+ {
+ no = GNUNET_NO;
+ if (GNUNET_OK !=
+ proc (proc_cls,
+ pos,
+ (pos->is_directory) ? pos->data.dir.dir_size : pos->data.
+ file.file_size, pos->meta, &pos->keywords, &pos->bo,
+ (dir->is_directory) ? &no : &dir->data.file.do_index,
+ &pos->client_info))
+ break;
+ pos = pos->next;
+ }
}
@@ -731,70 +694,60 @@
*/
void
GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi,
- GNUNET_FS_FileInformationProcessor cleaner,
- void *cleaner_cls)
+ GNUNET_FS_FileInformationProcessor cleaner,
+ void *cleaner_cls)
{
struct GNUNET_FS_FileInformation *pos;
int no;
no = GNUNET_NO;
if (fi->is_directory)
+ {
+ /* clean up directory */
+ while (NULL != (pos = fi->data.dir.entries))
{
- /* clean up directory */
- while (NULL != (pos = fi->data.dir.entries))
- {
- fi->data.dir.entries = pos->next;
- GNUNET_FS_file_information_destroy (pos, cleaner, cleaner_cls);
- }
- /* clean up client-info */
- if (NULL != cleaner)
- cleaner (cleaner_cls,
- fi,
- fi->data.dir.dir_size,
- fi->meta,
- &fi->keywords,
- &fi->bo,
- &no,
- &fi->client_info);
- GNUNET_free_non_null (fi->data.dir.dir_data);
+ fi->data.dir.entries = pos->next;
+ GNUNET_FS_file_information_destroy (pos, cleaner, cleaner_cls);
}
+ /* clean up client-info */
+ if (NULL != cleaner)
+ cleaner (cleaner_cls,
+ fi,
+ fi->data.dir.dir_size,
+ fi->meta, &fi->keywords, &fi->bo, &no, &fi->client_info);
+ GNUNET_free_non_null (fi->data.dir.dir_data);
+ }
else
- {
- /* call clean-up function of the reader */
- if (fi->data.file.reader != NULL)
- fi->data.file.reader (fi->data.file.reader_cls, 0, 0,
- NULL, NULL);
- /* clean up client-info */
- if (NULL != cleaner)
- cleaner (cleaner_cls,
- fi,
- fi->data.file.file_size,
- fi->meta,
- &fi->keywords,
- &fi->bo,
- &fi->data.file.do_index,
- &fi->client_info);
- }
+ {
+ /* call clean-up function of the reader */
+ if (fi->data.file.reader != NULL)
+ fi->data.file.reader (fi->data.file.reader_cls, 0, 0, NULL, NULL);
+ /* clean up client-info */
+ if (NULL != cleaner)
+ cleaner (cleaner_cls,
+ fi,
+ fi->data.file.file_size,
+ fi->meta,
+ &fi->keywords,
+ &fi->bo, &fi->data.file.do_index, &fi->client_info);
+ }
GNUNET_free_non_null (fi->filename);
GNUNET_free_non_null (fi->emsg);
GNUNET_free_non_null (fi->chk_uri);
/* clean up serialization */
- if ( (NULL != fi->serialization) &&
- (0 != UNLINK (fi->serialization)) )
+ if ((NULL != fi->serialization) && (0 != UNLINK (fi->serialization)))
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
- "unlink",
- fi->serialization);
+ "unlink", fi->serialization);
if (NULL != fi->keywords)
GNUNET_FS_uri_destroy (fi->keywords);
if (NULL != fi->meta)
GNUNET_CONTAINER_meta_data_destroy (fi->meta);
GNUNET_free_non_null (fi->serialization);
if (fi->te != NULL)
- {
- GNUNET_FS_tree_encoder_finish (fi->te,
- NULL, NULL);
- fi->te = NULL;
- }
+ {
+ GNUNET_FS_tree_encoder_finish (fi->te, NULL, NULL);
+ fi->te = NULL;
+ }
GNUNET_free (fi);
}
Modified: gnunet/src/fs/fs_getopt.c
===================================================================
--- gnunet/src/fs/fs_getopt.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/fs/fs_getopt.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -42,10 +42,9 @@
* @return GNUNET_OK on success
*/
int
-GNUNET_FS_getopt_set_keywords (struct
GNUNET_GETOPT_CommandLineProcessorContext* ctx,
- void *scls,
- const char *option,
- const char *value)
+GNUNET_FS_getopt_set_keywords (struct GNUNET_GETOPT_CommandLineProcessorContext
+ *ctx, void *scls, const char *option,
+ const char *value)
{
struct GNUNET_FS_Uri **uri = scls;
struct GNUNET_FS_Uri *u = *uri;
@@ -53,60 +52,58 @@
size_t slen;
if (u == NULL)
- {
- u = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
- *uri = u;
- u->type = ksk;
- u->data.ksk.keywordCount = 0;
- u->data.ksk.keywords = NULL;
- }
+ {
+ u = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
+ *uri = u;
+ u->type = ksk;
+ u->data.ksk.keywordCount = 0;
+ u->data.ksk.keywords = NULL;
+ }
else
- {
- GNUNET_assert (u->type == ksk);
- }
+ {
+ GNUNET_assert (u->type == ksk);
+ }
slen = strlen (value);
if (slen == 0)
return GNUNET_SYSERR; /* cannot be empty */
if (value[0] == '+')
+ {
+ /* simply preserve the "mandatory" flag */
+ if (slen < 2)
+ return GNUNET_SYSERR; /* empty keywords not allowed */
+ if ((value[1] == '"') && (slen > 3) && (value[slen - 1] == '"'))
{
- /* simply preserve the "mandatory" flag */
- if (slen < 2)
- return GNUNET_SYSERR; /* empty keywords not allowed */
- if ((value[1] == '"') && (slen > 3) && (value[slen - 1] == '"'))
- {
- /* remove the quotes, keep the '+' */
- val = GNUNET_malloc (slen - 1);
- val[0] = '+';
- memcpy (&val[1], &value[2], slen - 3);
- val[slen - 2] = '\0';
- }
- else
- {
- /* no quotes, just keep the '+' */
- val = GNUNET_strdup (value);
- }
+ /* remove the quotes, keep the '+' */
+ val = GNUNET_malloc (slen - 1);
+ val[0] = '+';
+ memcpy (&val[1], &value[2], slen - 3);
+ val[slen - 2] = '\0';
}
+ else
+ {
+ /* no quotes, just keep the '+' */
+ val = GNUNET_strdup (value);
+ }
+ }
else
+ {
+ if ((value[0] == '"') && (slen > 2) && (value[slen - 1] == '"'))
{
- if ((value[0] == '"') && (slen > 2) && (value[slen - 1] == '"'))
- {
- /* remove the quotes, add a space */
- val = GNUNET_malloc (slen);
- val[0] = ' ';
- memcpy (&val[1], &value[1], slen - 2);
- val[slen - 1] = '\0';
- }
- else
- {
- /* add a space to indicate "not mandatory" */
- val = GNUNET_malloc (slen + 2);
- strcpy (val, " ");
- strcat (val, value);
- }
+ /* remove the quotes, add a space */
+ val = GNUNET_malloc (slen);
+ val[0] = ' ';
+ memcpy (&val[1], &value[1], slen - 2);
+ val[slen - 1] = '\0';
}
- GNUNET_array_append (u->data.ksk.keywords,
- u->data.ksk.keywordCount,
- val);
+ else
+ {
+ /* add a space to indicate "not mandatory" */
+ val = GNUNET_malloc (slen + 2);
+ strcpy (val, " ");
+ strcat (val, value);
+ }
+ }
+ GNUNET_array_append (u->data.ksk.keywords, u->data.ksk.keywordCount, val);
return GNUNET_OK;
}
@@ -124,11 +121,9 @@
* @return GNUNET_OK on success
*/
int
-GNUNET_FS_getopt_set_metadata (struct
GNUNET_GETOPT_CommandLineProcessorContext* ctx,
- void *scls,
- const char *option,
- const char *value)
-
+GNUNET_FS_getopt_set_metadata (struct GNUNET_GETOPT_CommandLineProcessorContext
+ *ctx, void *scls, const char *option,
+ const char *value)
{
struct GNUNET_CONTAINER_MetaData **mm = scls;
enum EXTRACTOR_MetaType type;
@@ -139,69 +134,68 @@
meta = *mm;
if (meta == NULL)
- {
- meta = GNUNET_CONTAINER_meta_data_create ();
- *mm = meta;
- }
+ {
+ meta = GNUNET_CONTAINER_meta_data_create ();
+ *mm = meta;
+ }
#if ENABLE_NLS
- tmp = GNUNET_STRINGS_to_utf8 (value, strlen (value),
- nl_langinfo (CODESET));
+ tmp = GNUNET_STRINGS_to_utf8 (value, strlen (value), nl_langinfo (CODESET));
#else
- tmp = GNUNET_STRINGS_to_utf8 (value, strlen (value),
- "utf-8");
+ tmp = GNUNET_STRINGS_to_utf8 (value, strlen (value), "utf-8");
#endif
type = EXTRACTOR_metatype_get_max ();
while (type > 0)
+ {
+ type--;
+ typename = EXTRACTOR_metatype_to_string (type);
+ typename_i18n = dgettext (LIBEXTRACTOR_GETTEXT_DOMAIN, typename);
+ if ((strlen (tmp) >= strlen (typename) + 1) &&
+ (tmp[strlen (typename)] == ':') &&
+ (0 == strncmp (typename, tmp, strlen (typename))))
{
- type--;
- typename = EXTRACTOR_metatype_to_string (type);
- typename_i18n = dgettext (LIBEXTRACTOR_GETTEXT_DOMAIN, typename);
- if ((strlen (tmp) >= strlen (typename) + 1) &&
- (tmp[strlen (typename)] == ':') &&
- (0 == strncmp (typename, tmp, strlen (typename))))
- {
- GNUNET_CONTAINER_meta_data_insert (meta,
- "<gnunet>",
- type,
- EXTRACTOR_METAFORMAT_UTF8,
- "text/plain",
- &tmp[strlen (typename) + 1],
- strlen (&tmp[strlen (typename) +
1])+1);
- GNUNET_free (tmp);
- tmp = NULL;
- break;
- }
- if ((strlen (tmp) >= strlen (typename_i18n) + 1) &&
- (tmp[strlen (typename_i18n)] == ':') &&
- (0 == strncmp (typename_i18n, tmp, strlen (typename_i18n))))
- {
- GNUNET_CONTAINER_meta_data_insert (meta,
- "<gnunet>",
- type,
- EXTRACTOR_METAFORMAT_UTF8,
- "text/plain",
- &tmp[strlen (typename_i18n) + 1],
- strlen (&tmp[strlen
(typename_i18n) + 1]) + 1);
- GNUNET_free (tmp);
- tmp = NULL;
- break;
- }
+ GNUNET_CONTAINER_meta_data_insert (meta,
+ "<gnunet>",
+ type,
+ EXTRACTOR_METAFORMAT_UTF8,
+ "text/plain",
+ &tmp[strlen (typename) + 1],
+ strlen (&tmp[strlen (typename) + 1]) +
+ 1);
+ GNUNET_free (tmp);
+ tmp = NULL;
+ break;
}
- if (tmp != NULL)
+ if ((strlen (tmp) >= strlen (typename_i18n) + 1) &&
+ (tmp[strlen (typename_i18n)] == ':') &&
+ (0 == strncmp (typename_i18n, tmp, strlen (typename_i18n))))
{
- GNUNET_CONTAINER_meta_data_insert (meta,
- "<gnunet>",
- EXTRACTOR_METATYPE_UNKNOWN,
- EXTRACTOR_METAFORMAT_UTF8,
- "text/plain",
- tmp,
- strlen(tmp) + 1);
+ GNUNET_CONTAINER_meta_data_insert (meta,
+ "<gnunet>",
+ type,
+ EXTRACTOR_METAFORMAT_UTF8,
+ "text/plain",
+ &tmp[strlen (typename_i18n) + 1],
+ strlen (&tmp
+ [strlen (typename_i18n) + 1])
+
+ 1);
GNUNET_free (tmp);
- printf (_
- ("Unknown metadata type in metadata option `%s'. Using metadata
type `unknown' instead.\n"),
- value);
+ tmp = NULL;
+ break;
}
+ }
+ if (tmp != NULL)
+ {
+ GNUNET_CONTAINER_meta_data_insert (meta,
+ "<gnunet>",
+ EXTRACTOR_METATYPE_UNKNOWN,
+ EXTRACTOR_METAFORMAT_UTF8,
+ "text/plain", tmp, strlen (tmp) + 1);
+ GNUNET_free (tmp);
+ printf (_
+ ("Unknown metadata type in metadata option `%s'. Using metadata
type `unknown' instead.\n"),
+ value);
+ }
return GNUNET_OK;
}
Modified: gnunet/src/fs/fs_list_indexed.c
===================================================================
--- gnunet/src/fs/fs_list_indexed.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/fs/fs_list_indexed.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -76,8 +76,7 @@
* @param msg message with indexing information
*/
static void
-handle_index_info (void *cls,
- const struct GNUNET_MessageHeader *msg)
+handle_index_info (void *cls, const struct GNUNET_MessageHeader *msg)
{
struct GetIndexedContext *gic = cls;
const struct IndexInfoMessage *iim;
@@ -85,64 +84,58 @@
const char *filename;
if (NULL == msg)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to receive response for `%s' request from `%s'
service.\n"),
- "GET_INDEXED",
- "fs");
- GNUNET_SCHEDULER_add_continuation (gic->cont,
- gic->cont_cls,
- GNUNET_SCHEDULER_REASON_TIMEOUT);
- GNUNET_CLIENT_disconnect (gic->client, GNUNET_NO);
- GNUNET_free (gic);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Failed to receive response for `%s' request from `%s'
service.\n"),
+ "GET_INDEXED", "fs");
+ GNUNET_SCHEDULER_add_continuation (gic->cont, gic->cont_cls,
+ GNUNET_SCHEDULER_REASON_TIMEOUT);
+ GNUNET_CLIENT_disconnect (gic->client, GNUNET_NO);
+ GNUNET_free (gic);
+ return;
+ }
if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END)
- {
- /* normal end-of-list */
- GNUNET_SCHEDULER_add_continuation (gic->cont,
- gic->cont_cls,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- GNUNET_CLIENT_disconnect (gic->client, GNUNET_NO);
- GNUNET_free (gic);
- return;
- }
+ {
+ /* normal end-of-list */
+ GNUNET_SCHEDULER_add_continuation (gic->cont,
+ gic->cont_cls,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ GNUNET_CLIENT_disconnect (gic->client, GNUNET_NO);
+ GNUNET_free (gic);
+ return;
+ }
msize = ntohs (msg->size);
- iim = (const struct IndexInfoMessage*) msg;
- filename = (const char*) &iim[1];
- if ( (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY) ||
- (msize <= sizeof (struct IndexInfoMessage)) ||
- (filename[msize-sizeof (struct IndexInfoMessage) -1] != '\0') )
- {
- /* bogus reply */
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to receive valid response for `%s' request from
`%s' service.\n"),
- "GET_INDEXED",
- "fs");
- GNUNET_SCHEDULER_add_continuation (gic->cont,
- gic->cont_cls,
- GNUNET_SCHEDULER_REASON_TIMEOUT);
- GNUNET_CLIENT_disconnect (gic->client, GNUNET_NO);
- GNUNET_free (gic);
- return;
- }
- if (GNUNET_OK !=
- gic->iterator (gic->iterator_cls,
- filename,
- &iim->file_id))
- {
- GNUNET_SCHEDULER_add_continuation (gic->cont,
- gic->cont_cls,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- GNUNET_CLIENT_disconnect (gic->client, GNUNET_NO);
- GNUNET_free (gic);
- return;
- }
+ iim = (const struct IndexInfoMessage *) msg;
+ filename = (const char *) &iim[1];
+ if ((ntohs (msg->type) != GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY) ||
+ (msize <= sizeof (struct IndexInfoMessage)) ||
+ (filename[msize - sizeof (struct IndexInfoMessage) - 1] != '\0'))
+ {
+ /* bogus reply */
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Failed to receive valid response for `%s' request from `%s'
service.\n"),
+ "GET_INDEXED", "fs");
+ GNUNET_SCHEDULER_add_continuation (gic->cont, gic->cont_cls,
+ GNUNET_SCHEDULER_REASON_TIMEOUT);
+ GNUNET_CLIENT_disconnect (gic->client, GNUNET_NO);
+ GNUNET_free (gic);
+ return;
+ }
+ if (GNUNET_OK != gic->iterator (gic->iterator_cls, filename, &iim->file_id))
+ {
+ GNUNET_SCHEDULER_add_continuation (gic->cont,
+ gic->cont_cls,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ GNUNET_CLIENT_disconnect (gic->client, GNUNET_NO);
+ GNUNET_free (gic);
+ return;
+ }
/* get more */
GNUNET_CLIENT_receive (gic->client,
- &handle_index_info,
- gic,
- GNUNET_CONSTANTS_SERVICE_TIMEOUT);
+ &handle_index_info,
+ gic, GNUNET_CONSTANTS_SERVICE_TIMEOUT);
}
@@ -157,29 +150,26 @@
* error) or "PREREQ_DONE" (on success)
* @param cont_cls closure for cont
*/
-void
+void
GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h,
- GNUNET_FS_IndexedFileProcessor iterator,
- void *iterator_cls,
- GNUNET_SCHEDULER_Task cont,
- void *cont_cls)
+ GNUNET_FS_IndexedFileProcessor iterator,
+ void *iterator_cls,
+ GNUNET_SCHEDULER_Task cont, void *cont_cls)
{
struct GNUNET_CLIENT_Connection *client;
struct GetIndexedContext *gic;
struct GNUNET_MessageHeader msg;
- client = GNUNET_CLIENT_connect ("fs",
- h->cfg);
+ client = GNUNET_CLIENT_connect ("fs", h->cfg);
if (NULL == client)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to not connect to `%s' service.\n"),
- "fs");
- GNUNET_SCHEDULER_add_continuation (cont,
- cont_cls,
- GNUNET_SCHEDULER_REASON_TIMEOUT);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Failed to not connect to `%s' service.\n"), "fs");
+ GNUNET_SCHEDULER_add_continuation (cont,
+ cont_cls,
+ GNUNET_SCHEDULER_REASON_TIMEOUT);
+ return;
+ }
gic = GNUNET_malloc (sizeof (struct GetIndexedContext));
gic->h = h;
@@ -191,12 +181,12 @@
msg.size = htons (sizeof (struct GNUNET_MessageHeader));
msg.type = htons (GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_GET);
GNUNET_assert (GNUNET_OK ==
- GNUNET_CLIENT_transmit_and_get_response (client,
- &msg,
-
GNUNET_CONSTANTS_SERVICE_TIMEOUT,
- GNUNET_YES,
- &handle_index_info,
- gic));
+ GNUNET_CLIENT_transmit_and_get_response (client,
+ &msg,
+
GNUNET_CONSTANTS_SERVICE_TIMEOUT,
+ GNUNET_YES,
+ &handle_index_info,
+ gic));
}
/* end of fs_list_indexed.c */
Modified: gnunet/src/fs/fs_misc.c
===================================================================
--- gnunet/src/fs/fs_misc.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/fs/fs_misc.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -35,7 +35,8 @@
* @return NULL if meta data is useless for suggesting a filename
*/
char *
-GNUNET_FS_meta_data_suggest_filename (const struct GNUNET_CONTAINER_MetaData
*md)
+GNUNET_FS_meta_data_suggest_filename (const struct GNUNET_CONTAINER_MetaData
+ *md)
{
static const char *mimeMap[][2] = {
{"application/bz2", ".bz2"},
@@ -65,12 +66,12 @@
{"application/x-xcf", ".xcf"},
{"application/x-xfig", ".xfig"},
{"application/zip", ".zip"},
-
+
{"audio/midi", ".midi"},
{"audio/mpeg", ".mp3"},
{"audio/real", ".rm"},
{"audio/x-wav", ".wav"},
-
+
{"image/gif", ".gif"},
{"image/jpeg", ".jpg"},
{"image/pcx", ".pcx"},
@@ -78,7 +79,7 @@
{"image/tiff", ".tiff"},
{"image/x-ms-bmp", ".bmp"},
{"image/x-xpixmap", ".xpm"},
-
+
{"text/css", ".css"},
{"text/html", ".html"},
{"text/plain", ".txt"},
@@ -93,7 +94,7 @@
{"text/x-perl", ".pl"},
{"text/x-python", ".py"},
{"text/x-tex", ".tex"},
-
+
{"video/avi", ".avi"},
{"video/mpeg", ".mpeg"},
{"video/quicktime", ".qt"},
@@ -108,56 +109,50 @@
const char *ext;
ret = GNUNET_CONTAINER_meta_data_get_by_type (md,
-
EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME);
+
EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME);
if (ret != NULL)
- return ret;
+ return ret;
ext = NULL;
mime = GNUNET_CONTAINER_meta_data_get_by_type (md,
- EXTRACTOR_METATYPE_MIMETYPE);
+ EXTRACTOR_METATYPE_MIMETYPE);
if (mime != NULL)
- {
- i = 0;
- while ( (mimeMap[i][0] != NULL) &&
- (0 != strcmp (mime, mimeMap[i][0])))
- i++;
- if (mimeMap[i][1] == NULL)
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG |
- GNUNET_ERROR_TYPE_BULK,
- _("Did not find mime type `%s' in extension list.\n"),
- mime);
- else
- ext = mimeMap[i][1];
- GNUNET_free (mime);
- }
+ {
+ i = 0;
+ while ((mimeMap[i][0] != NULL) && (0 != strcmp (mime, mimeMap[i][0])))
+ i++;
+ if (mimeMap[i][1] == NULL)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG |
+ GNUNET_ERROR_TYPE_BULK,
+ _("Did not find mime type `%s' in extension list.\n"), mime);
+ else
+ ext = mimeMap[i][1];
+ GNUNET_free (mime);
+ }
base = GNUNET_CONTAINER_meta_data_get_first_by_types (md,
-
EXTRACTOR_METATYPE_TITLE,
-
EXTRACTOR_METATYPE_BOOK_TITLE,
-
EXTRACTOR_METATYPE_ORIGINAL_TITLE,
-
EXTRACTOR_METATYPE_PACKAGE_NAME,
- EXTRACTOR_METATYPE_URL,
- EXTRACTOR_METATYPE_URI,
-
EXTRACTOR_METATYPE_DESCRIPTION,
- EXTRACTOR_METATYPE_ISRC,
-
EXTRACTOR_METATYPE_JOURNAL_NAME,
-
EXTRACTOR_METATYPE_AUTHOR_NAME,
-
EXTRACTOR_METATYPE_SUBJECT,
-
EXTRACTOR_METATYPE_ALBUM,
-
EXTRACTOR_METATYPE_ARTIST,
-
EXTRACTOR_METATYPE_KEYWORDS,
-
EXTRACTOR_METATYPE_COMMENT,
-
EXTRACTOR_METATYPE_UNKNOWN,
- -1);
- if ( (base == NULL) &&
- (ext == NULL) )
+
EXTRACTOR_METATYPE_TITLE,
+
EXTRACTOR_METATYPE_BOOK_TITLE,
+
EXTRACTOR_METATYPE_ORIGINAL_TITLE,
+
EXTRACTOR_METATYPE_PACKAGE_NAME,
+ EXTRACTOR_METATYPE_URL,
+ EXTRACTOR_METATYPE_URI,
+
EXTRACTOR_METATYPE_DESCRIPTION,
+
EXTRACTOR_METATYPE_ISRC,
+
EXTRACTOR_METATYPE_JOURNAL_NAME,
+
EXTRACTOR_METATYPE_AUTHOR_NAME,
+
EXTRACTOR_METATYPE_SUBJECT,
+
EXTRACTOR_METATYPE_ALBUM,
+
EXTRACTOR_METATYPE_ARTIST,
+
EXTRACTOR_METATYPE_KEYWORDS,
+
EXTRACTOR_METATYPE_COMMENT,
+
EXTRACTOR_METATYPE_UNKNOWN,
+ -1);
+ if ((base == NULL) && (ext == NULL))
return NULL;
if (base == NULL)
return GNUNET_strdup (ext);
if (ext == NULL)
return base;
- GNUNET_asprintf (&ret,
- "%s%s",
- base,
- ext);
+ GNUNET_asprintf (&ret, "%s%s", base, ext);
GNUNET_free (base);
return ret;
}
@@ -168,7 +163,7 @@
*/
unsigned int
GNUNET_FS_get_current_year ()
-{
+{
time_t tp;
struct tm *t;
@@ -195,18 +190,18 @@
memset (&t, 0, sizeof (t));
if (year < 1900)
- {
- GNUNET_break (0);
- return GNUNET_TIME_absolute_get (); /* now */
- }
+ {
+ GNUNET_break (0);
+ return GNUNET_TIME_absolute_get (); /* now */
+ }
t.tm_year = year - 1900;
t.tm_mday = 1;
t.tm_mon = 1;
t.tm_wday = 1;
t.tm_yday = 1;
tp = mktime (&t);
- GNUNET_break (tp != (time_t) -1);
- ret.abs_value = tp * 1000LL; /* seconds to ms */
+ GNUNET_break (tp != (time_t) - 1);
+ ret.abs_value = tp * 1000LL; /* seconds to ms */
return ret;
}
Modified: gnunet/src/fs/fs_namespace.c
===================================================================
--- gnunet/src/fs/fs_namespace.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/fs/fs_namespace.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -46,16 +46,13 @@
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_filename (h->cfg,
- "FS",
- "IDENTITY_DIR",
- &dn))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Configuration fails to specify `%s' in section `%s'\n"),
- "IDENTITY_DIR",
- "fs");
- return NULL;
- }
+ "FS", "IDENTITY_DIR", &dn))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Configuration fails to specify `%s' in section `%s'\n"),
+ "IDENTITY_DIR", "fs");
+ return NULL;
+ }
return dn;
}
@@ -75,21 +72,14 @@
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_filename (ns->h->cfg,
- "FS",
- "UPDATE_DIR",
- &dn))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Configuration fails to specify `%s' in section `%s'\n"),
- "UPDATE_DIR",
- "fs");
- return NULL;
- }
- GNUNET_asprintf (&ret,
- "%s%s%s",
- dn,
- DIR_SEPARATOR_STR,
- ns->name);
+ "FS", "UPDATE_DIR", &dn))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Configuration fails to specify `%s' in section `%s'\n"),
+ "UPDATE_DIR", "fs");
+ return NULL;
+ }
+ GNUNET_asprintf (&ret, "%s%s%s", dn, DIR_SEPARATOR_STR, ns->name);
GNUNET_free (dn);
return ret;
}
@@ -103,7 +93,7 @@
static void
write_update_information_graph (struct GNUNET_FS_Namespace *ns)
{
- char * fn;
+ char *fn;
struct GNUNET_BIO_WriteHandle *wh;
unsigned int i;
struct NamespaceUpdateNode *n;
@@ -112,39 +102,35 @@
fn = get_update_information_directory (ns);
wh = GNUNET_BIO_write_open (fn);
if (wh == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to open `%s' for writing: %s\n"),
- STRERROR (errno));
- GNUNET_free (fn);
- return;
- }
- if (GNUNET_OK !=
- GNUNET_BIO_write_int32 (wh, ns->update_node_count))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to open `%s' for writing: %s\n"), STRERROR (errno));
+ GNUNET_free (fn);
+ return;
+ }
+ if (GNUNET_OK != GNUNET_BIO_write_int32 (wh, ns->update_node_count))
goto END;
- for (i=0;i<ns->update_node_count;i++)
+ for (i = 0; i < ns->update_node_count; i++)
+ {
+ n = ns->update_nodes[i];
+ uris = GNUNET_FS_uri_to_string (n->uri);
+ if ((GNUNET_OK !=
+ GNUNET_BIO_write_string (wh, n->id)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_write_meta_data (wh, n->md)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_write_string (wh, n->update)) ||
+ (GNUNET_OK != GNUNET_BIO_write_string (wh, uris)))
{
- n = ns->update_nodes[i];
- uris = GNUNET_FS_uri_to_string (n->uri);
- if ( (GNUNET_OK !=
- GNUNET_BIO_write_string (wh, n->id)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_meta_data (wh, n->md)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_string (wh, n->update)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_string (wh, uris)) )
- {
- GNUNET_free (uris);
- break;
- }
GNUNET_free (uris);
+ break;
}
- END:
+ GNUNET_free (uris);
+ }
+END:
if (GNUNET_OK != GNUNET_BIO_write_close (wh))
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to write `%s': %s\n"),
- STRERROR (errno));
+ _("Failed to write `%s': %s\n"), STRERROR (errno));
GNUNET_free (fn);
}
@@ -157,89 +143,85 @@
static void
read_update_information_graph (struct GNUNET_FS_Namespace *ns)
{
- char * fn;
+ char *fn;
struct GNUNET_BIO_ReadHandle *rh;
unsigned int i;
struct NamespaceUpdateNode *n;
char *uris;
uint32_t count;
char *emsg;
-
+
fn = get_update_information_directory (ns);
- if (GNUNET_YES !=
- GNUNET_DISK_file_test (fn))
- {
- GNUNET_free (fn);
- return;
- }
+ if (GNUNET_YES != GNUNET_DISK_file_test (fn))
+ {
+ GNUNET_free (fn);
+ return;
+ }
rh = GNUNET_BIO_read_open (fn);
if (rh == NULL)
+ {
+ GNUNET_free (fn);
+ return;
+ }
+ if (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &count))
+ {
+ GNUNET_break (0);
+ goto END;
+ }
+ if (count > 1024 * 1024)
+ {
+ GNUNET_break (0);
+ goto END;
+ }
+ if (count == 0)
+ {
+ GNUNET_break (GNUNET_OK == GNUNET_BIO_read_close (rh, NULL));
+ GNUNET_free (fn);
+ return;
+ }
+ ns->update_nodes =
+ GNUNET_malloc (count * sizeof (struct NamespaceUpdateNode *));
+
+ for (i = 0; i < count; i++)
+ {
+ n = GNUNET_malloc (sizeof (struct NamespaceUpdateNode));
+ if ((GNUNET_OK !=
+ GNUNET_BIO_read_string (rh, "identifier", &n->id, 1024)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_read_meta_data (rh, "meta", &n->md)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_read_string (rh, "update-id", &n->update, 1024)) ||
+ (GNUNET_OK != GNUNET_BIO_read_string (rh, "uri", &uris, 1024 * 2)))
{
- GNUNET_free (fn);
- return;
- }
- if (GNUNET_OK !=
- GNUNET_BIO_read_int32 (rh, &count))
- {
GNUNET_break (0);
- goto END;
+ GNUNET_free_non_null (n->id);
+ GNUNET_free_non_null (n->update);
+ if (n->md != NULL)
+ GNUNET_CONTAINER_meta_data_destroy (n->md);
+ GNUNET_free (n);
+ break;
}
- if (count > 1024 * 1024)
+ n->uri = GNUNET_FS_uri_parse (uris, &emsg);
+ GNUNET_free (uris);
+ if (n->uri == NULL)
{
GNUNET_break (0);
- goto END;
+ GNUNET_free (emsg);
+ GNUNET_free (n->id);
+ GNUNET_free_non_null (n->update);
+ GNUNET_CONTAINER_meta_data_destroy (n->md);
+ GNUNET_free (n);
+ break;
}
- if (count == 0)
- {
- GNUNET_break (GNUNET_OK == GNUNET_BIO_read_close (rh, NULL));
- GNUNET_free (fn);
- return;
- }
- ns->update_nodes = GNUNET_malloc (count * sizeof (struct
NamespaceUpdateNode*));
-
- for (i=0;i<count;i++)
- {
- n = GNUNET_malloc (sizeof (struct NamespaceUpdateNode));
- if ( (GNUNET_OK !=
- GNUNET_BIO_read_string (rh, "identifier", &n->id, 1024)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read_meta_data (rh, "meta", &n->md)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read_string (rh, "update-id", &n->update, 1024)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read_string (rh, "uri", &uris, 1024 * 2)) )
- {
- GNUNET_break (0);
- GNUNET_free_non_null (n->id);
- GNUNET_free_non_null (n->update);
- if (n->md != NULL)
- GNUNET_CONTAINER_meta_data_destroy (n->md);
- GNUNET_free (n);
- break;
- }
- n->uri = GNUNET_FS_uri_parse (uris, &emsg);
- GNUNET_free (uris);
- if (n->uri == NULL)
- {
- GNUNET_break (0);
- GNUNET_free (emsg);
- GNUNET_free (n->id);
- GNUNET_free_non_null (n->update);
- GNUNET_CONTAINER_meta_data_destroy (n->md);
- GNUNET_free (n);
- break;
- }
- ns->update_nodes[i] = n;
- }
+ ns->update_nodes[i] = n;
+ }
ns->update_node_count = i;
- END:
+END:
if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to write `%s': %s\n"),
- emsg);
- GNUNET_free (emsg);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to write `%s': %s\n"),
emsg);
+ GNUNET_free (emsg);
+ }
GNUNET_free (fn);
}
@@ -266,7 +248,7 @@
/**
* Our KSK URI.
- */
+ */
struct GNUNET_FS_Uri *ksk_uri;
/**
@@ -291,7 +273,7 @@
/**
* Number of bytes of plaintext.
- */
+ */
size_t pt_size;
/**
@@ -308,13 +290,11 @@
* @param tc scheduler context
*/
static void
-do_disconnect (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_disconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_DATASTORE_Handle *dsh = cls;
- GNUNET_DATASTORE_disconnect (dsh,
- GNUNET_NO);
+ GNUNET_DATASTORE_disconnect (dsh, GNUNET_NO);
}
@@ -327,9 +307,7 @@
* @param msg NULL on success, otherwise an error message
*/
static void
-advertisement_cont (void *cls,
- int success,
- const char *msg)
+advertisement_cont (void *cls, int success, const char *msg)
{
struct AdvertisementContext *ac = cls;
const char *keyword;
@@ -338,81 +316,75 @@
struct GNUNET_CRYPTO_AesSessionKey skey;
struct GNUNET_CRYPTO_AesInitializationVector iv;
struct GNUNET_CRYPTO_RsaPrivateKey *pk;
-
+
if (GNUNET_OK != success)
+ {
+ /* error! */
+ GNUNET_SCHEDULER_add_continuation (&do_disconnect,
+ ac->dsh,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ if (msg == NULL)
{
- /* error! */
- GNUNET_SCHEDULER_add_continuation (&do_disconnect,
- ac->dsh,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- if (msg == NULL)
- {
- GNUNET_break (0);
- msg = _("Unknown error");
- }
- if (ac->cont != NULL)
- ac->cont (ac->cont_cls, NULL, msg);
- GNUNET_FS_uri_destroy (ac->ksk_uri);
- GNUNET_free (ac->pt);
- GNUNET_free (ac->nb);
- GNUNET_FS_namespace_delete (ac->ns, GNUNET_NO);
- GNUNET_free (ac);
- return;
+ GNUNET_break (0);
+ msg = _("Unknown error");
}
+ if (ac->cont != NULL)
+ ac->cont (ac->cont_cls, NULL, msg);
+ GNUNET_FS_uri_destroy (ac->ksk_uri);
+ GNUNET_free (ac->pt);
+ GNUNET_free (ac->nb);
+ GNUNET_FS_namespace_delete (ac->ns, GNUNET_NO);
+ GNUNET_free (ac);
+ return;
+ }
if (ac->pos == ac->ksk_uri->data.ksk.keywordCount)
- {
- /* done! */
- GNUNET_SCHEDULER_add_continuation (&do_disconnect,
- ac->dsh,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- if (ac->cont != NULL)
- ac->cont (ac->cont_cls, ac->ksk_uri, NULL);
- GNUNET_FS_uri_destroy (ac->ksk_uri);
- GNUNET_free (ac->pt);
- GNUNET_free (ac->nb);
- GNUNET_FS_namespace_delete (ac->ns, GNUNET_NO);
- GNUNET_free (ac);
- return;
- }
+ {
+ /* done! */
+ GNUNET_SCHEDULER_add_continuation (&do_disconnect,
+ ac->dsh,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ if (ac->cont != NULL)
+ ac->cont (ac->cont_cls, ac->ksk_uri, NULL);
+ GNUNET_FS_uri_destroy (ac->ksk_uri);
+ GNUNET_free (ac->pt);
+ GNUNET_free (ac->nb);
+ GNUNET_FS_namespace_delete (ac->ns, GNUNET_NO);
+ GNUNET_free (ac);
+ return;
+ }
keyword = ac->ksk_uri->data.ksk.keywords[ac->pos++];
/* first character of keyword indicates if it is
- mandatory or not -- ignore for hashing */
+ * mandatory or not -- ignore for hashing */
GNUNET_CRYPTO_hash (&keyword[1], strlen (&keyword[1]), &key);
GNUNET_CRYPTO_hash_to_aes_key (&key, &skey, &iv);
- GNUNET_CRYPTO_aes_encrypt (ac->pt,
- ac->pt_size,
- &skey,
- &iv,
- &ac->nb[1]);
- GNUNET_break (GNUNET_OK ==
- GNUNET_CRYPTO_rsa_sign (ac->ns->key,
- &ac->nb->ns_purpose,
- &ac->nb->ns_signature));
+ GNUNET_CRYPTO_aes_encrypt (ac->pt, ac->pt_size, &skey, &iv, &ac->nb[1]);
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_CRYPTO_rsa_sign (ac->ns->key,
+ &ac->nb->ns_purpose,
+ &ac->nb->ns_signature));
pk = GNUNET_CRYPTO_rsa_key_create_from_hash (&key);
GNUNET_assert (pk != NULL);
GNUNET_CRYPTO_rsa_key_get_public (pk, &ac->nb->keyspace);
GNUNET_CRYPTO_hash (&ac->nb->keyspace,
- sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
- &query);
- GNUNET_break (GNUNET_OK ==
- GNUNET_CRYPTO_rsa_sign (pk,
- &ac->nb->ksk_purpose,
- &ac->nb->ksk_signature));
+ sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+ &query);
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_CRYPTO_rsa_sign (pk,
+ &ac->nb->ksk_purpose,
+ &ac->nb->ksk_signature));
GNUNET_CRYPTO_rsa_key_free (pk);
- GNUNET_DATASTORE_put (ac->dsh,
- 0 /* no reservation */,
- &query,
- ac->pt_size + sizeof (struct NBlock),
- ac->nb,
- GNUNET_BLOCK_TYPE_FS_NBLOCK,
- ac->bo.content_priority,
- ac->bo.anonymity_level,
- ac->bo.replication_level,
- ac->bo.expiration_time,
- -2, 1,
- GNUNET_CONSTANTS_SERVICE_TIMEOUT,
- &advertisement_cont,
- ac);
+ GNUNET_DATASTORE_put (ac->dsh, 0 /* no reservation */ ,
+ &query,
+ ac->pt_size + sizeof (struct NBlock),
+ ac->nb,
+ GNUNET_BLOCK_TYPE_FS_NBLOCK,
+ ac->bo.content_priority,
+ ac->bo.anonymity_level,
+ ac->bo.replication_level,
+ ac->bo.expiration_time,
+ -2, 1,
+ GNUNET_CONSTANTS_SERVICE_TIMEOUT,
+ &advertisement_cont, ac);
}
@@ -430,13 +402,13 @@
*/
void
GNUNET_FS_namespace_advertise (struct GNUNET_FS_Handle *h,
- struct GNUNET_FS_Uri *ksk_uri,
- struct GNUNET_FS_Namespace *namespace,
- const struct GNUNET_CONTAINER_MetaData *meta,
- const struct GNUNET_FS_BlockOptions *bo,
- const char *rootEntry,
- GNUNET_FS_PublishContinuation cont,
- void *cont_cls)
+ struct GNUNET_FS_Uri *ksk_uri,
+ struct GNUNET_FS_Namespace *namespace,
+ const struct GNUNET_CONTAINER_MetaData *meta,
+ const struct GNUNET_FS_BlockOptions *bo,
+ const char *rootEntry,
+ GNUNET_FS_PublishContinuation cont,
+ void *cont_cls)
{
size_t reslen;
size_t size;
@@ -450,50 +422,52 @@
/* create advertisements */
mdsize = GNUNET_CONTAINER_meta_data_get_serialized_size (meta);
if (-1 == mdsize)
- {
- cont (cont_cls, NULL, _("Failed to serialize meta data"));
- return;
- }
+ {
+ cont (cont_cls, NULL, _("Failed to serialize meta data"));
+ return;
+ }
reslen = strlen (rootEntry) + 1;
size = mdsize + sizeof (struct NBlock) + reslen;
if (size > MAX_NBLOCK_SIZE)
- {
- size = MAX_NBLOCK_SIZE;
- mdsize = size - sizeof (struct NBlock) - reslen;
- }
+ {
+ size = MAX_NBLOCK_SIZE;
+ mdsize = size - sizeof (struct NBlock) - reslen;
+ }
pt = GNUNET_malloc (mdsize + reslen);
memcpy (pt, rootEntry, reslen);
mdst = &pt[reslen];
mdsize = GNUNET_CONTAINER_meta_data_serialize (meta,
- &mdst,
- mdsize,
-
GNUNET_CONTAINER_META_DATA_SERIALIZE_PART);
+ &mdst,
+ mdsize,
+
GNUNET_CONTAINER_META_DATA_SERIALIZE_PART);
if (mdsize == -1)
- {
- GNUNET_break (0);
- GNUNET_free (pt);
- cont (cont_cls, NULL, _("Failed to serialize meta data"));
- return;
- }
- size = mdsize + sizeof (struct NBlock) + reslen;
+ {
+ GNUNET_break (0);
+ GNUNET_free (pt);
+ cont (cont_cls, NULL, _("Failed to serialize meta data"));
+ return;
+ }
+ size = mdsize + sizeof (struct NBlock) + reslen;
nb = GNUNET_malloc (size);
- GNUNET_CRYPTO_rsa_key_get_public (namespace->key,
- &nb->subspace);
- nb->ns_purpose.size = htonl (mdsize + reslen +
- sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
- sizeof (struct
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
+ GNUNET_CRYPTO_rsa_key_get_public (namespace->key, &nb->subspace);
+ nb->ns_purpose.size = htonl (mdsize + reslen +
+ sizeof (struct
GNUNET_CRYPTO_RsaSignaturePurpose)
+ +
+ sizeof (struct
+
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
nb->ns_purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK);
- nb->ksk_purpose.size = htonl (size - sizeof (struct
GNUNET_CRYPTO_RsaSignature));
+ nb->ksk_purpose.size =
+ htonl (size - sizeof (struct GNUNET_CRYPTO_RsaSignature));
nb->ksk_purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK_KSIG);
dsh = GNUNET_DATASTORE_connect (h->cfg);
if (NULL == dsh)
- {
- GNUNET_free (nb);
- GNUNET_free (pt);
- cont (cont_cls, NULL, _("Failed to connect to datastore service"));
- return;
- }
+ {
+ GNUNET_free (nb);
+ GNUNET_free (pt);
+ cont (cont_cls, NULL, _("Failed to connect to datastore service"));
+ return;
+ }
ctx = GNUNET_malloc (sizeof (struct AdvertisementContext));
ctx->cont = cont;
ctx->cont_cls = cont_cls;
@@ -518,33 +492,28 @@
* @return handle to the namespace, NULL on error
*/
struct GNUNET_FS_Namespace *
-GNUNET_FS_namespace_create (struct GNUNET_FS_Handle *h,
- const char *name)
+GNUNET_FS_namespace_create (struct GNUNET_FS_Handle *h, const char *name)
{
char *dn;
char *fn;
struct GNUNET_FS_Namespace *ret;
dn = get_namespace_directory (h);
- GNUNET_asprintf (&fn,
- "%s%s%s",
- dn,
- DIR_SEPARATOR_STR,
- name);
+ GNUNET_asprintf (&fn, "%s%s%s", dn, DIR_SEPARATOR_STR, name);
GNUNET_free (dn);
ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Namespace));
ret->h = h;
ret->rc = 1;
ret->key = GNUNET_CRYPTO_rsa_key_create_from_file (fn);
if (ret->key == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to create or read private key for namespace
`%s'\n"),
- name);
- GNUNET_free (ret);
- GNUNET_free (fn);
- return NULL;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to create or read private key for namespace `%s'\n"),
+ name);
+ GNUNET_free (ret);
+ GNUNET_free (fn);
+ return NULL;
+ }
ret->name = GNUNET_strdup (name);
ret->filename = fn;
return ret;
@@ -562,42 +531,39 @@
*
* @return GNUNET_OK on success, GNUNET_SYSERR on error
*/
-int
-GNUNET_FS_namespace_delete (struct GNUNET_FS_Namespace *namespace,
- int freeze)
+int
+GNUNET_FS_namespace_delete (struct GNUNET_FS_Namespace *namespace, int freeze)
{
unsigned int i;
struct NamespaceUpdateNode *nsn;
namespace->rc--;
if (freeze)
- {
- if (0 != UNLINK (namespace->filename))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
- "unlink",
- namespace->filename);
- }
+ {
+ if (0 != UNLINK (namespace->filename))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
+ "unlink", namespace->filename);
+ }
if (0 == namespace->rc)
+ {
+ GNUNET_CRYPTO_rsa_key_free (namespace->key);
+ GNUNET_free (namespace->filename);
+ GNUNET_free (namespace->name);
+ for (i = 0; i < namespace->update_node_count; i++)
{
- GNUNET_CRYPTO_rsa_key_free (namespace->key);
- GNUNET_free (namespace->filename);
- GNUNET_free (namespace->name);
- for (i=0;i<namespace->update_node_count;i++)
- {
- nsn = namespace->update_nodes[i];
- GNUNET_CONTAINER_meta_data_destroy (nsn->md);
- GNUNET_FS_uri_destroy (nsn->uri);
- GNUNET_free (nsn->id);
- GNUNET_free (nsn->update);
- GNUNET_free (nsn);
- }
- GNUNET_array_grow (namespace->update_nodes,
- namespace->update_node_count,
- 0);
- if (namespace->update_map != NULL)
- GNUNET_CONTAINER_multihashmap_destroy (namespace->update_map);
- GNUNET_free (namespace);
+ nsn = namespace->update_nodes[i];
+ GNUNET_CONTAINER_meta_data_destroy (nsn->md);
+ GNUNET_FS_uri_destroy (nsn->uri);
+ GNUNET_free (nsn->id);
+ GNUNET_free (nsn->update);
+ GNUNET_free (nsn);
}
+ GNUNET_array_grow (namespace->update_nodes,
+ namespace->update_node_count, 0);
+ if (namespace->update_map != NULL)
+ GNUNET_CONTAINER_multihashmap_destroy (namespace->update_map);
+ GNUNET_free (namespace);
+ }
return GNUNET_OK;
}
@@ -630,8 +596,7 @@
* GNUNET_SYSERR to abort iteration with error!
*/
static int
-process_namespace (void *cls,
- const char *filename)
+process_namespace (void *cls, const char *filename)
{
struct ProcessNamespaceContext *pnc = cls;
struct GNUNET_CRYPTO_RsaPrivateKey *key;
@@ -642,25 +607,22 @@
key = GNUNET_CRYPTO_rsa_key_create_from_file (filename);
if (key == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to read namespace private key file `%s', deleting
it!\n"),
- filename);
- if (0 != UNLINK (filename))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
- "unlink",
- filename);
- return GNUNET_OK;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _
+ ("Failed to read namespace private key file `%s', deleting
it!\n"),
+ filename);
+ if (0 != UNLINK (filename))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename);
+ return GNUNET_OK;
+ }
GNUNET_CRYPTO_rsa_key_get_public (key, &pk);
GNUNET_CRYPTO_rsa_key_free (key);
- GNUNET_CRYPTO_hash (&pk, sizeof(pk), &id);
+ GNUNET_CRYPTO_hash (&pk, sizeof (pk), &id);
name = filename;
while (NULL != (t = strstr (name, DIR_SEPARATOR_STR)))
name = t + 1;
- pnc->cb (pnc->cb_cls,
- name,
- &id);
+ pnc->cb (pnc->cb_cls, name, &id);
return GNUNET_OK;
}
@@ -674,22 +636,19 @@
* @param cb function to call on each known namespace
* @param cb_cls closure for cb
*/
-void
+void
GNUNET_FS_namespace_list (struct GNUNET_FS_Handle *h,
- GNUNET_FS_NamespaceInfoProcessor cb,
- void *cb_cls)
+ GNUNET_FS_NamespaceInfoProcessor cb, void *cb_cls)
{
char *dn;
struct ProcessNamespaceContext ctx;
-
+
dn = get_namespace_directory (h);
if (dn == NULL)
return;
ctx.cb = cb;
ctx.cb_cls = cb_cls;
- GNUNET_DISK_directory_scan (dn,
- &process_namespace,
- &ctx);
+ GNUNET_DISK_directory_scan (dn, &process_namespace, &ctx);
GNUNET_free (dn);
}
@@ -730,7 +689,7 @@
/**
* Closure for cont.
- */
+ */
void *cont_cls;
};
@@ -745,66 +704,56 @@
* @param msg error message (or NULL)
*/
static void
-sb_put_cont (void *cls,
- int success,
- const char *msg)
+sb_put_cont (void *cls, int success, const char *msg)
{
struct PublishSksContext *psc = cls;
GNUNET_HashCode hc;
if (NULL != psc->dsh)
- {
- GNUNET_DATASTORE_disconnect (psc->dsh, GNUNET_NO);
- psc->dsh = NULL;
- }
+ {
+ GNUNET_DATASTORE_disconnect (psc->dsh, GNUNET_NO);
+ psc->dsh = NULL;
+ }
if (GNUNET_OK != success)
- {
- if (psc->cont != NULL)
- psc->cont (psc->cont_cls,
- NULL,
- msg);
- }
+ {
+ if (psc->cont != NULL)
+ psc->cont (psc->cont_cls, NULL, msg);
+ }
else
+ {
+ if (psc->nsn != NULL)
{
- if (psc->nsn != NULL)
- {
- /* FIXME: this can be done much more
- efficiently by simply appending to the
- file and overwriting the 4-byte header */
- if (psc->namespace->update_nodes == NULL)
- read_update_information_graph (psc->namespace);
- GNUNET_array_append (psc->namespace->update_nodes,
- psc->namespace->update_node_count,
- psc->nsn);
- if (psc->namespace->update_map != NULL)
- {
- GNUNET_CRYPTO_hash (psc->nsn->id,
- strlen (psc->nsn->id),
- &hc);
- GNUNET_CONTAINER_multihashmap_put (psc->namespace->update_map,
- &hc,
- psc->nsn,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
- }
- psc->nsn = NULL;
- write_update_information_graph (psc->namespace);
- }
- if (psc->cont != NULL)
- psc->cont (psc->cont_cls,
- psc->uri,
- NULL);
+ /* FIXME: this can be done much more
+ * efficiently by simply appending to the
+ * file and overwriting the 4-byte header */
+ if (psc->namespace->update_nodes == NULL)
+ read_update_information_graph (psc->namespace);
+ GNUNET_array_append (psc->namespace->update_nodes,
+ psc->namespace->update_node_count, psc->nsn);
+ if (psc->namespace->update_map != NULL)
+ {
+ GNUNET_CRYPTO_hash (psc->nsn->id, strlen (psc->nsn->id), &hc);
+ GNUNET_CONTAINER_multihashmap_put (psc->namespace->update_map,
+ &hc,
+ psc->nsn,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
+ }
+ psc->nsn = NULL;
+ write_update_information_graph (psc->namespace);
}
- GNUNET_FS_namespace_delete (psc->namespace,
- GNUNET_NO);
+ if (psc->cont != NULL)
+ psc->cont (psc->cont_cls, psc->uri, NULL);
+ }
+ GNUNET_FS_namespace_delete (psc->namespace, GNUNET_NO);
GNUNET_FS_uri_destroy (psc->uri);
if (psc->nsn != NULL)
- {
- GNUNET_CONTAINER_meta_data_destroy (psc->nsn->md);
- GNUNET_FS_uri_destroy (psc->nsn->uri);
- GNUNET_free (psc->nsn->id);
- GNUNET_free (psc->nsn->update);
- GNUNET_free (psc->nsn);
- }
+ {
+ GNUNET_CONTAINER_meta_data_destroy (psc->nsn->md);
+ GNUNET_FS_uri_destroy (psc->nsn->uri);
+ GNUNET_free (psc->nsn->id);
+ GNUNET_free (psc->nsn->update);
+ GNUNET_free (psc->nsn);
+ }
GNUNET_free (psc);
}
@@ -825,15 +774,14 @@
*/
void
GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
- struct GNUNET_FS_Namespace *namespace,
- const char *identifier,
- const char *update,
- const struct GNUNET_CONTAINER_MetaData *meta,
- const struct GNUNET_FS_Uri *uri,
- const struct GNUNET_FS_BlockOptions *bo,
- enum GNUNET_FS_PublishOptions options,
- GNUNET_FS_PublishContinuation cont,
- void *cont_cls)
+ struct GNUNET_FS_Namespace *namespace,
+ const char *identifier,
+ const char *update,
+ const struct GNUNET_CONTAINER_MetaData *meta,
+ const struct GNUNET_FS_Uri *uri,
+ const struct GNUNET_FS_BlockOptions *bo,
+ enum GNUNET_FS_PublishOptions options,
+ GNUNET_FS_PublishContinuation cont, void *cont_cls)
{
struct PublishSksContext *psc;
struct GNUNET_CRYPTO_AesSessionKey sk;
@@ -849,9 +797,9 @@
struct SBlock *sb_enc;
char *dest;
struct GNUNET_CONTAINER_MetaData *mmeta;
- GNUNET_HashCode key; /* hash of thisId = key */
- GNUNET_HashCode id; /* hash of hc = identifier */
- GNUNET_HashCode query; /* id ^ nsid = DB query */
+ GNUNET_HashCode key; /* hash of thisId = key */
+ GNUNET_HashCode id; /* hash of hc = identifier */
+ GNUNET_HashCode query; /* id ^ nsid = DB query */
if (NULL == meta)
mmeta = GNUNET_CONTAINER_meta_data_create ();
@@ -867,10 +815,10 @@
mdsize = GNUNET_CONTAINER_meta_data_get_serialized_size (mmeta);
size = sizeof (struct SBlock) + slen + nidlen + mdsize;
if (size > MAX_SBLOCK_SIZE)
- {
- size = MAX_SBLOCK_SIZE;
- mdsize = size - (sizeof (struct SBlock) + slen + nidlen);
- }
+ {
+ size = MAX_SBLOCK_SIZE;
+ mdsize = size - (sizeof (struct SBlock) + slen + nidlen);
+ }
sb = GNUNET_malloc (sizeof (struct SBlock) + size);
dest = (char *) &sb[1];
if (update != NULL)
@@ -882,19 +830,17 @@
GNUNET_free (uris);
dest += slen;
mdsize = GNUNET_CONTAINER_meta_data_serialize (mmeta,
- &dest,
- mdsize,
-
GNUNET_CONTAINER_META_DATA_SERIALIZE_PART);
+ &dest,
+ mdsize,
+
GNUNET_CONTAINER_META_DATA_SERIALIZE_PART);
GNUNET_CONTAINER_meta_data_destroy (mmeta);
if (mdsize == -1)
- {
- GNUNET_break (0);
- GNUNET_free (sb);
- cont (cont_cls,
- NULL,
- _("Internal error."));
- return;
- }
+ {
+ GNUNET_break (0);
+ GNUNET_free (sb);
+ cont (cont_cls, NULL, _("Internal error."));
+ return;
+ }
size = sizeof (struct SBlock) + mdsize + slen + nidlen;
sb_enc = GNUNET_malloc (size);
GNUNET_CRYPTO_hash (identifier, idlen, &key);
@@ -903,76 +849,64 @@
sks_uri->type = sks;
GNUNET_CRYPTO_rsa_key_get_public (namespace->key, &sb_enc->subspace);
GNUNET_CRYPTO_hash (&sb_enc->subspace,
- sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
- &sks_uri->data.sks.namespace);
+ sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+ &sks_uri->data.sks.namespace);
sks_uri->data.sks.identifier = GNUNET_strdup (identifier);
- GNUNET_CRYPTO_hash_xor (&id,
- &sks_uri->data.sks.namespace,
- &sb_enc->identifier);
+ GNUNET_CRYPTO_hash_xor (&id,
+ &sks_uri->data.sks.namespace, &sb_enc->identifier);
GNUNET_CRYPTO_hash_to_aes_key (&key, &sk, &iv);
GNUNET_CRYPTO_aes_encrypt (&sb[1],
- size - sizeof (struct SBlock),
- &sk,
- &iv,
- &sb_enc[1]);
+ size - sizeof (struct SBlock),
+ &sk, &iv, &sb_enc[1]);
sb_enc->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_FS_SBLOCK);
- sb_enc->purpose.size = htonl(slen + mdsize + nidlen
- + sizeof(struct SBlock)
- - sizeof(struct GNUNET_CRYPTO_RsaSignature));
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CRYPTO_rsa_sign (namespace->key,
- &sb_enc->purpose,
- &sb_enc->signature));
- psc = GNUNET_malloc (sizeof(struct PublishSksContext));
+ sb_enc->purpose.size = htonl (slen + mdsize + nidlen
+ + sizeof (struct SBlock)
+ - sizeof (struct GNUNET_CRYPTO_RsaSignature));
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CRYPTO_rsa_sign (namespace->key,
+ &sb_enc->purpose,
&sb_enc->signature));
+ psc = GNUNET_malloc (sizeof (struct PublishSksContext));
psc->uri = sks_uri;
psc->cont = cont;
psc->namespace = namespace;
namespace->rc++;
psc->cont_cls = cont_cls;
if (0 != (options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY))
- {
- GNUNET_free (sb_enc);
- GNUNET_free (sb);
- sb_put_cont (psc,
- GNUNET_OK,
- NULL);
- return;
- }
+ {
+ GNUNET_free (sb_enc);
+ GNUNET_free (sb);
+ sb_put_cont (psc, GNUNET_OK, NULL);
+ return;
+ }
psc->dsh = GNUNET_DATASTORE_connect (h->cfg);
if (NULL == psc->dsh)
- {
- GNUNET_free (sb_enc);
- GNUNET_free (sb);
- sb_put_cont (psc,
- GNUNET_NO,
- _("Failed to connect to datastore."));
- return;
- }
- GNUNET_CRYPTO_hash_xor (&sks_uri->data.sks.namespace,
- &id,
- &query);
+ {
+ GNUNET_free (sb_enc);
+ GNUNET_free (sb);
+ sb_put_cont (psc, GNUNET_NO, _("Failed to connect to datastore."));
+ return;
+ }
+ GNUNET_CRYPTO_hash_xor (&sks_uri->data.sks.namespace, &id, &query);
if (NULL != update)
- {
- psc->nsn = GNUNET_malloc (sizeof (struct NamespaceUpdateNode));
- psc->nsn->id = GNUNET_strdup (identifier);
- psc->nsn->update = GNUNET_strdup (update);
- psc->nsn->md = GNUNET_CONTAINER_meta_data_duplicate (meta);
- psc->nsn->uri = GNUNET_FS_uri_dup (uri);
- }
+ {
+ psc->nsn = GNUNET_malloc (sizeof (struct NamespaceUpdateNode));
+ psc->nsn->id = GNUNET_strdup (identifier);
+ psc->nsn->update = GNUNET_strdup (update);
+ psc->nsn->md = GNUNET_CONTAINER_meta_data_duplicate (meta);
+ psc->nsn->uri = GNUNET_FS_uri_dup (uri);
+ }
GNUNET_DATASTORE_put (psc->dsh,
- 0,
- &sb_enc->identifier,
- size,
- sb_enc,
- GNUNET_BLOCK_TYPE_FS_SBLOCK,
- bo->content_priority,
- bo->anonymity_level,
- bo->replication_level,
- bo->expiration_time,
- -2, 1,
- GNUNET_CONSTANTS_SERVICE_TIMEOUT,
- &sb_put_cont,
- psc);
+ 0,
+ &sb_enc->identifier,
+ size,
+ sb_enc,
+ GNUNET_BLOCK_TYPE_FS_SBLOCK,
+ bo->content_priority,
+ bo->anonymity_level,
+ bo->replication_level,
+ bo->expiration_time,
+ -2, 1,
+ GNUNET_CONSTANTS_SERVICE_TIMEOUT, &sb_put_cont, psc);
GNUNET_free (sb);
GNUNET_free (sb_enc);
}
@@ -981,7 +915,7 @@
/**
* Closure for 'process_update_node'.
*/
-struct ProcessUpdateClosure
+struct ProcessUpdateClosure
{
/**
* Function to call for each node.
@@ -1006,18 +940,12 @@
* GNUNET_NO if not.
*/
static int
-process_update_node (void *cls,
- const GNUNET_HashCode * key,
- void *value)
+process_update_node (void *cls, const GNUNET_HashCode * key, void *value)
{
struct ProcessUpdateClosure *pc = cls;
struct NamespaceUpdateNode *nsn = value;
- pc->ip (pc->ip_cls,
- nsn->id,
- nsn->uri,
- nsn->md,
- nsn->update);
+ pc->ip (pc->ip_cls, nsn->id, nsn->uri, nsn->md, nsn->update);
return GNUNET_YES;
}
@@ -1025,7 +953,7 @@
/**
* Closure for 'find_trees'.
*/
-struct FindTreeClosure
+struct FindTreeClosure
{
/**
* Namespace we are operating on.
@@ -1075,42 +1003,36 @@
* GNUNET_NO if not.
*/
static int
-find_trees (void *cls,
- const GNUNET_HashCode * key,
- void *value)
+find_trees (void *cls, const GNUNET_HashCode * key, void *value)
{
struct FindTreeClosure *fc = cls;
struct NamespaceUpdateNode *nsn = value;
GNUNET_HashCode hc;
if (nsn->nug == fc->nug)
- {
- if (nsn->tree_id == UINT_MAX)
- return GNUNET_YES; /* circular */
- GNUNET_assert (nsn->tree_id < fc->tree_array_size);
- if (fc->tree_array[nsn->tree_id] != nsn)
- return GNUNET_YES; /* part of "another" (directed) TREE,
- and not root of it, end trace */
- if (nsn->tree_id == fc->id)
- return GNUNET_YES; /* that's our own root (can this be?) */
- /* merge existing TREE, we have a root for both */
- fc->tree_array[nsn->tree_id] = NULL;
- if (fc->id == UINT_MAX)
- fc->id = nsn->tree_id; /* take over ID */
- }
+ {
+ if (nsn->tree_id == UINT_MAX)
+ return GNUNET_YES; /* circular */
+ GNUNET_assert (nsn->tree_id < fc->tree_array_size);
+ if (fc->tree_array[nsn->tree_id] != nsn)
+ return GNUNET_YES; /* part of "another" (directed) TREE,
+ * and not root of it, end trace */
+ if (nsn->tree_id == fc->id)
+ return GNUNET_YES; /* that's our own root (can this be?) */
+ /* merge existing TREE, we have a root for both */
+ fc->tree_array[nsn->tree_id] = NULL;
+ if (fc->id == UINT_MAX)
+ fc->id = nsn->tree_id; /* take over ID */
+ }
else
- {
- nsn->nug = fc->nug;
- nsn->tree_id = UINT_MAX; /* mark as undef */
- /* trace */
- GNUNET_CRYPTO_hash (nsn->update,
- strlen (nsn->update),
- &hc);
- GNUNET_CONTAINER_multihashmap_get_multiple (fc->namespace->update_map,
- &hc,
- &find_trees,
- fc);
- }
+ {
+ nsn->nug = fc->nug;
+ nsn->tree_id = UINT_MAX; /* mark as undef */
+ /* trace */
+ GNUNET_CRYPTO_hash (nsn->update, strlen (nsn->update), &hc);
+ GNUNET_CONTAINER_multihashmap_get_multiple (fc->namespace->update_map,
+ &hc, &find_trees, fc);
+ }
return GNUNET_YES;
}
@@ -1139,9 +1061,9 @@
*/
void
GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Namespace *namespace,
- const char *next_id,
- GNUNET_FS_IdentifierProcessor ip,
- void *ip_cls)
+ const char *next_id,
+ GNUNET_FS_IdentifierProcessor ip,
+ void *ip_cls)
{
unsigned int i;
unsigned int nug;
@@ -1153,154 +1075,125 @@
if (namespace->update_nodes == NULL)
read_update_information_graph (namespace);
if (namespace->update_nodes == NULL)
- {
+ {
#if DEBUG_NAMESPACE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "No updateable nodes found for ID `%s'\n",
- next_id);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "No updateable nodes found for ID `%s'\n", next_id);
#endif
- return; /* no nodes */
- }
+ return; /* no nodes */
+ }
if (namespace->update_map == NULL)
+ {
+ /* need to construct */
+ namespace->update_map =
+ GNUNET_CONTAINER_multihashmap_create (2 +
+ 3 * namespace->update_node_count
/
+ 4);
+ for (i = 0; i < namespace->update_node_count; i++)
{
- /* need to construct */
- namespace->update_map = GNUNET_CONTAINER_multihashmap_create (2 + 3 *
namespace->update_node_count / 4);
- for (i=0;i<namespace->update_node_count;i++)
- {
- nsn = namespace->update_nodes[i];
- GNUNET_CRYPTO_hash (nsn->id,
- strlen (nsn->id),
- &hc);
- GNUNET_CONTAINER_multihashmap_put (namespace->update_map,
- &hc,
- nsn,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
- }
+ nsn = namespace->update_nodes[i];
+ GNUNET_CRYPTO_hash (nsn->id, strlen (nsn->id), &hc);
+ GNUNET_CONTAINER_multihashmap_put (namespace->update_map,
+ &hc,
+ nsn,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
}
+ }
if (next_id != NULL)
- {
- GNUNET_CRYPTO_hash (next_id,
- strlen (next_id),
- &hc);
- pc.ip = ip;
- pc.ip_cls = ip_cls;
- GNUNET_CONTAINER_multihashmap_get_multiple (namespace->update_map,
- &hc,
- &process_update_node,
- &pc);
- return;
- }
+ {
+ GNUNET_CRYPTO_hash (next_id, strlen (next_id), &hc);
+ pc.ip = ip;
+ pc.ip_cls = ip_cls;
+ GNUNET_CONTAINER_multihashmap_get_multiple (namespace->update_map,
+ &hc, &process_update_node,
&pc);
+ return;
+ }
#if DEBUG_NAMESPACE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Calculating TREEs to find roots of update trees\n");
+ "Calculating TREEs to find roots of update trees\n");
#endif
/* Find heads of TREEs in update graph */
nug = ++namespace->nug_gen;
fc.tree_array = NULL;
fc.tree_array_size = 0;
- for (i=0;i<namespace->update_node_count;i++)
+ for (i = 0; i < namespace->update_node_count; i++)
+ {
+ nsn = namespace->update_nodes[i];
+ if (nsn->nug == nug)
{
- nsn = namespace->update_nodes[i];
- if (nsn->nug == nug)
- {
#if DEBUG_NAMESPACE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "TREE of node `%s' is %u\n",
- nsn->id,
- nsn->nug);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "TREE of node `%s' is %u\n", nsn->id, nsn->nug);
#endif
- continue; /* already placed in TREE */
- }
- GNUNET_CRYPTO_hash (nsn->update,
- strlen (nsn->update),
- &hc);
- nsn->nug = nug;
- fc.id = UINT_MAX;
+ continue; /* already placed in TREE */
+ }
+ GNUNET_CRYPTO_hash (nsn->update, strlen (nsn->update), &hc);
+ nsn->nug = nug;
+ fc.id = UINT_MAX;
+ fc.nug = nug;
+ fc.namespace = namespace;
+ GNUNET_CONTAINER_multihashmap_get_multiple (namespace->update_map,
+ &hc, &find_trees, &fc);
+ if (fc.id == UINT_MAX)
+ {
+ /* start new TREE */
+ for (fc.id = 0; fc.id < fc.tree_array_size; fc.id++)
+ {
+ if (fc.tree_array[fc.id] == NULL)
+ {
+ fc.tree_array[fc.id] = nsn;
+ nsn->tree_id = fc.id;
+ break;
+ }
+ }
+ if (fc.id == fc.tree_array_size)
+ {
+ GNUNET_array_append (fc.tree_array, fc.tree_array_size, nsn);
+ nsn->tree_id = fc.id;
+ }
+#if DEBUG_NAMESPACE
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Starting new TREE %u with node `%s'\n",
+ nsn->tree_id, nsn->id);
+#endif
+ /* put all nodes with same identifier into this TREE */
+ GNUNET_CRYPTO_hash (nsn->id, strlen (nsn->id), &hc);
+ fc.id = nsn->tree_id;
fc.nug = nug;
fc.namespace = namespace;
GNUNET_CONTAINER_multihashmap_get_multiple (namespace->update_map,
- &hc,
- &find_trees,
- &fc);
- if (fc.id == UINT_MAX)
- {
- /* start new TREE */
- for (fc.id=0;fc.id<fc.tree_array_size;fc.id++)
- {
- if (fc.tree_array[fc.id] == NULL)
- {
- fc.tree_array[fc.id] = nsn;
- nsn->tree_id = fc.id;
- break;
- }
- }
- if (fc.id == fc.tree_array_size)
- {
- GNUNET_array_append (fc.tree_array,
- fc.tree_array_size,
- nsn);
- nsn->tree_id = fc.id;
- }
+ &hc, &find_trees, &fc);
+ }
+ else
+ {
+ /* make head of TREE "id" */
+ fc.tree_array[fc.id] = nsn;
+ nsn->tree_id = fc.id;
+ }
#if DEBUG_NAMESPACE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Starting new TREE %u with node `%s'\n",
- nsn->tree_id,
- nsn->id);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "TREE of node `%s' is %u\n", nsn->id, fc.id);
#endif
- /* put all nodes with same identifier into this TREE */
- GNUNET_CRYPTO_hash (nsn->id,
- strlen (nsn->id),
- &hc);
- fc.id = nsn->tree_id;
- fc.nug = nug;
- fc.namespace = namespace;
- GNUNET_CONTAINER_multihashmap_get_multiple (namespace->update_map,
- &hc,
- &find_trees,
- &fc);
- }
- else
- {
- /* make head of TREE "id" */
- fc.tree_array[fc.id] = nsn;
- nsn->tree_id = fc.id;
- }
+ }
+ for (i = 0; i < fc.tree_array_size; i++)
+ {
+ nsn = fc.tree_array[i];
+ if (NULL != nsn)
+ {
#if DEBUG_NAMESPACE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "TREE of node `%s' is %u\n",
- nsn->id,
- fc.id);
+ "Root of TREE %u is node `%s'\n", i, nsn->id);
#endif
- }
- for (i=0;i<fc.tree_array_size;i++)
- {
- nsn = fc.tree_array[i];
- if (NULL != nsn)
- {
-#if DEBUG_NAMESPACE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Root of TREE %u is node `%s'\n",
- i,
- nsn->id);
-#endif
- ip (ip_cls,
- nsn->id,
- nsn->uri,
- nsn->md,
- nsn->update);
- }
+ ip (ip_cls, nsn->id, nsn->uri, nsn->md, nsn->update);
}
- GNUNET_array_grow (fc.tree_array,
- fc.tree_array_size,
- 0);
+ }
+ GNUNET_array_grow (fc.tree_array, fc.tree_array_size, 0);
#if DEBUG_NAMESPACE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Done processing TREEs\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Done processing TREEs\n");
#endif
}
/* end of fs_namespace.c */
-
Modified: gnunet/src/fs/fs_publish.c
===================================================================
--- gnunet/src/fs/fs_publish.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/fs/fs_publish.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -49,28 +49,25 @@
*/
void *
GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
- struct GNUNET_FS_PublishContext *pc,
- const struct GNUNET_FS_FileInformation *p,
- uint64_t offset)
+ struct GNUNET_FS_PublishContext *pc,
+ const struct GNUNET_FS_FileInformation *p,
+ uint64_t offset)
{
pi->value.publish.pc = pc;
pi->value.publish.fi = p;
- pi->value.publish.cctx
- = p->client_info;
- pi->value.publish.pctx
- = (NULL == p->dir) ? NULL : p->dir->client_info;
+ pi->value.publish.cctx = p->client_info;
+ pi->value.publish.pctx = (NULL == p->dir) ? NULL : p->dir->client_info;
pi->value.publish.filename = p->filename;
- pi->value.publish.size
- = (p->is_directory) ? p->data.dir.dir_size : p->data.file.file_size;
- pi->value.publish.eta
- = GNUNET_TIME_calculate_eta (p->start_time,
- offset,
- pi->value.publish.size);
+ pi->value.publish.size
+ = (p->is_directory) ? p->data.dir.dir_size : p->data.file.file_size;
+ pi->value.publish.eta
+ = GNUNET_TIME_calculate_eta (p->start_time,
+ offset, pi->value.publish.size);
pi->value.publish.completed = offset;
- pi->value.publish.duration = GNUNET_TIME_absolute_get_duration
(p->start_time);
+ pi->value.publish.duration =
+ GNUNET_TIME_absolute_get_duration (p->start_time);
pi->value.publish.anonymity = p->bo.anonymity_level;
- return pc->h->upcb (pc->h->upcb_cls,
- pi);
+ return pc->h->upcb (pc->h->upcb_cls, pi);
}
@@ -81,39 +78,37 @@
* @param tc scheduler context
*/
static void
-publish_cleanup (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+publish_cleanup (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_FS_PublishContext *pc = cls;
#if DEBUG_PUBLISH
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Cleaning up publish context (done!)\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up publish context
(done!)\n");
#endif
if (pc->fhc != NULL)
- {
- GNUNET_CRYPTO_hash_file_cancel (pc->fhc);
- pc->fhc = NULL;
- }
+ {
+ GNUNET_CRYPTO_hash_file_cancel (pc->fhc);
+ pc->fhc = NULL;
+ }
GNUNET_FS_file_information_destroy (pc->fi, NULL, NULL);
if (pc->namespace != NULL)
- {
- GNUNET_FS_namespace_delete (pc->namespace, GNUNET_NO);
- pc->namespace = NULL;
- }
- GNUNET_free_non_null (pc->nid);
+ {
+ GNUNET_FS_namespace_delete (pc->namespace, GNUNET_NO);
+ pc->namespace = NULL;
+ }
+ GNUNET_free_non_null (pc->nid);
GNUNET_free_non_null (pc->nuid);
GNUNET_free_non_null (pc->serialization);
if (pc->dsh != NULL)
- {
- GNUNET_DATASTORE_disconnect (pc->dsh, GNUNET_NO);
- pc->dsh = NULL;
- }
+ {
+ GNUNET_DATASTORE_disconnect (pc->dsh, GNUNET_NO);
+ pc->dsh = NULL;
+ }
if (pc->client != NULL)
- {
- GNUNET_CLIENT_disconnect (pc->client, GNUNET_NO);
- pc->client = NULL;
- }
+ {
+ GNUNET_CLIENT_disconnect (pc->client, GNUNET_NO);
+ pc->client = NULL;
+ }
GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task);
GNUNET_free (pc);
}
@@ -128,48 +123,42 @@
* @param msg error message (or NULL)
*/
static void
-ds_put_cont (void *cls,
- int success,
- const char *msg)
+ds_put_cont (void *cls, int success, const char *msg)
{
struct GNUNET_FS_PublishContext *pc = cls;
struct GNUNET_FS_ProgressInfo pi;
pc->qre = NULL;
if (GNUNET_SYSERR == pc->in_network_wait)
- {
- /* we were aborted in the meantime, finish shutdown! */
- GNUNET_SCHEDULER_add_continuation (&publish_cleanup,
- pc,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- return;
- }
+ {
+ /* we were aborted in the meantime, finish shutdown! */
+ GNUNET_SCHEDULER_add_continuation (&publish_cleanup,
+ pc,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ return;
+ }
GNUNET_assert (GNUNET_YES == pc->in_network_wait);
pc->in_network_wait = GNUNET_NO;
if (GNUNET_SYSERR == success)
+ {
+ GNUNET_asprintf (&pc->fi_pos->emsg, _("Publishing failed: %s"), msg);
+ pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR;
+ pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL;
+ pi.value.publish.specifics.error.message = pc->fi_pos->emsg;
+ pc->fi_pos->client_info =
+ GNUNET_FS_publish_make_status_ (&pi, pc, pc->fi_pos, 0);
+ if ((pc->fi_pos->is_directory == GNUNET_NO) &&
+ (pc->fi_pos->filename != NULL) &&
+ (pc->fi_pos->data.file.do_index == GNUNET_YES))
{
- GNUNET_asprintf (&pc->fi_pos->emsg,
- _("Publishing failed: %s"),
- msg);
- pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR;
- pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL;
- pi.value.publish.specifics.error.message = pc->fi_pos->emsg;
- pc->fi_pos->client_info = GNUNET_FS_publish_make_status_ (&pi, pc,
pc->fi_pos, 0);
- if ( (pc->fi_pos->is_directory == GNUNET_NO) &&
- (pc->fi_pos->filename != NULL) &&
- (pc->fi_pos->data.file.do_index == GNUNET_YES) )
- {
- /* run unindex to clean up */
- GNUNET_FS_unindex_start (pc->h,
- pc->fi_pos->filename,
- NULL);
- }
+ /* run unindex to clean up */
+ GNUNET_FS_unindex_start (pc->h, pc->fi_pos->filename, NULL);
}
+ }
GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task);
- pc->upload_task
- = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
- &GNUNET_FS_publish_main_,
- pc);
+ pc->upload_task
+ =
+ GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
+ &GNUNET_FS_publish_main_, pc);
}
@@ -181,17 +170,19 @@
* @param p the completed upload
* @param pc context of the publication
*/
-static void
+static void
signal_publish_completion (struct GNUNET_FS_FileInformation *p,
- struct GNUNET_FS_PublishContext *pc)
+ struct GNUNET_FS_PublishContext *pc)
{
struct GNUNET_FS_ProgressInfo pi;
-
+
pi.status = GNUNET_FS_STATUS_PUBLISH_COMPLETED;
pi.value.publish.eta = GNUNET_TIME_UNIT_ZERO;
pi.value.publish.specifics.completed.chk_uri = p->chk_uri;
p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p,
- GNUNET_ntohll
(p->chk_uri->data.chk.file_length));
+ GNUNET_ntohll (p->
+
chk_uri->data.
+
chk.file_length));
}
@@ -204,28 +195,24 @@
* @param pc context of the publication
* @param emsg error message
*/
-static void
+static void
signal_publish_error (struct GNUNET_FS_FileInformation *p,
- struct GNUNET_FS_PublishContext *pc,
- const char *emsg)
+ struct GNUNET_FS_PublishContext *pc, const char *emsg)
{
struct GNUNET_FS_ProgressInfo pi;
-
+
p->emsg = GNUNET_strdup (emsg);
pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR;
pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL;
- pi.value.publish.specifics.error.message =emsg;
+ pi.value.publish.specifics.error.message = emsg;
p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, 0);
- if ( (p->is_directory == GNUNET_NO) &&
- (p->filename != NULL) &&
- (p->data.file.do_index == GNUNET_YES) )
- {
- /* run unindex to clean up */
- GNUNET_FS_unindex_start (pc->h,
- p->filename,
- NULL);
- }
-
+ if ((p->is_directory == GNUNET_NO) &&
+ (p->filename != NULL) && (p->data.file.do_index == GNUNET_YES))
+ {
+ /* run unindex to clean up */
+ GNUNET_FS_unindex_start (pc->h, p->filename, NULL);
+ }
+
}
@@ -237,16 +224,13 @@
* @param msg error message (typically NULL, not used)
*/
static void
-finish_release_reserve (void *cls,
- int success,
- const char *msg)
+finish_release_reserve (void *cls, int success, const char *msg)
{
struct GNUNET_FS_PublishContext *pc = cls;
pc->qre = NULL;
#if DEBUG_PUBLISH
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Releasing reserve done!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Releasing reserve done!\n");
#endif
signal_publish_completion (pc->fi, pc);
pc->all_done = GNUNET_YES;
@@ -264,34 +248,30 @@
*/
static void
publish_sblocks_cont (void *cls,
- const struct GNUNET_FS_Uri *uri,
- const char *emsg)
+ const struct GNUNET_FS_Uri *uri, const char *emsg)
{
struct GNUNET_FS_PublishContext *pc = cls;
+
if (NULL != emsg)
- {
- signal_publish_error (pc->fi,
- pc,
- emsg);
- GNUNET_FS_publish_sync_ (pc);
- return;
- }
+ {
+ signal_publish_error (pc->fi, pc, emsg);
+ GNUNET_FS_publish_sync_ (pc);
+ return;
+ }
GNUNET_assert (pc->qre == NULL);
- if ( (pc->dsh != NULL) &&
- (pc->rid != 0) )
- {
- pc->qre = GNUNET_DATASTORE_release_reserve (pc->dsh,
- pc->rid,
- UINT_MAX,
- UINT_MAX,
- GNUNET_TIME_UNIT_FOREVER_REL,
- &finish_release_reserve,
- pc);
- }
+ if ((pc->dsh != NULL) && (pc->rid != 0))
+ {
+ pc->qre = GNUNET_DATASTORE_release_reserve (pc->dsh,
+ pc->rid,
+ UINT_MAX,
+ UINT_MAX,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &finish_release_reserve, pc);
+ }
else
- {
- finish_release_reserve (pc, GNUNET_OK, NULL);
- }
+ {
+ finish_release_reserve (pc, GNUNET_OK, NULL);
+ }
}
@@ -306,15 +286,12 @@
{
if (NULL != pc->namespace)
GNUNET_FS_publish_sks (pc->h,
- pc->namespace,
- pc->nid,
- pc->nuid,
- pc->fi->meta,
- pc->fi->chk_uri,
- &pc->fi->bo,
- pc->options,
- &publish_sblocks_cont,
- pc);
+ pc->namespace,
+ pc->nid,
+ pc->nuid,
+ pc->fi->meta,
+ pc->fi->chk_uri,
+ &pc->fi->bo, pc->options, &publish_sblocks_cont,
pc);
else
publish_sblocks_cont (pc, NULL, NULL);
}
@@ -331,35 +308,33 @@
*/
static void
publish_kblocks_cont (void *cls,
- const struct GNUNET_FS_Uri *uri,
- const char *emsg)
+ const struct GNUNET_FS_Uri *uri, const char *emsg)
{
struct GNUNET_FS_PublishContext *pc = cls;
struct GNUNET_FS_FileInformation *p = pc->fi_pos;
if (NULL != emsg)
- {
+ {
#if DEBUG_PUBLISH
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Error uploading KSK blocks: %s\n",
- emsg);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Error uploading KSK blocks: %s\n", emsg);
#endif
- signal_publish_error (p, pc, emsg);
- GNUNET_FS_file_information_sync_ (p);
- GNUNET_FS_publish_sync_ (pc);
- GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task);
- pc->upload_task
- = GNUNET_SCHEDULER_add_with_priority
(GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
- &GNUNET_FS_publish_main_,
- pc);
- return;
- }
+ signal_publish_error (p, pc, emsg);
+ GNUNET_FS_file_information_sync_ (p);
+ GNUNET_FS_publish_sync_ (pc);
+ GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task);
+ pc->upload_task
+ =
+ GNUNET_SCHEDULER_add_with_priority
+ (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, &GNUNET_FS_publish_main_, pc);
+ return;
+ }
#if DEBUG_PUBLISH
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "KSK blocks published, moving on to next file\n");
+ "KSK blocks published, moving on to next file\n");
#endif
if (NULL != p->dir)
- signal_publish_completion (p, pc);
+ signal_publish_completion (p, pc);
/* move on to next file */
if (NULL != p->next)
pc->fi_pos = p->next;
@@ -367,10 +342,10 @@
pc->fi_pos = p->dir;
GNUNET_FS_publish_sync_ (pc);
GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task);
- pc->upload_task
- = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
- &GNUNET_FS_publish_main_,
- pc);
+ pc->upload_task
+ =
+ GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
+ &GNUNET_FS_publish_main_, pc);
}
@@ -388,11 +363,7 @@
* @return number of bytes copied to buf, 0 on error
*/
static size_t
-block_reader (void *cls,
- uint64_t offset,
- size_t max,
- void *buf,
- char **emsg)
+block_reader (void *cls, uint64_t offset, size_t max, void *buf, char **emsg)
{
struct GNUNET_FS_PublishContext *pc = cls;
struct GNUNET_FS_FileInformation *p;
@@ -401,29 +372,22 @@
p = pc->fi_pos;
if (p->is_directory)
- {
- pt_size = GNUNET_MIN(max,
- p->data.dir.dir_size - offset);
- dd = p->data.dir.dir_data;
- memcpy (buf,
- &dd[offset],
- pt_size);
- }
+ {
+ pt_size = GNUNET_MIN (max, p->data.dir.dir_size - offset);
+ dd = p->data.dir.dir_data;
+ memcpy (buf, &dd[offset], pt_size);
+ }
else
- {
- pt_size = GNUNET_MIN(max,
- p->data.file.file_size - offset);
- if (pt_size == 0)
- return 0; /* calling reader with pt_size==0
- might free buf, so don't! */
- if (pt_size !=
- p->data.file.reader (p->data.file.reader_cls,
- offset,
- pt_size,
- buf,
- emsg))
- return 0;
- }
+ {
+ pt_size = GNUNET_MIN (max, p->data.file.file_size - offset);
+ if (pt_size == 0)
+ return 0; /* calling reader with pt_size==0
+ * might free buf, so don't! */
+ if (pt_size !=
+ p->data.file.reader (p->data.file.reader_cls,
+ offset, pt_size, buf, emsg))
+ return 0;
+ }
return pt_size;
}
@@ -436,9 +400,8 @@
* @param cls our publishing context
* @param tc scheduler's task context (not used)
*/
-static void
-encode_cont (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+static void
+encode_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_FS_PublishContext *pc = cls;
struct GNUNET_FS_FileInformation *p;
@@ -447,30 +410,23 @@
uint64_t flen;
p = pc->fi_pos;
- GNUNET_FS_tree_encoder_finish (p->te,
- &p->chk_uri,
- &emsg);
+ GNUNET_FS_tree_encoder_finish (p->te, &p->chk_uri, &emsg);
p->te = NULL;
if (NULL != emsg)
- {
+ {
#if DEBUG_PUBLISH
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Error during tree walk: %s\n",
- emsg);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error during tree walk: %s\n", emsg);
#endif
- GNUNET_asprintf (&p->emsg,
- _("Publishing failed: %s"),
- emsg);
- GNUNET_free (emsg);
- pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR;
- pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL;
- pi.value.publish.specifics.error.message = p->emsg;
- p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, 0);
- }
+ GNUNET_asprintf (&p->emsg, _("Publishing failed: %s"), emsg);
+ GNUNET_free (emsg);
+ pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR;
+ pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL;
+ pi.value.publish.specifics.error.message = p->emsg;
+ p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, 0);
+ }
#if DEBUG_PUBLISH
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Finished with tree encoder\n");
-#endif
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Finished with tree encoder\n");
+#endif
/* final progress event */
flen = GNUNET_FS_uri_chk_get_file_size (p->chk_uri);
pi.status = GNUNET_FS_STATUS_PUBLISH_PROGRESS;
@@ -482,10 +438,10 @@
/* continue with main */
GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task);
- pc->upload_task
- = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
- &GNUNET_FS_publish_main_,
- pc);
+ pc->upload_task
+ =
+ GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
+ &GNUNET_FS_publish_main_, pc);
}
@@ -503,14 +459,12 @@
* @param block the (encrypted) block
* @param block_size size of block (in bytes)
*/
-static void
+static void
block_proc (void *cls,
- const struct ContentHashKey *chk,
- uint64_t offset,
- unsigned int depth,
- enum GNUNET_BLOCK_Type type,
- const void *block,
- uint16_t block_size)
+ const struct ContentHashKey *chk,
+ uint64_t offset,
+ unsigned int depth,
+ enum GNUNET_BLOCK_Type type, const void *block, uint16_t
block_size)
{
struct GNUNET_FS_PublishContext *pc = cls;
struct GNUNET_FS_FileInformation *p;
@@ -518,73 +472,68 @@
p = pc->fi_pos;
if (NULL == pc->dsh)
- {
+ {
#if DEBUG_PUBLISH
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Waiting for datastore connection\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Waiting for datastore connection\n");
#endif
- GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task);
- pc->upload_task
- = GNUNET_SCHEDULER_add_with_priority
(GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
- &GNUNET_FS_publish_main_,
- pc);
- return;
- }
-
+ GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task);
+ pc->upload_task
+ =
+ GNUNET_SCHEDULER_add_with_priority
+ (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, &GNUNET_FS_publish_main_, pc);
+ return;
+ }
+
GNUNET_assert (GNUNET_NO == pc->in_network_wait);
pc->in_network_wait = GNUNET_YES;
- if ( (! p->is_directory) &&
- (GNUNET_YES == p->data.file.do_index) &&
- (type == GNUNET_BLOCK_TYPE_FS_DBLOCK) )
- {
+ if ((!p->is_directory) &&
+ (GNUNET_YES == p->data.file.do_index) &&
+ (type == GNUNET_BLOCK_TYPE_FS_DBLOCK))
+ {
#if DEBUG_PUBLISH
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Indexing block `%s' for offset %llu with index size %u\n",
- GNUNET_h2s (&chk->query),
- (unsigned long long) offset,
- sizeof (struct OnDemandBlock));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Indexing block `%s' for offset %llu with index size %u\n",
+ GNUNET_h2s (&chk->query),
+ (unsigned long long) offset, sizeof (struct OnDemandBlock));
#endif
- odb.offset = GNUNET_htonll (offset);
- odb.file_id = p->data.file.file_id;
- GNUNET_assert (pc->qre == NULL);
- pc->qre = GNUNET_DATASTORE_put (pc->dsh,
- (p->is_directory) ? 0 : pc->rid,
- &chk->query,
- sizeof (struct OnDemandBlock),
- &odb,
- GNUNET_BLOCK_TYPE_FS_ONDEMAND,
- p->bo.content_priority,
- p->bo.anonymity_level,
- p->bo.replication_level,
- p->bo.expiration_time,
- -2, 1,
- GNUNET_CONSTANTS_SERVICE_TIMEOUT,
- &ds_put_cont,
- pc);
- return;
- }
+ odb.offset = GNUNET_htonll (offset);
+ odb.file_id = p->data.file.file_id;
+ GNUNET_assert (pc->qre == NULL);
+ pc->qre = GNUNET_DATASTORE_put (pc->dsh,
+ (p->is_directory) ? 0 : pc->rid,
+ &chk->query,
+ sizeof (struct OnDemandBlock),
+ &odb,
+ GNUNET_BLOCK_TYPE_FS_ONDEMAND,
+ p->bo.content_priority,
+ p->bo.anonymity_level,
+ p->bo.replication_level,
+ p->bo.expiration_time,
+ -2, 1,
+ GNUNET_CONSTANTS_SERVICE_TIMEOUT,
+ &ds_put_cont, pc);
+ return;
+ }
#if DEBUG_PUBLISH
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Publishing block `%s' for offset %llu with size %u\n",
- GNUNET_h2s (&chk->query),
- (unsigned long long) offset,
- (unsigned int) block_size);
+ "Publishing block `%s' for offset %llu with size %u\n",
+ GNUNET_h2s (&chk->query),
+ (unsigned long long) offset, (unsigned int) block_size);
#endif
GNUNET_assert (pc->qre == NULL);
pc->qre = GNUNET_DATASTORE_put (pc->dsh,
- (p->is_directory) ? 0 : pc->rid,
- &chk->query,
- block_size,
- block,
- type,
- p->bo.content_priority,
- p->bo.anonymity_level,
- p->bo.replication_level,
- p->bo.expiration_time,
- -2, 1,
- GNUNET_CONSTANTS_SERVICE_TIMEOUT,
- &ds_put_cont,
- pc);
+ (p->is_directory) ? 0 : pc->rid,
+ &chk->query,
+ block_size,
+ block,
+ type,
+ p->bo.content_priority,
+ p->bo.anonymity_level,
+ p->bo.replication_level,
+ p->bo.expiration_time,
+ -2, 1,
+ GNUNET_CONSTANTS_SERVICE_TIMEOUT,
+ &ds_put_cont, pc);
}
@@ -598,13 +547,11 @@
* @param pt_size size of pt_block
* @param depth depth of the block in the tree, 0 for DBLOCK
*/
-static void
+static void
progress_proc (void *cls,
- uint64_t offset,
- const void *pt_block,
- size_t pt_size,
- unsigned int depth)
-{
+ uint64_t offset,
+ const void *pt_block, size_t pt_size, unsigned int depth)
+{
struct GNUNET_FS_PublishContext *pc = cls;
struct GNUNET_FS_FileInformation *p;
struct GNUNET_FS_ProgressInfo pi;
@@ -627,7 +574,7 @@
* @param pc overall upload data
*/
static void
-publish_content (struct GNUNET_FS_PublishContext *pc)
+publish_content (struct GNUNET_FS_PublishContext *pc)
{
struct GNUNET_FS_FileInformation *p;
char *emsg;
@@ -639,77 +586,69 @@
p = pc->fi_pos;
GNUNET_assert (p != NULL);
if (NULL == p->te)
+ {
+ if (p->is_directory)
{
- if (p->is_directory)
- {
#if DEBUG_PUBLISH
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Creating directory\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating directory\n");
#endif
- db = GNUNET_FS_directory_builder_create (p->meta);
- dirpos = p->data.dir.entries;
- while (NULL != dirpos)
- {
- if (dirpos->is_directory)
- {
- raw_data = dirpos->data.dir.dir_data;
- dirpos->data.dir.dir_data = NULL;
- }
- else
- {
- raw_data = NULL;
- if ( (dirpos->data.file.file_size < MAX_INLINE_SIZE) &&
- (dirpos->data.file.file_size > 0) )
- {
- raw_data = GNUNET_malloc (dirpos->data.file.file_size);
- emsg = NULL;
- if (dirpos->data.file.file_size !=
- dirpos->data.file.reader
(dirpos->data.file.reader_cls,
- 0,
- dirpos->data.file.file_size,
- raw_data,
- &emsg))
- {
- GNUNET_free_non_null (emsg);
- GNUNET_free (raw_data);
- raw_data = NULL;
- }
- }
- }
- GNUNET_FS_directory_builder_add (db,
- dirpos->chk_uri,
- dirpos->meta,
- raw_data);
- GNUNET_free_non_null (raw_data);
- dirpos = dirpos->next;
- }
- GNUNET_free_non_null (p->data.dir.dir_data);
- p->data.dir.dir_data = NULL;
- p->data.dir.dir_size = 0;
- GNUNET_FS_directory_builder_finish (db,
- &p->data.dir.dir_size,
- &p->data.dir.dir_data);
- GNUNET_FS_file_information_sync_ (p);
- }
- size = (p->is_directory)
- ? p->data.dir.dir_size
- : p->data.file.file_size;
+ db = GNUNET_FS_directory_builder_create (p->meta);
+ dirpos = p->data.dir.entries;
+ while (NULL != dirpos)
+ {
+ if (dirpos->is_directory)
+ {
+ raw_data = dirpos->data.dir.dir_data;
+ dirpos->data.dir.dir_data = NULL;
+ }
+ else
+ {
+ raw_data = NULL;
+ if ((dirpos->data.file.file_size < MAX_INLINE_SIZE) &&
+ (dirpos->data.file.file_size > 0))
+ {
+ raw_data = GNUNET_malloc (dirpos->data.file.file_size);
+ emsg = NULL;
+ if (dirpos->data.file.file_size !=
+ dirpos->data.file.reader (dirpos->data.file.reader_cls,
+ 0,
+ dirpos->data.file.file_size,
+ raw_data, &emsg))
+ {
+ GNUNET_free_non_null (emsg);
+ GNUNET_free (raw_data);
+ raw_data = NULL;
+ }
+ }
+ }
+ GNUNET_FS_directory_builder_add (db,
+ dirpos->chk_uri,
+ dirpos->meta, raw_data);
+ GNUNET_free_non_null (raw_data);
+ dirpos = dirpos->next;
+ }
+ GNUNET_free_non_null (p->data.dir.dir_data);
+ p->data.dir.dir_data = NULL;
+ p->data.dir.dir_size = 0;
+ GNUNET_FS_directory_builder_finish (db,
+ &p->data.dir.dir_size,
+ &p->data.dir.dir_data);
+ GNUNET_FS_file_information_sync_ (p);
+ }
+ size = (p->is_directory) ? p->data.dir.dir_size : p->data.file.file_size;
#if DEBUG_PUBLISH
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Creating tree encoder\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating tree encoder\n");
#endif
- p->te = GNUNET_FS_tree_encoder_create (pc->h,
- size,
- pc,
- &block_reader,
- &block_proc,
- &progress_proc,
- &encode_cont);
+ p->te = GNUNET_FS_tree_encoder_create (pc->h,
+ size,
+ pc,
+ &block_reader,
+ &block_proc,
+ &progress_proc, &encode_cont);
- }
+ }
#if DEBUG_PUBLISH
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Processing next block from tree\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing next block from tree\n");
#endif
GNUNET_FS_tree_encoder_next (p->te);
}
@@ -723,8 +662,7 @@
* @param msg the response we got
*/
static void
-process_index_start_response (void *cls,
- const struct GNUNET_MessageHeader *msg)
+process_index_start_response (void *cls, const struct GNUNET_MessageHeader
*msg)
{
struct GNUNET_FS_PublishContext *pc = cls;
struct GNUNET_FS_FileInformation *p;
@@ -735,32 +673,33 @@
pc->client = NULL;
p = pc->fi_pos;
if (msg == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Can not index file `%s': %s. Will try to insert
instead.\n"),
- p->filename,
- _("timeout on index-start request to `fs' service"));
- p->data.file.do_index = GNUNET_NO;
- GNUNET_FS_file_information_sync_ (p);
- publish_content (pc);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Can not index file `%s': %s. Will try to insert
instead.\n"),
+ p->filename,
+ _("timeout on index-start request to `fs' service"));
+ p->data.file.do_index = GNUNET_NO;
+ GNUNET_FS_file_information_sync_ (p);
+ publish_content (pc);
+ return;
+ }
if (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK)
- {
- msize = ntohs (msg->size);
- emsg = (const char *) &msg[1];
- if ( (msize <= sizeof (struct GNUNET_MessageHeader)) ||
- (emsg[msize - sizeof(struct GNUNET_MessageHeader) - 1] != '\0') )
- emsg = gettext_noop ("unknown error");
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Can not index file `%s': %s. Will try to insert
instead.\n"),
- p->filename,
- gettext (emsg));
- p->data.file.do_index = GNUNET_NO;
- GNUNET_FS_file_information_sync_ (p);
- publish_content (pc);
- return;
- }
+ {
+ msize = ntohs (msg->size);
+ emsg = (const char *) &msg[1];
+ if ((msize <= sizeof (struct GNUNET_MessageHeader)) ||
+ (emsg[msize - sizeof (struct GNUNET_MessageHeader) - 1] != '\0'))
+ emsg = gettext_noop ("unknown error");
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Can not index file `%s': %s. Will try to insert
instead.\n"),
+ p->filename, gettext (emsg));
+ p->data.file.do_index = GNUNET_NO;
+ GNUNET_FS_file_information_sync_ (p);
+ publish_content (pc);
+ return;
+ }
p->data.file.index_start_confirmed = GNUNET_YES;
/* success! continue with indexing */
GNUNET_FS_file_information_sync_ (p);
@@ -775,10 +714,8 @@
* @param cls closure, our publishing context
* @param res resulting hash, NULL on error
*/
-static void
-hash_for_index_cb (void *cls,
- const GNUNET_HashCode *
- res)
+static void
+hash_for_index_cb (void *cls, const GNUNET_HashCode * res)
{
struct GNUNET_FS_PublishContext *pc = cls;
struct GNUNET_FS_FileInformation *p;
@@ -791,106 +728,97 @@
pc->fhc = NULL;
p = pc->fi_pos;
- if (NULL == res)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Can not index file `%s': %s. Will try to insert
instead.\n"),
- p->filename,
- _("failed to compute hash"));
- p->data.file.do_index = GNUNET_NO;
- GNUNET_FS_file_information_sync_ (p);
- publish_content (pc);
- return;
- }
+ if (NULL == res)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Can not index file `%s': %s. Will try to insert
instead.\n"),
+ p->filename, _("failed to compute hash"));
+ p->data.file.do_index = GNUNET_NO;
+ GNUNET_FS_file_information_sync_ (p);
+ publish_content (pc);
+ return;
+ }
if (GNUNET_YES == p->data.file.index_start_confirmed)
- {
- publish_content (pc);
- return;
- }
+ {
+ publish_content (pc);
+ return;
+ }
fn = GNUNET_STRINGS_filename_expand (p->filename);
GNUNET_assert (fn != NULL);
slen = strlen (fn) + 1;
- if (slen >= GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof(struct
IndexStartMessage))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Can not index file `%s': %s. Will try to insert
instead.\n"),
- fn,
- _("filename too long"));
- GNUNET_free (fn);
- p->data.file.do_index = GNUNET_NO;
- GNUNET_FS_file_information_sync_ (p);
- publish_content (pc);
- return;
- }
+ if (slen >=
+ GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct IndexStartMessage))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Can not index file `%s': %s. Will try to insert
instead.\n"),
+ fn, _("filename too long"));
+ GNUNET_free (fn);
+ p->data.file.do_index = GNUNET_NO;
+ GNUNET_FS_file_information_sync_ (p);
+ publish_content (pc);
+ return;
+ }
#if DEBUG_PUBLISH
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Hash of indexed file `%s' is `%s'\n",
- p->filename,
- GNUNET_h2s (res));
+ "Hash of indexed file `%s' is `%s'\n",
+ p->filename, GNUNET_h2s (res));
#endif
if (0 != (pc->options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY))
- {
- p->data.file.file_id = *res;
- p->data.file.have_hash = GNUNET_YES;
- p->data.file.index_start_confirmed = GNUNET_YES;
- GNUNET_FS_file_information_sync_ (p);
- publish_content (pc);
- GNUNET_free (fn);
- return;
- }
- client = GNUNET_CLIENT_connect ("fs",
- pc->h->cfg);
+ {
+ p->data.file.file_id = *res;
+ p->data.file.have_hash = GNUNET_YES;
+ p->data.file.index_start_confirmed = GNUNET_YES;
+ GNUNET_FS_file_information_sync_ (p);
+ publish_content (pc);
+ GNUNET_free (fn);
+ return;
+ }
+ client = GNUNET_CLIENT_connect ("fs", pc->h->cfg);
if (NULL == client)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Can not index file `%s': %s. Will try to insert
instead.\n"),
- p->filename,
- _("could not connect to `fs' service"));
- p->data.file.do_index = GNUNET_NO;
- publish_content (pc);
- GNUNET_free (fn);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Can not index file `%s': %s. Will try to insert
instead.\n"),
+ p->filename, _("could not connect to `fs' service"));
+ p->data.file.do_index = GNUNET_NO;
+ publish_content (pc);
+ GNUNET_free (fn);
+ return;
+ }
if (p->data.file.have_hash != GNUNET_YES)
- {
- p->data.file.file_id = *res;
- p->data.file.have_hash = GNUNET_YES;
- GNUNET_FS_file_information_sync_ (p);
- }
- ism = GNUNET_malloc (sizeof(struct IndexStartMessage) +
- slen);
- ism->header.size = htons(sizeof(struct IndexStartMessage) +
- slen);
- ism->header.type = htons(GNUNET_MESSAGE_TYPE_FS_INDEX_START);
- if (GNUNET_OK ==
- GNUNET_DISK_file_get_identifiers (p->filename,
- &dev,
- &ino))
- {
- ism->device = GNUNET_htonll (dev);
- ism->inode = GNUNET_htonll(ino);
- }
+ {
+ p->data.file.file_id = *res;
+ p->data.file.have_hash = GNUNET_YES;
+ GNUNET_FS_file_information_sync_ (p);
+ }
+ ism = GNUNET_malloc (sizeof (struct IndexStartMessage) + slen);
+ ism->header.size = htons (sizeof (struct IndexStartMessage) + slen);
+ ism->header.type = htons (GNUNET_MESSAGE_TYPE_FS_INDEX_START);
+ if (GNUNET_OK == GNUNET_DISK_file_get_identifiers (p->filename, &dev, &ino))
+ {
+ ism->device = GNUNET_htonll (dev);
+ ism->inode = GNUNET_htonll (ino);
+ }
#if DEBUG_PUBLISH
else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Failed to get file identifiers for `%s'\n"),
- p->filename);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ _("Failed to get file identifiers for `%s'\n"), p->filename);
+ }
#endif
ism->file_id = *res;
- memcpy (&ism[1],
- fn,
- slen);
+ memcpy (&ism[1], fn, slen);
GNUNET_free (fn);
pc->client = client;
GNUNET_break (GNUNET_YES ==
- GNUNET_CLIENT_transmit_and_get_response (client,
- &ism->header,
-
GNUNET_TIME_UNIT_FOREVER_REL,
- GNUNET_YES,
-
&process_index_start_response,
- pc));
+ GNUNET_CLIENT_transmit_and_get_response (client,
+ &ism->header,
+
GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_YES,
+
&process_index_start_response,
+ pc));
GNUNET_free (ism);
}
@@ -903,7 +831,7 @@
*/
void
GNUNET_FS_publish_main_ (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_FS_PublishContext *pc = cls;
struct GNUNET_FS_ProgressInfo pi;
@@ -911,135 +839,119 @@
struct GNUNET_FS_Uri *loc;
char *fn;
- pc->upload_task = GNUNET_SCHEDULER_NO_TASK;
+ pc->upload_task = GNUNET_SCHEDULER_NO_TASK;
p = pc->fi_pos;
if (NULL == p)
- {
+ {
#if DEBUG_PUBLISH
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Publishing complete, now publishing SKS and KSK blocks.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Publishing complete, now publishing SKS and KSK blocks.\n");
#endif
- /* upload of entire hierarchy complete,
- publish namespace entries */
- GNUNET_FS_publish_sync_ (pc);
- publish_sblock (pc);
- return;
- }
+ /* upload of entire hierarchy complete,
+ * publish namespace entries */
+ GNUNET_FS_publish_sync_ (pc);
+ publish_sblock (pc);
+ return;
+ }
/* find starting position */
- while ( (p->is_directory) &&
- (NULL != p->data.dir.entries) &&
- (NULL == p->emsg) &&
- (NULL == p->data.dir.entries->chk_uri) )
- {
- p = p->data.dir.entries;
- pc->fi_pos = p;
- GNUNET_FS_publish_sync_ (pc);
- }
+ while ((p->is_directory) &&
+ (NULL != p->data.dir.entries) &&
+ (NULL == p->emsg) && (NULL == p->data.dir.entries->chk_uri))
+ {
+ p = p->data.dir.entries;
+ pc->fi_pos = p;
+ GNUNET_FS_publish_sync_ (pc);
+ }
/* abort on error */
if (NULL != p->emsg)
- {
+ {
#if DEBUG_PUBLISH
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Error uploading: %s\n",
- p->emsg);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error uploading: %s\n", p->emsg);
#endif
- /* error with current file, abort all
- related files as well! */
- while (NULL != p->dir)
- {
- fn = GNUNET_CONTAINER_meta_data_get_by_type (p->meta,
-
EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME);
- p = p->dir;
- if (fn != NULL)
- {
- GNUNET_asprintf (&p->emsg,
- _("Recursive upload failed at `%s': %s"),
- fn,
- p->emsg);
- GNUNET_free (fn);
- }
- else
- {
- GNUNET_asprintf (&p->emsg,
- _("Recursive upload failed: %s"),
- p->emsg);
- }
- pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR;
- pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL;
- pi.value.publish.specifics.error.message = p->emsg;
- p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, 0);
- }
- pc->all_done = GNUNET_YES;
- GNUNET_FS_publish_sync_ (pc);
- return;
+ /* error with current file, abort all
+ * related files as well! */
+ while (NULL != p->dir)
+ {
+ fn = GNUNET_CONTAINER_meta_data_get_by_type (p->meta,
+
EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME);
+ p = p->dir;
+ if (fn != NULL)
+ {
+ GNUNET_asprintf (&p->emsg,
+ _("Recursive upload failed at `%s': %s"), fn,
p->emsg);
+ GNUNET_free (fn);
+ }
+ else
+ {
+ GNUNET_asprintf (&p->emsg, _("Recursive upload failed: %s"), p->emsg);
+ }
+ pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR;
+ pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL;
+ pi.value.publish.specifics.error.message = p->emsg;
+ p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, 0);
}
+ pc->all_done = GNUNET_YES;
+ GNUNET_FS_publish_sync_ (pc);
+ return;
+ }
/* handle completion */
if (NULL != p->chk_uri)
- {
+ {
#if DEBUG_PUBLISH
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "File upload complete, now publishing KSK blocks.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "File upload complete, now publishing KSK blocks.\n");
#endif
- if (0 == p->bo.anonymity_level)
- {
- /* zero anonymity, box CHK URI in LOC URI */
- loc = GNUNET_FS_uri_loc_create (p->chk_uri,
- pc->h->cfg,
- p->bo.expiration_time);
- GNUNET_FS_uri_destroy (p->chk_uri);
- p->chk_uri = loc;
- }
- GNUNET_FS_publish_sync_ (pc);
- /* upload of "p" complete, publish KBlocks! */
- if (p->keywords != NULL)
- {
- GNUNET_FS_publish_ksk (pc->h,
- p->keywords,
- p->meta,
- p->chk_uri,
- &p->bo,
- pc->options,
- &publish_kblocks_cont,
- pc);
- }
- else
- {
- publish_kblocks_cont (pc,
- p->chk_uri,
- NULL);
- }
- return;
+ if (0 == p->bo.anonymity_level)
+ {
+ /* zero anonymity, box CHK URI in LOC URI */
+ loc = GNUNET_FS_uri_loc_create (p->chk_uri,
+ pc->h->cfg, p->bo.expiration_time);
+ GNUNET_FS_uri_destroy (p->chk_uri);
+ p->chk_uri = loc;
}
- if ( (!p->is_directory) &&
- (p->data.file.do_index) )
+ GNUNET_FS_publish_sync_ (pc);
+ /* upload of "p" complete, publish KBlocks! */
+ if (p->keywords != NULL)
{
- if (NULL == p->filename)
- {
- p->data.file.do_index = GNUNET_NO;
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Can not index file `%s': %s. Will try to insert
instead.\n"),
- "<no-name>",
- _("needs to be an actual file"));
- GNUNET_FS_file_information_sync_ (p);
- publish_content (pc);
- return;
- }
- if (p->data.file.have_hash)
- {
- hash_for_index_cb (pc,
- &p->data.file.file_id);
- }
- else
- {
- p->start_time = GNUNET_TIME_absolute_get ();
- pc->fhc = GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE,
- p->filename,
- HASHING_BLOCKSIZE,
- &hash_for_index_cb,
- pc);
- }
+ GNUNET_FS_publish_ksk (pc->h,
+ p->keywords,
+ p->meta,
+ p->chk_uri,
+ &p->bo, pc->options, &publish_kblocks_cont, pc);
+ }
+ else
+ {
+ publish_kblocks_cont (pc, p->chk_uri, NULL);
+ }
+ return;
+ }
+ if ((!p->is_directory) && (p->data.file.do_index))
+ {
+ if (NULL == p->filename)
+ {
+ p->data.file.do_index = GNUNET_NO;
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Can not index file `%s': %s. Will try to insert
instead.\n"),
+ "<no-name>", _("needs to be an actual file"));
+ GNUNET_FS_file_information_sync_ (p);
+ publish_content (pc);
return;
}
+ if (p->data.file.have_hash)
+ {
+ hash_for_index_cb (pc, &p->data.file.file_id);
+ }
+ else
+ {
+ p->start_time = GNUNET_TIME_absolute_get ();
+ pc->fhc = GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE,
+ p->filename,
+ HASHING_BLOCKSIZE,
+ &hash_for_index_cb, pc);
+ }
+ return;
+ }
publish_content (pc);
}
@@ -1059,14 +971,13 @@
* @return GNUNET_OK to continue (always)
*/
static int
-fip_signal_start(void *cls,
- struct GNUNET_FS_FileInformation *fi,
- uint64_t length,
- struct GNUNET_CONTAINER_MetaData *meta,
- struct GNUNET_FS_Uri **uri,
- struct GNUNET_FS_BlockOptions *bo,
- int *do_index,
- void **client_info)
+fip_signal_start (void *cls,
+ struct GNUNET_FS_FileInformation *fi,
+ uint64_t length,
+ struct GNUNET_CONTAINER_MetaData *meta,
+ struct GNUNET_FS_Uri **uri,
+ struct GNUNET_FS_BlockOptions *bo,
+ int *do_index, void **client_info)
{
struct GNUNET_FS_PublishContext *pc = cls;
struct GNUNET_FS_ProgressInfo pi;
@@ -1074,38 +985,39 @@
uint64_t left;
#if DEBUG_PUBLISH
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Starting publish operation\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting publish operation\n");
#endif
if (*do_index)
- {
- /* space for on-demand blocks */
- pc->reserve_space += ((length + DBLOCK_SIZE - 1) / DBLOCK_SIZE) * sizeof
(struct OnDemandBlock);
- }
+ {
+ /* space for on-demand blocks */
+ pc->reserve_space +=
+ ((length + DBLOCK_SIZE -
+ 1) / DBLOCK_SIZE) * sizeof (struct OnDemandBlock);
+ }
else
- {
- /* space for DBlocks */
- pc->reserve_space += length;
- }
+ {
+ /* space for DBlocks */
+ pc->reserve_space += length;
+ }
/* entries for IBlocks and DBlocks, space for IBlocks */
left = length;
while (1)
- {
- left = (left + DBLOCK_SIZE - 1) / DBLOCK_SIZE;
- pc->reserve_entries += left;
- if (left <= 1)
- break;
- left = left * sizeof (struct ContentHashKey);
- pc->reserve_space += left;
- }
+ {
+ left = (left + DBLOCK_SIZE - 1) / DBLOCK_SIZE;
+ pc->reserve_entries += left;
+ if (left <= 1)
+ break;
+ left = left * sizeof (struct ContentHashKey);
+ pc->reserve_space += left;
+ }
pc->reserve_entries++;
/* entries and space for keywords */
if (NULL != *uri)
- {
- kc = GNUNET_FS_uri_ksk_get_keyword_count (*uri);
- pc->reserve_entries += kc;
- pc->reserve_space += GNUNET_SERVER_MAX_MESSAGE_SIZE * kc;
- }
+ {
+ kc = GNUNET_FS_uri_ksk_get_keyword_count (*uri);
+ pc->reserve_entries += kc;
+ pc->reserve_space += GNUNET_SERVER_MAX_MESSAGE_SIZE * kc;
+ }
pi.status = GNUNET_FS_STATUS_PUBLISH_START;
*client_info = GNUNET_FS_publish_make_status_ (&pi, pc, fi, 0);
GNUNET_FS_file_information_sync_ (fi);
@@ -1128,39 +1040,37 @@
* @return GNUNET_OK to continue (always)
*/
static int
-fip_signal_suspend(void *cls,
- struct GNUNET_FS_FileInformation *fi,
- uint64_t length,
- struct GNUNET_CONTAINER_MetaData *meta,
- struct GNUNET_FS_Uri **uri,
- struct GNUNET_FS_BlockOptions *bo,
- int *do_index,
- void **client_info)
+fip_signal_suspend (void *cls,
+ struct GNUNET_FS_FileInformation *fi,
+ uint64_t length,
+ struct GNUNET_CONTAINER_MetaData *meta,
+ struct GNUNET_FS_Uri **uri,
+ struct GNUNET_FS_BlockOptions *bo,
+ int *do_index, void **client_info)
{
- struct GNUNET_FS_PublishContext*pc = cls;
+ struct GNUNET_FS_PublishContext *pc = cls;
struct GNUNET_FS_ProgressInfo pi;
uint64_t off;
#if DEBUG_PUBLISH
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Suspending publish operation\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Suspending publish operation\n");
#endif
GNUNET_free_non_null (fi->serialization);
- fi->serialization = NULL;
+ fi->serialization = NULL;
off = (fi->chk_uri == NULL) ? 0 : length;
pi.status = GNUNET_FS_STATUS_PUBLISH_SUSPEND;
GNUNET_break (NULL == GNUNET_FS_publish_make_status_ (&pi, pc, fi, off));
*client_info = NULL;
if (NULL != pc->qre)
- {
- GNUNET_DATASTORE_cancel (pc->qre);
- pc->qre = NULL;
- }
+ {
+ GNUNET_DATASTORE_cancel (pc->qre);
+ pc->qre = NULL;
+ }
if (NULL != pc->dsh)
- {
- GNUNET_DATASTORE_disconnect (pc->dsh, GNUNET_NO);
- pc->dsh = NULL;
- }
+ {
+ GNUNET_DATASTORE_disconnect (pc->dsh, GNUNET_NO);
+ pc->dsh = NULL;
+ }
pc->rid = 0;
return GNUNET_OK;
}
@@ -1178,13 +1088,11 @@
struct GNUNET_FS_PublishContext *pc = cls;
if (GNUNET_SCHEDULER_NO_TASK != pc->upload_task)
- {
- GNUNET_SCHEDULER_cancel (pc->upload_task);
- pc->upload_task = GNUNET_SCHEDULER_NO_TASK;
- }
- GNUNET_FS_file_information_inspect (pc->fi,
- &fip_signal_suspend,
- pc);
+ {
+ GNUNET_SCHEDULER_cancel (pc->upload_task);
+ pc->upload_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ GNUNET_FS_file_information_inspect (pc->fi, &fip_signal_suspend, pc);
GNUNET_FS_end_top (pc->h, pc->top);
pc->top = NULL;
publish_cleanup (pc, NULL);
@@ -1200,35 +1108,27 @@
* @param msg error message on error, otherwise NULL
*/
static void
-finish_reserve (void *cls,
- int success,
- const char *msg)
+finish_reserve (void *cls, int success, const char *msg)
{
struct GNUNET_FS_PublishContext *pc = cls;
pc->qre = NULL;
#if DEBUG_PUBLISH
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Reservation complete (%d)!\n",
- success);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Reservation complete (%d)!\n",
success);
#endif
- if ( (msg != NULL) ||
- (success <= 0) )
- {
- GNUNET_asprintf (&pc->fi->emsg,
- _("Insufficient space for publishing: %s"),
- msg);
- signal_publish_error (pc->fi,
- pc,
- pc->fi->emsg);
- return;
- }
+ if ((msg != NULL) || (success <= 0))
+ {
+ GNUNET_asprintf (&pc->fi->emsg,
+ _("Insufficient space for publishing: %s"), msg);
+ signal_publish_error (pc->fi, pc, pc->fi->emsg);
+ return;
+ }
pc->rid = success;
GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task);
- pc->upload_task
- = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
- &GNUNET_FS_publish_main_,
- pc);
+ pc->upload_task
+ =
+ GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
+ &GNUNET_FS_publish_main_, pc);
}
@@ -1247,26 +1147,26 @@
*/
struct GNUNET_FS_PublishContext *
GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h,
- struct GNUNET_FS_FileInformation *fi,
- struct GNUNET_FS_Namespace *namespace,
- const char *nid,
- const char *nuid,
- enum GNUNET_FS_PublishOptions options)
+ struct GNUNET_FS_FileInformation *fi,
+ struct GNUNET_FS_Namespace *namespace,
+ const char *nid,
+ const char *nuid,
+ enum GNUNET_FS_PublishOptions options)
{
struct GNUNET_FS_PublishContext *ret;
struct GNUNET_DATASTORE_Handle *dsh;
GNUNET_assert (NULL != h);
if (0 == (options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY))
- {
- dsh = GNUNET_DATASTORE_connect (h->cfg);
- if (NULL == dsh)
- return NULL;
- }
+ {
+ dsh = GNUNET_DATASTORE_connect (h->cfg);
+ if (NULL == dsh)
+ return NULL;
+ }
else
- {
- dsh = NULL;
- }
+ {
+ dsh = NULL;
+ }
ret = GNUNET_malloc (sizeof (struct GNUNET_FS_PublishContext));
ret->dsh = dsh;
ret->h = h;
@@ -1274,44 +1174,40 @@
ret->namespace = namespace;
ret->options = options;
if (namespace != NULL)
- {
- namespace->rc++;
- GNUNET_assert (NULL != nid);
- ret->nid = GNUNET_strdup (nid);
- if (NULL != nuid)
- ret->nuid = GNUNET_strdup (nuid);
- }
+ {
+ namespace->rc++;
+ GNUNET_assert (NULL != nid);
+ ret->nid = GNUNET_strdup (nid);
+ if (NULL != nuid)
+ ret->nuid = GNUNET_strdup (nuid);
+ }
/* signal start */
- GNUNET_FS_file_information_inspect (ret->fi,
- &fip_signal_start,
- ret);
+ GNUNET_FS_file_information_inspect (ret->fi, &fip_signal_start, ret);
ret->fi_pos = ret->fi;
ret->top = GNUNET_FS_make_top (h, &GNUNET_FS_publish_signal_suspend_, ret);
GNUNET_FS_publish_sync_ (ret);
if (NULL != ret->dsh)
- {
- GNUNET_assert (NULL == ret->qre);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Reserving space for %u entries and %llu bytes for
publication\n"),
- (unsigned int) ret->reserve_entries,
- (unsigned long long) ret->reserve_space);
- ret->qre = GNUNET_DATASTORE_reserve (ret->dsh,
- ret->reserve_space,
- ret->reserve_entries,
- UINT_MAX,
- UINT_MAX,
- GNUNET_TIME_UNIT_FOREVER_REL,
- &finish_reserve,
- ret);
- }
+ {
+ GNUNET_assert (NULL == ret->qre);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _
+ ("Reserving space for %u entries and %llu bytes for
publication\n"),
+ (unsigned int) ret->reserve_entries,
+ (unsigned long long) ret->reserve_space);
+ ret->qre =
+ GNUNET_DATASTORE_reserve (ret->dsh, ret->reserve_space,
+ ret->reserve_entries, UINT_MAX, UINT_MAX,
+ GNUNET_TIME_UNIT_FOREVER_REL,
&finish_reserve,
+ ret);
+ }
else
- {
- GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == ret->upload_task);
- ret->upload_task
- = GNUNET_SCHEDULER_add_with_priority
(GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
- &GNUNET_FS_publish_main_,
- ret);
- }
+ {
+ GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == ret->upload_task);
+ ret->upload_task
+ =
+ GNUNET_SCHEDULER_add_with_priority
+ (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, &GNUNET_FS_publish_main_, ret);
+ }
return ret;
}
@@ -1331,27 +1227,26 @@
* @return GNUNET_OK to continue (always)
*/
static int
-fip_signal_stop(void *cls,
- struct GNUNET_FS_FileInformation *fi,
- uint64_t length,
- struct GNUNET_CONTAINER_MetaData *meta,
- struct GNUNET_FS_Uri **uri,
- struct GNUNET_FS_BlockOptions *bo,
- int *do_index,
- void **client_info)
+fip_signal_stop (void *cls,
+ struct GNUNET_FS_FileInformation *fi,
+ uint64_t length,
+ struct GNUNET_CONTAINER_MetaData *meta,
+ struct GNUNET_FS_Uri **uri,
+ struct GNUNET_FS_BlockOptions *bo,
+ int *do_index, void **client_info)
{
- struct GNUNET_FS_PublishContext*pc = cls;
+ struct GNUNET_FS_PublishContext *pc = cls;
struct GNUNET_FS_ProgressInfo pi;
uint64_t off;
- if (fi->serialization != NULL)
- {
- GNUNET_FS_remove_sync_file_ (pc->h,
- GNUNET_FS_SYNC_PATH_FILE_INFO,
- fi->serialization);
- GNUNET_free (fi->serialization);
- fi->serialization = NULL;
- }
+ if (fi->serialization != NULL)
+ {
+ GNUNET_FS_remove_sync_file_ (pc->h,
+ GNUNET_FS_SYNC_PATH_FILE_INFO,
+ fi->serialization);
+ GNUNET_free (fi->serialization);
+ fi->serialization = NULL;
+ }
off = (fi->chk_uri == NULL) ? 0 : length;
pi.status = GNUNET_FS_STATUS_PUBLISH_STOPPED;
GNUNET_break (NULL == GNUNET_FS_publish_make_status_ (&pi, pc, fi, off));
@@ -1368,43 +1263,41 @@
*
* @param pc context for the upload to stop
*/
-void
+void
GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *pc)
{
#if DEBUG_PUBLISH
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Publish stop called\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publish stop called\n");
#endif
GNUNET_FS_end_top (pc->h, pc->top);
if (NULL != pc->qre)
- {
- GNUNET_DATASTORE_cancel (pc->qre);
- pc->qre = NULL;
- }
+ {
+ GNUNET_DATASTORE_cancel (pc->qre);
+ pc->qre = NULL;
+ }
if (NULL != pc->dsh)
- {
- GNUNET_DATASTORE_disconnect (pc->dsh, GNUNET_NO);
- pc->dsh = NULL;
- }
+ {
+ GNUNET_DATASTORE_disconnect (pc->dsh, GNUNET_NO);
+ pc->dsh = NULL;
+ }
if (GNUNET_SCHEDULER_NO_TASK != pc->upload_task)
- {
- GNUNET_SCHEDULER_cancel (pc->upload_task);
- pc->upload_task = GNUNET_SCHEDULER_NO_TASK;
- }
- if (pc->serialization != NULL)
- {
- GNUNET_FS_remove_sync_file_ (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH,
pc->serialization);
- GNUNET_free (pc->serialization);
- pc->serialization = NULL;
- }
- GNUNET_FS_file_information_inspect (pc->fi,
- &fip_signal_stop,
- pc);
+ {
+ GNUNET_SCHEDULER_cancel (pc->upload_task);
+ pc->upload_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ if (pc->serialization != NULL)
+ {
+ GNUNET_FS_remove_sync_file_ (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH,
+ pc->serialization);
+ GNUNET_free (pc->serialization);
+ pc->serialization = NULL;
+ }
+ GNUNET_FS_file_information_inspect (pc->fi, &fip_signal_stop, pc);
if (GNUNET_YES == pc->in_network_wait)
- {
- pc->in_network_wait = GNUNET_SYSERR;
- return;
- }
+ {
+ pc->in_network_wait = GNUNET_SYSERR;
+ return;
+ }
publish_cleanup (pc, NULL);
}
@@ -1435,7 +1328,7 @@
/**
* Buffer of the same size as "kb" for
* the encrypted version.
- */
+ */
struct KBlock *cpy;
/**
@@ -1456,7 +1349,7 @@
/**
* Closure for cont.
- */
+ */
void *cont_cls;
/**
@@ -1491,8 +1384,7 @@
* @param tc unused
*/
static void
-publish_ksk_cont (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+publish_ksk_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
/**
@@ -1504,36 +1396,30 @@
* @param msg error message (or NULL)
*/
static void
-kb_put_cont (void *cls,
- int success,
- const char *msg)
+kb_put_cont (void *cls, int success, const char *msg)
{
struct PublishKskContext *pkc = cls;
pkc->qre = NULL;
if (GNUNET_OK != success)
- {
+ {
#if DEBUG_PUBLISH
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "KB PUT operation complete\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "KB PUT operation complete\n");
#endif
- if (NULL != pkc->dsh)
- {
- GNUNET_DATASTORE_disconnect (pkc->dsh, GNUNET_NO);
- pkc->dsh = NULL;
- }
- GNUNET_free (pkc->cpy);
- GNUNET_free (pkc->kb);
- pkc->cont (pkc->cont_cls,
- NULL,
- msg);
- GNUNET_FS_uri_destroy (pkc->ksk_uri);
- GNUNET_free (pkc);
- return;
+ if (NULL != pkc->dsh)
+ {
+ GNUNET_DATASTORE_disconnect (pkc->dsh, GNUNET_NO);
+ pkc->dsh = NULL;
}
+ GNUNET_free (pkc->cpy);
+ GNUNET_free (pkc->kb);
+ pkc->cont (pkc->cont_cls, NULL, msg);
+ GNUNET_FS_uri_destroy (pkc->ksk_uri);
+ GNUNET_free (pkc);
+ return;
+ }
GNUNET_SCHEDULER_add_continuation (&publish_ksk_cont,
- pkc,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ pkc, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
}
@@ -1545,8 +1431,7 @@
* @param tc unused
*/
static void
-publish_ksk_cont (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+publish_ksk_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct PublishKskContext *pkc = cls;
const char *keyword;
@@ -1557,69 +1442,60 @@
struct GNUNET_CRYPTO_RsaPrivateKey *pk;
- if ( (pkc->i == pkc->ksk_uri->data.ksk.keywordCount) ||
- (NULL == pkc->dsh) )
- {
+ if ((pkc->i == pkc->ksk_uri->data.ksk.keywordCount) || (NULL == pkc->dsh))
+ {
#if DEBUG_PUBLISH
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "KSK PUT operation complete\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "KSK PUT operation complete\n");
#endif
- if (NULL != pkc->dsh)
- {
- GNUNET_DATASTORE_disconnect (pkc->dsh, GNUNET_NO);
- pkc->dsh = NULL;
- }
- GNUNET_free (pkc->cpy);
- GNUNET_free (pkc->kb);
- pkc->cont (pkc->cont_cls,
- pkc->ksk_uri,
- NULL);
- GNUNET_FS_uri_destroy (pkc->ksk_uri);
- GNUNET_free (pkc);
- return;
+ if (NULL != pkc->dsh)
+ {
+ GNUNET_DATASTORE_disconnect (pkc->dsh, GNUNET_NO);
+ pkc->dsh = NULL;
}
+ GNUNET_free (pkc->cpy);
+ GNUNET_free (pkc->kb);
+ pkc->cont (pkc->cont_cls, pkc->ksk_uri, NULL);
+ GNUNET_FS_uri_destroy (pkc->ksk_uri);
+ GNUNET_free (pkc);
+ return;
+ }
keyword = pkc->ksk_uri->data.ksk.keywords[pkc->i++];
#if DEBUG_PUBLISH
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Publishing under keyword `%s'\n",
- keyword);
+ "Publishing under keyword `%s'\n", keyword);
#endif
/* first character of keyword indicates if it is
- mandatory or not -- ignore for hashing */
+ * mandatory or not -- ignore for hashing */
GNUNET_CRYPTO_hash (&keyword[1], strlen (&keyword[1]), &key);
GNUNET_CRYPTO_hash_to_aes_key (&key, &skey, &iv);
GNUNET_CRYPTO_aes_encrypt (&pkc->kb[1],
- pkc->slen + pkc->mdsize,
- &skey,
- &iv,
- &pkc->cpy[1]);
+ pkc->slen + pkc->mdsize, &skey, &iv,
&pkc->cpy[1]);
pk = GNUNET_CRYPTO_rsa_key_create_from_hash (&key);
GNUNET_assert (NULL != pk);
GNUNET_CRYPTO_rsa_key_get_public (pk, &pkc->cpy->keyspace);
GNUNET_CRYPTO_hash (&pkc->cpy->keyspace,
- sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
- &query);
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CRYPTO_rsa_sign (pk,
- &pkc->cpy->purpose,
- &pkc->cpy->signature));
+ sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+ &query);
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CRYPTO_rsa_sign (pk,
+ &pkc->cpy->purpose,
+ &pkc->cpy->signature));
GNUNET_CRYPTO_rsa_key_free (pk);
pkc->qre = GNUNET_DATASTORE_put (pkc->dsh,
- 0,
- &query,
- pkc->mdsize +
- sizeof (struct KBlock) +
- pkc->slen,
- pkc->cpy,
- GNUNET_BLOCK_TYPE_FS_KBLOCK,
- pkc->bo.content_priority,
- pkc->bo.anonymity_level,
- pkc->bo.replication_level,
- pkc->bo.expiration_time,
- -2, 1,
- GNUNET_CONSTANTS_SERVICE_TIMEOUT,
- &kb_put_cont,
- pkc);
+ 0,
+ &query,
+ pkc->mdsize +
+ sizeof (struct KBlock) +
+ pkc->slen,
+ pkc->cpy,
+ GNUNET_BLOCK_TYPE_FS_KBLOCK,
+ pkc->bo.content_priority,
+ pkc->bo.anonymity_level,
+ pkc->bo.replication_level,
+ pkc->bo.expiration_time,
+ -2, 1,
+ GNUNET_CONSTANTS_SERVICE_TIMEOUT,
+ &kb_put_cont, pkc);
}
@@ -1637,13 +1513,12 @@
*/
void
GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h,
- const struct GNUNET_FS_Uri *ksk_uri,
- const struct GNUNET_CONTAINER_MetaData *meta,
- const struct GNUNET_FS_Uri *uri,
- const struct GNUNET_FS_BlockOptions *bo,
- enum GNUNET_FS_PublishOptions options,
- GNUNET_FS_PublishContinuation cont,
- void *cont_cls)
+ const struct GNUNET_FS_Uri *ksk_uri,
+ const struct GNUNET_CONTAINER_MetaData *meta,
+ const struct GNUNET_FS_Uri *uri,
+ const struct GNUNET_FS_BlockOptions *bo,
+ enum GNUNET_FS_PublishOptions options,
+ GNUNET_FS_PublishContinuation cont, void *cont_cls)
{
struct PublishKskContext *pkc;
char *uris;
@@ -1658,15 +1533,15 @@
pkc->cont = cont;
pkc->cont_cls = cont_cls;
if (0 == (options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY))
+ {
+ pkc->dsh = GNUNET_DATASTORE_connect (h->cfg);
+ if (pkc->dsh == NULL)
{
- pkc->dsh = GNUNET_DATASTORE_connect (h->cfg);
- if (pkc->dsh == NULL)
- {
- cont (cont_cls, NULL, _("Could not connect to datastore."));
- GNUNET_free (pkc);
- return;
- }
+ cont (cont_cls, NULL, _("Could not connect to datastore."));
+ GNUNET_free (pkc);
+ return;
}
+ }
if (meta == NULL)
pkc->mdsize = 0;
else
@@ -1676,10 +1551,10 @@
pkc->slen = strlen (uris) + 1;
size = pkc->mdsize + sizeof (struct KBlock) + pkc->slen;
if (size > MAX_KBLOCK_SIZE)
- {
- size = MAX_KBLOCK_SIZE;
- pkc->mdsize = size - sizeof (struct KBlock) - pkc->slen;
- }
+ {
+ size = MAX_KBLOCK_SIZE;
+ pkc->mdsize = size - sizeof (struct KBlock) - pkc->slen;
+ }
pkc->kb = GNUNET_malloc (size);
kbe = (char *) &pkc->kb[1];
memcpy (kbe, uris, pkc->slen);
@@ -1687,34 +1562,33 @@
sptr = &kbe[pkc->slen];
if (meta != NULL)
pkc->mdsize = GNUNET_CONTAINER_meta_data_serialize (meta,
- &sptr,
- pkc->mdsize,
-
GNUNET_CONTAINER_META_DATA_SERIALIZE_PART);
+ &sptr,
+ pkc->mdsize,
+
GNUNET_CONTAINER_META_DATA_SERIALIZE_PART);
if (pkc->mdsize == -1)
+ {
+ GNUNET_break (0);
+ GNUNET_free (pkc->kb);
+ if (pkc->dsh != NULL)
{
- GNUNET_break (0);
- GNUNET_free (pkc->kb);
- if (pkc->dsh != NULL)
- {
- GNUNET_DATASTORE_disconnect (pkc->dsh, GNUNET_NO);
- pkc->dsh = NULL;
- }
- cont (cont_cls, NULL, _("Internal error."));
- GNUNET_free (pkc);
- return;
+ GNUNET_DATASTORE_disconnect (pkc->dsh, GNUNET_NO);
+ pkc->dsh = NULL;
}
+ cont (cont_cls, NULL, _("Internal error."));
+ GNUNET_free (pkc);
+ return;
+ }
size = sizeof (struct KBlock) + pkc->slen + pkc->mdsize;
pkc->cpy = GNUNET_malloc (size);
- pkc->cpy->purpose.size = htonl (sizeof (struct
GNUNET_CRYPTO_RsaSignaturePurpose) +
- sizeof(struct
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) +
- pkc->mdsize +
- pkc->slen);
- pkc->cpy->purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_FS_KBLOCK);
+ pkc->cpy->purpose.size =
+ htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
+ sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) +
+ pkc->mdsize + pkc->slen);
+ pkc->cpy->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_FS_KBLOCK);
pkc->ksk_uri = GNUNET_FS_uri_dup (ksk_uri);
GNUNET_SCHEDULER_add_continuation (&publish_ksk_cont,
- pkc,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ pkc, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
}
Modified: gnunet/src/fs/fs_search.c
===================================================================
--- gnunet/src/fs/fs_search.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/fs/fs_search.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -42,20 +42,19 @@
*/
void *
GNUNET_FS_search_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
- struct GNUNET_FS_SearchContext *sc)
-{
+ struct GNUNET_FS_SearchContext *sc)
+{
void *ret;
+
pi->value.search.sc = sc;
- pi->value.search.cctx
- = sc->client_info;
+ pi->value.search.cctx = sc->client_info;
pi->value.search.pctx
- = (sc->psearch_result == NULL) ? NULL : sc->psearch_result->client_info;
- pi->value.search.query
- = sc->uri;
- pi->value.search.duration = GNUNET_TIME_absolute_get_duration
(sc->start_time);
+ = (sc->psearch_result == NULL) ? NULL : sc->psearch_result->client_info;
+ pi->value.search.query = sc->uri;
+ pi->value.search.duration =
+ GNUNET_TIME_absolute_get_duration (sc->start_time);
pi->value.search.anonymity = sc->anonymity;
- ret = sc->h->upcb (sc->h->upcb_cls,
- pi);
+ ret = sc->h->upcb (sc->h->upcb_cls, pi);
return ret;
}
@@ -72,15 +71,12 @@
* GNUNET_OK otherwise
*/
static int
-test_result_present (void *cls,
- const GNUNET_HashCode * key,
- void *value)
+test_result_present (void *cls, const GNUNET_HashCode * key, void *value)
{
const struct GNUNET_FS_Uri *uri = cls;
struct GNUNET_FS_SearchResult *sr = value;
- if (GNUNET_FS_uri_test_equal (uri,
- sr->uri))
+ if (GNUNET_FS_uri_test_equal (uri, sr->uri))
return GNUNET_SYSERR;
return GNUNET_OK;
}
@@ -94,9 +90,9 @@
* @param sr the specific result
*/
static void
-notify_client_chk_result (struct GNUNET_FS_SearchContext *sc,
- struct GNUNET_FS_SearchResult *sr)
-{
+notify_client_chk_result (struct GNUNET_FS_SearchContext *sc,
+ struct GNUNET_FS_SearchResult *sr)
+{
struct GNUNET_FS_ProgressInfo pi;
pi.status = GNUNET_FS_STATUS_SEARCH_RESULT;
@@ -116,9 +112,9 @@
* @param sr the specific result
*/
static void
-notify_client_chk_update (struct GNUNET_FS_SearchContext *sc,
- struct GNUNET_FS_SearchResult *sr)
-{
+notify_client_chk_update (struct GNUNET_FS_SearchContext *sc,
+ struct GNUNET_FS_SearchResult *sr)
+{
struct GNUNET_FS_ProgressInfo pi;
pi.status = GNUNET_FS_STATUS_SEARCH_UPDATE;
@@ -126,11 +122,10 @@
pi.value.search.specifics.update.meta = sr->meta;
pi.value.search.specifics.update.uri = sr->uri;
pi.value.search.specifics.update.availability_rank
- = 2*sr->availability_success - sr->availability_trials;
- pi.value.search.specifics.update.availability_certainty
- = sr->availability_trials;
- pi.value.search.specifics.update.applicability_rank
- = sr->optional_support;
+ = 2 * sr->availability_success - sr->availability_trials;
+ pi.value.search.specifics.update.availability_certainty
+ = sr->availability_trials;
+ pi.value.search.specifics.update.applicability_rank = sr->optional_support;
sr->client_info = GNUNET_FS_search_make_status_ (&pi, sc);
}
@@ -138,7 +133,7 @@
/**
* Context for "get_result_present".
*/
-struct GetResultContext
+struct GetResultContext
{
/**
* The URI we're looking for.
@@ -164,15 +159,12 @@
* @return GNUNET_OK
*/
static int
-get_result_present (void *cls,
- const GNUNET_HashCode * key,
- void *value)
+get_result_present (void *cls, const GNUNET_HashCode * key, void *value)
{
struct GetResultContext *grc = cls;
struct GNUNET_FS_SearchResult *sr = value;
- if (GNUNET_FS_uri_test_equal (grc->uri,
- sr->uri))
+ if (GNUNET_FS_uri_test_equal (grc->uri, sr->uri))
grc->sr = sr;
return GNUNET_OK;
}
@@ -192,7 +184,8 @@
pi.value.search.specifics.update.meta = sr->meta;
pi.value.search.specifics.update.uri = sr->uri;
pi.value.search.specifics.update.availability_rank =
sr->availability_success;
- pi.value.search.specifics.update.availability_certainty =
sr->availability_trials;
+ pi.value.search.specifics.update.availability_certainty =
+ sr->availability_trials;
pi.value.search.specifics.update.applicability_rank = sr->optional_support;
sr->sc->client_info = GNUNET_FS_search_make_status_ (&pi, sr->sc);
GNUNET_FS_search_start_probe_ (sr);
@@ -206,10 +199,10 @@
* @param tc scheduler context
*/
static void
-probe_failure_handler (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+probe_failure_handler (void *cls, const struct GNUNET_SCHEDULER_TaskContext
*tc)
{
struct GNUNET_FS_SearchResult *sr = cls;
+
sr->availability_trials++;
GNUNET_FS_search_result_sync_ (sr);
signal_probe_result (sr);
@@ -223,10 +216,10 @@
* @param tc scheduler context
*/
static void
-probe_success_handler (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+probe_success_handler (void *cls, const struct GNUNET_SCHEDULER_TaskContext
*tc)
{
struct GNUNET_FS_SearchResult *sr = cls;
+
sr->availability_trials++;
sr->availability_success++;
GNUNET_FS_search_result_sync_ (sr);
@@ -249,79 +242,79 @@
* will be passed to future callbacks in the respective
* field in the GNUNET_FS_ProgressInfo struct.
*/
-void*
+void *
GNUNET_FS_search_probe_progress_ (void *cls,
- const struct GNUNET_FS_ProgressInfo *info)
+ const struct GNUNET_FS_ProgressInfo *info)
{
struct GNUNET_FS_SearchResult *sr = info->value.download.cctx;
struct GNUNET_TIME_Relative dur;
switch (info->status)
+ {
+ case GNUNET_FS_STATUS_DOWNLOAD_START:
+ /* ignore */
+ break;
+ case GNUNET_FS_STATUS_DOWNLOAD_RESUME:
+ /* probes should never be resumed */
+ GNUNET_assert (0);
+ break;
+ case GNUNET_FS_STATUS_DOWNLOAD_SUSPEND:
+ /* probes should never be suspended */
+ GNUNET_break (0);
+ break;
+ case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS:
+ /* ignore */
+ break;
+ case GNUNET_FS_STATUS_DOWNLOAD_ERROR:
+ if (sr->probe_cancel_task != GNUNET_SCHEDULER_NO_TASK)
{
- case GNUNET_FS_STATUS_DOWNLOAD_START:
- /* ignore */
- break;
- case GNUNET_FS_STATUS_DOWNLOAD_RESUME:
- /* probes should never be resumed */
- GNUNET_assert (0);
- break;
- case GNUNET_FS_STATUS_DOWNLOAD_SUSPEND:
- /* probes should never be suspended */
- GNUNET_break (0);
- break;
- case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS:
- /* ignore */
- break;
- case GNUNET_FS_STATUS_DOWNLOAD_ERROR:
- if (sr->probe_cancel_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (sr->probe_cancel_task);
- sr->probe_cancel_task = GNUNET_SCHEDULER_NO_TASK;
- }
- sr->probe_cancel_task = GNUNET_SCHEDULER_add_delayed
(sr->remaining_probe_time,
-
&probe_failure_handler,
- sr);
- break;
- case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
- if (sr->probe_cancel_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (sr->probe_cancel_task);
- sr->probe_cancel_task = GNUNET_SCHEDULER_NO_TASK;
- }
- sr->probe_cancel_task = GNUNET_SCHEDULER_add_delayed
(sr->remaining_probe_time,
-
&probe_success_handler,
- sr);
- break;
- case GNUNET_FS_STATUS_DOWNLOAD_STOPPED:
- if (sr->probe_cancel_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (sr->probe_cancel_task);
- sr->probe_cancel_task = GNUNET_SCHEDULER_NO_TASK;
- }
- sr = NULL;
- break;
- case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE:
- GNUNET_assert (sr->probe_cancel_task == GNUNET_SCHEDULER_NO_TASK);
- sr->probe_active_time = GNUNET_TIME_absolute_get ();
- sr->probe_cancel_task = GNUNET_SCHEDULER_add_delayed
(sr->remaining_probe_time,
-
&probe_failure_handler,
- sr);
- break;
- case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE:
- if (sr->probe_cancel_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (sr->probe_cancel_task);
- sr->probe_cancel_task = GNUNET_SCHEDULER_NO_TASK;
- }
- dur = GNUNET_TIME_absolute_get_duration (sr->probe_active_time);
- sr->remaining_probe_time = GNUNET_TIME_relative_subtract
(sr->remaining_probe_time,
- dur);
- GNUNET_FS_search_result_sync_ (sr);
- break;
- default:
- GNUNET_break (0);
- return NULL;
+ GNUNET_SCHEDULER_cancel (sr->probe_cancel_task);
+ sr->probe_cancel_task = GNUNET_SCHEDULER_NO_TASK;
}
+ sr->probe_cancel_task =
+ GNUNET_SCHEDULER_add_delayed (sr->remaining_probe_time,
+ &probe_failure_handler, sr);
+ break;
+ case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
+ if (sr->probe_cancel_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (sr->probe_cancel_task);
+ sr->probe_cancel_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ sr->probe_cancel_task =
+ GNUNET_SCHEDULER_add_delayed (sr->remaining_probe_time,
+ &probe_success_handler, sr);
+ break;
+ case GNUNET_FS_STATUS_DOWNLOAD_STOPPED:
+ if (sr->probe_cancel_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (sr->probe_cancel_task);
+ sr->probe_cancel_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ sr = NULL;
+ break;
+ case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE:
+ GNUNET_assert (sr->probe_cancel_task == GNUNET_SCHEDULER_NO_TASK);
+ sr->probe_active_time = GNUNET_TIME_absolute_get ();
+ sr->probe_cancel_task =
+ GNUNET_SCHEDULER_add_delayed (sr->remaining_probe_time,
+ &probe_failure_handler, sr);
+ break;
+ case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE:
+ if (sr->probe_cancel_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (sr->probe_cancel_task);
+ sr->probe_cancel_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ dur = GNUNET_TIME_absolute_get_duration (sr->probe_active_time);
+ sr->remaining_probe_time =
+ GNUNET_TIME_relative_subtract (sr->remaining_probe_time, dur);
+ GNUNET_FS_search_result_sync_ (sr);
+ break;
+ default:
+ GNUNET_break (0);
+ return NULL;
+ }
return sr;
}
@@ -336,7 +329,7 @@
{
uint64_t off;
uint64_t len;
-
+
if (sr->probe_ctx != NULL)
return;
if (sr->download != NULL)
@@ -348,7 +341,7 @@
len = GNUNET_FS_uri_chk_get_file_size (sr->uri);
if (len == 0)
return;
- if ( (len <= DBLOCK_SIZE) && (sr->availability_success > 0))
+ if ((len <= DBLOCK_SIZE) && (sr->availability_success > 0))
return;
off = len / DBLOCK_SIZE;
if (off > 0)
@@ -358,17 +351,14 @@
len = len - off;
else
len = DBLOCK_SIZE;
- sr->remaining_probe_time = GNUNET_TIME_relative_multiply
(sr->sc->h->avg_block_latency,
- 2 * (1 +
sr->availability_trials));
- sr->probe_ctx = GNUNET_FS_download_start (sr->sc->h,
- sr->uri,
- sr->meta,
- NULL, NULL,
- off, len,
- sr->sc->anonymity,
- GNUNET_FS_DOWNLOAD_NO_TEMPORARIES |
- GNUNET_FS_DOWNLOAD_IS_PROBE,
- sr, NULL);
+ sr->remaining_probe_time =
+ GNUNET_TIME_relative_multiply (sr->sc->h->avg_block_latency,
+ 2 * (1 + sr->availability_trials));
+ sr->probe_ctx =
+ GNUNET_FS_download_start (sr->sc->h, sr->uri, sr->meta, NULL, NULL, off,
+ len, sr->sc->anonymity,
+ GNUNET_FS_DOWNLOAD_NO_TEMPORARIES |
+ GNUNET_FS_DOWNLOAD_IS_PROBE, sr, NULL);
}
@@ -383,10 +373,10 @@
* under the "ent" keyword
*/
static void
-process_ksk_result (struct GNUNET_FS_SearchContext *sc,
- struct SearchRequestEntry *ent,
- const struct GNUNET_FS_Uri *uri,
- const struct GNUNET_CONTAINER_MetaData *meta)
+process_ksk_result (struct GNUNET_FS_SearchContext *sc,
+ struct SearchRequestEntry *ent,
+ const struct GNUNET_FS_Uri *uri,
+ const struct GNUNET_CONTAINER_MetaData *meta)
{
GNUNET_HashCode key;
struct GNUNET_FS_SearchResult *sr;
@@ -397,36 +387,34 @@
GNUNET_FS_uri_to_key (uri, &key);
if (GNUNET_SYSERR ==
GNUNET_CONTAINER_multihashmap_get_multiple (ent->results,
- &key,
- &test_result_present,
- (void*) uri))
- return; /* duplicate result */
+ &key,
+ &test_result_present,
+ (void *) uri))
+ return; /* duplicate result */
/* try to find search result in master map */
grc.sr = NULL;
grc.uri = uri;
GNUNET_CONTAINER_multihashmap_get_multiple (sc->master_result_map,
- &key,
- &get_result_present,
- &grc);
+ &key, &get_result_present, &grc);
sr = grc.sr;
is_new = (NULL == sr) || (sr->mandatory_missing > 0);
if (NULL == sr)
- {
- sr = GNUNET_malloc (sizeof (struct GNUNET_FS_SearchResult));
- sr->sc = sc;
- sr->uri = GNUNET_FS_uri_dup (uri);
- sr->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
- sr->mandatory_missing = sc->mandatory_count;
- sr->key = key;
- GNUNET_CONTAINER_multihashmap_put (sc->master_result_map,
- &key,
- sr,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
- }
+ {
+ sr = GNUNET_malloc (sizeof (struct GNUNET_FS_SearchResult));
+ sr->sc = sc;
+ sr->uri = GNUNET_FS_uri_dup (uri);
+ sr->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
+ sr->mandatory_missing = sc->mandatory_count;
+ sr->key = key;
+ GNUNET_CONTAINER_multihashmap_put (sc->master_result_map,
+ &key,
+ sr,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
+ }
else
- {
- GNUNET_CONTAINER_meta_data_merge (sr->meta, meta);
- }
+ {
+ GNUNET_CONTAINER_meta_data_merge (sr->meta, meta);
+ }
/* check if mandatory satisfied */
if (ent->mandatory)
sr->mandatory_missing--;
@@ -455,13 +443,15 @@
* @param psearch parent search result (for namespace update searches)
* @return context that can be used to control the search
*/
-static struct GNUNET_FS_SearchContext *
-search_start (struct GNUNET_FS_Handle *h,
- const struct GNUNET_FS_Uri *uri,
- uint32_t anonymity,
- enum GNUNET_FS_SearchOptions options,
- void *cctx,
- struct GNUNET_FS_SearchResult *psearch);
+static struct GNUNET_FS_SearchContext *search_start (struct GNUNET_FS_Handle
*h,
+ const struct GNUNET_FS_Uri
+ *uri, uint32_t anonymity,
+ enum
+ GNUNET_FS_SearchOptions
+ options, void *cctx,
+ struct
+ GNUNET_FS_SearchResult
+ *psearch);
/**
@@ -474,10 +464,10 @@
* @param meta metadata associated with the URI
*/
static void
-process_sks_result (struct GNUNET_FS_SearchContext *sc,
- const char *id_update,
- const struct GNUNET_FS_Uri *uri,
- const struct GNUNET_CONTAINER_MetaData *meta)
+process_sks_result (struct GNUNET_FS_SearchContext *sc,
+ const char *id_update,
+ const struct GNUNET_FS_Uri *uri,
+ const struct GNUNET_CONTAINER_MetaData *meta)
{
struct GNUNET_FS_Uri uu;
GNUNET_HashCode key;
@@ -486,39 +476,33 @@
/* check if new */
GNUNET_FS_uri_to_key (uri, &key);
GNUNET_CRYPTO_hash_xor (&uri->data.chk.chk.key,
- &uri->data.chk.chk.query,
- &key);
+ &uri->data.chk.chk.query, &key);
if (GNUNET_SYSERR ==
GNUNET_CONTAINER_multihashmap_get_multiple (sc->master_result_map,
- &key,
- &test_result_present,
- (void*) uri))
- return; /* duplicate result */
+ &key,
+ &test_result_present,
+ (void *) uri))
+ return; /* duplicate result */
sr = GNUNET_malloc (sizeof (struct GNUNET_FS_SearchResult));
sr->sc = sc;
sr->uri = GNUNET_FS_uri_dup (uri);
sr->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
sr->key = key;
GNUNET_CONTAINER_multihashmap_put (sc->master_result_map,
- &key,
- sr,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
+ &key,
+ sr,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
GNUNET_FS_search_result_sync_ (sr);
GNUNET_FS_search_start_probe_ (sr);
/* notify client */
notify_client_chk_result (sc, sr);
/* search for updates */
if (strlen (id_update) == 0)
- return; /* no updates */
+ return; /* no updates */
uu.type = sks;
uu.data.sks.namespace = sc->uri->data.sks.namespace;
uu.data.sks.identifier = GNUNET_strdup (id_update);
- (void) search_start (sc->h,
- &uu,
- sc->anonymity,
- sc->options,
- NULL,
- sr);
+ (void) search_start (sc->h, &uu, sc->anonymity, sc->options, NULL, sr);
GNUNET_free (uu.data.sks.identifier);
}
@@ -532,8 +516,7 @@
*/
static void
process_kblock (struct GNUNET_FS_SearchContext *sc,
- const struct KBlock *kb,
- size_t size)
+ const struct KBlock *kb, size_t size)
{
unsigned int i;
size_t j;
@@ -545,59 +528,54 @@
struct GNUNET_CONTAINER_MetaData *meta;
struct GNUNET_FS_Uri *uri;
char *emsg;
-
+
GNUNET_CRYPTO_hash (&kb->keyspace,
- sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
- &q);
+ sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+ &q);
/* find key */
- for (i=0;i<sc->uri->data.ksk.keywordCount;i++)
- if (0 == memcmp (&q,
- &sc->requests[i].query,
- sizeof (GNUNET_HashCode)))
+ for (i = 0; i < sc->uri->data.ksk.keywordCount; i++)
+ if (0 == memcmp (&q, &sc->requests[i].query, sizeof (GNUNET_HashCode)))
break;
if (i == sc->uri->data.ksk.keywordCount)
- {
- /* oops, does not match any of our keywords!? */
- GNUNET_break (0);
- return;
- }
+ {
+ /* oops, does not match any of our keywords!? */
+ GNUNET_break (0);
+ return;
+ }
/* decrypt */
GNUNET_CRYPTO_hash_to_aes_key (&sc->requests[i].key, &skey, &iv);
if (-1 == GNUNET_CRYPTO_aes_decrypt (&kb[1],
- size - sizeof (struct KBlock),
- &skey,
- &iv,
- pt))
- {
- GNUNET_break (0);
- return;
- }
+ size - sizeof (struct KBlock),
+ &skey, &iv, pt))
+ {
+ GNUNET_break (0);
+ return;
+ }
/* parse */
eos = memchr (pt, 0, sizeof (pt));
if (NULL == eos)
- {
- GNUNET_break_op (0);
- return;
- }
+ {
+ GNUNET_break_op (0);
+ return;
+ }
j = eos - pt + 1;
if (sizeof (pt) == j)
meta = GNUNET_CONTAINER_meta_data_create ();
else
- meta = GNUNET_CONTAINER_meta_data_deserialize (&pt[j],
- sizeof (pt) - j);
+ meta = GNUNET_CONTAINER_meta_data_deserialize (&pt[j], sizeof (pt) - j);
if (meta == NULL)
- {
- GNUNET_break_op (0); /* kblock malformed */
- return;
- }
+ {
+ GNUNET_break_op (0); /* kblock malformed */
+ return;
+ }
uri = GNUNET_FS_uri_parse (pt, &emsg);
if (uri == NULL)
- {
- GNUNET_break_op (0); /* kblock malformed */
- GNUNET_free_non_null (emsg);
- GNUNET_CONTAINER_meta_data_destroy (meta);
- return;
- }
+ {
+ GNUNET_break_op (0); /* kblock malformed */
+ GNUNET_free_non_null (emsg);
+ GNUNET_CONTAINER_meta_data_destroy (meta);
+ return;
+ }
/* process */
process_ksk_result (sc, &sc->requests[i], uri, meta);
@@ -616,8 +594,7 @@
*/
static void
process_nblock (struct GNUNET_FS_SearchContext *sc,
- const struct NBlock *nb,
- size_t size)
+ const struct NBlock *nb, size_t size)
{
unsigned int i;
size_t j;
@@ -629,70 +606,61 @@
struct GNUNET_CONTAINER_MetaData *meta;
struct GNUNET_FS_Uri *uri;
char *uris;
-
+
GNUNET_CRYPTO_hash (&nb->keyspace,
- sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
- &q);
+ sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+ &q);
/* find key */
- for (i=0;i<sc->uri->data.ksk.keywordCount;i++)
- if (0 == memcmp (&q,
- &sc->requests[i].query,
- sizeof (GNUNET_HashCode)))
+ for (i = 0; i < sc->uri->data.ksk.keywordCount; i++)
+ if (0 == memcmp (&q, &sc->requests[i].query, sizeof (GNUNET_HashCode)))
break;
if (i == sc->uri->data.ksk.keywordCount)
- {
- /* oops, does not match any of our keywords!? */
- GNUNET_break (0);
- return;
- }
+ {
+ /* oops, does not match any of our keywords!? */
+ GNUNET_break (0);
+ return;
+ }
/* decrypt */
GNUNET_CRYPTO_hash_to_aes_key (&sc->requests[i].key, &skey, &iv);
if (-1 == GNUNET_CRYPTO_aes_decrypt (&nb[1],
- size - sizeof (struct NBlock),
- &skey,
- &iv,
- pt))
- {
- GNUNET_break (0);
- return;
- }
+ size - sizeof (struct NBlock),
+ &skey, &iv, pt))
+ {
+ GNUNET_break (0);
+ return;
+ }
/* parse */
eos = memchr (pt, 0, sizeof (pt));
if (NULL == eos)
- {
- GNUNET_break_op (0);
- return;
- }
+ {
+ GNUNET_break_op (0);
+ return;
+ }
j = eos - pt + 1;
if (sizeof (pt) == j)
meta = GNUNET_CONTAINER_meta_data_create ();
else
- meta = GNUNET_CONTAINER_meta_data_deserialize (&pt[j],
- sizeof (pt) - j);
+ meta = GNUNET_CONTAINER_meta_data_deserialize (&pt[j], sizeof (pt) - j);
if (meta == NULL)
- {
- GNUNET_break_op (0); /* nblock malformed */
- return;
- }
+ {
+ GNUNET_break_op (0); /* nblock malformed */
+ return;
+ }
uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
uri->type = sks;
uri->data.sks.identifier = GNUNET_strdup (pt);
GNUNET_CRYPTO_hash (&nb->subspace,
- sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
- &uri->data.sks.namespace);
+ sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+ &uri->data.sks.namespace);
uris = GNUNET_FS_uri_to_string (uri);
GNUNET_CONTAINER_meta_data_insert (meta,
- "<gnunet>",
- EXTRACTOR_METATYPE_URI,
- EXTRACTOR_METAFORMAT_UTF8,
- "text/plain",
- uris,
- strlen (uris)+1);
+ "<gnunet>",
+ EXTRACTOR_METATYPE_URI,
+ EXTRACTOR_METAFORMAT_UTF8,
+ "text/plain", uris, strlen (uris) + 1);
GNUNET_free (uris);
- GNUNET_PSEUDONYM_add (sc->h->cfg,
- &uri->data.sks.namespace,
- meta);
+ GNUNET_PSEUDONYM_add (sc->h->cfg, &uri->data.sks.namespace, meta);
/* process */
process_ksk_result (sc, &sc->requests[i], uri, meta);
@@ -711,8 +679,7 @@
*/
static void
process_sblock (struct GNUNET_FS_SearchContext *sc,
- const struct SBlock *sb,
- size_t size)
+ const struct SBlock *sb, size_t size)
{
size_t len = size - sizeof (struct SBlock);
char pt[len];
@@ -729,48 +696,36 @@
/* decrypt */
identifier = sc->uri->data.sks.identifier;
- GNUNET_CRYPTO_hash (identifier,
- strlen (identifier),
- &key);
+ GNUNET_CRYPTO_hash (identifier, strlen (identifier), &key);
GNUNET_CRYPTO_hash_to_aes_key (&key, &skey, &iv);
- if (-1 == GNUNET_CRYPTO_aes_decrypt (&sb[1],
- len,
- &skey,
- &iv,
- pt))
- {
- GNUNET_break (0);
- return;
- }
+ if (-1 == GNUNET_CRYPTO_aes_decrypt (&sb[1], len, &skey, &iv, pt))
+ {
+ GNUNET_break (0);
+ return;
+ }
/* parse */
- off = GNUNET_STRINGS_buffer_tokenize (pt,
- len,
- 2,
- &id,
- &uris);
+ off = GNUNET_STRINGS_buffer_tokenize (pt, len, 2, &id, &uris);
if (off == 0)
- {
- GNUNET_break_op (0); /* sblock malformed */
- return;
- }
- meta = GNUNET_CONTAINER_meta_data_deserialize (&pt[off],
- len - off);
+ {
+ GNUNET_break_op (0); /* sblock malformed */
+ return;
+ }
+ meta = GNUNET_CONTAINER_meta_data_deserialize (&pt[off], len - off);
if (meta == NULL)
- {
- GNUNET_break_op (0); /* sblock malformed */
- return;
- }
+ {
+ GNUNET_break_op (0); /* sblock malformed */
+ return;
+ }
uri = GNUNET_FS_uri_parse (uris, &emsg);
if (uri == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to parse URI `%s': %s\n",
- uris, emsg);
- GNUNET_break_op (0); /* sblock malformed */
- GNUNET_free_non_null (emsg);
- GNUNET_CONTAINER_meta_data_destroy (meta);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to parse URI `%s': %s\n", uris, emsg);
+ GNUNET_break_op (0); /* sblock malformed */
+ GNUNET_free_non_null (emsg);
+ GNUNET_CONTAINER_meta_data_destroy (meta);
+ return;
+ }
/* process */
process_sks_result (sc, id, uri, meta);
/* clean up */
@@ -790,76 +745,74 @@
*/
static void
process_result (struct GNUNET_FS_SearchContext *sc,
- enum GNUNET_BLOCK_Type type,
- struct GNUNET_TIME_Absolute expiration,
- const void *data,
- size_t size)
+ enum GNUNET_BLOCK_Type type,
+ struct GNUNET_TIME_Absolute expiration,
+ const void *data, size_t size)
{
if (GNUNET_TIME_absolute_get_duration (expiration).rel_value > 0)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Result received has already expired.\n");
+ return; /* result expired */
+ }
+ switch (type)
+ {
+ case GNUNET_BLOCK_TYPE_FS_KBLOCK:
+ if (!GNUNET_FS_uri_test_ksk (sc->uri))
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Result received has already expired.\n");
- return; /* result expired */
+ GNUNET_break (0);
+ return;
}
- switch (type)
+ if (sizeof (struct KBlock) > size)
{
- case GNUNET_BLOCK_TYPE_FS_KBLOCK:
- if (! GNUNET_FS_uri_test_ksk (sc->uri))
- {
- GNUNET_break (0);
- return;
- }
- if (sizeof (struct KBlock) > size)
- {
- GNUNET_break_op (0);
- return;
- }
- process_kblock (sc, data, size);
- break;
- case GNUNET_BLOCK_TYPE_FS_SBLOCK:
- if (! GNUNET_FS_uri_test_sks (sc->uri))
- {
- GNUNET_break (0);
- return;
- }
- if (sizeof (struct SBlock) > size)
- {
- GNUNET_break_op (0);
- return;
- }
- process_sblock (sc, data, size);
- break;
- case GNUNET_BLOCK_TYPE_FS_NBLOCK:
- if (! GNUNET_FS_uri_test_ksk (sc->uri))
- {
- GNUNET_break (0);
- return;
- }
- if (sizeof (struct NBlock) > size)
- {
- GNUNET_break_op (0);
- return;
- }
- process_nblock (sc, data, size);
- break;
- case GNUNET_BLOCK_TYPE_ANY:
+ GNUNET_break_op (0);
+ return;
+ }
+ process_kblock (sc, data, size);
+ break;
+ case GNUNET_BLOCK_TYPE_FS_SBLOCK:
+ if (!GNUNET_FS_uri_test_sks (sc->uri))
+ {
GNUNET_break (0);
- break;
- case GNUNET_BLOCK_TYPE_FS_DBLOCK:
+ return;
+ }
+ if (sizeof (struct SBlock) > size)
+ {
+ GNUNET_break_op (0);
+ return;
+ }
+ process_sblock (sc, data, size);
+ break;
+ case GNUNET_BLOCK_TYPE_FS_NBLOCK:
+ if (!GNUNET_FS_uri_test_ksk (sc->uri))
+ {
GNUNET_break (0);
- break;
- case GNUNET_BLOCK_TYPE_FS_ONDEMAND:
- GNUNET_break (0);
- break;
- case GNUNET_BLOCK_TYPE_FS_IBLOCK:
- GNUNET_break (0);
- break;
- default:
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Got result with unknown block type `%d', ignoring"),
- type);
- break;
+ return;
}
+ if (sizeof (struct NBlock) > size)
+ {
+ GNUNET_break_op (0);
+ return;
+ }
+ process_nblock (sc, data, size);
+ break;
+ case GNUNET_BLOCK_TYPE_ANY:
+ GNUNET_break (0);
+ break;
+ case GNUNET_BLOCK_TYPE_FS_DBLOCK:
+ GNUNET_break (0);
+ break;
+ case GNUNET_BLOCK_TYPE_FS_ONDEMAND:
+ GNUNET_break (0);
+ break;
+ case GNUNET_BLOCK_TYPE_FS_IBLOCK:
+ GNUNET_break (0);
+ break;
+ default:
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Got result with unknown block type `%d', ignoring"), type);
+ break;
+ }
}
@@ -870,8 +823,7 @@
*
* @param sc the search to reconnec
*/
-static void
-try_reconnect (struct GNUNET_FS_SearchContext *sc);
+static void try_reconnect (struct GNUNET_FS_SearchContext *sc);
/**
@@ -881,36 +833,31 @@
* @param cls closure
* @param msg message received, NULL on timeout or fatal error
*/
-static void
-receive_results (void *cls,
- const struct GNUNET_MessageHeader * msg)
+static void
+receive_results (void *cls, const struct GNUNET_MessageHeader *msg)
{
struct GNUNET_FS_SearchContext *sc = cls;
const struct PutMessage *cm;
uint16_t msize;
- if ( (NULL == msg) ||
- (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_FS_PUT) ||
- (ntohs (msg->size) <= sizeof (struct PutMessage)) )
- {
- try_reconnect (sc);
- return;
- }
+ if ((NULL == msg) ||
+ (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_FS_PUT) ||
+ (ntohs (msg->size) <= sizeof (struct PutMessage)))
+ {
+ try_reconnect (sc);
+ return;
+ }
msize = ntohs (msg->size);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Receiving %u bytes of result from fs service\n",
- msize);
- cm = (const struct PutMessage*) msg;
- process_result (sc,
- ntohl (cm->type),
- GNUNET_TIME_absolute_ntoh (cm->expiration),
- &cm[1],
- msize - sizeof (struct PutMessage));
+ "Receiving %u bytes of result from fs service\n", msize);
+ cm = (const struct PutMessage *) msg;
+ process_result (sc,
+ ntohl (cm->type),
+ GNUNET_TIME_absolute_ntoh (cm->expiration),
+ &cm[1], msize - sizeof (struct PutMessage));
/* continue receiving */
GNUNET_CLIENT_receive (sc->client,
- &receive_results,
- sc,
- GNUNET_TIME_UNIT_FOREVER_REL);
+ &receive_results, sc, GNUNET_TIME_UNIT_FOREVER_REL);
}
@@ -967,22 +914,19 @@
* @return GNUNET_OK to continue iterating
*/
static int
-build_result_set (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+build_result_set (void *cls, const GNUNET_HashCode * key, void *value)
{
struct MessageBuilderContext *mbc = cls;
struct GNUNET_FS_SearchResult *sr = value;
-
- if ( (mbc->uri != NULL) &&
- (GNUNET_YES != GNUNET_FS_uri_test_equal (mbc->uri,
- sr->uri)) )
+
+ if ((mbc->uri != NULL) &&
+ (GNUNET_YES != GNUNET_FS_uri_test_equal (mbc->uri, sr->uri)))
return GNUNET_OK;
if (mbc->skip_cnt > 0)
- {
- mbc->skip_cnt--;
- return GNUNET_OK;
- }
+ {
+ mbc->skip_cnt--;
+ return GNUNET_OK;
+ }
if (mbc->put_cnt == 0)
return GNUNET_SYSERR;
mbc->sc->search_request_map_offset++;
@@ -1002,16 +946,13 @@
* @return GNUNET_OK to continue iterating
*/
static int
-find_result_set (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+find_result_set (void *cls, const GNUNET_HashCode * key, void *value)
{
struct MessageBuilderContext *mbc = cls;
struct GNUNET_FS_SearchResult *sr = value;
-
- if ( (mbc->uri != NULL) &&
- (GNUNET_YES != GNUNET_FS_uri_test_equal (mbc->uri,
- sr->uri)) )
+
+ if ((mbc->uri != NULL) &&
+ (GNUNET_YES != GNUNET_FS_uri_test_equal (mbc->uri, sr->uri)))
return GNUNET_OK;
mbc->put_cnt++;
return GNUNET_OK;
@@ -1028,9 +969,7 @@
* @return number of bytes written to buf
*/
static size_t
-transmit_search_request (void *cls,
- size_t size,
- void *buf)
+transmit_search_request (void *cls, size_t size, void *buf)
{
struct GNUNET_FS_SearchContext *sc = cls;
struct MessageBuilderContext mbc;
@@ -1042,105 +981,91 @@
unsigned int sqms;
if (NULL == buf)
- {
- try_reconnect (sc);
- return 0;
- }
+ {
+ try_reconnect (sc);
+ return 0;
+ }
mbc.sc = sc;
mbc.skip_cnt = sc->search_request_map_offset;
sm = buf;
sm->header.type = htons (GNUNET_MESSAGE_TYPE_FS_START_SEARCH);
- mbc.xoff = (GNUNET_HashCode* ) &sm[1];
+ mbc.xoff = (GNUNET_HashCode *) & sm[1];
if (GNUNET_FS_uri_test_ksk (sc->uri))
- {
- msize = sizeof (struct SearchMessage);
- GNUNET_assert (size >= msize);
- mbc.uri = NULL;
- mbc.put_cnt = 0;
- GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
- &find_result_set,
- &mbc);
- sqms = mbc.put_cnt;
- mbc.put_cnt = (size - msize) / sizeof (GNUNET_HashCode);
- mbc.put_cnt = GNUNET_MIN (mbc.put_cnt,
- sqms - mbc.skip_cnt);
- if (sc->search_request_map_offset < sqms)
- GNUNET_assert (mbc.put_cnt > 0);
+ {
+ msize = sizeof (struct SearchMessage);
+ GNUNET_assert (size >= msize);
+ mbc.uri = NULL;
+ mbc.put_cnt = 0;
+ GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
+ &find_result_set, &mbc);
+ sqms = mbc.put_cnt;
+ mbc.put_cnt = (size - msize) / sizeof (GNUNET_HashCode);
+ mbc.put_cnt = GNUNET_MIN (mbc.put_cnt, sqms - mbc.skip_cnt);
+ if (sc->search_request_map_offset < sqms)
+ GNUNET_assert (mbc.put_cnt > 0);
- sm->header.size = htons (msize);
- if (0 != (sc->options & GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY))
- sm->options = htonl (1);
- else
- sm->options = htonl (0);
- sm->type = htonl (GNUNET_BLOCK_TYPE_ANY);
- sm->anonymity_level = htonl (sc->anonymity);
- memset (&sm->target, 0, sizeof (GNUNET_HashCode));
- sm->query = sc->requests[sc->keyword_offset].query;
- msize += sizeof (GNUNET_HashCode) * mbc.put_cnt;
- GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
- &build_result_set,
- &mbc);
- sm->header.size = htons (msize);
- if (sqms != sc->search_request_map_offset)
- {
- /* more requesting to be done... */
- schedule_transmit_search_request (sc);
- return msize;
- }
- sc->keyword_offset++;
- if (sc->uri->data.ksk.keywordCount !=
- sc->keyword_offset)
- {
- /* more requesting to be done... */
- schedule_transmit_search_request (sc);
- return msize;
- }
+ sm->header.size = htons (msize);
+ if (0 != (sc->options & GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY))
+ sm->options = htonl (1);
+ else
+ sm->options = htonl (0);
+ sm->type = htonl (GNUNET_BLOCK_TYPE_ANY);
+ sm->anonymity_level = htonl (sc->anonymity);
+ memset (&sm->target, 0, sizeof (GNUNET_HashCode));
+ sm->query = sc->requests[sc->keyword_offset].query;
+ msize += sizeof (GNUNET_HashCode) * mbc.put_cnt;
+ GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
+ &build_result_set, &mbc);
+ sm->header.size = htons (msize);
+ if (sqms != sc->search_request_map_offset)
+ {
+ /* more requesting to be done... */
+ schedule_transmit_search_request (sc);
+ return msize;
}
+ sc->keyword_offset++;
+ if (sc->uri->data.ksk.keywordCount != sc->keyword_offset)
+ {
+ /* more requesting to be done... */
+ schedule_transmit_search_request (sc);
+ return msize;
+ }
+ }
else
+ {
+ GNUNET_assert (GNUNET_FS_uri_test_sks (sc->uri));
+ msize = sizeof (struct SearchMessage);
+ GNUNET_assert (size >= msize);
+ if (0 != (sc->options & GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY))
+ sm->options = htonl (1);
+ else
+ sm->options = htonl (0);
+ sm->type = htonl (GNUNET_BLOCK_TYPE_FS_SBLOCK);
+ sm->anonymity_level = htonl (sc->anonymity);
+ sm->target = sc->uri->data.sks.namespace;
+ identifier = sc->uri->data.sks.identifier;
+ GNUNET_CRYPTO_hash (identifier, strlen (identifier), &key);
+ GNUNET_CRYPTO_hash (&key, sizeof (GNUNET_HashCode), &idh);
+ GNUNET_CRYPTO_hash_xor (&idh, &sm->target, &sm->query);
+ mbc.put_cnt = (size - msize) / sizeof (GNUNET_HashCode);
+ sqms = GNUNET_CONTAINER_multihashmap_size (sc->master_result_map);
+ mbc.put_cnt = GNUNET_MIN (mbc.put_cnt, sqms - mbc.skip_cnt);
+ mbc.uri = NULL;
+ if (sc->search_request_map_offset < sqms)
+ GNUNET_assert (mbc.put_cnt > 0);
+ msize += sizeof (GNUNET_HashCode) * mbc.put_cnt;
+ GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
+ &build_result_set, &mbc);
+ sm->header.size = htons (msize);
+ if (sqms != sc->search_request_map_offset)
{
- GNUNET_assert (GNUNET_FS_uri_test_sks (sc->uri));
- msize = sizeof (struct SearchMessage);
- GNUNET_assert (size >= msize);
- if (0 != (sc->options & GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY))
- sm->options = htonl (1);
- else
- sm->options = htonl (0);
- sm->type = htonl (GNUNET_BLOCK_TYPE_FS_SBLOCK);
- sm->anonymity_level = htonl (sc->anonymity);
- sm->target = sc->uri->data.sks.namespace;
- identifier = sc->uri->data.sks.identifier;
- GNUNET_CRYPTO_hash (identifier,
- strlen (identifier),
- &key);
- GNUNET_CRYPTO_hash (&key,
- sizeof (GNUNET_HashCode),
- &idh);
- GNUNET_CRYPTO_hash_xor (&idh,
- &sm->target,
- &sm->query);
- mbc.put_cnt = (size - msize) / sizeof (GNUNET_HashCode);
- sqms = GNUNET_CONTAINER_multihashmap_size (sc->master_result_map);
- mbc.put_cnt = GNUNET_MIN (mbc.put_cnt,
- sqms - mbc.skip_cnt);
- mbc.uri = NULL;
- if (sc->search_request_map_offset < sqms)
- GNUNET_assert (mbc.put_cnt > 0);
- msize += sizeof (GNUNET_HashCode) * mbc.put_cnt;
- GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
- &build_result_set,
- &mbc);
- sm->header.size = htons (msize);
- if (sqms != sc->search_request_map_offset)
- {
- /* more requesting to be done... */
- schedule_transmit_search_request (sc);
- return msize;
- }
+ /* more requesting to be done... */
+ schedule_transmit_search_request (sc);
+ return msize;
}
+ }
GNUNET_CLIENT_receive (sc->client,
- &receive_results,
- sc,
- GNUNET_TIME_UNIT_FOREVER_REL);
+ &receive_results, sc, GNUNET_TIME_UNIT_FOREVER_REL);
return msize;
}
@@ -1159,16 +1084,16 @@
unsigned int fit;
size = sizeof (struct SearchMessage);
- sqms = GNUNET_CONTAINER_multihashmap_size (sc->master_result_map) -
sc->search_request_map_offset;
+ sqms =
+ GNUNET_CONTAINER_multihashmap_size (sc->master_result_map) -
+ sc->search_request_map_offset;
fit = (GNUNET_SERVER_MAX_MESSAGE_SIZE - 1 - size) / sizeof (GNUNET_HashCode);
fit = GNUNET_MIN (fit, sqms);
size += sizeof (GNUNET_HashCode) * fit;
GNUNET_CLIENT_notify_transmit_ready (sc->client,
- size,
+ size,
GNUNET_CONSTANTS_SERVICE_TIMEOUT,
- GNUNET_NO,
- &transmit_search_request,
- sc);
+ GNUNET_NO, &transmit_search_request,
sc);
}
@@ -1181,20 +1106,18 @@
* @param tc unused
*/
static void
-do_reconnect (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_FS_SearchContext *sc = cls;
struct GNUNET_CLIENT_Connection *client;
-
+
sc->task = GNUNET_SCHEDULER_NO_TASK;
- client = GNUNET_CLIENT_connect ("fs",
- sc->h->cfg);
+ client = GNUNET_CLIENT_connect ("fs", sc->h->cfg);
if (NULL == client)
- {
- try_reconnect (sc);
- return;
- }
+ {
+ try_reconnect (sc);
+ return;
+ }
sc->client = client;
sc->search_request_map_offset = 0;
sc->keyword_offset = 0;
@@ -1209,18 +1132,17 @@
*
* @param sc the search to reconnec
*/
-static void
+static void
try_reconnect (struct GNUNET_FS_SearchContext *sc)
{
if (NULL != sc->client)
- {
- GNUNET_CLIENT_disconnect (sc->client, GNUNET_NO);
- sc->client = NULL;
- }
+ {
+ GNUNET_CLIENT_disconnect (sc->client, GNUNET_NO);
+ sc->client = NULL;
+ }
sc->task
- = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
- &do_reconnect,
- sc);
+ = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &do_reconnect, sc);
}
@@ -1238,36 +1160,34 @@
*/
static struct GNUNET_FS_SearchContext *
search_start (struct GNUNET_FS_Handle *h,
- const struct GNUNET_FS_Uri *uri,
- uint32_t anonymity,
- enum GNUNET_FS_SearchOptions options,
- void *cctx,
- struct GNUNET_FS_SearchResult *psearch)
+ const struct GNUNET_FS_Uri *uri,
+ uint32_t anonymity,
+ enum GNUNET_FS_SearchOptions options,
+ void *cctx, struct GNUNET_FS_SearchResult *psearch)
{
struct GNUNET_FS_SearchContext *sc;
struct GNUNET_FS_ProgressInfo pi;
- sc = GNUNET_malloc (sizeof(struct GNUNET_FS_SearchContext));
+ sc = GNUNET_malloc (sizeof (struct GNUNET_FS_SearchContext));
sc->h = h;
sc->options = options;
sc->uri = GNUNET_FS_uri_dup (uri);
sc->anonymity = anonymity;
sc->start_time = GNUNET_TIME_absolute_get ();
if (psearch != NULL)
- {
- sc->psearch_result = psearch;
- psearch->update_search = sc;
- }
+ {
+ sc->psearch_result = psearch;
+ psearch->update_search = sc;
+ }
sc->master_result_map = GNUNET_CONTAINER_multihashmap_create (16);
sc->client_info = cctx;
- if (GNUNET_OK !=
- GNUNET_FS_search_start_searching_ (sc))
- {
- GNUNET_FS_uri_destroy (sc->uri);
- GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map);
- GNUNET_free (sc);
- return NULL;
- }
+ if (GNUNET_OK != GNUNET_FS_search_start_searching_ (sc))
+ {
+ GNUNET_FS_uri_destroy (sc->uri);
+ GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map);
+ GNUNET_free (sc);
+ return NULL;
+ }
GNUNET_FS_search_sync_ (sc);
pi.status = GNUNET_FS_STATUS_SEARCH_START;
sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc);
@@ -1288,39 +1208,35 @@
unsigned int i;
const char *keyword;
GNUNET_HashCode hc;
- struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub;
+ struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub;
struct GNUNET_CRYPTO_RsaPrivateKey *pk;
GNUNET_assert (NULL == sc->client);
if (GNUNET_FS_uri_test_ksk (sc->uri))
+ {
+ GNUNET_assert (0 != sc->uri->data.ksk.keywordCount);
+ sc->requests = GNUNET_malloc (sizeof (struct SearchRequestEntry) *
+ sc->uri->data.ksk.keywordCount);
+ for (i = 0; i < sc->uri->data.ksk.keywordCount; i++)
{
- GNUNET_assert (0 != sc->uri->data.ksk.keywordCount);
- sc->requests = GNUNET_malloc (sizeof (struct SearchRequestEntry) *
- sc->uri->data.ksk.keywordCount);
- for (i=0;i<sc->uri->data.ksk.keywordCount;i++)
- {
- keyword = &sc->uri->data.ksk.keywords[i][1];
- GNUNET_CRYPTO_hash (keyword,
- strlen (keyword),
- &hc);
- pk = GNUNET_CRYPTO_rsa_key_create_from_hash (&hc);
- GNUNET_assert (pk != NULL);
- GNUNET_CRYPTO_rsa_key_get_public (pk, &pub);
- GNUNET_CRYPTO_rsa_key_free (pk);
- GNUNET_CRYPTO_hash (&pub,
- sizeof (struct
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
- &sc->requests[i].query);
- sc->requests[i].mandatory = (sc->uri->data.ksk.keywords[i][0] == '+');
- if (sc->requests[i].mandatory)
- sc->mandatory_count++;
- sc->requests[i].results = GNUNET_CONTAINER_multihashmap_create (4);
- GNUNET_CRYPTO_hash (keyword,
- strlen (keyword),
- &sc->requests[i].key);
- }
+ keyword = &sc->uri->data.ksk.keywords[i][1];
+ GNUNET_CRYPTO_hash (keyword, strlen (keyword), &hc);
+ pk = GNUNET_CRYPTO_rsa_key_create_from_hash (&hc);
+ GNUNET_assert (pk != NULL);
+ GNUNET_CRYPTO_rsa_key_get_public (pk, &pub);
+ GNUNET_CRYPTO_rsa_key_free (pk);
+ GNUNET_CRYPTO_hash (&pub,
+ sizeof (struct
+ GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+ &sc->requests[i].query);
+ sc->requests[i].mandatory = (sc->uri->data.ksk.keywords[i][0] == '+');
+ if (sc->requests[i].mandatory)
+ sc->mandatory_count++;
+ sc->requests[i].results = GNUNET_CONTAINER_multihashmap_create (4);
+ GNUNET_CRYPTO_hash (keyword, strlen (keyword), &sc->requests[i].key);
}
- sc->client = GNUNET_CLIENT_connect ("fs",
- sc->h->cfg);
+ }
+ sc->client = GNUNET_CLIENT_connect ("fs", sc->h->cfg);
if (NULL == sc->client)
return GNUNET_SYSERR;
schedule_transmit_search_request (sc);
@@ -1338,21 +1254,20 @@
*/
static int
search_result_freeze_probes (void *cls,
- const GNUNET_HashCode * key,
- void *value)
+ const GNUNET_HashCode * key, void *value)
{
struct GNUNET_FS_SearchResult *sr = value;
if (sr->probe_ctx != NULL)
- {
- GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES);
- sr->probe_ctx = NULL;
- }
+ {
+ GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES);
+ sr->probe_ctx = NULL;
+ }
if (sr->probe_cancel_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (sr->probe_cancel_task);
- sr->probe_cancel_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (sr->probe_cancel_task);
+ sr->probe_cancel_task = GNUNET_SCHEDULER_NO_TASK;
+ }
if (sr->update_search != NULL)
GNUNET_FS_search_pause (sr->update_search);
return GNUNET_OK;
@@ -1369,8 +1284,7 @@
*/
static int
search_result_resume_probes (void *cls,
- const GNUNET_HashCode * key,
- void *value)
+ const GNUNET_HashCode * key, void *value)
{
struct GNUNET_FS_SearchResult *sr = value;
@@ -1390,9 +1304,7 @@
* @return GNUNET_OK
*/
static int
-search_result_suspend (void *cls,
- const GNUNET_HashCode * key,
- void *value)
+search_result_suspend (void *cls, const GNUNET_HashCode * key, void *value)
{
struct GNUNET_FS_SearchContext *sc = cls;
struct GNUNET_FS_SearchResult *sr = value;
@@ -1412,7 +1324,7 @@
GNUNET_FS_uri_destroy (sr->uri);
GNUNET_CONTAINER_meta_data_destroy (sr->meta);
if (sr->probe_ctx != NULL)
- GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES);
+ GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES);
if (sr->probe_cancel_task != GNUNET_SCHEDULER_NO_TASK)
GNUNET_SCHEDULER_cancel (sr->probe_cancel_task);
GNUNET_free (sr);
@@ -1435,8 +1347,7 @@
GNUNET_FS_end_top (sc->h, sc->top);
GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
- &search_result_suspend,
- sc);
+ &search_result_suspend, sc);
pi.status = GNUNET_FS_STATUS_SEARCH_SUSPEND;
sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc);
GNUNET_break (NULL == sc->client_info);
@@ -1446,11 +1357,11 @@
GNUNET_CLIENT_disconnect (sc->client, GNUNET_NO);
GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map);
if (sc->requests != NULL)
- {
- GNUNET_assert (GNUNET_FS_uri_test_ksk (sc->uri));
- for (i=0;i<sc->uri->data.ksk.keywordCount;i++)
- GNUNET_CONTAINER_multihashmap_destroy (sc->requests[i].results);
- }
+ {
+ GNUNET_assert (GNUNET_FS_uri_test_ksk (sc->uri));
+ for (i = 0; i < sc->uri->data.ksk.keywordCount; i++)
+ GNUNET_CONTAINER_multihashmap_destroy (sc->requests[i].results);
+ }
GNUNET_free_non_null (sc->requests);
GNUNET_free_non_null (sc->emsg);
GNUNET_FS_uri_destroy (sc->uri);
@@ -1472,12 +1383,12 @@
*/
struct GNUNET_FS_SearchContext *
GNUNET_FS_search_start (struct GNUNET_FS_Handle *h,
- const struct GNUNET_FS_Uri *uri,
- uint32_t anonymity,
- enum GNUNET_FS_SearchOptions options,
- void *cctx)
+ const struct GNUNET_FS_Uri *uri,
+ uint32_t anonymity,
+ enum GNUNET_FS_SearchOptions options, void *cctx)
{
struct GNUNET_FS_SearchContext *ret;
+
ret = search_start (h, uri, anonymity, options, cctx, NULL);
if (ret == NULL)
return NULL;
@@ -1491,7 +1402,7 @@
*
* @param sc context for the search that should be paused
*/
-void
+void
GNUNET_FS_search_pause (struct GNUNET_FS_SearchContext *sc)
{
struct GNUNET_FS_ProgressInfo pi;
@@ -1504,8 +1415,7 @@
sc->client = NULL;
GNUNET_FS_search_sync_ (sc);
GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
- &search_result_freeze_probes,
- sc);
+ &search_result_freeze_probes, sc);
pi.status = GNUNET_FS_STATUS_SEARCH_PAUSED;
sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc);
}
@@ -1516,7 +1426,7 @@
*
* @param sc context for the search that should be resumed
*/
-void
+void
GNUNET_FS_search_continue (struct GNUNET_FS_SearchContext *sc)
{
struct GNUNET_FS_ProgressInfo pi;
@@ -1528,8 +1438,7 @@
pi.status = GNUNET_FS_STATUS_SEARCH_CONTINUED;
sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc);
GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
- &search_result_resume_probes,
- sc);
+ &search_result_resume_probes, sc);
}
@@ -1542,39 +1451,36 @@
* @return GNUNET_OK
*/
static int
-search_result_free (void *cls,
- const GNUNET_HashCode * key,
- void *value)
+search_result_free (void *cls, const GNUNET_HashCode * key, void *value)
{
struct GNUNET_FS_SearchContext *sc = cls;
struct GNUNET_FS_SearchResult *sr = value;
struct GNUNET_FS_ProgressInfo pi;
if (NULL != sr->download)
+ {
+ sr->download->search = NULL;
+ sr->download->top = GNUNET_FS_make_top (sr->download->h,
+
&GNUNET_FS_download_signal_suspend_,
+ sr->download);
+ if (NULL != sr->download->serialization)
{
- sr->download->search = NULL;
- sr->download->top = GNUNET_FS_make_top (sr->download->h,
-
&GNUNET_FS_download_signal_suspend_,
- sr->download);
- if (NULL != sr->download->serialization)
- {
- GNUNET_FS_remove_sync_file_ (sc->h,
- GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD,
- sr->download->serialization);
- GNUNET_free (sr->download->serialization);
- sr->download->serialization = NULL;
- }
- pi.status = GNUNET_FS_STATUS_DOWNLOAD_LOST_PARENT;
- GNUNET_FS_download_make_status_ (&pi,
- sr->download);
- GNUNET_FS_download_sync_ (sr->download);
- sr->download = NULL;
+ GNUNET_FS_remove_sync_file_ (sc->h,
+ GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD,
+ sr->download->serialization);
+ GNUNET_free (sr->download->serialization);
+ sr->download->serialization = NULL;
}
+ pi.status = GNUNET_FS_STATUS_DOWNLOAD_LOST_PARENT;
+ GNUNET_FS_download_make_status_ (&pi, sr->download);
+ GNUNET_FS_download_sync_ (sr->download);
+ sr->download = NULL;
+ }
if (NULL != sr->update_search)
- {
- GNUNET_FS_search_stop (sr->update_search);
- GNUNET_assert (sr->update_search == NULL);
- }
+ {
+ GNUNET_FS_search_stop (sr->update_search);
+ GNUNET_assert (sr->update_search == NULL);
+ }
pi.status = GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED;
pi.value.search.specifics.result_stopped.cctx = sr->client_info;
pi.value.search.specifics.result_stopped.meta = sr->meta;
@@ -1585,7 +1491,7 @@
GNUNET_FS_uri_destroy (sr->uri);
GNUNET_CONTAINER_meta_data_destroy (sr->meta);
if (sr->probe_ctx != NULL)
- GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES);
+ GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES);
if (sr->probe_cancel_task != GNUNET_SCHEDULER_NO_TASK)
GNUNET_SCHEDULER_cancel (sr->probe_cancel_task);
GNUNET_free (sr);
@@ -1598,7 +1504,7 @@
*
* @param sc context for the search that should be stopped
*/
-void
+void
GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc)
{
struct GNUNET_FS_ProgressInfo pi;
@@ -1609,22 +1515,21 @@
if (sc->psearch_result != NULL)
sc->psearch_result->update_search = NULL;
GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
- &search_result_free,
- sc);
+ &search_result_free, sc);
if (sc->serialization != NULL)
- {
- GNUNET_FS_remove_sync_file_ (sc->h,
- (sc->psearch_result != NULL)
- ? GNUNET_FS_SYNC_PATH_CHILD_SEARCH
- : GNUNET_FS_SYNC_PATH_MASTER_SEARCH,
- sc->serialization);
- GNUNET_FS_remove_sync_dir_ (sc->h,
- (sc->psearch_result != NULL)
- ? GNUNET_FS_SYNC_PATH_CHILD_SEARCH
- : GNUNET_FS_SYNC_PATH_MASTER_SEARCH,
- sc->serialization);
- GNUNET_free (sc->serialization);
- }
+ {
+ GNUNET_FS_remove_sync_file_ (sc->h,
+ (sc->psearch_result != NULL)
+ ? GNUNET_FS_SYNC_PATH_CHILD_SEARCH
+ : GNUNET_FS_SYNC_PATH_MASTER_SEARCH,
+ sc->serialization);
+ GNUNET_FS_remove_sync_dir_ (sc->h,
+ (sc->psearch_result != NULL)
+ ? GNUNET_FS_SYNC_PATH_CHILD_SEARCH
+ : GNUNET_FS_SYNC_PATH_MASTER_SEARCH,
+ sc->serialization);
+ GNUNET_free (sc->serialization);
+ }
pi.status = GNUNET_FS_STATUS_SEARCH_STOPPED;
sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc);
GNUNET_break (NULL == sc->client_info);
@@ -1634,11 +1539,11 @@
GNUNET_CLIENT_disconnect (sc->client, GNUNET_NO);
GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map);
if (sc->requests != NULL)
- {
- GNUNET_assert (GNUNET_FS_uri_test_ksk (sc->uri));
- for (i=0;i<sc->uri->data.ksk.keywordCount;i++)
- GNUNET_CONTAINER_multihashmap_destroy (sc->requests[i].results);
- }
+ {
+ GNUNET_assert (GNUNET_FS_uri_test_ksk (sc->uri));
+ for (i = 0; i < sc->uri->data.ksk.keywordCount; i++)
+ GNUNET_CONTAINER_multihashmap_destroy (sc->requests[i].results);
+ }
GNUNET_free_non_null (sc->requests);
GNUNET_free_non_null (sc->emsg);
GNUNET_FS_uri_destroy (sc->uri);
Modified: gnunet/src/fs/fs_test_lib.c
===================================================================
--- gnunet/src/fs/fs_test_lib.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/fs/fs_test_lib.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -77,7 +77,7 @@
* Function to call when upload is done.
*/
GNUNET_FS_TEST_UriContinuation publish_cont;
-
+
/**
* Closure for publish_cont.
*/
@@ -105,7 +105,7 @@
/**
* Name of the temporary file used, or NULL for none.
- */
+ */
char *publish_tmp_file;
/**
@@ -130,7 +130,7 @@
/**
* Context for current download operation.
- */
+ */
struct GNUNET_FS_DownloadContext *download_context;
/**
@@ -138,39 +138,35 @@
*/
int verbose;
-
+
};
/**
* Check whether peers successfully shut down.
*/
-static void
-shutdown_callback (void *cls,
- const char *emsg)
+static void
+shutdown_callback (void *cls, const char *emsg)
{
struct GNUNET_CONFIGURATION_Handle *gcfg = cls;
if (emsg != NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Shutdown of peers failed: %s\n",
- emsg);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Shutdown of peers failed: %s\n", emsg);
+ }
else
- {
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "All peers successfully shut down!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers successfully shut
down!\n");
#endif
- }
+ }
if (gcfg != NULL)
GNUNET_CONFIGURATION_destroy (gcfg);
}
static void
-report_uri (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+report_uri (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_FS_TestDaemon *daemon = cls;
GNUNET_FS_TEST_UriContinuation cont;
@@ -181,73 +177,70 @@
cont = daemon->publish_cont;
daemon->publish_cont = NULL;
uri = daemon->publish_uri;
- cont (daemon->publish_cont_cls,
- uri);
+ cont (daemon->publish_cont_cls, uri);
GNUNET_FS_uri_destroy (uri);
-}
+}
static void
-report_success (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+report_success (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_FS_TestDaemon *daemon = cls;
GNUNET_FS_download_stop (daemon->download_context, GNUNET_YES);
daemon->download_context = NULL;
GNUNET_SCHEDULER_add_continuation (daemon->download_cont,
- daemon->download_cont_cls,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ daemon->download_cont_cls,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
daemon->download_cont = NULL;
}
-static void*
-progress_cb (void *cls,
- const struct GNUNET_FS_ProgressInfo *info)
+static void *
+progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
{
struct GNUNET_FS_TestDaemon *daemon = cls;
switch (info->status)
- {
- case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
- GNUNET_SCHEDULER_cancel (daemon->publish_timeout_task);
- daemon->publish_timeout_task = GNUNET_SCHEDULER_NO_TASK;
- daemon->publish_uri = GNUNET_FS_uri_dup
(info->value.publish.specifics.completed.chk_uri);
- GNUNET_SCHEDULER_add_continuation (&report_uri,
- daemon,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- break;
- case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
- if (daemon->verbose)
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Publishing at %llu/%llu bytes\n",
- (unsigned long long) info->value.publish.completed,
- (unsigned long long) info->value.publish.size);
- break;
- case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS:
- if (daemon->verbose)
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Download at %llu/%llu bytes\n",
- (unsigned long long) info->value.download.completed,
- (unsigned long long) info->value.download.size);
- break;
- case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
- GNUNET_SCHEDULER_cancel (daemon->download_timeout_task);
- daemon->download_timeout_task = GNUNET_SCHEDULER_NO_TASK;
- GNUNET_SCHEDULER_add_continuation (&report_success,
- daemon,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- break;
- case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE:
- case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE:
- break;
- /* FIXME: monitor data correctness during download progress */
- /* FIXME: do performance reports given sufficient verbosity */
- /* FIXME: advance timeout task to "immediate" on error */
- default:
- break;
- }
+ {
+ case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
+ GNUNET_SCHEDULER_cancel (daemon->publish_timeout_task);
+ daemon->publish_timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ daemon->publish_uri =
+ GNUNET_FS_uri_dup (info->value.publish.specifics.completed.chk_uri);
+ GNUNET_SCHEDULER_add_continuation (&report_uri, daemon,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
+ if (daemon->verbose)
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Publishing at %llu/%llu bytes\n",
+ (unsigned long long) info->value.publish.completed,
+ (unsigned long long) info->value.publish.size);
+ break;
+ case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS:
+ if (daemon->verbose)
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Download at %llu/%llu bytes\n",
+ (unsigned long long) info->value.download.completed,
+ (unsigned long long) info->value.download.size);
+ break;
+ case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
+ GNUNET_SCHEDULER_cancel (daemon->download_timeout_task);
+ daemon->download_timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ GNUNET_SCHEDULER_add_continuation (&report_success,
+ daemon,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ break;
+ case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE:
+ case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE:
+ break;
+ /* FIXME: monitor data correctness during download progress */
+ /* FIXME: do performance reports given sufficient verbosity */
+ /* FIXME: advance timeout task to "immediate" on error */
+ default:
+ break;
+ }
return NULL;
}
@@ -266,31 +259,28 @@
};
-static void
+static void
notify_running (void *cls,
- const struct GNUNET_PeerIdentity *id,
- const struct GNUNET_CONFIGURATION_Handle *cfg,
- struct GNUNET_TESTING_Daemon *d,
- const char *emsg)
+ const struct GNUNET_PeerIdentity *id,
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ struct GNUNET_TESTING_Daemon *d, const char *emsg)
{
struct StartContext *sctx = cls;
unsigned int i;
if (emsg != NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to start daemon: %s\n"),
- emsg);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to start daemon: %s\n"), emsg);
+ return;
+ }
i = 0;
while (i < sctx->total)
- {
- if (GNUNET_TESTING_daemon_get (sctx->group,
- i) == d)
- break;
- i++;
- }
+ {
+ if (GNUNET_TESTING_daemon_get (sctx->group, i) == d)
+ break;
+ i++;
+ }
GNUNET_assert (i < sctx->total);
GNUNET_assert (sctx->have < sctx->total);
GNUNET_assert (sctx->daemons[i]->cfg == NULL);
@@ -300,50 +290,49 @@
sctx->daemons[i]->id = *id;
sctx->have++;
if (sctx->have == sctx->total)
+ {
+ GNUNET_SCHEDULER_add_continuation (sctx->cont,
+ sctx->cont_cls,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ sctx->daemons[0]->gcfg = sctx->cfg;
+ GNUNET_SCHEDULER_cancel (sctx->timeout_task);
+ for (i = 0; i < sctx->total; i++)
{
- GNUNET_SCHEDULER_add_continuation (sctx->cont,
- sctx->cont_cls,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- sctx->daemons[0]->gcfg = sctx->cfg;
- GNUNET_SCHEDULER_cancel (sctx->timeout_task);
- for (i=0;i<sctx->total;i++)
- {
- sctx->daemons[i]->fs = GNUNET_FS_start (sctx->daemons[i]->cfg,
- "<tester>",
- &progress_cb,
- sctx->daemons[i],
- GNUNET_FS_FLAGS_NONE,
- GNUNET_FS_OPTIONS_END);
- }
- GNUNET_free (sctx);
+ sctx->daemons[i]->fs = GNUNET_FS_start (sctx->daemons[i]->cfg,
+ "<tester>",
+ &progress_cb,
+ sctx->daemons[i],
+ GNUNET_FS_FLAGS_NONE,
+ GNUNET_FS_OPTIONS_END);
}
+ GNUNET_free (sctx);
+ }
}
static void
-start_timeout (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+start_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct StartContext *sctx = cls;
unsigned int i;
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Timeout while trying to start daemons\n");
+ "Timeout while trying to start daemons\n");
GNUNET_TESTING_daemons_stop (sctx->group,
-
GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30),
- &shutdown_callback,
- NULL);
- for (i=0;i<sctx->total;i++)
- {
- if (i < sctx->have)
- GNUNET_CONFIGURATION_destroy (sctx->daemons[i]->cfg);
- GNUNET_free (sctx->daemons[i]);
- sctx->daemons[i] = NULL;
- }
+ GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 30),
+ &shutdown_callback, NULL);
+ for (i = 0; i < sctx->total; i++)
+ {
+ if (i < sctx->have)
+ GNUNET_CONFIGURATION_destroy (sctx->daemons[i]->cfg);
+ GNUNET_free (sctx->daemons[i]);
+ sctx->daemons[i] = NULL;
+ }
GNUNET_CONFIGURATION_destroy (sctx->cfg);
GNUNET_SCHEDULER_add_continuation (sctx->cont,
- sctx->cont_cls,
- GNUNET_SCHEDULER_REASON_TIMEOUT);
+ sctx->cont_cls,
+ GNUNET_SCHEDULER_REASON_TIMEOUT);
GNUNET_free (sctx);
}
@@ -362,11 +351,10 @@
*/
void
GNUNET_FS_TEST_daemons_start (const char *template_cfg_file,
- struct GNUNET_TIME_Relative timeout,
- unsigned int total,
- struct GNUNET_FS_TestDaemon **daemons,
- GNUNET_SCHEDULER_Task cont,
- void *cont_cls)
+ struct GNUNET_TIME_Relative timeout,
+ unsigned int total,
+ struct GNUNET_FS_TestDaemon **daemons,
+ GNUNET_SCHEDULER_Task cont, void *cont_cls)
{
struct StartContext *sctx;
unsigned int i;
@@ -378,34 +366,27 @@
sctx->cont = cont;
sctx->cont_cls = cont_cls;
sctx->cfg = GNUNET_CONFIGURATION_create ();
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_load (sctx->cfg,
- template_cfg_file))
- {
- GNUNET_break (0);
- GNUNET_CONFIGURATION_destroy (sctx->cfg);
- GNUNET_free (sctx);
- GNUNET_SCHEDULER_add_continuation (cont,
- cont_cls,
- GNUNET_SCHEDULER_REASON_TIMEOUT);
- return;
- }
- for (i=0;i<total;i++)
+ if (GNUNET_OK != GNUNET_CONFIGURATION_load (sctx->cfg, template_cfg_file))
+ {
+ GNUNET_break (0);
+ GNUNET_CONFIGURATION_destroy (sctx->cfg);
+ GNUNET_free (sctx);
+ GNUNET_SCHEDULER_add_continuation (cont,
+ cont_cls,
+ GNUNET_SCHEDULER_REASON_TIMEOUT);
+ return;
+ }
+ for (i = 0; i < total; i++)
daemons[i] = GNUNET_malloc (sizeof (struct GNUNET_FS_TestDaemon));
- sctx->group = GNUNET_TESTING_daemons_start (sctx->cfg,
- total,
- total, /* Outstanding connections
*/
- total, /* Outstanding ssh
connections */
- timeout,
- NULL,
- NULL,
- ¬ify_running,
- sctx,
- NULL, NULL,
- NULL);
+ sctx->group = GNUNET_TESTING_daemons_start (sctx->cfg, total, total, /*
Outstanding connections */
+ total, /* Outstanding ssh
connections */
+ timeout,
+ NULL,
+ NULL,
+ ¬ify_running,
+ sctx, NULL, NULL, NULL);
sctx->timeout_task = GNUNET_SCHEDULER_add_delayed (timeout,
- &start_timeout,
- sctx);
+ &start_timeout, sctx);
}
@@ -432,26 +413,25 @@
*/
static void
notify_connection (void *cls,
- const struct GNUNET_PeerIdentity *first,
- const struct GNUNET_PeerIdentity *second,
- uint32_t distance,
- const struct GNUNET_CONFIGURATION_Handle *first_cfg,
- const struct GNUNET_CONFIGURATION_Handle *second_cfg,
- struct GNUNET_TESTING_Daemon *first_daemon,
- struct GNUNET_TESTING_Daemon *second_daemon,
- const char *emsg)
+ const struct GNUNET_PeerIdentity *first,
+ const struct GNUNET_PeerIdentity *second,
+ uint32_t distance,
+ const struct GNUNET_CONFIGURATION_Handle *first_cfg,
+ const struct GNUNET_CONFIGURATION_Handle *second_cfg,
+ struct GNUNET_TESTING_Daemon *first_daemon,
+ struct GNUNET_TESTING_Daemon *second_daemon,
+ const char *emsg)
{
struct ConnectContext *cc = cls;
-
+
if (emsg != NULL)
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Failed to connect peers: %s\n",
- emsg);
+ "Failed to connect peers: %s\n", emsg);
GNUNET_SCHEDULER_add_continuation (cc->cont,
- cc->cont_cls,
- (emsg != NULL)
- ? GNUNET_SCHEDULER_REASON_TIMEOUT
- : GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ cc->cont_cls,
+ (emsg != NULL)
+ ? GNUNET_SCHEDULER_REASON_TIMEOUT
+ : GNUNET_SCHEDULER_REASON_PREREQ_DONE);
GNUNET_free (cc);
}
@@ -468,10 +448,9 @@
*/
void
GNUNET_FS_TEST_daemons_connect (struct GNUNET_FS_TestDaemon *daemon1,
- struct GNUNET_FS_TestDaemon *daemon2,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_SCHEDULER_Task cont,
- void *cont_cls)
+ struct GNUNET_FS_TestDaemon *daemon2,
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_SCHEDULER_Task cont, void *cont_cls)
{
struct ConnectContext *ncc;
@@ -479,12 +458,10 @@
ncc->cont = cont;
ncc->cont_cls = cont_cls;
GNUNET_TESTING_daemons_connect (daemon1->daemon,
- daemon2->daemon,
- timeout,
- CONNECT_ATTEMPTS,
- GNUNET_YES,
- ¬ify_connection,
- ncc);
+ daemon2->daemon,
+ timeout,
+ CONNECT_ATTEMPTS,
+ GNUNET_YES, ¬ify_connection, ncc);
}
@@ -497,9 +474,9 @@
*/
const struct GNUNET_CONFIGURATION_Handle *
GNUNET_FS_TEST_get_configuration (struct GNUNET_FS_TestDaemon **daemons,
- unsigned int off)
+ unsigned int off)
{
- return daemons[off]->cfg;
+ return daemons[off]->cfg;
}
/**
@@ -511,7 +488,7 @@
struct GNUNET_TESTING_PeerGroup *
GNUNET_FS_TEST_get_group (struct GNUNET_FS_TestDaemon **daemons)
{
- return daemons[0]->group;
+ return daemons[0]->group;
}
@@ -523,7 +500,7 @@
*/
void
GNUNET_FS_TEST_daemons_stop (unsigned int total,
- struct GNUNET_FS_TestDaemon **daemons)
+ struct GNUNET_FS_TestDaemon **daemons)
{
unsigned int i;
struct GNUNET_TESTING_PeerGroup *pg;
@@ -534,70 +511,64 @@
GNUNET_assert (daemons[0] != NULL);
pg = daemons[0]->group;
gcfg = daemons[0]->gcfg;
- for (i=0;i<total;i++)
+ for (i = 0; i < total; i++)
+ {
+ daemon = daemons[i];
+ if (daemon->download_timeout_task != GNUNET_SCHEDULER_NO_TASK)
{
- daemon = daemons[i];
- if (daemon->download_timeout_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (daemon->download_timeout_task);
- daemon->download_timeout_task = GNUNET_SCHEDULER_NO_TASK;
- }
- if (daemon->publish_timeout_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (daemon->publish_timeout_task);
- daemon->publish_timeout_task = GNUNET_SCHEDULER_NO_TASK;
- }
- if (NULL != daemon->download_context)
- {
- GNUNET_FS_download_stop (daemon->download_context, GNUNET_YES);
- daemon->download_context = NULL;
- }
- if (daemon->fs != NULL)
- GNUNET_FS_stop (daemon->fs);
- if (daemon->cfg != NULL)
- GNUNET_CONFIGURATION_destroy (daemon->cfg);
- if (NULL != daemon->publish_tmp_file)
- {
- GNUNET_break (GNUNET_OK ==
- GNUNET_DISK_directory_remove
(daemon->publish_tmp_file));
- GNUNET_free (daemon->publish_tmp_file);
- daemon->publish_tmp_file = NULL;
- }
- GNUNET_free (daemon);
- daemons[i] = NULL;
- }
- GNUNET_TESTING_daemons_stop (pg,
-
GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30),
- &shutdown_callback,
- gcfg);
+ GNUNET_SCHEDULER_cancel (daemon->download_timeout_task);
+ daemon->download_timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ if (daemon->publish_timeout_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (daemon->publish_timeout_task);
+ daemon->publish_timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ if (NULL != daemon->download_context)
+ {
+ GNUNET_FS_download_stop (daemon->download_context, GNUNET_YES);
+ daemon->download_context = NULL;
+ }
+ if (daemon->fs != NULL)
+ GNUNET_FS_stop (daemon->fs);
+ if (daemon->cfg != NULL)
+ GNUNET_CONFIGURATION_destroy (daemon->cfg);
+ if (NULL != daemon->publish_tmp_file)
+ {
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_DISK_directory_remove (daemon->publish_tmp_file));
+ GNUNET_free (daemon->publish_tmp_file);
+ daemon->publish_tmp_file = NULL;
+ }
+ GNUNET_free (daemon);
+ daemons[i] = NULL;
+ }
+ GNUNET_TESTING_daemons_stop (pg,
+ GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 30),
+ &shutdown_callback, gcfg);
}
static void
-publish_timeout (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+publish_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_FS_TestDaemon *daemon = cls;
GNUNET_FS_TEST_UriContinuation cont;
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Timeout while trying to publish data\n");
+ "Timeout while trying to publish data\n");
cont = daemon->publish_cont;
daemon->publish_timeout_task = GNUNET_SCHEDULER_NO_TASK;
daemon->publish_cont = NULL;
GNUNET_FS_publish_stop (daemon->publish_context);
daemon->publish_context = NULL;
- cont (daemon->publish_cont_cls,
- NULL);
+ cont (daemon->publish_cont_cls, NULL);
}
static size_t
-file_generator (void *cls,
- uint64_t offset,
- size_t max,
- void *buf,
- char **emsg)
+file_generator (void *cls, uint64_t offset, size_t max, void *buf, char **emsg)
{
struct GNUNET_FS_TestDaemon *daemon = cls;
uint64_t pos;
@@ -608,15 +579,15 @@
*emsg = NULL;
if (buf == NULL)
return 0;
- for (pos=0;pos<8;pos++)
- cbuf[pos] = (uint8_t) (offset >> pos*8);
- for (pos=8;pos<max;pos++)
- {
- mod = (255 - (offset / 1024 / 32));
- if (mod == 0)
- mod = 1;
- cbuf[pos] = (uint8_t) ((offset * daemon->publish_seed) % mod);
- }
+ for (pos = 0; pos < 8; pos++)
+ cbuf[pos] = (uint8_t) (offset >> pos * 8);
+ for (pos = 8; pos < max; pos++)
+ {
+ mod = (255 - (offset / 1024 / 32));
+ if (mod == 0)
+ mod = 1;
+ cbuf[pos] = (uint8_t) ((offset * daemon->publish_seed) % mod);
+ }
return max;
}
@@ -639,14 +610,13 @@
*/
void
GNUNET_FS_TEST_publish (struct GNUNET_FS_TestDaemon *daemon,
- struct GNUNET_TIME_Relative timeout,
- uint32_t anonymity,
- int do_index,
- uint64_t size,
- uint32_t seed,
- unsigned int verbose,
- GNUNET_FS_TEST_UriContinuation cont,
- void *cont_cls)
+ struct GNUNET_TIME_Relative timeout,
+ uint32_t anonymity,
+ int do_index,
+ uint64_t size,
+ uint32_t seed,
+ unsigned int verbose,
+ GNUNET_FS_TEST_UriContinuation cont, void *cont_cls)
{
struct GNUNET_FS_FileInformation *fi;
struct GNUNET_DISK_FileHandle *fh;
@@ -655,7 +625,7 @@
char buf[DBLOCK_SIZE];
size_t bsize;
struct GNUNET_FS_BlockOptions bo;
-
+
GNUNET_assert (daemon->publish_cont == NULL);
daemon->publish_cont = cont;
daemon->publish_cont_cls = cont_cls;
@@ -666,78 +636,66 @@
bo.content_priority = 42;
bo.replication_level = 1;
if (GNUNET_YES == do_index)
+ {
+ GNUNET_assert (daemon->publish_tmp_file == NULL);
+ daemon->publish_tmp_file = GNUNET_DISK_mktemp ("fs-test-publish-index");
+ GNUNET_assert (daemon->publish_tmp_file != NULL);
+ fh = GNUNET_DISK_file_open (daemon->publish_tmp_file,
+ GNUNET_DISK_OPEN_WRITE |
+ GNUNET_DISK_OPEN_CREATE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE);
+ GNUNET_assert (NULL != fh);
+ off = 0;
+ while (off < size)
{
- GNUNET_assert (daemon->publish_tmp_file == NULL);
- daemon->publish_tmp_file = GNUNET_DISK_mktemp ("fs-test-publish-index");
- GNUNET_assert (daemon->publish_tmp_file != NULL);
- fh = GNUNET_DISK_file_open (daemon->publish_tmp_file,
- GNUNET_DISK_OPEN_WRITE |
GNUNET_DISK_OPEN_CREATE,
- GNUNET_DISK_PERM_USER_READ |
GNUNET_DISK_PERM_USER_WRITE);
- GNUNET_assert (NULL != fh);
- off = 0;
- while (off < size)
- {
- bsize = GNUNET_MIN (sizeof (buf),
- size - off);
- emsg = NULL;
- GNUNET_assert (bsize ==
- file_generator (daemon,
- off,
- bsize,
- buf,
- &emsg));
- GNUNET_assert (emsg == NULL);
- GNUNET_assert (bsize ==
- GNUNET_DISK_file_write (fh,
- buf,
- bsize));
- off += bsize;
- }
- GNUNET_assert (GNUNET_OK ==
- GNUNET_DISK_file_close (fh));
- fi = GNUNET_FS_file_information_create_from_file (daemon->fs,
- daemon,
-
daemon->publish_tmp_file,
- NULL, NULL,
- do_index,
- &bo);
+ bsize = GNUNET_MIN (sizeof (buf), size - off);
+ emsg = NULL;
+ GNUNET_assert (bsize == file_generator (daemon, off, bsize, buf, &emsg));
+ GNUNET_assert (emsg == NULL);
+ GNUNET_assert (bsize == GNUNET_DISK_file_write (fh, buf, bsize));
+ off += bsize;
}
+ GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh));
+ fi = GNUNET_FS_file_information_create_from_file (daemon->fs,
+ daemon,
+ daemon->publish_tmp_file,
+ NULL, NULL,
+ do_index, &bo);
+ }
else
- {
- fi = GNUNET_FS_file_information_create_from_reader (daemon->fs,
- daemon,
- size,
- &file_generator,
- daemon,
- NULL,
- NULL,
- do_index,
- &bo);
- }
+ {
+ fi = GNUNET_FS_file_information_create_from_reader (daemon->fs,
+ daemon,
+ size,
+ &file_generator,
+ daemon,
+ NULL,
+ NULL, do_index, &bo);
+ }
daemon->publish_context = GNUNET_FS_publish_start (daemon->fs,
- fi,
- NULL, NULL, NULL,
-
GNUNET_FS_PUBLISH_OPTION_NONE);
+ fi,
+ NULL, NULL, NULL,
+
GNUNET_FS_PUBLISH_OPTION_NONE);
daemon->publish_timeout_task = GNUNET_SCHEDULER_add_delayed (timeout,
- &publish_timeout,
- daemon);
+
&publish_timeout,
+ daemon);
}
static void
-download_timeout (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+download_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_FS_TestDaemon *daemon = cls;
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Timeout while trying to download file\n");
+ "Timeout while trying to download file\n");
daemon->download_timeout_task = GNUNET_SCHEDULER_NO_TASK;
GNUNET_FS_download_stop (daemon->download_context, GNUNET_YES);
daemon->download_context = NULL;
GNUNET_SCHEDULER_add_continuation (daemon->download_cont,
- daemon->download_cont_cls,
- GNUNET_SCHEDULER_REASON_TIMEOUT);
+ daemon->download_cont_cls,
+ GNUNET_SCHEDULER_REASON_TIMEOUT);
daemon->download_cont = NULL;
}
@@ -757,35 +715,33 @@
*/
void
GNUNET_FS_TEST_download (struct GNUNET_FS_TestDaemon *daemon,
- struct GNUNET_TIME_Relative timeout,
- uint32_t anonymity,
- uint32_t seed,
- const struct GNUNET_FS_Uri *uri,
- unsigned int verbose,
- GNUNET_SCHEDULER_Task cont,
- void *cont_cls)
+ struct GNUNET_TIME_Relative timeout,
+ uint32_t anonymity,
+ uint32_t seed,
+ const struct GNUNET_FS_Uri *uri,
+ unsigned int verbose,
+ GNUNET_SCHEDULER_Task cont, void *cont_cls)
{
uint64_t size;
-
+
GNUNET_assert (daemon->download_cont == NULL);
size = GNUNET_FS_uri_chk_get_file_size (uri);
daemon->verbose = verbose;
daemon->download_cont = cont;
daemon->download_cont_cls = cont_cls;
- daemon->download_seed = seed;
+ daemon->download_seed = seed;
daemon->download_context = GNUNET_FS_download_start (daemon->fs,
- uri,
- NULL, NULL,
- NULL,
- 0,
- size,
- anonymity,
-
GNUNET_FS_DOWNLOAD_OPTION_NONE,
- NULL,
- NULL);
+ uri,
+ NULL, NULL,
+ NULL,
+ 0,
+ size,
+ anonymity,
+
GNUNET_FS_DOWNLOAD_OPTION_NONE,
+ NULL, NULL);
daemon->download_timeout_task = GNUNET_SCHEDULER_add_delayed (timeout,
-
&download_timeout,
- daemon);
+
&download_timeout,
+ daemon);
}
/* end of test_fs_lib.c */
Modified: gnunet/src/fs/fs_test_lib.h
===================================================================
--- gnunet/src/fs/fs_test_lib.h 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/fs/fs_test_lib.h 2011-08-15 21:46:35 UTC (rev 16581)
@@ -55,11 +55,10 @@
*/
void
GNUNET_FS_TEST_daemons_start (const char *template_cfg_file,
- struct GNUNET_TIME_Relative timeout,
- unsigned int total,
- struct GNUNET_FS_TestDaemon **daemons,
- GNUNET_SCHEDULER_Task cont,
- void *cont_cls);
+ struct GNUNET_TIME_Relative timeout,
+ unsigned int total,
+ struct GNUNET_FS_TestDaemon **daemons,
+ GNUNET_SCHEDULER_Task cont, void *cont_cls);
/**
@@ -74,10 +73,9 @@
*/
void
GNUNET_FS_TEST_daemons_connect (struct GNUNET_FS_TestDaemon *daemon1,
- struct GNUNET_FS_TestDaemon *daemon2,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_SCHEDULER_Task cont,
- void *cont_cls);
+ struct GNUNET_FS_TestDaemon *daemon2,
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_SCHEDULER_Task cont, void *cont_cls);
/**
@@ -86,8 +84,9 @@
* @param daemons array with the daemons (must contain at least one)
* @return peer group
*/
-struct GNUNET_TESTING_PeerGroup *
-GNUNET_FS_TEST_get_group (struct GNUNET_FS_TestDaemon **daemons);
+struct GNUNET_TESTING_PeerGroup *GNUNET_FS_TEST_get_group (struct
+ GNUNET_FS_TestDaemon
+ **daemons);
@@ -98,9 +97,9 @@
* @param off which configuration to get
* @return peer configuration
*/
-const struct GNUNET_CONFIGURATION_Handle *
-GNUNET_FS_TEST_get_configuration (struct GNUNET_FS_TestDaemon **daemons,
- unsigned int off);
+const struct GNUNET_CONFIGURATION_Handle
+ *GNUNET_FS_TEST_get_configuration (struct GNUNET_FS_TestDaemon **daemons,
+ unsigned int off);
/**
* Stop daemons used for testing.
@@ -110,7 +109,7 @@
*/
void
GNUNET_FS_TEST_daemons_stop (unsigned int total,
- struct GNUNET_FS_TestDaemon **daemons);
+ struct GNUNET_FS_TestDaemon **daemons);
/**
@@ -119,9 +118,9 @@
* @param cls closure (user defined)
* @param uri a URI, NULL for errors
*/
-typedef void
-(*GNUNET_FS_TEST_UriContinuation)(void *cls,
- const struct GNUNET_FS_Uri *uri);
+typedef void
+ (*GNUNET_FS_TEST_UriContinuation) (void *cls,
+ const struct GNUNET_FS_Uri * uri);
/**
@@ -141,14 +140,13 @@
*/
void
GNUNET_FS_TEST_publish (struct GNUNET_FS_TestDaemon *daemon,
- struct GNUNET_TIME_Relative timeout,
- uint32_t anonymity,
- int do_index,
- uint64_t size,
- uint32_t seed,
- unsigned int verbose,
- GNUNET_FS_TEST_UriContinuation cont,
- void *cont_cls);
+ struct GNUNET_TIME_Relative timeout,
+ uint32_t anonymity,
+ int do_index,
+ uint64_t size,
+ uint32_t seed,
+ unsigned int verbose,
+ GNUNET_FS_TEST_UriContinuation cont, void *cont_cls);
/**
@@ -166,13 +164,12 @@
*/
void
GNUNET_FS_TEST_download (struct GNUNET_FS_TestDaemon *daemon,
- struct GNUNET_TIME_Relative timeout,
- uint32_t anonymity,
- uint32_t seed,
- const struct GNUNET_FS_Uri *uri,
- unsigned int verbose,
- GNUNET_SCHEDULER_Task cont,
- void *cont_cls);
+ struct GNUNET_TIME_Relative timeout,
+ uint32_t anonymity,
+ uint32_t seed,
+ const struct GNUNET_FS_Uri *uri,
+ unsigned int verbose,
+ GNUNET_SCHEDULER_Task cont, void *cont_cls);
Modified: gnunet/src/fs/fs_tree.c
===================================================================
--- gnunet/src/fs/fs_tree.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/fs/fs_tree.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -40,7 +40,7 @@
* Global FS context.
*/
struct GNUNET_FS_Handle *h;
-
+
/**
* Closure for all callbacks.
*/
@@ -65,7 +65,7 @@
* Function to call once we're done with processing.
*/
GNUNET_SCHEDULER_Task cont;
-
+
/**
* Set to an error message (if we had an error).
*/
@@ -132,15 +132,15 @@
treeDepth = 1;
fl = DBLOCK_SIZE;
while (fl < flen)
+ {
+ treeDepth++;
+ if (fl * CHK_PER_INODE < fl)
{
- treeDepth++;
- if (fl * CHK_PER_INODE < fl)
- {
- /* integer overflow, this is a HUGE file... */
- return treeDepth;
- }
- fl = fl * CHK_PER_INODE;
+ /* integer overflow, this is a HUGE file... */
+ return treeDepth;
}
+ fl = fl * CHK_PER_INODE;
+ }
return treeDepth;
}
@@ -161,7 +161,7 @@
unsigned int i;
rsize = DBLOCK_SIZE;
- for (i = 0; i<depth; i++)
+ for (i = 0; i < depth; i++)
rsize *= CHK_PER_INODE;
return rsize;
}
@@ -181,9 +181,8 @@
* end of a block).
* @return size of the corresponding IBlock
*/
-static uint16_t
-GNUNET_FS_tree_compute_iblock_size (unsigned int depth,
- uint64_t end_offset)
+static uint16_t
+GNUNET_FS_tree_compute_iblock_size (unsigned int depth, uint64_t end_offset)
{
unsigned int ret;
uint64_t mod;
@@ -194,19 +193,19 @@
bds = GNUNET_FS_tree_compute_tree_size (depth);
mod = end_offset % bds;
if (0 == mod)
- {
- /* we were triggered at the end of a full block */
- ret = CHK_PER_INODE;
- }
+ {
+ /* we were triggered at the end of a full block */
+ ret = CHK_PER_INODE;
+ }
else
- {
- /* we were triggered at the end of the file */
- bds /= CHK_PER_INODE;
- ret = mod / bds;
- if (0 != mod % bds)
- ret++;
- }
- return (uint16_t) (ret * sizeof(struct ContentHashKey));
+ {
+ /* we were triggered at the end of the file */
+ bds /= CHK_PER_INODE;
+ ret = mod / bds;
+ if (0 != mod % bds)
+ ret++;
+ }
+ return (uint16_t) (ret * sizeof (struct ContentHashKey));
}
@@ -223,8 +222,7 @@
*/
size_t
GNUNET_FS_tree_calculate_block_size (uint64_t fsize,
- uint64_t offset,
- unsigned int depth)
+ uint64_t offset, unsigned int depth)
{
size_t ret;
uint64_t rsize;
@@ -234,18 +232,16 @@
GNUNET_assert (fsize > 0);
GNUNET_assert (offset <= fsize);
if (depth == 0)
- {
- ret = DBLOCK_SIZE;
- if ( (offset + ret > fsize) ||
- (offset + ret < offset) )
- ret = (size_t) (fsize - offset);
- return ret;
- }
+ {
+ ret = DBLOCK_SIZE;
+ if ((offset + ret > fsize) || (offset + ret < offset))
+ ret = (size_t) (fsize - offset);
+ return ret;
+ }
rsize = GNUNET_FS_tree_compute_tree_size (depth - 1);
epos = offset + rsize * CHK_PER_INODE;
- if ( (epos < offset) ||
- (epos > fsize) )
+ if ((epos < offset) || (epos > fsize))
epos = fsize;
/* round up when computing #CHKs in our IBlock */
chks = (epos - offset + rsize - 1) / rsize;
@@ -273,16 +269,16 @@
*/
struct GNUNET_FS_TreeEncoder *
GNUNET_FS_tree_encoder_create (struct GNUNET_FS_Handle *h,
- uint64_t size,
- void *cls,
- GNUNET_FS_DataReader reader,
- GNUNET_FS_TreeBlockProcessor proc,
- GNUNET_FS_TreeProgressCallback progress,
- GNUNET_SCHEDULER_Task cont)
+ uint64_t size,
+ void *cls,
+ GNUNET_FS_DataReader reader,
+ GNUNET_FS_TreeBlockProcessor proc,
+ GNUNET_FS_TreeProgressCallback progress,
+ GNUNET_SCHEDULER_Task cont)
{
struct GNUNET_FS_TreeEncoder *te;
-
- te = GNUNET_malloc (sizeof (struct GNUNET_FS_TreeEncoder));
+
+ te = GNUNET_malloc (sizeof (struct GNUNET_FS_TreeEncoder));
te->h = h;
te->size = size;
te->cls = cls;
@@ -292,8 +288,7 @@
te->cont = cont;
te->chk_tree_depth = GNUNET_FS_compute_depth (size);
te->chk_tree = GNUNET_malloc (te->chk_tree_depth *
- CHK_PER_INODE *
- sizeof (struct ContentHashKey));
+ CHK_PER_INODE * sizeof (struct
ContentHashKey));
return te;
}
@@ -310,17 +305,16 @@
* @return (array of CHKs') offset in the above IBlock
*/
static unsigned int
-compute_chk_offset (unsigned int depth,
- uint64_t end_offset)
+compute_chk_offset (unsigned int depth, uint64_t end_offset)
{
uint64_t bds;
unsigned int ret;
bds = GNUNET_FS_tree_compute_tree_size (depth);
if (depth > 0)
- end_offset--; /* round down since for depth > 0 offset is at the END of
the block */
+ end_offset--; /* round down since for depth > 0 offset is at
the END of the block */
ret = end_offset / bds;
- return ret % CHK_PER_INODE;
+ return ret % CHK_PER_INODE;
}
@@ -331,8 +325,8 @@
*
* @param te tree encoder to use
*/
-void
-GNUNET_FS_tree_encoder_next (struct GNUNET_FS_TreeEncoder * te)
+void
+GNUNET_FS_tree_encoder_next (struct GNUNET_FS_TreeEncoder *te)
{
struct ContentHashKey *mychk;
const void *pt_block;
@@ -346,105 +340,85 @@
GNUNET_assert (GNUNET_NO == te->in_next);
te->in_next = GNUNET_YES;
if (te->chk_tree_depth == te->current_depth)
- {
- off = CHK_PER_INODE * (te->chk_tree_depth - 1);
+ {
+ off = CHK_PER_INODE * (te->chk_tree_depth - 1);
#if DEBUG_TREE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "TE done, reading CHK `%s' from %u\n",
- GNUNET_h2s (&te->chk_tree[off].query),
- off);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "TE done, reading CHK `%s' from %u\n",
+ GNUNET_h2s (&te->chk_tree[off].query), off);
#endif
- te->uri = GNUNET_malloc (sizeof(struct GNUNET_FS_Uri));
- te->uri->type = chk;
- te->uri->data.chk.chk = te->chk_tree[off];
- te->uri->data.chk.file_length = GNUNET_htonll (te->size);
+ te->uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
+ te->uri->type = chk;
+ te->uri->data.chk.chk = te->chk_tree[off];
+ te->uri->data.chk.file_length = GNUNET_htonll (te->size);
+ te->in_next = GNUNET_NO;
+ te->cont (te->cls, NULL);
+ return;
+ }
+ if (0 == te->current_depth)
+ {
+ /* read DBLOCK */
+ pt_size = GNUNET_MIN (DBLOCK_SIZE, te->size - te->publish_offset);
+ if (pt_size !=
+ te->reader (te->cls, te->publish_offset, pt_size, iob, &te->emsg))
+ {
+ GNUNET_SCHEDULER_add_continuation (te->cont,
+ te->cls,
+ GNUNET_SCHEDULER_REASON_TIMEOUT);
te->in_next = GNUNET_NO;
- te->cont (te->cls, NULL);
return;
}
- if (0 == te->current_depth)
- {
- /* read DBLOCK */
- pt_size = GNUNET_MIN(DBLOCK_SIZE,
- te->size - te->publish_offset);
- if (pt_size !=
- te->reader (te->cls,
- te->publish_offset,
- pt_size,
- iob,
- &te->emsg))
- {
- GNUNET_SCHEDULER_add_continuation (te->cont,
- te->cls,
- GNUNET_SCHEDULER_REASON_TIMEOUT);
- te->in_next = GNUNET_NO;
- return;
- }
- pt_block = iob;
- }
+ pt_block = iob;
+ }
else
- {
- pt_size = GNUNET_FS_tree_compute_iblock_size (te->current_depth,
- te->publish_offset);
- pt_block = &te->chk_tree[(te->current_depth - 1) *
- CHK_PER_INODE];
- }
- off = compute_chk_offset (te->current_depth,
- te->publish_offset);
+ {
+ pt_size = GNUNET_FS_tree_compute_iblock_size (te->current_depth,
+ te->publish_offset);
+ pt_block = &te->chk_tree[(te->current_depth - 1) * CHK_PER_INODE];
+ }
+ off = compute_chk_offset (te->current_depth, te->publish_offset);
#if DEBUG_TREE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "TE is at offset %llu and depth %u with block size %u and
target-CHK-offset %u\n",
- (unsigned long long) te->publish_offset,
- te->current_depth,
- (unsigned int) pt_size,
- (unsigned int) off);
+ "TE is at offset %llu and depth %u with block size %u and
target-CHK-offset %u\n",
+ (unsigned long long) te->publish_offset,
+ te->current_depth, (unsigned int) pt_size, (unsigned int) off);
#endif
- mychk = &te->chk_tree[te->current_depth*CHK_PER_INODE+off];
+ mychk = &te->chk_tree[te->current_depth * CHK_PER_INODE + off];
GNUNET_CRYPTO_hash (pt_block, pt_size, &mychk->key);
GNUNET_CRYPTO_hash_to_aes_key (&mychk->key, &sk, &iv);
- GNUNET_CRYPTO_aes_encrypt (pt_block,
- pt_size,
- &sk,
- &iv,
- enc);
+ GNUNET_CRYPTO_aes_encrypt (pt_block, pt_size, &sk, &iv, enc);
GNUNET_CRYPTO_hash (enc, pt_size, &mychk->query);
#if DEBUG_TREE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "TE calculates query to be `%s', stored at %u\n",
- GNUNET_h2s (&mychk->query),
- te->current_depth * CHK_PER_INODE + off);
+ "TE calculates query to be `%s', stored at %u\n",
+ GNUNET_h2s (&mychk->query),
+ te->current_depth * CHK_PER_INODE + off);
#endif
if (NULL != te->proc)
te->proc (te->cls,
- mychk,
- te->publish_offset,
- te->current_depth,
- (0 == te->current_depth)
- ? GNUNET_BLOCK_TYPE_FS_DBLOCK
- : GNUNET_BLOCK_TYPE_FS_IBLOCK,
- enc,
- pt_size);
+ mychk,
+ te->publish_offset,
+ te->current_depth,
+ (0 == te->current_depth)
+ ? GNUNET_BLOCK_TYPE_FS_DBLOCK
+ : GNUNET_BLOCK_TYPE_FS_IBLOCK, enc, pt_size);
if (NULL != te->progress)
te->progress (te->cls,
- te->publish_offset,
- pt_block,
- pt_size,
- te->current_depth);
- if (0 == te->current_depth)
- {
- te->publish_offset += pt_size;
- if ( (te->publish_offset == te->size) ||
- (0 == te->publish_offset % (CHK_PER_INODE * DBLOCK_SIZE) ) )
- te->current_depth++;
- }
+ te->publish_offset, pt_block, pt_size, te->current_depth);
+ if (0 == te->current_depth)
+ {
+ te->publish_offset += pt_size;
+ if ((te->publish_offset == te->size) ||
+ (0 == te->publish_offset % (CHK_PER_INODE * DBLOCK_SIZE)))
+ te->current_depth++;
+ }
else
- {
- if ( (off == CHK_PER_INODE) ||
- (te->publish_offset == te->size) )
- te->current_depth++;
- else
- te->current_depth = 0;
- }
+ {
+ if ((off == CHK_PER_INODE) || (te->publish_offset == te->size))
+ te->current_depth++;
+ else
+ te->current_depth = 0;
+ }
te->in_next = GNUNET_NO;
}
@@ -460,16 +434,15 @@
* prior to completion and prior to an internal error,
* both "*uri" and "*emsg" will be set to NULL).
*/
-void GNUNET_FS_tree_encoder_finish (struct GNUNET_FS_TreeEncoder *te,
- struct GNUNET_FS_Uri **uri,
- char **emsg)
+void
+GNUNET_FS_tree_encoder_finish (struct GNUNET_FS_TreeEncoder *te,
+ struct GNUNET_FS_Uri **uri, char **emsg)
{
GNUNET_assert (GNUNET_NO == te->in_next);
if (uri != NULL)
*uri = te->uri;
- else
- if (NULL != te->uri)
- GNUNET_FS_uri_destroy (te->uri);
+ else if (NULL != te->uri)
+ GNUNET_FS_uri_destroy (te->uri);
if (emsg != NULL)
*emsg = te->emsg;
else
Modified: gnunet/src/fs/fs_tree.h
===================================================================
--- gnunet/src/fs/fs_tree.h 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/fs/fs_tree.h 2011-08-15 21:46:35 UTC (rev 16581)
@@ -40,8 +40,7 @@
* @param flen file length for which to compute the depth
* @return depth of the tree, always > 0. A depth of 1 means only a DBLOCK.
*/
-unsigned int
-GNUNET_FS_compute_depth (uint64_t flen);
+unsigned int GNUNET_FS_compute_depth (uint64_t flen);
/**
@@ -53,8 +52,7 @@
* @param depth depth of the block. depth==0 is a DBLOCK.
* @return number of bytes of payload a subtree of this depth may correspond to
*/
-uint64_t
-GNUNET_FS_tree_compute_tree_size (unsigned int depth);
+uint64_t GNUNET_FS_tree_compute_tree_size (unsigned int depth);
/**
@@ -70,8 +68,7 @@
*/
size_t
GNUNET_FS_tree_calculate_block_size (uint64_t fsize,
- uint64_t offset,
- unsigned int depth);
+ uint64_t offset, unsigned int depth);
/**
@@ -95,15 +92,15 @@
* @param block the (encrypted) block
* @param block_size size of block (in bytes)
*/
-typedef void (*GNUNET_FS_TreeBlockProcessor)(void *cls,
- const struct ContentHashKey *chk,
- uint64_t offset,
- unsigned int depth,
- enum GNUNET_BLOCK_Type type,
- const void *block,
- uint16_t block_size);
-
+typedef void (*GNUNET_FS_TreeBlockProcessor) (void *cls,
+ const struct ContentHashKey *
chk,
+ uint64_t offset,
+ unsigned int depth,
+ enum GNUNET_BLOCK_Type type,
+ const void *block,
+ uint16_t block_size);
+
/**
* Function called with information about our
* progress in computing the tree encoding.
@@ -114,13 +111,13 @@
* @param pt_size size of pt_block
* @param depth depth of the block in the tree, 0 for DBLOCKS
*/
-typedef void (*GNUNET_FS_TreeProgressCallback)(void *cls,
- uint64_t offset,
- const void *pt_block,
- size_t pt_size,
- unsigned int depth);
-
+typedef void (*GNUNET_FS_TreeProgressCallback) (void *cls,
+ uint64_t offset,
+ const void *pt_block,
+ size_t pt_size,
+ unsigned int depth);
+
/**
* Initialize a tree encoder. This function will call "proc" and
* "progress" on each block in the tree. Once all blocks have been
@@ -139,14 +136,18 @@
* @param cont function to call when done
* @return tree encoder context
*/
-struct GNUNET_FS_TreeEncoder *
-GNUNET_FS_tree_encoder_create (struct GNUNET_FS_Handle *h,
- uint64_t size,
- void *cls,
- GNUNET_FS_DataReader reader,
- GNUNET_FS_TreeBlockProcessor proc,
- GNUNET_FS_TreeProgressCallback progress,
- GNUNET_SCHEDULER_Task cont);
+struct GNUNET_FS_TreeEncoder *GNUNET_FS_tree_encoder_create (struct
+ GNUNET_FS_Handle
+ *h, uint64_t size,
+ void *cls,
+
GNUNET_FS_DataReader
+ reader,
+
GNUNET_FS_TreeBlockProcessor
+ proc,
+
GNUNET_FS_TreeProgressCallback
+ progress,
+
GNUNET_SCHEDULER_Task
+ cont);
/**
@@ -157,7 +158,7 @@
*
* @param te tree encoder to use
*/
-void GNUNET_FS_tree_encoder_next (struct GNUNET_FS_TreeEncoder * te);
+void GNUNET_FS_tree_encoder_next (struct GNUNET_FS_TreeEncoder *te);
/**
@@ -172,8 +173,7 @@
* both "*uri" and "*emsg" will be set to NULL).
*/
void GNUNET_FS_tree_encoder_finish (struct GNUNET_FS_TreeEncoder *te,
- struct GNUNET_FS_Uri **uri,
- char **emsg);
+ struct GNUNET_FS_Uri **uri, char **emsg);
#if 0
@@ -187,9 +187,8 @@
* @param data set to the resume data
* @param size set to the size of the resume data
*/
-void GNUNET_FS_tree_encoder_resume_get_data (const struct
GNUNET_FS_TreeEncoder *te,
- void **data,
- size_t *size);
+void GNUNET_FS_tree_encoder_resume_get_data (const struct GNUNET_FS_TreeEncoder
+ *te, void **data, size_t * size);
/**
@@ -201,8 +200,7 @@
* @param size the size of the resume data
*/
void GNUNET_FS_tree_encoder_resume (struct GNUNET_FS_TreeEncoder *te,
- const void *data,
- size_t size);
+ const void *data, size_t size);
#endif
#endif
Modified: gnunet/src/fs/fs_unindex.c
===================================================================
--- gnunet/src/fs/fs_unindex.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/fs/fs_unindex.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -47,31 +47,22 @@
* @return number of bytes copied to buf, 0 on error
*/
static size_t
-unindex_reader (void *cls,
- uint64_t offset,
- size_t max,
- void *buf,
- char **emsg)
+unindex_reader (void *cls, uint64_t offset, size_t max, void *buf, char **emsg)
{
struct GNUNET_FS_UnindexContext *uc = cls;
size_t pt_size;
- pt_size = GNUNET_MIN(max,
- uc->file_size - offset);
- if (offset !=
- GNUNET_DISK_file_seek (uc->fh, offset, GNUNET_DISK_SEEK_SET))
- {
- *emsg = GNUNET_strdup (_("Failed to find given position in file"));
- return 0;
- }
- if (pt_size !=
- GNUNET_DISK_file_read (uc->fh,
- buf,
- pt_size))
- {
- *emsg = GNUNET_strdup (_("Failed to read file"));
- return 0;
- }
+ pt_size = GNUNET_MIN (max, uc->file_size - offset);
+ if (offset != GNUNET_DISK_file_seek (uc->fh, offset, GNUNET_DISK_SEEK_SET))
+ {
+ *emsg = GNUNET_strdup (_("Failed to find given position in file"));
+ return 0;
+ }
+ if (pt_size != GNUNET_DISK_file_read (uc->fh, buf, pt_size))
+ {
+ *emsg = GNUNET_strdup (_("Failed to read file"));
+ return 0;
+ }
return pt_size;
}
@@ -86,22 +77,19 @@
*/
void
GNUNET_FS_unindex_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
- struct GNUNET_FS_UnindexContext *uc,
- uint64_t offset)
+ struct GNUNET_FS_UnindexContext *uc,
+ uint64_t offset)
{
pi->value.unindex.uc = uc;
pi->value.unindex.cctx = uc->client_info;
pi->value.unindex.filename = uc->filename;
pi->value.unindex.size = uc->file_size;
- pi->value.unindex.eta
- = GNUNET_TIME_calculate_eta (uc->start_time,
- offset,
- uc->file_size);
- pi->value.unindex.duration = GNUNET_TIME_absolute_get_duration
(uc->start_time);
+ pi->value.unindex.eta
+ = GNUNET_TIME_calculate_eta (uc->start_time, offset, uc->file_size);
+ pi->value.unindex.duration =
+ GNUNET_TIME_absolute_get_duration (uc->start_time);
pi->value.unindex.completed = offset;
- uc->client_info
- = uc->h->upcb (uc->h->upcb_cls,
- pi);
+ uc->client_info = uc->h->upcb (uc->h->upcb_cls, pi);
}
@@ -118,10 +106,8 @@
*/
static void
unindex_progress (void *cls,
- uint64_t offset,
- const void *pt_block,
- size_t pt_size,
- unsigned int depth)
+ uint64_t offset,
+ const void *pt_block, size_t pt_size, unsigned int depth)
{
struct GNUNET_FS_UnindexContext *uc = cls;
struct GNUNET_FS_ProgressInfo pi;
@@ -133,8 +119,8 @@
pi.value.unindex.specifics.progress.depth = depth;
GNUNET_FS_unindex_make_status_ (&pi, uc, offset);
}
-
+
/**
* We've encountered an error during
* unindexing. Signal the client.
@@ -145,7 +131,7 @@
signal_unindex_error (struct GNUNET_FS_UnindexContext *uc)
{
struct GNUNET_FS_ProgressInfo pi;
-
+
pi.status = GNUNET_FS_STATUS_UNINDEX_ERROR;
pi.value.unindex.eta = GNUNET_TIME_UNIT_FOREVER_REL;
pi.value.unindex.specifics.error.message = uc->emsg;
@@ -162,20 +148,19 @@
* @param msg NULL on success, otherwise an error message
*/
static void
-process_cont (void *cls,
- int success,
- const char *msg)
+process_cont (void *cls, int success, const char *msg)
{
struct GNUNET_FS_UnindexContext *uc = cls;
+
if (success == GNUNET_SYSERR)
- {
- uc->emsg = GNUNET_strdup (msg);
- signal_unindex_error (uc);
- return;
- }
+ {
+ uc->emsg = GNUNET_strdup (msg);
+ signal_unindex_error (uc);
+ return;
+ }
#if DEBUG_UNINDEX
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Datastore REMOVE operation succeeded\n");
+ "Datastore REMOVE operation succeeded\n");
#endif
GNUNET_FS_tree_encoder_next (uc->tc);
}
@@ -195,14 +180,13 @@
* @param block the (encrypted) block
* @param block_size size of block (in bytes)
*/
-static void
+static void
unindex_process (void *cls,
- const struct ContentHashKey *chk,
- uint64_t offset,
- unsigned int depth,
- enum GNUNET_BLOCK_Type type,
- const void *block,
- uint16_t block_size)
+ const struct ContentHashKey *chk,
+ uint64_t offset,
+ unsigned int depth,
+ enum GNUNET_BLOCK_Type type,
+ const void *block, uint16_t block_size)
{
struct GNUNET_FS_UnindexContext *uc = cls;
uint32_t size;
@@ -210,29 +194,27 @@
struct OnDemandBlock odb;
if (type != GNUNET_BLOCK_TYPE_FS_DBLOCK)
- {
- size = block_size;
- data = block;
- }
- else /* on-demand encoded DBLOCK */
- {
- size = sizeof(struct OnDemandBlock);
- odb.offset = GNUNET_htonll (offset);
- odb.file_id = uc->file_id;
- data = &odb;
- }
+ {
+ size = block_size;
+ data = block;
+ }
+ else /* on-demand encoded DBLOCK */
+ {
+ size = sizeof (struct OnDemandBlock);
+ odb.offset = GNUNET_htonll (offset);
+ odb.file_id = uc->file_id;
+ data = &odb;
+ }
#if DEBUG_UNINDEX
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending REMOVE request to DATASTORE service\n");
+ "Sending REMOVE request to DATASTORE service\n");
#endif
GNUNET_DATASTORE_remove (uc->dsh,
- &chk->query,
- size,
- data,
- -2, 1,
- GNUNET_CONSTANTS_SERVICE_TIMEOUT,
- &process_cont,
- uc);
+ &chk->query,
+ size,
+ data,
+ -2, 1,
+ GNUNET_CONSTANTS_SERVICE_TIMEOUT, &process_cont,
uc);
}
@@ -244,41 +226,41 @@
* @param msg NULL on timeout, otherwise the response
*/
static void
-process_fs_response (void *cls,
- const struct GNUNET_MessageHeader *msg)
+process_fs_response (void *cls, const struct GNUNET_MessageHeader *msg)
{
struct GNUNET_FS_UnindexContext *uc = cls;
struct GNUNET_FS_ProgressInfo pi;
if (uc->client != NULL)
- {
- GNUNET_CLIENT_disconnect (uc->client, GNUNET_NO);
- uc->client = NULL;
- }
- if (uc->state != UNINDEX_STATE_FS_NOTIFY)
- {
- uc->state = UNINDEX_STATE_ERROR;
- uc->emsg = GNUNET_strdup (_("Unexpected time for a response from `fs'
service."));
- GNUNET_FS_unindex_sync_ (uc);
- signal_unindex_error (uc);
- return;
- }
+ {
+ GNUNET_CLIENT_disconnect (uc->client, GNUNET_NO);
+ uc->client = NULL;
+ }
+ if (uc->state != UNINDEX_STATE_FS_NOTIFY)
+ {
+ uc->state = UNINDEX_STATE_ERROR;
+ uc->emsg =
+ GNUNET_strdup (_("Unexpected time for a response from `fs' service."));
+ GNUNET_FS_unindex_sync_ (uc);
+ signal_unindex_error (uc);
+ return;
+ }
if (NULL == msg)
- {
- uc->state = UNINDEX_STATE_ERROR;
- uc->emsg = GNUNET_strdup (_("Timeout waiting for `fs' service."));
- GNUNET_FS_unindex_sync_ (uc);
- signal_unindex_error (uc);
- return;
- }
- if (ntohs(msg->type) != GNUNET_MESSAGE_TYPE_FS_UNINDEX_OK)
- {
- uc->state = UNINDEX_STATE_ERROR;
- uc->emsg = GNUNET_strdup (_("Invalid response from `fs' service."));
- GNUNET_FS_unindex_sync_ (uc);
- signal_unindex_error (uc);
- return;
- }
+ {
+ uc->state = UNINDEX_STATE_ERROR;
+ uc->emsg = GNUNET_strdup (_("Timeout waiting for `fs' service."));
+ GNUNET_FS_unindex_sync_ (uc);
+ signal_unindex_error (uc);
+ return;
+ }
+ if (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_FS_UNINDEX_OK)
+ {
+ uc->state = UNINDEX_STATE_ERROR;
+ uc->emsg = GNUNET_strdup (_("Invalid response from `fs' service."));
+ GNUNET_FS_unindex_sync_ (uc);
+ signal_unindex_error (uc);
+ return;
+ }
uc->state = UNINDEX_STATE_COMPLETE;
pi.status = GNUNET_FS_STATUS_UNINDEX_COMPLETED;
pi.value.unindex.eta = GNUNET_TIME_UNIT_ZERO;
@@ -295,8 +277,7 @@
* @param tc not used
*/
static void
-unindex_finish (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+unindex_finish (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_FS_UnindexContext *uc = cls;
char *emsg;
@@ -304,13 +285,8 @@
struct UnindexMessage req;
/* generate final progress message */
- unindex_progress (uc,
- uc->file_size,
- NULL,
- 0, 0);
- GNUNET_FS_tree_encoder_finish (uc->tc,
- &uri,
- &emsg);
+ unindex_progress (uc, uc->file_size, NULL, 0, 0);
+ GNUNET_FS_tree_encoder_finish (uc->tc, &uri, &emsg);
uc->tc = NULL;
if (uri != NULL)
GNUNET_FS_uri_destroy (uri);
@@ -320,31 +296,31 @@
uc->dsh = NULL;
uc->state = UNINDEX_STATE_FS_NOTIFY;
GNUNET_FS_unindex_sync_ (uc);
- uc->client = GNUNET_CLIENT_connect ("fs",
- uc->h->cfg);
+ uc->client = GNUNET_CLIENT_connect ("fs", uc->h->cfg);
if (uc->client == NULL)
- {
- uc->state = UNINDEX_STATE_ERROR;
- uc->emsg = GNUNET_strdup (_("Failed to connect to FS service for
unindexing."));
- GNUNET_FS_unindex_sync_ (uc);
- signal_unindex_error (uc);
- return;
- }
+ {
+ uc->state = UNINDEX_STATE_ERROR;
+ uc->emsg =
+ GNUNET_strdup (_("Failed to connect to FS service for unindexing."));
+ GNUNET_FS_unindex_sync_ (uc);
+ signal_unindex_error (uc);
+ return;
+ }
#if DEBUG_UNINDEX
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending UNINDEX message to FS service\n");
+ "Sending UNINDEX message to FS service\n");
#endif
req.header.size = htons (sizeof (struct UnindexMessage));
req.header.type = htons (GNUNET_MESSAGE_TYPE_FS_UNINDEX);
req.reserved = 0;
req.file_id = uc->file_id;
- GNUNET_break (GNUNET_OK ==
- GNUNET_CLIENT_transmit_and_get_response (uc->client,
- &req.header,
-
GNUNET_CONSTANTS_SERVICE_TIMEOUT,
- GNUNET_YES,
- &process_fs_response,
- uc));
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_CLIENT_transmit_and_get_response (uc->client,
+ &req.header,
+
GNUNET_CONSTANTS_SERVICE_TIMEOUT,
+ GNUNET_YES,
+ &process_fs_response,
+ uc));
}
@@ -353,38 +329,36 @@
*
* @param uc context for the unindex operation.
*/
-void
+void
GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc)
{
uc->dsh = GNUNET_DATASTORE_connect (uc->h->cfg);
if (NULL == uc->dsh)
- {
- uc->state = UNINDEX_STATE_ERROR;
- uc->emsg = GNUNET_strdup (_("Failed to connect to `datastore'
service."));
- GNUNET_FS_unindex_sync_ (uc);
- signal_unindex_error (uc);
- return;
- }
+ {
+ uc->state = UNINDEX_STATE_ERROR;
+ uc->emsg = GNUNET_strdup (_("Failed to connect to `datastore' service."));
+ GNUNET_FS_unindex_sync_ (uc);
+ signal_unindex_error (uc);
+ return;
+ }
uc->fh = GNUNET_DISK_file_open (uc->filename,
- GNUNET_DISK_OPEN_READ,
- GNUNET_DISK_PERM_NONE);
+ GNUNET_DISK_OPEN_READ,
GNUNET_DISK_PERM_NONE);
if (NULL == uc->fh)
- {
- GNUNET_DATASTORE_disconnect (uc->dsh, GNUNET_NO);
- uc->dsh = NULL;
- uc->state = UNINDEX_STATE_ERROR;
- uc->emsg = GNUNET_strdup (_("Failed to open file for unindexing."));
- GNUNET_FS_unindex_sync_ (uc);
- signal_unindex_error (uc);
- return;
- }
+ {
+ GNUNET_DATASTORE_disconnect (uc->dsh, GNUNET_NO);
+ uc->dsh = NULL;
+ uc->state = UNINDEX_STATE_ERROR;
+ uc->emsg = GNUNET_strdup (_("Failed to open file for unindexing."));
+ GNUNET_FS_unindex_sync_ (uc);
+ signal_unindex_error (uc);
+ return;
+ }
uc->tc = GNUNET_FS_tree_encoder_create (uc->h,
- uc->file_size,
- uc,
- &unindex_reader,
- &unindex_process,
- &unindex_progress,
- &unindex_finish);
+ uc->file_size,
+ uc,
+ &unindex_reader,
+ &unindex_process,
+ &unindex_progress, &unindex_finish);
GNUNET_FS_tree_encoder_next (uc->tc);
}
@@ -396,26 +370,25 @@
* @param cls closure, unindex context
* @param file_id computed hash, NULL on error
*/
-void
-GNUNET_FS_unindex_process_hash_ (void *cls,
- const GNUNET_HashCode *file_id)
+void
+GNUNET_FS_unindex_process_hash_ (void *cls, const GNUNET_HashCode * file_id)
{
struct GNUNET_FS_UnindexContext *uc = cls;
uc->fhc = NULL;
- if (uc->state != UNINDEX_STATE_HASHING)
- {
- GNUNET_FS_unindex_stop (uc);
- return;
- }
+ if (uc->state != UNINDEX_STATE_HASHING)
+ {
+ GNUNET_FS_unindex_stop (uc);
+ return;
+ }
if (file_id == NULL)
- {
- uc->state = UNINDEX_STATE_ERROR;
- uc->emsg = GNUNET_strdup (_("Failed to compute hash of file."));
- GNUNET_FS_unindex_sync_ (uc);
- signal_unindex_error (uc);
- return;
- }
+ {
+ uc->state = UNINDEX_STATE_ERROR;
+ uc->emsg = GNUNET_strdup (_("Failed to compute hash of file."));
+ GNUNET_FS_unindex_sync_ (uc);
+ signal_unindex_error (uc);
+ return;
+ }
uc->file_id = *file_id;
uc->state = UNINDEX_STATE_DS_REMOVE;
GNUNET_FS_unindex_sync_ (uc);
@@ -436,37 +409,35 @@
struct GNUNET_FS_ProgressInfo pi;
if (uc->fhc != NULL)
- {
- GNUNET_CRYPTO_hash_file_cancel (uc->fhc);
- uc->fhc = NULL;
- }
+ {
+ GNUNET_CRYPTO_hash_file_cancel (uc->fhc);
+ uc->fhc = NULL;
+ }
if (uc->client != NULL)
- {
- GNUNET_CLIENT_disconnect (uc->client, GNUNET_NO);
- uc->client = NULL;
- }
+ {
+ GNUNET_CLIENT_disconnect (uc->client, GNUNET_NO);
+ uc->client = NULL;
+ }
if (NULL != uc->dsh)
- {
- GNUNET_DATASTORE_disconnect (uc->dsh, GNUNET_NO);
- uc->dsh = NULL;
- }
+ {
+ GNUNET_DATASTORE_disconnect (uc->dsh, GNUNET_NO);
+ uc->dsh = NULL;
+ }
if (NULL != uc->tc)
- {
- GNUNET_FS_tree_encoder_finish (uc->tc,
- NULL,
- NULL);
- uc->tc = NULL;
- }
+ {
+ GNUNET_FS_tree_encoder_finish (uc->tc, NULL, NULL);
+ uc->tc = NULL;
+ }
if (uc->fh != NULL)
- {
- GNUNET_DISK_file_close (uc->fh);
- uc->fh = NULL;
- }
+ {
+ GNUNET_DISK_file_close (uc->fh);
+ uc->fh = NULL;
+ }
GNUNET_FS_end_top (uc->h, uc->top);
pi.status = GNUNET_FS_STATUS_UNINDEX_SUSPEND;
- GNUNET_FS_unindex_make_status_ (&pi, uc,
- (uc->state == UNINDEX_STATE_COMPLETE)
- ? uc->file_size : 0);
+ GNUNET_FS_unindex_make_status_ (&pi, uc,
+ (uc->state == UNINDEX_STATE_COMPLETE)
+ ? uc->file_size : 0);
GNUNET_break (NULL == uc->client_info);
GNUNET_free (uc->filename);
GNUNET_free_non_null (uc->serialization);
@@ -485,17 +456,13 @@
*/
struct GNUNET_FS_UnindexContext *
GNUNET_FS_unindex_start (struct GNUNET_FS_Handle *h,
- const char *filename,
- void *cctx)
+ const char *filename, void *cctx)
{
struct GNUNET_FS_UnindexContext *ret;
struct GNUNET_FS_ProgressInfo pi;
uint64_t size;
- if (GNUNET_OK !=
- GNUNET_DISK_file_size (filename,
- &size,
- GNUNET_YES))
+ if (GNUNET_OK != GNUNET_DISK_file_size (filename, &size, GNUNET_YES))
return NULL;
ret = GNUNET_malloc (sizeof (struct GNUNET_FS_UnindexContext));
ret->h = h;
@@ -508,13 +475,10 @@
pi.value.unindex.eta = GNUNET_TIME_UNIT_FOREVER_REL;
GNUNET_FS_unindex_make_status_ (&pi, ret, 0);
ret->fhc = GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE,
- filename,
- HASHING_BLOCKSIZE,
- &GNUNET_FS_unindex_process_hash_,
- ret);
- ret->top = GNUNET_FS_make_top (h,
- &GNUNET_FS_unindex_signal_suspend_,
- ret);
+ filename,
+ HASHING_BLOCKSIZE,
+ &GNUNET_FS_unindex_process_hash_, ret);
+ ret->top = GNUNET_FS_make_top (h, &GNUNET_FS_unindex_signal_suspend_, ret);
return ret;
}
@@ -526,48 +490,47 @@
*/
void
GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc)
-{
+{
struct GNUNET_FS_ProgressInfo pi;
-
+
if (uc->fhc != NULL)
- {
- GNUNET_CRYPTO_hash_file_cancel (uc->fhc);
- uc->fhc = NULL;
- }
+ {
+ GNUNET_CRYPTO_hash_file_cancel (uc->fhc);
+ uc->fhc = NULL;
+ }
if (uc->client != NULL)
- {
- GNUNET_CLIENT_disconnect (uc->client, GNUNET_NO);
- uc->client = NULL;
- }
+ {
+ GNUNET_CLIENT_disconnect (uc->client, GNUNET_NO);
+ uc->client = NULL;
+ }
if (NULL != uc->dsh)
- {
- GNUNET_DATASTORE_disconnect (uc->dsh, GNUNET_NO);
- uc->dsh = NULL;
- }
+ {
+ GNUNET_DATASTORE_disconnect (uc->dsh, GNUNET_NO);
+ uc->dsh = NULL;
+ }
if (NULL != uc->tc)
- {
- GNUNET_FS_tree_encoder_finish (uc->tc,
- NULL,
- NULL);
- uc->tc = NULL;
- }
+ {
+ GNUNET_FS_tree_encoder_finish (uc->tc, NULL, NULL);
+ uc->tc = NULL;
+ }
if (uc->fh != NULL)
- {
- GNUNET_DISK_file_close (uc->fh);
- uc->fh = NULL;
- }
+ {
+ GNUNET_DISK_file_close (uc->fh);
+ uc->fh = NULL;
+ }
GNUNET_FS_end_top (uc->h, uc->top);
if (uc->serialization != NULL)
- {
- GNUNET_FS_remove_sync_file_ (uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX,
uc->serialization);
- GNUNET_free (uc->serialization);
- uc->serialization = NULL;
- }
+ {
+ GNUNET_FS_remove_sync_file_ (uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX,
+ uc->serialization);
+ GNUNET_free (uc->serialization);
+ uc->serialization = NULL;
+ }
pi.status = GNUNET_FS_STATUS_UNINDEX_STOPPED;
pi.value.unindex.eta = GNUNET_TIME_UNIT_ZERO;
- GNUNET_FS_unindex_make_status_ (&pi, uc,
- (uc->state == UNINDEX_STATE_COMPLETE)
- ? uc->file_size : 0);
+ GNUNET_FS_unindex_make_status_ (&pi, uc,
+ (uc->state == UNINDEX_STATE_COMPLETE)
+ ? uc->file_size : 0);
GNUNET_break (NULL == uc->client_info);
GNUNET_free (uc->filename);
GNUNET_free (uc);
Modified: gnunet/src/fs/fs_uri.c
===================================================================
--- gnunet/src/fs/fs_uri.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/fs/fs_uri.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -91,33 +91,33 @@
* @param uri uri to convert to a unique key
* @param key wherer to store the unique key
*/
-void
-GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri,
- GNUNET_HashCode * key)
+void
+GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri, GNUNET_HashCode * key)
{
switch (uri->type)
- {
- case chk:
- *key = uri->data.chk.chk.query;
- return;
- case sks:
- GNUNET_CRYPTO_hash (uri->data.sks.identifier,
- strlen (uri->data.sks.identifier), key);
- break;
- case ksk:
- if (uri->data.ksk.keywordCount > 0)
- GNUNET_CRYPTO_hash (uri->data.ksk.keywords[0],
- strlen (uri->data.ksk.keywords[0]), key);
- break;
- case loc:
- GNUNET_CRYPTO_hash (&uri->data.loc.fi,
- sizeof (struct FileIdentifier) +
- sizeof (struct
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), key);
- break;
- default:
- memset (key, 0, sizeof (GNUNET_HashCode));
- break;
- }
+ {
+ case chk:
+ *key = uri->data.chk.chk.query;
+ return;
+ case sks:
+ GNUNET_CRYPTO_hash (uri->data.sks.identifier,
+ strlen (uri->data.sks.identifier), key);
+ break;
+ case ksk:
+ if (uri->data.ksk.keywordCount > 0)
+ GNUNET_CRYPTO_hash (uri->data.ksk.keywords[0],
+ strlen (uri->data.ksk.keywords[0]), key);
+ break;
+ case loc:
+ GNUNET_CRYPTO_hash (&uri->data.loc.fi,
+ sizeof (struct FileIdentifier) +
+ sizeof (struct
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+ key);
+ break;
+ default:
+ memset (key, 0, sizeof (GNUNET_HashCode));
+ break;
+ }
}
@@ -139,45 +139,45 @@
unsigned int keywordCount;
if ((uri == NULL) || (uri->type != ksk))
- {
- GNUNET_break (0);
- return NULL;
- }
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
keywords = uri->data.ksk.keywords;
keywordCount = uri->data.ksk.keywordCount;
n = keywordCount + 1;
for (i = 0; i < keywordCount; i++)
- {
- keyword = keywords[i];
- n += strlen (keyword) - 1;
- if (NULL != strstr (&keyword[1], " "))
- n += 2;
- if (keyword[0] == '+')
- n++;
- }
+ {
+ keyword = keywords[i];
+ n += strlen (keyword) - 1;
+ if (NULL != strstr (&keyword[1], " "))
+ n += 2;
+ if (keyword[0] == '+')
+ n++;
+ }
ret = GNUNET_malloc (n);
strcpy (ret, "");
for (i = 0; i < keywordCount; i++)
+ {
+ keyword = keywords[i];
+ if (NULL != strstr (&keyword[1], " "))
{
- keyword = keywords[i];
- if (NULL != strstr (&keyword[1], " "))
- {
- strcat (ret, "\"");
- if (keyword[0] == '+')
- strcat (ret, keyword);
- else
- strcat (ret, &keyword[1]);
- strcat (ret, "\"");
- }
+ strcat (ret, "\"");
+ if (keyword[0] == '+')
+ strcat (ret, keyword);
else
- {
- if (keyword[0] == '+')
- strcat (ret, keyword);
- else
- strcat (ret, &keyword[1]);
- }
- strcat (ret, " ");
+ strcat (ret, &keyword[1]);
+ strcat (ret, "\"");
}
+ else
+ {
+ if (keyword[0] == '+')
+ strcat (ret, keyword);
+ else
+ strcat (ret, &keyword[1]);
+ }
+ strcat (ret, " ");
+ }
return ret;
}
@@ -205,37 +205,37 @@
rpos = 0;
wpos = 0;
while (out[rpos] != '\0')
+ {
+ if (out[rpos] == '%')
{
- if (out[rpos] == '%')
- {
- if (1 != sscanf (&out[rpos + 1], "%2X", &hx))
- {
- GNUNET_free (out);
- *emsg = GNUNET_strdup (_("`%' must be followed by HEX number"));
- return NULL;
- }
- rpos += 3;
- if (hx == '"')
- continue; /* skip double quote */
- out[wpos++] = (char) hx;
- }
- else
- {
- out[wpos++] = out[rpos++];
- }
+ if (1 != sscanf (&out[rpos + 1], "%2X", &hx))
+ {
+ GNUNET_free (out);
+ *emsg = GNUNET_strdup (_("`%' must be followed by HEX number"));
+ return NULL;
+ }
+ rpos += 3;
+ if (hx == '"')
+ continue; /* skip double quote */
+ out[wpos++] = (char) hx;
}
- out[wpos] = '\0';
- if (out[0] == '+')
+ else
{
- ret = GNUNET_strdup (out);
+ out[wpos++] = out[rpos++];
}
+ }
+ out[wpos] = '\0';
+ if (out[0] == '+')
+ {
+ ret = GNUNET_strdup (out);
+ }
else
- {
- /* need to prefix with space */
- ret = GNUNET_malloc (strlen (out) + 2);
- strcpy (ret, " ");
- strcat (ret, out);
- }
+ {
+ /* need to prefix with space */
+ ret = GNUNET_malloc (strlen (out) + 2);
+ strcpy (ret, " ");
+ strcat (ret, out);
+ }
GNUNET_free (out);
return ret;
}
@@ -265,66 +265,64 @@
GNUNET_assert (s != NULL);
slen = strlen (s);
pos = strlen (GNUNET_FS_URI_KSK_PREFIX);
- if ( (slen <= pos) ||
- (0 != strncmp (s, GNUNET_FS_URI_KSK_PREFIX,
- pos) ) )
- return NULL; /* not KSK URI */
- if ( (s[slen - 1] == '+') ||
- (s[pos] == '+') )
- {
- *emsg = GNUNET_strdup (_("Malformed KSK URI (must not begin or end with
`+')"));
- return NULL;
- }
+ if ((slen <= pos) || (0 != strncmp (s, GNUNET_FS_URI_KSK_PREFIX, pos)))
+ return NULL; /* not KSK URI */
+ if ((s[slen - 1] == '+') || (s[pos] == '+'))
+ {
+ *emsg =
+ GNUNET_strdup (_("Malformed KSK URI (must not begin or end with
`+')"));
+ return NULL;
+ }
max = 1;
saw_quote = 0;
for (i = pos; i < slen; i++)
+ {
+ if ((s[i] == '%') && (&s[i] == strstr (&s[i], "%22")))
{
- if ((s[i] == '%') && (&s[i] == strstr (&s[i], "%22")))
- {
- saw_quote = (saw_quote + 1) % 2;
- i += 3;
- continue;
- }
- if ((s[i] == '+') && (saw_quote == 0))
- {
- max++;
- if (s[i - 1] == '+')
- {
- *emsg = GNUNET_strdup (_("`++' not allowed in KSK URI"));
- return NULL;
- }
- }
+ saw_quote = (saw_quote + 1) % 2;
+ i += 3;
+ continue;
}
- if (saw_quote == 1)
+ if ((s[i] == '+') && (saw_quote == 0))
{
- *emsg = GNUNET_strdup (_("Quotes not balanced in KSK URI"));
- return NULL;
+ max++;
+ if (s[i - 1] == '+')
+ {
+ *emsg = GNUNET_strdup (_("`++' not allowed in KSK URI"));
+ return NULL;
+ }
}
+ }
+ if (saw_quote == 1)
+ {
+ *emsg = GNUNET_strdup (_("Quotes not balanced in KSK URI"));
+ return NULL;
+ }
iret = max;
dup = GNUNET_strdup (s);
keywords = GNUNET_malloc (max * sizeof (char *));
for (i = slen - 1; i >= pos; i--)
+ {
+ if ((s[i] == '%') && (&s[i] == strstr (&s[i], "%22")))
{
- if ((s[i] == '%') && (&s[i] == strstr (&s[i], "%22")))
- {
- saw_quote = (saw_quote + 1) % 2;
- i += 3;
- continue;
- }
- if ((dup[i] == '+') && (saw_quote == 0))
- {
- keywords[--max] = percent_decode_keyword (&dup[i + 1], emsg);
- if (NULL == keywords[max])
- goto CLEANUP;
- dup[i] = '\0';
- }
+ saw_quote = (saw_quote + 1) % 2;
+ i += 3;
+ continue;
}
+ if ((dup[i] == '+') && (saw_quote == 0))
+ {
+ keywords[--max] = percent_decode_keyword (&dup[i + 1], emsg);
+ if (NULL == keywords[max])
+ goto CLEANUP;
+ dup[i] = '\0';
+ }
+ }
keywords[--max] = percent_decode_keyword (&dup[pos], emsg);
if (NULL == keywords[max])
goto CLEANUP;
GNUNET_assert (max == 0);
GNUNET_free (dup);
- ret = GNUNET_malloc (sizeof(struct GNUNET_FS_Uri));
+ ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
ret->type = ksk;
ret->data.ksk.keywordCount = iret;
ret->data.ksk.keywords = keywords;
@@ -355,30 +353,29 @@
char *identifier;
unsigned int pos;
size_t slen;
- char enc[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)];
+ char enc[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)];
GNUNET_assert (s != NULL);
slen = strlen (s);
- pos = strlen ( GNUNET_FS_URI_SKS_PREFIX);
- if ( (slen <= pos) ||
- (0 != strncmp (s, GNUNET_FS_URI_SKS_PREFIX,
- pos) ) )
- return NULL; /* not an SKS URI */
- if ( (slen < pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)) ||
- (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '/') )
- {
- *emsg = GNUNET_strdup (_("Malformed SKS URI"));
- return NULL;
- }
- memcpy (enc, &s[pos], sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded));
- enc[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)-1] = '\0';
+ pos = strlen (GNUNET_FS_URI_SKS_PREFIX);
+ if ((slen <= pos) || (0 != strncmp (s, GNUNET_FS_URI_SKS_PREFIX, pos)))
+ return NULL; /* not an SKS URI */
+ if ((slen < pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)) ||
+ (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '/'))
+ {
+ *emsg = GNUNET_strdup (_("Malformed SKS URI"));
+ return NULL;
+ }
+ memcpy (enc, &s[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded));
+ enc[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0';
if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (enc, &namespace))
- {
- *emsg = GNUNET_strdup (_("Malformed SKS URI"));
- return NULL;
- }
- identifier = GNUNET_strdup (&s[pos + sizeof (struct
GNUNET_CRYPTO_HashAsciiEncoded)]);
- ret = GNUNET_malloc (sizeof(struct GNUNET_FS_Uri));
+ {
+ *emsg = GNUNET_strdup (_("Malformed SKS URI"));
+ return NULL;
+ }
+ identifier =
+ GNUNET_strdup (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)]);
+ ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
ret->type = sks;
ret->data.sks.namespace = namespace;
ret->data.sks.identifier = identifier;
@@ -403,46 +400,43 @@
unsigned int pos;
unsigned long long flen;
size_t slen;
- char h1[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)];
- char h2[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)];
+ char h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)];
+ char h2[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)];
if (NULL == s)
return NULL;
GNUNET_assert (s != NULL);
slen = strlen (s);
pos = strlen (GNUNET_FS_URI_CHK_PREFIX);
- if ( (slen < pos + 2 * sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) ||
- (0 != strncmp (s, GNUNET_FS_URI_CHK_PREFIX,
- pos) ) )
- return NULL; /* not a CHK URI */
- if ( (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '.') ||
- (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2 - 1] !=
'.') )
- {
- *emsg = GNUNET_strdup (_("Malformed CHK URI"));
- return NULL;
- }
- memcpy (h1,
- &s[pos],
- sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded));
- h1[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)-1] = '\0';
+ if ((slen < pos + 2 * sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) ||
+ (0 != strncmp (s, GNUNET_FS_URI_CHK_PREFIX, pos)))
+ return NULL; /* not a CHK URI */
+ if ((s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '.') ||
+ (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2 - 1] != '.'))
+ {
+ *emsg = GNUNET_strdup (_("Malformed CHK URI"));
+ return NULL;
+ }
+ memcpy (h1, &s[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded));
+ h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0';
memcpy (h2,
- &s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)],
- sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded));
- h2[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)-1] = '\0';
-
+ &s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)],
+ sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded));
+ h2[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0';
+
if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h1,
- &fi.chk.key)) ||
+ &fi.chk.key)) ||
(GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h2,
- &fi.chk.query)) ||
- (1 != SSCANF (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) *
2],
- "%llu",
- &flen)) )
- {
- *emsg = GNUNET_strdup (_("Malformed CHK URI"));
- return NULL;
- }
+ &fi.chk.query)) ||
+ (1 !=
+ SSCANF (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2],
+ "%llu", &flen)))
+ {
+ *emsg = GNUNET_strdup (_("Malformed CHK URI"));
+ return NULL;
+ }
fi.file_length = GNUNET_htonll (flen);
- ret = GNUNET_malloc (sizeof(struct GNUNET_FS_Uri));
+ ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
ret->type = chk;
ret->data.chk = fi;
return ret;
@@ -499,16 +493,16 @@
hbits = 0;
len = 0;
for (pos = 0; pos < size; pos++)
+ {
+ while (hbits < 8)
{
- while (hbits < 8)
- {
- bits |= (c2v (input[len++]) << hbits);
- hbits += 6;
- }
- (((unsigned char *) data)[pos]) = (unsigned char) bits;
- bits >>= 8;
- hbits -= 8;
+ bits |= (c2v (input[len++]) << hbits);
+ hbits += 6;
}
+ (((unsigned char *) data)[pos]) = (unsigned char) bits;
+ bits >>= 8;
+ hbits -= 8;
+ }
return len;
}
@@ -520,14 +514,14 @@
* verify the signature of a location
* URI.
*/
-struct LocUriAssembly
+struct LocUriAssembly
{
struct GNUNET_CRYPTO_RsaSignaturePurpose purpose;
struct GNUNET_TIME_AbsoluteNBO exptime;
struct FileIdentifier fi;
-
+
struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded peer;
};
@@ -547,8 +541,8 @@
uri_loc_parse (const char *s, char **emsg)
{
struct GNUNET_FS_Uri *uri;
- char h1[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)];
- char h2[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)];
+ char h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)];
+ char h2[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)];
unsigned int pos;
unsigned int npos;
unsigned long long exptime;
@@ -561,95 +555,92 @@
GNUNET_assert (s != NULL);
slen = strlen (s);
- pos = strlen ( GNUNET_FS_URI_LOC_PREFIX);
- if ( (slen < pos + 2 * sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) ||
- (0 != strncmp (s, GNUNET_FS_URI_LOC_PREFIX,
- pos) ) )
- return NULL; /* not an SKS URI */
- if ( (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '.') ||
- (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2 - 1] !=
'.') )
- {
- *emsg = GNUNET_strdup (_("SKS URI malformed"));
- return NULL;
- }
- memcpy (h1,
- &s[pos],
- sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded));
- h1[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)-1] = '\0';
+ pos = strlen (GNUNET_FS_URI_LOC_PREFIX);
+ if ((slen < pos + 2 * sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) ||
+ (0 != strncmp (s, GNUNET_FS_URI_LOC_PREFIX, pos)))
+ return NULL; /* not an SKS URI */
+ if ((s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '.') ||
+ (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2 - 1] != '.'))
+ {
+ *emsg = GNUNET_strdup (_("SKS URI malformed"));
+ return NULL;
+ }
+ memcpy (h1, &s[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded));
+ h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0';
memcpy (h2,
- &s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)],
- sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded));
- h2[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)-1] = '\0';
-
+ &s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)],
+ sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded));
+ h2[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0';
+
if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h1,
- &ass.fi.chk.key)) ||
+ &ass.fi.chk.key)) ||
(GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h2,
- &ass.fi.chk.query)) ||
- (1 != SSCANF (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) *
2],
- "%llu",
- &flen)) )
- {
- *emsg = GNUNET_strdup (_("SKS URI malformed"));
- return NULL;
- }
+ &ass.fi.chk.query)) ||
+ (1 !=
+ SSCANF (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2],
+ "%llu", &flen)))
+ {
+ *emsg = GNUNET_strdup (_("SKS URI malformed"));
+ return NULL;
+ }
ass.fi.file_length = GNUNET_htonll (flen);
npos = pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2;
while ((s[npos] != '\0') && (s[npos] != '.'))
npos++;
if (s[npos] == '\0')
- {
- *emsg = GNUNET_strdup (_("SKS URI malformed"));
- goto ERR;
- }
+ {
+ *emsg = GNUNET_strdup (_("SKS URI malformed"));
+ goto ERR;
+ }
npos++;
- ret = enc2bin (&s[npos],
- &ass.peer,
- sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
+ ret = enc2bin (&s[npos],
+ &ass.peer,
+ sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
if (ret == -1)
- {
- *emsg = GNUNET_strdup (_("SKS URI malformed (could not decode public
key)"));
- goto ERR;
- }
+ {
+ *emsg =
+ GNUNET_strdup (_("SKS URI malformed (could not decode public key)"));
+ goto ERR;
+ }
npos += ret;
if (s[npos++] != '.')
- {
- *emsg = GNUNET_strdup (_("SKS URI malformed (could not find
signature)"));
- goto ERR;
- }
- ret = enc2bin (&s[npos],
- &sig,
- sizeof (struct GNUNET_CRYPTO_RsaSignature));
+ {
+ *emsg = GNUNET_strdup (_("SKS URI malformed (could not find signature)"));
+ goto ERR;
+ }
+ ret = enc2bin (&s[npos], &sig, sizeof (struct GNUNET_CRYPTO_RsaSignature));
if (ret == -1)
- {
- *emsg = GNUNET_strdup (_("SKS URI malformed (could not decode
signature)"));
- goto ERR;
- }
- npos += ret;
+ {
+ *emsg = GNUNET_strdup (_("SKS URI malformed (could not decode
signature)"));
+ goto ERR;
+ }
+ npos += ret;
if (s[npos++] != '.')
- {
- *emsg = GNUNET_strdup (_("SKS URI malformed"));
- goto ERR;
- }
+ {
+ *emsg = GNUNET_strdup (_("SKS URI malformed"));
+ goto ERR;
+ }
if (1 != SSCANF (&s[npos], "%llu", &exptime))
- {
- *emsg = GNUNET_strdup (_("SKS URI malformed (could not parse expiration
time)"));
- goto ERR;
- }
- ass.purpose.size = htonl(sizeof(struct LocUriAssembly));
- ass.purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT);
+ {
+ *emsg =
+ GNUNET_strdup (_
+ ("SKS URI malformed (could not parse expiration
time)"));
+ goto ERR;
+ }
+ ass.purpose.size = htonl (sizeof (struct LocUriAssembly));
+ ass.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT);
et.abs_value = exptime;
ass.exptime = GNUNET_TIME_absolute_hton (et);
- if (GNUNET_OK !=
+ if (GNUNET_OK !=
GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT,
- &ass.purpose,
- &sig,
- &ass.peer))
- {
- *emsg = GNUNET_strdup (_("SKS URI malformed (signature failed
validation)"));
- goto ERR;
- }
- uri = GNUNET_malloc (sizeof(struct GNUNET_FS_Uri));
+ &ass.purpose, &sig, &ass.peer))
+ {
+ *emsg =
+ GNUNET_strdup (_("SKS URI malformed (signature failed validation)"));
+ goto ERR;
+ }
+ uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
uri->type = loc;
uri->data.loc.fi = ass.fi;
uri->data.loc.peer = ass.peer;
@@ -670,8 +661,7 @@
* @return NULL on error
*/
struct GNUNET_FS_Uri *
-GNUNET_FS_uri_parse (const char *uri,
- char **emsg)
+GNUNET_FS_uri_parse (const char *uri, char **emsg)
{
struct GNUNET_FS_Uri *ret;
char *msg;
@@ -679,10 +669,10 @@
if (NULL == emsg)
emsg = &msg;
*emsg = NULL;
- if ( (NULL != (ret = uri_chk_parse (uri, emsg))) ||
- (NULL != (ret = uri_ksk_parse (uri, emsg))) ||
- (NULL != (ret = uri_sks_parse (uri, emsg))) ||
- (NULL != (ret = uri_loc_parse (uri, emsg))) )
+ if ((NULL != (ret = uri_chk_parse (uri, emsg))) ||
+ (NULL != (ret = uri_ksk_parse (uri, emsg))) ||
+ (NULL != (ret = uri_sks_parse (uri, emsg))) ||
+ (NULL != (ret = uri_loc_parse (uri, emsg))))
return ret;
if (NULL == *emsg)
*emsg = GNUNET_strdup (_("Unrecognized URI type"));
@@ -697,29 +687,28 @@
*
* @param uri uri to free
*/
-void
+void
GNUNET_FS_uri_destroy (struct GNUNET_FS_Uri *uri)
{
unsigned int i;
GNUNET_assert (uri != NULL);
switch (uri->type)
- {
- case ksk:
- for (i = 0; i < uri->data.ksk.keywordCount; i++)
- GNUNET_free (uri->data.ksk.keywords[i]);
- GNUNET_array_grow (uri->data.ksk.keywords, uri->data.ksk.keywordCount,
- 0);
- break;
- case sks:
- GNUNET_free (uri->data.sks.identifier);
- break;
- case loc:
- break;
- default:
- /* do nothing */
- break;
- }
+ {
+ case ksk:
+ for (i = 0; i < uri->data.ksk.keywordCount; i++)
+ GNUNET_free (uri->data.ksk.keywords[i]);
+ GNUNET_array_grow (uri->data.ksk.keywords, uri->data.ksk.keywordCount, 0);
+ break;
+ case sks:
+ GNUNET_free (uri->data.sks.identifier);
+ break;
+ case loc:
+ break;
+ default:
+ /* do nothing */
+ break;
+ }
GNUNET_free (uri);
}
@@ -729,7 +718,7 @@
* @param uri ksk uri to get the number of keywords from
* @return 0 if this is not a keyword URI
*/
-unsigned int
+unsigned int
GNUNET_FS_uri_ksk_get_keyword_count (const struct GNUNET_FS_Uri *uri)
{
if (uri->type != ksk)
@@ -747,10 +736,10 @@
* @return -1 if this is not a keyword URI, otherwise number of
* keywords iterated over until iterator aborted
*/
-int
+int
GNUNET_FS_uri_ksk_get_keywords (const struct GNUNET_FS_Uri *uri,
- GNUNET_FS_KeywordIterator iterator,
- void *iterator_cls)
+ GNUNET_FS_KeywordIterator iterator,
+ void *iterator_cls)
{
unsigned int i;
char *keyword;
@@ -760,15 +749,13 @@
if (iterator == NULL)
return uri->data.ksk.keywordCount;
for (i = 0; i < uri->data.ksk.keywordCount; i++)
- {
- keyword = uri->data.ksk.keywords[i];
- /* first character of keyword indicates
- if it is mandatory or not */
- if (GNUNET_OK != iterator (iterator_cls,
- &keyword[1],
- keyword[0] == '+'))
- return i;
- }
+ {
+ keyword = uri->data.ksk.keywords[i];
+ /* first character of keyword indicates
+ * if it is mandatory or not */
+ if (GNUNET_OK != iterator (iterator_cls, &keyword[1], keyword[0] == '+'))
+ return i;
+ }
return i;
}
@@ -783,8 +770,7 @@
*/
void
GNUNET_FS_uri_ksk_add_keyword (struct GNUNET_FS_Uri *uri,
- const char *keyword,
- int is_mandatory)
+ const char *keyword, int is_mandatory)
{
unsigned int i;
const char *old;
@@ -792,17 +778,13 @@
GNUNET_assert (uri->type == ksk);
for (i = 0; i < uri->data.ksk.keywordCount; i++)
- {
- old = uri->data.ksk.keywords[i];
- if (0 == strcmp (&old[1], keyword))
- return;
- }
- GNUNET_asprintf (&n,
- is_mandatory ? "+%s" : " %s",
- keyword);
- GNUNET_array_append (uri->data.ksk.keywords,
- uri->data.ksk.keywordCount,
- n);
+ {
+ old = uri->data.ksk.keywords[i];
+ if (0 == strcmp (&old[1], keyword))
+ return;
+ }
+ GNUNET_asprintf (&n, is_mandatory ? "+%s" : " %s", keyword);
+ GNUNET_array_append (uri->data.ksk.keywords, uri->data.ksk.keywordCount, n);
}
@@ -815,25 +797,25 @@
*/
void
GNUNET_FS_uri_ksk_remove_keyword (struct GNUNET_FS_Uri *uri,
- const char *keyword)
+ const char *keyword)
{
unsigned int i;
char *old;
GNUNET_assert (uri->type == ksk);
for (i = 0; i < uri->data.ksk.keywordCount; i++)
+ {
+ old = uri->data.ksk.keywords[i];
+ if (0 == strcmp (&old[1], keyword))
{
- old = uri->data.ksk.keywords[i];
- if (0 == strcmp (&old[1], keyword))
- {
- uri->data.ksk.keywords[i] =
uri->data.ksk.keywords[uri->data.ksk.keywordCount-1];
- GNUNET_array_grow (uri->data.ksk.keywords,
- uri->data.ksk.keywordCount,
- uri->data.ksk.keywordCount - 1);
- GNUNET_free (old);
- return;
- }
+ uri->data.ksk.keywords[i] =
+ uri->data.ksk.keywords[uri->data.ksk.keywordCount - 1];
+ GNUNET_array_grow (uri->data.ksk.keywords, uri->data.ksk.keywordCount,
+ uri->data.ksk.keywordCount - 1);
+ GNUNET_free (old);
+ return;
}
+ }
}
@@ -846,13 +828,13 @@
*/
int
GNUNET_FS_uri_loc_get_peer_identity (const struct GNUNET_FS_Uri *uri,
- struct GNUNET_PeerIdentity * peer)
+ struct GNUNET_PeerIdentity *peer)
{
if (uri->type != loc)
return GNUNET_SYSERR;
GNUNET_CRYPTO_hash (&uri->data.loc.peer,
- sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
- &peer->hashPubKey);
+ sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+ &peer->hashPubKey);
return GNUNET_OK;
}
@@ -867,7 +849,7 @@
GNUNET_FS_uri_loc_get_expiration (const struct GNUNET_FS_Uri *uri)
{
GNUNET_assert (uri->type == loc);
- return uri->data.loc.expirationTime;
+ return uri->data.loc.expirationTime;
}
@@ -902,11 +884,11 @@
*/
struct GNUNET_FS_Uri *
GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *baseUri,
- const struct GNUNET_CONFIGURATION_Handle *cfg,
- struct GNUNET_TIME_Absolute expiration_time)
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ struct GNUNET_TIME_Absolute expiration_time)
{
struct GNUNET_FS_Uri *uri;
- struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key;
+ struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key;
struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded my_public_key;
char *keyfile;
struct LocUriAssembly ass;
@@ -915,27 +897,24 @@
return NULL;
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_filename (cfg,
- "GNUNETD",
- "HOSTKEY", &keyfile))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _
- ("Lacking key configuration settings.\n"));
- return NULL;
- }
+ "GNUNETD", "HOSTKEY", &keyfile))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Lacking key configuration settings.\n"));
+ return NULL;
+ }
my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
if (my_private_key == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Could not access hostkey file `%s'.\n"),
- keyfile);
- GNUNET_free (keyfile);
- return NULL;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Could not access hostkey file `%s'.\n"), keyfile);
+ GNUNET_free (keyfile);
+ return NULL;
+ }
GNUNET_free (keyfile);
GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key);
- ass.purpose.size = htonl(sizeof(struct LocUriAssembly));
- ass.purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT);
+ ass.purpose.size = htonl (sizeof (struct LocUriAssembly));
+ ass.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT);
ass.exptime = GNUNET_TIME_absolute_hton (expiration_time);
ass.fi = baseUri->data.chk;
ass.peer = my_public_key;
@@ -945,9 +924,9 @@
uri->data.loc.expirationTime = expiration_time;
uri->data.loc.peer = my_public_key;
GNUNET_assert (GNUNET_OK ==
- GNUNET_CRYPTO_rsa_sign (my_private_key,
- &ass.purpose,
- &uri->data.loc.contentSignature));
+ GNUNET_CRYPTO_rsa_sign (my_private_key,
+ &ass.purpose,
+ &uri->data.loc.contentSignature));
GNUNET_CRYPTO_rsa_key_free (my_private_key);
return uri;
}
@@ -963,19 +942,15 @@
*/
struct GNUNET_FS_Uri *
GNUNET_FS_uri_sks_create (struct GNUNET_FS_Namespace *ns,
- const char *id,
- char **emsg)
+ const char *id, char **emsg)
{
struct GNUNET_FS_Uri *ns_uri;
struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pk;
-
+
ns_uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
ns_uri->type = sks;
- GNUNET_CRYPTO_rsa_key_get_public (ns->key,
- &pk);
- GNUNET_CRYPTO_hash (&pk,
- sizeof (pk),
- &ns_uri->data.sks.namespace);
+ GNUNET_CRYPTO_rsa_key_get_public (ns->key, &pk);
+ GNUNET_CRYPTO_hash (&pk, sizeof (pk), &ns_uri->data.sks.namespace);
ns_uri->data.sks.identifier = GNUNET_strdup (id);
return ns_uri;
}
@@ -989,11 +964,10 @@
* @return an FS URI for the given namespace and identifier
*/
struct GNUNET_FS_Uri *
-GNUNET_FS_uri_sks_create_from_nsid (GNUNET_HashCode *nsid,
- const char *id)
+GNUNET_FS_uri_sks_create_from_nsid (GNUNET_HashCode * nsid, const char *id)
{
struct GNUNET_FS_Uri *ns_uri;
-
+
ns_uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
ns_uri->type = sks;
ns_uri->data.sks.namespace = *nsid;
@@ -1019,60 +993,60 @@
wpos = ret;
rpos = in;
while ('\0' != *rpos)
+ {
+ switch (tolower ((unsigned char) *rpos))
{
- switch (tolower( (unsigned char) *rpos))
- {
- case 'a':
- case 'e':
- case 'i':
- case 'o':
- case 'u':
- case ' ':
- case '\t':
- case '\n':
- case '\r':
- /* skip characters listed above */
- break;
- case 'b':
- case 'c':
- case 'd':
- case 'f':
- case 'g':
- case 'h':
- case 'j':
- case 'k':
- case 'l':
- case 'm':
- case 'n':
- case 'p':
- case 'r':
- case 's':
- case 't':
- case 'v':
- case 'w':
- case 'x':
- case 'y':
- case 'z':
- /* convert characters listed above to lower case */
- *wpos = tolower( (unsigned char)*rpos);
- wpos++;
- break;
- case '!':
- case '.':
- case '?':
- case '-':
- /* keep characters listed above without changes */
- *wpos = *rpos;
- wpos++;
- break;
- default:
- /* replace characters listed above with '_' */
- *wpos = '_';
- wpos++;
- break;
- }
- rpos++;
+ case 'a':
+ case 'e':
+ case 'i':
+ case 'o':
+ case 'u':
+ case ' ':
+ case '\t':
+ case '\n':
+ case '\r':
+ /* skip characters listed above */
+ break;
+ case 'b':
+ case 'c':
+ case 'd':
+ case 'f':
+ case 'g':
+ case 'h':
+ case 'j':
+ case 'k':
+ case 'l':
+ case 'm':
+ case 'n':
+ case 'p':
+ case 'r':
+ case 's':
+ case 't':
+ case 'v':
+ case 'w':
+ case 'x':
+ case 'y':
+ case 'z':
+ /* convert characters listed above to lower case */
+ *wpos = tolower ((unsigned char) *rpos);
+ wpos++;
+ break;
+ case '!':
+ case '.':
+ case '?':
+ case '-':
+ /* keep characters listed above without changes */
+ *wpos = *rpos;
+ wpos++;
+ break;
+ default:
+ /* replace characters listed above with '_' */
+ *wpos = '_';
+ wpos++;
+ break;
}
+ rpos++;
+ }
return ret;
}
@@ -1094,10 +1068,10 @@
char **kl;
kc = uri->data.ksk.keywordCount;
- kl = GNUNET_malloc (kc*sizeof(char*));
- for (i=0;i<kc;i++)
+ kl = GNUNET_malloc (kc * sizeof (char *));
+ for (i = 0; i < kc; i++)
kl[i] = canonicalize_keyword (uri->data.ksk.keywords[i]);
- ret = GNUNET_malloc (sizeof(struct GNUNET_FS_Uri));
+ ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
ret->type = ksk;
ret->data.ksk.keywordCount = kc;
ret->data.ksk.keywords = kl;
@@ -1116,7 +1090,7 @@
*/
struct GNUNET_FS_Uri *
GNUNET_FS_uri_ksk_merge (const struct GNUNET_FS_Uri *u1,
- const struct GNUNET_FS_Uri *u2)
+ const struct GNUNET_FS_Uri *u2)
{
struct GNUNET_FS_Uri *ret;
unsigned int kc;
@@ -1126,39 +1100,37 @@
const char *kp;
char **kl;
- if ( (u1 == NULL) && (u2 == NULL) )
+ if ((u1 == NULL) && (u2 == NULL))
return NULL;
if (u1 == NULL)
return GNUNET_FS_uri_dup (u2);
if (u2 == NULL)
return GNUNET_FS_uri_dup (u1);
- if ( (u1->type != ksk) ||
- (u2->type != ksk) )
- {
- GNUNET_break (0);
- return NULL;
- }
+ if ((u1->type != ksk) || (u2->type != ksk))
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
kc = u1->data.ksk.keywordCount;
- kl = GNUNET_malloc ((kc+u2->data.ksk.keywordCount)*sizeof(char*));
- for (i=0;i<u1->data.ksk.keywordCount;i++)
+ kl = GNUNET_malloc ((kc + u2->data.ksk.keywordCount) * sizeof (char *));
+ for (i = 0; i < u1->data.ksk.keywordCount; i++)
kl[i] = GNUNET_strdup (u1->data.ksk.keywords[i]);
- for (i=0;i<u2->data.ksk.keywordCount;i++)
- {
- kp = u2->data.ksk.keywords[i];
- found = 0;
- for (j=0;j<u1->data.ksk.keywordCount;j++)
- if (0 == strcmp(kp + 1,
- kl[j]+1))
- {
- found = 1;
- if (kp[0] == '+')
- kl[j][0] = '+';
- break;
- }
- if (0 == found)
- kl[kc++] = GNUNET_strdup (kp);
- }
- ret = GNUNET_malloc (sizeof(struct GNUNET_FS_Uri));
+ for (i = 0; i < u2->data.ksk.keywordCount; i++)
+ {
+ kp = u2->data.ksk.keywords[i];
+ found = 0;
+ for (j = 0; j < u1->data.ksk.keywordCount; j++)
+ if (0 == strcmp (kp + 1, kl[j] + 1))
+ {
+ found = 1;
+ if (kp[0] == '+')
+ kl[j][0] = '+';
+ break;
+ }
+ if (0 == found)
+ kl[kc++] = GNUNET_strdup (kp);
+ }
+ ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
ret->type = ksk;
ret->data.ksk.keywordCount = kc;
ret->data.ksk.keywords = kl;
@@ -1183,33 +1155,33 @@
ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
memcpy (ret, uri, sizeof (struct GNUNET_FS_Uri));
switch (ret->type)
+ {
+ case ksk:
+ if (ret->data.ksk.keywordCount >=
+ GNUNET_MAX_MALLOC_CHECKED / sizeof (char *))
{
- case ksk:
- if (ret->data.ksk.keywordCount >= GNUNET_MAX_MALLOC_CHECKED / sizeof
(char*))
- {
- GNUNET_break (0);
- GNUNET_free (ret);
- return NULL;
- }
- if (ret->data.ksk.keywordCount > 0)
- {
- ret->data.ksk.keywords
- = GNUNET_malloc (ret->data.ksk.keywordCount * sizeof (char *));
- for (i = 0; i < ret->data.ksk.keywordCount; i++)
- ret->data.ksk.keywords[i] =
- GNUNET_strdup (uri->data.ksk.keywords[i]);
- }
- else
- ret->data.ksk.keywords = NULL; /* just to be sure */
- break;
- case sks:
- ret->data.sks.identifier = GNUNET_strdup (uri->data.sks.identifier);
- break;
- case loc:
- break;
- default:
- break;
+ GNUNET_break (0);
+ GNUNET_free (ret);
+ return NULL;
}
+ if (ret->data.ksk.keywordCount > 0)
+ {
+ ret->data.ksk.keywords
+ = GNUNET_malloc (ret->data.ksk.keywordCount * sizeof (char *));
+ for (i = 0; i < ret->data.ksk.keywordCount; i++)
+ ret->data.ksk.keywords[i] = GNUNET_strdup (uri->data.ksk.keywords[i]);
+ }
+ else
+ ret->data.ksk.keywords = NULL; /* just to be sure */
+ break;
+ case sks:
+ ret->data.sks.identifier = GNUNET_strdup (uri->data.sks.identifier);
+ break;
+ case loc:
+ break;
+ default:
+ break;
+ }
return ret;
}
@@ -1232,8 +1204,7 @@
* if keywords is not legal (i.e. empty).
*/
struct GNUNET_FS_Uri *
-GNUNET_FS_uri_ksk_create (const char *keywords,
- char **emsg)
+GNUNET_FS_uri_ksk_create (const char *keywords, char **emsg)
{
char **keywordarr;
unsigned int num_Words;
@@ -1244,67 +1215,67 @@
int saw_quote;
if (keywords == NULL)
- {
- *emsg = GNUNET_strdup (_("No keywords specified!\n"));
- GNUNET_break (0);
- return NULL;
- }
+ {
+ *emsg = GNUNET_strdup (_("No keywords specified!\n"));
+ GNUNET_break (0);
+ return NULL;
+ }
searchString = GNUNET_strdup (keywords);
num_Words = 0;
inWord = 0;
saw_quote = 0;
pos = searchString;
while ('\0' != *pos)
+ {
+ if ((saw_quote == 0) && (isspace ((unsigned char) *pos)))
{
- if ((saw_quote == 0) && (isspace ((unsigned char) *pos)))
- {
- inWord = 0;
- }
- else if (0 == inWord)
- {
- inWord = 1;
- ++num_Words;
- }
- if ('"' == *pos)
- saw_quote = (saw_quote + 1) % 2;
- pos++;
+ inWord = 0;
}
- if (num_Words == 0)
+ else if (0 == inWord)
{
- GNUNET_free (searchString);
- *emsg = GNUNET_strdup (_("No keywords specified!\n"));
- return NULL;
+ inWord = 1;
+ ++num_Words;
}
+ if ('"' == *pos)
+ saw_quote = (saw_quote + 1) % 2;
+ pos++;
+ }
+ if (num_Words == 0)
+ {
+ GNUNET_free (searchString);
+ *emsg = GNUNET_strdup (_("No keywords specified!\n"));
+ return NULL;
+ }
if (saw_quote != 0)
- {
- GNUNET_free (searchString);
- *emsg = GNUNET_strdup (_("Number of double-quotes not balanced!\n"));
- return NULL;
- }
+ {
+ GNUNET_free (searchString);
+ *emsg = GNUNET_strdup (_("Number of double-quotes not balanced!\n"));
+ return NULL;
+ }
keywordarr = GNUNET_malloc (num_Words * sizeof (char *));
num_Words = 0;
inWord = 0;
pos = searchString;
while ('\0' != *pos)
+ {
+ if ((saw_quote == 0) && (isspace ((unsigned char) *pos)))
{
- if ((saw_quote == 0) && (isspace ( (unsigned char) *pos)))
- {
- inWord = 0;
- *pos = '\0';
- }
- else if (0 == inWord)
- {
- keywordarr[num_Words] = pos;
- inWord = 1;
- ++num_Words;
- }
- if ('"' == *pos)
- saw_quote = (saw_quote + 1) % 2;
- pos++;
+ inWord = 0;
+ *pos = '\0';
}
+ else if (0 == inWord)
+ {
+ keywordarr[num_Words] = pos;
+ inWord = 1;
+ ++num_Words;
+ }
+ if ('"' == *pos)
+ saw_quote = (saw_quote + 1) % 2;
+ pos++;
+ }
uri =
- GNUNET_FS_uri_ksk_create_from_args (num_Words,
- (const char **) keywordarr);
+ GNUNET_FS_uri_ksk_create_from_args (num_Words,
+ (const char **) keywordarr);
GNUNET_free (keywordarr);
GNUNET_free (searchString);
return uri;
@@ -1329,8 +1300,7 @@
* if keywords is not legal (i.e. empty).
*/
struct GNUNET_FS_Uri *
-GNUNET_FS_uri_ksk_create_from_args (unsigned int argc,
- const char **argv)
+GNUNET_FS_uri_ksk_create_from_args (unsigned int argc, const char **argv)
{
unsigned int i;
struct GNUNET_FS_Uri *uri;
@@ -1343,12 +1313,13 @@
if (argc == 0)
return NULL;
/* allow URI to be given as one and only keyword and
- handle accordingly */
+ * handle accordingly */
emsg = NULL;
- if ( (argc == 1) &&
- (strlen(argv[0]) > strlen(GNUNET_FS_URI_PREFIX)) &&
- (0 == strncmp(argv[0], GNUNET_FS_URI_PREFIX,
strlen(GNUNET_FS_URI_PREFIX)) ) &&
- (NULL != (uri = GNUNET_FS_uri_parse(argv[0], &emsg)) ) )
+ if ((argc == 1) &&
+ (strlen (argv[0]) > strlen (GNUNET_FS_URI_PREFIX)) &&
+ (0 ==
+ strncmp (argv[0], GNUNET_FS_URI_PREFIX, strlen (GNUNET_FS_URI_PREFIX)))
+ && (NULL != (uri = GNUNET_FS_uri_parse (argv[0], &emsg))))
return uri;
GNUNET_free_non_null (emsg);
uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
@@ -1356,24 +1327,24 @@
uri->data.ksk.keywordCount = argc;
uri->data.ksk.keywords = GNUNET_malloc (argc * sizeof (char *));
for (i = 0; i < argc; i++)
+ {
+ keyword = argv[i];
+ if (keyword[0] == '+')
+ val = GNUNET_strdup (keyword);
+ else
+ GNUNET_asprintf (&val, " %s", keyword);
+ r = val;
+ w = val;
+ while ('\0' != *r)
{
- keyword = argv[i];
- if (keyword[0] == '+')
- val = GNUNET_strdup (keyword);
+ if ('"' == *r)
+ r++;
else
- GNUNET_asprintf (&val, " %s", keyword);
- r = val;
- w = val;
- while ('\0' != *r)
- {
- if ('"' == *r)
- r++;
- else
- *(w++) = *(r++);
- }
- *w = '\0';
- uri->data.ksk.keywords[i] = val;
+ *(w++) = *(r++);
}
+ *w = '\0';
+ uri->data.ksk.keywords[i] = val;
+ }
return uri;
}
@@ -1385,9 +1356,9 @@
* @param u2 the other URI
* @return GNUNET_YES if the URIs are equal
*/
-int
+int
GNUNET_FS_uri_test_equal (const struct GNUNET_FS_Uri *u1,
- const struct GNUNET_FS_Uri *u2)
+ const struct GNUNET_FS_Uri *u2)
{
int ret;
unsigned int i;
@@ -1398,53 +1369,50 @@
if (u1->type != u2->type)
return GNUNET_NO;
switch (u1->type)
- {
- case chk:
- if (0 == memcmp (&u1->data.chk,
- &u2->data.chk,
- sizeof (struct FileIdentifier)))
- return GNUNET_YES;
- return GNUNET_NO;
- case sks:
- if ((0 == memcmp (&u1->data.sks.namespace,
- &u2->data.sks.namespace,
- sizeof (GNUNET_HashCode))) &&
- (0 == strcmp (u1->data.sks.identifier,
- u2->data.sks.identifier)))
+ {
+ case chk:
+ if (0 == memcmp (&u1->data.chk,
+ &u2->data.chk, sizeof (struct FileIdentifier)))
+ return GNUNET_YES;
+ return GNUNET_NO;
+ case sks:
+ if ((0 == memcmp (&u1->data.sks.namespace,
+ &u2->data.sks.namespace,
+ sizeof (GNUNET_HashCode))) &&
+ (0 == strcmp (u1->data.sks.identifier, u2->data.sks.identifier)))
- return GNUNET_YES;
+ return GNUNET_YES;
+ return GNUNET_NO;
+ case ksk:
+ if (u1->data.ksk.keywordCount != u2->data.ksk.keywordCount)
return GNUNET_NO;
- case ksk:
- if (u1->data.ksk.keywordCount != u2->data.ksk.keywordCount)
- return GNUNET_NO;
- for (i = 0; i < u1->data.ksk.keywordCount; i++)
+ for (i = 0; i < u1->data.ksk.keywordCount; i++)
+ {
+ ret = GNUNET_NO;
+ for (j = 0; j < u2->data.ksk.keywordCount; j++)
+ {
+ if (0 == strcmp (u1->data.ksk.keywords[i], u2->data.ksk.keywords[j]))
{
- ret = GNUNET_NO;
- for (j = 0; j < u2->data.ksk.keywordCount; j++)
- {
- if (0 == strcmp (u1->data.ksk.keywords[i],
- u2->data.ksk.keywords[j]))
- {
- ret = GNUNET_YES;
- break;
- }
- }
- if (ret == GNUNET_NO)
- return GNUNET_NO;
+ ret = GNUNET_YES;
+ break;
}
- return GNUNET_YES;
- case loc:
- if (memcmp (&u1->data.loc,
- &u2->data.loc,
- sizeof (struct FileIdentifier) +
- sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) +
- sizeof (struct GNUNET_TIME_Absolute) +
- sizeof (unsigned short) + sizeof (unsigned short)) != 0)
+ }
+ if (ret == GNUNET_NO)
return GNUNET_NO;
- return GNUNET_YES;
- default:
- return GNUNET_NO;
}
+ return GNUNET_YES;
+ case loc:
+ if (memcmp (&u1->data.loc,
+ &u2->data.loc,
+ sizeof (struct FileIdentifier) +
+ sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) +
+ sizeof (struct GNUNET_TIME_Absolute) +
+ sizeof (unsigned short) + sizeof (unsigned short)) != 0)
+ return GNUNET_NO;
+ return GNUNET_YES;
+ default:
+ return GNUNET_NO;
+ }
}
@@ -1469,15 +1437,15 @@
* @param nsid where to store the ID of the namespace
* @return GNUNET_OK on success
*/
-int
+int
GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri,
- GNUNET_HashCode * nsid)
+ GNUNET_HashCode * nsid)
{
- if (! GNUNET_FS_uri_test_sks (uri))
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
+ if (!GNUNET_FS_uri_test_sks (uri))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
*nsid = uri->data.sks.namespace;
return GNUNET_OK;
}
@@ -1493,10 +1461,10 @@
GNUNET_FS_uri_sks_get_content_id (const struct GNUNET_FS_Uri *uri)
{
if (!GNUNET_FS_uri_test_sks (uri))
- {
- GNUNET_break (0);
- return NULL;
- }
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
return GNUNET_strdup (uri->data.sks.identifier);
}
@@ -1511,7 +1479,7 @@
*/
char *
GNUNET_FS_uri_sks_to_string_fancy (struct GNUNET_CONFIGURATION_Handle *cfg,
- const struct GNUNET_FS_Uri *uri)
+ const struct GNUNET_FS_Uri *uri)
{
char *ret;
char *name;
@@ -1521,10 +1489,7 @@
name = GNUNET_PSEUDONYM_id_to_name (cfg, &uri->data.sks.namespace);
if (name == NULL)
return GNUNET_FS_uri_to_string (uri);
- GNUNET_asprintf (&ret,
- "%s: %s",
- name,
- uri->data.sks.identifier);
+ GNUNET_asprintf (&ret, "%s: %s", name, uri->data.sks.identifier);
GNUNET_free (name);
return ret;
}
@@ -1536,17 +1501,17 @@
* @param uri the uri
* @return GNUNET_YES if this is a KSK uri
*/
-int
+int
GNUNET_FS_uri_test_ksk (const struct GNUNET_FS_Uri *uri)
{
#if EXTRA_CHECKS
unsigned int i;
if (uri->type == ksk)
- {
- for (i = uri->data.ksk.keywordCount - 1; i >= 0; i--)
- GNUNET_assert (uri->data.ksk.keywords[i] != NULL);
- }
+ {
+ for (i = uri->data.ksk.keywordCount - 1; i >= 0; i--)
+ GNUNET_assert (uri->data.ksk.keywords[i] != NULL);
+ }
#endif
return uri->type == ksk;
}
@@ -1558,7 +1523,7 @@
* @param uri the uri to check
* @return GNUNET_YES if this is a CHK uri
*/
-int
+int
GNUNET_FS_uri_test_chk (const struct GNUNET_FS_Uri *uri)
{
return uri->type == chk;
@@ -1572,18 +1537,18 @@
* @param uri the CHK URI to inspect
* @return size of the file as specified in the CHK URI
*/
-uint64_t
-GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri *uri)
+uint64_t
+GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri * uri)
{
switch (uri->type)
- {
- case chk:
- return GNUNET_ntohll (uri->data.chk.file_length);
- case loc:
- return GNUNET_ntohll (uri->data.loc.fi.file_length);
- default:
- GNUNET_assert (0);
- }
+ {
+ case chk:
+ return GNUNET_ntohll (uri->data.chk.file_length);
+ case loc:
+ return GNUNET_ntohll (uri->data.loc.fi.file_length);
+ default:
+ GNUNET_assert (0);
+ }
return 0; /* unreachable */
}
@@ -1594,7 +1559,7 @@
* @param uri the uri to check
* @return GNUNET_YES if this is a LOC uri
*/
-int
+int
GNUNET_FS_uri_test_loc (const struct GNUNET_FS_Uri *uri)
{
return uri->type == loc;
@@ -1620,26 +1585,23 @@
*/
static int
gather_uri_data (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)
+ 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_FS_Uri *uri = cls;
char *nkword;
int j;
-
- if ( (format != EXTRACTOR_METAFORMAT_UTF8) &&
- (format != EXTRACTOR_METAFORMAT_C_STRING) )
+
+ if ((format != EXTRACTOR_METAFORMAT_UTF8) &&
+ (format != EXTRACTOR_METAFORMAT_C_STRING))
return 0;
for (j = uri->data.ksk.keywordCount - 1; j >= 0; j--)
if (0 == strcmp (&uri->data.ksk.keywords[j][1], data))
return GNUNET_OK;
- GNUNET_asprintf (&nkword,
- " %s", /* space to mark as 'non mandatory' */
- data);
+ GNUNET_asprintf (&nkword, " %s", /* space to mark as 'non mandatory' */
+ data);
uri->data.ksk.keywords[uri->data.ksk.keywordCount++] = nkword;
return 0;
}
@@ -1654,7 +1616,8 @@
* @return NULL on error, otherwise a KSK URI
*/
struct GNUNET_FS_Uri *
-GNUNET_FS_uri_ksk_create_from_meta_data (const struct
GNUNET_CONTAINER_MetaData *md)
+GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData
+ *md)
{
struct GNUNET_FS_Uri *ret;
int ent;
@@ -1665,11 +1628,10 @@
ret->type = ksk;
ent = GNUNET_CONTAINER_meta_data_iterate (md, NULL, NULL);
if (ent > 0)
- {
- ret->data.ksk.keywords
- = GNUNET_malloc (sizeof (char *) * ent);
- GNUNET_CONTAINER_meta_data_iterate (md, &gather_uri_data, ret);
- }
+ {
+ ret->data.ksk.keywords = GNUNET_malloc (sizeof (char *) * ent);
+ GNUNET_CONTAINER_meta_data_iterate (md, &gather_uri_data, ret);
+ }
return ret;
}
@@ -1681,7 +1643,7 @@
static int
needs_percent (char c)
{
- return (!((isalnum ( (unsigned char) c)) ||
+ return (!((isalnum ((unsigned char) c)) ||
(c == '-') || (c == '_') || (c == '.') || (c == '~')));
}
@@ -1695,7 +1657,7 @@
static char *
uri_ksk_to_string (const struct GNUNET_FS_Uri *uri)
{
- char ** keywords;
+ char **keywords;
unsigned int keywordCount;
size_t n;
char *ret;
@@ -1709,50 +1671,49 @@
return NULL;
keywords = uri->data.ksk.keywords;
keywordCount = uri->data.ksk.keywordCount;
- n =
- keywordCount + strlen (GNUNET_FS_URI_PREFIX) +
- strlen (GNUNET_FS_URI_KSK_INFIX) + 1;
+ n = keywordCount + strlen (GNUNET_FS_URI_PREFIX) +
+ strlen (GNUNET_FS_URI_KSK_INFIX) + 1;
for (i = 0; i < keywordCount; i++)
+ {
+ keyword = keywords[i];
+ slen = strlen (keyword);
+ n += slen;
+ for (j = 0; j < slen; j++)
{
- keyword = keywords[i];
- slen = strlen (keyword);
- n += slen;
- for (j = 0; j < slen; j++)
- {
- if ((j == 0) && (keyword[j] == ' '))
- {
- n--;
- continue; /* skip leading space */
- }
- if (needs_percent (keyword[j]))
- n += 2; /* will use %-encoding */
- }
+ if ((j == 0) && (keyword[j] == ' '))
+ {
+ n--;
+ continue; /* skip leading space */
+ }
+ if (needs_percent (keyword[j]))
+ n += 2; /* will use %-encoding */
}
+ }
ret = GNUNET_malloc (n);
strcpy (ret, GNUNET_FS_URI_PREFIX);
strcat (ret, GNUNET_FS_URI_KSK_INFIX);
wpos = strlen (ret);
for (i = 0; i < keywordCount; i++)
+ {
+ keyword = keywords[i];
+ slen = strlen (keyword);
+ for (j = 0; j < slen; j++)
{
- keyword = keywords[i];
- slen = strlen (keyword);
- for (j = 0; j < slen; j++)
- {
- if ((j == 0) && (keyword[j] == ' '))
- continue; /* skip leading space */
- if (needs_percent (keyword[j]))
- {
- sprintf (&ret[wpos], "%%%02X", keyword[j]);
- wpos += 3;
- }
- else
- {
- ret[wpos++] = keyword[j];
- }
- }
- if (i != keywordCount - 1)
- ret[wpos++] = '+';
+ if ((j == 0) && (keyword[j] == ' '))
+ continue; /* skip leading space */
+ if (needs_percent (keyword[j]))
+ {
+ sprintf (&ret[wpos], "%%%02X", keyword[j]);
+ wpos += 3;
+ }
+ else
+ {
+ ret[wpos++] = keyword[j];
+ }
}
+ if (i != keywordCount - 1)
+ ret[wpos++] = '+';
+ }
return ret;
}
@@ -1766,11 +1727,11 @@
static char *
uri_sks_to_string (const struct GNUNET_FS_Uri *uri)
{
- const GNUNET_HashCode * namespace;
+ const GNUNET_HashCode *namespace;
const char *identifier;
char *ret;
struct GNUNET_CRYPTO_HashAsciiEncoded ns;
-
+
if (uri->type != sks)
return NULL;
namespace = &uri->data.sks.namespace;
@@ -1778,9 +1739,8 @@
GNUNET_CRYPTO_hash_to_enc (namespace, &ns);
GNUNET_asprintf (&ret,
"%s%s%s/%s",
- GNUNET_FS_URI_PREFIX,
- GNUNET_FS_URI_SKS_INFIX,
- (const char *) &ns, identifier);
+ GNUNET_FS_URI_PREFIX,
+ GNUNET_FS_URI_SKS_INFIX, (const char *) &ns, identifier);
return ret;
}
@@ -1794,7 +1754,7 @@
static char *
uri_chk_to_string (const struct GNUNET_FS_Uri *uri)
{
- const struct FileIdentifier * fi;
+ const struct FileIdentifier *fi;
char *ret;
struct GNUNET_CRYPTO_HashAsciiEncoded keyhash;
struct GNUNET_CRYPTO_HashAsciiEncoded queryhash;
@@ -1809,9 +1769,8 @@
"%s%s%s.%s.%llu",
GNUNET_FS_URI_PREFIX,
GNUNET_FS_URI_CHK_INFIX,
- (const char *) &keyhash,
- (const char *) &queryhash,
- GNUNET_ntohll (fi->file_length));
+ (const char *) &keyhash,
+ (const char *) &queryhash, GNUNET_ntohll (fi->file_length));
return ret;
}
@@ -1829,8 +1788,8 @@
* 64 characters for encoding, 6 bits per character
*/
static char *tbl =
- "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_=";
-
+ "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_=";
+
size_t len;
size_t pos;
unsigned int bits;
@@ -1847,16 +1806,16 @@
bits = 0;
hbits = 0;
for (pos = 0; pos < size; pos++)
+ {
+ bits |= ((((const unsigned char *) data)[pos]) << hbits);
+ hbits += 8;
+ while (hbits >= 6)
{
- bits |= ((((const unsigned char *) data)[pos]) << hbits);
- hbits += 8;
- while (hbits >= 6)
- {
- ret[len++] = tbl[bits & 63];
- bits >>= 6;
- hbits -= 6;
- }
+ ret[len++] = tbl[bits & 63];
+ bits >>= 6;
+ hbits -= 6;
}
+ }
if (hbits > 0)
ret[len] = tbl[bits & 63];
return ret;
@@ -1881,19 +1840,19 @@
GNUNET_CRYPTO_hash_to_enc (&uri->data.loc.fi.chk.key, &keyhash);
GNUNET_CRYPTO_hash_to_enc (&uri->data.loc.fi.chk.query, &queryhash);
peerId = bin2enc (&uri->data.loc.peer,
- sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
- peerSig = bin2enc (&uri->data.loc.contentSignature,
- sizeof (struct GNUNET_CRYPTO_RsaSignature));
+ sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
+ peerSig = bin2enc (&uri->data.loc.contentSignature,
+ sizeof (struct GNUNET_CRYPTO_RsaSignature));
GNUNET_asprintf (&ret,
"%s%s%s.%s.%llu.%s.%s.%llu",
GNUNET_FS_URI_PREFIX,
GNUNET_FS_URI_LOC_INFIX,
(const char *) &keyhash,
(const char *) &queryhash,
- (unsigned long long) GNUNET_ntohll
(uri->data.loc.fi.file_length),
- peerId,
- peerSig,
- (unsigned long long) uri->data.loc.expirationTime.abs_value);
+ (unsigned long long) GNUNET_ntohll (uri->data.loc.
+ fi.file_length), peerId,
+ peerSig,
+ (unsigned long long)
uri->data.loc.expirationTime.abs_value);
GNUNET_free (peerSig);
GNUNET_free (peerId);
return ret;
@@ -1910,24 +1869,24 @@
GNUNET_FS_uri_to_string (const struct GNUNET_FS_Uri *uri)
{
if (uri == NULL)
- {
- GNUNET_break (0);
- return NULL;
- }
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
switch (uri->type)
- {
- case ksk:
- return uri_ksk_to_string (uri);
- case sks:
- return uri_sks_to_string (uri);
- case chk:
- return uri_chk_to_string (uri);
- case loc:
- return uri_loc_to_string (uri);
- default:
- GNUNET_break (0);
- return NULL;
- }
+ {
+ case ksk:
+ return uri_ksk_to_string (uri);
+ case sks:
+ return uri_sks_to_string (uri);
+ case chk:
+ return uri_chk_to_string (uri);
+ case loc:
+ return uri_loc_to_string (uri);
+ default:
+ GNUNET_break (0);
+ return NULL;
+ }
}
/* end of fs_uri.c */
Modified: gnunet/src/fs/gnunet-directory.c
===================================================================
--- gnunet/src/fs/gnunet-directory.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/fs/gnunet-directory.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -41,22 +41,20 @@
*/
static int
item_printer (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_size)
+ const char *plugin_name,
+ enum EXTRACTOR_MetaType type,
+ enum EXTRACTOR_MetaFormat format,
+ const char *data_mime_type, const char *data, size_t data_size)
{
- if (type == EXTRACTOR_METATYPE_GNUNET_FULL_DATA)
- {
- printf(_("\t<original file embedded in %u bytes of meta data>\n"),
- (unsigned int) data_size);
- return 0;
- }
- if ( (format != EXTRACTOR_METAFORMAT_UTF8) &&
- (format != EXTRACTOR_METAFORMAT_C_STRING) )
+ if (type == EXTRACTOR_METATYPE_GNUNET_FULL_DATA)
+ {
+ printf (_("\t<original file embedded in %u bytes of meta data>\n"),
+ (unsigned int) data_size);
return 0;
+ }
+ if ((format != EXTRACTOR_METAFORMAT_UTF8) &&
+ (format != EXTRACTOR_METAFORMAT_C_STRING))
+ return 0;
if (type == EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME)
return 0;
printf ("\t%20s: %s\n",
@@ -84,36 +82,29 @@
*/
static void
print_entry (void *cls,
- const char *filename,
- const struct GNUNET_FS_Uri *uri,
- const struct GNUNET_CONTAINER_MetaData *meta,
- size_t length,
- const void *data)
+ const char *filename,
+ const struct GNUNET_FS_Uri *uri,
+ const struct GNUNET_CONTAINER_MetaData *meta,
+ size_t length, const void *data)
{
char *string;
char *name;
-
+
name = GNUNET_CONTAINER_meta_data_get_by_type (meta,
-
EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME);
+
EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME);
if (uri == NULL)
- {
- printf (_("Directory `%s' meta data:\n"),
- name);
- GNUNET_CONTAINER_meta_data_iterate (meta,
- &item_printer,
- NULL);
- printf ("\n");
- printf (_("Directory `%s' contents:\n"),
- name);
- GNUNET_free (name);
- return;
- }
+ {
+ printf (_("Directory `%s' meta data:\n"), name);
+ GNUNET_CONTAINER_meta_data_iterate (meta, &item_printer, NULL);
+ printf ("\n");
+ printf (_("Directory `%s' contents:\n"), name);
+ GNUNET_free (name);
+ return;
+ }
string = GNUNET_FS_uri_to_string (uri);
printf ("%s (%s):\n", name, string);
GNUNET_free (string);
- GNUNET_CONTAINER_meta_data_iterate (meta,
- &item_printer,
- NULL);
+ GNUNET_CONTAINER_meta_data_iterate (meta, &item_printer, NULL);
printf ("\n");
GNUNET_free (name);
}
@@ -130,8 +121,7 @@
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
struct GNUNET_DISK_MapHandle *map;
struct GNUNET_DISK_FileHandle *h;
@@ -142,44 +132,35 @@
int i;
if (NULL == args[0])
- {
- fprintf (stderr,
- _("You must specify a filename to inspect."));
- ret = 1;
- return;
- }
+ {
+ fprintf (stderr, _("You must specify a filename to inspect."));
+ ret = 1;
+ return;
+ }
i = 0;
while (NULL != (filename = args[i++]))
+ {
+ if ((GNUNET_OK !=
+ GNUNET_DISK_file_size (filename,
+ &size,
+ GNUNET_YES)) ||
+ (NULL == (h = GNUNET_DISK_file_open (filename,
+ GNUNET_DISK_OPEN_READ,
+ GNUNET_DISK_PERM_NONE))))
{
- if ( (GNUNET_OK !=
- GNUNET_DISK_file_size (filename,
- &size,
- GNUNET_YES)) ||
- (NULL == (h = GNUNET_DISK_file_open (filename,
- GNUNET_DISK_OPEN_READ,
- GNUNET_DISK_PERM_NONE))) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to read directory `%s'\n"),
- filename);
- ret = 1;
- continue;
- }
- len = (size_t) size;
- data = GNUNET_DISK_file_map (h,
- &map,
- GNUNET_DISK_MAP_TYPE_READ,
- len);
- GNUNET_assert (NULL != data);
- GNUNET_FS_directory_list_contents (len,
- data,
- 0,
- &print_entry,
- NULL);
- printf ("\n");
- GNUNET_DISK_file_unmap (map);
- GNUNET_DISK_file_close (h);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to read directory `%s'\n"), filename);
+ ret = 1;
+ continue;
}
+ len = (size_t) size;
+ data = GNUNET_DISK_file_map (h, &map, GNUNET_DISK_MAP_TYPE_READ, len);
+ GNUNET_assert (NULL != data);
+ GNUNET_FS_directory_list_contents (len, data, 0, &print_entry, NULL);
+ printf ("\n");
+ GNUNET_DISK_file_unmap (map);
+ GNUNET_DISK_file_close (h);
+ }
}
/**
Modified: gnunet/src/fs/gnunet-download.c
===================================================================
--- gnunet/src/fs/gnunet-download.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/fs/gnunet-download.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -53,8 +53,7 @@
static int local_only;
static void
-cleanup_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GNUNET_FS_stop (ctx);
ctx = NULL;
@@ -62,17 +61,16 @@
static void
-shutdown_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_FS_DownloadContext *d;
if (dc != NULL)
- {
- d = dc;
- dc = NULL;
- GNUNET_FS_download_stop (d, delete_incomplete);
- }
+ {
+ d = dc;
+ dc = NULL;
+ GNUNET_FS_download_stop (d, delete_incomplete);
+ }
}
@@ -90,67 +88,64 @@
* field in the GNUNET_FS_ProgressInfo struct.
*/
static void *
-progress_cb (void *cls,
- const struct GNUNET_FS_ProgressInfo *info)
+progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
{
char *s;
char *t;
switch (info->status)
- {
- case GNUNET_FS_STATUS_DOWNLOAD_START:
- if (verbose > 1)
- fprintf (stderr,
- _("Starting download `%s'.\n"),
- info->value.download.filename);
- break;
- case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS:
- if (verbose)
- {
- s = GNUNET_STRINGS_relative_time_to_string(info->value.download.eta);
- t = GNUNET_STRINGS_byte_size_fancy(info->value.download.completed *
1000LL / (info->value.download.duration.rel_value + 1));
- fprintf (stdout,
- _("Downloading `%s' at %llu/%llu (%s remaining, %s/s)\n"),
- info->value.download.filename,
- (unsigned long long) info->value.download.completed,
- (unsigned long long) info->value.download.size,
- s,
- t);
- GNUNET_free (s);
- GNUNET_free (t);
- }
- break;
- case GNUNET_FS_STATUS_DOWNLOAD_ERROR:
+ {
+ case GNUNET_FS_STATUS_DOWNLOAD_START:
+ if (verbose > 1)
fprintf (stderr,
- _("Error downloading: %s.\n"),
- info->value.download.specifics.error.message);
- GNUNET_SCHEDULER_shutdown ();
- break;
- case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
- s = GNUNET_STRINGS_byte_size_fancy(info->value.download.completed * 1000
/ (info->value.download.duration.rel_value + 1));
+ _("Starting download `%s'.\n"), info->value.download.filename);
+ break;
+ case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS:
+ if (verbose)
+ {
+ s = GNUNET_STRINGS_relative_time_to_string (info->value.download.eta);
+ t = GNUNET_STRINGS_byte_size_fancy (info->value.download.completed *
+ 1000LL /
+ (info->value.download.
+ duration.rel_value + 1));
fprintf (stdout,
- _("Downloading `%s' done (%s/s).\n"),
- info->value.download.filename,
- s);
+ _("Downloading `%s' at %llu/%llu (%s remaining, %s/s)\n"),
+ info->value.download.filename,
+ (unsigned long long) info->value.download.completed,
+ (unsigned long long) info->value.download.size, s, t);
GNUNET_free (s);
- if (info->value.download.dc == dc)
- GNUNET_SCHEDULER_shutdown ();
- break;
- case GNUNET_FS_STATUS_DOWNLOAD_STOPPED:
- if (info->value.download.dc == dc)
- GNUNET_SCHEDULER_add_continuation (&cleanup_task,
- NULL,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- break;
- case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE:
- case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE:
- break;
- default:
- fprintf (stderr,
- _("Unexpected status: %d\n"),
- info->status);
- break;
+ GNUNET_free (t);
}
+ break;
+ case GNUNET_FS_STATUS_DOWNLOAD_ERROR:
+ fprintf (stderr,
+ _("Error downloading: %s.\n"),
+ info->value.download.specifics.error.message);
+ GNUNET_SCHEDULER_shutdown ();
+ break;
+ case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
+ s = GNUNET_STRINGS_byte_size_fancy (info->value.download.completed * 1000 /
+ (info->value.download.
+ duration.rel_value + 1));
+ fprintf (stdout, _("Downloading `%s' done (%s/s).\n"),
+ info->value.download.filename, s);
+ GNUNET_free (s);
+ if (info->value.download.dc == dc)
+ GNUNET_SCHEDULER_shutdown ();
+ break;
+ case GNUNET_FS_STATUS_DOWNLOAD_STOPPED:
+ if (info->value.download.dc == dc)
+ GNUNET_SCHEDULER_add_continuation (&cleanup_task,
+ NULL,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ break;
+ case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE:
+ case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE:
+ break;
+ default:
+ fprintf (stderr, _("Unexpected status: %d\n"), info->status);
+ break;
+ }
return NULL;
}
@@ -166,92 +161,77 @@
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *c)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
{
struct GNUNET_FS_Uri *uri;
char *emsg;
enum GNUNET_FS_DownloadOptions options;
if (NULL == args[0])
- {
- fprintf (stderr,
- _("You need to specify a URI argument.\n"));
- return;
- }
- uri = GNUNET_FS_uri_parse (args[0],
- &emsg);
+ {
+ fprintf (stderr, _("You need to specify a URI argument.\n"));
+ return;
+ }
+ uri = GNUNET_FS_uri_parse (args[0], &emsg);
if (NULL == uri)
- {
- fprintf (stderr,
- _("Failed to parse URI: %s\n"),
- emsg);
- GNUNET_free (emsg);
- ret = 1;
- return;
- }
- if ( (! GNUNET_FS_uri_test_chk (uri)) &&
- (! GNUNET_FS_uri_test_loc (uri)) )
- {
- fprintf (stderr,
- _("Only CHK or LOC URIs supported.\n"));
- ret = 1;
- GNUNET_FS_uri_destroy (uri);
- return;
- }
+ {
+ fprintf (stderr, _("Failed to parse URI: %s\n"), emsg);
+ GNUNET_free (emsg);
+ ret = 1;
+ return;
+ }
+ if ((!GNUNET_FS_uri_test_chk (uri)) && (!GNUNET_FS_uri_test_loc (uri)))
+ {
+ fprintf (stderr, _("Only CHK or LOC URIs supported.\n"));
+ ret = 1;
+ GNUNET_FS_uri_destroy (uri);
+ return;
+ }
if (NULL == filename)
- {
- fprintf (stderr,
- _("Target filename must be specified.\n"));
- ret = 1;
- GNUNET_FS_uri_destroy (uri);
- return;
- }
+ {
+ fprintf (stderr, _("Target filename must be specified.\n"));
+ ret = 1;
+ GNUNET_FS_uri_destroy (uri);
+ return;
+ }
cfg = c;
ctx = GNUNET_FS_start (cfg,
- "gnunet-download",
- &progress_cb,
- NULL,
- GNUNET_FS_FLAGS_NONE,
- GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM,
- parallelism,
- GNUNET_FS_OPTIONS_REQUEST_PARALLELISM,
- request_parallelism,
- GNUNET_FS_OPTIONS_END);
+ "gnunet-download",
+ &progress_cb,
+ NULL,
+ GNUNET_FS_FLAGS_NONE,
+ GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM,
+ parallelism,
+ GNUNET_FS_OPTIONS_REQUEST_PARALLELISM,
+ request_parallelism, GNUNET_FS_OPTIONS_END);
if (NULL == ctx)
- {
- fprintf (stderr,
- _("Could not initialize `%s' subsystem.\n"),
- "FS");
- GNUNET_FS_uri_destroy (uri);
- ret = 1;
- return;
- }
+ {
+ fprintf (stderr, _("Could not initialize `%s' subsystem.\n"), "FS");
+ GNUNET_FS_uri_destroy (uri);
+ ret = 1;
+ return;
+ }
options = GNUNET_FS_DOWNLOAD_OPTION_NONE;
if (do_recursive)
options |= GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE;
if (local_only)
options |= GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY;
dc = GNUNET_FS_download_start (ctx,
- uri,
- NULL,
- filename, NULL,
- 0,
- GNUNET_FS_uri_chk_get_file_size (uri),
- anonymity,
- options,
- NULL,
- NULL);
+ uri,
+ NULL,
+ filename, NULL,
+ 0,
+ GNUNET_FS_uri_chk_get_file_size (uri),
+ anonymity, options, NULL, NULL);
GNUNET_FS_uri_destroy (uri);
if (dc == NULL)
- {
- GNUNET_FS_stop (ctx);
- ctx = NULL;
- return;
- }
+ {
+ GNUNET_FS_stop (ctx);
+ ctx = NULL;
+ return;
+ }
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task,
- NULL);
+ &shutdown_task, NULL);
}
@@ -304,4 +284,3 @@
}
/* end of gnunet-download.c */
-
Modified: gnunet/src/fs/gnunet-pseudonym.c
===================================================================
--- gnunet/src/fs/gnunet-pseudonym.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/fs/gnunet-pseudonym.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -53,12 +53,12 @@
/**
* Our block options (-p, -r, -a).
*/
-static struct GNUNET_FS_BlockOptions bo = { { 0LL }, 1, 365, 1 };
+static struct GNUNET_FS_BlockOptions bo = { {0LL}, 1, 365, 1 };
/**
* -q option given.
*/
-static int no_remote_printing;
+static int no_remote_printing;
/**
* -r option.
@@ -87,53 +87,39 @@
static int ret;
-static void*
-progress_cb (void *cls,
- const struct GNUNET_FS_ProgressInfo *info)
+static void *
+progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
{
return NULL;
}
static void
-ns_printer (void *cls,
- const char *name,
- const GNUNET_HashCode *id)
+ns_printer (void *cls, const char *name, const GNUNET_HashCode * id)
{
struct GNUNET_CRYPTO_HashAsciiEncoded enc;
GNUNET_CRYPTO_hash_to_enc (id, &enc);
- fprintf (stdout,
- "%s (%s)\n",
- name,
- (const char*) &enc);
+ fprintf (stdout, "%s (%s)\n", name, (const char *) &enc);
}
static int
pseudo_printer (void *cls,
- const GNUNET_HashCode *
- pseudonym,
- const struct
- GNUNET_CONTAINER_MetaData * md,
- int rating)
+ const GNUNET_HashCode *
+ pseudonym,
+ const struct GNUNET_CONTAINER_MetaData *md, int rating)
{
char *id;
- id = GNUNET_PSEUDONYM_id_to_name (cfg,
- pseudonym);
+ id = GNUNET_PSEUDONYM_id_to_name (cfg, pseudonym);
if (id == NULL)
- {
- GNUNET_break (0);
- return GNUNET_OK;
- }
- fprintf (stdout,
- "%s (%d):\n",
- id,
- rating);
- GNUNET_CONTAINER_meta_data_iterate (md,
- &EXTRACTOR_meta_data_print,
- stdout);
+ {
+ GNUNET_break (0);
+ return GNUNET_OK;
+ }
+ fprintf (stdout, "%s (%d):\n", id, rating);
+ GNUNET_CONTAINER_meta_data_iterate (md, &EXTRACTOR_meta_data_print, stdout);
fprintf (stdout, "\n");
GNUNET_free (id);
return GNUNET_OK;
@@ -141,73 +127,58 @@
static void
-post_advertising (void *cls,
- const struct GNUNET_FS_Uri *uri,
- const char *emsg)
+post_advertising (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg)
{
GNUNET_HashCode nsid;
char *set;
int delta;
if (emsg != NULL)
- {
- fprintf (stderr, "%s", emsg);
- ret = 1;
- }
+ {
+ fprintf (stderr, "%s", emsg);
+ ret = 1;
+ }
if (ns != NULL)
+ {
+ if (GNUNET_OK != GNUNET_FS_namespace_delete (ns, GNUNET_NO))
+ ret = 1;
+ }
+ if (NULL != rating_change)
+ {
+ set = rating_change;
+ while ((*set != '\0') && (*set != ':'))
+ set++;
+ if (*set != ':')
{
- if (GNUNET_OK !=
- GNUNET_FS_namespace_delete (ns,
- GNUNET_NO))
- ret = 1;
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Invalid argument `%s'\n"), rating_change);
}
- if (NULL != rating_change)
+ else
{
- set = rating_change;
- while ((*set != '\0') && (*set != ':'))
- set++;
- if (*set != ':')
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Invalid argument `%s'\n"),
- rating_change);
- }
+ *set = '\0';
+ delta = strtol (&set[1], NULL, /* no error handling yet */
+ 10);
+ if (GNUNET_OK == GNUNET_PSEUDONYM_name_to_id (cfg, rating_change, &nsid))
+ {
+ (void) GNUNET_PSEUDONYM_rank (cfg, &nsid, delta);
+ }
else
- {
- *set = '\0';
- delta = strtol (&set[1], NULL, /* no error handling yet */
- 10);
- if (GNUNET_OK ==
- GNUNET_PSEUDONYM_name_to_id (cfg,
- rating_change,
- &nsid))
- {
- (void) GNUNET_PSEUDONYM_rank (cfg,
- &nsid,
- delta);
- }
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Namespace `%s' unknown.\n"),
- rating_change);
- }
- }
- GNUNET_free (rating_change);
- rating_change = NULL;
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Namespace `%s' unknown.\n"), rating_change);
+ }
}
+ GNUNET_free (rating_change);
+ rating_change = NULL;
+ }
if (0 != print_local_only)
- {
- GNUNET_FS_namespace_list (h,
- &ns_printer,
- NULL);
- }
+ {
+ GNUNET_FS_namespace_list (h, &ns_printer, NULL);
+ }
else if (0 == no_remote_printing)
- {
- GNUNET_PSEUDONYM_list_all (cfg,
- &pseudo_printer,
- NULL);
- }
+ {
+ GNUNET_PSEUDONYM_list_all (cfg, &pseudo_printer, NULL);
+ }
GNUNET_FS_stop (h);
}
@@ -223,76 +194,70 @@
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *c)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
{
char *emsg;
cfg = c;
h = GNUNET_FS_start (cfg,
- "gnunet-pseudonym",
- &progress_cb,
- NULL,
- GNUNET_FS_FLAGS_NONE,
- GNUNET_FS_OPTIONS_END);
+ "gnunet-pseudonym",
+ &progress_cb,
+ NULL, GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
if (NULL != delete_ns)
+ {
+ ns = GNUNET_FS_namespace_create (h, delete_ns);
+ if (ns == NULL)
{
- ns = GNUNET_FS_namespace_create (h, delete_ns);
- if (ns == NULL)
- {
- ret = 1;
- }
- else
- {
- if (GNUNET_OK !=
- GNUNET_FS_namespace_delete (ns,
- GNUNET_YES))
- ret = 1;
- ns = NULL;
- }
+ ret = 1;
}
+ else
+ {
+ if (GNUNET_OK != GNUNET_FS_namespace_delete (ns, GNUNET_YES))
+ ret = 1;
+ ns = NULL;
+ }
+ }
if (NULL != create_ns)
+ {
+ ns = GNUNET_FS_namespace_create (h, create_ns);
+ if (ns == NULL)
{
- ns = GNUNET_FS_namespace_create (h, create_ns);
- if (ns == NULL)
- {
- ret = 1;
- }
+ ret = 1;
+ }
+ else
+ {
+ if (NULL != root_identifier)
+ {
+ if (ksk_uri == NULL)
+ {
+ emsg = NULL;
+ ksk_uri = GNUNET_FS_uri_parse ("gnunet://fs/ksk/namespace", &emsg);
+ GNUNET_assert (NULL == emsg);
+ }
+ GNUNET_FS_namespace_advertise (h,
+ ksk_uri,
+ ns,
+ adv_metadata,
+ &bo,
+ root_identifier,
+ &post_advertising, NULL);
+ return;
+ }
else
- {
- if (NULL != root_identifier)
- {
- if (ksk_uri == NULL)
- {
- emsg = NULL;
- ksk_uri = GNUNET_FS_uri_parse ("gnunet://fs/ksk/namespace",
&emsg);
- GNUNET_assert (NULL == emsg);
- }
- GNUNET_FS_namespace_advertise (h,
- ksk_uri,
- ns,
- adv_metadata,
- &bo,
- root_identifier,
- &post_advertising,
- NULL);
- return;
- }
- else
- {
- if (ksk_uri != NULL)
- fprintf (stderr, _("Option `%s' ignored\n"), "-k");
- }
- }
+ {
+ if (ksk_uri != NULL)
+ fprintf (stderr, _("Option `%s' ignored\n"), "-k");
+ }
}
+ }
else
- {
- if (root_identifier != NULL)
- fprintf (stderr, _("Option `%s' ignored\n"), "-r");
- if (ksk_uri != NULL)
- fprintf (stderr, _("Option `%s' ignored\n"), "-k");
- }
-
+ {
+ if (root_identifier != NULL)
+ fprintf (stderr, _("Option `%s' ignored\n"), "-r");
+ if (ksk_uri != NULL)
+ fprintf (stderr, _("Option `%s' ignored\n"), "-k");
+ }
+
post_advertising (NULL, NULL, NULL);
}
@@ -313,12 +278,10 @@
gettext_noop ("set the desired LEVEL of sender-anonymity"),
1, &GNUNET_GETOPT_set_uint, &bo.anonymity_level},
{'C', "create", "NAME",
- gettext_noop
- ("create or advertise namespace NAME"),
+ gettext_noop ("create or advertise namespace NAME"),
1, &GNUNET_GETOPT_set_string, &create_ns},
{'D', "delete", "NAME",
- gettext_noop
- ("delete namespace NAME "),
+ gettext_noop ("delete namespace NAME "),
1, &GNUNET_GETOPT_set_string, &delete_ns},
{'k', "keyword", "VALUE",
gettext_noop
@@ -341,22 +304,18 @@
gettext_noop ("set the desired replication LEVEL"),
1, &GNUNET_GETOPT_set_uint, &bo.replication_level},
{'R', "root", "ID",
- gettext_noop
- ("specify ID of the root of the namespace"),
+ gettext_noop ("specify ID of the root of the namespace"),
1, &GNUNET_GETOPT_set_string, &root_identifier},
{'s', "set-rating", "ID:VALUE",
- gettext_noop
- ("change rating of namespace ID by VALUE"),
+ gettext_noop ("change rating of namespace ID by VALUE"),
1, &GNUNET_GETOPT_set_string, &rating_change},
GNUNET_GETOPT_OPTION_END
};
- bo.expiration_time = GNUNET_FS_year_to_time (GNUNET_FS_get_current_year () +
2);
+ bo.expiration_time =
+ GNUNET_FS_year_to_time (GNUNET_FS_get_current_year () + 2);
return (GNUNET_OK ==
- GNUNET_PROGRAM_run (argc,
- argv,
- "gnunet-pseudonym [OPTIONS]",
- gettext_noop
- ("Manage GNUnet pseudonyms."),
+ GNUNET_PROGRAM_run (argc, argv, "gnunet-pseudonym [OPTIONS]",
+ gettext_noop ("Manage GNUnet pseudonyms."),
options, &run, NULL)) ? ret : 1;
}
Modified: gnunet/src/fs/gnunet-publish.c
===================================================================
--- gnunet/src/fs/gnunet-publish.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/fs/gnunet-publish.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -44,7 +44,7 @@
static struct GNUNET_FS_Uri *uri;
-static struct GNUNET_FS_BlockOptions bo = { { 0LL }, 1, 365, 1 };
+static struct GNUNET_FS_BlockOptions bo = { {0LL}, 1, 365, 1 };
static char *uri_string;
@@ -67,23 +67,22 @@
static GNUNET_SCHEDULER_TaskIdentifier kill_task;
-static void
-do_stop_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+static void
+do_stop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_FS_PublishContext *p;
if (pc != NULL)
+ {
+ p = pc;
+ pc = NULL;
+ GNUNET_FS_publish_stop (p);
+ if (NULL != meta)
{
- p = pc;
- pc = NULL;
- GNUNET_FS_publish_stop (p);
- if (NULL != meta)
- {
- GNUNET_CONTAINER_meta_data_destroy (meta);
- meta = NULL;
- }
+ GNUNET_CONTAINER_meta_data_destroy (meta);
+ meta = NULL;
}
+ }
}
@@ -101,72 +100,66 @@
* field in the GNUNET_FS_ProgressInfo struct.
*/
static void *
-progress_cb (void *cls,
- const struct GNUNET_FS_ProgressInfo *info)
+progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
{
char *s;
switch (info->status)
+ {
+ case GNUNET_FS_STATUS_PUBLISH_START:
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
+ if (verbose)
{
- case GNUNET_FS_STATUS_PUBLISH_START:
- break;
- case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
- if (verbose)
- {
- s = GNUNET_STRINGS_relative_time_to_string(info->value.publish.eta);
- fprintf (stdout,
- _("Publishing `%s' at %llu/%llu (%s remaining)\n"),
- info->value.publish.filename,
- (unsigned long long) info->value.publish.completed,
- (unsigned long long) info->value.publish.size,
- s);
- GNUNET_free (s);
- }
- break;
- case GNUNET_FS_STATUS_PUBLISH_ERROR:
- fprintf (stderr,
- _("Error publishing: %s.\n"),
- info->value.publish.specifics.error.message);
- if (kill_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (kill_task);
- kill_task = GNUNET_SCHEDULER_NO_TASK;
- }
- GNUNET_SCHEDULER_add_continuation (&do_stop_task,
- NULL,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- break;
- case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
+ s = GNUNET_STRINGS_relative_time_to_string (info->value.publish.eta);
fprintf (stdout,
- _("Publishing `%s' done.\n"),
- info->value.publish.filename);
- s = GNUNET_FS_uri_to_string
(info->value.publish.specifics.completed.chk_uri);
- fprintf (stdout,
- _("URI is `%s'.\n"),
- s);
+ _("Publishing `%s' at %llu/%llu (%s remaining)\n"),
+ info->value.publish.filename,
+ (unsigned long long) info->value.publish.completed,
+ (unsigned long long) info->value.publish.size, s);
GNUNET_free (s);
- if (info->value.publish.pctx == NULL)
- {
- if (kill_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (kill_task);
- kill_task = GNUNET_SCHEDULER_NO_TASK;
- }
- GNUNET_SCHEDULER_add_continuation (&do_stop_task,
- NULL,
-
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- }
- break;
- case GNUNET_FS_STATUS_PUBLISH_STOPPED:
- GNUNET_break (NULL == pc);
- return NULL;
- default:
- fprintf (stderr,
- _("Unexpected status: %d\n"),
- info->status);
- return NULL;
}
- return ""; /* non-null */
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_ERROR:
+ fprintf (stderr,
+ _("Error publishing: %s.\n"),
+ info->value.publish.specifics.error.message);
+ if (kill_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (kill_task);
+ kill_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ GNUNET_SCHEDULER_add_continuation (&do_stop_task,
+ NULL,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
+ fprintf (stdout,
+ _("Publishing `%s' done.\n"), info->value.publish.filename);
+ s = GNUNET_FS_uri_to_string (info->value.publish.specifics.
+ completed.chk_uri);
+ fprintf (stdout, _("URI is `%s'.\n"), s);
+ GNUNET_free (s);
+ if (info->value.publish.pctx == NULL)
+ {
+ if (kill_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (kill_task);
+ kill_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ GNUNET_SCHEDULER_add_continuation (&do_stop_task,
+ NULL,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ }
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_STOPPED:
+ GNUNET_break (NULL == pc);
+ return NULL;
+ default:
+ fprintf (stderr, _("Unexpected status: %d\n"), info->status);
+ return NULL;
+ }
+ return ""; /* non-null */
}
@@ -185,22 +178,17 @@
*/
static int
meta_printer (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_size)
+ const char *plugin_name,
+ enum EXTRACTOR_MetaType type,
+ enum EXTRACTOR_MetaFormat format,
+ const char *data_mime_type, const char *data, size_t data_size)
{
- if ( (format != EXTRACTOR_METAFORMAT_UTF8) &&
- (format != EXTRACTOR_METAFORMAT_C_STRING) )
+ if ((format != EXTRACTOR_METAFORMAT_UTF8) &&
+ (format != EXTRACTOR_METAFORMAT_C_STRING))
return 0;
- if (type == EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME)
+ if (type == EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME)
return 0;
- fprintf (stdout,
- "\t%s - %s\n",
- EXTRACTOR_metatype_to_string (type),
- data);
+ fprintf (stdout, "\t%s - %s\n", EXTRACTOR_metatype_to_string (type), data);
return 0;
}
@@ -215,13 +203,9 @@
*/
static int
-keyword_printer (void *cls,
- const char *keyword,
- int is_mandatory)
+keyword_printer (void *cls, const char *keyword, int is_mandatory)
{
- fprintf (stdout,
- "\t%s\n",
- keyword);
+ fprintf (stdout, "\t%s\n", keyword);
return GNUNET_OK;
}
@@ -245,13 +229,12 @@
*/
static int
publish_inspector (void *cls,
- struct GNUNET_FS_FileInformation *fi,
- uint64_t length,
- struct GNUNET_CONTAINER_MetaData *m,
- struct GNUNET_FS_Uri **uri,
- struct GNUNET_FS_BlockOptions *bo,
- int *do_index,
- void **client_info)
+ struct GNUNET_FS_FileInformation *fi,
+ uint64_t length,
+ struct GNUNET_CONTAINER_MetaData *m,
+ struct GNUNET_FS_Uri **uri,
+ struct GNUNET_FS_BlockOptions *bo,
+ int *do_index, void **client_info)
{
char *fn;
char *fs;
@@ -260,73 +243,57 @@
if (cls == fi)
return GNUNET_OK;
if (NULL != topKeywords)
+ {
+ if (*uri != NULL)
{
- if (*uri != NULL)
- {
- new_uri = GNUNET_FS_uri_ksk_merge (topKeywords,
- *uri);
- GNUNET_FS_uri_destroy (*uri);
- *uri = new_uri;
- GNUNET_FS_uri_destroy (topKeywords);
- }
- else
- {
- *uri = topKeywords;
- }
- topKeywords = NULL;
+ new_uri = GNUNET_FS_uri_ksk_merge (topKeywords, *uri);
+ GNUNET_FS_uri_destroy (*uri);
+ *uri = new_uri;
+ GNUNET_FS_uri_destroy (topKeywords);
}
- if (NULL != meta)
+ else
{
- GNUNET_CONTAINER_meta_data_merge (m, meta);
- GNUNET_CONTAINER_meta_data_destroy (meta);
- meta = NULL;
+ *uri = topKeywords;
}
- if (! do_disable_creation_time)
+ topKeywords = NULL;
+ }
+ if (NULL != meta)
+ {
+ GNUNET_CONTAINER_meta_data_merge (m, meta);
+ GNUNET_CONTAINER_meta_data_destroy (meta);
+ meta = NULL;
+ }
+ if (!do_disable_creation_time)
GNUNET_CONTAINER_meta_data_add_publication_date (m);
if (extract_only)
- {
- fn = GNUNET_CONTAINER_meta_data_get_by_type (m,
-
EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME);
- fs = GNUNET_STRINGS_byte_size_fancy (length);
- fprintf (stdout,
- _("Meta data for file `%s' (%s)\n"),
- fn,
- fs);
- GNUNET_CONTAINER_meta_data_iterate (m,
- &meta_printer,
- NULL);
- fprintf (stdout,
- _("Keywords for file `%s' (%s)\n"),
- fn,
- fs);
- GNUNET_free (fn);
- GNUNET_free (fs);
- if (NULL != *uri)
- GNUNET_FS_uri_ksk_get_keywords (*uri,
- &keyword_printer,
- NULL);
- fprintf (stdout, "\n");
- }
+ {
+ fn = GNUNET_CONTAINER_meta_data_get_by_type (m,
+
EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME);
+ fs = GNUNET_STRINGS_byte_size_fancy (length);
+ fprintf (stdout, _("Meta data for file `%s' (%s)\n"), fn, fs);
+ GNUNET_CONTAINER_meta_data_iterate (m, &meta_printer, NULL);
+ fprintf (stdout, _("Keywords for file `%s' (%s)\n"), fn, fs);
+ GNUNET_free (fn);
+ GNUNET_free (fs);
+ if (NULL != *uri)
+ GNUNET_FS_uri_ksk_get_keywords (*uri, &keyword_printer, NULL);
+ fprintf (stdout, "\n");
+ }
if (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (m))
- GNUNET_FS_file_information_inspect (fi,
- &publish_inspector,
- fi);
+ GNUNET_FS_file_information_inspect (fi, &publish_inspector, fi);
return GNUNET_OK;
}
-static void
+static void
uri_sks_continuation (void *cls,
- const struct GNUNET_FS_Uri *ksk_uri,
- const char *emsg)
+ const struct GNUNET_FS_Uri *ksk_uri, const char *emsg)
{
if (emsg != NULL)
- {
- fprintf (stderr,
- "%s\n",
- emsg);
- ret = 1;
- }
+ {
+ fprintf (stderr, "%s\n", emsg);
+ ret = 1;
+ }
GNUNET_FS_uri_destroy (uri);
uri = NULL;
GNUNET_FS_stop (ctx);
@@ -334,48 +301,40 @@
}
-static void
+static void
uri_ksk_continuation (void *cls,
- const struct GNUNET_FS_Uri *ksk_uri,
- const char *emsg)
+ const struct GNUNET_FS_Uri *ksk_uri, const char *emsg)
{
struct GNUNET_FS_Namespace *ns;
if (emsg != NULL)
+ {
+ fprintf (stderr, "%s\n", emsg);
+ ret = 1;
+ }
+ if (pseudonym != NULL)
+ {
+ ns = GNUNET_FS_namespace_create (ctx, pseudonym);
+ if (ns == NULL)
{
- fprintf (stderr,
- "%s\n",
- emsg);
+ fprintf (stderr, _("Failed to create namespace `%s'\n"), pseudonym);
ret = 1;
}
- if (pseudonym != NULL)
+ else
{
- ns = GNUNET_FS_namespace_create (ctx,
- pseudonym);
- if (ns == NULL)
- {
- fprintf (stderr,
- _("Failed to create namespace `%s'\n"),
- pseudonym);
- ret = 1;
- }
- else
- {
- GNUNET_FS_publish_sks (ctx,
- ns,
- this_id,
- next_id,
- meta,
- uri,
- &bo,
- GNUNET_FS_PUBLISH_OPTION_NONE,
- uri_sks_continuation,
- NULL);
- GNUNET_assert (GNUNET_OK ==
- GNUNET_FS_namespace_delete (ns, GNUNET_NO));
- return;
- }
+ GNUNET_FS_publish_sks (ctx,
+ ns,
+ this_id,
+ next_id,
+ meta,
+ uri,
+ &bo,
+ GNUNET_FS_PUBLISH_OPTION_NONE,
+ uri_sks_continuation, NULL);
+ GNUNET_assert (GNUNET_OK == GNUNET_FS_namespace_delete (ns, GNUNET_NO));
+ return;
}
+ }
GNUNET_FS_uri_destroy (uri);
uri = NULL;
GNUNET_FS_stop (ctx);
@@ -394,8 +353,7 @@
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *c)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
{
struct GNUNET_FS_FileInformation *fi;
struct GNUNET_FS_Namespace *namespace;
@@ -404,212 +362,187 @@
struct stat sbuf;
char *ex;
char *emsg;
-
+
/* check arguments */
if ((uri_string != NULL) && (extract_only))
+ {
+ printf (_("Cannot extract metadata from a URI!\n"));
+ ret = -1;
+ return;
+ }
+ if (((uri_string == NULL) || (extract_only))
+ && ((args[0] == NULL) || (args[1] != NULL)))
+ {
+ printf (_("You must specify one and only one filename for insertion.\n"));
+ ret = -1;
+ return;
+ }
+ if ((uri_string != NULL) && (args[0] != NULL))
+ {
+ printf (_("You must NOT specify an URI and a filename.\n"));
+ ret = -1;
+ return;
+ }
+ if (pseudonym != NULL)
+ {
+ if (NULL == this_id)
{
- printf (_("Cannot extract metadata from a URI!\n"));
+ fprintf (stderr,
+ _("Option `%s' is required when using option `%s'.\n"),
+ "-t", "-P");
ret = -1;
return;
}
- if ( ( (uri_string == NULL) || (extract_only) )
- && ( (args[0] == NULL) || (args[1] != NULL) ) )
+ }
+ else
+ { /* ordinary insertion checks */
+ if (NULL != next_id)
{
- printf (_
- ("You must specify one and only one filename for insertion.\n"));
+ fprintf (stderr,
+ _("Option `%s' makes no sense without option `%s'.\n"),
+ "-N", "-P");
ret = -1;
return;
}
- if ((uri_string != NULL) && (args[0] != NULL))
+ if (NULL != this_id)
{
- printf (_("You must NOT specify an URI and a filename.\n"));
+ fprintf (stderr,
+ _("Option `%s' makes no sense without option `%s'.\n"),
+ "-t", "-P");
ret = -1;
return;
}
- if (pseudonym != NULL)
- {
- if (NULL == this_id)
- {
- fprintf (stderr,
- _("Option `%s' is required when using option `%s'.\n"),
- "-t", "-P");
- ret = -1;
- return;
- }
- }
- else
- { /* ordinary insertion checks */
- if (NULL != next_id)
- {
- fprintf (stderr,
- _("Option `%s' makes no sense without option `%s'.\n"),
- "-N", "-P");
- ret = -1;
- return;
- }
- if (NULL != this_id)
- {
- fprintf (stderr,
- _("Option `%s' makes no sense without option `%s'.\n"),
- "-t", "-P");
- ret = -1;
- return;
- }
- }
+ }
cfg = c;
ctx = GNUNET_FS_start (cfg,
- "gnunet-publish",
- &progress_cb,
- NULL,
- GNUNET_FS_FLAGS_NONE,
- GNUNET_FS_OPTIONS_END);
+ "gnunet-publish",
+ &progress_cb,
+ NULL, GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
if (NULL == ctx)
+ {
+ fprintf (stderr, _("Could not initialize `%s' subsystem.\n"), "FS");
+ ret = 1;
+ return;
+ }
+ namespace = NULL;
+ if (NULL != pseudonym)
+ {
+ namespace = GNUNET_FS_namespace_create (ctx, pseudonym);
+ if (NULL == namespace)
{
- fprintf (stderr,
- _("Could not initialize `%s' subsystem.\n"),
- "FS");
+ fprintf (stderr, _("Could not create namespace `%s'\n"), pseudonym);
+ GNUNET_FS_stop (ctx);
ret = 1;
return;
}
- namespace = NULL;
- if (NULL != pseudonym)
- {
- namespace = GNUNET_FS_namespace_create (ctx,
- pseudonym);
- if (NULL == namespace)
- {
- fprintf (stderr,
- _("Could not create namespace `%s'\n"),
- pseudonym);
- GNUNET_FS_stop (ctx);
- ret = 1;
- return;
- }
- }
+ }
if (NULL != uri_string)
- {
- emsg = NULL;
- uri = GNUNET_FS_uri_parse (uri_string,
- &emsg);
- if (uri == NULL)
- {
- fprintf (stderr,
- _("Failed to parse URI: %s\n"),
- emsg);
- GNUNET_free (emsg);
- if (namespace != NULL)
- GNUNET_FS_namespace_delete (namespace, GNUNET_NO);
- GNUNET_FS_stop (ctx);
- ret = 1;
- return;
- }
- GNUNET_FS_publish_ksk (ctx,
- topKeywords,
- meta,
- uri,
- &bo,
- GNUNET_FS_PUBLISH_OPTION_NONE,
- &uri_ksk_continuation,
- NULL);
+ {
+ emsg = NULL;
+ uri = GNUNET_FS_uri_parse (uri_string, &emsg);
+ if (uri == NULL)
+ {
+ fprintf (stderr, _("Failed to parse URI: %s\n"), emsg);
+ GNUNET_free (emsg);
if (namespace != NULL)
- GNUNET_FS_namespace_delete (namespace, GNUNET_NO);
+ GNUNET_FS_namespace_delete (namespace, GNUNET_NO);
+ GNUNET_FS_stop (ctx);
+ ret = 1;
return;
}
+ GNUNET_FS_publish_ksk (ctx,
+ topKeywords,
+ meta,
+ uri,
+ &bo,
+ GNUNET_FS_PUBLISH_OPTION_NONE,
+ &uri_ksk_continuation, NULL);
+ if (namespace != NULL)
+ GNUNET_FS_namespace_delete (namespace, GNUNET_NO);
+ return;
+ }
plugins = NULL;
- if (! disable_extractor)
+ if (!disable_extractor)
+ {
+ plugins = EXTRACTOR_plugin_add_defaults (EXTRACTOR_OPTION_DEFAULT_POLICY);
+ if (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_string (cfg, "FS", "EXTRACTORS", &ex))
{
- plugins = EXTRACTOR_plugin_add_defaults
(EXTRACTOR_OPTION_DEFAULT_POLICY);
- if (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (cfg, "FS", "EXTRACTORS",
- &ex))
- {
- if (strlen (ex) > 0)
- plugins = EXTRACTOR_plugin_add_config (plugins, ex,
EXTRACTOR_OPTION_DEFAULT_POLICY);
- GNUNET_free (ex);
- }
+ if (strlen (ex) > 0)
+ plugins =
+ EXTRACTOR_plugin_add_config (plugins, ex,
+ EXTRACTOR_OPTION_DEFAULT_POLICY);
+ GNUNET_free (ex);
}
+ }
emsg = NULL;
GNUNET_assert (NULL != args[0]);
if (0 != STAT (args[0], &sbuf))
- {
- GNUNET_asprintf (&emsg,
- _("Could not access file: %s\n"),
- STRERROR (errno));
- fi = NULL;
- }
+ {
+ GNUNET_asprintf (&emsg, _("Could not access file: %s\n"), STRERROR
(errno));
+ fi = NULL;
+ }
else if (S_ISDIR (sbuf.st_mode))
- {
- fi = GNUNET_FS_file_information_create_from_directory (ctx,
- NULL,
- args[0],
-
&GNUNET_FS_directory_scanner_default,
- plugins,
- !do_insert,
- &bo,
- &emsg);
- }
+ {
+ fi = GNUNET_FS_file_information_create_from_directory (ctx,
+ NULL,
+ args[0],
+
&GNUNET_FS_directory_scanner_default,
+ plugins,
+ !do_insert,
+ &bo, &emsg);
+ }
else
- {
- if (meta == NULL)
- meta = GNUNET_CONTAINER_meta_data_create ();
- GNUNET_FS_meta_data_extract_from_file (meta,
- args[0],
- plugins);
- keywords = GNUNET_FS_uri_ksk_create_from_meta_data (meta);
- fi = GNUNET_FS_file_information_create_from_file (ctx,
- NULL,
- args[0],
- keywords,
- NULL,
- !do_insert,
- &bo);
- GNUNET_break (fi != NULL);
- GNUNET_FS_uri_destroy (keywords);
- }
- EXTRACTOR_plugin_remove_all (plugins);
+ {
+ if (meta == NULL)
+ meta = GNUNET_CONTAINER_meta_data_create ();
+ GNUNET_FS_meta_data_extract_from_file (meta, args[0], plugins);
+ keywords = GNUNET_FS_uri_ksk_create_from_meta_data (meta);
+ fi = GNUNET_FS_file_information_create_from_file (ctx,
+ NULL,
+ args[0],
+ keywords,
+ NULL, !do_insert, &bo);
+ GNUNET_break (fi != NULL);
+ GNUNET_FS_uri_destroy (keywords);
+ }
+ EXTRACTOR_plugin_remove_all (plugins);
if (fi == NULL)
- {
- fprintf (stderr,
- _("Could not publish `%s': %s\n"),
- args[0],
- emsg);
- GNUNET_free (emsg);
- if (namespace != NULL)
- GNUNET_FS_namespace_delete (namespace, GNUNET_NO);
- GNUNET_FS_stop (ctx);
- ret = 1;
- return;
- }
- GNUNET_FS_file_information_inspect (fi,
- &publish_inspector,
- NULL);
+ {
+ fprintf (stderr, _("Could not publish `%s': %s\n"), args[0], emsg);
+ GNUNET_free (emsg);
+ if (namespace != NULL)
+ GNUNET_FS_namespace_delete (namespace, GNUNET_NO);
+ GNUNET_FS_stop (ctx);
+ ret = 1;
+ return;
+ }
+ GNUNET_FS_file_information_inspect (fi, &publish_inspector, NULL);
if (extract_only)
- {
- if (namespace != NULL)
- GNUNET_FS_namespace_delete (namespace, GNUNET_NO);
- GNUNET_FS_file_information_destroy (fi, NULL, NULL);
- GNUNET_FS_stop (ctx);
- return;
- }
+ {
+ if (namespace != NULL)
+ GNUNET_FS_namespace_delete (namespace, GNUNET_NO);
+ GNUNET_FS_file_information_destroy (fi, NULL, NULL);
+ GNUNET_FS_stop (ctx);
+ return;
+ }
pc = GNUNET_FS_publish_start (ctx,
- fi,
- namespace,
- this_id,
- next_id,
- (do_simulate)
- ? GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY
- : GNUNET_FS_PUBLISH_OPTION_NONE);
+ fi,
+ namespace,
+ this_id,
+ next_id,
+ (do_simulate)
+ ? GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY
+ : GNUNET_FS_PUBLISH_OPTION_NONE);
if (NULL == pc)
- {
- fprintf (stderr,
- _("Could not start publishing.\n"));
- GNUNET_FS_stop (ctx);
- ret = 1;
- return;
- }
+ {
+ fprintf (stderr, _("Could not start publishing.\n"));
+ GNUNET_FS_stop (ctx);
+ ret = 1;
+ return;
+ }
kill_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_stop_task,
- NULL);
+ &do_stop_task, NULL);
}
@@ -634,8 +567,7 @@
("disable adding the creation time to the metadata of the uploaded file"),
0, &GNUNET_GETOPT_set_one, &do_disable_creation_time},
{'D', "disable-extractor", NULL,
- gettext_noop
- ("do not use libextractor to add keywords or metadata"),
+ gettext_noop ("do not use libextractor to add keywords or metadata"),
0, &GNUNET_GETOPT_set_one, &disable_extractor},
{'e', "extract", NULL,
gettext_noop
@@ -651,7 +583,7 @@
1, &GNUNET_FS_getopt_set_metadata, &meta},
{'n', "noindex", NULL,
gettext_noop ("do not index, perform full insertion (stores entire "
- "file in encrypted form in GNUnet database)"),
+ "file in encrypted form in GNUnet database)"),
0, &GNUNET_GETOPT_set_one, &do_insert},
{'N', "next", "ID",
gettext_noop
@@ -670,26 +602,25 @@
1, &GNUNET_GETOPT_set_uint, &bo.replication_level},
{'s', "simulate-only", NULL,
gettext_noop ("only simulate the process but do not do any "
- "actual publishing (useful to compute URIs)"),
+ "actual publishing (useful to compute URIs)"),
0, &GNUNET_GETOPT_set_one, &do_simulate},
{'t', "this", "ID",
gettext_noop ("set the ID of this version of the publication"
- " (for namespace insertions only)"),
+ " (for namespace insertions only)"),
1, &GNUNET_GETOPT_set_string, &this_id},
{'u', "uri", "URI",
gettext_noop ("URI to be published (can be used instead of passing a "
- "file to add keywords to the file with the respective URI)"),
- 1, &GNUNET_GETOPT_set_string, &uri_string},
+ "file to add keywords to the file with the respective
URI)"),
+ 1, &GNUNET_GETOPT_set_string, &uri_string},
{'V', "verbose", NULL,
gettext_noop ("be verbose (print progress information)"),
0, &GNUNET_GETOPT_set_one, &verbose},
GNUNET_GETOPT_OPTION_END
};
- bo.expiration_time = GNUNET_FS_year_to_time (GNUNET_FS_get_current_year () +
2);
+ bo.expiration_time =
+ GNUNET_FS_year_to_time (GNUNET_FS_get_current_year () + 2);
return (GNUNET_OK ==
- GNUNET_PROGRAM_run (argc,
- argv,
- "gnunet-publish [OPTIONS] FILENAME",
+ GNUNET_PROGRAM_run (argc, argv, "gnunet-publish [OPTIONS] FILENAME",
gettext_noop
("Publish a file or directory on GNUnet"),
options, &run, NULL)) ? ret : 1;
Modified: gnunet/src/fs/gnunet-search.c
===================================================================
--- gnunet/src/fs/gnunet-search.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/fs/gnunet-search.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -68,32 +68,28 @@
* @param data actual meta-data found
* @param data_size number of bytes in data
* @return 0 to continue extracting, 1 to abort
- */
+ */
static int
item_printer (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_size)
+ const char *plugin_name,
+ enum EXTRACTOR_MetaType type,
+ enum EXTRACTOR_MetaFormat format,
+ const char *data_mime_type, const char *data, size_t data_size)
{
- if ( (format != EXTRACTOR_METAFORMAT_UTF8) &&
- (format != EXTRACTOR_METAFORMAT_C_STRING) )
+ if ((format != EXTRACTOR_METAFORMAT_UTF8) &&
+ (format != EXTRACTOR_METAFORMAT_C_STRING))
return 0;
- if (type == EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME)
+ if (type == EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME)
return 0;
printf ("\t%20s: %s\n",
dgettext (LIBEXTRACTOR_GETTEXT_DOMAIN,
- EXTRACTOR_metatype_to_string (type)),
- data);
+ EXTRACTOR_metatype_to_string (type)), data);
return 0;
}
static void
-clean_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+clean_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
size_t dsize;
void *ddata;
@@ -102,25 +98,23 @@
ctx = NULL;
if (output_filename == NULL)
return;
- if (GNUNET_OK !=
- GNUNET_FS_directory_builder_finish (db,
- &dsize,
- &ddata))
- {
- GNUNET_break (0);
- GNUNET_free (output_filename);
- return;
- }
- if (dsize !=
+ if (GNUNET_OK != GNUNET_FS_directory_builder_finish (db, &dsize, &ddata))
+ {
+ GNUNET_break (0);
+ GNUNET_free (output_filename);
+ return;
+ }
+ if (dsize !=
GNUNET_DISK_fn_write (output_filename,
- ddata,
- dsize,
- GNUNET_DISK_PERM_USER_READ |
GNUNET_DISK_PERM_USER_WRITE))
- {
- fprintf (stderr,
- _("Failed to write directory with search results to `%s'\n"),
- output_filename);
- }
+ ddata,
+ dsize,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE))
+ {
+ fprintf (stderr,
+ _("Failed to write directory with search results to `%s'\n"),
+ output_filename);
+ }
GNUNET_free_non_null (ddata);
GNUNET_free (output_filename);
}
@@ -140,8 +134,7 @@
* field in the GNUNET_FS_ProgressInfo struct.
*/
static void *
-progress_cb (void *cls,
- const struct GNUNET_FS_ProgressInfo *info)
+progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
{
static unsigned int cnt;
char *uri;
@@ -149,78 +142,72 @@
char *filename;
switch (info->status)
+ {
+ case GNUNET_FS_STATUS_SEARCH_START:
+ break;
+ case GNUNET_FS_STATUS_SEARCH_RESULT:
+ if (db != NULL)
+ GNUNET_FS_directory_builder_add (db,
+ info->value.search.specifics.result.uri,
+
info->value.search.specifics.result.meta,
+ NULL);
+ uri = GNUNET_FS_uri_to_string (info->value.search.specifics.result.uri);
+ printf ("#%u:\n", cnt++);
+ filename =
+ GNUNET_CONTAINER_meta_data_get_by_type (info->value.search.
+ specifics.result.meta,
+
EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME);
+ if (filename != NULL)
{
- case GNUNET_FS_STATUS_SEARCH_START:
- break;
- case GNUNET_FS_STATUS_SEARCH_RESULT:
- if (db != NULL)
- GNUNET_FS_directory_builder_add (db,
-
info->value.search.specifics.result.uri,
-
info->value.search.specifics.result.meta,
- NULL);
- uri = GNUNET_FS_uri_to_string (info->value.search.specifics.result.uri);
- printf ("#%u:\n", cnt++);
- filename =
- GNUNET_CONTAINER_meta_data_get_by_type
(info->value.search.specifics.result.meta,
-
EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME);
- if (filename != NULL)
- {
- while (NULL != (dotdot = strstr (filename, "..")))
- dotdot[0] = dotdot[1] = '_';
- printf ("gnunet-download -o \"%s\" %s\n",
- filename,
- uri);
- }
- else
- printf ("gnunet-download %s\n", uri);
- if (verbose)
- GNUNET_CONTAINER_meta_data_iterate
(info->value.search.specifics.result.meta,
- &item_printer,
- NULL);
- printf ("\n");
- fflush(stdout);
- GNUNET_free_non_null (filename);
- GNUNET_free (uri);
- results++;
- if ( (results_limit > 0) &&
- (results >= results_limit) )
- GNUNET_SCHEDULER_shutdown ();
- break;
- case GNUNET_FS_STATUS_SEARCH_UPDATE:
- break;
- case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED:
- /* ignore */
- break;
- case GNUNET_FS_STATUS_SEARCH_ERROR:
- fprintf (stderr,
- _("Error searching: %s.\n"),
- info->value.search.specifics.error.message);
- GNUNET_SCHEDULER_shutdown ();
- break;
- case GNUNET_FS_STATUS_SEARCH_STOPPED:
- GNUNET_SCHEDULER_add_continuation (&clean_task,
- NULL,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- break;
- default:
- fprintf (stderr,
- _("Unexpected status: %d\n"),
- info->status);
- break;
+ while (NULL != (dotdot = strstr (filename, "..")))
+ dotdot[0] = dotdot[1] = '_';
+ printf ("gnunet-download -o \"%s\" %s\n", filename, uri);
}
+ else
+ printf ("gnunet-download %s\n", uri);
+ if (verbose)
+ GNUNET_CONTAINER_meta_data_iterate (info->value.search.specifics.
+ result.meta, &item_printer, NULL);
+ printf ("\n");
+ fflush (stdout);
+ GNUNET_free_non_null (filename);
+ GNUNET_free (uri);
+ results++;
+ if ((results_limit > 0) && (results >= results_limit))
+ GNUNET_SCHEDULER_shutdown ();
+ break;
+ case GNUNET_FS_STATUS_SEARCH_UPDATE:
+ break;
+ case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED:
+ /* ignore */
+ break;
+ case GNUNET_FS_STATUS_SEARCH_ERROR:
+ fprintf (stderr,
+ _("Error searching: %s.\n"),
+ info->value.search.specifics.error.message);
+ GNUNET_SCHEDULER_shutdown ();
+ break;
+ case GNUNET_FS_STATUS_SEARCH_STOPPED:
+ GNUNET_SCHEDULER_add_continuation (&clean_task,
+ NULL,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ break;
+ default:
+ fprintf (stderr, _("Unexpected status: %d\n"), info->status);
+ break;
+ }
return NULL;
}
static void
-shutdown_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
if (sc != NULL)
- {
- GNUNET_FS_search_stop (sc);
- sc = NULL;
- }
+ {
+ GNUNET_FS_search_stop (sc);
+ sc = NULL;
+ }
}
@@ -235,8 +222,7 @@
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *c)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
{
struct GNUNET_FS_Uri *uri;
unsigned int argc;
@@ -246,63 +232,49 @@
argc = 0;
while (NULL != args[argc])
argc++;
- uri = GNUNET_FS_uri_ksk_create_from_args (argc,
- (const char **) args);
+ uri = GNUNET_FS_uri_ksk_create_from_args (argc, (const char **) args);
if (NULL == uri)
- {
- fprintf (stderr,
- _("Could not create keyword URI from arguments.\n"));
- ret = 1;
- return;
- }
+ {
+ fprintf (stderr, _("Could not create keyword URI from arguments.\n"));
+ ret = 1;
+ return;
+ }
cfg = c;
ctx = GNUNET_FS_start (cfg,
- "gnunet-search",
- &progress_cb,
- NULL,
- GNUNET_FS_FLAGS_NONE,
- GNUNET_FS_OPTIONS_END);
+ "gnunet-search",
+ &progress_cb,
+ NULL, GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
if (NULL == ctx)
- {
- fprintf (stderr,
- _("Could not initialize `%s' subsystem.\n"),
- "FS");
- GNUNET_FS_uri_destroy (uri);
- ret = 1;
- return;
- }
+ {
+ fprintf (stderr, _("Could not initialize `%s' subsystem.\n"), "FS");
+ GNUNET_FS_uri_destroy (uri);
+ ret = 1;
+ return;
+ }
if (output_filename != NULL)
db = GNUNET_FS_directory_builder_create (NULL);
options = GNUNET_FS_SEARCH_OPTION_NONE;
if (local_only)
options |= GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY;
- sc = GNUNET_FS_search_start (ctx,
- uri,
- anonymity,
- options,
- NULL);
+ sc = GNUNET_FS_search_start (ctx, uri, anonymity, options, NULL);
GNUNET_FS_uri_destroy (uri);
if (NULL == sc)
- {
- fprintf (stderr,
- _("Could not start searching.\n"));
- GNUNET_FS_stop (ctx);
- ret = 1;
- return;
- }
+ {
+ fprintf (stderr, _("Could not start searching.\n"));
+ GNUNET_FS_stop (ctx);
+ ret = 1;
+ return;
+ }
if (timeout != 0)
- {
- delay.rel_value = timeout;
- GNUNET_SCHEDULER_add_delayed (delay,
- &shutdown_task,
- NULL);
- }
+ {
+ delay.rel_value = timeout;
+ GNUNET_SCHEDULER_add_delayed (delay, &shutdown_task, NULL);
+ }
else
- {
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task,
- NULL);
- }
+ {
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
+ &shutdown_task, NULL);
+ }
}
@@ -324,12 +296,10 @@
gettext_noop ("only search the local peer (no P2P network search)"),
0, &GNUNET_GETOPT_set_one, &local_only},
{'o', "output", "PREFIX",
- gettext_noop
- ("write search results to file starting with PREFIX"),
- 1, &GNUNET_GETOPT_set_string, &output_filename},
+ gettext_noop ("write search results to file starting with PREFIX"),
+ 1, &GNUNET_GETOPT_set_string, &output_filename},
{'t', "timeout", "VALUE",
- gettext_noop
- ("automatically terminate search after VALUE ms"),
+ gettext_noop ("automatically terminate search after VALUE ms"),
1, &GNUNET_GETOPT_set_ulong, &timeout},
{'V', "verbose", NULL,
gettext_noop ("be verbose (print progress information)"),
@@ -339,7 +309,7 @@
("automatically terminate search after VALUE results are found"),
1, &GNUNET_GETOPT_set_ulong, &results_limit},
GNUNET_GETOPT_OPTION_END
- };
+ };
return (GNUNET_OK ==
GNUNET_PROGRAM_run (argc,
argv,
@@ -350,4 +320,3 @@
}
/* end of gnunet-search.c */
-
Modified: gnunet/src/fs/gnunet-service-fs.c
===================================================================
--- gnunet/src/fs/gnunet-service-fs.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/fs/gnunet-service-fs.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -162,14 +162,12 @@
* @param tc task context
*/
static void
-age_cover_counters (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+age_cover_counters (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GSF_cover_content_count = (GSF_cover_content_count * 15) / 16;
GSF_cover_query_count = (GSF_cover_query_count * 15) / 16;
cover_age_task = GNUNET_SCHEDULER_add_delayed (COVER_AGE_FREQUENCY,
- &age_cover_counters,
- NULL);
+ &age_cover_counters, NULL);
}
@@ -186,8 +184,7 @@
struct GNUNET_TIME_Relative delay;
delay = GNUNET_TIME_absolute_get_duration (start);
- GNUNET_LOAD_update (datastore_get_load,
- delay.rel_value);
+ GNUNET_LOAD_update (datastore_get_load, delay.rel_value);
}
@@ -207,9 +204,9 @@
ld = GNUNET_LOAD_get_load (datastore_get_load);
if (ld < 1)
- return GNUNET_SYSERR;
- if (ld <= priority)
- return GNUNET_NO;
+ return GNUNET_SYSERR;
+ if (ld <= priority)
+ return GNUNET_NO;
return GNUNET_YES;
}
@@ -227,18 +224,18 @@
*/
static int
handle_p2p_put (void *cls,
- const struct GNUNET_PeerIdentity *other,
- const struct GNUNET_MessageHeader *message,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+ const struct GNUNET_PeerIdentity *other,
+ const struct GNUNET_MessageHeader *message,
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
struct GSF_ConnectedPeer *cp;
cp = GSF_peer_get_ (other);
if (NULL == cp)
- {
- GNUNET_break (0);
- return GNUNET_OK;
- }
+ {
+ GNUNET_break (0);
+ return GNUNET_OK;
+ }
GSF_cover_content_count++;
return GSF_handle_p2p_content_ (cp, message);
}
@@ -255,9 +252,9 @@
*/
static void
consider_request_for_forwarding (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- struct GSF_ConnectedPeer *cp,
- const struct GSF_PeerPerformanceData *ppd)
+ const struct GNUNET_PeerIdentity *peer,
+ struct GSF_ConnectedPeer *cp,
+ const struct GSF_PeerPerformanceData *ppd)
{
struct GSF_PendingRequest *pr = cls;
@@ -277,13 +274,12 @@
*/
static void
consider_forwarding (void *cls,
- struct GSF_PendingRequest *pr,
- enum GNUNET_BLOCK_EvaluationResult result)
+ struct GSF_PendingRequest *pr,
+ enum GNUNET_BLOCK_EvaluationResult result)
{
if (GNUNET_BLOCK_EVALUATION_OK_LAST == result)
- return; /* we're done... */
- GSF_iterate_connected_peers_ (&consider_request_for_forwarding,
- pr);
+ return; /* we're done... */
+ GSF_iterate_connected_peers_ (&consider_request_for_forwarding, pr);
}
@@ -300,18 +296,16 @@
*/
static int
handle_p2p_get (void *cls,
- const struct GNUNET_PeerIdentity *other,
- const struct GNUNET_MessageHeader *message,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+ const struct GNUNET_PeerIdentity *other,
+ const struct GNUNET_MessageHeader *message,
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
struct GSF_PendingRequest *pr;
pr = GSF_handle_p2p_query_ (other, message);
if (NULL == pr)
return GNUNET_SYSERR;
- GSF_local_lookup_ (pr,
- &consider_forwarding,
- NULL);
+ GSF_local_lookup_ (pr, &consider_forwarding, NULL);
return GNUNET_OK;
}
@@ -328,8 +322,8 @@
*/
static void
start_p2p_processing (void *cls,
- struct GSF_PendingRequest *pr,
- enum GNUNET_BLOCK_EvaluationResult result)
+ struct GSF_PendingRequest *pr,
+ enum GNUNET_BLOCK_EvaluationResult result)
{
struct GNUNET_SERVER_Client *client = cls;
struct GSF_PendingRequestData *prd;
@@ -337,19 +331,17 @@
prd = GSF_pending_request_get_data_ (pr);
#if DEBUG_FS_CLIENT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Finished database lookup for local request `%s' with result
%d\n",
- GNUNET_h2s (&prd->query),
- result);
+ "Finished database lookup for local request `%s' with result
%d\n",
+ GNUNET_h2s (&prd->query), result);
#endif
- GNUNET_SERVER_receive_done (client,
- GNUNET_OK);
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
if (GNUNET_BLOCK_EVALUATION_OK_LAST == result)
- return; /* we're done, 'pr' was already destroyed... */
- if (0 != (GSF_PRO_LOCAL_ONLY & prd->options) )
- {
- GSF_pending_request_cancel_ (pr, GNUNET_YES);
- return;
- }
+ return; /* we're done, 'pr' was already destroyed... */
+ if (0 != (GSF_PRO_LOCAL_ONLY & prd->options))
+ {
+ GSF_pending_request_cancel_ (pr, GNUNET_YES);
+ return;
+ }
GSF_dht_lookup_ (pr);
consider_forwarding (NULL, pr, result);
}
@@ -364,20 +356,18 @@
*/
static void
handle_start_search (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
struct GSF_PendingRequest *pr;
pr = GSF_local_client_start_search_handler_ (client, message);
if (NULL == pr)
- {
- /* GNUNET_SERVER_receive_done was already called! */
- return;
- }
- GSF_local_lookup_ (pr,
- &start_p2p_processing,
- client);
+ {
+ /* GNUNET_SERVER_receive_done was already called! */
+ return;
+ }
+ GSF_local_lookup_ (pr, &start_p2p_processing, client);
}
@@ -388,14 +378,13 @@
* @param tc unused
*/
static void
-shutdown_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
if (NULL != GSF_core)
- {
- GNUNET_CORE_disconnect (GSF_core);
- GSF_core = NULL;
- }
+ {
+ GNUNET_CORE_disconnect (GSF_core);
+ GSF_core = NULL;
+ }
GSF_put_done_ ();
GSF_push_done_ ();
GSF_pending_request_done_ ();
@@ -412,10 +401,10 @@
GNUNET_STATISTICS_destroy (GSF_stats, GNUNET_NO);
GSF_stats = NULL;
if (GNUNET_SCHEDULER_NO_TASK != cover_age_task)
- {
- GNUNET_SCHEDULER_cancel (cover_age_task);
- cover_age_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (cover_age_task);
+ cover_age_task = GNUNET_SCHEDULER_NO_TASK;
+ }
GNUNET_FS_indexing_done ();
GNUNET_LOAD_value_free (datastore_get_load);
datastore_get_load = NULL;
@@ -436,11 +425,11 @@
*/
static int
consider_peer_for_forwarding (void *cls,
- const GNUNET_HashCode *key,
- struct GSF_PendingRequest *pr)
+ const GNUNET_HashCode * key,
+ struct GSF_PendingRequest *pr)
{
struct GSF_ConnectedPeer *cp = cls;
-
+
GSF_plan_add_ (cp, pr);
return GNUNET_YES;
}
@@ -453,20 +442,19 @@
* @param peer peer identity this notification is about
* @param atsi performance information
*/
-static void
+static void
peer_connect_handler (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+ const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
struct GSF_ConnectedPeer *cp;
if (0 == memcmp (&my_id, peer, sizeof (struct GNUNET_PeerIdentity)))
return;
- cp = GSF_peer_connect_handler_ (peer, atsi);
+ cp = GSF_peer_connect_handler_ (peer, atsi);
if (NULL == cp)
return;
- GSF_iterate_pending_requests_ (&consider_peer_for_forwarding,
- cp);
+ GSF_iterate_pending_requests_ (&consider_peer_for_forwarding, cp);
}
@@ -484,12 +472,10 @@
*/
static void
peer_init_handler (void *cls,
- struct GNUNET_CORE_Handle * server,
- const struct GNUNET_PeerIdentity *
- my_identity,
- const struct
- GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *
- publicKey)
+ struct GNUNET_CORE_Handle *server,
+ const struct GNUNET_PeerIdentity *my_identity,
+ const struct
+ GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
{
my_id = *my_identity;
}
@@ -503,59 +489,53 @@
*/
static int
main_init (struct GNUNET_SERVER_Handle *server,
- const struct GNUNET_CONFIGURATION_Handle *c)
+ const struct GNUNET_CONFIGURATION_Handle *c)
{
- static const struct GNUNET_CORE_MessageHandler p2p_handlers[] =
- {
- { &handle_p2p_get,
- GNUNET_MESSAGE_TYPE_FS_GET, 0 },
- { &handle_p2p_put,
- GNUNET_MESSAGE_TYPE_FS_PUT, 0 },
- { &GSF_handle_p2p_migration_stop_,
- GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP,
- sizeof (struct MigrationStopMessage) },
- { NULL, 0, 0 }
- };
+ static const struct GNUNET_CORE_MessageHandler p2p_handlers[] = {
+ {&handle_p2p_get,
+ GNUNET_MESSAGE_TYPE_FS_GET, 0},
+ {&handle_p2p_put,
+ GNUNET_MESSAGE_TYPE_FS_PUT, 0},
+ {&GSF_handle_p2p_migration_stop_,
+ GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP,
+ sizeof (struct MigrationStopMessage)},
+ {NULL, 0, 0}
+ };
static const struct GNUNET_SERVER_MessageHandler handlers[] = {
- {&GNUNET_FS_handle_index_start, NULL,
+ {&GNUNET_FS_handle_index_start, NULL,
GNUNET_MESSAGE_TYPE_FS_INDEX_START, 0},
- {&GNUNET_FS_handle_index_list_get, NULL,
- GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_GET, sizeof(struct
GNUNET_MessageHeader) },
- {&GNUNET_FS_handle_unindex, NULL, GNUNET_MESSAGE_TYPE_FS_UNINDEX,
- sizeof (struct UnindexMessage) },
- {&handle_start_search, NULL, GNUNET_MESSAGE_TYPE_FS_START_SEARCH,
- 0 },
+ {&GNUNET_FS_handle_index_list_get, NULL,
+ GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_GET,
+ sizeof (struct GNUNET_MessageHeader)},
+ {&GNUNET_FS_handle_unindex, NULL, GNUNET_MESSAGE_TYPE_FS_UNINDEX,
+ sizeof (struct UnindexMessage)},
+ {&handle_start_search, NULL, GNUNET_MESSAGE_TYPE_FS_START_SEARCH,
+ 0},
{NULL, NULL, 0, 0}
};
- GSF_core = GNUNET_CORE_connect (GSF_cfg,
- 2, /* larger? */
- NULL,
- &peer_init_handler,
- &peer_connect_handler,
- &GSF_peer_disconnect_handler_,
- &GSF_peer_status_handler_,
- NULL, GNUNET_NO,
- NULL, GNUNET_NO,
- p2p_handlers);
+ GSF_core = GNUNET_CORE_connect (GSF_cfg, 2, /* larger? */
+ NULL,
+ &peer_init_handler,
+ &peer_connect_handler,
+ &GSF_peer_disconnect_handler_,
+ &GSF_peer_status_handler_,
+ NULL, GNUNET_NO,
+ NULL, GNUNET_NO, p2p_handlers);
if (NULL == GSF_core)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to connect to `%s' service.\n"),
- "core");
- return GNUNET_SYSERR;
- }
- GNUNET_SERVER_disconnect_notify (server,
- &GSF_client_disconnect_handler_,
- NULL);
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to connect to `%s' service.\n"), "core");
+ return GNUNET_SYSERR;
+ }
+ GNUNET_SERVER_disconnect_notify (server,
+ &GSF_client_disconnect_handler_, NULL);
GNUNET_SERVER_add_handlers (server, handlers);
cover_age_task = GNUNET_SCHEDULER_add_delayed (COVER_AGE_FREQUENCY,
- &age_cover_counters,
- NULL);
+ &age_cover_counters, NULL);
datastore_get_load = GNUNET_LOAD_value_init (DATASTORE_LOAD_AUTODECLINE);
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task,
- NULL);
+ &shutdown_task, NULL);
return GNUNET_OK;
}
@@ -573,37 +553,33 @@
const struct GNUNET_CONFIGURATION_Handle *cfg)
{
GSF_cfg = cfg;
- GSF_enable_randomized_delays = GNUNET_CONFIGURATION_get_value_yesno (cfg,
"fs", "DELAY");
+ GSF_enable_randomized_delays =
+ GNUNET_CONFIGURATION_get_value_yesno (cfg, "fs", "DELAY");
GSF_dsh = GNUNET_DATASTORE_connect (cfg);
if (NULL == GSF_dsh)
- {
- GNUNET_SCHEDULER_shutdown ();
- return;
- }
+ {
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
GSF_rt_entry_lifetime = GNUNET_LOAD_value_init
(GNUNET_TIME_UNIT_FOREVER_REL);
GSF_stats = GNUNET_STATISTICS_create ("fs", cfg);
block_cfg = GNUNET_CONFIGURATION_create ();
- GNUNET_CONFIGURATION_set_value_string (block_cfg,
- "block",
- "PLUGINS",
- "fs");
+ GNUNET_CONFIGURATION_set_value_string (block_cfg, "block", "PLUGINS", "fs");
GSF_block_ctx = GNUNET_BLOCK_context_create (block_cfg);
GNUNET_assert (NULL != GSF_block_ctx);
- GSF_dht = GNUNET_DHT_connect (cfg,
- FS_DHT_HT_SIZE);
+ GSF_dht = GNUNET_DHT_connect (cfg, FS_DHT_HT_SIZE);
GSF_plan_init ();
GSF_pending_request_init_ ();
GSF_connected_peer_init_ ();
GSF_push_init_ ();
GSF_put_init_ ();
- if ( (GNUNET_OK != GNUNET_FS_indexing_init (cfg, GSF_dsh)) ||
-
- (GNUNET_OK != main_init (server, cfg)) )
- {
- GNUNET_SCHEDULER_shutdown ();
- shutdown_task (NULL, NULL);
- return;
- }
+ if ((GNUNET_OK != GNUNET_FS_indexing_init (cfg, GSF_dsh)) ||
+ (GNUNET_OK != main_init (server, cfg)))
+ {
+ GNUNET_SCHEDULER_shutdown ();
+ shutdown_task (NULL, NULL);
+ return;
+ }
}
@@ -621,8 +597,7 @@
GNUNET_SERVICE_run (argc,
argv,
"fs",
- GNUNET_SERVICE_OPTION_NONE,
- &run, NULL)) ? 0 : 1;
+ GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
}
/* end of gnunet-service-fs.c */
Modified: gnunet/src/fs/gnunet-service-fs.h
===================================================================
--- gnunet/src/fs/gnunet-service-fs.h 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/fs/gnunet-service-fs.h 2011-08-15 21:46:35 UTC (rev 16581)
@@ -167,8 +167,7 @@
* GNUNET_NO to process normally (load normal)
* GNUNET_SYSERR to process for free (load low)
*/
-int
-GSF_test_get_load_too_high_ (uint32_t priority);
+int GSF_test_get_load_too_high_ (uint32_t priority);
/**
@@ -177,8 +176,7 @@
*
* @param start time when the datastore request was issued
*/
-void
-GSF_update_datastore_delay_ (struct GNUNET_TIME_Absolute start);
+void GSF_update_datastore_delay_ (struct GNUNET_TIME_Absolute start);
Modified: gnunet/src/fs/gnunet-service-fs_cp.c
===================================================================
--- gnunet/src/fs/gnunet-service-fs_cp.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/fs/gnunet-service-fs_cp.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -134,7 +134,7 @@
/**
* Kept in a doubly-linked list.
*/
- struct GSF_DelayedHandle *next;
+ struct GSF_DelayedHandle *next;
/**
* Kept in a doubly-linked list.
@@ -160,7 +160,7 @@
* Size of the message.
*/
size_t msize;
-
+
};
@@ -174,7 +174,7 @@
* Handle to generic request.
*/
struct GSF_PendingRequest *pr;
-
+
/**
* Handle to specific peer.
*/
@@ -191,7 +191,7 @@
/**
* A connected peer.
*/
-struct GSF_ConnectedPeer
+struct GSF_ConnectedPeer
{
/**
@@ -330,17 +330,17 @@
{
if (atsi == NULL)
return GNUNET_TIME_UNIT_SECONDS;
- while ( (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR) &&
- (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY) )
+ while ((ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR) &&
+ (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY))
atsi++;
- if (ntohl (atsi->type) == GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR)
- {
- GNUNET_break (0);
- /* how can we not have latency data? */
- return GNUNET_TIME_UNIT_SECONDS;
- }
+ if (ntohl (atsi->type) == GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR)
+ {
+ GNUNET_break (0);
+ /* how can we not have latency data? */
+ return GNUNET_TIME_UNIT_SECONDS;
+ }
return GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
- ntohl (atsi->value));
+ ntohl (atsi->value));
}
@@ -352,13 +352,12 @@
*/
static void
update_atsi (struct GSF_ConnectedPeer *cp,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
struct GNUNET_TIME_Relative latency;
latency = get_latency (atsi);
- GNUNET_LOAD_value_set_decline (cp->ppd.transmission_delay,
- latency);
+ GNUNET_LOAD_value_set_decline (cp->ppd.transmission_delay, latency);
/* LATER: merge atsi into cp's performance data (if we ever care...) */
}
@@ -384,10 +383,7 @@
* @param buf where to copy the message
* @return number of bytes copied to buf
*/
-static size_t
-peer_transmit_ready_cb (void *cls,
- size_t size,
- void *buf);
+static size_t peer_transmit_ready_cb (void *cls, size_t size, void *buf);
@@ -406,11 +402,11 @@
*/
static void
core_reserve_callback (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
- int32_t amount,
- struct GNUNET_TIME_Relative res_delay,
- uint64_t preference);
+ const struct GNUNET_PeerIdentity *peer,
+ struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
+ int32_t amount,
+ struct GNUNET_TIME_Relative res_delay,
+ uint64_t preference);
/**
@@ -426,43 +422,38 @@
struct GNUNET_PeerIdentity target;
uint64_t ip;
- if ( (NULL != pth->cth) ||
- (0 != pth->cth_in_progress) )
- return; /* already done */
+ if ((NULL != pth->cth) || (0 != pth->cth_in_progress))
+ return; /* already done */
cp = pth->cp;
GNUNET_assert (0 != cp->ppd.pid);
- GNUNET_PEER_resolve (cp->ppd.pid,
- &target);
- if ( (GNUNET_YES == pth->is_query) &&
- (GNUNET_YES != pth->was_reserved) )
- {
- /* query, need reservation */
- if (GNUNET_YES != cp->did_reserve)
- return; /* not ready */
- cp->did_reserve = GNUNET_NO;
- /* reservation already done! */
- pth->was_reserved = GNUNET_YES;
- ip = cp->inc_preference;
- cp->inc_preference = 0;
- cp->irc = GNUNET_CORE_peer_change_preference (GSF_core,
- &target,
-
GNUNET_TIME_UNIT_FOREVER_REL,
- GNUNET_BANDWIDTH_VALUE_MAX,
- DBLOCK_SIZE,
- ip,
- &core_reserve_callback,
- cp);
- }
+ GNUNET_PEER_resolve (cp->ppd.pid, &target);
+ if ((GNUNET_YES == pth->is_query) && (GNUNET_YES != pth->was_reserved))
+ {
+ /* query, need reservation */
+ if (GNUNET_YES != cp->did_reserve)
+ return; /* not ready */
+ cp->did_reserve = GNUNET_NO;
+ /* reservation already done! */
+ pth->was_reserved = GNUNET_YES;
+ ip = cp->inc_preference;
+ cp->inc_preference = 0;
+ cp->irc = GNUNET_CORE_peer_change_preference (GSF_core,
+ &target,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_BANDWIDTH_VALUE_MAX,
+ DBLOCK_SIZE,
+ ip,
+ &core_reserve_callback, cp);
+ }
GNUNET_assert (pth->cth == NULL);
pth->cth_in_progress++;
pth->cth = GNUNET_CORE_notify_transmit_ready (GSF_core,
- GNUNET_YES,
- pth->priority,
-
GNUNET_TIME_absolute_get_remaining (pth->timeout),
- &target,
- pth->size,
- &peer_transmit_ready_cb,
- pth);
+ GNUNET_YES,
+ pth->priority,
+
GNUNET_TIME_absolute_get_remaining
+ (pth->timeout), &target,
+ pth->size,
+ &peer_transmit_ready_cb, pth);
GNUNET_assert (0 < pth->cth_in_progress--);
}
@@ -476,46 +467,43 @@
* @return number of bytes copied to buf
*/
static size_t
-peer_transmit_ready_cb (void *cls,
- size_t size,
- void *buf)
+peer_transmit_ready_cb (void *cls, size_t size, void *buf)
{
struct GSF_PeerTransmitHandle *pth = cls;
struct GSF_PeerTransmitHandle *pos;
struct GSF_ConnectedPeer *cp;
size_t ret;
- GNUNET_assert ( (NULL == buf) ||
- (pth->size <= size) );
+ GNUNET_assert ((NULL == buf) || (pth->size <= size));
pth->cth = NULL;
if (pth->timeout_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (pth->timeout_task);
- pth->timeout_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (pth->timeout_task);
+ pth->timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ }
cp = pth->cp;
- GNUNET_CONTAINER_DLL_remove (cp->pth_head,
- cp->pth_tail,
- pth);
+ GNUNET_CONTAINER_DLL_remove (cp->pth_head, cp->pth_tail, pth);
if (GNUNET_YES == pth->is_query)
- {
- cp->ppd.last_request_times[(cp->last_request_times_off++) %
MAX_QUEUE_PER_PEER] = GNUNET_TIME_absolute_get ();
- GNUNET_assert (0 < cp->ppd.pending_queries--);
- }
+ {
+ cp->ppd.last_request_times[(cp->last_request_times_off++) %
+ MAX_QUEUE_PER_PEER] =
+ GNUNET_TIME_absolute_get ();
+ GNUNET_assert (0 < cp->ppd.pending_queries--);
+ }
else if (GNUNET_NO == pth->is_query)
- {
- GNUNET_assert (0 < cp->ppd.pending_replies--);
- }
+ {
+ GNUNET_assert (0 < cp->ppd.pending_replies--);
+ }
GNUNET_LOAD_update (cp->ppd.transmission_delay,
- GNUNET_TIME_absolute_get_duration
(pth->transmission_request_start_time).rel_value);
- ret = pth->gmc (pth->gmc_cls,
- size, buf);
+ GNUNET_TIME_absolute_get_duration
+ (pth->transmission_request_start_time).rel_value);
+ ret = pth->gmc (pth->gmc_cls, size, buf);
GNUNET_assert (NULL == pth->cth);
for (pos = cp->pth_head; pos != NULL; pos = pos->next)
- {
- GNUNET_assert (pos != pth);
- schedule_transmission (pos);
- }
+ {
+ GNUNET_assert (pos != pth);
+ schedule_transmission (pos);
+ }
GNUNET_assert (pth->cth == NULL);
GNUNET_assert (pth->cth_in_progress == 0);
GNUNET_free (pth);
@@ -530,26 +518,22 @@
* @param tc scheduler context
*/
static void
-retry_reservation (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+retry_reservation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GSF_ConnectedPeer *cp = cls;
uint64_t ip;
struct GNUNET_PeerIdentity target;
- GNUNET_PEER_resolve (cp->ppd.pid,
- &target);
+ GNUNET_PEER_resolve (cp->ppd.pid, &target);
cp->irc_delay_task = GNUNET_SCHEDULER_NO_TASK;
ip = cp->inc_preference;
cp->inc_preference = 0;
cp->irc = GNUNET_CORE_peer_change_preference (GSF_core,
- &target,
- GNUNET_TIME_UNIT_FOREVER_REL,
- GNUNET_BANDWIDTH_VALUE_MAX,
- DBLOCK_SIZE,
- ip,
- &core_reserve_callback,
- cp);
+ &target,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_BANDWIDTH_VALUE_MAX,
+ DBLOCK_SIZE,
+ ip, &core_reserve_callback,
cp);
}
@@ -567,40 +551,37 @@
*/
static void
core_reserve_callback (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
- int32_t amount,
- struct GNUNET_TIME_Relative res_delay,
- uint64_t preference)
+ const struct GNUNET_PeerIdentity *peer,
+ struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
+ int32_t amount,
+ struct GNUNET_TIME_Relative res_delay,
+ uint64_t preference)
{
struct GSF_ConnectedPeer *cp = cls;
struct GSF_PeerTransmitHandle *pth;
cp->irc = NULL;
if (0 == amount)
- {
- cp->irc_delay_task = GNUNET_SCHEDULER_add_delayed (res_delay,
- &retry_reservation,
- cp);
- return;
- }
+ {
+ cp->irc_delay_task = GNUNET_SCHEDULER_add_delayed (res_delay,
+ &retry_reservation, cp);
+ return;
+ }
cp->did_reserve = GNUNET_YES;
pth = cp->pth_head;
- if ( (NULL != pth) &&
- (NULL == pth->cth) )
- {
- /* reservation success, try transmission now! */
- pth->cth_in_progress++;
- pth->cth = GNUNET_CORE_notify_transmit_ready (GSF_core,
- GNUNET_YES,
- pth->priority,
-
GNUNET_TIME_absolute_get_remaining (pth->timeout),
- peer,
- pth->size,
- &peer_transmit_ready_cb,
- pth);
- GNUNET_assert (0 < pth->cth_in_progress--);
- }
+ if ((NULL != pth) && (NULL == pth->cth))
+ {
+ /* reservation success, try transmission now! */
+ pth->cth_in_progress++;
+ pth->cth = GNUNET_CORE_notify_transmit_ready (GSF_core,
+ GNUNET_YES,
+ pth->priority,
+
GNUNET_TIME_absolute_get_remaining
+ (pth->timeout), peer,
+ pth->size,
+ &peer_transmit_ready_cb,
pth);
+ GNUNET_assert (0 < pth->cth_in_progress--);
+ }
}
@@ -614,7 +595,7 @@
*/
struct GSF_ConnectedPeer *
GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
struct GSF_ConnectedPeer *cp;
char *fn;
@@ -624,13 +605,11 @@
cp->ppd.pid = GNUNET_PEER_intern (peer);
cp->ppd.transmission_delay = GNUNET_LOAD_value_init (GNUNET_TIME_UNIT_ZERO);
cp->irc = GNUNET_CORE_peer_change_preference (GSF_core,
- peer,
- GNUNET_TIME_UNIT_FOREVER_REL,
- GNUNET_BANDWIDTH_VALUE_MAX,
- DBLOCK_SIZE,
- 0,
- &core_reserve_callback,
- cp);
+ peer,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_BANDWIDTH_VALUE_MAX,
+ DBLOCK_SIZE,
+ 0, &core_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))))
@@ -638,10 +617,10 @@
GNUNET_free (fn);
cp->request_map = GNUNET_CONTAINER_multihashmap_create (128);
GNUNET_break (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_put (cp_map,
- &peer->hashPubKey,
- cp,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+ GNUNET_CONTAINER_multihashmap_put (cp_map,
+ &peer->hashPubKey,
+ cp,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
update_atsi (cp, atsi);
GSF_push_start_ (cp);
return cp;
@@ -656,23 +635,20 @@
* @param tc scheduler context
*/
static void
-revive_migration (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+revive_migration (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GSF_ConnectedPeer *cp = cls;
struct GNUNET_TIME_Relative bt;
-
+
cp->mig_revive_task = GNUNET_SCHEDULER_NO_TASK;
bt = GNUNET_TIME_absolute_get_remaining (cp->ppd.migration_blocked_until);
if (0 != bt.rel_value)
- {
- /* still time left... */
- cp->mig_revive_task
- = GNUNET_SCHEDULER_add_delayed (bt,
- &revive_migration,
- cp);
- return;
- }
+ {
+ /* still time left... */
+ cp->mig_revive_task
+ = GNUNET_SCHEDULER_add_delayed (bt, &revive_migration, cp);
+ return;
+ }
GSF_push_start_ (cp);
}
@@ -686,9 +662,9 @@
struct GSF_ConnectedPeer *
GSF_peer_get_ (const struct GNUNET_PeerIdentity *peer)
{
- if (NULL == cp_map) return NULL;
- return GNUNET_CONTAINER_multihashmap_get (cp_map,
- &peer->hashPubKey);
+ if (NULL == cp_map)
+ return NULL;
+ return GNUNET_CONTAINER_multihashmap_get (cp_map, &peer->hashPubKey);
}
@@ -705,36 +681,33 @@
*/
int
GSF_handle_p2p_migration_stop_ (void *cls,
- const struct GNUNET_PeerIdentity *other,
- const struct GNUNET_MessageHeader *message,
- const struct GNUNET_TRANSPORT_ATS_Information
*atsi)
+ const struct GNUNET_PeerIdentity *other,
+ const struct GNUNET_MessageHeader *message,
+ const struct GNUNET_TRANSPORT_ATS_Information
+ *atsi)
{
- struct GSF_ConnectedPeer *cp;
+ struct GSF_ConnectedPeer *cp;
const struct MigrationStopMessage *msm;
struct GNUNET_TIME_Relative bt;
- msm = (const struct MigrationStopMessage*) message;
- cp = GNUNET_CONTAINER_multihashmap_get (cp_map,
- &other->hashPubKey);
+ msm = (const struct MigrationStopMessage *) message;
+ cp = GNUNET_CONTAINER_multihashmap_get (cp_map, &other->hashPubKey);
if (cp == NULL)
- {
- GNUNET_break (0);
- return GNUNET_OK;
- }
+ {
+ GNUNET_break (0);
+ return GNUNET_OK;
+ }
bt = GNUNET_TIME_relative_ntoh (msm->duration);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Migration of content to peer `%s' blocked for %llu ms\n"),
- GNUNET_i2s (other),
- (unsigned long long) bt.rel_value);
+ _("Migration of content to peer `%s' blocked for %llu ms\n"),
+ GNUNET_i2s (other), (unsigned long long) bt.rel_value);
cp->ppd.migration_blocked_until = GNUNET_TIME_relative_to_absolute (bt);
if (cp->mig_revive_task == GNUNET_SCHEDULER_NO_TASK)
- {
- GSF_push_stop_ (cp);
- cp->mig_revive_task
- = GNUNET_SCHEDULER_add_delayed (bt,
- &revive_migration,
- cp);
- }
+ {
+ GSF_push_stop_ (cp);
+ cp->mig_revive_task
+ = GNUNET_SCHEDULER_add_delayed (bt, &revive_migration, cp);
+ }
update_atsi (cp, atsi);
return GNUNET_OK;
}
@@ -748,32 +721,28 @@
* @param buf where to copy the message, NULL on error (peer disconnect)
* @return number of bytes copied to 'buf', can be 0 (without indicating an
error)
*/
-static size_t
-copy_reply (void *cls,
- size_t buf_size,
- void *buf)
+static size_t
+copy_reply (void *cls, size_t buf_size, void *buf)
{
struct PutMessage *pm = cls;
size_t size;
if (buf != NULL)
- {
- GNUNET_assert (buf_size >= ntohs (pm->header.size));
- size = ntohs (pm->header.size);
- memcpy (buf, pm, size);
- GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# replies transmitted to other
peers"),
- 1,
- GNUNET_NO);
- }
+ {
+ GNUNET_assert (buf_size >= ntohs (pm->header.size));
+ size = ntohs (pm->header.size);
+ memcpy (buf, pm, size);
+ GNUNET_STATISTICS_update (GSF_stats,
+ gettext_noop
+ ("# replies transmitted to other peers"), 1,
+ GNUNET_NO);
+ }
else
- {
- size = 0;
- GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# replies dropped"),
- 1,
- GNUNET_NO);
- }
+ {
+ size = 0;
+ GNUNET_STATISTICS_update (GSF_stats,
+ gettext_noop ("# replies dropped"), 1,
GNUNET_NO);
+ }
GNUNET_free (pm);
return size;
}
@@ -788,9 +757,7 @@
* @return GNUNET_YES (continue to iterate)
*/
static int
-cancel_pending_request (void *cls,
- const GNUNET_HashCode *query,
- void *value)
+cancel_pending_request (void *cls, const GNUNET_HashCode * query, void *value)
{
struct PeerRequest *peerreq = value;
struct GSF_PendingRequest *pr = peerreq->pr;
@@ -798,19 +765,17 @@
struct GSF_PendingRequestData *prd;
if (peerreq->kill_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (peerreq->kill_task);
- peerreq->kill_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (peerreq->kill_task);
+ peerreq->kill_task = GNUNET_SCHEDULER_NO_TASK;
+ }
GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# P2P searches active"),
- -1,
- GNUNET_NO);
+ gettext_noop ("# P2P searches active"),
+ -1, GNUNET_NO);
prd = GSF_pending_request_get_data_ (pr);
GNUNET_break (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove (cp->request_map,
- &prd->query,
- peerreq));
+ GNUNET_CONTAINER_multihashmap_remove (cp->request_map,
+ &prd->query, peerreq));
GSF_pending_request_cancel_ (pr, GNUNET_NO);
GNUNET_free (peerreq);
return GNUNET_OK;
@@ -822,10 +787,9 @@
*
* @param cls the request to free
* @param tc task context
- */
+ */
static void
-peer_request_destroy (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+peer_request_destroy (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct PeerRequest *peerreq = cls;
struct GSF_PendingRequest *pr = peerreq->pr;
@@ -833,9 +797,7 @@
peerreq->kill_task = GNUNET_SCHEDULER_NO_TASK;
prd = GSF_pending_request_get_data_ (pr);
- cancel_pending_request (NULL,
- &prd->query,
- peerreq);
+ cancel_pending_request (NULL, &prd->query, peerreq);
}
@@ -846,27 +808,21 @@
* @param tc scheduler context
*/
static void
-transmit_delayed_now (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+transmit_delayed_now (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GSF_DelayedHandle *dh = cls;
struct GSF_ConnectedPeer *cp = dh->cp;
- GNUNET_CONTAINER_DLL_remove (cp->delayed_head,
- cp->delayed_tail,
- dh);
+ GNUNET_CONTAINER_DLL_remove (cp->delayed_head, cp->delayed_tail, dh);
if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
- {
- GNUNET_free (dh->pm);
- GNUNET_free (dh);
- return;
- }
+ {
+ GNUNET_free (dh->pm);
+ GNUNET_free (dh);
+ return;
+ }
(void) GSF_peer_transmit_ (cp, GNUNET_NO,
- UINT32_MAX,
- REPLY_TIMEOUT,
- dh->msize,
- ©_reply,
- dh->pm);
+ UINT32_MAX,
+ REPLY_TIMEOUT, dh->msize, ©_reply, dh->pm);
GNUNET_free (dh);
}
@@ -883,12 +839,12 @@
/* FIXME: replace 5000 with something relating to current observed P2P
message latency */
ret = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
- GNUNET_CRYPTO_random_u32
(GNUNET_CRYPTO_QUALITY_WEAK,
- 5000));
+ GNUNET_CRYPTO_random_u32
+ (GNUNET_CRYPTO_QUALITY_WEAK, 5000));
GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# artificial delays introduced
(ms)"),
- ret.rel_value,
- GNUNET_NO);
+ gettext_noop
+ ("# artificial delays introduced (ms)"),
+ ret.rel_value, GNUNET_NO);
return ret;
}
@@ -913,13 +869,12 @@
*/
static void
handle_p2p_reply (void *cls,
- enum GNUNET_BLOCK_EvaluationResult eval,
- struct GSF_PendingRequest *pr,
- uint32_t reply_anonymity_level,
- struct GNUNET_TIME_Absolute expiration,
- enum GNUNET_BLOCK_Type type,
- const void *data,
- size_t data_len)
+ enum GNUNET_BLOCK_EvaluationResult eval,
+ struct GSF_PendingRequest *pr,
+ uint32_t reply_anonymity_level,
+ struct GNUNET_TIME_Absolute expiration,
+ enum GNUNET_BLOCK_Type type,
+ const void *data, size_t data_len)
{
struct PeerRequest *peerreq = cls;
struct GSF_ConnectedPeer *cp = peerreq->cp;
@@ -927,101 +882,91 @@
struct PutMessage *pm;
size_t msize;
- GNUNET_assert (data_len + sizeof (struct PutMessage) <
GNUNET_SERVER_MAX_MESSAGE_SIZE);
+ GNUNET_assert (data_len + sizeof (struct PutMessage) <
+ GNUNET_SERVER_MAX_MESSAGE_SIZE);
GNUNET_assert (peerreq->pr == pr);
prd = GSF_pending_request_get_data_ (pr);
if (NULL == data)
- {
- GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# P2P searches active"),
- -1,
- GNUNET_NO);
- GNUNET_break (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove (cp->request_map,
- &prd->query,
- peerreq));
- GNUNET_free (peerreq);
- return;
- }
+ {
+ GNUNET_STATISTICS_update (GSF_stats,
+ gettext_noop ("# P2P searches active"),
+ -1, GNUNET_NO);
+ GNUNET_break (GNUNET_YES ==
+ GNUNET_CONTAINER_multihashmap_remove (cp->request_map,
+ &prd->query, peerreq));
+ GNUNET_free (peerreq);
+ return;
+ }
GNUNET_break (type != GNUNET_BLOCK_TYPE_ANY);
- if ( (prd->type != type) &&
- (prd->type != GNUNET_BLOCK_TYPE_ANY) )
- {
- GNUNET_break (0);
- return;
- }
+ if ((prd->type != type) && (prd->type != GNUNET_BLOCK_TYPE_ANY))
+ {
+ GNUNET_break (0);
+ return;
+ }
#if DEBUG_FS
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitting result for query `%s' to peer\n",
- GNUNET_h2s (&prd->query));
-#endif
+ "Transmitting result for query `%s' to peer\n",
+ GNUNET_h2s (&prd->query));
+#endif
GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# replies received for other peers"),
- 1,
- GNUNET_NO);
+ gettext_noop ("# replies received for other
peers"),
+ 1, GNUNET_NO);
msize = sizeof (struct PutMessage) + data_len;
if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
+ {
+ GNUNET_break (0);
+ return;
+ }
+ if ((reply_anonymity_level != UINT32_MAX) && (reply_anonymity_level > 1))
+ {
+ if (reply_anonymity_level - 1 > GSF_cover_content_count)
{
- GNUNET_break (0);
+ GNUNET_STATISTICS_update (GSF_stats,
+ gettext_noop
+ ("# replies dropped due to insufficient cover
traffic"),
+ 1, GNUNET_NO);
return;
}
- if ( (reply_anonymity_level != UINT32_MAX) &&
- (reply_anonymity_level > 1) )
- {
- if (reply_anonymity_level - 1 > GSF_cover_content_count)
- {
- GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# replies dropped due to
insufficient cover traffic"),
- 1,
- GNUNET_NO);
- return;
- }
- GSF_cover_content_count -= (reply_anonymity_level - 1);
- }
-
+ GSF_cover_content_count -= (reply_anonymity_level - 1);
+ }
+
pm = GNUNET_malloc (msize);
pm->header.type = htons (GNUNET_MESSAGE_TYPE_FS_PUT);
pm->header.size = htons (msize);
pm->type = htonl (type);
pm->expiration = GNUNET_TIME_absolute_hton (expiration);
memcpy (&pm[1], data, data_len);
- if ( (reply_anonymity_level != UINT32_MAX) &&
- (reply_anonymity_level != 0) &&
- (GSF_enable_randomized_delays == GNUNET_YES) )
- {
- struct GSF_DelayedHandle *dh;
+ if ((reply_anonymity_level != UINT32_MAX) &&
+ (reply_anonymity_level != 0) &&
+ (GSF_enable_randomized_delays == GNUNET_YES))
+ {
+ struct GSF_DelayedHandle *dh;
- dh = GNUNET_malloc (sizeof (struct GSF_DelayedHandle));
- dh->cp = cp;
- dh->pm = pm;
- dh->msize = msize;
- GNUNET_CONTAINER_DLL_insert (cp->delayed_head,
- cp->delayed_tail,
- dh);
- dh->delay_task = GNUNET_SCHEDULER_add_delayed (get_randomized_delay (),
- &transmit_delayed_now,
- dh);
- }
+ dh = GNUNET_malloc (sizeof (struct GSF_DelayedHandle));
+ dh->cp = cp;
+ dh->pm = pm;
+ dh->msize = msize;
+ GNUNET_CONTAINER_DLL_insert (cp->delayed_head, cp->delayed_tail, dh);
+ dh->delay_task = GNUNET_SCHEDULER_add_delayed (get_randomized_delay (),
+ &transmit_delayed_now, dh);
+ }
else
- {
- (void) GSF_peer_transmit_ (cp, GNUNET_NO,
- UINT32_MAX,
- REPLY_TIMEOUT,
- msize,
- ©_reply,
- pm);
- }
+ {
+ (void) GSF_peer_transmit_ (cp, GNUNET_NO,
+ UINT32_MAX,
+ REPLY_TIMEOUT, msize, ©_reply, pm);
+ }
if (eval != GNUNET_BLOCK_EVALUATION_OK_LAST)
return;
if (GNUNET_SCHEDULER_NO_TASK == peerreq->kill_task)
- {
- GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# P2P searches destroyed due to
ultimate reply"),
- 1,
- GNUNET_NO);
- peerreq->kill_task = GNUNET_SCHEDULER_add_now (&peer_request_destroy,
- peerreq);
- }
+ {
+ GNUNET_STATISTICS_update (GSF_stats,
+ gettext_noop
+ ("# P2P searches destroyed due to ultimate
reply"),
+ 1, GNUNET_NO);
+ peerreq->kill_task =
+ GNUNET_SCHEDULER_add_now (&peer_request_destroy, peerreq);
+ }
}
@@ -1040,25 +985,25 @@
return 0;
GNUNET_assert (cp != NULL);
if (value > 0)
+ {
+ if (cp->ppd.trust + value < cp->ppd.trust)
{
- if (cp->ppd.trust + value < cp->ppd.trust)
- {
- value = UINT32_MAX - cp->ppd.trust;
- cp->ppd.trust = UINT32_MAX;
- }
- else
- cp->ppd.trust += value;
+ value = UINT32_MAX - cp->ppd.trust;
+ cp->ppd.trust = UINT32_MAX;
}
+ else
+ cp->ppd.trust += value;
+ }
else
+ {
+ if (cp->ppd.trust < -value)
{
- if (cp->ppd.trust < -value)
- {
- value = -cp->ppd.trust;
- cp->ppd.trust = 0;
- }
- else
- cp->ppd.trust += value;
+ value = -cp->ppd.trust;
+ cp->ppd.trust = 0;
}
+ else
+ cp->ppd.trust += value;
+ }
return value;
}
@@ -1072,8 +1017,7 @@
* @return effective priority
*/
static int32_t
-bound_priority (uint32_t prio_in,
- struct GSF_ConnectedPeer *cp)
+bound_priority (uint32_t prio_in, struct GSF_ConnectedPeer *cp)
{
#define N ((double)128.0)
uint32_t ret;
@@ -1082,47 +1026,46 @@
ld = GSF_test_get_load_too_high_ (0);
if (ld == GNUNET_SYSERR)
- {
- GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# requests done for free (low
load)"),
- 1,
- GNUNET_NO);
- return 0; /* excess resources */
- }
+ {
+ GNUNET_STATISTICS_update (GSF_stats,
+ gettext_noop
+ ("# requests done for free (low load)"), 1,
+ GNUNET_NO);
+ return 0; /* excess resources */
+ }
if (prio_in > INT32_MAX)
prio_in = INT32_MAX;
- ret = - change_host_trust (cp, - (int) prio_in);
+ ret = -change_host_trust (cp, -(int) prio_in);
if (ret > 0)
- {
- if (ret > GSF_current_priorities + N)
- rret = GSF_current_priorities + N;
- else
- rret = ret;
- GSF_current_priorities
- = (GSF_current_priorities * (N-1) + rret)/N;
- }
- if ( (ld == GNUNET_YES) && (ret > 0) )
- {
- /* try with charging */
- ld = GSF_test_get_load_too_high_ (ret);
- }
+ {
+ if (ret > GSF_current_priorities + N)
+ rret = GSF_current_priorities + N;
+ else
+ rret = ret;
+ GSF_current_priorities = (GSF_current_priorities * (N - 1) + rret) / N;
+ }
+ if ((ld == GNUNET_YES) && (ret > 0))
+ {
+ /* try with charging */
+ ld = GSF_test_get_load_too_high_ (ret);
+ }
if (ld == GNUNET_YES)
- {
- GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# request dropped, priority
insufficient"),
- 1,
- GNUNET_NO);
- /* undo charge */
- change_host_trust (cp, (int) ret);
- return -1; /* not enough resources */
- }
+ {
+ GNUNET_STATISTICS_update (GSF_stats,
+ gettext_noop
+ ("# request dropped, priority insufficient"), 1,
+ GNUNET_NO);
+ /* undo charge */
+ change_host_trust (cp, (int) ret);
+ return -1; /* not enough resources */
+ }
else
- {
- GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# requests done for a price
(normal load)"),
- 1,
- GNUNET_NO);
- }
+ {
+ GNUNET_STATISTICS_update (GSF_stats,
+ gettext_noop
+ ("# requests done for a price (normal load)"), 1,
+ GNUNET_NO);
+ }
#undef N
return ret;
}
@@ -1144,13 +1087,13 @@
if (ttl_in <= 0)
return ttl_in;
- allowed = ((unsigned long long) prio) * TTL_DECREMENT / 1000;
- if (ttl_in > allowed)
- {
- if (allowed >= (1 << 30))
- return 1 << 30;
- return allowed;
- }
+ allowed = ((unsigned long long) prio) * TTL_DECREMENT / 1000;
+ if (ttl_in > allowed)
+ {
+ if (allowed >= (1 << 30))
+ return 1 << 30;
+ return allowed;
+ }
return ttl_in;
}
@@ -1168,7 +1111,7 @@
*/
struct GSF_PendingRequest *
GSF_handle_p2p_query_ (const struct GNUNET_PeerIdentity *other,
- const struct GNUNET_MessageHeader *message)
+ const struct GNUNET_MessageHeader *message)
{
struct PeerRequest *peerreq;
struct GSF_PendingRequest *pr;
@@ -1177,7 +1120,7 @@
struct GSF_ConnectedPeer *cps;
const GNUNET_HashCode *namespace;
const struct GNUNET_PeerIdentity *target;
- enum GSF_PendingRequestOptions options;
+ enum GSF_PendingRequestOptions options;
uint16_t msize;
const struct GetMessage *gm;
unsigned int bits;
@@ -1191,229 +1134,214 @@
GNUNET_PEER_Id spid;
GNUNET_assert (other != NULL);
- msize = ntohs(message->size);
+ msize = ntohs (message->size);
if (msize < sizeof (struct GetMessage))
- {
- GNUNET_break_op (0);
- return NULL;
- }
+ {
+ GNUNET_break_op (0);
+ return NULL;
+ }
GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# GET requests received (from other
peers)"),
- 1,
- GNUNET_NO);
- gm = (const struct GetMessage*) message;
+ gettext_noop
+ ("# GET requests received (from other peers)"), 1,
+ GNUNET_NO);
+ gm = (const struct GetMessage *) message;
type = ntohl (gm->type);
bm = ntohl (gm->hash_bitmap);
bits = 0;
while (bm > 0)
- {
- if (1 == (bm & 1))
- bits++;
- bm >>= 1;
- }
+ {
+ if (1 == (bm & 1))
+ bits++;
+ bm >>= 1;
+ }
if (msize < sizeof (struct GetMessage) + bits * sizeof (GNUNET_HashCode))
- {
- GNUNET_break_op (0);
- return NULL;
- }
- opt = (const GNUNET_HashCode*) &gm[1];
+ {
+ GNUNET_break_op (0);
+ return NULL;
+ }
+ opt = (const GNUNET_HashCode *) &gm[1];
bfsize = msize - sizeof (struct GetMessage) - bits * sizeof
(GNUNET_HashCode);
/* bfsize must be power of 2, check! */
- if (0 != ( (bfsize - 1) & bfsize))
- {
- GNUNET_break_op (0);
- return NULL;
- }
+ if (0 != ((bfsize - 1) & bfsize))
+ {
+ GNUNET_break_op (0);
+ return NULL;
+ }
GSF_cover_query_count++;
bm = ntohl (gm->hash_bitmap);
bits = 0;
- cps = GNUNET_CONTAINER_multihashmap_get (cp_map,
- &other->hashPubKey);
+ cps = GNUNET_CONTAINER_multihashmap_get (cp_map, &other->hashPubKey);
if (NULL == cps)
- {
- /* peer must have just disconnected */
- GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# requests dropped due to
initiator not being connected"),
- 1,
- GNUNET_NO);
- return NULL;
- }
+ {
+ /* peer must have just disconnected */
+ GNUNET_STATISTICS_update (GSF_stats,
+ gettext_noop
+ ("# requests dropped due to initiator not being
connected"),
+ 1, GNUNET_NO);
+ return NULL;
+ }
if (0 != (bm & GET_MESSAGE_BIT_RETURN_TO))
- cp = GNUNET_CONTAINER_multihashmap_get (cp_map,
- &opt[bits++]);
+ cp = GNUNET_CONTAINER_multihashmap_get (cp_map, &opt[bits++]);
else
cp = cps;
if (cp == NULL)
- {
+ {
#if DEBUG_FS
- if (0 != (bm & GET_MESSAGE_BIT_RETURN_TO))
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Failed to find RETURN-TO peer `%4s' in connection set.
Dropping query.\n",
- GNUNET_i2s ((const struct GNUNET_PeerIdentity*)
&opt[bits-1]));
-
- else
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Failed to find peer `%4s' in connection set. Dropping
query.\n",
- GNUNET_i2s (other));
+ if (0 != (bm & GET_MESSAGE_BIT_RETURN_TO))
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to find RETURN-TO peer `%4s' in connection set.
Dropping query.\n",
+ GNUNET_i2s ((const struct GNUNET_PeerIdentity *)
+ &opt[bits - 1]));
+
+ else
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to find peer `%4s' in connection set. Dropping
query.\n",
+ GNUNET_i2s (other));
#endif
- GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# requests dropped due to
missing reverse route"),
- 1,
- GNUNET_NO);
- return NULL;
- }
+ GNUNET_STATISTICS_update (GSF_stats,
+ gettext_noop
+ ("# requests dropped due to missing reverse
route"),
+ 1, GNUNET_NO);
+ return NULL;
+ }
/* note that we can really only check load here since otherwise
- peers could find out that we are overloaded by not being
- disconnected after sending us a malformed query... */
+ * peers could find out that we are overloaded by not being
+ * disconnected after sending us a malformed query... */
priority = bound_priority (ntohl (gm->priority), cps);
if (priority < 0)
- {
+ {
#if DEBUG_FS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Dropping query from `%s', this peer is too busy.\n",
- GNUNET_i2s (other));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Dropping query from `%s', this peer is too busy.\n",
+ GNUNET_i2s (other));
#endif
- return NULL;
- }
-#if DEBUG_FS
+ return NULL;
+ }
+#if DEBUG_FS
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received request for `%s' of type %u from peer `%4s' with flags
%u\n",
- GNUNET_h2s (&gm->query),
- (unsigned int) type,
- GNUNET_i2s (other),
- (unsigned int) bm);
+ "Received request for `%s' of type %u from peer `%4s' with flags
%u\n",
+ GNUNET_h2s (&gm->query),
+ (unsigned int) type, GNUNET_i2s (other), (unsigned int) bm);
#endif
namespace = (0 != (bm & GET_MESSAGE_BIT_SKS_NAMESPACE)) ? &opt[bits++] :
NULL;
- if ( (type == GNUNET_BLOCK_TYPE_FS_SBLOCK) &&
- (namespace == NULL) )
- {
- GNUNET_break_op (0);
- return NULL;
- }
- if ( (type != GNUNET_BLOCK_TYPE_FS_SBLOCK) &&
- (namespace != NULL) )
- {
- GNUNET_break_op (0);
- return NULL;
- }
- target = (0 != (bm & GET_MESSAGE_BIT_TRANSMIT_TO)) ? ((const struct
GNUNET_PeerIdentity*) &opt[bits++]) : NULL;
+ if ((type == GNUNET_BLOCK_TYPE_FS_SBLOCK) && (namespace == NULL))
+ {
+ GNUNET_break_op (0);
+ return NULL;
+ }
+ if ((type != GNUNET_BLOCK_TYPE_FS_SBLOCK) && (namespace != NULL))
+ {
+ GNUNET_break_op (0);
+ return NULL;
+ }
+ target =
+ (0 !=
+ (bm & GET_MESSAGE_BIT_TRANSMIT_TO)) ? ((const struct GNUNET_PeerIdentity
+ *) &opt[bits++]) : NULL;
options = 0;
spid = 0;
- if ( (GNUNET_LOAD_get_load (cp->ppd.transmission_delay) > 3 * (1 +
priority)) ||
- (GNUNET_LOAD_get_average (cp->ppd.transmission_delay) >
- GNUNET_CONSTANTS_MAX_CORK_DELAY.rel_value * 2 + GNUNET_LOAD_get_average
(GSF_rt_entry_lifetime)) )
- {
- /* don't have BW to send to peer, or would likely take longer than we
have for it,
- so at best indirect the query */
- priority = 0;
- options |= GSF_PRO_FORWARD_ONLY;
- spid = GNUNET_PEER_intern (other);
- GNUNET_assert (0 != spid);
- }
+ if ((GNUNET_LOAD_get_load (cp->ppd.transmission_delay) > 3 * (1 + priority))
+ || (GNUNET_LOAD_get_average (cp->ppd.transmission_delay) >
+ GNUNET_CONSTANTS_MAX_CORK_DELAY.rel_value * 2 +
+ GNUNET_LOAD_get_average (GSF_rt_entry_lifetime)))
+ {
+ /* don't have BW to send to peer, or would likely take longer than we have
for it,
+ * so at best indirect the query */
+ priority = 0;
+ options |= GSF_PRO_FORWARD_ONLY;
+ spid = GNUNET_PEER_intern (other);
+ GNUNET_assert (0 != spid);
+ }
ttl = bound_ttl (ntohl (gm->ttl), priority);
/* decrement ttl (always) */
ttl_decrement = 2 * TTL_DECREMENT +
- GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
- TTL_DECREMENT);
- if ( (ttl < 0) &&
- (((int32_t)(ttl - ttl_decrement)) > 0) )
- {
+ GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, TTL_DECREMENT);
+ if ((ttl < 0) && (((int32_t) (ttl - ttl_decrement)) > 0))
+ {
#if DEBUG_FS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Dropping query from `%s' due to TTL underflow (%d - %u).\n",
- GNUNET_i2s (other),
- ttl,
- ttl_decrement);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Dropping query from `%s' due to TTL underflow (%d - %u).\n",
+ GNUNET_i2s (other), ttl, ttl_decrement);
#endif
- GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# requests dropped due TTL
underflow"),
- 1,
- GNUNET_NO);
- /* integer underflow => drop (should be very rare)! */
- return NULL;
- }
+ GNUNET_STATISTICS_update (GSF_stats,
+ gettext_noop
+ ("# requests dropped due TTL underflow"), 1,
+ GNUNET_NO);
+ /* integer underflow => drop (should be very rare)! */
+ return NULL;
+ }
ttl -= ttl_decrement;
/* test if the request already exists */
- peerreq = GNUNET_CONTAINER_multihashmap_get (cp->request_map,
- &gm->query);
- if (peerreq != NULL)
- {
- pr = peerreq->pr;
- prd = GSF_pending_request_get_data_ (pr);
- if ( (prd->type == type) &&
- ( (type != GNUNET_BLOCK_TYPE_FS_SBLOCK) ||
- (0 == memcmp (&prd->namespace,
- namespace,
- sizeof (GNUNET_HashCode))) ) )
- {
- if (prd->ttl.abs_value >= GNUNET_TIME_absolute_get().abs_value + ttl)
- {
- /* existing request has higher TTL, drop new one! */
- prd->priority += priority;
+ peerreq = GNUNET_CONTAINER_multihashmap_get (cp->request_map, &gm->query);
+ if (peerreq != NULL)
+ {
+ pr = peerreq->pr;
+ prd = GSF_pending_request_get_data_ (pr);
+ if ((prd->type == type) &&
+ ((type != GNUNET_BLOCK_TYPE_FS_SBLOCK) ||
+ (0 == memcmp (&prd->namespace, namespace, sizeof (GNUNET_HashCode)))))
+ {
+ if (prd->ttl.abs_value >= GNUNET_TIME_absolute_get ().abs_value + ttl)
+ {
+ /* existing request has higher TTL, drop new one! */
+ prd->priority += priority;
#if DEBUG_FS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Have existing request with higher TTL, dropping new
request.\n",
- GNUNET_i2s (other));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Have existing request with higher TTL, dropping new
request.\n",
+ GNUNET_i2s (other));
#endif
- GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# requests dropped due
to higher-TTL request"),
- 1,
- GNUNET_NO);
- return NULL;
- }
- /* existing request has lower TTL, drop old one! */
- GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# P2P searches active"),
- -1,
- GNUNET_NO);
- priority += prd->priority;
- GSF_pending_request_cancel_ (pr, GNUNET_YES);
- GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove (cp->request_map,
- &gm->query,
- peerreq));
- if (peerreq->kill_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (peerreq->kill_task);
- peerreq->kill_task = GNUNET_SCHEDULER_NO_TASK;
- }
- GNUNET_free (peerreq);
- }
+ GNUNET_STATISTICS_update (GSF_stats,
+ gettext_noop
+ ("# requests dropped due to higher-TTL
request"),
+ 1, GNUNET_NO);
+ return NULL;
+ }
+ /* existing request has lower TTL, drop old one! */
+ GNUNET_STATISTICS_update (GSF_stats,
+ gettext_noop ("# P2P searches active"),
+ -1, GNUNET_NO);
+ priority += prd->priority;
+ GSF_pending_request_cancel_ (pr, GNUNET_YES);
+ GNUNET_assert (GNUNET_YES ==
+ GNUNET_CONTAINER_multihashmap_remove (cp->request_map,
+ &gm->query,
+ peerreq));
+ if (peerreq->kill_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (peerreq->kill_task);
+ peerreq->kill_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ GNUNET_free (peerreq);
}
-
+ }
+
peerreq = GNUNET_malloc (sizeof (struct PeerRequest));
- peerreq->cp = cp;
+ peerreq->cp = cp;
pr = GSF_pending_request_create_ (options,
- type,
- &gm->query,
- namespace,
- target,
- (bfsize > 0) ? (const char*)&opt[bits] :
NULL,
- bfsize,
- ntohl (gm->filter_mutator),
- 1 /* anonymity */,
- (uint32_t) priority,
- ttl,
- spid,
- NULL, 0, /* replies_seen */
- &handle_p2p_reply,
- peerreq);
+ type,
+ &gm->query,
+ namespace,
+ target,
+ (bfsize >
+ 0) ? (const char *) &opt[bits] : NULL,
+ bfsize, ntohl (gm->filter_mutator),
+ 1 /* anonymity */ ,
+ (uint32_t) priority, ttl, spid, NULL, 0,
/* replies_seen */
+ &handle_p2p_reply, peerreq);
GNUNET_assert (NULL != pr);
peerreq->pr = pr;
GNUNET_break (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_put (cp->request_map,
- &gm->query,
- peerreq,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
+ GNUNET_CONTAINER_multihashmap_put (cp->request_map,
+ &gm->query,
+ peerreq,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# P2P query messages received and
processed"),
- 1,
- GNUNET_NO);
- GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# P2P searches active"),
- 1,
- GNUNET_NO);
+ gettext_noop
+ ("# P2P query messages received and processed"), 1,
+ GNUNET_NO);
+ GNUNET_STATISTICS_update (GSF_stats, gettext_noop ("# P2P searches active"),
+ 1, GNUNET_NO);
return pr;
}
@@ -1426,34 +1354,29 @@
* @param tc scheduler context
*/
static void
-peer_transmit_timeout (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+peer_transmit_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext
*tc)
{
struct GSF_PeerTransmitHandle *pth = cls;
struct GSF_ConnectedPeer *cp;
#if DEBUG_FS
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Timeout trying to transmit to other peer\n");
-#endif
+ "Timeout trying to transmit to other peer\n");
+#endif
pth->timeout_task = GNUNET_SCHEDULER_NO_TASK;
cp = pth->cp;
- GNUNET_CONTAINER_DLL_remove (cp->pth_head,
- cp->pth_tail,
- pth);
+ GNUNET_CONTAINER_DLL_remove (cp->pth_head, cp->pth_tail, pth);
if (GNUNET_YES == pth->is_query)
- GNUNET_assert (0 < cp->ppd.pending_queries--);
+ GNUNET_assert (0 < cp->ppd.pending_queries--);
else if (GNUNET_NO == pth->is_query)
GNUNET_assert (0 < cp->ppd.pending_replies--);
- GNUNET_LOAD_update (cp->ppd.transmission_delay,
- UINT64_MAX);
+ GNUNET_LOAD_update (cp->ppd.transmission_delay, UINT64_MAX);
if (NULL != pth->cth)
- {
- GNUNET_CORE_notify_transmit_ready_cancel (pth->cth);
- pth->cth = NULL;
- }
- pth->gmc (pth->gmc_cls,
- 0, NULL);
+ {
+ GNUNET_CORE_notify_transmit_ready_cancel (pth->cth);
+ pth->cth = NULL;
+ }
+ pth->gmc (pth->gmc_cls, 0, NULL);
GNUNET_assert (0 == pth->cth_in_progress);
GNUNET_free (pth);
}
@@ -1475,12 +1398,10 @@
*/
struct GSF_PeerTransmitHandle *
GSF_peer_transmit_ (struct GSF_ConnectedPeer *cp,
- int is_query,
- uint32_t priority,
- struct GNUNET_TIME_Relative timeout,
- size_t size,
- GSF_GetMessageCallback gmc,
- void *gmc_cls)
+ int is_query,
+ uint32_t priority,
+ struct GNUNET_TIME_Relative timeout,
+ size_t size, GSF_GetMessageCallback gmc, void *gmc_cls)
{
struct GSF_PeerTransmitHandle *pth;
struct GSF_PeerTransmitHandle *pos;
@@ -1498,28 +1419,22 @@
/* insertion sort (by priority, descending) */
prev = NULL;
pos = cp->pth_head;
- while ( (pos != NULL) &&
- (pos->priority > priority) )
- {
- prev = pos;
- pos = pos->next;
- }
+ while ((pos != NULL) && (pos->priority > priority))
+ {
+ prev = pos;
+ pos = pos->next;
+ }
if (prev == NULL)
- GNUNET_CONTAINER_DLL_insert (cp->pth_head,
- cp->pth_tail,
- pth);
+ GNUNET_CONTAINER_DLL_insert (cp->pth_head, cp->pth_tail, pth);
else
- GNUNET_CONTAINER_DLL_insert_after (cp->pth_head,
- cp->pth_tail,
- prev,
- pth);
+ GNUNET_CONTAINER_DLL_insert_after (cp->pth_head, cp->pth_tail, prev, pth);
if (GNUNET_YES == is_query)
cp->ppd.pending_queries++;
else if (GNUNET_NO == is_query)
cp->ppd.pending_replies++;
pth->timeout_task = GNUNET_SCHEDULER_add_delayed (timeout,
- &peer_transmit_timeout,
- pth);
+ &peer_transmit_timeout,
+ pth);
schedule_transmission (pth);
return pth;
}
@@ -1536,21 +1451,19 @@
struct GSF_ConnectedPeer *cp;
if (pth->timeout_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (pth->timeout_task);
- pth->timeout_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (pth->timeout_task);
+ pth->timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ }
if (NULL != pth->cth)
- {
- GNUNET_CORE_notify_transmit_ready_cancel (pth->cth);
- pth->cth = NULL;
- }
+ {
+ GNUNET_CORE_notify_transmit_ready_cancel (pth->cth);
+ pth->cth = NULL;
+ }
cp = pth->cp;
- GNUNET_CONTAINER_DLL_remove (cp->pth_head,
- cp->pth_tail,
- pth);
+ GNUNET_CONTAINER_DLL_remove (cp->pth_head, cp->pth_tail, pth);
if (GNUNET_YES == pth->is_query)
- GNUNET_assert (0 < cp->ppd.pending_queries--);
+ GNUNET_assert (0 < cp->ppd.pending_queries--);
else if (GNUNET_NO == pth->is_query)
GNUNET_assert (0 < cp->ppd.pending_replies--);
GNUNET_assert (0 == pth->cth_in_progress);
@@ -1567,14 +1480,18 @@
*/
void
GSF_peer_update_performance_ (struct GSF_ConnectedPeer *cp,
- struct GNUNET_TIME_Absolute request_time,
- uint32_t request_priority)
+ struct GNUNET_TIME_Absolute request_time,
+ uint32_t request_priority)
{
struct GNUNET_TIME_Relative delay;
- delay = GNUNET_TIME_absolute_get_duration (request_time);
- cp->ppd.avg_reply_delay.rel_value = (cp->ppd.avg_reply_delay.rel_value *
(RUNAVG_DELAY_N-1) + delay.rel_value) / RUNAVG_DELAY_N;
- cp->ppd.avg_priority = (cp->ppd.avg_priority * (RUNAVG_DELAY_N-1) +
request_priority) / RUNAVG_DELAY_N;
+ delay = GNUNET_TIME_absolute_get_duration (request_time);
+ cp->ppd.avg_reply_delay.rel_value =
+ (cp->ppd.avg_reply_delay.rel_value * (RUNAVG_DELAY_N - 1) +
+ delay.rel_value) / RUNAVG_DELAY_N;
+ cp->ppd.avg_priority =
+ (cp->ppd.avg_priority * (RUNAVG_DELAY_N - 1) +
+ request_priority) / RUNAVG_DELAY_N;
}
@@ -1587,9 +1504,10 @@
*/
void
GSF_peer_update_responder_client_ (struct GSF_ConnectedPeer *cp,
- struct GSF_LocalClient *initiator_client)
+ struct GSF_LocalClient *initiator_client)
{
- cp->ppd.last_client_replies[cp->last_client_replies_woff++ %
CS2P_SUCCESS_LIST_SIZE] = initiator_client;
+ cp->ppd.last_client_replies[cp->last_client_replies_woff++ %
+ CS2P_SUCCESS_LIST_SIZE] = initiator_client;
}
@@ -1602,7 +1520,7 @@
*/
void
GSF_peer_update_responder_peer_ (struct GSF_ConnectedPeer *cp,
- const struct GSF_ConnectedPeer *initiator_peer)
+ const struct GSF_ConnectedPeer
*initiator_peer)
{
unsigned int woff;
@@ -1627,16 +1545,15 @@
*/
void
GSF_peer_status_handler_ (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
- struct GNUNET_TIME_Absolute timeout,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+ const struct GNUNET_PeerIdentity *peer,
+ struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
+ struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
+ struct GNUNET_TIME_Absolute timeout,
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
struct GSF_ConnectedPeer *cp;
- cp = GNUNET_CONTAINER_multihashmap_get (cp_map,
- &peer->hashPubKey);
+ cp = GNUNET_CONTAINER_multihashmap_get (cp_map, &peer->hashPubKey);
GNUNET_assert (NULL != cp);
update_atsi (cp, atsi);
}
@@ -1650,40 +1567,36 @@
* @param peer identity of peer that connected
*/
void
-GSF_peer_disconnect_handler_ (void *cls,
- const struct GNUNET_PeerIdentity *peer)
+GSF_peer_disconnect_handler_ (void *cls, const struct GNUNET_PeerIdentity
*peer)
{
struct GSF_ConnectedPeer *cp;
struct GSF_PeerTransmitHandle *pth;
struct GSF_DelayedHandle *dh;
- cp = GNUNET_CONTAINER_multihashmap_get (cp_map,
- &peer->hashPubKey);
+ cp = GNUNET_CONTAINER_multihashmap_get (cp_map, &peer->hashPubKey);
if (NULL == cp)
- return; /* must have been disconnect from core with
- 'peer' == my_id, ignore */
+ return; /* must have been disconnect from core with
+ * 'peer' == my_id, ignore */
GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove (cp_map,
- &peer->hashPubKey,
- cp));
+ GNUNET_CONTAINER_multihashmap_remove (cp_map,
+ &peer->hashPubKey, cp));
if (NULL != cp->migration_pth)
- {
- GSF_peer_transmit_cancel_ (cp->migration_pth);
- cp->migration_pth = NULL;
- }
+ {
+ GSF_peer_transmit_cancel_ (cp->migration_pth);
+ cp->migration_pth = NULL;
+ }
if (NULL != cp->irc)
- {
- GNUNET_CORE_peer_change_preference_cancel (cp->irc);
- cp->irc = NULL;
- }
+ {
+ GNUNET_CORE_peer_change_preference_cancel (cp->irc);
+ cp->irc = NULL;
+ }
if (GNUNET_SCHEDULER_NO_TASK != cp->irc_delay_task)
- {
- GNUNET_SCHEDULER_cancel (cp->irc_delay_task);
- cp->irc_delay_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (cp->irc_delay_task);
+ cp->irc_delay_task = GNUNET_SCHEDULER_NO_TASK;
+ }
GNUNET_CONTAINER_multihashmap_iterate (cp->request_map,
- &cancel_pending_request,
- cp);
+ &cancel_pending_request, cp);
GNUNET_CONTAINER_multihashmap_destroy (cp->request_map);
cp->request_map = NULL;
GSF_plan_notify_peer_disconnect_ (cp);
@@ -1692,40 +1605,35 @@
memset (cp->ppd.last_p2p_replies, 0, sizeof (cp->ppd.last_p2p_replies));
GSF_push_stop_ (cp);
while (NULL != (pth = cp->pth_head))
+ {
+ if (NULL != pth->cth)
{
- if (NULL != pth->cth)
- {
- GNUNET_CORE_notify_transmit_ready_cancel (pth->cth);
- pth->cth = NULL;
- }
- if (pth->timeout_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (pth->timeout_task);
- pth->timeout_task = GNUNET_SCHEDULER_NO_TASK;
- }
- GNUNET_CONTAINER_DLL_remove (cp->pth_head,
- cp->pth_tail,
- pth);
- GNUNET_assert (0 == pth->cth_in_progress);
- pth->gmc (pth->gmc_cls,
- 0, NULL);
- GNUNET_free (pth);
+ GNUNET_CORE_notify_transmit_ready_cancel (pth->cth);
+ pth->cth = NULL;
}
- while (NULL != (dh = cp->delayed_head))
+ if (pth->timeout_task != GNUNET_SCHEDULER_NO_TASK)
{
- GNUNET_CONTAINER_DLL_remove (cp->delayed_head,
- cp->delayed_tail,
- dh);
- GNUNET_SCHEDULER_cancel (dh->delay_task);
- GNUNET_free (dh->pm);
- GNUNET_free (dh);
+ GNUNET_SCHEDULER_cancel (pth->timeout_task);
+ pth->timeout_task = GNUNET_SCHEDULER_NO_TASK;
}
+ GNUNET_CONTAINER_DLL_remove (cp->pth_head, cp->pth_tail, pth);
+ GNUNET_assert (0 == pth->cth_in_progress);
+ pth->gmc (pth->gmc_cls, 0, NULL);
+ GNUNET_free (pth);
+ }
+ while (NULL != (dh = cp->delayed_head))
+ {
+ GNUNET_CONTAINER_DLL_remove (cp->delayed_head, cp->delayed_tail, dh);
+ GNUNET_SCHEDULER_cancel (dh->delay_task);
+ GNUNET_free (dh->pm);
+ GNUNET_free (dh);
+ }
GNUNET_PEER_change_rc (cp->ppd.pid, -1);
if (GNUNET_SCHEDULER_NO_TASK != cp->mig_revive_task)
- {
- GNUNET_SCHEDULER_cancel (cp->mig_revive_task);
- cp->mig_revive_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (cp->mig_revive_task);
+ cp->mig_revive_task = GNUNET_SCHEDULER_NO_TASK;
+ }
GNUNET_free (cp);
}
@@ -1756,17 +1664,12 @@
* @return GNUNET_YES to continue iteration
*/
static int
-call_iterator (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+call_iterator (void *cls, const GNUNET_HashCode * key, void *value)
{
struct IterationContext *ic = cls;
struct GSF_ConnectedPeer *cp = value;
-
- ic->it (ic->it_cls,
- (const struct GNUNET_PeerIdentity*) key,
- cp,
- &cp->ppd);
+
+ ic->it (ic->it_cls, (const struct GNUNET_PeerIdentity *) key, cp, &cp->ppd);
return GNUNET_YES;
}
@@ -1778,16 +1681,13 @@
* @param it_cls closure for it
*/
void
-GSF_iterate_connected_peers_ (GSF_ConnectedPeerIterator it,
- void *it_cls)
+GSF_iterate_connected_peers_ (GSF_ConnectedPeerIterator it, void *it_cls)
{
struct IterationContext ic;
ic.it = it;
ic.it_cls = it_cls;
- GNUNET_CONTAINER_multihashmap_iterate (cp_map,
- &call_iterator,
- &ic);
+ GNUNET_CONTAINER_multihashmap_iterate (cp_map, &call_iterator, &ic);
}
@@ -1799,11 +1699,10 @@
*/
void
GSF_connected_peer_get_identity_ (const struct GSF_ConnectedPeer *cp,
- struct GNUNET_PeerIdentity *id)
+ struct GNUNET_PeerIdentity *id)
{
GNUNET_assert (0 != cp->ppd.pid);
- GNUNET_PEER_resolve (cp->ppd.pid,
- id);
+ GNUNET_PEER_resolve (cp->ppd.pid, id);
}
@@ -1816,9 +1715,7 @@
* @return number of bytes copied to buf
*/
static size_t
-create_migration_stop_message (void *cls,
- size_t size,
- void *buf)
+create_migration_stop_message (void *cls, size_t size, void *buf)
{
struct GSF_ConnectedPeer *cp = cls;
struct MigrationStopMessage msm;
@@ -1830,7 +1727,9 @@
msm.header.size = htons (sizeof (struct MigrationStopMessage));
msm.header.type = htons (GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP);
msm.reserved = htonl (0);
- msm.duration = GNUNET_TIME_relative_hton (GNUNET_TIME_absolute_get_remaining
(cp->last_migration_block));
+ msm.duration =
+ GNUNET_TIME_relative_hton (GNUNET_TIME_absolute_get_remaining
+ (cp->last_migration_block));
memcpy (buf, &msm, sizeof (struct MigrationStopMessage));
return sizeof (struct MigrationStopMessage);
}
@@ -1845,33 +1744,35 @@
*/
void
GSF_block_peer_migration_ (struct GSF_ConnectedPeer *cp,
- struct GNUNET_TIME_Relative block_time)
+ struct GNUNET_TIME_Relative block_time)
{
- if (GNUNET_TIME_absolute_get_remaining (cp->last_migration_block).rel_value
> block_time.rel_value)
- {
+ if (GNUNET_TIME_absolute_get_remaining (cp->last_migration_block).rel_value >
+ block_time.rel_value)
+ {
#if DEBUG_FS && 0
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Migration already blocked for another %llu ms\n",
- (unsigned long long) GNUNET_TIME_absolute_get_remaining
(cp->last_migration_block).rel_value);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Migration already blocked for another %llu ms\n",
+ (unsigned long long)
+ GNUNET_TIME_absolute_get_remaining
+ (cp->last_migration_block).rel_value);
#endif
- return; /* already blocked */
- }
+ return; /* already blocked */
+ }
#if DEBUG_FS && 0
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Asking to stop migration for %llu ms\n",
- (unsigned long long) block_time.rel_value);
+ "Asking to stop migration for %llu ms\n",
+ (unsigned long long) block_time.rel_value);
#endif
cp->last_migration_block = GNUNET_TIME_relative_to_absolute (block_time);
if (cp->migration_pth != NULL)
GSF_peer_transmit_cancel_ (cp->migration_pth);
- cp->migration_pth
- = GSF_peer_transmit_ (cp,
- GNUNET_SYSERR,
- UINT32_MAX,
- GNUNET_TIME_UNIT_FOREVER_REL,
- sizeof (struct MigrationStopMessage),
- &create_migration_stop_message,
- cp);
+ cp->migration_pth
+ = GSF_peer_transmit_ (cp,
+ GNUNET_SYSERR,
+ UINT32_MAX,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ sizeof (struct MigrationStopMessage),
+ &create_migration_stop_message, cp);
}
@@ -1884,9 +1785,7 @@
* @return GNUNET_OK to continue iteration
*/
static int
-flush_trust (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+flush_trust (void *cls, const GNUNET_HashCode * key, void *value)
{
struct GSF_ConnectedPeer *cp = value;
char *fn;
@@ -1894,26 +1793,27 @@
struct GNUNET_PeerIdentity pid;
if (cp->ppd.trust == cp->disk_trust)
- return GNUNET_OK; /* unchanged */
+ return GNUNET_OK; /* unchanged */
GNUNET_assert (0 != cp->ppd.pid);
- GNUNET_PEER_resolve (cp->ppd.pid,
- &pid);
+ GNUNET_PEER_resolve (cp->ppd.pid, &pid);
fn = get_trust_filename (&pid);
if (cp->ppd.trust == 0)
- {
- if ((0 != UNLINK (fn)) && (errno != ENOENT))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING |
- GNUNET_ERROR_TYPE_BULK, "unlink", fn);
- }
+ {
+ if ((0 != UNLINK (fn)) && (errno != ENOENT))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING |
+ GNUNET_ERROR_TYPE_BULK, "unlink", fn);
+ }
else
- {
- trust = htonl (cp->ppd.trust);
- if (sizeof(uint32_t) == GNUNET_DISK_fn_write (fn, &trust,
- sizeof(uint32_t),
- GNUNET_DISK_PERM_USER_READ
| GNUNET_DISK_PERM_USER_WRITE
- |
GNUNET_DISK_PERM_GROUP_READ | GNUNET_DISK_PERM_OTHER_READ))
- cp->disk_trust = cp->ppd.trust;
- }
+ {
+ trust = htonl (cp->ppd.trust);
+ if (sizeof (uint32_t) == GNUNET_DISK_fn_write (fn, &trust,
+ sizeof (uint32_t),
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE
|
+ GNUNET_DISK_PERM_GROUP_READ
|
+
GNUNET_DISK_PERM_OTHER_READ))
+ cp->disk_trust = cp->ppd.trust;
+ }
GNUNET_free (fn);
return GNUNET_OK;
}
@@ -1930,7 +1830,7 @@
*/
void
GSF_connected_peer_change_preference_ (struct GSF_ConnectedPeer *cp,
- uint64_t pref)
+ uint64_t pref)
{
cp->inc_preference += pref;
}
@@ -1943,22 +1843,17 @@
* @param tc task context, not used
*/
static void
-cron_flush_trust (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+cron_flush_trust (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
if (NULL == cp_map)
return;
- GNUNET_CONTAINER_multihashmap_iterate (cp_map,
- &flush_trust,
- NULL);
+ GNUNET_CONTAINER_multihashmap_iterate (cp_map, &flush_trust, NULL);
if (NULL == tc)
return;
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
return;
- GNUNET_SCHEDULER_add_delayed (TRUST_FLUSH_FREQ,
- &cron_flush_trust,
- NULL);
+ GNUNET_SCHEDULER_add_delayed (TRUST_FLUSH_FREQ, &cron_flush_trust, NULL);
}
@@ -1976,7 +1871,7 @@
&trustDirectory));
GNUNET_DISK_directory_create (trustDirectory);
GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_HIGH,
- &cron_flush_trust, NULL);
+ &cron_flush_trust, NULL);
}
@@ -1988,13 +1883,10 @@
* @param value value in the hash map (peer entry)
* @return GNUNET_YES (we should continue to iterate)
*/
-static int
-clean_peer (void *cls,
- const GNUNET_HashCode * key,
- void *value)
+static int
+clean_peer (void *cls, const GNUNET_HashCode * key, void *value)
{
- GSF_peer_disconnect_handler_ (NULL,
- (const struct GNUNET_PeerIdentity*) key);
+ GSF_peer_disconnect_handler_ (NULL, (const struct GNUNET_PeerIdentity *)
key);
return GNUNET_YES;
}
@@ -2006,9 +1898,7 @@
GSF_connected_peer_done_ ()
{
cron_flush_trust (NULL, NULL);
- GNUNET_CONTAINER_multihashmap_iterate (cp_map,
- &clean_peer,
- NULL);
+ GNUNET_CONTAINER_multihashmap_iterate (cp_map, &clean_peer, NULL);
GNUNET_CONTAINER_multihashmap_destroy (cp_map);
cp_map = NULL;
GNUNET_free (trustDirectory);
@@ -2024,16 +1914,14 @@
* @param value value in the hash map (peer entry)
* @return GNUNET_YES (we should continue to iterate)
*/
-static int
-clean_local_client (void *cls,
- const GNUNET_HashCode * key,
- void *value)
+static int
+clean_local_client (void *cls, const GNUNET_HashCode * key, void *value)
{
const struct GSF_LocalClient *lc = cls;
struct GSF_ConnectedPeer *cp = value;
unsigned int i;
- for (i=0;i<CS2P_SUCCESS_LIST_SIZE;i++)
+ for (i = 0; i < CS2P_SUCCESS_LIST_SIZE; i++)
if (cp->ppd.last_client_replies[i] == lc)
cp->ppd.last_client_replies[i] = NULL;
return GNUNET_YES;
@@ -2050,10 +1938,9 @@
GSF_handle_local_client_disconnect_ (const struct GSF_LocalClient *lc)
{
if (NULL == cp_map)
- return; /* already cleaned up */
+ return; /* already cleaned up */
GNUNET_CONTAINER_multihashmap_iterate (cp_map,
- &clean_local_client,
- (void*) lc);
+ &clean_local_client, (void *) lc);
}
Modified: gnunet/src/fs/gnunet-service-fs_cp.h
===================================================================
--- gnunet/src/fs/gnunet-service-fs_cp.h 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/fs/gnunet-service-fs_cp.h 2011-08-15 21:46:35 UTC (rev
16581)
@@ -59,7 +59,7 @@
* getting a reply (only calculated over the requests for
* which we actually got a reply). Calculated
* as a moving average: new_delay = ((n-1)*last_delay+curr_delay) / n
- */
+ */
struct GNUNET_TIME_Relative avg_reply_delay;
/**
@@ -125,10 +125,11 @@
* @param cp handle to the connected peer record
* @param perf peer performance data
*/
-typedef void (*GSF_ConnectedPeerIterator)(void *cls,
- const struct GNUNET_PeerIdentity
*peer,
- struct GSF_ConnectedPeer *cp,
- const struct GSF_PeerPerformanceData
*ppd);
+typedef void (*GSF_ConnectedPeerIterator) (void *cls,
+ const struct GNUNET_PeerIdentity *
+ peer, struct GSF_ConnectedPeer * cp,
+ const struct GSF_PeerPerformanceData
+ * ppd);
/**
@@ -139,9 +140,8 @@
* @param buf where to copy the message, NULL on error (peer disconnect)
* @return number of bytes copied to 'buf', can be 0 (without indicating an
error)
*/
-typedef size_t (*GSF_GetMessageCallback)(void *cls,
- size_t buf_size,
- void *buf);
+typedef size_t (*GSF_GetMessageCallback) (void *cls,
+ size_t buf_size, void *buf);
/**
@@ -151,9 +151,9 @@
* @param cp handle to the connected peer record
* @param success GNUNET_YES on success, GNUNET_NO on failure
*/
-typedef void (*GSF_PeerReserveCallback)(void *cls,
- struct GSF_ConnectedPeer *cp,
- int success);
+typedef void (*GSF_PeerReserveCallback) (void *cls,
+ struct GSF_ConnectedPeer * cp,
+ int success);
/**
@@ -170,9 +170,11 @@
* @param atsi performance data for the connection
* @return handle to connected peer entry
*/
-struct GSF_ConnectedPeer *
-GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi);
+struct GSF_ConnectedPeer *GSF_peer_connect_handler_ (const struct
+ GNUNET_PeerIdentity *peer,
+ const struct
+
GNUNET_TRANSPORT_ATS_Information
+ *atsi);
/**
@@ -181,8 +183,8 @@
* @param peer peer's identity
* @return NULL if this peer is not currently connected
*/
-struct GSF_ConnectedPeer *
-GSF_peer_get_ (const struct GNUNET_PeerIdentity *peer);
+struct GSF_ConnectedPeer *GSF_peer_get_ (const struct GNUNET_PeerIdentity
+ *peer);
/**
@@ -199,14 +201,13 @@
* @param gmc_cls closure for gmc
* @return handle to cancel request
*/
-struct GSF_PeerTransmitHandle *
-GSF_peer_transmit_ (struct GSF_ConnectedPeer *cp,
- int is_query,
- uint32_t priority,
- struct GNUNET_TIME_Relative timeout,
- size_t size,
- GSF_GetMessageCallback gmc,
- void *gmc_cls);
+struct GSF_PeerTransmitHandle *GSF_peer_transmit_ (struct GSF_ConnectedPeer
*cp,
+ int is_query,
+ uint32_t priority,
+ struct GNUNET_TIME_Relative
+ timeout, size_t size,
+ GSF_GetMessageCallback gmc,
+ void *gmc_cls);
/**
@@ -214,8 +215,7 @@
*
* @param pth request to cancel
*/
-void
-GSF_peer_transmit_cancel_ (struct GSF_PeerTransmitHandle *pth);
+void GSF_peer_transmit_cancel_ (struct GSF_PeerTransmitHandle *pth);
/**
@@ -227,8 +227,8 @@
*/
void
GSF_peer_update_performance_ (struct GSF_ConnectedPeer *cp,
- struct GNUNET_TIME_Absolute request_time,
- uint32_t request_priority);
+ struct GNUNET_TIME_Absolute request_time,
+ uint32_t request_priority);
/**
@@ -240,7 +240,7 @@
*/
void
GSF_peer_update_responder_client_ (struct GSF_ConnectedPeer *cp,
- struct GSF_LocalClient *initiator_client);
+ struct GSF_LocalClient *initiator_client);
/**
@@ -252,7 +252,8 @@
*/
void
GSF_peer_update_responder_peer_ (struct GSF_ConnectedPeer *cp,
- const struct GSF_ConnectedPeer
*initiator_peer);
+ const struct GSF_ConnectedPeer
+ *initiator_peer);
/**
@@ -268,11 +269,11 @@
*/
void
GSF_peer_status_handler_ (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
- struct GNUNET_TIME_Absolute timeout,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi);
+ const struct GNUNET_PeerIdentity *peer,
+ struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
+ struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
+ struct GNUNET_TIME_Absolute timeout,
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi);
/**
@@ -288,9 +289,10 @@
*/
int
GSF_handle_p2p_migration_stop_ (void *cls,
- const struct GNUNET_PeerIdentity *other,
- const struct GNUNET_MessageHeader *message,
- const struct GNUNET_TRANSPORT_ATS_Information
*atsi);
+ const struct GNUNET_PeerIdentity *other,
+ const struct GNUNET_MessageHeader *message,
+ const struct GNUNET_TRANSPORT_ATS_Information
+ *atsi);
/**
@@ -304,9 +306,11 @@
* @param message the actual message
* @return pending request handle, NULL on error
*/
-struct GSF_PendingRequest *
-GSF_handle_p2p_query_ (const struct GNUNET_PeerIdentity *other,
- const struct GNUNET_MessageHeader *message);
+struct GSF_PendingRequest *GSF_handle_p2p_query_ (const struct
+ GNUNET_PeerIdentity *other,
+ const struct
+ GNUNET_MessageHeader
+ *message);
/**
@@ -315,8 +319,9 @@
* @param cp peer to query
* @return performance data record for the peer
*/
-struct GSF_PeerPerformanceData *
-GSF_get_peer_performance_data_ (struct GSF_ConnectedPeer *cp);
+struct GSF_PeerPerformanceData *GSF_get_peer_performance_data_ (struct
+
GSF_ConnectedPeer
+ *cp);
/**
@@ -328,7 +333,7 @@
*/
void
GSF_block_peer_migration_ (struct GSF_ConnectedPeer *cp,
- struct GNUNET_TIME_Relative block_time);
+ struct GNUNET_TIME_Relative block_time);
/**
@@ -340,7 +345,7 @@
*/
void
GSF_peer_disconnect_handler_ (void *cls,
- const struct GNUNET_PeerIdentity *peer);
+ const struct GNUNET_PeerIdentity *peer);
/**
@@ -349,8 +354,7 @@
*
* @param lc handle to the local client (henceforth invalid)
*/
-void
-GSF_handle_local_client_disconnect_ (const struct GSF_LocalClient *lc);
+void GSF_handle_local_client_disconnect_ (const struct GSF_LocalClient *lc);
/**
@@ -364,7 +368,7 @@
*/
void
GSF_connected_peer_change_preference_ (struct GSF_ConnectedPeer *cp,
- uint64_t pref);
+ uint64_t pref);
/**
@@ -375,7 +379,7 @@
*/
void
GSF_connected_peer_get_identity_ (const struct GSF_ConnectedPeer *cp,
- struct GNUNET_PeerIdentity *id);
+ struct GNUNET_PeerIdentity *id);
/**
@@ -384,23 +388,19 @@
* @param it function to call for each peer
* @param it_cls closure for it
*/
-void
-GSF_iterate_connected_peers_ (GSF_ConnectedPeerIterator it,
- void *it_cls);
+void GSF_iterate_connected_peers_ (GSF_ConnectedPeerIterator it, void *it_cls);
/**
* Initialize peer management subsystem.
*/
-void
-GSF_connected_peer_init_ (void);
+void GSF_connected_peer_init_ (void);
/**
* Shutdown peer management subsystem.
*/
-void
-GSF_connected_peer_done_ (void);
+void GSF_connected_peer_done_ (void);
#endif
Modified: gnunet/src/fs/gnunet-service-fs_indexing.c
===================================================================
--- gnunet/src/fs/gnunet-service-fs_indexing.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/fs/gnunet-service-fs_indexing.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -41,7 +41,7 @@
*/
struct IndexInfo
{
-
+
/**
* This is a linked list.
*/
@@ -63,7 +63,7 @@
* Context for hashing of the file.
*/
struct GNUNET_CRYPTO_FileHashContext *fhc;
-
+
/**
* Hash of the contents of the file.
*/
@@ -98,57 +98,48 @@
/**
* Write the current index information list to disk.
- */
+ */
static void
write_index_list ()
{
struct GNUNET_BIO_WriteHandle *wh;
char *fn;
- struct IndexInfo *pos;
+ struct IndexInfo *pos;
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (cfg,
- "FS",
- "INDEXDB",
- &fn))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- _("Configuration option `%s' in section `%s' missing.\n"),
- "INDEXDB",
- "FS");
- return;
- }
+ GNUNET_CONFIGURATION_get_value_filename (cfg, "FS", "INDEXDB", &fn))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ _("Configuration option `%s' in section `%s' missing.\n"),
+ "INDEXDB", "FS");
+ return;
+ }
wh = GNUNET_BIO_write_open (fn);
if (NULL == wh)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- _("Could not open `%s'.\n"),
- fn);
- GNUNET_free (fn);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ _("Could not open `%s'.\n"), fn);
+ GNUNET_free (fn);
+ return;
+ }
pos = indexed_files;
while (pos != NULL)
- {
- if ( (GNUNET_OK !=
- GNUNET_BIO_write (wh,
- &pos->file_id,
- sizeof (GNUNET_HashCode))) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_string (wh,
- pos->filename)) )
- break;
- pos = pos->next;
- }
- if (GNUNET_OK !=
- GNUNET_BIO_write_close (wh))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- _("Error writing `%s'.\n"),
- fn);
- GNUNET_free (fn);
- return;
- }
+ {
+ if ((GNUNET_OK !=
+ GNUNET_BIO_write (wh,
+ &pos->file_id,
+ sizeof (GNUNET_HashCode))) ||
+ (GNUNET_OK != GNUNET_BIO_write_string (wh, pos->filename)))
+ break;
+ pos = pos->next;
+ }
+ if (GNUNET_OK != GNUNET_BIO_write_close (wh))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ _("Error writing `%s'.\n"), fn);
+ GNUNET_free (fn);
+ return;
+ }
GNUNET_free (fn);
}
@@ -161,73 +152,65 @@
{
struct GNUNET_BIO_ReadHandle *rh;
char *fn;
- struct IndexInfo *pos;
+ struct IndexInfo *pos;
char *fname;
GNUNET_HashCode hc;
size_t slen;
char *emsg;
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (cfg,
- "FS",
- "INDEXDB",
- &fn))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- _("Configuration option `%s' in section `%s' missing.\n"),
- "INDEXDB",
- "FS");
- return;
- }
+ GNUNET_CONFIGURATION_get_value_filename (cfg, "FS", "INDEXDB", &fn))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ _("Configuration option `%s' in section `%s' missing.\n"),
+ "INDEXDB", "FS");
+ return;
+ }
if (GNUNET_NO == GNUNET_DISK_file_test (fn))
- {
- /* no index info yet */
- GNUNET_free (fn);
- return;
- }
+ {
+ /* no index info yet */
+ GNUNET_free (fn);
+ return;
+ }
rh = GNUNET_BIO_read_open (fn);
if (NULL == rh)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ _("Could not open `%s'.\n"), fn);
+ GNUNET_free (fn);
+ return;
+ }
+ while ((GNUNET_OK ==
+ GNUNET_BIO_read (rh,
+ "Hash of indexed file",
+ &hc,
+ sizeof (GNUNET_HashCode))) &&
+ (GNUNET_OK ==
+ GNUNET_BIO_read_string (rh,
+ "Name of indexed file",
+ &fname, 1024 * 16)) && (fname != NULL))
+ {
+ slen = strlen (fname) + 1;
+ pos = GNUNET_malloc (sizeof (struct IndexInfo) + slen);
+ pos->file_id = hc;
+ pos->filename = (const char *) &pos[1];
+ memcpy (&pos[1], fname, slen);
+ if (GNUNET_SYSERR ==
+ GNUNET_CONTAINER_multihashmap_put (ifm,
+ &hc,
+ (void *) pos->filename,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- _("Could not open `%s'.\n"),
- fn);
- GNUNET_free (fn);
- return;
+ GNUNET_free (pos);
}
- while ( (GNUNET_OK ==
- GNUNET_BIO_read (rh,
- "Hash of indexed file",
- &hc,
- sizeof (GNUNET_HashCode))) &&
- (GNUNET_OK ==
- GNUNET_BIO_read_string (rh,
- "Name of indexed file",
- &fname,
- 1024 * 16)) &&
- (fname != NULL) )
+ else
{
- slen = strlen (fname) + 1;
- pos = GNUNET_malloc (sizeof (struct IndexInfo) + slen);
- pos->file_id = hc;
- pos->filename = (const char *) &pos[1];
- memcpy (&pos[1], fname, slen);
- if (GNUNET_SYSERR ==
- GNUNET_CONTAINER_multihashmap_put (ifm,
- &hc,
- (void*) pos->filename,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
- {
- GNUNET_free (pos);
- }
- else
- {
- pos->next = indexed_files;
- indexed_files = pos;
- }
- GNUNET_free (fname);
+ pos->next = indexed_files;
+ indexed_files = pos;
}
- if (GNUNET_OK !=
- GNUNET_BIO_read_close (rh, &emsg))
+ GNUNET_free (fname);
+ }
+ if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
GNUNET_free (emsg);
GNUNET_free (fn);
}
@@ -244,31 +227,29 @@
{
if (GNUNET_SYSERR ==
GNUNET_CONTAINER_multihashmap_put (ifm,
- &ii->file_id,
- (void*) ii->filename,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Index request received for file `%s' is already indexed as
`%s'. Permitting anyway.\n"),
- ii->filename,
- (const char*) GNUNET_CONTAINER_multihashmap_get (ifm,
-
&ii->file_id));
- GNUNET_SERVER_transmit_context_append_data (ii->tc,
- NULL, 0,
-
GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK);
- GNUNET_SERVER_transmit_context_run (ii->tc,
- GNUNET_TIME_UNIT_MINUTES);
- GNUNET_free (ii);
- return;
- }
+ &ii->file_id,
+ (void *) ii->filename,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _
+ ("Index request received for file `%s' is already indexed as
`%s'. Permitting anyway.\n"),
+ ii->filename,
+ (const char *) GNUNET_CONTAINER_multihashmap_get (ifm,
+
&ii->file_id));
+ GNUNET_SERVER_transmit_context_append_data (ii->tc, NULL, 0,
+
GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK);
+ GNUNET_SERVER_transmit_context_run (ii->tc, GNUNET_TIME_UNIT_MINUTES);
+ GNUNET_free (ii);
+ return;
+ }
ii->next = indexed_files;
indexed_files = ii;
write_index_list ();
GNUNET_SERVER_transmit_context_append_data (ii->tc,
- NULL, 0,
-
GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK);
- GNUNET_SERVER_transmit_context_run (ii->tc,
- GNUNET_TIME_UNIT_MINUTES);
+ NULL, 0,
+
GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK);
+ GNUNET_SERVER_transmit_context_run (ii->tc, GNUNET_TIME_UNIT_MINUTES);
ii->tc = NULL;
}
@@ -280,36 +261,30 @@
* @param cls closure, our publishing context
* @param res resulting hash, NULL on error
*/
-static void
-hash_for_index_val (void *cls,
- const GNUNET_HashCode *
- res)
+static void
+hash_for_index_val (void *cls, const GNUNET_HashCode * res)
{
struct IndexInfo *ii = cls;
ii->fhc = NULL;
- if ( (res == NULL) ||
- (0 != memcmp (res,
- &ii->file_id,
- sizeof(GNUNET_HashCode))) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Hash mismatch trying to index file `%s' which has hash
`%s'\n"),
- ii->filename,
- GNUNET_h2s (res));
+ if ((res == NULL) ||
+ (0 != memcmp (res, &ii->file_id, sizeof (GNUNET_HashCode))))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Hash mismatch trying to index file `%s' which has hash
`%s'\n"),
+ ii->filename, GNUNET_h2s (res));
#if DEBUG_FS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Wanted `%s'\n",
- GNUNET_h2s (&ii->file_id));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Wanted `%s'\n", GNUNET_h2s (&ii->file_id));
#endif
- GNUNET_SERVER_transmit_context_append_data (ii->tc,
- NULL, 0,
-
GNUNET_MESSAGE_TYPE_FS_INDEX_START_FAILED);
- GNUNET_SERVER_transmit_context_run (ii->tc,
- GNUNET_TIME_UNIT_MINUTES);
- GNUNET_free (ii);
- return;
- }
+ GNUNET_SERVER_transmit_context_append_data (ii->tc,
+ NULL, 0,
+
GNUNET_MESSAGE_TYPE_FS_INDEX_START_FAILED);
+ GNUNET_SERVER_transmit_context_run (ii->tc, GNUNET_TIME_UNIT_MINUTES);
+ GNUNET_free (ii);
+ return;
+ }
signal_index_ok (ii);
}
@@ -323,8 +298,8 @@
*/
void
GNUNET_FS_handle_index_start (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
const struct IndexStartMessage *ism;
char *fn;
@@ -336,77 +311,70 @@
uint64_t mydev;
uint64_t myino;
- msize = ntohs(message->size);
- if ( (msize <= sizeof (struct IndexStartMessage)) ||
- ( ((const char *)message)[msize-1] != '\0') )
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client,
- GNUNET_SYSERR);
- return;
- }
- ism = (const struct IndexStartMessage*) message;
+ msize = ntohs (message->size);
+ if ((msize <= sizeof (struct IndexStartMessage)) ||
+ (((const char *) message)[msize - 1] != '\0'))
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
+ ism = (const struct IndexStartMessage *) message;
if (0 != ism->reserved)
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client,
- GNUNET_SYSERR);
- return;
- }
- fn = GNUNET_STRINGS_filename_expand ((const char*) &ism[1]);
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
+ fn = GNUNET_STRINGS_filename_expand ((const char *) &ism[1]);
if (fn == NULL)
- {
- GNUNET_SERVER_receive_done (client,
- GNUNET_SYSERR);
- return;
- }
+ {
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
dev = GNUNET_ntohll (ism->device);
ino = GNUNET_ntohll (ism->inode);
- ism = (const struct IndexStartMessage*) message;
+ ism = (const struct IndexStartMessage *) message;
slen = strlen (fn) + 1;
ii = GNUNET_malloc (sizeof (struct IndexInfo) + slen);
- ii->filename = (const char*) &ii[1];
+ ii->filename = (const char *) &ii[1];
memcpy (&ii[1], fn, slen);
- ii->file_id = ism->file_id;
+ ii->file_id = ism->file_id;
#if DEBUG_FS
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received `%s' message for file `%s'\n",
- "START_INDEX",
- ii->filename);
+ "Received `%s' message for file `%s'\n",
+ "START_INDEX", ii->filename);
#endif
ii->tc = GNUNET_SERVER_transmit_context_create (client);
mydev = 0;
myino = 0;
- if ( ( (dev != 0) ||
- (ino != 0) ) &&
- (GNUNET_OK == GNUNET_DISK_file_get_identifiers (fn,
- &mydev,
- &myino)) &&
- ( (dev == mydev) &&
- (ino == myino) ) )
- {
- /* fast validation OK! */
- signal_index_ok (ii);
- GNUNET_free (fn);
- return;
- }
+ if (((dev != 0) ||
+ (ino != 0)) &&
+ (GNUNET_OK == GNUNET_DISK_file_get_identifiers (fn,
+ &mydev,
+ &myino)) &&
+ ((dev == mydev) && (ino == myino)))
+ {
+ /* fast validation OK! */
+ signal_index_ok (ii);
+ GNUNET_free (fn);
+ return;
+ }
#if DEBUG_FS
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Mismatch in file identifiers (%llu != %llu or %u != %u), need to
hash.\n",
- (unsigned long long) ino,
- (unsigned long long) myino,
- (unsigned int) dev,
- (unsigned int) mydev);
+ "Mismatch in file identifiers (%llu != %llu or %u != %u), need
to hash.\n",
+ (unsigned long long) ino,
+ (unsigned long long) myino,
+ (unsigned int) dev, (unsigned int) mydev);
#endif
/* slow validation, need to hash full file (again) */
ii->fhc = GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE,
- fn,
- HASHING_BLOCKSIZE,
- &hash_for_index_val,
- ii);
- if (ii->fhc == NULL)
- hash_for_index_val (ii, NULL);
+ fn,
+ HASHING_BLOCKSIZE,
+ &hash_for_index_val, ii);
+ if (ii->fhc == NULL)
+ hash_for_index_val (ii, NULL);
GNUNET_free (fn);
}
@@ -420,8 +388,8 @@
*/
void
GNUNET_FS_handle_index_list_get (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
struct GNUNET_SERVER_TransmitContext *tc;
struct IndexInfoMessage *iim;
@@ -431,31 +399,30 @@
struct IndexInfo *pos;
tc = GNUNET_SERVER_transmit_context_create (client);
- iim = (struct IndexInfoMessage*) buf;
+ iim = (struct IndexInfoMessage *) buf;
pos = indexed_files;
while (NULL != pos)
+ {
+ fn = pos->filename;
+ slen = strlen (fn) + 1;
+ if (slen + sizeof (struct IndexInfoMessage) >=
+ GNUNET_SERVER_MAX_MESSAGE_SIZE)
{
- fn = pos->filename;
- slen = strlen (fn) + 1;
- if (slen + sizeof (struct IndexInfoMessage) >=
GNUNET_SERVER_MAX_MESSAGE_SIZE)
- {
- GNUNET_break (0);
- break;
- }
- iim->header.type = htons (GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY);
- iim->header.size = htons (slen + sizeof (struct IndexInfoMessage));
- iim->reserved = 0;
- iim->file_id = pos->file_id;
- memcpy (&iim[1], fn, slen);
- GNUNET_SERVER_transmit_context_append_message (tc,
- &iim->header);
- pos = pos->next;
+ GNUNET_break (0);
+ break;
}
+ iim->header.type = htons (GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY);
+ iim->header.size = htons (slen + sizeof (struct IndexInfoMessage));
+ iim->reserved = 0;
+ iim->file_id = pos->file_id;
+ memcpy (&iim[1], fn, slen);
+ GNUNET_SERVER_transmit_context_append_message (tc, &iim->header);
+ pos = pos->next;
+ }
GNUNET_SERVER_transmit_context_append_data (tc,
- NULL, 0,
-
GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END);
- GNUNET_SERVER_transmit_context_run (tc,
- GNUNET_TIME_UNIT_MINUTES);
+ NULL, 0,
+
GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END);
+ GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_MINUTES);
}
@@ -468,8 +435,8 @@
*/
void
GNUNET_FS_handle_unindex (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
const struct UnindexMessage *um;
struct IndexInfo *pos;
@@ -478,55 +445,51 @@
struct GNUNET_SERVER_TransmitContext *tc;
int found;
- um = (const struct UnindexMessage*) message;
+ um = (const struct UnindexMessage *) message;
if (0 != um->reserved)
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client,
- GNUNET_SYSERR);
- return;
- }
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
found = GNUNET_NO;
prev = NULL;
pos = indexed_files;
while (NULL != pos)
+ {
+ next = pos->next;
+ if (0 == memcmp (&pos->file_id, &um->file_id, sizeof (GNUNET_HashCode)))
{
- next = pos->next;
- if (0 == memcmp (&pos->file_id,
- &um->file_id,
- sizeof (GNUNET_HashCode)))
- {
- if (prev == NULL)
- indexed_files = next;
- else
- prev->next = next;
- GNUNET_break (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_remove (ifm,
- &pos->file_id,
- (void*)
pos->filename));
- GNUNET_free (pos);
- found = GNUNET_YES;
- }
+ if (prev == NULL)
+ indexed_files = next;
else
- {
- prev = pos;
- }
- pos = next;
+ prev->next = next;
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_CONTAINER_multihashmap_remove (ifm,
+ &pos->file_id,
+ (void *)
+ pos->filename));
+ GNUNET_free (pos);
+ found = GNUNET_YES;
}
+ else
+ {
+ prev = pos;
+ }
+ pos = next;
+ }
#if DEBUG_FS
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Client requested unindexing of file `%s': %s\n",
- GNUNET_h2s (&um->file_id),
- found ? "found" : "not found");
+ "Client requested unindexing of file `%s': %s\n",
+ GNUNET_h2s (&um->file_id), found ? "found" : "not found");
#endif
- if (GNUNET_YES == found)
+ if (GNUNET_YES == found)
write_index_list ();
tc = GNUNET_SERVER_transmit_context_create (client);
GNUNET_SERVER_transmit_context_append_data (tc,
- NULL, 0,
-
GNUNET_MESSAGE_TYPE_FS_UNINDEX_OK);
- GNUNET_SERVER_transmit_context_run (tc,
- GNUNET_TIME_UNIT_MINUTES);
+ NULL, 0,
+
GNUNET_MESSAGE_TYPE_FS_UNINDEX_OK);
+ GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_MINUTES);
}
@@ -539,14 +502,11 @@
* @param msg error message
*/
static void
-remove_cont (void *cls,
- int success,
- const char *msg)
+remove_cont (void *cls, int success, const char *msg)
{
if (GNUNET_OK != success)
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to delete bogus block: %s\n"),
- msg);
+ _("Failed to delete bogus block: %s\n"), msg);
}
@@ -571,15 +531,15 @@
*/
int
GNUNET_FS_handle_on_demand_block (const GNUNET_HashCode * key,
- uint32_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- struct GNUNET_TIME_Absolute
- expiration, uint64_t uid,
- GNUNET_DATASTORE_DatumProcessor cont,
- void *cont_cls)
+ uint32_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute
+ expiration, uint64_t uid,
+ GNUNET_DATASTORE_DatumProcessor cont,
+ void *cont_cls)
{
const struct OnDemandBlock *odb;
GNUNET_HashCode nkey;
@@ -594,99 +554,72 @@
uint64_t off;
if (size != sizeof (struct OnDemandBlock))
- {
- GNUNET_break (0);
- GNUNET_DATASTORE_remove (dsh,
- key,
- size,
- data,
- -1, -1,
- GNUNET_TIME_UNIT_FOREVER_REL,
- &remove_cont,
- NULL);
- return GNUNET_SYSERR;
- }
- odb = (const struct OnDemandBlock*) data;
+ {
+ GNUNET_break (0);
+ GNUNET_DATASTORE_remove (dsh,
+ key,
+ size,
+ data,
+ -1, -1,
+ GNUNET_TIME_UNIT_FOREVER_REL, &remove_cont, NULL);
+ return GNUNET_SYSERR;
+ }
+ odb = (const struct OnDemandBlock *) data;
off = GNUNET_ntohll (odb->offset);
- fn = (const char*) GNUNET_CONTAINER_multihashmap_get (ifm,
- &odb->file_id);
+ fn = (const char *) GNUNET_CONTAINER_multihashmap_get (ifm, &odb->file_id);
fh = NULL;
- if ( (NULL == fn) ||
- (NULL == (fh = GNUNET_DISK_file_open (fn,
- GNUNET_DISK_OPEN_READ,
- GNUNET_DISK_PERM_NONE))) ||
- (off !=
- GNUNET_DISK_file_seek (fh,
- off,
- GNUNET_DISK_SEEK_SET)) ||
- (-1 ==
- (nsize = GNUNET_DISK_file_read (fh,
- ndata,
- sizeof (ndata)))) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Could not access indexed file `%s' (%s) at offset %llu:
%s\n"),
- GNUNET_h2s (&odb->file_id),
- fn,
- (unsigned long long) off,
- (fn == NULL) ? _("not indexed") : STRERROR (errno));
- if (fh != NULL)
- GNUNET_DISK_file_close (fh);
- GNUNET_DATASTORE_remove (dsh,
- key,
- size,
- data,
- -1, -1,
- GNUNET_TIME_UNIT_FOREVER_REL,
- &remove_cont,
- NULL);
- return GNUNET_SYSERR;
- }
+ if ((NULL == fn) ||
+ (NULL == (fh = GNUNET_DISK_file_open (fn,
+ GNUNET_DISK_OPEN_READ,
+ GNUNET_DISK_PERM_NONE))) ||
+ (off !=
+ GNUNET_DISK_file_seek (fh,
+ off,
+ GNUNET_DISK_SEEK_SET)) ||
+ (-1 == (nsize = GNUNET_DISK_file_read (fh, ndata, sizeof (ndata)))))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Could not access indexed file `%s' (%s) at offset %llu:
%s\n"),
+ GNUNET_h2s (&odb->file_id), fn, (unsigned long long) off,
+ (fn == NULL) ? _("not indexed") : STRERROR (errno));
+ if (fh != NULL)
+ GNUNET_DISK_file_close (fh);
+ GNUNET_DATASTORE_remove (dsh,
+ key,
+ size,
+ data,
+ -1, -1,
+ GNUNET_TIME_UNIT_FOREVER_REL, &remove_cont, NULL);
+ return GNUNET_SYSERR;
+ }
GNUNET_DISK_file_close (fh);
- GNUNET_CRYPTO_hash (ndata,
- nsize,
- &nkey);
+ GNUNET_CRYPTO_hash (ndata, nsize, &nkey);
GNUNET_CRYPTO_hash_to_aes_key (&nkey, &skey, &iv);
- GNUNET_CRYPTO_aes_encrypt (ndata,
- nsize,
- &skey,
- &iv,
- edata);
- GNUNET_CRYPTO_hash (edata,
- nsize,
- &query);
- if (0 != memcmp (&query,
- key,
- sizeof (GNUNET_HashCode)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Indexed file `%s' changed at offset %llu\n"),
- fn,
- (unsigned long long) off);
- GNUNET_DATASTORE_remove (dsh,
- key,
- size,
- data,
- -1, -1,
- GNUNET_TIME_UNIT_FOREVER_REL,
- &remove_cont,
- NULL);
- return GNUNET_SYSERR;
- }
+ GNUNET_CRYPTO_aes_encrypt (ndata, nsize, &skey, &iv, edata);
+ GNUNET_CRYPTO_hash (edata, nsize, &query);
+ if (0 != memcmp (&query, key, sizeof (GNUNET_HashCode)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Indexed file `%s' changed at offset %llu\n"),
+ fn, (unsigned long long) off);
+ GNUNET_DATASTORE_remove (dsh,
+ key,
+ size,
+ data,
+ -1, -1,
+ GNUNET_TIME_UNIT_FOREVER_REL, &remove_cont, NULL);
+ return GNUNET_SYSERR;
+ }
#if DEBUG_FS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "On-demand encoded block for query `%s'\n",
- GNUNET_h2s (key));
-#endif
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "On-demand encoded block for query `%s'\n", GNUNET_h2s (key));
+#endif
cont (cont_cls,
- key,
- nsize,
- edata,
- GNUNET_BLOCK_TYPE_FS_DBLOCK,
- priority,
- anonymity,
- expiration,
- uid);
+ key,
+ nsize,
+ edata,
+ GNUNET_BLOCK_TYPE_FS_DBLOCK, priority, anonymity, expiration, uid);
return GNUNET_OK;
}
@@ -697,17 +630,17 @@
void
GNUNET_FS_indexing_done ()
{
- struct IndexInfo *pos;
+ struct IndexInfo *pos;
GNUNET_CONTAINER_multihashmap_destroy (ifm);
ifm = NULL;
while (NULL != (pos = indexed_files))
- {
- indexed_files = pos->next;
- if (pos->fhc != NULL)
- GNUNET_CRYPTO_hash_file_cancel (pos->fhc);
- GNUNET_free (pos);
- }
+ {
+ indexed_files = pos->next;
+ if (pos->fhc != NULL)
+ GNUNET_CRYPTO_hash_file_cancel (pos->fhc);
+ GNUNET_free (pos);
+ }
cfg = NULL;
}
@@ -720,7 +653,7 @@
*/
int
GNUNET_FS_indexing_init (const struct GNUNET_CONFIGURATION_Handle *c,
- struct GNUNET_DATASTORE_Handle *d)
+ struct GNUNET_DATASTORE_Handle *d)
{
cfg = c;
dsh = d;
Modified: gnunet/src/fs/gnunet-service-fs_indexing.h
===================================================================
--- gnunet/src/fs/gnunet-service-fs_indexing.h 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/fs/gnunet-service-fs_indexing.h 2011-08-15 21:46:35 UTC (rev
16581)
@@ -56,15 +56,15 @@
*/
int
GNUNET_FS_handle_on_demand_block (const GNUNET_HashCode * key,
- uint32_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- struct GNUNET_TIME_Absolute
- expiration, uint64_t uid,
- GNUNET_DATASTORE_DatumProcessor cont,
- void *cont_cls);
+ uint32_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute
+ expiration, uint64_t uid,
+ GNUNET_DATASTORE_DatumProcessor cont,
+ void *cont_cls);
/**
* Handle INDEX_START-message.
@@ -75,8 +75,8 @@
*/
void
GNUNET_FS_handle_index_start (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message);
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message);
/**
@@ -88,8 +88,8 @@
*/
void
GNUNET_FS_handle_index_list_get (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message);
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message);
/**
@@ -101,8 +101,8 @@
*/
void
GNUNET_FS_handle_unindex (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message);
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message);
/**
@@ -114,14 +114,13 @@
*/
int
GNUNET_FS_indexing_init (const struct GNUNET_CONFIGURATION_Handle *c,
- struct GNUNET_DATASTORE_Handle *d);
+ struct GNUNET_DATASTORE_Handle *d);
/**
* Shutdown the module.
*/
-void
-GNUNET_FS_indexing_done (void);
+void GNUNET_FS_indexing_done (void);
#endif
Modified: gnunet/src/fs/gnunet-service-fs_lc.c
===================================================================
--- gnunet/src/fs/gnunet-service-fs_lc.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/fs/gnunet-service-fs_lc.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -170,16 +170,13 @@
struct GSF_LocalClient *pos;
pos = client_head;
- while ( (pos != NULL) &&
- (pos->client != client) )
+ while ((pos != NULL) && (pos->client != client))
pos = pos->next;
if (pos != NULL)
return pos;
pos = GNUNET_malloc (sizeof (struct GSF_LocalClient));
pos->client = client;
- GNUNET_CONTAINER_DLL_insert (client_head,
- client_tail,
- pos);
+ GNUNET_CONTAINER_DLL_insert (client_head, client_tail, pos);
return pos;
}
@@ -189,24 +186,21 @@
*
* @param cls the client request to free
* @param tc task context
- */
+ */
static void
client_request_destroy (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct ClientRequest *cr = cls;
struct GSF_LocalClient *lc;
cr->kill_task = GNUNET_SCHEDULER_NO_TASK;
lc = cr->lc;
- GNUNET_CONTAINER_DLL_remove (lc->cr_head,
- lc->cr_tail,
- cr);
+ GNUNET_CONTAINER_DLL_remove (lc->cr_head, lc->cr_tail, cr);
GSF_pending_request_cancel_ (cr->pr, GNUNET_NO);
GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# client searches active"),
- - 1,
- GNUNET_NO);
+ gettext_noop ("# client searches active"),
+ -1, GNUNET_NO);
GNUNET_free (cr);
}
@@ -230,13 +224,12 @@
*/
static void
client_response_handler (void *cls,
- enum GNUNET_BLOCK_EvaluationResult eval,
- struct GSF_PendingRequest *pr,
- uint32_t reply_anonymity_level,
- struct GNUNET_TIME_Absolute expiration,
- enum GNUNET_BLOCK_Type type,
- const void *data,
- size_t data_len)
+ enum GNUNET_BLOCK_EvaluationResult eval,
+ struct GSF_PendingRequest *pr,
+ uint32_t reply_anonymity_level,
+ struct GNUNET_TIME_Absolute expiration,
+ enum GNUNET_BLOCK_Type type,
+ const void *data, size_t data_len)
{
struct ClientRequest *cr = cls;
struct GSF_LocalClient *lc;
@@ -245,47 +238,44 @@
size_t msize;
if (NULL == data)
- {
- /* ugh, request 'timed out' -- how can this be? */
- GNUNET_break (0);
- return;
- }
+ {
+ /* ugh, request 'timed out' -- how can this be? */
+ GNUNET_break (0);
+ return;
+ }
prd = GSF_pending_request_get_data_ (pr);
GNUNET_break (type != GNUNET_BLOCK_TYPE_ANY);
- if ( (prd->type != type) &&
- (prd->type != GNUNET_BLOCK_TYPE_ANY) )
- {
- GNUNET_break (0);
- return;
- }
+ if ((prd->type != type) && (prd->type != GNUNET_BLOCK_TYPE_ANY))
+ {
+ GNUNET_break (0);
+ return;
+ }
GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# replies received for local
clients"),
- 1,
- GNUNET_NO);
+ gettext_noop
+ ("# replies received for local clients"), 1,
+ GNUNET_NO);
GNUNET_assert (pr == cr->pr);
lc = cr->lc;
msize = sizeof (struct PutMessage) + data_len;
{
char buf[msize];
-
- pm = (struct PutMessage*) buf;
+
+ pm = (struct PutMessage *) buf;
pm->header.type = htons (GNUNET_MESSAGE_TYPE_FS_PUT);
pm->header.size = htons (msize);
pm->type = htonl (type);
pm->expiration = GNUNET_TIME_absolute_hton (expiration);
- memcpy (&pm[1], data, data_len);
+ memcpy (&pm[1], data, data_len);
GSF_local_client_transmit_ (lc, &pm->header);
}
#if DEBUG_FS_CLIENT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Queued reply to query `%s' for local client\n",
- GNUNET_h2s (&prd->query),
- (unsigned int) prd->type);
+ "Queued reply to query `%s' for local client\n",
+ GNUNET_h2s (&prd->query), (unsigned int) prd->type);
#endif
if (eval != GNUNET_BLOCK_EVALUATION_OK_LAST)
return;
- cr->kill_task = GNUNET_SCHEDULER_add_now (&client_request_destroy,
- cr);
+ cr->kill_task = GNUNET_SCHEDULER_add_now (&client_request_destroy, cr);
}
@@ -298,7 +288,8 @@
*/
struct GSF_PendingRequest *
GSF_local_client_start_search_handler_ (struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader
*message)
+ const struct GNUNET_MessageHeader
+ *message)
{
static GNUNET_HashCode all_zeros;
const struct SearchMessage *sm;
@@ -311,99 +302,84 @@
enum GSF_PendingRequestOptions options;
msize = ntohs (message->size);
- if ( (msize < sizeof (struct SearchMessage)) ||
- (0 != (msize - sizeof (struct SearchMessage)) % sizeof
(GNUNET_HashCode)) )
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client,
- GNUNET_SYSERR);
- return NULL;
- }
+ if ((msize < sizeof (struct SearchMessage)) ||
+ (0 != (msize - sizeof (struct SearchMessage)) % sizeof
(GNUNET_HashCode)))
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return NULL;
+ }
GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# client searches received"),
- 1,
- GNUNET_NO);
+ gettext_noop ("# client searches received"),
+ 1, GNUNET_NO);
sc = (msize - sizeof (struct SearchMessage)) / sizeof (GNUNET_HashCode);
- sm = (const struct SearchMessage*) message;
+ sm = (const struct SearchMessage *) message;
type = ntohl (sm->type);
#if DEBUG_FS_CLIENT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received request for `%s' of type %u from local client\n",
- GNUNET_h2s (&sm->query),
- (unsigned int) type);
+ "Received request for `%s' of type %u from local client\n",
+ GNUNET_h2s (&sm->query), (unsigned int) type);
#endif
lc = GSF_local_client_lookup_ (client);
/* detect duplicate KBLOCK requests */
- if ( (type == GNUNET_BLOCK_TYPE_FS_KBLOCK) ||
- (type == GNUNET_BLOCK_TYPE_FS_NBLOCK) ||
- (type == GNUNET_BLOCK_TYPE_ANY) )
+ if ((type == GNUNET_BLOCK_TYPE_FS_KBLOCK) ||
+ (type == GNUNET_BLOCK_TYPE_FS_NBLOCK) || (type == GNUNET_BLOCK_TYPE_ANY))
+ {
+ /* FIXME: this does currently not work to filter duplicate
+ * results from *local* datastore since the local store is
+ * queried before we continue to process additional
+ * messages from the client! -- fix protocol? */
+ cr = lc->cr_head;
+ while (cr != NULL)
{
- /* FIXME: this does currently not work to filter duplicate
- results from *local* datastore since the local store is
- queried before we continue to process additional
- messages from the client! -- fix protocol? */
- cr = lc->cr_head;
- while (cr != NULL)
- {
- prd = GSF_pending_request_get_data_ (cr->pr);
- if ( (0 != memcmp (&prd->query,
- &sm->query,
- sizeof (GNUNET_HashCode))) &&
- (prd->type == type) )
- break;
- cr = cr->next;
- }
- if (cr != NULL)
- {
+ prd = GSF_pending_request_get_data_ (cr->pr);
+ if ((0 != memcmp (&prd->query,
+ &sm->query,
+ sizeof (GNUNET_HashCode))) && (prd->type == type))
+ break;
+ cr = cr->next;
+ }
+ if (cr != NULL)
+ {
#if DEBUG_FS_CLIENT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Have existing request, merging content-seen lists.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Have existing request, merging content-seen lists.\n");
#endif
- GSF_pending_request_update_ (cr->pr,
- (const GNUNET_HashCode*) &sm[1],
- sc);
- GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# client searches updated
(merged content seen list)"),
- 1,
- GNUNET_NO);
- GNUNET_SERVER_receive_done (client,
- GNUNET_OK);
- return NULL;
- }
+ GSF_pending_request_update_ (cr->pr,
+ (const GNUNET_HashCode *) &sm[1], sc);
+ GNUNET_STATISTICS_update (GSF_stats,
+ gettext_noop
+ ("# client searches updated (merged content
seen list)"),
+ 1, GNUNET_NO);
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ return NULL;
}
+ }
GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# client searches active"),
- 1,
- GNUNET_NO);
+ gettext_noop ("# client searches active"),
+ 1, GNUNET_NO);
cr = GNUNET_malloc (sizeof (struct ClientRequest));
cr->lc = lc;
- GNUNET_CONTAINER_DLL_insert (lc->cr_head,
- lc->cr_tail,
- cr);
- options = GSF_PRO_LOCAL_REQUEST;
+ GNUNET_CONTAINER_DLL_insert (lc->cr_head, lc->cr_tail, cr);
+ options = GSF_PRO_LOCAL_REQUEST;
if (0 != (1 & ntohl (sm->options)))
options |= GSF_PRO_LOCAL_ONLY;
- cr->pr = GSF_pending_request_create_ (options,
- type,
- &sm->query,
- (type == GNUNET_BLOCK_TYPE_FS_SBLOCK)
- ? &sm->target /* namespace */
- : NULL,
- (0 != memcmp (&sm->target,
- &all_zeros,
- sizeof (GNUNET_HashCode)))
- ? (const struct GNUNET_PeerIdentity*)
&sm->target
- : NULL,
- NULL, 0, 0 /* bf */,
- ntohl (sm->anonymity_level),
- 0 /* priority */,
- 0 /* ttl */,
- 0 /* sender PID */,
- (const GNUNET_HashCode*) &sm[1], sc,
- &client_response_handler,
- cr);
+ cr->pr = GSF_pending_request_create_ (options, type, &sm->query, (type ==
GNUNET_BLOCK_TYPE_FS_SBLOCK) ? &sm->target /* namespace */
+ : NULL,
+ (0 != memcmp (&sm->target,
+ &all_zeros,
+ sizeof
(GNUNET_HashCode)))
+ ? (const struct GNUNET_PeerIdentity *)
+ &sm->target : NULL, NULL, 0,
+ 0 /* bf */ ,
+ ntohl (sm->anonymity_level),
+ 0 /* priority */ ,
+ 0 /* ttl */ ,
+ 0 /* sender PID */ ,
+ (const GNUNET_HashCode *) &sm[1], sc,
+ &client_response_handler, cr);
return cr->pr;
}
@@ -422,36 +398,30 @@
* @return number of bytes written to buf
*/
static size_t
-transmit_to_client (void *cls,
- size_t size,
- void *buf)
+transmit_to_client (void *cls, size_t size, void *buf)
{
struct GSF_LocalClient *lc = cls;
char *cbuf = buf;
struct ClientResponse *res;
size_t msize;
-
+
lc->th = NULL;
if (NULL == buf)
return 0;
msize = 0;
- while ( (NULL != (res = lc->res_head) ) &&
- (res->msize <= size) )
- {
- memcpy (&cbuf[msize], &res[1], res->msize);
- msize += res->msize;
- size -= res->msize;
- GNUNET_CONTAINER_DLL_remove (lc->res_head,
- lc->res_tail,
- res);
- GNUNET_free (res);
- }
+ while ((NULL != (res = lc->res_head)) && (res->msize <= size))
+ {
+ memcpy (&cbuf[msize], &res[1], res->msize);
+ msize += res->msize;
+ size -= res->msize;
+ GNUNET_CONTAINER_DLL_remove (lc->res_head, lc->res_tail, res);
+ GNUNET_free (res);
+ }
if (NULL != res)
lc->th = GNUNET_SERVER_notify_transmit_ready (lc->client,
- res->msize,
- GNUNET_TIME_UNIT_FOREVER_REL,
- &transmit_to_client,
- lc);
+ res->msize,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &transmit_to_client, lc);
return msize;
}
@@ -466,7 +436,7 @@
*/
void
GSF_local_client_transmit_ (struct GSF_LocalClient *lc,
- const struct GNUNET_MessageHeader *msg)
+ const struct GNUNET_MessageHeader *msg)
{
struct ClientResponse *res;
size_t msize;
@@ -476,15 +446,12 @@
res->lc = lc;
res->msize = msize;
memcpy (&res[1], msg, msize);
- GNUNET_CONTAINER_DLL_insert_tail (lc->res_head,
- lc->res_tail,
- res);
+ GNUNET_CONTAINER_DLL_insert_tail (lc->res_head, lc->res_tail, res);
if (NULL == lc->th)
lc->th = GNUNET_SERVER_notify_transmit_ready (lc->client,
- msize,
- GNUNET_TIME_UNIT_FOREVER_REL,
- &transmit_to_client,
- lc);
+ msize,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &transmit_to_client, lc);
}
@@ -496,49 +463,40 @@
* @param client handle of the client
*/
void
-GSF_client_disconnect_handler_ (void *cls,
- struct GNUNET_SERVER_Client *client)
+GSF_client_disconnect_handler_ (void *cls, struct GNUNET_SERVER_Client *client)
{
struct GSF_LocalClient *pos;
struct ClientRequest *cr;
struct ClientResponse *res;
pos = client_head;
- while ( (pos != NULL) &&
- (pos->client != client) )
+ while ((pos != NULL) && (pos->client != client))
pos = pos->next;
if (pos == NULL)
return;
while (NULL != (cr = pos->cr_head))
- {
- GNUNET_CONTAINER_DLL_remove (pos->cr_head,
- pos->cr_tail,
- cr);
- GSF_pending_request_cancel_ (cr->pr, GNUNET_NO);
- GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# client searches active"),
- - 1,
- GNUNET_NO);
- if (GNUNET_SCHEDULER_NO_TASK != cr->kill_task)
- GNUNET_SCHEDULER_cancel (cr->kill_task);
- GNUNET_free (cr);
- }
+ {
+ GNUNET_CONTAINER_DLL_remove (pos->cr_head, pos->cr_tail, cr);
+ GSF_pending_request_cancel_ (cr->pr, GNUNET_NO);
+ GNUNET_STATISTICS_update (GSF_stats,
+ gettext_noop ("# client searches active"),
+ -1, GNUNET_NO);
+ if (GNUNET_SCHEDULER_NO_TASK != cr->kill_task)
+ GNUNET_SCHEDULER_cancel (cr->kill_task);
+ GNUNET_free (cr);
+ }
while (NULL != (res = pos->res_head))
- {
- GNUNET_CONTAINER_DLL_remove (pos->res_head,
- pos->res_tail,
- res);
- GNUNET_free (res);
- }
+ {
+ GNUNET_CONTAINER_DLL_remove (pos->res_head, pos->res_tail, res);
+ GNUNET_free (res);
+ }
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;
+ }
GSF_handle_local_client_disconnect_ (pos);
- GNUNET_CONTAINER_DLL_remove (client_head,
- client_tail,
- pos);
+ GNUNET_CONTAINER_DLL_remove (client_head, client_tail, pos);
GNUNET_free (pos);
}
Modified: gnunet/src/fs/gnunet-service-fs_lc.h
===================================================================
--- gnunet/src/fs/gnunet-service-fs_lc.h 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/fs/gnunet-service-fs_lc.h 2011-08-15 21:46:35 UTC (rev
16581)
@@ -36,8 +36,8 @@
* @param client handle of the client
* @return handle to local client entry
*/
-struct GSF_LocalClient *
-GSF_local_client_lookup_ (struct GNUNET_SERVER_Client *client);
+struct GSF_LocalClient *GSF_local_client_lookup_ (struct GNUNET_SERVER_Client
+ *client);
/**
@@ -50,9 +50,12 @@
* @param message the actual message
* @return pending request handle for the request, NULL on error
*/
-struct GSF_PendingRequest *
-GSF_local_client_start_search_handler_ (struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader
*message);
+struct GSF_PendingRequest *GSF_local_client_start_search_handler_ (struct
+
GNUNET_SERVER_Client
+ *client,
+ const struct
+
GNUNET_MessageHeader
+ *message);
/**
@@ -65,7 +68,7 @@
*/
void
GSF_local_client_transmit_ (struct GSF_LocalClient *lc,
- const struct GNUNET_MessageHeader *msg);
+ const struct GNUNET_MessageHeader *msg);
/**
@@ -75,8 +78,7 @@
* @param client handle of the client
*/
void
-GSF_client_disconnect_handler_ (void *cls,
- struct GNUNET_SERVER_Client *client);
+GSF_client_disconnect_handler_ (void *cls, struct GNUNET_SERVER_Client
*client);
#endif
Modified: gnunet/src/fs/gnunet-service-fs_pe.c
===================================================================
--- gnunet/src/fs/gnunet-service-fs_pe.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/fs/gnunet-service-fs_pe.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -43,7 +43,7 @@
*/
struct GSF_RequestPlanReference
{
-
+
/**
* This is a doubly-linked list.
*/
@@ -123,12 +123,12 @@
/**
* Head of list of associated pending requests.
*/
- struct PendingRequestList *prl_head;
+ struct PendingRequestList *prl_head;
/**
* Tail of list of associated pending requests.
*/
- struct PendingRequestList *prl_tail;
+ struct PendingRequestList *prl_tail;
/**
* Earliest time we'd be happy to (re)transmit this request.
@@ -209,7 +209,7 @@
*/
static void
schedule_peer_transmission (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+ const struct GNUNET_SCHEDULER_TaskContext *tc);
/**
@@ -219,42 +219,36 @@
* @param rp request to plan
*/
static void
-plan (struct PeerPlan *pp,
- struct GSF_RequestPlan *rp)
+plan (struct PeerPlan *pp, struct GSF_RequestPlan *rp)
{
struct GSF_PendingRequestData *prd;
struct GNUNET_TIME_Relative delay;
GNUNET_STATISTICS_set (GSF_stats,
- gettext_noop ("# average retransmission delay (ms)"),
- total_delay * 1000LL / plan_count,
- GNUNET_NO);
+ gettext_noop ("# average retransmission delay (ms)"),
+ total_delay * 1000LL / plan_count, GNUNET_NO);
prd = GSF_pending_request_get_data_ (rp->prl_head->pr);
// FIXME: calculate 'rp->priority'!
if (rp->transmission_counter < 32)
delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
- 1LL << rp->transmission_counter);
+ 1LL << rp->transmission_counter);
else
- delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
- UINT_MAX);
- rp->earliest_transmission
- = GNUNET_TIME_relative_to_absolute (delay);
+ delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, UINT_MAX);
+ rp->earliest_transmission = GNUNET_TIME_relative_to_absolute (delay);
#if DEBUG_FS
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Earliest (re)transmission for `%s' in %us\n",
- GNUNET_h2s (&prd->query),
- rp->transmission_counter);
-#endif
+ "Earliest (re)transmission for `%s' in %us\n",
+ GNUNET_h2s (&prd->query), rp->transmission_counter);
+#endif
GNUNET_assert (rp->hn == NULL);
- if (GNUNET_TIME_absolute_get_remaining (rp->earliest_transmission).rel_value
== 0)
- rp->hn = GNUNET_CONTAINER_heap_insert (pp->priority_heap,
- rp,
- rp->priority);
+ if (GNUNET_TIME_absolute_get_remaining (rp->earliest_transmission).rel_value
+ == 0)
+ rp->hn = GNUNET_CONTAINER_heap_insert (pp->priority_heap, rp,
rp->priority);
else
rp->hn = GNUNET_CONTAINER_heap_insert (pp->delay_heap,
- rp,
- rp->earliest_transmission.abs_value);
+ rp,
+
rp->earliest_transmission.abs_value);
if (GNUNET_SCHEDULER_NO_TASK != pp->task)
GNUNET_SCHEDULER_cancel (pp->task);
pp->task = GNUNET_SCHEDULER_add_now (&schedule_peer_transmission, pp);
@@ -277,13 +271,13 @@
ret = prl->pr;
prl = prl->next;
while (NULL != prl)
- {
- if (GSF_pending_request_get_data_ (prl->pr)->ttl.abs_value >
- GSF_pending_request_get_data_ (ret)->ttl.abs_value)
- ret = prl->pr;
- prl = prl->next;
- }
- return ret;
+ {
+ if (GSF_pending_request_get_data_ (prl->pr)->ttl.abs_value >
+ GSF_pending_request_get_data_ (ret)->ttl.abs_value)
+ ret = prl->pr;
+ prl = prl->next;
+ }
+ return ret;
}
@@ -295,10 +289,8 @@
* @param buf where to copy the message, NULL on error (peer disconnect)
* @return number of bytes copied to 'buf', can be 0 (without indicating an
error)
*/
-static size_t
-transmit_message_callback (void *cls,
- size_t buf_size,
- void *buf)
+static size_t
+transmit_message_callback (void *cls, size_t buf_size, void *buf)
{
struct PeerPlan *pp = cls;
struct GSF_RequestPlan *rp;
@@ -306,24 +298,24 @@
pp->pth = NULL;
if (NULL == buf)
- {
- /* failed, try again... */
- pp->task = GNUNET_SCHEDULER_add_now (&schedule_peer_transmission, pp);
- return 0;
- }
+ {
+ /* failed, try again... */
+ pp->task = GNUNET_SCHEDULER_add_now (&schedule_peer_transmission, pp);
+ return 0;
+ }
rp = GNUNET_CONTAINER_heap_peek (pp->priority_heap);
if (NULL == rp)
- {
- pp->task = GNUNET_SCHEDULER_add_now (&schedule_peer_transmission, pp);
- return 0;
- }
+ {
+ pp->task = GNUNET_SCHEDULER_add_now (&schedule_peer_transmission, pp);
+ return 0;
+ }
msize = GSF_pending_request_get_message_ (get_latest (rp), buf_size, buf);
if (msize > buf_size)
- {
- /* buffer to small (message changed), try again */
- pp->task = GNUNET_SCHEDULER_add_now (&schedule_peer_transmission, pp);
- return 0;
- }
+ {
+ /* buffer to small (message changed), try again */
+ pp->task = GNUNET_SCHEDULER_add_now (&schedule_peer_transmission, pp);
+ return 0;
+ }
/* remove from root, add again elsewhere... */
GNUNET_assert (rp == GNUNET_CONTAINER_heap_remove_root (pp->priority_heap));
rp->hn = NULL;
@@ -332,15 +324,14 @@
total_delay++;
#if DEBUG_FS
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Executing plan %p executed %u times, planning retransmission\n",
- rp,
- rp->transmission_counter);
-#endif
+ "Executing plan %p executed %u times, planning retransmission\n",
+ rp, rp->transmission_counter);
+#endif
plan (pp, rp);
GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# queries messages sent to other
peers"),
- 1,
- GNUNET_NO);
+ gettext_noop
+ ("# queries messages sent to other peers"), 1,
+ GNUNET_NO);
return msize;
}
@@ -353,7 +344,7 @@
*/
static void
schedule_peer_transmission (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct PeerPlan *pp = cls;
struct GSF_RequestPlan *rp;
@@ -361,59 +352,55 @@
pp->task = GNUNET_SCHEDULER_NO_TASK;
if (pp->pth != NULL)
- {
- GSF_peer_transmit_cancel_ (pp->pth);
- pp->pth = NULL;
- }
+ {
+ GSF_peer_transmit_cancel_ (pp->pth);
+ pp->pth = NULL;
+ }
/* move ready requests to priority queue */
- while ( (NULL != (rp = GNUNET_CONTAINER_heap_peek (pp->delay_heap))) &&
- (GNUNET_TIME_absolute_get_remaining
(rp->earliest_transmission).rel_value == 0) )
- {
- GNUNET_assert (rp == GNUNET_CONTAINER_heap_remove_root (pp->delay_heap));
- rp->hn = GNUNET_CONTAINER_heap_insert (pp->priority_heap,
- rp,
- rp->priority);
- }
+ while ((NULL != (rp = GNUNET_CONTAINER_heap_peek (pp->delay_heap))) &&
+ (GNUNET_TIME_absolute_get_remaining
+ (rp->earliest_transmission).rel_value == 0))
+ {
+ GNUNET_assert (rp == GNUNET_CONTAINER_heap_remove_root (pp->delay_heap));
+ rp->hn = GNUNET_CONTAINER_heap_insert (pp->priority_heap, rp,
rp->priority);
+ }
if (0 == GNUNET_CONTAINER_heap_get_size (pp->priority_heap))
+ {
+ /* priority heap (still) empty, check for delay... */
+ rp = GNUNET_CONTAINER_heap_peek (pp->delay_heap);
+ if (NULL == rp)
{
- /* priority heap (still) empty, check for delay... */
- rp = GNUNET_CONTAINER_heap_peek (pp->delay_heap);
- if (NULL == rp)
- {
#if DEBUG_FS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "No active requests for plan %p.\n",
- pp);
-#endif
- return; /* both queues empty */
- }
-#if DEBUG_FS
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sleeping for %llu ms before retrying requests on plan %p.\n",
- (unsigned long long) GNUNET_TIME_absolute_get_remaining
(rp->earliest_transmission).rel_value,
- pp);
+ "No active requests for plan %p.\n", pp);
#endif
- pp->task = GNUNET_SCHEDULER_add_delayed
(GNUNET_TIME_absolute_get_remaining (rp->earliest_transmission),
- &schedule_peer_transmission,
- pp);
- return;
+ return; /* both queues empty */
}
+#if DEBUG_FS
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sleeping for %llu ms before retrying requests on plan %p.\n",
+ (unsigned long long)
+ GNUNET_TIME_absolute_get_remaining
+ (rp->earliest_transmission).rel_value, pp);
+#endif
+ pp->task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
+ (rp->earliest_transmission),
+ &schedule_peer_transmission, pp);
+ return;
+ }
/* process from priority heap */
rp = GNUNET_CONTAINER_heap_peek (pp->priority_heap);
#if DEBUG_FS > 1
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Executing query plan %p\n",
- rp);
-#endif
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing query plan %p\n", rp);
+#endif
GNUNET_assert (NULL != rp);
msize = GSF_pending_request_get_message_ (get_latest (rp), 0, NULL);
pp->pth = GSF_peer_transmit_ (pp->cp,
- GNUNET_YES,
- rp->priority,
- GNUNET_TIME_UNIT_FOREVER_REL,
- msize,
- &transmit_message_callback,
- pp);
+ GNUNET_YES,
+ rp->priority,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ msize, &transmit_message_callback, pp);
GNUNET_assert (NULL != pp->pth);
}
@@ -444,9 +431,8 @@
*/
static int
merge_pr (void *cls,
- struct GNUNET_CONTAINER_HeapNode *node,
- void *element,
- GNUNET_CONTAINER_HeapCostType cost)
+ struct GNUNET_CONTAINER_HeapNode *node,
+ void *element, GNUNET_CONTAINER_HeapCostType cost)
{
struct MergeContext *mpr = cls;
struct GSF_RequestPlan *rp = element;
@@ -456,37 +442,30 @@
struct GSF_PendingRequest *latest;
if (GNUNET_OK !=
- GSF_pending_request_is_compatible_ (mpr->pr,
- rp->prl_head->pr))
+ GSF_pending_request_is_compatible_ (mpr->pr, rp->prl_head->pr))
return GNUNET_YES;
/* merge new request with existing request plan */
- rpr = GNUNET_malloc (sizeof (struct GSF_RequestPlanReference));
- prl = GNUNET_malloc (sizeof (struct PendingRequestList));
+ rpr = GNUNET_malloc (sizeof (struct GSF_RequestPlanReference));
+ prl = GNUNET_malloc (sizeof (struct PendingRequestList));
rpr->rp = rp;
rpr->prl = prl;
prl->rpr = rpr;
prl->pr = mpr->pr;
prd = GSF_pending_request_get_data_ (mpr->pr);
- GNUNET_CONTAINER_DLL_insert (prd->rpr_head,
- prd->rpr_tail,
- rpr);
- GNUNET_CONTAINER_DLL_insert (rp->prl_head,
- rp->prl_tail,
- prl);
+ GNUNET_CONTAINER_DLL_insert (prd->rpr_head, prd->rpr_tail, rpr);
+ GNUNET_CONTAINER_DLL_insert (rp->prl_head, rp->prl_tail, prl);
mpr->merged = GNUNET_YES;
GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# requests merged"),
- 1,
- GNUNET_NO);
+ gettext_noop ("# requests merged"), 1, GNUNET_NO);
latest = get_latest (rp);
- if (GSF_pending_request_get_data_ (latest)->ttl.abs_value <
prd->ttl.abs_value)
- {
- GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# requests refreshed"),
- 1,
- GNUNET_NO);
- rp->transmission_counter = 0; /* reset */
- }
+ if (GSF_pending_request_get_data_ (latest)->ttl.abs_value <
+ prd->ttl.abs_value)
+ {
+ GNUNET_STATISTICS_update (GSF_stats,
+ gettext_noop ("# requests refreshed"),
+ 1, GNUNET_NO);
+ rp->transmission_counter = 0; /* reset */
+ }
return GNUNET_NO;
}
@@ -498,8 +477,7 @@
* @param pr request with the entry
*/
void
-GSF_plan_add_ (struct GSF_ConnectedPeer *cp,
- struct GSF_PendingRequest *pr)
+GSF_plan_add_ (struct GSF_ConnectedPeer *cp, struct GSF_PendingRequest *pr)
{
struct GNUNET_PeerIdentity id;
struct PeerPlan *pp;
@@ -511,19 +489,20 @@
GNUNET_assert (NULL != cp);
GSF_connected_peer_get_identity_ (cp, &id);
- pp = GNUNET_CONTAINER_multihashmap_get (plans,
- &id.hashPubKey);
+ pp = GNUNET_CONTAINER_multihashmap_get (plans, &id.hashPubKey);
if (NULL == pp)
- {
- pp = GNUNET_malloc (sizeof (struct PeerPlan));
- pp->priority_heap = GNUNET_CONTAINER_heap_create
(GNUNET_CONTAINER_HEAP_ORDER_MAX);
- pp->delay_heap = GNUNET_CONTAINER_heap_create
(GNUNET_CONTAINER_HEAP_ORDER_MIN);
- pp->cp = cp;
- GNUNET_CONTAINER_multihashmap_put (plans,
- &id.hashPubKey,
- pp,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
- }
+ {
+ pp = GNUNET_malloc (sizeof (struct PeerPlan));
+ pp->priority_heap =
+ GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MAX);
+ pp->delay_heap =
+ GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
+ pp->cp = cp;
+ GNUNET_CONTAINER_multihashmap_put (plans,
+ &id.hashPubKey,
+ pp,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+ }
mpc.merged = GNUNET_NO;
mpc.pr = pr;
GNUNET_CONTAINER_heap_iterate (pp->priority_heap, &merge_pr, &mpc);
@@ -534,29 +513,23 @@
return;
plan_count++;
GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# query plan entries"),
- 1,
- GNUNET_NO);
+ gettext_noop ("# query plan entries"),
+ 1, GNUNET_NO);
prd = GSF_pending_request_get_data_ (pr);
#if DEBUG_FS
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Planning transmission of query `%s' to peer `%s'\n",
- GNUNET_h2s (&prd->query),
- GNUNET_i2s (&id));
-#endif
+ "Planning transmission of query `%s' to peer `%s'\n",
+ GNUNET_h2s (&prd->query), GNUNET_i2s (&id));
+#endif
rp = GNUNET_malloc (sizeof (struct GSF_RequestPlan));
- rpr = GNUNET_malloc (sizeof (struct GSF_RequestPlanReference));
- prl = GNUNET_malloc (sizeof (struct PendingRequestList));
+ rpr = GNUNET_malloc (sizeof (struct GSF_RequestPlanReference));
+ prl = GNUNET_malloc (sizeof (struct PendingRequestList));
rpr->rp = rp;
rpr->prl = prl;
prl->rpr = rpr;
prl->pr = pr;
- GNUNET_CONTAINER_DLL_insert (prd->rpr_head,
- prd->rpr_tail,
- rpr);
- GNUNET_CONTAINER_DLL_insert (rp->prl_head,
- rp->prl_tail,
- prl);
+ GNUNET_CONTAINER_DLL_insert (prd->rpr_head, prd->rpr_tail, rpr);
+ GNUNET_CONTAINER_DLL_insert (rp->prl_head, rp->prl_tail, prl);
plan (pp, rp);
}
@@ -577,58 +550,47 @@
struct PendingRequestList *prl;
GSF_connected_peer_get_identity_ (cp, &id);
- pp = GNUNET_CONTAINER_multihashmap_get (plans,
- &id.hashPubKey);
+ pp = GNUNET_CONTAINER_multihashmap_get (plans, &id.hashPubKey);
if (NULL == pp)
- return; /* nothing was ever planned for this peer */
+ return; /* nothing was ever planned for this peer */
GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove (plans,
- &id.hashPubKey,
- pp));
+ GNUNET_CONTAINER_multihashmap_remove (plans,
+ &id.hashPubKey, pp));
if (NULL != pp->pth)
GSF_peer_transmit_cancel_ (pp->pth);
if (GNUNET_SCHEDULER_NO_TASK != pp->task)
- {
- GNUNET_SCHEDULER_cancel (pp->task);
- pp->task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (pp->task);
+ pp->task = GNUNET_SCHEDULER_NO_TASK;
+ }
while (NULL != (rp = GNUNET_CONTAINER_heap_remove_root (pp->priority_heap)))
+ {
+ while (NULL != (prl = rp->prl_head))
{
- while (NULL != (prl = rp->prl_head))
- {
- GNUNET_CONTAINER_DLL_remove (rp->prl_head,
- rp->prl_tail,
- prl);
- prd = GSF_pending_request_get_data_ (prl->pr);
- GNUNET_CONTAINER_DLL_remove (prd->rpr_head,
- prd->rpr_tail,
- prl->rpr);
- GNUNET_free (prl->rpr);
- GNUNET_free (prl);
- }
- GNUNET_free (rp);
+ GNUNET_CONTAINER_DLL_remove (rp->prl_head, rp->prl_tail, prl);
+ prd = GSF_pending_request_get_data_ (prl->pr);
+ GNUNET_CONTAINER_DLL_remove (prd->rpr_head, prd->rpr_tail, prl->rpr);
+ GNUNET_free (prl->rpr);
+ GNUNET_free (prl);
}
+ GNUNET_free (rp);
+ }
GNUNET_CONTAINER_heap_destroy (pp->priority_heap);
while (NULL != (rp = GNUNET_CONTAINER_heap_remove_root (pp->delay_heap)))
+ {
+ while (NULL != (prl = rp->prl_head))
{
- while (NULL != (prl = rp->prl_head))
- {
- GNUNET_CONTAINER_DLL_remove (rp->prl_head,
- rp->prl_tail,
- prl);
- prd = GSF_pending_request_get_data_ (prl->pr);
- GNUNET_CONTAINER_DLL_remove (prd->rpr_head,
- prd->rpr_tail,
- prl->rpr);
- GNUNET_free (prl->rpr);
- GNUNET_free (prl);
- }
- GNUNET_free (rp);
+ GNUNET_CONTAINER_DLL_remove (rp->prl_head, rp->prl_tail, prl);
+ prd = GSF_pending_request_get_data_ (prl->pr);
+ GNUNET_CONTAINER_DLL_remove (prd->rpr_head, prd->rpr_tail, prl->rpr);
+ GNUNET_free (prl->rpr);
+ GNUNET_free (prl);
}
+ GNUNET_free (rp);
+ }
GNUNET_STATISTICS_set (GSF_stats,
- gettext_noop ("# query plan entries"),
- plan_count,
- GNUNET_NO);
+ gettext_noop ("# query plan entries"),
+ plan_count, GNUNET_NO);
GNUNET_CONTAINER_heap_destroy (pp->delay_heap);
GNUNET_free (pp);
@@ -650,27 +612,22 @@
prd = GSF_pending_request_get_data_ (pr);
while (NULL != (rpr = prd->rpr_head))
+ {
+ GNUNET_CONTAINER_DLL_remove (prd->rpr_head, prd->rpr_tail, rpr);
+ rp = rpr->rp;
+ GNUNET_CONTAINER_DLL_remove (rp->prl_head, rp->prl_tail, rpr->prl);
+ GNUNET_free (rpr->prl);
+ GNUNET_free (rpr);
+ if (rp->prl_head == 0)
{
- GNUNET_CONTAINER_DLL_remove (prd->rpr_head,
- prd->rpr_tail,
- rpr);
- rp = rpr->rp;
- GNUNET_CONTAINER_DLL_remove (rp->prl_head,
- rp->prl_tail,
- rpr->prl);
- GNUNET_free (rpr->prl);
- GNUNET_free (rpr);
- if (rp->prl_head == 0)
- {
- GNUNET_CONTAINER_heap_remove_node (rp->hn);
- plan_count--;
- GNUNET_free (rp);
- }
+ GNUNET_CONTAINER_heap_remove_node (rp->hn);
+ plan_count--;
+ GNUNET_free (rp);
}
+ }
GNUNET_STATISTICS_set (GSF_stats,
- gettext_noop ("# query plan entries"),
- plan_count,
- GNUNET_NO);
+ gettext_noop ("# query plan entries"),
+ plan_count, GNUNET_NO);
}
@@ -690,8 +647,7 @@
void
GSF_plan_done ()
{
- GNUNET_assert (0 ==
- GNUNET_CONTAINER_multihashmap_size (plans));
+ GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (plans));
GNUNET_CONTAINER_multihashmap_destroy (plans);
}
Modified: gnunet/src/fs/gnunet-service-fs_pe.h
===================================================================
--- gnunet/src/fs/gnunet-service-fs_pe.h 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/fs/gnunet-service-fs_pe.h 2011-08-15 21:46:35 UTC (rev
16581)
@@ -36,8 +36,7 @@
* @param pr request with the entry
*/
void
-GSF_plan_add_ (struct GSF_ConnectedPeer *cp,
- struct GSF_PendingRequest *pr);
+GSF_plan_add_ (struct GSF_ConnectedPeer *cp, struct GSF_PendingRequest *pr);
/**
@@ -46,8 +45,7 @@
*
* @param cp connected peer
*/
-void
-GSF_plan_notify_peer_disconnect_ (const struct GSF_ConnectedPeer *cp);
+void GSF_plan_notify_peer_disconnect_ (const struct GSF_ConnectedPeer *cp);
/**
@@ -56,22 +54,19 @@
*
* @param pr request that is done
*/
-void
-GSF_plan_notify_request_done_ (struct GSF_PendingRequest *pr);
+void GSF_plan_notify_request_done_ (struct GSF_PendingRequest *pr);
/**
* Initialize plan subsystem.
*/
-void
-GSF_plan_init (void);
+void GSF_plan_init (void);
/**
* Shutdown plan subsystem.
*/
-void
-GSF_plan_done (void);
+void GSF_plan_done (void);
#endif
Modified: gnunet/src/fs/gnunet-service-fs_pr.c
===================================================================
--- gnunet/src/fs/gnunet-service-fs_pr.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/fs/gnunet-service-fs_pr.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -43,7 +43,7 @@
{
/**
* Public data for the request.
- */
+ */
struct GSF_PendingRequestData public_data;
/**
@@ -236,23 +236,19 @@
GNUNET_HashCode mhash;
nsize = compute_bloomfilter_size (pr->replies_seen_count);
- if ( (pr->bf != NULL) &&
- (nsize == GNUNET_CONTAINER_bloomfilter_get_size (pr->bf)) )
- return GNUNET_NO; /* size not changed */
+ if ((pr->bf != NULL) &&
+ (nsize == GNUNET_CONTAINER_bloomfilter_get_size (pr->bf)))
+ return GNUNET_NO; /* size not changed */
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_CONTAINER_bloomfilter_init (NULL,
- nsize,
- BLOOMFILTER_K);
- for (i=0;i<pr->replies_seen_count;i++)
- {
- GNUNET_BLOCK_mingle_hash (&pr->replies_seen[i],
- pr->mingle,
- &mhash);
- GNUNET_CONTAINER_bloomfilter_add (pr->bf, &mhash);
- }
+ pr->mingle = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
+ UINT32_MAX);
+ pr->bf = GNUNET_CONTAINER_bloomfilter_init (NULL, nsize, BLOOMFILTER_K);
+ for (i = 0; i < pr->replies_seen_count; i++)
+ {
+ GNUNET_BLOCK_mingle_hash (&pr->replies_seen[i], pr->mingle, &mhash);
+ GNUNET_CONTAINER_bloomfilter_add (pr->bf, &mhash);
+ }
return GNUNET_YES;
}
@@ -280,118 +276,115 @@
*/
struct GSF_PendingRequest *
GSF_pending_request_create_ (enum GSF_PendingRequestOptions options,
- enum GNUNET_BLOCK_Type type,
- const GNUNET_HashCode *query,
- const GNUNET_HashCode *namespace,
- const struct GNUNET_PeerIdentity *target,
- const char *bf_data,
- size_t bf_size,
- uint32_t mingle,
- uint32_t anonymity_level,
- uint32_t priority,
- int32_t ttl,
- GNUNET_PEER_Id sender_pid,
- const GNUNET_HashCode *replies_seen,
- unsigned int replies_seen_count,
- GSF_PendingRequestReplyHandler rh,
- void *rh_cls)
+ enum GNUNET_BLOCK_Type type,
+ const GNUNET_HashCode * query,
+ const GNUNET_HashCode * namespace,
+ const struct GNUNET_PeerIdentity *target,
+ const char *bf_data,
+ size_t bf_size,
+ uint32_t mingle,
+ uint32_t anonymity_level,
+ uint32_t priority,
+ int32_t ttl,
+ GNUNET_PEER_Id sender_pid,
+ const GNUNET_HashCode * replies_seen,
+ unsigned int replies_seen_count,
+ GSF_PendingRequestReplyHandler rh, void *rh_cls)
{
struct GSF_PendingRequest *pr;
struct GSF_PendingRequest *dpr;
-
+
#if DEBUG_FS > 1
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Creating request handle for `%s' of type %d\n",
- GNUNET_h2s (query),
- type);
-#endif
+ "Creating request handle for `%s' of type %d\n",
+ GNUNET_h2s (query), type);
+#endif
GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# Pending requests created"),
- 1,
- GNUNET_NO);
+ gettext_noop ("# Pending requests created"),
+ 1, GNUNET_NO);
pr = GNUNET_malloc (sizeof (struct GSF_PendingRequest));
- pr->local_result_offset = GNUNET_CRYPTO_random_u64
(GNUNET_CRYPTO_QUALITY_WEAK,
- UINT64_MAX);
+ pr->local_result_offset =
+ GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX);
pr->public_data.query = *query;
if (GNUNET_BLOCK_TYPE_FS_SBLOCK == type)
- {
- GNUNET_assert (NULL != namespace);
- pr->public_data.namespace = *namespace;
- }
+ {
+ GNUNET_assert (NULL != namespace);
+ pr->public_data.namespace = *namespace;
+ }
if (NULL != target)
- {
- pr->public_data.target = *target;
- pr->public_data.has_target = GNUNET_YES;
- }
+ {
+ pr->public_data.target = *target;
+ pr->public_data.has_target = GNUNET_YES;
+ }
pr->public_data.anonymity_level = anonymity_level;
pr->public_data.priority = priority;
pr->public_data.original_priority = priority;
pr->public_data.options = options;
- pr->public_data.type = type;
+ pr->public_data.type = type;
pr->public_data.start_time = GNUNET_TIME_absolute_get ();
pr->sender_pid = sender_pid;
pr->rh = rh;
pr->rh_cls = rh_cls;
- GNUNET_assert ( (sender_pid != 0) ||
- (0 == (options & GSF_PRO_FORWARD_ONLY)) );
+ GNUNET_assert ((sender_pid != 0) || (0 == (options & GSF_PRO_FORWARD_ONLY)));
if (ttl >= 0)
- pr->public_data.ttl = GNUNET_TIME_relative_to_absolute
(GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
-
(uint32_t) ttl));
+ pr->public_data.ttl =
+ GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS,
+ (uint32_t) ttl));
else
- pr->public_data.ttl = GNUNET_TIME_absolute_subtract
(pr->public_data.start_time,
-
GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
-
(uint32_t) (- ttl)));
+ pr->public_data.ttl =
+ GNUNET_TIME_absolute_subtract (pr->public_data.start_time,
+ GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS,
+ (uint32_t) (-ttl)));
if (replies_seen_count > 0)
- {
- pr->replies_seen_size = replies_seen_count;
- pr->replies_seen = GNUNET_malloc (sizeof (GNUNET_HashCode) *
pr->replies_seen_size);
- memcpy (pr->replies_seen,
- replies_seen,
- replies_seen_count * sizeof (GNUNET_HashCode));
- pr->replies_seen_count = replies_seen_count;
- }
- if (NULL != bf_data)
- {
- pr->bf = GNUNET_CONTAINER_bloomfilter_init (bf_data,
- bf_size,
- BLOOMFILTER_K);
- pr->mingle = mingle;
- }
- else if ( (replies_seen_count > 0) &&
- (0 != (options & GSF_PRO_BLOOMFILTER_FULL_REFRESH)) )
- {
- GNUNET_assert (GNUNET_YES == refresh_bloomfilter (pr));
- }
+ {
+ pr->replies_seen_size = replies_seen_count;
+ pr->replies_seen =
+ GNUNET_malloc (sizeof (GNUNET_HashCode) * pr->replies_seen_size);
+ memcpy (pr->replies_seen, replies_seen,
+ replies_seen_count * sizeof (GNUNET_HashCode));
+ pr->replies_seen_count = replies_seen_count;
+ }
+ if (NULL != bf_data)
+ {
+ pr->bf = GNUNET_CONTAINER_bloomfilter_init (bf_data,
+ bf_size, BLOOMFILTER_K);
+ pr->mingle = mingle;
+ }
+ else if ((replies_seen_count > 0) &&
+ (0 != (options & GSF_PRO_BLOOMFILTER_FULL_REFRESH)))
+ {
+ GNUNET_assert (GNUNET_YES == refresh_bloomfilter (pr));
+ }
GNUNET_CONTAINER_multihashmap_put (pr_map,
- query,
- pr,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
+ query,
+ pr,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
if (0 != (options & GSF_PRO_REQUEST_EXPIRES))
+ {
+ pr->hnode = GNUNET_CONTAINER_heap_insert (requests_by_expiration_heap,
+ pr,
+ pr->public_data.ttl.abs_value);
+ /* make sure we don't track too many requests */
+ while (GNUNET_CONTAINER_heap_get_size (requests_by_expiration_heap) >
+ max_pending_requests)
{
- pr->hnode = GNUNET_CONTAINER_heap_insert (requests_by_expiration_heap,
- pr,
- pr->public_data.ttl.abs_value);
- /* make sure we don't track too many requests */
- while (GNUNET_CONTAINER_heap_get_size (requests_by_expiration_heap) >
max_pending_requests)
- {
- dpr = GNUNET_CONTAINER_heap_peek (requests_by_expiration_heap);
- GNUNET_assert (dpr != NULL);
- if (pr == dpr)
- break; /* let the request live briefly... */
- dpr->rh (dpr->rh_cls,
- GNUNET_BLOCK_EVALUATION_REQUEST_VALID,
- dpr,
- UINT32_MAX,
- GNUNET_TIME_UNIT_FOREVER_ABS,
- GNUNET_BLOCK_TYPE_ANY,
- NULL, 0);
- GSF_pending_request_cancel_ (dpr, GNUNET_YES);
- }
+ dpr = GNUNET_CONTAINER_heap_peek (requests_by_expiration_heap);
+ GNUNET_assert (dpr != NULL);
+ if (pr == dpr)
+ break; /* let the request live briefly... */
+ dpr->rh (dpr->rh_cls,
+ GNUNET_BLOCK_EVALUATION_REQUEST_VALID,
+ dpr,
+ UINT32_MAX,
+ GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_BLOCK_TYPE_ANY, NULL, 0);
+ GSF_pending_request_cancel_ (dpr, GNUNET_YES);
}
+ }
GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# Pending requests active"),
- 1,
- GNUNET_NO);
+ gettext_noop ("# Pending requests active"),
+ 1, GNUNET_NO);
return pr;
}
@@ -420,16 +413,15 @@
*/
int
GSF_pending_request_is_compatible_ (struct GSF_PendingRequest *pra,
- struct GSF_PendingRequest *prb)
+ struct GSF_PendingRequest *prb)
{
- if ( (pra->public_data.type != prb->public_data.type) ||
- (0 != memcmp (&pra->public_data.query,
- &prb->public_data.query,
- sizeof (GNUNET_HashCode))) ||
- ( (pra->public_data.type == GNUNET_BLOCK_TYPE_FS_SBLOCK) &&
- (0 != memcmp (&pra->public_data.namespace,
- &prb->public_data.namespace,
- sizeof (GNUNET_HashCode))) ) )
+ if ((pra->public_data.type != prb->public_data.type) ||
+ (0 != memcmp (&pra->public_data.query,
+ &prb->public_data.query,
+ sizeof (GNUNET_HashCode))) ||
+ ((pra->public_data.type == GNUNET_BLOCK_TYPE_FS_SBLOCK) &&
+ (0 != memcmp (&pra->public_data.namespace,
+ &prb->public_data.namespace, sizeof (GNUNET_HashCode)))))
return GNUNET_NO;
return GNUNET_OK;
}
@@ -446,57 +438,53 @@
*/
void
GSF_pending_request_update_ (struct GSF_PendingRequest *pr,
- const GNUNET_HashCode *replies_seen,
- unsigned int replies_seen_count)
+ const GNUNET_HashCode * replies_seen,
+ unsigned int replies_seen_count)
{
unsigned int i;
GNUNET_HashCode mhash;
if (replies_seen_count + pr->replies_seen_count < pr->replies_seen_count)
- return; /* integer overflow */
+ return; /* integer overflow */
if (0 != (pr->public_data.options & GSF_PRO_BLOOMFILTER_FULL_REFRESH))
+ {
+ /* we're responsible for the BF, full refresh */
+ if (replies_seen_count + pr->replies_seen_count > pr->replies_seen_size)
+ GNUNET_array_grow (pr->replies_seen,
+ pr->replies_seen_size,
+ replies_seen_count + pr->replies_seen_count);
+ memcpy (&pr->replies_seen[pr->replies_seen_count],
+ replies_seen, sizeof (GNUNET_HashCode) * replies_seen_count);
+ pr->replies_seen_count += replies_seen_count;
+ if (GNUNET_NO == refresh_bloomfilter (pr))
{
- /* we're responsible for the BF, full refresh */
- if (replies_seen_count + pr->replies_seen_count > pr->replies_seen_size)
- GNUNET_array_grow (pr->replies_seen,
- pr->replies_seen_size,
- replies_seen_count + pr->replies_seen_count);
- memcpy (&pr->replies_seen[pr->replies_seen_count],
- replies_seen,
- sizeof (GNUNET_HashCode) * replies_seen_count);
- pr->replies_seen_count += replies_seen_count;
- if (GNUNET_NO == refresh_bloomfilter (pr))
- {
- /* bf not recalculated, simply extend it with new bits */
- for (i=0;i<replies_seen_count;i++)
- {
- GNUNET_BLOCK_mingle_hash (&replies_seen[i],
- pr->mingle,
- &mhash);
- GNUNET_CONTAINER_bloomfilter_add (pr->bf, &mhash);
- }
- }
+ /* bf not recalculated, simply extend it with new bits */
+ for (i = 0; i < replies_seen_count; i++)
+ {
+ GNUNET_BLOCK_mingle_hash (&replies_seen[i], pr->mingle, &mhash);
+ GNUNET_CONTAINER_bloomfilter_add (pr->bf, &mhash);
+ }
}
+ }
else
+ {
+ if (NULL == pr->bf)
{
- if (NULL == pr->bf)
- {
- /* we're not the initiator, but the initiator did not give us
- any bloom-filter, so we need to create one on-the-fly */
- pr->mingle = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
- UINT32_MAX);
- pr->bf = GNUNET_CONTAINER_bloomfilter_init (NULL,
- compute_bloomfilter_size
(replies_seen_count),
- BLOOMFILTER_K);
- }
- 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);
- }
+ /* we're not the initiator, but the initiator did not give us
+ * any bloom-filter, so we need to create one on-the-fly */
+ pr->mingle = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
+ UINT32_MAX);
+ pr->bf = GNUNET_CONTAINER_bloomfilter_init (NULL,
+ compute_bloomfilter_size
+ (replies_seen_count),
+ BLOOMFILTER_K);
}
+ 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);
+ }
+ }
}
@@ -511,8 +499,7 @@
*/
size_t
GSF_pending_request_get_message_ (struct GSF_PendingRequest *pr,
- size_t buf_size,
- void *buf)
+ size_t buf_size, void *buf)
{
char lbuf[GNUNET_SERVER_MAX_MESSAGE_SIZE];
struct GetMessage *gm;
@@ -529,45 +516,44 @@
#if DEBUG_FS
if (buf_size > 0)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Building request message for `%s' of type %d\n",
- GNUNET_h2s (&pr->public_data.query),
- pr->public_data.type);
-#endif
+ "Building request message for `%s' of type %d\n",
+ GNUNET_h2s (&pr->public_data.query), pr->public_data.type);
+#endif
k = 0;
bm = 0;
do_route = (0 == (pr->public_data.options & GSF_PRO_FORWARD_ONLY));
- if ( (! do_route) && (pr->sender_pid == 0))
- {
- GNUNET_break (0);
- do_route = GNUNET_YES;
- }
- if (! do_route)
- {
- bm |= GET_MESSAGE_BIT_RETURN_TO;
- k++;
- }
+ if ((!do_route) && (pr->sender_pid == 0))
+ {
+ GNUNET_break (0);
+ do_route = GNUNET_YES;
+ }
+ if (!do_route)
+ {
+ bm |= GET_MESSAGE_BIT_RETURN_TO;
+ k++;
+ }
if (GNUNET_BLOCK_TYPE_FS_SBLOCK == pr->public_data.type)
- {
- bm |= GET_MESSAGE_BIT_SKS_NAMESPACE;
- k++;
- }
+ {
+ bm |= GET_MESSAGE_BIT_SKS_NAMESPACE;
+ k++;
+ }
if (GNUNET_YES == pr->public_data.has_target)
- {
- bm |= GET_MESSAGE_BIT_TRANSMIT_TO;
- k++;
- }
+ {
+ bm |= GET_MESSAGE_BIT_TRANSMIT_TO;
+ k++;
+ }
bf_size = GNUNET_CONTAINER_bloomfilter_get_size (pr->bf);
- msize = sizeof (struct GetMessage) + bf_size + k * sizeof(GNUNET_HashCode);
+ msize = sizeof (struct GetMessage) + bf_size + k * sizeof (GNUNET_HashCode);
GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE);
if (buf_size < msize)
- return msize;
- gm = (struct GetMessage*) lbuf;
+ return msize;
+ gm = (struct GetMessage *) lbuf;
gm->header.type = htons (GNUNET_MESSAGE_TYPE_FS_GET);
gm->header.size = htons (msize);
gm->type = htonl (pr->public_data.type);
if (do_route)
prio = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
- pr->public_data.priority + 1);
+ pr->public_data.priority + 1);
else
prio = 0;
pr->public_data.priority -= prio;
@@ -575,25 +561,23 @@
now = GNUNET_TIME_absolute_get ();
ttl = (int64_t) (pr->public_data.ttl.abs_value - now.abs_value);
gm->ttl = htonl (ttl / 1000);
- gm->filter_mutator = htonl(pr->mingle);
+ gm->filter_mutator = htonl (pr->mingle);
gm->hash_bitmap = htonl (bm);
gm->query = pr->public_data.query;
- ext = (GNUNET_HashCode*) &gm[1];
- k = 0;
- if (! do_route)
- GNUNET_PEER_resolve (pr->sender_pid,
- (struct GNUNET_PeerIdentity*) &ext[k++]);
+ ext = (GNUNET_HashCode *) & gm[1];
+ k = 0;
+ if (!do_route)
+ GNUNET_PEER_resolve (pr->sender_pid,
+ (struct GNUNET_PeerIdentity *) &ext[k++]);
if (GNUNET_BLOCK_TYPE_FS_SBLOCK == pr->public_data.type)
- memcpy (&ext[k++],
- &pr->public_data.namespace,
- sizeof (GNUNET_HashCode));
+ memcpy (&ext[k++], &pr->public_data.namespace, sizeof (GNUNET_HashCode));
if (GNUNET_YES == pr->public_data.has_target)
ext[k++] = pr->public_data.target.hashPubKey;
if (pr->bf != NULL)
GNUNET_assert (GNUNET_SYSERR !=
- GNUNET_CONTAINER_bloomfilter_get_raw_data (pr->bf,
- (char*) &ext[k],
- bf_size));
+ GNUNET_CONTAINER_bloomfilter_get_raw_data (pr->bf,
+ (char *) &ext[k],
+ bf_size));
memcpy (buf, gm, msize);
return msize;
}
@@ -607,63 +591,57 @@
* @param value value in the hash map (pending request)
* @return GNUNET_YES (we should continue to iterate)
*/
-static int
-clean_request (void *cls,
- const GNUNET_HashCode * key,
- void *value)
+static int
+clean_request (void *cls, const GNUNET_HashCode * key, void *value)
{
struct GSF_PendingRequest *pr = value;
GSF_LocalLookupContinuation cont;
#if DEBUG_FS
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Cleaning up pending request for `%s'.\n",
- GNUNET_h2s (key));
-#endif
+ "Cleaning up pending request for `%s'.\n", GNUNET_h2s (key));
+#endif
if (NULL != (cont = pr->llc_cont))
- {
- pr->llc_cont = NULL;
- cont (pr->llc_cont_cls,
- pr,
- pr->local_result);
- }
+ {
+ pr->llc_cont = NULL;
+ cont (pr->llc_cont_cls, pr, pr->local_result);
+ }
GSF_plan_notify_request_done_ (pr);
GNUNET_free_non_null (pr->replies_seen);
if (NULL != pr->bf)
- {
- GNUNET_CONTAINER_bloomfilter_free (pr->bf);
- pr->bf = NULL;
- }
+ {
+ GNUNET_CONTAINER_bloomfilter_free (pr->bf);
+ pr->bf = NULL;
+ }
GNUNET_PEER_change_rc (pr->sender_pid, -1);
pr->sender_pid = 0;
if (NULL != pr->hnode)
- {
- GNUNET_CONTAINER_heap_remove_node (pr->hnode);
- pr->hnode = NULL;
- }
+ {
+ GNUNET_CONTAINER_heap_remove_node (pr->hnode);
+ pr->hnode = NULL;
+ }
if (NULL != pr->qe)
- {
- GNUNET_DATASTORE_cancel (pr->qe);
- pr->qe = NULL;
- }
+ {
+ GNUNET_DATASTORE_cancel (pr->qe);
+ pr->qe = NULL;
+ }
if (NULL != pr->gh)
- {
- GNUNET_DHT_get_stop (pr->gh);
- pr->gh = NULL;
- }
+ {
+ GNUNET_DHT_get_stop (pr->gh);
+ pr->gh = NULL;
+ }
if (GNUNET_SCHEDULER_NO_TASK != pr->warn_task)
- {
- GNUNET_SCHEDULER_cancel (pr->warn_task);
- pr->warn_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (pr->warn_task);
+ pr->warn_task = GNUNET_SCHEDULER_NO_TASK;
+ }
GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_remove (pr_map,
- &pr->public_data.query,
- pr));
+ GNUNET_CONTAINER_multihashmap_remove (pr_map,
+ &pr->public_data.query,
+ pr));
GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# Pending requests active"),
- -1,
- GNUNET_NO);
+ gettext_noop ("# Pending requests active"),
+ -1, GNUNET_NO);
GNUNET_free (pr);
return GNUNET_YES;
}
@@ -676,46 +654,43 @@
* @param full_cleanup fully purge the request
*/
void
-GSF_pending_request_cancel_ (struct GSF_PendingRequest *pr,
- int full_cleanup)
+GSF_pending_request_cancel_ (struct GSF_PendingRequest *pr, int full_cleanup)
{
GSF_LocalLookupContinuation cont;
- if (NULL == pr_map)
- return; /* already cleaned up! */
+ if (NULL == pr_map)
+ return; /* already cleaned up! */
if (GNUNET_YES != full_cleanup)
+ {
+ /* make request inactive (we're no longer interested in more results),
+ * but do NOT remove from our data-structures, we still need it there
+ * to prevent the request from looping */
+ pr->rh = NULL;
+ if (NULL != (cont = pr->llc_cont))
{
- /* make request inactive (we're no longer interested in more results),
- but do NOT remove from our data-structures, we still need it there
- to prevent the request from looping */
- pr->rh = NULL;
- if (NULL != (cont = pr->llc_cont))
- {
- pr->llc_cont = NULL;
- cont (pr->llc_cont_cls,
- pr,
- pr->local_result);
- }
- GSF_plan_notify_request_done_ (pr);
- if (NULL != pr->qe)
- {
- GNUNET_DATASTORE_cancel (pr->qe);
- pr->qe = NULL;
- }
- if (NULL != pr->gh)
- {
- GNUNET_DHT_get_stop (pr->gh);
- pr->gh = NULL;
- }
- if (GNUNET_SCHEDULER_NO_TASK != pr->warn_task)
- {
- GNUNET_SCHEDULER_cancel (pr->warn_task);
- pr->warn_task = GNUNET_SCHEDULER_NO_TASK;
- }
- return;
+ pr->llc_cont = NULL;
+ cont (pr->llc_cont_cls, pr, pr->local_result);
}
+ GSF_plan_notify_request_done_ (pr);
+ if (NULL != pr->qe)
+ {
+ GNUNET_DATASTORE_cancel (pr->qe);
+ pr->qe = NULL;
+ }
+ if (NULL != pr->gh)
+ {
+ GNUNET_DHT_get_stop (pr->gh);
+ pr->gh = NULL;
+ }
+ if (GNUNET_SCHEDULER_NO_TASK != pr->warn_task)
+ {
+ GNUNET_SCHEDULER_cancel (pr->warn_task);
+ pr->warn_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ return;
+ }
GNUNET_assert (GNUNET_YES ==
- clean_request (NULL, &pr->public_data.query, pr));
+ clean_request (NULL, &pr->public_data.query, pr));
}
@@ -726,12 +701,11 @@
* @param cls closure for it
*/
void
-GSF_iterate_pending_requests_ (GSF_PendingRequestIterator it,
- void *cls)
+GSF_iterate_pending_requests_ (GSF_PendingRequestIterator it, void *cls)
{
GNUNET_CONTAINER_multihashmap_iterate (pr_map,
- (GNUNET_CONTAINER_HashMapIterator) it,
- cls);
+ (GNUNET_CONTAINER_HashMapIterator) it,
+ cls);
}
@@ -798,16 +772,15 @@
*/
static void
update_request_performance_data (struct ProcessReplyClosure *prq,
- struct GSF_PendingRequest *pr)
+ struct GSF_PendingRequest *pr)
{
if (prq->sender == NULL)
- return;
+ return;
GSF_peer_update_performance_ (prq->sender,
- pr->public_data.start_time,
- prq->priority);
+ pr->public_data.start_time, prq->priority);
}
-
+
/**
* We have received a reply; handle it!
*
@@ -817,9 +790,7 @@
* @return GNUNET_YES (we should continue to iterate)
*/
static int
-process_reply (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+process_reply (void *cls, const GNUNET_HashCode * key, void *value)
{
struct ProcessReplyClosure *prq = cls;
struct GSF_PendingRequest *pr = value;
@@ -829,88 +800,81 @@
return GNUNET_YES;
#if DEBUG_FS
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Matched result (type %u) for query `%s' with pending request\n",
- (unsigned int) prq->type,
- GNUNET_h2s (key));
-#endif
+ "Matched result (type %u) for query `%s' with pending request\n",
+ (unsigned int) prq->type, GNUNET_h2s (key));
+#endif
GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# replies received and matched"),
- 1,
- GNUNET_NO);
+ gettext_noop ("# replies received and matched"),
+ 1, GNUNET_NO);
prq->eval = GNUNET_BLOCK_evaluate (GSF_block_ctx,
- prq->type,
- key,
- &pr->bf,
- pr->mingle,
- &pr->public_data.namespace,
- (prq->type == GNUNET_BLOCK_TYPE_FS_SBLOCK)
? sizeof (GNUNET_HashCode) : 0,
- prq->data,
- prq->size);
+ prq->type,
+ key,
+ &pr->bf,
+ pr->mingle,
+ &pr->public_data.namespace,
+ (prq->type ==
+ GNUNET_BLOCK_TYPE_FS_SBLOCK) ?
+ sizeof (GNUNET_HashCode) : 0, prq->data,
+ prq->size);
switch (prq->eval)
- {
- case GNUNET_BLOCK_EVALUATION_OK_MORE:
- update_request_performance_data (prq, pr);
- break;
- case GNUNET_BLOCK_EVALUATION_OK_LAST:
- /* short cut: stop processing early, no BF-update, etc. */
- update_request_performance_data (prq, pr);
- GNUNET_LOAD_update (GSF_rt_entry_lifetime,
- GNUNET_TIME_absolute_get_duration
(pr->public_data.start_time).rel_value);
- /* pass on to other peers / local clients */
- pr->rh (pr->rh_cls,
- prq->eval,
- pr,
- prq->anonymity_level,
- prq->expiration,
- prq->type,
- prq->data, prq->size);
- return GNUNET_YES;
- case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE:
- GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# duplicate replies discarded
(bloomfilter)"),
- 1,
- GNUNET_NO);
+ {
+ case GNUNET_BLOCK_EVALUATION_OK_MORE:
+ update_request_performance_data (prq, pr);
+ break;
+ case GNUNET_BLOCK_EVALUATION_OK_LAST:
+ /* short cut: stop processing early, no BF-update, etc. */
+ update_request_performance_data (prq, pr);
+ GNUNET_LOAD_update (GSF_rt_entry_lifetime,
+ GNUNET_TIME_absolute_get_duration (pr->
+
public_data.start_time).rel_value);
+ /* pass on to other peers / local clients */
+ pr->rh (pr->rh_cls,
+ prq->eval,
+ pr,
+ prq->anonymity_level,
+ prq->expiration, prq->type, prq->data, prq->size);
+ return GNUNET_YES;
+ case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE:
+ GNUNET_STATISTICS_update (GSF_stats,
+ gettext_noop
+ ("# duplicate replies discarded (bloomfilter)"),
+ 1, GNUNET_NO);
#if DEBUG_FS && 0
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Duplicate response `%s', discarding.\n",
- GNUNET_h2s (&mhash));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Duplicate response `%s', discarding.\n", GNUNET_h2s (&mhash));
#endif
- return GNUNET_YES; /* duplicate */
- case GNUNET_BLOCK_EVALUATION_RESULT_INVALID:
- return GNUNET_YES; /* wrong namespace */
- case GNUNET_BLOCK_EVALUATION_REQUEST_VALID:
- GNUNET_break (0);
- return GNUNET_YES;
- case GNUNET_BLOCK_EVALUATION_REQUEST_INVALID:
- GNUNET_break (0);
- return GNUNET_YES;
- case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED:
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Unsupported block type %u\n"),
- prq->type);
- return GNUNET_NO;
- }
+ return GNUNET_YES; /* duplicate */
+ case GNUNET_BLOCK_EVALUATION_RESULT_INVALID:
+ return GNUNET_YES; /* wrong namespace */
+ case GNUNET_BLOCK_EVALUATION_REQUEST_VALID:
+ GNUNET_break (0);
+ return GNUNET_YES;
+ case GNUNET_BLOCK_EVALUATION_REQUEST_INVALID:
+ GNUNET_break (0);
+ return GNUNET_YES;
+ case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED:
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Unsupported block type %u\n"), prq->type);
+ return GNUNET_NO;
+ }
/* update bloomfilter */
- GNUNET_CRYPTO_hash (prq->data,
- prq->size,
- &chash);
+ GNUNET_CRYPTO_hash (prq->data, prq->size, &chash);
GSF_pending_request_update_ (pr, &chash, 1);
if (NULL == prq->sender)
- {
+ {
#if DEBUG_FS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Found result for query `%s' in local datastore\n",
- GNUNET_h2s (key));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Found result for query `%s' in local datastore\n",
+ GNUNET_h2s (key));
#endif
- GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# results found locally"),
- 1,
- GNUNET_NO);
- }
+ GNUNET_STATISTICS_update (GSF_stats,
+ gettext_noop ("# results found locally"),
+ 1, GNUNET_NO);
+ }
else
- {
- GSF_dht_lookup_ (pr);
- }
+ {
+ GSF_dht_lookup_ (pr);
+ }
prq->priority += pr->public_data.original_priority;
pr->public_data.priority = 0;
pr->public_data.original_priority = 0;
@@ -918,12 +882,10 @@
prq->request_found = GNUNET_YES;
/* finally, pass on to other peer / local client */
pr->rh (pr->rh_cls,
- prq->eval,
- pr,
- prq->anonymity_level,
- prq->expiration,
- prq->type,
- prq->data, prq->size);
+ prq->eval,
+ pr,
+ prq->anonymity_level,
+ prq->expiration, prq->type, prq->data, prq->size);
return GNUNET_YES;
}
@@ -960,52 +922,50 @@
* @param success GNUNET_SYSERR on failure
* @param msg NULL on success, otherwise an error message
*/
-static void
-put_migration_continuation (void *cls,
- int success,
- const char *msg)
+static void
+put_migration_continuation (void *cls, int success, const char *msg)
{
struct PutMigrationContext *pmc = cls;
struct GNUNET_TIME_Relative delay;
- struct GNUNET_TIME_Relative block_time;
+ struct GNUNET_TIME_Relative block_time;
struct GSF_ConnectedPeer *cp;
struct GSF_PeerPerformanceData *ppd;
-
+
delay = GNUNET_TIME_absolute_get_duration (pmc->start);
cp = GSF_peer_get_ (&pmc->origin);
- if ( (GNUNET_OK != success) &&
- (GNUNET_NO == pmc->requested) )
+ if ((GNUNET_OK != success) && (GNUNET_NO == pmc->requested))
+ {
+ /* block migration for a bit... */
+ if (NULL != cp)
{
- /* block migration for a bit... */
- if (NULL != cp)
- {
- ppd = GSF_get_peer_performance_data_ (cp);
- ppd->migration_duplication++;
- block_time = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
- 5 *
ppd->migration_duplication +
- GNUNET_CRYPTO_random_u32
(GNUNET_CRYPTO_QUALITY_WEAK, 5));
- GSF_block_peer_migration_ (cp, block_time);
- }
+ ppd = GSF_get_peer_performance_data_ (cp);
+ ppd->migration_duplication++;
+ block_time = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
+ 5 *
+ ppd->migration_duplication +
+ GNUNET_CRYPTO_random_u32
+ (GNUNET_CRYPTO_QUALITY_WEAK,
+ 5));
+ GSF_block_peer_migration_ (cp, block_time);
}
+ }
else
+ {
+ if (NULL != cp)
{
- if (NULL != cp)
- {
- ppd = GSF_get_peer_performance_data_ (cp);
- ppd->migration_duplication = 0; /* reset counter */
- }
+ ppd = GSF_get_peer_performance_data_ (cp);
+ ppd->migration_duplication = 0; /* reset counter */
}
+ }
GNUNET_free (pmc);
/* FIXME: should we really update the load value on failure? */
if (NULL != datastore_put_load)
- GNUNET_LOAD_update (datastore_put_load,
- delay.rel_value);
+ GNUNET_LOAD_update (datastore_put_load, delay.rel_value);
if (GNUNET_OK == success)
return;
GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# Datastore `PUT' failures"),
- 1,
- GNUNET_NO);
+ gettext_noop ("# Datastore `PUT' failures"),
+ 1, GNUNET_NO);
}
@@ -1025,14 +985,14 @@
if (NULL == datastore_put_load)
return GNUNET_NO;
if (GNUNET_LOAD_get_average (datastore_put_load) < 50)
- return GNUNET_NO; /* very fast */
+ return GNUNET_NO; /* very fast */
ld = GNUNET_LOAD_get_load (datastore_put_load);
if (ld < 2.0 * (1 + priority))
return GNUNET_NO;
GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# storage requests dropped due to
high load"),
- 1,
- GNUNET_NO);
+ gettext_noop
+ ("# storage requests dropped due to high load"), 1,
+ GNUNET_NO);
return GNUNET_YES;
}
@@ -1054,54 +1014,49 @@
*/
static void
handle_dht_reply (void *cls,
- struct GNUNET_TIME_Absolute exp,
- const GNUNET_HashCode *key,
- const struct GNUNET_PeerIdentity * const *get_path,
- const struct GNUNET_PeerIdentity * const *put_path,
- enum GNUNET_BLOCK_Type type,
- size_t size,
- const void *data)
+ struct GNUNET_TIME_Absolute exp,
+ const GNUNET_HashCode * key,
+ const struct GNUNET_PeerIdentity *const *get_path,
+ const struct GNUNET_PeerIdentity *const *put_path,
+ enum GNUNET_BLOCK_Type type, size_t size, const void *data)
{
struct GSF_PendingRequest *pr = cls;
struct ProcessReplyClosure prq;
struct PutMigrationContext *pmc;
GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# Replies received from DHT"),
- 1,
- GNUNET_NO);
+ gettext_noop ("# Replies received from DHT"),
+ 1, GNUNET_NO);
memset (&prq, 0, sizeof (prq));
prq.data = data;
prq.expiration = exp;
- prq.size = size;
+ prq.size = size;
prq.type = type;
process_reply (&prq, key, pr);
- if ( (GNUNET_YES == active_to_migration) &&
- (GNUNET_NO == test_put_load_too_high (prq.priority)) )
- {
+ if ((GNUNET_YES == active_to_migration) &&
+ (GNUNET_NO == test_put_load_too_high (prq.priority)))
+ {
#if DEBUG_FS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Replicating result for query `%s' with priority %u\n",
- GNUNET_h2s (key),
- prq.priority);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Replicating result for query `%s' with priority %u\n",
+ GNUNET_h2s (key), prq.priority);
#endif
- pmc = GNUNET_malloc (sizeof (struct PutMigrationContext));
- pmc->start = GNUNET_TIME_absolute_get ();
- pmc->requested = GNUNET_YES;
- if (NULL ==
- GNUNET_DATASTORE_put (GSF_dsh,
- 0, key, size, data,
- type, prq.priority, 1 /* anonymity */,
- 0 /* replication */,
- exp,
- 1 + prq.priority, MAX_DATASTORE_QUEUE,
- GNUNET_CONSTANTS_SERVICE_TIMEOUT,
- &put_migration_continuation,
- pmc))
- {
- put_migration_continuation (pmc, GNUNET_NO, NULL);
- }
+ pmc = GNUNET_malloc (sizeof (struct PutMigrationContext));
+ pmc->start = GNUNET_TIME_absolute_get ();
+ pmc->requested = GNUNET_YES;
+ if (NULL ==
+ GNUNET_DATASTORE_put (GSF_dsh,
+ 0, key, size, data,
+ type, prq.priority, 1 /* anonymity */ ,
+ 0 /* replication */ ,
+ exp,
+ 1 + prq.priority, MAX_DATASTORE_QUEUE,
+ GNUNET_CONSTANTS_SERVICE_TIMEOUT,
+ &put_migration_continuation, pmc))
+ {
+ put_migration_continuation (pmc, GNUNET_NO, NULL);
}
+ }
}
@@ -1121,38 +1076,34 @@
if (0 != pr->public_data.anonymity_level)
return;
if (NULL != pr->gh)
- {
- GNUNET_DHT_get_stop (pr->gh);
- pr->gh = NULL;
- }
+ {
+ GNUNET_DHT_get_stop (pr->gh);
+ pr->gh = NULL;
+ }
xquery = NULL;
xquery_size = 0;
if (GNUNET_BLOCK_TYPE_FS_SBLOCK == pr->public_data.type)
- {
- xquery = buf;
- memcpy (buf, &pr->public_data.namespace, sizeof (GNUNET_HashCode));
- xquery_size = sizeof (GNUNET_HashCode);
- }
+ {
+ xquery = buf;
+ memcpy (buf, &pr->public_data.namespace, sizeof (GNUNET_HashCode));
+ xquery_size = sizeof (GNUNET_HashCode);
+ }
if (0 != (pr->public_data.options & GSF_PRO_FORWARD_ONLY))
- {
- GNUNET_assert (0 != pr->sender_pid);
- GNUNET_PEER_resolve (pr->sender_pid,
- &pi);
- memcpy (&buf[xquery_size], &pi, sizeof (struct GNUNET_PeerIdentity));
- xquery_size += sizeof (struct GNUNET_PeerIdentity);
- }
+ {
+ GNUNET_assert (0 != pr->sender_pid);
+ GNUNET_PEER_resolve (pr->sender_pid, &pi);
+ memcpy (&buf[xquery_size], &pi, sizeof (struct GNUNET_PeerIdentity));
+ xquery_size += sizeof (struct GNUNET_PeerIdentity);
+ }
pr->gh = GNUNET_DHT_get_start (GSF_dht,
- GNUNET_TIME_UNIT_FOREVER_REL,
- pr->public_data.type,
- &pr->public_data.query,
- DEFAULT_GET_REPLICATION,
- GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
- pr->bf,
- pr->mingle,
- xquery,
- xquery_size,
- &handle_dht_reply,
- pr);
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ pr->public_data.type,
+ &pr->public_data.query,
+ DEFAULT_GET_REPLICATION,
+ GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
+ pr->bf,
+ pr->mingle,
+ xquery, xquery_size, &handle_dht_reply, pr);
}
@@ -1163,17 +1114,17 @@
* @param tc task context
*/
static void
-warn_delay_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+warn_delay_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GSF_PendingRequest *pr = cls;
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Datastore lookup already took %llu ms!\n"),
- (unsigned long long) GNUNET_TIME_absolute_get_duration
(pr->qe_start).rel_value);
- pr->warn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
- &warn_delay_task,
- pr);
+ _("Datastore lookup already took %llu ms!\n"),
+ (unsigned long long)
+ GNUNET_TIME_absolute_get_duration (pr->qe_start).rel_value);
+ pr->warn_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, &warn_delay_task,
+ pr);
}
@@ -1184,17 +1135,17 @@
* @param tc task context
*/
static void
-odc_warn_delay_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+odc_warn_delay_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GSF_PendingRequest *pr = cls;
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("On-demand lookup already took %llu ms!\n"),
- (unsigned long long) GNUNET_TIME_absolute_get_duration
(pr->qe_start).rel_value);
- pr->warn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
- &odc_warn_delay_task,
- pr);
+ _("On-demand lookup already took %llu ms!\n"),
+ (unsigned long long)
+ GNUNET_TIME_absolute_get_duration (pr->qe_start).rel_value);
+ pr->warn_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
+ &odc_warn_delay_task, pr);
}
@@ -1217,14 +1168,13 @@
*/
static void
process_local_reply (void *cls,
- const GNUNET_HashCode *key,
- size_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- struct GNUNET_TIME_Absolute expiration,
- uint64_t uid)
+ const GNUNET_HashCode * key,
+ size_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute expiration, uint64_t uid)
{
struct GSF_PendingRequest *pr = cls;
GSF_LocalLookupContinuation cont;
@@ -1235,236 +1185,228 @@
GNUNET_SCHEDULER_cancel (pr->warn_task);
pr->warn_task = GNUNET_SCHEDULER_NO_TASK;
if (NULL != pr->qe)
+ {
+ pr->qe = NULL;
+ if (NULL == key)
{
- pr->qe = NULL;
- if (NULL == key)
- {
- GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# Datastore lookups
concluded (no results)"),
- 1,
- GNUNET_NO);
- }
- if (GNUNET_NO == pr->have_first_uid)
- {
- pr->first_uid = uid;
- pr->have_first_uid = 1;
- }
- else
- {
- if ( (uid == pr->first_uid) && (key != NULL) )
- {
- GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# Datastore lookups
concluded (seen all)"),
- 1,
- GNUNET_NO);
- key = NULL; /* all replies seen! */
- }
- pr->have_first_uid++;
- if ( (pr->have_first_uid > MAX_RESULTS) && (key != NULL) )
- {
- GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# Datastore lookups
aborted (more than MAX_RESULTS)"),
- 1,
- GNUNET_NO);
- key = NULL; /* all replies seen! */
- }
- }
+ GNUNET_STATISTICS_update (GSF_stats,
+ gettext_noop
+ ("# Datastore lookups concluded (no results)"),
+ 1, GNUNET_NO);
}
- if (NULL == key)
+ if (GNUNET_NO == pr->have_first_uid)
{
+ pr->first_uid = uid;
+ pr->have_first_uid = 1;
+ }
+ else
+ {
+ if ((uid == pr->first_uid) && (key != NULL))
+ {
+ GNUNET_STATISTICS_update (GSF_stats,
+ gettext_noop
+ ("# Datastore lookups concluded (seen all)"),
+ 1, GNUNET_NO);
+ key = NULL; /* all replies seen! */
+ }
+ pr->have_first_uid++;
+ if ((pr->have_first_uid > MAX_RESULTS) && (key != NULL))
+ {
+ GNUNET_STATISTICS_update (GSF_stats,
+ gettext_noop
+ ("# Datastore lookups aborted (more than
MAX_RESULTS)"),
+ 1, GNUNET_NO);
+ key = NULL; /* all replies seen! */
+ }
+ }
+ }
+ if (NULL == key)
+ {
#if DEBUG_FS > 1
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "No further local responses available.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "No further local responses available.\n");
#endif
- if ( (pr->public_data.type == GNUNET_BLOCK_TYPE_FS_DBLOCK) ||
- (pr->public_data.type == GNUNET_BLOCK_TYPE_FS_IBLOCK) )
- GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# requested DBLOCK or IBLOCK
not found"),
- 1,
- GNUNET_NO);
- goto check_error_and_continue;
- }
+ if ((pr->public_data.type == GNUNET_BLOCK_TYPE_FS_DBLOCK) ||
+ (pr->public_data.type == GNUNET_BLOCK_TYPE_FS_IBLOCK))
+ GNUNET_STATISTICS_update (GSF_stats,
+ gettext_noop
+ ("# requested DBLOCK or IBLOCK not found"), 1,
+ GNUNET_NO);
+ goto check_error_and_continue;
+ }
#if DEBUG_FS
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received reply for `%s' of type %d with UID %llu from
datastore.\n",
- GNUNET_h2s (key),
- type,
- (unsigned long long) uid);
+ "Received reply for `%s' of type %d with UID %llu from
datastore.\n",
+ GNUNET_h2s (key), type, (unsigned long long) uid);
#endif
if (type == GNUNET_BLOCK_TYPE_FS_ONDEMAND)
- {
+ {
#if DEBUG_FS > 1
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Found ONDEMAND block, performing on-demand encoding\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Found ONDEMAND block, performing on-demand encoding\n");
#endif
+ GNUNET_STATISTICS_update (GSF_stats,
+ gettext_noop
+ ("# on-demand blocks matched requests"), 1,
+ GNUNET_NO);
+ pr->qe_start = GNUNET_TIME_absolute_get ();
+ pr->warn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
+ &odc_warn_delay_task, pr);
+ if (GNUNET_OK ==
+ GNUNET_FS_handle_on_demand_block (key, size, data, type, priority,
+ anonymity, expiration, uid,
+ &process_local_reply, pr))
+ {
GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# on-demand blocks matched
requests"),
- 1,
- GNUNET_NO);
- pr->qe_start = GNUNET_TIME_absolute_get ();
- pr->warn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
- &odc_warn_delay_task,
- pr);
- if (GNUNET_OK ==
- GNUNET_FS_handle_on_demand_block (key, size, data, type, priority,
- anonymity, expiration, uid,
- &process_local_reply,
- pr))
- {
- GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# on-demand lookups
performed successfully"),
- 1,
- GNUNET_NO);
- return; /* we're done */
- }
+ gettext_noop
+ ("# on-demand lookups performed successfully"),
+ 1, GNUNET_NO);
+ return; /* we're done */
+ }
+ GNUNET_STATISTICS_update (GSF_stats,
+ gettext_noop ("# on-demand lookups failed"),
+ 1, GNUNET_NO);
+ GNUNET_SCHEDULER_cancel (pr->warn_task);
+ pr->warn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
+ &warn_delay_task, pr);
+ pr->qe = GNUNET_DATASTORE_get_key (GSF_dsh,
+ pr->local_result_offset - 1,
+ &pr->public_data.query,
+ pr->public_data.type ==
+ GNUNET_BLOCK_TYPE_FS_DBLOCK ?
+ GNUNET_BLOCK_TYPE_ANY : pr->
+ public_data.type,
+ (0 !=
+ (GSF_PRO_PRIORITY_UNLIMITED &
+ pr->public_data.
+ options)) ? UINT_MAX : 1
+ /* queue priority */ ,
+ (0 !=
+ (GSF_PRO_PRIORITY_UNLIMITED &
+ pr->public_data.options)) ? UINT_MAX :
+ 1
+ /* max queue size */ ,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &process_local_reply, pr);
+ if (NULL != pr->qe)
+ {
GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# on-demand lookups failed"),
- 1,
- GNUNET_NO);
- GNUNET_SCHEDULER_cancel (pr->warn_task);
- pr->warn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
- &warn_delay_task,
- pr);
- pr->qe = GNUNET_DATASTORE_get_key (GSF_dsh,
- pr->local_result_offset - 1,
- &pr->public_data.query,
- pr->public_data.type ==
GNUNET_BLOCK_TYPE_FS_DBLOCK
- ? GNUNET_BLOCK_TYPE_ANY
- : pr->public_data.type,
- (0 != (GSF_PRO_PRIORITY_UNLIMITED &
pr->public_data.options))
- ? UINT_MAX
- : 1 /* queue priority */,
- (0 != (GSF_PRO_PRIORITY_UNLIMITED &
pr->public_data.options))
- ? UINT_MAX
- : 1 /* max queue size */,
- GNUNET_TIME_UNIT_FOREVER_REL,
- &process_local_reply,
- pr);
- if (NULL != pr->qe)
- {
- GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# Datastore lookups
concluded (error queueing)"),
- 1,
- GNUNET_NO);
- return; /* we're done */
- }
- goto check_error_and_continue;
+ gettext_noop
+ ("# Datastore lookups concluded (error
queueing)"),
+ 1, GNUNET_NO);
+ return; /* we're done */
}
+ goto check_error_and_continue;
+ }
old_rf = pr->public_data.results_found;
memset (&prq, 0, sizeof (prq));
prq.data = data;
prq.expiration = expiration;
- prq.size = size;
- if (GNUNET_OK !=
- GNUNET_BLOCK_get_key (GSF_block_ctx,
- type,
- data,
- size,
- &query))
+ prq.size = size;
+ if (GNUNET_OK !=
+ GNUNET_BLOCK_get_key (GSF_block_ctx, type, data, size, &query))
+ {
+ GNUNET_break (0);
+ GNUNET_DATASTORE_remove (GSF_dsh,
+ key,
+ size, data,
+ -1, -1, GNUNET_TIME_UNIT_FOREVER_REL, NULL, NULL);
+ pr->qe_start = GNUNET_TIME_absolute_get ();
+ pr->warn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
+ &warn_delay_task, pr);
+ pr->qe = GNUNET_DATASTORE_get_key (GSF_dsh,
+ pr->local_result_offset - 1,
+ &pr->public_data.query,
+ pr->public_data.type ==
+ GNUNET_BLOCK_TYPE_FS_DBLOCK ?
+ GNUNET_BLOCK_TYPE_ANY : pr->
+ public_data.type,
+ (0 !=
+ (GSF_PRO_PRIORITY_UNLIMITED &
+ pr->public_data.
+ options)) ? UINT_MAX : 1
+ /* queue priority */ ,
+ (0 !=
+ (GSF_PRO_PRIORITY_UNLIMITED &
+ pr->public_data.options)) ? UINT_MAX :
+ 1
+ /* max queue size */ ,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &process_local_reply, pr);
+ if (pr->qe == NULL)
{
- GNUNET_break (0);
- GNUNET_DATASTORE_remove (GSF_dsh,
- key,
- size, data,
- -1, -1,
- GNUNET_TIME_UNIT_FOREVER_REL,
- NULL, NULL);
- pr->qe_start = GNUNET_TIME_absolute_get ();
- pr->warn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
- &warn_delay_task,
- pr);
- pr->qe = GNUNET_DATASTORE_get_key (GSF_dsh,
- pr->local_result_offset - 1,
- &pr->public_data.query,
- pr->public_data.type ==
GNUNET_BLOCK_TYPE_FS_DBLOCK
- ? GNUNET_BLOCK_TYPE_ANY
- : pr->public_data.type,
- (0 != (GSF_PRO_PRIORITY_UNLIMITED &
pr->public_data.options))
- ? UINT_MAX
- : 1 /* queue priority */,
- (0 != (GSF_PRO_PRIORITY_UNLIMITED &
pr->public_data.options))
- ? UINT_MAX
- : 1 /* max queue size */,
- GNUNET_TIME_UNIT_FOREVER_REL,
- &process_local_reply,
- pr);
- if (pr->qe == NULL)
- {
- GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# Datastore lookups
concluded (error queueing)"),
- 1,
- GNUNET_NO);
- goto check_error_and_continue;
- }
- return;
+ GNUNET_STATISTICS_update (GSF_stats,
+ gettext_noop
+ ("# Datastore lookups concluded (error
queueing)"),
+ 1, GNUNET_NO);
+ goto check_error_and_continue;
}
+ return;
+ }
prq.type = type;
- prq.priority = priority;
+ prq.priority = priority;
prq.request_found = GNUNET_NO;
prq.anonymity_level = anonymity;
- if ( (old_rf == 0) &&
- (pr->public_data.results_found == 0) )
+ if ((old_rf == 0) && (pr->public_data.results_found == 0))
GSF_update_datastore_delay_ (pr->public_data.start_time);
process_reply (&prq, key, pr);
pr->local_result = prq.eval;
if (prq.eval == GNUNET_BLOCK_EVALUATION_OK_LAST)
- {
- GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# Datastore lookups concluded
(found ultimate result)"),
- 1,
- GNUNET_NO);
- goto check_error_and_continue;
- }
- if ( (0 == (GSF_PRO_PRIORITY_UNLIMITED & pr->public_data.options)) &&
- ( (GNUNET_YES == GSF_test_get_load_too_high_ (0)) ||
- (pr->public_data.results_found > 5 + 2 * pr->public_data.priority) ) )
- {
+ {
+ GNUNET_STATISTICS_update (GSF_stats,
+ gettext_noop
+ ("# Datastore lookups concluded (found ultimate
result)"),
+ 1, GNUNET_NO);
+ goto check_error_and_continue;
+ }
+ if ((0 == (GSF_PRO_PRIORITY_UNLIMITED & pr->public_data.options)) &&
+ ((GNUNET_YES == GSF_test_get_load_too_high_ (0)) ||
+ (pr->public_data.results_found > 5 + 2 * pr->public_data.priority)))
+ {
#if DEBUG_FS > 2
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Load too high, done with request\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Load too high, done with request\n");
#endif
- GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# Datastore lookups concluded
(load too high)"),
- 1,
- GNUNET_NO);
- goto check_error_and_continue;
- }
+ GNUNET_STATISTICS_update (GSF_stats,
+ gettext_noop
+ ("# Datastore lookups concluded (load too
high)"),
+ 1, GNUNET_NO);
+ goto check_error_and_continue;
+ }
pr->qe_start = GNUNET_TIME_absolute_get ();
pr->warn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
- &warn_delay_task,
- pr);
+ &warn_delay_task, pr);
pr->qe = GNUNET_DATASTORE_get_key (GSF_dsh,
- pr->local_result_offset++,
- &pr->public_data.query,
- pr->public_data.type ==
GNUNET_BLOCK_TYPE_FS_DBLOCK
- ? GNUNET_BLOCK_TYPE_ANY
- : pr->public_data.type,
- (0 != (GSF_PRO_PRIORITY_UNLIMITED &
pr->public_data.options))
- ? UINT_MAX
- : 1 /* queue priority */,
- (0 != (GSF_PRO_PRIORITY_UNLIMITED &
pr->public_data.options))
- ? UINT_MAX
- : 1 /* max queue size */,
- GNUNET_TIME_UNIT_FOREVER_REL,
- &process_local_reply,
- pr);
+ pr->local_result_offset++,
+ &pr->public_data.query,
+ pr->public_data.type ==
+ GNUNET_BLOCK_TYPE_FS_DBLOCK ?
+ GNUNET_BLOCK_TYPE_ANY : pr->
+ public_data.type,
+ (0 !=
+ (GSF_PRO_PRIORITY_UNLIMITED &
+ pr->public_data.options)) ? UINT_MAX : 1
+ /* queue priority */ ,
+ (0 !=
+ (GSF_PRO_PRIORITY_UNLIMITED &
+ pr->public_data.options)) ? UINT_MAX : 1
+ /* max queue size */ ,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &process_local_reply, pr);
/* check if we successfully queued another datastore request;
- if so, return, otherwise call our continuation (if we have
- any) */
- check_error_and_continue:
+ * if so, return, otherwise call our continuation (if we have
+ * any) */
+check_error_and_continue:
if (NULL != pr->qe)
return;
if (GNUNET_SCHEDULER_NO_TASK != pr->warn_task)
- {
- GNUNET_SCHEDULER_cancel (pr->warn_task);
- pr->warn_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (pr->warn_task);
+ pr->warn_task = GNUNET_SCHEDULER_NO_TASK;
+ }
if (NULL == (cont = pr->llc_cont))
- return; /* no continuation */
+ return; /* no continuation */
pr->llc_cont = NULL;
- cont (pr->llc_cont_cls,
- pr,
- pr->local_result);
+ cont (pr->llc_cont_cls, pr, pr->local_result);
}
@@ -1477,8 +1419,7 @@
*/
void
GSF_local_lookup_ (struct GSF_PendingRequest *pr,
- GSF_LocalLookupContinuation cont,
- void *cont_cls)
+ GSF_LocalLookupContinuation cont, void *cont_cls)
{
GNUNET_assert (NULL == pr->gh);
GNUNET_assert (NULL == pr->llc_cont);
@@ -1486,41 +1427,41 @@
pr->llc_cont_cls = cont_cls;
pr->qe_start = GNUNET_TIME_absolute_get ();
pr->warn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
- &warn_delay_task,
- pr);
+ &warn_delay_task, pr);
GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# Datastore lookups initiated"),
- 1,
- GNUNET_NO);
+ gettext_noop ("# Datastore lookups initiated"),
+ 1, GNUNET_NO);
pr->qe = GNUNET_DATASTORE_get_key (GSF_dsh,
- pr->local_result_offset++,
- &pr->public_data.query,
- pr->public_data.type ==
GNUNET_BLOCK_TYPE_FS_DBLOCK
- ? GNUNET_BLOCK_TYPE_ANY
- : pr->public_data.type,
- (0 != (GSF_PRO_PRIORITY_UNLIMITED &
pr->public_data.options))
- ? UINT_MAX
- : 1 /* queue priority */,
- (0 != (GSF_PRO_PRIORITY_UNLIMITED &
pr->public_data.options))
- ? UINT_MAX
- : 1 /* max queue size */,
- GNUNET_TIME_UNIT_FOREVER_REL,
- &process_local_reply,
- pr);
+ pr->local_result_offset++,
+ &pr->public_data.query,
+ pr->public_data.type ==
+ GNUNET_BLOCK_TYPE_FS_DBLOCK ?
+ GNUNET_BLOCK_TYPE_ANY : pr->
+ public_data.type,
+ (0 !=
+ (GSF_PRO_PRIORITY_UNLIMITED &
+ pr->public_data.options)) ? UINT_MAX : 1
+ /* queue priority */ ,
+ (0 !=
+ (GSF_PRO_PRIORITY_UNLIMITED &
+ pr->public_data.options)) ? UINT_MAX : 1
+ /* max queue size */ ,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &process_local_reply, pr);
if (NULL != pr->qe)
- {
- GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# Datastore lookups concluded
(error queueing)"),
- 1,
- GNUNET_NO);
-
- return;
- }
+ {
+ GNUNET_STATISTICS_update (GSF_stats,
+ gettext_noop
+ ("# Datastore lookups concluded (error
queueing)"),
+ 1, GNUNET_NO);
+
+ return;
+ }
GNUNET_SCHEDULER_cancel (pr->warn_task);
pr->warn_task = GNUNET_SCHEDULER_NO_TASK;
pr->llc_cont = NULL;
if (NULL != cont)
- cont (cont_cls, pr, pr->local_result);
+ cont (cont_cls, pr, pr->local_result);
}
@@ -1540,7 +1481,7 @@
*/
int
GSF_handle_p2p_content_ (struct GSF_ConnectedPeer *cp,
- const struct GNUNET_MessageHeader *message)
+ const struct GNUNET_MessageHeader *message)
{
const struct PutMessage *put;
uint16_t msize;
@@ -1549,38 +1490,33 @@
struct GNUNET_TIME_Absolute expiration;
GNUNET_HashCode query;
struct ProcessReplyClosure prq;
- struct GNUNET_TIME_Relative block_time;
+ struct GNUNET_TIME_Relative block_time;
double putl;
struct PutMigrationContext *pmc;
msize = ntohs (message->size);
if (msize < sizeof (struct PutMessage))
- {
- GNUNET_break_op(0);
- return GNUNET_SYSERR;
- }
- put = (const struct PutMessage*) message;
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ put = (const struct PutMessage *) message;
dsize = msize - sizeof (struct PutMessage);
type = ntohl (put->type);
expiration = GNUNET_TIME_absolute_ntoh (put->expiration);
if (type == GNUNET_BLOCK_TYPE_FS_ONDEMAND)
return GNUNET_SYSERR;
if (GNUNET_OK !=
- GNUNET_BLOCK_get_key (GSF_block_ctx,
- type,
- &put[1],
- dsize,
- &query))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
+ GNUNET_BLOCK_get_key (GSF_block_ctx, type, &put[1], dsize, &query))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# GAP PUT messages received"),
- 1,
- GNUNET_NO);
+ gettext_noop ("# GAP PUT messages received"),
+ 1, GNUNET_NO);
/* now, lookup 'query' */
- prq.data = (const void*) &put[1];
+ prq.data = (const void *) &put[1];
if (NULL != cp)
prq.sender = cp;
else
@@ -1592,66 +1528,66 @@
prq.anonymity_level = UINT32_MAX;
prq.request_found = GNUNET_NO;
GNUNET_CONTAINER_multihashmap_get_multiple (pr_map,
- &query,
- &process_reply,
- &prq);
+ &query, &process_reply, &prq);
if (NULL != cp)
- {
- GSF_connected_peer_change_preference_ (cp, CONTENT_BANDWIDTH_VALUE +
1000 * prq.priority);
- GSF_get_peer_performance_data_ (cp)->trust += prq.priority;
- }
- if ( (GNUNET_YES == active_to_migration) &&
- (GNUNET_NO == test_put_load_too_high (prq.priority)) )
- {
+ {
+ GSF_connected_peer_change_preference_ (cp,
+ CONTENT_BANDWIDTH_VALUE +
+ 1000 * prq.priority);
+ GSF_get_peer_performance_data_ (cp)->trust += prq.priority;
+ }
+ if ((GNUNET_YES == active_to_migration) &&
+ (GNUNET_NO == test_put_load_too_high (prq.priority)))
+ {
#if DEBUG_FS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Replicating result for query `%s' with priority %u\n",
- GNUNET_h2s (&query),
- prq.priority);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Replicating result for query `%s' with priority %u\n",
+ GNUNET_h2s (&query), prq.priority);
#endif
- pmc = GNUNET_malloc (sizeof (struct PutMigrationContext));
- pmc->start = GNUNET_TIME_absolute_get ();
- pmc->requested = prq.request_found;
- GNUNET_assert (0 != GSF_get_peer_performance_data_ (cp)->pid);
- GNUNET_PEER_resolve (GSF_get_peer_performance_data_ (cp)->pid,
- &pmc->origin);
- if (NULL ==
- GNUNET_DATASTORE_put (GSF_dsh,
- 0, &query, dsize, &put[1],
- type, prq.priority, 1 /* anonymity */,
- 0 /* replication */,
- expiration,
- 1 + prq.priority, MAX_DATASTORE_QUEUE,
- GNUNET_CONSTANTS_SERVICE_TIMEOUT,
- &put_migration_continuation,
- pmc))
- {
- put_migration_continuation (pmc, GNUNET_NO, NULL);
- }
+ pmc = GNUNET_malloc (sizeof (struct PutMigrationContext));
+ pmc->start = GNUNET_TIME_absolute_get ();
+ pmc->requested = prq.request_found;
+ GNUNET_assert (0 != GSF_get_peer_performance_data_ (cp)->pid);
+ GNUNET_PEER_resolve (GSF_get_peer_performance_data_ (cp)->pid,
+ &pmc->origin);
+ if (NULL ==
+ GNUNET_DATASTORE_put (GSF_dsh,
+ 0, &query, dsize, &put[1],
+ type, prq.priority, 1 /* anonymity */ ,
+ 0 /* replication */ ,
+ expiration,
+ 1 + prq.priority, MAX_DATASTORE_QUEUE,
+ GNUNET_CONSTANTS_SERVICE_TIMEOUT,
+ &put_migration_continuation, pmc))
+ {
+ put_migration_continuation (pmc, GNUNET_NO, NULL);
}
+ }
else
- {
+ {
#if DEBUG_FS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Choosing not to keep content `%s' (%d/%d)\n",
- GNUNET_h2s (&query),
- active_to_migration,
- test_put_load_too_high (prq.priority));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Choosing not to keep content `%s' (%d/%d)\n",
+ GNUNET_h2s (&query),
+ active_to_migration, test_put_load_too_high (prq.priority));
#endif
- }
+ }
putl = GNUNET_LOAD_get_load (datastore_put_load);
- if ( (NULL != (cp = prq.sender)) &&
- (GNUNET_NO == prq.request_found) &&
- ( (GNUNET_YES != active_to_migration) ||
- (putl > 2.5 * (1 + prq.priority)) ) )
- {
- if (GNUNET_YES != active_to_migration)
- putl = 1.0 + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 5);
- block_time = GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_MILLISECONDS,
- 5000 +
GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
-
(unsigned int) (60000 * putl * putl)));
- GSF_block_peer_migration_ (cp, block_time);
- }
+ if ((NULL != (cp = prq.sender)) &&
+ (GNUNET_NO == prq.request_found) &&
+ ((GNUNET_YES != active_to_migration) ||
+ (putl > 2.5 * (1 + prq.priority))))
+ {
+ if (GNUNET_YES != active_to_migration)
+ putl = 1.0 + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 5);
+ block_time = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
+ 5000 +
+ GNUNET_CRYPTO_random_u32
+ (GNUNET_CRYPTO_QUALITY_WEAK,
+ (unsigned int) (60000 * putl *
+ putl)));
+ GSF_block_peer_migration_ (cp, block_time);
+ }
return GNUNET_OK;
}
@@ -1664,20 +1600,22 @@
{
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_number (GSF_cfg,
- "fs",
- "MAX_PENDING_REQUESTS",
- &max_pending_requests))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Configuration fails to specify `%s', assuming default
value."),
- "MAX_PENDING_REQUESTS");
- }
+ "fs",
+ "MAX_PENDING_REQUESTS",
+ &max_pending_requests))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _
+ ("Configuration fails to specify `%s', assuming default
value."),
+ "MAX_PENDING_REQUESTS");
+ }
active_to_migration = GNUNET_CONFIGURATION_get_value_yesno (GSF_cfg,
- "FS",
-
"CONTENT_CACHING");
+ "FS",
+
"CONTENT_CACHING");
datastore_put_load = GNUNET_LOAD_value_init (DATASTORE_LOAD_AUTODECLINE);
pr_map = GNUNET_CONTAINER_multihashmap_create (32 * 1024);
- requests_by_expiration_heap = GNUNET_CONTAINER_heap_create
(GNUNET_CONTAINER_HEAP_ORDER_MIN);
+ requests_by_expiration_heap =
+ GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
}
@@ -1687,9 +1625,7 @@
void
GSF_pending_request_done_ ()
{
- GNUNET_CONTAINER_multihashmap_iterate (pr_map,
- &clean_request,
- NULL);
+ GNUNET_CONTAINER_multihashmap_iterate (pr_map, &clean_request, NULL);
GNUNET_CONTAINER_multihashmap_destroy (pr_map);
pr_map = NULL;
GNUNET_CONTAINER_heap_destroy (requests_by_expiration_heap);
Modified: gnunet/src/fs/gnunet-service-fs_pr.h
===================================================================
--- gnunet/src/fs/gnunet-service-fs_pr.h 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/fs/gnunet-service-fs_pr.h 2011-08-15 21:46:35 UTC (rev
16581)
@@ -33,40 +33,40 @@
* Options for pending requests (bits to be ORed).
*/
enum GSF_PendingRequestOptions
- {
+{
/**
* Request must only be processed locally.
*/
- GSF_PRO_LOCAL_ONLY = 1,
-
+ GSF_PRO_LOCAL_ONLY = 1,
+
/**
* Request must only be forwarded (no routing)
*/
- GSF_PRO_FORWARD_ONLY = 2,
+ GSF_PRO_FORWARD_ONLY = 2,
/**
* Request persists indefinitely (no expiration).
*/
- GSF_PRO_REQUEST_EXPIRES = 4,
+ GSF_PRO_REQUEST_EXPIRES = 4,
/**
* Request is allowed to refresh bloomfilter and change mingle value.
*/
- GSF_PRO_BLOOMFILTER_FULL_REFRESH = 8,
+ GSF_PRO_BLOOMFILTER_FULL_REFRESH = 8,
/**
* Request priority is allowed to be exceeded.
*/
- GSF_PRO_PRIORITY_UNLIMITED = 16,
+ GSF_PRO_PRIORITY_UNLIMITED = 16,
/**
* Option mask for typical local requests.
*/
- GSF_PRO_LOCAL_REQUEST = (GSF_PRO_BLOOMFILTER_FULL_REFRESH |
GSF_PRO_PRIORITY_UNLIMITED)
+ GSF_PRO_LOCAL_REQUEST =
+ (GSF_PRO_BLOOMFILTER_FULL_REFRESH | GSF_PRO_PRIORITY_UNLIMITED)
+};
- };
-
/**
* Public data (in the sense of not encapsulated within
* 'gnunet-service-fs_pr', not in the sense of network-wide
@@ -84,7 +84,7 @@
* Namespace to query, only set if the type is SBLOCK.
*/
GNUNET_HashCode namespace;
-
+
/**
* Identity of a peer hosting the content, only set if
* 'has_target' is GNUNET_YES.
@@ -130,7 +130,7 @@
* Options for the request.
*/
enum GSF_PendingRequestOptions options;
-
+
/**
* Type of the requested block.
*/
@@ -166,14 +166,17 @@
* @param data response data, NULL on request expiration
* @param data_len number of bytes in data
*/
-typedef void (*GSF_PendingRequestReplyHandler)(void *cls,
- enum
GNUNET_BLOCK_EvaluationResult eval,
- struct GSF_PendingRequest *pr,
- uint32_t reply_anonymity_level,
- struct GNUNET_TIME_Absolute
expiration,
- enum GNUNET_BLOCK_Type type,
- const void *data,
- size_t data_len);
+typedef void (*GSF_PendingRequestReplyHandler) (void *cls,
+ enum
+ GNUNET_BLOCK_EvaluationResult
+ eval,
+ struct GSF_PendingRequest * pr,
+ uint32_t reply_anonymity_level,
+ struct GNUNET_TIME_Absolute
+ expiration,
+ enum GNUNET_BLOCK_Type type,
+ const void *data,
+ size_t data_len);
/**
@@ -198,23 +201,33 @@
* @param rh_cls closure for rh
* @return handle for the new pending request
*/
-struct GSF_PendingRequest *
-GSF_pending_request_create_ (enum GSF_PendingRequestOptions options,
- enum GNUNET_BLOCK_Type type,
- const GNUNET_HashCode *query,
- const GNUNET_HashCode *namespace,
- const struct GNUNET_PeerIdentity *target,
- const char *bf_data,
- size_t bf_size,
- uint32_t mingle,
- uint32_t anonymity_level,
- uint32_t priority,
- int32_t ttl,
- GNUNET_PEER_Id sender_pid,
- const GNUNET_HashCode *replies_seen,
- unsigned int replies_seen_count,
- GSF_PendingRequestReplyHandler rh,
- void *rh_cls);
+struct GSF_PendingRequest *GSF_pending_request_create_ (enum
+
GSF_PendingRequestOptions
+ options,
+ enum GNUNET_BLOCK_Type
+ type,
+ const GNUNET_HashCode *
+ query,
+ const GNUNET_HashCode *
+ namespace,
+ const struct
+ GNUNET_PeerIdentity
+ *target,
+ const char *bf_data,
+ size_t bf_size,
+ uint32_t mingle,
+ uint32_t
+ anonymity_level,
+ uint32_t priority,
+ int32_t ttl,
+ GNUNET_PEER_Id
+ sender_pid,
+ const GNUNET_HashCode *
+ replies_seen,
+ unsigned int
+ replies_seen_count,
+
GSF_PendingRequestReplyHandler
+ rh, void *rh_cls);
/**
@@ -227,8 +240,8 @@
*/
void
GSF_pending_request_update_ (struct GSF_PendingRequest *pr,
- const GNUNET_HashCode *replies_seen,
- unsigned int replies_seen_count);
+ const GNUNET_HashCode * replies_seen,
+ unsigned int replies_seen_count);
/**
@@ -237,8 +250,9 @@
* @param pr pending request
* @return associated public data
*/
-struct GSF_PendingRequestData *
-GSF_pending_request_get_data_ (struct GSF_PendingRequest *pr);
+struct GSF_PendingRequestData *GSF_pending_request_get_data_ (struct
+
GSF_PendingRequest
+ *pr);
/**
@@ -252,7 +266,7 @@
*/
int
GSF_pending_request_is_compatible_ (struct GSF_PendingRequest *pra,
- struct GSF_PendingRequest *prb);
+ struct GSF_PendingRequest *prb);
/**
@@ -265,9 +279,14 @@
* @return number of bytes needed (if buf_size too small) or used
*/
size_t
+
+
+
+
+
+
GSF_pending_request_get_message_ (struct GSF_PendingRequest *pr,
- size_t buf_size,
- void *buf);
+ size_t buf_size, void *buf);
/**
@@ -277,8 +296,7 @@
* @param full_cleanup fully purge the request
*/
void
-GSF_pending_request_cancel_ (struct GSF_PendingRequest *pr,
- int full_cleanup);
+GSF_pending_request_cancel_ (struct GSF_PendingRequest *pr, int full_cleanup);
/**
@@ -290,9 +308,9 @@
* @param pr handle to the pending request
* @return GNUNET_YES to continue to iterate
*/
-typedef int (*GSF_PendingRequestIterator)(void *cls,
- const GNUNET_HashCode *key,
- struct GSF_PendingRequest *pr);
+typedef int (*GSF_PendingRequestIterator) (void *cls,
+ const GNUNET_HashCode * key,
+ struct GSF_PendingRequest * pr);
/**
@@ -301,9 +319,7 @@
* @param it function to call for each request
* @param cls closure for it
*/
-void
-GSF_iterate_pending_requests_ (GSF_PendingRequestIterator it,
- void *cls);
+void GSF_iterate_pending_requests_ (GSF_PendingRequestIterator it, void *cls);
/**
@@ -321,7 +337,7 @@
*/
int
GSF_handle_p2p_content_ (struct GSF_ConnectedPeer *cp,
- const struct GNUNET_MessageHeader *message);
+ const struct GNUNET_MessageHeader *message);
/**
@@ -329,8 +345,7 @@
*
* @param pr the pending request to process
*/
-void
-GSF_dht_lookup_ (struct GSF_PendingRequest *pr);
+void GSF_dht_lookup_ (struct GSF_PendingRequest *pr);
/**
@@ -341,9 +356,10 @@
* @param pr the pending request we were processing
* @param result final datastore lookup result
*/
-typedef void (*GSF_LocalLookupContinuation)(void *cls,
- struct GSF_PendingRequest *pr,
- enum GNUNET_BLOCK_EvaluationResult
result);
+typedef void (*GSF_LocalLookupContinuation) (void *cls,
+ struct GSF_PendingRequest * pr,
+ enum GNUNET_BLOCK_EvaluationResult
+ result);
/**
@@ -355,22 +371,19 @@
*/
void
GSF_local_lookup_ (struct GSF_PendingRequest *pr,
- GSF_LocalLookupContinuation cont,
- void *cont_cls);
+ GSF_LocalLookupContinuation cont, void *cont_cls);
/**
* Setup the subsystem.
*/
-void
-GSF_pending_request_init_ (void);
+void GSF_pending_request_init_ (void);
/**
* Shutdown the subsystem.
*/
-void
-GSF_pending_request_done_ (void);
+void GSF_pending_request_done_ (void);
#endif
Modified: gnunet/src/fs/gnunet-service-fs_push.c
===================================================================
--- gnunet/src/fs/gnunet-service-fs_push.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/fs/gnunet-service-fs_push.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -112,7 +112,7 @@
* Handle to peer.
*/
struct GSF_ConnectedPeer *peer;
-
+
/**
* Handle for current transmission request,
* or NULL for none.
@@ -181,11 +181,8 @@
static void
delete_migration_block (struct MigrationReadyBlock *mb)
{
- GNUNET_CONTAINER_DLL_remove (mig_head,
- mig_tail,
- mb);
- GNUNET_PEER_decrement_rcs (mb->target_list,
- MIGRATION_LIST_SIZE);
+ GNUNET_CONTAINER_DLL_remove (mig_head, mig_tail, mb);
+ GNUNET_PEER_decrement_rcs (mb->target_list, MIGRATION_LIST_SIZE);
mig_size--;
GNUNET_free (mb);
}
@@ -193,9 +190,8 @@
/**
* Find content for migration to this peer.
- */
-static void
-find_content (struct MigrationReadyPeer *mrp);
+ */
+static void find_content (struct MigrationReadyPeer *mrp);
/**
@@ -208,9 +204,7 @@
* @return number of bytes copied to 'buf', can be 0 (without indicating an
error)
*/
static size_t
-transmit_message (void *cls,
- size_t buf_size,
- void *buf)
+transmit_message (void *cls, size_t buf_size, void *buf)
{
struct MigrationReadyPeer *peer = cls;
struct PutMessage *msg;
@@ -220,22 +214,21 @@
msg = peer->msg;
peer->msg = NULL;
if (buf == NULL)
- {
+ {
#if DEBUG_FS_MIGRATION
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Failed to migrate content to another peer (disconnect)\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to migrate content to another peer (disconnect)\n");
#endif
- GNUNET_free (msg);
- return 0;
- }
+ GNUNET_free (msg);
+ return 0;
+ }
msize = ntohs (msg->header.size);
GNUNET_assert (msize <= buf_size);
memcpy (buf, msg, msize);
GNUNET_free (msg);
#if DEBUG_FS_MIGRATION
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Pushing %u bytes to another peer\n",
- msize);
+ "Pushing %u bytes to another peer\n", msize);
#endif
find_content (peer);
return msize;
@@ -251,11 +244,11 @@
*/
static int
transmit_content (struct MigrationReadyPeer *peer,
- struct MigrationReadyBlock *block)
+ struct MigrationReadyBlock *block)
{
size_t msize;
struct PutMessage *msg;
- unsigned int i;
+ unsigned int i;
struct GSF_PeerPerformanceData *ppd;
int ret;
@@ -267,40 +260,33 @@
msg->header.size = htons (msize);
msg->type = htonl (block->type);
msg->expiration = GNUNET_TIME_absolute_hton (block->expiration);
- memcpy (&msg[1],
- &block[1],
- block->size);
+ memcpy (&msg[1], &block[1], block->size);
peer->msg = msg;
- for (i=0;i<MIGRATION_LIST_SIZE;i++)
+ for (i = 0; i < MIGRATION_LIST_SIZE; i++)
+ {
+ if (block->target_list[i] == 0)
{
- if (block->target_list[i] == 0)
- {
- block->target_list[i] = ppd->pid;
- GNUNET_PEER_change_rc (block->target_list[i], 1);
- break;
- }
+ block->target_list[i] = ppd->pid;
+ GNUNET_PEER_change_rc (block->target_list[i], 1);
+ break;
}
+ }
if (MIGRATION_LIST_SIZE == i)
- {
- delete_migration_block (block);
- ret = GNUNET_YES;
- }
+ {
+ delete_migration_block (block);
+ ret = GNUNET_YES;
+ }
else
- {
- ret = GNUNET_NO;
- }
+ {
+ ret = GNUNET_NO;
+ }
#if DEBUG_FS_MIGRATION
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Asking for transmission of %u bytes for migration\n",
- msize);
+ "Asking for transmission of %u bytes for migration\n", msize);
#endif
- peer->th = GSF_peer_transmit_ (peer->peer,
- GNUNET_NO,
- 0 /* priority */,
- GNUNET_TIME_UNIT_FOREVER_REL,
- msize,
- &transmit_message,
- peer);
+ peer->th = GSF_peer_transmit_ (peer->peer, GNUNET_NO, 0 /* priority */ ,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ msize, &transmit_message, peer);
return ret;
}
@@ -317,7 +303,7 @@
{
unsigned int i;
- for (i=0;i<MIGRATION_LIST_SIZE;i++)
+ for (i = 0; i < MIGRATION_LIST_SIZE; i++)
if (block->target_list[i] == 0)
return i;
return i;
@@ -334,7 +320,7 @@
*/
static long
score_content (struct MigrationReadyPeer *peer,
- struct MigrationReadyBlock *block)
+ struct MigrationReadyBlock *block)
{
unsigned int i;
struct GSF_PeerPerformanceData *ppd;
@@ -342,14 +328,12 @@
uint32_t dist;
ppd = GSF_get_peer_performance_data_ (peer->peer);
- for (i=0;i<MIGRATION_LIST_SIZE;i++)
+ for (i = 0; i < MIGRATION_LIST_SIZE; i++)
if (block->target_list[i] == ppd->pid)
return -1;
GNUNET_assert (0 != ppd->pid);
- GNUNET_PEER_resolve (ppd->pid,
- &id);
- dist = GNUNET_CRYPTO_hash_distance_u32 (&block->query,
- &id.hashPubKey);
+ GNUNET_PEER_resolve (ppd->pid, &id);
+ dist = GNUNET_CRYPTO_hash_distance_u32 (&block->query, &id.hashPubKey);
/* closer distance, higher score: */
return UINT32_MAX - dist;
}
@@ -359,15 +343,14 @@
* If the migration task is not currently running, consider
* (re)scheduling it with the appropriate delay.
*/
-static void
-consider_gathering (void);
+static void consider_gathering (void);
/**
* Find content for migration to this peer.
*
* @param mrp peer to find content for
- */
+ */
static void
find_content (struct MigrationReadyPeer *mrp)
{
@@ -381,51 +364,51 @@
best_score = -1;
pos = mig_head;
while (NULL != pos)
+ {
+ score = score_content (mrp, pos);
+ if (score > best_score)
{
- score = score_content (mrp, pos);
- if (score > best_score)
- {
- best_score = score;
- best = pos;
- }
- pos = pos->next;
+ best_score = score;
+ best = pos;
}
- if (NULL == best)
+ pos = pos->next;
+ }
+ if (NULL == best)
+ {
+ if (mig_size < MAX_MIGRATION_QUEUE)
{
- if (mig_size < MAX_MIGRATION_QUEUE)
- {
#if DEBUG_FS_MIGRATION
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "No content found for pushing, waiting for queue to
fill\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "No content found for pushing, waiting for queue to fill\n");
#endif
- return; /* will fill up eventually... */
- }
+ return; /* will fill up eventually... */
+ }
#if DEBUG_FS_MIGRATION
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "No suitable content found, purging content from full
queue\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "No suitable content found, purging content from full
queue\n");
#endif
- /* failed to find migration target AND
- queue is full, purge most-forwarded
- block from queue to make room for more */
- pos = mig_head;
- while (NULL != pos)
- {
- score = count_targets (pos);
- if (score >= best_score)
- {
- best_score = score;
- best = pos;
- }
- pos = pos->next;
- }
- GNUNET_assert (NULL != best);
- delete_migration_block (best);
- consider_gathering ();
- return;
+ /* failed to find migration target AND
+ * queue is full, purge most-forwarded
+ * block from queue to make room for more */
+ pos = mig_head;
+ while (NULL != pos)
+ {
+ score = count_targets (pos);
+ if (score >= best_score)
+ {
+ best_score = score;
+ best = pos;
+ }
+ pos = pos->next;
}
+ GNUNET_assert (NULL != best);
+ delete_migration_block (best);
+ consider_gathering ();
+ return;
+ }
#if DEBUG_FS_MIGRATION
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Preparing to push best content to peer\n");
+ "Preparing to push best content to peer\n");
#endif
transmit_content (mrp, best);
}
@@ -440,7 +423,7 @@
*/
static void
gather_migration_blocks (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+ const struct GNUNET_SCHEDULER_TaskContext *tc);
/**
@@ -458,22 +441,17 @@
return;
if (mig_task != GNUNET_SCHEDULER_NO_TASK)
return;
- if (mig_size >= MAX_MIGRATION_QUEUE)
+ if (mig_size >= MAX_MIGRATION_QUEUE)
return;
- delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
- mig_size);
- delay = GNUNET_TIME_relative_divide (delay,
- MAX_MIGRATION_QUEUE);
- delay = GNUNET_TIME_relative_max (delay,
- min_migration_delay);
+ delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, mig_size);
+ delay = GNUNET_TIME_relative_divide (delay, MAX_MIGRATION_QUEUE);
+ delay = GNUNET_TIME_relative_max (delay, min_migration_delay);
#if DEBUG_FS_MIGRATION
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Scheduling gathering task (queue size: %u)\n",
- mig_size);
+ "Scheduling gathering task (queue size: %u)\n", mig_size);
#endif
mig_task = GNUNET_SCHEDULER_add_delayed (delay,
- &gather_migration_blocks,
- NULL);
+ &gather_migration_blocks, NULL);
}
@@ -493,53 +471,47 @@
*/
static void
process_migration_content (void *cls,
- const GNUNET_HashCode *key,
- size_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- struct GNUNET_TIME_Absolute
- expiration, uint64_t uid)
+ const GNUNET_HashCode * key,
+ size_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute expiration, uint64_t
uid)
{
struct MigrationReadyBlock *mb;
struct MigrationReadyPeer *pos;
-
+
mig_qe = NULL;
if (key == NULL)
- {
+ {
#if DEBUG_FS_MIGRATION
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "No content found for migration...\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No content found for
migration...\n");
#endif
- consider_gathering ();
- return;
- }
- if (GNUNET_TIME_absolute_get_remaining (expiration).rel_value <
+ consider_gathering ();
+ return;
+ }
+ if (GNUNET_TIME_absolute_get_remaining (expiration).rel_value <
MIN_MIGRATION_CONTENT_LIFETIME.rel_value)
- {
- /* content will expire soon, don't bother */
- consider_gathering ();
- return;
- }
+ {
+ /* content will expire soon, don't bother */
+ consider_gathering ();
+ return;
+ }
if (type == GNUNET_BLOCK_TYPE_FS_ONDEMAND)
- {
- if (GNUNET_OK !=
- GNUNET_FS_handle_on_demand_block (key, size, data,
- type, priority, anonymity,
- expiration, uid,
- &process_migration_content,
- NULL))
- consider_gathering ();
- return;
- }
+ {
+ if (GNUNET_OK !=
+ GNUNET_FS_handle_on_demand_block (key, size, data,
+ type, priority, anonymity,
+ expiration, uid,
+ &process_migration_content, NULL))
+ consider_gathering ();
+ return;
+ }
#if DEBUG_FS_MIGRATION
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Retrieved block `%s' of type %u for migration (queue size:
%u/%u)\n",
- GNUNET_h2s (key),
- type,
- mig_size + 1,
- MAX_MIGRATION_QUEUE);
+ "Retrieved block `%s' of type %u for migration (queue size:
%u/%u)\n",
+ GNUNET_h2s (key), type, mig_size + 1, MAX_MIGRATION_QUEUE);
#endif
mb = GNUNET_malloc (sizeof (struct MigrationReadyBlock) + size);
mb->query = *key;
@@ -547,25 +519,22 @@
mb->size = size;
mb->type = type;
memcpy (&mb[1], data, size);
- GNUNET_CONTAINER_DLL_insert_after (mig_head,
- mig_tail,
- mig_tail,
- mb);
+ GNUNET_CONTAINER_DLL_insert_after (mig_head, mig_tail, mig_tail, mb);
mig_size++;
pos = peer_head;
while (pos != NULL)
+ {
+ if (NULL == pos->th)
{
- if (NULL == pos->th)
- {
#if DEBUG_FS_MIGRATION
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Preparing to push best content to peer\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Preparing to push best content to peer\n");
#endif
- if (GNUNET_YES == transmit_content (pos, mb))
- break; /* 'mb' was freed! */
- }
- pos = pos->next;
+ if (GNUNET_YES == transmit_content (pos, mb))
+ break; /* 'mb' was freed! */
}
+ pos = pos->next;
+ }
consider_gathering ();
}
@@ -579,25 +548,26 @@
*/
static void
gather_migration_blocks (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
mig_task = GNUNET_SCHEDULER_NO_TASK;
- if (mig_size >= MAX_MIGRATION_QUEUE)
+ if (mig_size >= MAX_MIGRATION_QUEUE)
return;
if (GSF_dsh != NULL)
- {
+ {
#if DEBUG_FS_MIGRATION
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Asking datastore for content for replication (queue size:
%u)\n",
- mig_size);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Asking datastore for content for replication (queue size:
%u)\n",
+ mig_size);
#endif
- mig_qe = GNUNET_DATASTORE_get_for_replication (GSF_dsh,
- 0, UINT_MAX,
-
GNUNET_TIME_UNIT_FOREVER_REL,
-
&process_migration_content, NULL);
- if (NULL == mig_qe)
- consider_gathering ();
- }
+ mig_qe = GNUNET_DATASTORE_get_for_replication (GSF_dsh,
+ 0, UINT_MAX,
+
GNUNET_TIME_UNIT_FOREVER_REL,
+ &process_migration_content,
+ NULL);
+ if (NULL == mig_qe)
+ consider_gathering ();
+ }
}
@@ -617,9 +587,7 @@
mrp = GNUNET_malloc (sizeof (struct MigrationReadyPeer));
mrp->peer = peer;
find_content (mrp);
- GNUNET_CONTAINER_DLL_insert (peer_head,
- peer_tail,
- mrp);
+ GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, mrp);
}
@@ -636,27 +604,25 @@
pos = peer_head;
while (pos != NULL)
+ {
+ if (pos->peer == peer)
{
- if (pos->peer == peer)
- {
- GNUNET_CONTAINER_DLL_remove (peer_head,
- peer_tail,
- pos);
- if (NULL != pos->th)
- {
- GSF_peer_transmit_cancel_ (pos->th);
- pos->th = NULL;
- }
- if (NULL != pos->msg)
- {
- GNUNET_free (pos->msg);
- pos->msg = NULL;
- }
- GNUNET_free (pos);
- return;
- }
- pos = pos->next;
+ GNUNET_CONTAINER_DLL_remove (peer_head, peer_tail, pos);
+ if (NULL != pos->th)
+ {
+ GSF_peer_transmit_cancel_ (pos->th);
+ pos->th = NULL;
+ }
+ if (NULL != pos->msg)
+ {
+ GNUNET_free (pos->msg);
+ pos->msg = NULL;
+ }
+ GNUNET_free (pos);
+ return;
}
+ pos = pos->next;
+ }
}
@@ -667,23 +633,22 @@
GSF_push_init_ ()
{
enabled = GNUNET_CONFIGURATION_get_value_yesno (GSF_cfg,
- "FS",
- "CONTENT_PUSHING");
+ "FS", "CONTENT_PUSHING");
if (GNUNET_YES != enabled)
return;
-
- if (GNUNET_OK !=
+
+ if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_time (GSF_cfg,
- "fs",
- "MIN_MIGRATION_DELAY",
- &min_migration_delay))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Invalid value specified for option `%s' in section `%s',
content pushing disabled\n"),
- "MIN_MIGRATION_DELAY",
- "fs");
- return;
- }
+ "fs",
+ "MIN_MIGRATION_DELAY",
+ &min_migration_delay))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Invalid value specified for option `%s' in section `%s',
content pushing disabled\n"),
+ "MIN_MIGRATION_DELAY", "fs");
+ return;
+ }
consider_gathering ();
}
@@ -695,15 +660,15 @@
GSF_push_done_ ()
{
if (GNUNET_SCHEDULER_NO_TASK != mig_task)
- {
- GNUNET_SCHEDULER_cancel (mig_task);
- mig_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (mig_task);
+ mig_task = GNUNET_SCHEDULER_NO_TASK;
+ }
if (NULL != mig_qe)
- {
- GNUNET_DATASTORE_cancel (mig_qe);
- mig_qe = NULL;
- }
+ {
+ GNUNET_DATASTORE_cancel (mig_qe);
+ mig_qe = NULL;
+ }
while (NULL != mig_head)
delete_migration_block (mig_head);
GNUNET_assert (0 == mig_size);
Modified: gnunet/src/fs/gnunet-service-fs_push.h
===================================================================
--- gnunet/src/fs/gnunet-service-fs_push.h 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/fs/gnunet-service-fs_push.h 2011-08-15 21:46:35 UTC (rev
16581)
@@ -32,15 +32,13 @@
/**
* Setup the module.
*/
-void
-GSF_push_init_ (void);
+void GSF_push_init_ (void);
/**
* Shutdown the module.
*/
-void
-GSF_push_done_ (void);
+void GSF_push_done_ (void);
/**
@@ -49,8 +47,7 @@
*
* @param peer handle for the peer that connected
*/
-void
-GSF_push_start_ (struct GSF_ConnectedPeer *peer);
+void GSF_push_start_ (struct GSF_ConnectedPeer *peer);
/**
@@ -59,8 +56,7 @@
*
* @param peer handle for the peer that disconnected
*/
-void
-GSF_push_stop_ (struct GSF_ConnectedPeer *peer);
+void GSF_push_stop_ (struct GSF_ConnectedPeer *peer);
#endif
Modified: gnunet/src/fs/gnunet-service-fs_put.c
===================================================================
--- gnunet/src/fs/gnunet-service-fs_put.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/fs/gnunet-service-fs_put.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -54,7 +54,7 @@
* ID of task that collects blocks for DHT PUTs.
*/
GNUNET_SCHEDULER_TaskIdentifier dht_task;
-
+
/**
* How many entires with zero anonymity of our type do we currently
* estimate to have in the database?
@@ -72,13 +72,12 @@
* ANY-terminated list of our operators (one per type
* of block that we're putting into the DHT).
*/
-static struct PutOperator operators[] =
- {
- { NULL, GNUNET_BLOCK_TYPE_FS_KBLOCK, 0, 0, 0 },
- { NULL, GNUNET_BLOCK_TYPE_FS_SBLOCK, 0, 0, 0 },
- { NULL, GNUNET_BLOCK_TYPE_FS_NBLOCK, 0, 0, 0 },
- { NULL, GNUNET_BLOCK_TYPE_ANY, 0, 0, 0 }
- };
+static struct PutOperator operators[] = {
+ {NULL, GNUNET_BLOCK_TYPE_FS_KBLOCK, 0, 0, 0},
+ {NULL, GNUNET_BLOCK_TYPE_FS_SBLOCK, 0, 0, 0},
+ {NULL, GNUNET_BLOCK_TYPE_FS_NBLOCK, 0, 0, 0},
+ {NULL, GNUNET_BLOCK_TYPE_ANY, 0, 0, 0}
+};
/**
@@ -89,7 +88,7 @@
*/
static void
gather_dht_put_blocks (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+ const struct GNUNET_SCHEDULER_TaskContext *tc);
/**
@@ -99,8 +98,7 @@
* @param tc scheduler context (unused)
*/
static void
-delay_dht_put_blocks (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+delay_dht_put_blocks (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct PutOperator *po = cls;
struct GNUNET_TIME_Relative delay;
@@ -109,21 +107,19 @@
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
return;
if (po->zero_anonymity_count_estimate > 0)
- {
- delay = GNUNET_TIME_relative_divide
(GNUNET_DHT_DEFAULT_REPUBLISH_FREQUENCY,
- po->zero_anonymity_count_estimate);
- delay = GNUNET_TIME_relative_min (delay,
- MAX_DHT_PUT_FREQ);
- }
+ {
+ delay = GNUNET_TIME_relative_divide
(GNUNET_DHT_DEFAULT_REPUBLISH_FREQUENCY,
+ po->zero_anonymity_count_estimate);
+ delay = GNUNET_TIME_relative_min (delay, MAX_DHT_PUT_FREQ);
+ }
else
- {
- /* if we have NO zero-anonymity content yet, wait 5 minutes for some to
- (hopefully) appear */
- delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5);
- }
+ {
+ /* if we have NO zero-anonymity content yet, wait 5 minutes for some to
+ * (hopefully) appear */
+ delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5);
+ }
po->dht_task = GNUNET_SCHEDULER_add_delayed (delay,
- &gather_dht_put_blocks,
- po);
+ &gather_dht_put_blocks, po);
}
@@ -143,45 +139,40 @@
*/
static void
process_dht_put_content (void *cls,
- const GNUNET_HashCode * key,
- size_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- struct GNUNET_TIME_Absolute
- expiration, uint64_t uid)
-{
+ const GNUNET_HashCode * key,
+ size_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute expiration, uint64_t uid)
+{
struct PutOperator *po = cls;
po->dht_qe = NULL;
if (key == NULL)
- {
- po->zero_anonymity_count_estimate = po->current_offset - 1;
- po->current_offset = 0;
- po->dht_task = GNUNET_SCHEDULER_add_now (&delay_dht_put_blocks,
- po);
- return;
- }
+ {
+ po->zero_anonymity_count_estimate = po->current_offset - 1;
+ po->current_offset = 0;
+ po->dht_task = GNUNET_SCHEDULER_add_now (&delay_dht_put_blocks, po);
+ return;
+ }
po->zero_anonymity_count_estimate = GNUNET_MAX (po->current_offset,
-
po->zero_anonymity_count_estimate);
+
po->zero_anonymity_count_estimate);
#if DEBUG_FS
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Retrieved block `%s' of type %u for DHT PUT\n",
- GNUNET_h2s (key),
- type);
+ "Retrieved block `%s' of type %u for DHT PUT\n",
+ GNUNET_h2s (key), type);
#endif
GNUNET_DHT_put (GSF_dht,
- key,
- DEFAULT_PUT_REPLICATION,
- GNUNET_DHT_RO_NONE,
- type,
- size,
- data,
- expiration,
- GNUNET_TIME_UNIT_FOREVER_REL,
- &delay_dht_put_blocks,
- po);
+ key,
+ DEFAULT_PUT_REPLICATION,
+ GNUNET_DHT_RO_NONE,
+ type,
+ size,
+ data,
+ expiration,
+ GNUNET_TIME_UNIT_FOREVER_REL, &delay_dht_put_blocks, po);
}
@@ -192,23 +183,22 @@
* @param tc scheduler context (unused)
*/
static void
-gather_dht_put_blocks (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+gather_dht_put_blocks (void *cls, const struct GNUNET_SCHEDULER_TaskContext
*tc)
{
struct PutOperator *po = cls;
po->dht_task = GNUNET_SCHEDULER_NO_TASK;
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
return;
- po->dht_qe = GNUNET_DATASTORE_get_zero_anonymity (GSF_dsh,
- po->current_offset++,
- 0, UINT_MAX,
-
GNUNET_TIME_UNIT_FOREVER_REL,
- po->dht_put_type,
- &process_dht_put_content,
po);
+ po->dht_qe = GNUNET_DATASTORE_get_zero_anonymity (GSF_dsh,
+ po->current_offset++,
+ 0, UINT_MAX,
+
GNUNET_TIME_UNIT_FOREVER_REL,
+ po->dht_put_type,
+ &process_dht_put_content,
+ po);
if (NULL == po->dht_qe)
- po->dht_task = GNUNET_SCHEDULER_add_now (&delay_dht_put_blocks,
- po);
+ po->dht_task = GNUNET_SCHEDULER_add_now (&delay_dht_put_blocks, po);
}
@@ -222,10 +212,11 @@
i = 0;
while (operators[i].dht_put_type != GNUNET_BLOCK_TYPE_ANY)
- {
- operators[i].dht_task = GNUNET_SCHEDULER_add_now
(&gather_dht_put_blocks, &operators[i]);
- i++;
- }
+ {
+ operators[i].dht_task =
+ GNUNET_SCHEDULER_add_now (&gather_dht_put_blocks, &operators[i]);
+ i++;
+ }
}
@@ -240,19 +231,19 @@
i = 0;
while ((po = &operators[i])->dht_put_type != GNUNET_BLOCK_TYPE_ANY)
+ {
+ if (GNUNET_SCHEDULER_NO_TASK != po->dht_task)
{
- if (GNUNET_SCHEDULER_NO_TASK != po->dht_task)
- {
- GNUNET_SCHEDULER_cancel (po->dht_task);
- po->dht_task = GNUNET_SCHEDULER_NO_TASK;
- }
- if (NULL != po->dht_qe)
- {
- GNUNET_DATASTORE_cancel (po->dht_qe);
- po->dht_qe = NULL;
- }
- i++;
+ GNUNET_SCHEDULER_cancel (po->dht_task);
+ po->dht_task = GNUNET_SCHEDULER_NO_TASK;
}
+ if (NULL != po->dht_qe)
+ {
+ GNUNET_DATASTORE_cancel (po->dht_qe);
+ po->dht_qe = NULL;
+ }
+ i++;
+ }
}
/* end of gnunet-service-fs_put.c */
Modified: gnunet/src/fs/gnunet-service-fs_put.h
===================================================================
--- gnunet/src/fs/gnunet-service-fs_put.h 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/fs/gnunet-service-fs_put.h 2011-08-15 21:46:35 UTC (rev
16581)
@@ -32,15 +32,13 @@
/**
* Setup the module.
*/
-void
-GSF_put_init_ (void);
+void GSF_put_init_ (void);
/**
* Shutdown the module.
*/
-void
-GSF_put_done_ (void);
+void GSF_put_done_ (void);
#endif
Modified: gnunet/src/fs/gnunet-unindex.c
===================================================================
--- gnunet/src/fs/gnunet-unindex.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/fs/gnunet-unindex.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -40,8 +40,7 @@
static void
-cleanup_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GNUNET_FS_stop (ctx);
ctx = NULL;
@@ -49,17 +48,16 @@
static void
-shutdown_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_FS_UnindexContext *u;
if (uc != NULL)
- {
- u = uc;
- uc = NULL;
- GNUNET_FS_unindex_stop (u);
- }
+ {
+ u = uc;
+ uc = NULL;
+ GNUNET_FS_unindex_stop (u);
+ }
}
/**
@@ -76,49 +74,44 @@
* field in the GNUNET_FS_ProgressInfo struct.
*/
static void *
-progress_cb (void *cls,
- const struct GNUNET_FS_ProgressInfo *info)
+progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
{
char *s;
switch (info->status)
+ {
+ case GNUNET_FS_STATUS_UNINDEX_START:
+ break;
+ case GNUNET_FS_STATUS_UNINDEX_PROGRESS:
+ if (verbose)
{
- case GNUNET_FS_STATUS_UNINDEX_START:
- break;
- case GNUNET_FS_STATUS_UNINDEX_PROGRESS:
- if (verbose)
- {
- s = GNUNET_STRINGS_relative_time_to_string(info->value.unindex.eta);
- fprintf (stdout,
- _("Unindexing at %llu/%llu (%s remaining)\n"),
- (unsigned long long) info->value.unindex.completed,
- (unsigned long long) info->value.unindex.size,
- s);
- GNUNET_free (s);
- }
- break;
- case GNUNET_FS_STATUS_UNINDEX_ERROR:
- fprintf (stderr,
- _("Error unindexing: %s.\n"),
- info->value.unindex.specifics.error.message);
- GNUNET_SCHEDULER_shutdown ();
- break;
- case GNUNET_FS_STATUS_UNINDEX_COMPLETED:
+ s = GNUNET_STRINGS_relative_time_to_string (info->value.unindex.eta);
fprintf (stdout,
- _("Unindexing done.\n"));
- GNUNET_SCHEDULER_shutdown ();
- break;
- case GNUNET_FS_STATUS_UNINDEX_STOPPED:
- GNUNET_SCHEDULER_add_continuation (&cleanup_task,
- NULL,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- break;
- default:
- fprintf (stderr,
- _("Unexpected status: %d\n"),
- info->status);
- break;
+ _("Unindexing at %llu/%llu (%s remaining)\n"),
+ (unsigned long long) info->value.unindex.completed,
+ (unsigned long long) info->value.unindex.size, s);
+ GNUNET_free (s);
}
+ break;
+ case GNUNET_FS_STATUS_UNINDEX_ERROR:
+ fprintf (stderr,
+ _("Error unindexing: %s.\n"),
+ info->value.unindex.specifics.error.message);
+ GNUNET_SCHEDULER_shutdown ();
+ break;
+ case GNUNET_FS_STATUS_UNINDEX_COMPLETED:
+ fprintf (stdout, _("Unindexing done.\n"));
+ GNUNET_SCHEDULER_shutdown ();
+ break;
+ case GNUNET_FS_STATUS_UNINDEX_STOPPED:
+ GNUNET_SCHEDULER_add_continuation (&cleanup_task,
+ NULL,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ break;
+ default:
+ fprintf (stderr, _("Unexpected status: %d\n"), info->status);
+ break;
+ }
return NULL;
}
@@ -134,45 +127,35 @@
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *c)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
{
/* check arguments */
- if ( (args[0] == NULL) || (args[1] != NULL) )
- {
- printf (_
- ("You must specify one and only one filename for
unindexing.\n"));
- ret = -1;
- return;
- }
+ if ((args[0] == NULL) || (args[1] != NULL))
+ {
+ printf (_("You must specify one and only one filename for unindexing.\n"));
+ ret = -1;
+ return;
+ }
cfg = c;
ctx = GNUNET_FS_start (cfg,
- "gnunet-unindex",
- &progress_cb,
- NULL,
- GNUNET_FS_FLAGS_NONE,
- GNUNET_FS_OPTIONS_END);
+ "gnunet-unindex",
+ &progress_cb,
+ NULL, GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
if (NULL == ctx)
- {
- fprintf (stderr,
- _("Could not initialize `%s' subsystem.\n"),
- "FS");
- ret = 1;
- return;
- }
- uc = GNUNET_FS_unindex_start (ctx,
- args[0],
- NULL);
+ {
+ fprintf (stderr, _("Could not initialize `%s' subsystem.\n"), "FS");
+ ret = 1;
+ return;
+ }
+ uc = GNUNET_FS_unindex_start (ctx, args[0], NULL);
if (NULL == uc)
- {
- fprintf (stderr,
- _("Could not start unindex operation.\n"));
- GNUNET_FS_stop (ctx);
- return;
- }
+ {
+ fprintf (stderr, _("Could not start unindex operation.\n"));
+ GNUNET_FS_stop (ctx);
+ return;
+ }
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task,
- NULL);
+ &shutdown_task, NULL);
}
Modified: gnunet/src/fs/perf_gnunet_service_fs_p2p.c
===================================================================
--- gnunet/src/fs/perf_gnunet_service_fs_p2p.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/fs/perf_gnunet_service_fs_p2p.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -52,11 +52,9 @@
static const char *progname;
static void
-do_stop (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS,
- daemons);
+ GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons);
}
@@ -65,7 +63,7 @@
*/
struct StatMaster
{
- struct GNUNET_STATISTICS_Handle *stat;
+ struct GNUNET_STATISTICS_Handle *stat;
unsigned int daemon;
unsigned int value;
};
@@ -79,32 +77,31 @@
/**
* Statistics we print out.
*/
-static struct StatValues stats[] =
- {
- { "fs", "# artificial delays introduced (ms)"},
- { "fs", "# queries forwarded"},
- { "fs", "# replies received and matched"},
- { "fs", "# results found locally"},
- { "fs", "# requests forwarded due to high load"},
- { "fs", "# requests done for free (low load)"},
- { "fs", "# requests dropped, priority insufficient"},
- { "fs", "# requests done for a price (normal load)"},
- { "fs", "# requests dropped by datastore (queue length limit)"},
- { "fs", "# P2P searches received"},
- { "fs", "# P2P searches discarded (queue length bound)"},
- { "fs", "# replies received for local clients"},
- { "fs", "# queries retransmitted to same target"},
- { "core", "# bytes decrypted"},
- { "core", "# bytes encrypted"},
- { "core", "# discarded CORE_SEND requests"},
- { "core", "# discarded CORE_SEND request bytes"},
- { "core", "# discarded lower priority CORE_SEND requests"},
- { "core", "# discarded lower priority CORE_SEND request bytes"},
- { "transport", "# bytes received via TCP"},
- { "transport", "# bytes transmitted via TCP"},
- { "datacache", "# bytes stored"},
- { NULL, NULL}
- };
+static struct StatValues stats[] = {
+ {"fs", "# artificial delays introduced (ms)"},
+ {"fs", "# queries forwarded"},
+ {"fs", "# replies received and matched"},
+ {"fs", "# results found locally"},
+ {"fs", "# requests forwarded due to high load"},
+ {"fs", "# requests done for free (low load)"},
+ {"fs", "# requests dropped, priority insufficient"},
+ {"fs", "# requests done for a price (normal load)"},
+ {"fs", "# requests dropped by datastore (queue length limit)"},
+ {"fs", "# P2P searches received"},
+ {"fs", "# P2P searches discarded (queue length bound)"},
+ {"fs", "# replies received for local clients"},
+ {"fs", "# queries retransmitted to same target"},
+ {"core", "# bytes decrypted"},
+ {"core", "# bytes encrypted"},
+ {"core", "# discarded CORE_SEND requests"},
+ {"core", "# discarded CORE_SEND request bytes"},
+ {"core", "# discarded lower priority CORE_SEND requests"},
+ {"core", "# discarded lower priority CORE_SEND request bytes"},
+ {"transport", "# bytes received via TCP"},
+ {"transport", "# bytes transmitted via TCP"},
+ {"datacache", "# bytes stored"},
+ {NULL, NULL}
+};
/**
@@ -119,18 +116,14 @@
*/
static int
print_stat (void *cls,
- const char *subsystem,
- const char *name,
- uint64_t value,
- int is_persistent)
+ const char *subsystem,
+ const char *name, uint64_t value, int is_persistent)
{
struct StatMaster *sm = cls;
+
fprintf (stderr,
- "Peer %2u: %12s/%50s = %12llu\n",
- sm->daemon,
- subsystem,
- name,
- (unsigned long long) value);
+ "Peer %2u: %12s/%50s = %12llu\n",
+ sm->daemon, subsystem, name, (unsigned long long) value);
return GNUNET_OK;
}
@@ -138,20 +131,18 @@
/**
* Function that gathers stats from all daemons.
*/
-static void
-stat_run (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+static void stat_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext
*tc);
/**
* Function called when GET operation on stats is done.
*/
static void
-get_done (void *cls,
- int success)
+get_done (void *cls, int success)
{
struct StatMaster *sm = cls;
- GNUNET_break (GNUNET_OK == success);
+
+ GNUNET_break (GNUNET_OK == success);
sm->value++;
GNUNET_SCHEDULER_add_now (&stat_run, sm);
}
@@ -161,129 +152,115 @@
* Function that gathers stats from all daemons.
*/
static void
-stat_run (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+stat_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct StatMaster *sm = cls;
-
+
if (stats[sm->value].name != NULL)
- {
- GNUNET_STATISTICS_get (sm->stat,
+ {
+ GNUNET_STATISTICS_get (sm->stat,
#if 0
- NULL, NULL,
+ NULL, NULL,
#else
- stats[sm->value].subsystem,
- stats[sm->value].name,
+ stats[sm->value].subsystem, stats[sm->value].name,
#endif
- GNUNET_TIME_UNIT_FOREVER_REL,
- &get_done,
- &print_stat, sm);
- return;
- }
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &get_done, &print_stat, sm);
+ return;
+ }
GNUNET_STATISTICS_destroy (sm->stat, GNUNET_NO);
sm->value = 0;
sm->daemon++;
if (sm->daemon == NUM_DAEMONS)
- {
- GNUNET_free (sm);
- GNUNET_SCHEDULER_add_now (&do_stop, NULL);
- return;
- }
+ {
+ GNUNET_free (sm);
+ GNUNET_SCHEDULER_add_now (&do_stop, NULL);
+ return;
+ }
sm->stat = GNUNET_STATISTICS_create ("<driver>",
- GNUNET_FS_TEST_get_configuration
(daemons,
-
sm->daemon));
+ GNUNET_FS_TEST_get_configuration
+ (daemons, sm->daemon));
GNUNET_SCHEDULER_add_now (&stat_run, sm);
}
static void
-do_report (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_report (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_TIME_Relative del;
- char *fancy;
+ char *fancy;
struct StatMaster *sm;
-
+
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
- {
- del = GNUNET_TIME_absolute_get_duration (start_time);
- if (del.rel_value == 0)
- del.rel_value = 1;
- fancy = GNUNET_STRINGS_byte_size_fancy (((unsigned long long)FILESIZE) *
1000LL / del.rel_value);
- fprintf (stdout,
- "Download speed was %s/s\n",
- fancy);
- GNUNET_free (fancy);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Finished download, shutting down\n",
- (unsigned long long) FILESIZE);
- sm = GNUNET_malloc (sizeof (struct StatMaster));
- sm->stat = GNUNET_STATISTICS_create ("<driver>",
- GNUNET_FS_TEST_get_configuration
(daemons,
-
sm->daemon));
- GNUNET_SCHEDULER_add_now (&stat_run, sm);
- }
+ {
+ del = GNUNET_TIME_absolute_get_duration (start_time);
+ if (del.rel_value == 0)
+ del.rel_value = 1;
+ fancy =
+ GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) *
+ 1000LL / del.rel_value);
+ fprintf (stdout, "Download speed was %s/s\n", fancy);
+ GNUNET_free (fancy);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Finished download, shutting down\n",
+ (unsigned long long) FILESIZE);
+ sm = GNUNET_malloc (sizeof (struct StatMaster));
+ sm->stat = GNUNET_STATISTICS_create ("<driver>",
+ GNUNET_FS_TEST_get_configuration
+ (daemons, sm->daemon));
+ GNUNET_SCHEDULER_add_now (&stat_run, sm);
+ }
else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Timeout during download, shutting down with error\n");
- ok = 1;
- GNUNET_SCHEDULER_add_now (&do_stop, NULL);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Timeout during download, shutting down with error\n");
+ ok = 1;
+ GNUNET_SCHEDULER_add_now (&do_stop, NULL);
+ }
}
static void
-do_download (void *cls,
- const struct GNUNET_FS_Uri *uri)
+do_download (void *cls, const struct GNUNET_FS_Uri *uri)
{
int anonymity;
if (NULL == uri)
- {
- GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS,
- daemons);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Timeout during upload attempt, shutting down with error\n");
- ok = 1;
- return;
- }
+ {
+ GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Timeout during upload attempt, shutting down with error\n");
+ ok = 1;
+ return;
+ }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Downloading %llu bytes\n",
- (unsigned long long) FILESIZE);
+ "Downloading %llu bytes\n", (unsigned long long) FILESIZE);
start_time = GNUNET_TIME_absolute_get ();
if (NULL != strstr (progname, "dht"))
anonymity = 0;
else
anonymity = 1;
GNUNET_FS_TEST_download (daemons[0],
- TIMEOUT,
- anonymity, SEED, uri,
- VERBOSE,
- &do_report, NULL);
+ TIMEOUT,
+ anonymity, SEED, uri, VERBOSE, &do_report, NULL);
}
static void
-do_publish (void *cls,
- const char *emsg)
+do_publish (void *cls, const char *emsg)
{
int do_index;
int anonymity;
if (NULL != emsg)
- {
- GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS,
- daemons);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Error trying to connect: %s\n",
- emsg);
- ok = 1;
- return;
- }
+ {
+ GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error trying to connect: %s\n",
emsg);
+ ok = 1;
+ return;
+ }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Publishing %llu bytes\n",
- (unsigned long long) FILESIZE);
+ "Publishing %llu bytes\n", (unsigned long long) FILESIZE);
if (NULL != strstr (progname, "index"))
do_index = GNUNET_YES;
else
@@ -292,61 +269,52 @@
anonymity = 0;
else
anonymity = 1;
-
- GNUNET_FS_TEST_publish (daemons[NUM_DAEMONS-1],
- TIMEOUT,
- anonymity,
- do_index, FILESIZE, SEED,
- VERBOSE,
- &do_download, NULL);
+
+ GNUNET_FS_TEST_publish (daemons[NUM_DAEMONS - 1],
+ TIMEOUT,
+ anonymity,
+ do_index, FILESIZE, SEED,
+ VERBOSE, &do_download, NULL);
}
static void
-do_connect (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_TESTING_PeerGroup *pg;
GNUNET_assert (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Daemons started, will now try to connect them\n");
+ "Daemons started, will now try to connect them\n");
pg = GNUNET_FS_TEST_get_group (daemons);
- GNUNET_break ( (NUM_DAEMONS - 1) * 2
- == (GNUNET_TESTING_create_topology (pg,
-
GNUNET_TESTING_TOPOLOGY_LINE,
-
GNUNET_TESTING_TOPOLOGY_NONE,
- NULL)));
+ GNUNET_break ((NUM_DAEMONS - 1) * 2
+ == (GNUNET_TESTING_create_topology (pg,
+
GNUNET_TESTING_TOPOLOGY_LINE,
+
GNUNET_TESTING_TOPOLOGY_NONE,
+ NULL)));
GNUNET_TESTING_connect_topology (pg,
- GNUNET_TESTING_TOPOLOGY_LINE,
- GNUNET_TESTING_TOPOLOGY_OPTION_NONE,
- 0.0,
- TIMEOUT,
- NUM_DAEMONS,
- &do_publish,
- NULL);
+ GNUNET_TESTING_TOPOLOGY_LINE,
+ GNUNET_TESTING_TOPOLOGY_OPTION_NONE,
+ 0.0,
+ TIMEOUT, NUM_DAEMONS, &do_publish, NULL);
}
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
GNUNET_FS_TEST_daemons_start ("fs_test_lib_data.conf",
- TIMEOUT,
- NUM_DAEMONS,
- daemons,
- &do_connect,
- NULL);
+ TIMEOUT,
+ NUM_DAEMONS, daemons, &do_connect, NULL);
}
int
main (int argc, char *argv[])
{
- char *const argvx[] = {
+ char *const argvx[] = {
"perf-gnunet-service-fs-p2p",
"-c",
"fs_test_lib_data.conf",
@@ -360,16 +328,16 @@
};
progname = argv[0];
GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
- GNUNET_log_setup ("perf_gnunet_service_fs_p2p_index",
+ GNUNET_log_setup ("perf_gnunet_service_fs_p2p_index",
#if VERBOSE
- "DEBUG",
+ "DEBUG",
#else
- "WARNING",
+ "WARNING",
#endif
- NULL);
+ NULL);
GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
argvx, "perf-gnunet-service-fs-p2p-index",
- "nohelp", options, &run, NULL);
+ "nohelp", options, &run, NULL);
GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
return ok;
}
Modified: gnunet/src/fs/perf_gnunet_service_fs_p2p_trust.c
===================================================================
--- gnunet/src/fs/perf_gnunet_service_fs_p2p_trust.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/fs/perf_gnunet_service_fs_p2p_trust.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -87,11 +87,9 @@
static struct GNUNET_FS_Uri *uri2;
static void
-do_stop (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS,
- daemons);
+ GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons);
}
@@ -100,7 +98,7 @@
*/
struct StatMaster
{
- struct GNUNET_STATISTICS_Handle *stat;
+ struct GNUNET_STATISTICS_Handle *stat;
unsigned int daemon;
unsigned int value;
};
@@ -114,30 +112,29 @@
/**
* Statistics we print out.
*/
-static struct StatValues stats[] =
- {
- { "fs", "# artificial delays introduced (ms)"},
- { "fs", "# queries forwarded"},
- { "fs", "# replies received and matched"},
- { "fs", "# results found locally"},
- { "fs", "# requests forwarded due to high load"},
- { "fs", "# requests done for free (low load)"},
- { "fs", "# requests dropped, priority insufficient"},
- { "fs", "# requests done for a price (normal load)"},
- { "fs", "# requests dropped by datastore (queue length limit)"},
- { "fs", "# P2P searches received"},
- { "fs", "# P2P searches discarded (queue length bound)"},
- { "fs", "# replies received for local clients"},
- { "fs", "# queries retransmitted to same target"},
- { "core", "# bytes decrypted"},
- { "core", "# bytes encrypted"},
- { "core", "# discarded CORE_SEND requests"},
- { "core", "# discarded lower priority CORE_SEND requests"},
- { "transport", "# bytes received via TCP"},
- { "transport", "# bytes transmitted via TCP"},
- { "datacache", "# bytes stored"},
- { NULL, NULL}
- };
+static struct StatValues stats[] = {
+ {"fs", "# artificial delays introduced (ms)"},
+ {"fs", "# queries forwarded"},
+ {"fs", "# replies received and matched"},
+ {"fs", "# results found locally"},
+ {"fs", "# requests forwarded due to high load"},
+ {"fs", "# requests done for free (low load)"},
+ {"fs", "# requests dropped, priority insufficient"},
+ {"fs", "# requests done for a price (normal load)"},
+ {"fs", "# requests dropped by datastore (queue length limit)"},
+ {"fs", "# P2P searches received"},
+ {"fs", "# P2P searches discarded (queue length bound)"},
+ {"fs", "# replies received for local clients"},
+ {"fs", "# queries retransmitted to same target"},
+ {"core", "# bytes decrypted"},
+ {"core", "# bytes encrypted"},
+ {"core", "# discarded CORE_SEND requests"},
+ {"core", "# discarded lower priority CORE_SEND requests"},
+ {"transport", "# bytes received via TCP"},
+ {"transport", "# bytes transmitted via TCP"},
+ {"datacache", "# bytes stored"},
+ {NULL, NULL}
+};
/**
@@ -152,18 +149,14 @@
*/
static int
print_stat (void *cls,
- const char *subsystem,
- const char *name,
- uint64_t value,
- int is_persistent)
+ const char *subsystem,
+ const char *name, uint64_t value, int is_persistent)
{
struct StatMaster *sm = cls;
+
fprintf (stderr,
- "Peer %2u: %12s/%50s = %12llu\n",
- sm->daemon,
- subsystem,
- name,
- (unsigned long long) value);
+ "Peer %2u: %12s/%50s = %12llu\n",
+ sm->daemon, subsystem, name, (unsigned long long) value);
return GNUNET_OK;
}
@@ -171,20 +164,18 @@
/**
* Function that gathers stats from all daemons.
*/
-static void
-stat_run (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+static void stat_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext
*tc);
/**
* Function called when GET operation on stats is done.
*/
static void
-get_done (void *cls,
- int success)
+get_done (void *cls, int success)
{
struct StatMaster *sm = cls;
- GNUNET_break (GNUNET_OK == success);
+
+ GNUNET_break (GNUNET_OK == success);
sm->value++;
GNUNET_SCHEDULER_add_now (&stat_run, sm);
}
@@ -194,154 +185,140 @@
* Function that gathers stats from all daemons.
*/
static void
-stat_run (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+stat_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct StatMaster *sm = cls;
-
+
if (stats[sm->value].name != NULL)
- {
- GNUNET_STATISTICS_get (sm->stat,
+ {
+ GNUNET_STATISTICS_get (sm->stat,
#if 0
- NULL, NULL,
+ NULL, NULL,
#else
- stats[sm->value].subsystem,
- stats[sm->value].name,
+ stats[sm->value].subsystem, stats[sm->value].name,
#endif
- GNUNET_TIME_UNIT_FOREVER_REL,
- &get_done,
- &print_stat, sm);
- return;
- }
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &get_done, &print_stat, sm);
+ return;
+ }
GNUNET_STATISTICS_destroy (sm->stat, GNUNET_NO);
sm->value = 0;
sm->daemon++;
if (sm->daemon == NUM_DAEMONS)
- {
- GNUNET_free (sm);
- GNUNET_SCHEDULER_add_now (&do_stop, NULL);
- return;
- }
+ {
+ GNUNET_free (sm);
+ GNUNET_SCHEDULER_add_now (&do_stop, NULL);
+ return;
+ }
sm->stat = GNUNET_STATISTICS_create ("<driver>",
- GNUNET_FS_TEST_get_configuration
(daemons,
-
sm->daemon));
+ GNUNET_FS_TEST_get_configuration
+ (daemons, sm->daemon));
GNUNET_SCHEDULER_add_now (&stat_run, sm);
}
static void
-do_report (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_report (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
static int download_counter;
const char *type = cls;
struct GNUNET_TIME_Relative del;
- char *fancy;
+ char *fancy;
struct StatMaster *sm;
-
+
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
- {
- del = GNUNET_TIME_absolute_get_duration (start_time);
- if (del.rel_value == 0)
- del.rel_value = 1;
- fancy = GNUNET_STRINGS_byte_size_fancy (((unsigned long long)FILESIZE) *
1000LL / del.rel_value);
- fprintf (stderr,
- "Download speed of type `%s' was %s/s\n",
- type,
- fancy);
- GNUNET_free (fancy);
- if (NUM_DAEMONS != ++download_counter)
- return; /* more downloads to come */
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Finished all downloads, shutting down\n",
- (unsigned long long) FILESIZE);
- sm = GNUNET_malloc (sizeof (struct StatMaster));
- sm->stat = GNUNET_STATISTICS_create ("<driver>",
- GNUNET_FS_TEST_get_configuration
(daemons,
-
sm->daemon));
- GNUNET_SCHEDULER_add_now (&stat_run, sm);
- }
+ {
+ del = GNUNET_TIME_absolute_get_duration (start_time);
+ if (del.rel_value == 0)
+ del.rel_value = 1;
+ fancy =
+ GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) *
+ 1000LL / del.rel_value);
+ fprintf (stderr, "Download speed of type `%s' was %s/s\n", type, fancy);
+ GNUNET_free (fancy);
+ if (NUM_DAEMONS != ++download_counter)
+ return; /* more downloads to come */
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Finished all downloads, shutting down\n",
+ (unsigned long long) FILESIZE);
+ sm = GNUNET_malloc (sizeof (struct StatMaster));
+ sm->stat = GNUNET_STATISTICS_create ("<driver>",
+ GNUNET_FS_TEST_get_configuration
+ (daemons, sm->daemon));
+ GNUNET_SCHEDULER_add_now (&stat_run, sm);
+ }
else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Timeout during download for type `%s', shutting down with
error\n",
- type);
- ok = 1;
- GNUNET_SCHEDULER_add_now (&do_stop, NULL);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Timeout during download for type `%s', shutting down with
error\n",
+ type);
+ ok = 1;
+ GNUNET_SCHEDULER_add_now (&do_stop, NULL);
+ }
}
static void
-do_downloads (void *cls,
- const struct GNUNET_FS_Uri *u2)
+do_downloads (void *cls, const struct GNUNET_FS_Uri *u2)
{
int anonymity;
unsigned int i;
if (NULL == u2)
- {
- GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS,
- daemons);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Timeout during upload attempt, shutting down with error\n");
- ok = 1;
- return;
- }
+ {
+ GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Timeout during upload attempt, shutting down with error\n");
+ ok = 1;
+ return;
+ }
uri2 = GNUNET_FS_uri_dup (u2);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Downloading %llu bytes\n",
- (unsigned long long) FILESIZE);
+ "Downloading %llu bytes\n", (unsigned long long) FILESIZE);
start_time = GNUNET_TIME_absolute_get ();
if (NULL != strstr (progname, "dht"))
anonymity = 0;
else
anonymity = 1;
/* (semi) leach-download(s); not true leaches since
- these peers do participate in sharing, they just
- don't have to offer anything *initially*. */
- for (i=0;i<NUM_DAEMONS-2;i++)
+ * these peers do participate in sharing, they just
+ * don't have to offer anything *initially*. */
+ for (i = 0; i < NUM_DAEMONS - 2; i++)
GNUNET_FS_TEST_download (daemons[i],
- TIMEOUT,
- anonymity,
- 0 == (i%2) ? SEED1 : SEED2,
- 0 == (i%2) ? uri1 : uri2,
- VERBOSE,
- &do_report, "leach");
+ TIMEOUT,
+ anonymity,
+ 0 == (i % 2) ? SEED1 : SEED2,
+ 0 == (i % 2) ? uri1 : uri2,
+ VERBOSE, &do_report, "leach");
/* mutual downloads of (primary) sharing peers */
- GNUNET_FS_TEST_download (daemons[NUM_DAEMONS-2],
- TIMEOUT,
- anonymity, SEED1, uri1,
- VERBOSE,
- &do_report, "seeder 2");
- GNUNET_FS_TEST_download (daemons[NUM_DAEMONS-1],
- TIMEOUT,
- anonymity, SEED2, uri2,
- VERBOSE,
- &do_report, "seeder 1");
+ GNUNET_FS_TEST_download (daemons[NUM_DAEMONS - 2],
+ TIMEOUT,
+ anonymity, SEED1, uri1,
+ VERBOSE, &do_report, "seeder 2");
+ GNUNET_FS_TEST_download (daemons[NUM_DAEMONS - 1],
+ TIMEOUT,
+ anonymity, SEED2, uri2,
+ VERBOSE, &do_report, "seeder 1");
}
static void
-do_publish2 (void *cls,
- const struct GNUNET_FS_Uri *u1)
+do_publish2 (void *cls, const struct GNUNET_FS_Uri *u1)
{
int do_index;
int anonymity;
if (NULL == u1)
- {
- GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS,
- daemons);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Timeout during upload attempt, shutting down with error\n");
- ok = 1;
- return;
- }
+ {
+ GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Timeout during upload attempt, shutting down with error\n");
+ ok = 1;
+ return;
+ }
uri1 = GNUNET_FS_uri_dup (u1);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Publishing %llu bytes\n",
- (unsigned long long) FILESIZE);
+ "Publishing %llu bytes\n", (unsigned long long) FILESIZE);
if (NULL != strstr (progname, "index"))
do_index = GNUNET_YES;
else
@@ -350,35 +327,29 @@
anonymity = 0;
else
anonymity = 1;
-
- GNUNET_FS_TEST_publish (daemons[NUM_DAEMONS-2],
- TIMEOUT,
- anonymity,
- do_index, FILESIZE, SEED2,
- VERBOSE,
- &do_downloads, NULL);
+
+ GNUNET_FS_TEST_publish (daemons[NUM_DAEMONS - 2],
+ TIMEOUT,
+ anonymity,
+ do_index, FILESIZE, SEED2,
+ VERBOSE, &do_downloads, NULL);
}
static void
-do_publish1 (void *cls,
- const char *emsg)
+do_publish1 (void *cls, const char *emsg)
{
int do_index;
int anonymity;
if (NULL != emsg)
- {
- GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS,
- daemons);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Error trying to connect: %s\n",
- emsg);
- ok = 1;
- return;
- }
+ {
+ GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error trying to connect: %s\n",
emsg);
+ ok = 1;
+ return;
+ }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Publishing %llu bytes\n",
- (unsigned long long) FILESIZE);
+ "Publishing %llu bytes\n", (unsigned long long) FILESIZE);
if (NULL != strstr (progname, "index"))
do_index = GNUNET_YES;
else
@@ -387,60 +358,50 @@
anonymity = 0;
else
anonymity = 1;
-
- GNUNET_FS_TEST_publish (daemons[NUM_DAEMONS-1],
- TIMEOUT,
- anonymity,
- do_index, FILESIZE, SEED1,
- VERBOSE,
- &do_publish2, NULL);
+
+ GNUNET_FS_TEST_publish (daemons[NUM_DAEMONS - 1],
+ TIMEOUT,
+ anonymity,
+ do_index, FILESIZE, SEED1,
+ VERBOSE, &do_publish2, NULL);
}
static void
-do_connect (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_TESTING_PeerGroup *pg;
GNUNET_assert (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Daemons started, will now try to connect them\n");
+ "Daemons started, will now try to connect them\n");
pg = GNUNET_FS_TEST_get_group (daemons);
- GNUNET_TESTING_create_topology (pg,
- GNUNET_TESTING_TOPOLOGY_CLIQUE,
- GNUNET_TESTING_TOPOLOGY_NONE,
- NULL);
+ GNUNET_TESTING_create_topology (pg,
+ GNUNET_TESTING_TOPOLOGY_CLIQUE,
+ GNUNET_TESTING_TOPOLOGY_NONE, NULL);
GNUNET_TESTING_connect_topology (pg,
- GNUNET_TESTING_TOPOLOGY_CLIQUE,
- GNUNET_TESTING_TOPOLOGY_OPTION_NONE,
- 0.0,
- TIMEOUT,
- NUM_DAEMONS,
- &do_publish1,
- NULL);
+ GNUNET_TESTING_TOPOLOGY_CLIQUE,
+ GNUNET_TESTING_TOPOLOGY_OPTION_NONE,
+ 0.0,
+ TIMEOUT, NUM_DAEMONS, &do_publish1, NULL);
}
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
GNUNET_FS_TEST_daemons_start ("fs_test_lib_data.conf",
- TIMEOUT,
- NUM_DAEMONS,
- daemons,
- &do_connect,
- NULL);
+ TIMEOUT,
+ NUM_DAEMONS, daemons, &do_connect, NULL);
}
int
main (int argc, char *argv[])
{
- char *const argvx[] = {
+ char *const argvx[] = {
"perf-gnunet-service-fs-p2p",
"-c",
"fs_test_lib_data.conf",
@@ -454,16 +415,16 @@
};
progname = argv[0];
GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
- GNUNET_log_setup ("perf_gnunet_service_fs_p2p_trust",
+ GNUNET_log_setup ("perf_gnunet_service_fs_p2p_trust",
#if VERBOSE
- "DEBUG",
+ "DEBUG",
#else
- "WARNING",
+ "WARNING",
#endif
- NULL);
+ NULL);
GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
argvx, "perf-gnunet-service-fs-p2p-trust",
- "nohelp", options, &run, NULL);
+ "nohelp", options, &run, NULL);
GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
return ok;
}
Modified: gnunet/src/fs/test_fs.c
===================================================================
--- gnunet/src/fs/test_fs.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/fs/test_fs.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -37,9 +37,8 @@
{
char *fn;
- fn =
- GNUNET_malloc (strlen ("/tmp/gnunet-basic_fsui_test/BASIC_FSUI_TEST") +
- 14);
+ fn = GNUNET_malloc (strlen ("/tmp/gnunet-basic_fsui_test/BASIC_FSUI_TEST") +
+ 14);
GNUNET_snprintf (fn,
strlen ("/tmp/gnunet-basic_fsui_test/BASIC_FSUI_TEST") +
14, "/tmp/gnunet-basic_fsui_test/BASIC_FSUI_TEST%u", i);
@@ -61,39 +60,37 @@
static char unused;
switch (event->type)
- {
- case GNUNET_FSUI_search_resumed:
- case GNUNET_FSUI_download_resumed:
- case GNUNET_FSUI_upload_resumed:
- case GNUNET_FSUI_unindex_resumed:
- return &unused;
- case GNUNET_FSUI_search_result:
+ {
+ case GNUNET_FSUI_search_resumed:
+ case GNUNET_FSUI_download_resumed:
+ case GNUNET_FSUI_upload_resumed:
+ case GNUNET_FSUI_unindex_resumed:
+ return &unused;
+ case GNUNET_FSUI_search_result:
#if DEBUG_VERBOSE
- printf ("Received search result\n");
+ printf ("Received search result\n");
#endif
- search_uri =
- GNUNET_ECRS_uri_duplicate (event->data.SearchResult.fi.uri);
- search_meta =
- GNUNET_meta_data_duplicate (event->data.SearchResult.fi.meta);
- break;
- case GNUNET_FSUI_upload_completed:
+ search_uri = GNUNET_ECRS_uri_duplicate (event->data.SearchResult.fi.uri);
+ search_meta = GNUNET_meta_data_duplicate
(event->data.SearchResult.fi.meta);
+ break;
+ case GNUNET_FSUI_upload_completed:
#if DEBUG_VERBOSE
- printf ("Upload complete.\n");
+ printf ("Upload complete.\n");
#endif
- break;
- case GNUNET_FSUI_download_completed:
+ break;
+ case GNUNET_FSUI_download_completed:
#if DEBUG_VERBOSE
- printf ("Download complete.\n");
+ printf ("Download complete.\n");
#endif
- break;
- case GNUNET_FSUI_unindex_completed:
+ break;
+ case GNUNET_FSUI_unindex_completed:
#if DEBUG_VERBOSE
- printf ("Unindex complete.\n");
+ printf ("Unindex complete.\n");
#endif
- break;
- default:
- break;
- }
+ break;
+ default:
+ break;
+ }
lastEvent = event->type;
return NULL;
}
@@ -109,6 +106,7 @@
int ok;
struct GNUNET_ECRS_URI *uri;
char *filename = NULL;
+
char *keywords[] = {
"fsui_foo",
"fsui_bar",
@@ -126,16 +124,15 @@
cfg = GNUNET_GC_create ();
if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf"))
- {
- GNUNET_GC_free (cfg);
- return -1;
- }
+ {
+ GNUNET_GC_free (cfg);
+ return -1;
+ }
#if START_DAEMON
daemon = GNUNET_daemon_start (NULL, cfg, "peer.conf", GNUNET_NO);
GNUNET_GE_ASSERT (NULL, daemon != NULL);
CHECK (GNUNET_OK ==
- GNUNET_wait_for_daemon_running (NULL, cfg,
- 60 * GNUNET_CRON_SECONDS));
+ GNUNET_wait_for_daemon_running (NULL, cfg, 60 * GNUNET_CRON_SECONDS));
#endif
GNUNET_thread_sleep (5 * GNUNET_CRON_SECONDS); /* give apps time to
start */
ok = GNUNET_YES;
@@ -151,8 +148,8 @@
"foo bar test!", strlen ("foo bar test!"), "600");
meta = GNUNET_meta_data_create ();
kuri =
- GNUNET_ECRS_keyword_command_line_to_uri (NULL, 2,
- (const char **) keywords);
+ GNUNET_ECRS_keyword_command_line_to_uri (NULL, 2,
+ (const char **) keywords);
/* upload */
upload = GNUNET_FSUI_upload_start (ctx, filename,
(GNUNET_FSUI_DirectoryScanCallback) & GNUNET_disk_directory_scan, NULL, 0, /*
anonymity */
0, /* priority */
@@ -166,13 +163,12 @@
GNUNET_meta_data_destroy (meta);
prog = 0;
while (lastEvent != GNUNET_FSUI_upload_completed)
- {
- prog++;
- CHECK (prog <
- 10000) GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
- if (GNUNET_shutdown_test () == GNUNET_YES)
- break;
- }
+ {
+ prog++;
+ CHECK (prog < 10000) GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
+ if (GNUNET_shutdown_test () == GNUNET_YES)
+ break;
+ }
/* search */
GNUNET_snprintf (keyword, 40, "+%s +%s", keywords[0], keywords[1]);
@@ -182,13 +178,13 @@
CHECK (search != NULL);
prog = 0;
while (lastEvent != GNUNET_FSUI_search_result)
- {
- prog++;
- CHECK (prog < 10000);
- GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
- if (GNUNET_shutdown_test () == GNUNET_YES)
- break;
- }
+ {
+ prog++;
+ CHECK (prog < 10000);
+ GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
+ if (GNUNET_shutdown_test () == GNUNET_YES)
+ break;
+ }
GNUNET_FSUI_search_abort (search);
GNUNET_FSUI_search_stop (search);
@@ -202,13 +198,13 @@
GNUNET_free (fn);
prog = 0;
while (lastEvent != GNUNET_FSUI_download_completed)
- {
- prog++;
- CHECK (prog < 10000);
- GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
- if (GNUNET_shutdown_test () == GNUNET_YES)
- break;
- }
+ {
+ prog++;
+ CHECK (prog < 10000);
+ GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
+ if (GNUNET_shutdown_test () == GNUNET_YES)
+ break;
+ }
GNUNET_FSUI_download_stop (download);
download = NULL;
GNUNET_ECRS_uri_destroy (search_uri);
@@ -217,13 +213,13 @@
unindex = GNUNET_FSUI_unindex_start (ctx, filename);
prog = 0;
while (lastEvent != GNUNET_FSUI_unindex_completed)
- {
- prog++;
- CHECK (prog < 10000);
- GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
- if (GNUNET_shutdown_test () == GNUNET_YES)
- break;
- }
+ {
+ prog++;
+ CHECK (prog < 10000);
+ GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
+ if (GNUNET_shutdown_test () == GNUNET_YES)
+ break;
+ }
if (lastEvent != GNUNET_FSUI_unindex_completed)
GNUNET_FSUI_unindex_abort (unindex);
GNUNET_FSUI_unindex_stop (unindex);
@@ -234,15 +230,15 @@
if (ctx != NULL)
GNUNET_FSUI_stop (ctx);
if (filename != NULL)
- {
- UNLINK (filename);
- GNUNET_free (filename);
- }
+ {
+ UNLINK (filename);
+ GNUNET_free (filename);
+ }
if (download != NULL)
- {
- GNUNET_FSUI_download_abort (download);
- GNUNET_FSUI_download_stop (download);
- }
+ {
+ GNUNET_FSUI_download_abort (download);
+ GNUNET_FSUI_download_stop (download);
+ }
filename = makeName (43);
/* TODO: verify file 'filename(42)' == file 'filename(43)' */
UNLINK (filename);
Modified: gnunet/src/fs/test_fs_directory.c
===================================================================
--- gnunet/src/fs/test_fs_directory.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/fs/test_fs_directory.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -42,27 +42,26 @@
static void
processor (void *cls,
- const char *filename,
- const struct GNUNET_FS_Uri *uri,
- const struct GNUNET_CONTAINER_MetaData *md,
- size_t length,
- const void *data)
+ const char *filename,
+ const struct GNUNET_FS_Uri *uri,
+ const struct GNUNET_CONTAINER_MetaData *md,
+ size_t length, const void *data)
{
struct PCLS *p = cls;
int i;
if (NULL == uri)
- return; /* ignore directory's meta data */
+ return; /* ignore directory's meta data */
for (i = 0; i < p->max; i++)
+ {
+ if (GNUNET_CONTAINER_meta_data_test_equal (p->md[i],
+ md) &&
+ GNUNET_FS_uri_test_equal (p->uri[i], uri))
{
- if (GNUNET_CONTAINER_meta_data_test_equal (p->md[i],
- md) &&
- GNUNET_FS_uri_test_equal (p->uri[i], uri))
- {
- p->pos++;
- return;
- }
+ p->pos++;
+ return;
}
+ }
fprintf (stderr, "Error at %s:%d\n", __FILE__, __LINE__);
}
@@ -86,89 +85,81 @@
char *s;
cls.max = i;
- uris = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri*) * i);
- mds = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_MetaData*) * i);
+ uris = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri *) * i);
+ mds = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_MetaData *) * i);
meta = GNUNET_CONTAINER_meta_data_create ();
- GNUNET_CONTAINER_meta_data_insert (meta,
- "<test>",
- EXTRACTOR_METATYPE_TITLE,
- EXTRACTOR_METAFORMAT_UTF8,
- "text/plain",
- "A title",
- strlen("A title")+1);
- GNUNET_CONTAINER_meta_data_insert (meta,
- "<test>",
- EXTRACTOR_METATYPE_AUTHOR_NAME,
- EXTRACTOR_METAFORMAT_UTF8,
- "text/plain",
- "An author",
- strlen ("An author")+1);
+ GNUNET_CONTAINER_meta_data_insert (meta,
+ "<test>",
+ EXTRACTOR_METATYPE_TITLE,
+ EXTRACTOR_METAFORMAT_UTF8,
+ "text/plain",
+ "A title", strlen ("A title") + 1);
+ GNUNET_CONTAINER_meta_data_insert (meta,
+ "<test>",
+ EXTRACTOR_METATYPE_AUTHOR_NAME,
+ EXTRACTOR_METAFORMAT_UTF8,
+ "text/plain",
+ "An author", strlen ("An author") + 1);
for (p = 0; p < i; p++)
+ {
+ mds[p] = GNUNET_CONTAINER_meta_data_create ();
+ for (q = 0; q <= p; q++)
{
- mds[p] = GNUNET_CONTAINER_meta_data_create ();
- for (q = 0; q <= p; q++)
- {
- GNUNET_snprintf (txt, sizeof(txt), "%u -- %u\n", p, q);
- GNUNET_CONTAINER_meta_data_insert (mds[p],
- "<test>",
- q % EXTRACTOR_metatype_get_max (),
- EXTRACTOR_METAFORMAT_UTF8,
- "text/plain",
- txt,
- strlen(txt)+1);
- }
- GNUNET_snprintf (uri,
- sizeof(uri),
-
"gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.%u",
- p);
- emsg = NULL;
- uris[p] = GNUNET_FS_uri_parse (uri, &emsg);
- if (uris[p] == NULL)
- {
- GNUNET_CONTAINER_meta_data_destroy (mds[p]);
- while (--p > 0)
- {
- GNUNET_CONTAINER_meta_data_destroy (mds[p]);
- GNUNET_FS_uri_destroy (uris[p]);
- }
- GNUNET_free (mds);
- GNUNET_free (uris);
- GNUNET_free (emsg);
- GNUNET_CONTAINER_meta_data_destroy (meta);
- ABORT (); /* error in testcase */
- }
- GNUNET_assert (emsg == NULL);
+ GNUNET_snprintf (txt, sizeof (txt), "%u -- %u\n", p, q);
+ GNUNET_CONTAINER_meta_data_insert (mds[p],
+ "<test>",
+ q % EXTRACTOR_metatype_get_max (),
+ EXTRACTOR_METAFORMAT_UTF8,
+ "text/plain", txt, strlen (txt) + 1);
}
+ GNUNET_snprintf (uri,
+ sizeof (uri),
+
"gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.%u",
+ p);
+ emsg = NULL;
+ uris[p] = GNUNET_FS_uri_parse (uri, &emsg);
+ if (uris[p] == NULL)
+ {
+ GNUNET_CONTAINER_meta_data_destroy (mds[p]);
+ while (--p > 0)
+ {
+ GNUNET_CONTAINER_meta_data_destroy (mds[p]);
+ GNUNET_FS_uri_destroy (uris[p]);
+ }
+ GNUNET_free (mds);
+ GNUNET_free (uris);
+ GNUNET_free (emsg);
+ GNUNET_CONTAINER_meta_data_destroy (meta);
+ ABORT (); /* error in testcase */
+ }
+ GNUNET_assert (emsg == NULL);
+ }
start = GNUNET_TIME_absolute_get ();
db = GNUNET_FS_directory_builder_create (meta);
for (p = 0; p < i; p++)
GNUNET_FS_directory_builder_add (db, uris[p], mds[p], NULL);
- GNUNET_FS_directory_builder_finish (db,
- &dlen,
- (void**) &data);
- s = GNUNET_STRINGS_relative_time_to_string
(GNUNET_TIME_absolute_get_duration (start));
+ GNUNET_FS_directory_builder_finish (db, &dlen, (void **) &data);
+ s = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration
+ (start));
fprintf (stdout,
- "Creating directory with %u entires and total size %llu took %s\n",
- i,
- (unsigned long long) dlen,
- s);
+ "Creating directory with %u entires and total size %llu took %s\n",
+ i, (unsigned long long) dlen, s);
GNUNET_free (s);
if (i < 100)
- {
- cls.pos = 0;
- cls.uri = uris;
- cls.md = mds;
- GNUNET_FS_directory_list_contents (dlen, data, 0,
- &processor, &cls);
- GNUNET_assert (cls.pos == i);
- }
+ {
+ cls.pos = 0;
+ cls.uri = uris;
+ cls.md = mds;
+ GNUNET_FS_directory_list_contents (dlen, data, 0, &processor, &cls);
+ GNUNET_assert (cls.pos == i);
+ }
GNUNET_free (data);
GNUNET_CONTAINER_meta_data_destroy (meta);
for (p = 0; p < i; p++)
- {
- GNUNET_CONTAINER_meta_data_destroy (mds[p]);
- GNUNET_FS_uri_destroy (uris[p]);
- }
+ {
+ GNUNET_CONTAINER_meta_data_destroy (mds[p]);
+ GNUNET_FS_uri_destroy (uris[p]);
+ }
GNUNET_free (uris);
GNUNET_free (mds);
return ret;
@@ -181,15 +172,15 @@
int failureCount = 0;
int i;
- GNUNET_log_setup ("test_fs_directory",
+ GNUNET_log_setup ("test_fs_directory",
#if VERBOSE
- "DEBUG",
+ "DEBUG",
#else
- "WARNING",
+ "WARNING",
#endif
- NULL);
+ NULL);
for (i = 17; i < 1000; i *= 2)
- failureCount += testDirectory (i);
+ failureCount += testDirectory (i);
if (failureCount != 0)
return 1;
return 0;
Modified: gnunet/src/fs/test_fs_download.c
===================================================================
--- gnunet/src/fs/test_fs_download.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/fs/test_fs_download.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -46,7 +46,7 @@
/**
* How long should our test-content live?
- */
+ */
#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
struct PeerContext
@@ -74,57 +74,52 @@
static int err;
static void
-timeout_kill_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+timeout_kill_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
if (download != NULL)
- {
- GNUNET_FS_download_stop (download, GNUNET_YES);
- download = NULL;
- }
+ {
+ GNUNET_FS_download_stop (download, GNUNET_YES);
+ download = NULL;
+ }
else if (publish != NULL)
- {
- GNUNET_FS_publish_stop (publish);
- publish = NULL;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Timeout downloading file\n");
+ {
+ GNUNET_FS_publish_stop (publish);
+ publish = NULL;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Timeout downloading file\n");
timeout_kill = GNUNET_SCHEDULER_NO_TASK;
err = 1;
}
static void
-abort_publish_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+abort_publish_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
if (publish != NULL)
- {
- GNUNET_FS_publish_stop (publish);
- publish = NULL;
- }
+ {
+ GNUNET_FS_publish_stop (publish);
+ publish = NULL;
+ }
}
static void
-stop_fs_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+stop_fs_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GNUNET_FS_stop (fs);
fs = NULL;
}
static void
-abort_download_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+abort_download_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
uint64_t size;
-
+
if (download != NULL)
- {
- GNUNET_FS_download_stop (download, GNUNET_YES);
- download = NULL;
- }
+ {
+ GNUNET_FS_download_stop (download, GNUNET_YES);
+ download = NULL;
+ }
GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_size (fn, &size, GNUNET_YES));
- GNUNET_assert (size == FILESIZE);
+ GNUNET_assert (size == FILESIZE);
GNUNET_DISK_directory_remove (fn);
GNUNET_free (fn);
fn = NULL;
@@ -134,115 +129,116 @@
static void *
-progress_cb (void *cls,
- const struct GNUNET_FS_ProgressInfo *event)
+progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
{
switch (event->status)
- {
- case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
+ {
+ case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
#if VERBOSE
- printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n",
- (unsigned long long) event->value.publish.completed,
- (unsigned long long) event->value.publish.size,
- event->value.publish.specifics.progress.depth,
- (unsigned long long)
event->value.publish.specifics.progress.offset);
-#endif
- break;
- case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
- printf ("Publishing complete, %llu kb/s.\n",
- (unsigned long long) (FILESIZE * 1000LL /
(1+GNUNET_TIME_absolute_get_duration (start).rel_value) / 1024LL));
- GAUGER ("FS",
- "Publishing speed (insertion)",
- (unsigned long long) (FILESIZE * 1000LL /
(1+GNUNET_TIME_absolute_get_duration (start).rel_value) / 1024LL),
- "kb/s");
- fn = GNUNET_DISK_mktemp ("gnunet-download-test-dst");
- start = GNUNET_TIME_absolute_get ();
- download = GNUNET_FS_download_start (fs,
-
event->value.publish.specifics.completed.chk_uri,
- NULL,
- fn, NULL,
- 0,
- FILESIZE,
- 1,
- GNUNET_FS_DOWNLOAD_OPTION_NONE,
- "download",
- NULL);
- GNUNET_assert (download != NULL);
- break;
- case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
- printf ("Download complete, %llu kb/s.\n",
- (unsigned long long) (FILESIZE * 1000LL /
(1+GNUNET_TIME_absolute_get_duration (start).rel_value) / 1024LL));
- GAUGER ("FS",
- "Local download speed (inserted)",
- (unsigned long long) (FILESIZE * 1000LL /
(1+GNUNET_TIME_absolute_get_duration (start).rel_value) / 1024LL),
- "kb/s");
- GNUNET_SCHEDULER_add_now (&abort_download_task,
- NULL);
- break;
- case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS:
- GNUNET_assert (download == event->value.download.dc);
+ printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n",
+ (unsigned long long) event->value.publish.completed,
+ (unsigned long long) event->value.publish.size,
+ event->value.publish.specifics.progress.depth,
+ (unsigned long long) event->value.publish.specifics.
+ progress.offset);
+#endif
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
+ printf ("Publishing complete, %llu kb/s.\n",
+ (unsigned long long) (FILESIZE * 1000LL /
+ (1 +
+ GNUNET_TIME_absolute_get_duration
+ (start).rel_value) / 1024LL));
+ GAUGER ("FS", "Publishing speed (insertion)",
+ (unsigned long long) (FILESIZE * 1000LL /
+ (1 +
+ GNUNET_TIME_absolute_get_duration
+ (start).rel_value) / 1024LL), "kb/s");
+ fn = GNUNET_DISK_mktemp ("gnunet-download-test-dst");
+ start = GNUNET_TIME_absolute_get ();
+ download = GNUNET_FS_download_start (fs,
+ event->value.publish.
+ specifics.completed.chk_uri, NULL, fn,
+ NULL, 0, FILESIZE, 1,
+ GNUNET_FS_DOWNLOAD_OPTION_NONE,
+ "download", NULL);
+ GNUNET_assert (download != NULL);
+ break;
+ case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
+ printf ("Download complete, %llu kb/s.\n",
+ (unsigned long long) (FILESIZE * 1000LL /
+ (1 +
+ GNUNET_TIME_absolute_get_duration
+ (start).rel_value) / 1024LL));
+ GAUGER ("FS", "Local download speed (inserted)",
+ (unsigned long long) (FILESIZE * 1000LL /
+ (1 +
+ GNUNET_TIME_absolute_get_duration
+ (start).rel_value) / 1024LL), "kb/s");
+ GNUNET_SCHEDULER_add_now (&abort_download_task, NULL);
+ break;
+ case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS:
+ GNUNET_assert (download == event->value.download.dc);
#if VERBOSE
- printf ("Download is progressing (%llu/%llu at level %u off %llu)...\n",
- (unsigned long long) event->value.download.completed,
- (unsigned long long) event->value.download.size,
- event->value.download.specifics.progress.depth,
- (unsigned long long)
event->value.download.specifics.progress.offset);
+ printf ("Download is progressing (%llu/%llu at level %u off %llu)...\n",
+ (unsigned long long) event->value.download.completed,
+ (unsigned long long) event->value.download.size,
+ event->value.download.specifics.progress.depth,
+ (unsigned long long) event->value.download.specifics.
+ progress.offset);
#endif
- break;
- case GNUNET_FS_STATUS_PUBLISH_ERROR:
- fprintf (stderr,
- "Error publishing file: %s\n",
- event->value.publish.specifics.error.message);
- GNUNET_break (0);
- GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
- NULL,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- break;
- case GNUNET_FS_STATUS_DOWNLOAD_ERROR:
- fprintf (stderr,
- "Error downloading file: %s\n",
- event->value.download.specifics.error.message);
- GNUNET_SCHEDULER_add_now (&abort_download_task,
- NULL);
- break;
- case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE:
- case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE:
- break;
- case GNUNET_FS_STATUS_PUBLISH_START:
- GNUNET_assert (0 == strcmp ("publish-context",
event->value.publish.cctx));
- GNUNET_assert (NULL == event->value.publish.pctx);
- GNUNET_assert (FILESIZE == event->value.publish.size);
- GNUNET_assert (0 == event->value.publish.completed);
- GNUNET_assert (1 == event->value.publish.anonymity);
- break;
- case GNUNET_FS_STATUS_PUBLISH_STOPPED:
- GNUNET_assert (publish == event->value.publish.pc);
- GNUNET_assert (FILESIZE == event->value.publish.size);
- GNUNET_assert (1 == event->value.publish.anonymity);
- GNUNET_SCHEDULER_add_now (&stop_fs_task,
- NULL);
- break;
- case GNUNET_FS_STATUS_DOWNLOAD_START:
- GNUNET_assert (0 == strcmp ("download", event->value.download.cctx));
- GNUNET_assert (NULL == event->value.download.pctx);
- GNUNET_assert (NULL != event->value.download.uri);
- GNUNET_assert (0 == strcmp (fn, event->value.download.filename));
- GNUNET_assert (FILESIZE == event->value.download.size);
- GNUNET_assert (0 == event->value.download.completed);
- GNUNET_assert (1 == event->value.download.anonymity);
- break;
- case GNUNET_FS_STATUS_DOWNLOAD_STOPPED:
- GNUNET_assert (download == event->value.download.dc);
- GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
- NULL,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- break;
- default:
- printf ("Unexpected event: %d\n",
- event->status);
- break;
- }
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_ERROR:
+ fprintf (stderr,
+ "Error publishing file: %s\n",
+ event->value.publish.specifics.error.message);
+ GNUNET_break (0);
+ GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
+ NULL,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ break;
+ case GNUNET_FS_STATUS_DOWNLOAD_ERROR:
+ fprintf (stderr,
+ "Error downloading file: %s\n",
+ event->value.download.specifics.error.message);
+ GNUNET_SCHEDULER_add_now (&abort_download_task, NULL);
+ break;
+ case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE:
+ case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE:
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_START:
+ GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx));
+ GNUNET_assert (NULL == event->value.publish.pctx);
+ GNUNET_assert (FILESIZE == event->value.publish.size);
+ GNUNET_assert (0 == event->value.publish.completed);
+ GNUNET_assert (1 == event->value.publish.anonymity);
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_STOPPED:
+ GNUNET_assert (publish == event->value.publish.pc);
+ GNUNET_assert (FILESIZE == event->value.publish.size);
+ GNUNET_assert (1 == event->value.publish.anonymity);
+ GNUNET_SCHEDULER_add_now (&stop_fs_task, NULL);
+ break;
+ case GNUNET_FS_STATUS_DOWNLOAD_START:
+ GNUNET_assert (0 == strcmp ("download", event->value.download.cctx));
+ GNUNET_assert (NULL == event->value.download.pctx);
+ GNUNET_assert (NULL != event->value.download.uri);
+ GNUNET_assert (0 == strcmp (fn, event->value.download.filename));
+ GNUNET_assert (FILESIZE == event->value.download.size);
+ GNUNET_assert (0 == event->value.download.completed);
+ GNUNET_assert (1 == event->value.download.anonymity);
+ break;
+ case GNUNET_FS_STATUS_DOWNLOAD_STOPPED:
+ GNUNET_assert (download == event->value.download.dc);
+ GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
+ NULL,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ break;
+ default:
+ printf ("Unexpected event: %d\n", event->status);
+ break;
+ }
return NULL;
}
@@ -253,11 +249,11 @@
p->cfg = GNUNET_CONFIGURATION_create ();
#if START_ARM
p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
- "gnunet-service-arm",
+ "gnunet-service-arm",
#if VERBOSE
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", cfgname, NULL);
+ "-c", cfgname, NULL);
#endif
GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
}
@@ -268,16 +264,17 @@
{
#if START_ARM
if (NULL != p->arm_proc)
- {
- if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
- if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK)
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "ARM process %u stopped\n", GNUNET_OS_process_get_pid
(p->arm_proc));
- GNUNET_OS_process_close (p->arm_proc);
- p->arm_proc = NULL;
- }
+ {
+ if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
+ if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "ARM process %u stopped\n",
+ GNUNET_OS_process_get_pid (p->arm_proc));
+ GNUNET_OS_process_close (p->arm_proc);
+ p->arm_proc = NULL;
+ }
#endif
GNUNET_CONFIGURATION_destroy (p->cfg);
}
@@ -286,8 +283,7 @@
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
const char *keywords[] = {
"down_foo",
@@ -302,12 +298,10 @@
setup_peer (&p1, "test_fs_download_data.conf");
fs = GNUNET_FS_start (cfg,
- "test-fs-download",
- &progress_cb,
- NULL,
- GNUNET_FS_FLAGS_NONE,
- GNUNET_FS_OPTIONS_END);
- GNUNET_assert (NULL != fs);
+ "test-fs-download",
+ &progress_cb,
+ NULL, GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
+ GNUNET_assert (NULL != fs);
buf = GNUNET_malloc (FILESIZE);
for (i = 0; i < FILESIZE; i++)
buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
@@ -316,26 +310,22 @@
bo.content_priority = 42;
bo.anonymity_level = 1;
bo.replication_level = 0;
- bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
+ bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
fi = GNUNET_FS_file_information_create_from_data (fs,
- "publish-context",
- FILESIZE,
- buf,
- kuri,
- meta,
- GNUNET_NO,
- &bo);
+ "publish-context",
+ FILESIZE,
+ buf,
+ kuri, meta, GNUNET_NO,
&bo);
GNUNET_FS_uri_destroy (kuri);
GNUNET_CONTAINER_meta_data_destroy (meta);
GNUNET_assert (NULL != fi);
timeout_kill = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &timeout_kill_task,
- NULL);
+ &timeout_kill_task, NULL);
start = GNUNET_TIME_absolute_get ();
publish = GNUNET_FS_publish_start (fs,
- fi,
- NULL, NULL, NULL,
- GNUNET_FS_PUBLISH_OPTION_NONE);
+ fi,
+ NULL, NULL, NULL,
+ GNUNET_FS_PUBLISH_OPTION_NONE);
GNUNET_assert (publish != NULL);
}
@@ -343,7 +333,7 @@
int
main (int argc, char *argv[])
{
- char *const argvx[] = {
+ char *const argvx[] = {
"test-fs-download",
"-c",
"test_fs_download_data.conf",
@@ -356,16 +346,15 @@
GNUNET_GETOPT_OPTION_END
};
- GNUNET_log_setup ("test_fs_download",
+ GNUNET_log_setup ("test_fs_download",
#if VERBOSE
- "DEBUG",
+ "DEBUG",
#else
- "WARNING",
+ "WARNING",
#endif
- NULL);
+ NULL);
GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
- argvx, "test-fs-download",
- "nohelp", options, &run, NULL);
+ argvx, "test-fs-download", "nohelp", options, &run,
NULL);
stop_arm (&p1);
GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-download/");
return err;
Modified: gnunet/src/fs/test_fs_download_indexed.c
===================================================================
--- gnunet/src/fs/test_fs_download_indexed.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/fs/test_fs_download_indexed.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -46,7 +46,7 @@
/**
* How long should our test-content live?
- */
+ */
#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
struct PeerContext
@@ -76,55 +76,51 @@
static int err;
static void
-timeout_kill_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+timeout_kill_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
if (download != NULL)
- {
- GNUNET_FS_download_stop (download, GNUNET_YES);
- download = NULL;
- }
+ {
+ GNUNET_FS_download_stop (download, GNUNET_YES);
+ download = NULL;
+ }
else if (publish != NULL)
- {
- GNUNET_FS_publish_stop (publish);
- publish = NULL;
- }
+ {
+ GNUNET_FS_publish_stop (publish);
+ publish = NULL;
+ }
timeout_kill = GNUNET_SCHEDULER_NO_TASK;
err = 1;
}
static void
-abort_publish_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+abort_publish_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
if (publish != NULL)
- {
- GNUNET_FS_publish_stop (publish);
- publish = NULL;
- }
+ {
+ GNUNET_FS_publish_stop (publish);
+ publish = NULL;
+ }
}
static void
-stop_fs_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+stop_fs_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GNUNET_FS_stop (fs);
fs = NULL;
}
static void
-abort_download_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+abort_download_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
uint64_t size;
-
+
if (download != NULL)
- {
- GNUNET_FS_download_stop (download, GNUNET_YES);
- download = NULL;
- }
+ {
+ GNUNET_FS_download_stop (download, GNUNET_YES);
+ download = NULL;
+ }
GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_size (fn, &size, GNUNET_YES));
- GNUNET_assert (size == FILESIZE);
+ GNUNET_assert (size == FILESIZE);
GNUNET_DISK_directory_remove (fn);
GNUNET_free (fn);
fn = NULL;
@@ -134,115 +130,116 @@
static void *
-progress_cb (void *cls,
- const struct GNUNET_FS_ProgressInfo *event)
+progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
{
switch (event->status)
- {
- case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
+ {
+ case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
#if VERBOSE
- printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n",
- (unsigned long long) event->value.publish.completed,
- (unsigned long long) event->value.publish.size,
- event->value.publish.specifics.progress.depth,
- (unsigned long long)
event->value.publish.specifics.progress.offset);
-#endif
- break;
- case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
- printf ("Publishing complete, %llu kbps.\n",
- (unsigned long long) (FILESIZE * 1000LL /
(1+GNUNET_TIME_absolute_get_duration (start).rel_value) / 1024LL));
- GAUGER ("FS",
- "Publishing speed (indexing)",
- (unsigned long long) (FILESIZE * 1000LL /
(1+GNUNET_TIME_absolute_get_duration (start).rel_value) / 1024LL),
- "kb/s");
- fn = GNUNET_DISK_mktemp ("gnunet-download-test-dst");
- start = GNUNET_TIME_absolute_get ();
- download = GNUNET_FS_download_start (fs,
-
event->value.publish.specifics.completed.chk_uri,
- NULL,
- fn, NULL,
- 0,
- FILESIZE,
- 1,
- GNUNET_FS_DOWNLOAD_OPTION_NONE,
- "download",
- NULL);
- GNUNET_assert (download != NULL);
- break;
- case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
- printf ("Download complete, %llu kbps.\n",
- (unsigned long long) (FILESIZE * 1000LL /
(1+GNUNET_TIME_absolute_get_duration (start).rel_value) / 1024LL));
- GAUGER ("FS",
- "Local download speed (indexed)",
- (unsigned long long) (FILESIZE * 1000LL /
(1+GNUNET_TIME_absolute_get_duration (start).rel_value) / 1024LL),
- "kb/s");
- GNUNET_SCHEDULER_add_now (&abort_download_task,
- NULL);
- break;
- case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS:
- GNUNET_assert (download == event->value.download.dc);
+ printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n",
+ (unsigned long long) event->value.publish.completed,
+ (unsigned long long) event->value.publish.size,
+ event->value.publish.specifics.progress.depth,
+ (unsigned long long) event->value.publish.specifics.
+ progress.offset);
+#endif
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
+ printf ("Publishing complete, %llu kbps.\n",
+ (unsigned long long) (FILESIZE * 1000LL /
+ (1 +
+ GNUNET_TIME_absolute_get_duration
+ (start).rel_value) / 1024LL));
+ GAUGER ("FS", "Publishing speed (indexing)",
+ (unsigned long long) (FILESIZE * 1000LL /
+ (1 +
+ GNUNET_TIME_absolute_get_duration
+ (start).rel_value) / 1024LL), "kb/s");
+ fn = GNUNET_DISK_mktemp ("gnunet-download-test-dst");
+ start = GNUNET_TIME_absolute_get ();
+ download = GNUNET_FS_download_start (fs,
+ event->value.publish.
+ specifics.completed.chk_uri, NULL, fn,
+ NULL, 0, FILESIZE, 1,
+ GNUNET_FS_DOWNLOAD_OPTION_NONE,
+ "download", NULL);
+ GNUNET_assert (download != NULL);
+ break;
+ case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
+ printf ("Download complete, %llu kbps.\n",
+ (unsigned long long) (FILESIZE * 1000LL /
+ (1 +
+ GNUNET_TIME_absolute_get_duration
+ (start).rel_value) / 1024LL));
+ GAUGER ("FS", "Local download speed (indexed)",
+ (unsigned long long) (FILESIZE * 1000LL /
+ (1 +
+ GNUNET_TIME_absolute_get_duration
+ (start).rel_value) / 1024LL), "kb/s");
+ GNUNET_SCHEDULER_add_now (&abort_download_task, NULL);
+ break;
+ case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS:
+ GNUNET_assert (download == event->value.download.dc);
#if VERBOSE
- printf ("Download is progressing (%llu/%llu at level %u off %llu)...\n",
- (unsigned long long) event->value.download.completed,
- (unsigned long long) event->value.download.size,
- event->value.download.specifics.progress.depth,
- (unsigned long long)
event->value.download.specifics.progress.offset);
+ printf ("Download is progressing (%llu/%llu at level %u off %llu)...\n",
+ (unsigned long long) event->value.download.completed,
+ (unsigned long long) event->value.download.size,
+ event->value.download.specifics.progress.depth,
+ (unsigned long long) event->value.download.specifics.
+ progress.offset);
#endif
- break;
- case GNUNET_FS_STATUS_PUBLISH_ERROR:
- fprintf (stderr,
- "Error publishing file: %s\n",
- event->value.publish.specifics.error.message);
- GNUNET_break (0);
- GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
- NULL,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- break;
- case GNUNET_FS_STATUS_DOWNLOAD_ERROR:
- fprintf (stderr,
- "Error downloading file: %s\n",
- event->value.download.specifics.error.message);
- GNUNET_SCHEDULER_add_now (&abort_download_task,
- NULL);
- break;
- case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE:
- case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE:
- break;
- case GNUNET_FS_STATUS_PUBLISH_START:
- GNUNET_assert (0 == strcmp ("publish-context",
event->value.publish.cctx));
- GNUNET_assert (NULL == event->value.publish.pctx);
- GNUNET_assert (FILESIZE == event->value.publish.size);
- GNUNET_assert (0 == event->value.publish.completed);
- GNUNET_assert (1 == event->value.publish.anonymity);
- break;
- case GNUNET_FS_STATUS_PUBLISH_STOPPED:
- GNUNET_assert (publish == event->value.publish.pc);
- GNUNET_assert (FILESIZE == event->value.publish.size);
- GNUNET_assert (1 == event->value.publish.anonymity);
- GNUNET_SCHEDULER_add_now (&stop_fs_task,
- NULL);
- break;
- case GNUNET_FS_STATUS_DOWNLOAD_START:
- GNUNET_assert (0 == strcmp ("download", event->value.download.cctx));
- GNUNET_assert (NULL == event->value.download.pctx);
- GNUNET_assert (NULL != event->value.download.uri);
- GNUNET_assert (0 == strcmp (fn, event->value.download.filename));
- GNUNET_assert (FILESIZE == event->value.download.size);
- GNUNET_assert (0 == event->value.download.completed);
- GNUNET_assert (1 == event->value.download.anonymity);
- break;
- case GNUNET_FS_STATUS_DOWNLOAD_STOPPED:
- GNUNET_assert (download == event->value.download.dc);
- GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
- NULL,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- break;
- default:
- printf ("Unexpected event: %d\n",
- event->status);
- break;
- }
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_ERROR:
+ fprintf (stderr,
+ "Error publishing file: %s\n",
+ event->value.publish.specifics.error.message);
+ GNUNET_break (0);
+ GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
+ NULL,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ break;
+ case GNUNET_FS_STATUS_DOWNLOAD_ERROR:
+ fprintf (stderr,
+ "Error downloading file: %s\n",
+ event->value.download.specifics.error.message);
+ GNUNET_SCHEDULER_add_now (&abort_download_task, NULL);
+ break;
+ case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE:
+ case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE:
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_START:
+ GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx));
+ GNUNET_assert (NULL == event->value.publish.pctx);
+ GNUNET_assert (FILESIZE == event->value.publish.size);
+ GNUNET_assert (0 == event->value.publish.completed);
+ GNUNET_assert (1 == event->value.publish.anonymity);
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_STOPPED:
+ GNUNET_assert (publish == event->value.publish.pc);
+ GNUNET_assert (FILESIZE == event->value.publish.size);
+ GNUNET_assert (1 == event->value.publish.anonymity);
+ GNUNET_SCHEDULER_add_now (&stop_fs_task, NULL);
+ break;
+ case GNUNET_FS_STATUS_DOWNLOAD_START:
+ GNUNET_assert (0 == strcmp ("download", event->value.download.cctx));
+ GNUNET_assert (NULL == event->value.download.pctx);
+ GNUNET_assert (NULL != event->value.download.uri);
+ GNUNET_assert (0 == strcmp (fn, event->value.download.filename));
+ GNUNET_assert (FILESIZE == event->value.download.size);
+ GNUNET_assert (0 == event->value.download.completed);
+ GNUNET_assert (1 == event->value.download.anonymity);
+ break;
+ case GNUNET_FS_STATUS_DOWNLOAD_STOPPED:
+ GNUNET_assert (download == event->value.download.dc);
+ GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
+ NULL,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ break;
+ default:
+ printf ("Unexpected event: %d\n", event->status);
+ break;
+ }
return NULL;
}
@@ -253,11 +250,11 @@
p->cfg = GNUNET_CONFIGURATION_create ();
#if START_ARM
p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
- "gnunet-service-arm",
+ "gnunet-service-arm",
#if VERBOSE
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", cfgname, NULL);
+ "-c", cfgname, NULL);
#endif
GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
}
@@ -268,16 +265,17 @@
{
#if START_ARM
if (NULL != p->arm_proc)
- {
- if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
- if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK)
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "ARM process %u stopped\n", GNUNET_OS_process_get_pid
(p->arm_proc));
- GNUNET_OS_process_close (p->arm_proc);
- p->arm_proc = NULL;
- }
+ {
+ if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
+ if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "ARM process %u stopped\n",
+ GNUNET_OS_process_get_pid (p->arm_proc));
+ GNUNET_OS_process_close (p->arm_proc);
+ p->arm_proc = NULL;
+ }
#endif
GNUNET_CONFIGURATION_destroy (p->cfg);
}
@@ -286,8 +284,7 @@
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
const char *keywords[] = {
"down_foo",
@@ -302,47 +299,43 @@
setup_peer (&p1, "test_fs_download_data.conf");
fs = GNUNET_FS_start (cfg,
- "test-fs-download-indexed",
- &progress_cb,
- NULL,
- GNUNET_FS_FLAGS_NONE,
- GNUNET_FS_OPTIONS_END);
- GNUNET_assert (NULL != fs);
+ "test-fs-download-indexed",
+ &progress_cb,
+ NULL, GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
+ GNUNET_assert (NULL != fs);
fn1 = GNUNET_DISK_mktemp ("gnunet-download-indexed-test");
buf = GNUNET_malloc (FILESIZE);
for (i = 0; i < FILESIZE; i++)
buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
GNUNET_assert (FILESIZE ==
- GNUNET_DISK_fn_write (fn1,
- buf,
- FILESIZE,
- GNUNET_DISK_PERM_USER_READ |
GNUNET_DISK_PERM_USER_WRITE));
+ GNUNET_DISK_fn_write (fn1,
+ buf,
+ FILESIZE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE));
GNUNET_free (buf);
meta = GNUNET_CONTAINER_meta_data_create ();
kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords);
bo.content_priority = 42;
bo.anonymity_level = 1;
bo.replication_level = 0;
- bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
+ bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
fi = GNUNET_FS_file_information_create_from_file (fs,
- "publish-context",
- fn1,
- kuri,
- meta,
- GNUNET_YES,
- &bo);
+ "publish-context",
+ fn1,
+ kuri,
+ meta, GNUNET_YES, &bo);
GNUNET_FS_uri_destroy (kuri);
GNUNET_CONTAINER_meta_data_destroy (meta);
GNUNET_assert (NULL != fi);
timeout_kill = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &timeout_kill_task,
- NULL);
+ &timeout_kill_task, NULL);
start = GNUNET_TIME_absolute_get ();
publish = GNUNET_FS_publish_start (fs,
- fi,
- NULL, NULL, NULL,
- GNUNET_FS_PUBLISH_OPTION_NONE);
+ fi,
+ NULL, NULL, NULL,
+ GNUNET_FS_PUBLISH_OPTION_NONE);
GNUNET_assert (publish != NULL);
}
@@ -350,7 +343,7 @@
int
main (int argc, char *argv[])
{
- char *const argvx[] = {
+ char *const argvx[] = {
"test-fs-download-indexed",
"-c",
"test_fs_download_data.conf",
@@ -363,27 +356,27 @@
GNUNET_GETOPT_OPTION_END
};
- GNUNET_log_setup ("test_fs_download_indexed",
+ GNUNET_log_setup ("test_fs_download_indexed",
#if VERBOSE
- "DEBUG",
+ "DEBUG",
#else
- "WARNING",
+ "WARNING",
#endif
- NULL);
+ NULL);
GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
argvx, "test-fs-download-indexed",
- "nohelp", options, &run, NULL);
+ "nohelp", options, &run, NULL);
stop_arm (&p1);
if (fn1 != NULL)
- {
- GNUNET_DISK_directory_remove (fn1);
- GNUNET_free (fn1);
- }
+ {
+ GNUNET_DISK_directory_remove (fn1);
+ GNUNET_free (fn1);
+ }
if (fn != NULL)
- {
- GNUNET_DISK_directory_remove (fn);
- GNUNET_free (fn);
- }
+ {
+ GNUNET_DISK_directory_remove (fn);
+ GNUNET_free (fn);
+ }
GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-download/");
return err;
}
Modified: gnunet/src/fs/test_fs_download_persistence.c
===================================================================
--- gnunet/src/fs/test_fs_download_persistence.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/fs/test_fs_download_persistence.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -45,7 +45,7 @@
/**
* How long should our test-content live?
- */
+ */
#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
struct PeerContext
@@ -75,50 +75,46 @@
static int err;
static void
-timeout_kill_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+timeout_kill_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Timeout downloading file\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Timeout downloading file\n");
if (download != NULL)
- {
- GNUNET_FS_download_stop (download, GNUNET_YES);
- download = NULL;
- }
+ {
+ GNUNET_FS_download_stop (download, GNUNET_YES);
+ download = NULL;
+ }
else if (publish != NULL)
- {
- GNUNET_FS_publish_stop (publish);
- publish = NULL;
- }
+ {
+ GNUNET_FS_publish_stop (publish);
+ publish = NULL;
+ }
timeout_kill = GNUNET_SCHEDULER_NO_TASK;
err = 1;
}
static void
-abort_publish_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+abort_publish_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
if (publish != NULL)
- {
- GNUNET_FS_publish_stop (publish);
- publish = NULL;
- }
+ {
+ GNUNET_FS_publish_stop (publish);
+ publish = NULL;
+ }
}
static void
-abort_download_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+abort_download_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
uint64_t size;
-
+
if (download != NULL)
- {
- GNUNET_FS_download_stop (download, GNUNET_YES);
- download = NULL;
- }
+ {
+ GNUNET_FS_download_stop (download, GNUNET_YES);
+ download = NULL;
+ }
GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_size (fn, &size, GNUNET_YES));
- GNUNET_assert (size == FILESIZE);
+ GNUNET_assert (size == FILESIZE);
GNUNET_DISK_directory_remove (fn);
GNUNET_free (fn);
fn = NULL;
@@ -127,24 +123,20 @@
}
-static void *
-progress_cb (void *cls,
- const struct GNUNET_FS_ProgressInfo *event);
+static void *progress_cb (void *cls,
+ const struct GNUNET_FS_ProgressInfo *event);
static void
-restart_fs_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+restart_fs_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Restarting FS.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Restarting FS.\n");
GNUNET_FS_stop (fs);
fs = GNUNET_FS_start (cfg,
- "test-fs-download-persistence",
- &progress_cb,
- NULL,
- GNUNET_FS_FLAGS_PERSISTENCE,
- GNUNET_FS_OPTIONS_END);
+ "test-fs-download-persistence",
+ &progress_cb,
+ NULL,
+ GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END);
}
@@ -161,152 +153,149 @@
static int prev[32];
static int off;
int i;
- for (i=0;i<off;i++)
+
+ for (i = 0; i < off; i++)
if (prev[i] == ev)
return;
prev[off++] = ev;
GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_URGENT,
- &restart_fs_task,
- NULL);
+ &restart_fs_task, NULL);
}
static void *
-progress_cb (void *cls,
- const struct GNUNET_FS_ProgressInfo *event)
+progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
{
switch (event->status)
- {
- case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
+ {
+ case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
#if VERBOSE
- printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n",
- (unsigned long long) event->value.publish.completed,
- (unsigned long long) event->value.publish.size,
- event->value.publish.specifics.progress.depth,
- (unsigned long long)
event->value.publish.specifics.progress.offset);
-#endif
- break;
- case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
- printf ("Publishing complete, %llu kbps.\n",
- (unsigned long long) (FILESIZE * 1000LL /
(1+GNUNET_TIME_absolute_get_duration (start).rel_value) / 1024LL));
- fn = GNUNET_DISK_mktemp ("gnunet-download-test-dst");
- start = GNUNET_TIME_absolute_get ();
- GNUNET_assert (download == NULL);
- GNUNET_FS_download_start (fs,
-
event->value.publish.specifics.completed.chk_uri,
- NULL,
- fn, NULL,
- 0,
- FILESIZE,
- 1,
- GNUNET_FS_DOWNLOAD_OPTION_NONE,
- "download",
- NULL);
- break;
- case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
- consider_restart (event->status);
- printf ("Download complete, %llu kbps.\n",
- (unsigned long long) (FILESIZE * 1000LL /
(1+GNUNET_TIME_absolute_get_duration (start).rel_value) / 1024LL));
- GNUNET_SCHEDULER_add_now (&abort_download_task,
- NULL);
- break;
- case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS:
- consider_restart (event->status);
- GNUNET_assert (download == event->value.download.dc);
+ printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n",
+ (unsigned long long) event->value.publish.completed,
+ (unsigned long long) event->value.publish.size,
+ event->value.publish.specifics.progress.depth,
+ (unsigned long long) event->value.publish.specifics.
+ progress.offset);
+#endif
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
+ printf ("Publishing complete, %llu kbps.\n",
+ (unsigned long long) (FILESIZE * 1000LL /
+ (1 +
+ GNUNET_TIME_absolute_get_duration
+ (start).rel_value) / 1024LL));
+ fn = GNUNET_DISK_mktemp ("gnunet-download-test-dst");
+ start = GNUNET_TIME_absolute_get ();
+ GNUNET_assert (download == NULL);
+ GNUNET_FS_download_start (fs,
+ event->value.publish.specifics.completed.chk_uri,
+ NULL,
+ fn, NULL,
+ 0,
+ FILESIZE,
+ 1,
+ GNUNET_FS_DOWNLOAD_OPTION_NONE, "download",
NULL);
+ break;
+ case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
+ consider_restart (event->status);
+ printf ("Download complete, %llu kbps.\n",
+ (unsigned long long) (FILESIZE * 1000LL /
+ (1 +
+ GNUNET_TIME_absolute_get_duration
+ (start).rel_value) / 1024LL));
+ GNUNET_SCHEDULER_add_now (&abort_download_task, NULL);
+ break;
+ case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS:
+ consider_restart (event->status);
+ GNUNET_assert (download == event->value.download.dc);
#if VERBOSE
- printf ("Download is progressing (%llu/%llu at level %u off %llu)...\n",
- (unsigned long long) event->value.download.completed,
- (unsigned long long) event->value.download.size,
- event->value.download.specifics.progress.depth,
- (unsigned long long)
event->value.download.specifics.progress.offset);
+ printf ("Download is progressing (%llu/%llu at level %u off %llu)...\n",
+ (unsigned long long) event->value.download.completed,
+ (unsigned long long) event->value.download.size,
+ event->value.download.specifics.progress.depth,
+ (unsigned long long) event->value.download.specifics.
+ progress.offset);
#endif
- break;
- case GNUNET_FS_STATUS_PUBLISH_ERROR:
- fprintf (stderr,
- "Error publishing file: %s\n",
- event->value.publish.specifics.error.message);
- GNUNET_break (0);
- GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
- NULL,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- break;
- case GNUNET_FS_STATUS_DOWNLOAD_ERROR:
- fprintf (stderr,
- "Error downloading file: %s\n",
- event->value.download.specifics.error.message);
- GNUNET_SCHEDULER_add_now (&abort_download_task,
- NULL);
- break;
- case GNUNET_FS_STATUS_PUBLISH_SUSPEND:
- GNUNET_assert (event->value.publish.pc == publish);
- publish = NULL;
- break;
- case GNUNET_FS_STATUS_PUBLISH_RESUME:
- GNUNET_assert (NULL == publish);
- publish = event->value.publish.pc;
- break;
- case GNUNET_FS_STATUS_DOWNLOAD_SUSPEND:
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Download suspended.\n");
- GNUNET_assert (event->value.download.dc == download);
- download = NULL;
- break;
- case GNUNET_FS_STATUS_DOWNLOAD_RESUME:
- GNUNET_assert (NULL == download);
- download = event->value.download.dc;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Download resumed.\n");
- break;
- case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE:
- consider_restart (event->status);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Download active.\n");
- break;
- case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE:
- consider_restart (event->status);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Download inactive.\n");
- break;
- case GNUNET_FS_STATUS_PUBLISH_START:
- GNUNET_assert (0 == strcmp ("publish-context",
event->value.publish.cctx));
- GNUNET_assert (NULL == event->value.publish.pctx);
- GNUNET_assert (FILESIZE == event->value.publish.size);
- GNUNET_assert (0 == event->value.publish.completed);
- GNUNET_assert (1 == event->value.publish.anonymity);
- break;
- case GNUNET_FS_STATUS_PUBLISH_STOPPED:
- GNUNET_assert (publish == event->value.publish.pc);
- GNUNET_assert (FILESIZE == event->value.publish.size);
- GNUNET_assert (1 == event->value.publish.anonymity);
- GNUNET_FS_stop (fs);
- fs = NULL;
- break;
- case GNUNET_FS_STATUS_DOWNLOAD_START:
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Download started.\n");
- consider_restart (event->status);
- GNUNET_assert (download == NULL);
- download = event->value.download.dc;
- GNUNET_assert (0 == strcmp ("download", event->value.download.cctx));
- GNUNET_assert (NULL == event->value.download.pctx);
- GNUNET_assert (NULL != event->value.download.uri);
- GNUNET_assert (0 == strcmp (fn, event->value.download.filename));
- GNUNET_assert (FILESIZE == event->value.download.size);
- GNUNET_assert (0 == event->value.download.completed);
- GNUNET_assert (1 == event->value.download.anonymity);
- break;
- case GNUNET_FS_STATUS_DOWNLOAD_STOPPED:
- GNUNET_assert (download == event->value.download.dc);
- GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
- NULL,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- download = NULL;
- break;
- default:
- printf ("Unexpected event: %d\n",
- event->status);
- break;
- }
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_ERROR:
+ fprintf (stderr,
+ "Error publishing file: %s\n",
+ event->value.publish.specifics.error.message);
+ GNUNET_break (0);
+ GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
+ NULL,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ break;
+ case GNUNET_FS_STATUS_DOWNLOAD_ERROR:
+ fprintf (stderr,
+ "Error downloading file: %s\n",
+ event->value.download.specifics.error.message);
+ GNUNET_SCHEDULER_add_now (&abort_download_task, NULL);
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_SUSPEND:
+ GNUNET_assert (event->value.publish.pc == publish);
+ publish = NULL;
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_RESUME:
+ GNUNET_assert (NULL == publish);
+ publish = event->value.publish.pc;
+ break;
+ case GNUNET_FS_STATUS_DOWNLOAD_SUSPEND:
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download suspended.\n");
+ GNUNET_assert (event->value.download.dc == download);
+ download = NULL;
+ break;
+ case GNUNET_FS_STATUS_DOWNLOAD_RESUME:
+ GNUNET_assert (NULL == download);
+ download = event->value.download.dc;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download resumed.\n");
+ break;
+ case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE:
+ consider_restart (event->status);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download active.\n");
+ break;
+ case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE:
+ consider_restart (event->status);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download inactive.\n");
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_START:
+ GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx));
+ GNUNET_assert (NULL == event->value.publish.pctx);
+ GNUNET_assert (FILESIZE == event->value.publish.size);
+ GNUNET_assert (0 == event->value.publish.completed);
+ GNUNET_assert (1 == event->value.publish.anonymity);
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_STOPPED:
+ GNUNET_assert (publish == event->value.publish.pc);
+ GNUNET_assert (FILESIZE == event->value.publish.size);
+ GNUNET_assert (1 == event->value.publish.anonymity);
+ GNUNET_FS_stop (fs);
+ fs = NULL;
+ break;
+ case GNUNET_FS_STATUS_DOWNLOAD_START:
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download started.\n");
+ consider_restart (event->status);
+ GNUNET_assert (download == NULL);
+ download = event->value.download.dc;
+ GNUNET_assert (0 == strcmp ("download", event->value.download.cctx));
+ GNUNET_assert (NULL == event->value.download.pctx);
+ GNUNET_assert (NULL != event->value.download.uri);
+ GNUNET_assert (0 == strcmp (fn, event->value.download.filename));
+ GNUNET_assert (FILESIZE == event->value.download.size);
+ GNUNET_assert (0 == event->value.download.completed);
+ GNUNET_assert (1 == event->value.download.anonymity);
+ break;
+ case GNUNET_FS_STATUS_DOWNLOAD_STOPPED:
+ GNUNET_assert (download == event->value.download.dc);
+ GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
+ NULL,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ download = NULL;
+ break;
+ default:
+ printf ("Unexpected event: %d\n", event->status);
+ break;
+ }
return NULL;
}
@@ -317,11 +306,11 @@
p->cfg = GNUNET_CONFIGURATION_create ();
#if START_ARM
p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
- "gnunet-service-arm",
+ "gnunet-service-arm",
#if VERBOSE
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", cfgname, NULL);
+ "-c", cfgname, NULL);
#endif
GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
}
@@ -332,16 +321,17 @@
{
#if START_ARM
if (NULL != p->arm_proc)
- {
- if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
- if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK)
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "ARM process %u stopped\n", GNUNET_OS_process_get_pid
(p->arm_proc));
- GNUNET_OS_process_close (p->arm_proc);
- p->arm_proc = NULL;
- }
+ {
+ if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
+ if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "ARM process %u stopped\n",
+ GNUNET_OS_process_get_pid (p->arm_proc));
+ GNUNET_OS_process_close (p->arm_proc);
+ p->arm_proc = NULL;
+ }
#endif
GNUNET_CONFIGURATION_destroy (p->cfg);
}
@@ -350,8 +340,7 @@
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *c)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
{
const char *keywords[] = {
"down_foo",
@@ -367,12 +356,11 @@
cfg = c;
setup_peer (&p1, "test_fs_download_data.conf");
fs = GNUNET_FS_start (cfg,
- "test-fs-download-persistence",
- &progress_cb,
- NULL,
- GNUNET_FS_FLAGS_PERSISTENCE,
- GNUNET_FS_OPTIONS_END);
- GNUNET_assert (NULL != fs);
+ "test-fs-download-persistence",
+ &progress_cb,
+ NULL,
+ GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END);
+ GNUNET_assert (NULL != fs);
buf = GNUNET_malloc (FILESIZE);
for (i = 0; i < FILESIZE; i++)
buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
@@ -381,26 +369,22 @@
bo.content_priority = 42;
bo.anonymity_level = 1;
bo.replication_level = 0;
- bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
+ bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
fi = GNUNET_FS_file_information_create_from_data (fs,
- "publish-context",
- FILESIZE,
- buf,
- kuri,
- meta,
- GNUNET_NO,
- &bo);
+ "publish-context",
+ FILESIZE,
+ buf,
+ kuri, meta, GNUNET_NO,
&bo);
GNUNET_FS_uri_destroy (kuri);
GNUNET_CONTAINER_meta_data_destroy (meta);
GNUNET_assert (NULL != fi);
timeout_kill = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &timeout_kill_task,
- NULL);
+ &timeout_kill_task, NULL);
start = GNUNET_TIME_absolute_get ();
publish = GNUNET_FS_publish_start (fs,
- fi,
- NULL, NULL, NULL,
- GNUNET_FS_PUBLISH_OPTION_NONE);
+ fi,
+ NULL, NULL, NULL,
+ GNUNET_FS_PUBLISH_OPTION_NONE);
GNUNET_assert (publish != NULL);
}
@@ -408,7 +392,7 @@
int
main (int argc, char *argv[])
{
- char *const argvx[] = {
+ char *const argvx[] = {
"test-fs-download-persistence",
"-c",
"test_fs_download_data.conf",
@@ -420,17 +404,17 @@
struct GNUNET_GETOPT_CommandLineOption options[] = {
GNUNET_GETOPT_OPTION_END
};
- GNUNET_log_setup ("test_fs_download_persistence",
+ GNUNET_log_setup ("test_fs_download_persistence",
#if VERBOSE
- "DEBUG",
+ "DEBUG",
#else
- "WARNING",
+ "WARNING",
#endif
- NULL);
+ NULL);
GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-download/");
GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
argvx, "test-fs-download-persistence",
- "nohelp", options, &run, NULL);
+ "nohelp", options, &run, NULL);
stop_arm (&p1);
GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-download/");
return err;
Modified: gnunet/src/fs/test_fs_download_recursive.c
===================================================================
--- gnunet/src/fs/test_fs_download_recursive.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/fs/test_fs_download_recursive.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -46,10 +46,9 @@
{
char *fn;
- fn =
- GNUNET_malloc (strlen
- ("/tmp/gnunet-fsui-recursive_download_test/FSUITEST") +
- 15);
+ fn = GNUNET_malloc (strlen
+ ("/tmp/gnunet-fsui-recursive_download_test/FSUITEST") +
+ 15);
GNUNET_snprintf (fn,
strlen
("/tmp/gnunet-fsui-recursive_download_test/FSUITEST") + 15,
@@ -68,56 +67,56 @@
fi = 0;
done = 0;
while (!done && tree[index] != '\0')
+ {
+ s = GNUNET_malloc (strlen (current) + strlen (DIR_SEPARATOR_STR) + 14);
+ GNUNET_snprintf (s, strlen (current) + strlen (DIR_SEPARATOR_STR) + 14,
+ "%s%s%u", current, DIR_SEPARATOR_STR, fi);
+ switch (tree[index++])
{
- s = GNUNET_malloc (strlen (current) + strlen (DIR_SEPARATOR_STR) + 14);
- GNUNET_snprintf (s, strlen (current) + strlen (DIR_SEPARATOR_STR) + 14,
- "%s%s%u", current, DIR_SEPARATOR_STR, fi);
- switch (tree[index++])
+ case 'd':
+ if (check)
+ {
+ if (GNUNET_disk_directory_test (NULL, s) == GNUNET_NO)
{
- case 'd':
- if (check)
- {
- if (GNUNET_disk_directory_test (NULL, s) == GNUNET_NO)
- {
- index = -1;
- done = 1;
- }
- }
- else
- {
- GNUNET_disk_directory_create (NULL, s);
- }
- if (!done)
- index = makeHierarchyHelper (s, tree, index, check);
- break;
- case 'f':
- if (check)
- {
- /* TODO: compare file contents */
- if (GNUNET_disk_directory_test (NULL, s) != GNUNET_NO)
- {
- index = -1;
- done = 1;
- }
- }
- else
- {
- buf = GNUNET_malloc (FILESIZE);
- for (i = 0; i < FILESIZE; i++)
- buf[i] = GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 256);
- GNUNET_disk_file_write (ectx, s, buf, FILESIZE, "600");
- GNUNET_free (buf);
- }
- break;
- case '.':
+ index = -1;
done = 1;
- break;
- default:
- break;
}
- GNUNET_free (s);
- fi++;
+ }
+ else
+ {
+ GNUNET_disk_directory_create (NULL, s);
+ }
+ if (!done)
+ index = makeHierarchyHelper (s, tree, index, check);
+ break;
+ case 'f':
+ if (check)
+ {
+ /* TODO: compare file contents */
+ if (GNUNET_disk_directory_test (NULL, s) != GNUNET_NO)
+ {
+ index = -1;
+ done = 1;
+ }
+ }
+ else
+ {
+ buf = GNUNET_malloc (FILESIZE);
+ for (i = 0; i < FILESIZE; i++)
+ buf[i] = GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 256);
+ GNUNET_disk_file_write (ectx, s, buf, FILESIZE, "600");
+ GNUNET_free (buf);
+ }
+ break;
+ case '.':
+ done = 1;
+ break;
+ default:
+ break;
}
+ GNUNET_free (s);
+ fi++;
+ }
return index;
}
@@ -139,10 +138,10 @@
fn = makeName (i);
if (GNUNET_disk_directory_test (NULL, fn) != GNUNET_YES)
- {
- GNUNET_free (fn);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_free (fn);
+ return GNUNET_SYSERR;
+ }
res = ((makeHierarchyHelper (fn, tree, 0, 1) == -1) ?
GNUNET_SYSERR : GNUNET_OK);
GNUNET_free (fn);
@@ -160,89 +159,87 @@
eventCallback (void *cls, const GNUNET_FSUI_Event * event)
{
switch (event->type)
- {
- case GNUNET_FSUI_download_suspended:
- download = NULL;
- break;
- case GNUNET_FSUI_download_resumed:
- download = event->data.DownloadResumed.dc.pos;
- break;
- break;
- case GNUNET_FSUI_upload_progress:
+ {
+ case GNUNET_FSUI_download_suspended:
+ download = NULL;
+ break;
+ case GNUNET_FSUI_download_resumed:
+ download = event->data.DownloadResumed.dc.pos;
+ break;
+ break;
+ case GNUNET_FSUI_upload_progress:
#if DEBUG_VERBOSE > 1
- printf ("Upload is progressing (%llu/%llu)...\n",
- event->data.UploadProgress.completed,
- event->data.UploadProgress.total);
+ printf ("Upload is progressing (%llu/%llu)...\n",
+ event->data.UploadProgress.completed,
+ event->data.UploadProgress.total);
#endif
- break;
- case GNUNET_FSUI_upload_completed:
- upURI = GNUNET_ECRS_uri_duplicate (event->data.UploadCompleted.uri);
+ break;
+ case GNUNET_FSUI_upload_completed:
+ upURI = GNUNET_ECRS_uri_duplicate (event->data.UploadCompleted.uri);
#if DEBUG_VERBOSE
- printf ("Upload of `%s' complete.\n",
- event->data.UploadCompleted.filename);
+ printf ("Upload of `%s' complete.\n",
event->data.UploadCompleted.filename);
#endif
- break;
- case GNUNET_FSUI_download_completed:
+ break;
+ case GNUNET_FSUI_download_completed:
#if DEBUG_VERBOSE
- printf ("Download of `%s' complete.\n",
- event->data.DownloadCompleted.filename);
+ printf ("Download of `%s' complete.\n",
+ event->data.DownloadCompleted.filename);
#endif
- if (checkHierarchy (43, DIRECTORY_TREE_SPEC) == GNUNET_OK)
- download_done = 1;
+ if (checkHierarchy (43, DIRECTORY_TREE_SPEC) == GNUNET_OK)
+ download_done = 1;
#if DEBUG_VERBOSE
- else
- printf ("Hierarchy check not successful yet...\n");
+ else
+ printf ("Hierarchy check not successful yet...\n");
#endif
- break;
- case GNUNET_FSUI_download_progress:
+ break;
+ case GNUNET_FSUI_download_progress:
#if DEBUG_VERBOSE > 1
- printf ("Download is progressing (%llu/%llu)...\n",
- event->data.DownloadProgress.completed,
- event->data.DownloadProgress.total);
+ printf ("Download is progressing (%llu/%llu)...\n",
+ event->data.DownloadProgress.completed,
+ event->data.DownloadProgress.total);
#endif
- break;
- case GNUNET_FSUI_unindex_progress:
+ break;
+ case GNUNET_FSUI_unindex_progress:
#if DEBUG_VERBOSE > 1
- printf ("Unindex is progressing (%llu/%llu)...\n",
- event->data.UnindexProgress.completed,
- event->data.UnindexProgress.total);
+ printf ("Unindex is progressing (%llu/%llu)...\n",
+ event->data.UnindexProgress.completed,
+ event->data.UnindexProgress.total);
#endif
- break;
- case GNUNET_FSUI_unindex_completed:
+ break;
+ case GNUNET_FSUI_unindex_completed:
#if DEBUG_VERBOSE
- printf ("Unindex complete.\n");
+ printf ("Unindex complete.\n");
#endif
- break;
- case GNUNET_FSUI_unindex_error:
- fprintf (stderr, "Error unindexing: %s\n",
- event->data.UnindexError.message);
- break;
- case GNUNET_FSUI_upload_error:
- fprintf (stderr, "Error uploading: %s\n",
- event->data.UploadError.message);
- break;
- case GNUNET_FSUI_download_error:
- fprintf (stderr, "Error downloading: %s\n",
- event->data.DownloadError.message);
- break;
- case GNUNET_FSUI_download_aborted:
+ break;
+ case GNUNET_FSUI_unindex_error:
+ fprintf (stderr, "Error unindexing: %s\n",
+ event->data.UnindexError.message);
+ break;
+ case GNUNET_FSUI_upload_error:
+ fprintf (stderr, "Error uploading: %s\n", event->data.UploadError.message);
+ break;
+ case GNUNET_FSUI_download_error:
+ fprintf (stderr, "Error downloading: %s\n",
+ event->data.DownloadError.message);
+ break;
+ case GNUNET_FSUI_download_aborted:
#if DEBUG_VERBOSE
- printf ("Received download aborted event.\n");
+ printf ("Received download aborted event.\n");
#endif
- break;
- case GNUNET_FSUI_unindex_suspended:
- case GNUNET_FSUI_upload_suspended:
- case GNUNET_FSUI_upload_started:
- case GNUNET_FSUI_upload_stopped:
- case GNUNET_FSUI_download_started:
- case GNUNET_FSUI_download_stopped:
- case GNUNET_FSUI_unindex_started:
- case GNUNET_FSUI_unindex_stopped:
- break;
- default:
- printf ("Unexpected event: %d\n", event->type);
- break;
- }
+ break;
+ case GNUNET_FSUI_unindex_suspended:
+ case GNUNET_FSUI_upload_suspended:
+ case GNUNET_FSUI_upload_started:
+ case GNUNET_FSUI_upload_stopped:
+ case GNUNET_FSUI_download_started:
+ case GNUNET_FSUI_download_stopped:
+ case GNUNET_FSUI_unindex_started:
+ case GNUNET_FSUI_unindex_stopped:
+ break;
+ default:
+ printf ("Unexpected event: %d\n", event->type);
+ break;
+ }
if (lastEvent == waitForEvent)
return NULL; /* ignore all other events */
lastEvent = event->type;
@@ -261,6 +258,7 @@
int ok;
char *fn = NULL;
char *fn43 = NULL;
+
char *keywords[] = {
"down_foo",
"down_bar",
@@ -274,20 +272,18 @@
ok = GNUNET_YES;
cfg = GNUNET_GC_create ();
if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf"))
- {
- GNUNET_GC_free (cfg);
- return -1;
- }
- fprintf(stderr,
- "Setup...\n");
+ {
+ GNUNET_GC_free (cfg);
+ return -1;
+ }
+ fprintf (stderr, "Setup...\n");
#if START_DAEMON
GNUNET_disk_directory_remove (NULL,
"/tmp/gnunet-fsui-recursive_download_test/");
daemon = GNUNET_daemon_start (NULL, cfg, "peer.conf", GNUNET_NO);
GNUNET_GE_ASSERT (NULL, daemon != NULL);
CHECK (GNUNET_OK ==
- GNUNET_wait_for_daemon_running (NULL, cfg,
- 30 * GNUNET_CRON_SECONDS));
+ GNUNET_wait_for_daemon_running (NULL, cfg, 30 * GNUNET_CRON_SECONDS));
GNUNET_thread_sleep (5 * GNUNET_CRON_SECONDS); /* give apps time to
start */
/* ACTUAL TEST CODE */
#endif
@@ -298,10 +294,9 @@
fn = makeHierarchy (42, DIRECTORY_TREE_SPEC);
meta = GNUNET_meta_data_create ();
kuri =
- GNUNET_ECRS_keyword_command_line_to_uri (ectx, 2,
- (const char **) keywords);
- fprintf(stderr,
- "Uploading...\n");
+ GNUNET_ECRS_keyword_command_line_to_uri (ectx, 2,
+ (const char **) keywords);
+ fprintf (stderr, "Uploading...\n");
waitForEvent = GNUNET_FSUI_upload_completed;
upload = GNUNET_FSUI_upload_start (ctx,
fn,
@@ -315,19 +310,18 @@
kuri = NULL;
prog = 0;
while (lastEvent != GNUNET_FSUI_upload_completed)
- {
- prog++;
- CHECK (prog < 5000);
- GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
- if (GNUNET_shutdown_test () == GNUNET_YES)
- break;
- }
+ {
+ prog++;
+ CHECK (prog < 5000);
+ GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
+ if (GNUNET_shutdown_test () == GNUNET_YES)
+ break;
+ }
GNUNET_FSUI_upload_stop (upload);
upload = NULL;
CHECK (upURI != NULL);
- fprintf(stderr,
- "Downloading...\n");
+ fprintf (stderr, "Downloading...\n");
waitForEvent = GNUNET_FSUI_download_completed;
fn43 = makeName (43);
download = GNUNET_FSUI_download_start (ctx,
@@ -339,29 +333,28 @@
fn43 = NULL;
prog = 0;
while (!download_done)
- {
- prog++;
- CHECK (prog < 5000);
- GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
- if (GNUNET_shutdown_test () == GNUNET_YES)
- break;
- }
+ {
+ prog++;
+ CHECK (prog < 5000);
+ GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
+ if (GNUNET_shutdown_test () == GNUNET_YES)
+ break;
+ }
FAILURE:
- fprintf(stderr,
- "Cleanup...\n");
+ fprintf (stderr, "Cleanup...\n");
if (meta != NULL)
GNUNET_meta_data_destroy (meta);
if (ctx != NULL)
- {
- if (download != NULL)
- GNUNET_FSUI_download_stop (download);
- GNUNET_FSUI_stop (ctx);
- }
+ {
+ if (download != NULL)
+ GNUNET_FSUI_download_stop (download);
+ GNUNET_FSUI_stop (ctx);
+ }
if (fn != NULL)
- {
- GNUNET_disk_directory_remove (NULL, fn);
- GNUNET_free (fn);
- }
+ {
+ GNUNET_disk_directory_remove (NULL, fn);
+ GNUNET_free (fn);
+ }
if (kuri != NULL)
GNUNET_ECRS_uri_destroy (kuri);
fn43 = makeName (43);
Modified: gnunet/src/fs/test_fs_file_information.c
===================================================================
--- gnunet/src/fs/test_fs_file_information.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/fs/test_fs_file_information.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -45,19 +45,17 @@
/**
* How long should our test-content live?
- */
+ */
#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
static int
-mycleaner(void *cls,
- struct GNUNET_FS_FileInformation *fi,
- uint64_t length,
- struct GNUNET_CONTAINER_MetaData *meta,
- struct GNUNET_FS_Uri **uri,
- struct GNUNET_FS_BlockOptions *bo,
- int *do_index,
- void **client_info)
+mycleaner (void *cls,
+ struct GNUNET_FS_FileInformation *fi,
+ uint64_t length,
+ struct GNUNET_CONTAINER_MetaData *meta,
+ struct GNUNET_FS_Uri **uri,
+ struct GNUNET_FS_BlockOptions *bo, int *do_index, void
**client_info)
{
return GNUNET_OK;
}
@@ -66,8 +64,7 @@
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
const char *keywords[] = {
"down_foo",
@@ -86,17 +83,17 @@
struct GNUNET_FS_BlockOptions bo;
fs = GNUNET_FS_start (cfg, "test-fs-file-information", NULL, NULL,
- GNUNET_FS_FLAGS_NONE,
- GNUNET_FS_OPTIONS_END);
+ GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
fn1 = GNUNET_DISK_mktemp ("gnunet-file_information-test-dst");
buf = GNUNET_malloc (FILESIZE);
for (i = 0; i < FILESIZE; i++)
buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
GNUNET_assert (FILESIZE ==
- GNUNET_DISK_fn_write (fn1,
- buf,
- FILESIZE,
- GNUNET_DISK_PERM_USER_READ |
GNUNET_DISK_PERM_USER_WRITE));
+ GNUNET_DISK_fn_write (fn1,
+ buf,
+ FILESIZE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE));
GNUNET_free (buf);
fn2 = GNUNET_DISK_mktemp ("gnunet-file_information-test-dst");
@@ -104,48 +101,41 @@
for (i = 0; i < FILESIZE; i++)
buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
GNUNET_assert (FILESIZE ==
- GNUNET_DISK_fn_write (fn2,
- buf,
- FILESIZE,
- GNUNET_DISK_PERM_USER_READ |
GNUNET_DISK_PERM_USER_WRITE));
+ GNUNET_DISK_fn_write (fn2,
+ buf,
+ FILESIZE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE));
GNUNET_free (buf);
meta = GNUNET_CONTAINER_meta_data_create ();
- kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords);
+ kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords);
bo.content_priority = 42;
bo.anonymity_level = 1;
bo.replication_level = 0;
- bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
+ bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
fi1 = GNUNET_FS_file_information_create_from_file (fs,
-
"file_information-context1",
- fn1,
- kuri,
- meta,
- GNUNET_YES,
- &bo);
+
"file_information-context1",
+ fn1,
+ kuri,
+ meta, GNUNET_YES, &bo);
GNUNET_assert (fi1 != NULL);
fi2 = GNUNET_FS_file_information_create_from_file (fs,
-
"file_information-context2",
- fn2,
- kuri,
- meta,
- GNUNET_YES,
- &bo);
+
"file_information-context2",
+ fn2,
+ kuri,
+ meta, GNUNET_YES, &bo);
GNUNET_assert (fi2 != NULL);
fidir = GNUNET_FS_file_information_create_empty_directory (fs,
-
"file_information-context-dir",
- kuri,
- meta,
- &bo);
+
"file_information-context-dir",
+ kuri, meta, &bo);
GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1));
GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2));
GNUNET_FS_uri_destroy (kuri);
GNUNET_CONTAINER_meta_data_destroy (meta);
GNUNET_assert (NULL != fidir);
/* FIXME: test more of API! */
- GNUNET_FS_file_information_destroy (fidir,
- &mycleaner,
- NULL);
+ GNUNET_FS_file_information_destroy (fidir, &mycleaner, NULL);
GNUNET_DISK_directory_remove (fn1);
GNUNET_DISK_directory_remove (fn2);
GNUNET_free_non_null (fn1);
@@ -164,45 +154,47 @@
size_t size;
char *date;
- ex = EXTRACTOR_plugin_add_config (NULL, "thumbnailgtk",
EXTRACTOR_OPTION_DEFAULT_POLICY);
+ ex = EXTRACTOR_plugin_add_config (NULL, "thumbnailgtk",
+ EXTRACTOR_OPTION_DEFAULT_POLICY);
if (ex == NULL)
- {
- fprintf (stderr,
- "Test incomplete, have no GTK thumbnail extractor
available.\n");
- return 0; /* can not test, no thumbnailer */
- }
- ex = EXTRACTOR_plugin_add_config (ex, "mime",
EXTRACTOR_OPTION_DEFAULT_POLICY);
+ {
+ fprintf (stderr,
+ "Test incomplete, have no GTK thumbnail extractor available.\n");
+ return 0; /* can not test, no thumbnailer */
+ }
+ ex = EXTRACTOR_plugin_add_config (ex, "mime",
+ EXTRACTOR_OPTION_DEFAULT_POLICY);
m = GNUNET_CONTAINER_meta_data_create ();
if (3 != GNUNET_FS_meta_data_extract_from_file (m,
-
"test_fs_file_information_meta_data_image.jpg",
- ex))
- {
- GNUNET_break (0);
- EXTRACTOR_plugin_remove_all (ex);
- GNUNET_CONTAINER_meta_data_destroy (m);
- return 1;
- }
+
"test_fs_file_information_meta_data_image.jpg",
+ ex))
+ {
+ GNUNET_break (0);
+ EXTRACTOR_plugin_remove_all (ex);
+ GNUNET_CONTAINER_meta_data_destroy (m);
+ return 1;
+ }
EXTRACTOR_plugin_remove_all (ex);
d = GNUNET_CONTAINER_meta_data_duplicate (m);
GNUNET_CONTAINER_meta_data_destroy (m);
thumb = NULL;
size = GNUNET_CONTAINER_meta_data_get_thumbnail (d, &thumb);
if (size == 0)
- {
- GNUNET_break (0);
- GNUNET_CONTAINER_meta_data_destroy (d);
- return 1;
- }
+ {
+ GNUNET_break (0);
+ GNUNET_CONTAINER_meta_data_destroy (d);
+ return 1;
+ }
GNUNET_free (thumb);
GNUNET_CONTAINER_meta_data_add_publication_date (d);
date = GNUNET_CONTAINER_meta_data_get_by_type (d,
EXTRACTOR_METATYPE_PUBLICATION_DATE);
if (date == NULL)
- {
- GNUNET_break (0);
- GNUNET_CONTAINER_meta_data_destroy (d);
- return 1;
- }
+ {
+ GNUNET_break (0);
+ GNUNET_CONTAINER_meta_data_destroy (d);
+ return 1;
+ }
GNUNET_free (date);
GNUNET_CONTAINER_meta_data_destroy (d);
return 0;
@@ -213,7 +205,7 @@
int
main (int argc, char *argv[])
{
- char *const argvx[] = {
+ char *const argvx[] = {
"test-fs-file_information",
"-c",
"test_fs_file_information_data.conf",
@@ -226,18 +218,18 @@
GNUNET_GETOPT_OPTION_END
};
- GNUNET_log_setup ("test_fs_file_information",
+ GNUNET_log_setup ("test_fs_file_information",
#if VERBOSE
- "DEBUG",
+ "DEBUG",
#else
- "WARNING",
+ "WARNING",
#endif
- NULL);
+ NULL);
if (0 != testThumbnail ())
return 1;
GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
argvx, "test-fs-file_information",
- "nohelp", options, &run, NULL);
+ "nohelp", options, &run, NULL);
return 0;
}
Modified: gnunet/src/fs/test_fs_getopt.c
===================================================================
--- gnunet/src/fs/test_fs_getopt.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/fs/test_fs_getopt.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -28,13 +28,13 @@
int
main (int argc, char *argv[])
{
- GNUNET_log_setup ("test_fs_directory",
+ GNUNET_log_setup ("test_fs_directory",
#if VERBOSE
- "DEBUG",
+ "DEBUG",
#else
- "WARNING",
+ "WARNING",
#endif
- NULL);
+ NULL);
fprintf (stderr, "WARNING: testcase not yet written.\n");
return 0; /* testcase passed */
}
Modified: gnunet/src/fs/test_fs_list_indexed.c
===================================================================
--- gnunet/src/fs/test_fs_list_indexed.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/fs/test_fs_list_indexed.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -49,7 +49,7 @@
/**
* How long should our test-content live?
- */
+ */
#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
struct PeerContext
@@ -75,8 +75,7 @@
static int err;
static void
-abort_publish_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+abort_publish_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GNUNET_FS_publish_stop (publish);
publish = NULL;
@@ -90,101 +89,96 @@
static void
-list_indexed_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+list_indexed_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
- NULL,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ NULL,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
}
static void *
-progress_cb (void *cls,
- const struct GNUNET_FS_ProgressInfo *event)
+progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
{
void *ret;
ret = NULL;
switch (event->status)
- {
- case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
- ret = event->value.publish.cctx;
- printf ("Publish complete, %llu kbps.\n",
- (unsigned long long) (FILESIZE * 1000 /
(1+GNUNET_TIME_absolute_get_duration (start).rel_value) / 1024));
- if (0 == strcmp ("list_indexed-context-dir",
- event->value.publish.cctx))
- GNUNET_SCHEDULER_add_continuation (&list_indexed_task,
- NULL,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
-
- break;
- case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
- ret = event->value.publish.cctx;
- GNUNET_assert (publish == event->value.publish.pc);
+ {
+ case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
+ ret = event->value.publish.cctx;
+ printf ("Publish complete, %llu kbps.\n",
+ (unsigned long long) (FILESIZE * 1000 /
+ (1 +
+ GNUNET_TIME_absolute_get_duration
+ (start).rel_value) / 1024));
+ if (0 == strcmp ("list_indexed-context-dir", event->value.publish.cctx))
+ GNUNET_SCHEDULER_add_continuation (&list_indexed_task,
+ NULL,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
+ ret = event->value.publish.cctx;
+ GNUNET_assert (publish == event->value.publish.pc);
#if VERBOSE
- printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n",
- (unsigned long long) event->value.publish.completed,
- (unsigned long long) event->value.publish.size,
- event->value.publish.specifics.progress.depth,
- (unsigned long long)
event->value.publish.specifics.progress.offset);
+ printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n",
+ (unsigned long long) event->value.publish.completed,
+ (unsigned long long) event->value.publish.size,
+ event->value.publish.specifics.progress.depth,
+ (unsigned long long) event->value.publish.specifics.
+ progress.offset);
#endif
- break;
- case GNUNET_FS_STATUS_PUBLISH_ERROR:
- ret = event->value.publish.cctx;
- fprintf (stderr,
- "Error publishing file: %s\n",
- event->value.publish.specifics.error.message);
- err = 1;
- if (0 == strcmp ("list_indexed-context-dir",
- event->value.publish.cctx))
- GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
- NULL,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- break;
- case GNUNET_FS_STATUS_PUBLISH_START:
- ret = event->value.publish.cctx;
- if (0 == strcmp ("list_indexed-context1",
- event->value.publish.cctx))
- {
- GNUNET_assert (0 == strcmp ("list_indexed-context-dir",
- event->value.publish.pctx));
- GNUNET_assert (FILESIZE == event->value.publish.size);
- GNUNET_assert (0 == event->value.publish.completed);
- GNUNET_assert (1 == event->value.publish.anonymity);
- }
- else if (0 == strcmp ("list_indexed-context2",
- event->value.publish.cctx))
- {
- GNUNET_assert (0 == strcmp ("list_indexed-context-dir",
- event->value.publish.pctx));
- GNUNET_assert (FILESIZE == event->value.publish.size);
- GNUNET_assert (0 == event->value.publish.completed);
- GNUNET_assert (2 == event->value.publish.anonymity);
- }
- else if (0 == strcmp ("list_indexed-context-dir",
- event->value.publish.cctx))
- {
- GNUNET_assert (0 == event->value.publish.completed);
- GNUNET_assert (3 == event->value.publish.anonymity);
- }
- else
- GNUNET_assert (0);
- break;
- case GNUNET_FS_STATUS_PUBLISH_STOPPED:
- if (0 == strcmp ("list_indexed-context-dir",
- event->value.publish.cctx))
- {
- GNUNET_assert (publish == event->value.publish.pc);
- publish = NULL;
- }
- break;
- default:
- printf ("Unexpected event: %d\n",
- event->status);
- break;
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_ERROR:
+ ret = event->value.publish.cctx;
+ fprintf (stderr,
+ "Error publishing file: %s\n",
+ event->value.publish.specifics.error.message);
+ err = 1;
+ if (0 == strcmp ("list_indexed-context-dir", event->value.publish.cctx))
+ GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
+ NULL,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_START:
+ ret = event->value.publish.cctx;
+ if (0 == strcmp ("list_indexed-context1", event->value.publish.cctx))
+ {
+ GNUNET_assert (0 == strcmp ("list_indexed-context-dir",
+ event->value.publish.pctx));
+ GNUNET_assert (FILESIZE == event->value.publish.size);
+ GNUNET_assert (0 == event->value.publish.completed);
+ GNUNET_assert (1 == event->value.publish.anonymity);
}
+ else if (0 == strcmp ("list_indexed-context2", event->value.publish.cctx))
+ {
+ GNUNET_assert (0 == strcmp ("list_indexed-context-dir",
+ event->value.publish.pctx));
+ GNUNET_assert (FILESIZE == event->value.publish.size);
+ GNUNET_assert (0 == event->value.publish.completed);
+ GNUNET_assert (2 == event->value.publish.anonymity);
+ }
+ else if (0 == strcmp ("list_indexed-context-dir",
+ event->value.publish.cctx))
+ {
+ GNUNET_assert (0 == event->value.publish.completed);
+ GNUNET_assert (3 == event->value.publish.anonymity);
+ }
+ else
+ GNUNET_assert (0);
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_STOPPED:
+ if (0 == strcmp ("list_indexed-context-dir", event->value.publish.cctx))
+ {
+ GNUNET_assert (publish == event->value.publish.pc);
+ publish = NULL;
+ }
+ break;
+ default:
+ printf ("Unexpected event: %d\n", event->status);
+ break;
+ }
return ret;
}
@@ -195,11 +189,11 @@
p->cfg = GNUNET_CONFIGURATION_create ();
#if START_ARM
p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
- "gnunet-service-arm",
+ "gnunet-service-arm",
#if VERBOSE
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", cfgname, NULL);
+ "-c", cfgname, NULL);
#endif
GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
}
@@ -210,16 +204,17 @@
{
#if START_ARM
if (NULL != p->arm_proc)
- {
- if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
- if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK)
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "ARM process %u stopped\n", GNUNET_OS_process_get_pid
(p->arm_proc));
- GNUNET_OS_process_close (p->arm_proc);
- p->arm_proc = NULL;
- }
+ {
+ if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
+ if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "ARM process %u stopped\n",
+ GNUNET_OS_process_get_pid (p->arm_proc));
+ GNUNET_OS_process_close (p->arm_proc);
+ p->arm_proc = NULL;
+ }
#endif
GNUNET_CONFIGURATION_destroy (p->cfg);
}
@@ -228,8 +223,7 @@
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
const char *keywords[] = {
"down_foo",
@@ -246,21 +240,20 @@
setup_peer (&p1, "test_fs_list_indexed_data.conf");
fs = GNUNET_FS_start (cfg,
- "test-fs-list_indexed",
- &progress_cb,
- NULL,
- GNUNET_FS_FLAGS_NONE,
- GNUNET_FS_OPTIONS_END);
- GNUNET_assert (NULL != fs);
+ "test-fs-list_indexed",
+ &progress_cb,
+ NULL, GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
+ GNUNET_assert (NULL != fs);
fn1 = GNUNET_DISK_mktemp ("gnunet-list_indexed-test-dst");
buf = GNUNET_malloc (FILESIZE);
for (i = 0; i < FILESIZE; i++)
buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
GNUNET_assert (FILESIZE ==
- GNUNET_DISK_fn_write (fn1,
- buf,
- FILESIZE,
- GNUNET_DISK_PERM_USER_READ |
GNUNET_DISK_PERM_USER_WRITE));
+ GNUNET_DISK_fn_write (fn1,
+ buf,
+ FILESIZE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE));
GNUNET_free (buf);
fn2 = GNUNET_DISK_mktemp ("gnunet-list_indexed-test-dst");
@@ -268,10 +261,11 @@
for (i = 0; i < FILESIZE; i++)
buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
GNUNET_assert (FILESIZE ==
- GNUNET_DISK_fn_write (fn2,
- buf,
- FILESIZE,
- GNUNET_DISK_PERM_USER_READ |
GNUNET_DISK_PERM_USER_WRITE));
+ GNUNET_DISK_fn_write (fn2,
+ buf,
+ FILESIZE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE));
GNUNET_free (buf);
meta = GNUNET_CONTAINER_meta_data_create ();
@@ -279,30 +273,24 @@
bo.content_priority = 42;
bo.anonymity_level = 1;
bo.replication_level = 0;
- bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
+ bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
fi1 = GNUNET_FS_file_information_create_from_file (fs,
- "list_indexed-context1",
- fn1,
- kuri,
- meta,
- GNUNET_YES,
- &bo);
+ "list_indexed-context1",
+ fn1,
+ kuri,
+ meta, GNUNET_YES, &bo);
GNUNET_assert (NULL != fi1);
bo.anonymity_level = 2;
fi2 = GNUNET_FS_file_information_create_from_file (fs,
- "list_indexed-context2",
- fn2,
- kuri,
- meta,
- GNUNET_YES,
- &bo);
+ "list_indexed-context2",
+ fn2,
+ kuri,
+ meta, GNUNET_YES, &bo);
GNUNET_assert (NULL != fi2);
bo.anonymity_level = 3;
fidir = GNUNET_FS_file_information_create_empty_directory (fs,
-
"list_indexed-context-dir",
- kuri,
- meta,
- &bo);
+
"list_indexed-context-dir",
+ kuri, meta, &bo);
GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1));
GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2));
GNUNET_FS_uri_destroy (kuri);
@@ -310,9 +298,9 @@
GNUNET_assert (NULL != fidir);
start = GNUNET_TIME_absolute_get ();
publish = GNUNET_FS_publish_start (fs,
- fidir,
- NULL, NULL, NULL,
- GNUNET_FS_PUBLISH_OPTION_NONE);
+ fidir,
+ NULL, NULL, NULL,
+ GNUNET_FS_PUBLISH_OPTION_NONE);
GNUNET_assert (publish != NULL);
}
@@ -320,7 +308,7 @@
int
main (int argc, char *argv[])
{
- char *const argvx[] = {
+ char *const argvx[] = {
"test-fs-list_indexed",
"-c",
"test_fs_list_indexed_data.conf",
@@ -333,28 +321,28 @@
GNUNET_GETOPT_OPTION_END
};
- GNUNET_log_setup ("test_fs_list_indexed",
+ GNUNET_log_setup ("test_fs_list_indexed",
#if VERBOSE
- "DEBUG",
+ "DEBUG",
#else
- "WARNING",
+ "WARNING",
#endif
- NULL);
+ NULL);
GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
argvx, "test-fs-list_indexed",
- "nohelp", options, &run, NULL);
+ "nohelp", options, &run, NULL);
stop_arm (&p1);
GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-list-indexed/");
if (fn1 != NULL)
- {
- GNUNET_DISK_directory_remove (fn1);
- GNUNET_free (fn1);
- }
+ {
+ GNUNET_DISK_directory_remove (fn1);
+ GNUNET_free (fn1);
+ }
if (fn2 != NULL)
- {
- GNUNET_DISK_directory_remove (fn2);
- GNUNET_free (fn2);
- }
+ {
+ GNUNET_DISK_directory_remove (fn2);
+ GNUNET_free (fn2);
+ }
return err;
}
Modified: gnunet/src/fs/test_fs_namespace.c
===================================================================
--- gnunet/src/fs/test_fs_namespace.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/fs/test_fs_namespace.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -67,11 +67,11 @@
p->cfg = GNUNET_CONFIGURATION_create ();
#if START_ARM
p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
- "gnunet-service-arm",
+ "gnunet-service-arm",
#if VERBOSE
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", cfgname, NULL);
+ "-c", cfgname, NULL);
#endif
GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
}
@@ -82,68 +82,64 @@
{
#if START_ARM
if (NULL != p->arm_proc)
- {
- if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
- if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK)
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "ARM process %u stopped\n", GNUNET_OS_process_get_pid
(p->arm_proc));
- GNUNET_OS_process_close (p->arm_proc);
- p->arm_proc = NULL;
- }
+ {
+ if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
+ if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "ARM process %u stopped\n",
+ GNUNET_OS_process_get_pid (p->arm_proc));
+ GNUNET_OS_process_close (p->arm_proc);
+ p->arm_proc = NULL;
+ }
#endif
GNUNET_CONFIGURATION_destroy (p->cfg);
}
static void
-abort_ksk_search_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+abort_ksk_search_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext
*tc)
{
if (ksk_search != NULL)
+ {
+ GNUNET_FS_search_stop (ksk_search);
+ ksk_search = NULL;
+ if (sks_search == NULL)
{
- GNUNET_FS_search_stop (ksk_search);
- ksk_search = NULL;
- if (sks_search == NULL)
- {
- GNUNET_FS_stop (fs);
- if (GNUNET_SCHEDULER_NO_TASK != kill_task)
- GNUNET_SCHEDULER_cancel (kill_task);
- }
+ GNUNET_FS_stop (fs);
+ if (GNUNET_SCHEDULER_NO_TASK != kill_task)
+ GNUNET_SCHEDULER_cancel (kill_task);
}
+ }
}
static void
-abort_sks_search_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+abort_sks_search_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext
*tc)
{
struct GNUNET_FS_Namespace *ns;
if (sks_search == NULL)
return;
- GNUNET_FS_search_stop (sks_search);
+ GNUNET_FS_search_stop (sks_search);
sks_search = NULL;
- ns = GNUNET_FS_namespace_create (fs,
- "testNamespace");
+ ns = GNUNET_FS_namespace_create (fs, "testNamespace");
GNUNET_assert (NULL != ns);
GNUNET_assert (GNUNET_OK == GNUNET_FS_namespace_delete (ns, GNUNET_YES));
if (ksk_search == NULL)
- {
- GNUNET_FS_stop (fs);
- if (GNUNET_SCHEDULER_NO_TASK != kill_task)
- GNUNET_SCHEDULER_cancel (kill_task);
- }
+ {
+ GNUNET_FS_stop (fs);
+ if (GNUNET_SCHEDULER_NO_TASK != kill_task)
+ GNUNET_SCHEDULER_cancel (kill_task);
+ }
}
static void
-do_timeout (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- fprintf (stderr,
- "Operation timed out\n");
+ fprintf (stderr, "Operation timed out\n");
kill_task = GNUNET_SCHEDULER_NO_TASK;
abort_sks_search_task (NULL, tc);
abort_ksk_search_task (NULL, tc);
@@ -152,134 +148,121 @@
static void *
-progress_cb (void *cls,
- const struct GNUNET_FS_ProgressInfo *event)
+progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
{
switch (event->status)
+ {
+ case GNUNET_FS_STATUS_SEARCH_RESULT:
+ if (sks_search == event->value.search.sc)
{
- case GNUNET_FS_STATUS_SEARCH_RESULT:
- if (sks_search == event->value.search.sc)
- {
- if (! GNUNET_FS_uri_test_equal (sks_expect_uri,
-
event->value.search.specifics.result.uri))
- {
- fprintf (stderr,
- "Wrong result for sks search!\n");
- err = 1;
- }
- /* give system 1ms to initiate update search! */
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
- &abort_sks_search_task,
- NULL);
- }
- else if (ksk_search == event->value.search.sc)
- {
- if (! GNUNET_FS_uri_test_equal (ksk_expect_uri,
-
event->value.search.specifics.result.uri))
- {
- fprintf (stderr,
- "Wrong result for ksk search!\n");
- err = 1;
- }
- GNUNET_SCHEDULER_add_continuation (&abort_ksk_search_task,
- NULL,
-
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- }
- else
- {
- fprintf (stderr,
- "Unexpected search result received!\n");
- GNUNET_break (0);
- }
- break;
- case GNUNET_FS_STATUS_SEARCH_ERROR:
- fprintf (stderr,
- "Error searching file: %s\n",
- event->value.search.specifics.error.message);
- if (sks_search == event->value.search.sc)
- GNUNET_SCHEDULER_add_continuation (&abort_sks_search_task,
- NULL,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- else if (ksk_search == event->value.search.sc)
- GNUNET_SCHEDULER_add_continuation (&abort_ksk_search_task,
- NULL,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- else
- GNUNET_break (0);
- break;
- case GNUNET_FS_STATUS_SEARCH_START:
- GNUNET_assert ( (NULL == event->value.search.cctx) ||
- (0 == strcmp ("sks_search", event->value.search.cctx)) ||
- (0 == strcmp ("ksk_search", event->value.search.cctx)));
- if (NULL == event->value.search.cctx)
- {
- GNUNET_assert (0 == strcmp ("sks_search", event->value.search.pctx));
- update_started = GNUNET_YES;
- }
- GNUNET_assert (1 == event->value.search.anonymity);
- break;
- case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED:
- return NULL;
- case GNUNET_FS_STATUS_SEARCH_STOPPED:
- return NULL;
- default:
- fprintf (stderr,
- "Unexpected event: %d\n",
- event->status);
- break;
+ if (!GNUNET_FS_uri_test_equal (sks_expect_uri,
+ event->value.search.specifics.result.uri))
+ {
+ fprintf (stderr, "Wrong result for sks search!\n");
+ err = 1;
+ }
+ /* give system 1ms to initiate update search! */
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
+ &abort_sks_search_task, NULL);
}
+ else if (ksk_search == event->value.search.sc)
+ {
+ if (!GNUNET_FS_uri_test_equal (ksk_expect_uri,
+ event->value.search.specifics.result.uri))
+ {
+ fprintf (stderr, "Wrong result for ksk search!\n");
+ err = 1;
+ }
+ GNUNET_SCHEDULER_add_continuation (&abort_ksk_search_task,
+ NULL,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ }
+ else
+ {
+ fprintf (stderr, "Unexpected search result received!\n");
+ GNUNET_break (0);
+ }
+ break;
+ case GNUNET_FS_STATUS_SEARCH_ERROR:
+ fprintf (stderr,
+ "Error searching file: %s\n",
+ event->value.search.specifics.error.message);
+ if (sks_search == event->value.search.sc)
+ GNUNET_SCHEDULER_add_continuation (&abort_sks_search_task,
+ NULL,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ else if (ksk_search == event->value.search.sc)
+ GNUNET_SCHEDULER_add_continuation (&abort_ksk_search_task,
+ NULL,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ else
+ GNUNET_break (0);
+ break;
+ case GNUNET_FS_STATUS_SEARCH_START:
+ GNUNET_assert ((NULL == event->value.search.cctx) ||
+ (0 == strcmp ("sks_search", event->value.search.cctx)) ||
+ (0 == strcmp ("ksk_search", event->value.search.cctx)));
+ if (NULL == event->value.search.cctx)
+ {
+ GNUNET_assert (0 == strcmp ("sks_search", event->value.search.pctx));
+ update_started = GNUNET_YES;
+ }
+ GNUNET_assert (1 == event->value.search.anonymity);
+ break;
+ case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED:
+ return NULL;
+ case GNUNET_FS_STATUS_SEARCH_STOPPED:
+ return NULL;
+ default:
+ fprintf (stderr, "Unexpected event: %d\n", event->status);
+ break;
+ }
return event->value.search.cctx;
}
static void
-publish_cont (void *cls,
- const struct GNUNET_FS_Uri *ksk_uri,
- const char *emsg)
+publish_cont (void *cls, const struct GNUNET_FS_Uri *ksk_uri, const char *emsg)
{
char *msg;
struct GNUNET_FS_Uri *sks_uri;
char sbuf[1024];
struct GNUNET_CRYPTO_HashAsciiEncoded enc;
-
+
if (NULL != emsg)
- {
- fprintf (stderr, "Error publishing: %s\n", emsg);
- err = 1;
- GNUNET_FS_stop (fs);
- return;
- }
- GNUNET_CRYPTO_hash_to_enc (&nsid,
- &enc);
- GNUNET_snprintf (sbuf,
- sizeof (sbuf),
- "gnunet://fs/sks/%s/this",
- &enc);
+ {
+ fprintf (stderr, "Error publishing: %s\n", emsg);
+ err = 1;
+ GNUNET_FS_stop (fs);
+ return;
+ }
+ GNUNET_CRYPTO_hash_to_enc (&nsid, &enc);
+ GNUNET_snprintf (sbuf, sizeof (sbuf), "gnunet://fs/sks/%s/this", &enc);
sks_uri = GNUNET_FS_uri_parse (sbuf, &msg);
if (msg != NULL)
- {
- fprintf (stderr, "failed to parse URI `%s': %s\n",
- sbuf,
- msg);
- err = 1;
- GNUNET_FS_stop (fs);
- GNUNET_free (msg);
- return;
- }
- ksk_search = GNUNET_FS_search_start (fs, ksk_uri, 1,
GNUNET_FS_SEARCH_OPTION_NONE, "ksk_search");
- sks_search = GNUNET_FS_search_start (fs, sks_uri, 1,
GNUNET_FS_SEARCH_OPTION_NONE, "sks_search");
+ {
+ fprintf (stderr, "failed to parse URI `%s': %s\n", sbuf, msg);
+ err = 1;
+ GNUNET_FS_stop (fs);
+ GNUNET_free (msg);
+ return;
+ }
+ ksk_search =
+ GNUNET_FS_search_start (fs, ksk_uri, 1, GNUNET_FS_SEARCH_OPTION_NONE,
+ "ksk_search");
+ sks_search =
+ GNUNET_FS_search_start (fs, sks_uri, 1, GNUNET_FS_SEARCH_OPTION_NONE,
+ "sks_search");
GNUNET_FS_uri_destroy (sks_uri);
}
static void
-sks_cont (void *cls,
- const struct GNUNET_FS_Uri *uri,
- const char *emsg)
+sks_cont (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg)
{
struct GNUNET_CONTAINER_MetaData *meta;
struct GNUNET_FS_Uri *ksk_uri;
- char * msg;
+ char *msg;
struct GNUNET_FS_BlockOptions bo;
meta = GNUNET_CONTAINER_meta_data_create ();
@@ -290,38 +273,30 @@
bo.content_priority = 1;
bo.anonymity_level = 1;
bo.replication_level = 0;
- bo.expiration_time = GNUNET_TIME_relative_to_absolute
(GNUNET_TIME_UNIT_MINUTES);
- GNUNET_FS_publish_ksk (fs,
- ksk_uri,
- meta,
- uri,
- &bo,
- GNUNET_FS_PUBLISH_OPTION_NONE,
- &publish_cont,
- NULL);
+ bo.expiration_time =
+ GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES);
+ GNUNET_FS_publish_ksk (fs, ksk_uri, meta, uri, &bo,
+ GNUNET_FS_PUBLISH_OPTION_NONE, &publish_cont, NULL);
GNUNET_FS_uri_destroy (ksk_uri);
GNUNET_CONTAINER_meta_data_destroy (meta);
}
static void
-adv_cont (void *cls,
- const struct GNUNET_FS_Uri *uri,
- const char *emsg)
+adv_cont (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg)
{
struct GNUNET_CONTAINER_MetaData *meta;
struct GNUNET_FS_Namespace *ns;
struct GNUNET_FS_BlockOptions bo;
if (NULL != emsg)
- {
- fprintf (stderr, "Error publishing: %s\n", emsg);
- err = 1;
- GNUNET_FS_stop (fs);
- return;
- }
- ns = GNUNET_FS_namespace_create (fs,
- "testNamespace");
+ {
+ fprintf (stderr, "Error publishing: %s\n", emsg);
+ err = 1;
+ GNUNET_FS_stop (fs);
+ return;
+ }
+ ns = GNUNET_FS_namespace_create (fs, "testNamespace");
GNUNET_assert (NULL != ns);
meta = GNUNET_CONTAINER_meta_data_create ();
GNUNET_assert (NULL == emsg);
@@ -329,31 +304,21 @@
bo.content_priority = 1;
bo.anonymity_level = 1;
bo.replication_level = 0;
- bo.expiration_time = GNUNET_TIME_relative_to_absolute
(GNUNET_TIME_UNIT_MINUTES);
- GNUNET_FS_publish_sks (fs,
- ns,
- "this",
- "next",
- meta,
- uri, /* FIXME: this is non-sense (use CHK URI!?) */
- &bo,
- GNUNET_FS_PUBLISH_OPTION_NONE,
- &sks_cont,
- NULL);
+ bo.expiration_time =
+ GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES);
+ GNUNET_FS_publish_sks (fs, ns, "this", "next", meta, uri, /* FIXME: this
is non-sense (use CHK URI!?) */
+ &bo, GNUNET_FS_PUBLISH_OPTION_NONE, &sks_cont, NULL);
GNUNET_CONTAINER_meta_data_destroy (meta);
GNUNET_FS_namespace_delete (ns, GNUNET_NO);
}
static void
-ns_iterator (void *cls,
- const char *name,
- const GNUNET_HashCode *id)
+ns_iterator (void *cls, const char *name, const GNUNET_HashCode * id)
{
int *ok = cls;
- if (0 != strcmp (name,
- "testNamespace"))
+ if (0 != strcmp (name, "testNamespace"))
return;
*ok = GNUNET_YES;
nsid = *id;
@@ -369,35 +334,30 @@
struct GNUNET_FS_Uri *ksk_uri;
int ok;
- ns = GNUNET_FS_namespace_create (fs,
- "testNamespace");
+ ns = GNUNET_FS_namespace_create (fs, "testNamespace");
GNUNET_assert (NULL != ns);
ok = GNUNET_NO;
GNUNET_FS_namespace_list (fs, &ns_iterator, &ok);
if (GNUNET_NO == ok)
- {
- fprintf (stderr, "namespace_list failed to find namespace!\n");
- GNUNET_FS_namespace_delete (ns, GNUNET_YES);
- GNUNET_FS_stop (fs);
- err = 1;
- return;
- }
+ {
+ fprintf (stderr, "namespace_list failed to find namespace!\n");
+ GNUNET_FS_namespace_delete (ns, GNUNET_YES);
+ GNUNET_FS_stop (fs);
+ err = 1;
+ return;
+ }
meta = GNUNET_CONTAINER_meta_data_create ();
ksk_uri = GNUNET_FS_uri_parse ("gnunet://fs/ksk/testnsa", NULL);
bo.content_priority = 1;
bo.anonymity_level = 1;
bo.replication_level = 0;
- bo.expiration_time = GNUNET_TIME_relative_to_absolute
(GNUNET_TIME_UNIT_MINUTES);
- GNUNET_FS_namespace_advertise (fs,
- ksk_uri,
- ns,
- meta,
- &bo,
- "root",
- &adv_cont, NULL);
- kill_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
- &do_timeout,
- NULL);
+ bo.expiration_time =
+ GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES);
+ GNUNET_FS_namespace_advertise (fs, ksk_uri, ns, meta, &bo, "root", &adv_cont,
+ NULL);
+ kill_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, &do_timeout,
+ NULL);
GNUNET_FS_uri_destroy (ksk_uri);
GNUNET_FS_namespace_delete (ns, GNUNET_NO);
GNUNET_CONTAINER_meta_data_destroy (meta);
@@ -407,16 +367,13 @@
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
setup_peer (&p1, "test_fs_namespace_data.conf");
fs = GNUNET_FS_start (cfg,
- "test-fs-namespace",
- &progress_cb,
- NULL,
- GNUNET_FS_FLAGS_NONE,
- GNUNET_FS_OPTIONS_END);
+ "test-fs-namespace",
+ &progress_cb,
+ NULL, GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
testNamespace ();
}
@@ -424,7 +381,7 @@
int
main (int argc, char *argv[])
{
- char *const argvx[] = {
+ char *const argvx[] = {
"test-fs-namespace",
"-c",
"test_fs_namespace_data.conf",
@@ -437,23 +394,22 @@
GNUNET_GETOPT_OPTION_END
};
- GNUNET_log_setup ("test_fs_namespace",
+ GNUNET_log_setup ("test_fs_namespace",
#if VERBOSE
- "DEBUG",
+ "DEBUG",
#else
- "WARNING",
+ "WARNING",
#endif
- NULL);
+ NULL);
GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
argvx, "test-fs-namespace",
- "nohelp", options, &run, NULL);
+ "nohelp", options, &run, NULL);
stop_arm (&p1);
if (GNUNET_YES != update_started)
- {
- fprintf (stderr,
- "Update search never started!\n");
- err = 1;
- }
+ {
+ fprintf (stderr, "Update search never started!\n");
+ err = 1;
+ }
GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-namespace/");
return err;
}
Modified: gnunet/src/fs/test_fs_namespace_list_updateable.c
===================================================================
--- gnunet/src/fs/test_fs_namespace_list_updateable.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/fs/test_fs_namespace_list_updateable.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -59,8 +59,7 @@
static void *
-progress_cb (void *cls,
- const struct GNUNET_FS_ProgressInfo *event)
+progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
{
return NULL;
}
@@ -72,11 +71,11 @@
p->cfg = GNUNET_CONFIGURATION_create ();
#if START_ARM
p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
- "gnunet-service-arm",
+ "gnunet-service-arm",
#if VERBOSE
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", cfgname, NULL);
+ "-c", cfgname, NULL);
#endif
GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
}
@@ -87,16 +86,17 @@
{
#if START_ARM
if (NULL != p->arm_proc)
- {
- if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
- if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK)
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "ARM process %u stopped\n", GNUNET_OS_process_get_pid
(p->arm_proc));
- GNUNET_OS_process_close (p->arm_proc);
- p->arm_proc = NULL;
- }
+ {
+ if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
+ if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "ARM process %u stopped\n",
+ GNUNET_OS_process_get_pid (p->arm_proc));
+ GNUNET_OS_process_close (p->arm_proc);
+ p->arm_proc = NULL;
+ }
#endif
if (uri_this != NULL)
GNUNET_FS_uri_destroy (uri_this);
@@ -113,10 +113,10 @@
static void
check_next (void *cls,
- const char *last_id,
- const struct GNUNET_FS_Uri *last_uri,
- const struct GNUNET_CONTAINER_MetaData *last_meta,
- const char *next_id)
+ const char *last_id,
+ const struct GNUNET_FS_Uri *last_uri,
+ const struct GNUNET_CONTAINER_MetaData *last_meta,
+ const char *next_id)
{
GNUNET_break (0 == strcmp (last_id, "next"));
GNUNET_break (0 == strcmp (next_id, "future"));
@@ -126,43 +126,35 @@
static void
check_this_next (void *cls,
- const char *last_id,
- const struct GNUNET_FS_Uri *last_uri,
- const struct GNUNET_CONTAINER_MetaData *last_meta,
- const char *next_id)
+ const char *last_id,
+ const struct GNUNET_FS_Uri *last_uri,
+ const struct GNUNET_CONTAINER_MetaData *last_meta,
+ const char *next_id)
{
GNUNET_break (0 == strcmp (last_id, "this"));
GNUNET_break (0 == strcmp (next_id, "next"));
err -= 2;
err += 4;
- GNUNET_FS_namespace_list_updateable (ns,
- next_id,
- &check_next,
- NULL);
+ GNUNET_FS_namespace_list_updateable (ns, next_id, &check_next, NULL);
}
static void
-sks_cont_next (void *cls,
- const struct GNUNET_FS_Uri *uri,
- const char *emsg)
+sks_cont_next (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg)
{
GNUNET_assert (NULL == emsg);
err += 2;
- GNUNET_FS_namespace_list_updateable (ns,
- NULL,
- &check_this_next,
- NULL);
+ GNUNET_FS_namespace_list_updateable (ns, NULL, &check_this_next, NULL);
}
static void
check_this (void *cls,
- const char *last_id,
- const struct GNUNET_FS_Uri *last_uri,
- const struct GNUNET_CONTAINER_MetaData *last_meta,
- const char *next_id)
+ const char *last_id,
+ const struct GNUNET_FS_Uri *last_uri,
+ const struct GNUNET_CONTAINER_MetaData *last_meta,
+ const char *next_id)
{
GNUNET_break (0 == strcmp (last_id, "this"));
GNUNET_break (0 == strcmp (next_id, "next"));
@@ -171,27 +163,20 @@
static void
-sks_cont_this (void *cls,
- const struct GNUNET_FS_Uri *uri,
- const char *emsg)
+sks_cont_this (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg)
{
GNUNET_assert (NULL == emsg);
err = 1;
- GNUNET_FS_namespace_list_updateable (ns,
- NULL,
- &check_this,
- NULL);
+ GNUNET_FS_namespace_list_updateable (ns, NULL, &check_this, NULL);
GNUNET_FS_publish_sks (fs,
- ns,
- "next",
- "future",
- meta,
- uri_next,
- &bo,
- GNUNET_FS_PUBLISH_OPTION_NONE,
- &sks_cont_next,
- NULL);
+ ns,
+ "next",
+ "future",
+ meta,
+ uri_next,
+ &bo,
+ GNUNET_FS_PUBLISH_OPTION_NONE, &sks_cont_next, NULL);
}
@@ -201,45 +186,38 @@
testNamespace ()
{
- ns = GNUNET_FS_namespace_create (fs,
- "testNamespace");
+ ns = GNUNET_FS_namespace_create (fs, "testNamespace");
GNUNET_assert (NULL != ns);
bo.content_priority = 1;
bo.anonymity_level = 1;
bo.replication_level = 0;
- bo.expiration_time = GNUNET_TIME_relative_to_absolute
(GNUNET_TIME_UNIT_MINUTES);
+ bo.expiration_time =
+ GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES);
meta = GNUNET_CONTAINER_meta_data_create ();
uri_this =
- GNUNET_FS_uri_parse
("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.42",
NULL);
+ GNUNET_FS_uri_parse
+
("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.42",
+ NULL);
uri_next =
- GNUNET_FS_uri_parse
("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.43",
NULL);
- GNUNET_FS_publish_sks (fs,
- ns,
- "this",
- "next",
- meta,
- uri_this,
- &bo,
- GNUNET_FS_PUBLISH_OPTION_NONE,
- &sks_cont_this,
- NULL);
+ GNUNET_FS_uri_parse
+
("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.43",
+ NULL);
+ GNUNET_FS_publish_sks (fs, ns, "this", "next", meta, uri_this, &bo,
+ GNUNET_FS_PUBLISH_OPTION_NONE, &sks_cont_this, NULL);
}
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
setup_peer (&p1, "test_fs_namespace_data.conf");
fs = GNUNET_FS_start (cfg,
- "test-fs-namespace",
- &progress_cb,
- NULL,
- GNUNET_FS_FLAGS_NONE,
- GNUNET_FS_OPTIONS_END);
+ "test-fs-namespace",
+ &progress_cb,
+ NULL, GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
testNamespace ();
}
@@ -247,7 +225,7 @@
int
main (int argc, char *argv[])
{
- char *const argvx[] = {
+ char *const argvx[] = {
"test-fs-namespace",
"-c",
"test_fs_namespace_data.conf",
@@ -260,16 +238,16 @@
GNUNET_GETOPT_OPTION_END
};
- GNUNET_log_setup ("test_fs_namespace_list_updateable",
+ GNUNET_log_setup ("test_fs_namespace_list_updateable",
#if VERBOSE
- "DEBUG",
+ "DEBUG",
#else
- "WARNING",
+ "WARNING",
#endif
- NULL);
+ NULL);
GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
argvx, "test-fs-namespace",
- "nohelp", options, &run, NULL);
+ "nohelp", options, &run, NULL);
stop_arm (&p1);
GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-namespace/");
return err;
Modified: gnunet/src/fs/test_fs_publish.c
===================================================================
--- gnunet/src/fs/test_fs_publish.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/fs/test_fs_publish.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -46,7 +46,7 @@
/**
* How long should our test-content live?
- */
+ */
#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
struct PeerContext
@@ -72,8 +72,7 @@
static int err;
static void
-abort_publish_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+abort_publish_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GNUNET_FS_publish_stop (publish);
publish = NULL;
@@ -87,90 +86,86 @@
static void *
-progress_cb (void *cls,
- const struct GNUNET_FS_ProgressInfo *event)
+progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
{
void *ret;
ret = NULL;
switch (event->status)
- {
- case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
- ret = event->value.publish.cctx;
- printf ("Publish complete, %llu kbps.\n",
- (unsigned long long) (FILESIZE * 1000 /
(1+GNUNET_TIME_absolute_get_duration (start).rel_value) / 1024));
- if (0 == strcmp ("publish-context-dir",
- event->value.publish.cctx))
- GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
- NULL,
-
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- break;
- case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
- ret = event->value.publish.cctx;
- GNUNET_assert (publish == event->value.publish.pc);
+ {
+ case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
+ ret = event->value.publish.cctx;
+ printf ("Publish complete, %llu kbps.\n",
+ (unsigned long long) (FILESIZE * 1000 /
+ (1 +
+ GNUNET_TIME_absolute_get_duration
+ (start).rel_value) / 1024));
+ if (0 == strcmp ("publish-context-dir", event->value.publish.cctx))
+ GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
+ NULL,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
+ ret = event->value.publish.cctx;
+ GNUNET_assert (publish == event->value.publish.pc);
#if VERBOSE
- printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n",
- (unsigned long long) event->value.publish.completed,
- (unsigned long long) event->value.publish.size,
- event->value.publish.specifics.progress.depth,
- (unsigned long long)
event->value.publish.specifics.progress.offset);
+ printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n",
+ (unsigned long long) event->value.publish.completed,
+ (unsigned long long) event->value.publish.size,
+ event->value.publish.specifics.progress.depth,
+ (unsigned long long) event->value.publish.specifics.
+ progress.offset);
#endif
- break;
- case GNUNET_FS_STATUS_PUBLISH_ERROR:
- ret = event->value.publish.cctx;
- fprintf (stderr,
- "Error publishing file: %s\n",
- event->value.publish.specifics.error.message);
- err = 1;
- if (0 == strcmp ("publish-context-dir",
- event->value.publish.cctx))
- {
- fprintf (stderr, "Scheduling abort task for error on `%s'\n",
- (const char*) event->value.publish.cctx);
- GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
- NULL,
-
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- }
- break;
- case GNUNET_FS_STATUS_PUBLISH_START:
- ret = event->value.publish.cctx;
- if (0 == strcmp ("publish-context1",
- event->value.publish.cctx))
- {
- GNUNET_assert (0 == strcmp ("publish-context-dir",
- event->value.publish.pctx));
- GNUNET_assert (FILESIZE == event->value.publish.size);
- GNUNET_assert (0 == event->value.publish.completed);
- GNUNET_assert (1 == event->value.publish.anonymity);
- }
- else if (0 == strcmp ("publish-context2",
- event->value.publish.cctx))
- {
- GNUNET_assert (0 == strcmp ("publish-context-dir",
- event->value.publish.pctx));
- GNUNET_assert (FILESIZE == event->value.publish.size);
- GNUNET_assert (0 == event->value.publish.completed);
- GNUNET_assert (2 == event->value.publish.anonymity);
- }
- else if (0 == strcmp ("publish-context-dir",
- event->value.publish.cctx))
- {
- GNUNET_assert (0 == event->value.publish.completed);
- GNUNET_assert (3 == event->value.publish.anonymity);
- }
- else
- GNUNET_assert (0);
- break;
- case GNUNET_FS_STATUS_PUBLISH_STOPPED:
- if (0 == strcmp ("publish-context-dir",
- event->value.publish.cctx))
- GNUNET_assert (publish == event->value.publish.pc);
- break;
- default:
- printf ("Unexpected event: %d\n",
- event->status);
- break;
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_ERROR:
+ ret = event->value.publish.cctx;
+ fprintf (stderr,
+ "Error publishing file: %s\n",
+ event->value.publish.specifics.error.message);
+ err = 1;
+ if (0 == strcmp ("publish-context-dir", event->value.publish.cctx))
+ {
+ fprintf (stderr, "Scheduling abort task for error on `%s'\n",
+ (const char *) event->value.publish.cctx);
+ GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
+ NULL,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
}
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_START:
+ ret = event->value.publish.cctx;
+ if (0 == strcmp ("publish-context1", event->value.publish.cctx))
+ {
+ GNUNET_assert (0 == strcmp ("publish-context-dir",
+ event->value.publish.pctx));
+ GNUNET_assert (FILESIZE == event->value.publish.size);
+ GNUNET_assert (0 == event->value.publish.completed);
+ GNUNET_assert (1 == event->value.publish.anonymity);
+ }
+ else if (0 == strcmp ("publish-context2", event->value.publish.cctx))
+ {
+ GNUNET_assert (0 == strcmp ("publish-context-dir",
+ event->value.publish.pctx));
+ GNUNET_assert (FILESIZE == event->value.publish.size);
+ GNUNET_assert (0 == event->value.publish.completed);
+ GNUNET_assert (2 == event->value.publish.anonymity);
+ }
+ else if (0 == strcmp ("publish-context-dir", event->value.publish.cctx))
+ {
+ GNUNET_assert (0 == event->value.publish.completed);
+ GNUNET_assert (3 == event->value.publish.anonymity);
+ }
+ else
+ GNUNET_assert (0);
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_STOPPED:
+ if (0 == strcmp ("publish-context-dir", event->value.publish.cctx))
+ GNUNET_assert (publish == event->value.publish.pc);
+ break;
+ default:
+ printf ("Unexpected event: %d\n", event->status);
+ break;
+ }
return ret;
}
@@ -181,11 +176,11 @@
p->cfg = GNUNET_CONFIGURATION_create ();
#if START_ARM
p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
- "gnunet-service-arm",
+ "gnunet-service-arm",
#if VERBOSE
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", cfgname, NULL);
+ "-c", cfgname, NULL);
#endif
GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
}
@@ -196,16 +191,17 @@
{
#if START_ARM
if (NULL != p->arm_proc)
- {
- if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
- if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK)
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "ARM process %u stopped\n", GNUNET_OS_process_get_pid
(p->arm_proc));
- GNUNET_OS_process_close (p->arm_proc);
- p->arm_proc = NULL;
- }
+ {
+ if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
+ if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "ARM process %u stopped\n",
+ GNUNET_OS_process_get_pid (p->arm_proc));
+ GNUNET_OS_process_close (p->arm_proc);
+ p->arm_proc = NULL;
+ }
#endif
GNUNET_CONFIGURATION_destroy (p->cfg);
}
@@ -214,8 +210,7 @@
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
const char *keywords[] = {
"down_foo",
@@ -232,21 +227,20 @@
setup_peer (&p1, "test_fs_publish_data.conf");
fs = GNUNET_FS_start (cfg,
- "test-fs-publish",
- &progress_cb,
- NULL,
- GNUNET_FS_FLAGS_NONE,
- GNUNET_FS_OPTIONS_END);
- GNUNET_assert (NULL != fs);
+ "test-fs-publish",
+ &progress_cb,
+ NULL, GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
+ GNUNET_assert (NULL != fs);
fn1 = GNUNET_DISK_mktemp ("gnunet-publish-test-dst");
buf = GNUNET_malloc (FILESIZE);
for (i = 0; i < FILESIZE; i++)
buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
GNUNET_assert (FILESIZE ==
- GNUNET_DISK_fn_write (fn1,
- buf,
- FILESIZE,
- GNUNET_DISK_PERM_USER_READ |
GNUNET_DISK_PERM_USER_WRITE));
+ GNUNET_DISK_fn_write (fn1,
+ buf,
+ FILESIZE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE));
GNUNET_free (buf);
fn2 = GNUNET_DISK_mktemp ("gnunet-publish-test-dst");
@@ -254,10 +248,11 @@
for (i = 0; i < FILESIZE; i++)
buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
GNUNET_assert (FILESIZE ==
- GNUNET_DISK_fn_write (fn2,
- buf,
- FILESIZE,
- GNUNET_DISK_PERM_USER_READ |
GNUNET_DISK_PERM_USER_WRITE));
+ GNUNET_DISK_fn_write (fn2,
+ buf,
+ FILESIZE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE));
GNUNET_free (buf);
meta = GNUNET_CONTAINER_meta_data_create ();
@@ -268,29 +263,23 @@
bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
fi1 = GNUNET_FS_file_information_create_from_file (fs,
- "publish-context1",
- fn1,
- kuri,
- meta,
- GNUNET_YES,
- &bo);
-
+ "publish-context1",
+ fn1,
+ kuri,
+ meta, GNUNET_YES, &bo);
+
GNUNET_assert (NULL != fi1);
bo.anonymity_level = 2;
fi2 = GNUNET_FS_file_information_create_from_file (fs,
- "publish-context2",
- fn2,
- kuri,
- meta,
- GNUNET_YES,
- &bo);
+ "publish-context2",
+ fn2,
+ kuri,
+ meta, GNUNET_YES, &bo);
GNUNET_assert (NULL != fi2);
bo.anonymity_level = 3;
fidir = GNUNET_FS_file_information_create_empty_directory (fs,
-
"publish-context-dir",
- kuri,
- meta,
- &bo);
+
"publish-context-dir",
+ kuri, meta, &bo);
GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1));
GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2));
GNUNET_FS_uri_destroy (kuri);
@@ -298,9 +287,9 @@
GNUNET_assert (NULL != fidir);
start = GNUNET_TIME_absolute_get ();
publish = GNUNET_FS_publish_start (fs,
- fidir,
- NULL, NULL, NULL,
- GNUNET_FS_PUBLISH_OPTION_NONE);
+ fidir,
+ NULL, NULL, NULL,
+ GNUNET_FS_PUBLISH_OPTION_NONE);
GNUNET_assert (publish != NULL);
}
@@ -308,7 +297,7 @@
int
main (int argc, char *argv[])
{
- char *const argvx[] = {
+ char *const argvx[] = {
"test-fs-publish",
"-c",
"test_fs_publish_data.conf",
@@ -321,28 +310,27 @@
GNUNET_GETOPT_OPTION_END
};
- GNUNET_log_setup ("test_fs_publish",
+ GNUNET_log_setup ("test_fs_publish",
#if VERBOSE
- "DEBUG",
+ "DEBUG",
#else
- "WARNING",
+ "WARNING",
#endif
- NULL);
+ NULL);
GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
- argvx, "test-fs-publish",
- "nohelp", options, &run, NULL);
+ argvx, "test-fs-publish", "nohelp", options, &run, NULL);
stop_arm (&p1);
GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-publish/");
if (fn1 != NULL)
- {
- GNUNET_DISK_directory_remove (fn1);
- GNUNET_free (fn1);
- }
+ {
+ GNUNET_DISK_directory_remove (fn1);
+ GNUNET_free (fn1);
+ }
if (fn2 != NULL)
- {
- GNUNET_DISK_directory_remove (fn2);
- GNUNET_free (fn2);
- }
+ {
+ GNUNET_DISK_directory_remove (fn2);
+ GNUNET_free (fn2);
+ }
return err;
}
Modified: gnunet/src/fs/test_fs_publish_persistence.c
===================================================================
--- gnunet/src/fs/test_fs_publish_persistence.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/fs/test_fs_publish_persistence.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -45,7 +45,7 @@
/**
* How long should our test-content live?
- */
+ */
#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
struct PeerContext
@@ -77,8 +77,7 @@
static GNUNET_SCHEDULER_TaskIdentifier rtask;
static void
-abort_publish_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+abort_publish_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GNUNET_FS_publish_stop (publish);
publish = NULL;
@@ -91,30 +90,27 @@
GNUNET_FS_stop (fs);
fs = NULL;
if (GNUNET_SCHEDULER_NO_TASK != rtask)
- {
- GNUNET_SCHEDULER_cancel (rtask);
- rtask = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (rtask);
+ rtask = GNUNET_SCHEDULER_NO_TASK;
+ }
}
-static void *
-progress_cb (void *cls,
- const struct GNUNET_FS_ProgressInfo *event);
+static void *progress_cb (void *cls,
+ const struct GNUNET_FS_ProgressInfo *event);
static void
-restart_fs_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+restart_fs_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
rtask = GNUNET_SCHEDULER_NO_TASK;
GNUNET_FS_stop (fs);
fs = GNUNET_FS_start (cfg,
- "test-fs-publish-persistence",
- &progress_cb,
- NULL,
- GNUNET_FS_FLAGS_PERSISTENCE,
- GNUNET_FS_OPTIONS_END);
+ "test-fs-publish-persistence",
+ &progress_cb,
+ NULL,
+ GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END);
}
@@ -131,111 +127,108 @@
static int prev[32];
static int off;
int i;
- for (i=0;i<off;i++)
+
+ for (i = 0; i < off; i++)
if (prev[i] == ev)
return;
prev[off++] = ev;
rtask = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_URGENT,
- &restart_fs_task,
- NULL);
+ &restart_fs_task, NULL);
}
static void *
-progress_cb (void *cls,
- const struct GNUNET_FS_ProgressInfo *event)
+progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
{
void *ret;
ret = NULL;
switch (event->status)
- {
- case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
- consider_restart (event->status);
- ret = event->value.publish.cctx;
- printf ("Publish complete, %llu kbps.\n",
- (unsigned long long) (FILESIZE * 1000LL /
(1+GNUNET_TIME_absolute_get_duration (start).rel_value) / 1024));
- if (0 == strcmp ("publish-context-dir",
- event->value.publish.cctx))
- GNUNET_SCHEDULER_add_now (&abort_publish_task,
- NULL);
- break;
- case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
- consider_restart (event->status);
- ret = event->value.publish.cctx;
- GNUNET_assert (publish == event->value.publish.pc);
+ {
+ case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
+ consider_restart (event->status);
+ ret = event->value.publish.cctx;
+ printf ("Publish complete, %llu kbps.\n",
+ (unsigned long long) (FILESIZE * 1000LL /
+ (1 +
+ GNUNET_TIME_absolute_get_duration
+ (start).rel_value) / 1024));
+ if (0 == strcmp ("publish-context-dir", event->value.publish.cctx))
+ GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL);
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
+ consider_restart (event->status);
+ ret = event->value.publish.cctx;
+ GNUNET_assert (publish == event->value.publish.pc);
#if VERBOSE
- printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n",
- (unsigned long long) event->value.publish.completed,
- (unsigned long long) event->value.publish.size,
- event->value.publish.specifics.progress.depth,
- (unsigned long long)
event->value.publish.specifics.progress.offset);
+ printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n",
+ (unsigned long long) event->value.publish.completed,
+ (unsigned long long) event->value.publish.size,
+ event->value.publish.specifics.progress.depth,
+ (unsigned long long) event->value.publish.specifics.
+ progress.offset);
#endif
- break;
- case GNUNET_FS_STATUS_PUBLISH_SUSPEND:
- if (event->value.publish.pc == publish)
- publish = NULL;
- break;
- case GNUNET_FS_STATUS_PUBLISH_RESUME:
- if (NULL == publish)
- {
- GNUNET_assert (GNUNET_YES ==
- GNUNET_FS_file_information_is_directory
(event->value.publish.fi));
- publish = event->value.publish.pc;
- return "publish-context-dir";
- }
- break;
- case GNUNET_FS_STATUS_PUBLISH_ERROR:
- ret = event->value.publish.cctx;
- fprintf (stderr,
- "Error publishing file: %s\n",
- event->value.publish.specifics.error.message);
- err = 1;
- GNUNET_SCHEDULER_add_now (&abort_publish_task,
- NULL);
- break;
- case GNUNET_FS_STATUS_PUBLISH_START:
- consider_restart (event->status);
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_SUSPEND:
+ if (event->value.publish.pc == publish)
+ publish = NULL;
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_RESUME:
+ if (NULL == publish)
+ {
+ GNUNET_assert (GNUNET_YES ==
+ GNUNET_FS_file_information_is_directory (event->
+ value.publish.
+ fi));
publish = event->value.publish.pc;
- ret = event->value.publish.cctx;
- if (0 == strcmp ("publish-context1",
- event->value.publish.cctx))
- {
- GNUNET_assert (0 == strcmp ("publish-context-dir",
- event->value.publish.pctx));
- GNUNET_assert (FILESIZE == event->value.publish.size);
- GNUNET_assert (0 == event->value.publish.completed);
- GNUNET_assert (1 == event->value.publish.anonymity);
- }
- else if (0 == strcmp ("publish-context2",
- event->value.publish.cctx))
- {
- GNUNET_assert (0 == strcmp ("publish-context-dir",
- event->value.publish.pctx));
- GNUNET_assert (FILESIZE == event->value.publish.size);
- GNUNET_assert (0 == event->value.publish.completed);
- GNUNET_assert (2 == event->value.publish.anonymity);
- }
- else if (0 == strcmp ("publish-context-dir",
- event->value.publish.cctx))
- {
- GNUNET_assert (0 == event->value.publish.completed);
- GNUNET_assert (3 == event->value.publish.anonymity);
- }
- else
- GNUNET_assert (0);
- break;
- case GNUNET_FS_STATUS_PUBLISH_STOPPED:
- consider_restart (event->status);
- if (0 == strcmp ("publish-context-dir",
- event->value.publish.cctx))
- GNUNET_assert (publish == event->value.publish.pc);
- break;
- default:
- printf ("Unexpected event: %d\n",
- event->status);
- break;
+ return "publish-context-dir";
}
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_ERROR:
+ ret = event->value.publish.cctx;
+ fprintf (stderr,
+ "Error publishing file: %s\n",
+ event->value.publish.specifics.error.message);
+ err = 1;
+ GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL);
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_START:
+ consider_restart (event->status);
+ publish = event->value.publish.pc;
+ ret = event->value.publish.cctx;
+ if (0 == strcmp ("publish-context1", event->value.publish.cctx))
+ {
+ GNUNET_assert (0 == strcmp ("publish-context-dir",
+ event->value.publish.pctx));
+ GNUNET_assert (FILESIZE == event->value.publish.size);
+ GNUNET_assert (0 == event->value.publish.completed);
+ GNUNET_assert (1 == event->value.publish.anonymity);
+ }
+ else if (0 == strcmp ("publish-context2", event->value.publish.cctx))
+ {
+ GNUNET_assert (0 == strcmp ("publish-context-dir",
+ event->value.publish.pctx));
+ GNUNET_assert (FILESIZE == event->value.publish.size);
+ GNUNET_assert (0 == event->value.publish.completed);
+ GNUNET_assert (2 == event->value.publish.anonymity);
+ }
+ else if (0 == strcmp ("publish-context-dir", event->value.publish.cctx))
+ {
+ GNUNET_assert (0 == event->value.publish.completed);
+ GNUNET_assert (3 == event->value.publish.anonymity);
+ }
+ else
+ GNUNET_assert (0);
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_STOPPED:
+ consider_restart (event->status);
+ if (0 == strcmp ("publish-context-dir", event->value.publish.cctx))
+ GNUNET_assert (publish == event->value.publish.pc);
+ break;
+ default:
+ printf ("Unexpected event: %d\n", event->status);
+ break;
+ }
return ret;
}
@@ -246,11 +239,11 @@
p->cfg = GNUNET_CONFIGURATION_create ();
#if START_ARM
p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
- "gnunet-service-arm",
+ "gnunet-service-arm",
#if VERBOSE
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", cfgname, NULL);
+ "-c", cfgname, NULL);
#endif
GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
}
@@ -261,16 +254,17 @@
{
#if START_ARM
if (NULL != p->arm_proc)
- {
- if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
- if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK)
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "ARM process %u stopped\n", GNUNET_OS_process_get_pid
(p->arm_proc));
- GNUNET_OS_process_close (p->arm_proc);
- p->arm_proc = NULL;
- }
+ {
+ if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
+ if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "ARM process %u stopped\n",
+ GNUNET_OS_process_get_pid (p->arm_proc));
+ GNUNET_OS_process_close (p->arm_proc);
+ p->arm_proc = NULL;
+ }
#endif
GNUNET_CONFIGURATION_destroy (p->cfg);
}
@@ -279,8 +273,7 @@
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *c)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
{
const char *keywords[] = {
"down_foo",
@@ -298,21 +291,21 @@
cfg = c;
setup_peer (&p1, "test_fs_publish_data.conf");
fs = GNUNET_FS_start (cfg,
- "test-fs-publish-persistence",
- &progress_cb,
- NULL,
- GNUNET_FS_FLAGS_PERSISTENCE,
- GNUNET_FS_OPTIONS_END);
- GNUNET_assert (NULL != fs);
+ "test-fs-publish-persistence",
+ &progress_cb,
+ NULL,
+ GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END);
+ GNUNET_assert (NULL != fs);
fn1 = GNUNET_DISK_mktemp ("gnunet-publish-test-dst");
buf = GNUNET_malloc (FILESIZE);
for (i = 0; i < FILESIZE; i++)
buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
GNUNET_assert (FILESIZE ==
- GNUNET_DISK_fn_write (fn1,
- buf,
- FILESIZE,
- GNUNET_DISK_PERM_USER_READ |
GNUNET_DISK_PERM_USER_WRITE));
+ GNUNET_DISK_fn_write (fn1,
+ buf,
+ FILESIZE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE));
GNUNET_free (buf);
fn2 = GNUNET_DISK_mktemp ("gnunet-publish-test-dst");
@@ -320,10 +313,11 @@
for (i = 0; i < FILESIZE; i++)
buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
GNUNET_assert (FILESIZE ==
- GNUNET_DISK_fn_write (fn2,
- buf,
- FILESIZE,
- GNUNET_DISK_PERM_USER_READ |
GNUNET_DISK_PERM_USER_WRITE));
+ GNUNET_DISK_fn_write (fn2,
+ buf,
+ FILESIZE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE));
GNUNET_free (buf);
meta = GNUNET_CONTAINER_meta_data_create ();
@@ -331,30 +325,24 @@
bo.content_priority = 42;
bo.anonymity_level = 1;
bo.replication_level = 0;
- bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
+ bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
fi1 = GNUNET_FS_file_information_create_from_file (fs,
- "publish-context1",
- fn1,
- kuri,
- meta,
- GNUNET_YES,
- &bo);
+ "publish-context1",
+ fn1,
+ kuri,
+ meta, GNUNET_YES, &bo);
GNUNET_assert (NULL != fi1);
bo.anonymity_level = 2;
fi2 = GNUNET_FS_file_information_create_from_file (fs,
- "publish-context2",
- fn2,
- kuri,
- meta,
- GNUNET_YES,
- &bo);
+ "publish-context2",
+ fn2,
+ kuri,
+ meta, GNUNET_YES, &bo);
GNUNET_assert (NULL != fi2);
bo.anonymity_level = 3;
fidir = GNUNET_FS_file_information_create_empty_directory (fs,
-
"publish-context-dir",
- kuri,
- meta,
- &bo);
+
"publish-context-dir",
+ kuri, meta, &bo);
GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1));
GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2));
GNUNET_FS_uri_destroy (kuri);
@@ -362,9 +350,8 @@
GNUNET_assert (NULL != fidir);
start = GNUNET_TIME_absolute_get ();
GNUNET_FS_publish_start (fs,
- fidir,
- NULL, NULL, NULL,
- GNUNET_FS_PUBLISH_OPTION_NONE);
+ fidir,
+ NULL, NULL, NULL, GNUNET_FS_PUBLISH_OPTION_NONE);
GNUNET_assert (publish != NULL);
}
@@ -372,7 +359,7 @@
int
main (int argc, char *argv[])
{
- char *const argvx[] = {
+ char *const argvx[] = {
"test-fs-publish-persistence",
"-c",
"test_fs_publish_data.conf",
@@ -385,28 +372,27 @@
GNUNET_GETOPT_OPTION_END
};
- GNUNET_log_setup ("test_fs_publish_persistence",
+ GNUNET_log_setup ("test_fs_publish_persistence",
#if VERBOSE
- "DEBUG",
+ "DEBUG",
#else
- "WARNING",
+ "WARNING",
#endif
- NULL);
+ NULL);
GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
- argvx, "test-fs-publish",
- "nohelp", options, &run, NULL);
+ argvx, "test-fs-publish", "nohelp", options, &run, NULL);
stop_arm (&p1);
GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-publish/");
if (fn1 != NULL)
- {
- GNUNET_DISK_directory_remove (fn1);
- GNUNET_free (fn1);
- }
+ {
+ GNUNET_DISK_directory_remove (fn1);
+ GNUNET_free (fn1);
+ }
if (fn2 != NULL)
- {
- GNUNET_DISK_directory_remove (fn2);
- GNUNET_free (fn2);
- }
+ {
+ GNUNET_DISK_directory_remove (fn2);
+ GNUNET_free (fn2);
+ }
return err;
}
Modified: gnunet/src/fs/test_fs_search.c
===================================================================
--- gnunet/src/fs/test_fs_search.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/fs/test_fs_search.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -45,13 +45,13 @@
/**
* How long should our test-content live?
- */
+ */
#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
struct PeerContext
{
struct GNUNET_CONFIGURATION_Handle *cfg;
- struct GNUNET_PeerIdentity id;
+ struct GNUNET_PeerIdentity id;
#if START_ARM
struct GNUNET_OS_Process *arm_proc;
#endif
@@ -69,8 +69,7 @@
static void
-abort_publish_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+abort_publish_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GNUNET_FS_publish_stop (publish);
publish = NULL;
@@ -78,8 +77,7 @@
static void
-abort_search_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+abort_search_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
if (search != NULL)
GNUNET_FS_search_stop (search);
@@ -88,94 +86,90 @@
static void *
-progress_cb (void *cls,
- const struct GNUNET_FS_ProgressInfo *event)
-{
+progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
+{
const char *keywords[] = {
"down_foo"
};
struct GNUNET_FS_Uri *kuri;
switch (event->status)
- {
- case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
+ {
+ case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
#if VERBOSE
- printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n",
- (unsigned long long) event->value.publish.completed,
- (unsigned long long) event->value.publish.size,
- event->value.publish.specifics.progress.depth,
- (unsigned long long)
event->value.publish.specifics.progress.offset);
-#endif
- break;
- case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
- kuri = GNUNET_FS_uri_ksk_create_from_args (1, keywords);
- start = GNUNET_TIME_absolute_get ();
- search = GNUNET_FS_search_start (fs,
- kuri,
- 1,
- GNUNET_FS_SEARCH_OPTION_NONE,
- "search");
- GNUNET_FS_uri_destroy (kuri);
- GNUNET_assert (search != NULL);
- break;
- case GNUNET_FS_STATUS_SEARCH_RESULT:
+ printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n",
+ (unsigned long long) event->value.publish.completed,
+ (unsigned long long) event->value.publish.size,
+ event->value.publish.specifics.progress.depth,
+ (unsigned long long) event->value.publish.specifics.
+ progress.offset);
+#endif
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
+ kuri = GNUNET_FS_uri_ksk_create_from_args (1, keywords);
+ start = GNUNET_TIME_absolute_get ();
+ search = GNUNET_FS_search_start (fs,
+ kuri,
+ 1, GNUNET_FS_SEARCH_OPTION_NONE,
"search");
+ GNUNET_FS_uri_destroy (kuri);
+ GNUNET_assert (search != NULL);
+ break;
+ case GNUNET_FS_STATUS_SEARCH_RESULT:
#if VERBOSE
- printf ("Search complete.\n");
+ printf ("Search complete.\n");
#endif
- GNUNET_SCHEDULER_add_continuation (&abort_search_task,
- NULL,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- break;
- case GNUNET_FS_STATUS_PUBLISH_ERROR:
- fprintf (stderr,
- "Error publishing file: %s\n",
- event->value.publish.specifics.error.message);
- GNUNET_break (0);
- GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
- NULL,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- break;
- case GNUNET_FS_STATUS_SEARCH_ERROR:
- fprintf (stderr,
- "Error searching file: %s\n",
- event->value.search.specifics.error.message);
- GNUNET_SCHEDULER_add_continuation (&abort_search_task,
- NULL,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- break;
- case GNUNET_FS_STATUS_PUBLISH_START:
- GNUNET_assert (0 == strcmp ("publish-context",
event->value.publish.cctx));
- GNUNET_assert (NULL == event->value.publish.pctx);
- GNUNET_assert (FILESIZE == event->value.publish.size);
- GNUNET_assert (0 == event->value.publish.completed);
- GNUNET_assert (1 == event->value.publish.anonymity);
- break;
- case GNUNET_FS_STATUS_PUBLISH_STOPPED:
- GNUNET_assert (publish == event->value.publish.pc);
- GNUNET_assert (FILESIZE == event->value.publish.size);
- GNUNET_assert (1 == event->value.publish.anonymity);
- GNUNET_FS_stop (fs);
- fs = NULL;
- break;
- case GNUNET_FS_STATUS_SEARCH_START:
- GNUNET_assert (search == NULL);
- GNUNET_assert (0 == strcmp ("search", event->value.search.cctx));
- GNUNET_assert (1 == event->value.search.anonymity);
- break;
- case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED:
- break;
- case GNUNET_FS_STATUS_SEARCH_STOPPED:
- GNUNET_assert (search == event->value.search.sc);
- GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
- NULL,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- break;
- default:
- fprintf (stderr,
- "Unexpected event: %d\n",
- event->status);
- break;
- }
+ GNUNET_SCHEDULER_add_continuation (&abort_search_task,
+ NULL,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_ERROR:
+ fprintf (stderr,
+ "Error publishing file: %s\n",
+ event->value.publish.specifics.error.message);
+ GNUNET_break (0);
+ GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
+ NULL,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ break;
+ case GNUNET_FS_STATUS_SEARCH_ERROR:
+ fprintf (stderr,
+ "Error searching file: %s\n",
+ event->value.search.specifics.error.message);
+ GNUNET_SCHEDULER_add_continuation (&abort_search_task,
+ NULL,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_START:
+ GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx));
+ GNUNET_assert (NULL == event->value.publish.pctx);
+ GNUNET_assert (FILESIZE == event->value.publish.size);
+ GNUNET_assert (0 == event->value.publish.completed);
+ GNUNET_assert (1 == event->value.publish.anonymity);
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_STOPPED:
+ GNUNET_assert (publish == event->value.publish.pc);
+ GNUNET_assert (FILESIZE == event->value.publish.size);
+ GNUNET_assert (1 == event->value.publish.anonymity);
+ GNUNET_FS_stop (fs);
+ fs = NULL;
+ break;
+ case GNUNET_FS_STATUS_SEARCH_START:
+ GNUNET_assert (search == NULL);
+ GNUNET_assert (0 == strcmp ("search", event->value.search.cctx));
+ GNUNET_assert (1 == event->value.search.anonymity);
+ break;
+ case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED:
+ break;
+ case GNUNET_FS_STATUS_SEARCH_STOPPED:
+ GNUNET_assert (search == event->value.search.sc);
+ GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
+ NULL,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ break;
+ default:
+ fprintf (stderr, "Unexpected event: %d\n", event->status);
+ break;
+ }
return NULL;
}
@@ -186,11 +180,11 @@
p->cfg = GNUNET_CONFIGURATION_create ();
#if START_ARM
p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
- "gnunet-service-arm",
+ "gnunet-service-arm",
#if VERBOSE
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", cfgname, NULL);
+ "-c", cfgname, NULL);
#endif
GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
}
@@ -201,16 +195,17 @@
{
#if START_ARM
if (NULL != p->arm_proc)
- {
- if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
- if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK)
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "ARM process %u stopped\n", GNUNET_OS_process_get_pid
(p->arm_proc));
- GNUNET_OS_process_close (p->arm_proc);
- p->arm_proc = NULL;
- }
+ {
+ if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
+ if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "ARM process %u stopped\n",
+ GNUNET_OS_process_get_pid (p->arm_proc));
+ GNUNET_OS_process_close (p->arm_proc);
+ p->arm_proc = NULL;
+ }
#endif
GNUNET_CONFIGURATION_destroy (p->cfg);
}
@@ -219,8 +214,7 @@
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
const char *keywords[] = {
"down_foo",
@@ -235,12 +229,10 @@
setup_peer (&p1, "test_fs_search_data.conf");
fs = GNUNET_FS_start (cfg,
- "test-fs-search",
- &progress_cb,
- NULL,
- GNUNET_FS_FLAGS_NONE,
- GNUNET_FS_OPTIONS_END);
- GNUNET_assert (NULL != fs);
+ "test-fs-search",
+ &progress_cb,
+ NULL, GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
+ GNUNET_assert (NULL != fs);
buf = GNUNET_malloc (FILESIZE);
for (i = 0; i < FILESIZE; i++)
buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
@@ -251,21 +243,18 @@
bo.replication_level = 0;
bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
fi = GNUNET_FS_file_information_create_from_data (fs,
- "publish-context",
- FILESIZE,
- buf,
- kuri,
- meta,
- GNUNET_NO,
- &bo);
+ "publish-context",
+ FILESIZE,
+ buf,
+ kuri, meta, GNUNET_NO,
&bo);
GNUNET_FS_uri_destroy (kuri);
GNUNET_CONTAINER_meta_data_destroy (meta);
GNUNET_assert (NULL != fi);
start = GNUNET_TIME_absolute_get ();
publish = GNUNET_FS_publish_start (fs,
- fi,
- NULL, NULL, NULL,
- GNUNET_FS_PUBLISH_OPTION_NONE);
+ fi,
+ NULL, NULL, NULL,
+ GNUNET_FS_PUBLISH_OPTION_NONE);
GNUNET_assert (publish != NULL);
}
@@ -273,7 +262,7 @@
int
main (int argc, char *argv[])
{
- char *const argvx[] = {
+ char *const argvx[] = {
"test-fs-search",
"-c",
"test_fs_search_data.conf",
@@ -286,16 +275,15 @@
GNUNET_GETOPT_OPTION_END
};
- GNUNET_log_setup ("test_fs_search",
+ GNUNET_log_setup ("test_fs_search",
#if VERBOSE
- "DEBUG",
+ "DEBUG",
#else
- "WARNING",
+ "WARNING",
#endif
- NULL);
+ NULL);
GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
- argvx, "test-fs-search",
- "nohelp", options, &run, NULL);
+ argvx, "test-fs-search", "nohelp", options, &run, NULL);
stop_arm (&p1);
GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-search/");
return 0;
Modified: gnunet/src/fs/test_fs_search_persistence.c
===================================================================
--- gnunet/src/fs/test_fs_search_persistence.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/fs/test_fs_search_persistence.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -45,13 +45,13 @@
/**
* How long should our test-content live?
- */
+ */
#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
struct PeerContext
{
struct GNUNET_CONFIGURATION_Handle *cfg;
- struct GNUNET_PeerIdentity id;
+ struct GNUNET_PeerIdentity id;
#if START_ARM
struct GNUNET_OS_Process *arm_proc;
#endif
@@ -70,8 +70,7 @@
static const struct GNUNET_CONFIGURATION_Handle *cfg;
static void
-abort_publish_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+abort_publish_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GNUNET_FS_publish_stop (publish);
publish = NULL;
@@ -79,8 +78,7 @@
static void
-abort_search_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+abort_search_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
if (search != NULL)
GNUNET_FS_search_stop (search);
@@ -88,22 +86,19 @@
}
-static void *
-progress_cb (void *cls,
- const struct GNUNET_FS_ProgressInfo *event);
+static void *progress_cb (void *cls,
+ const struct GNUNET_FS_ProgressInfo *event);
static void
-restart_fs_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+restart_fs_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GNUNET_FS_stop (fs);
fs = GNUNET_FS_start (cfg,
- "test-fs-search-persistence",
- &progress_cb,
- NULL,
- GNUNET_FS_FLAGS_PERSISTENCE,
- GNUNET_FS_OPTIONS_END);
+ "test-fs-search-persistence",
+ &progress_cb,
+ NULL,
+ GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END);
}
@@ -122,129 +117,124 @@
static int prev[32];
static int off;
int i;
- for (i=0;i<off;i++)
+
+ for (i = 0; i < off; i++)
if (prev[i] == ev)
return;
prev[off++] = ev;
GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_URGENT,
- &restart_fs_task,
- NULL);
+ &restart_fs_task, NULL);
}
static void *
-progress_cb (void *cls,
- const struct GNUNET_FS_ProgressInfo *event)
-{
+progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
+{
const char *keywords[] = {
"down_foo"
};
struct GNUNET_FS_Uri *kuri;
switch (event->status)
- {
- case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
+ {
+ case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
#if VERBOSE
- printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n",
- (unsigned long long) event->value.publish.completed,
- (unsigned long long) event->value.publish.size,
- event->value.publish.specifics.progress.depth,
- (unsigned long long)
event->value.publish.specifics.progress.offset);
-#endif
- break;
- case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
- kuri = GNUNET_FS_uri_ksk_create_from_args (1, keywords);
- start = GNUNET_TIME_absolute_get ();
- GNUNET_FS_search_start (fs,
- kuri,
- 1,
- GNUNET_FS_SEARCH_OPTION_NONE,
- "search");
- GNUNET_FS_uri_destroy (kuri);
- GNUNET_assert (search != NULL);
- break;
- case GNUNET_FS_STATUS_PUBLISH_SUSPEND:
- if (event->value.publish.pc == publish)
- publish = NULL;
- break;
- case GNUNET_FS_STATUS_PUBLISH_RESUME:
- if (NULL == publish)
- publish = event->value.publish.pc;
- break;
- case GNUNET_FS_STATUS_SEARCH_RESULT:
- /* FIXME: consider_restart (event->status); cannot be tested with
- search result since we exit here after the first one... */
+ printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n",
+ (unsigned long long) event->value.publish.completed,
+ (unsigned long long) event->value.publish.size,
+ event->value.publish.specifics.progress.depth,
+ (unsigned long long) event->value.publish.specifics.
+ progress.offset);
+#endif
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
+ kuri = GNUNET_FS_uri_ksk_create_from_args (1, keywords);
+ start = GNUNET_TIME_absolute_get ();
+ GNUNET_FS_search_start (fs,
+ kuri, 1, GNUNET_FS_SEARCH_OPTION_NONE, "search");
+ GNUNET_FS_uri_destroy (kuri);
+ GNUNET_assert (search != NULL);
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_SUSPEND:
+ if (event->value.publish.pc == publish)
+ publish = NULL;
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_RESUME:
+ if (NULL == publish)
+ publish = event->value.publish.pc;
+ break;
+ case GNUNET_FS_STATUS_SEARCH_RESULT:
+ /* FIXME: consider_restart (event->status); cannot be tested with
+ * search result since we exit here after the first one... */
#if VERBOSE
- printf ("Search complete.\n");
+ printf ("Search complete.\n");
#endif
- GNUNET_SCHEDULER_add_continuation (&abort_search_task,
- NULL,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- break;
- case GNUNET_FS_STATUS_PUBLISH_ERROR:
- fprintf (stderr,
- "Error publishing file: %s\n",
- event->value.publish.specifics.error.message);
- GNUNET_break (0);
- GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
- NULL,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- break;
- case GNUNET_FS_STATUS_SEARCH_ERROR:
- fprintf (stderr,
- "Error searching file: %s\n",
- event->value.search.specifics.error.message);
- GNUNET_SCHEDULER_add_continuation (&abort_search_task,
- NULL,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- break;
- case GNUNET_FS_STATUS_SEARCH_SUSPEND:
- if (event->value.search.sc == search)
- search = NULL;
- break;
- case GNUNET_FS_STATUS_SEARCH_RESUME:
- if (NULL == search)
- {
- search = event->value.search.sc;
- return "search";
- }
- break;
- case GNUNET_FS_STATUS_PUBLISH_START:
- GNUNET_assert (0 == strcmp ("publish-context",
event->value.publish.cctx));
- GNUNET_assert (NULL == event->value.publish.pctx);
- GNUNET_assert (FILESIZE == event->value.publish.size);
- GNUNET_assert (0 == event->value.publish.completed);
- GNUNET_assert (1 == event->value.publish.anonymity);
- break;
- case GNUNET_FS_STATUS_PUBLISH_STOPPED:
- GNUNET_assert (publish == event->value.publish.pc);
- GNUNET_assert (FILESIZE == event->value.publish.size);
- GNUNET_assert (1 == event->value.publish.anonymity);
- GNUNET_FS_stop (fs);
- fs = NULL;
- break;
- case GNUNET_FS_STATUS_SEARCH_START:
- consider_restart (event->status);
- GNUNET_assert (search == NULL);
- search = event->value.search.sc;
- GNUNET_assert (0 == strcmp ("search", event->value.search.cctx));
- GNUNET_assert (1 == event->value.search.anonymity);
- break;
- case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED:
- break;
- case GNUNET_FS_STATUS_SEARCH_STOPPED:
- GNUNET_assert (search == event->value.search.sc);
- GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
- NULL,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ GNUNET_SCHEDULER_add_continuation (&abort_search_task,
+ NULL,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_ERROR:
+ fprintf (stderr,
+ "Error publishing file: %s\n",
+ event->value.publish.specifics.error.message);
+ GNUNET_break (0);
+ GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
+ NULL,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ break;
+ case GNUNET_FS_STATUS_SEARCH_ERROR:
+ fprintf (stderr,
+ "Error searching file: %s\n",
+ event->value.search.specifics.error.message);
+ GNUNET_SCHEDULER_add_continuation (&abort_search_task,
+ NULL,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ break;
+ case GNUNET_FS_STATUS_SEARCH_SUSPEND:
+ if (event->value.search.sc == search)
search = NULL;
- break;
- default:
- fprintf (stderr,
- "Unexpected event: %d\n",
- event->status);
- break;
+ break;
+ case GNUNET_FS_STATUS_SEARCH_RESUME:
+ if (NULL == search)
+ {
+ search = event->value.search.sc;
+ return "search";
}
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_START:
+ GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx));
+ GNUNET_assert (NULL == event->value.publish.pctx);
+ GNUNET_assert (FILESIZE == event->value.publish.size);
+ GNUNET_assert (0 == event->value.publish.completed);
+ GNUNET_assert (1 == event->value.publish.anonymity);
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_STOPPED:
+ GNUNET_assert (publish == event->value.publish.pc);
+ GNUNET_assert (FILESIZE == event->value.publish.size);
+ GNUNET_assert (1 == event->value.publish.anonymity);
+ GNUNET_FS_stop (fs);
+ fs = NULL;
+ break;
+ case GNUNET_FS_STATUS_SEARCH_START:
+ consider_restart (event->status);
+ GNUNET_assert (search == NULL);
+ search = event->value.search.sc;
+ GNUNET_assert (0 == strcmp ("search", event->value.search.cctx));
+ GNUNET_assert (1 == event->value.search.anonymity);
+ break;
+ case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED:
+ break;
+ case GNUNET_FS_STATUS_SEARCH_STOPPED:
+ GNUNET_assert (search == event->value.search.sc);
+ GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
+ NULL,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ search = NULL;
+ break;
+ default:
+ fprintf (stderr, "Unexpected event: %d\n", event->status);
+ break;
+ }
return NULL;
}
@@ -255,11 +245,11 @@
p->cfg = GNUNET_CONFIGURATION_create ();
#if START_ARM
p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
- "gnunet-service-arm",
+ "gnunet-service-arm",
#if VERBOSE
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", cfgname, NULL);
+ "-c", cfgname, NULL);
#endif
GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
}
@@ -270,16 +260,17 @@
{
#if START_ARM
if (NULL != p->arm_proc)
- {
- if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
- if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK)
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "ARM process %u stopped\n", GNUNET_OS_process_get_pid
(p->arm_proc));
- GNUNET_OS_process_close (p->arm_proc);
- p->arm_proc = NULL;
- }
+ {
+ if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
+ if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "ARM process %u stopped\n",
+ GNUNET_OS_process_get_pid (p->arm_proc));
+ GNUNET_OS_process_close (p->arm_proc);
+ p->arm_proc = NULL;
+ }
#endif
GNUNET_CONFIGURATION_destroy (p->cfg);
}
@@ -288,8 +279,7 @@
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *c)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
{
const char *keywords[] = {
"down_foo",
@@ -305,12 +295,11 @@
cfg = c;
setup_peer (&p1, "test_fs_search_data.conf");
fs = GNUNET_FS_start (cfg,
- "test-fs-search-persistence",
- &progress_cb,
- NULL,
- GNUNET_FS_FLAGS_PERSISTENCE,
- GNUNET_FS_OPTIONS_END);
- GNUNET_assert (NULL != fs);
+ "test-fs-search-persistence",
+ &progress_cb,
+ NULL,
+ GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END);
+ GNUNET_assert (NULL != fs);
buf = GNUNET_malloc (FILESIZE);
for (i = 0; i < FILESIZE; i++)
buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
@@ -321,21 +310,18 @@
bo.replication_level = 0;
bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
fi = GNUNET_FS_file_information_create_from_data (fs,
- "publish-context",
- FILESIZE,
- buf,
- kuri,
- meta,
- GNUNET_NO,
- &bo);
+ "publish-context",
+ FILESIZE,
+ buf,
+ kuri, meta, GNUNET_NO,
&bo);
GNUNET_FS_uri_destroy (kuri);
GNUNET_CONTAINER_meta_data_destroy (meta);
GNUNET_assert (NULL != fi);
start = GNUNET_TIME_absolute_get ();
publish = GNUNET_FS_publish_start (fs,
- fi,
- NULL, NULL, NULL,
- GNUNET_FS_PUBLISH_OPTION_NONE);
+ fi,
+ NULL, NULL, NULL,
+ GNUNET_FS_PUBLISH_OPTION_NONE);
GNUNET_assert (publish != NULL);
}
@@ -343,7 +329,7 @@
int
main (int argc, char *argv[])
{
- char *const argvx[] = {
+ char *const argvx[] = {
"test-fs-search-persistence",
"-c",
"test_fs_search_data.conf",
@@ -357,16 +343,16 @@
};
GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-search/");
- GNUNET_log_setup ("test_fs_search_persistence",
+ GNUNET_log_setup ("test_fs_search_persistence",
#if VERBOSE
- "DEBUG",
+ "DEBUG",
#else
- "WARNING",
+ "WARNING",
#endif
- NULL);
+ NULL);
GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
argvx, "test-fs-search-persistence",
- "nohelp", options, &run, NULL);
+ "nohelp", options, &run, NULL);
stop_arm (&p1);
GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-search/");
return 0;
Modified: gnunet/src/fs/test_fs_search_ranking.c
===================================================================
--- gnunet/src/fs/test_fs_search_ranking.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/fs/test_fs_search_ranking.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -37,8 +37,7 @@
{
char *fn;
- fn =
- GNUNET_malloc (strlen ("/tmp/gnunet-fsui-searchranktest/FSUITEST") + 14);
+ fn = GNUNET_malloc (strlen ("/tmp/gnunet-fsui-searchranktest/FSUITEST") +
14);
GNUNET_snprintf (fn,
strlen ("/tmp/gnunet-fsui-searchranktest/FSUITEST") + 14,
"/tmp/gnunet-fsui-searchranktest/FSUITEST%u", i);
@@ -64,57 +63,57 @@
static char unused;
switch (event->type)
- {
- case GNUNET_FSUI_search_resumed:
- search = event->data.SearchResumed.sc.pos;
- break;
- case GNUNET_FSUI_search_suspended:
- search = NULL;
- break;
- case GNUNET_FSUI_search_update:
- availability = event->data.SearchUpdate.availability_rank;
- rank = event->data.SearchUpdate.applicability_rank;
- break;
- case GNUNET_FSUI_search_paused:
- case GNUNET_FSUI_search_restarted:
- break;
- case GNUNET_FSUI_download_resumed:
- case GNUNET_FSUI_upload_resumed:
- case GNUNET_FSUI_unindex_resumed:
- return &unused;
- case GNUNET_FSUI_search_result:
+ {
+ case GNUNET_FSUI_search_resumed:
+ search = event->data.SearchResumed.sc.pos;
+ break;
+ case GNUNET_FSUI_search_suspended:
+ search = NULL;
+ break;
+ case GNUNET_FSUI_search_update:
+ availability = event->data.SearchUpdate.availability_rank;
+ rank = event->data.SearchUpdate.applicability_rank;
+ break;
+ case GNUNET_FSUI_search_paused:
+ case GNUNET_FSUI_search_restarted:
+ break;
+ case GNUNET_FSUI_download_resumed:
+ case GNUNET_FSUI_upload_resumed:
+ case GNUNET_FSUI_unindex_resumed:
+ return &unused;
+ case GNUNET_FSUI_search_result:
#if CHECK_VERBOSE
- printf ("Received search result\n");
+ printf ("Received search result\n");
#endif
- uri = GNUNET_ECRS_uri_duplicate (event->data.SearchResult.fi.uri);
- break;
- case GNUNET_FSUI_upload_completed:
+ uri = GNUNET_ECRS_uri_duplicate (event->data.SearchResult.fi.uri);
+ break;
+ case GNUNET_FSUI_upload_completed:
#if CHECK_VERBOSE
- printf ("Upload complete.\n");
+ printf ("Upload complete.\n");
#endif
- break;
- case GNUNET_FSUI_download_completed:
+ break;
+ case GNUNET_FSUI_download_completed:
#if CHECK_VERBOSE
- printf ("Download complete.\n");
+ printf ("Download complete.\n");
#endif
- break;
- case GNUNET_FSUI_unindex_completed:
+ break;
+ case GNUNET_FSUI_unindex_completed:
#if CHECK_VERBOSE
- printf ("Unindex complete.\n");
+ printf ("Unindex complete.\n");
#endif
- break;
- case GNUNET_FSUI_upload_error:
- printf ("Upload error.\n");
- break;
- case GNUNET_FSUI_download_error:
- printf ("Download error.\n");
- break;
- case GNUNET_FSUI_unindex_error:
- printf ("Unindex error.\n");
- break;
- default:
- break;
- }
+ break;
+ case GNUNET_FSUI_upload_error:
+ printf ("Upload error.\n");
+ break;
+ case GNUNET_FSUI_download_error:
+ printf ("Download error.\n");
+ break;
+ case GNUNET_FSUI_unindex_error:
+ printf ("Unindex error.\n");
+ break;
+ default:
+ break;
+ }
if (lastEvent != waitForEvent)
lastEvent = event->type;
return NULL;
@@ -130,6 +129,7 @@
#endif
int ok;
char *fn = NULL;
+
char *keywords[] = {
"search_foo",
"search_bar",
@@ -146,17 +146,16 @@
ok = GNUNET_YES;
cfg = GNUNET_GC_create ();
if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf"))
- {
- GNUNET_GC_free (cfg);
- return -1;
- }
+ {
+ GNUNET_GC_free (cfg);
+ return -1;
+ }
#if START_DAEMON
GNUNET_disk_directory_remove (NULL, "/tmp/gnunet-fsui-searchranktest/");
daemon = GNUNET_daemon_start (NULL, cfg, "peer.conf", GNUNET_NO);
GNUNET_GE_ASSERT (NULL, daemon != NULL);
CHECK (GNUNET_OK ==
- GNUNET_wait_for_daemon_running (NULL, cfg,
- 30 * GNUNET_CRON_SECONDS));
+ GNUNET_wait_for_daemon_running (NULL, cfg, 30 * GNUNET_CRON_SECONDS));
GNUNET_thread_sleep (5 * GNUNET_CRON_SECONDS); /* give apps time to
start */
/* ACTUAL TEST CODE */
#endif
@@ -167,21 +166,20 @@
/* upload */
fn = makeName (42);
GNUNET_disk_file_write (NULL,
- fn, "foo bar test!", strlen ("foo bar test!"),
- "600");
+ fn, "foo bar test!", strlen ("foo bar test!"),
"600");
meta = GNUNET_meta_data_create ();
kuri =
- GNUNET_ECRS_keyword_command_line_to_uri (NULL, 2,
- (const char **) keywords);
+ GNUNET_ECRS_keyword_command_line_to_uri (NULL, 2,
+ (const char **) keywords);
waitForEvent = GNUNET_FSUI_upload_completed;
upload =
- GNUNET_FSUI_upload_start (ctx,
- fn,
- (GNUNET_FSUI_DirectoryScanCallback) &
- GNUNET_disk_directory_scan, NULL, 0, 0,
- GNUNET_YES, GNUNET_NO, GNUNET_NO,
- GNUNET_get_time () + 5 * GNUNET_CRON_HOURS,
- meta, kuri, kuri);
+ GNUNET_FSUI_upload_start (ctx,
+ fn,
+ (GNUNET_FSUI_DirectoryScanCallback) &
+ GNUNET_disk_directory_scan, NULL, 0, 0,
+ GNUNET_YES, GNUNET_NO, GNUNET_NO,
+ GNUNET_get_time () + 5 * GNUNET_CRON_HOURS,
+ meta, kuri, kuri);
CHECK (NULL != upload);
GNUNET_free (fn);
fn = NULL;
@@ -189,19 +187,18 @@
GNUNET_meta_data_destroy (meta);
prog = 0;
while (lastEvent != GNUNET_FSUI_upload_completed)
+ {
+ prog++;
+ if (prog == 10000)
{
- prog++;
- if (prog == 10000)
- {
- fprintf (stderr,
- "Upload failed to complete -- last event: %u\n",
- lastEvent);
- }
- CHECK (prog < 10000);
- GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
- if (GNUNET_shutdown_test () == GNUNET_YES)
- break;
+ fprintf (stderr,
+ "Upload failed to complete -- last event: %u\n", lastEvent);
}
+ CHECK (prog < 10000);
+ GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
+ if (GNUNET_shutdown_test () == GNUNET_YES)
+ break;
+ }
GNUNET_FSUI_upload_stop (upload);
/* search */
@@ -217,11 +214,11 @@
while ((uri == NULL) &&
(availability < 3) &&
(rank != 2) && (GNUNET_shutdown_test () != GNUNET_YES))
- {
- prog++;
- CHECK (prog < 10000);
- GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
- }
+ {
+ prog++;
+ CHECK (prog < 10000);
+ GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
+ }
GNUNET_FSUI_search_abort (search);
GNUNET_FSUI_search_stop (search);
CHECK (uri != NULL);
Modified: gnunet/src/fs/test_fs_start_stop.c
===================================================================
--- gnunet/src/fs/test_fs_start_stop.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/fs/test_fs_start_stop.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -45,8 +45,7 @@
static void *
-progress_cb (void *cls,
- const struct GNUNET_FS_ProgressInfo *event)
+progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
{
return NULL;
}
@@ -58,11 +57,11 @@
p->cfg = GNUNET_CONFIGURATION_create ();
#if START_ARM
p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
- "gnunet-service-arm",
+ "gnunet-service-arm",
#if VERBOSE
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", cfgname, NULL);
+ "-c", cfgname, NULL);
#endif
GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
}
@@ -73,16 +72,17 @@
{
#if START_ARM
if (NULL != p->arm_proc)
- {
- if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
- if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK)
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "ARM process %u stopped\n", GNUNET_OS_process_get_pid
(p->arm_proc));
- GNUNET_OS_process_close (p->arm_proc);
- p->arm_proc = NULL;
- }
+ {
+ if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
+ if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "ARM process %u stopped\n",
+ GNUNET_OS_process_get_pid (p->arm_proc));
+ GNUNET_OS_process_close (p->arm_proc);
+ p->arm_proc = NULL;
+ }
#endif
GNUNET_CONFIGURATION_destroy (p->cfg);
}
@@ -91,19 +91,16 @@
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
struct GNUNET_FS_Handle *fs;
setup_peer (&p1, "test_fs_data.conf");
fs = GNUNET_FS_start (cfg,
- "test-fs-start-stop",
- &progress_cb,
- NULL,
- GNUNET_FS_FLAGS_NONE,
- GNUNET_FS_OPTIONS_END);
- GNUNET_assert (NULL != fs);
+ "test-fs-start-stop",
+ &progress_cb,
+ NULL, GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
+ GNUNET_assert (NULL != fs);
GNUNET_FS_stop (fs);
}
@@ -111,7 +108,7 @@
int
main (int argc, char *argv[])
{
- char *const argvx[] = {
+ char *const argvx[] = {
"test-fs-start-stop",
"-c",
"test_fs_data.conf",
@@ -124,16 +121,16 @@
GNUNET_GETOPT_OPTION_END
};
- GNUNET_log_setup ("test_fs_start_stop",
+ GNUNET_log_setup ("test_fs_start_stop",
#if VERBOSE
- "DEBUG",
+ "DEBUG",
#else
- "WARNING",
+ "WARNING",
#endif
- NULL);
+ NULL);
GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
argvx, "test-fs-start-stop",
- "nohelp", options, &run, NULL);
+ "nohelp", options, &run, NULL);
stop_arm (&p1);
GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs/");
return 0;
Modified: gnunet/src/fs/test_fs_test_lib.c
===================================================================
--- gnunet/src/fs/test_fs_test_lib.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/fs/test_fs_test_lib.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -47,112 +47,91 @@
static int ret;
static void
-do_stop (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
- {
- GNUNET_break (0);
- ret = 1;
- }
+ {
+ GNUNET_break (0);
+ ret = 1;
+ }
else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Finished download, shutting down\n",
- (unsigned long long) FILESIZE);
- }
- GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS,
- daemons);
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Finished download, shutting down\n",
+ (unsigned long long) FILESIZE);
+ }
+ GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons);
}
static void
-do_download (void *cls,
- const struct GNUNET_FS_Uri *uri)
+do_download (void *cls, const struct GNUNET_FS_Uri *uri)
{
if (NULL == uri)
- {
- GNUNET_break (0);
- GNUNET_SCHEDULER_add_now (&do_stop,
- NULL);
- ret = 1;
- return;
- }
+ {
+ GNUNET_break (0);
+ GNUNET_SCHEDULER_add_now (&do_stop, NULL);
+ ret = 1;
+ return;
+ }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Downloading %llu bytes\n",
- (unsigned long long) FILESIZE);
+ "Downloading %llu bytes\n", (unsigned long long) FILESIZE);
GNUNET_FS_TEST_download (daemons[0],
- TIMEOUT,
- 1, SEED, uri,
- VERBOSE,
- &do_stop, NULL);
+ TIMEOUT, 1, SEED, uri, VERBOSE, &do_stop, NULL);
}
static void
-do_publish (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_publish (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
- {
- GNUNET_break (0);
- ret = 1;
- GNUNET_SCHEDULER_add_now (&do_stop,
- NULL);
- return;
- }
+ {
+ GNUNET_break (0);
+ ret = 1;
+ GNUNET_SCHEDULER_add_now (&do_stop, NULL);
+ return;
+ }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Publishing %llu bytes\n",
- (unsigned long long) FILESIZE);
+ "Publishing %llu bytes\n", (unsigned long long) FILESIZE);
GNUNET_FS_TEST_publish (daemons[0],
- TIMEOUT,
- 1, GNUNET_NO, FILESIZE, SEED,
- VERBOSE,
- &do_download, NULL);
+ TIMEOUT,
+ 1, GNUNET_NO, FILESIZE, SEED,
+ VERBOSE, &do_download, NULL);
}
static void
-do_connect (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
- {
- GNUNET_break (0);
- ret = 1;
- GNUNET_SCHEDULER_add_now (&do_stop,
- NULL);
- return;
- }
+ {
+ GNUNET_break (0);
+ ret = 1;
+ GNUNET_SCHEDULER_add_now (&do_stop, NULL);
+ return;
+ }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Daemons started, will now try to connect them\n");
+ "Daemons started, will now try to connect them\n");
GNUNET_FS_TEST_daemons_connect (daemons[0],
- daemons[1],
- TIMEOUT,
- &do_publish,
- NULL);
+ daemons[1], TIMEOUT, &do_publish, NULL);
}
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
GNUNET_FS_TEST_daemons_start ("fs_test_lib_data.conf",
- TIMEOUT,
- NUM_DAEMONS,
- daemons,
- &do_connect,
- NULL);
+ TIMEOUT,
+ NUM_DAEMONS, daemons, &do_connect, NULL);
}
int
main (int argc, char *argv[])
{
- char *const argvx[] = {
+ char *const argvx[] = {
"test-fs-test-lib",
"-c",
"fs_test_lib_data.conf",
@@ -166,16 +145,15 @@
};
GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
- GNUNET_log_setup ("test_fs_test_lib",
+ GNUNET_log_setup ("test_fs_test_lib",
#if VERBOSE
- "DEBUG",
+ "DEBUG",
#else
- "WARNING",
+ "WARNING",
#endif
- NULL);
+ NULL);
GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
- argvx, "test-fs-test-lib",
- "nohelp", options, &run, NULL);
+ argvx, "test-fs-test-lib", "nohelp", options, &run,
NULL);
GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
return ret;
}
Modified: gnunet/src/fs/test_fs_unindex.c
===================================================================
--- gnunet/src/fs/test_fs_unindex.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/fs/test_fs_unindex.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -45,7 +45,7 @@
/**
* How long should our test-content live?
- */
+ */
#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
struct PeerContext
@@ -70,8 +70,7 @@
static void
-abort_publish_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+abort_publish_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GNUNET_FS_publish_stop (publish);
publish = NULL;
@@ -79,8 +78,7 @@
static void
-abort_unindex_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+abort_unindex_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GNUNET_FS_unindex_stop (unindex);
unindex = NULL;
@@ -91,96 +89,99 @@
static void *
-progress_cb (void *cls,
- const struct GNUNET_FS_ProgressInfo *event)
+progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
{
switch (event->status)
- {
- case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
+ {
+ case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
#if VERBOSE
- printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n",
- (unsigned long long) event->value.publish.completed,
- (unsigned long long) event->value.publish.size,
- event->value.publish.specifics.progress.depth,
- (unsigned long long)
event->value.publish.specifics.progress.offset);
-#endif
- break;
- case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
- printf ("Publishing complete, %llu kbps.\n",
- (unsigned long long) (FILESIZE * 1000 /
(1+GNUNET_TIME_absolute_get_duration (start).rel_value) / 1024));
- start = GNUNET_TIME_absolute_get ();
- unindex = GNUNET_FS_unindex_start (fs,
- fn,
- "unindex");
- GNUNET_assert (unindex != NULL);
- break;
- case GNUNET_FS_STATUS_UNINDEX_COMPLETED:
- printf ("Unindex complete, %llu kbps.\n",
- (unsigned long long) (FILESIZE * 1000 /
(1+GNUNET_TIME_absolute_get_duration (start).rel_value) / 1024));
- GNUNET_SCHEDULER_add_continuation (&abort_unindex_task,
- NULL,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- break;
- case GNUNET_FS_STATUS_UNINDEX_PROGRESS:
- GNUNET_assert (unindex == event->value.unindex.uc);
+ printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n",
+ (unsigned long long) event->value.publish.completed,
+ (unsigned long long) event->value.publish.size,
+ event->value.publish.specifics.progress.depth,
+ (unsigned long long) event->value.publish.specifics.
+ progress.offset);
+#endif
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
+ printf ("Publishing complete, %llu kbps.\n",
+ (unsigned long long) (FILESIZE * 1000 /
+ (1 +
+ GNUNET_TIME_absolute_get_duration
+ (start).rel_value) / 1024));
+ start = GNUNET_TIME_absolute_get ();
+ unindex = GNUNET_FS_unindex_start (fs, fn, "unindex");
+ GNUNET_assert (unindex != NULL);
+ break;
+ case GNUNET_FS_STATUS_UNINDEX_COMPLETED:
+ printf ("Unindex complete, %llu kbps.\n",
+ (unsigned long long) (FILESIZE * 1000 /
+ (1 +
+ GNUNET_TIME_absolute_get_duration
+ (start).rel_value) / 1024));
+ GNUNET_SCHEDULER_add_continuation (&abort_unindex_task, NULL,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ break;
+ case GNUNET_FS_STATUS_UNINDEX_PROGRESS:
+ GNUNET_assert (unindex == event->value.unindex.uc);
#if VERBOSE
- printf ("Unindex is progressing (%llu/%llu at level %u off %llu)...\n",
- (unsigned long long) event->value.unindex.completed,
- (unsigned long long) event->value.unindex.size,
- event->value.unindex.specifics.progress.depth,
- (unsigned long long)
event->value.unindex.specifics.progress.offset);
+ printf ("Unindex is progressing (%llu/%llu at level %u off %llu)...\n",
+ (unsigned long long) event->value.unindex.completed,
+ (unsigned long long) event->value.unindex.size,
+ event->value.unindex.specifics.progress.depth,
+ (unsigned long long) event->value.unindex.specifics.
+ progress.offset);
#endif
- break;
- case GNUNET_FS_STATUS_PUBLISH_ERROR:
- fprintf (stderr,
- "Error publishing file: %s\n",
- event->value.publish.specifics.error.message);
- GNUNET_break (0);
- GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
- NULL,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- break;
- case GNUNET_FS_STATUS_UNINDEX_ERROR:
- fprintf (stderr,
- "Error unindexing file: %s\n",
- event->value.unindex.specifics.error.message);
- GNUNET_SCHEDULER_add_continuation (&abort_unindex_task,
- NULL,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- break;
- case GNUNET_FS_STATUS_PUBLISH_START:
- GNUNET_assert (0 == strcmp ("publish-context",
event->value.publish.cctx));
- GNUNET_assert (NULL == event->value.publish.pctx);
- GNUNET_assert (FILESIZE == event->value.publish.size);
- GNUNET_assert (0 == event->value.publish.completed);
- GNUNET_assert (1 == event->value.publish.anonymity);
- break;
- case GNUNET_FS_STATUS_PUBLISH_STOPPED:
- GNUNET_assert (publish == event->value.publish.pc);
- GNUNET_assert (FILESIZE == event->value.publish.size);
- GNUNET_assert (1 == event->value.publish.anonymity);
- GNUNET_FS_stop (fs);
- fs = NULL;
- break;
- case GNUNET_FS_STATUS_UNINDEX_START:
- GNUNET_assert (unindex == NULL);
- GNUNET_assert (0 == strcmp ("unindex", event->value.unindex.cctx));
- GNUNET_assert (0 == strcmp (fn, event->value.unindex.filename));
- GNUNET_assert (FILESIZE == event->value.unindex.size);
- GNUNET_assert (0 == event->value.unindex.completed);
- break;
- case GNUNET_FS_STATUS_UNINDEX_STOPPED:
- GNUNET_assert (unindex == event->value.unindex.uc);
- GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
- NULL,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- break;
- default:
- printf ("Unexpected event: %d\n",
- event->status);
- break;
- }
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_ERROR:
+ fprintf (stderr,
+ "Error publishing file: %s\n",
+ event->value.publish.specifics.error.message);
+ GNUNET_break (0);
+ GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
+ NULL,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ break;
+ case GNUNET_FS_STATUS_UNINDEX_ERROR:
+ fprintf (stderr,
+ "Error unindexing file: %s\n",
+ event->value.unindex.specifics.error.message);
+ GNUNET_SCHEDULER_add_continuation (&abort_unindex_task,
+ NULL,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_START:
+ GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx));
+ GNUNET_assert (NULL == event->value.publish.pctx);
+ GNUNET_assert (FILESIZE == event->value.publish.size);
+ GNUNET_assert (0 == event->value.publish.completed);
+ GNUNET_assert (1 == event->value.publish.anonymity);
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_STOPPED:
+ GNUNET_assert (publish == event->value.publish.pc);
+ GNUNET_assert (FILESIZE == event->value.publish.size);
+ GNUNET_assert (1 == event->value.publish.anonymity);
+ GNUNET_FS_stop (fs);
+ fs = NULL;
+ break;
+ case GNUNET_FS_STATUS_UNINDEX_START:
+ GNUNET_assert (unindex == NULL);
+ GNUNET_assert (0 == strcmp ("unindex", event->value.unindex.cctx));
+ GNUNET_assert (0 == strcmp (fn, event->value.unindex.filename));
+ GNUNET_assert (FILESIZE == event->value.unindex.size);
+ GNUNET_assert (0 == event->value.unindex.completed);
+ break;
+ case GNUNET_FS_STATUS_UNINDEX_STOPPED:
+ GNUNET_assert (unindex == event->value.unindex.uc);
+ GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
+ NULL,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ break;
+ default:
+ printf ("Unexpected event: %d\n", event->status);
+ break;
+ }
return NULL;
}
@@ -191,11 +192,11 @@
p->cfg = GNUNET_CONFIGURATION_create ();
#if START_ARM
p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
- "gnunet-service-arm",
+ "gnunet-service-arm",
#if VERBOSE
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", cfgname, NULL);
+ "-c", cfgname, NULL);
#endif
GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
}
@@ -206,16 +207,17 @@
{
#if START_ARM
if (NULL != p->arm_proc)
- {
- if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
- if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK)
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "ARM process %u stopped\n", GNUNET_OS_process_get_pid
(p->arm_proc));
- GNUNET_OS_process_close (p->arm_proc);
- p->arm_proc = NULL;
- }
+ {
+ if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
+ if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "ARM process %u stopped\n",
+ GNUNET_OS_process_get_pid (p->arm_proc));
+ GNUNET_OS_process_close (p->arm_proc);
+ p->arm_proc = NULL;
+ }
#endif
GNUNET_CONFIGURATION_destroy (p->cfg);
}
@@ -224,8 +226,7 @@
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
const char *keywords[] = {
"down_foo",
@@ -241,20 +242,19 @@
setup_peer (&p1, "test_fs_unindex_data.conf");
fn = GNUNET_DISK_mktemp ("gnunet-unindex-test-dst");
fs = GNUNET_FS_start (cfg,
- "test-fs-unindex",
- &progress_cb,
- NULL,
- GNUNET_FS_FLAGS_NONE,
- GNUNET_FS_OPTIONS_END);
- GNUNET_assert (NULL != fs);
+ "test-fs-unindex",
+ &progress_cb,
+ NULL, GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
+ GNUNET_assert (NULL != fs);
buf = GNUNET_malloc (FILESIZE);
for (i = 0; i < FILESIZE; i++)
buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
GNUNET_assert (FILESIZE ==
- GNUNET_DISK_fn_write (fn,
- buf,
- FILESIZE,
- GNUNET_DISK_PERM_USER_READ |
GNUNET_DISK_PERM_USER_WRITE));
+ GNUNET_DISK_fn_write (fn,
+ buf,
+ FILESIZE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE));
GNUNET_free (buf);
meta = GNUNET_CONTAINER_meta_data_create ();
kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords);
@@ -263,20 +263,18 @@
bo.replication_level = 0;
bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
fi = GNUNET_FS_file_information_create_from_file (fs,
- "publish-context",
- fn,
- kuri,
- meta,
- GNUNET_YES,
- &bo);
+ "publish-context",
+ fn,
+ kuri,
+ meta, GNUNET_YES, &bo);
GNUNET_FS_uri_destroy (kuri);
GNUNET_CONTAINER_meta_data_destroy (meta);
GNUNET_assert (NULL != fi);
start = GNUNET_TIME_absolute_get ();
publish = GNUNET_FS_publish_start (fs,
- fi,
- NULL, NULL, NULL,
- GNUNET_FS_PUBLISH_OPTION_NONE);
+ fi,
+ NULL, NULL, NULL,
+ GNUNET_FS_PUBLISH_OPTION_NONE);
GNUNET_assert (publish != NULL);
}
@@ -284,7 +282,7 @@
int
main (int argc, char *argv[])
{
- char *const argvx[] = {
+ char *const argvx[] = {
"test-fs-unindex",
"-c",
"test_fs_unindex_data.conf",
@@ -297,23 +295,22 @@
GNUNET_GETOPT_OPTION_END
};
- GNUNET_log_setup ("test_fs_unindex",
+ GNUNET_log_setup ("test_fs_unindex",
#if VERBOSE
- "DEBUG",
+ "DEBUG",
#else
- "WARNING",
+ "WARNING",
#endif
- NULL);
+ NULL);
GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
- argvx, "test-fs-unindex",
- "nohelp", options, &run, NULL);
+ argvx, "test-fs-unindex", "nohelp", options, &run, NULL);
stop_arm (&p1);
GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-unindex/");
if (NULL != fn)
- {
- GNUNET_DISK_directory_remove (fn);
- GNUNET_free (fn);
- }
+ {
+ GNUNET_DISK_directory_remove (fn);
+ GNUNET_free (fn);
+ }
return 0;
}
Modified: gnunet/src/fs/test_fs_unindex_persistence.c
===================================================================
--- gnunet/src/fs/test_fs_unindex_persistence.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/fs/test_fs_unindex_persistence.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -44,7 +44,7 @@
/**
* How long should our test-content live?
- */
+ */
#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
struct PeerContext
@@ -70,8 +70,7 @@
static const struct GNUNET_CONFIGURATION_Handle *cfg;
static void
-abort_publish_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+abort_publish_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GNUNET_FS_publish_stop (publish);
publish = NULL;
@@ -79,39 +78,35 @@
static void
-abort_unindex_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+abort_unindex_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
if (unindex != NULL)
- {
- GNUNET_FS_unindex_stop (unindex);
- unindex = NULL;
- }
+ {
+ GNUNET_FS_unindex_stop (unindex);
+ unindex = NULL;
+ }
if (fn != NULL)
- {
- GNUNET_DISK_directory_remove (fn);
- GNUNET_free (fn);
- fn = NULL;
- }
+ {
+ GNUNET_DISK_directory_remove (fn);
+ GNUNET_free (fn);
+ fn = NULL;
+ }
}
-static void *
-progress_cb (void *cls,
- const struct GNUNET_FS_ProgressInfo *event);
+static void *progress_cb (void *cls,
+ const struct GNUNET_FS_ProgressInfo *event);
static void
-restart_fs_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+restart_fs_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GNUNET_FS_stop (fs);
fs = GNUNET_FS_start (cfg,
- "test-fs-unindex-persistence",
- &progress_cb,
- NULL,
- GNUNET_FS_FLAGS_PERSISTENCE,
- GNUNET_FS_OPTIONS_END);
+ "test-fs-unindex-persistence",
+ &progress_cb,
+ NULL,
+ GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END);
}
@@ -128,127 +123,130 @@
static int prev[32];
static int off;
int i;
- for (i=0;i<off;i++)
+
+ for (i = 0; i < off; i++)
if (prev[i] == ev)
return;
prev[off++] = ev;
GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_URGENT,
- &restart_fs_task,
- NULL);
+ &restart_fs_task, NULL);
}
static void *
-progress_cb (void *cls,
- const struct GNUNET_FS_ProgressInfo *event)
+progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
{
switch (event->status)
- {
- case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
+ {
+ case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
#if VERBOSE
- printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n",
- (unsigned long long) event->value.publish.completed,
- (unsigned long long) event->value.publish.size,
- event->value.publish.specifics.progress.depth,
- (unsigned long long)
event->value.publish.specifics.progress.offset);
-#endif
- break;
- case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
- printf ("Publishing complete, %llu kbps.\n",
- (unsigned long long) (FILESIZE * 1000 /
(1+GNUNET_TIME_absolute_get_duration (start).rel_value) / 1024));
- start = GNUNET_TIME_absolute_get ();
- unindex = GNUNET_FS_unindex_start (fs,
- fn,
- "unindex");
- GNUNET_assert (unindex != NULL);
- break;
- case GNUNET_FS_STATUS_UNINDEX_COMPLETED:
- printf ("Unindex complete, %llu kbps.\n",
- (unsigned long long) (FILESIZE * 1000 /
(1+GNUNET_TIME_absolute_get_duration (start).rel_value) / 1024));
- GNUNET_SCHEDULER_add_continuation (&abort_unindex_task,
- NULL,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- break;
- case GNUNET_FS_STATUS_UNINDEX_PROGRESS:
- consider_restart (event->status);
- GNUNET_assert (unindex == event->value.unindex.uc);
+ printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n",
+ (unsigned long long) event->value.publish.completed,
+ (unsigned long long) event->value.publish.size,
+ event->value.publish.specifics.progress.depth,
+ (unsigned long long) event->value.publish.specifics.
+ progress.offset);
+#endif
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
+ printf ("Publishing complete, %llu kbps.\n",
+ (unsigned long long) (FILESIZE * 1000 /
+ (1 +
+ GNUNET_TIME_absolute_get_duration
+ (start).rel_value) / 1024));
+ start = GNUNET_TIME_absolute_get ();
+ unindex = GNUNET_FS_unindex_start (fs, fn, "unindex");
+ GNUNET_assert (unindex != NULL);
+ break;
+ case GNUNET_FS_STATUS_UNINDEX_COMPLETED:
+ printf ("Unindex complete, %llu kbps.\n",
+ (unsigned long long) (FILESIZE * 1000 /
+ (1 +
+ GNUNET_TIME_absolute_get_duration
+ (start).rel_value) / 1024));
+ GNUNET_SCHEDULER_add_continuation (&abort_unindex_task, NULL,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ break;
+ case GNUNET_FS_STATUS_UNINDEX_PROGRESS:
+ consider_restart (event->status);
+ GNUNET_assert (unindex == event->value.unindex.uc);
#if VERBOSE
- printf ("Unindex is progressing (%llu/%llu at level %u off %llu)...\n",
- (unsigned long long) event->value.unindex.completed,
- (unsigned long long) event->value.unindex.size,
- event->value.unindex.specifics.progress.depth,
- (unsigned long long)
event->value.unindex.specifics.progress.offset);
+ printf ("Unindex is progressing (%llu/%llu at level %u off %llu)...\n",
+ (unsigned long long) event->value.unindex.completed,
+ (unsigned long long) event->value.unindex.size,
+ event->value.unindex.specifics.progress.depth,
+ (unsigned long long) event->value.unindex.specifics.
+ progress.offset);
#endif
- break;
- case GNUNET_FS_STATUS_PUBLISH_SUSPEND:
- if (event->value.publish.pc == publish)
- publish = NULL;
- break;
- case GNUNET_FS_STATUS_PUBLISH_RESUME:
- if (NULL == publish)
- {
- publish = event->value.publish.pc;
- return "publish-context";
- }
- break;
- case GNUNET_FS_STATUS_UNINDEX_SUSPEND:
- GNUNET_assert (event->value.unindex.uc == unindex);
- unindex = NULL;
- break;
- case GNUNET_FS_STATUS_UNINDEX_RESUME:
- GNUNET_assert (NULL == unindex);
- unindex = event->value.unindex.uc;
- return "unindex";
- case GNUNET_FS_STATUS_PUBLISH_ERROR:
- fprintf (stderr,
- "Error publishing file: %s\n",
- event->value.publish.specifics.error.message);
- GNUNET_break (0);
- GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
- NULL,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- break;
- case GNUNET_FS_STATUS_UNINDEX_ERROR:
- fprintf (stderr,
- "Error unindexing file: %s\n",
- event->value.unindex.specifics.error.message);
- GNUNET_SCHEDULER_add_continuation (&abort_unindex_task,
- NULL,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- break;
- case GNUNET_FS_STATUS_PUBLISH_START:
- GNUNET_assert (0 == strcmp ("publish-context",
event->value.publish.cctx));
- GNUNET_assert (NULL == event->value.publish.pctx);
- GNUNET_assert (FILESIZE == event->value.publish.size);
- GNUNET_assert (0 == event->value.publish.completed);
- GNUNET_assert (1 == event->value.publish.anonymity);
- break;
- case GNUNET_FS_STATUS_PUBLISH_STOPPED:
- GNUNET_assert (publish == event->value.publish.pc);
- GNUNET_assert (FILESIZE == event->value.publish.size);
- GNUNET_assert (1 == event->value.publish.anonymity);
- GNUNET_FS_stop (fs);
- fs = NULL;
- break;
- case GNUNET_FS_STATUS_UNINDEX_START:
- consider_restart (event->status);
- GNUNET_assert (unindex == NULL);
- GNUNET_assert (0 == strcmp ("unindex", event->value.unindex.cctx));
- GNUNET_assert (0 == strcmp (fn, event->value.unindex.filename));
- GNUNET_assert (FILESIZE == event->value.unindex.size);
- GNUNET_assert (0 == event->value.unindex.completed);
- break;
- case GNUNET_FS_STATUS_UNINDEX_STOPPED:
- GNUNET_assert (unindex == event->value.unindex.uc);
- GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
- NULL,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- break;
- default:
- printf ("Unexpected event: %d\n",
- event->status);
- break;
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_SUSPEND:
+ if (event->value.publish.pc == publish)
+ publish = NULL;
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_RESUME:
+ if (NULL == publish)
+ {
+ publish = event->value.publish.pc;
+ return "publish-context";
}
+ break;
+ case GNUNET_FS_STATUS_UNINDEX_SUSPEND:
+ GNUNET_assert (event->value.unindex.uc == unindex);
+ unindex = NULL;
+ break;
+ case GNUNET_FS_STATUS_UNINDEX_RESUME:
+ GNUNET_assert (NULL == unindex);
+ unindex = event->value.unindex.uc;
+ return "unindex";
+ case GNUNET_FS_STATUS_PUBLISH_ERROR:
+ fprintf (stderr,
+ "Error publishing file: %s\n",
+ event->value.publish.specifics.error.message);
+ GNUNET_break (0);
+ GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
+ NULL,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ break;
+ case GNUNET_FS_STATUS_UNINDEX_ERROR:
+ fprintf (stderr,
+ "Error unindexing file: %s\n",
+ event->value.unindex.specifics.error.message);
+ GNUNET_SCHEDULER_add_continuation (&abort_unindex_task,
+ NULL,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_START:
+ GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx));
+ GNUNET_assert (NULL == event->value.publish.pctx);
+ GNUNET_assert (FILESIZE == event->value.publish.size);
+ GNUNET_assert (0 == event->value.publish.completed);
+ GNUNET_assert (1 == event->value.publish.anonymity);
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_STOPPED:
+ GNUNET_assert (publish == event->value.publish.pc);
+ GNUNET_assert (FILESIZE == event->value.publish.size);
+ GNUNET_assert (1 == event->value.publish.anonymity);
+ GNUNET_FS_stop (fs);
+ fs = NULL;
+ break;
+ case GNUNET_FS_STATUS_UNINDEX_START:
+ consider_restart (event->status);
+ GNUNET_assert (unindex == NULL);
+ GNUNET_assert (0 == strcmp ("unindex", event->value.unindex.cctx));
+ GNUNET_assert (0 == strcmp (fn, event->value.unindex.filename));
+ GNUNET_assert (FILESIZE == event->value.unindex.size);
+ GNUNET_assert (0 == event->value.unindex.completed);
+ break;
+ case GNUNET_FS_STATUS_UNINDEX_STOPPED:
+ GNUNET_assert (unindex == event->value.unindex.uc);
+ GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
+ NULL,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ break;
+ default:
+ printf ("Unexpected event: %d\n", event->status);
+ break;
+ }
return NULL;
}
@@ -259,11 +257,11 @@
p->cfg = GNUNET_CONFIGURATION_create ();
#if START_ARM
p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
- "gnunet-service-arm",
+ "gnunet-service-arm",
#if VERBOSE
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", cfgname, NULL);
+ "-c", cfgname, NULL);
#endif
GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
}
@@ -274,16 +272,17 @@
{
#if START_ARM
if (NULL != p->arm_proc)
- {
- if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
- if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK)
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "ARM process %u stopped\n", GNUNET_OS_process_get_pid
(p->arm_proc));
- GNUNET_OS_process_close (p->arm_proc);
- p->arm_proc = NULL;
- }
+ {
+ if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
+ if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "ARM process %u stopped\n",
+ GNUNET_OS_process_get_pid (p->arm_proc));
+ GNUNET_OS_process_close (p->arm_proc);
+ p->arm_proc = NULL;
+ }
#endif
GNUNET_CONFIGURATION_destroy (p->cfg);
}
@@ -292,8 +291,7 @@
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *c)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
{
const char *keywords[] = {
"down_foo",
@@ -310,20 +308,20 @@
setup_peer (&p1, "test_fs_unindex_data.conf");
fn = GNUNET_DISK_mktemp ("gnunet-unindex-test-dst");
fs = GNUNET_FS_start (cfg,
- "test-fs-unindex-persistence",
- &progress_cb,
- NULL,
- GNUNET_FS_FLAGS_PERSISTENCE,
- GNUNET_FS_OPTIONS_END);
- GNUNET_assert (NULL != fs);
+ "test-fs-unindex-persistence",
+ &progress_cb,
+ NULL,
+ GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END);
+ GNUNET_assert (NULL != fs);
buf = GNUNET_malloc (FILESIZE);
for (i = 0; i < FILESIZE; i++)
buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
GNUNET_assert (FILESIZE ==
- GNUNET_DISK_fn_write (fn,
- buf,
- FILESIZE,
- GNUNET_DISK_PERM_USER_READ |
GNUNET_DISK_PERM_USER_WRITE));
+ GNUNET_DISK_fn_write (fn,
+ buf,
+ FILESIZE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE));
GNUNET_free (buf);
meta = GNUNET_CONTAINER_meta_data_create ();
kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords);
@@ -332,20 +330,18 @@
bo.replication_level = 0;
bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
fi = GNUNET_FS_file_information_create_from_file (fs,
- "publish-context",
- fn,
- kuri,
- meta,
- GNUNET_YES,
- &bo);
+ "publish-context",
+ fn,
+ kuri,
+ meta, GNUNET_YES, &bo);
GNUNET_FS_uri_destroy (kuri);
GNUNET_CONTAINER_meta_data_destroy (meta);
GNUNET_assert (NULL != fi);
start = GNUNET_TIME_absolute_get ();
publish = GNUNET_FS_publish_start (fs,
- fi,
- NULL, NULL, NULL,
- GNUNET_FS_PUBLISH_OPTION_NONE);
+ fi,
+ NULL, NULL, NULL,
+ GNUNET_FS_PUBLISH_OPTION_NONE);
GNUNET_assert (publish != NULL);
}
@@ -353,7 +349,7 @@
int
main (int argc, char *argv[])
{
- char *const argvx[] = {
+ char *const argvx[] = {
"test-fs-unindex",
"-c",
"test_fs_unindex_data.conf",
@@ -366,23 +362,22 @@
GNUNET_GETOPT_OPTION_END
};
- GNUNET_log_setup ("test_fs_unindex_persistence",
+ GNUNET_log_setup ("test_fs_unindex_persistence",
#if VERBOSE
- "DEBUG",
+ "DEBUG",
#else
- "WARNING",
+ "WARNING",
#endif
- NULL);
+ NULL);
GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
- argvx, "test-fs-unindex",
- "nohelp", options, &run, NULL);
+ argvx, "test-fs-unindex", "nohelp", options, &run, NULL);
stop_arm (&p1);
GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-unindex/");
if (NULL != fn)
- {
- GNUNET_DISK_directory_remove (fn);
- GNUNET_free (fn);
- }
+ {
+ GNUNET_DISK_directory_remove (fn);
+ GNUNET_free (fn);
+ }
return 0;
}
Modified: gnunet/src/fs/test_fs_uri.c
===================================================================
--- gnunet/src/fs/test_fs_uri.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/fs/test_fs_uri.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -39,37 +39,37 @@
char *emsg;
if (NULL != (ret = GNUNET_FS_uri_parse ("gnunet://fs/ksk/++", &emsg)))
- {
- GNUNET_FS_uri_destroy (ret);
- ABORT ();
- }
+ {
+ GNUNET_FS_uri_destroy (ret);
+ ABORT ();
+ }
GNUNET_free (emsg);
ret = GNUNET_FS_uri_parse ("gnunet://fs/ksk/foo+bar", &emsg);
if (ret == NULL)
- {
- GNUNET_free (emsg);
- ABORT ();
- }
+ {
+ GNUNET_free (emsg);
+ ABORT ();
+ }
if (!GNUNET_FS_uri_test_ksk (ret))
- {
- GNUNET_FS_uri_destroy (ret);
- ABORT ();
- }
+ {
+ GNUNET_FS_uri_destroy (ret);
+ ABORT ();
+ }
if ((2 != ret->data.ksk.keywordCount) ||
(0 != strcmp (" foo", ret->data.ksk.keywords[0])) ||
(0 != strcmp (" bar", ret->data.ksk.keywords[1])))
- {
- GNUNET_FS_uri_destroy (ret);
- ABORT ();
- }
+ {
+ GNUNET_FS_uri_destroy (ret);
+ ABORT ();
+ }
uri = GNUNET_FS_uri_to_string (ret);
if (0 != strcmp (uri, "gnunet://fs/ksk/foo+bar"))
- {
- GNUNET_free (uri);
- GNUNET_FS_uri_destroy (ret);
- ABORT ();
- }
+ {
+ GNUNET_free (uri);
+ GNUNET_FS_uri_destroy (ret);
+ ABORT ();
+ }
GNUNET_free (uri);
GNUNET_FS_uri_destroy (ret);
return 0;
@@ -86,46 +86,45 @@
struct GNUNET_CONFIGURATION_Handle *cfg;
baseURI =
- GNUNET_FS_uri_parse
("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.42",
&emsg);
+ GNUNET_FS_uri_parse
+
("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.42",
+ &emsg);
GNUNET_assert (baseURI != NULL);
GNUNET_assert (emsg == NULL);
cfg = GNUNET_CONFIGURATION_create ();
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_parse (cfg, "test_fs_uri_data.conf"))
- {
- fprintf (stderr, "Failed to parse configuration file\n");
- GNUNET_FS_uri_destroy (baseURI);
- GNUNET_CONFIGURATION_destroy (cfg);
- return 1;
- }
- uri = GNUNET_FS_uri_loc_create (baseURI,
- cfg,
- GNUNET_TIME_absolute_get ());
+ if (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, "test_fs_uri_data.conf"))
+ {
+ fprintf (stderr, "Failed to parse configuration file\n");
+ GNUNET_FS_uri_destroy (baseURI);
+ GNUNET_CONFIGURATION_destroy (cfg);
+ return 1;
+ }
+ uri = GNUNET_FS_uri_loc_create (baseURI, cfg, GNUNET_TIME_absolute_get ());
if (uri == NULL)
- {
- GNUNET_break (0);
- GNUNET_FS_uri_destroy (baseURI);
- GNUNET_CONFIGURATION_destroy (cfg);
- return 1;
- }
+ {
+ GNUNET_break (0);
+ GNUNET_FS_uri_destroy (baseURI);
+ GNUNET_CONFIGURATION_destroy (cfg);
+ return 1;
+ }
if (!GNUNET_FS_uri_test_loc (uri))
- {
- GNUNET_break (0);
- GNUNET_FS_uri_destroy (uri);
- GNUNET_FS_uri_destroy (baseURI);
- GNUNET_CONFIGURATION_destroy (cfg);
- return 1;
- }
+ {
+ GNUNET_break (0);
+ GNUNET_FS_uri_destroy (uri);
+ GNUNET_FS_uri_destroy (baseURI);
+ GNUNET_CONFIGURATION_destroy (cfg);
+ return 1;
+ }
uri2 = GNUNET_FS_uri_loc_get_uri (uri);
if (!GNUNET_FS_uri_test_equal (baseURI, uri2))
- {
- GNUNET_break (0);
- GNUNET_FS_uri_destroy (uri);
- GNUNET_FS_uri_destroy (uri2);
- GNUNET_FS_uri_destroy (baseURI);
- GNUNET_CONFIGURATION_destroy (cfg);
- return 1;
- }
+ {
+ GNUNET_break (0);
+ GNUNET_FS_uri_destroy (uri);
+ GNUNET_FS_uri_destroy (uri2);
+ GNUNET_FS_uri_destroy (baseURI);
+ GNUNET_CONFIGURATION_destroy (cfg);
+ return 1;
+ }
GNUNET_FS_uri_destroy (uri2);
GNUNET_FS_uri_destroy (baseURI);
uric = GNUNET_FS_uri_to_string (uri);
@@ -136,22 +135,22 @@
uri2 = GNUNET_FS_uri_parse (uric, &emsg);
GNUNET_free (uric);
if (uri2 == NULL)
- {
- GNUNET_break (0);
- GNUNET_FS_uri_destroy (uri);
- GNUNET_CONFIGURATION_destroy (cfg);
- GNUNET_free (emsg);
- return 1;
- }
+ {
+ GNUNET_break (0);
+ GNUNET_FS_uri_destroy (uri);
+ GNUNET_CONFIGURATION_destroy (cfg);
+ GNUNET_free (emsg);
+ return 1;
+ }
GNUNET_assert (NULL == emsg);
if (GNUNET_YES != GNUNET_FS_uri_test_equal (uri, uri2))
- {
- GNUNET_break (0);
- GNUNET_FS_uri_destroy (uri);
- GNUNET_FS_uri_destroy (uri2);
- GNUNET_CONFIGURATION_destroy (cfg);
- return 1;
- }
+ {
+ GNUNET_break (0);
+ GNUNET_FS_uri_destroy (uri);
+ GNUNET_FS_uri_destroy (uri2);
+ GNUNET_CONFIGURATION_destroy (cfg);
+ return 1;
+ }
GNUNET_FS_uri_destroy (uri2);
GNUNET_FS_uri_destroy (uri);
GNUNET_CONFIGURATION_destroy (cfg);
@@ -166,51 +165,57 @@
char *emsg;
if (NULL !=
- (ret = GNUNET_FS_uri_parse
("gnunet://fs/sks/D1KJS9H2A82Q65VKQ0ML3RFU6U1D3VUK", &emsg)))
- {
- GNUNET_FS_uri_destroy (ret);
- ABORT ();
- }
+ (ret =
+ GNUNET_FS_uri_parse ("gnunet://fs/sks/D1KJS9H2A82Q65VKQ0ML3RFU6U1D3VUK",
+ &emsg)))
+ {
+ GNUNET_FS_uri_destroy (ret);
+ ABORT ();
+ }
GNUNET_free (emsg);
if (NULL !=
- (ret = GNUNET_FS_uri_parse
("gnunet://fs/sks/D1KJS9H2A82Q65VKQ0ML3RFU6U1D3V/test", &emsg)))
- {
- GNUNET_FS_uri_destroy (ret);
- ABORT ();
- }
+ (ret =
+ GNUNET_FS_uri_parse
+ ("gnunet://fs/sks/D1KJS9H2A82Q65VKQ0ML3RFU6U1D3V/test", &emsg)))
+ {
+ GNUNET_FS_uri_destroy (ret);
+ ABORT ();
+ }
GNUNET_free (emsg);
if (NULL != (ret = GNUNET_FS_uri_parse ("gnunet://fs/sks/test", &emsg)))
- {
- GNUNET_FS_uri_destroy (ret);
- ABORT ();
- }
+ {
+ GNUNET_FS_uri_destroy (ret);
+ ABORT ();
+ }
GNUNET_free (emsg);
ret =
- GNUNET_FS_uri_parse
("gnunet://fs/sks/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820/test",
&emsg);
+ GNUNET_FS_uri_parse
+
("gnunet://fs/sks/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820/test",
+ &emsg);
if (ret == NULL)
- {
- GNUNET_free (emsg);
- ABORT ();
- }
+ {
+ GNUNET_free (emsg);
+ ABORT ();
+ }
if (GNUNET_FS_uri_test_ksk (ret))
- {
- GNUNET_FS_uri_destroy (ret);
- ABORT ();
- }
+ {
+ GNUNET_FS_uri_destroy (ret);
+ ABORT ();
+ }
if (!GNUNET_FS_uri_test_sks (ret))
- {
- GNUNET_FS_uri_destroy (ret);
- ABORT ();
- }
+ {
+ GNUNET_FS_uri_destroy (ret);
+ ABORT ();
+ }
uri = GNUNET_FS_uri_to_string (ret);
if (0 != strcmp (uri,
"gnunet://fs/sks/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820/test"))
- {
- GNUNET_FS_uri_destroy (ret);
- GNUNET_free (uri);
- ABORT ();
- }
+ {
+ GNUNET_FS_uri_destroy (ret);
+ GNUNET_free (uri);
+ ABORT ();
+ }
GNUNET_free (uri);
GNUNET_FS_uri_destroy (ret);
return 0;
@@ -224,57 +229,68 @@
char *emsg;
if (NULL !=
- (ret = GNUNET_FS_uri_parse
("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H00000440000.42",
&emsg)))
- {
- GNUNET_FS_uri_destroy (ret);
- ABORT ();
- }
+ (ret =
+ GNUNET_FS_uri_parse
+
("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H00000440000.42",
+ &emsg)))
+ {
+ GNUNET_FS_uri_destroy (ret);
+ ABORT ();
+ }
GNUNET_free (emsg);
if (NULL !=
- (ret = GNUNET_FS_uri_parse
("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000",
&emsg)))
- {
- GNUNET_FS_uri_destroy (ret);
- ABORT ();
- }
+ (ret =
+ GNUNET_FS_uri_parse
+
("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000",
+ &emsg)))
+ {
+ GNUNET_FS_uri_destroy (ret);
+ ABORT ();
+ }
GNUNET_free (emsg);
if (NULL !=
- (ret = GNUNET_FS_uri_parse
("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.FGH",
&emsg)))
- {
- GNUNET_FS_uri_destroy (ret);
- ABORT ();
- }
+ (ret =
+ GNUNET_FS_uri_parse
+
("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.FGH",
+ &emsg)))
+ {
+ GNUNET_FS_uri_destroy (ret);
+ ABORT ();
+ }
GNUNET_free (emsg);
ret =
- GNUNET_FS_uri_parse
("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.42",
&emsg);
+ GNUNET_FS_uri_parse
+
("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.42",
+ &emsg);
if (ret == NULL)
- {
- GNUNET_free (emsg);
- ABORT ();
- }
+ {
+ GNUNET_free (emsg);
+ ABORT ();
+ }
if (GNUNET_FS_uri_test_ksk (ret))
- {
- GNUNET_FS_uri_destroy (ret);
- ABORT ();
- }
+ {
+ GNUNET_FS_uri_destroy (ret);
+ ABORT ();
+ }
if (GNUNET_FS_uri_test_sks (ret))
- {
- GNUNET_FS_uri_destroy (ret);
- ABORT ();
- }
+ {
+ GNUNET_FS_uri_destroy (ret);
+ ABORT ();
+ }
if (GNUNET_ntohll (ret->data.chk.file_length) != 42)
- {
- GNUNET_FS_uri_destroy (ret);
- ABORT ();
- }
+ {
+ GNUNET_FS_uri_destroy (ret);
+ ABORT ();
+ }
uri = GNUNET_FS_uri_to_string (ret);
if (0 != strcmp (uri,
"gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.42"))
- {
- GNUNET_free (uri);
- GNUNET_FS_uri_destroy (ret);
- ABORT ();
- }
+ {
+ GNUNET_free (uri);
+ GNUNET_FS_uri_destroy (ret);
+ ABORT ();
+ }
GNUNET_free (uri);
GNUNET_FS_uri_destroy (ret);
return 0;
@@ -286,22 +302,22 @@
int failureCount = 0;
int i;
- GNUNET_log_setup ("test_fs_uri",
+ GNUNET_log_setup ("test_fs_uri",
#if VERBOSE
- "DEBUG",
+ "DEBUG",
#else
- "WARNING",
+ "WARNING",
#endif
- NULL);
+ NULL);
GNUNET_CRYPTO_random_disable_entropy_gathering ();
failureCount += testKeyword ();
failureCount += testLocation ();
for (i = 0; i < 255; i++)
- {
- /* fprintf (stderr, "."); */
- failureCount += testNamespace (i);
- failureCount += testFile (i);
- }
+ {
+ /* fprintf (stderr, "."); */
+ failureCount += testNamespace (i);
+ failureCount += testFile (i);
+ }
/* fprintf (stderr, "\n"); */
GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-uri");
if (failureCount != 0)
Modified: gnunet/src/fs/test_gnunet_service_fs_migration.c
===================================================================
--- gnunet/src/fs/test_gnunet_service_fs_migration.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/fs/test_gnunet_service_fs_migration.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -53,172 +53,140 @@
static struct GNUNET_TIME_Absolute start_time;
static void
-do_stop (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_TIME_Relative del;
char *fancy;
- GNUNET_FS_TEST_daemons_stop (2,
- daemons);
+ GNUNET_FS_TEST_daemons_stop (2, daemons);
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
- {
- del = GNUNET_TIME_absolute_get_duration (start_time);
- if (del.rel_value == 0)
- del.rel_value = 1;
- fancy = GNUNET_STRINGS_byte_size_fancy (((unsigned long long)FILESIZE) *
1000LL / del.rel_value);
- fprintf (stdout,
- "Download speed was %s/s\n",
- fancy);
- GNUNET_free (fancy);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Finished download, shutting down\n",
- (unsigned long long) FILESIZE);
- }
+ {
+ del = GNUNET_TIME_absolute_get_duration (start_time);
+ if (del.rel_value == 0)
+ del.rel_value = 1;
+ fancy =
+ GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) *
+ 1000LL / del.rel_value);
+ fprintf (stdout, "Download speed was %s/s\n", fancy);
+ GNUNET_free (fancy);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Finished download, shutting down\n",
+ (unsigned long long) FILESIZE);
+ }
else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Timeout during download, shutting down with error\n");
- ok = 1;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Timeout during download, shutting down with error\n");
+ ok = 1;
+ }
}
static void
-do_download (void *cls,
- const char *emsg)
+do_download (void *cls, const char *emsg)
{
struct GNUNET_FS_Uri *uri = cls;
if (emsg != NULL)
- {
- GNUNET_FS_TEST_daemons_stop (2,
- daemons);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Failed to stop source daemon: %s\n",
- emsg);
- GNUNET_FS_uri_destroy (uri);
- ok = 1;
- return;
- }
+ {
+ GNUNET_FS_TEST_daemons_stop (2, daemons);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to stop source daemon: %s\n", emsg);
+ GNUNET_FS_uri_destroy (uri);
+ ok = 1;
+ return;
+ }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Downloading %llu bytes\n",
- (unsigned long long) FILESIZE);
+ "Downloading %llu bytes\n", (unsigned long long) FILESIZE);
start_time = GNUNET_TIME_absolute_get ();
GNUNET_FS_TEST_download (daemons[0],
- TIMEOUT,
- 1, SEED, uri,
- VERBOSE,
- &do_stop, NULL);
+ TIMEOUT, 1, SEED, uri, VERBOSE, &do_stop, NULL);
GNUNET_FS_uri_destroy (uri);
}
static void
-stop_source_peer (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+stop_source_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_FS_Uri *uri = cls;
struct GNUNET_TESTING_PeerGroup *pg;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Stopping source peer\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping source peer\n");
pg = GNUNET_FS_TEST_get_group (daemons);
- GNUNET_TESTING_daemons_vary (pg, 1, GNUNET_NO, TIMEOUT,
- &do_download,
- uri);
+ GNUNET_TESTING_daemons_vary (pg, 1, GNUNET_NO, TIMEOUT, &do_download, uri);
}
static void
-do_wait (void *cls,
- const struct GNUNET_FS_Uri *uri)
+do_wait (void *cls, const struct GNUNET_FS_Uri *uri)
{
struct GNUNET_FS_Uri *d;
if (NULL == uri)
- {
- GNUNET_FS_TEST_daemons_stop (2,
- daemons);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Timeout during upload attempt, shutting down with error\n");
- ok = 1;
- return;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Waiting to allow content to migrate\n");
+ {
+ GNUNET_FS_TEST_daemons_stop (2, daemons);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Timeout during upload attempt, shutting down with error\n");
+ ok = 1;
+ return;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Waiting to allow content to
migrate\n");
d = GNUNET_FS_uri_dup (uri);
- (void) GNUNET_SCHEDULER_add_delayed (MIGRATION_DELAY,
- &stop_source_peer,
- d);
+ (void) GNUNET_SCHEDULER_add_delayed (MIGRATION_DELAY, &stop_source_peer, d);
}
static void
-do_publish (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_publish (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
- {
- GNUNET_FS_TEST_daemons_stop (2,
- daemons);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Timeout during connect attempt, shutting down with error\n");
- ok = 1;
- return;
- }
+ {
+ GNUNET_FS_TEST_daemons_stop (2, daemons);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Timeout during connect attempt, shutting down with error\n");
+ ok = 1;
+ return;
+ }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Publishing %llu bytes\n",
- (unsigned long long) FILESIZE);
+ "Publishing %llu bytes\n", (unsigned long long) FILESIZE);
GNUNET_FS_TEST_publish (daemons[1],
- TIMEOUT,
- 1, GNUNET_NO, FILESIZE, SEED,
- VERBOSE,
- &do_wait, NULL);
+ TIMEOUT,
+ 1, GNUNET_NO, FILESIZE, SEED,
+ VERBOSE, &do_wait, NULL);
}
static void
-do_connect (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
- {
- fprintf (stderr,
- "Daemons failed to start!\n");
- GNUNET_break (0);
- ok = 1;
- return;
- }
+ {
+ fprintf (stderr, "Daemons failed to start!\n");
+ GNUNET_break (0);
+ ok = 1;
+ return;
+ }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Daemons started, will now try to connect them\n");
+ "Daemons started, will now try to connect them\n");
GNUNET_FS_TEST_daemons_connect (daemons[0],
- daemons[1],
- TIMEOUT,
- &do_publish,
- NULL);
+ daemons[1], TIMEOUT, &do_publish, NULL);
}
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
GNUNET_FS_TEST_daemons_start ("test_gnunet_service_fs_migration_data.conf",
- TIMEOUT,
- 2,
- daemons,
- &do_connect,
- NULL);
+ TIMEOUT, 2, daemons, &do_connect, NULL);
}
int
main (int argc, char *argv[])
{
- char *const argvx[] = {
+ char *const argvx[] = {
"test-gnunet-service-fs-migration",
"-c",
"fs_test_lib_data.conf",
@@ -232,16 +200,16 @@
};
GNUNET_DISK_directory_remove ("/tmp/test-gnunet-service-fs-migration/");
- GNUNET_log_setup ("test_gnunet_service_fs_migration",
+ GNUNET_log_setup ("test_gnunet_service_fs_migration",
#if VERBOSE
- "DEBUG",
+ "DEBUG",
#else
- "WARNING",
+ "WARNING",
#endif
- NULL);
+ NULL);
GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
argvx, "test-gnunet-service-fs-migration",
- "nohelp", options, &run, NULL);
+ "nohelp", options, &run, NULL);
GNUNET_DISK_directory_remove ("/tmp/test-gnunet-service-fs-migration/");
return ok;
}
Modified: gnunet/src/fs/test_gnunet_service_fs_p2p.c
===================================================================
--- gnunet/src/fs/test_gnunet_service_fs_p2p.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/fs/test_gnunet_service_fs_p2p.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -49,120 +49,100 @@
static struct GNUNET_TIME_Absolute start_time;
static void
-do_stop (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_TIME_Relative del;
char *fancy;
- GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS,
- daemons);
+ GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons);
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
- {
- del = GNUNET_TIME_absolute_get_duration (start_time);
- if (del.rel_value == 0)
- del.rel_value = 1;
- fancy = GNUNET_STRINGS_byte_size_fancy (((unsigned long long)FILESIZE) *
1000LL / del.rel_value);
- fprintf (stdout,
- "Download speed was %s/s\n",
- fancy);
- GNUNET_free (fancy);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Finished download, shutting down\n",
- (unsigned long long) FILESIZE);
- }
+ {
+ del = GNUNET_TIME_absolute_get_duration (start_time);
+ if (del.rel_value == 0)
+ del.rel_value = 1;
+ fancy =
+ GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) *
+ 1000LL / del.rel_value);
+ fprintf (stdout, "Download speed was %s/s\n", fancy);
+ GNUNET_free (fancy);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Finished download, shutting down\n",
+ (unsigned long long) FILESIZE);
+ }
else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Timeout during download, shutting down with error\n");
- ok = 1;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Timeout during download, shutting down with error\n");
+ ok = 1;
+ }
}
static void
-do_download (void *cls,
- const struct GNUNET_FS_Uri *uri)
+do_download (void *cls, const struct GNUNET_FS_Uri *uri)
{
if (NULL == uri)
- {
- GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS,
- daemons);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Timeout during upload attempt, shutting down with error\n");
- ok = 1;
- return;
- }
+ {
+ GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Timeout during upload attempt, shutting down with error\n");
+ ok = 1;
+ return;
+ }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Downloading %llu bytes\n",
- (unsigned long long) FILESIZE);
+ "Downloading %llu bytes\n", (unsigned long long) FILESIZE);
start_time = GNUNET_TIME_absolute_get ();
GNUNET_FS_TEST_download (daemons[0],
- TIMEOUT,
- 1, SEED, uri,
- VERBOSE,
- &do_stop, NULL);
+ TIMEOUT, 1, SEED, uri, VERBOSE, &do_stop, NULL);
}
static void
-do_publish (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_publish (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
- {
- GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS,
- daemons);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Timeout during connect attempt, shutting down with error\n");
- ok = 1;
- return;
- }
+ {
+ GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Timeout during connect attempt, shutting down with error\n");
+ ok = 1;
+ return;
+ }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Publishing %llu bytes\n",
- (unsigned long long) FILESIZE);
+ "Publishing %llu bytes\n", (unsigned long long) FILESIZE);
GNUNET_FS_TEST_publish (daemons[1],
- TIMEOUT,
- 1, GNUNET_NO, FILESIZE, SEED,
- VERBOSE,
- &do_download, NULL);
+ TIMEOUT,
+ 1, GNUNET_NO, FILESIZE, SEED,
+ VERBOSE, &do_download, NULL);
}
static void
-do_connect (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GNUNET_assert (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Daemons started, will now try to connect them\n");
+ "Daemons started, will now try to connect them\n");
GNUNET_FS_TEST_daemons_connect (daemons[0],
- daemons[1],
- TIMEOUT,
- &do_publish,
- NULL);
+ daemons[1], TIMEOUT, &do_publish, NULL);
}
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
GNUNET_FS_TEST_daemons_start ("fs_test_lib_data.conf",
- TIMEOUT,
- NUM_DAEMONS,
- daemons,
- &do_connect,
- NULL);
+ TIMEOUT,
+ NUM_DAEMONS, daemons, &do_connect, NULL);
}
int
main (int argc, char *argv[])
{
- char *const argvx[] = {
+ char *const argvx[] = {
"test-gnunet-service-fs-p2p",
"-c",
"fs_test_lib_data.conf",
@@ -176,16 +156,16 @@
};
GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
- GNUNET_log_setup ("test_gnunet_service_fs_p2p",
+ GNUNET_log_setup ("test_gnunet_service_fs_p2p",
#if VERBOSE
- "DEBUG",
+ "DEBUG",
#else
- "WARNING",
+ "WARNING",
#endif
- NULL);
+ NULL);
GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
argvx, "test-gnunet-service-fs-p2p",
- "nohelp", options, &run, NULL);
+ "nohelp", options, &run, NULL);
GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
return ok;
}
Modified: gnunet/src/hello/hello.c
===================================================================
--- gnunet/src/hello/hello.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/hello/hello.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -121,35 +121,35 @@
pos = buf;
slen = 1;
while ((left > 0) && ('\0' != *pos))
- {
- left--;
- pos++;
- slen++;
- }
+ {
+ left--;
+ pos++;
+ slen++;
+ }
if (left == 0)
- {
- /* 0-termination not found */
- GNUNET_break_op (0);
- abort ();
- return 0;
- }
+ {
+ /* 0-termination not found */
+ GNUNET_break_op (0);
+ abort ();
+ return 0;
+ }
pos++;
if (left < sizeof (uint16_t) + sizeof (struct GNUNET_TIME_AbsoluteNBO))
- {
- /* not enough space for addrlen */
- GNUNET_break_op (0);
- return 0;
- }
+ {
+ /* not enough space for addrlen */
+ GNUNET_break_op (0);
+ return 0;
+ }
memcpy (&alen, pos, sizeof (uint16_t));
alen = ntohs (alen);
*ralen = alen;
slen += alen + sizeof (uint16_t) + sizeof (struct GNUNET_TIME_AbsoluteNBO);
if (max < slen)
- {
- /* not enough space for addr */
- GNUNET_break_op (0);
- return 0;
- }
+ {
+ /* not enough space for addr */
+ GNUNET_break_op (0);
+ return 0;
+ }
return slen;
}
@@ -177,13 +177,13 @@
max = sizeof (buffer);
used = 0;
if (addrgen != NULL)
+ {
+ while (0 != (ret = addrgen (addrgen_cls, max, &buffer[used])))
{
- while (0 != (ret = addrgen (addrgen_cls, max, &buffer[used])))
- {
- max -= ret;
- used += ret;
- }
+ max -= ret;
+ used += ret;
}
+ }
hello = GNUNET_malloc (sizeof (struct GNUNET_HELLO_Message) + used);
hello->header.type = htons (GNUNET_MESSAGE_TYPE_HELLO);
hello->header.size = htons (sizeof (struct GNUNET_HELLO_Message) + used);
@@ -225,46 +225,44 @@
return NULL;
ret = NULL;
if (return_modified)
- {
- ret = GNUNET_malloc (msize);
- memcpy (ret, msg, msize);
- }
+ {
+ ret = GNUNET_malloc (msize);
+ memcpy (ret, msg, msize);
+ }
inptr = (const char *) &msg[1];
insize = msize - sizeof (struct GNUNET_HELLO_Message);
wpos = 0;
woff = (ret != NULL) ? (char *) &ret[1] : NULL;
while (insize > 0)
+ {
+ esize = get_hello_address_size (inptr, insize, &alen);
+ if (esize == 0)
{
- esize = get_hello_address_size (inptr, insize, &alen);
- if (esize == 0)
- {
- GNUNET_break (0);
- GNUNET_free_non_null (ret);
- return NULL;
- }
- memcpy (&expire,
- &inptr[esize - alen - sizeof (struct GNUNET_TIME_AbsoluteNBO)],
- sizeof (struct GNUNET_TIME_AbsoluteNBO));
- iret = it (it_cls,
- inptr,
- GNUNET_TIME_absolute_ntoh (expire),
- &inptr[esize - alen], alen);
- if (iret == GNUNET_SYSERR)
- {
- if (ret != NULL)
- ret->header.size =
- ntohs (sizeof (struct GNUNET_HELLO_Message) + wpos);
- return ret;
- }
- if ((iret == GNUNET_OK) && (ret != NULL))
- {
- memcpy (woff, inptr, esize);
- woff += esize;
- wpos += esize;
- }
- insize -= esize;
- inptr += esize;
+ GNUNET_break (0);
+ GNUNET_free_non_null (ret);
+ return NULL;
}
+ memcpy (&expire,
+ &inptr[esize - alen - sizeof (struct GNUNET_TIME_AbsoluteNBO)],
+ sizeof (struct GNUNET_TIME_AbsoluteNBO));
+ iret = it (it_cls,
+ inptr,
+ GNUNET_TIME_absolute_ntoh (expire), &inptr[esize - alen], alen);
+ if (iret == GNUNET_SYSERR)
+ {
+ if (ret != NULL)
+ ret->header.size = ntohs (sizeof (struct GNUNET_HELLO_Message) + wpos);
+ return ret;
+ }
+ if ((iret == GNUNET_OK) && (ret != NULL))
+ {
+ memcpy (woff, inptr, esize);
+ woff += esize;
+ wpos += esize;
+ }
+ insize -= esize;
+ inptr += esize;
+ }
if (ret != NULL)
ret->header.size = ntohs (sizeof (struct GNUNET_HELLO_Message) + wpos);
return ret;
@@ -289,14 +287,14 @@
{
struct ExpireContext *ec = cls;
- if ( (addrlen == ec->addrlen) &&
- (0 == memcmp (addr, ec->addr, addrlen)) &&
- (0 == strcmp (tname, ec->tname)) )
- {
- ec->found = GNUNET_YES;
- ec->expiration = expiration;
- return GNUNET_SYSERR; /* done here */
- }
+ if ((addrlen == ec->addrlen) &&
+ (0 == memcmp (addr, ec->addr, addrlen)) &&
+ (0 == strcmp (tname, ec->tname)))
+ {
+ ec->found = GNUNET_YES;
+ ec->expiration = expiration;
+ return GNUNET_SYSERR; /* done here */
+ }
return GNUNET_OK;
}
@@ -328,18 +326,17 @@
ec.found = GNUNET_NO;
ec.tname = tname;
GNUNET_HELLO_iterate_addresses (mc->other, GNUNET_NO, &get_match_exp, &ec);
- if ( (ec.found == GNUNET_NO) ||
- (ec.expiration.abs_value < expiration.abs_value) ||
- ( (ec.expiration.abs_value == expiration.abs_value) &&
- (mc->take_equal == GNUNET_YES) ) )
- {
- mc->ret += GNUNET_HELLO_add_address (tname,
- expiration,
- addr,
- addrlen,
- &mc->buf[mc->ret],
- mc->max - mc->ret);
- }
+ if ((ec.found == GNUNET_NO) ||
+ (ec.expiration.abs_value < expiration.abs_value) ||
+ ((ec.expiration.abs_value == expiration.abs_value) &&
+ (mc->take_equal == GNUNET_YES)))
+ {
+ mc->ret += GNUNET_HELLO_add_address (tname,
+ expiration,
+ addr,
+ addrlen,
+ &mc->buf[mc->ret], mc->max - mc->ret);
+ }
return GNUNET_OK;
}
@@ -461,6 +458,7 @@
GNUNET_HELLO_size (const struct GNUNET_HELLO_Message *hello)
{
uint16_t ret = ntohs (hello->header.size);
+
if ((ret < sizeof (struct GNUNET_HELLO_Message)) ||
(ntohs (hello->header.type) != GNUNET_MESSAGE_TYPE_HELLO))
return 0;
@@ -477,10 +475,10 @@
*/
int
GNUNET_HELLO_get_key (const struct GNUNET_HELLO_Message *hello,
- struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
- *publicKey)
+ struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
*publicKey)
{
uint16_t ret = ntohs (hello->header.size);
+
if ((ret < sizeof (struct GNUNET_HELLO_Message)) ||
(ntohs (hello->header.type) != GNUNET_MESSAGE_TYPE_HELLO))
return GNUNET_SYSERR;
@@ -498,15 +496,16 @@
*/
int
GNUNET_HELLO_get_id (const struct GNUNET_HELLO_Message *hello,
- struct GNUNET_PeerIdentity *peer)
+ struct GNUNET_PeerIdentity *peer)
{
uint16_t ret = ntohs (hello->header.size);
+
if ((ret < sizeof (struct GNUNET_HELLO_Message)) ||
(ntohs (hello->header.type) != GNUNET_MESSAGE_TYPE_HELLO))
return GNUNET_SYSERR;
GNUNET_CRYPTO_hash (&hello->publicKey,
- sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
- &peer->hashPubKey);
+ sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+ &peer->hashPubKey);
return GNUNET_OK;
}
@@ -523,6 +522,7 @@
GNUNET_HELLO_get_header (struct GNUNET_HELLO_Message *hello)
{
uint16_t ret = ntohs (hello->header.size);
+
if ((ret < sizeof (struct GNUNET_HELLO_Message)) ||
(ntohs (hello->header.type) != GNUNET_MESSAGE_TYPE_HELLO))
return NULL;
@@ -538,11 +538,11 @@
struct GNUNET_TIME_Absolute result;
const struct GNUNET_HELLO_Message *h2;
-
+
const char *tname;
-
+
const void *addr;
-
+
struct GNUNET_TIME_Absolute expiration;
int found;
@@ -554,27 +554,23 @@
static int
find_other_matching (void *cls,
- const char *tname,
- struct GNUNET_TIME_Absolute expiration,
- const void *addr, uint16_t addrlen)
+ const char *tname,
+ struct GNUNET_TIME_Absolute expiration,
+ const void *addr, uint16_t addrlen)
{
struct EqualsContext *ec = cls;
if (expiration.abs_value < ec->expiration_limit.abs_value)
return GNUNET_YES;
- if ( (addrlen == ec->addrlen) &&
- (0 == strcmp (tname,
- ec->tname)) &&
- (0 == memcmp (addr,
- ec->addr,
- addrlen)) )
- {
- ec->found = GNUNET_YES;
- if (expiration.abs_value < ec->expiration.abs_value)
- ec->result = GNUNET_TIME_absolute_min (expiration,
- ec->result);
- return GNUNET_SYSERR;
- }
+ if ((addrlen == ec->addrlen) &&
+ (0 == strcmp (tname,
+ ec->tname)) && (0 == memcmp (addr, ec->addr, addrlen)))
+ {
+ ec->found = GNUNET_YES;
+ if (expiration.abs_value < ec->expiration.abs_value)
+ ec->result = GNUNET_TIME_absolute_min (expiration, ec->result);
+ return GNUNET_SYSERR;
+ }
return GNUNET_YES;
}
@@ -594,15 +590,12 @@
ec->addr = addr;
ec->addrlen = addrlen;
ec->found = GNUNET_NO;
- GNUNET_HELLO_iterate_addresses (ec->h2,
- GNUNET_NO,
- &find_other_matching,
- ec);
+ GNUNET_HELLO_iterate_addresses (ec->h2, GNUNET_NO, &find_other_matching, ec);
if (ec->found == GNUNET_NO)
- {
- ec->result = GNUNET_TIME_UNIT_ZERO_ABS;
- return GNUNET_SYSERR;
- }
+ {
+ ec->result = GNUNET_TIME_UNIT_ZERO_ABS;
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
}
@@ -622,34 +615,26 @@
* zero if the some addresses with expirations >= now
* do not match at all
*/
-struct GNUNET_TIME_Absolute
+struct GNUNET_TIME_Absolute
GNUNET_HELLO_equals (const struct
- GNUNET_HELLO_Message *h1,
- const struct
- GNUNET_HELLO_Message *h2,
- struct GNUNET_TIME_Absolute now)
+ GNUNET_HELLO_Message *h1,
+ const struct
+ GNUNET_HELLO_Message *h2, struct GNUNET_TIME_Absolute now)
{
struct EqualsContext ec;
if (0 != memcmp (&h1->publicKey,
- &h2->publicKey,
- sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)))
+ &h2->publicKey,
+ sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)))
return GNUNET_TIME_UNIT_ZERO_ABS;
ec.expiration_limit = now;
ec.result = GNUNET_TIME_UNIT_FOREVER_ABS;
ec.h2 = h2;
- GNUNET_HELLO_iterate_addresses (h1,
- GNUNET_NO,
- &find_matching,
- &ec);
- if (ec.result.abs_value ==
- GNUNET_TIME_UNIT_ZERO.rel_value)
- return ec.result;
+ GNUNET_HELLO_iterate_addresses (h1, GNUNET_NO, &find_matching, &ec);
+ if (ec.result.abs_value == GNUNET_TIME_UNIT_ZERO.rel_value)
+ return ec.result;
ec.h2 = h1;
- GNUNET_HELLO_iterate_addresses (h2,
- GNUNET_NO,
- &find_matching,
- &ec);
+ GNUNET_HELLO_iterate_addresses (h2, GNUNET_NO, &find_matching, &ec);
return ec.result;
}
Modified: gnunet/src/hello/test_hello.c
===================================================================
--- gnunet/src/hello/test_hello.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/hello/test_hello.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -84,10 +84,10 @@
#endif
GNUNET_assert (addrlen > 0);
if (*i & (1 << (addrlen - 1)))
- {
- *i -= (1 << (addrlen - 1));
- return GNUNET_NO;
- }
+ {
+ *i -= (1 << (addrlen - 1));
+ return GNUNET_NO;
+ }
return GNUNET_OK;
}
Modified: gnunet/src/hostlist/gnunet-daemon-hostlist.c
===================================================================
--- gnunet/src/hostlist/gnunet-daemon-hostlist.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/hostlist/gnunet-daemon-hostlist.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -129,12 +129,9 @@
static void
core_init (void *cls,
- struct GNUNET_CORE_Handle * server,
- const struct GNUNET_PeerIdentity *
- my_identity,
- const struct
- GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *
- publicKey)
+ struct GNUNET_CORE_Handle *server,
+ const struct GNUNET_PeerIdentity *my_identity,
+ const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
{
me = *my_identity;
}
@@ -142,10 +139,11 @@
/**
* Core handler for p2p hostlist advertisements
*/
-static int advertisement_handler (void *cls,
- const struct GNUNET_PeerIdentity * peer,
- const struct GNUNET_MessageHeader * message,
- const struct GNUNET_TRANSPORT_ATS_Information
*atsi)
+static int
+advertisement_handler (void *cls,
+ const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_MessageHeader *message,
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
GNUNET_assert (NULL != client_adv_handler);
return (*client_adv_handler) (cls, peer, message, atsi);
@@ -162,17 +160,17 @@
static void
connect_handler (void *cls,
const struct
- GNUNET_PeerIdentity * peer,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+ GNUNET_PeerIdentity *peer,
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
if (0 == memcmp (&me, peer, sizeof (struct GNUNET_PeerIdentity)))
return;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"A new peer connected, notifying client and server\n");
- if ( NULL != client_ch)
+ if (NULL != client_ch)
(*client_ch) (cls, peer, atsi);
#if HAVE_MHD
- if ( NULL != server_ch)
+ if (NULL != server_ch)
(*server_ch) (cls, peer, atsi);
#endif
}
@@ -184,18 +182,16 @@
* @param peer peer identity this notification is about
*/
static void
-disconnect_handler (void *cls,
- const struct
- GNUNET_PeerIdentity * peer)
+disconnect_handler (void *cls, const struct GNUNET_PeerIdentity *peer)
{
if (0 == memcmp (&me, peer, sizeof (struct GNUNET_PeerIdentity)))
return;
- /* call hostlist client disconnect handler*/
- if ( NULL != client_dh)
+ /* call hostlist client disconnect handler */
+ if (NULL != client_dh)
(*client_dh) (cls, peer);
#if HAVE_MHD
- /* call hostlist server disconnect handler*/
- if ( NULL != server_dh)
+ /* call hostlist server disconnect handler */
+ if (NULL != server_dh)
(*server_dh) (cls, peer);
#endif
}
@@ -207,29 +203,27 @@
static void
cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Hostlist daemon is shutting down\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist daemon is shutting down\n");
if (core != NULL)
- {
- GNUNET_CORE_disconnect (core);
- core = NULL;
- }
+ {
+ GNUNET_CORE_disconnect (core);
+ core = NULL;
+ }
if (bootstrapping)
- {
- GNUNET_HOSTLIST_client_stop ();
- }
+ {
+ GNUNET_HOSTLIST_client_stop ();
+ }
#if HAVE_MHD
if (provide_hostlist)
- {
- GNUNET_HOSTLIST_server_stop ();
- }
+ {
+ GNUNET_HOSTLIST_server_stop ();
+ }
#endif
if (stats != NULL)
- {
- GNUNET_STATISTICS_destroy (stats,
- GNUNET_NO);
- stats = NULL;
- }
+ {
+ GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
+ stats = NULL;
+ }
}
@@ -241,67 +235,67 @@
* @param cfgfile name of the configuration file used (for saving, can be
NULL!)
* @param cfg configuration
*/
-static void
+static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle * cfg)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
static const struct GNUNET_CORE_MessageHandler learn_handlers[] = {
- { &advertisement_handler, GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT, 0},
- { NULL, 0, 0 }
+ {&advertisement_handler, GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT, 0},
+ {NULL, 0, 0}
};
static const struct GNUNET_CORE_MessageHandler no_learn_handlers[] = {
- { NULL, 0, 0 }
+ {NULL, 0, 0}
};
- if ( (! bootstrapping) &&
- (! learning)
+ if ((!bootstrapping) && (!learning)
#if HAVE_MHD
- && (! provide_hostlist)
+ && (!provide_hostlist)
#endif
- )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("None of the functions for the hostlist daemon were
enabled. I have no reason to run!\n"));
- return;
- }
+ )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("None of the functions for the hostlist daemon were enabled.
I have no reason to run!\n"));
+ return;
+ }
stats = GNUNET_STATISTICS_create ("hostlist", cfg);
core = GNUNET_CORE_connect (cfg,
- 1,
- NULL,
- &core_init,
- &connect_handler, &disconnect_handler, NULL,
- NULL, GNUNET_NO,
- NULL, GNUNET_NO,
- learning? learn_handlers : no_learn_handlers);
+ 1,
+ NULL,
+ &core_init,
+ &connect_handler, &disconnect_handler, NULL,
+ NULL, GNUNET_NO,
+ NULL, GNUNET_NO,
+ learning ? learn_handlers : no_learn_handlers);
if (bootstrapping)
- {
- GNUNET_HOSTLIST_client_start (cfg, stats,
- &client_ch, &client_dh,
&client_adv_handler, learning);
- }
+ {
+ GNUNET_HOSTLIST_client_start (cfg, stats,
+ &client_ch, &client_dh, &client_adv_handler,
+ learning);
+ }
- #if HAVE_MHD
+#if HAVE_MHD
if (provide_hostlist)
- {
- GNUNET_HOSTLIST_server_start (cfg, stats, core, &server_ch, &server_dh,
advertising );
- }
+ {
+ GNUNET_HOSTLIST_server_start (cfg, stats, core, &server_ch, &server_dh,
+ advertising);
+ }
#endif
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
&cleaning_task, NULL);
if (NULL == core)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to connect to `%s' service.\n"),
- "core");
- GNUNET_SCHEDULER_shutdown ();
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to connect to `%s' service.\n"), "core");
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
}
@@ -317,33 +311,34 @@
{
static const struct GNUNET_GETOPT_CommandLineOption options[] = {
#if HAVE_MHD
- { 'a', "advertise", NULL,
- gettext_noop ("advertise our hostlist to other peers"),
- GNUNET_NO, &GNUNET_GETOPT_set_one, &advertising },
+ {'a', "advertise", NULL,
+ gettext_noop ("advertise our hostlist to other peers"),
+ GNUNET_NO, &GNUNET_GETOPT_set_one, &advertising},
#endif
- { 'b', "bootstrap", NULL,
- gettext_noop ("bootstrap using hostlists (it is highly recommended that
you always use this option)"),
- GNUNET_NO, &GNUNET_GETOPT_set_one, &bootstrapping },
- { 'e', "enable-learning", NULL,
- gettext_noop ("enable learning about hostlist servers from other peers"),
- GNUNET_NO, &GNUNET_GETOPT_set_one, &learning},
+ {'b', "bootstrap", NULL,
+ gettext_noop
+ ("bootstrap using hostlists (it is highly recommended that you always use
this option)"),
+ GNUNET_NO, &GNUNET_GETOPT_set_one, &bootstrapping},
+ {'e', "enable-learning", NULL,
+ gettext_noop ("enable learning about hostlist servers from other peers"),
+ GNUNET_NO, &GNUNET_GETOPT_set_one, &learning},
#if HAVE_MHD
- { 'p', "provide-hostlist", NULL,
- gettext_noop ("provide a hostlist server"),
- GNUNET_NO, &GNUNET_GETOPT_set_one, &provide_hostlist},
+ {'p', "provide-hostlist", NULL,
+ gettext_noop ("provide a hostlist server"),
+ GNUNET_NO, &GNUNET_GETOPT_set_one, &provide_hostlist},
#endif
GNUNET_GETOPT_OPTION_END
};
int ret;
+
GNUNET_log_setup ("hostlist", "WARNING", NULL);
ret = (GNUNET_OK ==
GNUNET_PROGRAM_run (argc,
argv,
- "hostlist",
- _("GNUnet hostlist server and client"),
- options,
- &run, NULL)) ? 0 : 1;
+ "hostlist",
+ _("GNUnet hostlist server and client"),
+ options, &run, NULL)) ? 0 : 1;
return ret;
}
Modified: gnunet/src/hostlist/hostlist-client.c
===================================================================
--- gnunet/src/hostlist/hostlist-client.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/hostlist/hostlist-client.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -58,12 +58,12 @@
/**
* previous entry, used to manage entries in a double linked list
*/
- struct Hostlist * prev;
+ struct Hostlist *prev;
/**
* next entry, used to manage entries in a double linked list
*/
- struct Hostlist * next;
+ struct Hostlist *next;
/**
* URI where hostlist can be obtained
@@ -111,13 +111,13 @@
/**
* Statistics handle.
*/
-static struct GNUNET_STATISTICS_Handle *stats;
+static struct GNUNET_STATISTICS_Handle *stats;
/**
* Transport handle.
*/
static struct GNUNET_TRANSPORT_Handle *transport;
-
+
/**
* Proxy that we are using (can be NULL).
*/
@@ -186,17 +186,17 @@
/**
* Head of the linked list used to store hostlists
*/
-static struct Hostlist * linked_list_head;
+static struct Hostlist *linked_list_head;
/**
* Tail of the linked list used to store hostlists
*/
-static struct Hostlist * linked_list_tail;
+static struct Hostlist *linked_list_tail;
/**
* Current hostlist used for downloading
*/
-static struct Hostlist * current_hostlist;
+static struct Hostlist *current_hostlist;
/**
* Size of the linke list used to store hostlists
@@ -206,7 +206,7 @@
/**
* Head of the linked list used to store hostlists
*/
-static struct Hostlist * hostlist_to_test;
+static struct Hostlist *hostlist_to_test;
/**
* Set to GNUNET_YES if the current URL had some problems.
@@ -232,6 +232,7 @@
* Value saying if a preconfigured bootstrap server is used
*/
static unsigned int stat_use_bootstrap;
+
/**
* Set if we are allowed to learn new hostlists and use them
*/
@@ -263,13 +264,10 @@
* @return number of bytes that were processed (always size*nmemb)
*/
static size_t
-callback_download (void *ptr,
- size_t size,
- size_t nmemb,
- void *ctx)
+callback_download (void *ptr, size_t size, size_t nmemb, void *ctx)
{
static char download_buffer[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1];
- const char * cbuf = ptr;
+ const char *cbuf = ptr;
const struct GNUNET_MessageHeader *msg;
size_t total;
size_t cpy;
@@ -278,85 +276,78 @@
total = size * nmemb;
stat_bytes_downloaded += total;
- if ( (total == 0) || (stat_bogus_url) )
- {
- return total; /* ok, no data or bogus data */
- }
+ if ((total == 0) || (stat_bogus_url))
+ {
+ return total; /* ok, no data or bogus data */
+ }
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# bytes downloaded from hostlist
servers"),
- (int64_t) total,
- GNUNET_NO);
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# bytes downloaded from hostlist servers"),
+ (int64_t) total, GNUNET_NO);
left = total;
- while ( (left > 0) ||
- (download_pos > 0) )
+ while ((left > 0) || (download_pos > 0))
+ {
+ cpy = GNUNET_MIN (left, GNUNET_SERVER_MAX_MESSAGE_SIZE - 1 - download_pos);
+ memcpy (&download_buffer[download_pos], cbuf, cpy);
+ cbuf += cpy;
+ download_pos += cpy;
+ left -= cpy;
+ if (download_pos < sizeof (struct GNUNET_MessageHeader))
{
- cpy = GNUNET_MIN (left, GNUNET_SERVER_MAX_MESSAGE_SIZE - 1 -
download_pos);
- memcpy (&download_buffer[download_pos],
- cbuf,
- cpy);
- cbuf += cpy;
- download_pos += cpy;
- left -= cpy;
- if (download_pos < sizeof(struct GNUNET_MessageHeader))
- {
- GNUNET_assert (left == 0);
- break;
- }
- msg = (const struct GNUNET_MessageHeader *) download_buffer;
- msize = ntohs(msg->size);
- if (msize < sizeof(struct GNUNET_MessageHeader))
- {
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# invalid HELLOs downloaded
from hostlist servers"),
- 1,
- GNUNET_NO);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Invalid `%s' message received from hostlist at
`%s'\n"),
- "HELLO",
- current_url);
- stat_hellos_obtained++;
- stat_bogus_url = 1;
- return total;
- }
- if (download_pos < msize)
- {
- GNUNET_assert (left == 0);
- break;
- }
- if (GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message*)msg) == msize)
- {
+ GNUNET_assert (left == 0);
+ break;
+ }
+ msg = (const struct GNUNET_MessageHeader *) download_buffer;
+ msize = ntohs (msg->size);
+ if (msize < sizeof (struct GNUNET_MessageHeader))
+ {
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# invalid HELLOs downloaded from hostlist
servers"),
+ 1, GNUNET_NO);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Invalid `%s' message received from hostlist at `%s'\n"),
+ "HELLO", current_url);
+ stat_hellos_obtained++;
+ stat_bogus_url = 1;
+ return total;
+ }
+ if (download_pos < msize)
+ {
+ GNUNET_assert (left == 0);
+ break;
+ }
+ if (GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *) msg) == msize)
+ {
#if DEBUG_HOSTLIST_CLIENT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received valid `%s' message from hostlist server.\n",
- "HELLO");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received valid `%s' message from hostlist server.\n",
+ "HELLO");
#endif
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# valid HELLOs downloaded
from hostlist servers"),
- 1,
- GNUNET_NO);
- stat_hellos_obtained++;
- GNUNET_TRANSPORT_offer_hello (transport, msg, NULL, NULL);
- }
- else
- {
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# invalid HELLOs downloaded
from hostlist servers"),
- 1,
- GNUNET_NO);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Invalid `%s' message received from hostlist at
`%s'\n"),
- "HELLO",
- current_url);
- stat_bogus_url = GNUNET_YES;
- stat_hellos_obtained++;
- return total;
- }
- memmove (download_buffer,
- &download_buffer[msize],
- download_pos - msize);
- download_pos -= msize;
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# valid HELLOs downloaded from hostlist
servers"),
+ 1, GNUNET_NO);
+ stat_hellos_obtained++;
+ GNUNET_TRANSPORT_offer_hello (transport, msg, NULL, NULL);
}
+ else
+ {
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# invalid HELLOs downloaded from hostlist
servers"),
+ 1, GNUNET_NO);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Invalid `%s' message received from hostlist at `%s'\n"),
+ "HELLO", current_url);
+ stat_bogus_url = GNUNET_YES;
+ stat_hellos_obtained++;
+ return total;
+ }
+ memmove (download_buffer, &download_buffer[msize], download_pos - msize);
+ download_pos -= msize;
+ }
return total;
}
@@ -374,55 +365,55 @@
size_t urls;
size_t pos;
- if (GNUNET_OK !=
+ if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
- "HOSTLIST",
- "SERVERS",
- &servers))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("No `%s' specified in `%s' configuration, will not
bootstrap.\n"),
- "SERVERS", "HOSTLIST");
- return NULL;
- }
+ "HOSTLIST", "SERVERS", &servers))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("No `%s' specified in `%s' configuration, will not
bootstrap.\n"),
+ "SERVERS", "HOSTLIST");
+ return NULL;
+ }
urls = 0;
if (strlen (servers) > 0)
+ {
+ urls++;
+ pos = strlen (servers) - 1;
+ while (pos > 0)
{
- urls++;
- pos = strlen (servers) - 1;
- while (pos > 0)
- {
- if (servers[pos] == ' ')
- urls++;
- pos--;
- }
+ if (servers[pos] == ' ')
+ urls++;
+ pos--;
}
+ }
if (urls == 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("No `%s' specified in `%s' configuration, will not
bootstrap.\n"),
- "SERVERS", "HOSTLIST");
- GNUNET_free (servers);
- return NULL;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("No `%s' specified in `%s' configuration, will not
bootstrap.\n"),
+ "SERVERS", "HOSTLIST");
+ GNUNET_free (servers);
+ return NULL;
+ }
urls = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, urls) + 1;
pos = strlen (servers) - 1;
while (pos > 0)
+ {
+ if (servers[pos] == ' ')
{
- if (servers[pos] == ' ')
- {
- urls--;
- servers[pos] = '\0';
- }
- if (urls == 0)
- {
- pos++;
- break;
- }
- pos--;
+ urls--;
+ servers[pos] = '\0';
}
+ if (urls == 0)
+ {
+ pos++;
+ break;
+ }
+ pos--;
+ }
ret = GNUNET_strdup (&servers[pos]);
GNUNET_free (servers);
return ret;
@@ -437,45 +428,44 @@
{
uint32_t index;
unsigned int counter;
- struct Hostlist * pos;
+ struct Hostlist *pos;
- if ( GNUNET_NO == stat_learning)
+ if (GNUNET_NO == stat_learning)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Using preconfigured bootstrap server\n");
current_hostlist = NULL;
- return get_bootstrap_server();
+ return get_bootstrap_server ();
}
- if ( ( GNUNET_YES == stat_testing_hostlist) && (NULL != hostlist_to_test) )
+ if ((GNUNET_YES == stat_testing_hostlist) && (NULL != hostlist_to_test))
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Testing new advertised hostlist if it is obtainable\n");
current_hostlist = hostlist_to_test;
- return strdup(hostlist_to_test->hostlist_uri);
+ return strdup (hostlist_to_test->hostlist_uri);
}
- if ( (GNUNET_YES == stat_use_bootstrap) ||
- (linked_list_size == 0) )
+ if ((GNUNET_YES == stat_use_bootstrap) || (linked_list_size == 0))
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Using preconfigured bootstrap server\n");
current_hostlist = NULL;
- return get_bootstrap_server();
+ return get_bootstrap_server ();
}
- index = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
- linked_list_size);
+ index = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
+ linked_list_size);
counter = 0;
pos = linked_list_head;
- while ( counter < index )
- {
- pos = pos->next;
- counter ++;
- }
+ while (counter < index)
+ {
+ pos = pos->next;
+ counter++;
+ }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Using learned hostlist `%s'\n", pos->hostlist_uri);
current_hostlist = pos;
- return strdup(pos->hostlist_uri);
+ return strdup (pos->hostlist_uri);
}
@@ -486,7 +476,7 @@
* Method to save hostlist to a file during hostlist client shutdown
* @param shutdown set if called because of shutdown, entries in linked list
will be destroyed
*/
-static void save_hostlist_file ( int shutdown );
+static void save_hostlist_file (int shutdown);
/**
@@ -495,7 +485,8 @@
* @param val2 value 2
* @return result
*/
-static uint64_t checked_add (uint64_t val1, uint64_t val2)
+static uint64_t
+checked_add (uint64_t val1, uint64_t val2)
{
static uint64_t temp;
static uint64_t maxv;
@@ -503,8 +494,8 @@
maxv = 0;
maxv--;
- temp = val1+val2;
- if ( temp < val1)
+ temp = val1 + val2;
+ if (temp < val1)
return maxv;
else
return temp;
@@ -516,14 +507,13 @@
* @param val2 value 2
* @return result
*/
-static uint64_t
-checked_sub (uint64_t val1,
- uint64_t val2)
+static uint64_t
+checked_sub (uint64_t val1, uint64_t val2)
{
- if ( val1 <= val2)
+ if (val1 <= val2)
return 0;
else
- return (val1-val2);
+ return (val1 - val2);
}
/**
@@ -532,17 +522,17 @@
* @return GNUNET_YES if existing in linked list, GNUNET_NO if not
*/
static int
-linked_list_contains (const char * uri)
+linked_list_contains (const char *uri)
{
- struct Hostlist * pos;
+ struct Hostlist *pos;
pos = linked_list_head;
while (pos != NULL)
- {
- if (0 == strcmp(pos->hostlist_uri, uri) )
- return GNUNET_YES;
- pos = pos->next;
- }
+ {
+ if (0 == strcmp (pos->hostlist_uri, uri))
+ return GNUNET_YES;
+ pos = pos->next;
+ }
return GNUNET_NO;
}
@@ -552,21 +542,21 @@
* @return hostlist with lowest quality
*/
static struct Hostlist *
-linked_list_get_lowest_quality ( )
+linked_list_get_lowest_quality ()
{
- struct Hostlist * pos;
- struct Hostlist * lowest;
+ struct Hostlist *pos;
+ struct Hostlist *lowest;
if (linked_list_size == 0)
return NULL;
lowest = linked_list_head;
pos = linked_list_head->next;
while (pos != NULL)
- {
- if (pos->quality < lowest->quality)
- lowest = pos;
- pos = pos->next;
- }
+ {
+ if (pos->quality < lowest->quality)
+ lowest = pos;
+ pos = pos->next;
+ }
return lowest;
}
@@ -579,29 +569,28 @@
static void
insert_hostlist ()
{
- struct Hostlist * lowest_quality;
+ struct Hostlist *lowest_quality;
if (MAX_NUMBER_HOSTLISTS <= linked_list_size)
- {
- /* No free entries available, replace existing entry */
- lowest_quality = linked_list_get_lowest_quality();
- GNUNET_assert (lowest_quality != NULL);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Removing hostlist with URI `%s' which has the worst quality
of all (%llu)\n",
- lowest_quality->hostlist_uri,
- (unsigned long long) lowest_quality->quality);
- GNUNET_CONTAINER_DLL_remove (linked_list_head, linked_list_tail,
lowest_quality);
- linked_list_size--;
- GNUNET_free (lowest_quality);
- }
- GNUNET_CONTAINER_DLL_insert(linked_list_head,
- linked_list_tail,
- hostlist_to_test);
+ {
+ /* No free entries available, replace existing entry */
+ lowest_quality = linked_list_get_lowest_quality ();
+ GNUNET_assert (lowest_quality != NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Removing hostlist with URI `%s' which has the worst quality
of all (%llu)\n",
+ lowest_quality->hostlist_uri,
+ (unsigned long long) lowest_quality->quality);
+ GNUNET_CONTAINER_DLL_remove (linked_list_head, linked_list_tail,
+ lowest_quality);
+ linked_list_size--;
+ GNUNET_free (lowest_quality);
+ }
+ GNUNET_CONTAINER_DLL_insert (linked_list_head,
+ linked_list_tail, hostlist_to_test);
linked_list_size++;
GNUNET_STATISTICS_set (stats,
- gettext_noop("# advertised hostlist URIs"),
- linked_list_size,
- GNUNET_NO);
+ gettext_noop ("# advertised hostlist URIs"),
+ linked_list_size, GNUNET_NO);
stat_testing_hostlist = GNUNET_NO;
}
@@ -609,33 +598,36 @@
/**
* Method updating hostlist statistics
*/
-static void update_hostlist ( )
+static void
+update_hostlist ()
{
char *stat;
- if ( ((stat_use_bootstrap == GNUNET_NO) && ( NULL != current_hostlist )) ||
- ((stat_testing_hostlist == GNUNET_YES) && ( NULL != current_hostlist ))
)
+
+ if (((stat_use_bootstrap == GNUNET_NO) && (NULL != current_hostlist)) ||
+ ((stat_testing_hostlist == GNUNET_YES) && (NULL != current_hostlist)))
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Updating hostlist statics for URI
`%s'\n",current_hostlist->hostlist_uri );
- current_hostlist->hello_count = stat_hellos_obtained;
- current_hostlist->time_last_usage = GNUNET_TIME_absolute_get();
- current_hostlist->quality = checked_add ( current_hostlist->quality,
(stat_hellos_obtained * HOSTLIST_SUCCESSFUL_HELLO));
- if ( GNUNET_YES == stat_download_successful )
- {
- current_hostlist->times_used++;
- current_hostlist->quality = checked_add ( current_hostlist->quality,
HOSTLIST_SUCCESSFUL_DOWNLOAD);
- GNUNET_asprintf (&stat,
- gettext_noop("# advertised URI `%s' downloaded"),
- current_hostlist->hostlist_uri);
+ "Updating hostlist statics for URI `%s'\n",
+ current_hostlist->hostlist_uri);
+ current_hostlist->hello_count = stat_hellos_obtained;
+ current_hostlist->time_last_usage = GNUNET_TIME_absolute_get ();
+ current_hostlist->quality =
+ checked_add (current_hostlist->quality,
+ (stat_hellos_obtained * HOSTLIST_SUCCESSFUL_HELLO));
+ if (GNUNET_YES == stat_download_successful)
+ {
+ current_hostlist->times_used++;
+ current_hostlist->quality =
+ checked_add (current_hostlist->quality,
HOSTLIST_SUCCESSFUL_DOWNLOAD);
+ GNUNET_asprintf (&stat, gettext_noop ("# advertised URI `%s'
downloaded"),
+ current_hostlist->hostlist_uri);
- GNUNET_STATISTICS_update ( stats,
- stat,
- 1,
- GNUNET_YES);
- GNUNET_free (stat);
- }
- else
- current_hostlist->quality = checked_sub ( current_hostlist->quality,
HOSTLIST_FAILED_DOWNLOAD );
+ GNUNET_STATISTICS_update (stats, stat, 1, GNUNET_YES);
+ GNUNET_free (stat);
+ }
+ else
+ current_hostlist->quality =
+ checked_sub (current_hostlist->quality, HOSTLIST_FAILED_DOWNLOAD);
}
current_hostlist = NULL;
/* Alternating the usage of preconfigured and learned hostlists */
@@ -643,13 +635,13 @@
if (stat_testing_hostlist == GNUNET_YES)
return;
- if ( GNUNET_YES == stat_learning)
- {
+ if (GNUNET_YES == stat_learning)
+ {
if (stat_use_bootstrap == GNUNET_YES)
stat_use_bootstrap = GNUNET_NO;
else
stat_use_bootstrap = GNUNET_YES;
- }
+ }
else
stat_use_bootstrap = GNUNET_YES;
}
@@ -658,53 +650,53 @@
* Clean up the state from the task that downloaded the
* hostlist and schedule the next task.
*/
-static void
+static void
clean_up ()
{
CURLMcode mret;
- if ( (stat_testing_hostlist == GNUNET_YES) &&
- (GNUNET_NO == stat_download_successful) &&
- (NULL != hostlist_to_test))
+ if ((stat_testing_hostlist == GNUNET_YES) &&
+ (GNUNET_NO == stat_download_successful) && (NULL != hostlist_to_test))
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Advertised hostlist with URI `%s' could not be downloaded.
Advertised URI gets dismissed.\n"),
- hostlist_to_test->hostlist_uri);
+ _
+ ("Advertised hostlist with URI `%s' could not be downloaded.
Advertised URI gets dismissed.\n"),
+ hostlist_to_test->hostlist_uri);
}
if (stat_testing_hostlist == GNUNET_YES)
- {
- stat_testing_hostlist = GNUNET_NO;
- }
- if ( NULL != hostlist_to_test)
{
+ stat_testing_hostlist = GNUNET_NO;
+ }
+ if (NULL != hostlist_to_test)
+ {
GNUNET_free (hostlist_to_test);
hostlist_to_test = NULL;
}
if (multi != NULL)
+ {
+ mret = curl_multi_remove_handle (multi, curl);
+ if (mret != CURLM_OK)
{
- mret = curl_multi_remove_handle (multi, curl);
- if (mret != CURLM_OK)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("%s failed at %s:%d: `%s'\n"),
- "curl_multi_remove_handle", __FILE__, __LINE__,
- curl_multi_strerror (mret));
- }
- mret = curl_multi_cleanup (multi);
- if (mret != CURLM_OK)
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("%s failed at %s:%d: `%s'\n"),
- "curl_multi_cleanup", __FILE__, __LINE__,
- curl_multi_strerror (mret));
- multi = NULL;
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("%s failed at %s:%d: `%s'\n"),
+ "curl_multi_remove_handle", __FILE__, __LINE__,
+ curl_multi_strerror (mret));
}
+ mret = curl_multi_cleanup (multi);
+ if (mret != CURLM_OK)
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("%s failed at %s:%d: `%s'\n"),
+ "curl_multi_cleanup", __FILE__, __LINE__,
+ curl_multi_strerror (mret));
+ multi = NULL;
+ }
if (curl != NULL)
- {
- curl_easy_cleanup (curl);
- curl = NULL;
- }
+ {
+ curl_easy_cleanup (curl);
+ curl = NULL;
+ }
GNUNET_free_non_null (current_url);
current_url = NULL;
stat_bytes_downloaded = 0;
@@ -720,8 +712,7 @@
* @param tc task context, unused
*/
static void
-task_download (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+task_download (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
/**
@@ -747,27 +738,28 @@
FD_ZERO (&es);
mret = curl_multi_fdset (multi, &rs, &ws, &es, &max);
if (mret != CURLM_OK)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("%s failed at %s:%d: `%s'\n"),
- "curl_multi_fdset", __FILE__, __LINE__,
- curl_multi_strerror (mret));
- clean_up ();
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("%s failed at %s:%d: `%s'\n"),
+ "curl_multi_fdset", __FILE__, __LINE__,
+ curl_multi_strerror (mret));
+ clean_up ();
+ return;
+ }
mret = curl_multi_timeout (multi, &timeout);
if (mret != CURLM_OK)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("%s failed at %s:%d: `%s'\n"),
- "curl_multi_timeout", __FILE__, __LINE__,
- curl_multi_strerror (mret));
- clean_up ();
- return;
- }
- rtime = GNUNET_TIME_relative_min (GNUNET_TIME_absolute_get_remaining
(end_time),
- GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_MILLISECONDS,
- timeout));
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("%s failed at %s:%d: `%s'\n"),
+ "curl_multi_timeout", __FILE__, __LINE__,
+ curl_multi_strerror (mret));
+ clean_up ();
+ return;
+ }
+ rtime =
+ GNUNET_TIME_relative_min (GNUNET_TIME_absolute_get_remaining (end_time),
+ GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MILLISECONDS, timeout));
grs = GNUNET_NETWORK_fdset_create ();
gws = GNUNET_NETWORK_fdset_create ();
GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1);
@@ -777,13 +769,9 @@
"Scheduling task for hostlist download using cURL\n");
#endif
ti_download
- = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
- GNUNET_SCHEDULER_NO_TASK,
- rtime,
- grs,
- gws,
- &task_download,
- multi);
+ = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
+ GNUNET_SCHEDULER_NO_TASK,
+ rtime, grs, gws, &task_download, multi);
GNUNET_NETWORK_fdset_destroy (gws);
GNUNET_NETWORK_fdset_destroy (grs);
}
@@ -797,108 +785,107 @@
* @param tc task context, unused
*/
static void
-task_download (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+task_download (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
int running;
struct CURLMsg *msg;
CURLMcode mret;
-
+
ti_download = GNUNET_SCHEDULER_NO_TASK;
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- {
+ {
#if DEBUG_HOSTLIST_CLIENT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Shutdown requested while trying to download hostlist from
`%s'\n",
- current_url);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Shutdown requested while trying to download hostlist from
`%s'\n",
+ current_url);
#endif
- update_hostlist();
- clean_up ();
- return;
- }
+ update_hostlist ();
+ clean_up ();
+ return;
+ }
if (GNUNET_TIME_absolute_get_remaining (end_time).rel_value == 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Timeout trying to download hostlist from `%s'\n"),
- current_url);
- update_hostlist();
- clean_up ();
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Timeout trying to download hostlist from `%s'\n"),
+ current_url);
+ update_hostlist ();
+ clean_up ();
+ return;
+ }
#if DEBUG_HOSTLIST_CLIENT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Ready for processing hostlist client request\n");
+ "Ready for processing hostlist client request\n");
#endif
- do
+ do
+ {
+ running = 0;
+ if (stat_bytes_downloaded > MAX_BYTES_PER_HOSTLISTS)
{
- running = 0;
- if (stat_bytes_downloaded > MAX_BYTES_PER_HOSTLISTS)
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Download limit of %u bytes exceeded, stopping
download\n"),
+ MAX_BYTES_PER_HOSTLISTS);
+ clean_up ();
+ return;
+ }
+ mret = curl_multi_perform (multi, &running);
+ if (running == 0)
+ {
+ do
+ {
+ msg = curl_multi_info_read (multi, &running);
+ GNUNET_break (msg != NULL);
+ if (msg == NULL)
+ break;
+ switch (msg->msg)
{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Download limit of %u bytes exceeded, stopping
download\n"),
- MAX_BYTES_PER_HOSTLISTS);
- clean_up();
- return;
+ case CURLMSG_DONE:
+ if ((msg->data.result != CURLE_OK) &&
+ (msg->data.result != CURLE_GOT_NOTHING))
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("%s failed for `%s' at %s:%d: `%s'\n"),
+ "curl_multi_perform",
+ current_url,
+ __FILE__,
+ __LINE__, curl_easy_strerror (msg->data.result));
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Download of hostlist `%s' completed.\n"),
+ current_url);
+ stat_download_successful = GNUNET_YES;
+ update_hostlist ();
+ if (GNUNET_YES == stat_testing_hostlist)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _
+ ("Adding successfully tested hostlist `%s'
datastore.\n"),
+ current_url);
+ insert_hostlist ();
+ hostlist_to_test = NULL;
+ stat_testing_hostlist = GNUNET_NO;
+ }
+ }
+ clean_up ();
+ return;
+ default:
+ break;
}
- mret = curl_multi_perform (multi, &running);
- if (running == 0)
- {
- do
- {
- msg = curl_multi_info_read (multi, &running);
- GNUNET_break (msg != NULL);
- if (msg == NULL)
- break;
- switch (msg->msg)
- {
- case CURLMSG_DONE:
- if ( (msg->data.result != CURLE_OK) &&
- (msg->data.result != CURLE_GOT_NOTHING) )
- GNUNET_log(GNUNET_ERROR_TYPE_INFO,
- _("%s failed for `%s' at %s:%d: `%s'\n"),
- "curl_multi_perform",
- current_url,
- __FILE__,
- __LINE__,
- curl_easy_strerror (msg->data.result));
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Download of hostlist `%s' completed.\n"),
- current_url);
- stat_download_successful = GNUNET_YES;
- update_hostlist();
- if (GNUNET_YES == stat_testing_hostlist)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Adding successfully tested hostlist `%s'
datastore.\n"),
- current_url);
- insert_hostlist();
- hostlist_to_test = NULL;
- stat_testing_hostlist = GNUNET_NO;
- }
- }
- clean_up ();
- return;
- default:
- break;
- }
- }
- while ( (running > 0) );
- }
+ }
+ while ((running > 0));
}
+ }
while (mret == CURLM_CALL_MULTI_PERFORM);
if (mret != CURLM_OK)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("%s failed at %s:%d: `%s'\n"),
- "curl_multi_perform", __FILE__, __LINE__,
- curl_multi_strerror (mret));
- clean_up ();
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("%s failed at %s:%d: `%s'\n"),
+ "curl_multi_perform", __FILE__, __LINE__,
+ curl_multi_strerror (mret));
+ clean_up ();
+ }
download_prepare ();
}
@@ -908,7 +895,7 @@
* data.
*/
static void
-download_hostlist ()
+download_hostlist ()
{
CURLcode ret;
CURLMcode mret;
@@ -920,132 +907,110 @@
curl = curl_easy_init ();
multi = NULL;
if (curl == NULL)
- {
- GNUNET_break (0);
- clean_up ();
- return;
- }
+ {
+ GNUNET_break (0);
+ clean_up ();
+ return;
+ }
GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK,
- _("Bootstrapping using hostlist at `%s'.\n"),
- current_url);
+ _("Bootstrapping using hostlist at `%s'.\n"), current_url);
stat_download_in_progress = GNUNET_YES;
stat_download_successful = GNUNET_NO;
stat_hellos_obtained = 0;
stat_bytes_downloaded = 0;
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# hostlist downloads initiated"),
- 1,
- GNUNET_NO);
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# hostlist downloads initiated"),
+ 1, GNUNET_NO);
if (proxy != NULL)
- CURL_EASY_SETOPT (curl, CURLOPT_PROXY, proxy);
+ CURL_EASY_SETOPT (curl, CURLOPT_PROXY, proxy);
download_pos = 0;
stat_bogus_url = 0;
- CURL_EASY_SETOPT (curl,
- CURLOPT_WRITEFUNCTION,
- &callback_download);
+ CURL_EASY_SETOPT (curl, CURLOPT_WRITEFUNCTION, &callback_download);
if (ret != CURLE_OK)
- {
- clean_up ();
- return;
- }
- CURL_EASY_SETOPT (curl,
- CURLOPT_WRITEDATA,
- NULL);
+ {
+ clean_up ();
+ return;
+ }
+ CURL_EASY_SETOPT (curl, CURLOPT_WRITEDATA, NULL);
if (ret != CURLE_OK)
- {
- clean_up ();
- return;
- }
+ {
+ clean_up ();
+ return;
+ }
CURL_EASY_SETOPT (curl, CURLOPT_FOLLOWLOCATION, 1);
CURL_EASY_SETOPT (curl, CURLOPT_MAXREDIRS, 4);
/* no need to abort if the above failed */
- CURL_EASY_SETOPT (curl,
- CURLOPT_URL,
- current_url);
+ CURL_EASY_SETOPT (curl, CURLOPT_URL, current_url);
if (ret != CURLE_OK)
- {
- clean_up ();
- return;
- }
- CURL_EASY_SETOPT (curl,
- CURLOPT_FAILONERROR,
- 1);
+ {
+ clean_up ();
+ return;
+ }
+ CURL_EASY_SETOPT (curl, CURLOPT_FAILONERROR, 1);
#if 0
- CURL_EASY_SETOPT (curl,
- CURLOPT_VERBOSE,
- 1);
+ CURL_EASY_SETOPT (curl, CURLOPT_VERBOSE, 1);
#endif
- CURL_EASY_SETOPT (curl,
- CURLOPT_BUFFERSIZE,
- GNUNET_SERVER_MAX_MESSAGE_SIZE);
+ CURL_EASY_SETOPT (curl, CURLOPT_BUFFERSIZE, GNUNET_SERVER_MAX_MESSAGE_SIZE);
if (0 == strncmp (current_url, "http", 4))
CURL_EASY_SETOPT (curl, CURLOPT_USERAGENT, "GNUnet");
- CURL_EASY_SETOPT (curl,
- CURLOPT_CONNECTTIMEOUT,
- 60L);
- CURL_EASY_SETOPT (curl,
- CURLOPT_TIMEOUT,
- 60L);
+ CURL_EASY_SETOPT (curl, CURLOPT_CONNECTTIMEOUT, 60L);
+ CURL_EASY_SETOPT (curl, CURLOPT_TIMEOUT, 60L);
#if 0
/* this should no longer be needed; we're now single-threaded! */
- CURL_EASY_SETOPT (curl,
- CURLOPT_NOSIGNAL,
- 1);
+ CURL_EASY_SETOPT (curl, CURLOPT_NOSIGNAL, 1);
#endif
multi = curl_multi_init ();
if (multi == NULL)
- {
- GNUNET_break (0);
- /* clean_up (); */
- return;
- }
+ {
+ GNUNET_break (0);
+ /* clean_up (); */
+ return;
+ }
mret = curl_multi_add_handle (multi, curl);
if (mret != CURLM_OK)
- {
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("%s failed at %s:%d: `%s'\n"),
+ "curl_multi_add_handle", __FILE__, __LINE__,
+ curl_multi_strerror (mret));
+ mret = curl_multi_cleanup (multi);
+ if (mret != CURLM_OK)
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("%s failed at %s:%d: `%s'\n"),
- "curl_multi_add_handle", __FILE__, __LINE__,
- curl_multi_strerror (mret));
- mret = curl_multi_cleanup (multi);
- if (mret != CURLM_OK)
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("%s failed at %s:%d: `%s'\n"),
- "curl_multi_cleanup", __FILE__, __LINE__,
- curl_multi_strerror (mret));
- multi = NULL;
- clean_up ();
- return;
- }
+ _("%s failed at %s:%d: `%s'\n"),
+ "curl_multi_cleanup", __FILE__, __LINE__,
+ curl_multi_strerror (mret));
+ multi = NULL;
+ clean_up ();
+ return;
+ }
end_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES);
download_prepare ();
-}
+}
static void
task_download_dispatcher (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
ti_download_dispatcher_task = GNUNET_SCHEDULER_NO_TASK;
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Download is initiated...\n");
- if ( GNUNET_NO == stat_download_in_progress )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Download can start immediately...\n");
- download_hostlist();
- }
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Download in progess, have to wait...\n");
- ti_download_dispatcher_task = GNUNET_SCHEDULER_add_delayed
(WAITING_INTERVALL,
-
&task_download_dispatcher,
- NULL);
- }
+ if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
+ return;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download is initiated...\n");
+ if (GNUNET_NO == stat_download_in_progress)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download can start
immediately...\n");
+ download_hostlist ();
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Download in progess, have to wait...\n");
+ ti_download_dispatcher_task =
+ GNUNET_SCHEDULER_add_delayed (WAITING_INTERVALL,
+ &task_download_dispatcher, NULL);
+ }
}
/**
@@ -1054,8 +1019,7 @@
* this task again for a later time.
*/
static void
-task_check (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+task_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
static int once;
struct GNUNET_TIME_Relative delay;
@@ -1066,40 +1030,40 @@
if (stat_connection_count < MIN_CONNECTIONS)
{
- ti_download_dispatcher_task = GNUNET_SCHEDULER_add_now
(&task_download_dispatcher,
- NULL);
+ ti_download_dispatcher_task =
+ GNUNET_SCHEDULER_add_now (&task_download_dispatcher, NULL);
}
if (stats == NULL)
{
curl_global_cleanup ();
- return; /* in shutdown */
+ return; /* in shutdown */
}
delay = hostlist_delay;
if (hostlist_delay.rel_value == 0)
hostlist_delay = GNUNET_TIME_UNIT_SECONDS;
else
hostlist_delay = GNUNET_TIME_relative_multiply (hostlist_delay, 2);
- if (hostlist_delay.rel_value > GNUNET_TIME_UNIT_HOURS.rel_value * (1 +
stat_connection_count))
- hostlist_delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS,
- (1 +
stat_connection_count));
+ if (hostlist_delay.rel_value >
+ GNUNET_TIME_UNIT_HOURS.rel_value * (1 + stat_connection_count))
+ hostlist_delay =
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS,
+ (1 + stat_connection_count));
GNUNET_STATISTICS_set (stats,
- gettext_noop("# milliseconds between hostlist
downloads"),
- hostlist_delay.rel_value,
- GNUNET_YES);
+ gettext_noop
+ ("# milliseconds between hostlist downloads"),
+ hostlist_delay.rel_value, GNUNET_YES);
if (0 == once)
- {
- delay = GNUNET_TIME_UNIT_ZERO;
- once = 1;
- }
+ {
+ delay = GNUNET_TIME_UNIT_ZERO;
+ once = 1;
+ }
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Have %u/%u connections. Will consider downloading hostlist
in %llums\n"),
- stat_connection_count,
- MIN_CONNECTIONS,
+ _
+ ("Have %u/%u connections. Will consider downloading hostlist in
%llums\n"),
+ stat_connection_count, MIN_CONNECTIONS,
(unsigned long long) delay.rel_value);
- ti_check_download = GNUNET_SCHEDULER_add_delayed (delay,
- &task_check,
- NULL);
+ ti_check_download = GNUNET_SCHEDULER_add_delayed (delay, &task_check, NULL);
}
@@ -1111,14 +1075,14 @@
*/
static void
task_testing_intervall_reset (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
ti_testing_intervall_task = GNUNET_SCHEDULER_NO_TASK;
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
return;
- stat_testing_allowed = GNUNET_OK;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Testing new hostlist advertisements is allowed again\n");
+ stat_testing_allowed = GNUNET_OK;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Testing new hostlist advertisements is allowed again\n");
}
@@ -1129,22 +1093,19 @@
* @param tc TaskContext
*/
static void
-task_hostlist_saving (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+task_hostlist_saving (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
ti_saving_task = GNUNET_SCHEDULER_NO_TASK;
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
return;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Scheduled saving of hostlists\n"));
- save_hostlist_file ( GNUNET_NO );
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Scheduled saving of hostlists\n"));
+ save_hostlist_file (GNUNET_NO);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
_("Hostlists will be saved to file again in %llums\n"),
(unsigned long long) SAVING_INTERVALL.rel_value);
ti_saving_task = GNUNET_SCHEDULER_add_delayed (SAVING_INTERVALL,
- &task_hostlist_saving,
- NULL);
+ &task_hostlist_saving, NULL);
}
@@ -1157,16 +1118,15 @@
*/
static void
handler_connect (void *cls,
- const struct
- GNUNET_PeerIdentity * peer,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+ const struct
+ GNUNET_PeerIdentity *peer,
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
GNUNET_assert (stat_connection_count < UINT_MAX);
stat_connection_count++;
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# active connections"),
- 1,
- GNUNET_NO);
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# active connections"),
+ 1, GNUNET_NO);
}
@@ -1177,16 +1137,13 @@
* @param peer peer identity this notification is about
*/
static void
-handler_disconnect (void *cls,
- const struct
- GNUNET_PeerIdentity * peer)
+handler_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
{
GNUNET_assert (stat_connection_count > 0);
stat_connection_count--;
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# active connections"),
- -1,
- GNUNET_NO);
+ gettext_noop ("# active connections"),
+ -1, GNUNET_NO);
}
@@ -1202,76 +1159,74 @@
*/
static int
handler_advertisement (void *cls,
- const struct GNUNET_PeerIdentity * peer,
- const struct GNUNET_MessageHeader * message,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+ const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_MessageHeader *message,
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
size_t size;
size_t uri_size;
- const struct GNUNET_MessageHeader * incoming;
+ const struct GNUNET_MessageHeader *incoming;
const char *uri;
- struct Hostlist * hostlist;
+ struct Hostlist *hostlist;
- GNUNET_assert (ntohs (message->type) ==
GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT);
+ GNUNET_assert (ntohs (message->type) ==
+ GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT);
size = ntohs (message->size);
- if (size <= sizeof(struct GNUNET_MessageHeader))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
+ if (size <= sizeof (struct GNUNET_MessageHeader))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
incoming = (const struct GNUNET_MessageHeader *) message;
- uri = (const char*) &incoming[1];
+ uri = (const char *) &incoming[1];
uri_size = size - sizeof (struct GNUNET_MessageHeader);
- if (uri [uri_size - 1] != '\0')
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
+ if (uri[uri_size - 1] != '\0')
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Hostlist client recieved advertisement from `%s' containing URI
`%s'\n",
- GNUNET_i2s (peer),
- uri);
+ "Hostlist client recieved advertisement from `%s' containing URI
`%s'\n",
+ GNUNET_i2s (peer), uri);
if (GNUNET_NO != linked_list_contains (uri))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "URI `%s' is already known\n",
- uri);
- return GNUNET_OK;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "URI `%s' is already known\n", uri);
+ return GNUNET_OK;
+ }
- if ( GNUNET_NO == stat_testing_allowed )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ if (GNUNET_NO == stat_testing_allowed)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Currently not accepting new advertisements: interval between
to advertisements is not reached\n");
- return GNUNET_SYSERR;
- }
- if ( GNUNET_YES == stat_testing_hostlist )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ return GNUNET_SYSERR;
+ }
+ if (GNUNET_YES == stat_testing_hostlist)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Currently not accepting new advertisements: we are already
testing a hostlist\n");
- return GNUNET_SYSERR;
- }
+ return GNUNET_SYSERR;
+ }
hostlist = GNUNET_malloc (sizeof (struct Hostlist) + uri_size);
- hostlist->hostlist_uri = (const char*) &hostlist[1];
+ hostlist->hostlist_uri = (const char *) &hostlist[1];
memcpy (&hostlist[1], uri, uri_size);
- hostlist->time_creation = GNUNET_TIME_absolute_get();
- hostlist->time_last_usage = GNUNET_TIME_absolute_get_zero();
+ hostlist->time_creation = GNUNET_TIME_absolute_get ();
+ hostlist->time_last_usage = GNUNET_TIME_absolute_get_zero ();
hostlist->quality = HOSTLIST_INITIAL;
hostlist_to_test = hostlist;
stat_testing_hostlist = GNUNET_YES;
stat_testing_allowed = GNUNET_NO;
ti_testing_intervall_task = GNUNET_SCHEDULER_add_delayed (TESTING_INTERVAL,
-
&task_testing_intervall_reset,
- NULL);
+
&task_testing_intervall_reset,
+ NULL);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Testing new hostlist advertisements is locked for the next %u
ms\n",
- TESTING_INTERVAL.rel_value);
+ "Testing new hostlist advertisements is locked for the next %u
ms\n",
+ TESTING_INTERVAL.rel_value);
- ti_download_dispatcher_task = GNUNET_SCHEDULER_add_now
(&task_download_dispatcher,
- NULL);
+ ti_download_dispatcher_task =
+ GNUNET_SCHEDULER_add_now (&task_download_dispatcher, NULL);
return GNUNET_OK;
}
@@ -1290,26 +1245,23 @@
primary_task (void *cls, int success)
{
if (stats == NULL)
- return; /* in shutdown */
+ return; /* in shutdown */
#if DEBUG_HOSTLIST_CLIENT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Statistics request done, scheduling hostlist download\n");
+ "Statistics request done, scheduling hostlist download\n");
#endif
- ti_check_download = GNUNET_SCHEDULER_add_now (&task_check,
- NULL);
+ ti_check_download = GNUNET_SCHEDULER_add_now (&task_check, NULL);
}
static int
process_stat (void *cls,
- const char *subsystem,
- const char *name,
- uint64_t value,
- int is_persistent)
+ const char *subsystem,
+ const char *name, uint64_t value, int is_persistent)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Initial time between hostlist downloads is %llums\n"),
- (unsigned long long) value);
+ _("Initial time between hostlist downloads is %llums\n"),
+ (unsigned long long) value);
hostlist_delay.rel_value = value;
return GNUNET_OK;
}
@@ -1317,13 +1269,14 @@
/**
* Method to load persistent hostlist file during hostlist client startup
*/
-static void
+static void
load_hostlist_file ()
{
char *filename;
char *uri;
char *emsg;
- struct Hostlist * hostlist;
+ struct Hostlist *hostlist;
+
uri = NULL;
uint32_t times_used;
uint32_t hellos_returned;
@@ -1333,74 +1286,75 @@
uint32_t counter;
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (cfg,
- "HOSTLIST",
- "HOSTLISTFILE",
- &filename))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("No `%s' specified in `%s' configuration, cannot load
hostlists from file.\n"),
- "HOSTLISTFILE", "HOSTLIST");
- return;
- }
+ GNUNET_CONFIGURATION_get_value_filename (cfg,
+ "HOSTLIST",
+ "HOSTLISTFILE", &filename))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("No `%s' specified in `%s' configuration, cannot load
hostlists from file.\n"),
+ "HOSTLISTFILE", "HOSTLIST");
+ return;
+ }
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
_("Loading saved hostlist entries from file `%s' \n"), filename);
- if ( GNUNET_NO == GNUNET_DISK_file_test (filename) )
+ if (GNUNET_NO == GNUNET_DISK_file_test (filename))
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
_("Hostlist file `%s' is not existing\n"), filename);
- GNUNET_free ( filename );
+ GNUNET_free (filename);
return;
}
- struct GNUNET_BIO_ReadHandle * rh = GNUNET_BIO_read_open (filename);
+ struct GNUNET_BIO_ReadHandle *rh = GNUNET_BIO_read_open (filename);
+
if (NULL == rh)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Could not open file `%s' for reading to load hostlists:
%s\n"),
- filename,
- STRERROR (errno));
- GNUNET_free (filename);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _
+ ("Could not open file `%s' for reading to load hostlists:
%s\n"),
+ filename, STRERROR (errno));
+ GNUNET_free (filename);
+ return;
+ }
counter = 0;
- while ( (GNUNET_OK == GNUNET_BIO_read_string (rh, "url" , &uri,
MAX_URL_LEN)) &&
- (NULL != uri) &&
- (GNUNET_OK == GNUNET_BIO_read_int32 (rh, ×_used)) &&
- (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &quality)) &&
- (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &last_used)) &&
- (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &created)) &&
- (GNUNET_OK == GNUNET_BIO_read_int32 (rh, &hellos_returned)) )
- {
- hostlist = GNUNET_malloc (sizeof (struct Hostlist) + strlen (uri) + 1);
- hostlist->hello_count = hellos_returned;
- hostlist->hostlist_uri = (const char *) &hostlist[1];
- memcpy (&hostlist[1], uri, strlen(uri)+1);
- hostlist->quality = quality;
- hostlist->time_creation.abs_value = created;
- hostlist->time_last_usage.abs_value = last_used;
- GNUNET_CONTAINER_DLL_insert(linked_list_head, linked_list_tail,
hostlist);
- linked_list_size++;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Added hostlist entry eith URI `%s' \n",
hostlist->hostlist_uri);
- GNUNET_free (uri);
- uri = NULL;
- counter++;
- if ( counter >= MAX_NUMBER_HOSTLISTS ) break;
- }
+ while ((GNUNET_OK == GNUNET_BIO_read_string (rh, "url", &uri, MAX_URL_LEN))
&&
+ (NULL != uri) &&
+ (GNUNET_OK == GNUNET_BIO_read_int32 (rh, ×_used)) &&
+ (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &quality)) &&
+ (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &last_used)) &&
+ (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &created)) &&
+ (GNUNET_OK == GNUNET_BIO_read_int32 (rh, &hellos_returned)))
+ {
+ hostlist = GNUNET_malloc (sizeof (struct Hostlist) + strlen (uri) + 1);
+ hostlist->hello_count = hellos_returned;
+ hostlist->hostlist_uri = (const char *) &hostlist[1];
+ memcpy (&hostlist[1], uri, strlen (uri) + 1);
+ hostlist->quality = quality;
+ hostlist->time_creation.abs_value = created;
+ hostlist->time_last_usage.abs_value = last_used;
+ GNUNET_CONTAINER_DLL_insert (linked_list_head, linked_list_tail, hostlist);
+ linked_list_size++;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Added hostlist entry eith URI `%s' \n",
+ hostlist->hostlist_uri);
+ GNUNET_free (uri);
+ uri = NULL;
+ counter++;
+ if (counter >= MAX_NUMBER_HOSTLISTS)
+ break;
+ }
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
_("%u hostlist URIs loaded from file\n"), counter);
GNUNET_STATISTICS_set (stats,
- gettext_noop("# hostlist URIs read from file"),
- counter,
- GNUNET_YES);
+ gettext_noop ("# hostlist URIs read from file"),
+ counter, GNUNET_YES);
GNUNET_STATISTICS_set (stats,
- gettext_noop("# advertised hostlist URIs"),
- linked_list_size,
- GNUNET_NO);
+ gettext_noop ("# advertised hostlist URIs"),
+ linked_list_size, GNUNET_NO);
GNUNET_free_non_null (uri);
emsg = NULL;
@@ -1415,89 +1369,87 @@
* Method to save persistent hostlist file during hostlist client shutdown
* @param shutdown set if called because of shutdown, entries in linked list
will be destroyed
*/
-static void save_hostlist_file ( int shutdown )
+static void
+save_hostlist_file (int shutdown)
{
char *filename;
struct Hostlist *pos;
- struct GNUNET_BIO_WriteHandle * wh;
+ struct GNUNET_BIO_WriteHandle *wh;
int ok;
uint32_t counter;
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_filename (cfg,
- "HOSTLIST",
- "HOSTLISTFILE",
- &filename))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("No `%s' specified in `%s' configuration, cannot save
hostlists to file.\n"),
- "HOSTLISTFILE", "HOSTLIST");
- return;
- }
+ "HOSTLIST",
+ "HOSTLISTFILE", &filename))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("No `%s' specified in `%s' configuration, cannot save
hostlists to file.\n"),
+ "HOSTLISTFILE", "HOSTLIST");
+ return;
+ }
if (GNUNET_SYSERR == GNUNET_DISK_directory_create_for_file (filename))
- {
- GNUNET_free (filename);
- return;
- }
+ {
+ GNUNET_free (filename);
+ return;
+ }
wh = GNUNET_BIO_write_open (filename);
- if ( NULL == wh)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Could not open file `%s' for writing to save hostlists:
%s\n"),
- filename,
- STRERROR (errno));
- GNUNET_free (filename);
- return;
- }
+ if (NULL == wh)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Could not open file `%s' for writing to save hostlists:
%s\n"),
+ filename, STRERROR (errno));
+ GNUNET_free (filename);
+ return;
+ }
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Writing %u hostlist URIs to `%s'\n" ),
+ _("Writing %u hostlist URIs to `%s'\n"),
linked_list_size, filename);
/* add code to write hostlists to file using bio */
ok = GNUNET_YES;
counter = 0;
while (NULL != (pos = linked_list_head))
+ {
+ if (GNUNET_YES == shutdown)
{
- if ( GNUNET_YES == shutdown)
+ GNUNET_CONTAINER_DLL_remove (linked_list_head, linked_list_tail, pos);
+ linked_list_size--;
+ }
+ if (GNUNET_YES == ok)
+ {
+ if ((GNUNET_OK !=
+ GNUNET_BIO_write_string (wh, pos->hostlist_uri)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_write_int32 (wh, pos->times_used)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_write_int64 (wh, pos->quality)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_write_int64 (wh, pos->time_last_usage.abs_value)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_write_int64 (wh, pos->time_creation.abs_value)) ||
+ (GNUNET_OK != GNUNET_BIO_write_int32 (wh, pos->hello_count)))
{
- GNUNET_CONTAINER_DLL_remove (linked_list_head, linked_list_tail, pos);
- linked_list_size--;
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Error writing hostlist URIs to file `%s'\n"), filename);
+ ok = GNUNET_NO;
}
- if (GNUNET_YES == ok)
- {
- if ( (GNUNET_OK !=
- GNUNET_BIO_write_string (wh, pos->hostlist_uri)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_int32 (wh, pos->times_used)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_int64 (wh, pos->quality)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_int64 (wh, pos->time_last_usage.abs_value)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_int64 (wh, pos->time_creation.abs_value)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_int32 (wh, pos->hello_count)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Error writing hostlist URIs to file `%s'\n"),
- filename);
- ok = GNUNET_NO;
- }
- }
+ }
- if ( GNUNET_YES == shutdown)
- GNUNET_free (pos);
- counter ++;
- if ( counter >= MAX_NUMBER_HOSTLISTS) break;
- }
+ if (GNUNET_YES == shutdown)
+ GNUNET_free (pos);
+ counter++;
+ if (counter >= MAX_NUMBER_HOSTLISTS)
+ break;
+ }
GNUNET_STATISTICS_set (stats,
- gettext_noop("# hostlist URIs written to file"),
- counter,
- GNUNET_YES);
+ gettext_noop ("# hostlist URIs written to file"),
+ counter, GNUNET_YES);
- if ( GNUNET_OK != GNUNET_BIO_write_close ( wh ) )
+ if (GNUNET_OK != GNUNET_BIO_write_close (wh))
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Error writing hostlist URIs to file `%s'\n"),
- filename);
+ _("Error writing hostlist URIs to file `%s'\n"), filename);
GNUNET_free (filename);
}
@@ -1506,33 +1458,30 @@
*/
int
GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c,
- struct GNUNET_STATISTICS_Handle *st,
- GNUNET_CORE_ConnectEventHandler *ch,
- GNUNET_CORE_DisconnectEventHandler *dh,
- GNUNET_CORE_MessageCallback *msgh,
- int learn)
+ struct GNUNET_STATISTICS_Handle *st,
+ GNUNET_CORE_ConnectEventHandler *ch,
+ GNUNET_CORE_DisconnectEventHandler *dh,
+ GNUNET_CORE_MessageCallback *msgh, int learn)
{
char *filename;
int result;
if (0 != curl_global_init (CURL_GLOBAL_WIN32))
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
transport = GNUNET_TRANSPORT_connect (c, NULL, NULL, NULL, NULL, NULL);
if (NULL == transport)
- {
- curl_global_cleanup ();
- return GNUNET_SYSERR;
- }
+ {
+ curl_global_cleanup ();
+ return GNUNET_SYSERR;
+ }
cfg = c;
stats = st;
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
- "HOSTLIST",
- "HTTP-PROXY",
- &proxy))
+ "HOSTLIST", "HTTP-PROXY", &proxy))
proxy = NULL;
stat_learning = learn;
*ch = &handler_connect;
@@ -1543,51 +1492,49 @@
stat_testing_hostlist = GNUNET_NO;
stat_testing_allowed = GNUNET_YES;
- if ( GNUNET_YES == stat_learning )
+ if (GNUNET_YES == stat_learning)
{
*msgh = &handler_advertisement;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Learning is enabled on this peer\n"));
+ _("Learning is enabled on this peer\n"));
load_hostlist_file ();
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Hostlists will be saved to file again in %llums\n"),
- (unsigned long long) SAVING_INTERVALL.rel_value);
+ _("Hostlists will be saved to file again in %llums\n"),
+ (unsigned long long) SAVING_INTERVALL.rel_value);
ti_saving_task = GNUNET_SCHEDULER_add_delayed (SAVING_INTERVALL,
- &task_hostlist_saving,
- NULL);
+ &task_hostlist_saving,
NULL);
}
else
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Learning is not enabled on this peer\n"));
+ _("Learning is not enabled on this peer\n"));
*msgh = NULL;
if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename (cfg,
- "HOSTLIST",
- "HOSTLISTFILE",
- &filename))
+ "HOSTLIST",
+ "HOSTLISTFILE",
+ &filename))
{
- if ( GNUNET_YES == GNUNET_DISK_file_test (filename) )
+ if (GNUNET_YES == GNUNET_DISK_file_test (filename))
{
result = remove (filename);
if (result == 0)
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Since learning is not enabled on this peer, hostlist
file `%s' was removed\n"),
- filename);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _
+ ("Since learning is not enabled on this peer, hostlist
file `%s' was removed\n"),
+ filename);
else
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Hostlist file `%s' could not be removed\n"),
- filename);
+ _("Hostlist file `%s' could not be removed\n"),
filename);
}
}
- GNUNET_free ( filename );
+ GNUNET_free (filename);
}
GNUNET_STATISTICS_get (stats,
- "hostlist",
- gettext_noop("# milliseconds between hostlist
downloads"),
- GNUNET_TIME_UNIT_MINUTES,
- &primary_task,
- &process_stat,
- NULL);
+ "hostlist",
+ gettext_noop
+ ("# milliseconds between hostlist downloads"),
+ GNUNET_TIME_UNIT_MINUTES, &primary_task,
&process_stat,
+ NULL);
return GNUNET_OK;
}
@@ -1598,42 +1545,40 @@
void
GNUNET_HOSTLIST_client_stop ()
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Hostlist client shutdown\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist client shutdown\n");
#if DEBUG_HOSTLIST_CLIENT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Hostlist client shutdown\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist client shutdown\n");
#endif
- if ( GNUNET_YES == stat_learning )
- save_hostlist_file ( GNUNET_YES );
+ if (GNUNET_YES == stat_learning)
+ save_hostlist_file (GNUNET_YES);
if (ti_saving_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (ti_saving_task);
- }
+ {
+ GNUNET_SCHEDULER_cancel (ti_saving_task);
+ }
if (ti_download_dispatcher_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (ti_download_dispatcher_task);
- }
+ {
+ GNUNET_SCHEDULER_cancel (ti_download_dispatcher_task);
+ }
if (ti_testing_intervall_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (ti_testing_intervall_task);
- }
+ {
+ GNUNET_SCHEDULER_cancel (ti_testing_intervall_task);
+ }
if (ti_download != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (ti_download);
- }
+ {
+ GNUNET_SCHEDULER_cancel (ti_download);
+ }
if (ti_check_download != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (ti_check_download);
- curl_global_cleanup ();
- }
+ {
+ GNUNET_SCHEDULER_cancel (ti_check_download);
+ curl_global_cleanup ();
+ }
if (transport != NULL)
- {
- GNUNET_TRANSPORT_disconnect (transport);
- transport = NULL;
- }
+ {
+ GNUNET_TRANSPORT_disconnect (transport);
+ transport = NULL;
+ }
GNUNET_assert (NULL == transport);
GNUNET_free_non_null (proxy);
proxy = NULL;
Modified: gnunet/src/hostlist/hostlist-client.h
===================================================================
--- gnunet/src/hostlist/hostlist-client.h 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/hostlist/hostlist-client.h 2011-08-15 21:46:35 UTC (rev
16581)
@@ -91,18 +91,16 @@
*/
int
GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c,
- struct GNUNET_STATISTICS_Handle *st,
- GNUNET_CORE_ConnectEventHandler *ch,
- GNUNET_CORE_DisconnectEventHandler *dh,
- GNUNET_CORE_MessageCallback *msgh,
- int learn);
+ struct GNUNET_STATISTICS_Handle *st,
+ GNUNET_CORE_ConnectEventHandler *ch,
+ GNUNET_CORE_DisconnectEventHandler *dh,
+ GNUNET_CORE_MessageCallback *msgh, int learn);
/**
* Stop downloading hostlists from hostlist servers as necessary.
*/
-void
-GNUNET_HOSTLIST_client_stop (void);
+void GNUNET_HOSTLIST_client_stop (void);
#endif
Modified: gnunet/src/hostlist/hostlist-server.c
===================================================================
--- gnunet/src/hostlist/hostlist-server.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/hostlist/hostlist-server.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -51,7 +51,7 @@
/**
* For keeping statistics.
- */
+ */
static struct GNUNET_STATISTICS_Handle *stats;
/**
@@ -107,7 +107,7 @@
/**
* Buffer for the hostlist address
*/
-static char * hostlist_uri;
+static char *hostlist_uri;
/**
@@ -125,16 +125,14 @@
#endif
response = MHD_create_response_from_data (results->size,
results->data, MHD_YES, MHD_NO);
- if ( (daemon_handle_v4 == NULL) &&
- (daemon_handle_v6 == NULL) )
+ if ((daemon_handle_v4 == NULL) && (daemon_handle_v6 == NULL))
{
MHD_destroy_response (response);
response = NULL;
}
GNUNET_STATISTICS_set (stats,
- gettext_noop("bytes in hostlist"),
- results->size,
- GNUNET_YES);
+ gettext_noop ("bytes in hostlist"),
+ results->size, GNUNET_YES);
GNUNET_free (results);
}
@@ -151,21 +149,19 @@
*/
static int
check_has_addr (void *cls,
- const char *tname,
- struct GNUNET_TIME_Absolute expiration,
- const void *addr,
- uint16_t addrlen)
+ const char *tname,
+ struct GNUNET_TIME_Absolute expiration,
+ const void *addr, uint16_t addrlen)
{
int *arg = cls;
if (GNUNET_TIME_absolute_get_remaining (expiration).rel_value == 0)
- {
- GNUNET_STATISTICS_update (stats,
- gettext_noop("expired addresses encountered"),
- 1,
- GNUNET_YES);
- return GNUNET_YES; /* ignore this address */
- }
+ {
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("expired addresses encountered"),
+ 1, GNUNET_YES);
+ return GNUNET_YES; /* ignore this address */
+ }
*arg = GNUNET_YES;
return GNUNET_SYSERR;
}
@@ -177,74 +173,66 @@
*/
static void
host_processor (void *cls,
- const struct GNUNET_PeerIdentity * peer,
- const struct GNUNET_HELLO_Message *hello,
- const char *err_msg)
+ const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_HELLO_Message *hello, const char *err_msg)
{
struct HostSet *results = cls;
size_t old;
size_t s;
int has_addr;
-
+
if (err_msg != NULL)
- {
- GNUNET_assert (NULL == peer);
- pitr = NULL;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Error in communication with PEERINFO service: %s\n"),
- err_msg);
- return;
- }
+ {
+ GNUNET_assert (NULL == peer);
+ pitr = NULL;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ _("Error in communication with PEERINFO service: %s\n"),
+ err_msg);
+ return;
+ }
if (peer == NULL)
- {
- pitr = NULL;
- finish_response (results);
- return;
- }
+ {
+ pitr = NULL;
+ finish_response (results);
+ return;
+ }
if (hello == NULL)
return;
has_addr = GNUNET_NO;
- GNUNET_HELLO_iterate_addresses (hello,
- GNUNET_NO,
- &check_has_addr,
- &has_addr);
+ GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &check_has_addr,
&has_addr);
if (GNUNET_NO == has_addr)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "HELLO for peer `%4s' has no address, not suitable for
hostlist!\n",
- GNUNET_i2s (peer));
- GNUNET_STATISTICS_update (stats,
- gettext_noop("HELLOs without addresses
encountered (ignored)"),
- 1,
- GNUNET_NO);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "HELLO for peer `%4s' has no address, not suitable for
hostlist!\n",
+ GNUNET_i2s (peer));
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("HELLOs without addresses encountered
(ignored)"),
+ 1, GNUNET_NO);
+ return;
+ }
old = results->size;
- s = GNUNET_HELLO_size(hello);
+ s = GNUNET_HELLO_size (hello);
#if DEBUG_HOSTLIST_SERVER
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received %u bytes of `%s' from peer `%s' for hostlist.\n",
- (unsigned int) s,
- "HELLO",
- GNUNET_i2s (peer));
+ "Received %u bytes of `%s' from peer `%s' for hostlist.\n",
+ (unsigned int) s, "HELLO", GNUNET_i2s (peer));
#endif
- if ( (old + s >= GNUNET_MAX_MALLOC_CHECKED) || (old + s >=
MAX_BYTES_PER_HOSTLISTS) )
- {
- GNUNET_STATISTICS_update (stats,
- gettext_noop("bytes not included in hostlist
(size limit)"),
- s,
- GNUNET_NO);
- return; /* too large, skip! */
- }
+ if ((old + s >= GNUNET_MAX_MALLOC_CHECKED) ||
+ (old + s >= MAX_BYTES_PER_HOSTLISTS))
+ {
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("bytes not included in hostlist (size limit)"),
+ s, GNUNET_NO);
+ return; /* too large, skip! */
+ }
#if DEBUG_HOSTLIST_SERVER
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Adding peer `%s' to hostlist (%u bytes)\n",
- GNUNET_i2s (peer),
- (unsigned int) s);
+ "Adding peer `%s' to hostlist (%u bytes)\n",
+ GNUNET_i2s (peer), (unsigned int) s);
#endif
- GNUNET_array_grow (results->data,
- results->size,
- old + s);
+ GNUNET_array_grow (results->data, results->size, old + s);
memcpy (&results->data[old], hello, s);
}
@@ -258,13 +246,13 @@
const struct sockaddr *addr, socklen_t addrlen)
{
if (NULL == response)
- {
+ {
#if DEBUG_HOSTLIST_SERVER
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received request for hostlist, but I am not yet ready;
rejecting!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received request for hostlist, but I am not yet ready;
rejecting!\n");
#endif
- return MHD_NO;
- }
+ return MHD_NO;
+ }
return MHD_YES; /* accept all */
}
@@ -279,58 +267,54 @@
const char *method,
const char *version,
const char *upload_data,
- size_t*upload_data_size, void **con_cls)
+ size_t * upload_data_size, void **con_cls)
{
static int dummy;
-
+
if (0 != strcmp (method, MHD_HTTP_METHOD_GET))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Refusing `%s' request to hostlist server\n"),
- method);
- GNUNET_STATISTICS_update (stats,
- gettext_noop("hostlist requests refused (not
HTTP GET)"),
- 1,
- GNUNET_YES);
- return MHD_NO;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Refusing `%s' request to hostlist server\n"), method);
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("hostlist requests refused (not HTTP GET)"), 1,
+ GNUNET_YES);
+ return MHD_NO;
+ }
if (NULL == *con_cls)
- {
- (*con_cls) = &dummy;
+ {
+ (*con_cls) = &dummy;
#if DEBUG_HOSTLIST_SERVER
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Sending 100 CONTINUE reply\n"));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Sending 100 CONTINUE reply\n"));
#endif
- return MHD_YES; /* send 100 continue */
- }
+ return MHD_YES; /* send 100 continue */
+ }
if (*upload_data_size != 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Refusing `%s' request with %llu bytes of upload data\n"),
- method,
- (unsigned long long) *upload_data_size);
- GNUNET_STATISTICS_update (stats,
- gettext_noop("hostlist requests refused (upload
data)"),
- 1,
- GNUNET_YES);
- return MHD_NO; /* do not support upload data */
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Refusing `%s' request with %llu bytes of upload data\n"),
+ method, (unsigned long long) *upload_data_size);
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("hostlist requests refused (upload data)"), 1,
+ GNUNET_YES);
+ return MHD_NO; /* do not support upload data */
+ }
if (response == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Could not handle hostlist request since I do not have a
response yet\n"));
- GNUNET_STATISTICS_update (stats,
- gettext_noop("hostlist requests refused (not
ready)"),
- 1,
- GNUNET_YES);
- return MHD_NO; /* internal error, no response yet */
- }
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Received request for our hostlist\n"));
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Could not handle hostlist request since I do not have a
response yet\n"));
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("hostlist requests refused (not ready)"), 1,
+ GNUNET_YES);
+ return MHD_NO; /* internal error, no response yet */
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Received request for our
hostlist\n"));
GNUNET_STATISTICS_update (stats,
- gettext_noop("hostlist requests processed"),
- 1,
- GNUNET_YES);
+ gettext_noop ("hostlist requests processed"),
+ 1, GNUNET_YES);
return MHD_queue_response (connection, MHD_HTTP_OK, response);
}
@@ -342,41 +326,38 @@
* @param buf buffer to copy message to
*/
static size_t
-adv_transmit_ready ( void *cls, size_t size, void *buf)
+adv_transmit_ready (void *cls, size_t size, void *buf)
{
static uint64_t hostlist_adv_count;
size_t transmission_size;
- size_t uri_size; /* Including \0 termination! */
+ size_t uri_size; /* Including \0 termination! */
struct GNUNET_MessageHeader header;
char *cbuf;
if (buf == NULL)
- {
- GNUNET_log ( GNUNET_ERROR_TYPE_DEBUG,
- "Transmission failed, buffer invalid!\n" );
- return 0;
- }
- uri_size = strlen ( hostlist_uri ) + 1;
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Transmission failed, buffer invalid!\n");
+ return 0;
+ }
+ uri_size = strlen (hostlist_uri) + 1;
transmission_size = sizeof (struct GNUNET_MessageHeader) + uri_size;
header.type = htons (GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT);
header.size = htons (transmission_size);
GNUNET_assert (size >= transmission_size);
memcpy (buf, &header, sizeof (struct GNUNET_MessageHeader));
- cbuf = buf;
- memcpy (&cbuf[sizeof (struct GNUNET_MessageHeader)],
- hostlist_uri, uri_size);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sent advertisement message: Copied %u bytes into buffer!\n",
- (unsigned int) transmission_size);
+ cbuf = buf;
+ memcpy (&cbuf[sizeof (struct GNUNET_MessageHeader)], hostlist_uri, uri_size);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sent advertisement message: Copied %u bytes into buffer!\n",
+ (unsigned int) transmission_size);
hostlist_adv_count++;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- " # Sent advertisement message: %u\n",
- hostlist_adv_count);
+ " # Sent advertisement message: %u\n", hostlist_adv_count);
GNUNET_STATISTICS_update (stats,
- gettext_noop("# hostlist advertisements send"),
- 1,
- GNUNET_NO);
+ gettext_noop ("# hostlist advertisements send"),
+ 1, GNUNET_NO);
return transmission_size;
}
@@ -391,41 +372,42 @@
static void
connect_handler (void *cls,
const struct
- GNUNET_PeerIdentity * peer,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+ GNUNET_PeerIdentity *peer,
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
size_t size;
- if ( !advertising )
+ if (!advertising)
return;
if (hostlist_uri == NULL)
return;
size = strlen (hostlist_uri) + 1;
- if (size + sizeof (struct GNUNET_MessageHeader) >=
GNUNET_SERVER_MAX_MESSAGE_SIZE)
- {
- GNUNET_break (0);
- return;
- }
+ if (size + sizeof (struct GNUNET_MessageHeader) >=
+ GNUNET_SERVER_MAX_MESSAGE_SIZE)
+ {
+ GNUNET_break (0);
+ return;
+ }
size += sizeof (struct GNUNET_MessageHeader);
if (NULL == core)
- {
- GNUNET_break (0);
- return;
- }
+ {
+ GNUNET_break (0);
+ return;
+ }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Asked core to transmit advertisement message with a size of %u
bytes to peer `%s'\n",
- size,GNUNET_i2s(peer));
+ size, GNUNET_i2s (peer));
if (NULL == GNUNET_CORE_notify_transmit_ready (core,
- GNUNET_YES,
- 0,
- GNUNET_ADV_TIMEOUT,
- peer,
- size,
- &adv_transmit_ready, NULL))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Advertisement message could not be queued by core\n"));
- }
+ GNUNET_YES,
+ 0,
+ GNUNET_ADV_TIMEOUT,
+ peer,
+ size,
+ &adv_transmit_ready, NULL))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Advertisement message could not be queued by core\n"));
+ }
}
@@ -436,9 +418,7 @@
* @param peer peer identity this notification is about
*/
static void
-disconnect_handler (void *cls,
- const struct
- GNUNET_PeerIdentity * peer)
+disconnect_handler (void *cls, const struct GNUNET_PeerIdentity *peer)
{
/* nothing to do */
}
@@ -455,27 +435,26 @@
static void
process_notify (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 HostSet *results;
+
#if DEBUG_HOSTLIST_SERVER
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peerinfo is notifying us to rebuild our hostlist\n");
+ "Peerinfo is notifying us to rebuild our hostlist\n");
#endif
if (err_msg != NULL)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Error in communication with PEERINFO service\n"));
- /* return; */
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ _("Error in communication with PEERINFO service\n"));
+ /* return; */
}
- results = GNUNET_malloc(sizeof(struct HostSet));
+ results = GNUNET_malloc (sizeof (struct HostSet));
GNUNET_assert (peerinfo != NULL);
pitr = GNUNET_PEERINFO_iterate (peerinfo,
NULL,
GNUNET_TIME_UNIT_MINUTES,
- &host_processor,
- results);
+ &host_processor, results);
}
/**
@@ -491,8 +470,7 @@
* and schedule the next run.
*/
static void
-run_daemon (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+run_daemon (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct MHD_Daemon *daemon_handle = cls;
@@ -502,7 +480,7 @@
hostlist_task_v6 = GNUNET_SCHEDULER_NO_TASK;
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
+ return;
GNUNET_assert (MHD_YES == MHD_run (daemon_handle));
if (daemon_handle == daemon_handle_v4)
hostlist_task_v4 = prepare_daemon (daemon_handle);
@@ -529,20 +507,15 @@
unsigned long long timeout;
int haveto;
struct GNUNET_TIME_Relative tv;
-
- FD_ZERO(&rs);
- FD_ZERO(&ws);
- FD_ZERO(&es);
+
+ FD_ZERO (&rs);
+ FD_ZERO (&ws);
+ FD_ZERO (&es);
wrs = GNUNET_NETWORK_fdset_create ();
wes = GNUNET_NETWORK_fdset_create ();
wws = GNUNET_NETWORK_fdset_create ();
max = -1;
- GNUNET_assert (MHD_YES ==
- MHD_get_fdset (daemon_handle,
- &rs,
- &ws,
- &es,
- &max));
+ GNUNET_assert (MHD_YES == MHD_get_fdset (daemon_handle, &rs, &ws, &es,
&max));
haveto = MHD_get_timeout (daemon_handle, &timeout);
if (haveto == MHD_YES)
tv.rel_value = (uint64_t) timeout;
@@ -552,12 +525,8 @@
GNUNET_NETWORK_fdset_copy_native (wws, &ws, max + 1);
GNUNET_NETWORK_fdset_copy_native (wes, &es, max + 1);
ret = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH,
- GNUNET_SCHEDULER_NO_TASK,
- tv,
- wrs,
- wws,
- &run_daemon,
- daemon_handle);
+ GNUNET_SCHEDULER_NO_TASK,
+ tv, wrs, wws, &run_daemon, daemon_handle);
GNUNET_NETWORK_fdset_destroy (wrs);
GNUNET_NETWORK_fdset_destroy (wws);
GNUNET_NETWORK_fdset_destroy (wes);
@@ -573,9 +542,9 @@
*/
int
GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c,
- struct GNUNET_STATISTICS_Handle *st,
- struct GNUNET_CORE_Handle *co,
- GNUNET_CORE_ConnectEventHandler *server_ch,
+ struct GNUNET_STATISTICS_Handle *st,
+ struct GNUNET_CORE_Handle *co,
+ GNUNET_CORE_ConnectEventHandler *server_ch,
GNUNET_CORE_DisconnectEventHandler *server_dh,
int advertise)
{
@@ -584,102 +553,100 @@
size_t size;
advertising = advertise;
- if ( !advertising )
+ if (!advertising)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Advertising not enabled on this hostlist server\n");
+ "Advertising not enabled on this hostlist server\n");
else
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Advertising enabled on this hostlist server\n");
+ "Advertising enabled on this hostlist server\n");
cfg = c;
stats = st;
peerinfo = GNUNET_PEERINFO_connect (cfg);
if (peerinfo == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Could not access PEERINFO service. Exiting.\n"));
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Could not access PEERINFO service. Exiting.\n"));
+ return GNUNET_SYSERR;
+ }
if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg,
- "HOSTLIST",
- "HTTPPORT",
- &port))
+ "HOSTLIST",
+ "HTTPPORT", &port))
return GNUNET_SYSERR;
- if ( (port == 0) ||
- (port > UINT16_MAX) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Invalid port number %llu. Exiting.\n"),
- port);
- return GNUNET_SYSERR;
- }
+ if ((port == 0) || (port > UINT16_MAX))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Invalid port number %llu. Exiting.\n"), port);
+ return GNUNET_SYSERR;
+ }
- if ( GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
- "HOSTLIST",
- "EXTERNAL_DNS_NAME",
- &hostname))
+ if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
+ "HOSTLIST",
+
"EXTERNAL_DNS_NAME",
+ &hostname))
hostname = GNUNET_RESOLVER_local_fqdn_get ();
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Hostlist service starts on %s:%llu\n"),
- hostname, port);
+ _("Hostlist service starts on %s:%llu\n"), hostname, port);
if (NULL != hostname)
+ {
+ size = strlen (hostname);
+ if (size + 15 > MAX_URL_LEN)
{
- size = strlen (hostname);
- if (size + 15 > MAX_URL_LEN)
- {
- GNUNET_break (0);
- }
- else
- {
- GNUNET_asprintf (&hostlist_uri,
- "http://%s:%u/",
- hostname,
- (unsigned int) port);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Address to obtain hostlist: `%s'\n"),
- hostlist_uri);
- }
- GNUNET_free ( hostname );
+ GNUNET_break (0);
}
- daemon_handle_v6 = MHD_start_daemon (MHD_USE_IPv6
+ else
+ {
+ GNUNET_asprintf (&hostlist_uri,
+ "http://%s:%u/", hostname, (unsigned int) port);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Address to obtain hostlist: `%s'\n"), hostlist_uri);
+ }
+ GNUNET_free (hostname);
+ }
+ daemon_handle_v6 = MHD_start_daemon (MHD_USE_IPv6
#if DEBUG_HOSTLIST_SERVER
- | MHD_USE_DEBUG
+ | MHD_USE_DEBUG
#endif
- ,
- (unsigned short) port,
- &accept_policy_callback,
- NULL,
- &access_handler_callback,
- NULL,
- MHD_OPTION_CONNECTION_LIMIT, (unsigned
int) 16,
- MHD_OPTION_PER_IP_CONNECTION_LIMIT,
(unsigned int) 1,
- MHD_OPTION_CONNECTION_TIMEOUT, (unsigned
int) 16,
- MHD_OPTION_CONNECTION_MEMORY_LIMIT,
(size_t) (16 * 1024),
- MHD_OPTION_END);
+ ,
+ (unsigned short) port,
+ &accept_policy_callback,
+ NULL,
+ &access_handler_callback,
+ NULL,
+ MHD_OPTION_CONNECTION_LIMIT,
+ (unsigned int) 16,
+ MHD_OPTION_PER_IP_CONNECTION_LIMIT,
+ (unsigned int) 1,
+ MHD_OPTION_CONNECTION_TIMEOUT,
+ (unsigned int) 16,
+ MHD_OPTION_CONNECTION_MEMORY_LIMIT,
+ (size_t) (16 * 1024), MHD_OPTION_END);
daemon_handle_v4 = MHD_start_daemon (MHD_NO_FLAG
#if DEBUG_HOSTLIST_SERVER
- | MHD_USE_DEBUG
+ | MHD_USE_DEBUG
#endif
- ,
- (unsigned short) port,
- &accept_policy_callback,
- NULL,
- &access_handler_callback,
- NULL,
- MHD_OPTION_CONNECTION_LIMIT, (unsigned
int) 16,
- MHD_OPTION_PER_IP_CONNECTION_LIMIT,
(unsigned int) 1,
- MHD_OPTION_CONNECTION_TIMEOUT, (unsigned
int) 16,
- MHD_OPTION_CONNECTION_MEMORY_LIMIT,
(size_t) (16 * 1024),
- MHD_OPTION_END);
+ ,
+ (unsigned short) port,
+ &accept_policy_callback,
+ NULL,
+ &access_handler_callback,
+ NULL,
+ MHD_OPTION_CONNECTION_LIMIT,
+ (unsigned int) 16,
+ MHD_OPTION_PER_IP_CONNECTION_LIMIT,
+ (unsigned int) 1,
+ MHD_OPTION_CONNECTION_TIMEOUT,
+ (unsigned int) 16,
+ MHD_OPTION_CONNECTION_MEMORY_LIMIT,
+ (size_t) (16 * 1024), MHD_OPTION_END);
- if ( (daemon_handle_v6 == NULL) &&
- (daemon_handle_v4 == NULL) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Could not start hostlist HTTP server on port %u\n"),
- (unsigned short) port);
- return GNUNET_SYSERR;
- }
+ if ((daemon_handle_v6 == NULL) && (daemon_handle_v4 == NULL))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Could not start hostlist HTTP server on port %u\n"),
+ (unsigned short) port);
+ return GNUNET_SYSERR;
+ }
core = co;
@@ -691,7 +658,7 @@
if (daemon_handle_v6 != NULL)
hostlist_task_v6 = prepare_daemon (daemon_handle_v6);
- notify = GNUNET_PEERINFO_notify ( cfg, process_notify, NULL);
+ notify = GNUNET_PEERINFO_notify (cfg, process_notify, NULL);
return GNUNET_OK;
}
@@ -703,49 +670,48 @@
GNUNET_HOSTLIST_server_stop ()
{
#if DEBUG_HOSTLIST_SERVER
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Hostlist server shutdown\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist server shutdown\n");
#endif
if (NULL != notify)
- {
- GNUNET_PEERINFO_notify_cancel (notify);
- notify = NULL;
- }
+ {
+ GNUNET_PEERINFO_notify_cancel (notify);
+ notify = NULL;
+ }
if (GNUNET_SCHEDULER_NO_TASK != hostlist_task_v6)
- {
- GNUNET_SCHEDULER_cancel (hostlist_task_v6);
- hostlist_task_v6 = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (hostlist_task_v6);
+ hostlist_task_v6 = GNUNET_SCHEDULER_NO_TASK;
+ }
if (GNUNET_SCHEDULER_NO_TASK != hostlist_task_v4)
- {
- GNUNET_SCHEDULER_cancel (hostlist_task_v4);
- hostlist_task_v4 = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (hostlist_task_v4);
+ hostlist_task_v4 = GNUNET_SCHEDULER_NO_TASK;
+ }
if (pitr != NULL)
- {
- GNUNET_PEERINFO_iterate_cancel (pitr);
- pitr = NULL;
- }
+ {
+ GNUNET_PEERINFO_iterate_cancel (pitr);
+ pitr = NULL;
+ }
if (NULL != daemon_handle_v4)
- {
- MHD_stop_daemon (daemon_handle_v4);
- daemon_handle_v4 = NULL;
- }
+ {
+ MHD_stop_daemon (daemon_handle_v4);
+ daemon_handle_v4 = NULL;
+ }
if (NULL != daemon_handle_v6)
- {
- MHD_stop_daemon (daemon_handle_v6);
- daemon_handle_v6 = NULL;
- }
+ {
+ MHD_stop_daemon (daemon_handle_v6);
+ daemon_handle_v6 = NULL;
+ }
if (response != NULL)
- {
- MHD_destroy_response (response);
- response = NULL;
- }
+ {
+ MHD_destroy_response (response);
+ response = NULL;
+ }
if (peerinfo != NULL)
- {
- GNUNET_PEERINFO_disconnect (peerinfo);
- peerinfo = NULL;
- }
+ {
+ GNUNET_PEERINFO_disconnect (peerinfo);
+ peerinfo = NULL;
+ }
cfg = NULL;
stats = NULL;
core = NULL;
Modified: gnunet/src/hostlist/hostlist-server.h
===================================================================
--- gnunet/src/hostlist/hostlist-server.h 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/hostlist/hostlist-server.h 2011-08-15 21:46:35 UTC (rev
16581)
@@ -40,18 +40,17 @@
*/
int
GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c,
- struct GNUNET_STATISTICS_Handle *st,
- struct GNUNET_CORE_Handle *core,
+ struct GNUNET_STATISTICS_Handle *st,
+ struct GNUNET_CORE_Handle *core,
GNUNET_CORE_ConnectEventHandler *server_ch,
- GNUNET_CORE_DisconnectEventHandler *server_dh,
- int advertise);
+ GNUNET_CORE_DisconnectEventHandler *server_dh,
+ int advertise);
/**
* Stop server offering our hostlist.
*/
-void
-GNUNET_HOSTLIST_server_stop (void);
+void GNUNET_HOSTLIST_server_stop (void);
#endif
Modified: gnunet/src/hostlist/test_gnunet_daemon_hostlist.c
===================================================================
--- gnunet/src/hostlist/test_gnunet_daemon_hostlist.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/hostlist/test_gnunet_daemon_hostlist.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -40,7 +40,7 @@
static int ok;
static GNUNET_SCHEDULER_TaskIdentifier timeout_task;
-
+
struct PeerContext
{
struct GNUNET_CONFIGURATION_Handle *cfg;
@@ -60,15 +60,15 @@
clean_up (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
if (p1.th != NULL)
- {
- GNUNET_TRANSPORT_disconnect (p1.th);
- p1.th = NULL;
- }
+ {
+ GNUNET_TRANSPORT_disconnect (p1.th);
+ p1.th = NULL;
+ }
if (p2.th != NULL)
- {
- GNUNET_TRANSPORT_disconnect (p2.th);
- p2.th = NULL;
- }
+ {
+ GNUNET_TRANSPORT_disconnect (p2.th);
+ p2.th = NULL;
+ }
GNUNET_SCHEDULER_shutdown ();
}
@@ -80,7 +80,7 @@
{
timeout_task = GNUNET_SCHEDULER_NO_TASK;
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Timeout trying to connect peers, test failed.\n");
+ "Timeout trying to connect peers, test failed.\n");
clean_up (NULL, tc);
}
@@ -96,32 +96,31 @@
*/
static void
notify_connect (void *cls,
- const struct GNUNET_PeerIdentity * peer,
- const struct GNUNET_TRANSPORT_ATS_Information *ats, uint32_t
ats_count)
+ const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_TRANSPORT_ATS_Information *ats,
+ uint32_t ats_count)
{
if (peer == NULL)
return;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peers connected, shutting down.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected, shutting down.\n");
ok = 0;
if (timeout_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (timeout_task);
- timeout_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (timeout_task);
+ timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ }
GNUNET_SCHEDULER_add_now (&clean_up, NULL);
}
static void
-process_hello (void *cls,
- const struct GNUNET_MessageHeader *message)
+process_hello (void *cls, const struct GNUNET_MessageHeader *message)
{
struct PeerContext *p = cls;
GNUNET_TRANSPORT_get_hello_cancel (p->th, &process_hello, p);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received HELLO, starting hostlist service.\n");
+ "Received HELLO, starting hostlist service.\n");
}
@@ -131,35 +130,34 @@
p->cfg = GNUNET_CONFIGURATION_create ();
#if START_ARM
p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
- "gnunet-service-arm",
+ "gnunet-service-arm",
#if VERBOSE
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", cfgname, NULL);
+ "-c", cfgname, NULL);
#endif
GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL,
- ¬ify_connect, NULL);
+ ¬ify_connect, NULL);
GNUNET_assert (p->th != NULL);
GNUNET_TRANSPORT_get_hello (p->th, &process_hello, p);
}
static void
-waitpid_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+waitpid_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct PeerContext *p = cls;
-#if START_ARM
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Killing ARM process.\n");
+#if START_ARM
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Killing ARM process.\n");
if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
- if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK)
+ if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "ARM process %u stopped\n", GNUNET_OS_process_get_pid
(p->arm_proc));
+ "ARM process %u stopped\n",
+ GNUNET_OS_process_get_pid (p->arm_proc));
GNUNET_OS_process_close (p->arm_proc);
p->arm_proc = NULL;
#endif
@@ -170,10 +168,8 @@
static void
stop_arm (struct PeerContext *p)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Asking ARM to stop core service\n");
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
- &waitpid_task, p);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking ARM to stop core service\n");
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &waitpid_task, p);
}
@@ -191,17 +187,13 @@
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
GNUNET_assert (ok == 1);
ok++;
- timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &timeout_error,
- NULL);
+ timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_error, NULL);
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task,
- NULL);
+ &shutdown_task, NULL);
setup_peer (&p1, "test_gnunet_daemon_hostlist_peer1.conf");
setup_peer (&p2, "test_gnunet_daemon_hostlist_peer2.conf");
}
@@ -223,7 +215,7 @@
ok = 1;
GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
argv, "test-gnunet-daemon-hostlist",
- "nohelp", options, &run, &ok);
+ "nohelp", options, &run, &ok);
return ok;
}
@@ -231,7 +223,7 @@
int
main (int argc, char *argv[])
{
-
+
int ret;
GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-1");
@@ -248,7 +240,7 @@
GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-1");
GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-2");
GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist");
- return ret;
+ return ret;
}
/* end of test_gnunet_daemon_hostlist.c */
Modified: gnunet/src/hostlist/test_gnunet_daemon_hostlist_learning.c
===================================================================
--- gnunet/src/hostlist/test_gnunet_daemon_hostlist_learning.c 2011-08-15
21:40:08 UTC (rev 16580)
+++ gnunet/src/hostlist/test_gnunet_daemon_hostlist_learning.c 2011-08-15
21:46:35 UTC (rev 16581)
@@ -43,7 +43,7 @@
#define CHECK_INTERVALL GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_SECONDS, 1)
-
+
struct PeerContext
{
struct GNUNET_CONFIGURATION_Handle *cfg;
@@ -66,7 +66,7 @@
static int learned_hostlist_downloaded;
-static char * current_adv_uri;
+static char *current_adv_uri;
static const struct GNUNET_CONFIGURATION_Handle *cfg;
@@ -78,106 +78,99 @@
static struct PeerContext learn_peer;
-static struct GNUNET_STATISTICS_GetHandle * download_stats;
+static struct GNUNET_STATISTICS_GetHandle *download_stats;
-static struct GNUNET_STATISTICS_GetHandle * urisrecv_stat;
+static struct GNUNET_STATISTICS_GetHandle *urisrecv_stat;
-static struct GNUNET_STATISTICS_GetHandle * advsent_stat;
+static struct GNUNET_STATISTICS_GetHandle *advsent_stat;
-static void
-shutdown_testcase()
+static void
+shutdown_testcase ()
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Shutdown testcase....\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown testcase....\n");
if (timeout_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (timeout_task);
- timeout_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (timeout_task);
+ timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ }
if (NULL != download_stats)
- {
- GNUNET_STATISTICS_get_cancel (download_stats);
- download_stats = NULL;
- }
+ {
+ GNUNET_STATISTICS_get_cancel (download_stats);
+ download_stats = NULL;
+ }
if (NULL != urisrecv_stat)
- {
- GNUNET_STATISTICS_get_cancel (urisrecv_stat);
- urisrecv_stat = NULL;
- }
+ {
+ GNUNET_STATISTICS_get_cancel (urisrecv_stat);
+ urisrecv_stat = NULL;
+ }
if (NULL != advsent_stat)
- {
- GNUNET_STATISTICS_get_cancel (advsent_stat);
- advsent_stat = NULL;
- }
+ {
+ GNUNET_STATISTICS_get_cancel (advsent_stat);
+ advsent_stat = NULL;
+ }
if (check_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (check_task);
- check_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (check_task);
+ check_task = GNUNET_SCHEDULER_NO_TASK;
+ }
if (NULL != current_adv_uri)
- {
- GNUNET_free (current_adv_uri);
- current_adv_uri = NULL;
- }
+ {
+ GNUNET_free (current_adv_uri);
+ current_adv_uri = NULL;
+ }
if (adv_peer.th != NULL)
- {
- GNUNET_TRANSPORT_disconnect (adv_peer.th);
- adv_peer.th = NULL;
- }
+ {
+ GNUNET_TRANSPORT_disconnect (adv_peer.th);
+ adv_peer.th = NULL;
+ }
if (learn_peer.th != NULL)
- {
- GNUNET_TRANSPORT_disconnect (learn_peer.th);
- learn_peer.th = NULL;
- }
+ {
+ GNUNET_TRANSPORT_disconnect (learn_peer.th);
+ learn_peer.th = NULL;
+ }
if (adv_peer.core != NULL)
- {
- GNUNET_CORE_disconnect (adv_peer.core);
- adv_peer.core = NULL;
- }
+ {
+ GNUNET_CORE_disconnect (adv_peer.core);
+ adv_peer.core = NULL;
+ }
if (learn_peer.core != NULL)
- {
- GNUNET_CORE_disconnect (learn_peer.core);
- learn_peer.core = NULL;
- }
+ {
+ GNUNET_CORE_disconnect (learn_peer.core);
+ learn_peer.core = NULL;
+ }
#if START_ARM
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Killing hostlist server ARM process.\n");
if (0 != GNUNET_OS_process_kill (adv_peer.arm_proc, SIGTERM))
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
- "kill");
- if (GNUNET_OS_process_wait(adv_peer.arm_proc) != GNUNET_OK)
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
- "waitpid");
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
+ if (GNUNET_OS_process_wait (adv_peer.arm_proc) != GNUNET_OK)
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
GNUNET_OS_process_close (adv_peer.arm_proc);
adv_peer.arm_proc = NULL;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Killing hostlist client ARM process.\n");
if (0 != GNUNET_OS_process_kill (learn_peer.arm_proc, SIGTERM))
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
- "kill");
- if (GNUNET_OS_process_wait(learn_peer.arm_proc) != GNUNET_OK)
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
- "waitpid");
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
+ if (GNUNET_OS_process_wait (learn_peer.arm_proc) != GNUNET_OK)
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
GNUNET_OS_process_close (learn_peer.arm_proc);
learn_peer.arm_proc = NULL;
#endif
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Shutdown complete....\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown complete....\n");
}
/**
* Timeout, give up.
*/
static void
-timeout_error (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+timeout_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
timeout_task = GNUNET_SCHEDULER_NO_TASK;
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Timeout while executing testcase, test failed.\n");
timeout = GNUNET_YES;
- shutdown_testcase();
+ shutdown_testcase ();
}
@@ -190,21 +183,17 @@
static int
process_downloads (void *cls,
- const char *subsystem,
- const char *name,
- uint64_t value,
- int is_persistent)
+ const char *subsystem,
+ const char *name, uint64_t value, int is_persistent)
{
- if ( (value >= 2) &&
- (learned_hostlist_downloaded == GNUNET_NO) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Peer has successfully downloaded advertised URI\n");
- learned_hostlist_downloaded = GNUNET_YES;
- if ( (learned_hostlist_saved == GNUNET_YES) &&
- (adv_sent == GNUNET_YES) )
- shutdown_testcase();
- }
+ if ((value >= 2) && (learned_hostlist_downloaded == GNUNET_NO))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Peer has successfully downloaded advertised URI\n");
+ learned_hostlist_downloaded = GNUNET_YES;
+ if ((learned_hostlist_saved == GNUNET_YES) && (adv_sent == GNUNET_YES))
+ shutdown_testcase ();
+ }
return GNUNET_OK;
}
@@ -218,22 +207,18 @@
static int
process_uris_recv (void *cls,
- const char *subsystem,
- const char *name,
- uint64_t value,
- int is_persistent)
+ const char *subsystem,
+ const char *name, uint64_t value, int is_persistent)
{
- if ( ((struct PeerContext *) cls == &learn_peer) &&
- (value == 1) &&
- (learned_hostlist_saved == GNUNET_NO) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Peer has successfully saved advertised URI\n");
- learned_hostlist_saved = GNUNET_YES;
- if ( (learned_hostlist_downloaded == GNUNET_YES) &&
- (adv_sent == GNUNET_YES) )
- shutdown_testcase();
- }
+ if (((struct PeerContext *) cls == &learn_peer) &&
+ (value == 1) && (learned_hostlist_saved == GNUNET_NO))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Peer has successfully saved advertised URI\n");
+ learned_hostlist_saved = GNUNET_YES;
+ if ((learned_hostlist_downloaded == GNUNET_YES) && (adv_sent ==
GNUNET_YES))
+ shutdown_testcase ();
+ }
return GNUNET_OK;
}
@@ -247,20 +232,18 @@
static int
process_adv_sent (void *cls,
- const char *subsystem,
- const char *name,
- uint64_t value,
- int is_persistent)
+ const char *subsystem,
+ const char *name, uint64_t value, int is_persistent)
{
- if ( (value >= 1) && (adv_sent == GNUNET_NO))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Server has successfully sent advertisement\n");
- adv_sent = GNUNET_YES;
- if ( (learned_hostlist_downloaded == GNUNET_YES) &&
- (learned_hostlist_saved == GNUNET_YES) )
- shutdown_testcase();
- }
+ if ((value >= 1) && (adv_sent == GNUNET_NO))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Server has successfully sent advertisement\n");
+ adv_sent = GNUNET_YES;
+ if ((learned_hostlist_downloaded == GNUNET_YES) &&
+ (learned_hostlist_saved == GNUNET_YES))
+ shutdown_testcase ();
+ }
return GNUNET_OK;
}
@@ -269,8 +252,7 @@
* Check the server statistics regularly
*/
static void
-check_statistics (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+check_statistics (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
char *stat;
@@ -278,105 +260,102 @@
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
return;
GNUNET_asprintf (&stat,
- gettext_noop("# advertised URI `%s' downloaded"),
- current_adv_uri);
+ gettext_noop ("# advertised URI `%s' downloaded"),
+ current_adv_uri);
if (NULL != learn_peer.stats)
- {
- if (NULL != download_stats)
- GNUNET_STATISTICS_get_cancel (download_stats);
- download_stats = GNUNET_STATISTICS_get (learn_peer.stats,
- "hostlist",
- stat,
- GNUNET_TIME_UNIT_MINUTES,
- &process_downloads_done,
- &process_downloads,
- &learn_peer);
- if (NULL != urisrecv_stat)
- GNUNET_STATISTICS_get_cancel (urisrecv_stat);
- urisrecv_stat = GNUNET_STATISTICS_get (learn_peer.stats,
- "hostlist",
- gettext_noop("# advertised
hostlist URIs"),
- GNUNET_TIME_UNIT_MINUTES,
- &process_uris_recv_done,
- &process_uris_recv,
- &learn_peer);
- }
+ {
+ if (NULL != download_stats)
+ GNUNET_STATISTICS_get_cancel (download_stats);
+ download_stats = GNUNET_STATISTICS_get (learn_peer.stats,
+ "hostlist",
+ stat,
+ GNUNET_TIME_UNIT_MINUTES,
+ &process_downloads_done,
+ &process_downloads, &learn_peer);
+ if (NULL != urisrecv_stat)
+ GNUNET_STATISTICS_get_cancel (urisrecv_stat);
+ urisrecv_stat = GNUNET_STATISTICS_get (learn_peer.stats,
+ "hostlist",
+ gettext_noop
+ ("# advertised hostlist URIs"),
+ GNUNET_TIME_UNIT_MINUTES,
+ &process_uris_recv_done,
+ &process_uris_recv, &learn_peer);
+ }
GNUNET_free (stat);
- if ( NULL != adv_peer.stats)
- {
- if (NULL != advsent_stat)
- GNUNET_STATISTICS_get_cancel (advsent_stat);
- advsent_stat = GNUNET_STATISTICS_get (adv_peer.stats,
- "hostlist",
- gettext_noop("# hostlist
advertisements send"),
- GNUNET_TIME_UNIT_MINUTES,
- &process_adv_sent_done,
- &process_adv_sent,
- NULL);
- }
+ if (NULL != adv_peer.stats)
+ {
+ if (NULL != advsent_stat)
+ GNUNET_STATISTICS_get_cancel (advsent_stat);
+ advsent_stat = GNUNET_STATISTICS_get (adv_peer.stats,
+ "hostlist",
+ gettext_noop
+ ("# hostlist advertisements send"),
+ GNUNET_TIME_UNIT_MINUTES,
+ &process_adv_sent_done,
+ &process_adv_sent, NULL);
+ }
check_task = GNUNET_SCHEDULER_add_delayed (CHECK_INTERVALL,
- &check_statistics,
- NULL);
+ &check_statistics, NULL);
}
/**
* Core handler for p2p hostlist advertisements
*/
-static int
+static int
ad_arrive_handler (void *cls,
- const struct GNUNET_PeerIdentity * peer,
- const struct GNUNET_MessageHeader * message,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+ const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_MessageHeader *message,
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
char *hostname;
char *expected_uri;
unsigned long long port;
- const struct GNUNET_MessageHeader * incoming;
+ const struct GNUNET_MessageHeader *incoming;
const char *end;
if (-1 == GNUNET_CONFIGURATION_get_value_number (adv_peer.cfg,
"HOSTLIST",
- "HTTPPORT",
- &port))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Could not read advertising server's configuration\n" );
- return GNUNET_SYSERR;
- }
+ "HTTPPORT", &port))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Could not read advertising server's configuration\n");
+ return GNUNET_SYSERR;
+ }
- if ( GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (adv_peer.cfg,
- "HOSTLIST",
-
"EXTERNAL_DNS_NAME",
- &hostname))
+ if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (adv_peer.cfg,
+ "HOSTLIST",
+
"EXTERNAL_DNS_NAME",
+ &hostname))
hostname = GNUNET_RESOLVER_local_fqdn_get ();
GNUNET_asprintf (&expected_uri,
- "http://%s:%u/",
- hostname != NULL ? hostname : "localhost",
- (unsigned int) port);
+ "http://%s:%u/",
+ hostname != NULL ? hostname : "localhost",
+ (unsigned int) port);
incoming = (const struct GNUNET_MessageHeader *) message;
- end = (const char*) &incoming[1];
- if ('\0' != end[ntohs(message->size) - sizeof (struct GNUNET_MessageHeader)
- 1])
- {
- GNUNET_break (0);
- GNUNET_free (expected_uri);
- GNUNET_free_non_null (hostname);
- return GNUNET_SYSERR;
- }
+ end = (const char *) &incoming[1];
+ if ('\0' !=
+ end[ntohs (message->size) - sizeof (struct GNUNET_MessageHeader) - 1])
+ {
+ GNUNET_break (0);
+ GNUNET_free (expected_uri);
+ GNUNET_free_non_null (hostname);
+ return GNUNET_SYSERR;
+ }
current_adv_uri = GNUNET_strdup (end);
- if ( 0 == strcmp( expected_uri, current_adv_uri ) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Received hostlist advertisement with URI `%s' as expected\n",
- current_adv_uri);
- adv_arrived = GNUNET_YES;
- adv_sent = GNUNET_YES;
- }
+ if (0 == strcmp (expected_uri, current_adv_uri))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Received hostlist advertisement with URI `%s' as expected\n",
+ current_adv_uri);
+ adv_arrived = GNUNET_YES;
+ adv_sent = GNUNET_YES;
+ }
else
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Expected URI `%s' and recieved URI `%s' differ\n",
- expected_uri,
- current_adv_uri);
+ expected_uri, current_adv_uri);
GNUNET_free (expected_uri);
GNUNET_free_non_null (hostname);
return GNUNET_OK;
@@ -387,83 +366,79 @@
* List of handlers if we are learning.
*/
static struct GNUNET_CORE_MessageHandler learn_handlers[] = {
- { &ad_arrive_handler, GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT, 0},
- { NULL, 0, 0 }
+ {&ad_arrive_handler, GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT, 0},
+ {NULL, 0, 0}
};
static void
-setup_learn_peer (struct PeerContext *p,
- const char *cfgname)
+setup_learn_peer (struct PeerContext *p, const char *cfgname)
{
- char * filename;
+ char *filename;
unsigned int result;
p->cfg = GNUNET_CONFIGURATION_create ();
#if START_ARM
p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
- "gnunet-service-arm",
+ "gnunet-service-arm",
#if VERBOSE
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", cfgname, NULL);
+ "-c", cfgname, NULL);
#endif
GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (p->cfg,
"HOSTLIST",
"HOSTLISTFILE",
&filename))
+ {
+ if (GNUNET_YES == GNUNET_DISK_file_test (filename))
{
- if (GNUNET_YES == GNUNET_DISK_file_test (filename))
- {
- result = UNLINK (filename);
- if (result == 0)
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Hostlist file `%s' was removed\n"),filename);
- }
- GNUNET_free (filename);
+ result = UNLINK (filename);
+ if (result == 0)
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Hostlist file `%s' was removed\n"), filename);
}
+ GNUNET_free (filename);
+ }
p->core = GNUNET_CORE_connect (p->cfg,
- 1,
- NULL,
- NULL,
- NULL, NULL, NULL,
- NULL, GNUNET_NO,
- NULL, GNUNET_NO,
- learn_handlers );
- GNUNET_assert ( NULL != p->core );
+ 1,
+ NULL,
+ 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 );
+ GNUNET_assert (NULL != p->stats);
}
static void
-setup_adv_peer (struct PeerContext *p,
- const char *cfgname)
+setup_adv_peer (struct PeerContext *p, const char *cfgname)
{
p->cfg = GNUNET_CONFIGURATION_create ();
#if START_ARM
p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
- "gnunet-service-arm",
+ "gnunet-service-arm",
#if VERBOSE
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", cfgname, NULL);
+ "-c", cfgname, NULL);
#endif
GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
p->stats = GNUNET_STATISTICS_create ("hostlist", p->cfg);
- GNUNET_assert ( NULL != p->stats );
+ GNUNET_assert (NULL != p->stats);
}
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *c)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
{
timeout = GNUNET_NO;
- adv_sent =GNUNET_NO;
+ adv_sent = GNUNET_NO;
adv_arrived = 0;
learned_hostlist_saved = GNUNET_NO;
@@ -473,13 +448,10 @@
setup_adv_peer (&adv_peer, "test_learning_adv_peer.conf");
setup_learn_peer (&learn_peer, "test_learning_learn_peer.conf");
- timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &timeout_error,
- NULL);
+ timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_error, NULL);
check_task = GNUNET_SCHEDULER_add_delayed (CHECK_INTERVALL,
- &check_statistics,
- NULL);
+ &check_statistics, NULL);
}
@@ -487,7 +459,8 @@
check ()
{
unsigned int failed;
- char *const argv[] = {
+
+ char *const argv[] = {
"test-gnunet-daemon-hostlist-learning",
"-c", "learning_data.conf",
#if VERBOSE
@@ -501,39 +474,37 @@
GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
argv, "test-gnunet-daemon-hostlist-learning",
- "nohelp", options,
- &run, NULL);
+ "nohelp", options, &run, NULL);
failed = GNUNET_NO;
if (timeout == GNUNET_YES)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Testcase timeout\n");
- failed = GNUNET_YES;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Testcase timeout\n");
+ failed = GNUNET_YES;
+ }
if (adv_arrived != GNUNET_YES)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Learning peer did not receive advertisement from server\n");
- failed = GNUNET_YES;
- }
- if ( learned_hostlist_saved == GNUNET_NO )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Advertised hostlist was not saved in datastore\n");
- failed = GNUNET_YES;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Learning peer did not receive advertisement from server\n");
+ failed = GNUNET_YES;
+ }
+ if (learned_hostlist_saved == GNUNET_NO)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Advertised hostlist was not saved in datastore\n");
+ failed = GNUNET_YES;
+ }
if (learned_hostlist_downloaded == GNUNET_NO)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Advertised hostlist could not be downloaded from server\n");
- failed = GNUNET_YES;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Advertised hostlist could not be downloaded from server\n");
+ failed = GNUNET_YES;
+ }
if (adv_sent == GNUNET_NO)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Advertised was not sent from server to client\n");
- failed = GNUNET_YES;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Advertised was not sent from server to client\n");
+ failed = GNUNET_YES;
+ }
if (GNUNET_YES == failed)
return GNUNET_YES;
return GNUNET_NO;
@@ -542,7 +513,7 @@
int
main (int argc, char *argv[])
-{
+{
int ret;
GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-1");
@@ -565,12 +536,12 @@
GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-1");
GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-2");
if (GNUNET_YES == GNUNET_DISK_file_test ("hostlists_learn_peer.file"))
- {
- if (0 == UNLINK("hostlists_learn_peer.file"))
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Hostlist file hostlists_learn_peer.file was removed\n");
- }
- return ret;
+ {
+ if (0 == UNLINK ("hostlists_learn_peer.file"))
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Hostlist file hostlists_learn_peer.file was removed\n");
+ }
+ return ret;
}
/* end of test_gnunet_daemon_hostlist.c */
Modified: gnunet/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c
===================================================================
--- gnunet/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c 2011-08-15
21:40:08 UTC (rev 16580)
+++ gnunet/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c 2011-08-15
21:46:35 UTC (rev 16581)
@@ -41,7 +41,7 @@
static int ok;
static GNUNET_SCHEDULER_TaskIdentifier timeout_task;
-
+
struct PeerContext
{
struct GNUNET_CONFIGURATION_Handle *cfg;
@@ -61,15 +61,15 @@
clean_up (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
if (p1.th != NULL)
- {
- GNUNET_TRANSPORT_disconnect (p1.th);
- p1.th = NULL;
- }
+ {
+ GNUNET_TRANSPORT_disconnect (p1.th);
+ p1.th = NULL;
+ }
if (p2.th != NULL)
- {
- GNUNET_TRANSPORT_disconnect (p2.th);
- p2.th = NULL;
- }
+ {
+ GNUNET_TRANSPORT_disconnect (p2.th);
+ p2.th = NULL;
+ }
GNUNET_SCHEDULER_shutdown ();
}
@@ -81,7 +81,7 @@
{
timeout_task = GNUNET_SCHEDULER_NO_TASK;
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Timeout trying to connect peers, test failed.\n");
+ "Timeout trying to connect peers, test failed.\n");
clean_up (NULL, tc);
}
@@ -97,35 +97,34 @@
*/
static void
notify_connect (void *cls,
- const struct GNUNET_PeerIdentity * peer,
- const struct GNUNET_TRANSPORT_ATS_Information *ats, uint32_t
ats_count)
+ const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_TRANSPORT_ATS_Information *ats,
+ uint32_t ats_count)
{
if (peer == NULL)
return;
#if VERBOSE
fprintf (stderr, "Peer %s connected\n", GNUNET_i2s (peer));
#endif
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peers connected, shutting down.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected, shutting down.\n");
ok = 0;
if (timeout_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (timeout_task);
- timeout_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (timeout_task);
+ timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ }
GNUNET_SCHEDULER_add_now (&clean_up, NULL);
}
static void
-process_hello (void *cls,
- const struct GNUNET_MessageHeader *message)
+process_hello (void *cls, const struct GNUNET_MessageHeader *message)
{
struct PeerContext *p = cls;
GNUNET_TRANSPORT_get_hello_cancel (p->th, &process_hello, p);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received HELLO, starting hostlist service.\n");
+ "Received HELLO, starting hostlist service.\n");
}
@@ -135,35 +134,34 @@
p->cfg = GNUNET_CONFIGURATION_create ();
#if START_ARM
p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
- "gnunet-service-arm",
+ "gnunet-service-arm",
#if VERBOSE
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", cfgname, NULL);
+ "-c", cfgname, NULL);
#endif
GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL,
- ¬ify_connect, NULL);
+ ¬ify_connect, NULL);
GNUNET_assert (p->th != NULL);
GNUNET_TRANSPORT_get_hello (p->th, &process_hello, p);
}
static void
-waitpid_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+waitpid_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct PeerContext *p = cls;
-#if START_ARM
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Killing ARM process.\n");
+#if START_ARM
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Killing ARM process.\n");
if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
- if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK)
+ if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "ARM process %u stopped\n", GNUNET_OS_process_get_pid
(p->arm_proc));
+ "ARM process %u stopped\n",
+ GNUNET_OS_process_get_pid (p->arm_proc));
GNUNET_OS_process_close (p->arm_proc);
p->arm_proc = NULL;
#endif
@@ -174,10 +172,8 @@
static void
stop_arm (struct PeerContext *p)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Asking ARM to stop core service\n");
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
- &waitpid_task, p);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking ARM to stop core service\n");
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &waitpid_task, p);
}
@@ -195,17 +191,13 @@
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
GNUNET_assert (ok == 1);
ok++;
- timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &timeout_error,
- NULL);
+ timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_error, NULL);
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task,
- NULL);
+ &shutdown_task, NULL);
setup_peer (&p1, "test_gnunet_daemon_hostlist_peer1.conf");
setup_peer (&p2, "test_gnunet_daemon_hostlist_peer2.conf");
}
@@ -227,7 +219,7 @@
ok = 1;
GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
argv, "test-gnunet-daemon-hostlist",
- "nohelp", options, &run, &ok);
+ "nohelp", options, &run, &ok);
return ok;
}
@@ -235,7 +227,7 @@
int
main (int argc, char *argv[])
{
-
+
int ret;
GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-1");
@@ -250,16 +242,16 @@
NULL);
ret = check ();
if (ret == 0)
- {
- fprintf (stderr, ".");
- /* now do it again */
- ret = check ();
- fprintf (stderr, ".\n");
- }
+ {
+ fprintf (stderr, ".");
+ /* now do it again */
+ ret = check ();
+ fprintf (stderr, ".\n");
+ }
GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-1");
GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-2");
GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-3");
- return ret;
+ return ret;
}
/* end of test_gnunet_daemon_hostlist_reconnect.c */
Modified: gnunet/src/include/gettext.h
===================================================================
--- gnunet/src/include/gettext.h 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/include/gettext.h 2011-08-15 21:46:35 UTC (rev 16581)
@@ -23,7 +23,7 @@
#if ENABLE_NLS
/* Get declarations of GNU message catalog functions. */
-# include <libintl.h>
+#include <libintl.h>
#else
@@ -34,7 +34,7 @@
and also including <libintl.h> would fail on SunOS 4, whereas <locale.h>
is GNUNET_OK. */
#if defined(__sun)
-# include <locale.h>
+#include <locale.h>
#endif
/* Disabled NLS.
@@ -42,20 +42,20 @@
for invalid uses of the value returned from these functions.
On pre-ANSI systems without 'const', the config.h file is supposed to
contain "#define const". */
-# define gettext(Msgid) ((const char *) (Msgid))
-# define dgettext(Domainname, Msgid) ((const char *) (Msgid))
-# define dcgettext(Domainname, Msgid, Category) ((const char *) (Msgid))
-# define ngettext(Msgid1, Msgid2, N) \
+#define gettext(Msgid) ((const char *) (Msgid))
+#define dgettext(Domainname, Msgid) ((const char *) (Msgid))
+#define dcgettext(Domainname, Msgid, Category) ((const char *) (Msgid))
+#define ngettext(Msgid1, Msgid2, N) \
((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2))
-# define dngettext(Domainname, Msgid1, Msgid2, N) \
+#define dngettext(Domainname, Msgid1, Msgid2, N) \
((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2))
-# define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \
+#define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \
((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2))
/* slight modification here to avoid warnings: generate GNUNET_NO code,
not even the cast... */
-# define textdomain(Domainname)
-# define bindtextdomain(Domainname, Dirname)
-# define bind_textdomain_codeset(Domainname, Codeset) ((const char *)
(Codeset))
+#define textdomain(Domainname)
+#define bindtextdomain(Domainname, Dirname)
+#define bind_textdomain_codeset(Domainname, Codeset) ((const char *) (Codeset))
#endif
Modified: gnunet/src/include/gnunet_arm_service.h
===================================================================
--- gnunet/src/include/gnunet_arm_service.h 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/include/gnunet_arm_service.h 2011-08-15 21:46:35 UTC (rev
16581)
@@ -59,7 +59,7 @@
/**
* Handle for interacting with ARM.
- */
+ */
struct GNUNET_ARM_Handle;
@@ -73,9 +73,9 @@
* @param service service that *this* process is implementing/providing, can
be NULL
* @return context to use for further ARM operations, NULL on error
*/
-struct GNUNET_ARM_Handle *
-GNUNET_ARM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *service);
+struct GNUNET_ARM_Handle *GNUNET_ARM_connect (const struct
+ GNUNET_CONFIGURATION_Handle *cfg,
+ const char *service);
/**
@@ -83,8 +83,7 @@
*
* @param h the handle that was being used
*/
-void
-GNUNET_ARM_disconnect (struct GNUNET_ARM_Handle *h);
+void GNUNET_ARM_disconnect (struct GNUNET_ARM_Handle *h);
/**
@@ -107,7 +106,7 @@
*/
void
GNUNET_ARM_start_service (struct GNUNET_ARM_Handle *h,
- const char *service_name,
+ const char *service_name,
struct GNUNET_TIME_Relative timeout,
GNUNET_ARM_Callback cb, void *cb_cls);
@@ -125,7 +124,7 @@
*/
void
GNUNET_ARM_stop_service (struct GNUNET_ARM_Handle *h,
- const char *service_name,
+ const char *service_name,
struct GNUNET_TIME_Relative timeout,
GNUNET_ARM_Callback cb, void *cb_cls);
Modified: gnunet/src/include/gnunet_ats_service.h
===================================================================
--- gnunet/src/include/gnunet_ats_service.h 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/include/gnunet_ats_service.h 2011-08-15 21:46:35 UTC (rev
16581)
@@ -58,13 +58,21 @@
* @param plugin_addr_len number of bytes in addr
* @param bandwidth assigned outbound bandwidth for the connection
*/
-typedef void (*GNUNET_TRANSPORT_ATS_AllocationNotification)(void *cls,
- const struct
GNUNET_PeerIdentity *peer,
- const char
*plugin_name,
- struct Session
*session,
- const void
*plugin_addr,
- size_t
plugin_addr_len,
- struct
GNUNET_BANDWIDTH_Value32NBO bandwidth);
+typedef void (*GNUNET_TRANSPORT_ATS_AllocationNotification) (void *cls,
+ const struct
+
GNUNET_PeerIdentity
+ * peer,
+ const char
+ *plugin_name,
+ struct Session *
+ session,
+ const void
+ *plugin_addr,
+ size_t
+ plugin_addr_len,
+ struct
+
GNUNET_BANDWIDTH_Value32NBO
+ bandwidth);
/**
@@ -75,10 +83,10 @@
* @param alloc_cb_cls closure for 'alloc_cb'
* @return ats context
*/
-struct GNUNET_ATS_Handle *
-GNUNET_ATS_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
- GNUNET_TRANSPORT_ATS_AllocationNotification alloc_cb,
- void *alloc_cb_cls);
+struct GNUNET_ATS_Handle *GNUNET_ATS_init (const struct
+ GNUNET_CONFIGURATION_Handle *cfg,
+
GNUNET_TRANSPORT_ATS_AllocationNotification
+ alloc_cb, void *alloc_cb_cls);
/**
@@ -86,8 +94,7 @@
*
* @param atc handle
*/
-void
-GNUNET_ATS_shutdown (struct GNUNET_ATS_Handle *atc);
+void GNUNET_ATS_shutdown (struct GNUNET_ATS_Handle *atc);
/**
@@ -102,14 +109,20 @@
* @param ats performance data for the address (as far as known)
* @param ats_count number of performance records in 'ats'
*/
-typedef void (*GNUNET_ATS_AddressSuggestionCallback)(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,
- const struct
GNUNET_TRANSPORT_ATS_Information *ats,
- uint32_t ats_count);
+typedef void (*GNUNET_ATS_AddressSuggestionCallback) (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,
+ const struct
+
GNUNET_TRANSPORT_ATS_Information
+ * ats,
+ uint32_t ats_count);
/**
@@ -127,11 +140,15 @@
* @param cb function to call with the address
* @param cb_cls closure for cb
*/
-struct GNUNET_ATS_SuggestionContext *
-GNUNET_ATS_suggest_address (struct GNUNET_ATS_Handle *atc,
- const struct GNUNET_PeerIdentity *peer,
- GNUNET_ATS_AddressSuggestionCallback cb,
- void *cb_cls);
+struct GNUNET_ATS_SuggestionContext *GNUNET_ATS_suggest_address (struct
+
GNUNET_ATS_Handle
+ *atc,
+ const struct
+
GNUNET_PeerIdentity
+ *peer,
+
GNUNET_ATS_AddressSuggestionCallback
+ cb,
+ void *cb_cls);
/**
@@ -159,13 +176,13 @@
*/
void
GNUNET_ATS_peer_connect (struct GNUNET_ATS_Handle *atc,
- const struct GNUNET_PeerIdentity *peer,
- const char *plugin_name,
- struct Session *session,
- const void *plugin_addr,
- size_t plugin_addr_len,
- const struct GNUNET_TRANSPORT_ATS_Information *ats,
- uint32_t ats_count);
+ const struct GNUNET_PeerIdentity *peer,
+ const char *plugin_name,
+ struct Session *session,
+ const void *plugin_addr,
+ size_t plugin_addr_len,
+ const struct GNUNET_TRANSPORT_ATS_Information *ats,
+ uint32_t ats_count);
/**
@@ -178,7 +195,7 @@
*/
void
GNUNET_ATS_peer_disconnect (struct GNUNET_ATS_Handle *atc,
- const struct GNUNET_PeerIdentity *peer);
+ const struct GNUNET_PeerIdentity *peer);
/**
@@ -190,8 +207,8 @@
*/
void
GNUNET_ATS_session_destroyed (struct GNUNET_ATS_Handle *atc,
- const struct GNUNET_PeerIdentity *peer,
- const struct Session *session);
+ const struct GNUNET_PeerIdentity *peer,
+ const struct Session *session);
/**
@@ -214,14 +231,14 @@
*/
void
GNUNET_ATS_address_update (struct GNUNET_ATS_Handle *atc,
- const struct GNUNET_PeerIdentity *peer,
- struct GNUNET_TIME_Absolute valid_until,
- const char *plugin_name,
- struct Session *session,
- const void *plugin_addr,
- size_t plugin_addr_len,
- const struct GNUNET_TRANSPORT_ATS_Information *ats,
- uint32_t ats_count);
+ const struct GNUNET_PeerIdentity *peer,
+ struct GNUNET_TIME_Absolute valid_until,
+ const char *plugin_name,
+ struct Session *session,
+ const void *plugin_addr,
+ size_t plugin_addr_len,
+ const struct GNUNET_TRANSPORT_ATS_Information *ats,
+ uint32_t ats_count);
#endif
Modified: gnunet/src/include/gnunet_bandwidth_lib.h
===================================================================
--- gnunet/src/include/gnunet_bandwidth_lib.h 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/include/gnunet_bandwidth_lib.h 2011-08-15 21:46:35 UTC (rev
16581)
@@ -107,9 +107,20 @@
* @param deadline when is the deadline
* @return number of bytes available at bps until deadline
*/
-uint64_t
-GNUNET_BANDWIDTH_value_get_available_until (struct GNUNET_BANDWIDTH_Value32NBO
bps,
- struct GNUNET_TIME_Relative
deadline);
+uint64_t
+
+
+
+
+
+
+
+
+
+ GNUNET_BANDWIDTH_value_get_available_until (struct GNUNET_BANDWIDTH_Value32NBO
+ bps,
+ struct GNUNET_TIME_Relative
+ deadline);
/**
@@ -122,7 +133,7 @@
*/
struct GNUNET_TIME_Relative
GNUNET_BANDWIDTH_value_get_delay_for (struct GNUNET_BANDWIDTH_Value32NBO bps,
- uint64_t size);
+ uint64_t size);
@@ -135,7 +146,7 @@
*/
struct GNUNET_BANDWIDTH_Value32NBO
GNUNET_BANDWIDTH_value_min (struct GNUNET_BANDWIDTH_Value32NBO b1,
- struct GNUNET_BANDWIDTH_Value32NBO b2);
+ struct GNUNET_BANDWIDTH_Value32NBO b2);
/**
@@ -154,8 +165,8 @@
*/
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);
/**
@@ -171,7 +182,7 @@
*/
int
GNUNET_BANDWIDTH_tracker_consume (struct GNUNET_BANDWIDTH_Tracker *av,
- ssize_t size);
+ ssize_t size);
/**
@@ -185,7 +196,7 @@
*/
struct GNUNET_TIME_Relative
GNUNET_BANDWIDTH_tracker_get_delay (struct GNUNET_BANDWIDTH_Tracker *av,
- size_t size);
+ size_t size);
/**
@@ -195,8 +206,15 @@
* @param av tracker to query
* @return number of bytes available for consumption right now
*/
-int64_t
-GNUNET_BANDWIDTH_tracker_get_available (struct GNUNET_BANDWIDTH_Tracker *av);
+int64_t
+
+
+
+
+
+
+
+ GNUNET_BANDWIDTH_tracker_get_available (struct GNUNET_BANDWIDTH_Tracker
*av);
/**
@@ -207,7 +225,8 @@
*/
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);
#if 0 /* keep Emacsens' auto-indent happy */
Modified: gnunet/src/include/gnunet_bio_lib.h
===================================================================
--- gnunet/src/include/gnunet_bio_lib.h 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/include/gnunet_bio_lib.h 2011-08-15 21:46:35 UTC (rev 16581)
@@ -60,8 +60,7 @@
* @param emsg set to the error message
* @return GNUNET_OK on success, GNUNET_SYSERR otherwise
*/
-int GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h,
- char **emsg);
+int GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h, char **emsg);
/**
@@ -73,10 +72,8 @@
* @param len the number of bytes to read
* @return GNUNET_OK on success, GNUNET_SYSERR on failure
*/
-int GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h,
- const char *what,
- void *result,
- size_t len);
+int GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h,
+ const char *what, void *result, size_t len);
/**
@@ -89,10 +86,8 @@
* @param len the number of bytes to read
* @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);
+int GNUNET_BIO_read_fn (struct GNUNET_BIO_ReadHandle *h,
+ const char *file, int line, void *result, size_t len);
/**
* Read 0-terminated string from a file.
@@ -105,9 +100,7 @@
* @return GNUNET_OK on success, GNUNET_SYSERR on failure
*/
int GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h,
- const char *what,
- char **result,
- size_t maxLen);
+ const char *what, char **result, size_t maxLen);
/**
@@ -118,9 +111,9 @@
* @param result the buffer to store a pointer to the (allocated) metadata
* @return GNUNET_OK on success, GNUNET_SYSERR on failure
*/
-int GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h,
- const char *what,
- struct GNUNET_CONTAINER_MetaData **result);
+int GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h,
+ const char *what,
+ struct GNUNET_CONTAINER_MetaData **result);
/**
@@ -128,7 +121,7 @@
*
* @param h hande to open file
* @param f address of float to read
- */
+ */
#define GNUNET_BIO_read_float(h, f) (GNUNET_BIO_read_fn (h, __FILE__,
__LINE__, f, sizeof(float)))
@@ -138,7 +131,7 @@
*
* @param h hande to open file
* @param f address of double to read
- */
+ */
#define GNUNET_BIO_read_double(h, f) (GNUNET_BIO_read_fn (h, __FILE__,
__LINE__, f, sizeof(double)))
@@ -150,10 +143,9 @@
* @param line line number in the code
* @param i address of 32-bit integer to read
* @return GNUNET_OK on success, GNUNET_SYSERR on error
- */
-int GNUNET_BIO_read_int32__ (struct GNUNET_BIO_ReadHandle *h,
- const char *file, int line,
- int32_t *i);
+ */
+int GNUNET_BIO_read_int32__ (struct GNUNET_BIO_ReadHandle *h,
+ const char *file, int line, int32_t * i);
/**
@@ -161,7 +153,7 @@
*
* @param h hande to open file
* @param i address of 32-bit integer to read
- */
+ */
#define GNUNET_BIO_read_int32(h, i) GNUNET_BIO_read_int32__ (h, __FILE__,
__LINE__, (int32_t*) i)
@@ -173,10 +165,9 @@
* @param line line number in the code
* @param i address of 64-bit integer to read
* @return GNUNET_OK on success, GNUNET_SYSERR on error
- */
-int GNUNET_BIO_read_int64__ (struct GNUNET_BIO_ReadHandle *h,
- const char *file, int line,
- int64_t *i);
+ */
+int GNUNET_BIO_read_int64__ (struct GNUNET_BIO_ReadHandle *h,
+ const char *file, int line, int64_t * i);
/**
@@ -184,7 +175,7 @@
*
* @param h hande to open file
* @param i address of 64-bit integer to read
- */
+ */
#define GNUNET_BIO_read_int64(h, i) GNUNET_BIO_read_int64__ (h, __FILE__,
__LINE__, (int64_t*) i)
@@ -192,6 +183,7 @@
* Handle for buffered writing.
*/
struct GNUNET_BIO_WriteHandle;
+
/**
* Open a file for writing.
*
@@ -218,9 +210,8 @@
* @param n number of bytes to write
* @return GNUNET_OK on success, GNUNET_SYSERR on error
*/
-int GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h,
- const void *buffer,
- size_t n);
+int GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h,
+ const void *buffer, size_t n);
/**
@@ -230,8 +221,7 @@
* @param s string to write (can be NULL)
* @return GNUNET_OK on success, GNUNET_SYSERR on error
*/
-int GNUNET_BIO_write_string (struct GNUNET_BIO_WriteHandle *h,
- const char *s);
+int GNUNET_BIO_write_string (struct GNUNET_BIO_WriteHandle *h, const char *s);
@@ -243,8 +233,8 @@
* @param m metadata to write
* @return GNUNET_OK on success, GNUNET_SYSERR on error
*/
-int GNUNET_BIO_write_meta_data (struct GNUNET_BIO_WriteHandle *h,
- const struct GNUNET_CONTAINER_MetaData *m);
+int GNUNET_BIO_write_meta_data (struct GNUNET_BIO_WriteHandle *h,
+ const struct GNUNET_CONTAINER_MetaData *m);
@@ -253,7 +243,7 @@
*
* @param h hande to open file
* @param f float to write (must be a variable)
- */
+ */
#define GNUNET_BIO_write_float(h, f) GNUNET_BIO_write (h, &f, sizeof(float))
@@ -263,7 +253,7 @@
*
* @param h hande to open file
* @param f double to write (must be a variable)
- */
+ */
#define GNUNET_BIO_write_double(h, f) GNUNET_BIO_write (h, &f, sizeof(double))
@@ -273,9 +263,8 @@
* @param h hande to open file
* @param i address of 32-bit integer to write
* @return GNUNET_OK on success, GNUNET_SYSERR on error
- */
-int GNUNET_BIO_write_int32 (struct GNUNET_BIO_WriteHandle *h,
- int32_t i);
+ */
+int GNUNET_BIO_write_int32 (struct GNUNET_BIO_WriteHandle *h, int32_t i);
/**
@@ -284,9 +273,8 @@
* @param h hande to open file
* @param i address of 64-bit integer to write
* @return GNUNET_OK on success, GNUNET_SYSERR on error
- */
-int GNUNET_BIO_write_int64 (struct GNUNET_BIO_WriteHandle *h,
- int64_t i);
+ */
+int GNUNET_BIO_write_int64 (struct GNUNET_BIO_WriteHandle *h, int64_t i);
#if 0 /* keep Emacsens' auto-indent happy */
Modified: gnunet/src/include/gnunet_block_lib.h
===================================================================
--- gnunet/src/include/gnunet_block_lib.h 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/include/gnunet_block_lib.h 2011-08-15 21:46:35 UTC (rev
16581)
@@ -39,113 +39,113 @@
/**
* Blocks in the datastore and the datacache must have a unique type.
*/
-enum GNUNET_BLOCK_Type
- {
+enum GNUNET_BLOCK_Type
+{
/**
* Any type of block, used as a wildcard when searching. Should
* never be attached to a specific block.
*/
- GNUNET_BLOCK_TYPE_ANY = 0,
+ GNUNET_BLOCK_TYPE_ANY = 0,
/**
* Data block (leaf) in the CHK tree.
*/
- GNUNET_BLOCK_TYPE_FS_DBLOCK = 1,
+ GNUNET_BLOCK_TYPE_FS_DBLOCK = 1,
/**
* Inner block in the CHK tree.
*/
- GNUNET_BLOCK_TYPE_FS_IBLOCK = 2,
+ GNUNET_BLOCK_TYPE_FS_IBLOCK = 2,
/**
* Type of a block representing a keyword search result. Note that
* the values for KBLOCK, SBLOCK and NBLOCK must be consecutive.
*/
- GNUNET_BLOCK_TYPE_FS_KBLOCK = 3,
+ GNUNET_BLOCK_TYPE_FS_KBLOCK = 3,
/**
* Type of a block that is used to advertise content in a namespace.
*/
- GNUNET_BLOCK_TYPE_FS_SBLOCK = 4,
+ GNUNET_BLOCK_TYPE_FS_SBLOCK = 4,
/**
* Type of a block that is used to advertise a namespace.
*/
- GNUNET_BLOCK_TYPE_FS_NBLOCK = 5,
+ GNUNET_BLOCK_TYPE_FS_NBLOCK = 5,
/**
* Type of a block representing a block to be encoded on demand from disk.
* Should never appear on the network directly.
*/
- GNUNET_BLOCK_TYPE_FS_ONDEMAND = 6,
+ GNUNET_BLOCK_TYPE_FS_ONDEMAND = 6,
/**
* Type of a block that contains a HELLO for a peer (for
* DHT find-peer operations).
*/
- GNUNET_BLOCK_TYPE_DHT_HELLO = 7,
+ GNUNET_BLOCK_TYPE_DHT_HELLO = 7,
/**
* Block for testing.
*/
- GNUNET_BLOCK_TYPE_TEST = 8,
+ GNUNET_BLOCK_TYPE_TEST = 8,
-#if HAVE_MALICIOUS
+#if HAVE_MALICIOUS
/**
* Block for simulating malicious peers.
*/
- GNUNET_BLOCK_DHT_MALICIOUS_MESSAGE_TYPE = 9,
+ GNUNET_BLOCK_DHT_MALICIOUS_MESSAGE_TYPE = 9,
#endif
/**
* Block for storing .gnunet-domains
*/
- GNUNET_BLOCK_TYPE_DNS = 10
- };
+ GNUNET_BLOCK_TYPE_DNS = 10
+};
/**
* Possible ways for how a block may relate to a query.
*/
enum GNUNET_BLOCK_EvaluationResult
- {
+{
/**
* Valid result, and there may be more.
*/
- GNUNET_BLOCK_EVALUATION_OK_MORE = 0,
+ GNUNET_BLOCK_EVALUATION_OK_MORE = 0,
/**
* Last possible valid result.
*/
- GNUNET_BLOCK_EVALUATION_OK_LAST = 1,
+ GNUNET_BLOCK_EVALUATION_OK_LAST = 1,
/**
* Valid result, but suppressed because it is a duplicate.
*/
- GNUNET_BLOCK_EVALUATION_OK_DUPLICATE = 2,
+ GNUNET_BLOCK_EVALUATION_OK_DUPLICATE = 2,
/**
* Block does not match query (invalid result)
*/
- GNUNET_BLOCK_EVALUATION_RESULT_INVALID = 3,
+ GNUNET_BLOCK_EVALUATION_RESULT_INVALID = 3,
/**
* Query is valid, no reply given.
*/
- GNUNET_BLOCK_EVALUATION_REQUEST_VALID = 4,
+ GNUNET_BLOCK_EVALUATION_REQUEST_VALID = 4,
/**
* Query format does not match block type (invalid query). For
* example, xquery not given or xquery_size not appropriate for
* type.
*/
- GNUNET_BLOCK_EVALUATION_REQUEST_INVALID = 5,
+ GNUNET_BLOCK_EVALUATION_REQUEST_INVALID = 5,
/**
* Specified block type not supported by this plugin.
*/
- GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED = 6
- };
+ GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED = 6
+};
/**
@@ -163,8 +163,7 @@
*/
void
GNUNET_BLOCK_mingle_hash (const GNUNET_HashCode * in,
- uint32_t mingle_number,
- GNUNET_HashCode * hc);
+ uint32_t mingle_number, GNUNET_HashCode * hc);
/**
@@ -173,8 +172,9 @@
* @param cfg configuration to use
* @return NULL on error
*/
-struct GNUNET_BLOCK_Context *
-GNUNET_BLOCK_context_create (const struct GNUNET_CONFIGURATION_Handle *cfg);
+struct GNUNET_BLOCK_Context *GNUNET_BLOCK_context_create (const struct
+
GNUNET_CONFIGURATION_Handle
+ *cfg);
/**
@@ -182,8 +182,7 @@
*
* @param ctx context to destroy
*/
-void
-GNUNET_BLOCK_context_destroy (struct GNUNET_BLOCK_Context *ctx);
+void GNUNET_BLOCK_context_destroy (struct GNUNET_BLOCK_Context *ctx);
/**
@@ -206,14 +205,13 @@
*/
enum GNUNET_BLOCK_EvaluationResult
GNUNET_BLOCK_evaluate (struct GNUNET_BLOCK_Context *ctx,
- enum GNUNET_BLOCK_Type type,
- const GNUNET_HashCode *query,
- struct GNUNET_CONTAINER_BloomFilter **bf,
- int32_t bf_mutator,
- const void *xquery,
- size_t xquery_size,
- const void *reply_block,
- size_t reply_block_size);
+ enum GNUNET_BLOCK_Type type,
+ const GNUNET_HashCode * query,
+ struct GNUNET_CONTAINER_BloomFilter **bf,
+ int32_t bf_mutator,
+ const void *xquery,
+ size_t xquery_size,
+ const void *reply_block, size_t reply_block_size);
/**
@@ -231,10 +229,9 @@
*/
int
GNUNET_BLOCK_get_key (struct GNUNET_BLOCK_Context *ctx,
- enum GNUNET_BLOCK_Type type,
- const void *block,
- size_t block_size,
- GNUNET_HashCode *key);
+ enum GNUNET_BLOCK_Type type,
+ const void *block,
+ size_t block_size, GNUNET_HashCode * key);
#if 0 /* keep Emacsens' auto-indent happy */
Modified: gnunet/src/include/gnunet_block_plugin.h
===================================================================
--- gnunet/src/include/gnunet_block_plugin.h 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/include/gnunet_block_plugin.h 2011-08-15 21:46:35 UTC (rev
16581)
@@ -51,15 +51,14 @@
* @return characterization of result
*/
typedef enum GNUNET_BLOCK_EvaluationResult
- (*GNUNET_BLOCK_EvaluationFunction) (void *cls,
- enum GNUNET_BLOCK_Type type,
- const GNUNET_HashCode *query,
- struct GNUNET_CONTAINER_BloomFilter **bf,
- int32_t bf_mutator,
- const void *xquery,
- size_t xquery_size,
- const void *reply_block,
- size_t reply_block_size);
+ (*GNUNET_BLOCK_EvaluationFunction) (void *cls,
+ enum GNUNET_BLOCK_Type type,
+ const GNUNET_HashCode * query,
+ struct GNUNET_CONTAINER_BloomFilter **
+ bf, int32_t bf_mutator,
+ const void *xquery, size_t xquery_size,
+ const void *reply_block,
+ size_t reply_block_size);
/**
@@ -76,14 +75,13 @@
* (or if extracting a key from a block of this type does not work)
*/
typedef int
- (*GNUNET_BLOCK_GetKeyFunction) (void *cls,
- enum GNUNET_BLOCK_Type type,
- const void *block,
- size_t block_size,
- GNUNET_HashCode *key);
-
+ (*GNUNET_BLOCK_GetKeyFunction) (void *cls,
+ enum GNUNET_BLOCK_Type type,
+ const void *block,
+ size_t block_size, GNUNET_HashCode * key);
+
/**
* Each plugin is required to return a pointer to a struct of this
* type as the return value from its entry point.
Modified: gnunet/src/include/gnunet_chat_service.h
===================================================================
--- gnunet/src/include/gnunet_chat_service.h 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/include/gnunet_chat_service.h 2011-08-15 21:46:35 UTC (rev
16581)
@@ -47,42 +47,42 @@
* Options for messaging. Compatible options can be OR'ed together.
*/
enum GNUNET_CHAT_MsgOptions
- {
+{
/**
* No special options.
*/
- GNUNET_CHAT_MSG_OPTION_NONE = 0,
-
+ GNUNET_CHAT_MSG_OPTION_NONE = 0,
+
/**
* Encrypt the message so that only the receiver can decrypt it.
*/
- GNUNET_CHAT_MSG_PRIVATE = 1,
-
+ GNUNET_CHAT_MSG_PRIVATE = 1,
+
/**
* Hide the identity of the sender.
*/
- GNUNET_CHAT_MSG_ANONYMOUS = 2,
-
+ GNUNET_CHAT_MSG_ANONYMOUS = 2,
+
/**
* Sign the content, authenticating the sender (using the provided private
* key, which may represent a pseudonym).
*/
- GNUNET_CHAT_MSG_AUTHENTICATED = 4,
-
+ GNUNET_CHAT_MSG_AUTHENTICATED = 4,
+
/**
* Require signed acknowledgment before completing delivery (and of course,
* only acknowledge if delivery is guaranteed).
*/
- GNUNET_CHAT_MSG_ACKNOWLEDGED = 8,
-
+ GNUNET_CHAT_MSG_ACKNOWLEDGED = 8,
+
/**
* Authenticate for the receiver, but ensure that receiver cannot prove
* authenticity to third parties later. (not yet implemented)
*/
- GNUNET_CHAT_MSG_OFF_THE_RECORD = 16,
-
- };
+ GNUNET_CHAT_MSG_OFF_THE_RECORD = 16,
+};
+
/**
* Handle for a (joined) chat room.
*/
@@ -110,12 +110,15 @@
* accept (but user is away), GNUNET_SYSERR to signal denied delivery
*/
typedef int (*GNUNET_CHAT_MessageCallback) (void *cls,
- struct GNUNET_CHAT_Room *room,
- const GNUNET_HashCode *sender,
- const struct
GNUNET_CONTAINER_MetaData *member_info,
- const char *message,
- struct GNUNET_TIME_Absolute
timestamp,
- enum GNUNET_CHAT_MsgOptions
options);
+ struct GNUNET_CHAT_Room * room,
+ const GNUNET_HashCode * sender,
+ const struct
+ GNUNET_CONTAINER_MetaData *
+ member_info, const char *message,
+ struct GNUNET_TIME_Absolute
+ timestamp,
+ enum GNUNET_CHAT_MsgOptions
+ options);
/**
* Callback used for notification that another room member has joined or left.
@@ -128,9 +131,14 @@
* @return GNUNET_OK
*/
typedef int (*GNUNET_CHAT_MemberListCallback) (void *cls,
- const struct
GNUNET_CONTAINER_MetaData *member_info,
- const struct
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *member_id,
- enum GNUNET_CHAT_MsgOptions
options);
+ const struct
+ GNUNET_CONTAINER_MetaData *
+ member_info,
+ const struct
+
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
+ * member_id,
+ enum GNUNET_CHAT_MsgOptions
+ options);
/**
* Callback used for message delivery confirmations.
@@ -144,10 +152,12 @@
* confirmations from anyone for this message
*/
typedef int (*GNUNET_CHAT_MessageConfirmation) (void *cls,
- struct GNUNET_CHAT_Room *room,
+ struct GNUNET_CHAT_Room * room,
uint32_t orig_seq_number,
- struct GNUNET_TIME_Absolute
timestamp,
- const GNUNET_HashCode
*receiver);
+ struct GNUNET_TIME_Absolute
+ timestamp,
+ const GNUNET_HashCode *
+ receiver);
/**
* Join a chat room.
@@ -173,21 +183,26 @@
* @param me member ID (pseudonym)
* @return NULL on error
*/
-struct GNUNET_CHAT_Room *
-GNUNET_CHAT_join_room (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *nick_name,
- struct GNUNET_CONTAINER_MetaData *member_info,
- const char *room_name,
- enum GNUNET_CHAT_MsgOptions msg_options,
- GNUNET_CHAT_JoinCallback joinCallback,
- void *join_cls,
- GNUNET_CHAT_MessageCallback messageCallback,
- void *message_cls,
- GNUNET_CHAT_MemberListCallback memberCallback,
- void *member_cls,
- GNUNET_CHAT_MessageConfirmation confirmationCallback,
- void *confirmation_cls,
- GNUNET_HashCode *me);
+struct GNUNET_CHAT_Room *GNUNET_CHAT_join_room (const struct
+ GNUNET_CONFIGURATION_Handle
+ *cfg, const char *nick_name,
+ struct
GNUNET_CONTAINER_MetaData
+ *member_info,
+ const char *room_name,
+ enum GNUNET_CHAT_MsgOptions
+ msg_options,
+ GNUNET_CHAT_JoinCallback
+ joinCallback, void *join_cls,
+ GNUNET_CHAT_MessageCallback
+ messageCallback,
+ void *message_cls,
+ GNUNET_CHAT_MemberListCallback
+ memberCallback,
+ void *member_cls,
+ GNUNET_CHAT_MessageConfirmation
+ confirmationCallback,
+ void *confirmation_cls,
+ GNUNET_HashCode * me);
/**
* Send a message.
@@ -202,15 +217,14 @@
GNUNET_CHAT_send_message (struct GNUNET_CHAT_Room *room,
const char *message,
enum GNUNET_CHAT_MsgOptions options,
- const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
*receiver,
- uint32_t *sequence_number);
+ const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
+ *receiver, uint32_t * sequence_number);
/**
* Leave a chat room.
*/
-void
-GNUNET_CHAT_leave_room (struct GNUNET_CHAT_Room *chat_room);
+void GNUNET_CHAT_leave_room (struct GNUNET_CHAT_Room *chat_room);
#if 0
Modified: gnunet/src/include/gnunet_client_lib.h
===================================================================
--- gnunet/src/include/gnunet_client_lib.h 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/include/gnunet_client_lib.h 2011-08-15 21:46:35 UTC (rev
16581)
@@ -68,7 +68,7 @@
*/
void
GNUNET_CLIENT_ignore_shutdown (struct GNUNET_CLIENT_Connection *h,
- int do_ignore);
+ int do_ignore);
@@ -88,7 +88,7 @@
* handle be completed?
*/
void GNUNET_CLIENT_disconnect (struct GNUNET_CLIENT_Connection *sock,
- int finish_pending_write);
+ int finish_pending_write);
/**
* Type of a function to call when we receive a message
@@ -111,8 +111,7 @@
* GNUNET_YES on running
* GNUNET_SYSERR on failure to transmit message
*/
-typedef void (*GNUNET_CLIENT_ShutdownTask) (void *cls,
- int reason);
+typedef void (*GNUNET_CLIENT_ShutdownTask) (void *cls, int reason);
/**
* Read from the service.
@@ -125,7 +124,7 @@
void GNUNET_CLIENT_receive (struct GNUNET_CLIENT_Connection *sock,
GNUNET_CLIENT_MessageHandler handler,
void *handler_cls,
- struct GNUNET_TIME_Relative timeout);
+ struct GNUNET_TIME_Relative timeout);
/**
@@ -155,13 +154,12 @@
* using GNUNET_CONNECTION_notify_transmit_ready_cancel)
*/
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);
+ *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);
/**
@@ -170,7 +168,8 @@
* @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);
/**
@@ -196,11 +195,11 @@
*/
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);
+ const struct GNUNET_MessageHeader
*hdr,
+ struct GNUNET_TIME_Relative timeout,
+ int auto_retry,
+ GNUNET_CLIENT_MessageHandler rn,
+ void *rn_cls);
/**
Modified: gnunet/src/include/gnunet_common.h
===================================================================
--- gnunet/src/include/gnunet_common.h 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/include/gnunet_common.h 2011-08-15 21:46:35 UTC (rev 16581)
@@ -45,7 +45,7 @@
#ifdef HAVE_STDARG_H
#include <stdarg.h>
#endif
-
+
/**
* Version of the API (for entire gnunetutil.so library).
*/
@@ -193,8 +193,7 @@
* @param n number of log calls to ignore
* @param check_reset GNUNET_YES to assert that the log skip counter is
currently zero
*/
-void
-GNUNET_log_skip (unsigned int n, int check_reset);
+void GNUNET_log_skip (unsigned int n, int check_reset);
/**
@@ -206,8 +205,7 @@
* @return GNUNET_OK on success, GNUNET_SYSERR if logfile could not be opened
*/
int
-GNUNET_log_setup (const char *comp,
- const char *loglevel, const char *logfile);
+GNUNET_log_setup (const char *comp, const char *loglevel, const char *logfile);
/**
@@ -236,7 +234,7 @@
* @param hc the hash code
* @return string
*/
-const char *GNUNET_h2s (const GNUNET_HashCode *hc);
+const char *GNUNET_h2s (const GNUNET_HashCode * hc);
/**
@@ -248,7 +246,7 @@
* @param hc the hash code
* @return string
*/
-const char *GNUNET_h2s_full (const GNUNET_HashCode *hc);
+const char *GNUNET_h2s_full (const GNUNET_HashCode * hc);
/**
@@ -273,8 +271,7 @@
* @return nicely formatted string for the address
* will be overwritten by next call to GNUNET_a2s.
*/
-const char *GNUNET_a2s (const struct sockaddr *addr,
- socklen_t addrlen);
+const char *GNUNET_a2s (const struct sockaddr *addr, socklen_t addrlen);
/**
* Convert error type to string.
@@ -515,7 +512,8 @@
* @param linenumber line where this call is being made (for debugging)
* @return allocated memory, never NULL
*/
-void *GNUNET_xmemdup_ (const void *buf, size_t size, const char *filename, int
linenumber);
+void *GNUNET_xmemdup_ (const void *buf, size_t size, const char *filename,
+ int linenumber);
/**
@@ -569,7 +567,8 @@
* @param linenumber line where this call is being made (for debugging)
* @return the duplicated string
*/
-char *GNUNET_xstrndup_ (const char *str, size_t len, const char *filename, int
linenumber);
+char *GNUNET_xstrndup_ (const char *str, size_t len, const char *filename,
+ int linenumber);
/**
* Grow an array, the new elements are zeroed out.
@@ -596,11 +595,11 @@
#if __STDC_VERSION__ < 199901L
-# if __GNUC__ >= 2
-# define __func__ __FUNCTION__
-# else
-# define __func__ "<unknown>"
-# endif
+#if __GNUC__ >= 2
+#define __func__ __FUNCTION__
+#else
+#define __func__ "<unknown>"
#endif
+#endif
#endif /*GNUNET_COMMON_H_ */
Modified: gnunet/src/include/gnunet_configuration_lib.h
===================================================================
--- gnunet/src/include/gnunet_configuration_lib.h 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/include/gnunet_configuration_lib.h 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -58,8 +58,9 @@
* @param cfg configuration to duplicate
* @return duplicate configuration
*/
-struct GNUNET_CONFIGURATION_Handle *
-GNUNET_CONFIGURATION_dup (const struct GNUNET_CONFIGURATION_Handle *cfg);
+struct GNUNET_CONFIGURATION_Handle *GNUNET_CONFIGURATION_dup (const struct
+
GNUNET_CONFIGURATION_Handle
+ *cfg);
/**
@@ -113,9 +114,10 @@
* @return GNUNET_OK on success, GNUNET_SYSERR on error
*/
int
-GNUNET_CONFIGURATION_write_diffs(const struct GNUNET_CONFIGURATION_Handle
*cfgDefault,
- const struct GNUNET_CONFIGURATION_Handle
*cfgNew,
- const char* filename);
+GNUNET_CONFIGURATION_write_diffs (const struct GNUNET_CONFIGURATION_Handle
+ *cfgDefault,
+ const struct GNUNET_CONFIGURATION_Handle
+ *cfgNew, const char *filename);
/**
* Test if there are configuration options that were
@@ -124,7 +126,8 @@
* @param cfg configuration to inspect
* @return GNUNET_NO if clean, GNUNET_YES if dirty, GNUNET_SYSERR on error
(i.e. last save failed)
*/
-int GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle
*cfg);
+int GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle
+ *cfg);
/**
@@ -135,10 +138,10 @@
* @param option name of the option
* @param value value of the option
*/
-typedef void (*GNUNET_CONFIGURATION_Iterator)(void *cls,
- const char *section,
- const char *option,
- const char *value);
+typedef void (*GNUNET_CONFIGURATION_Iterator) (void *cls,
+ const char *section,
+ const char *option,
+ const char *value);
/**
@@ -147,8 +150,8 @@
* @param cls closure
* @param section name of the section
*/
-typedef void (*GNUNET_CONFIGURATION_Section_Iterator)(void *cls,
- const char *section);
+typedef void (*GNUNET_CONFIGURATION_Section_Iterator) (void *cls,
+ const char *section);
/**
@@ -158,9 +161,9 @@
* @param iter function to call on each option
* @param iter_cls closure for iter
*/
-void GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle
*cfg,
- GNUNET_CONFIGURATION_Iterator iter,
- void *iter_cls);
+void GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle
+ *cfg, GNUNET_CONFIGURATION_Iterator iter,
+ void *iter_cls);
/**
@@ -170,9 +173,10 @@
* @param iter function to call on each section
* @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);
+void GNUNET_CONFIGURATION_iterate_sections (const struct
+ GNUNET_CONFIGURATION_Handle *cfg,
+
GNUNET_CONFIGURATION_Section_Iterator
+ iter, void *iter_cls);
/**
@@ -181,8 +185,8 @@
* @param cfg configuration to inspect
* @param section name of the section to remove
*/
-void GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle
*cfg,
- const char *section);
+void GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle
+ *cfg, const char *section);
/**
* Get a configuration value that should be a number.
@@ -193,8 +197,9 @@
* @param number where to store the numeric value of the option
* @return GNUNET_OK on success, GNUNET_SYSERR on error
*/
-int GNUNET_CONFIGURATION_get_value_number (const struct
GNUNET_CONFIGURATION_Handle
- *cfg, const char *section,
+int GNUNET_CONFIGURATION_get_value_number (const struct
+ GNUNET_CONFIGURATION_Handle *cfg,
+ const char *section,
const char *option,
unsigned long long *number);
@@ -208,10 +213,11 @@
* @param time set to the time value stored in the configuration
* @return GNUNET_OK on success, GNUNET_SYSERR on error
*/
-int GNUNET_CONFIGURATION_get_value_time (const struct
GNUNET_CONFIGURATION_Handle
- *cfg, const char *section,
- const char *option,
- struct GNUNET_TIME_Relative *time);
+int GNUNET_CONFIGURATION_get_value_time (const struct
+ GNUNET_CONFIGURATION_Handle *cfg,
+ const char *section,
+ const char *option,
+ struct GNUNET_TIME_Relative *time);
/**
@@ -222,8 +228,9 @@
* @param option option of interest
* @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);
+int GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle
+ *cfg, const char *section,
+ const char *option);
/**
@@ -236,8 +243,9 @@
* value, or NULL if option is not specified
* @return GNUNET_OK on success, GNUNET_SYSERR on error
*/
-int GNUNET_CONFIGURATION_get_value_string (const struct
GNUNET_CONFIGURATION_Handle
- *cfg, const char *section,
+int GNUNET_CONFIGURATION_get_value_string (const struct
+ GNUNET_CONFIGURATION_Handle *cfg,
+ const char *section,
const char *option, char **value);
@@ -255,8 +263,7 @@
int GNUNET_CONFIGURATION_get_value_filename (const struct
GNUNET_CONFIGURATION_Handle *cfg,
const char *section,
- const char *option,
- char **value);
+ const char *option, char **value);
/**
* Iterate over the set of filenames stored in a configuration value.
@@ -285,10 +292,11 @@
* @param iter_cls closure for iter
*/
void
-GNUNET_CONFIGURATION_iterate_section_values (const struct
GNUNET_CONFIGURATION_Handle *cfg,
- const char *section,
- GNUNET_CONFIGURATION_Iterator iter,
- void *iter_cls);
+GNUNET_CONFIGURATION_iterate_section_values (const struct
+ GNUNET_CONFIGURATION_Handle *cfg,
+ const char *section,
+ GNUNET_CONFIGURATION_Iterator
iter,
+ void *iter_cls);
/**
* Get a configuration value that should be in a set of
@@ -302,8 +310,9 @@
* or NULL if option is not specified and no default given
* @return GNUNET_OK on success, GNUNET_SYSERR on error
*/
-int GNUNET_CONFIGURATION_get_value_choice (const struct
GNUNET_CONFIGURATION_Handle
- *cfg, const char *section,
+int GNUNET_CONFIGURATION_get_value_choice (const struct
+ GNUNET_CONFIGURATION_Handle *cfg,
+ const char *section,
const char *option,
const char **choices,
const char **value);
@@ -317,8 +326,9 @@
* @param option option of interest
* @return GNUNET_YES, GNUNET_NO or if option has no valid value, GNUNET_SYSERR
*/
-int GNUNET_CONFIGURATION_get_value_yesno (const struct
GNUNET_CONFIGURATION_Handle
- *cfg, const char *section,
+int GNUNET_CONFIGURATION_get_value_yesno (const struct
+ GNUNET_CONFIGURATION_Handle *cfg,
+ const char *section,
const char *option);
/**
@@ -330,8 +340,9 @@
* @param orig string to $-expand (will be freed!)
* @return $-expanded string
*/
-char *GNUNET_CONFIGURATION_expand_dollar (const struct
GNUNET_CONFIGURATION_Handle
- *cfg, char *orig);
+char *GNUNET_CONFIGURATION_expand_dollar (const struct
+ GNUNET_CONFIGURATION_Handle *cfg,
+ char *orig);
/**
Modified: gnunet/src/include/gnunet_connection_lib.h
===================================================================
--- gnunet/src/include/gnunet_connection_lib.h 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/include/gnunet_connection_lib.h 2011-08-15 21:46:35 UTC (rev
16581)
@@ -80,9 +80,11 @@
* for unknown address family (will be denied).
*/
typedef int (*GNUNET_CONNECTION_AccessCheck) (void *cls,
- const struct
GNUNET_CONNECTION_Credentials *ucred,
- const struct sockaddr * addr,
- socklen_t addrlen);
+ const struct
+ GNUNET_CONNECTION_Credentials *
+ ucred,
+ const struct sockaddr * addr,
+ socklen_t addrlen);
/**
@@ -98,10 +100,10 @@
* @param errCode value of errno (on errors receiving)
*/
typedef void (*GNUNET_CONNECTION_Receiver) (void *cls,
- const void *buf,
- size_t available,
- const struct sockaddr * addr,
- socklen_t addrlen, int errCode);
+ const void *buf,
+ size_t available,
+ const struct sockaddr * addr,
+ socklen_t addrlen, int errCode);
/**
* Set the persist option on this connection handle. Indicates
@@ -110,8 +112,7 @@
*
* @param sock the connection to set persistent
*/
-void
-GNUNET_CONNECTION_persist_(struct GNUNET_CONNECTION_Handle *sock);
+void GNUNET_CONNECTION_persist_ (struct GNUNET_CONNECTION_Handle *sock);
/**
* Disable the "CORK" feature for communication with the given socket,
@@ -124,8 +125,7 @@
* @param sock the connection to make flushing and blocking
* @return GNUNET_OK on success
*/
-int
-GNUNET_CONNECTION_disable_corking (struct GNUNET_CONNECTION_Handle *sock);
+int GNUNET_CONNECTION_disable_corking (struct GNUNET_CONNECTION_Handle *sock);
/**
@@ -137,9 +137,8 @@
* @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);
/**
@@ -152,11 +151,9 @@
* @return the socket handle, NULL on error (for example, access refused)
*/
struct GNUNET_CONNECTION_Handle
- *GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck
- access, void *access_cls,
- struct
- GNUNET_NETWORK_Handle
- *lsock);
+ *GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck
+ access, void *access_cls,
+ struct GNUNET_NETWORK_Handle
*lsock);
/**
@@ -170,9 +167,10 @@
* @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);
/**
@@ -184,10 +182,11 @@
* @param unixpath path to connect to)
* @return the socket handle, NULL on systems without UNIX support
*/
-struct GNUNET_CONNECTION_Handle *
-GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct
- GNUNET_CONFIGURATION_Handle
*cfg,
- const char *unixpath);
+struct GNUNET_CONNECTION_Handle
+ *GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct
+
GNUNET_CONFIGURATION_Handle
+ *cfg,
+ const char *unixpath);
@@ -203,10 +202,9 @@
* @return the socket handle
*/
struct GNUNET_CONNECTION_Handle
- *GNUNET_CONNECTION_create_from_sockaddr (int af_family,
- const struct sockaddr
- *serv_addr,
- socklen_t addrlen);
+ *GNUNET_CONNECTION_create_from_sockaddr (int af_family,
+ const struct sockaddr
+ *serv_addr, socklen_t addrlen);
/**
* Check if socket is valid (no fatal errors have happened so far).
@@ -216,8 +214,7 @@
* @param sock socket to check
* @return GNUNET_YES if valid, GNUNET_NO otherwise
*/
-int GNUNET_CONNECTION_check (struct GNUNET_CONNECTION_Handle
- *sock);
+int GNUNET_CONNECTION_check (struct GNUNET_CONNECTION_Handle *sock);
/**
@@ -229,9 +226,8 @@
* @return GNUNET_OK on success
*/
int GNUNET_CONNECTION_get_address (struct
- GNUNET_CONNECTION_Handle
- *sock, void **addr,
- size_t * addrlen);
+ GNUNET_CONNECTION_Handle
+ *sock, void **addr, size_t * addrlen);
/**
@@ -249,7 +245,7 @@
*/
void
GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *sock,
- int finish_pending_write);
+ int finish_pending_write);
/**
@@ -267,10 +263,10 @@
*/
void
GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle
- *sock, size_t max,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_CONNECTION_Receiver receiver,
- void *receiver_cls);
+ *sock, size_t max,
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_CONNECTION_Receiver receiver,
+ void *receiver_cls);
/**
@@ -281,9 +277,7 @@
* @param sock socket handle
* @return closure of the original receiver callback closure
*/
-void *GNUNET_CONNECTION_receive_cancel (struct
- GNUNET_CONNECTION_Handle
- *sock);
+void *GNUNET_CONNECTION_receive_cancel (struct GNUNET_CONNECTION_Handle *sock);
/**
@@ -298,7 +292,8 @@
* @return number of bytes written to buf
*/
typedef size_t (*GNUNET_CONNECTION_TransmitReadyNotify) (void *cls,
- size_t size, void
*buf);
+ size_t size,
+ void *buf);
/**
@@ -337,14 +332,14 @@
* 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);
/**
@@ -355,8 +350,8 @@
*/
void
GNUNET_CONNECTION_notify_transmit_ready_cancel (struct
-
GNUNET_CONNECTION_TransmitHandle
- *h);
+
GNUNET_CONNECTION_TransmitHandle
+ *h);
/**
@@ -367,7 +362,7 @@
*/
void
GNUNET_CONNECTION_ignore_shutdown (struct GNUNET_CONNECTION_Handle *sock,
- int do_ignore);
+ int do_ignore);
#if 0 /* keep Emacsens' auto-indent happy */
Modified: gnunet/src/include/gnunet_container_lib.h
===================================================================
--- gnunet/src/include/gnunet_container_lib.h 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/include/gnunet_container_lib.h 2011-08-15 21:46:35 UTC (rev
16581)
@@ -62,8 +62,7 @@
* @return GNUNET_YES if next was updated
* GNUNET_NO if there are no more entries
*/
-typedef int (*GNUNET_HashCodeIterator) (void *cls,
- GNUNET_HashCode * next);
+typedef int (*GNUNET_HashCodeIterator) (void *cls, GNUNET_HashCode * next);
/**
@@ -76,15 +75,13 @@
* element (number of bits set per element in the set)
* @return the bloomfilter
*/
-struct GNUNET_CONTAINER_BloomFilter *
-GNUNET_CONTAINER_bloomfilter_load (const
- char
- *filename,
- size_t
- size,
- unsigned
- int
- k);
+struct GNUNET_CONTAINER_BloomFilter *GNUNET_CONTAINER_bloomfilter_load (const
+ char
+
*filename,
+ size_t
+ size,
+
unsigned
+ int k);
/**
@@ -100,15 +97,13 @@
* element (number of bits set per element in the set)
* @return the bloomfilter
*/
-struct GNUNET_CONTAINER_BloomFilter *
-GNUNET_CONTAINER_bloomfilter_init (const
- char
- *data,
- size_t
- size,
- unsigned
- int
- k);
+struct GNUNET_CONTAINER_BloomFilter *GNUNET_CONTAINER_bloomfilter_init (const
+ char
+ *data,
+ size_t
+ size,
+
unsigned
+ int k);
/**
@@ -121,8 +116,7 @@
*/
int GNUNET_CONTAINER_bloomfilter_get_raw_data (const struct
GNUNET_CONTAINER_BloomFilter
- *bf, char *data,
- size_t size);
+ *bf, char *data, size_t size);
/**
@@ -159,8 +153,10 @@
* @param bf the filter
* @return copy of bf
*/
-struct GNUNET_CONTAINER_BloomFilter *
-GNUNET_CONTAINER_bloomfilter_copy (const struct GNUNET_CONTAINER_BloomFilter
*bf);
+struct GNUNET_CONTAINER_BloomFilter *GNUNET_CONTAINER_bloomfilter_copy (const
+ struct
+
GNUNET_CONTAINER_BloomFilter
+ *bf);
@@ -180,9 +176,20 @@
* @param bf the filter
* @return number of bytes used for the data of the bloom filter
*/
-size_t
+size_t
+
+
+
+
+
+
+
+
+
+
+
GNUNET_CONTAINER_bloomfilter_get_size (const struct
GNUNET_CONTAINER_BloomFilter
- *bf);
+ *bf);
/**
@@ -218,8 +225,8 @@
*/
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);
/**
* Resize a bloom filter. Note that this operation
@@ -250,8 +257,7 @@
*
* @return empty meta-data container
*/
-struct GNUNET_CONTAINER_MetaData *
-GNUNET_CONTAINER_meta_data_create (void);
+struct GNUNET_CONTAINER_MetaData *GNUNET_CONTAINER_meta_data_create (void);
/**
* Duplicate a MetaData token.
@@ -259,17 +265,17 @@
* @param md what to duplicate
* @return duplicate meta-data container
*/
-struct GNUNET_CONTAINER_MetaData *
-GNUNET_CONTAINER_meta_data_duplicate (const struct
- GNUNET_CONTAINER_MetaData *md);
+struct GNUNET_CONTAINER_MetaData *GNUNET_CONTAINER_meta_data_duplicate (const
+ struct
+
GNUNET_CONTAINER_MetaData
+ *md);
/**
* Free meta data.
*
* @param md what to free
*/
-void
-GNUNET_CONTAINER_meta_data_destroy (struct GNUNET_CONTAINER_MetaData *md);
+void GNUNET_CONTAINER_meta_data_destroy (struct GNUNET_CONTAINER_MetaData *md);
/**
* Test if two MDs are equal. We consider them equal if
@@ -281,11 +287,11 @@
* @param md2 other value to check
* @return GNUNET_YES if they are equal
*/
-int
+int
GNUNET_CONTAINER_meta_data_test_equal (const struct
- GNUNET_CONTAINER_MetaData *md1,
- const struct
- GNUNET_CONTAINER_MetaData *md2);
+ GNUNET_CONTAINER_MetaData *md1,
+ const struct
+ GNUNET_CONTAINER_MetaData *md2);
/**
@@ -305,14 +311,13 @@
* @return GNUNET_OK on success, GNUNET_SYSERR if this entry already exists
* data_mime_type and plugin_name are not considered for "exists"
checks
*/
-int
+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);
/**
@@ -322,9 +327,9 @@
* @param md metadata to extend
* @param in metadata to merge
*/
-void
+void
GNUNET_CONTAINER_meta_data_merge (struct GNUNET_CONTAINER_MetaData *md,
- const struct GNUNET_CONTAINER_MetaData *in);
+ const struct GNUNET_CONTAINER_MetaData *in);
/**
@@ -337,11 +342,10 @@
* @param data_len number of bytes in data
* @return GNUNET_OK on success, GNUNET_SYSERR if the item does not exist in md
*/
-int
+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);
/**
@@ -349,8 +353,7 @@
*
* @param md metadata to manipulate
*/
-void
-GNUNET_CONTAINER_meta_data_clear (struct GNUNET_CONTAINER_MetaData *md);
+void GNUNET_CONTAINER_meta_data_clear (struct GNUNET_CONTAINER_MetaData *md);
/**
@@ -359,10 +362,9 @@
*
* @param md metadata to modify
*/
-void
+void
GNUNET_CONTAINER_meta_data_add_publication_date (struct
- GNUNET_CONTAINER_MetaData
- *md);
+ GNUNET_CONTAINER_MetaData
*md);
/**
@@ -374,9 +376,9 @@
* @return number of entries
*/
int GNUNET_CONTAINER_meta_data_iterate (const struct
- GNUNET_CONTAINER_MetaData *md,
- EXTRACTOR_MetaDataProcessor
- iter, void *iter_cls);
+ GNUNET_CONTAINER_MetaData *md,
+ EXTRACTOR_MetaDataProcessor
+ iter, void *iter_cls);
/**
* Get the first MD entry of the given type. Caller
@@ -388,10 +390,9 @@
* @param type type to look for
* @return NULL if no entry was found
*/
-char *
-GNUNET_CONTAINER_meta_data_get_by_type (const struct
- GNUNET_CONTAINER_MetaData *md,
- enum EXTRACTOR_MetaType type);
+char *GNUNET_CONTAINER_meta_data_get_by_type (const struct
+ GNUNET_CONTAINER_MetaData *md,
+ enum EXTRACTOR_MetaType type);
/**
@@ -405,10 +406,9 @@
* @return NULL if we do not have any such entry,
* otherwise client is responsible for freeing the value!
*/
-char *
-GNUNET_CONTAINER_meta_data_get_first_by_types (const struct
- GNUNET_CONTAINER_MetaData
- *md, ...);
+char *GNUNET_CONTAINER_meta_data_get_first_by_types (const struct
+ GNUNET_CONTAINER_MetaData
+ *md, ...);
/**
* Get a thumbnail from the meta-data (if present). Only matches meta
@@ -419,10 +419,10 @@
* freed by the caller!
* @return number of bytes in thumbnail, 0 if not available
*/
-size_t
+size_t
GNUNET_CONTAINER_meta_data_get_thumbnail (const struct
- GNUNET_CONTAINER_MetaData
- *md, unsigned char **thumb);
+ GNUNET_CONTAINER_MetaData
+ *md, unsigned char **thumb);
@@ -463,14 +463,33 @@
* -1 on error (typically: not enough
* space)
*/
-ssize_t
+ssize_t
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
GNUNET_CONTAINER_meta_data_serialize (const struct
- GNUNET_CONTAINER_MetaData *md,
- char **target,
- size_t max,
- enum
-
GNUNET_CONTAINER_MetaDataSerializationOptions
- opt);
+ GNUNET_CONTAINER_MetaData *md,
+ char **target,
+ size_t max,
+ enum
+
GNUNET_CONTAINER_MetaDataSerializationOptions
+ opt);
/**
@@ -479,10 +498,28 @@
* @param md metadata to inspect
* @return number of bytes needed for serialization, -1 on error
*/
-ssize_t
+ssize_t
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
GNUNET_CONTAINER_meta_data_get_serialized_size (const struct
- GNUNET_CONTAINER_MetaData
- *md);
+ GNUNET_CONTAINER_MetaData *md);
/**
@@ -493,9 +530,11 @@
* @return MD on success, NULL on error (i.e.
* bad format)
*/
-struct GNUNET_CONTAINER_MetaData *
-GNUNET_CONTAINER_meta_data_deserialize (const char *input,
- size_t size);
+struct GNUNET_CONTAINER_MetaData *GNUNET_CONTAINER_meta_data_deserialize (const
+ char
+
*input,
+
size_t
+
size);
/* ******************************* HashMap **************************** */
@@ -561,7 +600,7 @@
* @return NULL on error
*/
struct GNUNET_CONTAINER_MultiHashMap
- *GNUNET_CONTAINER_multihashmap_create (unsigned int len);
+ *GNUNET_CONTAINER_multihashmap_create (unsigned int len);
/**
@@ -571,8 +610,7 @@
* @param map the map
*/
void GNUNET_CONTAINER_multihashmap_destroy (struct
- GNUNET_CONTAINER_MultiHashMap
- *map);
+ GNUNET_CONTAINER_MultiHashMap
*map);
/**
@@ -630,8 +668,7 @@
*/
int GNUNET_CONTAINER_multihashmap_contains (const struct
GNUNET_CONTAINER_MultiHashMap
- *map,
- const GNUNET_HashCode * key);
+ *map, const GNUNET_HashCode * key);
/**
@@ -645,10 +682,10 @@
* GNUNET_NO if not
*/
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);
/**
@@ -667,8 +704,7 @@
*map, const GNUNET_HashCode * key,
void *value,
enum
- GNUNET_CONTAINER_MultiHashMapOption
- opt);
+ GNUNET_CONTAINER_MultiHashMapOption
opt);
/**
* Get the number of key-value pairs in the map.
@@ -886,8 +922,9 @@
* @param order how should the heap be sorted?
* @return handle to the heap
*/
-struct GNUNET_CONTAINER_Heap *
-GNUNET_CONTAINER_heap_create (enum GNUNET_CONTAINER_HeapOrder order);
+struct GNUNET_CONTAINER_Heap *GNUNET_CONTAINER_heap_create (enum
+
GNUNET_CONTAINER_HeapOrder
+ order);
/**
@@ -905,8 +942,7 @@
* @param heap heap to inspect
* @return NULL if heap is empty
*/
-void *
-GNUNET_CONTAINER_heap_peek (const struct GNUNET_CONTAINER_Heap *heap);
+void *GNUNET_CONTAINER_heap_peek (const struct GNUNET_CONTAINER_Heap *heap);
/**
@@ -926,7 +962,8 @@
* @return cost of the node
*/
GNUNET_CONTAINER_HeapCostType
-GNUNET_CONTAINER_heap_node_get_cost (const struct GNUNET_CONTAINER_HeapNode
*node);
+GNUNET_CONTAINER_heap_node_get_cost (const struct GNUNET_CONTAINER_HeapNode
+ *node);
/**
* Iterator for heap
@@ -939,9 +976,10 @@
* GNUNET_NO if not.
*/
typedef int (*GNUNET_CONTAINER_HeapIterator) (void *cls,
- struct GNUNET_CONTAINER_HeapNode
*node,
- void *element,
- GNUNET_CONTAINER_HeapCostType
cost);
+ struct GNUNET_CONTAINER_HeapNode
*
+ node, void *element,
+ GNUNET_CONTAINER_HeapCostType
+ cost);
/**
@@ -953,8 +991,8 @@
*/
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);
/**
@@ -969,9 +1007,8 @@
* NULL if the heap is empty.
*
*/
-void *
-GNUNET_CONTAINER_heap_get_random (struct GNUNET_CONTAINER_Heap *heap,
- uint32_t max);
+void *GNUNET_CONTAINER_heap_get_random (struct GNUNET_CONTAINER_Heap *heap,
+ uint32_t max);
/**
@@ -985,8 +1022,7 @@
* @return data stored at the next random node in the walk;
* NULL if the tree is empty.
*/
-void *
-GNUNET_CONTAINER_heap_walk_get_next (struct GNUNET_CONTAINER_Heap *heap);
+void *GNUNET_CONTAINER_heap_walk_get_next (struct GNUNET_CONTAINER_Heap *heap);
/**
@@ -997,10 +1033,12 @@
* @param cost cost for the element
* @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);
+struct GNUNET_CONTAINER_HeapNode *GNUNET_CONTAINER_heap_insert (struct
+
GNUNET_CONTAINER_Heap
+ *heap,
+ void *element,
+
GNUNET_CONTAINER_HeapCostType
+ cost);
/**
@@ -1009,8 +1047,7 @@
* @param heap heap to modify
* @return element data stored at the root node
*/
-void *
-GNUNET_CONTAINER_heap_remove_root (struct GNUNET_CONTAINER_Heap *heap);
+void *GNUNET_CONTAINER_heap_remove_root (struct GNUNET_CONTAINER_Heap *heap);
/**
@@ -1019,8 +1056,8 @@
* @param node node to remove
* @return element data stored at the node, NULL if heap is empty
*/
-void *
-GNUNET_CONTAINER_heap_remove_node (struct GNUNET_CONTAINER_HeapNode *node);
+void *GNUNET_CONTAINER_heap_remove_node (struct GNUNET_CONTAINER_HeapNode
+ *node);
/**
@@ -1032,8 +1069,8 @@
*/
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);
/* ******************** Singly linked list *************** */
@@ -1041,24 +1078,24 @@
/**
* Possible ways for how data stored in the linked list
* might be allocated.
- */
+ */
enum GNUNET_CONTAINER_SListDisposition
- {
+{
/**
* Single-linked list must copy the buffer.
*/
- GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT = 0,
+ GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT = 0,
/**
* Data is static, no need to copy or free.
*/
- GNUNET_CONTAINER_SLIST_DISPOSITION_STATIC = 2,
+ GNUNET_CONTAINER_SLIST_DISPOSITION_STATIC = 2,
/**
* Data is dynamic, do not copy but free when done.
*/
- GNUNET_CONTAINER_SLIST_DISPOSITION_DYNAMIC = 4
- };
+ GNUNET_CONTAINER_SLIST_DISPOSITION_DYNAMIC = 4
+};
@@ -1080,9 +1117,9 @@
* @param buf payload buffer
* @param len length of the buffer
*/
-void GNUNET_CONTAINER_slist_add (struct GNUNET_CONTAINER_SList *l,
- enum GNUNET_CONTAINER_SListDisposition disp,
- const void *buf, size_t len);
+void GNUNET_CONTAINER_slist_add (struct GNUNET_CONTAINER_SList *l,
+ enum GNUNET_CONTAINER_SListDisposition disp,
+ const void *buf, size_t len);
/**
@@ -1093,8 +1130,8 @@
* @param len length of the buffer
*/
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);
/**
@@ -1103,7 +1140,8 @@
* @param src source
*/
void
-GNUNET_CONTAINER_slist_append (struct GNUNET_CONTAINER_SList *dst, struct
GNUNET_CONTAINER_SList *src);
+GNUNET_CONTAINER_slist_append (struct GNUNET_CONTAINER_SList *dst,
+ struct GNUNET_CONTAINER_SList *src);
/**
@@ -1126,8 +1164,9 @@
* @param l list
* @return iterator pointing to the beginning, free using "GNUNET_free"
*/
-struct GNUNET_CONTAINER_SList_Iterator *
-GNUNET_CONTAINER_slist_begin(struct GNUNET_CONTAINER_SList *l);
+struct GNUNET_CONTAINER_SList_Iterator *GNUNET_CONTAINER_slist_begin (struct
+
GNUNET_CONTAINER_SList
+ *l);
/**
@@ -1144,7 +1183,8 @@
* @param buf payload buffer to find
* @param len length of the payload (number of bytes in buf)
*/
-int GNUNET_CONTAINER_slist_contains (const struct GNUNET_CONTAINER_SList *l,
const void *buf, size_t len);
+int GNUNET_CONTAINER_slist_contains (const struct GNUNET_CONTAINER_SList *l,
+ const void *buf, size_t len);
/**
@@ -1169,10 +1209,10 @@
* @param buf payload buffer
* @param len length of the payload
*/
-void GNUNET_CONTAINER_slist_insert (struct GNUNET_CONTAINER_SList_Iterator
*before,
- enum GNUNET_CONTAINER_SListDisposition disp,
- const void *buf,
- size_t len);
+void GNUNET_CONTAINER_slist_insert (struct GNUNET_CONTAINER_SList_Iterator
+ *before,
+ enum GNUNET_CONTAINER_SListDisposition
disp,
+ const void *buf, size_t len);
/**
@@ -1199,16 +1239,16 @@
* @param len set to the payload length
* @return payload
*/
-void *
-GNUNET_CONTAINER_slist_get (const struct GNUNET_CONTAINER_SList_Iterator *i,
- size_t *len);
+void *GNUNET_CONTAINER_slist_get (const struct GNUNET_CONTAINER_SList_Iterator
+ *i, size_t * len);
/**
* Release an iterator
* @param i iterator
*/
-void GNUNET_CONTAINER_slist_iter_destroy (struct
GNUNET_CONTAINER_SList_Iterator *i);
+void GNUNET_CONTAINER_slist_iter_destroy (struct
GNUNET_CONTAINER_SList_Iterator
+ *i);
#if 0 /* keep Emacsens' auto-indent happy */
Modified: gnunet/src/include/gnunet_core_service.h
===================================================================
--- gnunet/src/include/gnunet_core_service.h 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/include/gnunet_core_service.h 2011-08-15 21:46:35 UTC (rev
16581)
@@ -59,9 +59,11 @@
* @param atsi performance data for the connection
*/
typedef void (*GNUNET_CORE_ConnectEventHandler) (void *cls,
- const struct
- GNUNET_PeerIdentity *peer,
- const struct
GNUNET_TRANSPORT_ATS_Information *atsi);
+ const struct
+ GNUNET_PeerIdentity * peer,
+ const struct
+
GNUNET_TRANSPORT_ATS_Information
+ * atsi);
/**
@@ -76,12 +78,19 @@
* @param atsi performance data for the connection
*/
typedef void (*GNUNET_CORE_PeerStatusEventHandler) (void *cls,
- const struct
- GNUNET_PeerIdentity *peer,
- struct
GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
- struct
GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
- struct GNUNET_TIME_Absolute
timeout,
- const struct
GNUNET_TRANSPORT_ATS_Information *atsi);
+ const struct
+ GNUNET_PeerIdentity * peer,
+ struct
+ GNUNET_BANDWIDTH_Value32NBO
+ bandwidth_in,
+ struct
+ GNUNET_BANDWIDTH_Value32NBO
+ bandwidth_out,
+ struct GNUNET_TIME_Absolute
+ timeout,
+ const struct
+
GNUNET_TRANSPORT_ATS_Information
+ * atsi);
/**
@@ -91,8 +100,8 @@
* @param peer peer identity this notification is about
*/
typedef void (*GNUNET_CORE_DisconnectEventHandler) (void *cls,
- const struct
- GNUNET_PeerIdentity *peer);
+ const struct
+ GNUNET_PeerIdentity *
peer);
/**
@@ -108,10 +117,11 @@
* GNUNET_SYSERR to close it (signal serious error)
*/
typedef int
- (*GNUNET_CORE_MessageCallback) (void *cls,
- const struct GNUNET_PeerIdentity *other,
- const struct GNUNET_MessageHeader *message,
- const struct
GNUNET_TRANSPORT_ATS_Information *atsi);
+ (*GNUNET_CORE_MessageCallback) (void *cls,
+ const struct GNUNET_PeerIdentity * other,
+ const struct GNUNET_MessageHeader *
message,
+ const struct
+ GNUNET_TRANSPORT_ATS_Information * atsi);
/**
@@ -153,13 +163,13 @@
* @param publicKey public key of this peer, NULL if we failed
*/
typedef void
- (*GNUNET_CORE_StartupCallback) (void *cls,
- struct GNUNET_CORE_Handle * server,
- const struct GNUNET_PeerIdentity *
- my_identity,
- const struct
- GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *
- publicKey);
+ (*GNUNET_CORE_StartupCallback) (void *cls,
+ struct GNUNET_CORE_Handle * server,
+ const struct GNUNET_PeerIdentity *
+ my_identity,
+ const struct
+ GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *
+ publicKey);
/**
@@ -208,19 +218,27 @@
* @return handle to the core service (only useful for disconnect until 'init'
is called),
* NULL on error (in this case, init is never called)
*/
-struct GNUNET_CORE_Handle *
-GNUNET_CORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
- unsigned int queue_size,
- void *cls,
- GNUNET_CORE_StartupCallback init,
- GNUNET_CORE_ConnectEventHandler connects,
- GNUNET_CORE_DisconnectEventHandler disconnects,
- GNUNET_CORE_PeerStatusEventHandler status_events,
- GNUNET_CORE_MessageCallback inbound_notify,
- int inbound_hdr_only,
- GNUNET_CORE_MessageCallback outbound_notify,
- int outbound_hdr_only,
- const struct GNUNET_CORE_MessageHandler *handlers);
+struct GNUNET_CORE_Handle *GNUNET_CORE_connect (const struct
+ GNUNET_CONFIGURATION_Handle
+ *cfg, unsigned int queue_size,
+ void *cls,
+ GNUNET_CORE_StartupCallback
+ init,
+ GNUNET_CORE_ConnectEventHandler
+ connects,
+
GNUNET_CORE_DisconnectEventHandler
+ disconnects,
+
GNUNET_CORE_PeerStatusEventHandler
+ status_events,
+ GNUNET_CORE_MessageCallback
+ inbound_notify,
+ int inbound_hdr_only,
+ GNUNET_CORE_MessageCallback
+ outbound_notify,
+ int outbound_hdr_only,
+ const struct
+ GNUNET_CORE_MessageHandler
+ *handlers);
/**
@@ -251,7 +269,7 @@
* GNUNET_NO on timeout,
* GNUNET_SYSERR if core was shut down
*/
-typedef void (*GNUNET_CORE_ControlContinuation)(void *cls, int success);
+typedef void (*GNUNET_CORE_ControlContinuation) (void *cls, int success);
/**
@@ -271,11 +289,17 @@
* @param cont_cls closure for cont
* @return NULL on error (cont will not be called), otherwise handle for
cancellation
*/
-struct GNUNET_CORE_PeerRequestHandle *
-GNUNET_CORE_peer_request_connect (struct GNUNET_CORE_Handle *h,
- const struct GNUNET_PeerIdentity * peer,
- GNUNET_CORE_ControlContinuation cont,
- void *cont_cls);
+struct GNUNET_CORE_PeerRequestHandle *GNUNET_CORE_peer_request_connect (struct
+
GNUNET_CORE_Handle
+ *h,
+ const
+ struct
+
GNUNET_PeerIdentity
+ *peer,
+
GNUNET_CORE_ControlContinuation
+ cont,
+ void
+
*cont_cls);
/**
@@ -285,7 +309,8 @@
* @param req request handle that was returned for the original request
*/
void
-GNUNET_CORE_peer_request_connect_cancel (struct GNUNET_CORE_PeerRequestHandle
*req);
+GNUNET_CORE_peer_request_connect_cancel (struct GNUNET_CORE_PeerRequestHandle
+ *req);
/**
@@ -301,13 +326,15 @@
* @param preference current traffic preference for the given peer
*/
typedef void
- (*GNUNET_CORE_PeerConfigurationInfoCallback) (void *cls,
- const struct
- GNUNET_PeerIdentity *peer,
- struct
GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
- int32_t amount,
- struct GNUNET_TIME_Relative
res_delay,
- uint64_t preference);
+ (*GNUNET_CORE_PeerConfigurationInfoCallback) (void *cls,
+ const struct
+ GNUNET_PeerIdentity * peer,
+ struct
+ GNUNET_BANDWIDTH_Value32NBO
+ bandwidth_out, int32_t
amount,
+ struct GNUNET_TIME_Relative
+ res_delay,
+ uint64_t preference);
@@ -342,15 +369,15 @@
* @param info_cls closure for info
* @return NULL on error
*/
-struct GNUNET_CORE_InformationRequestContext *
-GNUNET_CORE_peer_change_preference (struct GNUNET_CORE_Handle *h,
- const struct GNUNET_PeerIdentity *peer,
- struct GNUNET_TIME_Relative timeout,
- struct GNUNET_BANDWIDTH_Value32NBO bw_out,
- int32_t amount,
- uint64_t preference,
- GNUNET_CORE_PeerConfigurationInfoCallback
info,
- void *info_cls);
+struct GNUNET_CORE_InformationRequestContext
+ *GNUNET_CORE_peer_change_preference (struct GNUNET_CORE_Handle *h,
+ const struct GNUNET_PeerIdentity
*peer,
+ struct GNUNET_TIME_Relative timeout,
+ struct GNUNET_BANDWIDTH_Value32NBO
+ bw_out, int32_t amount,
+ uint64_t preference,
+
GNUNET_CORE_PeerConfigurationInfoCallback
+ info, void *info_cls);
/**
@@ -365,7 +392,9 @@
* @param irc context returned by the original GNUNET_CORE_peer_get_info call
*/
void
-GNUNET_CORE_peer_change_preference_cancel (struct
GNUNET_CORE_InformationRequestContext *irc);
+GNUNET_CORE_peer_change_preference_cancel (struct
+
GNUNET_CORE_InformationRequestContext
+ *irc);
/**
@@ -435,25 +464,25 @@
* NULL if we can not even queue the request (insufficient
* memory); if NULL is returned, "notify" will NOT be called.
*/
-struct GNUNET_CORE_TransmitHandle *
-GNUNET_CORE_notify_transmit_ready (struct
- GNUNET_CORE_Handle
- *handle,
- int cork,
- uint32_t priority,
- struct
- GNUNET_TIME_Relative
- maxdelay,
- const
- struct
- GNUNET_PeerIdentity
- *target,
- size_t
- notify_size,
- GNUNET_CONNECTION_TransmitReadyNotify
- notify,
- void
- *notify_cls);
+struct GNUNET_CORE_TransmitHandle *GNUNET_CORE_notify_transmit_ready (struct
+
GNUNET_CORE_Handle
+ *handle,
+ int cork,
+ uint32_t
+ priority,
+ struct
+
GNUNET_TIME_Relative
+ maxdelay,
+ const
+ struct
+
GNUNET_PeerIdentity
+ *target,
+ size_t
+
notify_size,
+
GNUNET_CONNECTION_TransmitReadyNotify
+ notify,
+ void
+
*notify_cls);
/**
Modified: gnunet/src/include/gnunet_crypto_lib.h
===================================================================
--- gnunet/src/include/gnunet_crypto_lib.h 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/include/gnunet_crypto_lib.h 2011-08-15 21:46:35 UTC (rev
16581)
@@ -231,8 +231,7 @@
* @param len the length of the buffer in bytes
* @return the resulting CRC32 checksum
*/
-int32_t GNUNET_CRYPTO_crc32_n (const void *buf,
- size_t len);
+int32_t GNUNET_CRYPTO_crc32_n (const void *buf, size_t len);
/**
@@ -242,8 +241,7 @@
* @param i the upper limit (exclusive) for the random number
* @return a random value in the interval [0,i) (exclusive).
*/
-uint32_t GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode,
- uint32_t i);
+uint32_t GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode, uint32_t
i);
/**
@@ -254,7 +252,7 @@
* @return random 64-bit number
*/
uint64_t GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode,
- uint64_t max);
+ uint64_t max);
/**
@@ -298,12 +296,12 @@
* @return the size of the encrypted block, -1 for errors
*/
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);
+ size_t len,
+ const struct GNUNET_CRYPTO_AesSessionKey
+ *sessionkey,
+ const struct
+ GNUNET_CRYPTO_AesInitializationVector *iv,
+ void *result);
/**
@@ -316,11 +314,13 @@
* @param result address to store the result at
* @return -1 on failure, size of decrypted block on success
*/
-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);
+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);
/**
@@ -333,9 +333,8 @@
*/
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, ...);
/**
@@ -348,9 +347,8 @@
*/
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);
+ const struct GNUNET_CRYPTO_AesSessionKey *skey,
+ const void *salt, size_t salt_len, va_list
argp);
/**
@@ -360,8 +358,7 @@
* safely cast to char*, a '\\0' termination is set).
*/
void GNUNET_CRYPTO_hash_to_enc (const GNUNET_HashCode * block,
- struct GNUNET_CRYPTO_HashAsciiEncoded
- *result);
+ struct GNUNET_CRYPTO_HashAsciiEncoded *result);
/**
@@ -370,8 +367,7 @@
* @param result where to store the GNUNET_CRYPTO_hash code
* @return GNUNET_OK on success, GNUNET_SYSERR if result has the wrong encoding
*/
-int GNUNET_CRYPTO_hash_from_string (const char *enc,
- GNUNET_HashCode * result);
+int GNUNET_CRYPTO_hash_from_string (const char *enc, GNUNET_HashCode * result);
/**
@@ -386,7 +382,7 @@
* @return number between 0 and UINT32_MAX
*/
uint32_t GNUNET_CRYPTO_hash_distance_u32 (const GNUNET_HashCode * a,
- const GNUNET_HashCode * b);
+ const GNUNET_HashCode * b);
/**
@@ -396,9 +392,7 @@
* @param size size of the block
* @param ret pointer to where to write the hashcode
*/
-void GNUNET_CRYPTO_hash (const void *block,
- size_t size,
- GNUNET_HashCode * ret);
+void GNUNET_CRYPTO_hash (const void *block, size_t size, GNUNET_HashCode *
ret);
/**
@@ -409,11 +403,10 @@
* @param plaintext_len length of plaintext
* @param hmac where to store the hmac
*/
-void
+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);
/**
@@ -443,12 +436,16 @@
* @param callback_cls closure for callback
* @return NULL on (immediate) errror
*/
-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);
+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);
/**
@@ -456,8 +453,7 @@
*
* @param fhc operation to cancel (callback must not yet have been invoked)
*/
-void
-GNUNET_CRYPTO_hash_file_cancel (struct GNUNET_CRYPTO_FileHashContext *fhc);
+void GNUNET_CRYPTO_hash_file_cancel (struct GNUNET_CRYPTO_FileHashContext
*fhc);
/**
@@ -467,7 +463,7 @@
* @param result hash code that is randomized
*/
void GNUNET_CRYPTO_hash_create_random (enum GNUNET_CRYPTO_Quality mode,
- GNUNET_HashCode * result);
+ GNUNET_HashCode * result);
/**
@@ -516,8 +512,7 @@
void GNUNET_CRYPTO_hash_to_aes_key (const GNUNET_HashCode * hc,
struct GNUNET_CRYPTO_AesSessionKey *skey,
struct
- GNUNET_CRYPTO_AesInitializationVector
- *iv);
+ GNUNET_CRYPTO_AesInitializationVector *iv);
/**
@@ -527,8 +522,7 @@
* @param bit index into the hashcode, [0...159]
* @return Bit \a bit from hashcode \a code, -1 for invalid index
*/
-int GNUNET_CRYPTO_hash_get_bit (const GNUNET_HashCode * code,
- unsigned int bit);
+int GNUNET_CRYPTO_hash_get_bit (const GNUNET_HashCode * code, unsigned int
bit);
/**
* Determine how many low order bits match in two
@@ -542,7 +536,8 @@
*
* @return the number of bits that match
*/
-unsigned int GNUNET_CRYPTO_hash_matching_bits(const GNUNET_HashCode *first,
const GNUNET_HashCode *second);
+unsigned int GNUNET_CRYPTO_hash_matching_bits (const GNUNET_HashCode * first,
+ const GNUNET_HashCode * second);
/**
@@ -580,11 +575,10 @@
* @param argp pair of void * & size_t for context chunks, terminated by NULL
*/
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);
+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);
/**
@@ -596,11 +590,9 @@
* @param ... pair of void * & size_t for context chunks, terminated by NULL
*/
void
-GNUNET_CRYPTO_hmac_derive_key(struct GNUNET_CRYPTO_AuthKey *key,
- const struct GNUNET_CRYPTO_AesSessionKey *rkey,
- const void *salt,
- size_t salt_len,
- ...);
+GNUNET_CRYPTO_hmac_derive_key (struct GNUNET_CRYPTO_AuthKey *key,
+ const struct GNUNET_CRYPTO_AesSessionKey *rkey,
+ const void *salt, size_t salt_len, ...);
/**
* @brief Derive key
@@ -615,12 +607,11 @@
* @return GNUNET_YES on success
*/
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,
- ...);
+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, ...);
/**
@@ -637,13 +628,12 @@
* @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);
/**
@@ -658,11 +648,10 @@
* @return GNUNET_YES on success
*/
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);
+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);
/**
@@ -678,8 +667,8 @@
*/
int
GNUNET_CRYPTO_kdf (void *result, size_t out_len,
- 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, ...);
/**
@@ -696,8 +685,9 @@
* @param buf the buffer where the private key data is stored
* @param len the length of the data in 'buffer'
*/
-struct GNUNET_CRYPTO_RsaPrivateKey *
-GNUNET_CRYPTO_rsa_decode_key (const char *buf, uint16_t len);
+struct GNUNET_CRYPTO_RsaPrivateKey *GNUNET_CRYPTO_rsa_decode_key (const char
+ *buf,
+ uint16_t
len);
/**
* Create a new private key by reading it from a file. If the
@@ -714,7 +704,7 @@
* permission denied)
*/
struct GNUNET_CRYPTO_RsaPrivateKey
- *GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename);
+ *GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename);
/**
@@ -725,7 +715,7 @@
* @return some private key purely dependent on input
*/
struct GNUNET_CRYPTO_RsaPrivateKey
- *GNUNET_CRYPTO_rsa_key_create_from_hash (const GNUNET_HashCode * hc);
+ *GNUNET_CRYPTO_rsa_key_create_from_hash (const GNUNET_HashCode * hc);
/**
@@ -775,11 +765,10 @@
* @param max how many bytes of a result are expected? Must be exact.
* @return the size of the decrypted block (that is, size) or -1 on error
*/
-ssize_t GNUNET_CRYPTO_rsa_decrypt (const struct GNUNET_CRYPTO_RsaPrivateKey
*key,
- const struct GNUNET_CRYPTO_RsaEncryptedData
- *block,
- void *result,
- size_t max);
+ssize_t GNUNET_CRYPTO_rsa_decrypt (const struct GNUNET_CRYPTO_RsaPrivateKey
+ *key,
+ const struct GNUNET_CRYPTO_RsaEncryptedData
+ *block, void *result, size_t max);
/**
@@ -792,8 +781,7 @@
*/
int GNUNET_CRYPTO_rsa_sign (const struct GNUNET_CRYPTO_RsaPrivateKey *key,
const struct GNUNET_CRYPTO_RsaSignaturePurpose
- *purpose,
- struct GNUNET_CRYPTO_RsaSignature *sig);
+ *purpose, struct GNUNET_CRYPTO_RsaSignature *sig);
/**
Modified: gnunet/src/include/gnunet_datacache_lib.h
===================================================================
--- gnunet/src/include/gnunet_datacache_lib.h 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/include/gnunet_datacache_lib.h 2011-08-15 21:46:35 UTC (rev
16581)
@@ -56,9 +56,10 @@
* @param section section in the configuration that contains our options
* @return handle to use to access the service
*/
-struct GNUNET_DATACACHE_Handle *
-GNUNET_DATACACHE_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *section);
+struct GNUNET_DATACACHE_Handle *GNUNET_DATACACHE_create (const struct
+
GNUNET_CONFIGURATION_Handle
+ *cfg,
+ const char *section);
/**
@@ -81,11 +82,11 @@
* @return GNUNET_OK to continue iterating, GNUNET_SYSERR to abort
*/
typedef int (*GNUNET_DATACACHE_Iterator) (void *cls,
- struct GNUNET_TIME_Absolute exp,
- const GNUNET_HashCode * key,
- size_t size,
- const char *data,
- enum GNUNET_BLOCK_Type type);
+ struct GNUNET_TIME_Absolute exp,
+ const GNUNET_HashCode * key,
+ size_t size,
+ const char *data,
+ enum GNUNET_BLOCK_Type type);
/**
@@ -99,13 +100,13 @@
* @param discard_time when to discard the value in any case
* @return GNUNET_OK on success, GNUNET_SYSERR on error (full, etc.)
*/
-int
+int
GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h,
- const GNUNET_HashCode * key,
- size_t size,
- const char *data,
- enum GNUNET_BLOCK_Type type,
- struct GNUNET_TIME_Absolute discard_time);
+ const GNUNET_HashCode * key,
+ size_t size,
+ const char *data,
+ enum GNUNET_BLOCK_Type type,
+ struct GNUNET_TIME_Absolute discard_time);
/**
@@ -119,12 +120,11 @@
* @param iter_cls closure for iter
* @return the number of results found
*/
-unsigned int
+unsigned int
GNUNET_DATACACHE_get (struct GNUNET_DATACACHE_Handle *h,
- const GNUNET_HashCode * key,
- enum GNUNET_BLOCK_Type type,
- GNUNET_DATACACHE_Iterator iter,
- void *iter_cls);
+ const GNUNET_HashCode * key,
+ enum GNUNET_BLOCK_Type type,
+ GNUNET_DATACACHE_Iterator iter, void *iter_cls);
#if 0 /* keep Emacsens' auto-indent happy */
Modified: gnunet/src/include/gnunet_datacache_plugin.h
===================================================================
--- gnunet/src/include/gnunet_datacache_plugin.h 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/include/gnunet_datacache_plugin.h 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -45,9 +45,9 @@
* @param key key of the content that was deleted
* @param size number of bytes that were made available
*/
-typedef void (*GNUNET_DATACACHE_DeleteNotifyCallback)(void *cls,
- const GNUNET_HashCode
*key,
- size_t size);
+typedef void (*GNUNET_DATACACHE_DeleteNotifyCallback) (void *cls,
+ const GNUNET_HashCode *
+ key, size_t size);
/**
@@ -57,8 +57,8 @@
*/
struct GNUNET_DATACACHE_PluginEnvironment
{
-
+
/**
* Configuration to use.
*/
@@ -91,11 +91,12 @@
/**
* @brief struct returned by the initialization function of the plugin
*/
-struct GNUNET_DATACACHE_PluginFunctions {
+struct GNUNET_DATACACHE_PluginFunctions
+{
/**
* Closure to pass to all plugin functions.
- */
+ */
void *cls;
/**
@@ -108,12 +109,12 @@
* @param discard_time when to discard the value in any case
* @return 0 on error, number of bytes used otherwise
*/
- size_t (*put) (void *cls,
- const GNUNET_HashCode * key,
- size_t size,
- const char *data,
- enum GNUNET_BLOCK_Type type,
- struct GNUNET_TIME_Absolute discard_time);
+ size_t (*put) (void *cls,
+ const GNUNET_HashCode * key,
+ size_t size,
+ const char *data,
+ enum GNUNET_BLOCK_Type type,
+ struct GNUNET_TIME_Absolute discard_time);
/**
@@ -128,10 +129,9 @@
* @return the number of results found
*/
unsigned int (*get) (void *cls,
- const GNUNET_HashCode * key,
- enum GNUNET_BLOCK_Type type,
- GNUNET_DATACACHE_Iterator iter,
- void *iter_cls);
+ const GNUNET_HashCode * key,
+ enum GNUNET_BLOCK_Type type,
+ GNUNET_DATACACHE_Iterator iter, void *iter_cls);
/**
@@ -140,7 +140,7 @@
*
* @param cls closure (internal context for the plugin)
* @return GNUNET_OK on success, GNUNET_SYSERR on error
- */
+ */
int (*del) (void *cls);
Modified: gnunet/src/include/gnunet_datastore_plugin.h
===================================================================
--- gnunet/src/include/gnunet_datastore_plugin.h 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/include/gnunet_datastore_plugin.h 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -48,8 +48,7 @@
* @param delta change in disk utilization,
* 0 for "reset to empty"
*/
-typedef void (*DiskUtilizationChange)(void *cls,
- int delta);
+typedef void (*DiskUtilizationChange) (void *cls, int delta);
/**
@@ -94,15 +93,14 @@
* GNUNET_NO to delete the item
*/
typedef int (*PluginDatumProcessor) (void *cls,
- const GNUNET_HashCode * key,
- uint32_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- struct GNUNET_TIME_Absolute
- expiration,
- uint64_t uid);
+ const GNUNET_HashCode * key,
+ uint32_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute
+ expiration, uint64_t uid);
/**
* Get an estimate of how much space the database is
@@ -133,15 +131,14 @@
* GNUNET_SYSERR on failure
*/
typedef int (*PluginPut) (void *cls,
- const GNUNET_HashCode * key,
- uint32_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- uint32_t replication,
- struct GNUNET_TIME_Absolute expiration,
- char **msg);
+ const GNUNET_HashCode * key,
+ uint32_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ uint32_t replication,
+ struct GNUNET_TIME_Absolute expiration, char **msg);
/**
@@ -163,11 +160,11 @@
* @param proc_cls closure for proc
*/
typedef void (*PluginGetKey) (void *cls,
- uint64_t offset,
- const GNUNET_HashCode *key,
- const GNUNET_HashCode *vhash,
- enum GNUNET_BLOCK_Type type,
- PluginDatumProcessor proc, void *proc_cls);
+ uint64_t offset,
+ const GNUNET_HashCode * key,
+ const GNUNET_HashCode * vhash,
+ enum GNUNET_BLOCK_Type type,
+ PluginDatumProcessor proc, void *proc_cls);
@@ -182,7 +179,7 @@
* @param proc_cls closure for proc
*/
typedef void (*PluginGetRandom) (void *cls,
- PluginDatumProcessor proc, void *proc_cls);
+ PluginDatumProcessor proc, void *proc_cls);
/**
@@ -209,10 +206,9 @@
* @return GNUNET_OK on success
*/
typedef int (*PluginUpdate) (void *cls,
- uint64_t uid,
- int delta,
- struct GNUNET_TIME_Absolute expire,
- char **msg);
+ uint64_t uid,
+ int delta,
+ struct GNUNET_TIME_Absolute expire, char **msg);
/**
@@ -228,10 +224,9 @@
* @param proc_cls closure for proc
*/
typedef void (*PluginGetType) (void *cls,
- uint64_t offset,
- enum GNUNET_BLOCK_Type type,
- PluginDatumProcessor proc,
- void *proc_cls);
+ uint64_t offset,
+ enum GNUNET_BLOCK_Type type,
+ PluginDatumProcessor proc, void *proc_cls);
/**
Modified: gnunet/src/include/gnunet_datastore_service.h
===================================================================
--- gnunet/src/include/gnunet_datastore_service.h 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/include/gnunet_datastore_service.h 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -75,8 +75,7 @@
* @param h handle to the datastore
* @param drop set to GNUNET_YES to delete all data in datastore (!)
*/
-void GNUNET_DATASTORE_disconnect (struct GNUNET_DATASTORE_Handle *h,
- int drop);
+void GNUNET_DATASTORE_disconnect (struct GNUNET_DATASTORE_Handle *h, int drop);
/**
@@ -89,9 +88,9 @@
* GNUNET_YES (or other positive value) on success
* @param msg NULL on success, otherwise an error message
*/
-typedef void (*GNUNET_DATASTORE_ContinuationWithStatus)(void *cls,
- int32_t success,
- const char *msg);
+typedef void (*GNUNET_DATASTORE_ContinuationWithStatus) (void *cls,
+ int32_t success,
+ const char *msg);
/**
@@ -113,15 +112,21 @@
* cancel; note that even if NULL is returned, the callback will be
invoked
* (or rather, will already have been invoked)
*/
-struct GNUNET_DATASTORE_QueueEntry *
-GNUNET_DATASTORE_reserve (struct GNUNET_DATASTORE_Handle *h,
- uint64_t amount,
- uint32_t entries,
- unsigned int queue_priority,
- unsigned int max_queue_size,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_DATASTORE_ContinuationWithStatus cont,
- void *cont_cls);
+struct GNUNET_DATASTORE_QueueEntry *GNUNET_DATASTORE_reserve (struct
+
GNUNET_DATASTORE_Handle
+ *h,
+ uint64_t amount,
+ uint32_t entries,
+ unsigned int
+ queue_priority,
+ unsigned int
+ max_queue_size,
+ struct
+
GNUNET_TIME_Relative
+ timeout,
+
GNUNET_DATASTORE_ContinuationWithStatus
+ cont,
+ void *cont_cls);
/**
@@ -150,22 +155,29 @@
* cancel; note that even if NULL is returned, the callback will be
invoked
* (or rather, will already have been invoked)
*/
-struct GNUNET_DATASTORE_QueueEntry *
-GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h,
- uint32_t rid,
- const GNUNET_HashCode * key,
- size_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- uint32_t replication,
- struct GNUNET_TIME_Absolute expiration,
- unsigned int queue_priority,
- unsigned int max_queue_size,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_DATASTORE_ContinuationWithStatus cont,
- void *cont_cls);
+struct GNUNET_DATASTORE_QueueEntry *GNUNET_DATASTORE_put (struct
+
GNUNET_DATASTORE_Handle
+ *h, uint32_t rid,
+ const GNUNET_HashCode
+ * key, size_t size,
+ const void *data,
+ enum
GNUNET_BLOCK_Type
+ type,
+ uint32_t priority,
+ uint32_t anonymity,
+ uint32_t replication,
+ struct
+ GNUNET_TIME_Absolute
+ expiration,
+ unsigned int
+ queue_priority,
+ unsigned int
+ max_queue_size,
+ struct
+ GNUNET_TIME_Relative
+ timeout,
+
GNUNET_DATASTORE_ContinuationWithStatus
+ cont, void
*cont_cls);
/**
@@ -189,14 +201,24 @@
* cancel; note that even if NULL is returned, the callback will be
invoked
* (or rather, will already have been invoked)
*/
-struct GNUNET_DATASTORE_QueueEntry *
-GNUNET_DATASTORE_release_reserve (struct GNUNET_DATASTORE_Handle *h,
- uint32_t rid,
- unsigned int queue_priority,
- unsigned int max_queue_size,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_DATASTORE_ContinuationWithStatus cont,
- void *cont_cls);
+struct GNUNET_DATASTORE_QueueEntry *GNUNET_DATASTORE_release_reserve (struct
+
GNUNET_DATASTORE_Handle
+ *h,
+ uint32_t
+ rid,
+ unsigned
+ int
+
queue_priority,
+ unsigned
+ int
+
max_queue_size,
+ struct
+
GNUNET_TIME_Relative
+ timeout,
+
GNUNET_DATASTORE_ContinuationWithStatus
+ cont,
+ void
+
*cont_cls);
/**
@@ -216,16 +238,23 @@
* cancel; note that even if NULL is returned, the callback will be
invoked
* (or rather, will already have been invoked)
*/
-struct GNUNET_DATASTORE_QueueEntry *
-GNUNET_DATASTORE_update (struct GNUNET_DATASTORE_Handle *h,
- uint64_t uid,
- uint32_t priority,
- struct GNUNET_TIME_Absolute expiration,
- unsigned int queue_priority,
- unsigned int max_queue_size,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_DATASTORE_ContinuationWithStatus cont,
- void *cont_cls);
+struct GNUNET_DATASTORE_QueueEntry *GNUNET_DATASTORE_update (struct
+
GNUNET_DATASTORE_Handle
+ *h, uint64_t uid,
+ uint32_t priority,
+ struct
+
GNUNET_TIME_Absolute
+ expiration,
+ unsigned int
+ queue_priority,
+ unsigned int
+ max_queue_size,
+ struct
+
GNUNET_TIME_Relative
+ timeout,
+
GNUNET_DATASTORE_ContinuationWithStatus
+ cont,
+ void *cont_cls);
/**
@@ -249,16 +278,23 @@
* cancel; note that even if NULL is returned, the callback will be
invoked
* (or rather, will already have been invoked)
*/
-struct GNUNET_DATASTORE_QueueEntry *
-GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h,
- const GNUNET_HashCode *key,
- size_t size,
- const void *data,
- unsigned int queue_priority,
- unsigned int max_queue_size,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_DATASTORE_ContinuationWithStatus cont,
- void *cont_cls);
+struct GNUNET_DATASTORE_QueueEntry *GNUNET_DATASTORE_remove (struct
+
GNUNET_DATASTORE_Handle
+ *h,
+ const
+ GNUNET_HashCode *
+ key, size_t size,
+ const void *data,
+ unsigned int
+ queue_priority,
+ unsigned int
+ max_queue_size,
+ struct
+
GNUNET_TIME_Relative
+ timeout,
+
GNUNET_DATASTORE_ContinuationWithStatus
+ cont,
+ void *cont_cls);
/**
@@ -276,14 +312,14 @@
* maybe 0 if no unique identifier is available
*/
typedef void (*GNUNET_DATASTORE_DatumProcessor) (void *cls,
- const GNUNET_HashCode * key,
- size_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- struct GNUNET_TIME_Absolute
- expiration, uint64_t uid);
+ const GNUNET_HashCode * key,
+ size_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute
+ expiration, uint64_t uid);
/**
@@ -307,16 +343,26 @@
* @return NULL if the entry was not queued, otherwise a handle that can be
used to
* cancel
*/
-struct GNUNET_DATASTORE_QueueEntry *
-GNUNET_DATASTORE_get_key (struct GNUNET_DATASTORE_Handle *h,
- uint64_t offset,
- const GNUNET_HashCode * key,
- enum GNUNET_BLOCK_Type type,
- unsigned int queue_priority,
- unsigned int max_queue_size,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_DATASTORE_DatumProcessor proc,
- void *proc_cls);
+struct GNUNET_DATASTORE_QueueEntry *GNUNET_DATASTORE_get_key (struct
+
GNUNET_DATASTORE_Handle
+ *h,
+ uint64_t offset,
+ const
+ GNUNET_HashCode *
+ key,
+ enum
+ GNUNET_BLOCK_Type
+ type,
+ unsigned int
+ queue_priority,
+ unsigned int
+ max_queue_size,
+ struct
+
GNUNET_TIME_Relative
+ timeout,
+
GNUNET_DATASTORE_DatumProcessor
+ proc,
+ void *proc_cls);
/**
@@ -343,15 +389,27 @@
* @return NULL if the entry was not queued, otherwise a handle that can be
used to
* cancel
*/
-struct GNUNET_DATASTORE_QueueEntry *
-GNUNET_DATASTORE_get_zero_anonymity (struct GNUNET_DATASTORE_Handle *h,
- uint64_t offset,
- unsigned int queue_priority,
- unsigned int max_queue_size,
- struct GNUNET_TIME_Relative timeout,
- enum GNUNET_BLOCK_Type type,
- GNUNET_DATASTORE_DatumProcessor proc,
- void *proc_cls);
+struct GNUNET_DATASTORE_QueueEntry *GNUNET_DATASTORE_get_zero_anonymity (struct
+
GNUNET_DATASTORE_Handle
+ *h,
+
uint64_t
+
offset,
+
unsigned
+ int
+
queue_priority,
+
unsigned
+ int
+
max_queue_size,
+ struct
+
GNUNET_TIME_Relative
+
timeout,
+ enum
+
GNUNET_BLOCK_Type
+ type,
+
GNUNET_DATASTORE_DatumProcessor
+ proc,
+ void
+
*proc_cls);
/**
@@ -373,13 +431,22 @@
* @return NULL if the entry was not queued, otherwise a handle that can be
used to
* cancel
*/
-struct GNUNET_DATASTORE_QueueEntry *
-GNUNET_DATASTORE_get_for_replication (struct GNUNET_DATASTORE_Handle *h,
- unsigned int queue_priority,
- unsigned int max_queue_size,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_DATASTORE_DatumProcessor proc,
- void *proc_cls);
+struct GNUNET_DATASTORE_QueueEntry *GNUNET_DATASTORE_get_for_replication
(struct
+
GNUNET_DATASTORE_Handle
+ *h,
+
unsigned
+ int
+
queue_priority,
+
unsigned
+ int
+
max_queue_size,
+
struct
+
GNUNET_TIME_Relative
+
timeout,
+
GNUNET_DATASTORE_DatumProcessor
+ proc,
+ void
+
*proc_cls);
@@ -389,8 +456,7 @@
*
* @param qe operation to cancel
*/
-void
-GNUNET_DATASTORE_cancel (struct GNUNET_DATASTORE_QueueEntry *qe);
+void GNUNET_DATASTORE_cancel (struct GNUNET_DATASTORE_QueueEntry *qe);
#if 0 /* keep Emacsens' auto-indent happy */
Modified: gnunet/src/include/gnunet_dht_service.h
===================================================================
--- gnunet/src/include/gnunet_dht_service.h 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/include/gnunet_dht_service.h 2011-08-15 21:46:35 UTC (rev
16581)
@@ -90,29 +90,29 @@
* Options for routing.
*/
enum GNUNET_DHT_RouteOption
- {
+{
/**
* Default. Do nothing special.
*/
- GNUNET_DHT_RO_NONE = 0,
+ GNUNET_DHT_RO_NONE = 0,
/**
* Each peer along the way should look at 'enc' (otherwise
* only the k-peers closest to the key should look at it).
*/
- GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE = 1,
+ GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE = 1,
/**
* We should keep track of the route that the message
* took in the P2P network.
*/
- GNUNET_DHT_RO_RECORD_ROUTE = 2,
+ GNUNET_DHT_RO_RECORD_ROUTE = 2,
/**
* Possible message option for query key randomization.
*/
- GNUNET_DHT_RO_BART = 4
- };
+ GNUNET_DHT_RO_BART = 4
+};
/**
@@ -123,9 +123,9 @@
* processing multiple GET/FIND requests in parallel
* @return NULL on error
*/
-struct GNUNET_DHT_Handle *
-GNUNET_DHT_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
- unsigned int ht_len);
+struct GNUNET_DHT_Handle *GNUNET_DHT_connect (const struct
+ GNUNET_CONFIGURATION_Handle *cfg,
+ unsigned int ht_len);
/**
@@ -133,8 +133,7 @@
*
* @param handle connection to shut down
*/
-void
-GNUNET_DHT_disconnect (struct GNUNET_DHT_Handle *handle);
+void GNUNET_DHT_disconnect (struct GNUNET_DHT_Handle *handle);
/* *************** Standard API: get and put ******************* */
@@ -165,8 +164,7 @@
const char *data,
struct GNUNET_TIME_Absolute exp,
struct GNUNET_TIME_Relative timeout,
- GNUNET_SCHEDULER_Task cont,
- void *cont_cls);
+ GNUNET_SCHEDULER_Task cont, void *cont_cls);
/**
@@ -184,14 +182,15 @@
* @param size number of bytes in data
* @param data pointer to the result data
*/
-typedef void (*GNUNET_DHT_GetIterator)(void *cls,
- struct GNUNET_TIME_Absolute exp,
- const GNUNET_HashCode * key,
- const struct GNUNET_PeerIdentity * const
*get_path,
- const struct GNUNET_PeerIdentity * const
*put_path,
- enum GNUNET_BLOCK_Type type,
- size_t size,
- const void *data);
+typedef void (*GNUNET_DHT_GetIterator) (void *cls,
+ struct GNUNET_TIME_Absolute exp,
+ const GNUNET_HashCode * key,
+ const struct GNUNET_PeerIdentity *
+ const *get_path,
+ const struct GNUNET_PeerIdentity *
+ const *put_path,
+ enum GNUNET_BLOCK_Type type,
+ size_t size, const void *data);
@@ -215,19 +214,23 @@
*
* @return handle to stop the async get
*/
-struct GNUNET_DHT_GetHandle *
-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 struct GNUNET_CONTAINER_BloomFilter *bf,
- int32_t bf_mutator,
- const void *xquery,
- size_t xquery_size,
- GNUNET_DHT_GetIterator iter,
- void *iter_cls);
+struct GNUNET_DHT_GetHandle *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 struct
+ GNUNET_CONTAINER_BloomFilter
+ *bf, int32_t bf_mutator,
+ const void *xquery,
+ size_t xquery_size,
+ GNUNET_DHT_GetIterator iter,
+ void *iter_cls);
/**
@@ -238,8 +241,7 @@
* On return get_handle will no longer be valid, caller
* must not use again!!!
*/
-void
-GNUNET_DHT_get_stop (struct GNUNET_DHT_GetHandle *get_handle);
+void GNUNET_DHT_get_stop (struct GNUNET_DHT_GetHandle *get_handle);
/* ******** Special high-level API for finding peers *********** */
@@ -251,8 +253,9 @@
* @param cls closure
* @param peer hello of a target (peer near key)
*/
-typedef void (*GNUNET_DHT_FindPeerProcessor)(void *cls,
- const struct GNUNET_HELLO_Message
*peer);
+typedef void (*GNUNET_DHT_FindPeerProcessor) (void *cls,
+ const struct GNUNET_HELLO_Message
+ * peer);
/**
@@ -267,13 +270,21 @@
* @param proc_cls closure for proc
* @return handle to stop the async get, NULL on error
*/
-struct GNUNET_DHT_FindPeerHandle *
-GNUNET_DHT_find_peer_start (struct GNUNET_DHT_Handle *handle,
- struct GNUNET_TIME_Relative timeout,
- const GNUNET_HashCode *key,
- enum GNUNET_DHT_RouteOption options,
- GNUNET_DHT_FindPeerProcessor proc,
- void *proc_cls);
+struct GNUNET_DHT_FindPeerHandle *GNUNET_DHT_find_peer_start (struct
+ GNUNET_DHT_Handle
+ *handle,
+ struct
+
GNUNET_TIME_Relative
+ timeout,
+ const
+ GNUNET_HashCode *
+ key,
+ enum
+
GNUNET_DHT_RouteOption
+ options,
+
GNUNET_DHT_FindPeerProcessor
+ proc,
+ void *proc_cls);
/**
@@ -300,10 +311,12 @@
* to the peers on the PUT path (or NULL if not recorded)
* @param reply response
*/
-typedef void (*GNUNET_DHT_ReplyProcessor)(void *cls,
- const GNUNET_HashCode *key,
- const struct GNUNET_PeerIdentity *
const *outgoing_path,
- const struct GNUNET_MessageHeader
*reply);
+typedef void (*GNUNET_DHT_ReplyProcessor) (void *cls,
+ const GNUNET_HashCode * key,
+ const struct GNUNET_PeerIdentity *
+ const *outgoing_path,
+ const struct GNUNET_MessageHeader *
+ reply);
/**
@@ -327,17 +340,25 @@
* @param cont_cls closure for cont
* @return handle to stop the request, NULL if the request is "fire and forget"
*/
-struct GNUNET_DHT_RouteHandle *
-GNUNET_DHT_route_start (struct GNUNET_DHT_Handle *handle,
- const GNUNET_HashCode *key,
- uint32_t desired_replication_level,
- enum GNUNET_DHT_RouteOption options,
- const struct GNUNET_MessageHeader *enc,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_DHT_ReplyProcessor iter,
- void *iter_cls,
- GNUNET_SCHEDULER_Task cont,
- void *cont_cls);
+struct GNUNET_DHT_RouteHandle *GNUNET_DHT_route_start (struct GNUNET_DHT_Handle
+ *handle,
+ const GNUNET_HashCode *
+ key,
+ uint32_t
+
desired_replication_level,
+ enum
+ GNUNET_DHT_RouteOption
+ options,
+ const struct
+ GNUNET_MessageHeader
+ *enc,
+ struct
+ GNUNET_TIME_Relative
+ timeout,
+
GNUNET_DHT_ReplyProcessor
+ iter, void *iter_cls,
+ GNUNET_SCHEDULER_Task
+ cont, void *cont_cls);
@@ -346,8 +367,7 @@
*
* @param route_handle operation to stop.
*/
-void
-GNUNET_DHT_route_stop (struct GNUNET_DHT_RouteHandle *route_handle);
+void GNUNET_DHT_route_stop (struct GNUNET_DHT_RouteHandle *route_handle);
/* ***** Special API for controlling DHT routing maintenance ******* */
@@ -366,8 +386,7 @@
*/
void
GNUNET_DHT_find_peers (struct GNUNET_DHT_Handle *handle,
- GNUNET_SCHEDULER_Task cont,
- void *cont_cls);
+ GNUNET_SCHEDULER_Task cont, void *cont_cls);
/* ***** Special API for testing robustness with malicious peers ******* */
@@ -387,9 +406,9 @@
* @param cont_cls closure for cont
*
*/
-void
-GNUNET_DHT_set_malicious_dropper (struct GNUNET_DHT_Handle *handle,
GNUNET_SCHEDULER_Task cont,
- void *cont_cls);
+void
+GNUNET_DHT_set_malicious_dropper (struct GNUNET_DHT_Handle *handle,
+ GNUNET_SCHEDULER_Task cont, void *cont_cls);
/**
@@ -401,10 +420,10 @@
* @param cont continuation to call when done (transmitting request to service)
* @param cont_cls closure for cont
*/
-void
+void
GNUNET_DHT_set_malicious_putter (struct GNUNET_DHT_Handle *handle,
- struct GNUNET_TIME_Relative frequency, GNUNET_SCHEDULER_Task cont,
- void *cont_cls);
+ struct GNUNET_TIME_Relative frequency,
+ GNUNET_SCHEDULER_Task cont, void *cont_cls);
/**
@@ -418,8 +437,8 @@
*/
void
GNUNET_DHT_set_malicious_getter (struct GNUNET_DHT_Handle *handle,
- struct GNUNET_TIME_Relative frequency, GNUNET_SCHEDULER_Task cont,
- void *cont_cls);
+ struct GNUNET_TIME_Relative frequency,
+ GNUNET_SCHEDULER_Task cont, void *cont_cls);
#endif
Modified: gnunet/src/include/gnunet_disk_lib.h
===================================================================
--- gnunet/src/include/gnunet_disk_lib.h 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/include/gnunet_disk_lib.h 2011-08-15 21:46:35 UTC (rev
16581)
@@ -36,7 +36,8 @@
struct GNUNET_DISK_PipeHandle;
-enum GNUNET_FILE_Type {
+enum GNUNET_FILE_Type
+{
GNUNET_DISK_FILE, GNUNET_PIPE
};
@@ -74,7 +75,7 @@
int fd;
#endif /*
- */
+ */
};
@@ -99,159 +100,159 @@
* Specifies how a file should be opened.
*/
enum GNUNET_DISK_OpenFlags
- {
+{
/**
* Open the file for reading
*/
- GNUNET_DISK_OPEN_READ = 1,
-
+ GNUNET_DISK_OPEN_READ = 1,
+
/**
* Open the file for writing
*/
- GNUNET_DISK_OPEN_WRITE = 2,
-
+ GNUNET_DISK_OPEN_WRITE = 2,
+
/**
* Open the file for both reading and writing
*/
- GNUNET_DISK_OPEN_READWRITE = 3,
-
+ GNUNET_DISK_OPEN_READWRITE = 3,
+
/**
* Fail if file already exists
*/
- GNUNET_DISK_OPEN_FAILIFEXISTS = 4,
-
+ GNUNET_DISK_OPEN_FAILIFEXISTS = 4,
+
/**
* Truncate file if it exists
*/
- GNUNET_DISK_OPEN_TRUNCATE = 8,
-
+ GNUNET_DISK_OPEN_TRUNCATE = 8,
+
/**
* Create file if it doesn't exist
*/
- GNUNET_DISK_OPEN_CREATE = 16,
+ GNUNET_DISK_OPEN_CREATE = 16,
/**
* Append to the file
*/
- GNUNET_DISK_OPEN_APPEND = 32
- };
+ GNUNET_DISK_OPEN_APPEND = 32
+};
/**
* Specifies what type of memory map is desired.
*/
enum GNUNET_DISK_MapType
- {
+{
/**
* Read-only memory map.
*/
- GNUNET_DISK_MAP_TYPE_READ = 1,
+ GNUNET_DISK_MAP_TYPE_READ = 1,
/**
* Write-able memory map.
*/
- GNUNET_DISK_MAP_TYPE_WRITE = 2,
+ GNUNET_DISK_MAP_TYPE_WRITE = 2,
/**
* Read-write memory map.
*/
- GNUNET_DISK_MAP_TYPE_READWRITE = 3
- };
+ GNUNET_DISK_MAP_TYPE_READWRITE = 3
+};
/**
* File access permissions, UNIX-style.
*/
enum GNUNET_DISK_AccessPermissions
- {
+{
/**
* Nobody is allowed to do anything to the file.
*/
- GNUNET_DISK_PERM_NONE = 0,
+ GNUNET_DISK_PERM_NONE = 0,
/**
* Owner can read.
*/
- GNUNET_DISK_PERM_USER_READ = 1,
+ GNUNET_DISK_PERM_USER_READ = 1,
/**
* Owner can write.
*/
- GNUNET_DISK_PERM_USER_WRITE = 2,
+ GNUNET_DISK_PERM_USER_WRITE = 2,
/**
* Owner can execute.
*/
- GNUNET_DISK_PERM_USER_EXEC = 4,
+ GNUNET_DISK_PERM_USER_EXEC = 4,
/**
* Group can read.
*/
- GNUNET_DISK_PERM_GROUP_READ = 8,
+ GNUNET_DISK_PERM_GROUP_READ = 8,
/**
* Group can write.
*/
- GNUNET_DISK_PERM_GROUP_WRITE = 16,
+ GNUNET_DISK_PERM_GROUP_WRITE = 16,
/**
* Group can execute.
*/
- GNUNET_DISK_PERM_GROUP_EXEC = 32,
+ GNUNET_DISK_PERM_GROUP_EXEC = 32,
/**
* Everybody can read.
*/
- GNUNET_DISK_PERM_OTHER_READ = 64,
+ GNUNET_DISK_PERM_OTHER_READ = 64,
/**
* Everybody can write.
*/
- GNUNET_DISK_PERM_OTHER_WRITE = 128,
+ GNUNET_DISK_PERM_OTHER_WRITE = 128,
/**
* Everybody can execute.
*/
- GNUNET_DISK_PERM_OTHER_EXEC = 256
- };
+ GNUNET_DISK_PERM_OTHER_EXEC = 256
+};
/**
* Constants for specifying how to seek.
*/
-enum GNUNET_DISK_Seek
- {
+enum GNUNET_DISK_Seek
+{
/**
* Seek an absolute position (from the start of the file).
*/
- GNUNET_DISK_SEEK_SET,
+ GNUNET_DISK_SEEK_SET,
/**
* Seek a relative position (from the current offset).
*/
- GNUNET_DISK_SEEK_CUR,
-
+ GNUNET_DISK_SEEK_CUR,
+
/**
* Seek an absolute position from the end of the file.
*/
- GNUNET_DISK_SEEK_END
- };
+ GNUNET_DISK_SEEK_END
+};
/**
* Enumeration identifying the two ends of a pipe.
*/
enum GNUNET_DISK_PipeEnd
- {
+{
/**
* The reading-end of a pipe.
*/
- GNUNET_DISK_PIPE_END_READ = 0,
+ GNUNET_DISK_PIPE_END_READ = 0,
/**
* The writing-end of a pipe.
*/
- GNUNET_DISK_PIPE_END_WRITE = 1
- };
+ GNUNET_DISK_PIPE_END_WRITE = 1
+};
/**
@@ -292,9 +293,8 @@
* @return the new position on success, GNUNET_SYSERR otherwise
*/
off_t
-GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle *h,
- off_t offset,
- enum GNUNET_DISK_Seek whence);
+GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle *h,
+ off_t offset, enum GNUNET_DISK_Seek whence);
/**
@@ -310,8 +310,7 @@
* @return GNUNET_OK on success, GNUNET_SYSERR on error
*/
int GNUNET_DISK_file_size (const char *filename,
- uint64_t *size,
- int includeSymLinks);
+ uint64_t * size, int includeSymLinks);
/**
@@ -330,10 +329,9 @@
* @return GNUNET_OK on success
*/
int GNUNET_DISK_file_get_identifiers (const char *filename,
- uint64_t *dev,
- uint64_t *ino);
-
+ uint64_t * dev, uint64_t * ino);
+
/**
* Create an (empty) temporary file on disk. If the given name is not
* an absolute path, the current 'TMPDIR' will be prepended. In any case,
@@ -345,8 +343,7 @@
* @return NULL on error, otherwise name of fresh
* file on disk in directory for temporary files
*/
-char *
-GNUNET_DISK_mktemp (const char *t);
+char *GNUNET_DISK_mktemp (const char *t);
/**
@@ -362,8 +359,11 @@
* @return IO handle on success, NULL on error
*/
struct GNUNET_DISK_FileHandle *GNUNET_DISK_file_open (const char *fn,
- enum
GNUNET_DISK_OpenFlags flags,
- enum
GNUNET_DISK_AccessPermissions perm);
+ enum
GNUNET_DISK_OpenFlags
+ flags,
+ enum
+
GNUNET_DISK_AccessPermissions
+ perm);
/**
* Creates an interprocess channel
@@ -373,8 +373,8 @@
* @return handle to the new pipe, NULL on error
*/
struct GNUNET_DISK_PipeHandle *GNUNET_DISK_pipe (int blocking,
- int inherit_read,
- int inherit_write);
+ int inherit_read,
+ int inherit_write);
/**
@@ -392,8 +392,8 @@
* @return GNUNET_OK on success, GNUNET_SYSERR otherwise
*/
int
-GNUNET_DISK_pipe_close_end (struct GNUNET_DISK_PipeHandle *p,
- enum GNUNET_DISK_PipeEnd end);
+GNUNET_DISK_pipe_close_end (struct GNUNET_DISK_PipeHandle *p,
+ enum GNUNET_DISK_PipeEnd end);
/**
* Close an open file.
@@ -411,11 +411,12 @@
* @param n end to access
* @return handle for the respective end
*/
-const struct GNUNET_DISK_FileHandle *
-GNUNET_DISK_pipe_handle (const struct
- GNUNET_DISK_PipeHandle
- *p,
- enum GNUNET_DISK_PipeEnd n);
+const struct GNUNET_DISK_FileHandle *GNUNET_DISK_pipe_handle (const struct
+
GNUNET_DISK_PipeHandle
+ *p,
+ enum
+
GNUNET_DISK_PipeEnd
+ n);
/**
* Read the contents of a binary file into a buffer.
@@ -424,8 +425,8 @@
* @param len the maximum number of bytes to read
* @return the number of bytes read on success, GNUNET_SYSERR on failure
*/
-ssize_t GNUNET_DISK_file_read (const struct GNUNET_DISK_FileHandle *h, void
*result,
- size_t len);
+ssize_t GNUNET_DISK_file_read (const struct GNUNET_DISK_FileHandle *h,
+ void *result, size_t len);
/**
@@ -436,9 +437,7 @@
* @param len the maximum number of bytes to read
* @return number of bytes read, GNUNET_SYSERR on failure
*/
-ssize_t GNUNET_DISK_fn_read (const char *fn,
- void *result,
- size_t len);
+ssize_t GNUNET_DISK_fn_read (const char *fn, void *result, size_t len);
/**
@@ -449,9 +448,8 @@
* @param n number of bytes to write
* @return number of bytes written on success, GNUNET_SYSERR on error
*/
-ssize_t GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle *h,
- const void *buffer,
- size_t n);
+ssize_t GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle *h,
+ const void *buffer, size_t n);
/**
@@ -464,10 +462,10 @@
* @param mode file permissions
* @return number of bytes written on success, GNUNET_SYSERR on error
*/
-ssize_t GNUNET_DISK_fn_write (const char *fn,
- const void *buffer,
- size_t n,
- enum GNUNET_DISK_AccessPermissions mode);
+ssize_t GNUNET_DISK_fn_write (const char *fn,
+ const void *buffer,
+ size_t n,
+ enum GNUNET_DISK_AccessPermissions mode);
/**
@@ -489,8 +487,8 @@
* @return the number of files found, -1 on error
*/
int GNUNET_DISK_directory_scan (const char *dirName,
- GNUNET_FileNameCallback callback,
- void *callback_cls);
+ GNUNET_FileNameCallback callback,
+ void *callback_cls);
/**
@@ -603,7 +601,7 @@
*/
int
GNUNET_DISK_file_lock (struct GNUNET_DISK_FileHandle *fh, off_t lockStart,
- off_t lockEnd, int excl);
+ off_t lockEnd, int excl);
/**
@@ -614,9 +612,8 @@
* @return GNUNET_OK on success, GNUNET_SYSERR on error
*/
int
-GNUNET_DISK_file_unlock (struct GNUNET_DISK_FileHandle *fh,
- off_t unlockStart,
- off_t unlockEnd);
+GNUNET_DISK_file_unlock (struct GNUNET_DISK_FileHandle *fh,
+ off_t unlockStart, off_t unlockEnd);
/**
@@ -649,8 +646,8 @@
* private directory name.
* @return the constructed filename
*/
-char *GNUNET_DISK_get_home_filename (const struct GNUNET_CONFIGURATION_Handle
*cfg,
- const char *serviceName, ...);
+char *GNUNET_DISK_get_home_filename (const struct GNUNET_CONFIGURATION_Handle
+ *cfg, const char *serviceName, ...);
/**
@@ -666,9 +663,9 @@
* @param len size of the mapping
* @return pointer to the mapped memory region, NULL on failure
*/
-void *GNUNET_DISK_file_map (const struct GNUNET_DISK_FileHandle *h,
- struct GNUNET_DISK_MapHandle **m,
- enum GNUNET_DISK_MapType access, size_t len);
+void *GNUNET_DISK_file_map (const struct GNUNET_DISK_FileHandle *h,
+ struct GNUNET_DISK_MapHandle **m,
+ enum GNUNET_DISK_MapType access, size_t len);
/**
* Unmap a file
@@ -693,7 +690,12 @@
* @return pipe handle on success, NULL on error
*/
struct GNUNET_DISK_FileHandle *GNUNET_DISK_npipe_create (char **fn,
- enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm);
+ enum
+ GNUNET_DISK_OpenFlags
+ flags,
+ enum
+
GNUNET_DISK_AccessPermissions
+ perm);
/**
* Opens already existing named pipe/FIFO
@@ -704,7 +706,12 @@
* @return pipe handle on success, NULL on error
*/
struct GNUNET_DISK_FileHandle *GNUNET_DISK_npipe_open (const char *fn,
- enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm);
+ enum
+ GNUNET_DISK_OpenFlags
+ flags,
+ enum
+
GNUNET_DISK_AccessPermissions
+ perm);
/**
* Closes a named pipe/FIFO
Modified: gnunet/src/include/gnunet_dv_service.h
===================================================================
--- gnunet/src/include/gnunet_dv_service.h 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/include/gnunet_dv_service.h 2011-08-15 21:46:35 UTC (rev
16581)
@@ -76,8 +76,7 @@
struct GNUNET_TIME_Relative timeout,
const void *addr,
size_t addrlen,
- GNUNET_TRANSPORT_TransmitContinuation
- cont, void *cont_cls);
+ GNUNET_TRANSPORT_TransmitContinuation cont, void
*cont_cls);
Modified: gnunet/src/include/gnunet_fragmentation_lib.h
===================================================================
--- gnunet/src/include/gnunet_fragmentation_lib.h 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/include/gnunet_fragmentation_lib.h 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -58,7 +58,8 @@
* @param msg the message that was created
*/
typedef void (*GNUNET_FRAGMENT_MessageProcessor) (void *cls,
- const struct
GNUNET_MessageHeader *msg);
+ const struct
+ GNUNET_MessageHeader * msg);
/**
@@ -79,14 +80,22 @@
* @param proc_cls closure for proc
* @return the fragmentation context
*/
-struct GNUNET_FRAGMENT_Context *
-GNUNET_FRAGMENT_context_create (struct GNUNET_STATISTICS_Handle *stats,
- uint16_t mtu,
- struct GNUNET_BANDWIDTH_Tracker *tracker,
- struct GNUNET_TIME_Relative delay,
- const struct GNUNET_MessageHeader *msg,
- GNUNET_FRAGMENT_MessageProcessor proc,
- void *proc_cls);
+struct GNUNET_FRAGMENT_Context *GNUNET_FRAGMENT_context_create (struct
+
GNUNET_STATISTICS_Handle
+ *stats,
+ uint16_t mtu,
+ struct
+
GNUNET_BANDWIDTH_Tracker
+ *tracker,
+ struct
+
GNUNET_TIME_Relative
+ delay,
+ const struct
+
GNUNET_MessageHeader
+ *msg,
+
GNUNET_FRAGMENT_MessageProcessor
+ proc,
+ void
*proc_cls);
/**
@@ -112,7 +121,7 @@
* GNUNET_SYSERR if this ack is not valid for this fc
*/
int GNUNET_FRAGMENT_process_ack (struct GNUNET_FRAGMENT_Context *fc,
- const struct GNUNET_MessageHeader *msg);
+ const struct GNUNET_MessageHeader *msg);
/**
@@ -144,8 +153,9 @@
* @param msg the message that was created
*/
typedef void (*GNUNET_DEFRAGMENT_AckProcessor) (void *cls,
- uint32_t id,
- const struct
GNUNET_MessageHeader *msg);
+ uint32_t id,
+ const struct
+ GNUNET_MessageHeader * msg);
/**
@@ -161,13 +171,18 @@
* back to the other side)
* @return the defragmentation context
*/
-struct GNUNET_DEFRAGMENT_Context *
-GNUNET_DEFRAGMENT_context_create (struct GNUNET_STATISTICS_Handle *stats,
- uint16_t mtu,
- unsigned int num_msgs,
- void *cls,
- GNUNET_FRAGMENT_MessageProcessor proc,
- GNUNET_DEFRAGMENT_AckProcessor ackp);
+struct GNUNET_DEFRAGMENT_Context *GNUNET_DEFRAGMENT_context_create (struct
+
GNUNET_STATISTICS_Handle
+ *stats,
+ uint16_t
+ mtu,
+ unsigned
int
+ num_msgs,
+ void *cls,
+
GNUNET_FRAGMENT_MessageProcessor
+ proc,
+
GNUNET_DEFRAGMENT_AckProcessor
+ ackp);
/**
@@ -175,8 +190,7 @@
*
* @param dc defragmentation context
*/
-void
-GNUNET_DEFRAGMENT_context_destroy (struct GNUNET_DEFRAGMENT_Context *dc);
+void GNUNET_DEFRAGMENT_context_destroy (struct GNUNET_DEFRAGMENT_Context *dc);
/**
@@ -188,7 +202,7 @@
*/
int
GNUNET_DEFRAGMENT_process_fragment (struct GNUNET_DEFRAGMENT_Context *dc,
- const struct GNUNET_MessageHeader *msg);
+ const struct GNUNET_MessageHeader *msg);
#if 0 /* keep Emacsens' auto-indent happy */
Modified: gnunet/src/include/gnunet_fs_service.h
===================================================================
--- gnunet/src/include/gnunet_fs_service.h 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/include/gnunet_fs_service.h 2011-08-15 21:46:35 UTC (rev
16581)
@@ -80,8 +80,8 @@
* @return GNUNET_OK to continue to iterate, GNUNET_SYSERR to abort
*/
typedef int (*GNUNET_FS_KeywordIterator) (void *cls,
- const char *keyword,
- int is_mandatory);
+ const char *keyword,
+ int is_mandatory);
/**
* Get a unique key from a URI. This is for putting URIs
@@ -90,9 +90,8 @@
* @param uri uri to convert to a unique key
* @param key wherer to store the unique key
*/
-void
-GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri,
- GNUNET_HashCode * key);
+void
+GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri, GNUNET_HashCode * key);
/**
* Convert a URI to a UTF-8 String.
@@ -100,8 +99,7 @@
* @param uri uri to convert to a string
* @return the UTF-8 string
*/
-char *
-GNUNET_FS_uri_to_string (const struct GNUNET_FS_Uri *uri);
+char *GNUNET_FS_uri_to_string (const struct GNUNET_FS_Uri *uri);
/**
* Convert keyword URI to a human readable format
@@ -110,8 +108,7 @@
* @param uri ksk uri to convert to a string
* @return string with the keywords
*/
-char *
-GNUNET_FS_uri_ksk_to_string_fancy (const struct GNUNET_FS_Uri *uri);
+char *GNUNET_FS_uri_ksk_to_string_fancy (const struct GNUNET_FS_Uri *uri);
/**
@@ -124,8 +121,7 @@
*/
void
GNUNET_FS_uri_ksk_add_keyword (struct GNUNET_FS_Uri *uri,
- const char *keyword,
- int is_mandatory);
+ const char *keyword, int is_mandatory);
/**
@@ -137,7 +133,7 @@
*/
void
GNUNET_FS_uri_ksk_remove_keyword (struct GNUNET_FS_Uri *uri,
- const char *keyword);
+ const char *keyword);
/**
@@ -147,17 +143,14 @@
* @param emsg where to store the parser error message (if any)
* @return NULL on error
*/
-struct GNUNET_FS_Uri *
-GNUNET_FS_uri_parse (const char *uri,
- char **emsg);
+struct GNUNET_FS_Uri *GNUNET_FS_uri_parse (const char *uri, char **emsg);
/**
* Free URI.
*
* @param uri uri to free
*/
-void
-GNUNET_FS_uri_destroy (struct GNUNET_FS_Uri *uri);
+void GNUNET_FS_uri_destroy (struct GNUNET_FS_Uri *uri);
/**
@@ -166,7 +159,7 @@
* @param uri ksk uri to get the number of keywords from
* @return 0 if this is not a keyword URI
*/
-unsigned int
+unsigned int
GNUNET_FS_uri_ksk_get_keyword_count (const struct GNUNET_FS_Uri *uri);
@@ -179,10 +172,10 @@
* @return -1 if this is not a keyword URI, otherwise number of
* keywords iterated over until iterator aborted
*/
-int
+int
GNUNET_FS_uri_ksk_get_keywords (const struct GNUNET_FS_Uri *uri,
- GNUNET_FS_KeywordIterator iterator,
- void *iterator_cls);
+ GNUNET_FS_KeywordIterator iterator,
+ void *iterator_cls);
/**
@@ -194,7 +187,7 @@
*/
int
GNUNET_FS_uri_loc_get_peer_identity (const struct GNUNET_FS_Uri *uri,
- struct GNUNET_PeerIdentity * peer);
+ struct GNUNET_PeerIdentity *peer);
/**
@@ -203,8 +196,8 @@
* @param uri location URI to get the content URI from
* @return NULL if argument is not a location URI
*/
-struct GNUNET_FS_Uri *
-GNUNET_FS_uri_loc_get_uri (const struct GNUNET_FS_Uri *uri);
+struct GNUNET_FS_Uri *GNUNET_FS_uri_loc_get_uri (const struct GNUNET_FS_Uri
+ *uri);
/**
@@ -225,10 +218,13 @@
* @param expiration_time how long will the content be offered?
* @return the location URI, NULL on error
*/
-struct GNUNET_FS_Uri *
-GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *baseUri,
- const struct GNUNET_CONFIGURATION_Handle *cfg,
- struct GNUNET_TIME_Absolute expiration_time);
+struct GNUNET_FS_Uri *GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri
+ *baseUri,
+ const struct
+ GNUNET_CONFIGURATION_Handle
+ *cfg,
+ struct GNUNET_TIME_Absolute
+ expiration_time);
/**
@@ -239,8 +235,8 @@
* @param uri the URI to canonicalize
* @return canonicalized version of the URI, NULL on error
*/
-struct GNUNET_FS_Uri *
-GNUNET_FS_uri_ksk_canonicalize (const struct GNUNET_FS_Uri *uri);
+struct GNUNET_FS_Uri *GNUNET_FS_uri_ksk_canonicalize (const struct
GNUNET_FS_Uri
+ *uri);
/**
@@ -252,9 +248,8 @@
* @param u2 second uri
* @return merged URI, NULL on error
*/
-struct GNUNET_FS_Uri *
-GNUNET_FS_uri_ksk_merge (const struct GNUNET_FS_Uri *u1,
- const struct GNUNET_FS_Uri *u2);
+struct GNUNET_FS_Uri *GNUNET_FS_uri_ksk_merge (const struct GNUNET_FS_Uri *u1,
+ const struct GNUNET_FS_Uri *u2);
/**
@@ -263,8 +258,7 @@
* @param uri the URI to duplicate
* @return copy of the URI
*/
-struct GNUNET_FS_Uri *
-GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri);
+struct GNUNET_FS_Uri *GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri);
/**
@@ -284,9 +278,8 @@
* @return an FS URI for the given keywords, NULL
* if keywords is not legal (i.e. empty).
*/
-struct GNUNET_FS_Uri *
-GNUNET_FS_uri_ksk_create (const char *keywords,
- char **emsg);
+struct GNUNET_FS_Uri *GNUNET_FS_uri_ksk_create (const char *keywords,
+ char **emsg);
/**
@@ -306,9 +299,8 @@
* @return an FS URI for the given keywords, NULL
* if keywords is not legal (i.e. empty).
*/
-struct GNUNET_FS_Uri *
-GNUNET_FS_uri_ksk_create_from_args (unsigned int argc,
- const char **argv);
+struct GNUNET_FS_Uri *GNUNET_FS_uri_ksk_create_from_args (unsigned int argc,
+ const char **argv);
/**
@@ -318,9 +310,9 @@
* @param u2 the other URI
* @return GNUNET_YES if the URIs are equal
*/
-int
+int
GNUNET_FS_uri_test_equal (const struct GNUNET_FS_Uri *u1,
- const struct GNUNET_FS_Uri *u2);
+ const struct GNUNET_FS_Uri *u2);
/**
@@ -329,8 +321,7 @@
* @param uri the uri to check
* @return GNUNET_YES if this is an SKS uri
*/
-int
-GNUNET_FS_uri_test_sks (const struct GNUNET_FS_Uri *uri);
+int GNUNET_FS_uri_test_sks (const struct GNUNET_FS_Uri *uri);
/**
@@ -347,10 +338,8 @@
* @param emsg where to store an error message
* @return an FS URI for the given namespace and identifier
*/
-struct GNUNET_FS_Uri *
-GNUNET_FS_uri_sks_create (struct GNUNET_FS_Namespace *ns,
- const char *id,
- char **emsg);
+struct GNUNET_FS_Uri *GNUNET_FS_uri_sks_create (struct GNUNET_FS_Namespace *ns,
+ const char *id, char **emsg);
/**
@@ -360,9 +349,8 @@
* @param id identifier
* @return an FS URI for the given namespace and identifier
*/
-struct GNUNET_FS_Uri *
-GNUNET_FS_uri_sks_create_from_nsid (GNUNET_HashCode *nsid,
- const char *id);
+struct GNUNET_FS_Uri *GNUNET_FS_uri_sks_create_from_nsid (GNUNET_HashCode *
+ nsid, const char
*id);
/**
@@ -373,9 +361,9 @@
* @param nsid where to store the ID of the namespace
* @return GNUNET_OK on success
*/
-int
+int
GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri,
- GNUNET_HashCode * nsid);
+ GNUNET_HashCode * nsid);
/**
@@ -384,8 +372,7 @@
* @param uri the sks uri
* @return NULL on error (not a valid SKS URI)
*/
-char *
-GNUNET_FS_uri_sks_get_content_id (const struct GNUNET_FS_Uri *uri);
+char *GNUNET_FS_uri_sks_get_content_id (const struct GNUNET_FS_Uri *uri);
/**
@@ -396,9 +383,8 @@
* @param uri SKS uri to convert
* @return NULL on error (not an SKS URI)
*/
-char *
-GNUNET_FS_uri_sks_to_string_fancy (struct GNUNET_CONFIGURATION_Handle *cfg,
- const struct GNUNET_FS_Uri *uri);
+char *GNUNET_FS_uri_sks_to_string_fancy (struct GNUNET_CONFIGURATION_Handle
+ *cfg, const struct GNUNET_FS_Uri
*uri);
/**
@@ -407,8 +393,7 @@
* @param uri the uri
* @return GNUNET_YES if this is a KSK uri
*/
-int
-GNUNET_FS_uri_test_ksk (const struct GNUNET_FS_Uri *uri);
+int GNUNET_FS_uri_test_ksk (const struct GNUNET_FS_Uri *uri);
/**
@@ -417,8 +402,7 @@
* @param uri the uri to check
* @return GNUNET_YES if this is a CHK uri
*/
-int
-GNUNET_FS_uri_test_chk (const struct GNUNET_FS_Uri *uri);
+int GNUNET_FS_uri_test_chk (const struct GNUNET_FS_Uri *uri);
/**
@@ -428,8 +412,7 @@
* @param uri the CHK (or LOC) URI to inspect
* @return size of the file as specified in the CHK URI
*/
-uint64_t
-GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri *uri);
+uint64_t GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri *uri);
/**
@@ -438,8 +421,7 @@
* @param uri the uri to check
* @return GNUNET_YES if this is a LOC uri
*/
-int
-GNUNET_FS_uri_test_loc (const struct GNUNET_FS_Uri *uri);
+int GNUNET_FS_uri_test_loc (const struct GNUNET_FS_Uri *uri);
/**
@@ -450,8 +432,9 @@
* @param md metadata to use
* @return NULL on error, otherwise a KSK URI
*/
-struct GNUNET_FS_Uri *
-GNUNET_FS_uri_ksk_create_from_meta_data (const struct
GNUNET_CONTAINER_MetaData *md);
+struct GNUNET_FS_Uri *GNUNET_FS_uri_ksk_create_from_meta_data (const struct
+
GNUNET_CONTAINER_MetaData
+ *md);
/* ******************** command-line option parsing API
*********************** */
@@ -469,10 +452,9 @@
* @return GNUNET_OK on success
*/
int
-GNUNET_FS_getopt_set_keywords (struct
GNUNET_GETOPT_CommandLineProcessorContext* ctx,
- void *scls,
- const char *option,
- const char *value);
+GNUNET_FS_getopt_set_keywords (struct GNUNET_GETOPT_CommandLineProcessorContext
+ *ctx, void *scls, const char *option,
+ const char *value);
/**
@@ -488,10 +470,9 @@
* @return GNUNET_OK on success
*/
int
-GNUNET_FS_getopt_set_metadata (struct
GNUNET_GETOPT_CommandLineProcessorContext* ctx,
- void *scls,
- const char *option,
- const char *value);
+GNUNET_FS_getopt_set_metadata (struct GNUNET_GETOPT_CommandLineProcessorContext
+ *ctx, void *scls, const char *option,
+ const char *value);
@@ -636,7 +617,7 @@
* be generated in this case.
*/
GNUNET_FS_STATUS_SEARCH_SUSPEND,
-
+
/**
* This search has yielded a result.
*/
@@ -689,7 +670,7 @@
/**
* Notification that we started to unindex a file.
- */
+ */
GNUNET_FS_STATUS_UNINDEX_START,
/**
@@ -724,7 +705,6 @@
* was stopped (final event for this action).
*/
GNUNET_FS_STATUS_UNINDEX_STOPPED
-
};
@@ -773,17 +753,19 @@
* information about what is going on.
*/
struct GNUNET_FS_ProgressInfo
-{
+{
/**
* Values that depend on the event type.
*/
- union {
-
+ union
+ {
+
/**
* Values for all "GNUNET_FS_STATUS_PUBLISH_*" events.
*/
- struct {
+ struct
+ {
/**
* Context for controlling the upload.
@@ -811,7 +793,7 @@
* Name of the file being published; can be NULL.
*/
const char *filename;
-
+
/**
* How large is the file overall? For directories,
* this is only the size of the directory itself,
@@ -824,7 +806,7 @@
* At what time do we expect to finish the upload?
* (will be a value in the past for completed
* uploads).
- */
+ */
struct GNUNET_TIME_Relative eta;
/**
@@ -846,90 +828,96 @@
/**
* Additional values for specific events.
*/
- union {
+ union
+ {
- /**
+ /**
* These values are only valid for
* GNUNET_FS_STATUS_PUBLISH_PROGRESS events.
*/
- struct {
-
- /**
+ struct
+ {
+
+ /**
* Data block we just published.
*/
- const void *data;
-
- /**
+ const void *data;
+
+ /**
* At what offset in the file is "data"?
*/
- uint64_t offset;
-
- /**
+ uint64_t offset;
+
+ /**
* Length of the data block.
*/
- uint64_t data_len;
+ uint64_t data_len;
- /**
+ /**
* Depth of the given block in the tree;
* 0 would be the lowest level (DBLOCKs).
*/
- unsigned int depth;
+ unsigned int depth;
- } progress;
+ } progress;
- /**
+ /**
* These values are only valid for
* GNUNET_FS_STATUS_PUBLISH_RESUME events.
*/
- struct {
-
- /**
+ struct
+ {
+
+ /**
* Error message, NULL if no error was encountered so far.
*/
- const char *message;
-
- /**
+ const char *message;
+
+ /**
* URI of the file (if the download had been completed)
*/
- const struct GNUNET_FS_Uri *chk_uri;
+ const struct GNUNET_FS_Uri *chk_uri;
- } resume;
+ } resume;
- /**
+ /**
* These values are only valid for
* GNUNET_FS_STATUS_PUBLISH_COMPLETED events.
*/
- struct {
-
- /**
+ struct
+ {
+
+ /**
* URI of the file.
*/
- const struct GNUNET_FS_Uri *chk_uri;
+ const struct GNUNET_FS_Uri *chk_uri;
- } completed;
+ } completed;
- /**
+ /**
* These values are only valid for
* GNUNET_FS_STATUS_PUBLISH_ERROR events.
*/
- struct {
-
- /**
+ struct
+ {
+
+ /**
* Error message, never NULL.
*/
- const char *message;
+ const char *message;
- } error;
+ } error;
} specifics;
} publish;
-
+
/**
* Values for all "GNUNET_FS_STATUS_DOWNLOAD_*" events.
*/
- struct {
+ struct
+ {
/**
* Context for controlling the download.
@@ -956,7 +944,7 @@
* download was started from a search result.
*/
void *sctx;
-
+
/**
* URI used for this download.
*/
@@ -966,7 +954,7 @@
* Name of the file that we are downloading.
*/
const char *filename;
-
+
/**
* How large is the download overall? This
* is NOT necessarily the size from the
@@ -978,12 +966,12 @@
* At what time do we expect to finish the download?
* (will be a value in the past for completed
* uploads).
- */
+ */
struct GNUNET_TIME_Relative eta;
/**
* How long has this download been active?
- */
+ */
struct GNUNET_TIME_Relative duration;
/**
@@ -1004,83 +992,88 @@
/**
* Additional values for specific events.
*/
- union {
-
- /**
+ union
+ {
+
+ /**
* These values are only valid for
* GNUNET_FS_STATUS_DOWNLOAD_PROGRESS events.
*/
- struct {
-
- /**
+ struct
+ {
+
+ /**
* Data block we just obtained, can be NULL (even if
* data_len > 0) if we found the entire block 'intact' on
* disk. In this case, it is also possible for 'data_len'
* to be larger than an individual (32k) block.
*/
- const void *data;
-
- /**
+ const void *data;
+
+ /**
* At what offset in the file is "data"?
*/
- uint64_t offset;
-
- /**
+ uint64_t offset;
+
+ /**
* Length of the data block.
*/
- uint64_t data_len;
+ uint64_t data_len;
- /**
+ /**
* Depth of the given block in the tree;
* 0 would be the lowest level (DBLOCKS).
*/
- unsigned int depth;
+ unsigned int depth;
- } progress;
+ } progress;
- /**
+ /**
* These values are only valid for
* GNUNET_FS_STATUS_DOWNLOAD_START events.
*/
- struct {
+ struct
+ {
- /**
+ /**
* Known metadata for the download.
*/
- const struct GNUNET_CONTAINER_MetaData *meta;
-
- } start;
+ const struct GNUNET_CONTAINER_MetaData *meta;
- /**
+ } start;
+
+ /**
* These values are only valid for
* GNUNET_FS_STATUS_DOWNLOAD_RESUME events.
*/
- struct {
+ struct
+ {
- /**
+ /**
* Known metadata for the download.
*/
- const struct GNUNET_CONTAINER_MetaData *meta;
+ const struct GNUNET_CONTAINER_MetaData *meta;
- /**
+ /**
* Error message, NULL if we have not encountered any error yet.
*/
- const char *message;
+ const char *message;
- } resume;
+ } resume;
- /**
+ /**
* These values are only valid for
* GNUNET_FS_STATUS_DOWNLOAD_ERROR events.
*/
- struct {
+ struct
+ {
- /**
+ /**
* Error message.
*/
- const char *message;
+ const char *message;
- } error;
+ } error;
} specifics;
@@ -1089,7 +1082,8 @@
/**
* Values for all "GNUNET_FS_STATUS_SEARCH_*" events.
*/
- struct {
+ struct
+ {
/**
* Context for controlling the search, NULL for
@@ -1138,123 +1132,127 @@
/**
* Additional values for specific events.
*/
- union {
-
- /**
+ union
+ {
+
+ /**
* These values are only valid for
* GNUNET_FS_STATUS_SEARCH_RESULT events.
*/
- struct {
-
- /**
+ struct
+ {
+
+ /**
* Metadata for the search result.
*/
- const struct GNUNET_CONTAINER_MetaData *meta;
+ const struct GNUNET_CONTAINER_MetaData *meta;
- /**
+ /**
* URI for the search result.
*/
- const struct GNUNET_FS_Uri *uri;
+ const struct GNUNET_FS_Uri *uri;
- /**
+ /**
* Handle to the result (for starting downloads).
*/
- struct GNUNET_FS_SearchResult *result;
+ struct GNUNET_FS_SearchResult *result;
- /**
+ /**
* Applicability rank (the larger, the better the result
* fits the search criteria).
*/
- uint32_t applicability_rank;
+ uint32_t applicability_rank;
- } result;
-
- /**
+ } result;
+
+ /**
* These values are only valid for
* GNUNET_FS_STATUS_SEARCH_RESUME_RESULT events.
*/
- struct {
-
- /**
+ struct
+ {
+
+ /**
* Metadata for the search result.
*/
- const struct GNUNET_CONTAINER_MetaData *meta;
+ const struct GNUNET_CONTAINER_MetaData *meta;
- /**
+ /**
* URI for the search result.
*/
- const struct GNUNET_FS_Uri *uri;
+ const struct GNUNET_FS_Uri *uri;
- /**
+ /**
* Handle to the result (for starting downloads).
*/
- struct GNUNET_FS_SearchResult *result;
+ struct GNUNET_FS_SearchResult *result;
- /**
+ /**
* Current availability rank (negative:
* unavailable, positive: available)
*/
- int32_t availability_rank;
-
- /**
+ int32_t availability_rank;
+
+ /**
* On how many total queries is the given
* availability_rank based?
*/
- uint32_t availability_certainty;
+ uint32_t availability_certainty;
- /**
+ /**
* Updated applicability rank (the larger,
* the better the result fits the search
* criteria).
*/
- uint32_t applicability_rank;
-
- } resume_result;
-
- /**
+ uint32_t applicability_rank;
+
+ } resume_result;
+
+ /**
* These values are only valid for
* GNUNET_FS_STATUS_SEARCH_UPDATE events.
*/
- struct {
+ struct
+ {
- /**
+ /**
* Private context set for for this result
* during the "RESULT" event.
*/
- void *cctx;
-
- /**
+ void *cctx;
+
+ /**
* Metadata for the search result.
*/
- const struct GNUNET_CONTAINER_MetaData *meta;
+ const struct GNUNET_CONTAINER_MetaData *meta;
- /**
+ /**
* URI for the search result.
*/
- const struct GNUNET_FS_Uri *uri;
+ const struct GNUNET_FS_Uri *uri;
- /**
+ /**
* Current availability rank (negative:
* unavailable, positive: available)
*/
- int32_t availability_rank;
-
- /**
+ int32_t availability_rank;
+
+ /**
* On how many total queries is the given
* availability_rank based?
*/
- uint32_t availability_certainty;
+ uint32_t availability_certainty;
- /**
+ /**
* Updated applicability rank (the larger,
* the better the result fits the search
* criteria).
*/
- uint32_t applicability_rank;
+ uint32_t applicability_rank;
- } update;
-
- /**
+ } update;
+
+ /**
* These values are only valid for
* GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND events.
* These events are automatically triggered for
@@ -1263,27 +1261,28 @@
* happens primarily to give the client a chance
* to clean up the "cctx" (if needed).
*/
- struct {
+ struct
+ {
- /**
+ /**
* Private context set for for this result
* during the "RESULT" event.
*/
- void *cctx;
-
- /**
+ void *cctx;
+
+ /**
* Metadata for the search result.
*/
- const struct GNUNET_CONTAINER_MetaData *meta;
+ const struct GNUNET_CONTAINER_MetaData *meta;
- /**
+ /**
* URI for the search result.
*/
- const struct GNUNET_FS_Uri *uri;
+ const struct GNUNET_FS_Uri *uri;
- } result_suspend;
-
- /**
+ } result_suspend;
+
+ /**
* These values are only valid for
* GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED events.
* These events are automatically triggered for
@@ -1292,90 +1291,94 @@
* happens primarily to give the client a chance
* to clean up the "cctx" (if needed).
*/
- struct {
+ struct
+ {
- /**
+ /**
* Private context set for for this result
* during the "RESULT" event.
*/
- void *cctx;
-
- /**
+ void *cctx;
+
+ /**
* Metadata for the search result.
*/
- const struct GNUNET_CONTAINER_MetaData *meta;
+ const struct GNUNET_CONTAINER_MetaData *meta;
- /**
+ /**
* URI for the search result.
*/
- const struct GNUNET_FS_Uri *uri;
+ const struct GNUNET_FS_Uri *uri;
- } result_stopped;
+ } result_stopped;
- /**
+ /**
* These values are only valid for
* GNUNET_FS_STATUS_SEARCH_RESUME events.
*/
- struct {
+ struct
+ {
- /**
+ /**
* Error message, NULL if we have not encountered any error yet.
*/
- const char *message;
+ const char *message;
- /**
+ /**
* Is this search currently paused?
*/
- int is_paused;
+ int is_paused;
- } resume;
+ } resume;
- /**
+ /**
* These values are only valid for
* GNUNET_FS_STATUS_SEARCH_ERROR events.
*/
- struct {
+ struct
+ {
- /**
+ /**
* Error message.
*/
- const char *message;
+ const char *message;
- } error;
-
- /**
+ } error;
+
+ /**
* Values for all "GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE" events.
*/
- struct {
-
- /**
+ struct
+ {
+
+ /**
* Handle to the namespace (NULL if it is not a local
* namespace).
*/
- struct GNUNET_FS_Namespace *ns;
-
- /**
+ struct GNUNET_FS_Namespace *ns;
+
+ /**
* Short, human-readable name of the namespace.
*/
- const char *name;
-
- /**
+ const char *name;
+
+ /**
* Root identifier for the namespace, can be NULL.
*/
- const char *root;
-
- /**
+ const char *root;
+
+ /**
* Metadata for the namespace.
*/
- const struct GNUNET_CONTAINER_MetaData *meta;
-
- /**
+ const struct GNUNET_CONTAINER_MetaData *meta;
+
+ /**
* Hash-identifier for the namespace.
*/
- GNUNET_HashCode id;
-
- } namespace;
+ GNUNET_HashCode id;
+ } namespace;
+
} specifics;
} search;
@@ -1383,7 +1386,8 @@
/**
* Values for all "GNUNET_FS_STATUS_UNINDEX_*" events.
*/
- struct {
+ struct
+ {
/**
* Context for controlling the unindexing.
@@ -1411,7 +1415,7 @@
* At what time do we expect to finish unindexing?
* (will be a value in the past for completed
* unindexing opeations).
- */
+ */
struct GNUNET_TIME_Relative eta;
/**
@@ -1428,62 +1432,66 @@
/**
* Additional values for specific events.
*/
- union {
+ union
+ {
- /**
+ /**
* These values are only valid for
* GNUNET_FS_STATUS_UNINDEX_PROGRESS events.
*/
- struct {
-
- /**
+ struct
+ {
+
+ /**
* Data block we just unindexed.
*/
- const void *data;
-
- /**
+ const void *data;
+
+ /**
* At what offset in the file is "data"?
*/
- uint64_t offset;
-
- /**
+ uint64_t offset;
+
+ /**
* Length of the data block.
*/
- uint64_t data_len;
+ uint64_t data_len;
- /**
+ /**
* Depth of the given block in the tree;
* 0 would be the lowest level (DBLOCKS).
*/
- unsigned int depth;
+ unsigned int depth;
- } progress;
+ } progress;
- /**
+ /**
* These values are only valid for
* GNUNET_FS_STATUS_UNINDEX_RESUME events.
*/
- struct {
+ struct
+ {
- /**
+ /**
* Error message, NULL if we have not encountered any error yet.
*/
- const char *message;
+ const char *message;
- } resume;
+ } resume;
- /**
+ /**
* These values are only valid for
* GNUNET_FS_STATUS_UNINDEX_ERROR events.
*/
- struct {
+ struct
+ {
- /**
+ /**
* Error message.
*/
- const char *message;
+ const char *message;
- } error;
+ } error;
} specifics;
@@ -1493,7 +1501,7 @@
/**
* Specific status code (determines the event type).
- */
+ */
enum GNUNET_FS_Status status;
};
@@ -1514,53 +1522,51 @@
* will be passed to future callbacks in the respective
* field in the GNUNET_FS_ProgressInfo struct.
*/
-typedef void* (*GNUNET_FS_ProgressCallback)
- (void *cls,
- const struct GNUNET_FS_ProgressInfo *info);
+typedef void *(*GNUNET_FS_ProgressCallback)
+ (void *cls, const struct GNUNET_FS_ProgressInfo * info);
/**
* General (global) option flags for file-sharing.
*/
enum GNUNET_FS_Flags
- {
+{
/**
* No special flags set.
*/
- GNUNET_FS_FLAGS_NONE = 0,
+ GNUNET_FS_FLAGS_NONE = 0,
/**
* Is persistence of operations desired?
* (will create SUSPEND/RESUME events).
*/
- GNUNET_FS_FLAGS_PERSISTENCE = 1,
+ GNUNET_FS_FLAGS_PERSISTENCE = 1,
/**
* Should we automatically trigger probes for search results
* to determine availability?
* (will create GNUNET_FS_STATUS_SEARCH_UPDATE events).
*/
- GNUNET_FS_FLAGS_DO_PROBES = 2
+ GNUNET_FS_FLAGS_DO_PROBES = 2
+};
- };
-
/**
* Options specified in the VARARGs portion of GNUNET_FS_start.
*/
enum GNUNET_FS_OPTIONS
- {
-
+{
+
/**
* Last option in the VARARG list.
*/
- GNUNET_FS_OPTIONS_END = 0,
+ GNUNET_FS_OPTIONS_END = 0,
/**
* Select the desired amount of parallelism (this option should be
* followed by an "unsigned int" giving the desired maximum number
* of parallel downloads).
*/
- GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM = 1,
+ GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM = 1,
/**
* Maximum number of requests that should be pending at a given
@@ -1568,11 +1574,10 @@
* if we are above this threshold, we should not activate any
* additional downloads.
*/
- GNUNET_FS_OPTIONS_REQUEST_PARALLELISM = 2
+ GNUNET_FS_OPTIONS_REQUEST_PARALLELISM = 2
+};
- };
-
/**
* Settings for publishing a block (which may of course also
* apply to an entire directory or file).
@@ -1621,8 +1626,7 @@
/**
* Return the current year (i.e. '2011').
*/
-unsigned int
-GNUNET_FS_get_current_year (void);
+unsigned int GNUNET_FS_get_current_year (void);
/**
@@ -1631,8 +1635,7 @@
* @param year a year (after 1970, please ;-)).
* @return absolute time for January 1st of that year.
*/
-struct GNUNET_TIME_Absolute
-GNUNET_FS_year_to_time (unsigned int year);
+struct GNUNET_TIME_Absolute GNUNET_FS_year_to_time (unsigned int year);
/**
@@ -1652,13 +1655,12 @@
* @param ... list of optional options, terminated with GNUNET_FS_OPTIONS_END
* @return NULL on error
*/
-struct GNUNET_FS_Handle *
-GNUNET_FS_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *client_name,
- GNUNET_FS_ProgressCallback upcb,
- void *upcb_cls,
- enum GNUNET_FS_Flags flags,
- ...);
+struct GNUNET_FS_Handle *GNUNET_FS_start (const struct
+ GNUNET_CONFIGURATION_Handle *cfg,
+ const char *client_name,
+ GNUNET_FS_ProgressCallback upcb,
+ void *upcb_cls,
+ enum GNUNET_FS_Flags flags, ...);
/**
@@ -1667,9 +1669,8 @@
* called after this function returns.
*
* @param h handle that was returned from GNUNET_FS_start
- */
-void
-GNUNET_FS_stop (struct GNUNET_FS_Handle *h);
+ */
+void GNUNET_FS_stop (struct GNUNET_FS_Handle *h);
/**
@@ -1681,12 +1682,11 @@
* @return GNUNET_SYSERR on error, otherwise the number
* of meta-data items obtained
*/
-int
+int
GNUNET_FS_meta_data_extract_from_file (struct
- GNUNET_CONTAINER_MetaData
- *md, const char *filename,
- struct EXTRACTOR_PluginList *
- extractors);
+ GNUNET_CONTAINER_MetaData
+ *md, const char *filename,
+ struct EXTRACTOR_PluginList
*extractors);
/**
@@ -1704,14 +1704,17 @@
* this entry from the directory, GNUNET_SYSERR
* to abort the iteration
*/
-typedef int (*GNUNET_FS_FileInformationProcessor)(void *cls,
- struct
GNUNET_FS_FileInformation *fi,
- uint64_t length,
- struct
GNUNET_CONTAINER_MetaData *meta,
- struct GNUNET_FS_Uri **uri,
- struct GNUNET_FS_BlockOptions
*bo,
- int *do_index,
- void **client_info);
+typedef int (*GNUNET_FS_FileInformationProcessor) (void *cls,
+ struct
+ GNUNET_FS_FileInformation *
+ fi, uint64_t length,
+ struct
+ GNUNET_CONTAINER_MetaData *
+ meta,
+ struct GNUNET_FS_Uri ** uri,
+ struct
GNUNET_FS_BlockOptions
+ * bo, int *do_index,
+ void **client_info);
/**
@@ -1724,8 +1727,8 @@
* can be passed to "GNUNET_FS_file_information_recover"
* to read this fi-struct from disk.
*/
-const char *
-GNUNET_FS_file_information_get_id (struct GNUNET_FS_FileInformation *s);
+const char *GNUNET_FS_file_information_get_id (struct GNUNET_FS_FileInformation
+ *s);
@@ -1743,14 +1746,17 @@
* @param bo block options
* @return publish structure entry for the file
*/
-struct GNUNET_FS_FileInformation *
-GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h,
- void *client_info,
- const char *filename,
- const struct GNUNET_FS_Uri
*keywords,
- const struct
GNUNET_CONTAINER_MetaData *meta,
- int do_index,
- const struct
GNUNET_FS_BlockOptions *bo);
+struct GNUNET_FS_FileInformation
+ *GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h,
+ void *client_info,
+ const char *filename,
+ const struct GNUNET_FS_Uri
+ *keywords,
+ const struct
+ GNUNET_CONTAINER_MetaData
+ *meta, int do_index,
+ const struct
+ GNUNET_FS_BlockOptions *bo);
/**
@@ -1769,15 +1775,17 @@
* @param bo block options
* @return publish structure entry for the file
*/
-struct GNUNET_FS_FileInformation *
-GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h,
- void *client_info,
- uint64_t length,
- void *data,
- const struct GNUNET_FS_Uri
*keywords,
- const struct
GNUNET_CONTAINER_MetaData *meta,
- int do_index,
- const struct
GNUNET_FS_BlockOptions *bo);
+struct GNUNET_FS_FileInformation
+ *GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h,
+ void *client_info,
+ uint64_t length, void *data,
+ const struct GNUNET_FS_Uri
+ *keywords,
+ const struct
+ GNUNET_CONTAINER_MetaData
+ *meta, int do_index,
+ const struct
+ GNUNET_FS_BlockOptions *bo);
/**
@@ -1796,11 +1804,9 @@
* @param emsg location for the reader to store an error message
* @return number of bytes written, usually "max", 0 on error
*/
-typedef size_t (*GNUNET_FS_DataReader)(void *cls,
- uint64_t offset,
- size_t max,
- void *buf,
- char **emsg);
+typedef size_t (*GNUNET_FS_DataReader) (void *cls,
+ uint64_t offset,
+ size_t max, void *buf, char **emsg);
/**
@@ -1819,16 +1825,19 @@
* @param bo block options
* @return publish structure entry for the file
*/
-struct GNUNET_FS_FileInformation *
-GNUNET_FS_file_information_create_from_reader (struct GNUNET_FS_Handle *h,
- void *client_info,
- uint64_t length,
- GNUNET_FS_DataReader reader,
- void *reader_cls,
- const struct GNUNET_FS_Uri
*keywords,
- const struct
GNUNET_CONTAINER_MetaData *meta,
- int do_index,
- const struct
GNUNET_FS_BlockOptions *bo);
+struct GNUNET_FS_FileInformation
+ *GNUNET_FS_file_information_create_from_reader (struct GNUNET_FS_Handle *h,
+ void *client_info,
+ uint64_t length,
+ GNUNET_FS_DataReader
reader,
+ void *reader_cls,
+ const struct GNUNET_FS_Uri
+ *keywords,
+ const struct
+ GNUNET_CONTAINER_MetaData
+ *meta, int do_index,
+ const struct
+ GNUNET_FS_BlockOptions
*bo);
/**
@@ -1841,9 +1850,9 @@
* @param fi information about the file (should not be
* used henceforth by the caller)
*/
-typedef void (*GNUNET_FS_FileProcessor)(void *cls,
- const char *filename,
- struct GNUNET_FS_FileInformation *fi);
+typedef void (*GNUNET_FS_FileProcessor) (void *cls,
+ const char *filename,
+ struct GNUNET_FS_FileInformation *
fi);
/**
@@ -1859,14 +1868,13 @@
* @param emsg where to store an error message (on errors)
* @return GNUNET_OK on success
*/
-typedef int (*GNUNET_FS_DirectoryScanner)(void *cls,
- struct GNUNET_FS_Handle *h,
- const char *dirname,
- int do_index,
- const struct GNUNET_FS_BlockOptions
*bo,
- GNUNET_FS_FileProcessor proc,
- void *proc_cls,
- char **emsg);
+typedef int (*GNUNET_FS_DirectoryScanner) (void *cls,
+ struct GNUNET_FS_Handle * h,
+ const char *dirname,
+ int do_index,
+ const struct GNUNET_FS_BlockOptions
*
+ bo, GNUNET_FS_FileProcessor proc,
+ void *proc_cls, char **emsg);
@@ -1893,13 +1901,12 @@
*/
int
GNUNET_FS_directory_scanner_default (void *cls,
- struct GNUNET_FS_Handle *h,
- const char *dirname,
- int do_index,
- const struct GNUNET_FS_BlockOptions *bo,
- GNUNET_FS_FileProcessor proc,
- void *proc_cls,
- char **emsg);
+ struct GNUNET_FS_Handle *h,
+ const char *dirname,
+ int do_index,
+ const struct GNUNET_FS_BlockOptions *bo,
+ GNUNET_FS_FileProcessor proc,
+ void *proc_cls, char **emsg);
/**
@@ -1922,15 +1929,17 @@
* @param emsg where to store an error message
* @return publish structure entry for the directory, NULL on error
*/
-struct GNUNET_FS_FileInformation *
-GNUNET_FS_file_information_create_from_directory (struct GNUNET_FS_Handle *h,
- void *client_info,
- const char *filename,
- GNUNET_FS_DirectoryScanner
scanner,
- void *scanner_cls,
- int do_index,
- const struct
GNUNET_FS_BlockOptions *bo,
- char **emsg);
+struct GNUNET_FS_FileInformation
+ *GNUNET_FS_file_information_create_from_directory (struct GNUNET_FS_Handle
+ *h, void *client_info,
+ const char *filename,
+
GNUNET_FS_DirectoryScanner
+ scanner,
+ void *scanner_cls,
+ int do_index,
+ const struct
+ GNUNET_FS_BlockOptions
+ *bo, char **emsg);
/**
@@ -1947,12 +1956,17 @@
* @param bo block options
* @return publish structure entry for the directory , NULL on error
*/
-struct GNUNET_FS_FileInformation *
-GNUNET_FS_file_information_create_empty_directory (struct GNUNET_FS_Handle *h,
- void *client_info,
- const struct GNUNET_FS_Uri
*keywords,
- const struct
GNUNET_CONTAINER_MetaData *meta,
- const struct
GNUNET_FS_BlockOptions *bo);
+struct GNUNET_FS_FileInformation
+ *GNUNET_FS_file_information_create_empty_directory (struct GNUNET_FS_Handle
+ *h, void *client_info,
+ const struct
+ GNUNET_FS_Uri
*keywords,
+ const struct
+
GNUNET_CONTAINER_MetaData
+ *meta,
+ const struct
+ GNUNET_FS_BlockOptions
+ *bo);
/**
@@ -1962,7 +1976,8 @@
* @return GNUNET_YES if so, GNUNET_NO if not
*/
int
-GNUNET_FS_file_information_is_directory (const struct
GNUNET_FS_FileInformation *ent);
+GNUNET_FS_file_information_is_directory (const struct GNUNET_FS_FileInformation
+ *ent);
/**
@@ -1978,7 +1993,7 @@
*/
int
GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir,
- struct GNUNET_FS_FileInformation *ent);
+ struct GNUNET_FS_FileInformation *ent);
/**
@@ -1997,8 +2012,8 @@
*/
void
GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir,
- GNUNET_FS_FileInformationProcessor proc,
- void *proc_cls);
+ GNUNET_FS_FileInformationProcessor proc,
+ void *proc_cls);
/**
@@ -2013,27 +2028,27 @@
*/
void
GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi,
- GNUNET_FS_FileInformationProcessor cleaner,
- void *cleaner_cls);
+ GNUNET_FS_FileInformationProcessor cleaner,
+ void *cleaner_cls);
/**
* Options for publishing. Compatible options
* can be OR'ed together.
*/
-enum GNUNET_FS_PublishOptions
- {
+enum GNUNET_FS_PublishOptions
+{
/**
* No options (use defaults for everything).
*/
- GNUNET_FS_PUBLISH_OPTION_NONE = 0,
-
+ GNUNET_FS_PUBLISH_OPTION_NONE = 0,
+
/**
* Simulate publishing. With this option, no data will be stored
* in the datastore. Useful for computing URIs from files.
*/
- GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY = 1
- };
+ GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY = 1
+};
/**
* Publish a file or directory.
@@ -2048,13 +2063,19 @@
* @param options options for the publication
* @return context that can be used to control the publish operation
*/
-struct GNUNET_FS_PublishContext *
-GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h,
- struct GNUNET_FS_FileInformation *fi,
- struct GNUNET_FS_Namespace *namespace,
- const char *nid,
- const char *nuid,
- enum GNUNET_FS_PublishOptions options);
+struct GNUNET_FS_PublishContext *GNUNET_FS_publish_start (struct
+ GNUNET_FS_Handle *h,
+ struct
+
GNUNET_FS_FileInformation
+ *fi,
+ struct
+ GNUNET_FS_Namespace
+ *namespace,
+ const char *nid,
+ const char *nuid,
+ enum
+
GNUNET_FS_PublishOptions
+ options);
/**
@@ -2065,8 +2086,7 @@
*
* @param pc context for the publication to stop
*/
-void
-GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *pc);
+void GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *pc);
/**
@@ -2077,11 +2097,11 @@
* @param uri URI under which the block is now available, NULL on error
* @param emsg error message, NULL on success
*/
-typedef void (*GNUNET_FS_PublishContinuation)(void *cls,
- const struct GNUNET_FS_Uri *uri,
- const char *emsg);
-
+typedef void (*GNUNET_FS_PublishContinuation) (void *cls,
+ const struct GNUNET_FS_Uri *
uri,
+ const char *emsg);
+
/**
* Publish a KBlock on GNUnet.
*
@@ -2096,13 +2116,12 @@
*/
void
GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h,
- const struct GNUNET_FS_Uri *ksk_uri,
- const struct GNUNET_CONTAINER_MetaData *meta,
- const struct GNUNET_FS_Uri *uri,
- const struct GNUNET_FS_BlockOptions *bo,
- enum GNUNET_FS_PublishOptions options,
- GNUNET_FS_PublishContinuation cont,
- void *cont_cls);
+ const struct GNUNET_FS_Uri *ksk_uri,
+ const struct GNUNET_CONTAINER_MetaData *meta,
+ const struct GNUNET_FS_Uri *uri,
+ const struct GNUNET_FS_BlockOptions *bo,
+ enum GNUNET_FS_PublishOptions options,
+ GNUNET_FS_PublishContinuation cont, void *cont_cls);
/**
@@ -2121,15 +2140,14 @@
*/
void
GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
- struct GNUNET_FS_Namespace *namespace,
- const char *identifier,
- const char *update,
- const struct GNUNET_CONTAINER_MetaData *meta,
- const struct GNUNET_FS_Uri *uri,
- const struct GNUNET_FS_BlockOptions *bo,
- enum GNUNET_FS_PublishOptions options,
- GNUNET_FS_PublishContinuation cont,
- void *cont_cls);
+ struct GNUNET_FS_Namespace *namespace,
+ const char *identifier,
+ const char *update,
+ const struct GNUNET_CONTAINER_MetaData *meta,
+ const struct GNUNET_FS_Uri *uri,
+ const struct GNUNET_FS_BlockOptions *bo,
+ enum GNUNET_FS_PublishOptions options,
+ GNUNET_FS_PublishContinuation cont, void *cont_cls);
/**
@@ -2141,8 +2159,8 @@
* @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort
*/
typedef int (*GNUNET_FS_IndexedFileProcessor) (void *cls,
- const char *filename,
- const GNUNET_HashCode *file_id);
+ const char *filename,
+ const GNUNET_HashCode *
file_id);
/**
@@ -2156,12 +2174,11 @@
* error) or "PREREQ_DONE" (on success)
* @param cont_cls closure for cont
*/
-void
+void
GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h,
- GNUNET_FS_IndexedFileProcessor iterator,
- void *iterator_cls,
- GNUNET_SCHEDULER_Task cont,
- void *cont_cls);
+ GNUNET_FS_IndexedFileProcessor iterator,
+ void *iterator_cls,
+ GNUNET_SCHEDULER_Task cont, void *cont_cls);
/**
@@ -2172,10 +2189,10 @@
* @param cctx initial value for the client context
* @return NULL on error, otherwise handle
*/
-struct GNUNET_FS_UnindexContext *
-GNUNET_FS_unindex_start (struct GNUNET_FS_Handle *h,
- const char *filename,
- void *cctx);
+struct GNUNET_FS_UnindexContext *GNUNET_FS_unindex_start (struct
+ GNUNET_FS_Handle *h,
+ const char *filename,
+ void *cctx);
/**
@@ -2183,8 +2200,7 @@
*
* @param uc handle
*/
-void
-GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc);
+void GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc);
/**
@@ -2201,13 +2217,13 @@
*/
void
GNUNET_FS_namespace_advertise (struct GNUNET_FS_Handle *h,
- struct GNUNET_FS_Uri *ksk_uri,
- struct GNUNET_FS_Namespace *namespace,
- const struct GNUNET_CONTAINER_MetaData *meta,
- const struct GNUNET_FS_BlockOptions *bo,
- const char *rootEntry,
- GNUNET_FS_PublishContinuation cont,
- void *cont_cls);
+ struct GNUNET_FS_Uri *ksk_uri,
+ struct GNUNET_FS_Namespace *namespace,
+ const struct GNUNET_CONTAINER_MetaData *meta,
+ const struct GNUNET_FS_BlockOptions *bo,
+ const char *rootEntry,
+ GNUNET_FS_PublishContinuation cont,
+ void *cont_cls);
/**
@@ -2218,9 +2234,8 @@
* @param name name to use for the namespace
* @return handle to the namespace, NULL on error
*/
-struct GNUNET_FS_Namespace *
-GNUNET_FS_namespace_create (struct GNUNET_FS_Handle *h,
- const char *name);
+struct GNUNET_FS_Namespace *GNUNET_FS_namespace_create (struct GNUNET_FS_Handle
+ *h, const char *name);
/**
@@ -2234,9 +2249,8 @@
*
* @return GNUNET_OK on success, GNUNET_SYSERR on error
*/
-int
-GNUNET_FS_namespace_delete (struct GNUNET_FS_Namespace *namespace,
- int freeze);
+int
+GNUNET_FS_namespace_delete (struct GNUNET_FS_Namespace *namespace, int freeze);
/**
@@ -2249,8 +2263,8 @@
* @param id hash identifier for the namespace
*/
typedef void (*GNUNET_FS_NamespaceInfoProcessor) (void *cls,
- const char *name,
- const GNUNET_HashCode *id);
+ const char *name,
+ const GNUNET_HashCode * id);
/**
@@ -2262,10 +2276,9 @@
* @param cb function to call on each known namespace
* @param cb_cls closure for cb
*/
-void
+void
GNUNET_FS_namespace_list (struct GNUNET_FS_Handle *h,
- GNUNET_FS_NamespaceInfoProcessor cb,
- void *cb_cls);
+ GNUNET_FS_NamespaceInfoProcessor cb, void *cb_cls);
/**
@@ -2277,12 +2290,12 @@
* @param last_meta metadata associated with last_uri
* @param next_id identifier that should be used for updates
*/
-typedef void
-(*GNUNET_FS_IdentifierProcessor)(void *cls,
- const char *last_id,
- const struct GNUNET_FS_Uri *last_uri,
- const struct GNUNET_CONTAINER_MetaData
*last_meta,
- const char *next_id);
+typedef void
+ (*GNUNET_FS_IdentifierProcessor) (void *cls,
+ const char *last_id,
+ const struct GNUNET_FS_Uri * last_uri,
+ const struct GNUNET_CONTAINER_MetaData *
+ last_meta, const char *next_id);
/**
@@ -2307,30 +2320,29 @@
*/
void
GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Namespace *namespace,
- const char *next_id,
- GNUNET_FS_IdentifierProcessor ip,
- void *ip_cls);
+ const char *next_id,
+ GNUNET_FS_IdentifierProcessor ip,
+ void *ip_cls);
/**
* Options for searching. Compatible options
* can be OR'ed together.
*/
-enum GNUNET_FS_SearchOptions
- {
+enum GNUNET_FS_SearchOptions
+{
/**
* No options (use defaults for everything).
*/
- GNUNET_FS_SEARCH_OPTION_NONE = 0,
+ GNUNET_FS_SEARCH_OPTION_NONE = 0,
/**
* Only search the local host, do not search remote systems (no P2P)
*/
- GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY = 1
+ GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY = 1
+};
- };
-
/**
* Start search for content.
*
@@ -2342,12 +2354,14 @@
* @param cctx initial value for the client context
* @return context that can be used to control the search
*/
-struct GNUNET_FS_SearchContext *
-GNUNET_FS_search_start (struct GNUNET_FS_Handle *h,
- const struct GNUNET_FS_Uri *uri,
- uint32_t anonymity,
- enum GNUNET_FS_SearchOptions options,
- void *cctx);
+struct GNUNET_FS_SearchContext *GNUNET_FS_search_start (struct GNUNET_FS_Handle
+ *h,
+ const struct
+ GNUNET_FS_Uri *uri,
+ uint32_t anonymity,
+ enum
+ GNUNET_FS_SearchOptions
+ options, void *cctx);
/**
@@ -2355,8 +2369,7 @@
*
* @param sc context for the search that should be paused
*/
-void
-GNUNET_FS_search_pause (struct GNUNET_FS_SearchContext *sc);
+void GNUNET_FS_search_pause (struct GNUNET_FS_SearchContext *sc);
/**
@@ -2364,8 +2377,7 @@
*
* @param sc context for the search that should be resumed
*/
-void
-GNUNET_FS_search_continue (struct GNUNET_FS_SearchContext *sc);
+void GNUNET_FS_search_continue (struct GNUNET_FS_SearchContext *sc);
/**
@@ -2373,8 +2385,7 @@
*
* @param sc context for the search that should be stopped
*/
-void
-GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc);
+void GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc);
@@ -2383,29 +2394,29 @@
* Options for downloading. Compatible options
* can be OR'ed together.
*/
-enum GNUNET_FS_DownloadOptions
- {
+enum GNUNET_FS_DownloadOptions
+{
/**
* No options (use defaults for everything).
*/
- GNUNET_FS_DOWNLOAD_OPTION_NONE = 0,
+ GNUNET_FS_DOWNLOAD_OPTION_NONE = 0,
/**
* Only download from the local host, do not access remote systems (no P2P)
*/
- GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY = 1,
-
+ GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY = 1,
+
/**
* Do a recursive download (that is, automatically trigger the
* download of files in directories).
*/
- GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE = 2,
+ GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE = 2,
/**
* Do not append temporary data to
* the target file (for the IBlocks).
*/
- GNUNET_FS_DOWNLOAD_NO_TEMPORARIES = 4,
+ GNUNET_FS_DOWNLOAD_NO_TEMPORARIES = 4,
/**
* Internal option used to flag this download as a 'probe' for a
@@ -2414,12 +2425,11 @@
* Also, probe downloads are not serialized on suspension. Normal
* clients should not use this!
*/
- GNUNET_FS_DOWNLOAD_IS_PROBE = (1<<31)
+ GNUNET_FS_DOWNLOAD_IS_PROBE = (1 << 31)
+};
- };
-
/**
* Download parts of a file. Note that this will store
* the blocks at the respective offset in the given file. Also, the
@@ -2450,18 +2460,26 @@
* for top-level downloads; useful for manually-triggered recursive
downloads)
* @return context that can be used to control this download
*/
-struct GNUNET_FS_DownloadContext *
-GNUNET_FS_download_start (struct GNUNET_FS_Handle *h,
- const struct GNUNET_FS_Uri *uri,
- const struct GNUNET_CONTAINER_MetaData *meta,
- const char *filename,
- const char *tempname,
- uint64_t offset,
- uint64_t length,
- uint32_t anonymity,
- enum GNUNET_FS_DownloadOptions options,
- void *cctx,
- struct GNUNET_FS_DownloadContext *parent);
+struct GNUNET_FS_DownloadContext *GNUNET_FS_download_start (struct
+ GNUNET_FS_Handle
*h,
+ const struct
+ GNUNET_FS_Uri *uri,
+ const struct
+
GNUNET_CONTAINER_MetaData
+ *meta,
+ const char
+ *filename,
+ const char
+ *tempname,
+ uint64_t offset,
+ uint64_t length,
+ uint32_t anonymity,
+ enum
+
GNUNET_FS_DownloadOptions
+ options, void
*cctx,
+ struct
+
GNUNET_FS_DownloadContext
+ *parent);
/**
@@ -2498,16 +2516,29 @@
* @param cctx initial value for the client context for this download
* @return context that can be used to control this download
*/
-struct GNUNET_FS_DownloadContext *
-GNUNET_FS_download_start_from_search (struct GNUNET_FS_Handle *h,
- struct GNUNET_FS_SearchResult *sr,
- const char *filename,
- const char *tempname,
- uint64_t offset,
- uint64_t length,
- uint32_t anonymity,
- enum GNUNET_FS_DownloadOptions options,
- void *cctx);
+struct GNUNET_FS_DownloadContext *GNUNET_FS_download_start_from_search (struct
+
GNUNET_FS_Handle
+ *h,
+ struct
+
GNUNET_FS_SearchResult
+ *sr,
+ const
+ char
+
*filename,
+ const
+ char
+
*tempname,
+
uint64_t
+ offset,
+
uint64_t
+ length,
+
uint32_t
+
anonymity,
+ enum
+
GNUNET_FS_DownloadOptions
+
options,
+ void
+ *cctx);
/**
@@ -2517,8 +2548,7 @@
* @param do_delete delete files of incomplete downloads
*/
void
-GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc,
- int do_delete);
+GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc, int do_delete);
@@ -2536,8 +2566,9 @@
* @return GNUNET_YES if it is, GNUNET_NO if it is not, GNUNET_SYSERR if
* we have no mime-type information (treat as 'GNUNET_NO')
*/
-int
-GNUNET_FS_meta_data_test_for_directory (const struct GNUNET_CONTAINER_MetaData
*md);
+int
+GNUNET_FS_meta_data_test_for_directory (const struct GNUNET_CONTAINER_MetaData
+ *md);
/**
@@ -2546,8 +2577,7 @@
*
* @param md metadata to add mimetype to
*/
-void
-GNUNET_FS_meta_data_make_directory (struct GNUNET_CONTAINER_MetaData *md);
+void GNUNET_FS_meta_data_make_directory (struct GNUNET_CONTAINER_MetaData *md);
/**
@@ -2556,8 +2586,8 @@
* @param md given meta data
* @return NULL if meta data is useless for suggesting a filename
*/
-char *
-GNUNET_FS_meta_data_suggest_filename (const struct GNUNET_CONTAINER_MetaData
*md);
+char *GNUNET_FS_meta_data_suggest_filename (const struct
+ GNUNET_CONTAINER_MetaData *md);
/**
@@ -2575,12 +2605,14 @@
* embedded with the directory itself).
* @param data data available for the file (length bytes)
*/
-typedef void (*GNUNET_FS_DirectoryEntryProcessor)(void *cls,
- const char *filename,
- const struct GNUNET_FS_Uri
*uri,
- const struct
GNUNET_CONTAINER_MetaData *meta,
- size_t length,
- const void *data);
+typedef void (*GNUNET_FS_DirectoryEntryProcessor) (void *cls,
+ const char *filename,
+ const struct GNUNET_FS_Uri *
+ uri,
+ const struct
+ GNUNET_CONTAINER_MetaData *
+ meta, size_t length,
+ const void *data);
/**
@@ -2602,12 +2634,12 @@
* GNUNET_NO if this could be part of a directory (but not 100% OK)
* GNUNET_SYSERR if 'data' does not represent a directory
*/
-int
+int
GNUNET_FS_directory_list_contents (size_t size,
- const void *data,
- uint64_t offset,
- GNUNET_FS_DirectoryEntryProcessor dep,
- void *dep_cls);
+ const void *data,
+ uint64_t offset,
+ GNUNET_FS_DirectoryEntryProcessor dep,
+ void *dep_cls);
/**
@@ -2620,8 +2652,10 @@
*
* @param mdir metadata for the directory
*/
-struct GNUNET_FS_DirectoryBuilder *
-GNUNET_FS_directory_builder_create (const struct GNUNET_CONTAINER_MetaData
*mdir);
+struct GNUNET_FS_DirectoryBuilder *GNUNET_FS_directory_builder_create (const
+ struct
+
GNUNET_CONTAINER_MetaData
+ *mdir);
/**
@@ -2636,11 +2670,11 @@
*/
void
GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld,
- const struct GNUNET_FS_Uri *uri,
- const struct GNUNET_CONTAINER_MetaData *md,
- const void *data);
-
+ const struct GNUNET_FS_Uri *uri,
+ const struct GNUNET_CONTAINER_MetaData *md,
+ const void *data);
+
/**
* Finish building the directory. Frees the
* builder context and returns the directory
@@ -2653,8 +2687,7 @@
*/
int
GNUNET_FS_directory_builder_finish (struct GNUNET_FS_DirectoryBuilder *bld,
- size_t *rsize,
- void **rdata);
+ size_t * rsize, void **rdata);
#if 0 /* keep Emacsens' auto-indent happy */
Modified: gnunet/src/include/gnunet_getopt_lib.h
===================================================================
--- gnunet/src/include/gnunet_getopt_lib.h 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/include/gnunet_getopt_lib.h 2011-08-15 21:46:35 UTC (rev
16581)
@@ -86,11 +86,11 @@
* @return GNUNET_OK to continue processing other options, GNUNET_SYSERR to
abort
*/
typedef
- int (*GNUNET_GETOPT_CommandLineOptionProcessor) (struct
-
GNUNET_GETOPT_CommandLineProcessorContext
- * ctx, void *scls,
- const char *option,
- const char *value);
+ int (*GNUNET_GETOPT_CommandLineOptionProcessor) (struct
+
GNUNET_GETOPT_CommandLineProcessorContext
+ * ctx, void *scls,
+ const char *option,
+ const char *value);
/**
* @brief Definition of a command line option.
Modified: gnunet/src/include/gnunet_hello_lib.h
===================================================================
--- gnunet/src/include/gnunet_hello_lib.h 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/include/gnunet_hello_lib.h 2011-08-15 21:46:35 UTC (rev
16581)
@@ -61,6 +61,13 @@
* the target buffer was not big enough.
*/
size_t
+
+
+
+
+
+
+
GNUNET_HELLO_add_address (const char *tname,
struct GNUNET_TIME_Absolute expiration,
const void *addr,
@@ -79,8 +86,8 @@
* end of the iteration.
*/
typedef size_t
- (*GNUNET_HELLO_GenerateAddressListCallback) (void *cls,
- size_t max, void *buf);
+ (*GNUNET_HELLO_GenerateAddressListCallback) (void *cls,
+ size_t max, void *buf);
/**
@@ -136,12 +143,11 @@
* zero if the some addresses with expirations >= now
* do not match at all
*/
-struct GNUNET_TIME_Absolute
+struct GNUNET_TIME_Absolute
GNUNET_HELLO_equals (const struct
- GNUNET_HELLO_Message *h1,
- const struct
- GNUNET_HELLO_Message *h2,
- struct GNUNET_TIME_Absolute now);
+ GNUNET_HELLO_Message *h1,
+ const struct
+ GNUNET_HELLO_Message *h2, struct GNUNET_TIME_Absolute
now);
/**
@@ -157,11 +163,10 @@
* GNUNET_SYSERR to stop iterating (but keep current address)
*/
typedef int
- (*GNUNET_HELLO_AddressIterator) (void *cls,
- const char *tname,
- struct GNUNET_TIME_Absolute expiration,
- const void *addr,
- uint16_t addrlen);
+ (*GNUNET_HELLO_AddressIterator) (void *cls,
+ const char *tname,
+ struct GNUNET_TIME_Absolute expiration,
+ const void *addr, uint16_t addrlen);
/**
@@ -182,8 +187,7 @@
int
return_modified,
GNUNET_HELLO_AddressIterator
- it,
- void *it_cls);
+ it, void *it_cls);
/**
@@ -230,7 +234,7 @@
*/
int
GNUNET_HELLO_get_id (const struct GNUNET_HELLO_Message *hello,
- struct GNUNET_PeerIdentity *peer);
+ struct GNUNET_PeerIdentity *peer);
/**
@@ -241,8 +245,9 @@
*
* @return header or NULL if the HELLO was malformed
*/
-struct GNUNET_MessageHeader *
-GNUNET_HELLO_get_header (struct GNUNET_HELLO_Message *hello);
+struct GNUNET_MessageHeader *GNUNET_HELLO_get_header (struct
+ GNUNET_HELLO_Message
+ *hello);
/* ifndef GNUNET_HELLO_LIB_H */
#endif
Modified: gnunet/src/include/gnunet_load_lib.h
===================================================================
--- gnunet/src/include/gnunet_load_lib.h 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/include/gnunet_load_lib.h 2011-08-15 21:46:35 UTC (rev
16581)
@@ -51,8 +51,8 @@
* frequency, 0-load values will be added to the load
* @return the new load value
*/
-struct GNUNET_LOAD_Value *
-GNUNET_LOAD_value_init (struct GNUNET_TIME_Relative autodecline);
+struct GNUNET_LOAD_Value *GNUNET_LOAD_value_init (struct GNUNET_TIME_Relative
+ autodecline);
/**
@@ -63,7 +63,7 @@
*/
void
GNUNET_LOAD_value_set_decline (struct GNUNET_LOAD_Value *load,
- struct GNUNET_TIME_Relative autodecline);
+ struct GNUNET_TIME_Relative autodecline);
/**
@@ -83,8 +83,7 @@
* 100 if the latest updates were so large
* that we could not do proper calculations
*/
-double
-GNUNET_LOAD_get_load (struct GNUNET_LOAD_Value *load);
+double GNUNET_LOAD_get_load (struct GNUNET_LOAD_Value *load);
/**
@@ -93,8 +92,7 @@
* @param load load handle
* @return zero if update was never called
*/
-double
-GNUNET_LOAD_get_average (struct GNUNET_LOAD_Value *load);
+double GNUNET_LOAD_get_average (struct GNUNET_LOAD_Value *load);
/**
@@ -103,9 +101,7 @@
* @param load to update
* @param data latest measurement value (for example, delay)
*/
-void
-GNUNET_LOAD_update (struct GNUNET_LOAD_Value *load,
- uint64_t data);
+void GNUNET_LOAD_update (struct GNUNET_LOAD_Value *load, uint64_t data);
#if 0 /* keep Emacsens' auto-indent happy */
Modified: gnunet/src/include/gnunet_mesh_service.h
===================================================================
--- gnunet/src/include/gnunet_mesh_service.h 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/include/gnunet_mesh_service.h 2011-08-15 21:46:35 UTC (rev
16581)
@@ -68,12 +68,13 @@
* GNUNET_SYSERR to close it (signal serious error)
*/
typedef int
- (*GNUNET_MESH_MessageCallback) (void *cls,
- struct GNUNET_MESH_Tunnel *tunnel,
- void **tunnel_ctx,
- const struct GNUNET_PeerIdentity *sender,
- const struct GNUNET_MessageHeader *message,
- const struct GNUNET_TRANSPORT_ATS_Information
*atsi);
+ (*GNUNET_MESH_MessageCallback) (void *cls,
+ struct GNUNET_MESH_Tunnel * tunnel,
+ void **tunnel_ctx,
+ const struct GNUNET_PeerIdentity * sender,
+ const struct GNUNET_MessageHeader *
message,
+ const struct
+ GNUNET_TRANSPORT_ATS_Information * atsi);
/**
@@ -110,9 +111,9 @@
* @param tunnel connection to the other end (henceforth invalid)
* @param tunnel_ctx place where local state associated with the tunnel is
stored
*/
-typedef void (GNUNET_MESH_TunnelEndHandler)(void *cls,
- const struct GNUNET_MESH_Tunnel
*tunnel,
- void **tunnel_ctx);
+typedef void (GNUNET_MESH_TunnelEndHandler) (void *cls,
+ const struct GNUNET_MESH_Tunnel *
+ tunnel, void **tunnel_ctx);
/**
@@ -135,12 +136,17 @@
* @return handle to the mesh service
* NULL on error (in this case, init is never called)
*/
-struct GNUNET_MESH_Handle *
-GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
- void *cls,
- GNUNET_MESH_TunnelEndHandler cleaner,
- const struct GNUNET_MESH_MessageHandler *handlers,
- const GNUNET_MESH_ApplicationType *stypes);
+struct GNUNET_MESH_Handle *GNUNET_MESH_connect (const struct
+ GNUNET_CONFIGURATION_Handle
+ *cfg, void *cls,
+ GNUNET_MESH_TunnelEndHandler
+ cleaner,
+ const struct
+ GNUNET_MESH_MessageHandler
+ *handlers,
+ const
+ GNUNET_MESH_ApplicationType
+ *stypes);
/**
* Get the peer on the other side of this tunnel if it is just one. Return
NULL otherwise
@@ -148,8 +154,9 @@
* @param tunnel the tunnel
* @return the peer or NULL
*/
-const struct GNUNET_PeerIdentity*
-GNUNET_MESH_get_peer(const struct GNUNET_MESH_Tunnel* tunnel);
+const struct GNUNET_PeerIdentity *GNUNET_MESH_get_peer (const struct
+ GNUNET_MESH_Tunnel
+ *tunnel);
/**
@@ -170,7 +177,9 @@
* @param peer peer identity the tunnel stopped working with
*/
typedef void (*GNUNET_MESH_TunnelDisconnectHandler) (void *cls,
- const struct
GNUNET_PeerIdentity *peer);
+ const struct
+ GNUNET_PeerIdentity *
+ peer);
/**
@@ -181,8 +190,11 @@
* @param atsi performance data for the connection
*/
typedef void (*GNUNET_MESH_TunnelConnectHandler) (void *cls,
- const struct
GNUNET_PeerIdentity *peer,
- const struct
GNUNET_TRANSPORT_ATS_Information *atsi);
+ const struct
+ GNUNET_PeerIdentity * peer,
+ const struct
+
GNUNET_TRANSPORT_ATS_Information
+ * atsi);
@@ -206,14 +218,23 @@
* @param handler_cls closure for handler
* @return NULL on error (handler will not be called), otherwise handle for
cancellation
*/
-struct GNUNET_MESH_Tunnel *
-GNUNET_MESH_peer_request_connect_any (struct GNUNET_MESH_Handle *h,
- struct GNUNET_TIME_Relative timeout,
- unsigned int num_peers,
- const struct GNUNET_PeerIdentity *peers,
- GNUNET_MESH_TunnelConnectHandler
connect_handler,
- GNUNET_MESH_TunnelDisconnectHandler
disconnect_handler,
- void *handler_cls);
+struct GNUNET_MESH_Tunnel *GNUNET_MESH_peer_request_connect_any (struct
+
GNUNET_MESH_Handle
+ *h,
+ struct
+
GNUNET_TIME_Relative
+ timeout,
+ unsigned int
+ num_peers,
+ const struct
+
GNUNET_PeerIdentity
+ *peers,
+
GNUNET_MESH_TunnelConnectHandler
+
connect_handler,
+
GNUNET_MESH_TunnelDisconnectHandler
+
disconnect_handler,
+ void
+ *handler_cls);
/**
@@ -233,14 +254,23 @@
* @param handler_cls closure for handler
* @return NULL on error (handler will not be called), otherwise handle for
cancellation
*/
-struct GNUNET_MESH_Tunnel *
-GNUNET_MESH_peer_request_connect_all (struct GNUNET_MESH_Handle *h,
- struct GNUNET_TIME_Relative timeout,
- unsigned int num_peers,
- const struct GNUNET_PeerIdentity *peers,
- GNUNET_MESH_TunnelConnectHandler
connect_handler,
- GNUNET_MESH_TunnelDisconnectHandler
disconnect_handler,
- void *handler_cls);
+struct GNUNET_MESH_Tunnel *GNUNET_MESH_peer_request_connect_all (struct
+
GNUNET_MESH_Handle
+ *h,
+ struct
+
GNUNET_TIME_Relative
+ timeout,
+ unsigned int
+ num_peers,
+ const struct
+
GNUNET_PeerIdentity
+ *peers,
+
GNUNET_MESH_TunnelConnectHandler
+
connect_handler,
+
GNUNET_MESH_TunnelDisconnectHandler
+
disconnect_handler,
+ void
+ *handler_cls);
/**
@@ -253,8 +283,8 @@
*/
void
GNUNET_MESH_peer_request_connect_add (struct GNUNET_MESH_Tunnel *tunnel,
- struct GNUNET_TIME_Relative timeout,
- const struct GNUNET_PeerIdentity *peer);
+ struct GNUNET_TIME_Relative timeout,
+ const struct GNUNET_PeerIdentity *peer);
/**
@@ -266,7 +296,7 @@
*/
void
GNUNET_MESH_peer_request_connect_del (struct GNUNET_MESH_Tunnel *tunnel,
- const struct GNUNET_PeerIdentity *peer);
+ const struct GNUNET_PeerIdentity *peer);
/**
@@ -286,13 +316,20 @@
* @param handler_cls closure for handler
* @return NULL on error (handler will not be called), otherwise handle for
cancellation
*/
-struct GNUNET_MESH_Tunnel *
-GNUNET_MESH_peer_request_connect_by_type (struct GNUNET_MESH_Handle *h,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_MESH_ApplicationType app_type,
- GNUNET_MESH_TunnelConnectHandler
connect_handler,
- GNUNET_MESH_TunnelDisconnectHandler
disconnect_handler,
- void *handler_cls);
+struct GNUNET_MESH_Tunnel *GNUNET_MESH_peer_request_connect_by_type (struct
+
GNUNET_MESH_Handle
+ *h,
+ struct
+
GNUNET_TIME_Relative
+ timeout,
+
GNUNET_MESH_ApplicationType
+ app_type,
+
GNUNET_MESH_TunnelConnectHandler
+
connect_handler,
+
GNUNET_MESH_TunnelDisconnectHandler
+
disconnect_handler,
+ void
+
*handler_cls);
/**
@@ -301,8 +338,7 @@
*
* @param req request handle that was returned for the original request
*/
-void
-GNUNET_MESH_peer_request_connect_cancel (struct GNUNET_MESH_Tunnel *req);
+void GNUNET_MESH_peer_request_connect_cancel (struct GNUNET_MESH_Tunnel *req);
/**
@@ -332,22 +368,25 @@
* NULL if we can not even queue the request (insufficient
* memory); if NULL is returned, "notify" will NOT be called.
*/
-struct GNUNET_MESH_TransmitHandle *
-GNUNET_MESH_notify_transmit_ready (struct
- GNUNET_MESH_Tunnel
- *tunnel,
- int cork,
- uint32_t priority,
- struct
- GNUNET_TIME_Relative
- maxdelay,
- const struct GNUNET_PeerIdentity *target,
- size_t
- notify_size,
- GNUNET_CONNECTION_TransmitReadyNotify
- notify,
- void
- *notify_cls);
+struct GNUNET_MESH_TransmitHandle *GNUNET_MESH_notify_transmit_ready (struct
+
GNUNET_MESH_Tunnel
+ *tunnel,
+ int cork,
+ uint32_t
+ priority,
+ struct
+
GNUNET_TIME_Relative
+ maxdelay,
+ const
+ struct
+
GNUNET_PeerIdentity
+ *target,
+ size_t
+
notify_size,
+
GNUNET_CONNECTION_TransmitReadyNotify
+ notify,
+ void
+
*notify_cls);
/**
@@ -359,13 +398,16 @@
GNUNET_MESH_notify_transmit_ready_cancel (struct GNUNET_MESH_TransmitHandle
*th);
-void GNUNET_MESH_tunnel_set_head(struct GNUNET_MESH_Tunnel* tunnel, void*
head);
-void GNUNET_MESH_tunnel_set_tail(struct GNUNET_MESH_Tunnel* tunnel, void*
tail);
-void* GNUNET_MESH_tunnel_get_head(struct GNUNET_MESH_Tunnel* tunnel);
-void* GNUNET_MESH_tunnel_get_tail(struct GNUNET_MESH_Tunnel* tunnel);
+void GNUNET_MESH_tunnel_set_head (struct GNUNET_MESH_Tunnel *tunnel,
+ void *head);
+void GNUNET_MESH_tunnel_set_tail (struct GNUNET_MESH_Tunnel *tunnel,
+ void *tail);
+void *GNUNET_MESH_tunnel_get_head (struct GNUNET_MESH_Tunnel *tunnel);
+void *GNUNET_MESH_tunnel_get_tail (struct GNUNET_MESH_Tunnel *tunnel);
-void GNUNET_MESH_tunnel_set_data(struct GNUNET_MESH_Tunnel* tunnel, void*
data);
-void* GNUNET_MESH_tunnel_get_data(struct GNUNET_MESH_Tunnel* tunnel);
+void GNUNET_MESH_tunnel_set_data (struct GNUNET_MESH_Tunnel *tunnel,
+ void *data);
+void *GNUNET_MESH_tunnel_get_data (struct GNUNET_MESH_Tunnel *tunnel);
#if 0 /* keep Emacsens' auto-indent happy */
{
Modified: gnunet/src/include/gnunet_mesh_service_new.h
===================================================================
--- gnunet/src/include/gnunet_mesh_service_new.h 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/include/gnunet_mesh_service_new.h 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -68,13 +68,13 @@
* GNUNET_SYSERR to close it (signal serious error)
*/
typedef int
- (*GNUNET_MESH_MessageCallback) (void *cls,
- struct GNUNET_MESH_Tunnel *tunnel,
- void **tunnel_ctx,
- const struct GNUNET_PeerIdentity *sender,
- const struct GNUNET_MessageHeader *message,
- const struct GNUNET_TRANSPORT_ATS_Information
- *atsi);
+ (*GNUNET_MESH_MessageCallback) (void *cls,
+ struct GNUNET_MESH_Tunnel * tunnel,
+ void **tunnel_ctx,
+ const struct GNUNET_PeerIdentity * sender,
+ const struct GNUNET_MessageHeader *
message,
+ const struct
+ GNUNET_TRANSPORT_ATS_Information * atsi);
/**
@@ -112,10 +112,9 @@
* @param tunnel_ctx place where local state associated
* with the tunnel is stored
*/
-typedef void (GNUNET_MESH_TunnelEndHandler)(void *cls,
- const struct GNUNET_MESH_Tunnel
- *tunnel,
- void **tunnel_ctx);
+typedef void (GNUNET_MESH_TunnelEndHandler) (void *cls,
+ const struct GNUNET_MESH_Tunnel
+ * tunnel, void **tunnel_ctx);
/**
@@ -139,12 +138,17 @@
* @return handle to the mesh service NULL on error
* (in this case, init is never called)
*/
-struct GNUNET_MESH_Handle *
-GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
- void *cls,
- GNUNET_MESH_TunnelEndHandler cleaner,
- const struct GNUNET_MESH_MessageHandler *handlers,
- const GNUNET_MESH_ApplicationType *stypes);
+struct GNUNET_MESH_Handle *GNUNET_MESH_connect (const struct
+ GNUNET_CONFIGURATION_Handle
+ *cfg, void *cls,
+ GNUNET_MESH_TunnelEndHandler
+ cleaner,
+ const struct
+ GNUNET_MESH_MessageHandler
+ *handlers,
+ const
+ GNUNET_MESH_ApplicationType
+ *stypes);
/**
@@ -162,7 +166,9 @@
* @param peer peer identity the tunnel stopped working with
*/
typedef void (*GNUNET_MESH_TunnelDisconnectHandler) (void *cls,
- const struct GNUNET_PeerIdentity
*peer);
+ const struct
+ GNUNET_PeerIdentity *
+ peer);
/**
@@ -173,8 +179,11 @@
* @param atsi performance data for the connection
*/
typedef void (*GNUNET_MESH_TunnelConnectHandler) (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_TRANSPORT_ATS_Information
*atsi);
+ const struct
+ GNUNET_PeerIdentity * peer,
+ const struct
+
GNUNET_TRANSPORT_ATS_Information
+ * atsi);
@@ -187,21 +196,20 @@
* @param disconnect_handler function to call when peers are disconnected
* @param handler_cls closure for connect/disconnect handlers
*/
-struct GNUNET_MESH_Tunnel *
-GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h,
- GNUNET_MESH_TunnelConnectHandler
- connect_handler,
- GNUNET_MESH_TunnelDisconnectHandler
- disconnect_handler,
- void *handler_cls);
+struct GNUNET_MESH_Tunnel *GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle
+ *h,
+
GNUNET_MESH_TunnelConnectHandler
+ connect_handler,
+
GNUNET_MESH_TunnelDisconnectHandler
+ disconnect_handler,
+ void *handler_cls);
/**
* Destroy an existing tunnel.
*
* @param tun tunnel handle
*/
-void
-GNUNET_MESH_tunnel_destroy (struct GNUNET_MESH_Tunnel *tun);
+void GNUNET_MESH_tunnel_destroy (struct GNUNET_MESH_Tunnel *tun);
/**
@@ -214,8 +222,8 @@
*/
void
GNUNET_MESH_peer_request_connect_add (struct GNUNET_MESH_Tunnel *tunnel,
- struct GNUNET_TIME_Relative timeout,
- const struct GNUNET_PeerIdentity *peer);
+ struct GNUNET_TIME_Relative timeout,
+ const struct GNUNET_PeerIdentity *peer);
/**
@@ -227,7 +235,7 @@
*/
void
GNUNET_MESH_peer_request_connect_del (struct GNUNET_MESH_Tunnel *tunnel,
- const struct GNUNET_PeerIdentity *peer);
+ const struct GNUNET_PeerIdentity *peer);
/**
@@ -241,8 +249,8 @@
*/
void
GNUNET_MESH_peer_request_connect_by_type (struct GNUNET_MESH_Tunnel *tunnel,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_MESH_ApplicationType app_type);
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_MESH_ApplicationType
app_type);
/**
@@ -271,22 +279,25 @@
* NULL if we can not even queue the request (insufficient
* memory); if NULL is returned, "notify" will NOT be called.
*/
-struct GNUNET_MESH_TransmitHandle *
-GNUNET_MESH_notify_transmit_ready (struct
- GNUNET_MESH_Tunnel
- *tunnel,
- int cork,
- uint32_t priority,
- struct
- GNUNET_TIME_Relative
- maxdelay,
- const struct GNUNET_PeerIdentity *target,
- size_t
- notify_size,
- GNUNET_CONNECTION_TransmitReadyNotify
- notify,
- void
- *notify_cls);
+struct GNUNET_MESH_TransmitHandle *GNUNET_MESH_notify_transmit_ready (struct
+
GNUNET_MESH_Tunnel
+ *tunnel,
+ int cork,
+ uint32_t
+ priority,
+ struct
+
GNUNET_TIME_Relative
+ maxdelay,
+ const
+ struct
+
GNUNET_PeerIdentity
+ *target,
+ size_t
+
notify_size,
+
GNUNET_CONNECTION_TransmitReadyNotify
+ notify,
+ void
+
*notify_cls);
/**
Modified: gnunet/src/include/gnunet_nat_lib.h
===================================================================
--- gnunet/src/include/gnunet_nat_lib.h 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/include/gnunet_nat_lib.h 2011-08-15 21:46:35 UTC (rev 16581)
@@ -41,9 +41,9 @@
* @param addr either the previous or the new public IP address
* @param addrlen actual lenght of the address
*/
-typedef void (*GNUNET_NAT_AddressCallback) (void *cls,
- int add_remove,
- const struct sockaddr *addr,
+typedef void (*GNUNET_NAT_AddressCallback) (void *cls,
+ int add_remove,
+ const struct sockaddr * addr,
socklen_t addrlen);
@@ -56,9 +56,9 @@
* @param addr public IP address of the other peer
* @param addrlen actual lenght of the address
*/
-typedef void (*GNUNET_NAT_ReversalCallback) (void *cls,
- const struct sockaddr *addr,
- socklen_t addrlen);
+typedef void (*GNUNET_NAT_ReversalCallback) (void *cls,
+ const struct sockaddr * addr,
+ socklen_t addrlen);
/**
@@ -87,16 +87,17 @@
* @param callback_cls closure for callback
* @return NULL on error, otherwise handle that can be used to unregister
*/
-struct GNUNET_NAT_Handle *
-GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg,
- int is_tcp,
- uint16_t adv_port,
- unsigned int num_addrs,
- const struct sockaddr **addrs,
- const socklen_t *addrlens,
- GNUNET_NAT_AddressCallback address_callback,
- GNUNET_NAT_ReversalCallback reversal_callback,
- void *callback_cls);
+struct GNUNET_NAT_Handle *GNUNET_NAT_register (const struct
+ GNUNET_CONFIGURATION_Handle
*cfg,
+ int is_tcp, uint16_t adv_port,
+ unsigned int num_addrs,
+ const struct sockaddr **addrs,
+ const socklen_t * addrlens,
+ GNUNET_NAT_AddressCallback
+ address_callback,
+ GNUNET_NAT_ReversalCallback
+ reversal_callback,
+ void *callback_cls);
/**
@@ -111,8 +112,7 @@
*/
int
GNUNET_NAT_test_address (struct GNUNET_NAT_Handle *h,
- const void *addr,
- socklen_t addrlen);
+ const void *addr, socklen_t addrlen);
/**
@@ -125,7 +125,7 @@
*/
void
GNUNET_NAT_run_client (struct GNUNET_NAT_Handle *h,
- const struct sockaddr_in *sa);
+ const struct sockaddr_in *sa);
@@ -135,8 +135,7 @@
*
* @param h the handle to stop
*/
-void
-GNUNET_NAT_unregister (struct GNUNET_NAT_Handle *h);
+void GNUNET_NAT_unregister (struct GNUNET_NAT_Handle *h);
/**
@@ -153,8 +152,7 @@
* GNUNET_SYSERR if the test could not be
* properly started (internal failure)
*/
-typedef void (*GNUNET_NAT_TestCallback)(void *cls,
- int success);
+typedef void (*GNUNET_NAT_TestCallback) (void *cls, int success);
/**
* Start testing if NAT traversal works using the
@@ -168,13 +166,12 @@
* @param report_cls closure for report
* @return handle to cancel NAT test
*/
-struct GNUNET_NAT_Test *
-GNUNET_NAT_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
- int is_tcp,
- uint16_t bnd_port,
- uint16_t adv_port,
- GNUNET_NAT_TestCallback report,
- void *report_cls);
+struct GNUNET_NAT_Test *GNUNET_NAT_test_start (const struct
+ GNUNET_CONFIGURATION_Handle
*cfg,
+ int is_tcp, uint16_t bnd_port,
+ uint16_t adv_port,
+ GNUNET_NAT_TestCallback report,
+ void *report_cls);
/**
@@ -182,8 +179,7 @@
*
* @param tst test to stop.
*/
-void
-GNUNET_NAT_test_stop (struct GNUNET_NAT_Test *tst);
+void GNUNET_NAT_test_stop (struct GNUNET_NAT_Test *tst);
/**
@@ -192,8 +188,7 @@
* @param cls closure
* @param addr the address, NULL on errors
*/
-typedef void (*GNUNET_NAT_IPCallback)(void *cls,
- const struct in_addr *addr);
+typedef void (*GNUNET_NAT_IPCallback) (void *cls, const struct in_addr * addr);
@@ -211,10 +206,13 @@
* @param cb_cls closure for 'cb'
* @return handle for cancellation (can only be used until 'cb' is called),
NULL on error
*/
-struct GNUNET_NAT_ExternalHandle *
-GNUNET_NAT_mini_get_external_ipv4 (struct GNUNET_TIME_Relative timeout,
- GNUNET_NAT_IPCallback cb,
- void *cb_cls);
+struct GNUNET_NAT_ExternalHandle *GNUNET_NAT_mini_get_external_ipv4 (struct
+
GNUNET_TIME_Relative
+ timeout,
+
GNUNET_NAT_IPCallback
+ cb,
+ void
+ *cb_cls);
/**
@@ -228,7 +226,7 @@
/**
* Handle to a mapping created with upnpc.
- */
+ */
struct GNUNET_NAT_MiniHandle;
@@ -245,11 +243,10 @@
* @param ac_cls closure for 'ac'
* @return NULL on error
*/
-struct GNUNET_NAT_MiniHandle *
-GNUNET_NAT_mini_map_start (uint16_t port,
- int is_tcp,
- GNUNET_NAT_AddressCallback ac,
- void *ac_cls);
+struct GNUNET_NAT_MiniHandle *GNUNET_NAT_mini_map_start (uint16_t port,
+ int is_tcp,
+
GNUNET_NAT_AddressCallback
+ ac, void *ac_cls);
/**
@@ -260,10 +257,9 @@
*
* @param mini the handle
*/
-void
-GNUNET_NAT_mini_map_stop (struct GNUNET_NAT_MiniHandle *mini);
+void GNUNET_NAT_mini_map_stop (struct GNUNET_NAT_MiniHandle *mini);
-#endif
+#endif
/* end of gnunet_nat_lib.h */
Modified: gnunet/src/include/gnunet_network_lib.h
===================================================================
--- gnunet/src/include/gnunet_network_lib.h 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/include/gnunet_network_lib.h 2011-08-15 21:46:35 UTC (rev
16581)
@@ -98,8 +98,7 @@
* @param fd socket to box
* @return NULL on error (including not supported on target platform)
*/
-struct GNUNET_NETWORK_Handle *
-GNUNET_NETWORK_socket_box_native (int fd);
+struct GNUNET_NETWORK_Handle *GNUNET_NETWORK_socket_box_native (int fd);
/**
@@ -181,10 +180,16 @@
* @param addrlen length of the addr
*/
ssize_t
+
+
+
+
+
+
+
GNUNET_NETWORK_socket_recvfrom (const struct GNUNET_NETWORK_Handle *desc,
void *buffer, size_t length,
- struct sockaddr *src_addr,
- socklen_t * addrlen);
+ struct sockaddr *src_addr, socklen_t *
addrlen);
/**
@@ -322,8 +327,8 @@
* @param h the file handle to add
*/
void
-GNUNET_NETWORK_fdset_handle_set_native_w32_handle (struct GNUNET_NETWORK_FDSet
*fds,
- HANDLE h);
+GNUNET_NETWORK_fdset_handle_set_native_w32_handle (struct GNUNET_NETWORK_FDSet
+ *fds, HANDLE h);
#endif
@@ -380,8 +385,7 @@
* @param to destination
* @param nfd native FD to set
*/
-void GNUNET_NETWORK_fdset_set_native (struct GNUNET_NETWORK_FDSet *to,
- int nfd);
+void GNUNET_NETWORK_fdset_set_native (struct GNUNET_NETWORK_FDSet *to, int
nfd);
/**
@@ -391,9 +395,9 @@
* @param nfd native FD to test, -1 for none
* @return GNUNET_YES if to contains nfd
*/
-int
+int
GNUNET_NETWORK_fdset_test_native (const struct GNUNET_NETWORK_FDSet *to,
- int nfd);
+ int nfd);
/**
@@ -412,8 +416,7 @@
* @return GNUNET_YES if the file handle is part of the set
*/
int GNUNET_NETWORK_fdset_handle_isset (const struct GNUNET_NETWORK_FDSet *fds,
- const struct GNUNET_DISK_FileHandle
- *h);
+ const struct GNUNET_DISK_FileHandle *h);
/**
Modified: gnunet/src/include/gnunet_nse_service.h
===================================================================
--- gnunet/src/include/gnunet_nse_service.h 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/include/gnunet_nse_service.h 2011-08-15 21:46:35 UTC (rev
16581)
@@ -63,8 +63,7 @@
*/
typedef void (*GNUNET_NSE_Callback) (void *cls,
struct GNUNET_TIME_Absolute timestamp,
- double logestimate,
- double std_dev);
+ double logestimate, double std_dev);
/**
@@ -85,9 +84,10 @@
*
* @return handle to use
*/
-struct GNUNET_NSE_Handle *
-GNUNET_NSE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
- GNUNET_NSE_Callback func, void *func_cls);
+struct GNUNET_NSE_Handle *GNUNET_NSE_connect (const struct
+ GNUNET_CONFIGURATION_Handle *cfg,
+ GNUNET_NSE_Callback func,
+ void *func_cls);
/**
@@ -96,8 +96,7 @@
* @param h handle to destroy
*
*/
-void
-GNUNET_NSE_disconnect (struct GNUNET_NSE_Handle *h);
+void GNUNET_NSE_disconnect (struct GNUNET_NSE_Handle *h);
#if 0 /* keep Emacsens' auto-indent happy */
Modified: gnunet/src/include/gnunet_os_lib.h
===================================================================
--- gnunet/src/include/gnunet_os_lib.h 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/include/gnunet_os_lib.h 2011-08-15 21:46:35 UTC (rev 16581)
@@ -211,8 +211,7 @@
*
* @return the current process id
*/
-pid_t
-GNUNET_OS_process_get_pid (struct GNUNET_OS_Process *proc);
+pid_t GNUNET_OS_process_get_pid (struct GNUNET_OS_Process *proc);
/**
* Set process priority
@@ -234,10 +233,11 @@
* @param ... NULL-terminated list of arguments to the process
* @return pointer to process structure of the new process, NULL on error
*/
-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_OS_Process *GNUNET_OS_start_process (struct
GNUNET_DISK_PipeHandle
+ *pipe_stdin,
+ struct
GNUNET_DISK_PipeHandle
+ *pipe_stdout,
+ const char *filename, ...);
/**
@@ -249,11 +249,14 @@
* @param va NULL-terminated list of arguments to the process
* @return pointer to process structure of the new process, NULL on error
*/
-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_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);
/**
* Start a process.
@@ -265,9 +268,9 @@
* including the process name as the first argument
* @return pointer to process structure of the new process, NULL on error
*/
-struct GNUNET_OS_Process *
-GNUNET_OS_start_process_v (const int *lsocks, const char *filename,
- char *const argv[]);
+struct GNUNET_OS_Process *GNUNET_OS_start_process_v (const int *lsocks,
+ const char *filename,
+ char *const argv[]);
/**
@@ -281,16 +284,14 @@
* @param cls closure
* @param line line of output from a command, NULL for the end
*/
-typedef void (*GNUNET_OS_LineProcessor)(void *cls,
- const char *line);
+typedef void (*GNUNET_OS_LineProcessor) (void *cls, const char *line);
/**
* Stop/kill a command.
*
* @param cmd handle to the process
*/
-void
-GNUNET_OS_command_stop (struct GNUNET_OS_CommandHandle *cmd);
+void GNUNET_OS_command_stop (struct GNUNET_OS_CommandHandle *cmd);
/**
@@ -304,12 +305,12 @@
* @param ... arguments to command
* @return NULL on error
*/
-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_OS_CommandHandle *GNUNET_OS_command_run (GNUNET_OS_LineProcessor
+ proc, void *proc_cls,
+ struct
+ GNUNET_TIME_Relative
+ timeout,
+ const char *binary,
...);
/**
@@ -321,7 +322,8 @@
* @return GNUNET_OK on success, GNUNET_NO if the process is still running,
GNUNET_SYSERR otherwise
*/
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);
/**
@@ -343,7 +345,7 @@
void
GNUNET_OS_install_parent_control_handler (void *cls,
const struct
- GNUNET_SCHEDULER_TaskContext * tc);
+ GNUNET_SCHEDULER_TaskContext *tc);
/**
@@ -357,8 +359,7 @@
* GNUNET_NO if not SUID (but binary exists)
* GNUNET_SYSERR on error (no such binary or not executable)
*/
-int
-GNUNET_OS_check_helper_binary (const char *binary);
+int GNUNET_OS_check_helper_binary (const char *binary);
#if 0 /* keep Emacsens' auto-indent happy */
Modified: gnunet/src/include/gnunet_peer_lib.h
===================================================================
--- gnunet/src/include/gnunet_peer_lib.h 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/include/gnunet_peer_lib.h 2011-08-15 21:46:35 UTC (rev
16581)
@@ -63,7 +63,7 @@
* @param pid identity to intern
* @return the interned identity.
*/
-GNUNET_PEER_Id GNUNET_PEER_intern (const struct GNUNET_PeerIdentity * pid);
+GNUNET_PEER_Id GNUNET_PEER_intern (const struct GNUNET_PeerIdentity *pid);
/**
@@ -81,8 +81,7 @@
* @param ids array of PIDs to decrement the RCs of
* @param count size of the ids array
*/
-void GNUNET_PEER_decrement_rcs (const GNUNET_PEER_Id * ids,
- unsigned int count);
+void GNUNET_PEER_decrement_rcs (const GNUNET_PEER_Id *ids, unsigned int count);
/**
@@ -91,8 +90,7 @@
* @param id interned PID to convert
* @param pid where to write the normal peer identity
*/
-void GNUNET_PEER_resolve (GNUNET_PEER_Id id,
- struct GNUNET_PeerIdentity * pid);
+void GNUNET_PEER_resolve (GNUNET_PEER_Id id, struct GNUNET_PeerIdentity *pid);
/* ifndef GNUNET_PEER_LIB_H */
Modified: gnunet/src/include/gnunet_peerinfo_service.h
===================================================================
--- gnunet/src/include/gnunet_peerinfo_service.h 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/include/gnunet_peerinfo_service.h 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -54,11 +54,12 @@
* @return NULL on error (configuration related, actual connection
* etablishment may happen asynchronously).
*/
-struct GNUNET_PEERINFO_Handle *
-GNUNET_PEERINFO_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
-
+struct GNUNET_PEERINFO_Handle *GNUNET_PEERINFO_connect (const struct
+
GNUNET_CONFIGURATION_Handle
+ *cfg);
+
/**
* Disconnect from the peerinfo service. Note that all iterators must
* have completed or have been cancelled by the time this function is
@@ -68,8 +69,7 @@
*
* @param h handle to disconnect
*/
-void
-GNUNET_PEERINFO_disconnect (struct GNUNET_PEERINFO_Handle *h);
+void GNUNET_PEERINFO_disconnect (struct GNUNET_PEERINFO_Handle *h);
/**
@@ -85,7 +85,7 @@
*/
void
GNUNET_PEERINFO_add_peer (struct GNUNET_PEERINFO_Handle *h,
- const struct GNUNET_HELLO_Message *hello);
+ const struct GNUNET_HELLO_Message *hello);
/**
@@ -98,10 +98,10 @@
* @param error message
*/
typedef void
- (*GNUNET_PEERINFO_Processor) (void *cls,
- const struct GNUNET_PeerIdentity * peer,
- const struct GNUNET_HELLO_Message * hello,
- const char * err_msg);
+ (*GNUNET_PEERINFO_Processor) (void *cls,
+ const struct GNUNET_PeerIdentity * peer,
+ const struct GNUNET_HELLO_Message * hello,
+ const char *err_msg);
/**
@@ -127,12 +127,19 @@
* @return NULL on error (in this case, 'callback' is never called!),
* otherwise an iterator context
*/
-struct GNUNET_PEERINFO_IteratorContext *
-GNUNET_PEERINFO_iterate (struct GNUNET_PEERINFO_Handle *h,
- const struct GNUNET_PeerIdentity *peer,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_PEERINFO_Processor callback,
- void *callback_cls);
+struct GNUNET_PEERINFO_IteratorContext *GNUNET_PEERINFO_iterate (struct
+
GNUNET_PEERINFO_Handle
+ *h,
+ const struct
+
GNUNET_PeerIdentity
+ *peer,
+ struct
+
GNUNET_TIME_Relative
+ timeout,
+
GNUNET_PEERINFO_Processor
+ callback,
+ void
+
*callback_cls);
@@ -164,10 +171,13 @@
* @param callback_cls closure for callback
* @return NULL on error
*/
-struct GNUNET_PEERINFO_NotifyContext *
-GNUNET_PEERINFO_notify (const struct GNUNET_CONFIGURATION_Handle *cfg,
- GNUNET_PEERINFO_Processor callback,
- void *callback_cls);
+struct GNUNET_PEERINFO_NotifyContext *GNUNET_PEERINFO_notify (const struct
+
GNUNET_CONFIGURATION_Handle
+ *cfg,
+
GNUNET_PEERINFO_Processor
+ callback,
+ void
+ *callback_cls);
/**
@@ -175,8 +185,7 @@
*
* @param nc context to stop notifying
*/
-void
-GNUNET_PEERINFO_notify_cancel (struct GNUNET_PEERINFO_NotifyContext *nc);
+void GNUNET_PEERINFO_notify_cancel (struct GNUNET_PEERINFO_NotifyContext *nc);
#if 0 /* keep Emacsens' auto-indent happy */
Modified: gnunet/src/include/gnunet_pseudonym_lib.h
===================================================================
--- gnunet/src/include/gnunet_pseudonym_lib.h 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/include/gnunet_pseudonym_lib.h 2011-08-15 21:46:35 UTC (rev
16581)
@@ -64,7 +64,7 @@
* @return new rating of the namespace
*/
int GNUNET_PSEUDONYM_rank (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const GNUNET_HashCode *nsid, int delta);
+ const GNUNET_HashCode * nsid, int delta);
/**
* Add a pseudonym to the set of known pseudonyms.
@@ -76,7 +76,7 @@
* @param meta metadata for the pseudonym
*/
void GNUNET_PSEUDONYM_add (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const GNUNET_HashCode *id,
+ const GNUNET_HashCode * id,
const struct GNUNET_CONTAINER_MetaData *meta);
@@ -114,8 +114,8 @@
*
* @return NULL on failure (should never happen)
*/
-char *GNUNET_PSEUDONYM_id_to_name (const struct GNUNET_CONFIGURATION_Handle
*cfg,
- const GNUNET_HashCode * pseudo);
+char *GNUNET_PSEUDONYM_id_to_name (const struct GNUNET_CONFIGURATION_Handle
+ *cfg, const GNUNET_HashCode * pseudo);
/**
* Get the pseudonym ID belonging to the given human readable name.
Modified: gnunet/src/include/gnunet_resolver_service.h
===================================================================
--- gnunet/src/include/gnunet_resolver_service.h 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/include/gnunet_resolver_service.h 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -48,7 +48,7 @@
* @param addrlen length of the address
*/
typedef void (*GNUNET_RESOLVER_AddressCallback) (void *cls,
- const struct sockaddr *addr,
+ const struct sockaddr * addr,
socklen_t addrlen);
@@ -63,15 +63,13 @@
*
* @param cfg configuration to use
*/
-void
-GNUNET_RESOLVER_connect (const struct GNUNET_CONFIGURATION_Handle *c);
+void GNUNET_RESOLVER_connect (const struct GNUNET_CONFIGURATION_Handle *c);
/**
* Destroy the connection to the resolver service.
*/
-void
-GNUNET_RESOLVER_disconnect (void);
+void GNUNET_RESOLVER_disconnect (void);
/**
@@ -84,12 +82,16 @@
* @param timeout how long to try resolving
* @return handle that can be used to cancel the request, NULL on error
*/
-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_RESOLVER_RequestHandle *GNUNET_RESOLVER_ip_get (const char
+ *hostname,
+ int domain,
+ struct
+
GNUNET_TIME_Relative
+ timeout,
+
GNUNET_RESOLVER_AddressCallback
+ callback,
+ void
+ *callback_cls);
/**
@@ -102,11 +104,15 @@
* @param timeout how long to try resolving
* @return handle that can be used to cancel the request, NULL on error
*/
-struct GNUNET_RESOLVER_RequestHandle *
-GNUNET_RESOLVER_hostname_resolve (int domain,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_RESOLVER_AddressCallback callback,
- void *cls);
+struct GNUNET_RESOLVER_RequestHandle *GNUNET_RESOLVER_hostname_resolve (int
+ domain,
+ struct
+
GNUNET_TIME_Relative
+
timeout,
+
GNUNET_RESOLVER_AddressCallback
+
callback,
+ void
+ *cls);
/**
@@ -124,8 +130,7 @@
*
* @return local hostname, caller must free
*/
-char *
-GNUNET_RESOLVER_local_fqdn_get (void);
+char *GNUNET_RESOLVER_local_fqdn_get (void);
/**
@@ -140,13 +145,19 @@
* @param cls closure for callback
* @return handle that can be used to cancel the request, NULL on error
*/
-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);
+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);
/**
@@ -157,8 +168,7 @@
*
* @param rh handle of request to cancel
*/
-void
-GNUNET_RESOLVER_request_cancel (struct GNUNET_RESOLVER_RequestHandle *rh);
+void GNUNET_RESOLVER_request_cancel (struct GNUNET_RESOLVER_RequestHandle *rh);
#if 0 /* keep Emacsens' auto-indent happy */
Modified: gnunet/src/include/gnunet_scheduler_lib.h
===================================================================
--- gnunet/src/include/gnunet_scheduler_lib.h 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/include/gnunet_scheduler_lib.h 2011-08-15 21:46:35 UTC (rev
16581)
@@ -206,10 +206,10 @@
* @return number of selected sockets, GNUNET_SYSERR on error
*/
typedef int (*GNUNET_SCHEDULER_select) (void *cls,
- struct GNUNET_NETWORK_FDSet *rfds,
- struct GNUNET_NETWORK_FDSet *wfds,
- struct GNUNET_NETWORK_FDSet *efds,
- struct GNUNET_TIME_Relative timeout);
+ struct GNUNET_NETWORK_FDSet * rfds,
+ struct GNUNET_NETWORK_FDSet * wfds,
+ struct GNUNET_NETWORK_FDSet * efds,
+ struct GNUNET_TIME_Relative timeout);
/**
* Initialize and run scheduler. This function will return when all
* tasks have completed. On systems with signals, receiving a SIGTERM
@@ -258,8 +258,7 @@
*
* * @return reason(s) why the current task is run
*/
-enum GNUNET_SCHEDULER_Reason
-GNUNET_SCHEDULER_get_reason ();
+enum GNUNET_SCHEDULER_Reason GNUNET_SCHEDULER_get_reason ();
/**
@@ -305,8 +304,7 @@
*/
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);
/**
@@ -320,8 +318,7 @@
*/
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);
/**
@@ -334,8 +331,7 @@
* only valid until "task" is started!
*/
GNUNET_SCHEDULER_TaskIdentifier
-GNUNET_SCHEDULER_add_now (GNUNET_SCHEDULER_Task task,
- void *task_cls);
+GNUNET_SCHEDULER_add_now (GNUNET_SCHEDULER_Task task, void *task_cls);
/**
@@ -354,8 +350,8 @@
*/
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);
/**
@@ -372,8 +368,7 @@
*/
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);
/**
@@ -394,9 +389,8 @@
*/
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);
/**
@@ -417,9 +411,8 @@
*/
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);
/**
@@ -440,9 +433,8 @@
*/
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);
/**
@@ -463,9 +455,8 @@
*/
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);
/**
@@ -505,10 +496,9 @@
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);
+ const struct GNUNET_NETWORK_FDSet *rs,
+ const struct GNUNET_NETWORK_FDSet *ws,
+ GNUNET_SCHEDULER_Task task, void *task_cls);
/**
* Sets the select function to use in the scheduler (scheduler_select).
@@ -518,7 +508,7 @@
*/
void
GNUNET_SCHEDULER_set_select (GNUNET_SCHEDULER_select new_select,
- void *new_select_cls);
+ void *new_select_cls);
#if 0 /* keep Emacsens' auto-indent happy */
Modified: gnunet/src/include/gnunet_server_lib.h
===================================================================
--- gnunet/src/include/gnunet_server_lib.h 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/include/gnunet_server_lib.h 2011-08-15 21:46:35 UTC (rev
16581)
@@ -74,8 +74,7 @@
struct GNUNET_SERVER_Client *
client,
const struct
- GNUNET_MessageHeader *
- message);
+ GNUNET_MessageHeader * message);
@@ -123,12 +122,12 @@
* @return handle for the new server, NULL on error
* (typically, "port" already in use)
*/
-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);
+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);
/**
* Create a new server.
@@ -145,8 +144,9 @@
*/
struct GNUNET_SERVER_Handle *GNUNET_SERVER_create
(GNUNET_CONNECTION_AccessCheck
access, void *access_cls,
- struct sockaddr
*const*serverAddr,
- const socklen_t *socklen,
+ struct sockaddr *const
+ *serverAddr,
+ const socklen_t * socklen,
struct GNUNET_TIME_Relative
idle_timeout,
int require_found);
@@ -195,11 +195,11 @@
* NULL if we are already going to notify someone else (busy)
*/
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);
+ *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);
/**
@@ -208,8 +208,7 @@
*
* @param client the client to set the persistent flag on
*/
-void
-GNUNET_SERVER_client_persist_ (struct GNUNET_SERVER_Client *client);
+void GNUNET_SERVER_client_persist_ (struct GNUNET_SERVER_Client *client);
/**
* Resume receiving from this client, we are done processing the
@@ -237,7 +236,7 @@
*/
void
GNUNET_SERVER_client_set_timeout (struct GNUNET_SERVER_Client *client,
- struct GNUNET_TIME_Relative timeout);
+ struct GNUNET_TIME_Relative timeout);
/**
@@ -248,7 +247,8 @@
* @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);
/**
@@ -364,9 +364,10 @@
* @param callback function to call on disconnect
* @param callback_cls closure for callback
*/
-void GNUNET_SERVER_disconnect_notify_cancel (struct GNUNET_SERVER_Handle
*server,
- GNUNET_SERVER_DisconnectCallback
- callback, void *callback_cls);
+void GNUNET_SERVER_disconnect_notify_cancel (struct GNUNET_SERVER_Handle
+ *server,
+ GNUNET_SERVER_DisconnectCallback
+ callback, void *callback_cls);
/**
@@ -392,8 +393,7 @@
* @param do_ignore GNUNET_YES to ignore, GNUNET_NO to restore default
*/
void
-GNUNET_SERVER_ignore_shutdown (struct GNUNET_SERVER_Handle *h,
- int do_ignore);
+GNUNET_SERVER_ignore_shutdown (struct GNUNET_SERVER_Handle *h, int do_ignore);
@@ -405,8 +405,7 @@
* @param client handle to the client
* @return GNUNET_OK on success
*/
-int
-GNUNET_SERVER_client_disable_corking (struct GNUNET_SERVER_Client *client);
+int GNUNET_SERVER_client_disable_corking (struct GNUNET_SERVER_Client *client);
/**
@@ -425,8 +424,8 @@
* @return NULL on error
*/
struct GNUNET_SERVER_TransmitContext
- *GNUNET_SERVER_transmit_context_create (struct GNUNET_SERVER_Client
- *client);
+ *GNUNET_SERVER_transmit_context_create (struct GNUNET_SERVER_Client
+ *client);
/**
@@ -441,8 +440,8 @@
*/
void
GNUNET_SERVER_transmit_context_append_data (struct
GNUNET_SERVER_TransmitContext
- *tc, const void *data, size_t
length,
- uint16_t type);
+ *tc, const void *data,
+ size_t length, uint16_t type);
/**
@@ -454,8 +453,11 @@
* @param msg message to append
*/
void
-GNUNET_SERVER_transmit_context_append_message (struct
GNUNET_SERVER_TransmitContext
- *tc, const struct
GNUNET_MessageHeader *msg);
+GNUNET_SERVER_transmit_context_append_message (struct
+ GNUNET_SERVER_TransmitContext
+ *tc,
+ const struct
GNUNET_MessageHeader
+ *msg);
/**
@@ -493,9 +495,10 @@
* if the queue gets longer than this number of messages
* @return handle to the notification context
*/
-struct GNUNET_SERVER_NotificationContext *
-GNUNET_SERVER_notification_context_create (struct GNUNET_SERVER_Handle *server,
- unsigned int queue_length);
+struct GNUNET_SERVER_NotificationContext
+ *GNUNET_SERVER_notification_context_create (struct GNUNET_SERVER_Handle
+ *server,
+ unsigned int queue_length);
/**
@@ -504,7 +507,9 @@
* @param nc context to destroy.
*/
void
-GNUNET_SERVER_notification_context_destroy (struct
GNUNET_SERVER_NotificationContext *nc);
+GNUNET_SERVER_notification_context_destroy (struct
+ GNUNET_SERVER_NotificationContext
+ *nc);
/**
@@ -514,8 +519,9 @@
* @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);
/**
@@ -528,10 +534,12 @@
* @param can_drop can this message be dropped due to queue length limitations
*/
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_notification_context_unicast (struct
+ GNUNET_SERVER_NotificationContext
+ *nc,
+ struct GNUNET_SERVER_Client
*client,
+ const struct GNUNET_MessageHeader
+ *msg, int can_drop);
/**
@@ -542,9 +550,11 @@
* @param can_drop can this message be dropped due to queue length limitations
*/
void
-GNUNET_SERVER_notification_context_broadcast (struct
GNUNET_SERVER_NotificationContext *nc,
- const struct GNUNET_MessageHeader
*msg,
- int can_drop);
+GNUNET_SERVER_notification_context_broadcast (struct
+ GNUNET_SERVER_NotificationContext
+ *nc,
+ const struct GNUNET_MessageHeader
+ *msg, int can_drop);
@@ -562,10 +572,10 @@
* @param message the actual message
*/
typedef void (*GNUNET_SERVER_MessageTokenizerCallback) (void *cls,
- void *client,
- const struct
- GNUNET_MessageHeader *
- message);
+ void *client,
+ const struct
+ GNUNET_MessageHeader *
+ message);
/**
@@ -575,9 +585,9 @@
* @param cb_cls closure for cb
* @return handle to tokenizer
*/
-struct GNUNET_SERVER_MessageStreamTokenizer *
-GNUNET_SERVER_mst_create (GNUNET_SERVER_MessageTokenizerCallback cb,
- void *cb_cls);
+struct GNUNET_SERVER_MessageStreamTokenizer
+ *GNUNET_SERVER_mst_create (GNUNET_SERVER_MessageTokenizerCallback cb,
+ void *cb_cls);
/**
@@ -598,11 +608,9 @@
*/
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);
/**
Modified: gnunet/src/include/gnunet_service_lib.h
===================================================================
--- gnunet/src/include/gnunet_service_lib.h 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/include/gnunet_service_lib.h 2011-08-15 21:46:35 UTC (rev
16581)
@@ -61,9 +61,9 @@
*/
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);
/**
@@ -84,18 +84,18 @@
* Options for the service (bitmask).
*/
enum GNUNET_SERVICE_Options
- {
+{
/**
* Use defaults.
*/
- GNUNET_SERVICE_OPTION_NONE = 0,
+ GNUNET_SERVICE_OPTION_NONE = 0,
/**
* Do not trigger server shutdown on signals, allow for the user
* to terminate the server explicitly when needed.
*/
- GNUNET_SERVICE_OPTION_MANUAL_SHUTDOWN = 1
- };
+ GNUNET_SERVICE_OPTION_MANUAL_SHUTDOWN = 1
+};
/**
@@ -111,12 +111,12 @@
* @return GNUNET_SYSERR on error, GNUNET_OK
* if we shutdown nicely
*/
-int GNUNET_SERVICE_run (int argc,
- char *const *argv,
- const char *serviceName,
- enum GNUNET_SERVICE_Options opt,
- GNUNET_SERVICE_Main task,
- void *task_cls);
+int
+GNUNET_SERVICE_run (int argc,
+ char *const *argv,
+ const char *serviceName,
+ enum GNUNET_SERVICE_Options opt,
+ GNUNET_SERVICE_Main task, void *task_cls);
struct GNUNET_SERVICE_Context;
Modified: gnunet/src/include/gnunet_statistics_service.h
===================================================================
--- gnunet/src/include/gnunet_statistics_service.h 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/include/gnunet_statistics_service.h 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -64,8 +64,7 @@
typedef int (*GNUNET_STATISTICS_Iterator) (void *cls,
const char *subsystem,
const char *name,
- uint64_t value,
- int is_persistent);
+ uint64_t value, int is_persistent);
/**
* Get handle for the statistics service.
@@ -75,8 +74,8 @@
* @return handle to use
*/
struct GNUNET_STATISTICS_Handle
- *GNUNET_STATISTICS_create (const char *subsystem,
- const struct GNUNET_CONFIGURATION_Handle *cfg);
+ *GNUNET_STATISTICS_create (const char *subsystem,
+ const struct GNUNET_CONFIGURATION_Handle *cfg);
/**
@@ -88,7 +87,7 @@
* be completed
*/
void GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h,
- int sync_first);
+ int sync_first);
/**
@@ -105,10 +104,9 @@
*/
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);
/**
@@ -138,13 +136,19 @@
* @param cls closure for proc and cont
* @return NULL on error
*/
-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);
+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);
/**
@@ -153,8 +157,7 @@
*
* @param gh handle of the request to cancel
*/
-void
-GNUNET_STATISTICS_get_cancel (struct GNUNET_STATISTICS_GetHandle *gh);
+void GNUNET_STATISTICS_get_cancel (struct GNUNET_STATISTICS_GetHandle *gh);
/**
@@ -168,8 +171,7 @@
*/
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);
/**
* Set statistic value for the peer. Will always use our
@@ -182,8 +184,7 @@
*/
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);
Modified: gnunet/src/include/gnunet_strings_lib.h
===================================================================
--- gnunet/src/include/gnunet_strings_lib.h 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/include/gnunet_strings_lib.h 2011-08-15 21:46:35 UTC (rev
16581)
@@ -105,8 +105,7 @@
* (or number of bytes that would have been written)
*/
size_t GNUNET_STRINGS_buffer_fill (char *buffer,
- size_t size,
- unsigned int count, ...);
+ size_t size, unsigned int count, ...);
/**
Modified: gnunet/src/include/gnunet_testing_lib.h
===================================================================
--- gnunet/src/include/gnunet_testing_lib.h 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/include/gnunet_testing_lib.h 2011-08-15 21:46:35 UTC (rev
16581)
@@ -88,10 +88,12 @@
* @param d handle for the daemon
* @param emsg error message (NULL on success)
*/
-typedef void (*GNUNET_TESTING_NotifyHostkeyCreated)(void *cls,
- const struct
GNUNET_PeerIdentity *id,
- struct
GNUNET_TESTING_Daemon *d,
- const char *emsg);
+typedef void (*GNUNET_TESTING_NotifyHostkeyCreated) (void *cls,
+ const struct
+ GNUNET_PeerIdentity * id,
+ struct
+ GNUNET_TESTING_Daemon * d,
+ const char *emsg);
/**
* Prototype of a function that will be called whenever
@@ -103,11 +105,14 @@
* @param d handle for the daemon
* @param emsg error message (NULL on success)
*/
-typedef void (*GNUNET_TESTING_NotifyDaemonRunning)(void *cls,
- const struct
GNUNET_PeerIdentity *id,
- const struct
GNUNET_CONFIGURATION_Handle *cfg,
- struct GNUNET_TESTING_Daemon
*d,
- const char *emsg);
+typedef void (*GNUNET_TESTING_NotifyDaemonRunning) (void *cls,
+ const struct
+ GNUNET_PeerIdentity * id,
+ const struct
+ GNUNET_CONFIGURATION_Handle
+ * cfg,
+ struct
GNUNET_TESTING_Daemon
+ * d, const char *emsg);
/**
@@ -203,8 +208,7 @@
* @param cls closure
* @param emsg NULL on success
*/
-typedef void (*GNUNET_TESTING_NotifyCompletion)(void *cls,
- const char *emsg);
+typedef void (*GNUNET_TESTING_NotifyCompletion) (void *cls, const char *emsg);
/**
* Prototype of a function that will be called with the
@@ -213,8 +217,8 @@
* @param cls closure
* @param num_connections the number of connections created
*/
-typedef void (*GNUNET_TESTING_NotifyConnections)(void *cls,
- unsigned int num_connections);
+typedef void (*GNUNET_TESTING_NotifyConnections) (void *cls,
+ unsigned int
num_connections);
/**
* Handle for a GNUnet daemon (technically a set of
@@ -405,15 +409,23 @@
* @param second_daemon handle for the second daemon
* @param emsg error message (NULL on success)
*/
-typedef void (*GNUNET_TESTING_NotifyConnection)(void *cls,
- const struct
GNUNET_PeerIdentity *first,
- const struct
GNUNET_PeerIdentity *second,
- uint32_t distance,
- const struct
GNUNET_CONFIGURATION_Handle *first_cfg,
- const struct
GNUNET_CONFIGURATION_Handle *second_cfg,
- struct GNUNET_TESTING_Daemon
*first_daemon,
- struct GNUNET_TESTING_Daemon
*second_daemon,
- const char *emsg);
+typedef void (*GNUNET_TESTING_NotifyConnection) (void *cls,
+ const struct
+ GNUNET_PeerIdentity * first,
+ const struct
+ GNUNET_PeerIdentity * second,
+ uint32_t distance,
+ const struct
+ GNUNET_CONFIGURATION_Handle *
+ first_cfg,
+ const struct
+ GNUNET_CONFIGURATION_Handle *
+ second_cfg,
+ struct GNUNET_TESTING_Daemon *
+ first_daemon,
+ struct GNUNET_TESTING_Daemon *
+ second_daemon,
+ const char *emsg);
/**
* Prototype of a callback function indicating that two peers
@@ -425,10 +437,11 @@
* @param distance distance between the connected peers
* @param emsg error message (NULL on success)
*/
-typedef void (*GNUNET_TESTING_NotifyTopology)(void *cls,
- const struct GNUNET_PeerIdentity
*first,
- const struct GNUNET_PeerIdentity
*second,
- const char *emsg);
+typedef void (*GNUNET_TESTING_NotifyTopology) (void *cls,
+ const struct GNUNET_PeerIdentity
+ * first,
+ const struct GNUNET_PeerIdentity
+ * second, const char *emsg);
/**
* Starts a GNUnet daemon. GNUnet must be installed on the target
@@ -453,18 +466,22 @@
* @param cb_cls closure for cb
* @return handle to the daemon (actual start will be completed asynchronously)
*/
-struct GNUNET_TESTING_Daemon *
-GNUNET_TESTING_daemon_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
- struct GNUNET_TIME_Relative timeout,
- int pretend,
- const char *hostname,
- const char *ssh_username,
- uint16_t sshport,
- const char *hostkey,
- GNUNET_TESTING_NotifyHostkeyCreated
- hostkey_callback, void *hostkey_cls,
- GNUNET_TESTING_NotifyDaemonRunning cb,
- void *cb_cls);
+struct GNUNET_TESTING_Daemon *GNUNET_TESTING_daemon_start (const struct
+
GNUNET_CONFIGURATION_Handle
+ *cfg,
+ struct
+ GNUNET_TIME_Relative
+ timeout, int
pretend,
+ const char
*hostname,
+ const char
+ *ssh_username,
+ uint16_t sshport,
+ const char *hostkey,
+
GNUNET_TESTING_NotifyHostkeyCreated
+ hostkey_callback,
+ void *hostkey_cls,
+
GNUNET_TESTING_NotifyDaemonRunning
+ cb, void *cb_cls);
/**
* Continues GNUnet daemon startup when user wanted to be notified
@@ -474,7 +491,7 @@
* @param daemon the daemon to finish starting
*/
void
-GNUNET_TESTING_daemon_continue_startup(struct GNUNET_TESTING_Daemon *daemon);
+GNUNET_TESTING_daemon_continue_startup (struct GNUNET_TESTING_Daemon *daemon);
/**
* Check whether the given daemon is running.
@@ -484,8 +501,7 @@
* @return GNUNET_YES if the daemon is up, GNUNET_NO if the
* daemon is down, GNUNET_SYSERR on error.
*/
-int
-GNUNET_TESTING_daemon_running (struct GNUNET_TESTING_Daemon *daemon);
+int GNUNET_TESTING_daemon_running (struct GNUNET_TESTING_Daemon *daemon);
/**
* Restart (stop and start) a GNUnet daemon.
@@ -496,7 +512,8 @@
*/
void
GNUNET_TESTING_daemon_restart (struct GNUNET_TESTING_Daemon *d,
- GNUNET_TESTING_NotifyDaemonRunning cb, void
*cb_cls);
+ GNUNET_TESTING_NotifyDaemonRunning cb,
+ void *cb_cls);
/**
* Start a peer that has previously been stopped using the daemon_stop
@@ -526,7 +543,8 @@
GNUNET_TESTING_daemon_start_service (struct GNUNET_TESTING_Daemon *d,
char *service,
struct GNUNET_TIME_Relative timeout,
- GNUNET_TESTING_NotifyDaemonRunning cb,
void *cb_cls);
+ GNUNET_TESTING_NotifyDaemonRunning cb,
+ void *cb_cls);
/**
* Starts a GNUnet daemon's service which has been previously turned off.
@@ -540,8 +558,10 @@
void
GNUNET_TESTING_daemon_start_stopped_service (struct GNUNET_TESTING_Daemon *d,
char *service,
- struct GNUNET_TIME_Relative
timeout,
-
GNUNET_TESTING_NotifyDaemonRunning cb, void *cb_cls);
+ struct GNUNET_TIME_Relative
+ timeout,
+ GNUNET_TESTING_NotifyDaemonRunning
+ cb, void *cb_cls);
/**
* Get a certain testing daemon handle.
@@ -549,9 +569,10 @@
* @param pg handle to the set of running peers
* @param position the number of the peer to return
*/
-struct GNUNET_TESTING_Daemon *
-GNUNET_TESTING_daemon_get (struct GNUNET_TESTING_PeerGroup *pg,
- unsigned int position);
+struct GNUNET_TESTING_Daemon *GNUNET_TESTING_daemon_get (struct
+
GNUNET_TESTING_PeerGroup
+ *pg,
+ unsigned int
position);
/*
* Get a daemon by peer identity, so callers can
@@ -562,9 +583,12 @@
*
* @return the daemon on success, or NULL if no such peer identity is found
*/
-struct GNUNET_TESTING_Daemon *
-GNUNET_TESTING_daemon_get_by_id (struct GNUNET_TESTING_PeerGroup *pg,
- struct GNUNET_PeerIdentity *peer_id);
+struct GNUNET_TESTING_Daemon *GNUNET_TESTING_daemon_get_by_id (struct
+
GNUNET_TESTING_PeerGroup
+ *pg,
+ struct
+
GNUNET_PeerIdentity
+ *peer_id);
/**
* Stops a GNUnet daemon.
@@ -595,9 +619,9 @@
* @param cb_cls closure for cb
*/
void GNUNET_TESTING_daemon_reconfigure (struct GNUNET_TESTING_Daemon *d,
- struct GNUNET_CONFIGURATION_Handle *cfg,
- GNUNET_TESTING_NotifyCompletion cb,
- void * cb_cls);
+ struct GNUNET_CONFIGURATION_Handle
*cfg,
+ GNUNET_TESTING_NotifyCompletion cb,
+ void *cb_cls);
/**
* Stops a single service of a GNUnet daemon. Used like daemon_stop,
@@ -615,7 +639,8 @@
GNUNET_TESTING_daemon_stop_service (struct GNUNET_TESTING_Daemon *d,
char *service,
struct GNUNET_TIME_Relative timeout,
- GNUNET_TESTING_NotifyCompletion cb, void
*cb_cls);
+ GNUNET_TESTING_NotifyCompletion cb,
+ void *cb_cls);
/**
* Read a testing hosts file based on a configuration.
@@ -626,8 +651,9 @@
*
* @return DLL of hosts on success, NULL on failure
*/
-struct GNUNET_TESTING_Host *
-GNUNET_TESTING_hosts_load (const struct GNUNET_CONFIGURATION_Handle *cfg);
+struct GNUNET_TESTING_Host *GNUNET_TESTING_hosts_load (const struct
+
GNUNET_CONFIGURATION_Handle
+ *cfg);
/**
@@ -657,19 +683,31 @@
*
* @return NULL on error, otherwise handle to control peer group
*/
-struct GNUNET_TESTING_PeerGroup *
-GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
- unsigned int total,
- unsigned int max_concurrent_connections,
- unsigned int max_concurrent_ssh,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_TESTING_NotifyHostkeyCreated
- hostkey_callback, void *hostkey_cls,
- GNUNET_TESTING_NotifyDaemonRunning cb,
- void *cb_cls,
- GNUNET_TESTING_NotifyConnection
- connect_callback, void *connect_callback_cls,
- const struct GNUNET_TESTING_Host *hostnames);
+struct GNUNET_TESTING_PeerGroup *GNUNET_TESTING_daemons_start (const struct
+
GNUNET_CONFIGURATION_Handle
+ *cfg,
+ unsigned int
+ total,
+ unsigned int
+
max_concurrent_connections,
+ unsigned int
+
max_concurrent_ssh,
+ struct
+
GNUNET_TIME_Relative
+ timeout,
+
GNUNET_TESTING_NotifyHostkeyCreated
+
hostkey_callback,
+ void
+ *hostkey_cls,
+
GNUNET_TESTING_NotifyDaemonRunning
+ cb, void
*cb_cls,
+
GNUNET_TESTING_NotifyConnection
+
connect_callback,
+ void
+
*connect_callback_cls,
+ const struct
+
GNUNET_TESTING_Host
+ *hostnames);
/**
* Function which continues a peer group starting up
@@ -678,7 +716,7 @@
* @param pg the peer group to continue starting
*/
void
-GNUNET_TESTING_daemons_continue_startup(struct GNUNET_TESTING_PeerGroup *pg);
+GNUNET_TESTING_daemons_continue_startup (struct GNUNET_TESTING_PeerGroup *pg);
/**
@@ -727,10 +765,9 @@
* @param cb_cls closure for cb
*/
void
-GNUNET_TESTING_daemons_stop (struct GNUNET_TESTING_PeerGroup *pg,
+GNUNET_TESTING_daemons_stop (struct GNUNET_TESTING_PeerGroup *pg,
struct GNUNET_TIME_Relative timeout,
- GNUNET_TESTING_NotifyCompletion cb,
- void *cb_cls);
+ GNUNET_TESTING_NotifyCompletion cb, void *cb_cls);
/**
@@ -772,8 +809,7 @@
unsigned int voff,
unsigned int von,
struct GNUNET_TIME_Relative timeout,
- GNUNET_TESTING_NotifyCompletion cb,
- void *cb_cls);
+ GNUNET_TESTING_NotifyCompletion cb, void
*cb_cls);
/*
* Start a given service for each of the peers in the peer group.
*
@@ -804,7 +840,8 @@
* @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
*/
typedef int (*GNUNET_TESTING_STATISTICS_Iterator) (void *cls,
- const struct
GNUNET_PeerIdentity *peer,
+ const struct
+ GNUNET_PeerIdentity * peer,
const char *subsystem,
const char *name,
uint64_t value,
@@ -822,7 +859,8 @@
void
GNUNET_TESTING_get_statistics (struct GNUNET_TESTING_PeerGroup *pg,
GNUNET_STATISTICS_Callback cont,
- GNUNET_TESTING_STATISTICS_Iterator proc, void
*cls);
+ GNUNET_TESTING_STATISTICS_Iterator proc,
+ void *cls);
/**
* Topologies supported for testbeds.
@@ -938,8 +976,8 @@
* known topology, GNUNET_NO if not
*/
int
-GNUNET_TESTING_topology_get(enum GNUNET_TESTING_Topology *topology,
- const char * topology_string);
+GNUNET_TESTING_topology_get (enum GNUNET_TESTING_Topology *topology,
+ const char *topology_string);
/**
* Get connect topology option from string input.
@@ -951,8 +989,9 @@
* known topology, GNUNET_NO if not
*/
int
-GNUNET_TESTING_topology_option_get(enum GNUNET_TESTING_TopologyOption
*topology_option,
- const char * topology_string);
+GNUNET_TESTING_topology_option_get (enum GNUNET_TESTING_TopologyOption
+ *topology_option,
+ const char *topology_string);
/**
@@ -1007,21 +1046,21 @@
*/
void
GNUNET_TESTING_get_topology (struct GNUNET_TESTING_PeerGroup *pg,
- GNUNET_TESTING_NotifyTopology cb, void *cls);
+ GNUNET_TESTING_NotifyTopology cb, void *cls);
/**
* Stop the connection process temporarily.
*
* @param pg the peer group to stop connecting
*/
-void GNUNET_TESTING_stop_connections(struct GNUNET_TESTING_PeerGroup *pg);
+void GNUNET_TESTING_stop_connections (struct GNUNET_TESTING_PeerGroup *pg);
/**
* Resume the connection process.
*
* @param pg the peer group to resume connecting
*/
-void GNUNET_TESTING_resume_connections(struct GNUNET_TESTING_PeerGroup *pg);
+void GNUNET_TESTING_resume_connections (struct GNUNET_TESTING_PeerGroup *pg);
/**
* There are many ways to connect peers that are supported by this function.
@@ -1066,12 +1105,11 @@
* @param cb_cls closure for cb
*/
void
-GNUNET_TESTING_daemons_vary (struct GNUNET_TESTING_PeerGroup *pg,
- unsigned int offset,
- int desired_status,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_TESTING_NotifyCompletion cb,
- void *cb_cls);
+GNUNET_TESTING_daemons_vary (struct GNUNET_TESTING_PeerGroup *pg,
+ unsigned int offset,
+ int desired_status,
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_TESTING_NotifyCompletion cb, void *cb_cls);
/**
* Start a peer group with a given number of peers. Notify
@@ -1090,15 +1128,23 @@
*
* @return NULL on error, otherwise handle to control peer group
*/
-struct GNUNET_TESTING_PeerGroup *
-GNUNET_TESTING_peergroup_start(
- const struct GNUNET_CONFIGURATION_Handle *cfg,
- unsigned int total,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_TESTING_NotifyConnection connect_cb,
- GNUNET_TESTING_NotifyCompletion peergroup_cb,
- void *peergroup_cls,
- const struct GNUNET_TESTING_Host *hostnames);
+struct GNUNET_TESTING_PeerGroup *GNUNET_TESTING_peergroup_start (const struct
+
GNUNET_CONFIGURATION_Handle
+ *cfg,
+ unsigned int
+ total,
+ struct
+
GNUNET_TIME_Relative
+ timeout,
+
GNUNET_TESTING_NotifyConnection
+ connect_cb,
+
GNUNET_TESTING_NotifyCompletion
+ peergroup_cb,
+ void
+
*peergroup_cls,
+ const struct
+
GNUNET_TESTING_Host
+ *hostnames);
/**
* Print current topology to a graphviz readable file.
@@ -1110,10 +1156,10 @@
*
*/
void
-GNUNET_TESTING_peergroup_topology_to_file(struct GNUNET_TESTING_PeerGroup *pg,
- const char *output_filename,
- GNUNET_TESTING_NotifyCompletion
notify_cb,
- void *notify_cb_cls);
+GNUNET_TESTING_peergroup_topology_to_file (struct GNUNET_TESTING_PeerGroup *pg,
+ const char *output_filename,
+ GNUNET_TESTING_NotifyCompletion
+ notify_cb, void *notify_cb_cls);
#if 0 /* keep Emacsens' auto-indent happy */
Modified: gnunet/src/include/gnunet_time_lib.h
===================================================================
--- gnunet/src/include/gnunet_time_lib.h 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/include/gnunet_time_lib.h 2011-08-15 21:46:35 UTC (rev
16581)
@@ -199,10 +199,10 @@
* @return timestamp that is smaller
*/
struct GNUNET_TIME_Relative GNUNET_TIME_relative_min (struct
- GNUNET_TIME_Relative
- t1,
- struct
- GNUNET_TIME_Relative t2);
+ GNUNET_TIME_Relative
+ t1,
+ struct
+ GNUNET_TIME_Relative t2);
/**
@@ -213,10 +213,10 @@
* @return timestamp that is larger
*/
struct GNUNET_TIME_Relative GNUNET_TIME_relative_max (struct
- GNUNET_TIME_Relative
- t1,
- struct
- GNUNET_TIME_Relative t2);
+ GNUNET_TIME_Relative
+ t1,
+ struct
+ GNUNET_TIME_Relative t2);
/**
* Return the minimum of two absolute time values.
@@ -226,10 +226,10 @@
* @return timestamp that is smaller
*/
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_min (struct
- GNUNET_TIME_Absolute
- t1,
- struct
- GNUNET_TIME_Absolute t2);
+ GNUNET_TIME_Absolute
+ t1,
+ struct
+ GNUNET_TIME_Absolute t2);
/**
* Return the maximum of two absolute time values.
@@ -239,10 +239,10 @@
* @return timestamp that is smaller
*/
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_max (struct
- GNUNET_TIME_Absolute
- t1,
- struct
- GNUNET_TIME_Absolute t2);
+ GNUNET_TIME_Absolute
+ t1,
+ struct
+ GNUNET_TIME_Absolute t2);
/**
* Given a timestamp in the future, how much time
@@ -266,9 +266,10 @@
* @return remaining duration for the operation,
* 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);
+struct GNUNET_TIME_Relative GNUNET_TIME_calculate_eta (struct
+ GNUNET_TIME_Absolute
+ start, uint64_t
finished,
+ uint64_t total);
/**
@@ -324,11 +325,11 @@
* @return ZERO if start <= duration, or FOREVER if start time is FOREVER;
start-duration otherwise
*/
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_subtract (struct
- GNUNET_TIME_Absolute
- start,
- struct
- GNUNET_TIME_Relative
- duration);
+ GNUNET_TIME_Absolute
+ start,
+ struct
+ GNUNET_TIME_Relative
+ duration);
/**
* Multiply relative time by a given factor.
@@ -340,8 +341,7 @@
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply (struct
GNUNET_TIME_Relative
rel,
- unsigned int
- factor);
+ unsigned int
factor);
/**
* Divide relative time by a given factor.
@@ -351,10 +351,9 @@
* @return FOREVER if rel=FOREVER or factor==0; otherwise rel/factor
*/
struct GNUNET_TIME_Relative GNUNET_TIME_relative_divide (struct
- GNUNET_TIME_Relative
- rel,
- unsigned int
- factor);
+ GNUNET_TIME_Relative
+ rel,
+ unsigned int factor);
/**
* Add relative times together.
@@ -366,8 +365,7 @@
struct GNUNET_TIME_Relative GNUNET_TIME_relative_add (struct
GNUNET_TIME_Relative a1,
struct
- GNUNET_TIME_Relative
- a2);
+ GNUNET_TIME_Relative a2);
/**
* Subtract relative timestamp from the other.
@@ -378,7 +376,7 @@
*/
struct GNUNET_TIME_Relative
GNUNET_TIME_relative_subtract (struct GNUNET_TIME_Relative a1,
- struct GNUNET_TIME_Relative a2);
+ struct GNUNET_TIME_Relative a2);
/**
@@ -429,16 +427,14 @@
*
* @return string form of the time (as milliseconds)
*/
-const char *
-GNUNET_TIME_relative_to_string (struct GNUNET_TIME_Relative time);
+const char *GNUNET_TIME_relative_to_string (struct GNUNET_TIME_Relative time);
/**
* Set the timestamp offset for this instance.
*
* @param offset the offset to skew the locale time by
*/
-void
-GNUNET_TIME_set_offset(long long offset);
+void GNUNET_TIME_set_offset (long long offset);
#if 0 /* keep Emacsens' auto-indent happy */
{
Modified: gnunet/src/include/gnunet_transport_plugin.h
===================================================================
--- gnunet/src/include/gnunet_transport_plugin.h 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/include/gnunet_transport_plugin.h 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -63,7 +63,7 @@
* Expiration time for signature. Do not use in the plugin!
*/
struct GNUNET_TIME_Absolute pong_sig_expires;
-
+
};
/**
@@ -80,8 +80,8 @@
* @param session which session is being destoyed
*/
typedef void (*GNUNET_TRANSPORT_SessionEnd) (void *cls,
- const struct GNUNET_PeerIdentity
*peer,
- struct Session *session);
+ const struct GNUNET_PeerIdentity *
+ peer, struct Session * session);
/**
@@ -105,18 +105,26 @@
* @return how long the plugin should wait until receiving more data
* (plugins that do not support this, can ignore the return value)
*/
-typedef struct GNUNET_TIME_Relative (*GNUNET_TRANSPORT_PluginReceiveCallback)
(void *cls,
-
const struct
-
GNUNET_PeerIdentity *
-
peer,
-
const struct
-
GNUNET_MessageHeader *
-
message,
-
const struct GNUNET_TRANSPORT_ATS_Information *ats,
-
uint32_t ats_count,
-
struct Session *session,
-
const char *sender_address,
-
uint16_t sender_address_len);
+typedef struct
+ GNUNET_TIME_Relative (*GNUNET_TRANSPORT_PluginReceiveCallback) (void *cls,
+ const
struct
+
GNUNET_PeerIdentity
+ * peer,
+ const
struct
+
GNUNET_MessageHeader
+ * message,
+ const
struct
+
GNUNET_TRANSPORT_ATS_Information
+ * ats,
+ uint32_t
+ ats_count,
+ struct
+ Session *
+ session,
+ const char
+
*sender_address,
+ uint16_t
+
sender_address_len);
/**
@@ -131,7 +139,7 @@
* @param addrlen length of the address
*/
typedef void (*GNUNET_TRANSPORT_AddressNotification) (void *cls,
- int add_remove,
+ int add_remove,
const void *addr,
size_t addrlen);
@@ -151,16 +159,21 @@
* @return how long to wait until reading more from this peer
* (to enforce inbound quotas)
*/
-typedef struct GNUNET_TIME_Relative (*GNUNET_TRANSPORT_TrafficReport) (void
*cls,
- const
struct
-
GNUNET_PeerIdentity *peer,
- size_t
amount_recved);
+typedef struct GNUNET_TIME_Relative (*GNUNET_TRANSPORT_TrafficReport) (void
+ *cls,
+ const
+ struct
+
GNUNET_PeerIdentity
+ * peer,
+ size_t
+
amount_recved);
/**
* Function that returns a HELLO message.
- */
-typedef const struct GNUNET_MessageHeader *
(*GNUNET_TRANSPORT_GetHelloCallback)(void);
+ */
+typedef const struct GNUNET_MessageHeader
+ *(*GNUNET_TRANSPORT_GetHelloCallback) (void);
/**
@@ -242,9 +255,9 @@
* the ReceiveCallback.
*/
typedef void
- (*GNUNET_TRANSPORT_TransmitContinuation) (void *cls,
- const struct GNUNET_PeerIdentity *
- target, int result);
+ (*GNUNET_TRANSPORT_TransmitContinuation) (void *cls,
+ const struct GNUNET_PeerIdentity
*
+ target, int result);
/**
@@ -284,19 +297,19 @@
* and does NOT mean that the message was not transmitted (DV)
*/
typedef ssize_t
- (*GNUNET_TRANSPORT_TransmitFunction) (void *cls,
- const struct GNUNET_PeerIdentity *
- target,
- const char *msgbuf,
- size_t msgbuf_size,
- uint32_t priority,
- struct GNUNET_TIME_Relative timeout,
- struct Session *session,
- const void *addr,
- size_t addrlen,
- int force_address,
- GNUNET_TRANSPORT_TransmitContinuation
- cont, void *cont_cls);
+ (*GNUNET_TRANSPORT_TransmitFunction) (void *cls,
+ const struct GNUNET_PeerIdentity *
+ target,
+ const char *msgbuf,
+ size_t msgbuf_size,
+ uint32_t priority,
+ struct GNUNET_TIME_Relative timeout,
+ struct Session * session,
+ const void *addr,
+ size_t addrlen,
+ int force_address,
+ GNUNET_TRANSPORT_TransmitContinuation
+ cont, void *cont_cls);
/**
@@ -316,9 +329,9 @@
* to be cancelled
*/
typedef void
- (*GNUNET_TRANSPORT_DisconnectFunction) (void *cls,
- const struct GNUNET_PeerIdentity *
- target);
+ (*GNUNET_TRANSPORT_DisconnectFunction) (void *cls,
+ const struct GNUNET_PeerIdentity *
+ target);
/**
@@ -348,15 +361,15 @@
* @param asc_cls closure for asc
*/
typedef void
- (*GNUNET_TRANSPORT_AddressPrettyPrinter) (void *cls,
- const char *type,
- const void *addr,
- size_t addrlen,
- int numeric,
- struct GNUNET_TIME_Relative
- timeout,
-
GNUNET_TRANSPORT_AddressStringCallback
- asc, void *asc_cls);
+ (*GNUNET_TRANSPORT_AddressPrettyPrinter) (void *cls,
+ const char *type,
+ const void *addr,
+ size_t addrlen,
+ int numeric,
+ struct GNUNET_TIME_Relative
+ timeout,
+
GNUNET_TRANSPORT_AddressStringCallback
+ asc, void *asc_cls);
/**
@@ -374,8 +387,8 @@
* and transport, GNUNET_SYSERR if not
*/
typedef int
-(*GNUNET_TRANSPORT_CheckAddress) (void *cls,
- const void *addr, size_t addrlen);
+ (*GNUNET_TRANSPORT_CheckAddress) (void *cls,
+ const void *addr, size_t addrlen);
/**
@@ -389,9 +402,9 @@
* @param addr_len length of the address
* @return string representing the same address
*/
-typedef const char* (*GNUNET_TRANSPORT_AddressToString) (void *cls,
- const void *addr,
- size_t addrlen);
+typedef const char *(*GNUNET_TRANSPORT_AddressToString) (void *cls,
+ const void *addr,
+ size_t addrlen);
/**
Modified: gnunet/src/include/gnunet_transport_service.h
===================================================================
--- gnunet/src/include/gnunet_transport_service.h 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/include/gnunet_transport_service.h 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -90,7 +90,7 @@
* 2G : 10 [cent/MB]
*/
GNUNET_TRANSPORT_ATS_COST_FINANCIAL_PER_VOLUME = 1,
-
+
/**
* Time based cost in financial units to transmit data
*
@@ -108,7 +108,7 @@
* Dialup: 10 [cent/h]
*/
GNUNET_TRANSPORT_ATS_COST_FINANCIAL_PER_TIME = 2,
-
+
/**
* Computational costs
*
@@ -128,7 +128,7 @@
* HTTPS with RC4-1024: 2,652
*/
GNUNET_TRANSPORT_ATS_COST_COMPUTATIONAL = 3,
-
+
/**
* Energy consumption
*
@@ -157,7 +157,7 @@
* Bluetooth: 267 (100 mW @ BT2.0 EDR /w 3 MBit/s)
*/
GNUNET_TRANSPORT_ATS_COST_ENERGY_CONSUMPTION = 4,
-
+
/**
* Connect cost
* How many bytes are transmitted to initiate a new connection using
@@ -180,7 +180,7 @@
*
* */
GNUNET_TRANSPORT_ATS_COST_CONNECT = 5,
-
+
/**
* Bandwidth cost
*
@@ -198,7 +198,7 @@
*
*/
GNUNET_TRANSPORT_ATS_COST_BANDWITH_AVAILABLE = 6,
-
+
/**
* Network overhead
*
@@ -219,36 +219,36 @@
* UDP/IPv6 over Ethernet: 1024 + 38 + 40 + 8 = 1110 [bytes/kb]
*/
GNUNET_TRANSPORT_ATS_COST_NETWORK_OVERHEAD = 7,
-
-
+
+
/* Quality related values */
/* ====================== */
-
+
/* Physical layer quality properties */
-
+
/**
* Signal strength on physical layer
*
* Unit: [dBm]
*/
GNUNET_TRANSPORT_ATS_QUALITY_PHY_SIGNAL_STRENGTH = 1025,
-
+
/**
* Collision rate on physical layer
*
* Unit: [B/s]
*/
GNUNET_TRANSPORT_ATS_QUALITY_PHY_COLLISION_RATE = 1026,
-
+
/**
* Error rate on physical layer
*
* Unit: [B/s]
*/
GNUNET_TRANSPORT_ATS_QUALITY_PHY_ERROR_RATE = 1027,
-
+
/* Network layer quality properties */
-
+
/**
* Delay
* Time between when the time packet is sent and the packet arrives
@@ -262,7 +262,7 @@
* Dialup: 500
*/
GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY = 1028,
-
+
/**
* Jitter
* Time variations of the delay
@@ -271,7 +271,7 @@
* Unit: [ms]
*/
GNUNET_TRANSPORT_ATS_QUALITY_NET_JITTER = 1029,
-
+
/**
* Error rate on network layer
*
@@ -286,7 +286,7 @@
* measured or somehow determined
*/
GNUNET_TRANSPORT_ATS_QUALITY_NET_ERRORRATE = 1030,
-
+
/**
* Drop rate on network layer
* Bytes actively dismissed by a network component during transmission
@@ -303,7 +303,7 @@
* measured or somehow determined
*/
GNUNET_TRANSPORT_ATS_QUALITY_NET_DROPRATE = 1031,
-
+
/**
* Loss rate on network layer
* Bytes lost during transmission
@@ -320,7 +320,7 @@
* or somehow determined
*/
GNUNET_TRANSPORT_ATS_QUALITY_NET_LOSSRATE = 1032,
-
+
/**
* Throughput on network layer
*
@@ -334,7 +334,7 @@
*
*/
GNUNET_TRANSPORT_ATS_QUALITY_NET_THROUGHPUT = 1033,
-
+
/**
* Distance on network layer
*
@@ -345,17 +345,16 @@
/* Availability related values */
/* =========================== */
-
+
/**
* Is a peer reachable?
*/
GNUNET_TRANSPORT_ATS_AVAILABILITY_REACHABLE = 2048,
-
+
/**
* Is there a connection established to a peer using this transport
*/
GNUNET_TRANSPORT_ATS_AVAILABILITY_CONNECTED = 2049
-
};
@@ -383,7 +382,7 @@
* ATS property type, in network byte order.
*/
uint32_t type;
-
+
/**
* ATS property value, in network byte order.
*/
@@ -407,8 +406,9 @@
const struct
GNUNET_MessageHeader *
message,
- const struct
GNUNET_TRANSPORT_ATS_Information *ats,
- uint32_t ats_count);
+ const struct
+
GNUNET_TRANSPORT_ATS_Information
+ * ats, uint32_t ats_count);
/**
@@ -427,10 +427,11 @@
* @param ats_count number of entries in ats (excluding 0-termination)
*/
typedef void
- (*GNUNET_TRANSPORT_NotifyConnect) (void *cls,
- const struct GNUNET_PeerIdentity * peer,
- const struct
GNUNET_TRANSPORT_ATS_Information *ats,
- uint32_t ats_count);
+ (*GNUNET_TRANSPORT_NotifyConnect) (void *cls,
+ const struct GNUNET_PeerIdentity * peer,
+ const struct
+ GNUNET_TRANSPORT_ATS_Information * ats,
+ uint32_t ats_count);
/**
* Function called to notify transport users that another
@@ -440,9 +441,9 @@
* @param peer the peer that disconnected
*/
typedef void
- (*GNUNET_TRANSPORT_NotifyDisconnect) (void *cls,
- const struct GNUNET_PeerIdentity *
- peer);
+ (*GNUNET_TRANSPORT_NotifyDisconnect) (void *cls,
+ const struct GNUNET_PeerIdentity *
+ peer);
/**
@@ -452,8 +453,7 @@
* @param address NULL on error, otherwise 0-terminated printable UTF-8 string
*/
typedef void
-(*GNUNET_TRANSPORT_AddressLookUpCallback) (void *cls,
- const char *address);
+ (*GNUNET_TRANSPORT_AddressLookUpCallback) (void *cls, const char *address);
/**
@@ -471,9 +471,10 @@
*/
struct GNUNET_TRANSPORT_Handle *GNUNET_TRANSPORT_connect (const struct
GNUNET_CONFIGURATION_Handle
- *cfg,
- const struct
GNUNET_PeerIdentity *self,
- void *cls,
+ *cfg,
+ const struct
+ GNUNET_PeerIdentity
+ *self, void *cls,
GNUNET_TRANSPORT_ReceiveCallback
rec,
GNUNET_TRANSPORT_NotifyConnect
@@ -499,7 +500,7 @@
*/
void
GNUNET_TRANSPORT_try_connect (struct GNUNET_TRANSPORT_Handle *handle,
- const struct GNUNET_PeerIdentity *target);
+ const struct GNUNET_PeerIdentity *target);
/**
@@ -544,15 +545,15 @@
* using GNUNET_TRANSPORT_notify_transmit_ready_cancel)
*/
struct GNUNET_TRANSPORT_TransmitHandle
- *GNUNET_TRANSPORT_notify_transmit_ready (struct GNUNET_TRANSPORT_Handle
- *handle,
- const struct GNUNET_PeerIdentity
- *target, size_t size,
- uint32_t priority,
- struct GNUNET_TIME_Relative
- timeout,
-
GNUNET_CONNECTION_TransmitReadyNotify
- notify, void *notify_cls);
+ *GNUNET_TRANSPORT_notify_transmit_ready (struct GNUNET_TRANSPORT_Handle
+ *handle,
+ const struct GNUNET_PeerIdentity
+ *target, size_t size,
+ uint32_t priority,
+ struct GNUNET_TIME_Relative
+ timeout,
+
GNUNET_CONNECTION_TransmitReadyNotify
+ notify, void *notify_cls);
/**
@@ -574,8 +575,10 @@
* @param cls closure
* @param hello our updated HELLO
*/
-typedef void (*GNUNET_TRANSPORT_HelloUpdateCallback)(void *cls,
- const struct
GNUNET_MessageHeader *hello);
+typedef void (*GNUNET_TRANSPORT_HelloUpdateCallback) (void *cls,
+ const struct
+ GNUNET_MessageHeader *
+ hello);
/**
@@ -600,8 +603,8 @@
*/
void
GNUNET_TRANSPORT_get_hello_cancel (struct GNUNET_TRANSPORT_Handle *handle,
- GNUNET_TRANSPORT_HelloUpdateCallback rec,
- void *rec_cls);
+ GNUNET_TRANSPORT_HelloUpdateCallback rec,
+ void *rec_cls);
/**
@@ -618,8 +621,7 @@
void
GNUNET_TRANSPORT_offer_hello (struct GNUNET_TRANSPORT_Handle *handle,
const struct GNUNET_MessageHeader *hello,
- GNUNET_SCHEDULER_Task cont,
- void *cls);
+ GNUNET_SCHEDULER_Task cont, void *cls);
/**
@@ -637,13 +639,13 @@
*/
void
GNUNET_TRANSPORT_address_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const char * address,
+ const char *address,
size_t addressLen,
- int numeric,
+ int numeric,
const char *nameTrans,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_TRANSPORT_AddressLookUpCallback aluc,
- void *aluc_cls);
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_TRANSPORT_AddressLookUpCallback aluc,
+ void *aluc_cls);
/**
@@ -657,10 +659,12 @@
* @param peer_address_callback_cls closure for peer_address_callback
*/
void
-GNUNET_TRANSPORT_peer_address_lookup (const struct GNUNET_CONFIGURATION_Handle
*cfg,
+GNUNET_TRANSPORT_peer_address_lookup (const struct GNUNET_CONFIGURATION_Handle
+ *cfg,
const struct GNUNET_PeerIdentity *peer,
struct GNUNET_TIME_Relative timeout,
- GNUNET_TRANSPORT_AddressLookUpCallback
peer_address_callback,
+ GNUNET_TRANSPORT_AddressLookUpCallback
+ peer_address_callback,
void *peer_address_callback_cls);
@@ -676,7 +680,8 @@
void
GNUNET_TRANSPORT_address_iterate (const struct GNUNET_CONFIGURATION_Handle
*cfg,
struct GNUNET_TIME_Relative timeout,
- GNUNET_TRANSPORT_AddressLookUpCallback
peer_address_callback,
+ GNUNET_TRANSPORT_AddressLookUpCallback
+ peer_address_callback,
void *peer_address_callback_cls);
@@ -693,8 +698,9 @@
* @param pid peer to approve or disapproave
* @return GNUNET_OK if the connection is allowed
*/
-typedef int (*GNUNET_TRANSPORT_BlacklistCallback)(void *cls,
- const struct
GNUNET_PeerIdentity *pid);
+typedef int (*GNUNET_TRANSPORT_BlacklistCallback) (void *cls,
+ const struct
+ GNUNET_PeerIdentity * pid);
/**
@@ -711,10 +717,12 @@
* @param cb_cls closure for cb
* @return NULL on error, otherwise handle for cancellation
*/
-struct GNUNET_TRANSPORT_Blacklist *
-GNUNET_TRANSPORT_blacklist (const struct GNUNET_CONFIGURATION_Handle *cfg,
- GNUNET_TRANSPORT_BlacklistCallback cb,
- void *cb_cls);
+struct GNUNET_TRANSPORT_Blacklist *GNUNET_TRANSPORT_blacklist (const struct
+
GNUNET_CONFIGURATION_Handle
+ *cfg,
+
GNUNET_TRANSPORT_BlacklistCallback
+ cb,
+ void *cb_cls);
/**
@@ -723,8 +731,7 @@
*
* @param br handle of the request that is to be cancelled
*/
-void
-GNUNET_TRANSPORT_blacklist_cancel (struct GNUNET_TRANSPORT_Blacklist *br);
+void GNUNET_TRANSPORT_blacklist_cancel (struct GNUNET_TRANSPORT_Blacklist *br);
Modified: gnunet/src/include/platform.h
===================================================================
--- gnunet/src/include/platform.h 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/include/platform.h 2011-08-15 21:46:35 UTC (rev 16581)
@@ -90,7 +90,7 @@
#if HAVE_NETINET_IN_SYSTM_H
#include <netinet/in_systm.h>
#endif
-#include <netinet/ip.h> /* superset of previous */
+#include <netinet/ip.h> /* superset of previous */
#include <arpa/inet.h>
#include <netinet/tcp.h>
#include <pwd.h>
@@ -110,7 +110,7 @@
#include <errno.h>
#include <signal.h>
#ifdef WINDOWS
-#include <malloc.h> /* for alloca(), on other OSes it's in stdlib.h */
+#include <malloc.h> /* for alloca(), on other OSes it's in
stdlib.h */
#endif
#ifndef _MSC_VER
#include <unistd.h> /* KLB_FIX */
Modified: gnunet/src/include/plibc.h
===================================================================
--- gnunet/src/include/plibc.h 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/include/plibc.h 2011-08-15 21:46:35 UTC (rev 16581)
@@ -29,17 +29,18 @@
#define _PLIBC_H_
#ifndef SIGALRM
- #define SIGALRM 14
+#define SIGALRM 14
#endif
#ifdef __cplusplus
-extern "C" {
+extern "C"
+{
#endif
#include <stddef.h>
#ifdef Q_OS_WIN32
- #define WINDOWS 1
+#define WINDOWS 1
#endif
#define HAVE_PLIBC_FD 0
@@ -47,7 +48,7 @@
#ifdef WINDOWS
#if ENABLE_NLS
- #include "langinfo.h"
+#include "langinfo.h"
#endif
#include <winsock2.h>
@@ -72,8 +73,8 @@
#define Li2Double(x) ((double)((x).HighPart) * 4.294967296E9 + \
(double)((x).LowPart))
-struct stat64
-{
+ struct stat64
+ {
_dev_t st_dev;
_ino_t st_ino;
_mode_t st_mode;
@@ -85,133 +86,134 @@
__time64_t st_atime;
__time64_t st_mtime;
__time64_t st_ctime;
-};
+ };
-typedef unsigned int sa_family_t;
+ typedef unsigned int sa_family_t;
-struct sockaddr_un {
- short sun_family; /*AF_UNIX*/
- char sun_path[108]; /*path name */
-};
+ struct sockaddr_un
+ {
+ short sun_family; /*AF_UNIX */
+ char sun_path[108]; /*path name */
+ };
#ifndef pid_t
- #define pid_t DWORD
+#define pid_t DWORD
#endif
#ifndef error_t
- #define error_t int
+#define error_t int
#endif
#ifndef WEXITSTATUS
- #define WEXITSTATUS(status) (((status) & 0xff00) >> 8)
+#define WEXITSTATUS(status) (((status) & 0xff00) >> 8)
#endif
#ifndef MSG_DONTWAIT
- #define MSG_DONTWAIT 0
+#define MSG_DONTWAIT 0
#endif
-enum
-{
- _SC_PAGESIZE = 30,
- _SC_PAGE_SIZE = 30
-};
+ enum
+ {
+ _SC_PAGESIZE = 30,
+ _SC_PAGE_SIZE = 30
+ };
/* Thanks to the Cygwin project */
-#define ENOCSI 43 /* No CSI structure available */
-#define EL2HLT 44 /* Level 2 halted */
+#define ENOCSI 43 /* No CSI structure available */
+#define EL2HLT 44 /* Level 2 halted */
#ifndef EDEADLK
- #define EDEADLK 45 /* Deadlock condition */
+#define EDEADLK 45 /* Deadlock condition */
#endif
#ifndef ENOLCK
- #define ENOLCK 46 /* No record locks available */
+#define ENOLCK 46 /* No record locks available */
#endif
-#define EBADE 50 /* Invalid exchange */
-#define EBADR 51 /* Invalid request descriptor */
-#define EXFULL 52 /* Exchange full */
-#define ENOANO 53 /* No anode */
-#define EBADRQC 54 /* Invalid request code */
-#define EBADSLT 55 /* Invalid slot */
+#define EBADE 50 /* Invalid exchange */
+#define EBADR 51 /* Invalid request descriptor */
+#define EXFULL 52 /* Exchange full */
+#define ENOANO 53 /* No anode */
+#define EBADRQC 54 /* Invalid request code */
+#define EBADSLT 55 /* Invalid slot */
#ifndef EDEADLOCK
- #define EDEADLOCK EDEADLK /* File locking deadlock error */
+#define EDEADLOCK EDEADLK /* File locking deadlock error */
#endif
-#define EBFONT 57 /* Bad font file fmt */
-#define ENOSTR 60 /* Device not a stream */
-#define ENODATA 61 /* No data (for no delay io) */
-#define ETIME 62 /* Timer expired */
-#define ENOSR 63 /* Out of streams resources */
-#define ENONET 64 /* Machine is not on the network */
-#define ENOPKG 65 /* Package not installed */
-#define EREMOTE 66 /* The object is remote */
-#define ENOLINK 67 /* The link has been severed */
-#define EADV 68 /* Advertise error */
-#define ESRMNT 69 /* Srmount error */
-#define ECOMM 70 /* Communication error on send */
-#define EPROTO 71 /* Protocol error */
-#define EMULTIHOP 74 /* Multihop attempted */
-#define ELBIN 75 /* Inode is remote (not really error) */
-#define EDOTDOT 76 /* Cross mount point (not really error) */
-#define EBADMSG 77 /* Trying to read unreadable message */
-#define ENOTUNIQ 80 /* Given log. name not unique */
-#define EBADFD 81 /* f.d. invalid for this operation */
-#define EREMCHG 82 /* Remote address changed */
-#define ELIBACC 83 /* Can't access a needed shared lib */
-#define ELIBBAD 84 /* Accessing a corrupted shared lib */
-#define ELIBSCN 85 /* .lib section in a.out corrupted */
-#define ELIBMAX 86 /* Attempting to link in too many libs */
-#define ELIBEXEC 87 /* Attempting to exec a shared library */
+#define EBFONT 57 /* Bad font file fmt */
+#define ENOSTR 60 /* Device not a stream */
+#define ENODATA 61 /* No data (for no delay io) */
+#define ETIME 62 /* Timer expired */
+#define ENOSR 63 /* Out of streams resources */
+#define ENONET 64 /* Machine is not on the network */
+#define ENOPKG 65 /* Package not installed */
+#define EREMOTE 66 /* The object is remote */
+#define ENOLINK 67 /* The link has been severed */
+#define EADV 68 /* Advertise error */
+#define ESRMNT 69 /* Srmount error */
+#define ECOMM 70 /* Communication error on send */
+#define EPROTO 71 /* Protocol error */
+#define EMULTIHOP 74 /* Multihop attempted */
+#define ELBIN 75 /* Inode is remote (not really error) */
+#define EDOTDOT 76 /* Cross mount point (not really error) */
+#define EBADMSG 77 /* Trying to read unreadable message */
+#define ENOTUNIQ 80 /* Given log. name not unique */
+#define EBADFD 81 /* f.d. invalid for this operation */
+#define EREMCHG 82 /* Remote address changed */
+#define ELIBACC 83 /* Can't access a needed shared lib */
+#define ELIBBAD 84 /* Accessing a corrupted shared lib */
+#define ELIBSCN 85 /* .lib section in a.out corrupted */
+#define ELIBMAX 86 /* Attempting to link in too many libs */
+#define ELIBEXEC 87 /* Attempting to exec a shared library */
#ifndef ENOSYS
- #define ENOSYS 88 /* Function not implemented */
+#define ENOSYS 88 /* Function not implemented */
#endif
-#define ENMFILE 89 /* No more files */
+#define ENMFILE 89 /* No more files */
#ifndef ENOTEMPTY
- #define ENOTEMPTY 90 /* Directory not empty */
+#define ENOTEMPTY 90 /* Directory not empty */
#endif
#ifndef ENAMETOOLONG
- #define ENAMETOOLONG 91 /* File or path name too long */
+#define ENAMETOOLONG 91 /* File or path name too long */
#endif
-#define ELOOP 92 /* Too many symbolic links */
-#define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */
-#define EPFNOSUPPORT 96 /* Protocol family not supported */
-#define ECONNRESET 104 /* Connection reset by peer */
-#define ENOBUFS 105 /* No buffer space available */
-#define EAFNOSUPPORT 106 /* Address family not supported by protocol family */
-#define EPROTOTYPE 107 /* Protocol wrong type for socket */
-#define ENOTSOCK 108 /* Socket operation on non-socket */
-#define ENOPROTOOPT 109 /* Protocol not available */
-#define ESHUTDOWN 110 /* Can't send after socket shutdown */
-#define ECONNREFUSED 111 /* Connection refused */
-#define EADDRINUSE 112 /* Address already in use */
-#define ECONNABORTED 113 /* Connection aborted */
-#define ENETUNREACH 114 /* Network is unreachable */
-#define ENETDOWN 115 /* Network interface is not configured */
+#define ELOOP 92 /* Too many symbolic links */
+#define EOPNOTSUPP 95 /* Operation not supported on transport
endpoint */
+#define EPFNOSUPPORT 96 /* Protocol family not supported */
+#define ECONNRESET 104 /* Connection reset by peer */
+#define ENOBUFS 105 /* No buffer space available */
+#define EAFNOSUPPORT 106 /* Address family not supported by protocol
family */
+#define EPROTOTYPE 107 /* Protocol wrong type for socket */
+#define ENOTSOCK 108 /* Socket operation on non-socket */
+#define ENOPROTOOPT 109 /* Protocol not available */
+#define ESHUTDOWN 110 /* Can't send after socket shutdown */
+#define ECONNREFUSED 111 /* Connection refused */
+#define EADDRINUSE 112 /* Address already in use */
+#define ECONNABORTED 113 /* Connection aborted */
+#define ENETUNREACH 114 /* Network is unreachable */
+#define ENETDOWN 115 /* Network interface is not configured */
#ifndef ETIMEDOUT
- #define ETIMEDOUT 116 /* Connection timed out */
+#define ETIMEDOUT 116 /* Connection timed out */
#endif
-#define EHOSTDOWN 117 /* Host is down */
-#define EHOSTUNREACH 118 /* Host is unreachable */
-#define EINPROGRESS 119 /* Connection already in progress */
-#define EALREADY 120 /* Socket already connected */
-#define EDESTADDRREQ 121 /* Destination address required */
-#define EMSGSIZE 122 /* Message too long */
-#define EPROTONOSUPPORT 123 /* Unknown protocol */
-#define ESOCKTNOSUPPORT 124 /* Socket type not supported */
-#define EADDRNOTAVAIL 125 /* Address not available */
-#define ENETRESET 126 /* Connection aborted by network */
-#define EISCONN 127 /* Socket is already connected */
-#define ENOTCONN 128 /* Socket is not connected */
-#define ETOOMANYREFS 129 /* Too many references: cannot splice */
-#define EPROCLIM 130 /* Too many processes */
-#define EUSERS 131 /* Too many users */
-#define EDQUOT 132 /* Disk quota exceeded */
-#define ESTALE 133 /* Unknown error */
+#define EHOSTDOWN 117 /* Host is down */
+#define EHOSTUNREACH 118 /* Host is unreachable */
+#define EINPROGRESS 119 /* Connection already in progress */
+#define EALREADY 120 /* Socket already connected */
+#define EDESTADDRREQ 121 /* Destination address required */
+#define EMSGSIZE 122 /* Message too long */
+#define EPROTONOSUPPORT 123 /* Unknown protocol */
+#define ESOCKTNOSUPPORT 124 /* Socket type not supported */
+#define EADDRNOTAVAIL 125 /* Address not available */
+#define ENETRESET 126 /* Connection aborted by network */
+#define EISCONN 127 /* Socket is already connected */
+#define ENOTCONN 128 /* Socket is not connected */
+#define ETOOMANYREFS 129 /* Too many references: cannot splice */
+#define EPROCLIM 130 /* Too many processes */
+#define EUSERS 131 /* Too many users */
+#define EDQUOT 132 /* Disk quota exceeded */
+#define ESTALE 133 /* Unknown error */
#ifndef ENOTSUP
- #define ENOTSUP 134 /* Not supported */
+#define ENOTSUP 134 /* Not supported */
#endif
-#define ENOMEDIUM 135 /* No medium (in tape drive) */
-#define ENOSHARE 136 /* No such host or network path */
-#define ECASECLASH 137 /* Filename exists with different case */
-#define EWOULDBLOCK EAGAIN /* Operation would block */
-#define EOVERFLOW 139 /* Value too large for defined data type */
+#define ENOMEDIUM 135 /* No medium (in tape drive) */
+#define ENOSHARE 136 /* No such host or network path */
+#define ECASECLASH 137 /* Filename exists with different case */
+#define EWOULDBLOCK EAGAIN /* Operation would block */
+#define EOVERFLOW 139 /* Value too large for defined data type */
#undef HOST_NOT_FOUND
#define HOST_NOT_FOUND 1
@@ -225,68 +227,68 @@
#define PROT_READ 0x1
#define PROT_WRITE 0x2
#define MAP_SHARED 0x1
-#define MAP_PRIVATE 0x2 /* unsupported */
+#define MAP_PRIVATE 0x2 /* unsupported */
#define MAP_FIXED 0x10
#define MAP_FAILED ((void *)-1)
-struct statfs
-{
- long f_type; /* type of filesystem (see below) */
- long f_bsize; /* optimal transfer block size */
- long f_blocks; /* total data blocks in file system */
- long f_bfree; /* free blocks in fs */
- long f_bavail; /* free blocks avail to non-superuser */
- long f_files; /* total file nodes in file system */
- long f_ffree; /* free file nodes in fs */
- long f_fsid; /* file system id */
- long f_namelen; /* maximum length of filenames */
- long f_spare[6]; /* spare for later */
-};
+ struct statfs
+ {
+ long f_type; /* type of filesystem (see below) */
+ long f_bsize; /* optimal transfer block size */
+ long f_blocks; /* total data blocks in file system */
+ long f_bfree; /* free blocks in fs */
+ long f_bavail; /* free blocks avail to non-superuser */
+ long f_files; /* total file nodes in file system */
+ long f_ffree; /* free file nodes in fs */
+ long f_fsid; /* file system id */
+ long f_namelen; /* maximum length of filenames */
+ long f_spare[6]; /* spare for later */
+ };
-extern const struct in6_addr in6addr_any; /* :: */
-extern const struct in6_addr in6addr_loopback; /* ::1 */
+ extern const struct in6_addr in6addr_any; /* :: */
+ extern const struct in6_addr in6addr_loopback; /* ::1 */
/* Taken from the Wine project <http://www.winehq.org>
/wine/include/winternl.h */
-enum SYSTEM_INFORMATION_CLASS
-{
- SystemBasicInformation = 0,
- Unknown1,
- SystemPerformanceInformation = 2,
- SystemTimeOfDayInformation = 3, /* was SystemTimeInformation */
- Unknown4,
- SystemProcessInformation = 5,
- Unknown6,
- Unknown7,
- SystemProcessorPerformanceInformation = 8,
- Unknown9,
- Unknown10,
- SystemDriverInformation,
- Unknown12,
- Unknown13,
- Unknown14,
- Unknown15,
- SystemHandleList,
- Unknown17,
- Unknown18,
- Unknown19,
- Unknown20,
- SystemCacheInformation,
- Unknown22,
- SystemInterruptInformation = 23,
- SystemExceptionInformation = 33,
- SystemRegistryQuotaInformation = 37,
- SystemLookasideInformation = 45
-};
+ enum SYSTEM_INFORMATION_CLASS
+ {
+ SystemBasicInformation = 0,
+ Unknown1,
+ SystemPerformanceInformation = 2,
+ SystemTimeOfDayInformation = 3, /* was SystemTimeInformation */
+ Unknown4,
+ SystemProcessInformation = 5,
+ Unknown6,
+ Unknown7,
+ SystemProcessorPerformanceInformation = 8,
+ Unknown9,
+ Unknown10,
+ SystemDriverInformation,
+ Unknown12,
+ Unknown13,
+ Unknown14,
+ Unknown15,
+ SystemHandleList,
+ Unknown17,
+ Unknown18,
+ Unknown19,
+ Unknown20,
+ SystemCacheInformation,
+ Unknown22,
+ SystemInterruptInformation = 23,
+ SystemExceptionInformation = 33,
+ SystemRegistryQuotaInformation = 37,
+ SystemLookasideInformation = 45
+ };
-typedef struct
-{
+ typedef struct
+ {
LARGE_INTEGER IdleTime;
LARGE_INTEGER KernelTime;
LARGE_INTEGER UserTime;
LARGE_INTEGER Reserved1[2];
ULONG Reserved2;
-} SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION;
+ } SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION;
#define sleep(secs) (Sleep(secs * 1000))
@@ -303,11 +305,11 @@
#define SHUT_RDWR SD_BOTH
/* Operations for flock() */
-#define LOCK_SH 1 /* shared lock */
-#define LOCK_EX 2 /* exclusive lock */
-#define LOCK_NB 4 /* or'd with one of the above to prevent
- blocking */
-#define LOCK_UN 8 /* remove lock */
+#define LOCK_SH 1 /* shared lock */
+#define LOCK_EX 2 /* exclusive lock */
+#define LOCK_NB 4 /* or'd with one of the above to prevent
+ * blocking */
+#define LOCK_UN 8 /* remove lock */
/* Not supported under MinGW */
#define S_IRGRP 0
@@ -331,330 +333,331 @@
#define SetErrnoFromWinError(e) _SetErrnoFromWinError(e, __FILE__, __LINE__)
-BOOL _plibc_CreateShortcut(const char *pszSrc, const char *pszDest);
-BOOL _plibc_DereferenceShortcut(char *pszShortcut);
-char *plibc_ChooseDir(char *pszTitle, unsigned long ulFlags);
-char *plibc_ChooseFile(char *pszTitle, unsigned long ulFlags);
-long QueryRegistry(HKEY hMainKey, const char *pszKey, const char *pszSubKey,
- char *pszBuffer, long *pdLength);
+ BOOL _plibc_CreateShortcut (const char *pszSrc, const char *pszDest);
+ BOOL _plibc_DereferenceShortcut (char *pszShortcut);
+ char *plibc_ChooseDir (char *pszTitle, unsigned long ulFlags);
+ char *plibc_ChooseFile (char *pszTitle, unsigned long ulFlags);
+ long QueryRegistry (HKEY hMainKey, const char *pszKey, const char *pszSubKey,
+ char *pszBuffer, long *pdLength);
-BOOL __win_IsHandleMarkedAsBlocking(int hHandle);
-void __win_SetHandleBlockingMode(int s, BOOL bBlocking);
-void __win_DiscardHandleBlockingMode(int s);
-int _win_isSocketValid(int s);
-int plibc_conv_to_win_path(const char *pszUnix, char *pszWindows);
-unsigned plibc_get_handle_count();
+ BOOL __win_IsHandleMarkedAsBlocking (int hHandle);
+ void __win_SetHandleBlockingMode (int s, BOOL bBlocking);
+ void __win_DiscardHandleBlockingMode (int s);
+ int _win_isSocketValid (int s);
+ int plibc_conv_to_win_path (const char *pszUnix, char *pszWindows);
+ unsigned plibc_get_handle_count ();
-typedef void (*TPanicProc) (int, char *);
-void plibc_set_panic_proc(TPanicProc proc);
+ typedef void (*TPanicProc) (int, char *);
+ void plibc_set_panic_proc (TPanicProc proc);
-int flock(int fd, int operation);
-int fsync(int fildes);
-int inet_pton(int af, const char *src, void *dst);
-int inet_pton4(const char *src, u_char *dst, int pton);
+ int flock (int fd, int operation);
+ int fsync (int fildes);
+ int inet_pton (int af, const char *src, void *dst);
+ int inet_pton4 (const char *src, u_char * dst, int pton);
#if USE_IPV6
-int inet_pton6(const char *src, u_char *dst);
+ int inet_pton6 (const char *src, u_char * dst);
#endif
-int truncate(const char *fname, int distance);
-int statfs(const char *path, struct statfs *buf);
-const char *hstrerror(int err);
-int mkstemp(char *tmplate);
-char *strptime (const char *buf, const char *format, struct tm *tm);
-const char *inet_ntop(int af, const void *src, char *dst, size_t size);
+ int truncate (const char *fname, int distance);
+ int statfs (const char *path, struct statfs *buf);
+ const char *hstrerror (int err);
+ int mkstemp (char *tmplate);
+ char *strptime (const char *buf, const char *format, struct tm *tm);
+ const char *inet_ntop (int af, const void *src, char *dst, size_t size);
-int plibc_init(char *pszOrg, char *pszApp);
-void plibc_shutdown();
-int plibc_initialized();
-int plibc_conv_to_win_path_ex(const char *pszUnix, char *pszWindows, int
derefLinks);
-void _SetErrnoFromWinError(long lWinError, char *pszCaller, int iLine);
-void SetErrnoFromWinsockError(long lWinError);
-void SetHErrnoFromWinError(long lWinError);
-void SetErrnoFromHRESULT(HRESULT hRes);
-int GetErrnoFromWinsockError(long lWinError);
-FILE *_win_fopen(const char *filename, const char *mode);
-DIR *_win_opendir(const char *dirname);
-int _win_open(const char *filename, int oflag, ...);
+ int plibc_init (char *pszOrg, char *pszApp);
+ void plibc_shutdown ();
+ int plibc_initialized ();
+ int plibc_conv_to_win_path_ex (const char *pszUnix, char *pszWindows,
+ int derefLinks);
+ void _SetErrnoFromWinError (long lWinError, char *pszCaller, int iLine);
+ void SetErrnoFromWinsockError (long lWinError);
+ void SetHErrnoFromWinError (long lWinError);
+ void SetErrnoFromHRESULT (HRESULT hRes);
+ int GetErrnoFromWinsockError (long lWinError);
+ FILE *_win_fopen (const char *filename, const char *mode);
+ DIR *_win_opendir (const char *dirname);
+ int _win_open (const char *filename, int oflag, ...);
#ifdef ENABLE_NLS
-char *_win_bindtextdomain(const char *domainname, const char *dirname);
+ char *_win_bindtextdomain (const char *domainname, const char *dirname);
#endif
-int _win_chdir(const char *path);
-int _win_close(int fd);
-int _win_creat(const char *path, mode_t mode);
-char *_win_ctime(const time_t *clock);
-char *_win_ctime_r(const time_t *clock, char *buf);
-int _win_fstat(int handle, struct stat *buffer);
-int _win_ftruncate(int fildes, off_t length);
-void _win_gettimeofday(struct timeval *tp, void *tzp);
-int _win_kill(pid_t pid, int sig);
-int _win_pipe(int *phandles);
-int _win_rmdir(const char *path);
-int _win_access( const char *path, int mode );
-int _win_chmod(const char *filename, int pmode);
-char *realpath(const char *file_name, char *resolved_name);
-long _win_random(void);
-void _win_srandom(unsigned int seed);
-int _win_remove(const char *path);
-int _win_rename(const char *oldname, const char *newname);
-int _win_stat(const char *path, struct stat *buffer);
-int _win_stat64(const char *path, struct stat64 *buffer);
-long _win_sysconf(int name);
-int _win_unlink(const char *filename);
-int _win_write(int fildes, const void *buf, size_t nbyte);
-int _win_read(int fildes, void *buf, size_t nbyte);
-size_t _win_fwrite(const void *buffer, size_t size, size_t count, FILE
*stream);
-size_t _win_fread( void *buffer, size_t size, size_t count, FILE *stream );
-int _win_symlink(const char *path1, const char *path2);
-void *_win_mmap(void *start, size_t len, int access, int flags, int fd,
- unsigned long long offset);
-int _win_munmap(void *start, size_t length);
-int _win_lstat(const char *path, struct stat *buf);
-int _win_lstat64(const char *path, struct stat64 *buf);
-int _win_readlink(const char *path, char *buf, size_t bufsize);
-int _win_accept(int s, struct sockaddr *addr, int *addrlen);
-int _win_printf(const char *format,...);
-int _win_fprintf(FILE *f,const char *format,...);
-int _win_vprintf(const char *format, va_list ap);
-int _win_vfprintf(FILE *stream, const char *format, va_list arg_ptr);
-int _win_vsprintf(char *dest,const char *format, va_list arg_ptr);
-int _win_vsnprintf(char* str, size_t size, const char *format, va_list
arg_ptr);
-int _win_snprintf(char *str,size_t size,const char *format,...);
-int _win_sprintf(char *dest,const char *format,...);
-int _win_vsscanf(const char* str, const char* format, va_list arg_ptr);
-int _win_sscanf(const char *str, const char *format, ...);
-int _win_vfscanf(FILE *stream, const char *format, va_list arg_ptr);
-int _win_vscanf(const char *format, va_list arg_ptr);
-int _win_scanf(const char *format, ...);
-int _win_fscanf(FILE *stream, const char *format, ...);
-pid_t _win_waitpid(pid_t pid, int *stat_loc, int options);
-int _win_bind(int s, const struct sockaddr *name, int namelen);
-int _win_connect(int s,const struct sockaddr *name, int namelen);
-int _win_getpeername(int s, struct sockaddr *name,
- int *namelen);
-int _win_getsockname(int s, struct sockaddr *name,
- int *namelen);
-int _win_getsockopt(int s, int level, int optname, char *optval,
- int *optlen);
-int _win_listen(int s, int backlog);
-int _win_recv(int s, char *buf, int len, int flags);
-int _win_recvfrom(int s, void *buf, int len, int flags,
- struct sockaddr *from, int *fromlen);
-int _win_select(int max_fd, fd_set * rfds, fd_set * wfds, fd_set * efds,
- const struct timeval *tv);
-int _win_send(int s, const char *buf, int len, int flags);
-int _win_sendto(int s, const char *buf, int len, int flags,
- const struct sockaddr *to, int tolen);
-int _win_setsockopt(int s, int level, int optname, const void *optval,
- int optlen);
-int _win_shutdown(int s, int how);
-int _win_socket(int af, int type, int protocol);
-struct hostent *_win_gethostbyaddr(const char *addr, int len, int type);
-struct hostent *_win_gethostbyname(const char *name);
-struct hostent *gethostbyname2(const char *name, int af);
-char *_win_strerror(int errnum);
-int IsWinNT();
-char *index(const char *s, int c);
+ int _win_chdir (const char *path);
+ int _win_close (int fd);
+ int _win_creat (const char *path, mode_t mode);
+ char *_win_ctime (const time_t * clock);
+ char *_win_ctime_r (const time_t * clock, char *buf);
+ int _win_fstat (int handle, struct stat *buffer);
+ int _win_ftruncate (int fildes, off_t length);
+ void _win_gettimeofday (struct timeval *tp, void *tzp);
+ int _win_kill (pid_t pid, int sig);
+ int _win_pipe (int *phandles);
+ int _win_rmdir (const char *path);
+ int _win_access (const char *path, int mode);
+ int _win_chmod (const char *filename, int pmode);
+ char *realpath (const char *file_name, char *resolved_name);
+ long _win_random (void);
+ void _win_srandom (unsigned int seed);
+ int _win_remove (const char *path);
+ int _win_rename (const char *oldname, const char *newname);
+ int _win_stat (const char *path, struct stat *buffer);
+ int _win_stat64 (const char *path, struct stat64 *buffer);
+ long _win_sysconf (int name);
+ int _win_unlink (const char *filename);
+ int _win_write (int fildes, const void *buf, size_t nbyte);
+ int _win_read (int fildes, void *buf, size_t nbyte);
+ size_t _win_fwrite (const void *buffer, size_t size, size_t count,
+ FILE * stream);
+ size_t _win_fread (void *buffer, size_t size, size_t count, FILE * stream);
+ int _win_symlink (const char *path1, const char *path2);
+ void *_win_mmap (void *start, size_t len, int access, int flags, int fd,
+ unsigned long long offset);
+ int _win_munmap (void *start, size_t length);
+ int _win_lstat (const char *path, struct stat *buf);
+ int _win_lstat64 (const char *path, struct stat64 *buf);
+ int _win_readlink (const char *path, char *buf, size_t bufsize);
+ int _win_accept (int s, struct sockaddr *addr, int *addrlen);
+ int _win_printf (const char *format, ...);
+ int _win_fprintf (FILE * f, const char *format, ...);
+ int _win_vprintf (const char *format, va_list ap);
+ int _win_vfprintf (FILE * stream, const char *format, va_list arg_ptr);
+ int _win_vsprintf (char *dest, const char *format, va_list arg_ptr);
+ int _win_vsnprintf (char *str, size_t size, const char *format,
+ va_list arg_ptr);
+ int _win_snprintf (char *str, size_t size, const char *format, ...);
+ int _win_sprintf (char *dest, const char *format, ...);
+ int _win_vsscanf (const char *str, const char *format, va_list arg_ptr);
+ int _win_sscanf (const char *str, const char *format, ...);
+ int _win_vfscanf (FILE * stream, const char *format, va_list arg_ptr);
+ int _win_vscanf (const char *format, va_list arg_ptr);
+ int _win_scanf (const char *format, ...);
+ int _win_fscanf (FILE * stream, const char *format, ...);
+ pid_t _win_waitpid (pid_t pid, int *stat_loc, int options);
+ int _win_bind (int s, const struct sockaddr *name, int namelen);
+ int _win_connect (int s, const struct sockaddr *name, int namelen);
+ int _win_getpeername (int s, struct sockaddr *name, int *namelen);
+ int _win_getsockname (int s, struct sockaddr *name, int *namelen);
+ int _win_getsockopt (int s, int level, int optname, char *optval,
+ int *optlen);
+ int _win_listen (int s, int backlog);
+ int _win_recv (int s, char *buf, int len, int flags);
+ int _win_recvfrom (int s, void *buf, int len, int flags,
+ struct sockaddr *from, int *fromlen);
+ int _win_select (int max_fd, fd_set * rfds, fd_set * wfds, fd_set * efds,
+ const struct timeval *tv);
+ int _win_send (int s, const char *buf, int len, int flags);
+ int _win_sendto (int s, const char *buf, int len, int flags,
+ const struct sockaddr *to, int tolen);
+ int _win_setsockopt (int s, int level, int optname, const void *optval,
+ int optlen);
+ int _win_shutdown (int s, int how);
+ int _win_socket (int af, int type, int protocol);
+ struct hostent *_win_gethostbyaddr (const char *addr, int len, int type);
+ struct hostent *_win_gethostbyname (const char *name);
+ struct hostent *gethostbyname2 (const char *name, int af);
+ char *_win_strerror (int errnum);
+ int IsWinNT ();
+ char *index (const char *s, int c);
#if !HAVE_STRNDUP
-char *strndup (const char *s, size_t n);
+ char *strndup (const char *s, size_t n);
#endif
#if !HAVE_STRNLEN
-size_t strnlen (const char *str, size_t maxlen);
+ size_t strnlen (const char *str, size_t maxlen);
#endif
-char *stpcpy(char *dest, const char *src);
-char *strcasestr(const char *haystack_start, const char *needle_start);
+ char *stpcpy (char *dest, const char *src);
+ char *strcasestr (const char *haystack_start, const char *needle_start);
#define strcasecmp(a, b) stricmp(a, b)
#define strncasecmp(a, b, c) strnicmp(a, b, c)
-#endif /* WINDOWS */
+#endif /* WINDOWS */
#ifndef WINDOWS
- #define DIR_SEPARATOR '/'
- #define DIR_SEPARATOR_STR "/"
- #define PATH_SEPARATOR ':'
- #define PATH_SEPARATOR_STR ":"
- #define NEWLINE "\n"
+#define DIR_SEPARATOR '/'
+#define DIR_SEPARATOR_STR "/"
+#define PATH_SEPARATOR ':'
+#define PATH_SEPARATOR_STR ":"
+#define NEWLINE "\n"
#ifdef ENABLE_NLS
- #define BINDTEXTDOMAIN(d, n) bindtextdomain(d, n)
+#define BINDTEXTDOMAIN(d, n) bindtextdomain(d, n)
#endif
- #define CREAT(p, m) creat(p, m)
- #define PLIBC_CTIME(c) ctime(c)
- #define CTIME_R(c, b) ctime_r(c, b)
- #undef FOPEN
- #define FOPEN(f, m) fopen(f, m)
- #define FTRUNCATE(f, l) ftruncate(f, l)
- #define OPENDIR(d) opendir(d)
- #define OPEN open
- #define CHDIR(d) chdir(d)
- #define CLOSE(f) close(f)
- #define LSEEK(f, o, w) lseek(f, o, w)
- #define RMDIR(f) rmdir(f)
- #define ACCESS(p, m) access(p, m)
- #define CHMOD(f, p) chmod(f, p)
- #define FSTAT(h, b) fstat(h, b)
- #define PLIBC_KILL(p, s) kill(p, s)
- #define PIPE(h) pipe(h)
- #define REMOVE(p) remove(p)
- #define RENAME(o, n) rename(o, n)
- #define STAT(p, b) stat(p, b)
- #define STAT64(p, b) stat64(p, b)
- #define SYSCONF(n) sysconf(n)
- #define UNLINK(f) unlink(f)
- #define WRITE(f, b, n) write(f, b, n)
- #define READ(f, b, n) read(f, b, n)
- #define GN_FREAD(b, s, c, f) fread(b, s, c, f)
- #define GN_FWRITE(b, s, c, f) fwrite(b, s, c, f)
- #define SYMLINK(a, b) symlink(a, b)
- #define MMAP(s, l, p, f, d, o) mmap(s, l, p, f, d, o)
- #define MUNMAP(s, l) munmap(s, l)
- #define STRERROR(i) strerror(i)
- #define RANDOM() random()
- #define SRANDOM(s) srandom(s)
- #define READLINK(p, b, s) readlink(p, b, s)
- #define LSTAT(p, b) lstat(p, b)
- #define LSTAT64(p, b) lstat64(p, b)
- #define PRINTF printf
- #define FPRINTF fprintf
- #define VPRINTF(f, a) vprintf(f, a)
- #define VFPRINTF(s, f, a) vfprintf(s, f, a)
- #define VSPRINTF(d, f, a) vsprintf(d, f, a)
- #define VSNPRINTF(str, size, fmt, a) vsnprintf(str, size, fmt, a)
- #define _REAL_SNPRINTF snprintf
- #define SPRINTF sprintf
- #define VSSCANF(s, f, a) vsscanf(s, f, a)
- #define SSCANF sscanf
- #define VFSCANF(s, f, a) vfscanf(s, f, a)
- #define VSCANF(f, a) vscanf(f, a)
- #define SCANF scanf
- #define FSCANF fscanf
- #define WAITPID(p, s, o) waitpid(p, s, o)
- #define ACCEPT(s, a, l) accept(s, a, l)
- #define BIND(s, n, l) bind(s, n, l)
- #define CONNECT(s, n, l) connect(s, n, l)
- #define GETPEERNAME(s, n, l) getpeername(s, n, l)
- #define GETSOCKNAME(s, n, l) getsockname(s, n, l)
- #define GETSOCKOPT(s, l, o, v, p) getsockopt(s, l, o, v, p)
- #define LISTEN(s, b) listen(s, b)
- #define RECV(s, b, l, f) recv(s, b, l, f)
- #define RECVFROM(s, b, l, f, r, o) recvfrom(s, b, l, f, r, o)
- #define SELECT(n, r, w, e, t) select(n, r, w, e, t)
- #define SEND(s, b, l, f) send(s, b, l, f)
- #define SENDTO(s, b, l, f, o, n) sendto(s, b, l, f, o, n)
- #define SETSOCKOPT(s, l, o, v, n) setsockopt(s, l, o, v, n)
- #define SHUTDOWN(s, h) shutdown(s, h)
- #define SOCKET(a, t, p) socket(a, t, p)
- #define GETHOSTBYADDR(a, l, t) gethostbyname(a, l, t)
- #define GETHOSTBYNAME(n) gethostbyname(n)
- #define GETTIMEOFDAY(t, n) gettimeofday(t, n)
- #define INSQUE(e, p) insque(e, p)
- #define REMQUE(e) remque(e)
- #define HSEARCH(i, a) hsearch(i, a)
- #define HCREATE(n) hcreate(n)
- #define HDESTROY() hdestroy()
- #define HSEARCH_R(i, a, r, h) hsearch_r(i, a, r, h)
- #define HCREATE_R(n, h) hcreate_r(n, h)
- #define HDESTROY_R(h) hdestroy_r(h)
- #define TSEARCH(k, r, c) tsearch(k, r, c)
- #define TFIND(k, r, c) tfind(k, r, c)
- #define TDELETE(k, r, c) tdelete(k, r, c)
- #define TWALK(r, a) twalk(r, a)
- #define TDESTROY(r, f) tdestroy(r, f)
- #define LFIND(k, b, n, s, c) lfind(k, b, n, s, c)
- #define LSEARCH(k, b, n, s, c) lsearch(k, b, n, s, c)
+#define CREAT(p, m) creat(p, m)
+#define PLIBC_CTIME(c) ctime(c)
+#define CTIME_R(c, b) ctime_r(c, b)
+#undef FOPEN
+#define FOPEN(f, m) fopen(f, m)
+#define FTRUNCATE(f, l) ftruncate(f, l)
+#define OPENDIR(d) opendir(d)
+#define OPEN open
+#define CHDIR(d) chdir(d)
+#define CLOSE(f) close(f)
+#define LSEEK(f, o, w) lseek(f, o, w)
+#define RMDIR(f) rmdir(f)
+#define ACCESS(p, m) access(p, m)
+#define CHMOD(f, p) chmod(f, p)
+#define FSTAT(h, b) fstat(h, b)
+#define PLIBC_KILL(p, s) kill(p, s)
+#define PIPE(h) pipe(h)
+#define REMOVE(p) remove(p)
+#define RENAME(o, n) rename(o, n)
+#define STAT(p, b) stat(p, b)
+#define STAT64(p, b) stat64(p, b)
+#define SYSCONF(n) sysconf(n)
+#define UNLINK(f) unlink(f)
+#define WRITE(f, b, n) write(f, b, n)
+#define READ(f, b, n) read(f, b, n)
+#define GN_FREAD(b, s, c, f) fread(b, s, c, f)
+#define GN_FWRITE(b, s, c, f) fwrite(b, s, c, f)
+#define SYMLINK(a, b) symlink(a, b)
+#define MMAP(s, l, p, f, d, o) mmap(s, l, p, f, d, o)
+#define MUNMAP(s, l) munmap(s, l)
+#define STRERROR(i) strerror(i)
+#define RANDOM() random()
+#define SRANDOM(s) srandom(s)
+#define READLINK(p, b, s) readlink(p, b, s)
+#define LSTAT(p, b) lstat(p, b)
+#define LSTAT64(p, b) lstat64(p, b)
+#define PRINTF printf
+#define FPRINTF fprintf
+#define VPRINTF(f, a) vprintf(f, a)
+#define VFPRINTF(s, f, a) vfprintf(s, f, a)
+#define VSPRINTF(d, f, a) vsprintf(d, f, a)
+#define VSNPRINTF(str, size, fmt, a) vsnprintf(str, size, fmt, a)
+#define _REAL_SNPRINTF snprintf
+#define SPRINTF sprintf
+#define VSSCANF(s, f, a) vsscanf(s, f, a)
+#define SSCANF sscanf
+#define VFSCANF(s, f, a) vfscanf(s, f, a)
+#define VSCANF(f, a) vscanf(f, a)
+#define SCANF scanf
+#define FSCANF fscanf
+#define WAITPID(p, s, o) waitpid(p, s, o)
+#define ACCEPT(s, a, l) accept(s, a, l)
+#define BIND(s, n, l) bind(s, n, l)
+#define CONNECT(s, n, l) connect(s, n, l)
+#define GETPEERNAME(s, n, l) getpeername(s, n, l)
+#define GETSOCKNAME(s, n, l) getsockname(s, n, l)
+#define GETSOCKOPT(s, l, o, v, p) getsockopt(s, l, o, v, p)
+#define LISTEN(s, b) listen(s, b)
+#define RECV(s, b, l, f) recv(s, b, l, f)
+#define RECVFROM(s, b, l, f, r, o) recvfrom(s, b, l, f, r, o)
+#define SELECT(n, r, w, e, t) select(n, r, w, e, t)
+#define SEND(s, b, l, f) send(s, b, l, f)
+#define SENDTO(s, b, l, f, o, n) sendto(s, b, l, f, o, n)
+#define SETSOCKOPT(s, l, o, v, n) setsockopt(s, l, o, v, n)
+#define SHUTDOWN(s, h) shutdown(s, h)
+#define SOCKET(a, t, p) socket(a, t, p)
+#define GETHOSTBYADDR(a, l, t) gethostbyname(a, l, t)
+#define GETHOSTBYNAME(n) gethostbyname(n)
+#define GETTIMEOFDAY(t, n) gettimeofday(t, n)
+#define INSQUE(e, p) insque(e, p)
+#define REMQUE(e) remque(e)
+#define HSEARCH(i, a) hsearch(i, a)
+#define HCREATE(n) hcreate(n)
+#define HDESTROY() hdestroy()
+#define HSEARCH_R(i, a, r, h) hsearch_r(i, a, r, h)
+#define HCREATE_R(n, h) hcreate_r(n, h)
+#define HDESTROY_R(h) hdestroy_r(h)
+#define TSEARCH(k, r, c) tsearch(k, r, c)
+#define TFIND(k, r, c) tfind(k, r, c)
+#define TDELETE(k, r, c) tdelete(k, r, c)
+#define TWALK(r, a) twalk(r, a)
+#define TDESTROY(r, f) tdestroy(r, f)
+#define LFIND(k, b, n, s, c) lfind(k, b, n, s, c)
+#define LSEARCH(k, b, n, s, c) lsearch(k, b, n, s, c)
#else
- #define DIR_SEPARATOR '\\'
- #define DIR_SEPARATOR_STR "\\"
- #define PATH_SEPARATOR ';'
- #define PATH_SEPARATOR_STR ";"
- #define NEWLINE "\r\n"
+#define DIR_SEPARATOR '\\'
+#define DIR_SEPARATOR_STR "\\"
+#define PATH_SEPARATOR ';'
+#define PATH_SEPARATOR_STR ";"
+#define NEWLINE "\r\n"
#ifdef ENABLE_NLS
- #define BINDTEXTDOMAIN(d, n) _win_bindtextdomain(d, n)
+#define BINDTEXTDOMAIN(d, n) _win_bindtextdomain(d, n)
#endif
- #define CREAT(p, m) _win_creat(p, m)
- #define PLIBC_CTIME(c) _win_ctime(c)
- #define CTIME_R(c, b) _win_ctime_r(c, b)
- #define FOPEN(f, m) _win_fopen(f, m)
- #define FTRUNCATE(f, l) _win_ftruncate(f, l)
- #define OPENDIR(d) _win_opendir(d)
- #define OPEN _win_open
- #define CHDIR(d) _win_chdir(d)
- #define CLOSE(f) _win_close(f)
- #define PLIBC_KILL(p, s) _win_kill(p, s)
- #define LSEEK(f, o, w) _win_lseek(f, o, w)
- #define FSTAT(h, b) _win_fstat(h, b)
- #define RMDIR(f) _win_rmdir(f)
- #define ACCESS(p, m) _win_access(p, m)
- #define CHMOD(f, p) _win_chmod(f, p)
- #define PIPE(h) _win_pipe(h)
- #define RANDOM() _win_random()
- #define SRANDOM(s) _win_srandom(s)
- #define REMOVE(p) _win_remove(p)
- #define RENAME(o, n) _win_rename(o, n)
- #define STAT(p, b) _win_stat(p, b)
- #define STAT64(p, b) _win_stat64(p, b)
- #define SYSCONF(n) _win_sysconf(n)
- #define UNLINK(f) _win_unlink(f)
- #define WRITE(f, b, n) _win_write(f, b, n)
- #define READ(f, b, n) _win_read(f, b, n)
- #define GN_FREAD(b, s, c, f) _win_fread(b, s, c, f)
- #define GN_FWRITE(b, s, c, f) _win_fwrite(b, s, c, f)
- #define SYMLINK(a, b) _win_symlink(a, b)
- #define MMAP(s, l, p, f, d, o) _win_mmap(s, l, p, f, d, o)
- #define MUNMAP(s, l) _win_munmap(s, l)
- #define STRERROR(i) _win_strerror(i)
- #define READLINK(p, b, s) _win_readlink(p, b, s)
- #define LSTAT(p, b) _win_lstat(p, b)
- #define LSTAT64(p, b) _win_lstat64(p, b)
- #define PRINTF(f, ...) _win_printf(f , __VA_ARGS__)
- #define FPRINTF(fil, fmt, ...) _win_fprintf(fil, fmt, __VA_ARGS__)
- #define VPRINTF(f, a) _win_vprintf(f, a)
- #define VFPRINTF(s, f, a) _win_vfprintf(s, f, a)
- #define VSPRINTF(d, f, a) _win_vsprintf(d, f, a)
- #define VSNPRINTF(str, size, fmt, a) _win_vsnprintf(str, size, fmt, a)
- #define _REAL_SNPRINTF(str, size, fmt, ...) _win_snprintf(str, size, fmt,
__VA_ARGS__)
- #define SPRINTF(d, f, ...) _win_sprintf(d, f, __VA_ARGS__)
- #define VSSCANF(s, f, a) _win_vsscanf(s, f, a)
- #define SSCANF(s, f, ...) _win_sscanf(s, f, __VA_ARGS__)
- #define VFSCANF(s, f, a) _win_vfscanf(s, f, a)
- #define VSCANF(f, a) _win_vscanf(f, a)
- #define SCANF(f, ...) _win_scanf(f, __VA_ARGS__)
- #define FSCANF(s, f, ...) _win_fscanf(s, f, __VA_ARGS__)
- #define WAITPID(p, s, o) _win_waitpid(p, s, o)
- #define ACCEPT(s, a, l) _win_accept(s, a, l)
- #define BIND(s, n, l) _win_bind(s, n, l)
- #define CONNECT(s, n, l) _win_connect(s, n, l)
- #define GETPEERNAME(s, n, l) _win_getpeername(s, n, l)
- #define GETSOCKNAME(s, n, l) _win_getsockname(s, n, l)
- #define GETSOCKOPT(s, l, o, v, p) _win_getsockopt(s, l, o, v, p)
- #define LISTEN(s, b) _win_listen(s, b)
- #define RECV(s, b, l, f) _win_recv(s, b, l, f)
- #define RECVFROM(s, b, l, f, r, o) _win_recvfrom(s, b, l, f, r, o)
- #define SELECT(n, r, w, e, t) _win_select(n, r, w, e, t)
- #define SEND(s, b, l, f) _win_send(s, b, l, f)
- #define SENDTO(s, b, l, f, o, n) _win_sendto(s, b, l, f, o, n)
- #define SETSOCKOPT(s, l, o, v, n) _win_setsockopt(s, l, o, v, n)
- #define SHUTDOWN(s, h) _win_shutdown(s, h)
- #define SOCKET(a, t, p) _win_socket(a, t, p)
- #define GETHOSTBYADDR(a, l, t) _win_gethostbyname(a, l, t)
- #define GETHOSTBYNAME(n) _win_gethostbyname(n)
- #define GETTIMEOFDAY(t, n) _win_gettimeofday(t, n)
- #define INSQUE(e, p) _win_insque(e, p)
- #define REMQUE(e) _win_remque(e)
- #define HSEARCH(i, a) _win_hsearch(i, a)
- #define HCREATE(n) _win_hcreate(n)
- #define HDESTROY() _win_hdestroy()
- #define HSEARCH_R(i, a, r, h) _win_hsearch_r(i, a, r, h)
- #define HCREATE_R(n, h) _win_hcreate_r(n, h)
- #define HDESTROY_R(h) _win_hdestroy_r(h)
- #define TSEARCH(k, r, c) _win_tsearch(k, r, c)
- #define TFIND(k, r, c) _win_tfind(k, r, c)
- #define TDELETE(k, r, c) _win_tdelete(k, r, c)
- #define TWALK(r, a) _win_twalk(r, a)
- #define TDESTROY(r, f) _win_tdestroy(r, f)
- #define LFIND(k, b, n, s, c) _win_lfind(k, b, n, s, c)
- #define LSEARCH(k, b, n, s, c) _win_lsearch(k, b, n, s, c)
+#define CREAT(p, m) _win_creat(p, m)
+#define PLIBC_CTIME(c) _win_ctime(c)
+#define CTIME_R(c, b) _win_ctime_r(c, b)
+#define FOPEN(f, m) _win_fopen(f, m)
+#define FTRUNCATE(f, l) _win_ftruncate(f, l)
+#define OPENDIR(d) _win_opendir(d)
+#define OPEN _win_open
+#define CHDIR(d) _win_chdir(d)
+#define CLOSE(f) _win_close(f)
+#define PLIBC_KILL(p, s) _win_kill(p, s)
+#define LSEEK(f, o, w) _win_lseek(f, o, w)
+#define FSTAT(h, b) _win_fstat(h, b)
+#define RMDIR(f) _win_rmdir(f)
+#define ACCESS(p, m) _win_access(p, m)
+#define CHMOD(f, p) _win_chmod(f, p)
+#define PIPE(h) _win_pipe(h)
+#define RANDOM() _win_random()
+#define SRANDOM(s) _win_srandom(s)
+#define REMOVE(p) _win_remove(p)
+#define RENAME(o, n) _win_rename(o, n)
+#define STAT(p, b) _win_stat(p, b)
+#define STAT64(p, b) _win_stat64(p, b)
+#define SYSCONF(n) _win_sysconf(n)
+#define UNLINK(f) _win_unlink(f)
+#define WRITE(f, b, n) _win_write(f, b, n)
+#define READ(f, b, n) _win_read(f, b, n)
+#define GN_FREAD(b, s, c, f) _win_fread(b, s, c, f)
+#define GN_FWRITE(b, s, c, f) _win_fwrite(b, s, c, f)
+#define SYMLINK(a, b) _win_symlink(a, b)
+#define MMAP(s, l, p, f, d, o) _win_mmap(s, l, p, f, d, o)
+#define MUNMAP(s, l) _win_munmap(s, l)
+#define STRERROR(i) _win_strerror(i)
+#define READLINK(p, b, s) _win_readlink(p, b, s)
+#define LSTAT(p, b) _win_lstat(p, b)
+#define LSTAT64(p, b) _win_lstat64(p, b)
+#define PRINTF(f, ...) _win_printf(f , __VA_ARGS__)
+#define FPRINTF(fil, fmt, ...) _win_fprintf(fil, fmt, __VA_ARGS__)
+#define VPRINTF(f, a) _win_vprintf(f, a)
+#define VFPRINTF(s, f, a) _win_vfprintf(s, f, a)
+#define VSPRINTF(d, f, a) _win_vsprintf(d, f, a)
+#define VSNPRINTF(str, size, fmt, a) _win_vsnprintf(str, size, fmt, a)
+#define _REAL_SNPRINTF(str, size, fmt, ...) _win_snprintf(str, size, fmt,
__VA_ARGS__)
+#define SPRINTF(d, f, ...) _win_sprintf(d, f, __VA_ARGS__)
+#define VSSCANF(s, f, a) _win_vsscanf(s, f, a)
+#define SSCANF(s, f, ...) _win_sscanf(s, f, __VA_ARGS__)
+#define VFSCANF(s, f, a) _win_vfscanf(s, f, a)
+#define VSCANF(f, a) _win_vscanf(f, a)
+#define SCANF(f, ...) _win_scanf(f, __VA_ARGS__)
+#define FSCANF(s, f, ...) _win_fscanf(s, f, __VA_ARGS__)
+#define WAITPID(p, s, o) _win_waitpid(p, s, o)
+#define ACCEPT(s, a, l) _win_accept(s, a, l)
+#define BIND(s, n, l) _win_bind(s, n, l)
+#define CONNECT(s, n, l) _win_connect(s, n, l)
+#define GETPEERNAME(s, n, l) _win_getpeername(s, n, l)
+#define GETSOCKNAME(s, n, l) _win_getsockname(s, n, l)
+#define GETSOCKOPT(s, l, o, v, p) _win_getsockopt(s, l, o, v, p)
+#define LISTEN(s, b) _win_listen(s, b)
+#define RECV(s, b, l, f) _win_recv(s, b, l, f)
+#define RECVFROM(s, b, l, f, r, o) _win_recvfrom(s, b, l, f, r, o)
+#define SELECT(n, r, w, e, t) _win_select(n, r, w, e, t)
+#define SEND(s, b, l, f) _win_send(s, b, l, f)
+#define SENDTO(s, b, l, f, o, n) _win_sendto(s, b, l, f, o, n)
+#define SETSOCKOPT(s, l, o, v, n) _win_setsockopt(s, l, o, v, n)
+#define SHUTDOWN(s, h) _win_shutdown(s, h)
+#define SOCKET(a, t, p) _win_socket(a, t, p)
+#define GETHOSTBYADDR(a, l, t) _win_gethostbyname(a, l, t)
+#define GETHOSTBYNAME(n) _win_gethostbyname(n)
+#define GETTIMEOFDAY(t, n) _win_gettimeofday(t, n)
+#define INSQUE(e, p) _win_insque(e, p)
+#define REMQUE(e) _win_remque(e)
+#define HSEARCH(i, a) _win_hsearch(i, a)
+#define HCREATE(n) _win_hcreate(n)
+#define HDESTROY() _win_hdestroy()
+#define HSEARCH_R(i, a, r, h) _win_hsearch_r(i, a, r, h)
+#define HCREATE_R(n, h) _win_hcreate_r(n, h)
+#define HDESTROY_R(h) _win_hdestroy_r(h)
+#define TSEARCH(k, r, c) _win_tsearch(k, r, c)
+#define TFIND(k, r, c) _win_tfind(k, r, c)
+#define TDELETE(k, r, c) _win_tdelete(k, r, c)
+#define TWALK(r, a) _win_twalk(r, a)
+#define TDESTROY(r, f) _win_tdestroy(r, f)
+#define LFIND(k, b, n, s, c) _win_lfind(k, b, n, s, c)
+#define LSEARCH(k, b, n, s, c) _win_lsearch(k, b, n, s, c)
#endif
/* search.h */
@@ -662,7 +665,7 @@
/* Prototype structure for a linked-list data structure.
This is the type used by the `insque' and `remque' functions. */
-struct PLIBC_SEARCH_QELEM
+ struct PLIBC_SEARCH_QELEM
{
struct qelem *q_forw;
struct qelem *q_back;
@@ -671,41 +674,41 @@
/* Insert ELEM into a doubly-linked list, after PREV. */
-void _win_insque (void *__elem, void *__prev);
+ void _win_insque (void *__elem, void *__prev);
/* Unlink ELEM from the doubly-linked list that it is in. */
-void _win_remque (void *__elem);
+ void _win_remque (void *__elem);
/* For use with hsearch(3). */
-typedef int (*PLIBC_SEARCH__compar_fn_t) (__const void *, __const void *);
+ typedef int (*PLIBC_SEARCH__compar_fn_t) (__const void *, __const void *);
-typedef PLIBC_SEARCH__compar_fn_t _win_comparison_fn_t;
+ typedef PLIBC_SEARCH__compar_fn_t _win_comparison_fn_t;
/* Action which shall be performed in the call the hsearch. */
-typedef enum
+ typedef enum
{
PLIBC_SEARCH_FIND,
PLIBC_SEARCH_ENTER
}
-PLIBC_SEARCH_ACTION;
+ PLIBC_SEARCH_ACTION;
-typedef struct PLIBC_SEARCH_entry
+ typedef struct PLIBC_SEARCH_entry
{
char *key;
void *data;
}
-PLIBC_SEARCH_ENTRY;
+ PLIBC_SEARCH_ENTRY;
/* The reentrant version has no static variables to maintain the state.
Instead the interface of all functions is extended to take an argument
which describes the current status. */
-typedef struct _PLIBC_SEARCH_ENTRY
-{
- unsigned int used;
- PLIBC_SEARCH_ENTRY entry;
-}
-_PLIBC_SEARCH_ENTRY;
+ typedef struct _PLIBC_SEARCH_ENTRY
+ {
+ unsigned int used;
+ PLIBC_SEARCH_ENTRY entry;
+ }
+ _PLIBC_SEARCH_ENTRY;
/* Family of hash table handling functions. The functions also
@@ -716,16 +719,17 @@
ACTION is `FIND' return found entry or signal error by returning
NULL. If ACTION is `ENTER' replace existing data (if any) with
ITEM.data. */
-PLIBC_SEARCH_ENTRY *_win_hsearch (PLIBC_SEARCH_ENTRY __item,
PLIBC_SEARCH_ACTION __action);
+ PLIBC_SEARCH_ENTRY *_win_hsearch (PLIBC_SEARCH_ENTRY __item,
+ PLIBC_SEARCH_ACTION __action);
/* Create a new hashing table which will at most contain NEL elements. */
-int _win_hcreate (size_t __nel);
+ int _win_hcreate (size_t __nel);
/* Destroy current internal hashing table. */
-void _win_hdestroy (void);
+ void _win_hdestroy (void);
/* Data type for reentrant functions. */
-struct PLIBC_SEARCH_hsearch_data
+ struct PLIBC_SEARCH_hsearch_data
{
struct _PLIBC_SEARCH_ENTRY *table;
unsigned int size;
@@ -734,10 +738,11 @@
/* Reentrant versions which can handle multiple hashing tables at the
same time. */
-int _win_hsearch_r (PLIBC_SEARCH_ENTRY __item, PLIBC_SEARCH_ACTION __action,
PLIBC_SEARCH_ENTRY **__retval,
- struct PLIBC_SEARCH_hsearch_data *__htab);
-int _win_hcreate_r (size_t __nel, struct PLIBC_SEARCH_hsearch_data *__htab);
-void _win_hdestroy_r (struct PLIBC_SEARCH_hsearch_data *__htab);
+ int _win_hsearch_r (PLIBC_SEARCH_ENTRY __item, PLIBC_SEARCH_ACTION __action,
+ PLIBC_SEARCH_ENTRY ** __retval,
+ struct PLIBC_SEARCH_hsearch_data *__htab);
+ int _win_hcreate_r (size_t __nel, struct PLIBC_SEARCH_hsearch_data *__htab);
+ void _win_hdestroy_r (struct PLIBC_SEARCH_hsearch_data *__htab);
/* The tsearch routines are very interesting. They make many
@@ -745,54 +750,57 @@
in node must be the "key" field, which points to the datum.
Everything depends on that. */
/* For tsearch */
-typedef enum
-{
- PLIBC_SEARCH_preorder,
- PLIBC_SEARCH_postorder,
- PLIBC_SEARCH_endorder,
- PLIBC_SEARCH_leaf
-}
-PLIBC_SEARCH_VISIT;
+ typedef enum
+ {
+ PLIBC_SEARCH_preorder,
+ PLIBC_SEARCH_postorder,
+ PLIBC_SEARCH_endorder,
+ PLIBC_SEARCH_leaf
+ }
+ PLIBC_SEARCH_VISIT;
/* Search for an entry matching the given KEY in the tree pointed to
by *ROOTP and insert a new element if not found. */
-void *_win_tsearch (__const void *__key, void **__rootp,
- PLIBC_SEARCH__compar_fn_t __compar);
+ void *_win_tsearch (__const void *__key, void **__rootp,
+ PLIBC_SEARCH__compar_fn_t __compar);
/* Search for an entry matching the given KEY in the tree pointed to
by *ROOTP. If no matching entry is available return NULL. */
-void *_win_tfind (__const void *__key, void *__const *__rootp,
- PLIBC_SEARCH__compar_fn_t __compar);
+ void *_win_tfind (__const void *__key, void *__const * __rootp,
+ PLIBC_SEARCH__compar_fn_t __compar);
/* Remove the element matching KEY from the tree pointed to by *ROOTP. */
-void *_win_tdelete (__const void *__restrict __key,
- void **__restrict __rootp,
- PLIBC_SEARCH__compar_fn_t __compar);
+ void *_win_tdelete (__const void *__restrict __key,
+ void **__restrict __rootp,
+ PLIBC_SEARCH__compar_fn_t __compar);
-typedef void (*PLIBC_SEARCH__action_fn_t) (__const void *__nodep,
PLIBC_SEARCH_VISIT __value,
- int __level);
+ typedef void (*PLIBC_SEARCH__action_fn_t) (__const void *__nodep,
+ PLIBC_SEARCH_VISIT __value,
+ int __level);
/* Walk through the whole tree and call the ACTION callback for every node
or leaf. */
-void _win_twalk (__const void *__root, PLIBC_SEARCH__action_fn_t __action);
+ void _win_twalk (__const void *__root, PLIBC_SEARCH__action_fn_t __action);
/* Callback type for function to free a tree node. If the keys are atomic
data this function should do nothing. */
-typedef void (*PLIBC_SEARCH__free_fn_t) (void *__nodep);
+ typedef void (*PLIBC_SEARCH__free_fn_t) (void *__nodep);
/* Destroy the whole tree, call FREEFCT for each node or leaf. */
-void _win_tdestroy (void *__root, PLIBC_SEARCH__free_fn_t __freefct);
+ void _win_tdestroy (void *__root, PLIBC_SEARCH__free_fn_t __freefct);
/* Perform linear search for KEY by comparing by COMPAR in an array
[BASE,BASE+NMEMB*SIZE). */
-void *_win_lfind (__const void *__key, __const void *__base,
- size_t *__nmemb, size_t __size, PLIBC_SEARCH__compar_fn_t __compar);
+ void *_win_lfind (__const void *__key, __const void *__base,
+ size_t * __nmemb, size_t __size,
+ PLIBC_SEARCH__compar_fn_t __compar);
/* Perform linear search for KEY by comparing by COMPAR function in
array [BASE,BASE+NMEMB*SIZE) and insert entry if not found. */
-void *_win_lsearch (__const void *__key, void *__base,
- size_t *__nmemb, size_t __size, PLIBC_SEARCH__compar_fn_t __compar);
+ void *_win_lsearch (__const void *__key, void *__base,
+ size_t * __nmemb, size_t __size,
+ PLIBC_SEARCH__compar_fn_t __compar);
#ifdef __cplusplus
@@ -800,6 +808,6 @@
#endif
-#endif //_PLIBC_H_
+#endif //_PLIBC_H_
/* end of plibc.h */
Modified: gnunet/src/include/winproc.h
===================================================================
--- gnunet/src/include/winproc.h 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/include/winproc.h 2011-08-15 21:46:35 UTC (rev 16581)
@@ -56,8 +56,7 @@
#define MAX_NAME_LENGTH 25
#endif
- typedef DWORD WINAPI (*TNtQuerySystemInformation) (int, PVOID, ULONG,
- PULONG);
+ typedef DWORD WINAPI (*TNtQuerySystemInformation) (int, PVOID, ULONG,
PULONG);
typedef DWORD WINAPI (*TGetIfEntry) (PMIB_IFROW pIfRow);
typedef DWORD WINAPI (*TGetIpAddrTable) (PMIB_IPADDRTABLE pIpAddrTable,
PULONG pdwSize, BOOL bOrder);
@@ -104,8 +103,7 @@
PDWORD pdwBestIfIndex);
typedef DWORD WINAPI (*TGetAdaptersInfo) (PIP_ADAPTER_INFO pAdapterInfo,
PULONG pOutBufLen);
- typedef NET_API_STATUS WINAPI (*TNetUserAdd) (LPCWSTR, DWORD, PBYTE,
- PDWORD);
+ typedef NET_API_STATUS WINAPI (*TNetUserAdd) (LPCWSTR, DWORD, PBYTE, PDWORD);
typedef NET_API_STATUS WINAPI (*TNetUserSetInfo) (LPCWSTR servername,
LPCWSTR username,
DWORD level, LPBYTE buf,
@@ -205,7 +203,7 @@
BOOL AddPathAccessRights (char *lpszFileName, char *lpszAccountName,
DWORD dwAccessMask);
char *winErrorStr (const char *prefix, int dwErr);
- void EnumNICs(PMIB_IFTABLE *pIfTable, PMIB_IPADDRTABLE *pAddrTable);
+ void EnumNICs (PMIB_IFTABLE * pIfTable, PMIB_IPADDRTABLE * pAddrTable);
int GNInitWinEnv ();
void GNShutdownWinEnv ();
Modified: gnunet/src/mesh/gnunet-service-mesh.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/mesh/gnunet-service-mesh.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -64,11 +64,13 @@
static void
mesh_debug (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- char *s = cls;
- if (GNUNET_SCHEDULER_REASON_SHUTDOWN == tc->reason) {
- return;
- }
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s", s);
+ char *s = cls;
+
+ if (GNUNET_SCHEDULER_REASON_SHUTDOWN == tc->reason)
+ {
+ return;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s", s);
}
#endif
@@ -100,23 +102,23 @@
/**
* Linked list
*/
- struct MeshPath *next;
- struct MeshPath *prev;
+ struct MeshPath *next;
+ struct MeshPath *prev;
/**
* Whether the path is serving traffic in a tunnel or is a backup
*/
- int in_use;
+ int in_use;
/**
* List of all the peers that form the path from origin to target
*/
- GNUNET_PEER_Id *peers;
+ GNUNET_PEER_Id *peers;
/**
* Number of peers (hops) in the path
*/
- unsigned int length;
+ unsigned int length;
};
@@ -128,22 +130,22 @@
/**
* Path to the peer not known yet
*/
- MESH_PEER_SEARCHING,
+ MESH_PEER_SEARCHING,
/**
* Request sent, not yet answered.
*/
- MESH_PEER_WAITING,
+ MESH_PEER_WAITING,
/**
* Peer connected and ready to accept data
*/
- MESH_PEER_READY,
+ MESH_PEER_READY,
/**
* Peer connected previosly but not responding
*/
- MESH_PEER_RECONNECTING
+ MESH_PEER_RECONNECTING
};
@@ -157,27 +159,27 @@
struct MeshDataDescriptor
{
/** ID of the tunnel this packet travels in */
- struct MESH_TunnelID *origin;
+ struct MESH_TunnelID *origin;
/** Ultimate destination of the packet */
- GNUNET_PEER_Id destination;
+ GNUNET_PEER_Id destination;
/** Number of identical messages sent to different hops (multicast) */
- unsigned int copies;
+ unsigned int copies;
/** Size of the data */
- size_t size;
+ size_t size;
/** Client that asked for the transmission, if any */
- struct GNUNET_SERVER_Client *client;
+ struct GNUNET_SERVER_Client *client;
/** Who was is message being sent to */
- struct MeshPeerInfo *peer;
+ struct MeshPeerInfo *peer;
/** Which handler was used to request the transmission */
- unsigned int handler_n;
+ unsigned int handler_n;
- /* Data at the end */
+ /* Data at the end */
};
@@ -189,48 +191,48 @@
/**
* ID of the peer
*/
- GNUNET_PEER_Id id;
+ GNUNET_PEER_Id id;
/**
* Is the peer reachable? Is the peer even connected?
*/
- enum MeshPeerState state;
+ enum MeshPeerState state;
/**
* Last time we heard from this peer
*/
- struct GNUNET_TIME_Absolute last_contact;
+ struct GNUNET_TIME_Absolute last_contact;
/**
* Number of attempts to reconnect so far
*/
- int n_reconnect_attempts;
+ int n_reconnect_attempts;
/**
* Paths to reach the peer
*/
- struct MeshPath *path;
- struct MeshPath *path_tail;
+ struct MeshPath *path;
+ struct MeshPath *path_tail;
/**
* Handle to stop the DHT search for a path to this peer
*/
- struct GNUNET_DHT_GetHandle *dhtget;
+ struct GNUNET_DHT_GetHandle *dhtget;
/**
* Handles to stop queued transmissions for this peer
*/
- struct GNUNET_CORE_TransmitHandle *core_transmit[CORE_QUEUE_SIZE];
+ struct GNUNET_CORE_TransmitHandle *core_transmit[CORE_QUEUE_SIZE];
/**
* Pointer to info stuctures used as cls for queued transmissions
*/
- struct MeshDataDescriptor *infos[CORE_QUEUE_SIZE];
+ struct MeshDataDescriptor *infos[CORE_QUEUE_SIZE];
/**
* Task to send keepalive packets over the current active path
*/
- GNUNET_SCHEDULER_TaskIdentifier path_refresh_task;
+ GNUNET_SCHEDULER_TaskIdentifier path_refresh_task;
};
@@ -242,54 +244,56 @@
/**
* Double linked list
*/
- struct MeshQueue *next;
- struct MeshQueue *prev;
+ struct MeshQueue *next;
+ struct MeshQueue *prev;
/**
* Target of the data (NULL if target is client)
*/
- struct MeshPeerInfo *peer;
+ struct MeshPeerInfo *peer;
/**
* Client to send the data to (NULL if target is peer)
*/
- struct MeshClient *client;
+ struct MeshClient *client;
/**
* Size of the message to transmit
*/
- unsigned int size;
+ unsigned int size;
/**
* How old is the data?
*/
- struct GNUNET_TIME_Absolute timestamp;
+ struct GNUNET_TIME_Absolute timestamp;
/**
* Data itself
*/
- struct GNUNET_MessageHeader *data;
+ struct GNUNET_MessageHeader *data;
};
/**
* Globally unique tunnel identification (owner + number)
* DO NOT USE OVER THE NETWORK
*/
-struct MESH_TunnelID {
+struct MESH_TunnelID
+{
/**
* Node that owns the tunnel
*/
- GNUNET_PEER_Id oid;
+ GNUNET_PEER_Id oid;
/**
* Tunnel number to differentiate all the tunnels owned by the node oid
* ( tid < GNUNET_MESH_LOCAL_TUNNEL_ID_MARK )
*/
- MESH_TunnelNumber tid;
+ MESH_TunnelNumber tid;
};
-struct MeshClient; /* FWD declaration */
+struct MeshClient; /* FWD declaration */
+
/**
* Struct containing all information regarding a tunnel
* For an intermediate node the improtant info used will be:
@@ -302,44 +306,44 @@
/**
* Tunnel ID
*/
- struct MESH_TunnelID id;
+ struct MESH_TunnelID id;
/**
* Local tunnel number ( >= GNUNET_MESH_LOCAL_TUNNEL_ID_MARK or 0 )
*/
- MESH_TunnelNumber local_tid;
+ MESH_TunnelNumber local_tid;
/**
* Last time the tunnel was used
*/
- struct GNUNET_TIME_Absolute timestamp;
+ struct GNUNET_TIME_Absolute timestamp;
/**
* Peers in the tunnel, indexed by PeerIdentity -> (MeshPeerInfo)
*/
- struct GNUNET_CONTAINER_MultiHashMap* peers;
+ struct GNUNET_CONTAINER_MultiHashMap *peers;
/**
* Number of peers that are connected and potentially ready to receive data
*/
- unsigned int peers_ready;
+ unsigned int peers_ready;
/**
* Number of peers that have been added to the tunnel
*/
- unsigned int peers_total;
+ unsigned int peers_total;
/**
* Client owner of the tunnel, if any
*/
- struct MeshClient *client;
+ struct MeshClient *client;
/**
* Messages ready to transmit
*/
- struct MeshQueue *queue_head;
- struct MeshQueue *queue_tail;
+ struct MeshQueue *queue_head;
+ struct MeshQueue *queue_tail;
};
@@ -351,35 +355,35 @@
/**
* Linked list
*/
- struct MeshClient *next;
- struct MeshClient *prev;
+ struct MeshClient *next;
+ struct MeshClient *prev;
/**
* Tunnels that belong to this client, indexed by local id
*/
- struct GNUNET_CONTAINER_MultiHashMap* tunnels;
+ struct GNUNET_CONTAINER_MultiHashMap *tunnels;
/**
* Handle to communicate with the client
*/
- struct GNUNET_SERVER_Client *handle;
+ struct GNUNET_SERVER_Client *handle;
/**
* Applications that this client has claimed to provide
*/
- GNUNET_MESH_ApplicationType *apps;
- unsigned int app_counter;
+ GNUNET_MESH_ApplicationType *apps;
+ unsigned int app_counter;
/**
* Messages that this client has declared interest in
*/
- uint16_t *types;
- unsigned int type_counter;
+ uint16_t *types;
+ unsigned int type_counter;
/**
* Used for seachching peers offering a service
*/
- struct GNUNET_DHT_GetHandle *dht_get_type;
+ struct GNUNET_DHT_GetHandle *dht_get_type;
};
@@ -390,33 +394,33 @@
/**
* All the clients
*/
-static struct MeshClient *clients;
-static struct MeshClient *clients_tail;
+static struct MeshClient *clients;
+static struct MeshClient *clients_tail;
/**
* Tunnels known, indexed by MESH_TunnelID (MeshTunnel)
*/
-static struct GNUNET_CONTAINER_MultiHashMap *tunnels;
+static struct GNUNET_CONTAINER_MultiHashMap *tunnels;
/**
* Peers known, indexed by PeerIdentity (MeshPeerInfo)
*/
-static struct GNUNET_CONTAINER_MultiHashMap *peers;
+static struct GNUNET_CONTAINER_MultiHashMap *peers;
/**
* Handle to communicate with core
*/
-static struct GNUNET_CORE_Handle *core_handle;
+static struct GNUNET_CORE_Handle *core_handle;
/**
* Handle to use DHT
*/
-static struct GNUNET_DHT_Handle *dht_handle;
+static struct GNUNET_DHT_Handle *dht_handle;
/**
* Handle to server
*/
-static struct GNUNET_SERVER_Handle *server_handle;
+static struct GNUNET_SERVER_Handle *server_handle;
/**
* Notification context, to send messages to local clients
@@ -426,37 +430,37 @@
/**
* Local peer own ID (memory efficient handle)
*/
-static GNUNET_PEER_Id myid;
+static GNUNET_PEER_Id myid;
/**
* Tunnel ID for the next created tunnel (global tunnel number)
*/
-static MESH_TunnelNumber next_tid;
+static MESH_TunnelNumber next_tid;
/**
* All application types provided by this peer
*/
-static GNUNET_MESH_ApplicationType *applications;
+static GNUNET_MESH_ApplicationType *applications;
/**
* All application types provided by this peer (reference counter)
*/
-static unsigned int *applications_rc;
+static unsigned int *applications_rc;
/**
* Number of applications provided by this peer
*/
-static unsigned int n_applications;
+static unsigned int n_applications;
/**
* Task to periodically announce provided applications
*/
-GNUNET_SCHEDULER_TaskIdentifier announce_applications_task;
+GNUNET_SCHEDULER_TaskIdentifier announce_applications_task;
/**
* Task to periodically announce itself in the network
*/
-GNUNET_SCHEDULER_TaskIdentifier announce_id_task;
+GNUNET_SCHEDULER_TaskIdentifier announce_id_task;
/******************************************************************************/
/****************** GENERAL HELPER FUNCTIONS
************************/
@@ -471,22 +475,22 @@
static struct MeshPeerInfo *
get_peer_info (const struct GNUNET_PeerIdentity *peer)
{
- struct MeshPeerInfo * peer_info;
+ struct MeshPeerInfo *peer_info;
- peer_info = GNUNET_CONTAINER_multihashmap_get(peers,
- &peer->hashPubKey);
- if (NULL == peer_info) {
- peer_info = (struct MeshPeerInfo *)
- GNUNET_malloc(sizeof(struct MeshPeerInfo));
- GNUNET_CONTAINER_multihashmap_put(peers,
- &peer->hashPubKey,
- peer_info,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
- peer_info->id = GNUNET_PEER_intern(peer);
- peer_info->state = MESH_PEER_SEARCHING;
- }
+ peer_info = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey);
+ if (NULL == peer_info)
+ {
+ peer_info = (struct MeshPeerInfo *)
+ GNUNET_malloc (sizeof (struct MeshPeerInfo));
+ GNUNET_CONTAINER_multihashmap_put (peers,
+ &peer->hashPubKey,
+ peer_info,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+ peer_info->id = GNUNET_PEER_intern (peer);
+ peer_info->state = MESH_PEER_SEARCHING;
+ }
- return peer_info;
+ return peer_info;
}
/**
@@ -498,28 +502,36 @@
static GNUNET_PEER_Id
get_first_hop (struct MeshPath *path)
{
- unsigned int i;
+ unsigned int i;
- while (NULL != path) {
- if (path->in_use) break;
- path = path->next;
- }
- if (NULL == path) {
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
- "tried to get the next hop from an invalid path\n");
- return 0;
- }
+ while (NULL != path)
+ {
+ if (path->in_use)
+ break;
+ path = path->next;
+ }
+ if (NULL == path)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "tried to get the next hop from an invalid path\n");
+ return 0;
+ }
- for (i = 0; i < path->length; i++) {
- if (path->peers[i] == myid) {
- if (i < path->length - 1) {
- return path->peers[i+1];
- } else {
- return myid;
- }
- }
+ for (i = 0; i < path->length; i++)
+ {
+ if (path->peers[i] == myid)
+ {
+ if (i < path->length - 1)
+ {
+ return path->peers[i + 1];
+ }
+ else
+ {
+ return myid;
+ }
}
- return 0;
+ }
+ return 0;
}
@@ -530,17 +542,20 @@
* in the path
*/
static unsigned int
-get_path_cost(struct MeshPath *path)
+get_path_cost (struct MeshPath *path)
{
- unsigned int i;
+ unsigned int i;
- if (NULL == path) return UINT_MAX;
- for (i = 0; i < path->length; i++) {
- if (path->peers[i] == myid) {
- return path->length - i;
- }
+ if (NULL == path)
+ return UINT_MAX;
+ for (i = 0; i < path->length; i++)
+ {
+ if (path->peers[i] == myid)
+ {
+ return path->length - i;
}
- return UINT_MAX;
+ }
+ return UINT_MAX;
}
@@ -551,38 +566,42 @@
* @param path New path to add. Last peer must be the peer in arg 1.
*/
static void
-add_path_to_peer(struct MeshPeerInfo *peer_info, struct MeshPath *path)
+add_path_to_peer (struct MeshPeerInfo *peer_info, struct MeshPath *path)
{
- unsigned int i;
- unsigned int new_cost;
- unsigned int best_cost;
- struct MeshPath *aux;
- struct MeshPath *best;
+ unsigned int i;
+ unsigned int new_cost;
+ unsigned int best_cost;
+ struct MeshPath *aux;
+ struct MeshPath *best;
- if (NULL == peer_info || NULL == path) return;
+ if (NULL == peer_info || NULL == path)
+ return;
- new_cost = get_path_cost(path);
- best_cost = UINT_MAX;
- best = NULL;
- for (aux = peer_info->path; aux != NULL; aux = aux->next) {
- if ((i = get_path_cost(aux)) < best_cost) {
- best = aux;
- best_cost = i;
- }
+ new_cost = get_path_cost (path);
+ best_cost = UINT_MAX;
+ best = NULL;
+ for (aux = peer_info->path; aux != NULL; aux = aux->next)
+ {
+ if ((i = get_path_cost (aux)) < best_cost)
+ {
+ best = aux;
+ best_cost = i;
}
- if (best_cost < new_cost) {
- path->in_use = 0;
- GNUNET_CONTAINER_DLL_insert_tail(peer_info->path,
- peer_info->path_tail,
- path);
- } else {
- if (NULL != best) best->in_use = 0;
- path->in_use = 1;
- GNUNET_CONTAINER_DLL_insert(peer_info->path,
- peer_info->path_tail,
- path);
- }
- return;
+ }
+ if (best_cost < new_cost)
+ {
+ path->in_use = 0;
+ GNUNET_CONTAINER_DLL_insert_tail (peer_info->path,
+ peer_info->path_tail, path);
+ }
+ else
+ {
+ if (NULL != best)
+ best->in_use = 0;
+ path->in_use = 1;
+ GNUNET_CONTAINER_DLL_insert (peer_info->path, peer_info->path_tail, path);
+ }
+ return;
}
@@ -595,17 +614,18 @@
* @param path New path to add. First peer must be the peer in arg 1.
*/
static void
-add_path_to_origin(struct MeshPeerInfo *peer_info, struct MeshPath *path)
+add_path_to_origin (struct MeshPeerInfo *peer_info, struct MeshPath *path)
{
- GNUNET_PEER_Id aux;
- unsigned int i;
+ GNUNET_PEER_Id aux;
+ unsigned int i;
- for (i = 0; i < path->length/2; i++) {
- aux = path->peers[i];
- path->peers[i] = path->peers[path->length - i - 1];
- path->peers[path->length - i - 1] = aux;
- }
- add_path_to_peer(peer_info, path);
+ for (i = 0; i < path->length / 2; i++)
+ {
+ aux = path->peers[i];
+ path->peers[i] = path->peers[path->length - i - 1];
+ path->peers[path->length - i - 1] = aux;
+ }
+ add_path_to_peer (peer_info, path);
}
@@ -617,14 +637,16 @@
static struct MeshClient *
retrieve_client (struct GNUNET_SERVER_Client *client)
{
- struct MeshClient *c;
+ struct MeshClient *c;
- c = clients;
- while (NULL != c) {
- if (c->handle == client) return c;
- c = c->next;
- }
- return NULL;
+ c = clients;
+ while (NULL != c)
+ {
+ if (c->handle == client)
+ return c;
+ c = c->next;
+ }
+ return NULL;
}
@@ -634,15 +656,17 @@
* @param c Client to check
* @return GNUNET_YES or GNUNET_NO, depending on subscription status
*/
-static int /* FIXME inline? */
-is_client_subscribed(uint16_t message_type, struct MeshClient *c)
+static int /* FIXME inline? */
+is_client_subscribed (uint16_t message_type, struct MeshClient *c)
{
- unsigned int i;
+ unsigned int i;
- for (i = 0; i < c->type_counter; i++) {
- if (c->types[i] == message_type) return GNUNET_YES;
- }
- return GNUNET_NO;
+ for (i = 0; i < c->type_counter; i++)
+ {
+ if (c->types[i] == message_type)
+ return GNUNET_YES;
+ }
+ return GNUNET_NO;
}
@@ -655,10 +679,10 @@
static struct MeshTunnel *
retrieve_tunnel_by_local_id (struct MeshClient *c, MESH_TunnelNumber tid)
{
- GNUNET_HashCode hash;
+ GNUNET_HashCode hash;
- GNUNET_CRYPTO_hash(&tid, sizeof(MESH_TunnelNumber), &hash);
- return GNUNET_CONTAINER_multihashmap_get(c->tunnels, &hash);
+ GNUNET_CRYPTO_hash (&tid, sizeof (MESH_TunnelNumber), &hash);
+ return GNUNET_CONTAINER_multihashmap_get (c->tunnels, &hash);
}
/**
@@ -670,14 +694,14 @@
static struct MeshTunnel *
retrieve_tunnel_by_pi (GNUNET_PEER_Id pi, MESH_TunnelNumber tid)
{
- struct MESH_TunnelID id;
- GNUNET_HashCode hash;
+ struct MESH_TunnelID id;
+ GNUNET_HashCode hash;
- id.oid = pi;
- id.tid = tid;
+ id.oid = pi;
+ id.tid = tid;
- GNUNET_CRYPTO_hash(&id, sizeof(struct MESH_TunnelID), &hash);
- return GNUNET_CONTAINER_multihashmap_get(tunnels, &hash);
+ GNUNET_CRYPTO_hash (&id, sizeof (struct MESH_TunnelID), &hash);
+ return GNUNET_CONTAINER_multihashmap_get (tunnels, &hash);
}
@@ -691,7 +715,7 @@
static struct MeshTunnel *
retrieve_tunnel (struct GNUNET_PeerIdentity *oid, MESH_TunnelNumber tid)
{
- return retrieve_tunnel_by_pi(GNUNET_PEER_search(oid), tid);
+ return retrieve_tunnel_by_pi (GNUNET_PEER_search (oid), tid);
}
@@ -702,12 +726,12 @@
* @return GNUNET_OK on success
*/
static int
-destroy_path(struct MeshPath *p)
+destroy_path (struct MeshPath *p)
{
- GNUNET_PEER_decrement_rcs(p->peers, p->length);
- GNUNET_free(p->peers);
- GNUNET_free(p);
- return GNUNET_OK;
+ GNUNET_PEER_decrement_rcs (p->peers, p->length);
+ GNUNET_free (p->peers);
+ GNUNET_free (p);
+ return GNUNET_OK;
}
#if LATER
@@ -718,19 +742,19 @@
* @return GNUNET_OK on success
*/
static int
-destroy_peer_info(struct MeshPeerInfo *pi)
+destroy_peer_info (struct MeshPeerInfo *pi)
{
- GNUNET_HashCode hash;
- struct GNUNET_PeerIdentity id;
+ GNUNET_HashCode hash;
+ struct GNUNET_PeerIdentity id;
- GNUNET_PEER_resolve(pi->id, &id);
- GNUNET_PEER_change_rc(pi->id, -1);
- GNUNET_CRYPTO_hash(&id, sizeof(struct GNUNET_PeerIdentity), &hash);
+ GNUNET_PEER_resolve (pi->id, &id);
+ GNUNET_PEER_change_rc (pi->id, -1);
+ GNUNET_CRYPTO_hash (&id, sizeof (struct GNUNET_PeerIdentity), &hash);
- GNUNET_CONTAINER_multihashmap_remove(peers, &hash, pi);
- GNUNET_SCHEDULER_cancel(pi->path_refresh_task);
- GNUNET_free(pi);
- return GNUNET_OK;
+ GNUNET_CONTAINER_multihashmap_remove (peers, &hash, pi);
+ GNUNET_SCHEDULER_cancel (pi->path_refresh_task);
+ GNUNET_free (pi);
+ return GNUNET_OK;
}
#endif
@@ -742,29 +766,30 @@
* @return GNUNET_OK on success
*/
static int
-destroy_tunnel(struct MeshTunnel *t)
+destroy_tunnel (struct MeshTunnel *t)
{
- struct MeshClient *c;
- GNUNET_HashCode hash;
- int r;
+ struct MeshClient *c;
+ GNUNET_HashCode hash;
+ int r;
- if (NULL == t) return GNUNET_OK;
+ if (NULL == t)
+ return GNUNET_OK;
- c = t->client;
+ c = t->client;
- GNUNET_CRYPTO_hash(&t->id, sizeof(struct MESH_TunnelID), &hash);
- if(GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove(tunnels, &hash, t)) {
- r = GNUNET_SYSERR;
- }
+ GNUNET_CRYPTO_hash (&t->id, sizeof (struct MESH_TunnelID), &hash);
+ if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove (tunnels, &hash, t))
+ {
+ r = GNUNET_SYSERR;
+ }
- GNUNET_CRYPTO_hash(&t->local_tid, sizeof(MESH_TunnelNumber), &hash);
- if(GNUNET_YES !=
- GNUNET_CONTAINER_multihashmap_remove(c->tunnels, &hash, t))
- {
- r = GNUNET_SYSERR;
- }
- GNUNET_free(t);
- return r;
+ GNUNET_CRYPTO_hash (&t->local_tid, sizeof (MESH_TunnelNumber), &hash);
+ if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove (c->tunnels, &hash,
t))
+ {
+ r = GNUNET_SYSERR;
+ }
+ GNUNET_free (t);
+ return r;
}
/******************************************************************************/
@@ -780,46 +805,45 @@
static void
announce_applications (void *cls, const struct GNUNET_SCHEDULER_TaskContext
*tc)
{
- struct GNUNET_PeerIdentity id;
- GNUNET_HashCode hash;
- uint8_t buffer[12] = "MESH_APP";
- uint32_t *p;
- uint32_t i;
+ struct GNUNET_PeerIdentity id;
+ GNUNET_HashCode hash;
+ uint8_t buffer[12] = "MESH_APP";
+ uint32_t *p;
+ uint32_t i;
- if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) {
- announce_applications_task = (GNUNET_SCHEDULER_TaskIdentifier) 0;
- return;
- }
- p = (unsigned int *) &buffer[8];
- GNUNET_PEER_resolve(myid, &id);
- for (i = 0; i < n_applications; i++) {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Starting PUT for app %d\n",
- applications[i]);
- *p = htonl(applications[i]);
- GNUNET_CRYPTO_hash(buffer, 12, &hash);
- GNUNET_DHT_put(dht_handle,
- &hash,
- 10U,
- GNUNET_DHT_RO_RECORD_ROUTE,
- GNUNET_BLOCK_TYPE_ANY,
- sizeof(struct GNUNET_PeerIdentity),
- (const char *) &id,
- GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(),
- APP_ANNOUNCE_TIME),
- APP_ANNOUNCE_TIME,
+ if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
+ {
+ announce_applications_task = (GNUNET_SCHEDULER_TaskIdentifier) 0;
+ return;
+ }
+ p = (unsigned int *) &buffer[8];
+ GNUNET_PEER_resolve (myid, &id);
+ for (i = 0; i < n_applications; i++)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Starting PUT for app %d\n", applications[i]);
+ *p = htonl (applications[i]);
+ GNUNET_CRYPTO_hash (buffer, 12, &hash);
+ GNUNET_DHT_put (dht_handle,
+ &hash,
+ 10U,
+ GNUNET_DHT_RO_RECORD_ROUTE,
+ GNUNET_BLOCK_TYPE_ANY,
+ sizeof (struct GNUNET_PeerIdentity),
+ (const char *) &id,
+ GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
+ APP_ANNOUNCE_TIME),
+ APP_ANNOUNCE_TIME,
#if MESH_DEBUG
- &mesh_debug,
- "DHT_put for app completed\n");
+ &mesh_debug, "DHT_put for app completed\n");
#else
- NULL,
- NULL);
+ NULL, NULL);
#endif
- }
- announce_applications_task = GNUNET_SCHEDULER_add_delayed(
- APP_ANNOUNCE_TIME,
- &announce_applications, cls);
- return;
+ }
+ announce_applications_task = GNUNET_SCHEDULER_add_delayed (APP_ANNOUNCE_TIME,
+
&announce_applications,
+ cls);
+ return;
}
@@ -832,34 +856,35 @@
static void
announce_id (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- struct GNUNET_PeerIdentity id;
- if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) {
- announce_id_task = (GNUNET_SCHEDULER_TaskIdentifier) 0;
- return;
- }
- GNUNET_PEER_resolve(myid, &id);
- /* TODO
- * - Set data expiration in function of X
- * - Adapt X to churn
- */
- GNUNET_DHT_put(dht_handle, /* DHT handle
*/
- &id.hashPubKey, /* Key to use
*/
- 10U, /* Replication level
*/
- GNUNET_DHT_RO_RECORD_ROUTE, /* DHT options
*/
- GNUNET_BLOCK_TYPE_ANY, /* Block type
*/
- 0, /* Size of the data
*/
- NULL, /* Data itself
*/
- GNUNET_TIME_absolute_get_forever(), /* Data expiration
*/
- GNUNET_TIME_UNIT_FOREVER_REL, /* Retry time
*/
+ struct GNUNET_PeerIdentity id;
+
+ if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
+ {
+ announce_id_task = (GNUNET_SCHEDULER_TaskIdentifier) 0;
+ return;
+ }
+ GNUNET_PEER_resolve (myid, &id);
+ /* TODO
+ * - Set data expiration in function of X
+ * - Adapt X to churn
+ */
+ GNUNET_DHT_put (dht_handle, /* DHT handle */
+ &id.hashPubKey, /* Key to use */
+ 10U, /* Replication level */
+ GNUNET_DHT_RO_RECORD_ROUTE, /* DHT options */
+ GNUNET_BLOCK_TYPE_ANY, /* Block type */
+ 0, /* Size of the data */
+ NULL, /* Data itself */
+ GNUNET_TIME_absolute_get_forever (), /* Data expiration */
+ GNUNET_TIME_UNIT_FOREVER_REL, /* Retry time */
#if MESH_DEBUG
- &mesh_debug,
- "DHT_put for id completed\n");
+ &mesh_debug, "DHT_put for id completed\n");
#else
- NULL, /* Continuation
*/
- NULL); /* Continuation closure
*/
+ NULL, /* Continuation */
+ NULL); /* Continuation closure */
#endif
- announce_id_task = GNUNET_SCHEDULER_add_delayed(ID_ANNOUNCE_TIME,
- &announce_id, cls);
+ announce_id_task = GNUNET_SCHEDULER_add_delayed (ID_ANNOUNCE_TIME,
+ &announce_id, cls);
}
/******************************************************************************/
@@ -880,57 +905,64 @@
static size_t
send_core_create_path_for_peer (void *cls, size_t size, void *buf)
{
- struct MeshPeerInfo *peer_info = cls;
- struct GNUNET_MESH_ManipulatePath *msg;
- struct MeshPath *p;
- struct GNUNET_PeerIdentity *peer_ptr;
- struct GNUNET_PeerIdentity id;
- size_t size_needed;
- int i;
+ struct MeshPeerInfo *peer_info = cls;
+ struct GNUNET_MESH_ManipulatePath *msg;
+ struct MeshPath *p;
+ struct GNUNET_PeerIdentity *peer_ptr;
+ struct GNUNET_PeerIdentity id;
+ size_t size_needed;
+ int i;
- if (0 == size && NULL == buf) {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Retransmitting create path\n");
- GNUNET_PEER_resolve(get_first_hop(peer_info->path), &id);
- GNUNET_CORE_notify_transmit_ready(core_handle,
- 0,
- 0,
- GNUNET_TIME_UNIT_FOREVER_REL,
- &id,
- sizeof(struct GNUNET_MESH_ManipulatePath)
- + (peer_info->path->length
- * sizeof (struct GNUNET_PeerIdentity)),
- &send_core_create_path_for_peer,
- peer_info);
- return 0;
+ if (0 == size && NULL == buf)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Retransmitting create path\n");
+ GNUNET_PEER_resolve (get_first_hop (peer_info->path), &id);
+ GNUNET_CORE_notify_transmit_ready (core_handle,
+ 0,
+ 0,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &id,
+ sizeof (struct
+ GNUNET_MESH_ManipulatePath) +
+ (peer_info->path->length *
+ sizeof (struct GNUNET_PeerIdentity)),
+ &send_core_create_path_for_peer,
+ peer_info);
+ return 0;
+ }
+ p = peer_info->path;
+ while (NULL != p)
+ {
+ if (p->in_use)
+ {
+ break;
}
- p = peer_info->path;
- while (NULL != p) {
- if (p->in_use) {
- break;
- }
- p = p->next;
- }
- if (p == NULL) return 0; // TODO Notify ERROR Path not found
+ p = p->next;
+ }
+ if (p == NULL)
+ return 0; // TODO Notify ERROR Path not found
- size_needed = sizeof(struct GNUNET_MESH_ManipulatePath)
- + p->length * sizeof(struct GNUNET_PeerIdentity);
- if (size < size_needed) {
- // TODO retry? cancel?
- return 0;
- }
+ size_needed = sizeof (struct GNUNET_MESH_ManipulatePath)
+ + p->length * sizeof (struct GNUNET_PeerIdentity);
+ if (size < size_needed)
+ {
+ // TODO retry? cancel?
+ return 0;
+ }
- msg = (struct GNUNET_MESH_ManipulatePath *) buf;
- msg->header.size = htons(size_needed);
- msg->header.type = htons(GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE);
+ msg = (struct GNUNET_MESH_ManipulatePath *) buf;
+ msg->header.size = htons (size_needed);
+ msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE);
- peer_ptr = (struct GNUNET_PeerIdentity *) &msg[1];
- for (i = 0; i < p->length; i++) {
- GNUNET_PEER_resolve(p->peers[i], peer_ptr++);
- }
+ peer_ptr = (struct GNUNET_PeerIdentity *) &msg[1];
+ for (i = 0; i < p->length; i++)
+ {
+ GNUNET_PEER_resolve (p->peers[i], peer_ptr++);
+ }
- peer_info->state = MESH_PEER_WAITING;
+ peer_info->state = MESH_PEER_WAITING;
- return size_needed;
+ return size_needed;
}
@@ -949,31 +981,34 @@
static size_t
send_core_data_to_origin (void *cls, size_t size, void *buf)
{
- struct MeshDataDescriptor *info = cls;
- struct GNUNET_MESH_ToOrigin *msg = buf;
- size_t total_size;
+ struct MeshDataDescriptor *info = cls;
+ struct GNUNET_MESH_ToOrigin *msg = buf;
+ size_t total_size;
- GNUNET_assert(NULL != info);
- total_size = sizeof(struct GNUNET_MESH_ToOrigin) + info->size;
- GNUNET_assert(total_size < 65536); /* UNIT16_MAX */
+ GNUNET_assert (NULL != info);
+ total_size = sizeof (struct GNUNET_MESH_ToOrigin) + info->size;
+ GNUNET_assert (total_size < 65536); /* UNIT16_MAX */
- if (total_size > size) {
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
- "not enough buffer to send data to origin\n");
- return 0;
- }
- msg->header.size = htons(total_size);
- msg->header.type = htons(GNUNET_MESSAGE_TYPE_DATA_MESSAGE_TO_ORIGIN);
- GNUNET_PEER_resolve(info->origin->oid, &msg->oid);
- msg->tid = htonl(info->origin->tid);
- if (0 != info->size) {
- memcpy(&msg[1], &info[1], info->size);
- }
- if (NULL != info->client) {
- GNUNET_SERVER_receive_done(info->client, GNUNET_OK);
- }
- GNUNET_free(info);
- return total_size;
+ if (total_size > size)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "not enough buffer to send data to origin\n");
+ return 0;
+ }
+ msg->header.size = htons (total_size);
+ msg->header.type = htons (GNUNET_MESSAGE_TYPE_DATA_MESSAGE_TO_ORIGIN);
+ GNUNET_PEER_resolve (info->origin->oid, &msg->oid);
+ msg->tid = htonl (info->origin->tid);
+ if (0 != info->size)
+ {
+ memcpy (&msg[1], &info[1], info->size);
+ }
+ if (NULL != info->client)
+ {
+ GNUNET_SERVER_receive_done (info->client, GNUNET_OK);
+ }
+ GNUNET_free (info);
+ return total_size;
}
#endif
@@ -991,32 +1026,35 @@
static size_t
send_core_data_unicast (void *cls, size_t size, void *buf)
{
- struct MeshDataDescriptor *info = cls;
- struct GNUNET_MESH_Unicast *msg = buf;
- size_t total_size;
+ struct MeshDataDescriptor *info = cls;
+ struct GNUNET_MESH_Unicast *msg = buf;
+ size_t total_size;
- GNUNET_assert(NULL != info);
- total_size = sizeof(struct GNUNET_MESH_Unicast) + info->size;
- GNUNET_assert(total_size < 65536); /* UNIT16_MAX */
+ GNUNET_assert (NULL != info);
+ total_size = sizeof (struct GNUNET_MESH_Unicast) + info->size;
+ GNUNET_assert (total_size < 65536); /* UNIT16_MAX */
- if (total_size > size) {
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
- "not enough buffer to send data to peer\n");
- return 0;
- }
- msg->header.size = htons(total_size);
- msg->header.type = htons(GNUNET_MESSAGE_TYPE_MESH_UNICAST);
- GNUNET_PEER_resolve(info->origin->oid, &msg->oid);
- GNUNET_PEER_resolve(info->destination, &msg->destination);
- msg->tid = htonl(info->origin->tid);
- if (0 != info->size) {
- memcpy(&msg[1], &info[1], info->size);
- }
- if (NULL != info->client) {
- GNUNET_SERVER_receive_done(info->client, GNUNET_OK);
- }
- GNUNET_free(info);
- return total_size;
+ if (total_size > size)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "not enough buffer to send data to peer\n");
+ return 0;
+ }
+ msg->header.size = htons (total_size);
+ msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_UNICAST);
+ GNUNET_PEER_resolve (info->origin->oid, &msg->oid);
+ GNUNET_PEER_resolve (info->destination, &msg->destination);
+ msg->tid = htonl (info->origin->tid);
+ if (0 != info->size)
+ {
+ memcpy (&msg[1], &info[1], info->size);
+ }
+ if (NULL != info->client)
+ {
+ GNUNET_SERVER_receive_done (info->client, GNUNET_OK);
+ }
+ GNUNET_free (info);
+ return total_size;
}
@@ -1034,34 +1072,38 @@
static size_t
send_core_data_multicast (void *cls, size_t size, void *buf)
{
- struct MeshDataDescriptor *info = cls;
- struct GNUNET_MESH_Multicast *msg = buf;
- size_t total_size;
+ struct MeshDataDescriptor *info = cls;
+ struct GNUNET_MESH_Multicast *msg = buf;
+ size_t total_size;
- GNUNET_assert(NULL != info);
- total_size = info->size + sizeof(struct GNUNET_MESH_Multicast);
- GNUNET_assert(total_size < GNUNET_SERVER_MAX_MESSAGE_SIZE);
+ GNUNET_assert (NULL != info);
+ total_size = info->size + sizeof (struct GNUNET_MESH_Multicast);
+ GNUNET_assert (total_size < GNUNET_SERVER_MAX_MESSAGE_SIZE);
- if (info->peer) {
- info->peer->core_transmit[info->handler_n] = NULL;
+ if (info->peer)
+ {
+ info->peer->core_transmit[info->handler_n] = NULL;
+ }
+ if (total_size > size)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "not enough buffer to send data futher\n");
+ return 0;
+ }
+ msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_MULTICAST);
+ msg->header.size = htons (total_size);
+ GNUNET_PEER_resolve (info->origin->oid, &msg->oid);
+ msg->tid = htonl (info->origin->tid);
+ memcpy (&msg[1], &info[1], total_size);
+ if (0 == --info->copies)
+ {
+ if (NULL != info->client)
+ {
+ GNUNET_SERVER_receive_done (info->client, GNUNET_OK);
}
- if (total_size > size) {
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
- "not enough buffer to send data futher\n");
- return 0;
- }
- msg->header.type = htons(GNUNET_MESSAGE_TYPE_MESH_MULTICAST);
- msg->header.size = htons(total_size);
- GNUNET_PEER_resolve(info->origin->oid, &msg->oid);
- msg->tid = htonl(info->origin->tid);
- memcpy(&msg[1], &info[1], total_size);
- if (0 == --info->copies) {
- if (NULL != info->client) {
- GNUNET_SERVER_receive_done(info->client, GNUNET_OK);
- }
- GNUNET_free(info);
- }
- return total_size;
+ GNUNET_free (info);
+ }
+ return total_size;
}
@@ -1077,26 +1119,29 @@
* @return number of bytes written to buf
*/
static size_t
-send_core_path_ack (void *cls, size_t size, void *buf) {
- struct MeshDataDescriptor *info = cls;
- struct GNUNET_MESH_PathACK *msg = buf;
+send_core_path_ack (void *cls, size_t size, void *buf)
+{
+ struct MeshDataDescriptor *info = cls;
+ struct GNUNET_MESH_PathACK *msg = buf;
- GNUNET_assert(NULL != info);
- if (info->peer) {
- info->peer->core_transmit[info->handler_n] = NULL;
- }
- if (sizeof(struct GNUNET_MESH_PathACK) > size) {
- GNUNET_break(0);
- return 0;
- }
- msg->header.size = htons(sizeof(struct GNUNET_MESH_PathACK));
- msg->header.type = htons(GNUNET_MESSAGE_TYPE_MESH_PATH_ACK);
- GNUNET_PEER_resolve(info->origin->oid, &msg->oid);
- msg->tid = htonl(info->origin->tid);
- GNUNET_PEER_resolve(myid, &msg->peer_id);
- /* TODO add signature */
+ GNUNET_assert (NULL != info);
+ if (info->peer)
+ {
+ info->peer->core_transmit[info->handler_n] = NULL;
+ }
+ if (sizeof (struct GNUNET_MESH_PathACK) > size)
+ {
+ GNUNET_break (0);
+ return 0;
+ }
+ msg->header.size = htons (sizeof (struct GNUNET_MESH_PathACK));
+ msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_PATH_ACK);
+ GNUNET_PEER_resolve (info->origin->oid, &msg->oid);
+ msg->tid = htonl (info->origin->tid);
+ GNUNET_PEER_resolve (myid, &msg->peer_id);
+ /* TODO add signature */
- return sizeof(struct GNUNET_MESH_PathACK);
+ return sizeof (struct GNUNET_MESH_PathACK);
}
@@ -1114,19 +1159,20 @@
static size_t
send_core_data_raw (void *cls, size_t size, void *buf)
{
- struct GNUNET_MessageHeader *msg = cls;
- size_t total_size;
+ struct GNUNET_MessageHeader *msg = cls;
+ size_t total_size;
- GNUNET_assert(NULL != msg);
- total_size = ntohs(msg->size);
+ GNUNET_assert (NULL != msg);
+ total_size = ntohs (msg->size);
- if (total_size > size) {
- GNUNET_break(0);
- return 0;
- }
- memcpy(buf, msg, total_size);
- GNUNET_free(cls);
- return total_size;
+ if (total_size > size)
+ {
+ GNUNET_break (0);
+ return 0;
+ }
+ memcpy (buf, msg, total_size);
+ GNUNET_free (cls);
+ return total_size;
}
@@ -1139,20 +1185,21 @@
* @return Size of data put in buffer
*/
static size_t
-send_p2p_tunnel_destroy(void *cls, size_t size, void *buf)
+send_p2p_tunnel_destroy (void *cls, size_t size, void *buf)
{
- struct MeshTunnel *t = cls;
- struct MeshClient *c;
- struct GNUNET_MESH_TunnelMessage *msg;
+ struct MeshTunnel *t = cls;
+ struct MeshClient *c;
+ struct GNUNET_MESH_TunnelMessage *msg;
- c = t->client;
- msg = buf;
- msg->header.type = htons(GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY);
/*FIXME*/
- msg->header.size = htons(sizeof(struct GNUNET_MESH_TunnelMessage));
- msg->tunnel_id = htonl(t->id.tid);
+ c = t->client;
+ msg = buf;
+ msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY);
+ /*FIXME*/
+ msg->header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage));
+ msg->tunnel_id = htonl (t->id.tid);
- destroy_tunnel(c, t);
- return sizeof(struct GNUNET_MESH_TunnelMessage);
+ destroy_tunnel (c, t);
+ return sizeof (struct GNUNET_MESH_TunnelMessage);
}
#endif
@@ -1166,21 +1213,21 @@
static unsigned int
send_subscribed_clients (struct GNUNET_MessageHeader *msg)
{
- struct MeshClient *c;
- unsigned int count;
- uint16_t type;
+ struct MeshClient *c;
+ unsigned int count;
+ uint16_t type;
- type = ntohs(msg->type);
- for (count = 0, c = clients; c != NULL; c = c->next) {
- if (is_client_subscribed(type, c)) {
- count++;
- GNUNET_SERVER_notification_context_unicast(nc,
- c->handle,
- msg,
- GNUNET_YES);
- }
+ type = ntohs (msg->type);
+ for (count = 0, c = clients; c != NULL; c = c->next)
+ {
+ if (is_client_subscribed (type, c))
+ {
+ count++;
+ GNUNET_SERVER_notification_context_unicast (nc,
+ c->handle, msg, GNUNET_YES);
}
- return count;
+ }
+ return count;
}
@@ -1193,27 +1240,29 @@
* @param value value in the hash map (peer_info)
* @return GNUNET_YES if we should continue to iterate, GNUNET_NO if not.
*/
-static int iterate_collect_neighbors (void *cls,
- const GNUNET_HashCode * key,
- void *value)
+static int
+iterate_collect_neighbors (void *cls, const GNUNET_HashCode * key, void *value)
{
- struct MeshPeerInfo *peer_info = value;
- GNUNET_PEER_Id **neighbors = cls;
- GNUNET_PEER_Id id;
- unsigned int i;
+ struct MeshPeerInfo *peer_info = value;
+ GNUNET_PEER_Id **neighbors = cls;
+ GNUNET_PEER_Id id;
+ unsigned int i;
- if (peer_info->id == myid) {
- return GNUNET_YES;
- }
- id = get_first_hop(peer_info->path);
- for (i = 0; *neighbors[i] != 0; i++) {
- if (*neighbors[i] == id) return GNUNET_YES;
- }
- *neighbors = GNUNET_realloc(*neighbors, (i + 2) * sizeof(GNUNET_PEER_Id));
- *neighbors[i] = id;
- *neighbors[i + 1] = 0;
+ if (peer_info->id == myid)
+ {
+ return GNUNET_YES;
+ }
+ id = get_first_hop (peer_info->path);
+ for (i = 0; *neighbors[i] != 0; i++)
+ {
+ if (*neighbors[i] == id)
+ return GNUNET_YES;
+ }
+ *neighbors = GNUNET_realloc (*neighbors, (i + 2) * sizeof (GNUNET_PEER_Id));
+ *neighbors[i] = id;
+ *neighbors[i + 1] = 0;
- return GNUNET_YES;
+ return GNUNET_YES;
}
@@ -1236,146 +1285,155 @@
*/
static int
handle_mesh_path_create (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_MessageHeader *message,
- const struct GNUNET_TRANSPORT_ATS_Information
- *atsi)
+ const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_MessageHeader *message,
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
- unsigned int own_pos;
- uint16_t size;
- uint16_t i;
- MESH_TunnelNumber tid;
- struct GNUNET_MESH_ManipulatePath *msg;
- struct GNUNET_PeerIdentity *pi;
- struct GNUNET_PeerIdentity id;
- GNUNET_HashCode hash;
- struct MeshPath *path;
- struct MeshPeerInfo *dest_peer_info;
- struct MeshPeerInfo *orig_peer_info;
- struct MeshTunnel *t;
+ unsigned int own_pos;
+ uint16_t size;
+ uint16_t i;
+ MESH_TunnelNumber tid;
+ struct GNUNET_MESH_ManipulatePath *msg;
+ struct GNUNET_PeerIdentity *pi;
+ struct GNUNET_PeerIdentity id;
+ GNUNET_HashCode hash;
+ struct MeshPath *path;
+ struct MeshPeerInfo *dest_peer_info;
+ struct MeshPeerInfo *orig_peer_info;
+ struct MeshTunnel *t;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received a MESH path create msg\n");
- size = ntohs(message->size);
- if (size < sizeof(struct GNUNET_MESH_ManipulatePath)) {
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
- "received create path message too short\n");
- return GNUNET_OK;
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received a MESH path create msg\n");
+ size = ntohs (message->size);
+ if (size < sizeof (struct GNUNET_MESH_ManipulatePath))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "received create path message too short\n");
+ return GNUNET_OK;
+ }
- size -= sizeof(struct GNUNET_MESH_ManipulatePath);
- if (size < 2 * sizeof(struct GNUNET_PeerIdentity)) {
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
- "create path message lacks enough peers\n");
- return GNUNET_OK;
- }
- if (size % sizeof(struct GNUNET_PeerIdentity)) {
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
- "create path message of wrong size\n");
- return GNUNET_OK;
- }
- msg = (struct GNUNET_MESH_ManipulatePath *) message;
- size /= sizeof(struct GNUNET_PeerIdentity);
+ size -= sizeof (struct GNUNET_MESH_ManipulatePath);
+ if (size < 2 * sizeof (struct GNUNET_PeerIdentity))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "create path message lacks enough peers\n");
+ return GNUNET_OK;
+ }
+ if (size % sizeof (struct GNUNET_PeerIdentity))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "create path message of wrong size\n");
+ return GNUNET_OK;
+ }
+ msg = (struct GNUNET_MESH_ManipulatePath *) message;
+ size /= sizeof (struct GNUNET_PeerIdentity);
- tid = ntohl(msg->tid);
- pi = (struct GNUNET_PeerIdentity *) &msg[1];
- t = retrieve_tunnel(pi, tid);
+ tid = ntohl (msg->tid);
+ pi = (struct GNUNET_PeerIdentity *) &msg[1];
+ t = retrieve_tunnel (pi, tid);
- if (NULL == t) {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Creating tunnel\n");
- t = GNUNET_malloc(sizeof(struct MeshTunnel));
- t->id.oid = GNUNET_PEER_intern(pi);
- t->id.tid = tid;
- t->peers = GNUNET_CONTAINER_multihashmap_create(32);
+ if (NULL == t)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating tunnel\n");
+ t = GNUNET_malloc (sizeof (struct MeshTunnel));
+ t->id.oid = GNUNET_PEER_intern (pi);
+ t->id.tid = tid;
+ t->peers = GNUNET_CONTAINER_multihashmap_create (32);
- 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_break(0);
- return GNUNET_OK;
- }
-
+ 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_break (0);
+ return GNUNET_OK;
}
- dest_peer_info = GNUNET_CONTAINER_multihashmap_get(peers,
- &pi[size - 1].hashPubKey);
- if (NULL == dest_peer_info) {
- dest_peer_info = GNUNET_malloc(sizeof(struct MeshPeerInfo));
- dest_peer_info->id = GNUNET_PEER_intern(&pi[size - 1]);
- dest_peer_info->state = MESH_PEER_WAITING;
- GNUNET_CONTAINER_multihashmap_put(peers,
- &pi[size - 1].hashPubKey,
- dest_peer_info,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
- }
- orig_peer_info = GNUNET_CONTAINER_multihashmap_get(peers, &pi->hashPubKey);
- if (NULL == orig_peer_info) {
- orig_peer_info = GNUNET_malloc(sizeof(struct MeshPeerInfo));
- orig_peer_info->id = GNUNET_PEER_intern(pi);
- orig_peer_info->state = MESH_PEER_WAITING;
- GNUNET_CONTAINER_multihashmap_put(peers,
- &pi->hashPubKey,
- orig_peer_info,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
- }
+ }
+ dest_peer_info = GNUNET_CONTAINER_multihashmap_get (peers,
+ &pi[size -
1].hashPubKey);
+ if (NULL == dest_peer_info)
+ {
+ dest_peer_info = GNUNET_malloc (sizeof (struct MeshPeerInfo));
+ dest_peer_info->id = GNUNET_PEER_intern (&pi[size - 1]);
+ dest_peer_info->state = MESH_PEER_WAITING;
+ GNUNET_CONTAINER_multihashmap_put (peers,
+ &pi[size - 1].hashPubKey,
+ dest_peer_info,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+ }
+ orig_peer_info = GNUNET_CONTAINER_multihashmap_get (peers, &pi->hashPubKey);
+ if (NULL == orig_peer_info)
+ {
+ orig_peer_info = GNUNET_malloc (sizeof (struct MeshPeerInfo));
+ orig_peer_info->id = GNUNET_PEER_intern (pi);
+ orig_peer_info->state = MESH_PEER_WAITING;
+ GNUNET_CONTAINER_multihashmap_put (peers,
+ &pi->hashPubKey,
+ orig_peer_info,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+ }
- path = GNUNET_malloc(sizeof(struct MeshPath));
- path->length = size;
- path->peers = GNUNET_malloc(size * sizeof(GNUNET_PEER_Id));
- own_pos = 0;
- for (i = 0; i < size; i++) {
- path->peers[i] = GNUNET_PEER_intern(&pi[i]);
- if (path->peers[i] == myid) own_pos = i;
- }
- if (own_pos == 0) { /* cannot be self, must be 'not found' */
- /* create path: self not found in path through self */
- GNUNET_break_op(0);
- destroy_path(path);
- /* FIXME error. destroy tunnel? leave for timeout? */
- return 0;
- }
- if (own_pos == size - 1) { /* it is for us! */
- struct MeshDataDescriptor *info;
- unsigned int j;
- add_path_to_origin(orig_peer_info, path); /* inverts path!
*/
- GNUNET_PEER_resolve(get_first_hop(path), &id); /* path is inverted :)
*/
- info = GNUNET_malloc(sizeof(struct MeshDataDescriptor));
- info->origin = &t->id;
- info->peer = GNUNET_CONTAINER_multihashmap_get(peers, &id.hashPubKey);
- GNUNET_assert(info->peer);
- for (j = 0; info->peer->core_transmit[j]; j++) {
- if (j == 9) {
- GNUNET_break(0);
- return GNUNET_OK;
- }
- }
- info->handler_n = j;
- info->peer->core_transmit[j] = GNUNET_CORE_notify_transmit_ready(
- core_handle,
- 0,
- 100,
- GNUNET_TIME_UNIT_FOREVER_REL,
- &id,
- sizeof(struct
GNUNET_MessageHeader),
- &send_core_path_ack,
- info);
- } else {
- add_path_to_peer(dest_peer_info, path);
- GNUNET_PEER_resolve(get_first_hop(path), &id);
- GNUNET_CORE_notify_transmit_ready(core_handle,
- 0,
- 0,
- GNUNET_TIME_UNIT_FOREVER_REL,
- &id,
- sizeof(struct GNUNET_MessageHeader),
- &send_core_create_path_for_peer,
- dest_peer_info);
+ path = GNUNET_malloc (sizeof (struct MeshPath));
+ path->length = size;
+ path->peers = GNUNET_malloc (size * sizeof (GNUNET_PEER_Id));
+ own_pos = 0;
+ for (i = 0; i < size; i++)
+ {
+ path->peers[i] = GNUNET_PEER_intern (&pi[i]);
+ if (path->peers[i] == myid)
+ own_pos = i;
+ }
+ if (own_pos == 0)
+ { /* cannot be self, must be 'not found' */
+ /* create path: self not found in path through self */
+ GNUNET_break_op (0);
+ destroy_path (path);
+ /* FIXME error. destroy tunnel? leave for timeout? */
+ return 0;
+ }
+ if (own_pos == size - 1)
+ { /* it is for us! */
+ struct MeshDataDescriptor *info;
+ unsigned int j;
+
+ add_path_to_origin (orig_peer_info, path); /* inverts path! */
+ GNUNET_PEER_resolve (get_first_hop (path), &id); /* path is inverted :)
*/
+ info = GNUNET_malloc (sizeof (struct MeshDataDescriptor));
+ info->origin = &t->id;
+ info->peer = GNUNET_CONTAINER_multihashmap_get (peers, &id.hashPubKey);
+ GNUNET_assert (info->peer);
+ for (j = 0; info->peer->core_transmit[j]; j++)
+ {
+ if (j == 9)
+ {
+ GNUNET_break (0);
+ return GNUNET_OK;
+ }
}
- return GNUNET_OK;
+ info->handler_n = j;
+ info->peer->core_transmit[j] =
+ GNUNET_CORE_notify_transmit_ready (core_handle, 0, 100,
+ GNUNET_TIME_UNIT_FOREVER_REL, &id,
+ sizeof (struct
GNUNET_MessageHeader),
+ &send_core_path_ack, info);
+ }
+ else
+ {
+ add_path_to_peer (dest_peer_info, path);
+ GNUNET_PEER_resolve (get_first_hop (path), &id);
+ GNUNET_CORE_notify_transmit_ready (core_handle,
+ 0,
+ 0,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &id,
+ sizeof (struct GNUNET_MessageHeader),
+ &send_core_create_path_for_peer,
+ dest_peer_info);
+ }
+ return GNUNET_OK;
}
@@ -1393,50 +1451,49 @@
handle_mesh_data_unicast (void *cls,
const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_TRANSPORT_ATS_Information
- *atsi)
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
- struct GNUNET_MESH_Unicast *msg;
- struct GNUNET_PeerIdentity id;
- struct MeshTunnel *t;
- struct MeshPeerInfo *pi;
- size_t size;
+ struct GNUNET_MESH_Unicast *msg;
+ struct GNUNET_PeerIdentity id;
+ struct MeshTunnel *t;
+ struct MeshPeerInfo *pi;
+ size_t size;
- size = ntohs(message->size);
- if (size < sizeof(struct GNUNET_MESH_Unicast)
- + sizeof(struct GNUNET_MessageHeader))
- {
- GNUNET_break(0);
- return GNUNET_OK;
- }
- msg = (struct GNUNET_MESH_Unicast *) message;
- t = retrieve_tunnel(&msg->oid, ntohl(msg->tid));
- if (NULL == t) {
- /* TODO notify back: we don't know this tunnel */
- return GNUNET_OK;
- }
- pi = GNUNET_CONTAINER_multihashmap_get(t->peers,
- &msg->destination.hashPubKey);
- if (NULL == pi) {
- /* TODO maybe feedback, log to statistics */
- return GNUNET_OK;
- }
- if (pi->id == myid) {
- send_subscribed_clients((struct GNUNET_MessageHeader *)&msg[1]);
- return GNUNET_OK;
- }
- GNUNET_PEER_resolve(get_first_hop(pi->path), &id);
- msg = GNUNET_malloc(size);
- memcpy(msg, message, size);
- GNUNET_CORE_notify_transmit_ready(core_handle,
- 0,
- 0,
- GNUNET_TIME_UNIT_FOREVER_REL,
- &id,
- size,
- &send_core_data_raw,
- msg);
+ size = ntohs (message->size);
+ if (size < sizeof (struct GNUNET_MESH_Unicast)
+ + sizeof (struct GNUNET_MessageHeader))
+ {
+ GNUNET_break (0);
return GNUNET_OK;
+ }
+ msg = (struct GNUNET_MESH_Unicast *) message;
+ t = retrieve_tunnel (&msg->oid, ntohl (msg->tid));
+ if (NULL == t)
+ {
+ /* TODO notify back: we don't know this tunnel */
+ return GNUNET_OK;
+ }
+ pi = GNUNET_CONTAINER_multihashmap_get (t->peers,
+ &msg->destination.hashPubKey);
+ if (NULL == pi)
+ {
+ /* TODO maybe feedback, log to statistics */
+ return GNUNET_OK;
+ }
+ if (pi->id == myid)
+ {
+ send_subscribed_clients ((struct GNUNET_MessageHeader *) &msg[1]);
+ return GNUNET_OK;
+ }
+ GNUNET_PEER_resolve (get_first_hop (pi->path), &id);
+ msg = GNUNET_malloc (size);
+ memcpy (msg, message, size);
+ GNUNET_CORE_notify_transmit_ready (core_handle,
+ 0,
+ 0,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &id, size, &send_core_data_raw, msg);
+ return GNUNET_OK;
}
@@ -1452,80 +1509,81 @@
*/
static int
handle_mesh_data_multicast (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_MessageHeader *message,
- const struct GNUNET_TRANSPORT_ATS_Information
- *atsi)
+ const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_MessageHeader *message,
+ const struct GNUNET_TRANSPORT_ATS_Information
*atsi)
{
- struct GNUNET_MESH_Multicast *msg;
- struct GNUNET_PeerIdentity id;
- struct MeshTunnel *t;
- struct MeshDataDescriptor *info;
- GNUNET_PEER_Id *neighbors;
- size_t size;
- uint16_t i;
- uint16_t j;
+ struct GNUNET_MESH_Multicast *msg;
+ struct GNUNET_PeerIdentity id;
+ struct MeshTunnel *t;
+ struct MeshDataDescriptor *info;
+ GNUNET_PEER_Id *neighbors;
+ size_t size;
+ uint16_t i;
+ uint16_t j;
- size = ntohs(message->size);
- if (size < sizeof(struct GNUNET_MESH_Multicast)
- + sizeof(struct GNUNET_MessageHeader))
- {
- GNUNET_break_op (0);
- return GNUNET_OK;
- }
- msg = (struct GNUNET_MESH_Multicast *) message;
- t = retrieve_tunnel(&msg->oid, ntohl(msg->tid));
+ size = ntohs (message->size);
+ if (size < sizeof (struct GNUNET_MESH_Multicast)
+ + sizeof (struct GNUNET_MessageHeader))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_OK;
+ }
+ msg = (struct GNUNET_MESH_Multicast *) message;
+ t = retrieve_tunnel (&msg->oid, ntohl (msg->tid));
- if (NULL == t) {
- /* TODO notify that we dont know that tunnel */
- return GNUNET_OK;
- }
+ if (NULL == t)
+ {
+ /* TODO notify that we dont know that tunnel */
+ return GNUNET_OK;
+ }
- /* Transmit to locally interested clients */
- GNUNET_PEER_resolve(myid, &id);
- if (GNUNET_CONTAINER_multihashmap_contains(t->peers, &id.hashPubKey)) {
- send_subscribed_clients((struct GNUNET_MessageHeader *)&msg[1]);
- }
+ /* Transmit to locally interested clients */
+ GNUNET_PEER_resolve (myid, &id);
+ if (GNUNET_CONTAINER_multihashmap_contains (t->peers, &id.hashPubKey))
+ {
+ send_subscribed_clients ((struct GNUNET_MessageHeader *) &msg[1]);
+ }
- /* Retransmit to other peers */
- neighbors = GNUNET_malloc(sizeof(GNUNET_PEER_Id));
- neighbors[0] = 0;
- GNUNET_CONTAINER_multihashmap_iterate(t->peers,
- &iterate_collect_neighbors,
- &neighbors);
- if (!neighbors[0]) {
+ /* Retransmit to other peers */
+ neighbors = GNUNET_malloc (sizeof (GNUNET_PEER_Id));
+ neighbors[0] = 0;
+ GNUNET_CONTAINER_multihashmap_iterate (t->peers,
+ &iterate_collect_neighbors,
+ &neighbors);
+ if (!neighbors[0])
+ {
+ return GNUNET_OK;
+ }
+ size -= sizeof (struct GNUNET_MESH_Multicast);
+ info = GNUNET_malloc (sizeof (struct MeshDataDescriptor) + size);
+ info->origin = &t->id;
+ info->copies = 0;
+ for (i = 0; 0 != neighbors[i]; i++)
+ {
+ GNUNET_PEER_resolve (neighbors[i], &id);
+ info->copies++;
+ info->destination = neighbors[i];
+ info->peer = GNUNET_CONTAINER_multihashmap_get (peers, &id.hashPubKey);
+ GNUNET_assert (info->peer);
+ for (j = 0; info->peer->core_transmit[j]; j++)
+ {
+ if (j == 9)
+ {
+ GNUNET_break (0);
return GNUNET_OK;
+ }
}
- size -= sizeof(struct GNUNET_MESH_Multicast);
- info = GNUNET_malloc(sizeof(struct MeshDataDescriptor) + size);
- info->origin = &t->id;
- info->copies = 0;
- for (i = 0; 0 != neighbors[i]; i++) {
- GNUNET_PEER_resolve(neighbors[i], &id);
- info->copies++;
- info->destination = neighbors[i];
- info->peer = GNUNET_CONTAINER_multihashmap_get(peers, &id.hashPubKey);
- GNUNET_assert(info->peer);
- for (j = 0; info->peer->core_transmit[j]; j++) {
- if (j == 9) {
- GNUNET_break(0);
- return GNUNET_OK;
- }
- }
- info->handler_n = j;
- info->peer->infos[j] = info;
- info->peer->core_transmit[j] = GNUNET_CORE_notify_transmit_ready(
- core_handle,
- 0,
- 0,
- GNUNET_TIME_UNIT_FOREVER_REL,
- &id,
- ntohs(msg->header.size),
- &send_core_data_multicast,
- info);
- }
- return GNUNET_OK;
+ info->handler_n = j;
+ info->peer->infos[j] = info;
+ info->peer->core_transmit[j] =
+ GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0,
+ GNUNET_TIME_UNIT_FOREVER_REL, &id,
+ ntohs (msg->header.size),
+ &send_core_data_multicast, info);
+ }
+ return GNUNET_OK;
}
@@ -1543,61 +1601,60 @@
handle_mesh_data_to_orig (void *cls,
const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_TRANSPORT_ATS_Information
- *atsi)
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
- struct GNUNET_MESH_ToOrigin *msg;
- struct GNUNET_PeerIdentity id;
- struct MeshTunnel *t;
- struct MeshPeerInfo *peer_info;
- size_t size;
+ struct GNUNET_MESH_ToOrigin *msg;
+ struct GNUNET_PeerIdentity id;
+ struct MeshTunnel *t;
+ struct MeshPeerInfo *peer_info;
+ size_t size;
- size = ntohs(message->size);
- if (size < sizeof(struct GNUNET_MESH_ToOrigin)
- + sizeof(struct GNUNET_MessageHeader))
- {
- GNUNET_break_op (0);
- return GNUNET_OK;
- }
- msg = (struct GNUNET_MESH_ToOrigin *) message;
- t = retrieve_tunnel(&msg->oid, ntohl(msg->tid));
+ size = ntohs (message->size);
+ if (size < sizeof (struct GNUNET_MESH_ToOrigin)
+ + sizeof (struct GNUNET_MessageHeader))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_OK;
+ }
+ msg = (struct GNUNET_MESH_ToOrigin *) message;
+ t = retrieve_tunnel (&msg->oid, ntohl (msg->tid));
- if (NULL == t) {
- /* TODO notify that we dont know this tunnel (whom)? */
- return GNUNET_OK;
- }
+ if (NULL == t)
+ {
+ /* TODO notify that we dont know this tunnel (whom)? */
+ return GNUNET_OK;
+ }
- if (t->id.oid == myid) {
- if (NULL == t->client) {
- /* got data packet for ownerless tunnel */
- GNUNET_break_op (0);
- return GNUNET_OK;
- }
- GNUNET_SERVER_notification_context_unicast(nc,
- t->client->handle,
- message,
- GNUNET_YES);
- return GNUNET_OK;
+ if (t->id.oid == myid)
+ {
+ if (NULL == t->client)
+ {
+ /* got data packet for ownerless tunnel */
+ GNUNET_break_op (0);
+ return GNUNET_OK;
}
- peer_info = get_peer_info(&msg->oid);
- if (NULL == peer_info) {
- /* unknown origin of tunnel */
- GNUNET_break (0);
- return GNUNET_OK;
- }
- GNUNET_PEER_resolve(get_first_hop(peer_info->path), &id);
- msg = GNUNET_malloc(size);
- memcpy(msg, message, size);
- GNUNET_CORE_notify_transmit_ready(core_handle,
- 0,
- 0,
- GNUNET_TIME_UNIT_FOREVER_REL,
- &id,
- size,
- &send_core_data_raw,
- msg);
+ GNUNET_SERVER_notification_context_unicast (nc,
+ t->client->handle,
+ message, GNUNET_YES);
+ return GNUNET_OK;
+ }
+ peer_info = get_peer_info (&msg->oid);
+ if (NULL == peer_info)
+ {
+ /* unknown origin of tunnel */
+ GNUNET_break (0);
+ return GNUNET_OK;
+ }
+ GNUNET_PEER_resolve (get_first_hop (peer_info->path), &id);
+ msg = GNUNET_malloc (size);
+ memcpy (msg, message, size);
+ GNUNET_CORE_notify_transmit_ready (core_handle,
+ 0,
+ 0,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &id, size, &send_core_data_raw, msg);
- return GNUNET_OK;
+ return GNUNET_OK;
}
@@ -1613,65 +1670,68 @@
*/
static int
handle_mesh_path_ack (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_MessageHeader *message,
- const struct GNUNET_TRANSPORT_ATS_Information
- *atsi)
+ const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_MessageHeader *message,
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
- struct GNUNET_MESH_PathACK *msg;
- struct GNUNET_PeerIdentity id;
- struct MeshTunnel *t;
- struct MeshPeerInfo *peer_info;
+ struct GNUNET_MESH_PathACK *msg;
+ struct GNUNET_PeerIdentity id;
+ struct MeshTunnel *t;
+ struct MeshPeerInfo *peer_info;
- msg = (struct GNUNET_MESH_PathACK *) message;
- t = retrieve_tunnel(&msg->oid, msg->tid);
- if (NULL == t) {
- /* TODO notify that we don't know the tunnel */
- return GNUNET_OK;
- }
+ msg = (struct GNUNET_MESH_PathACK *) message;
+ t = retrieve_tunnel (&msg->oid, msg->tid);
+ if (NULL == t)
+ {
+ /* TODO notify that we don't know the tunnel */
+ return GNUNET_OK;
+ }
- /* Message for us? */
- if (GNUNET_PEER_search(&msg->oid) == myid) {
- struct GNUNET_MESH_PeerControl pc;
- if (NULL == t->client) {
- GNUNET_break(0);
- return GNUNET_OK;
- }
- peer_info = get_peer_info(&msg->peer_id);
- if (NULL == peer_info) {
- GNUNET_break_op(0);
- return GNUNET_OK;
- }
- peer_info->state = MESH_PEER_READY;
- pc.header.type = htons(GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_CONNECTED);
- pc.header.size = htons(sizeof(struct GNUNET_MESH_PeerControl));
- pc.tunnel_id = htonl(t->local_tid);
- GNUNET_PEER_resolve(peer_info->id, &pc.peer);
- GNUNET_SERVER_notification_context_unicast(nc,
- t->client->handle,
- &pc.header,
- GNUNET_NO);
- return GNUNET_OK;
- }
+ /* Message for us? */
+ if (GNUNET_PEER_search (&msg->oid) == myid)
+ {
+ struct GNUNET_MESH_PeerControl pc;
- peer_info = get_peer_info(&msg->oid);
- if (NULL == peer_info) {
- /* If we know the tunnel, we should DEFINITELY know the peer */
- GNUNET_break(0);
- return GNUNET_OK;
+ if (NULL == t->client)
+ {
+ GNUNET_break (0);
+ return GNUNET_OK;
}
- GNUNET_PEER_resolve(get_first_hop(peer_info->path), &id);
- msg = GNUNET_malloc(sizeof(struct GNUNET_MESH_PathACK));
- memcpy(msg, message, sizeof(struct GNUNET_MESH_PathACK));
- GNUNET_CORE_notify_transmit_ready(core_handle,
- 0,
- 0,
- GNUNET_TIME_UNIT_FOREVER_REL,
- &id,
- sizeof(struct GNUNET_MESH_PathACK),
- &send_core_data_raw,
- msg);
+ peer_info = get_peer_info (&msg->peer_id);
+ if (NULL == peer_info)
+ {
+ GNUNET_break_op (0);
+ return GNUNET_OK;
+ }
+ peer_info->state = MESH_PEER_READY;
+ pc.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_CONNECTED);
+ pc.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl));
+ pc.tunnel_id = htonl (t->local_tid);
+ GNUNET_PEER_resolve (peer_info->id, &pc.peer);
+ GNUNET_SERVER_notification_context_unicast (nc,
+ t->client->handle,
+ &pc.header, GNUNET_NO);
return GNUNET_OK;
+ }
+
+ peer_info = get_peer_info (&msg->oid);
+ if (NULL == peer_info)
+ {
+ /* If we know the tunnel, we should DEFINITELY know the peer */
+ GNUNET_break (0);
+ return GNUNET_OK;
+ }
+ GNUNET_PEER_resolve (get_first_hop (peer_info->path), &id);
+ msg = GNUNET_malloc (sizeof (struct GNUNET_MESH_PathACK));
+ memcpy (msg, message, sizeof (struct GNUNET_MESH_PathACK));
+ GNUNET_CORE_notify_transmit_ready (core_handle,
+ 0,
+ 0,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &id,
+ sizeof (struct GNUNET_MESH_PathACK),
+ &send_core_data_raw, msg);
+ return GNUNET_OK;
}
@@ -1684,7 +1744,7 @@
{&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}
};
@@ -1703,10 +1763,12 @@
* @return GNUNET_OK on success
*/
static int
-delete_tunnel_entry (void *cls, const GNUNET_HashCode * key, void *value) {
- int r;
- r = destroy_tunnel((struct MeshTunnel *) value);
- return r;
+delete_tunnel_entry (void *cls, const GNUNET_HashCode * key, void *value)
+{
+ int r;
+
+ r = destroy_tunnel ((struct MeshTunnel *) value);
+ return r;
}
#if LATER
@@ -1724,26 +1786,27 @@
static size_t
notify_client_connection_failure (void *cls, size_t size, void *buf)
{
- int size_needed;
- struct MeshPeerInfo *peer_info;
- struct GNUNET_MESH_PeerControl *msg;
- struct GNUNET_PeerIdentity id;
+ int size_needed;
+ struct MeshPeerInfo *peer_info;
+ struct GNUNET_MESH_PeerControl *msg;
+ struct GNUNET_PeerIdentity id;
- if (0 == size && NULL == buf) {
- // TODO retry? cancel?
- return 0;
- }
+ if (0 == size && NULL == buf)
+ {
+ // TODO retry? cancel?
+ return 0;
+ }
- size_needed = sizeof(struct GNUNET_MESH_PeerControl);
- peer_info = (struct MeshPeerInfo *) cls;
- msg = (struct GNUNET_MESH_PeerControl *) buf;
- msg->header.size = htons(sizeof(struct GNUNET_MESH_PeerControl));
- msg->header.type = htons(GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DISCONNECTED);
+ size_needed = sizeof (struct GNUNET_MESH_PeerControl);
+ peer_info = (struct MeshPeerInfo *) cls;
+ msg = (struct GNUNET_MESH_PeerControl *) buf;
+ msg->header.size = htons (sizeof (struct GNUNET_MESH_PeerControl));
+ msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DISCONNECTED);
// msg->tunnel_id = htonl(peer_info->t->tid);
- GNUNET_PEER_resolve(peer_info->id, &id);
- memcpy(&msg->peer, &id, sizeof(struct GNUNET_PeerIdentity));
+ GNUNET_PEER_resolve (peer_info->id, &id);
+ memcpy (&msg->peer, &id, sizeof (struct GNUNET_PeerIdentity));
- return size_needed;
+ return size_needed;
}
#endif
@@ -1757,26 +1820,26 @@
static void
path_refresh (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- struct MeshPeerInfo *peer_info = cls;
- struct GNUNET_PeerIdentity id;
+ struct MeshPeerInfo *peer_info = cls;
+ struct GNUNET_PeerIdentity id;
- if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) return;
- GNUNET_PEER_resolve(get_first_hop(peer_info->path), &id);
- GNUNET_CORE_notify_transmit_ready(core_handle,
- 0,
- 0,
- GNUNET_TIME_UNIT_FOREVER_REL,
- &id,
- sizeof(struct GNUNET_MESH_ManipulatePath)
- + (peer_info->path->length
- * sizeof (struct GNUNET_PeerIdentity)),
- &send_core_create_path_for_peer,
- peer_info);
- peer_info->path_refresh_task = GNUNET_SCHEDULER_add_delayed(
- REFRESH_PATH_TIME,
- &path_refresh,
- peer_info);
+ if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
return;
+ GNUNET_PEER_resolve (get_first_hop (peer_info->path), &id);
+ GNUNET_CORE_notify_transmit_ready (core_handle,
+ 0,
+ 0,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &id,
+ sizeof (struct GNUNET_MESH_ManipulatePath)
+ + (peer_info->path->length
+ * sizeof (struct GNUNET_PeerIdentity)),
+ &send_core_create_path_for_peer,
+ peer_info);
+ peer_info->path_refresh_task =
+ GNUNET_SCHEDULER_add_delayed (REFRESH_PATH_TIME, &path_refresh,
+ peer_info);
+ return;
}
@@ -1797,71 +1860,67 @@
* @param data pointer to the result data
*/
static void
-dht_get_id_handler(void *cls,
+dht_get_id_handler (void *cls,
struct GNUNET_TIME_Absolute exp,
const GNUNET_HashCode * key,
- const struct GNUNET_PeerIdentity * const *get_path,
- const struct GNUNET_PeerIdentity * const *put_path,
- enum GNUNET_BLOCK_Type type,
- size_t size,
- const void *data)
+ const struct GNUNET_PeerIdentity *const *get_path,
+ const struct GNUNET_PeerIdentity *const *put_path,
+ enum GNUNET_BLOCK_Type type, size_t size, const void *data)
{
- struct MeshPeerInfo *peer_info = cls;
- struct MeshPath *p;
- struct GNUNET_PeerIdentity pi;
- int i;
+ struct MeshPeerInfo *peer_info = cls;
+ struct MeshPath *p;
+ struct GNUNET_PeerIdentity pi;
+ int i;
- if ((NULL == get_path || NULL == put_path) && NULL == peer_info->path) {
- // Find ourselves some alternate initial path to the destination: retry
- GNUNET_DHT_get_stop(peer_info->dhtget);
- GNUNET_PEER_resolve(peer_info->id, &pi);
- peer_info->dhtget = GNUNET_DHT_get_start(dht_handle,
- GNUNET_TIME_UNIT_FOREVER_REL,
- GNUNET_BLOCK_TYPE_ANY,
- &pi.hashPubKey,
- 4, /* replication level */
- GNUNET_DHT_RO_RECORD_ROUTE,
- NULL, /* bloom filter */
- 0, /* mutator */
- NULL, /* xquery */
- 0, /* xquery bits */
- dht_get_id_handler,
- (void *)peer_info);
- }
+ if ((NULL == get_path || NULL == put_path) && NULL == peer_info->path)
+ {
+ // Find ourselves some alternate initial path to the destination: retry
+ GNUNET_DHT_get_stop (peer_info->dhtget);
+ GNUNET_PEER_resolve (peer_info->id, &pi);
+ peer_info->dhtget = GNUNET_DHT_get_start (dht_handle,
GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_BLOCK_TYPE_ANY, &pi.hashPubKey, 4,
/* replication level */
+ GNUNET_DHT_RO_RECORD_ROUTE,
NULL, /* bloom filter */
+ 0, /* mutator */
+ NULL, /* xquery */
+ 0, /* xquery bits */
+ dht_get_id_handler,
+ (void *) peer_info);
+ }
- p = GNUNET_malloc(sizeof(struct MeshPath));
- for (i = 0; get_path[i] != NULL; i++);
- for (i--; i >= 0; i--) {
- p->peers = GNUNET_realloc(p->peers,
- sizeof(GNUNET_PEER_Id) * (p->length + 1));
- p->peers[p->length] = GNUNET_PEER_intern(get_path[i]);
- p->length++;
- }
- for (i = 0; put_path[i] != NULL; i++);
- for (i--; i >= 0; i--) {
- p->peers = GNUNET_realloc(p->peers,
- sizeof(GNUNET_PEER_Id) * (p->length + 1));
- p->peers[p->length] = GNUNET_PEER_intern(put_path[i]);
- p->length++;
- }
- add_path_to_peer(peer_info, p);
- GNUNET_CORE_notify_transmit_ready(core_handle,
- 0,
- 0,
- GNUNET_TIME_UNIT_FOREVER_REL,
- get_path[1],
- sizeof(struct GNUNET_MESH_ManipulatePath)
- + (p->length
+ p = GNUNET_malloc (sizeof (struct MeshPath));
+ for (i = 0; get_path[i] != NULL; i++) ;
+ for (i--; i >= 0; i--)
+ {
+ p->peers = GNUNET_realloc (p->peers,
+ sizeof (GNUNET_PEER_Id) * (p->length + 1));
+ p->peers[p->length] = GNUNET_PEER_intern (get_path[i]);
+ p->length++;
+ }
+ for (i = 0; put_path[i] != NULL; i++) ;
+ for (i--; i >= 0; i--)
+ {
+ p->peers = GNUNET_realloc (p->peers,
+ sizeof (GNUNET_PEER_Id) * (p->length + 1));
+ p->peers[p->length] = GNUNET_PEER_intern (put_path[i]);
+ p->length++;
+ }
+ add_path_to_peer (peer_info, p);
+ GNUNET_CORE_notify_transmit_ready (core_handle,
+ 0,
+ 0,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ get_path[1],
+ sizeof (struct GNUNET_MESH_ManipulatePath)
+ + (p->length
* sizeof (struct GNUNET_PeerIdentity)),
- &send_core_create_path_for_peer,
+ &send_core_create_path_for_peer,
+ peer_info);
+ if (0 == peer_info->path_refresh_task)
+ {
+ peer_info->path_refresh_task =
+ GNUNET_SCHEDULER_add_delayed (REFRESH_PATH_TIME, &path_refresh,
peer_info);
- if (0 == peer_info->path_refresh_task) {
- peer_info->path_refresh_task = GNUNET_SCHEDULER_add_delayed(
- REFRESH_PATH_TIME,
- &path_refresh,
- peer_info);
- }
- return;
+ }
+ return;
}
@@ -1882,75 +1941,73 @@
* @param data pointer to the result data
*/
static void
-dht_get_type_handler(void *cls,
- struct GNUNET_TIME_Absolute exp,
- const GNUNET_HashCode * key,
- const struct GNUNET_PeerIdentity * const *get_path,
- const struct GNUNET_PeerIdentity * const *put_path,
- enum GNUNET_BLOCK_Type type,
- size_t size,
- const void *data)
+dht_get_type_handler (void *cls,
+ struct GNUNET_TIME_Absolute exp,
+ const GNUNET_HashCode * key,
+ const struct GNUNET_PeerIdentity *const *get_path,
+ const struct GNUNET_PeerIdentity *const *put_path,
+ enum GNUNET_BLOCK_Type type,
+ size_t size, const void *data)
{
- const struct GNUNET_PeerIdentity *pi = data;
- struct MeshTunnel *t = cls;
- struct MeshPeerInfo *peer_info;
- struct MeshPath *p;
- int i;
+ const struct GNUNET_PeerIdentity *pi = data;
+ struct MeshTunnel *t = cls;
+ struct MeshPeerInfo *peer_info;
+ struct MeshPath *p;
+ int i;
- if (size != sizeof(struct GNUNET_PeerIdentity)) {
- GNUNET_break_op(0);
- return;
+ if (size != sizeof (struct GNUNET_PeerIdentity))
+ {
+ GNUNET_break_op (0);
+ return;
+ }
+ peer_info = get_peer_info (pi);
+ GNUNET_CONTAINER_multihashmap_put (t->peers,
+ &pi->hashPubKey,
+ peer_info,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+ if ((NULL == get_path || NULL == put_path) && NULL == peer_info->path)
+ {
+ /* we don't have a route to the peer, let's try a direct lookup */
+ if (NULL == peer_info->dhtget)
+ {
+ peer_info->dhtget = GNUNET_DHT_get_start (dht_handle,
GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_BLOCK_TYPE_ANY, &pi->hashPubKey, 10U, /*
replication level */
+ GNUNET_DHT_RO_RECORD_ROUTE,
NULL, /* bloom filter */
+ 0, /* mutator */
+ NULL, /* xquery */
+ 0, /* xquery bits */
+ dht_get_id_handler, peer_info);
}
- peer_info = get_peer_info(pi);
- GNUNET_CONTAINER_multihashmap_put(t->peers,
- &pi->hashPubKey,
- peer_info,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
- if ((NULL == get_path || NULL == put_path) && NULL == peer_info->path) {
- /* we don't have a route to the peer, let's try a direct lookup */
- if (NULL == peer_info->dhtget) {
- peer_info->dhtget = GNUNET_DHT_get_start(dht_handle,
- GNUNET_TIME_UNIT_FOREVER_REL,
- GNUNET_BLOCK_TYPE_ANY,
- &pi->hashPubKey,
- 10U, /* replication level */
- GNUNET_DHT_RO_RECORD_ROUTE,
- NULL, /* bloom filter */
- 0, /* mutator */
- NULL, /* xquery */
- 0, /* xquery bits */
- dht_get_id_handler,
- peer_info);
- }
- }
- /* TODO refactor */
- p = GNUNET_malloc(sizeof(struct MeshPath));
- for (i = 0; get_path[i] != NULL; i++);
- for (i--; i >= 0; i--) {
- p->peers = GNUNET_realloc(p->peers,
- sizeof(GNUNET_PEER_Id) * (p->length + 1));
- p->peers[p->length] = GNUNET_PEER_intern(get_path[i]);
- p->length++;
- }
- for (i = 0; put_path[i] != NULL; i++);
- for (i--; i >= 0; i--) {
- p->peers = GNUNET_realloc(p->peers,
- sizeof(GNUNET_PEER_Id) * (p->length + 1));
- p->peers[p->length] = GNUNET_PEER_intern(put_path[i]);
- p->length++;
- }
- add_path_to_peer(peer_info, p);
- GNUNET_CORE_notify_transmit_ready(core_handle,
- 0,
- 0,
- GNUNET_TIME_UNIT_FOREVER_REL,
- get_path[1],
- sizeof(struct GNUNET_MESH_ManipulatePath)
- + (p->length
+ }
+ /* TODO refactor */
+ p = GNUNET_malloc (sizeof (struct MeshPath));
+ for (i = 0; get_path[i] != NULL; i++) ;
+ for (i--; i >= 0; i--)
+ {
+ p->peers = GNUNET_realloc (p->peers,
+ sizeof (GNUNET_PEER_Id) * (p->length + 1));
+ p->peers[p->length] = GNUNET_PEER_intern (get_path[i]);
+ p->length++;
+ }
+ for (i = 0; put_path[i] != NULL; i++) ;
+ for (i--; i >= 0; i--)
+ {
+ p->peers = GNUNET_realloc (p->peers,
+ sizeof (GNUNET_PEER_Id) * (p->length + 1));
+ p->peers[p->length] = GNUNET_PEER_intern (put_path[i]);
+ p->length++;
+ }
+ add_path_to_peer (peer_info, p);
+ GNUNET_CORE_notify_transmit_ready (core_handle,
+ 0,
+ 0,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ get_path[1],
+ sizeof (struct GNUNET_MESH_ManipulatePath)
+ + (p->length
* sizeof (struct GNUNET_PeerIdentity)),
- &send_core_create_path_for_peer,
- peer_info);
+ &send_core_create_path_for_peer,
+ peer_info);
}
@@ -1969,65 +2026,69 @@
static void
handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
{
- struct MeshClient *c;
- struct MeshClient *next;
- unsigned int i;
- unsigned int j;
+ struct MeshClient *c;
+ struct MeshClient *next;
+ unsigned int i;
+ unsigned int j;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "client disconnected\n");
- c = clients;
- while (NULL != c) {
- if (c->handle == client) {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- " matching client found, cleaning\n");
- GNUNET_CONTAINER_multihashmap_iterate(c->tunnels,
- &delete_tunnel_entry,
- c);
- GNUNET_CONTAINER_multihashmap_destroy(c->tunnels);
- if(0 != c->app_counter) { /* deregister clients applications
*/
- for (i = 0; i < c->app_counter; i++) {
- for (j = 0; j < n_applications; j++) {
- if (c->apps[i] == applications[j]) {
- if (0 == --applications_rc[j]) {
- applications[j] =
- applications[n_applications -1];
- applications_rc[j] =
- applications_rc[n_applications -1];
- n_applications--;
- applications = GNUNET_realloc(
- applications,
- n_applications *
- sizeof(GNUNET_MESH_ApplicationType));
- applications_rc = GNUNET_realloc(
- applications_rc,
- n_applications *
- sizeof(unsigned int));
- }
- break;
- }
- }
- }
- GNUNET_free (c->apps);
- if (0 == n_applications) {
- GNUNET_SCHEDULER_cancel(announce_applications_task);
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "client disconnected\n");
+ c = clients;
+ while (NULL != c)
+ {
+ if (c->handle == client)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ " matching client found, cleaning\n");
+ GNUNET_CONTAINER_multihashmap_iterate (c->tunnels,
+ &delete_tunnel_entry, c);
+ GNUNET_CONTAINER_multihashmap_destroy (c->tunnels);
+ if (0 != c->app_counter)
+ { /* deregister clients applications */
+ for (i = 0; i < c->app_counter; i++)
+ {
+ for (j = 0; j < n_applications; j++)
+ {
+ if (c->apps[i] == applications[j])
+ {
+ if (0 == --applications_rc[j])
+ {
+ applications[j] = applications[n_applications - 1];
+ applications_rc[j] = applications_rc[n_applications - 1];
+ n_applications--;
+ applications = GNUNET_realloc (applications,
+ n_applications *
+ sizeof
+ (GNUNET_MESH_ApplicationType));
+ applications_rc =
+ GNUNET_realloc (applications_rc,
+ n_applications * sizeof (unsigned int));
+ }
+ break;
}
- if(0 != c->type_counter) GNUNET_free (c->types);
- GNUNET_CONTAINER_DLL_remove(clients, clients_tail, c);
- next = c->next;
- GNUNET_free (c);
- c = next;
- } else {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- " ... searching\n");
- c = c->next;
+ }
}
+ GNUNET_free (c->apps);
+ if (0 == n_applications)
+ {
+ GNUNET_SCHEDULER_cancel (announce_applications_task);
+ }
+ }
+ if (0 != c->type_counter)
+ GNUNET_free (c->types);
+ GNUNET_CONTAINER_DLL_remove (clients, clients_tail, c);
+ next = c->next;
+ GNUNET_free (c);
+ c = next;
}
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ... searching\n");
+ c = c->next;
+ }
+ }
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- " done!\n");
- return;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " done!\n");
+ return;
}
@@ -2043,81 +2104,85 @@
struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
- struct GNUNET_MESH_ClientConnect *cc_msg;
- struct MeshClient *c;
- unsigned int size;
- uint16_t types;
- uint16_t apps;
- uint16_t i;
- uint16_t j;
- int known;
+ struct GNUNET_MESH_ClientConnect *cc_msg;
+ struct MeshClient *c;
+ unsigned int size;
+ uint16_t types;
+ uint16_t apps;
+ uint16_t i;
+ uint16_t j;
+ int known;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "new client connected\n");
- /* Check data sanity */
- size = ntohs(message->size) - sizeof(struct GNUNET_MESH_ClientConnect);
- cc_msg = (struct GNUNET_MESH_ClientConnect *) message;
- types = ntohs(cc_msg->types);
- apps = ntohs(cc_msg->applications);
- if (size !=
- types * sizeof(uint16_t) + apps * sizeof(GNUNET_MESH_ApplicationType))
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "new client connected\n");
+ /* Check data sanity */
+ size = ntohs (message->size) - sizeof (struct GNUNET_MESH_ClientConnect);
+ cc_msg = (struct GNUNET_MESH_ClientConnect *) message;
+ types = ntohs (cc_msg->types);
+ apps = ntohs (cc_msg->applications);
+ if (size !=
+ types * sizeof (uint16_t) + apps * sizeof (GNUNET_MESH_ApplicationType))
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
+
+ /* Create new client structure */
+ c = GNUNET_malloc (sizeof (struct MeshClient));
+ c->handle = client;
+ if (types != 0)
+ {
+ c->type_counter = types;
+ c->types = GNUNET_malloc (types * sizeof (uint16_t));
+ memcpy (c->types, &message[1], types * sizeof (uint16_t));
+ }
+ if (apps != 0)
+ {
+ c->app_counter = apps;
+ c->apps = GNUNET_malloc (apps * sizeof (GNUNET_MESH_ApplicationType));
+ memcpy (c->apps,
+ &message[1] + types * sizeof (uint16_t),
+ apps * sizeof (GNUNET_MESH_ApplicationType));
+ }
+ for (i = 0; i < apps; i++)
+ {
+ known = GNUNET_NO;
+ for (j = 0; i < n_applications; j++)
{
- GNUNET_break(0);
- GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
- return;
+ if (c->apps[i] == applications[j])
+ {
+ known = GNUNET_YES;
+ applications_rc[j]++;
+ break;
+ }
}
-
- /* Create new client structure */
- c = GNUNET_malloc(sizeof(struct MeshClient));
- c->handle = client;
- if (types != 0) {
- c->type_counter = types;
- c->types = GNUNET_malloc(types * sizeof(uint16_t));
- memcpy(c->types, &message[1], types * sizeof(uint16_t));
+ if (!known)
+ { /* Register previously unknown application */
+ n_applications++;
+ applications = GNUNET_realloc (applications,
+ n_applications *
+ sizeof (GNUNET_MESH_ApplicationType));
+ applications_rc = GNUNET_realloc (applications_rc,
+ n_applications * sizeof (unsigned
int));
+ applications[n_applications - 1] = c->apps[i];
+ applications_rc[n_applications - 1] = 1;
+ if (0 == announce_applications_task)
+ {
+ announce_applications_task =
+ GNUNET_SCHEDULER_add_delayed (APP_ANNOUNCE_TIME,
+ &announce_applications, NULL);
+ }
}
- if (apps != 0) {
- c->app_counter = apps;
- c->apps = GNUNET_malloc(apps * sizeof(GNUNET_MESH_ApplicationType));
- memcpy(c->apps,
- &message[1] + types * sizeof(uint16_t),
- apps * sizeof(GNUNET_MESH_ApplicationType));
- }
- for (i = 0; i < apps; i++) {
- known = GNUNET_NO;
- for (j = 0; i < n_applications; j++) {
- if (c->apps[i] == applications[j]) {
- known = GNUNET_YES;
- applications_rc[j]++;
- break;
- }
- }
- if (!known) { /* Register previously unknown application
*/
- n_applications++;
- applications = GNUNET_realloc(applications,
- n_applications *
- sizeof(GNUNET_MESH_ApplicationType));
- applications_rc = GNUNET_realloc(applications_rc,
- n_applications *
- sizeof(unsigned int));
- applications[n_applications - 1] = c->apps[i];
- applications_rc[n_applications - 1] = 1;
- if (0 == announce_applications_task) {
- announce_applications_task = GNUNET_SCHEDULER_add_delayed(
- APP_ANNOUNCE_TIME,
- &announce_applications,
- NULL);
- }
- }
- }
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- " client has %u+%u subscriptions\n",
- c->type_counter,
- c->app_counter);
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ " client has %u+%u subscriptions\n",
+ c->type_counter, c->app_counter);
- GNUNET_CONTAINER_DLL_insert(clients, clients_tail, c);
- c->tunnels = GNUNET_CONTAINER_multihashmap_create(32);
- GNUNET_SERVER_notification_context_add(nc, client);
+ GNUNET_CONTAINER_DLL_insert (clients, clients_tail, c);
+ c->tunnels = GNUNET_CONTAINER_multihashmap_create (32);
+ GNUNET_SERVER_notification_context_add (nc, client);
- GNUNET_SERVER_receive_done(client, GNUNET_OK);
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
@@ -2134,70 +2199,74 @@
struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
- struct GNUNET_MESH_TunnelMessage *t_msg;
- struct MeshTunnel *t;
- struct MeshClient *c;
- GNUNET_HashCode hash;
+ struct GNUNET_MESH_TunnelMessage *t_msg;
+ struct MeshTunnel *t;
+ struct MeshClient *c;
+ GNUNET_HashCode hash;
- /* Sanity check for client registration */
- if (NULL == (c = retrieve_client(client))) {
- GNUNET_break(0);
- GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
- return;
- }
+ /* Sanity check for client registration */
+ if (NULL == (c = retrieve_client (client)))
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
- /* Message sanity check */
- if (sizeof(struct GNUNET_MESH_TunnelMessage) != ntohs(message->size)) {
- GNUNET_break(0);
- GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
- return;
- }
+ /* Message sanity check */
+ if (sizeof (struct GNUNET_MESH_TunnelMessage) != ntohs (message->size))
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
- t_msg = (struct GNUNET_MESH_TunnelMessage *) message;
- /* Sanity check for tunnel numbering */
- if (0 == (ntohl(t_msg->tunnel_id) & GNUNET_MESH_LOCAL_TUNNEL_ID_MARK)) {
- GNUNET_break(0);
- GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
- return;
- }
- /* Sanity check for duplicate tunnel IDs */
- if(NULL != retrieve_tunnel_by_local_id(c, ntohl(t_msg->tunnel_id))) {
- GNUNET_break(0);
- GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
- return;
- }
+ t_msg = (struct GNUNET_MESH_TunnelMessage *) message;
+ /* Sanity check for tunnel numbering */
+ if (0 == (ntohl (t_msg->tunnel_id) & GNUNET_MESH_LOCAL_TUNNEL_ID_MARK))
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
+ /* Sanity check for duplicate tunnel IDs */
+ if (NULL != retrieve_tunnel_by_local_id (c, ntohl (t_msg->tunnel_id)))
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
- t = GNUNET_malloc(sizeof(struct MeshTunnel));
- while (NULL != retrieve_tunnel_by_pi(myid, next_tid))
- next_tid = (next_tid + 1) % GNUNET_MESH_LOCAL_TUNNEL_ID_MARK;
- t->id.tid = next_tid++;
- t->id.oid = myid;
- t->local_tid = ntohl(t_msg->tunnel_id);
- t->client = c;
- t->peers = GNUNET_CONTAINER_multihashmap_create(32);
+ t = GNUNET_malloc (sizeof (struct MeshTunnel));
+ while (NULL != retrieve_tunnel_by_pi (myid, next_tid))
+ next_tid = (next_tid + 1) % GNUNET_MESH_LOCAL_TUNNEL_ID_MARK;
+ t->id.tid = next_tid++;
+ t->id.oid = myid;
+ t->local_tid = ntohl (t_msg->tunnel_id);
+ 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_break(0);
- GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
- return;
- }
+ 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_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
- 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_break(0);
- GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
- return;
- }
+ 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_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
- GNUNET_SERVER_receive_done(client, GNUNET_OK);
- return;
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ return;
}
@@ -2213,43 +2282,45 @@
struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
- struct GNUNET_MESH_TunnelMessage *tunnel_msg;
- struct MeshClient *c;
- struct MeshTunnel *t;
- MESH_TunnelNumber tid;
- GNUNET_HashCode hash;
+ struct GNUNET_MESH_TunnelMessage *tunnel_msg;
+ struct MeshClient *c;
+ struct MeshTunnel *t;
+ MESH_TunnelNumber tid;
+ GNUNET_HashCode hash;
- /* Sanity check for client registration */
- if (NULL == (c = retrieve_client(client))) {
- GNUNET_break(0);
- GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
- return;
- }
- /* Message sanity check */
- if (sizeof(struct GNUNET_MESH_TunnelMessage) != ntohs(message->size)) {
- GNUNET_break(0);
- GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
- return;
- }
+ /* Sanity check for client registration */
+ if (NULL == (c = retrieve_client (client)))
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
+ /* Message sanity check */
+ if (sizeof (struct GNUNET_MESH_TunnelMessage) != ntohs (message->size))
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
- tunnel_msg = (struct GNUNET_MESH_TunnelMessage *) message;
+ tunnel_msg = (struct GNUNET_MESH_TunnelMessage *) message;
- /* Retrieve tunnel */
- tid = ntohl(tunnel_msg->tunnel_id);
+ /* Retrieve tunnel */
+ tid = ntohl (tunnel_msg->tunnel_id);
- /* Remove from local id hashmap */
- GNUNET_CRYPTO_hash(&tid, sizeof(MESH_TunnelNumber), &hash);
- t = GNUNET_CONTAINER_multihashmap_get(c->tunnels, &hash);
- GNUNET_CONTAINER_multihashmap_remove(c->tunnels, &hash, t);
+ /* Remove from local id hashmap */
+ GNUNET_CRYPTO_hash (&tid, sizeof (MESH_TunnelNumber), &hash);
+ t = GNUNET_CONTAINER_multihashmap_get (c->tunnels, &hash);
+ GNUNET_CONTAINER_multihashmap_remove (c->tunnels, &hash, t);
- /* Remove from global id hashmap */
- GNUNET_CRYPTO_hash(&t->id, sizeof(struct MESH_TunnelID), &hash);
- GNUNET_CONTAINER_multihashmap_remove(tunnels, &hash, t);
+ /* Remove from global id hashmap */
+ GNUNET_CRYPTO_hash (&t->id, sizeof (struct MESH_TunnelID), &hash);
+ GNUNET_CONTAINER_multihashmap_remove (tunnels, &hash, t);
// notify_tunnel_destroy(t);
- GNUNET_SERVER_receive_done(client, GNUNET_OK);
- return;
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ return;
}
@@ -2265,67 +2336,65 @@
struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
- struct GNUNET_MESH_PeerControl *peer_msg;
- struct MeshClient *c;
- struct MeshTunnel *t;
- MESH_TunnelNumber tid;
- struct MeshPeerInfo *peer_info;
+ struct GNUNET_MESH_PeerControl *peer_msg;
+ struct MeshClient *c;
+ struct MeshTunnel *t;
+ MESH_TunnelNumber tid;
+ struct MeshPeerInfo *peer_info;
- /* Sanity check for client registration */
- if (NULL == (c = retrieve_client(client))) {
- GNUNET_break(0);
- GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
- return;
- }
+ /* Sanity check for client registration */
+ if (NULL == (c = retrieve_client (client)))
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
- peer_msg = (struct GNUNET_MESH_PeerControl *)message;
- /* Sanity check for message size */
- if (sizeof(struct GNUNET_MESH_PeerControl)
- != ntohs(peer_msg->header.size))
- {
- GNUNET_break(0);
- GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
- return;
- }
+ peer_msg = (struct GNUNET_MESH_PeerControl *) message;
+ /* Sanity check for message size */
+ if (sizeof (struct GNUNET_MESH_PeerControl) != ntohs (peer_msg->header.size))
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
- /* Tunnel exists? */
- tid = ntohl(peer_msg->tunnel_id);
- t = retrieve_tunnel_by_local_id(c, tid);
- if (NULL == t) {
- GNUNET_break(0);
- GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
- return;
- }
+ /* Tunnel exists? */
+ tid = ntohl (peer_msg->tunnel_id);
+ t = retrieve_tunnel_by_local_id (c, tid);
+ if (NULL == t)
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
- /* Does client own tunnel? */
- if (t->client->handle != client) {
- GNUNET_break(0);
- GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
- return;
- }
+ /* Does client own tunnel? */
+ if (t->client->handle != client)
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
- t->peers_total++;
- peer_info = get_peer_info(&peer_msg->peer);
+ t->peers_total++;
+ peer_info = get_peer_info (&peer_msg->peer);
- /* Start DHT search if needed */
- if(MESH_PEER_READY != peer_info->state && NULL == peer_info->dhtget) {
- peer_info->dhtget = GNUNET_DHT_get_start(dht_handle,
- GNUNET_TIME_UNIT_FOREVER_REL,
- GNUNET_BLOCK_TYPE_ANY,
- &peer_msg->peer.hashPubKey,
- 4, /* replication level */
- GNUNET_DHT_RO_RECORD_ROUTE,
- NULL, /* bloom filter */
- 0, /* mutator */
- NULL, /* xquery */
- 0, /* xquery bits */
- dht_get_id_handler,
- (void *)peer_info);
- }
+ /* Start DHT search if needed */
+ if (MESH_PEER_READY != peer_info->state && NULL == peer_info->dhtget)
+ {
+ peer_info->dhtget = GNUNET_DHT_get_start (dht_handle,
GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_BLOCK_TYPE_ANY,
&peer_msg->peer.hashPubKey, 4, /* replication level */
+ GNUNET_DHT_RO_RECORD_ROUTE,
NULL, /* bloom filter */
+ 0, /* mutator */
+ NULL, /* xquery */
+ 0, /* xquery bits */
+ dht_get_id_handler,
+ (void *) peer_info);
+ }
- GNUNET_SERVER_receive_done(client, GNUNET_OK);
- return;
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ return;
}
@@ -2341,49 +2410,51 @@
struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
- struct GNUNET_MESH_PeerControl *peer_msg;
- struct MeshClient *c;
- struct MeshTunnel *t;
- MESH_TunnelNumber tid;
+ struct GNUNET_MESH_PeerControl *peer_msg;
+ struct MeshClient *c;
+ struct MeshTunnel *t;
+ MESH_TunnelNumber tid;
- /* Sanity check for client registration */
- if (NULL == (c = retrieve_client(client))) {
- GNUNET_break(0);
- GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
- return;
- }
- peer_msg = (struct GNUNET_MESH_PeerControl *)message;
- /* Sanity check for message size */
- if (sizeof(struct GNUNET_MESH_PeerControl)
- != ntohs(peer_msg->header.size))
- {
- GNUNET_break(0);
- GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
- return;
- }
+ /* Sanity check for client registration */
+ if (NULL == (c = retrieve_client (client)))
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
+ peer_msg = (struct GNUNET_MESH_PeerControl *) message;
+ /* Sanity check for message size */
+ if (sizeof (struct GNUNET_MESH_PeerControl) != ntohs (peer_msg->header.size))
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
- /* Tunnel exists? */
- tid = ntohl(peer_msg->tunnel_id);
- t = retrieve_tunnel_by_local_id(c, tid);
- if (NULL == t) {
- GNUNET_break(0);
- GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
- return;
- }
+ /* Tunnel exists? */
+ tid = ntohl (peer_msg->tunnel_id);
+ t = retrieve_tunnel_by_local_id (c, tid);
+ if (NULL == t)
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
- /* Does client own tunnel? */
- if (t->client->handle != client) {
- GNUNET_break(0);
- GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
- return;
- }
+ /* Does client own tunnel? */
+ if (t->client->handle != client)
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
- /* Ok, delete peer from tunnel */
- GNUNET_CONTAINER_multihashmap_remove_all(t->peers,
- &peer_msg->peer.hashPubKey);
+ /* Ok, delete peer from tunnel */
+ GNUNET_CONTAINER_multihashmap_remove_all (t->peers,
+ &peer_msg->peer.hashPubKey);
- GNUNET_SERVER_receive_done(client, GNUNET_OK);
- return;
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ return;
}
@@ -2399,94 +2470,93 @@
struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
- struct GNUNET_MESH_ConnectPeerByType *connect_msg;
- struct MeshClient *c;
- struct MeshTunnel *t;
- GNUNET_HashCode hash;
- GNUNET_MESH_ApplicationType type;
- MESH_TunnelNumber tid;
- uint8_t buffer[12] = "MESH_APP";
- uint32_t *p;
- unsigned int i;
+ struct GNUNET_MESH_ConnectPeerByType *connect_msg;
+ struct MeshClient *c;
+ struct MeshTunnel *t;
+ GNUNET_HashCode hash;
+ GNUNET_MESH_ApplicationType type;
+ MESH_TunnelNumber tid;
+ uint8_t buffer[12] = "MESH_APP";
+ uint32_t *p;
+ unsigned int i;
- /* Sanity check for client registration */
- if (NULL == (c = retrieve_client(client))) {
- GNUNET_break(0);
- GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
- return;
- }
+ /* Sanity check for client registration */
+ if (NULL == (c = retrieve_client (client)))
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
- connect_msg = (struct GNUNET_MESH_ConnectPeerByType *)message;
- /* Sanity check for message size */
- if (sizeof(struct GNUNET_MESH_PeerControl) !=
- ntohs(connect_msg->header.size))
- {
- GNUNET_break(0);
- GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
- return;
- }
+ connect_msg = (struct GNUNET_MESH_ConnectPeerByType *) message;
+ /* Sanity check for message size */
+ if (sizeof (struct GNUNET_MESH_PeerControl) !=
+ ntohs (connect_msg->header.size))
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
- /* Tunnel exists? */
- tid = ntohl(connect_msg->tunnel_id);
- t = retrieve_tunnel_by_local_id(c, tid);
- if (NULL == t) {
- GNUNET_break(0);
- GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
- return;
- }
+ /* Tunnel exists? */
+ tid = ntohl (connect_msg->tunnel_id);
+ t = retrieve_tunnel_by_local_id (c, tid);
+ if (NULL == t)
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
- /* Does client own tunnel? */
- if (t->client->handle != client) {
- GNUNET_break(0);
- GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
- return;
- }
+ /* Does client own tunnel? */
+ if (t->client->handle != client)
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
- /* Do WE have the service? */
- type = ntohl(connect_msg->type);
- for (i = 0; i < n_applications; i++) {
- if (applications[i] == type) {
- /* Yes! Fast forward, add ourselves to the tunnel and send the
- * good news to the client
- */
- struct GNUNET_MESH_PeerControl pc;
- GNUNET_PEER_resolve(myid, &pc.peer);
- GNUNET_CONTAINER_multihashmap_put(t->peers,
- &pc.peer.hashPubKey,
- get_peer_info(&pc.peer),
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
- pc.header.size = htons(sizeof(struct GNUNET_MESH_PeerControl));
- pc.header.type =
- htons(GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_CONNECTED);
- pc.tunnel_id = htonl(t->local_tid);
- GNUNET_SERVER_notification_context_unicast(nc,
- client,
- NULL,
- GNUNET_NO);
- }
+ /* Do WE have the service? */
+ type = ntohl (connect_msg->type);
+ for (i = 0; i < n_applications; i++)
+ {
+ if (applications[i] == type)
+ {
+ /* Yes! Fast forward, add ourselves to the tunnel and send the
+ * good news to the client
+ */
+ struct GNUNET_MESH_PeerControl pc;
+
+ GNUNET_PEER_resolve (myid, &pc.peer);
+ GNUNET_CONTAINER_multihashmap_put (t->peers,
+ &pc.peer.hashPubKey,
+ get_peer_info (&pc.peer),
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+ pc.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl));
+ pc.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_CONNECTED);
+ pc.tunnel_id = htonl (t->local_tid);
+ GNUNET_SERVER_notification_context_unicast (nc, client, NULL, GNUNET_NO);
}
- /* Ok, lets find a peer offering the service */
- p = (uint32_t *) &buffer[8];
- *p = connect_msg->type; /* Already in Network Byte Order! */
- GNUNET_CRYPTO_hash(buffer, 12, &hash);
- if (c->dht_get_type) {
- GNUNET_DHT_get_stop(c->dht_get_type);
- }
- c->dht_get_type = GNUNET_DHT_get_start(dht_handle,
- GNUNET_TIME_UNIT_FOREVER_REL,
- GNUNET_BLOCK_TYPE_ANY,
- &hash,
- 10U,
- GNUNET_DHT_RO_RECORD_ROUTE,
- NULL,
- 0,
- NULL,
- 0,
- &dht_get_type_handler,
- t);
+ }
+ /* Ok, lets find a peer offering the service */
+ p = (uint32_t *) & buffer[8];
+ *p = connect_msg->type; /* Already in Network Byte Order! */
+ GNUNET_CRYPTO_hash (buffer, 12, &hash);
+ if (c->dht_get_type)
+ {
+ GNUNET_DHT_get_stop (c->dht_get_type);
+ }
+ c->dht_get_type = GNUNET_DHT_get_start (dht_handle,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_BLOCK_TYPE_ANY,
+ &hash,
+ 10U,
+ GNUNET_DHT_RO_RECORD_ROUTE,
+ NULL,
+ 0, NULL, 0, &dht_get_type_handler,
t);
- GNUNET_SERVER_receive_done(client, GNUNET_OK);
- return;
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ return;
}
@@ -2502,83 +2572,87 @@
struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
- struct MeshClient *c;
- struct MeshTunnel *t;
- struct MeshPeerInfo *pi;
- struct GNUNET_MESH_Unicast *data_msg;
- struct GNUNET_PeerIdentity next_hop;
- struct MeshDataDescriptor *info;
- MESH_TunnelNumber tid;
- size_t data_size;
+ struct MeshClient *c;
+ struct MeshTunnel *t;
+ struct MeshPeerInfo *pi;
+ struct GNUNET_MESH_Unicast *data_msg;
+ struct GNUNET_PeerIdentity next_hop;
+ struct MeshDataDescriptor *info;
+ MESH_TunnelNumber tid;
+ size_t data_size;
- /* Sanity check for client registration */
- if (NULL == (c = retrieve_client(client))) {
- GNUNET_break(0);
- GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
- return;
- }
- data_msg = (struct GNUNET_MESH_Unicast *)message;
- /* Sanity check for message size */
- if (sizeof(struct GNUNET_MESH_Unicast) + sizeof(struct
GNUNET_MessageHeader)
- > ntohs(data_msg->header.size))
- {
- GNUNET_break(0);
- GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
- return;
- }
+ /* Sanity check for client registration */
+ if (NULL == (c = retrieve_client (client)))
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
+ data_msg = (struct GNUNET_MESH_Unicast *) message;
+ /* Sanity check for message size */
+ if (sizeof (struct GNUNET_MESH_Unicast) + sizeof (struct
GNUNET_MessageHeader)
+ > ntohs (data_msg->header.size))
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
- /* Tunnel exists? */
- tid = ntohl(data_msg->tid);
- t = retrieve_tunnel_by_local_id(c, tid);
- if (NULL == t) {
- GNUNET_break(0);
- GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
- return;
- }
+ /* Tunnel exists? */
+ tid = ntohl (data_msg->tid);
+ t = retrieve_tunnel_by_local_id (c, tid);
+ if (NULL == t)
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
- /* Is it a local tunnel? Then, does client own the tunnel? */
- if (t->client->handle != NULL && t->client->handle != client) {
- GNUNET_break(0);
- GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
- return;
- }
+ /* Is it a local tunnel? Then, does client own the tunnel? */
+ if (t->client->handle != NULL && t->client->handle != client)
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
- pi = GNUNET_CONTAINER_multihashmap_get(t->peers,
- &data_msg->destination.hashPubKey);
- /* Is the selected peer in the tunnel? */
- if (NULL == pi) {
- /* TODO
- * Are we SO nice that we automatically try to add him to the tunnel?
- */
- GNUNET_break(0);
- GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
- return;
- }
- if (pi->id == myid) {
- struct GNUNET_MESH_Unicast copy;
- memcpy(©, data_msg, sizeof(struct GNUNET_MESH_Unicast));
+ pi = GNUNET_CONTAINER_multihashmap_get (t->peers,
+ &data_msg->destination.hashPubKey);
+ /* Is the selected peer in the tunnel? */
+ if (NULL == pi)
+ {
+ /* TODO
+ * Are we SO nice that we automatically try to add him to the tunnel?
+ */
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
+ if (pi->id == myid)
+ {
+ struct GNUNET_MESH_Unicast copy;
- handle_mesh_data_unicast(NULL, NULL, ©.header, NULL);
- return;
- }
- GNUNET_PEER_resolve(get_first_hop(pi->path), &next_hop);
- data_size = ntohs(message->size) - sizeof(struct GNUNET_MESH_Unicast);
- info = GNUNET_malloc(sizeof(struct MeshDataDescriptor) + data_size);
- memcpy(&info[1], &data_msg[1], data_size);
- info->destination = pi->id;
- info->origin = &t->id;
- info->size = data_size;
- info->client = client;
- GNUNET_CORE_notify_transmit_ready(core_handle,
- 0,
- 0,
- GNUNET_TIME_UNIT_FOREVER_REL,
- &next_hop,
- /* FIXME re-check types */
- data_size + sizeof(struct GNUNET_MESH_Unicast),
- &send_core_data_unicast,
- info);
+ memcpy (©, data_msg, sizeof (struct GNUNET_MESH_Unicast));
+
+ handle_mesh_data_unicast (NULL, NULL, ©.header, NULL);
return;
+ }
+ GNUNET_PEER_resolve (get_first_hop (pi->path), &next_hop);
+ data_size = ntohs (message->size) - sizeof (struct GNUNET_MESH_Unicast);
+ info = GNUNET_malloc (sizeof (struct MeshDataDescriptor) + data_size);
+ memcpy (&info[1], &data_msg[1], data_size);
+ info->destination = pi->id;
+ info->origin = &t->id;
+ info->size = data_size;
+ info->client = client;
+ GNUNET_CORE_notify_transmit_ready (core_handle,
+ 0,
+ 0, GNUNET_TIME_UNIT_FOREVER_REL,
&next_hop,
+ /* FIXME re-check types */
+ data_size +
+ sizeof (struct GNUNET_MESH_Unicast),
+ &send_core_data_unicast, info);
+ return;
}
/**
@@ -2593,47 +2667,49 @@
struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
- struct MeshClient *c;
- struct MeshTunnel *t;
- struct GNUNET_MESH_Multicast *data_msg;
- MESH_TunnelNumber tid;
+ struct MeshClient *c;
+ struct MeshTunnel *t;
+ struct GNUNET_MESH_Multicast *data_msg;
+ MESH_TunnelNumber tid;
- /* Sanity check for client registration */
- if (NULL == (c = retrieve_client(client))) {
- GNUNET_break(0);
- GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
- return;
- }
- data_msg = (struct GNUNET_MESH_Multicast *)message;
- /* Sanity check for message size */
- if (sizeof(struct GNUNET_MESH_PeerControl)
- != ntohs(data_msg->header.size))
- {
- GNUNET_break(0);
- GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
- return;
- }
+ /* Sanity check for client registration */
+ if (NULL == (c = retrieve_client (client)))
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
+ data_msg = (struct GNUNET_MESH_Multicast *) message;
+ /* Sanity check for message size */
+ if (sizeof (struct GNUNET_MESH_PeerControl) != ntohs (data_msg->header.size))
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
- /* Tunnel exists? */
- tid = ntohl(data_msg->tid);
- t = retrieve_tunnel_by_local_id(c, tid);
- if (NULL == t) {
- GNUNET_break(0);
- GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
- return;
- }
+ /* Tunnel exists? */
+ tid = ntohl (data_msg->tid);
+ t = retrieve_tunnel_by_local_id (c, tid);
+ if (NULL == t)
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
- /* Does client own tunnel? */
- if (t->client->handle != client) {
- GNUNET_break(0);
- GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
- return;
- }
+ /* Does client own tunnel? */
+ if (t->client->handle != client)
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
- /* TODO */
+ /* TODO */
- GNUNET_SERVER_receive_done(client, GNUNET_OK);
- return;
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ return;
}
/**
@@ -2643,19 +2719,19 @@
{&handle_local_new_client, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT, 0},
{&handle_local_tunnel_create, NULL,
GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE,
- sizeof(struct GNUNET_MESH_TunnelMessage)},
+ sizeof (struct GNUNET_MESH_TunnelMessage)},
{&handle_local_tunnel_destroy, NULL,
GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY,
- sizeof(struct GNUNET_MESH_TunnelMessage)},
+ sizeof (struct GNUNET_MESH_TunnelMessage)},
{&handle_local_connect_add, NULL,
GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ADD,
- sizeof(struct GNUNET_MESH_PeerControl)},
+ sizeof (struct GNUNET_MESH_PeerControl)},
{&handle_local_connect_del, NULL,
GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_DEL,
- sizeof(struct GNUNET_MESH_PeerControl)},
+ sizeof (struct GNUNET_MESH_PeerControl)},
{&handle_local_connect_by_type, NULL,
GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_BY_TYPE,
- sizeof(struct GNUNET_MESH_ConnectPeerByType)},
+ sizeof (struct GNUNET_MESH_ConnectPeerByType)},
{&handle_local_unicast, NULL,
GNUNET_MESSAGE_TYPE_MESH_UNICAST, 0},
{&handle_local_unicast, NULL,
@@ -2680,12 +2756,11 @@
const struct GNUNET_PeerIdentity *identity,
const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Core init\n");
- core_handle = server;
- myid = GNUNET_PEER_intern(identity);
- announce_id_task = GNUNET_SCHEDULER_add_now(&announce_id, cls);
- return;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core init\n");
+ core_handle = server;
+ myid = GNUNET_PEER_intern (identity);
+ announce_id_task = GNUNET_SCHEDULER_add_now (&announce_id, cls);
+ return;
}
/**
@@ -2701,23 +2776,22 @@
const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
// GNUNET_PEER_Id pid;
- struct MeshPeerInfo *peer_info;
- struct MeshPath *path;
+ struct MeshPeerInfo *peer_info;
+ struct MeshPath *path;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peer connected\n");
- peer_info = get_peer_info(peer);
- if (myid == peer_info->id) {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- " (self)\n");
- }
- path = GNUNET_malloc(sizeof(struct MeshPath));
- path->length = 2;
- path->peers = GNUNET_malloc(sizeof(GNUNET_PEER_Id) * 2);
- path->peers[0] = myid;
- path->peers[1] = peer_info->id;
- add_path_to_peer(peer_info, path);
- return;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer connected\n");
+ peer_info = get_peer_info (peer);
+ if (myid == peer_info->id)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " (self)\n");
+ }
+ path = GNUNET_malloc (sizeof (struct MeshPath));
+ path->length = 2;
+ path->peers = GNUNET_malloc (sizeof (GNUNET_PEER_Id) * 2);
+ path->peers[0] = myid;
+ path->peers[1] = peer_info->id;
+ add_path_to_peer (peer_info, path);
+ return;
}
/**
@@ -2727,32 +2801,32 @@
* @param peer peer identity this notification is about
*/
static void
-core_disconnect (void *cls,
- const struct
- GNUNET_PeerIdentity *peer)
+core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
{
- struct MeshPeerInfo *pi;
- unsigned int i;
+ struct MeshPeerInfo *pi;
+ unsigned int i;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peer disconnected\n");
- pi = GNUNET_CONTAINER_multihashmap_get(peers, &peer->hashPubKey);
- if (!pi) {
- GNUNET_break(0);
- return;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer disconnected\n");
+ pi = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey);
+ if (!pi)
+ {
+ GNUNET_break (0);
+ return;
+ }
+ for (i = 0; i < CORE_QUEUE_SIZE; i++)
+ {
+ if (pi->core_transmit[i])
+ {
+ GNUNET_CORE_notify_transmit_ready_cancel (pi->core_transmit[i]);
+ /* TODO: notify that tranmission has failed */
+ GNUNET_free (pi->infos[i]);
}
- for (i = 0; i < CORE_QUEUE_SIZE; i++) {
- if (pi->core_transmit[i]) {
- GNUNET_CORE_notify_transmit_ready_cancel(pi->core_transmit[i]);
- /* TODO: notify that tranmission has failed */
- GNUNET_free(pi->infos[i]);
- }
- }
- if (myid == pi->id) {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- " (self)\n");
- }
- return;
+ }
+ if (myid == pi->id)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " (self)\n");
+ }
+ return;
}
@@ -2769,22 +2843,23 @@
static void
shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "shutting down\n");
- if (core_handle != NULL) {
- GNUNET_CORE_disconnect (core_handle);
- core_handle = NULL;
- }
- if (dht_handle != NULL) {
- GNUNET_DHT_disconnect (dht_handle);
- dht_handle = NULL;
- }
- if (nc != NULL) {
- GNUNET_SERVER_notification_context_destroy(nc);
- nc = NULL;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "shut down\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "shutting down\n");
+ if (core_handle != NULL)
+ {
+ GNUNET_CORE_disconnect (core_handle);
+ core_handle = NULL;
+ }
+ if (dht_handle != NULL)
+ {
+ GNUNET_DHT_disconnect (dht_handle);
+ dht_handle = NULL;
+ }
+ if (nc != NULL)
+ {
+ GNUNET_SERVER_notification_context_destroy (nc);
+ nc = NULL;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "shut down\n");
}
/**
@@ -2799,56 +2874,55 @@
struct GNUNET_SERVER_Handle *server,
const struct GNUNET_CONFIGURATION_Handle *c)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "starting to run\n");
- GNUNET_SERVER_add_handlers (server, plugin_handlers);
- GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL);
- server_handle = server;
- core_handle = GNUNET_CORE_connect (c, /* Main configuration
*/
- CORE_QUEUE_SIZE, /* queue size
*/
- NULL, /* Closure passed to MESH functions
*/
- &core_init, /* Call core_init once connected
*/
- &core_connect, /* Handle connects
*/
- &core_disconnect, /* remove peers on disconnects
*/
- NULL, /* Do we care about "status" updates?
*/
- NULL, /* Don't notify about all incoming messages
*/
- GNUNET_NO, /* For header only in notification
*/
- NULL, /* Don't notify about all outbound messages
*/
- GNUNET_NO, /* For header-only out notification
*/
- core_handlers); /* Register these handlers
*/
- if (core_handle == NULL) {
- GNUNET_break(0);
- }
- dht_handle = GNUNET_DHT_connect(c, 64);
- if (dht_handle == NULL) {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- "Error connecting to DHT.\
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "starting to run\n");
+ GNUNET_SERVER_add_handlers (server, plugin_handlers);
+ GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL);
+ server_handle = server;
+ core_handle = GNUNET_CORE_connect (c, /* Main configuration */
+ CORE_QUEUE_SIZE, /* queue size */
+ NULL, /* Closure passed to MESH
functions */
+ &core_init, /* Call core_init once
connected */
+ &core_connect, /* Handle connects */
+ &core_disconnect, /* remove peers on
disconnects */
+ NULL, /* Do we care about "status"
updates? */
+ NULL, /* Don't notify about all
incoming messages */
+ GNUNET_NO, /* For header only in
notification */
+ NULL, /* Don't notify about all
outbound messages */
+ GNUNET_NO, /* For header-only out
notification */
+ core_handlers); /* Register these
handlers */
+ if (core_handle == NULL)
+ {
+ GNUNET_break (0);
+ }
+ dht_handle = GNUNET_DHT_connect (c, 64);
+ if (dht_handle == NULL)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error connecting to DHT.\
Running without DHT has a severe\
impact in MESH capabilities.\n\
Plase check your configuretion and enable DHT.\n");
- GNUNET_break(0);
- }
+ GNUNET_break (0);
+ }
- next_tid = 0;
+ next_tid = 0;
- tunnels = GNUNET_CONTAINER_multihashmap_create(32);
- peers = GNUNET_CONTAINER_multihashmap_create(32);
- nc = GNUNET_SERVER_notification_context_create(server_handle,
- LOCAL_QUEUE_SIZE);
- clients = NULL;
- clients_tail = NULL;
+ tunnels = GNUNET_CONTAINER_multihashmap_create (32);
+ peers = GNUNET_CONTAINER_multihashmap_create (32);
+ nc = GNUNET_SERVER_notification_context_create (server_handle,
+ LOCAL_QUEUE_SIZE);
+ clients = NULL;
+ clients_tail = NULL;
- applications = NULL;
- applications_rc = NULL;
- n_applications = 0;
- announce_applications_task = 0;
+ applications = NULL;
+ applications_rc = NULL;
+ n_applications = 0;
+ announce_applications_task = 0;
- /* Scheduled the task to clean up when shutdown is called */
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task, NULL);
+ /* Scheduled the task to clean up when shutdown is called */
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
+ &shutdown_task, NULL);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "end of run()\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "end of run()\n");
}
/**
@@ -2861,15 +2935,13 @@
int
main (int argc, char *const *argv)
{
- int ret;
+ int ret;
- ret = (GNUNET_OK ==
- GNUNET_SERVICE_run (argc,
- argv,
- "mesh",
- GNUNET_SERVICE_OPTION_NONE,
- &run, NULL)) ? 0 : 1;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "end of main()\n");
- return ret;
+ ret = (GNUNET_OK ==
+ GNUNET_SERVICE_run (argc,
+ argv,
+ "mesh",
+ GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "end of main()\n");
+ return ret;
}
Modified: gnunet/src/mesh/mesh.h
===================================================================
--- gnunet/src/mesh/mesh.h 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/mesh/mesh.h 2011-08-15 21:46:35 UTC (rev 16581)
@@ -77,7 +77,8 @@
/**
* Message for a client to register to the service
*/
-struct GNUNET_MESH_ClientConnect {
+struct GNUNET_MESH_ClientConnect
+{
/**
* Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT
*
@@ -85,11 +86,11 @@
* sizeof(uint16_t) * types +
* sizeof(MESH_ApplicationType) * applications
*/
- struct GNUNET_MessageHeader header;
- uint16_t types GNUNET_PACKED;
- uint16_t applications GNUNET_PACKED;
- /* uint16_t list_types[types] */
- /* uint16_t list_apps[applications] */
+ struct GNUNET_MessageHeader header;
+ uint16_t types GNUNET_PACKED;
+ uint16_t applications GNUNET_PACKED;
+ /* uint16_t list_types[types] */
+ /* uint16_t list_apps[applications] */
};
@@ -103,18 +104,19 @@
/**
* Message for a client to create and destroy tunnels.
*/
-struct GNUNET_MESH_TunnelMessage {
+struct GNUNET_MESH_TunnelMessage
+{
/**
* Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_[CREATE|DESTROY]
*
* Size: sizeof(struct GNUNET_MESH_TunnelMessage)
*/
- struct GNUNET_MessageHeader header;
+ struct GNUNET_MessageHeader header;
/**
* ID of a tunnel controlled by this client.
*/
- MESH_TunnelNumber tunnel_id GNUNET_PACKED;
+ MESH_TunnelNumber tunnel_id GNUNET_PACKED;
};
/**
@@ -125,7 +127,8 @@
* -- unrequested (new incoming tunnels)
* - notify the client that peers have disconnected
*/
-struct GNUNET_MESH_PeerControl {
+struct GNUNET_MESH_PeerControl
+{
/**
* Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_[ADD|DEL]
@@ -135,38 +138,39 @@
*
* Size: sizeof(struct GNUNET_MESH_PeerControl)
*/
- struct GNUNET_MessageHeader header;
+ struct GNUNET_MessageHeader header;
/**
* ID of a tunnel controlled by this client.
*/
- MESH_TunnelNumber tunnel_id GNUNET_PACKED;
-
+ MESH_TunnelNumber tunnel_id GNUNET_PACKED;
+
/**
* Peer to connect/disconnect.
*/
- struct GNUNET_PeerIdentity peer;
+ struct GNUNET_PeerIdentity peer;
};
/**
* Message for connecting to peers offering a certain service.
*/
-struct GNUNET_MESH_ConnectPeerByType {
+struct GNUNET_MESH_ConnectPeerByType
+{
/**
* Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_BY_TYPE
*/
- struct GNUNET_MessageHeader header;
+ struct GNUNET_MessageHeader header;
/**
* ID of a tunnel controlled by this client.
*/
- MESH_TunnelNumber tunnel_id GNUNET_PACKED;
-
+ MESH_TunnelNumber tunnel_id GNUNET_PACKED;
+
/**
* Type specification
*/
- GNUNET_MESH_ApplicationType type GNUNET_PACKED;
+ GNUNET_MESH_ApplicationType type GNUNET_PACKED;
};
#endif
Modified: gnunet/src/mesh/mesh_api.c
===================================================================
--- gnunet/src/mesh/mesh_api.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/mesh/mesh_api.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -49,7 +49,7 @@
struct notify_cls
{
- void* notify_cls;
+ void *notify_cls;
GNUNET_CONNECTION_TransmitReadyNotify notify;
struct GNUNET_MESH_Tunnel *tunnel;
};
@@ -66,24 +66,24 @@
GNUNET_MESH_TunnelConnectHandler connect_handler;
void *handler_cls;
- struct GNUNET_MESH_Handle* handle;
+ struct GNUNET_MESH_Handle *handle;
/* The application-type requested for this tunnel. Is only needed for pending
* by_tupe-tunnels
*/
uint16_t application_type;
- struct GNUNET_MESH_TransmitHandle* notify_handle;
+ struct GNUNET_MESH_TransmitHandle *notify_handle;
/* The context of the receive-function. */
void *ctx;
/* A list, usable by application-code (for queues) */
- void* app_head;
- void* app_tail;
+ void *app_head;
+ void *app_tail;
/* A pointer, usable by application-code */
- void* app_data;
+ void *app_data;
};
struct tunnel_list_element
@@ -136,51 +136,49 @@
};
static void
-send_end_connect(void* cls,
- const struct GNUNET_SCHEDULER_TaskContext* tc)
+send_end_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
+ if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
return;
- struct GNUNET_MESH_Tunnel* tunnel = cls;
+ struct GNUNET_MESH_Tunnel *tunnel = cls;
- tunnel->connect_handler(tunnel->handler_cls, NULL, NULL);
+ tunnel->connect_handler (tunnel->handler_cls, NULL, NULL);
}
static void
-send_self_connect(void* cls,
- const struct GNUNET_SCHEDULER_TaskContext* tc)
+send_self_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
+ if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
+ return;
- struct GNUNET_MESH_Tunnel* tunnel = cls;
+ struct GNUNET_MESH_Tunnel *tunnel = cls;
- tunnel->connect_handler(tunnel->handler_cls, &tunnel->handle->myself, NULL);
- GNUNET_SCHEDULER_add_now(send_end_connect, tunnel);
+ tunnel->connect_handler (tunnel->handler_cls, &tunnel->handle->myself, NULL);
+ GNUNET_SCHEDULER_add_now (send_end_connect, tunnel);
}
static void
-call_connect_handler (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+call_connect_handler (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
+ if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
+ return;
struct GNUNET_MESH_Tunnel *tunnel = cls;
- tunnel->connect_handler (tunnel->handler_cls, &tunnel->peer,
- NULL);
+ tunnel->connect_handler (tunnel->handler_cls, &tunnel->peer, NULL);
GNUNET_SCHEDULER_add_now (send_end_connect, tunnel);
}
static void
core_startup (void *cls,
- struct GNUNET_CORE_Handle *core __attribute__((unused)),
- const struct GNUNET_PeerIdentity *my_identity,
- const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey
__attribute__((unused)))
+ struct GNUNET_CORE_Handle *core __attribute__ ((unused)),
+ const struct GNUNET_PeerIdentity *my_identity,
+ const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey
+ __attribute__ ((unused)))
{
struct GNUNET_MESH_Handle *handle = cls;
+
memcpy (&handle->myself, my_identity, sizeof (struct GNUNET_PeerIdentity));
handle->connected_to_core = GNUNET_YES;
}
@@ -188,21 +186,24 @@
static size_t
send_hello_message (void *cls, size_t size, void *buf)
{
- if (cls == NULL) return 0;
+ if (cls == NULL)
+ return 0;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending hello\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending hello\n");
struct GNUNET_MESH_Handle *handle = cls;
struct GNUNET_MessageHeader *hdr = buf;
- size_t sent = sizeof(struct GNUNET_MessageHeader) +
handle->hello_message_size;
+ size_t sent =
+ sizeof (struct GNUNET_MessageHeader) + handle->hello_message_size;
- if (sent > size) return 0;
+ if (sent > size)
+ return 0;
- hdr->type = htons(GNUNET_MESSAGE_TYPE_MESH_HELLO);
- hdr->size = htons(size);
+ hdr->type = htons (GNUNET_MESSAGE_TYPE_MESH_HELLO);
+ hdr->size = htons (size);
- memcpy(hdr+1, handle->hello_message, handle->hello_message_size);
+ memcpy (hdr + 1, handle->hello_message, handle->hello_message_size);
return sent;
}
@@ -215,26 +216,27 @@
*/
static void
core_connect (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+ const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
struct GNUNET_MESH_Handle *handle = cls;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Core tells us we are connected to peer
%s\n", GNUNET_i2s(peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Core tells us we are connected to peer %s\n", GNUNET_i2s
(peer));
/* Send a hello to this peer */
- GNUNET_CORE_notify_transmit_ready(handle->core,
- GNUNET_NO,
- 42,
- GNUNET_TIME_UNIT_SECONDS,
- peer,
- sizeof(struct GNUNET_MessageHeader) +
handle->hello_message_size,
- &send_hello_message,
- cls);
+ GNUNET_CORE_notify_transmit_ready (handle->core,
+ GNUNET_NO,
+ 42,
+ GNUNET_TIME_UNIT_SECONDS,
+ peer,
+ sizeof (struct GNUNET_MessageHeader) +
+ handle->hello_message_size,
+ &send_hello_message, cls);
/* put the new peer into the list of connected peers */
struct peer_list_element *element =
- GNUNET_malloc (sizeof (struct peer_list_element));
+ GNUNET_malloc (sizeof (struct peer_list_element));
memcpy (&element->peer, peer, sizeof (struct GNUNET_PeerIdentity));
if (NULL != atsi)
@@ -242,31 +244,32 @@
sizeof (struct GNUNET_TRANSPORT_ATS_Information));
GNUNET_CONTAINER_DLL_insert_after (handle->connected_peers.head,
- handle->connected_peers.tail,
- handle->connected_peers.tail, element);
+ handle->connected_peers.tail,
+ handle->connected_peers.tail, element);
struct tunnel_list_element *tunnel = handle->pending_tunnels.head;
+
while (tunnel != NULL)
+ {
+ if (0 ==
+ memcmp (&tunnel->tunnel.peer, peer,
+ sizeof (struct GNUNET_PeerIdentity)))
{
- if (0 ==
- memcmp (&tunnel->tunnel.peer, peer,
- sizeof (struct GNUNET_PeerIdentity)))
- {
- struct tunnel_list_element *next = tunnel->next;
- GNUNET_CONTAINER_DLL_remove (handle->pending_tunnels.head,
- handle->pending_tunnels.tail, tunnel);
- GNUNET_CONTAINER_DLL_insert_after (handle->established_tunnels.head,
- handle->established_tunnels.tail,
- handle->established_tunnels.tail,
- tunnel);
- tunnel->tunnel.connect_handler (tunnel->tunnel.handler_cls,
- peer, atsi);
- GNUNET_SCHEDULER_add_now(send_end_connect, tunnel);
- tunnel = next;
- }
- else
- tunnel = tunnel->next;
+ struct tunnel_list_element *next = tunnel->next;
+
+ GNUNET_CONTAINER_DLL_remove (handle->pending_tunnels.head,
+ handle->pending_tunnels.tail, tunnel);
+ GNUNET_CONTAINER_DLL_insert_after (handle->established_tunnels.head,
+ handle->established_tunnels.tail,
+ handle->established_tunnels.tail,
+ tunnel);
+ tunnel->tunnel.connect_handler (tunnel->tunnel.handler_cls, peer, atsi);
+ GNUNET_SCHEDULER_add_now (send_end_connect, tunnel);
+ tunnel = next;
}
+ else
+ tunnel = tunnel->next;
+ }
}
/**
@@ -280,58 +283,63 @@
{
struct GNUNET_MESH_Handle *handle = cls;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Core tells us we are no longer
connected to peer %s\n", GNUNET_i2s(peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Core tells us we are no longer connected to peer %s\n",
+ GNUNET_i2s (peer));
struct peer_list_element *element = handle->connected_peers.head;
+
while (element != NULL)
- {
- if (0 ==
- memcmp (&element->peer, peer, sizeof (struct GNUNET_PeerIdentity)))
- break;
- element = element->next;
- }
+ {
+ if (0 == memcmp (&element->peer, peer, sizeof (struct
GNUNET_PeerIdentity)))
+ break;
+ element = element->next;
+ }
if (element != NULL)
+ {
+ GNUNET_CONTAINER_DLL_remove (handle->connected_peers.head,
+ handle->connected_peers.tail, element);
+ while (element->type_head != NULL)
{
- GNUNET_CONTAINER_DLL_remove (handle->connected_peers.head,
- handle->connected_peers.tail, element);
- while (element->type_head != NULL)
- {
- struct type_list_element* tail = element->type_tail;
- GNUNET_CONTAINER_DLL_remove(element->type_head, element->type_tail,
tail);
- GNUNET_free(tail);
- }
- GNUNET_free (element);
+ struct type_list_element *tail = element->type_tail;
+
+ GNUNET_CONTAINER_DLL_remove (element->type_head, element->type_tail,
+ tail);
+ GNUNET_free (tail);
}
+ GNUNET_free (element);
+ }
struct tunnel_list_element *telement = handle->established_tunnels.head;
+
while (telement != NULL)
+ {
+ if (0 ==
+ memcmp (&telement->tunnel.peer, peer,
+ sizeof (struct GNUNET_PeerIdentity)))
{
- if (0 ==
- memcmp (&telement->tunnel.peer, peer,
- sizeof (struct GNUNET_PeerIdentity)))
- {
- /* disconnect tunnels */
- /* outbound tunnels */
- if (telement->tunnel.connect_handler != NULL && NULL !=
telement->tunnel.disconnect_handler)
- telement->tunnel.disconnect_handler (telement->tunnel.handler_cls,
- peer);
- /* inbound tunnels */
- else if (NULL != handle->cleaner)
- handle->cleaner (handle->cls, &telement->tunnel,
- &telement->tunnel.ctx);
+ /* disconnect tunnels */
+ /* outbound tunnels */
+ if (telement->tunnel.connect_handler != NULL &&
+ NULL != telement->tunnel.disconnect_handler)
+ telement->tunnel.disconnect_handler (telement->tunnel.handler_cls,
+ peer);
+ /* inbound tunnels */
+ else if (NULL != handle->cleaner)
+ handle->cleaner (handle->cls, &telement->tunnel,
&telement->tunnel.ctx);
- struct tunnel_list_element *next = telement->next;
- GNUNET_CONTAINER_DLL_remove (handle->established_tunnels.head,
- handle->established_tunnels.tail,
- telement);
- GNUNET_free (telement);
- telement = next;
- }
- else
- {
- telement = telement->next;
- }
+ struct tunnel_list_element *next = telement->next;
+
+ GNUNET_CONTAINER_DLL_remove (handle->established_tunnels.head,
+ handle->established_tunnels.tail, telement);
+ GNUNET_free (telement);
+ telement = next;
}
+ else
+ {
+ telement = telement->next;
+ }
+ }
}
/**
@@ -346,66 +354,79 @@
{
struct GNUNET_MESH_Handle *handle = cls;
uint16_t *num = (uint16_t *) (message + 1);
- GNUNET_MESH_ApplicationType *ports = (GNUNET_MESH_ApplicationType*) (num +
1);
+ GNUNET_MESH_ApplicationType *ports =
+ (GNUNET_MESH_ApplicationType *) (num + 1);
unsigned int i;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "The peer %s tells us he supports %d
application-types.\n", GNUNET_i2s(other), ntohs(*num));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "The peer %s tells us he supports %d application-types.\n",
+ GNUNET_i2s (other), ntohs (*num));
struct peer_list_element *element = handle->connected_peers.head;
+
while (element != NULL)
- {
- if (0 ==
- memcmp (&element->peer, other, sizeof (struct GNUNET_PeerIdentity)))
- break;
- element = element->next;
- }
+ {
+ if (0 ==
+ memcmp (&element->peer, other, sizeof (struct GNUNET_PeerIdentity)))
+ break;
+ element = element->next;
+ }
- GNUNET_assert(NULL != element);
+ GNUNET_assert (NULL != element);
- for (i = 0; i < ntohs(*num); i++)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "The peer %s newly supports the
application-type %d\n", GNUNET_i2s(other), ntohs(ports[i]));
- if (GNUNET_APPLICATION_TYPE_END == ntohs(ports[i])) continue;
- struct type_list_element* new_type = GNUNET_malloc(sizeof *new_type);
- new_type->type = (GNUNET_MESH_ApplicationType)ntohs (ports[i]);
- GNUNET_CONTAINER_DLL_insert(element->type_head, element->type_tail,
new_type);
- }
+ for (i = 0; i < ntohs (*num); i++)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "The peer %s newly supports the application-type %d\n",
+ GNUNET_i2s (other), ntohs (ports[i]));
+ if (GNUNET_APPLICATION_TYPE_END == ntohs (ports[i]))
+ continue;
+ struct type_list_element *new_type = GNUNET_malloc (sizeof *new_type);
+ new_type->type = (GNUNET_MESH_ApplicationType) ntohs (ports[i]);
+ GNUNET_CONTAINER_DLL_insert (element->type_head, element->type_tail,
+ new_type);
+ }
+
struct type_list_element *type;
+
for (type = element->type_head; type != NULL; type = type->next)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "The peer %s supports the
application-type %d\n", GNUNET_i2s(other), type->type);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "The peer %s supports the application-type %d\n",
+ GNUNET_i2s (other), type->type);
+ }
struct tunnel_list_element *tunnel = handle->pending_by_type_tunnels.head;
+
while (tunnel != NULL)
+ {
+ struct tunnel_list_element *next = tunnel->next;
+
+ for (i = 0; i < ntohs (*num); i++)
{
- struct tunnel_list_element *next = tunnel->next;
- for (i = 0; i < ntohs(*num); i++)
- {
- if (ntohs (ports[i]) == tunnel->tunnel.application_type)
- {
- GNUNET_CONTAINER_DLL_remove
(handle->pending_by_type_tunnels.head,
-
handle->pending_by_type_tunnels.tail,
+ if (ntohs (ports[i]) == tunnel->tunnel.application_type)
+ {
+ GNUNET_CONTAINER_DLL_remove (handle->pending_by_type_tunnels.head,
+ handle->pending_by_type_tunnels.tail,
+ tunnel);
+ GNUNET_CONTAINER_DLL_insert_after (handle->established_tunnels.head,
+ handle->established_tunnels.tail,
+ handle->established_tunnels.tail,
tunnel);
- GNUNET_CONTAINER_DLL_insert_after (handle->established_tunnels.
- head,
- handle->established_tunnels.
- tail,
- handle->established_tunnels.
- tail, tunnel);
- memcpy(&tunnel->tunnel.peer, other, sizeof(struct
GNUNET_PeerIdentity));
- tunnel->tunnel.connect_handler (tunnel->tunnel.handler_cls,
- &tunnel->tunnel.peer, atsi);
- GNUNET_SCHEDULER_add_now (send_end_connect, tunnel);
- break;
- }
- }
- if (ntohs (ports[i]) == tunnel->tunnel.application_type)
- tunnel = next;
- else
- tunnel = tunnel->next;
+ memcpy (&tunnel->tunnel.peer, other,
+ sizeof (struct GNUNET_PeerIdentity));
+ tunnel->tunnel.connect_handler (tunnel->tunnel.handler_cls,
+ &tunnel->tunnel.peer, atsi);
+ GNUNET_SCHEDULER_add_now (send_end_connect, tunnel);
+ break;
+ }
}
+ if (ntohs (ports[i]) == tunnel->tunnel.application_type)
+ tunnel = next;
+ else
+ tunnel = tunnel->next;
+ }
return GNUNET_OK;
}
@@ -414,110 +435,115 @@
*/
static int
core_receive (void *cls,
- const struct GNUNET_PeerIdentity *other,
- const struct GNUNET_MessageHeader *message,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+ const struct GNUNET_PeerIdentity *other,
+ const struct GNUNET_MessageHeader *message,
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
struct GNUNET_MESH_Handle *handle = cls;
struct tunnel_message *tmessage = (struct tunnel_message *) message;
struct GNUNET_MessageHeader *rmessage =
- (struct GNUNET_MessageHeader *) (tmessage + 1);
+ (struct GNUNET_MessageHeader *) (tmessage + 1);
struct GNUNET_MESH_MessageHandler *handler;
for (handler = handle->handlers; handler->callback != NULL; handler++)
+ {
+ if ((ntohs (rmessage->type) == handler->type)
+ && ((handler->expected_size == 0)
+ || (handler->expected_size == ntohs (rmessage->size))))
{
- if ( (ntohs (rmessage->type) == handler->type)
- && ( (handler->expected_size == 0)
- || (handler->expected_size == ntohs (rmessage->size))) )
- {
- break;
- }
+ break;
}
+ }
/* handler->callback handles this message */
/* If no handler was found, drop the message but keep the channel open */
if (handler->callback == NULL)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received message of type %d from
peer %s; dropping it.\n",
- ntohs(rmessage->type), GNUNET_i2s(other));
- return GNUNET_OK;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received message of type %d from peer %s; dropping it.\n",
+ ntohs (rmessage->type), GNUNET_i2s (other));
+ return GNUNET_OK;
+ }
struct tunnel_list_element *tunnel = handle->established_tunnels.head;
while (tunnel != NULL)
- {
- if (tunnel->tunnel.id.id == tmessage->id.id &&
- (0 ==
- memcmp (&tmessage->id.initiator, &tunnel->tunnel.id.initiator,
- sizeof (struct GNUNET_PeerIdentity)))
- && (0 ==
- memcmp (&tmessage->id.target, &tunnel->tunnel.id.target,
- sizeof (struct GNUNET_PeerIdentity))))
- break;
- tunnel = tunnel->next;
- }
+ {
+ if (tunnel->tunnel.id.id == tmessage->id.id &&
+ (0 ==
+ memcmp (&tmessage->id.initiator, &tunnel->tunnel.id.initiator,
+ sizeof (struct GNUNET_PeerIdentity)))
+ && (0 ==
+ memcmp (&tmessage->id.target, &tunnel->tunnel.id.target,
+ sizeof (struct GNUNET_PeerIdentity))))
+ break;
+ tunnel = tunnel->next;
+ }
/* if no tunnel was found: create a new inbound tunnel */
if (tunnel == NULL)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "New inbound tunnel from peer %s;
first message has type %d.\n",
- GNUNET_i2s(other), ntohs(rmessage->type));
- tunnel = GNUNET_malloc (sizeof (struct tunnel_list_element));
- tunnel->tunnel.connect_handler = NULL;
- tunnel->tunnel.disconnect_handler = NULL;
- tunnel->tunnel.handler_cls = NULL;
- tunnel->tunnel.ctx = NULL;
- tunnel->tunnel.handle = handle;
- memcpy (&tunnel->tunnel.peer, other,
- sizeof (struct GNUNET_PeerIdentity));
- memcpy (&tunnel->tunnel.id, &tmessage->id, sizeof (struct tunnel_id));
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "New inbound tunnel from peer %s; first message has type
%d.\n",
+ GNUNET_i2s (other), ntohs (rmessage->type));
+ tunnel = GNUNET_malloc (sizeof (struct tunnel_list_element));
+ tunnel->tunnel.connect_handler = NULL;
+ tunnel->tunnel.disconnect_handler = NULL;
+ tunnel->tunnel.handler_cls = NULL;
+ tunnel->tunnel.ctx = NULL;
+ tunnel->tunnel.handle = handle;
+ memcpy (&tunnel->tunnel.peer, other, sizeof (struct GNUNET_PeerIdentity));
+ memcpy (&tunnel->tunnel.id, &tmessage->id, sizeof (struct tunnel_id));
- GNUNET_CONTAINER_DLL_insert_after (handle->established_tunnels.head,
- handle->established_tunnels.tail,
- handle->established_tunnels.tail,
- tunnel);
- }
+ GNUNET_CONTAINER_DLL_insert_after (handle->established_tunnels.head,
+ handle->established_tunnels.tail,
+ handle->established_tunnels.tail,
+ tunnel);
+ }
else
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Inbound message from peer %s; type
%d.\n",
- GNUNET_i2s(other), ntohs(rmessage->type));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Inbound message from peer %s; type %d.\n", GNUNET_i2s (other),
+ ntohs (rmessage->type));
return handler->callback (handle->cls, &tunnel->tunnel,
- &tunnel->tunnel.ctx, other, rmessage, atsi);
+ &tunnel->tunnel.ctx, other, rmessage, atsi);
}
struct GNUNET_MESH_Tunnel *
GNUNET_MESH_peer_request_connect_by_type (struct GNUNET_MESH_Handle *handle,
struct GNUNET_TIME_Relative timeout,
- GNUNET_MESH_ApplicationType
application_type,
+ GNUNET_MESH_ApplicationType
+ application_type,
GNUNET_MESH_TunnelConnectHandler
connect_handler,
GNUNET_MESH_TunnelDisconnectHandler
- disconnect_handler,
- void *handler_cls)
+ disconnect_handler, void
*handler_cls)
{
/* Look in the list of connected peers */
struct peer_list_element *element = handle->connected_peers.head;
+
while (element != NULL)
- {
- struct type_list_element* i;
- for (i = element->type_head; i != NULL; i = i->next)
- if (application_type == i->type)
- return GNUNET_MESH_peer_request_connect_all (handle, timeout, 1,
- &element->peer,
- connect_handler,
- disconnect_handler,
- handler_cls);
- element = element->next;
- }
+ {
+ struct type_list_element *i;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Trying to connect by tupe %d.\n",
application_type);
+ for (i = element->type_head; i != NULL; i = i->next)
+ if (application_type == i->type)
+ return GNUNET_MESH_peer_request_connect_all (handle, timeout, 1,
+ &element->peer,
+ connect_handler,
+ disconnect_handler,
+ handler_cls);
+ element = element->next;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to connect by tupe %d.\n",
+ application_type);
+
/* Put into pending list */
struct tunnel_list_element *tunnel =
- GNUNET_malloc (sizeof (struct tunnel_list_element));
+ GNUNET_malloc (sizeof (struct tunnel_list_element));
tunnel->tunnel.connect_handler = connect_handler;
tunnel->tunnel.disconnect_handler = disconnect_handler;
@@ -540,19 +566,19 @@
struct GNUNET_MESH_Tunnel *
GNUNET_MESH_peer_request_connect_all (struct GNUNET_MESH_Handle *handle,
- struct GNUNET_TIME_Relative timeout,
- unsigned int num_peers,
- const struct GNUNET_PeerIdentity *peers,
- GNUNET_MESH_TunnelConnectHandler
- connect_handler,
- GNUNET_MESH_TunnelDisconnectHandler
- disconnect_handler, void *handler_cls)
+ struct GNUNET_TIME_Relative timeout,
+ unsigned int num_peers,
+ const struct GNUNET_PeerIdentity *peers,
+ GNUNET_MESH_TunnelConnectHandler
+ connect_handler,
+ GNUNET_MESH_TunnelDisconnectHandler
+ disconnect_handler, void *handler_cls)
{
if (num_peers != 1)
return NULL;
struct tunnel_list_element *tunnel =
- GNUNET_malloc (sizeof (struct tunnel_list_element));
+ GNUNET_malloc (sizeof (struct tunnel_list_element));
tunnel->tunnel.connect_handler = connect_handler;
tunnel->tunnel.disconnect_handler = disconnect_handler;
@@ -560,83 +586,85 @@
tunnel->tunnel.ctx = NULL;
tunnel->tunnel.handle = handle;
memcpy (&tunnel->tunnel.id.initiator, &handle->myself,
- sizeof (struct GNUNET_PeerIdentity));
+ sizeof (struct GNUNET_PeerIdentity));
memcpy (&tunnel->tunnel.id.target, peers,
- sizeof (struct GNUNET_PeerIdentity));
+ sizeof (struct GNUNET_PeerIdentity));
tunnel->tunnel.id.id = current_id++;
- memcpy (&tunnel->tunnel.peer, peers, sizeof(struct GNUNET_PeerIdentity));
+ memcpy (&tunnel->tunnel.peer, peers, sizeof (struct GNUNET_PeerIdentity));
struct peer_list_element *element = handle->connected_peers.head;
+
while (element != NULL)
- {
- if (0 ==
- memcmp (&element->peer, peers, sizeof (struct GNUNET_PeerIdentity)))
- break;
- element = element->next;
- }
+ {
+ if (0 ==
+ memcmp (&element->peer, peers, sizeof (struct GNUNET_PeerIdentity)))
+ break;
+ element = element->next;
+ }
if (element != NULL)
- {
- /* we are connected to this peer */
- GNUNET_CONTAINER_DLL_insert_after (handle->established_tunnels.head,
- handle->established_tunnels.tail,
- handle->established_tunnels.tail,
- tunnel);
- GNUNET_SCHEDULER_add_now(call_connect_handler, tunnel);
- }
+ {
+ /* we are connected to this peer */
+ GNUNET_CONTAINER_DLL_insert_after (handle->established_tunnels.head,
+ handle->established_tunnels.tail,
+ handle->established_tunnels.tail,
+ tunnel);
+ GNUNET_SCHEDULER_add_now (call_connect_handler, tunnel);
+ }
else if (0 ==
- memcmp (peers, &handle->myself,
- sizeof (struct GNUNET_PeerIdentity)))
- {
- /* we are the peer */
- GNUNET_CONTAINER_DLL_insert_after (handle->established_tunnels.head,
- handle->established_tunnels.tail,
- handle->established_tunnels.tail,
- tunnel);
- GNUNET_SCHEDULER_add_now(send_self_connect, tunnel);
- }
+ memcmp (peers, &handle->myself, sizeof (struct
GNUNET_PeerIdentity)))
+ {
+ /* we are the peer */
+ GNUNET_CONTAINER_DLL_insert_after (handle->established_tunnels.head,
+ handle->established_tunnels.tail,
+ handle->established_tunnels.tail,
+ tunnel);
+ GNUNET_SCHEDULER_add_now (send_self_connect, tunnel);
+ }
else
- {
- /* we are not connected to this peer */
- GNUNET_CONTAINER_DLL_insert_after (handle->pending_tunnels.head,
- handle->pending_tunnels.tail,
- handle->pending_tunnels.tail,
- tunnel);
- (void) GNUNET_CORE_peer_request_connect (handle->core,
- peers,
- NULL, NULL);
- }
+ {
+ /* we are not connected to this peer */
+ GNUNET_CONTAINER_DLL_insert_after (handle->pending_tunnels.head,
+ handle->pending_tunnels.tail,
+ handle->pending_tunnels.tail, tunnel);
+ (void) GNUNET_CORE_peer_request_connect (handle->core, peers, NULL, NULL);
+ }
return &tunnel->tunnel;
}
-const struct GNUNET_PeerIdentity*
-GNUNET_MESH_get_peer(const struct GNUNET_MESH_Tunnel* tunnel)
+const struct GNUNET_PeerIdentity *
+GNUNET_MESH_get_peer (const struct GNUNET_MESH_Tunnel *tunnel)
{
return &tunnel->peer;
}
static size_t
-core_notify(void* cls, size_t size, void* buf)
+core_notify (void *cls, size_t size, void *buf)
{
struct notify_cls *ncls = cls;
struct GNUNET_MESH_Tunnel *tunnel = ncls->tunnel;
+
tunnel->notify_handle = NULL;
- struct tunnel_message* message = buf;
- void* cbuf = (void*) &message[1];
- GNUNET_assert(NULL != ncls->notify);
+ struct tunnel_message *message = buf;
+ void *cbuf = (void *) &message[1];
- size_t sent = ncls->notify(ncls->notify_cls, size - sizeof(struct
tunnel_message), cbuf);
+ GNUNET_assert (NULL != ncls->notify);
- GNUNET_free(ncls);
+ size_t sent =
+ ncls->notify (ncls->notify_cls, size - sizeof (struct tunnel_message),
+ cbuf);
- if (0 == sent) return 0;
+ GNUNET_free (ncls);
- sent += sizeof(struct tunnel_message);
+ if (0 == sent)
+ return 0;
- message->hdr.type = htons(GNUNET_MESSAGE_TYPE_MESH);
- message->hdr.size = htons(sent);
- memcpy(&message->id, &tunnel->id, sizeof(struct tunnel_id));
+ sent += sizeof (struct tunnel_message);
+
+ message->hdr.type = htons (GNUNET_MESSAGE_TYPE_MESH);
+ message->hdr.size = htons (sent);
+ memcpy (&message->id, &tunnel->id, sizeof (struct tunnel_id));
return sent;
}
@@ -678,30 +706,30 @@
notify, void *notify_cls)
{
if (NULL != tunnel->notify_handle)
- {
- GNUNET_break(0);
- return NULL;
- }
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
struct notify_cls *cls = GNUNET_malloc (sizeof (struct notify_cls));
+
cls->notify_cls = notify_cls;
GNUNET_assert (NULL != notify);
cls->notify = notify;
cls->tunnel = tunnel;
tunnel->notify_handle = (struct GNUNET_MESH_TransmitHandle *)
- GNUNET_CORE_notify_transmit_ready (tunnel->handle->core, cork, priority,
- maxdelay, &tunnel->peer,
- notify_size +
- sizeof (struct tunnel_message),
- &core_notify, (void *) cls);
+ GNUNET_CORE_notify_transmit_ready (tunnel->handle->core, cork, priority,
+ maxdelay, &tunnel->peer,
+ notify_size +
+ sizeof (struct tunnel_message),
+ &core_notify, (void *) cls);
return tunnel->notify_handle;
}
void
-GNUNET_MESH_notify_transmit_ready_cancel (struct GNUNET_MESH_TransmitHandle
- *th)
+GNUNET_MESH_notify_transmit_ready_cancel (struct GNUNET_MESH_TransmitHandle
*th)
{
GNUNET_CORE_notify_transmit_ready_cancel ((struct GNUNET_CORE_TransmitHandle
*) th);
@@ -744,30 +772,34 @@
}
-void build_hello_message(struct GNUNET_MESH_Handle* handle,
- const GNUNET_MESH_ApplicationType *stypes)
+void
+build_hello_message (struct GNUNET_MESH_Handle *handle,
+ const GNUNET_MESH_ApplicationType *stypes)
{
int num = 0;
const GNUNET_MESH_ApplicationType *t;
- for (t = stypes; *t != GNUNET_APPLICATION_TYPE_END; t++, num++);
+ for (t = stypes; *t != GNUNET_APPLICATION_TYPE_END; t++, num++) ;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "I can handle %d app-types.\n", num);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "I can handle %d app-types.\n", num);
- handle->hello_message_size = sizeof(uint16_t) + /* For the number of types */
- num * sizeof(GNUNET_MESH_ApplicationType); /* For the types */
+ handle->hello_message_size = sizeof (uint16_t) + /* For the number of
types */
+ num * sizeof (GNUNET_MESH_ApplicationType); /* For the types */
- uint16_t *nums = GNUNET_malloc(handle->hello_message_size);
- GNUNET_MESH_ApplicationType *types = (GNUNET_MESH_ApplicationType*)(nums +
1);
+ uint16_t *nums = GNUNET_malloc (handle->hello_message_size);
+ GNUNET_MESH_ApplicationType *types =
+ (GNUNET_MESH_ApplicationType *) (nums + 1);
- *nums = htons(num);
+ *nums = htons (num);
int i;
+
for (i = 0; i < num; i++)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "I can handle the app-type %d\n",
stypes[i]);
- types[i] = htons(stypes[i]);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "I can handle the app-type %d\n",
+ stypes[i]);
+ types[i] = htons (stypes[i]);
+ }
handle->hello_message = nums;
}
@@ -775,15 +807,15 @@
struct GNUNET_MESH_Handle *
GNUNET_MESH_connect (const struct
- GNUNET_CONFIGURATION_Handle
- *cfg, void *cls,
- GNUNET_MESH_TunnelEndHandler
- cleaner,
- const struct GNUNET_MESH_MessageHandler *handlers,
+ GNUNET_CONFIGURATION_Handle
+ *cfg, void *cls,
+ GNUNET_MESH_TunnelEndHandler
+ cleaner,
+ const struct GNUNET_MESH_MessageHandler *handlers,
const GNUNET_MESH_ApplicationType *stypes)
{
struct GNUNET_MESH_Handle *ret =
- GNUNET_malloc (sizeof (struct GNUNET_MESH_Handle));
+ GNUNET_malloc (sizeof (struct GNUNET_MESH_Handle));
ret->connected_to_core = GNUNET_NO;
ret->connected_peers.head = NULL;
@@ -793,18 +825,19 @@
const struct GNUNET_MESH_MessageHandler *it;
unsigned int len = 1;
+
for (it = handlers; it->callback != NULL; it++)
- {
- len++;
- }
+ {
+ len++;
+ }
ret->handlers =
- GNUNET_malloc (len * sizeof (struct GNUNET_MESH_MessageHandler));
- memset(ret->handlers, 0, len * sizeof(struct GNUNET_MESH_MessageHandler));
+ GNUNET_malloc (len * sizeof (struct GNUNET_MESH_MessageHandler));
+ memset (ret->handlers, 0, len * sizeof (struct GNUNET_MESH_MessageHandler));
memcpy (ret->handlers, handlers,
- len * sizeof (struct GNUNET_MESH_MessageHandler));
+ len * sizeof (struct GNUNET_MESH_MessageHandler));
- build_hello_message(ret, stypes);
+ build_hello_message (ret, stypes);
static const struct GNUNET_CORE_MessageHandler core_handlers[] = {
{&core_receive, GNUNET_MESSAGE_TYPE_MESH, 0},
@@ -813,14 +846,14 @@
};
ret->core = GNUNET_CORE_connect (cfg,
- 42,
- ret,
- &core_startup,
- &core_connect,
- &core_disconnect,
- NULL,
- NULL,
- GNUNET_NO, NULL, GNUNET_NO, core_handlers);
+ 42,
+ ret,
+ &core_startup,
+ &core_connect,
+ &core_disconnect,
+ NULL,
+ NULL,
+ GNUNET_NO, NULL, GNUNET_NO, core_handlers);
return ret;
}
@@ -832,34 +865,41 @@
GNUNET_CORE_disconnect (handle->core);
struct peer_list_element *element = handle->connected_peers.head;
+
while (element != NULL)
+ {
+ struct peer_list_element *next = element->next;
+
+ while (element->type_head != NULL)
{
- struct peer_list_element *next = element->next;
- while (element->type_head != NULL)
- {
- struct type_list_element* tail = element->type_tail;
- GNUNET_CONTAINER_DLL_remove(element->type_head, element->type_tail,
tail);
- GNUNET_free(tail);
- }
- GNUNET_free (element);
- element = next;
+ struct type_list_element *tail = element->type_tail;
+
+ GNUNET_CONTAINER_DLL_remove (element->type_head, element->type_tail,
+ tail);
+ GNUNET_free (tail);
}
+ GNUNET_free (element);
+ element = next;
+ }
struct tunnel_list_element *tunnel = handle->pending_tunnels.head;
+
while (tunnel != NULL)
- {
- struct tunnel_list_element *next = tunnel->next;
- GNUNET_free (tunnel);
- tunnel = next;
- }
+ {
+ struct tunnel_list_element *next = tunnel->next;
+
+ GNUNET_free (tunnel);
+ tunnel = next;
+ }
tunnel = handle->established_tunnels.head;;
while (tunnel != NULL)
- {
- struct tunnel_list_element *next = tunnel->next;
- GNUNET_free (tunnel);
- tunnel = next;
- }
+ {
+ struct tunnel_list_element *next = tunnel->next;
+ GNUNET_free (tunnel);
+ tunnel = next;
+ }
+
GNUNET_free (handle);
}
Modified: gnunet/src/mesh/mesh_api_new.c
===================================================================
--- gnunet/src/mesh/mesh_api_new.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/mesh/mesh_api_new.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -57,17 +57,18 @@
/**
* Opaque handle to the service.
*/
-struct GNUNET_MESH_Handle {
+struct GNUNET_MESH_Handle
+{
/**
* Handle to the server connection, to send messages later
*/
- struct GNUNET_CLIENT_Connection *client;
+ struct GNUNET_CLIENT_Connection *client;
/**
* Set of handlers used for processing incoming messages in the tunnels
*/
- const struct GNUNET_MESH_MessageHandler *message_handlers;
- int n_handlers;
+ const struct GNUNET_MESH_MessageHandler *message_handlers;
+ int n_handlers;
/**
* Set of applications that should be claimed to be offered at this node.
@@ -75,85 +76,87 @@
* registered independently and the mapping is up to the developer of the
* client application.
*/
- const GNUNET_MESH_ApplicationType *applications;
- int n_applications;
+ const GNUNET_MESH_ApplicationType *applications;
+ int n_applications;
/**
* Double linked list of the tunnels this client is connected to.
*/
- struct GNUNET_MESH_Tunnel *tunnels_head;
- struct GNUNET_MESH_Tunnel *tunnels_tail;
+ struct GNUNET_MESH_Tunnel *tunnels_head;
+ struct GNUNET_MESH_Tunnel *tunnels_tail;
/**
* tid of the next tunnel to create (to avoid reusing IDs often)
*/
- MESH_TunnelNumber next_tid;
+ MESH_TunnelNumber next_tid;
/**
* Callback for tunnel disconnection
*/
- GNUNET_MESH_TunnelEndHandler *cleaner;
+ GNUNET_MESH_TunnelEndHandler *cleaner;
/**
* Handle to cancel pending transmissions in case of disconnection
*/
- struct GNUNET_CLIENT_TransmitHandle *th;
+ struct GNUNET_CLIENT_TransmitHandle *th;
/**
* Closure for all the handlers given by the client
*/
- void *cls;
+ void *cls;
};
/**
* Opaque handle to a tunnel.
*/
-struct GNUNET_MESH_Tunnel {
+struct GNUNET_MESH_Tunnel
+{
/**
* DLL
*/
- struct GNUNET_MESH_Tunnel *next;
- struct GNUNET_MESH_Tunnel *prev;
+ struct GNUNET_MESH_Tunnel *next;
+ struct GNUNET_MESH_Tunnel *prev;
/**
* Local ID of the tunnel
*/
- MESH_TunnelNumber tid;
+ MESH_TunnelNumber tid;
/**
* Owner of the tunnel
*/
- GNUNET_PEER_Id owner;
+ GNUNET_PEER_Id owner;
/**
* Callback to execute when peers connect to the tunnel
*/
- GNUNET_MESH_TunnelConnectHandler connect_handler;
+ GNUNET_MESH_TunnelConnectHandler connect_handler;
/**
* Callback to execute when peers disconnect to the tunnel
*/
- GNUNET_MESH_TunnelDisconnectHandler disconnect_handler;
+ GNUNET_MESH_TunnelDisconnectHandler disconnect_handler;
/**
* All peers added to the tunnel
*/
- GNUNET_PEER_Id *peers;
+ GNUNET_PEER_Id *peers;
/**
* Closure for the connect/disconnect handlers
*/
- void *cls;
+ void *cls;
/**
* Handle to the mesh this tunnel belongs to
*/
- struct GNUNET_MESH_Handle *mesh;
+ struct GNUNET_MESH_Handle *mesh;
};
-struct GNUNET_MESH_TransmitHandle {
- // TODO
+struct GNUNET_MESH_TransmitHandle
+{
+ // TODO
};
/******************************************************************************/
@@ -167,16 +170,18 @@
* @return handle to the required tunnel or NULL if not found
*/
static struct GNUNET_MESH_Tunnel *
-retrieve_tunnel (struct GNUNET_MESH_Handle *h, MESH_TunnelNumber tid)
+retrieve_tunnel (struct GNUNET_MESH_Handle *h, MESH_TunnelNumber tid)
{
- struct GNUNET_MESH_Tunnel *t;
+ struct GNUNET_MESH_Tunnel *t;
- t = h->tunnels_head;
- while (t != NULL) {
- if (t->tid == tid) return t;
- t = t->next;
- }
- return NULL;
+ t = h->tunnels_head;
+ while (t != NULL)
+ {
+ if (t->tid == tid)
+ return t;
+ t = t->next;
+ }
+ return NULL;
}
@@ -196,65 +201,63 @@
* @param buf where the callee should write the connect message
* @return number of bytes written to buf
*/
-static size_t
+static size_t
send_connect_packet (void *cls, size_t size, void *buf)
{
- struct GNUNET_MESH_Handle *h = cls;
- struct GNUNET_MESH_ClientConnect *msg;
- uint16_t *types;
- uint16_t ntypes;
- GNUNET_MESH_ApplicationType *apps;
- uint16_t napps;
+ struct GNUNET_MESH_Handle *h = cls;
+ struct GNUNET_MESH_ClientConnect *msg;
+ uint16_t *types;
+ uint16_t ntypes;
+ GNUNET_MESH_ApplicationType *apps;
+ uint16_t napps;
- h->th = NULL;
- if (0 == size || buf == NULL) {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Send connect packet: buffer size 0 or buffer invalid\n");
- // FIXME: disconnect, reconnect, retry!
- return 0;
- }
- if (sizeof(struct GNUNET_MessageHeader) > size) {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Send connect packet: buffer size too small\n");
- // FIXME: disconnect, reconnect, retry!
- return 0;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Send connect packet: %lu bytes buffer\n",
- size);
- msg = (struct GNUNET_MESH_ClientConnect *) buf;
- msg->header.type = htons(GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT);
+ h->th = NULL;
+ if (0 == size || buf == NULL)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Send connect packet: buffer size 0 or buffer invalid\n");
+ // FIXME: disconnect, reconnect, retry!
+ return 0;
+ }
+ if (sizeof (struct GNUNET_MessageHeader) > size)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Send connect packet: buffer size too small\n");
+ // FIXME: disconnect, reconnect, retry!
+ return 0;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Send connect packet: %lu bytes buffer\n", size);
+ msg = (struct GNUNET_MESH_ClientConnect *) buf;
+ msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT);
- for (ntypes = 0, types = NULL; ntypes < h->n_handlers; ntypes++) {
- types = GNUNET_realloc(types, sizeof(uint16_t) * (ntypes + 1));
- types[ntypes] = h->message_handlers[ntypes].type;
- }
+ for (ntypes = 0, types = NULL; ntypes < h->n_handlers; ntypes++)
+ {
+ types = GNUNET_realloc (types, sizeof (uint16_t) * (ntypes + 1));
+ types[ntypes] = h->message_handlers[ntypes].type;
+ }
- for(napps = 0, apps = NULL; napps < h->n_applications; napps++) {
- apps = GNUNET_realloc(apps,
- sizeof(GNUNET_MESH_ApplicationType) *
- (napps + 1));
- apps[napps] = h->applications[napps];
- }
+ for (napps = 0, apps = NULL; napps < h->n_applications; napps++)
+ {
+ apps = GNUNET_realloc (apps,
+ sizeof (GNUNET_MESH_ApplicationType) * (napps + 1));
+ apps[napps] = h->applications[napps];
+ }
- msg->header.size = htons(sizeof(struct GNUNET_MESH_ClientConnect) +
- sizeof(uint16_t) * ntypes +
- sizeof(GNUNET_MESH_ApplicationType) * napps);
+ msg->header.size = htons (sizeof (struct GNUNET_MESH_ClientConnect) +
+ sizeof (uint16_t) * ntypes +
+ sizeof (GNUNET_MESH_ApplicationType) * napps);
- memcpy(&msg[1], types, sizeof(uint16_t) * ntypes);
- memcpy(&msg[1] + sizeof(uint16_t) * ntypes,
- apps,
- sizeof(GNUNET_MESH_ApplicationType) * napps);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sent %lu bytes long message %d types and %d apps\n",
- ntohs(msg->header.size),
- ntypes,
- napps
- );
- msg->applications = htons(napps);
- msg->types = htons(ntypes);
+ memcpy (&msg[1], types, sizeof (uint16_t) * ntypes);
+ memcpy (&msg[1] + sizeof (uint16_t) * ntypes,
+ apps, sizeof (GNUNET_MESH_ApplicationType) * napps);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sent %lu bytes long message %d types and %d apps\n",
+ ntohs (msg->header.size), ntypes, napps);
+ msg->applications = htons (napps);
+ msg->types = htons (ntypes);
- return ntohs(msg->header.size);
+ return ntohs (msg->header.size);
}
@@ -269,41 +272,41 @@
* @param buf where the callee should write the create tunnel message
* @return number of bytes written to buf
*/
-static size_t
+static size_t
send_tunnel_create_packet (void *cls, size_t size, void *buf)
{
- struct GNUNET_MESH_Tunnel *t = cls;
- struct GNUNET_MESH_Handle *h;
- struct GNUNET_MESH_TunnelMessage *msg;
+ struct GNUNET_MESH_Tunnel *t = cls;
+ struct GNUNET_MESH_Handle *h;
+ struct GNUNET_MESH_TunnelMessage *msg;
- h = t->mesh;
- h->th = NULL;
- if (0 == size || buf == NULL) {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Send connect packet: buffer size 0 or buffer invalid\n");
- // FIXME: disconnect, reconnect, retry!
- return 0;
- }
- if (sizeof(struct GNUNET_MessageHeader) > size) {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Send connect packet: buffer size too small\n");
- // FIXME: disconnect, reconnect, retry!
- return 0;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Send connect packet: %lu bytes buffer\n",
- size);
- msg = (struct GNUNET_MESH_TunnelMessage *) buf;
- msg->header.type = htons(GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT);
+ h = t->mesh;
+ h->th = NULL;
+ if (0 == size || buf == NULL)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Send connect packet: buffer size 0 or buffer invalid\n");
+ // FIXME: disconnect, reconnect, retry!
+ return 0;
+ }
+ if (sizeof (struct GNUNET_MessageHeader) > size)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Send connect packet: buffer size too small\n");
+ // FIXME: disconnect, reconnect, retry!
+ return 0;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Send connect packet: %lu bytes buffer\n", size);
+ msg = (struct GNUNET_MESH_TunnelMessage *) buf;
+ msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT);
- msg->header.size = htons(sizeof(struct GNUNET_MESH_TunnelMessage));
- msg->tunnel_id = htonl(t->tid);
+ msg->header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage));
+ msg->tunnel_id = htonl (t->tid);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sent %lu bytes long message\n",
- ntohs(msg->header.size));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sent %lu bytes long message\n", ntohs (msg->header.size));
- return ntohs(msg->header.size);
+ return ntohs (msg->header.size);
}
@@ -318,26 +321,27 @@
* @param msg A message with the details of the new incoming tunnel
*/
static void
-process_tunnel_create(struct GNUNET_MESH_Handle *h,
- const struct GNUNET_MESH_TunnelMessage *msg)
+process_tunnel_create (struct GNUNET_MESH_Handle *h,
+ const struct GNUNET_MESH_TunnelMessage *msg)
{
- struct GNUNET_MESH_Tunnel *t;
- MESH_TunnelNumber tid;
+ struct GNUNET_MESH_Tunnel *t;
+ MESH_TunnelNumber tid;
- tid = ntohl(msg->tunnel_id);
- if (tid >= GNUNET_MESH_LOCAL_TUNNEL_ID_MARK) {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "MESH: received an incoming tunnel with tid in local range (%X)\n",
- tid);
- GNUNET_break_op(0);
- return; //FIXME abort? reconnect?
- }
- t = GNUNET_malloc(sizeof(struct GNUNET_MESH_Tunnel));
- t->cls = h->cls;
- t->mesh = h;
- t->tid = tid;
+ tid = ntohl (msg->tunnel_id);
+ if (tid >= GNUNET_MESH_LOCAL_TUNNEL_ID_MARK)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "MESH: received an incoming tunnel with tid in local range
(%X)\n",
+ tid);
+ GNUNET_break_op (0);
+ return; //FIXME abort? reconnect?
+ }
+ t = GNUNET_malloc (sizeof (struct GNUNET_MESH_Tunnel));
+ t->cls = h->cls;
+ t->mesh = h;
+ t->tid = tid;
- return;
+ return;
}
@@ -348,31 +352,38 @@
* @param msg A message with the details of the peer event
*/
static void
-process_peer_event(struct GNUNET_MESH_Handle *h,
- const struct GNUNET_MESH_PeerControl *msg)
+process_peer_event (struct GNUNET_MESH_Handle *h,
+ const struct GNUNET_MESH_PeerControl *msg)
{
- struct GNUNET_MESH_Tunnel *t;
- uint16_t size;
+ struct GNUNET_MESH_Tunnel *t;
+ uint16_t size;
- size = ntohs(msg->header.size);
- if (size != sizeof(struct GNUNET_MESH_PeerControl)) {
- GNUNET_break_op(0);
- return;
+ size = ntohs (msg->header.size);
+ if (size != sizeof (struct GNUNET_MESH_PeerControl))
+ {
+ GNUNET_break_op (0);
+ return;
+ }
+ t = retrieve_tunnel (h, ntohl (msg->tunnel_id));
+ if (NULL == t)
+ {
+ GNUNET_break_op (0);
+ return;
+ }
+ if (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_CONNECTED == msg->header.type)
+ {
+ if (NULL != t->connect_handler)
+ {
+ t->connect_handler (t->cls, &msg->peer, NULL); /* FIXME atsi */
}
- t = retrieve_tunnel(h, ntohl(msg->tunnel_id));
- if (NULL == t) {
- GNUNET_break_op(0);
- return;
+ }
+ else
+ {
+ if (NULL != t->disconnect_handler)
+ {
+ t->disconnect_handler (t->cls, &msg->peer);
}
- if (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_CONNECTED == msg->header.type) {
- if (NULL != t->connect_handler) {
- t->connect_handler(t->cls, &msg->peer, NULL); /* FIXME atsi */
- }
- } else {
- if (NULL != t->disconnect_handler) {
- t->disconnect_handler(t->cls, &msg->peer);
- }
- }
+ }
}
@@ -383,67 +394,69 @@
* @param msh A message encapsulating the data
*/
static void
-process_incoming_data(struct GNUNET_MESH_Handle *h,
- const struct GNUNET_MessageHeader *message)
+process_incoming_data (struct GNUNET_MESH_Handle *h,
+ const struct GNUNET_MessageHeader *message)
{
- const struct GNUNET_MessageHeader *payload;
- const struct GNUNET_MESH_MessageHandler *handler;
- const struct GNUNET_PeerIdentity *peer;
- struct GNUNET_MESH_Unicast *ucast;
- struct GNUNET_MESH_Multicast *mcast;
- struct GNUNET_MESH_ToOrigin *to_orig;
- struct GNUNET_MESH_Tunnel *t;
- uint16_t type;
- int i;
+ const struct GNUNET_MessageHeader *payload;
+ const struct GNUNET_MESH_MessageHandler *handler;
+ const struct GNUNET_PeerIdentity *peer;
+ struct GNUNET_MESH_Unicast *ucast;
+ struct GNUNET_MESH_Multicast *mcast;
+ struct GNUNET_MESH_ToOrigin *to_orig;
+ struct GNUNET_MESH_Tunnel *t;
+ uint16_t type;
+ int i;
- type = ntohs(message->type);
- switch (type) {
- case GNUNET_MESSAGE_TYPE_MESH_UNICAST:
- ucast = (struct GNUNET_MESH_Unicast *) message;
- t = retrieve_tunnel(h, ntohl(ucast->tid));
- payload = (struct GNUNET_MessageHeader *) &ucast[1];
- peer = &ucast->oid;
- break;
- case GNUNET_MESSAGE_TYPE_MESH_MULTICAST:
- mcast = (struct GNUNET_MESH_Multicast *) message;
- t = retrieve_tunnel(h, ntohl(mcast->tid));
- payload = (struct GNUNET_MessageHeader *) &mcast[1];
- peer = &mcast->oid;
- break;
- case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN:
- to_orig = (struct GNUNET_MESH_ToOrigin *) message;
- t = retrieve_tunnel(h, ntohl(to_orig->tid));
- payload = (struct GNUNET_MessageHeader *) &to_orig[1];
- peer = &to_orig->sender;
- break;
- default:
- GNUNET_break_op(0);
- return;
+ type = ntohs (message->type);
+ switch (type)
+ {
+ case GNUNET_MESSAGE_TYPE_MESH_UNICAST:
+ ucast = (struct GNUNET_MESH_Unicast *) message;
+ t = retrieve_tunnel (h, ntohl (ucast->tid));
+ payload = (struct GNUNET_MessageHeader *) &ucast[1];
+ peer = &ucast->oid;
+ break;
+ case GNUNET_MESSAGE_TYPE_MESH_MULTICAST:
+ mcast = (struct GNUNET_MESH_Multicast *) message;
+ t = retrieve_tunnel (h, ntohl (mcast->tid));
+ payload = (struct GNUNET_MessageHeader *) &mcast[1];
+ peer = &mcast->oid;
+ break;
+ case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN:
+ to_orig = (struct GNUNET_MESH_ToOrigin *) message;
+ t = retrieve_tunnel (h, ntohl (to_orig->tid));
+ payload = (struct GNUNET_MessageHeader *) &to_orig[1];
+ peer = &to_orig->sender;
+ break;
+ default:
+ GNUNET_break_op (0);
+ return;
+ }
+ if (NULL == t)
+ {
+ GNUNET_break_op (0);
+ return;
+ }
+ for (i = 0; i < h->n_handlers; i++)
+ {
+ handler = &h->message_handlers[i];
+ if (handler->type == type)
+ {
+ if (GNUNET_OK == handler->callback (h->cls, t, NULL, /* FIXME ctx */
+ peer, payload, NULL)) /* FIXME atsi
*/
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "MESH: callback completed successfully\n");
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "MESH: callback caused disconnection\n");
+ GNUNET_MESH_disconnect (h);
+ }
}
- if (NULL == t) {
- GNUNET_break_op(0);
- return;
- }
- for (i = 0; i < h->n_handlers; i++) {
- handler = &h->message_handlers[i];
- if (handler->type == type) {
- if (GNUNET_OK == handler->callback (h->cls,
- t,
- NULL, /* FIXME ctx */
- peer,
- payload,
- NULL)) /* FIXME atsi
*/
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "MESH: callback completed successfully\n");
- } else {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "MESH: callback caused disconnection\n");
- GNUNET_MESH_disconnect(h);
- }
- }
- }
- return;
+ }
+ return;
}
@@ -454,45 +467,44 @@
* @param msg message received, NULL on timeout or fatal error
*/
static void
-msg_received (void *cls, const struct GNUNET_MessageHeader * msg)
+msg_received (void *cls, const struct GNUNET_MessageHeader *msg)
{
- struct GNUNET_MESH_Handle *h = cls;
+ struct GNUNET_MESH_Handle *h = cls;
- if (msg == NULL) {
- GNUNET_break_op(0);
- return;
- }
+ if (msg == NULL)
+ {
+ GNUNET_break_op (0);
+ return;
+ }
- switch (ntohs(msg->type)) {
- /* Notify of a new incoming tunnel */
- case GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE:
- process_tunnel_create(h, (struct GNUNET_MESH_TunnelMessage *)msg);
- break;
- /* Notify of a new peer or a peer disconnect in the tunnel*/
- case GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_CONNECTED:
- case GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DISCONNECTED:
- process_peer_event(h, (struct GNUNET_MESH_PeerControl *)msg);
- break;
- /* Notify of a new data packet in the tunnel */
- case GNUNET_MESSAGE_TYPE_MESH_UNICAST:
- case GNUNET_MESSAGE_TYPE_MESH_MULTICAST:
- case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN:
- process_incoming_data(h, msg);
- break;
- /* We shouldn't get any other packages, log and ignore */
- default:
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
- "MESH: unsolicited message form service (type %d)\n",
- ntohs(msg->type));
- }
+ switch (ntohs (msg->type))
+ {
+ /* Notify of a new incoming tunnel */
+ case GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE:
+ process_tunnel_create (h, (struct GNUNET_MESH_TunnelMessage *) msg);
+ break;
+ /* Notify of a new peer or a peer disconnect in the tunnel */
+ case GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_CONNECTED:
+ case GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DISCONNECTED:
+ process_peer_event (h, (struct GNUNET_MESH_PeerControl *) msg);
+ break;
+ /* Notify of a new data packet in the tunnel */
+ case GNUNET_MESSAGE_TYPE_MESH_UNICAST:
+ case GNUNET_MESSAGE_TYPE_MESH_MULTICAST:
+ case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN:
+ process_incoming_data (h, msg);
+ break;
+ /* We shouldn't get any other packages, log and ignore */
+ default:
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "MESH: unsolicited message form service (type %d)\n",
+ ntohs (msg->type));
+ }
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "received a message from mesh\n");
- GNUNET_CLIENT_receive (h->client,
- &msg_received,
- h,
- GNUNET_TIME_UNIT_FOREVER_REL);
- return;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "received a message from mesh\n");
+ GNUNET_CLIENT_receive (h->client,
+ &msg_received, h, GNUNET_TIME_UNIT_FOREVER_REL);
+ return;
}
/******************************************************************************/
@@ -519,44 +531,43 @@
void *cls,
GNUNET_MESH_TunnelEndHandler cleaner,
const struct GNUNET_MESH_MessageHandler *handlers,
- const GNUNET_MESH_ApplicationType *stypes)
+ const GNUNET_MESH_ApplicationType *stypes)
{
- struct GNUNET_MESH_Handle *h;
- size_t size;
+ struct GNUNET_MESH_Handle *h;
+ size_t size;
- h = GNUNET_malloc(sizeof(struct GNUNET_MESH_Handle));
+ h = GNUNET_malloc (sizeof (struct GNUNET_MESH_Handle));
- h->cleaner = cleaner;
- h->client = GNUNET_CLIENT_connect("mesh", cfg);
- GNUNET_CLIENT_receive (h->client,
- &msg_received,
- h,
- GNUNET_TIME_UNIT_FOREVER_REL);
- if(h->client == NULL) {
- GNUNET_free(h);
- return NULL;
- }
+ h->cleaner = cleaner;
+ h->client = GNUNET_CLIENT_connect ("mesh", cfg);
+ GNUNET_CLIENT_receive (h->client,
+ &msg_received, h, GNUNET_TIME_UNIT_FOREVER_REL);
+ if (h->client == NULL)
+ {
+ GNUNET_free (h);
+ return NULL;
+ }
- h->cls = cls;
- h->message_handlers = handlers;
- h->applications = stypes;
- h->next_tid = 0x80000000;
+ h->cls = cls;
+ h->message_handlers = handlers;
+ h->applications = stypes;
+ h->next_tid = 0x80000000;
- for(h->n_handlers = 0; handlers[h->n_handlers].type; h->n_handlers++);
- for(h->n_applications = 0; stypes[h->n_applications]; h->n_applications++);
+ for (h->n_handlers = 0; handlers[h->n_handlers].type; h->n_handlers++) ;
+ for (h->n_applications = 0; stypes[h->n_applications]; h->n_applications++) ;
- size = sizeof(struct GNUNET_MESH_ClientConnect);
- size += h->n_handlers * sizeof(uint16_t);
- size += h->n_applications * sizeof(GNUNET_MESH_ApplicationType);
+ size = sizeof (struct GNUNET_MESH_ClientConnect);
+ size += h->n_handlers * sizeof (uint16_t);
+ size += h->n_applications * sizeof (GNUNET_MESH_ApplicationType);
- h->th = GNUNET_CLIENT_notify_transmit_ready(h->client,
- size,
- GNUNET_TIME_UNIT_FOREVER_REL,
- GNUNET_YES,
- &send_connect_packet,
- (void *)h);
+ h->th = GNUNET_CLIENT_notify_transmit_ready (h->client,
+ size,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_YES,
+ &send_connect_packet,
+ (void *) h);
- return h;
+ return h;
}
@@ -565,16 +576,18 @@
*
* @param handle connection to mesh to disconnect
*/
-void
-GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle)
+void
+GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle)
{
- if (NULL != handle->th) {
- GNUNET_CLIENT_notify_transmit_ready_cancel (handle->th);
- }
- if (NULL != handle->client) {
- GNUNET_CLIENT_disconnect (handle->client, GNUNET_NO);
- }
- GNUNET_free(handle);
+ if (NULL != handle->th)
+ {
+ GNUNET_CLIENT_notify_transmit_ready_cancel (handle->th);
+ }
+ if (NULL != handle->client)
+ {
+ GNUNET_CLIENT_disconnect (handle->client, GNUNET_NO);
+ }
+ GNUNET_free (handle);
}
@@ -592,30 +605,29 @@
GNUNET_MESH_TunnelConnectHandler
connect_handler,
GNUNET_MESH_TunnelDisconnectHandler
- disconnect_handler,
- void *handler_cls)
+ disconnect_handler, void *handler_cls)
{
- struct GNUNET_MESH_Tunnel *tunnel;
+ struct GNUNET_MESH_Tunnel *tunnel;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "MESH: Creating new tunnel\n");
- tunnel = GNUNET_malloc(sizeof(struct GNUNET_MESH_Tunnel));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Creating new tunnel\n");
+ tunnel = GNUNET_malloc (sizeof (struct GNUNET_MESH_Tunnel));
- tunnel->connect_handler = connect_handler;
- tunnel->disconnect_handler = disconnect_handler;
- tunnel->cls = handler_cls;
- tunnel->mesh = h;
- tunnel->tid = h->next_tid++;
- h->next_tid |= GNUNET_MESH_LOCAL_TUNNEL_ID_MARK; // keep in range
+ tunnel->connect_handler = connect_handler;
+ tunnel->disconnect_handler = disconnect_handler;
+ tunnel->cls = handler_cls;
+ tunnel->mesh = h;
+ tunnel->tid = h->next_tid++;
+ h->next_tid |= GNUNET_MESH_LOCAL_TUNNEL_ID_MARK; // keep in range
- h->th = GNUNET_CLIENT_notify_transmit_ready(h->client,
- sizeof(struct GNUNET_MESH_TunnelMessage),
- GNUNET_TIME_UNIT_FOREVER_REL,
- GNUNET_YES,
- &send_tunnel_create_packet,
- (void *)tunnel);
+ h->th = GNUNET_CLIENT_notify_transmit_ready (h->client,
+ sizeof (struct
+
GNUNET_MESH_TunnelMessage),
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_YES,
+ &send_tunnel_create_packet,
+ (void *) tunnel);
- return tunnel;
+ return tunnel;
}
@@ -632,14 +644,14 @@
struct GNUNET_TIME_Relative timeout,
const struct GNUNET_PeerIdentity *peer)
{
- static GNUNET_PEER_Id peer_id;
+ static GNUNET_PEER_Id peer_id;
- peer_id = GNUNET_PEER_intern(peer);
+ peer_id = GNUNET_PEER_intern (peer);
- /* FIXME ACTUALLY DO STUFF */
- tunnel->peers = &peer_id;
- tunnel->connect_handler(tunnel->cls, peer, NULL);
- return;
+ /* FIXME ACTUALLY DO STUFF */
+ tunnel->peers = &peer_id;
+ tunnel->connect_handler (tunnel->cls, peer, NULL);
+ return;
}
@@ -654,10 +666,10 @@
GNUNET_MESH_peer_request_connect_del (struct GNUNET_MESH_Tunnel *tunnel,
const struct GNUNET_PeerIdentity *peer)
{
- /* FIXME ACTUALLY DO STUFF */
- tunnel->peers = NULL;
- tunnel->disconnect_handler(tunnel->cls, peer);
- return;
+ /* FIXME ACTUALLY DO STUFF */
+ tunnel->peers = NULL;
+ tunnel->disconnect_handler (tunnel->cls, peer);
+ return;
}
@@ -673,10 +685,9 @@
void
GNUNET_MESH_peer_request_connect_by_type (struct GNUNET_MESH_Tunnel *tunnel,
struct GNUNET_TIME_Relative timeout,
- GNUNET_MESH_ApplicationType
- app_type)
+ GNUNET_MESH_ApplicationType app_type)
{
- return;
+ return;
}
@@ -710,14 +721,13 @@
const struct GNUNET_PeerIdentity *target,
size_t notify_size,
GNUNET_CONNECTION_TransmitReadyNotify
- notify,
- void *notify_cls)
+ notify, void *notify_cls)
{
- struct GNUNET_MESH_TransmitHandle *handle;
+ struct GNUNET_MESH_TransmitHandle *handle;
- handle = GNUNET_malloc(sizeof(struct GNUNET_MESH_TransmitHandle));
+ handle = GNUNET_malloc (sizeof (struct GNUNET_MESH_TransmitHandle));
- return handle;
+ return handle;
}
Modified: gnunet/src/mesh/mesh_protocol.h
===================================================================
--- gnunet/src/mesh/mesh_protocol.h 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/mesh/mesh_protocol.h 2011-08-15 21:46:35 UTC (rev 16581)
@@ -49,19 +49,19 @@
* Size: sizeof(struct GNUNET_MESH_ManipulatePath) +
* path_length * sizeof (struct GNUNET_PeerIdentity)
*/
- struct GNUNET_MessageHeader header;
+ struct GNUNET_MessageHeader header;
/**
* Global id of the tunnel this path belongs to,
* unique in conjunction with the origin.
*/
- uint32_t tid GNUNET_PACKED;
+ uint32_t tid GNUNET_PACKED;
/**
* path_length structs defining the *whole* path from the origin [0] to the
* final destination [path_length-1].
*/
- /* struct GNUNET_PeerIdentity peers[path_length]; */
+ /* struct GNUNET_PeerIdentity peers[path_length]; */
};
/**
@@ -72,17 +72,17 @@
/**
* Type: GNUNET_MESSAGE_TYPE_MESH_MULTICAST
*/
- struct GNUNET_MessageHeader header;
+ struct GNUNET_MessageHeader header;
/**
* TID of the tunnel
*/
- uint32_t tid GNUNET_PACKED;
+ uint32_t tid GNUNET_PACKED;
/**
* OID of the tunnel
*/
- struct GNUNET_PeerIdentity oid;
+ struct GNUNET_PeerIdentity oid;
/**
* Payload follows
@@ -98,22 +98,22 @@
/**
* Type: GNUNET_MESSAGE_TYPE_MESH_UNICAST
*/
- struct GNUNET_MessageHeader header;
+ struct GNUNET_MessageHeader header;
/**
* TID of the tunnel
*/
- uint32_t tid GNUNET_PACKED;
+ uint32_t tid GNUNET_PACKED;
/**
* OID of the tunnel
*/
- struct GNUNET_PeerIdentity oid;
+ struct GNUNET_PeerIdentity oid;
/**
* Destination.
*/
- struct GNUNET_PeerIdentity destination;
+ struct GNUNET_PeerIdentity destination;
/**
* Payload follows
@@ -129,22 +129,22 @@
/**
* Type: GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN
*/
- struct GNUNET_MessageHeader header;
+ struct GNUNET_MessageHeader header;
/**
* TID of the tunnel
*/
- uint32_t tid GNUNET_PACKED;
+ uint32_t tid GNUNET_PACKED;
/**
* OID of the tunnel
*/
- struct GNUNET_PeerIdentity oid;
+ struct GNUNET_PeerIdentity oid;
/**
* Sender of the message.
*/
- struct GNUNET_PeerIdentity sender;
+ struct GNUNET_PeerIdentity sender;
/**
* Payload follows
@@ -160,24 +160,24 @@
/**
* Type: GNUNET_MESSAGE_TYPE_PATH_ACK
*/
- struct GNUNET_MessageHeader header;
+ struct GNUNET_MessageHeader header;
/**
* TID of the tunnel
*/
- uint32_t tid GNUNET_PACKED;
+ uint32_t tid GNUNET_PACKED;
/**
* OID of the tunnel
*/
- struct GNUNET_PeerIdentity oid;
+ struct GNUNET_PeerIdentity oid;
/**
* ID of the endpoint
*/
- struct GNUNET_PeerIdentity peer_id;
+ struct GNUNET_PeerIdentity peer_id;
- /* TODO: signature */
+ /* TODO: signature */
};
@@ -189,22 +189,22 @@
/**
* Type: GNUNET_MESSAGE_TYPE_DATA_SPEED_NOTIFY
*/
- struct GNUNET_MessageHeader header;
+ struct GNUNET_MessageHeader header;
/**
* TID of the tunnel
*/
- uint32_t tid GNUNET_PACKED;
+ uint32_t tid GNUNET_PACKED;
/**
* OID of the tunnel
*/
- struct GNUNET_PeerIdentity oid;
+ struct GNUNET_PeerIdentity oid;
/**
* Slowest link down the path (above minimum speed requirement).
*/
- uint32_t speed_min;
+ uint32_t speed_min;
};
Modified: gnunet/src/mesh/test_mesh_api.c
===================================================================
--- gnunet/src/mesh/test_mesh_api.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/mesh/test_mesh_api.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -32,11 +32,11 @@
#define VERBOSE 1
#define VERBOSE_ARM 0
-static struct GNUNET_OS_Process *arm_pid;
-static struct GNUNET_MESH_Handle *mesh;
-static int result;
-GNUNET_SCHEDULER_TaskIdentifier abort_task;
-GNUNET_SCHEDULER_TaskIdentifier test_task;
+static struct GNUNET_OS_Process *arm_pid;
+static struct GNUNET_MESH_Handle *mesh;
+static int result;
+GNUNET_SCHEDULER_TaskIdentifier abort_task;
+GNUNET_SCHEDULER_TaskIdentifier test_task;
/**
* Function is called whenever a message is received.
@@ -51,70 +51,76 @@
* GNUNET_SYSERR to close it (signal serious error)
*/
static int
-callback(void *cls,
- struct GNUNET_MESH_Tunnel *tunnel,
- void **tunnel_ctx,
- const struct GNUNET_PeerIdentity *sender,
- const struct GNUNET_MessageHeader *message,
- const struct GNUNET_TRANSPORT_ATS_Information
- *atsi)
+callback (void *cls,
+ struct GNUNET_MESH_Tunnel *tunnel,
+ void **tunnel_ctx,
+ const struct GNUNET_PeerIdentity *sender,
+ const struct GNUNET_MessageHeader *message,
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
- return 0;
+ return 0;
}
-static struct GNUNET_MESH_MessageHandler handlers[] = {{&callback, 1,
0},
- {NULL, 0, 0}};
+static struct GNUNET_MESH_MessageHandler handlers[] = { {&callback, 1, 0},
+{NULL, 0, 0}
+};
static void
do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- if (0 != abort_task) {
- GNUNET_SCHEDULER_cancel(abort_task);
- }
- if (NULL != mesh) {
- GNUNET_MESH_disconnect (mesh);
- }
- if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM)) {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
- }
- GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (arm_pid));
- GNUNET_OS_process_close (arm_pid);
+ if (0 != abort_task)
+ {
+ GNUNET_SCHEDULER_cancel (abort_task);
+ }
+ if (NULL != mesh)
+ {
+ GNUNET_MESH_disconnect (mesh);
+ }
+ if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM))
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
+ }
+ GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (arm_pid));
+ GNUNET_OS_process_close (arm_pid);
}
static void
do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- if (0 != test_task) {
- GNUNET_SCHEDULER_cancel(test_task);
- }
- result = GNUNET_SYSERR;
- abort_task = 0;
- do_shutdown(cls, tc);
+ if (0 != test_task)
+ {
+ GNUNET_SCHEDULER_cancel (test_task);
+ }
+ result = GNUNET_SYSERR;
+ abort_task = 0;
+ do_shutdown (cls, tc);
}
static void
test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- struct GNUNET_CONFIGURATION_Handle *cfg = cls;
- GNUNET_MESH_ApplicationType app[3];
+ struct GNUNET_CONFIGURATION_Handle *cfg = cls;
+ GNUNET_MESH_ApplicationType app[3];
- test_task = (GNUNET_SCHEDULER_TaskIdentifier) 0;
- app[0] = (GNUNET_MESH_ApplicationType) 1;
- app[1] = (GNUNET_MESH_ApplicationType) 2;
- app[2] = (GNUNET_MESH_ApplicationType) 0;
- mesh = GNUNET_MESH_connect(cfg, NULL, NULL, handlers, &app);
- if(NULL == mesh) {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Couldn't connect to mesh :(\n");
- return;
- } else {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "YAY! CONNECTED TO MESH :D\n");
- }
+ test_task = (GNUNET_SCHEDULER_TaskIdentifier) 0;
+ app[0] = (GNUNET_MESH_ApplicationType) 1;
+ app[1] = (GNUNET_MESH_ApplicationType) 2;
+ app[2] = (GNUNET_MESH_ApplicationType) 0;
+ mesh = GNUNET_MESH_connect (cfg, NULL, NULL, handlers, &app);
+ if (NULL == mesh)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Couldn't connect to mesh :(\n");
+ return;
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "YAY! CONNECTED TO MESH :D\n");
+ }
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(
- GNUNET_TIME_UNIT_SECONDS, 1),
- &do_shutdown,
- NULL);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 1), &do_shutdown,
+ NULL);
}
@@ -123,23 +129,21 @@
char *const *args,
const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
- arm_pid = GNUNET_OS_start_process (NULL, NULL,
- "gnunet-service-arm",
- "gnunet-service-arm",
+ arm_pid = GNUNET_OS_start_process (NULL, NULL,
+ "gnunet-service-arm",
"gnunet-service-arm",
#if VERBOSE_ARM
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", "test_mesh.conf",
- NULL);
+ "-c", "test_mesh.conf", NULL);
- abort_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(
- GNUNET_TIME_UNIT_SECONDS, 20),
- &do_abort,
- NULL);
- test_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(
- GNUNET_TIME_UNIT_SECONDS, 1),
- &test,
- (void *)cfg);
+ abort_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 20), &do_abort,
+ NULL);
+ test_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 1), &test,
+ (void *) cfg);
}
@@ -147,37 +151,39 @@
int
main (int argc, char *argv[])
{
- int ret;
- char *const argv2[] = {"test-mesh-api",
- "-c", "test_mesh.conf",
+ int ret;
+
+ char *const argv2[] = { "test-mesh-api",
+ "-c", "test_mesh.conf",
#if VERBOSE
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- NULL
- };
- struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_OPTION_END
- };
- GNUNET_log_setup ("test-mesh-api",
+ NULL
+ };
+ struct GNUNET_GETOPT_CommandLineOption options[] = {
+ GNUNET_GETOPT_OPTION_END
+ };
+ GNUNET_log_setup ("test-mesh-api",
#if VERBOSE
"DEBUG",
#else
"WARNING",
#endif
NULL);
- ret = GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1,
- argv2, "test-mesh-api", "nohelp",
- options, &run, NULL);
+ ret = GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1,
+ argv2, "test-mesh-api", "nohelp",
+ options, &run, NULL);
- if ( GNUNET_OK != ret ) {
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
- "run failed with error code %d\n", ret);
- return 1;
- }
- if ( GNUNET_SYSERR == result ) {
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
- "test failed\n");
- return 1;
- }
- return 0;
+ if (GNUNET_OK != ret)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "run failed with error code %d\n", ret);
+ return 1;
+ }
+ if (GNUNET_SYSERR == result)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "test failed\n");
+ return 1;
+ }
+ return 0;
}
Modified: gnunet/src/mesh/test_mesh_small.c
===================================================================
--- gnunet/src/mesh/test_mesh_small.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/mesh/test_mesh_small.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -138,38 +138,36 @@
shutdown_callback (void *cls, const char *emsg)
{
if (emsg != NULL)
- {
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n");
#endif
- if (ok == 0)
- ok = 666;
- }
+ if (ok == 0)
+ ok = 666;
+ }
else
- {
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "All peers successfully shut down!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers successfully shut
down!\n");
#endif
- ok = 0;
- }
+ ok = 0;
+ }
}
static void
-shutdown_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
// struct NSEPeer *pos;
#if VERBOSE
- fprintf(stderr, "Ending test.\n");
+ fprintf (stderr, "Ending test.\n");
#endif
if (disconnect_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel(disconnect_task);
- disconnect_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (disconnect_task);
+ disconnect_task = GNUNET_SCHEDULER_NO_TASK;
+ }
// while (NULL != (pos = peer_head))
// {
// if (pos->nse_handle != NULL)
@@ -179,28 +177,27 @@
// }
if (data_file != NULL)
- GNUNET_DISK_file_close(data_file);
+ GNUNET_DISK_file_close (data_file);
GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
}
static void
-connect_mesh_service (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+connect_mesh_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
// struct NSEPeer *current_peer;
unsigned int i;
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connecting to mesh service of peers\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting to mesh service of
peers\n");
#endif
for (i = 0; i < num_peers; i++)
- {
+ {
// if ((connection_limit > 0) && (i % (num_peers / connection_limit) !=
0))
- continue;
+ continue;
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "test_mesh_small: connecting to
mesh service of peer %d\n", i);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "test_mesh_small: connecting to mesh service of peer %d\n", i);
#endif
/* current_peer = GNUNET_malloc(sizeof(struct NSEPeer));
current_peer->daemon = GNUNET_TESTING_daemon_get(pg, i);
@@ -212,13 +209,12 @@
GNUNET_assert(current_peer->nse_handle != NULL);
}
GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, current_peer);*/
- }
+ }
}
static void
-churn_peers (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+churn_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
/**
@@ -228,31 +224,30 @@
* @param success GNUNET_OK if statistics were
* successfully obtained, GNUNET_SYSERR if not.
*/
-static void
+static void
stats_finished_callback (void *cls, int success)
{
struct StatsContext *stats_context = cls;
char *buf;
int buf_len;
- if ( (GNUNET_OK == success) &&
- (data_file != NULL) )
+ if ((GNUNET_OK == success) && (data_file != NULL))
+ {
+ /* Stats lookup successful, write out data */
+ buf = NULL;
+ buf_len = GNUNET_asprintf (&buf,
+ "TOTAL_MESH_BYTES: %u\n",
+ stats_context->total_mesh_bytes);
+ if (buf_len > 0)
{
- /* Stats lookup successful, write out data */
- buf = NULL;
- buf_len = GNUNET_asprintf(&buf,
- "TOTAL_MESH_BYTES: %u\n",
- stats_context->total_mesh_bytes);
- if (buf_len > 0)
- {
- GNUNET_DISK_file_write(data_file, buf, buf_len);
- }
- GNUNET_free_non_null(buf);
+ GNUNET_DISK_file_write (data_file, buf, buf_len);
}
+ GNUNET_free_non_null (buf);
+ }
GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == shutdown_handle);
- shutdown_handle = GNUNET_SCHEDULER_add_now(&shutdown_task, NULL);
- GNUNET_free(stats_context);
+ shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
+ GNUNET_free (stats_context);
}
@@ -267,33 +262,30 @@
* @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
* @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
*/
-static int
+static int
statistics_iterator (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- const char *subsystem,
- const char *name,
- uint64_t value,
- int is_persistent)
+ const struct GNUNET_PeerIdentity *peer,
+ const char *subsystem,
+ const char *name, uint64_t value, int is_persistent)
{
struct StatsContext *stats_context = cls;
+
//
// if ( (0 == strstr(subsystem, "nse")) &&
// (0 == strstr(name, "# flood messages received")) )
- stats_context->total_mesh_bytes += 1; //value;
+ stats_context->total_mesh_bytes += 1; //value;
return GNUNET_OK;
}
static void
-disconnect_mesh_peers (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+disconnect_mesh_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext
*tc)
{
// struct NSEPeer *pos;
char *buf;
struct StatsContext *stats_context;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "disconnecting mesh service of peers\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "disconnecting mesh service of
peers\n");
disconnect_task = GNUNET_SCHEDULER_NO_TASK;
// pos = peer_head;
// while (NULL != (pos = peer_head))
@@ -307,29 +299,26 @@
// GNUNET_free(pos);
// }
- GNUNET_asprintf(&buf,
- "round%llu",
- current_round);
- if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (testing_cfg,
- "test_mesh_small",
- buf,
- &peers_next_round))
- {
- current_round++;
- GNUNET_assert(churn_task == GNUNET_SCHEDULER_NO_TASK);
- churn_task = GNUNET_SCHEDULER_add_now(&churn_peers, NULL);
- }
- else /* No more rounds, let's shut it down! */
- {
- stats_context = GNUNET_malloc(sizeof(struct StatsContext));
- GNUNET_SCHEDULER_cancel(shutdown_handle);
- shutdown_handle = GNUNET_SCHEDULER_NO_TASK;
- GNUNET_TESTING_get_statistics(pg,
- &stats_finished_callback,
- &statistics_iterator,
- stats_context);
- }
- GNUNET_free(buf);
+ GNUNET_asprintf (&buf, "round%llu", current_round);
+ if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (testing_cfg,
+ "test_mesh_small",
+ buf,
+ &peers_next_round))
+ {
+ current_round++;
+ GNUNET_assert (churn_task == GNUNET_SCHEDULER_NO_TASK);
+ churn_task = GNUNET_SCHEDULER_add_now (&churn_peers, NULL);
+ }
+ else /* No more rounds, let's shut it down! */
+ {
+ stats_context = GNUNET_malloc (sizeof (struct StatsContext));
+ GNUNET_SCHEDULER_cancel (shutdown_handle);
+ shutdown_handle = GNUNET_SCHEDULER_NO_TASK;
+ GNUNET_TESTING_get_statistics (pg,
+ &stats_finished_callback,
+ &statistics_iterator, stats_context);
+ }
+ GNUNET_free (buf);
}
@@ -339,12 +328,12 @@
* @param cls unused
* @param emsg NULL on success
*/
-static void
+static void
topology_output_callback (void *cls, const char *emsg)
{
- disconnect_task = GNUNET_SCHEDULER_add_delayed(wait_time,
- &disconnect_mesh_peers, NULL);
- GNUNET_SCHEDULER_add_now(&connect_mesh_service, NULL);
+ disconnect_task = GNUNET_SCHEDULER_add_delayed (wait_time,
+ &disconnect_mesh_peers,
NULL);
+ GNUNET_SCHEDULER_add_now (&connect_mesh_service, NULL);
}
@@ -359,121 +348,108 @@
{
char *temp_output_file;
- if (emsg == NULL) /* Everything is okay! */
- {
- peers_running = peers_next_round;
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Round %llu, churn finished successfully.\n",
- current_round);
- GNUNET_assert(disconnect_task == GNUNET_SCHEDULER_NO_TASK);
- GNUNET_asprintf(&temp_output_file,
- "%s_%llu.dot",
- topology_file,
- current_round);
- GNUNET_TESTING_peergroup_topology_to_file(pg,
- temp_output_file,
- &topology_output_callback,
- NULL);
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
- "Writing topology to file %s\n",
- temp_output_file);
- GNUNET_free(temp_output_file);
- }
+ if (emsg == NULL) /* Everything is okay! */
+ {
+ peers_running = peers_next_round;
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Round %llu, churn finished successfully.\n", current_round);
+ GNUNET_assert (disconnect_task == GNUNET_SCHEDULER_NO_TASK);
+ GNUNET_asprintf (&temp_output_file,
+ "%s_%llu.dot", topology_file, current_round);
+ GNUNET_TESTING_peergroup_topology_to_file (pg,
+ temp_output_file,
+ &topology_output_callback,
NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Writing topology to file %s\n", temp_output_file);
+ GNUNET_free (temp_output_file);
+ }
else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Round %llu, churn FAILED!!\n",
- current_round);
- GNUNET_SCHEDULER_cancel(shutdown_handle);
- shutdown_handle = GNUNET_SCHEDULER_add_now(&shutdown_task, NULL);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Round %llu, churn FAILED!!\n", current_round);
+ GNUNET_SCHEDULER_cancel (shutdown_handle);
+ shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
+ }
}
static void
-churn_peers (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+churn_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
/* peers_running = GNUNET_TESTING_daemons_running(pg); */
churn_task = GNUNET_SCHEDULER_NO_TASK;
if (peers_next_round == peers_running)
- {
- /* Nothing to do... */
- GNUNET_SCHEDULER_add_now(&connect_mesh_service, NULL);
- GNUNET_assert(disconnect_task == GNUNET_SCHEDULER_NO_TASK);
- disconnect_task = GNUNET_SCHEDULER_add_delayed(wait_time,
- &disconnect_mesh_peers,
NULL);
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
- "Round %lu, doing nothing!\n",
- current_round);
- }
+ {
+ /* Nothing to do... */
+ GNUNET_SCHEDULER_add_now (&connect_mesh_service, NULL);
+ GNUNET_assert (disconnect_task == GNUNET_SCHEDULER_NO_TASK);
+ disconnect_task = GNUNET_SCHEDULER_add_delayed (wait_time,
+ &disconnect_mesh_peers,
+ NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Round %lu, doing nothing!\n",
+ current_round);
+ }
else
+ {
+ if (peers_next_round > num_peers)
{
- if (peers_next_round > num_peers)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- "Asked to turn on more peers than we have!!\n");
- GNUNET_SCHEDULER_cancel(shutdown_handle);
- GNUNET_SCHEDULER_add_now(&shutdown_task, NULL);
- }
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Round %llu, turning off %llu peers, turning on %llu
peers!\n",
- current_round,
- (peers_running > peers_next_round)
- ? peers_running - peers_next_round
- : 0,
- (peers_next_round > peers_running)
- ? peers_next_round - peers_running
- : 0);
- GNUNET_TESTING_daemons_churn (pg, "nse",
- (peers_running > peers_next_round)
- ? peers_running - peers_next_round
- : 0,
- (peers_next_round > peers_running)
- ? peers_next_round - peers_running
- : 0,
- wait_time,
- &churn_callback, NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Asked to turn on more peers than we have!!\n");
+ GNUNET_SCHEDULER_cancel (shutdown_handle);
+ GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
}
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Round %llu, turning off %llu peers, turning on %llu peers!\n",
+ current_round,
+ (peers_running > peers_next_round)
+ ? peers_running - peers_next_round
+ : 0,
+ (peers_next_round > peers_running)
+ ? peers_next_round - peers_running : 0);
+ GNUNET_TESTING_daemons_churn (pg, "nse",
+ (peers_running > peers_next_round)
+ ? peers_running - peers_next_round
+ : 0,
+ (peers_next_round > peers_running)
+ ? peers_next_round - peers_running
+ : 0, wait_time, &churn_callback, NULL);
+ }
}
static void
-my_cb (void *cls,
- const char *emsg)
+my_cb (void *cls, const char *emsg)
{
char *buf;
int buf_len;
+
if (emsg != NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peergroup callback called with error, aborting test!\n");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error from testing: `%s'\n");
- ok = 1;
- GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Peergroup callback called with error, aborting test!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error from testing: `%s'\n");
+ ok = 1;
+ GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
+ return;
+ }
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peer Group started successfully!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer Group started successfully!\n");
#endif
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Have %u connections\n",
- total_connections);
+ "Have %u connections\n", total_connections);
if (data_file != NULL)
- {
- buf = NULL;
- buf_len = GNUNET_asprintf(&buf,
- "CONNECTIONS_0: %u\n",
- total_connections);
- if (buf_len > 0)
- GNUNET_DISK_file_write(data_file, buf, buf_len);
- GNUNET_free (buf);
- }
- peers_running = GNUNET_TESTING_daemons_running(pg);
+ {
+ buf = NULL;
+ buf_len = GNUNET_asprintf (&buf, "CONNECTIONS_0: %u\n", total_connections);
+ if (buf_len > 0)
+ GNUNET_DISK_file_write (data_file, buf, buf_len);
+ GNUNET_free (buf);
+ }
+ peers_running = GNUNET_TESTING_daemons_running (pg);
- GNUNET_SCHEDULER_add_now(&connect_mesh_service, NULL);
- disconnect_task = GNUNET_SCHEDULER_add_delayed(wait_time,
&disconnect_mesh_peers, NULL);
+ GNUNET_SCHEDULER_add_now (&connect_mesh_service, NULL);
+ disconnect_task =
+ GNUNET_SCHEDULER_add_delayed (wait_time, &disconnect_mesh_peers, NULL);
}
@@ -492,16 +468,15 @@
* @param second_daemon handle for the second daemon
* @param emsg error message (NULL on success)
*/
-static void
+static void
connect_cb (void *cls,
- const struct GNUNET_PeerIdentity *first,
- const struct GNUNET_PeerIdentity *second,
- uint32_t distance,
- const struct GNUNET_CONFIGURATION_Handle *first_cfg,
- const struct GNUNET_CONFIGURATION_Handle *second_cfg,
- struct GNUNET_TESTING_Daemon *first_daemon,
- struct GNUNET_TESTING_Daemon *second_daemon,
- const char *emsg)
+ const struct GNUNET_PeerIdentity *first,
+ const struct GNUNET_PeerIdentity *second,
+ uint32_t distance,
+ const struct GNUNET_CONFIGURATION_Handle *first_cfg,
+ const struct GNUNET_CONFIGURATION_Handle *second_cfg,
+ struct GNUNET_TESTING_Daemon *first_daemon,
+ struct GNUNET_TESTING_Daemon *second_daemon, const char *emsg)
{
if (emsg == NULL)
total_connections++;
@@ -513,96 +488,95 @@
char *const *args,
const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
- char *temp_str;
- unsigned long long temp_wait;
- struct GNUNET_TESTING_Host *hosts;
+ char *temp_str;
+ unsigned long long temp_wait;
+ struct GNUNET_TESTING_Host *hosts;
ok = 1;
- testing_cfg = (struct GNUNET_CONFIGURATION_Handle *)cfg; //
GNUNET_CONFIGURATION_create();
+ testing_cfg = (struct GNUNET_CONFIGURATION_Handle *) cfg; //
GNUNET_CONFIGURATION_create();
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemons.\n");
GNUNET_CONFIGURATION_set_value_string (testing_cfg,
- "testing",
- "use_progressbars",
- "YES");
+ "testing", "use_progressbars", "YES");
#endif
- if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (testing_cfg,
- "testing",
- "num_peers",
&num_peers))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Option TESTING:NUM_PEERS is
required!\n");
- return;
- }
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (testing_cfg,
+ "testing",
+ "num_peers",
+ &num_peers))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Option TESTING:NUM_PEERS is required!\n");
+ return;
+ }
- if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (testing_cfg,
- "test_mesh_small",
- "wait_time",
- &temp_wait))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- "Option nsetest_mesh_small:wait_time is required!\n");
- return;
- }
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (testing_cfg,
+ "test_mesh_small",
+ "wait_time",
+ &temp_wait))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Option nsetest_mesh_small:wait_time is required!\n");
+ return;
+ }
- if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (testing_cfg,
- "testing",
"topology_output_file",
- &topology_file))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- "Option test_mesh_small:topology_output_file is required!\n");
- return;
- }
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (testing_cfg,
+ "testing",
+
"topology_output_file",
+ &topology_file))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Option test_mesh_small:topology_output_file is required!\n");
+ return;
+ }
- if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (testing_cfg,
- "test_mesh_small",
"data_output_file",
- &data_filename))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- "Option test_mesh_small:data_output_file is required!\n");
- return;
- }
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (testing_cfg,
+ "test_mesh_small",
+ "data_output_file",
+ &data_filename))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Option test_mesh_small:data_output_file is required!\n");
+ return;
+ }
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_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);
- wait_time = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
temp_wait);
+ wait_time =
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_wait);
- if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string(cfg,
- "test_mesh_small",
- "output_file",
- &temp_str))
- {
- output_file = GNUNET_DISK_file_open (temp_str, GNUNET_DISK_OPEN_READWRITE
- |
GNUNET_DISK_OPEN_CREATE,
-
GNUNET_DISK_PERM_USER_READ |
-
GNUNET_DISK_PERM_USER_WRITE);
- if (output_file == NULL)
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
- "Failed to open %s for output!\n",
- temp_str);
- }
- GNUNET_free_non_null(temp_str);
+ if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (cfg,
+ "test_mesh_small",
+ "output_file",
+ &temp_str))
+ {
+ output_file = GNUNET_DISK_file_open (temp_str, GNUNET_DISK_OPEN_READWRITE
+ | GNUNET_DISK_OPEN_CREATE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE);
+ if (output_file == NULL)
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to open %s for output!\n", temp_str);
+ }
+ GNUNET_free_non_null (temp_str);
hosts = GNUNET_TESTING_hosts_load (testing_cfg);
- pg = GNUNET_TESTING_peergroup_start(testing_cfg,
- num_peers,
- TIMEOUT,
- &connect_cb,
- &my_cb, NULL,
- hosts);
+ pg = GNUNET_TESTING_peergroup_start (testing_cfg,
+ num_peers,
+ TIMEOUT,
+ &connect_cb, &my_cb, NULL, hosts);
GNUNET_assert (pg != NULL);
- shutdown_handle = GNUNET_SCHEDULER_add_delayed
(GNUNET_TIME_relative_get_forever(),
- &shutdown_task,
- NULL);
+ shutdown_handle =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_get_forever (),
+ &shutdown_task, NULL);
}
@@ -629,10 +603,9 @@
#endif
NULL);
GNUNET_PROGRAM_run (argc,
- argv, "test_mesh_small",
- gettext_noop ("Test mesh in a small network."),
- options,
- &run, NULL);
+ argv, "test_mesh_small",
+ gettext_noop ("Test mesh in a small network."),
+ options, &run, NULL);
#if REMOVE_DIR
GNUNET_DISK_directory_remove ("/tmp/test_mesh_small");
#endif
Modified: gnunet/src/nat/gnunet-helper-nat-client-windows.c
===================================================================
--- gnunet/src/nat/gnunet-helper-nat-client-windows.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/nat/gnunet-helper-nat-client-windows.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -193,19 +193,14 @@
* @return 1 on success
*/
static int
-inet_pton (int af,
- const char *cp,
- struct in_addr *buf)
+inet_pton (int af, const char *cp, struct in_addr *buf)
{
- buf->s_addr = inet_addr(cp);
+ buf->s_addr = inet_addr (cp);
if (buf->s_addr == INADDR_NONE)
- {
- fprintf(stderr,
- "Error %d handling address %s",
- WSAGetLastError(),
- cp);
- return 0;
- }
+ {
+ fprintf (stderr, "Error %d handling address %s", WSAGetLastError (), cp);
+ return 0;
+ }
return 1;
}
@@ -218,17 +213,16 @@
* @return the CRC 16.
*/
static uint16_t
-calc_checksum(const uint16_t *data,
- unsigned int bytes)
+calc_checksum (const uint16_t * data, unsigned int bytes)
{
uint32_t sum;
unsigned int i;
sum = 0;
- for (i=0;i<bytes/2;i++)
+ for (i = 0; i < bytes / 2; i++)
sum += data[i];
sum = (sum & 0xffff) + (sum >> 16);
- sum = htons(0xffff - sum);
+ sum = htons (0xffff - sum);
return sum;
}
@@ -240,12 +234,11 @@
* @param other target address
*/
static void
-send_icmp_udp (const struct in_addr *my_ip,
- const struct in_addr *other)
+send_icmp_udp (const struct in_addr *my_ip, const struct in_addr *other)
{
- char packet[sizeof(struct ip_header) * 2 +
- sizeof(struct icmp_ttl_exceeded_header) +
- sizeof(struct udp_header)];
+ char packet[sizeof (struct ip_header) * 2 +
+ sizeof (struct icmp_ttl_exceeded_header) +
+ sizeof (struct udp_header)];
struct ip_header ip_pkt;
struct icmp_ttl_exceeded_header icmp_pkt;
struct udp_header udp_pkt;
@@ -257,86 +250,74 @@
off = 0;
ip_pkt.vers_ihl = 0x45;
ip_pkt.tos = 0;
- ip_pkt.pkt_len = htons(sizeof (packet));
- ip_pkt.id = htons(256);
+ ip_pkt.pkt_len = htons (sizeof (packet));
+ ip_pkt.id = htons (256);
ip_pkt.flags_frag_offset = 0;
ip_pkt.ttl = 128;
ip_pkt.proto = IPPROTO_ICMP;
ip_pkt.checksum = 0;
ip_pkt.src_ip = my_ip->s_addr;
ip_pkt.dst_ip = other->s_addr;
- ip_pkt.checksum = htons(calc_checksum((uint16_t*)&ip_pkt,
- sizeof (struct ip_header)));
- memcpy(&packet[off],
- &ip_pkt,
- sizeof(struct ip_header));
- off += sizeof(struct ip_header);
+ ip_pkt.checksum = htons (calc_checksum ((uint16_t *) & ip_pkt,
+ sizeof (struct ip_header)));
+ memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header));
+ off += sizeof (struct ip_header);
icmp_pkt.type = ICMP_TIME_EXCEEDED;
icmp_pkt.code = 0;
icmp_pkt.checksum = 0;
icmp_pkt.unused = 0;
- memcpy(&packet[off],
- &icmp_pkt,
- sizeof(struct icmp_ttl_exceeded_header));
- off += sizeof(struct icmp_ttl_exceeded_header);
+ memcpy (&packet[off], &icmp_pkt, sizeof (struct icmp_ttl_exceeded_header));
+ off += sizeof (struct icmp_ttl_exceeded_header);
/* ip header of the presumably 'lost' udp packet */
ip_pkt.vers_ihl = 0x45;
ip_pkt.tos = 0;
- ip_pkt.pkt_len = htons(sizeof (struct ip_header) +
- sizeof (struct udp_header));
- ip_pkt.id = htons(0);
+ ip_pkt.pkt_len = htons (sizeof (struct ip_header) +
+ sizeof (struct udp_header));
+ ip_pkt.id = htons (0);
ip_pkt.flags_frag_offset = 0;
ip_pkt.ttl = 128;
ip_pkt.proto = IPPROTO_UDP;
ip_pkt.checksum = 0;
ip_pkt.src_ip = other->s_addr;
ip_pkt.dst_ip = dummy.s_addr;
- ip_pkt.checksum = htons(calc_checksum((uint16_t*)&ip_pkt,
- sizeof (struct ip_header)));
- memcpy(&packet[off],
- &ip_pkt,
- sizeof(struct ip_header));
- off += sizeof(struct ip_header);
+ ip_pkt.checksum = htons (calc_checksum ((uint16_t *) & ip_pkt,
+ sizeof (struct ip_header)));
+ memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header));
+ off += sizeof (struct ip_header);
/* build UDP header */
- udp_pkt.src_port = htons(NAT_TRAV_PORT);
- udp_pkt.dst_port = htons(NAT_TRAV_PORT);
+ udp_pkt.src_port = htons (NAT_TRAV_PORT);
+ udp_pkt.dst_port = htons (NAT_TRAV_PORT);
udp_pkt.length = htons (port);
udp_pkt.crc = 0;
- memcpy(&packet[off],
- &udp_pkt,
- sizeof(struct udp_header));
- off += sizeof(struct udp_header);
+ memcpy (&packet[off], &udp_pkt, sizeof (struct udp_header));
+ off += sizeof (struct udp_header);
/* no go back to calculate ICMP packet checksum */
- icmp_pkt.checksum = htons(calc_checksum((uint16_t*)&packet[off],
- sizeof (struct
icmp_ttl_exceeded_header) +
- sizeof (struct ip_header) +
- sizeof (struct udp_header)));
- memcpy (&packet[sizeof (struct ip_header)],
- &icmp_pkt,
- sizeof (struct icmp_ttl_exceeded_header));
+ icmp_pkt.checksum = htons (calc_checksum ((uint16_t *) & packet[off],
+ sizeof (struct
+ icmp_ttl_exceeded_header) +
+ sizeof (struct ip_header) +
+ sizeof (struct udp_header)));
+ memcpy (&packet[sizeof (struct ip_header)], &icmp_pkt,
+ sizeof (struct icmp_ttl_exceeded_header));
memset (&dst, 0, sizeof (dst));
dst.sin_family = AF_INET;
dst.sin_addr = *other;
- err = sendto(rawsock,
- packet,
- sizeof (packet), 0,
- (struct sockaddr*)&dst,
- sizeof(dst));
+ err = sendto (rawsock,
+ packet,
+ sizeof (packet), 0, (struct sockaddr *) &dst, sizeof (dst));
if (err < 0)
- {
- fprintf(stderr,
- "sendto failed: %s\n", strerror(errno));
- }
+ {
+ fprintf (stderr, "sendto failed: %s\n", strerror (errno));
+ }
else if (sizeof (packet) != (size_t) err)
- {
- fprintf(stderr,
- "Error: partial send of ICMP message\n");
- }
+ {
+ fprintf (stderr, "Error: partial send of ICMP message\n");
+ }
}
@@ -347,16 +328,15 @@
* @param other target address
*/
static void
-send_icmp (const struct in_addr *my_ip,
- const struct in_addr *other)
+send_icmp (const struct in_addr *my_ip, const struct in_addr *other)
{
struct ip_header ip_pkt;
struct icmp_ttl_exceeded_header icmp_ttl;
struct icmp_echo_header icmp_echo;
struct sockaddr_in dst;
char packet[sizeof (struct ip_header) * 2 +
- sizeof (struct icmp_ttl_exceeded_header) +
- sizeof(struct icmp_echo_header)];
+ sizeof (struct icmp_ttl_exceeded_header) +
+ sizeof (struct icmp_echo_header)];
size_t off;
int err;
@@ -365,88 +345,76 @@
ip_pkt.vers_ihl = 0x45;
ip_pkt.tos = 0;
ip_pkt.pkt_len = htons (sizeof (packet));
- ip_pkt.id = htons(256);
+ ip_pkt.id = htons (256);
ip_pkt.flags_frag_offset = 0;
ip_pkt.ttl = IPDEFTTL;
ip_pkt.proto = IPPROTO_ICMP;
ip_pkt.checksum = 0;
ip_pkt.src_ip = my_ip->s_addr;
ip_pkt.dst_ip = other->s_addr;
- ip_pkt.checksum = htons(calc_checksum((uint16_t*)&ip_pkt,
- sizeof (struct ip_header)));
- memcpy (&packet[off],
- &ip_pkt,
- sizeof (struct ip_header));
+ ip_pkt.checksum = htons (calc_checksum ((uint16_t *) & ip_pkt,
+ sizeof (struct ip_header)));
+ memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header));
off += sizeof (ip_pkt);
/* icmp reply: time exceeded */
icmp_ttl.type = ICMP_TIME_EXCEEDED;
icmp_ttl.code = 0;
icmp_ttl.checksum = 0;
- icmp_ttl.unused = 0;
- memcpy (&packet[off],
- &icmp_ttl,
- sizeof (struct icmp_ttl_exceeded_header));
+ icmp_ttl.unused = 0;
+ memcpy (&packet[off], &icmp_ttl, sizeof (struct icmp_ttl_exceeded_header));
off += sizeof (struct icmp_ttl_exceeded_header);
/* ip header of the presumably 'lost' udp packet */
ip_pkt.vers_ihl = 0x45;
ip_pkt.tos = 0;
- ip_pkt.pkt_len = htons(sizeof (struct ip_header) + sizeof (struct
icmp_echo_header));
+ ip_pkt.pkt_len =
+ htons (sizeof (struct ip_header) + sizeof (struct icmp_echo_header));
ip_pkt.id = htons (256);
ip_pkt.flags_frag_offset = 0;
- ip_pkt.ttl = 1; /* real TTL would be 1 on a time exceeded packet */
+ ip_pkt.ttl = 1; /* real TTL would be 1 on a time exceeded
packet */
ip_pkt.proto = IPPROTO_ICMP;
ip_pkt.src_ip = other->s_addr;
ip_pkt.dst_ip = dummy.s_addr;
ip_pkt.checksum = 0;
- ip_pkt.checksum = htons(calc_checksum((uint16_t*)&ip_pkt,
- sizeof (struct ip_header)));
- memcpy (&packet[off],
- &ip_pkt,
- sizeof (struct ip_header));
+ ip_pkt.checksum = htons (calc_checksum ((uint16_t *) & ip_pkt,
+ sizeof (struct ip_header)));
+ memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header));
off += sizeof (struct ip_header);
icmp_echo.type = ICMP_ECHO;
icmp_echo.code = 0;
- icmp_echo.reserved = htonl(port);
+ icmp_echo.reserved = htonl (port);
icmp_echo.checksum = 0;
- icmp_echo.checksum = htons(calc_checksum((uint16_t*) &icmp_echo,
- sizeof (struct icmp_echo_header)));
- memcpy (&packet[off],
- &icmp_echo,
- sizeof(struct icmp_echo_header));
+ icmp_echo.checksum = htons (calc_checksum ((uint16_t *) & icmp_echo,
+ sizeof (struct
icmp_echo_header)));
+ memcpy (&packet[off], &icmp_echo, sizeof (struct icmp_echo_header));
/* no go back to calculate ICMP packet checksum */
off = sizeof (struct ip_header);
- icmp_ttl.checksum = htons(calc_checksum((uint16_t*) &packet[off],
- sizeof (struct
icmp_ttl_exceeded_header) +
- sizeof (struct ip_header) +
- sizeof (struct icmp_echo_header)));
- memcpy (&packet[off],
- &icmp_ttl,
- sizeof (struct icmp_ttl_exceeded_header));
+ icmp_ttl.checksum = htons (calc_checksum ((uint16_t *) & packet[off],
+ sizeof (struct
+ icmp_ttl_exceeded_header) +
+ sizeof (struct ip_header) +
+ sizeof (struct icmp_echo_header)));
+ memcpy (&packet[off], &icmp_ttl, sizeof (struct icmp_ttl_exceeded_header));
memset (&dst, 0, sizeof (dst));
dst.sin_family = AF_INET;
dst.sin_addr = *other;
- err = sendto(rawsock,
- packet,
- sizeof (packet), 0,
- (struct sockaddr*)&dst,
- sizeof(dst));
+ err = sendto (rawsock,
+ packet,
+ sizeof (packet), 0, (struct sockaddr *) &dst, sizeof (dst));
if (err < 0)
- {
- fprintf(stderr,
- "sendto failed: %s\n", strerror(errno));
- }
+ {
+ fprintf (stderr, "sendto failed: %s\n", strerror (errno));
+ }
else if (sizeof (packet) != (size_t) err)
- {
- fprintf(stderr,
- "Error: partial send of ICMP message\n");
- }
+ {
+ fprintf (stderr, "Error: partial send of ICMP message\n");
+ }
}
@@ -459,34 +427,30 @@
make_raw_socket ()
{
DWORD bOptVal = TRUE;
- int bOptLen = sizeof(bOptVal);
+ int bOptLen = sizeof (bOptVal);
SOCKET ret;
ret = socket (AF_INET, SOCK_RAW, IPPROTO_RAW);
if (INVALID_SOCKET == ret)
- {
- fprintf (stderr,
- "Error opening RAW socket: %s\n",
- strerror (errno));
- return INVALID_SOCKET;
- }
- if (0 != setsockopt(ret, SOL_SOCKET, SO_BROADCAST, (char*)&bOptVal, bOptLen))
- {
- fprintf(stderr,
- "Error setting SO_BROADCAST to ON: %s\n",
- strerror (errno));
- closesocket(rawsock);
- return INVALID_SOCKET;
- }
+ {
+ fprintf (stderr, "Error opening RAW socket: %s\n", strerror (errno));
+ return INVALID_SOCKET;
+ }
+ if (0 !=
+ setsockopt (ret, SOL_SOCKET, SO_BROADCAST, (char *) &bOptVal, bOptLen))
+ {
+ fprintf (stderr,
+ "Error setting SO_BROADCAST to ON: %s\n", strerror (errno));
+ closesocket (rawsock);
+ return INVALID_SOCKET;
+ }
- if (0 != setsockopt(ret, IPPROTO_IP, IP_HDRINCL, (char*)&bOptVal, bOptLen))
- {
- fprintf(stderr,
- "Error setting IP_HDRINCL to ON: %s\n",
- strerror (errno));
- closesocket(rawsock);
- return INVALID_SOCKET;
- }
+ if (0 != setsockopt (ret, IPPROTO_IP, IP_HDRINCL, (char *) &bOptVal,
bOptLen))
+ {
+ fprintf (stderr, "Error setting IP_HDRINCL to ON: %s\n", strerror (errno));
+ closesocket (rawsock);
+ return INVALID_SOCKET;
+ }
return ret;
}
@@ -501,47 +465,38 @@
unsigned int p;
if (argc != 4)
- {
- fprintf (stderr,
- "This program must be started with our IP, the targets external
IP, and our port as arguments.\n");
- return 1;
- }
- if ( (1 != inet_pton (AF_INET, argv[1], &external)) ||
- (1 != inet_pton (AF_INET, argv[2], &target)) )
- {
- fprintf (stderr,
- "Error parsing IPv4 address: %s\n",
- strerror (errno));
- return 1;
- }
- if ( (1 != sscanf (argv[3], "%u", &p) ) ||
- (0 == p) ||
- (0xFFFF < p) )
- {
- fprintf (stderr,
- "Error parsing port value `%s'\n",
- argv[3]);
- return 1;
- }
+ {
+ fprintf (stderr,
+ "This program must be started with our IP, the targets external
IP, and our port as arguments.\n");
+ return 1;
+ }
+ if ((1 != inet_pton (AF_INET, argv[1], &external)) ||
+ (1 != inet_pton (AF_INET, argv[2], &target)))
+ {
+ fprintf (stderr, "Error parsing IPv4 address: %s\n", strerror (errno));
+ return 1;
+ }
+ if ((1 != sscanf (argv[3], "%u", &p)) || (0 == p) || (0xFFFF < p))
+ {
+ fprintf (stderr, "Error parsing port value `%s'\n", argv[3]);
+ return 1;
+ }
port = (uint16_t) p;
if (0 != WSAStartup (MAKEWORD (2, 1), &wsaData))
- {
- fprintf (stderr, "Failed to find Winsock 2.1 or better.\n");
- return 2;
- }
+ {
+ fprintf (stderr, "Failed to find Winsock 2.1 or better.\n");
+ return 2;
+ }
if (1 != inet_pton (AF_INET, DUMMY_IP, &dummy))
- {
- fprintf (stderr,
- "Internal error converting dummy IP to binary.\n");
- return 2;
- }
- if (-1 == (rawsock = make_raw_socket()))
+ {
+ fprintf (stderr, "Internal error converting dummy IP to binary.\n");
+ return 2;
+ }
+ if (-1 == (rawsock = make_raw_socket ()))
return 3;
- send_icmp (&external,
- &target);
- send_icmp_udp (&external,
- &target);
+ send_icmp (&external, &target);
+ send_icmp_udp (&external, &target);
closesocket (rawsock);
WSACleanup ();
return 0;
Modified: gnunet/src/nat/gnunet-helper-nat-client.c
===================================================================
--- gnunet/src/nat/gnunet-helper-nat-client.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/nat/gnunet-helper-nat-client.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -190,17 +190,16 @@
* @return the CRC 16.
*/
static uint16_t
-calc_checksum (const uint16_t *data,
- unsigned int bytes)
+calc_checksum (const uint16_t * data, unsigned int bytes)
{
uint32_t sum;
unsigned int i;
sum = 0;
- for (i=0;i<bytes/2;i++)
+ for (i = 0; i < bytes / 2; i++)
sum += data[i];
sum = (sum & 0xffff) + (sum >> 16);
- sum = htons(0xffff - sum);
+ sum = htons (0xffff - sum);
return sum;
}
@@ -212,12 +211,11 @@
* @param other target address
*/
static void
-send_icmp_udp (const struct in_addr *my_ip,
- const struct in_addr *other)
+send_icmp_udp (const struct in_addr *my_ip, const struct in_addr *other)
{
- char packet[sizeof(struct ip_header) * 2 +
- sizeof(struct icmp_ttl_exceeded_header) +
- sizeof(struct udp_header)];
+ char packet[sizeof (struct ip_header) * 2 +
+ sizeof (struct icmp_ttl_exceeded_header) +
+ sizeof (struct udp_header)];
struct ip_header ip_pkt;
struct icmp_ttl_exceeded_header icmp_pkt;
struct udp_header udp_pkt;
@@ -230,66 +228,58 @@
ip_pkt.vers_ihl = 0x45;
ip_pkt.tos = 0;
ip_pkt.pkt_len = htons (sizeof (packet));
- ip_pkt.id = htons(256);
+ ip_pkt.id = htons (256);
ip_pkt.flags_frag_offset = 0;
ip_pkt.ttl = 128;
ip_pkt.proto = IPPROTO_ICMP;
ip_pkt.checksum = 0;
ip_pkt.src_ip = my_ip->s_addr;
ip_pkt.dst_ip = other->s_addr;
- ip_pkt.checksum = htons(calc_checksum((uint16_t*)&ip_pkt,
- sizeof (struct ip_header)));
- memcpy(&packet[off],
- &ip_pkt,
- sizeof(struct ip_header));
- off += sizeof(struct ip_header);
+ ip_pkt.checksum = htons (calc_checksum ((uint16_t *) & ip_pkt,
+ sizeof (struct ip_header)));
+ memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header));
+ off += sizeof (struct ip_header);
icmp_pkt.type = ICMP_TIME_EXCEEDED;
icmp_pkt.code = 0;
icmp_pkt.checksum = 0;
icmp_pkt.unused = 0;
- memcpy(&packet[off],
- &icmp_pkt,
- sizeof(struct icmp_ttl_exceeded_header));
- off += sizeof(struct icmp_ttl_exceeded_header);
+ memcpy (&packet[off], &icmp_pkt, sizeof (struct icmp_ttl_exceeded_header));
+ off += sizeof (struct icmp_ttl_exceeded_header);
/* ip header of the presumably 'lost' udp packet */
ip_pkt.vers_ihl = 0x45;
ip_pkt.tos = 0;
- ip_pkt.pkt_len = htons(sizeof (struct ip_header) +
- sizeof (struct udp_header));
- ip_pkt.id = htons(0);
+ ip_pkt.pkt_len = htons (sizeof (struct ip_header) +
+ sizeof (struct udp_header));
+ ip_pkt.id = htons (0);
ip_pkt.flags_frag_offset = 0;
ip_pkt.ttl = 128;
ip_pkt.proto = IPPROTO_UDP;
ip_pkt.checksum = 0;
ip_pkt.src_ip = other->s_addr;
ip_pkt.dst_ip = dummy.s_addr;
- ip_pkt.checksum = htons(calc_checksum((uint16_t*)&ip_pkt,
- sizeof (struct ip_header)));
- memcpy(&packet[off],
- &ip_pkt,
- sizeof(struct ip_header));
- off += sizeof(struct ip_header);
+ ip_pkt.checksum = htons (calc_checksum ((uint16_t *) & ip_pkt,
+ sizeof (struct ip_header)));
+ memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header));
+ off += sizeof (struct ip_header);
/* build UDP header */
- udp_pkt.src_port = htons(NAT_TRAV_PORT);
- udp_pkt.dst_port = htons(NAT_TRAV_PORT);
+ udp_pkt.src_port = htons (NAT_TRAV_PORT);
+ udp_pkt.dst_port = htons (NAT_TRAV_PORT);
udp_pkt.length = htons (port);
udp_pkt.crc = 0;
- memcpy(&packet[off],
- &udp_pkt,
- sizeof(struct udp_header));
- off += sizeof(struct udp_header);
+ memcpy (&packet[off], &udp_pkt, sizeof (struct udp_header));
+ off += sizeof (struct udp_header);
/* set ICMP checksum */
- icmp_pkt.checksum = htons(calc_checksum((uint16_t*)&packet[sizeof(struct
ip_header)],
- sizeof (struct
icmp_ttl_exceeded_header) +
- sizeof (struct ip_header) +
- sizeof (struct udp_header)));
- memcpy (&packet[sizeof(struct ip_header)],
- &icmp_pkt,
- sizeof (struct icmp_ttl_exceeded_header));
+ icmp_pkt.checksum =
+ htons (calc_checksum
+ ((uint16_t *) & packet[sizeof (struct ip_header)],
+ sizeof (struct icmp_ttl_exceeded_header) +
+ sizeof (struct ip_header) + sizeof (struct udp_header)));
+ memcpy (&packet[sizeof (struct ip_header)], &icmp_pkt,
+ sizeof (struct icmp_ttl_exceeded_header));
memset (&dst, 0, sizeof (dst));
dst.sin_family = AF_INET;
@@ -297,21 +287,17 @@
dst.sin_len = sizeof (struct sockaddr_in);
#endif
dst.sin_addr = *other;
- err = sendto(rawsock,
- packet,
- sizeof (packet), 0,
- (struct sockaddr*)&dst,
- sizeof(dst));
+ err = sendto (rawsock,
+ packet,
+ sizeof (packet), 0, (struct sockaddr *) &dst, sizeof (dst));
if (err < 0)
- {
- fprintf(stderr,
- "sendto failed: %s\n", strerror(errno));
- }
+ {
+ fprintf (stderr, "sendto failed: %s\n", strerror (errno));
+ }
else if (sizeof (packet) != (size_t) err)
- {
- fprintf(stderr,
- "Error: partial send of ICMP message\n");
- }
+ {
+ fprintf (stderr, "Error: partial send of ICMP message\n");
+ }
}
@@ -322,16 +308,15 @@
* @param other target address
*/
static void
-send_icmp (const struct in_addr *my_ip,
- const struct in_addr *other)
+send_icmp (const struct in_addr *my_ip, const struct in_addr *other)
{
struct ip_header ip_pkt;
struct icmp_ttl_exceeded_header icmp_ttl;
struct icmp_echo_header icmp_echo;
struct sockaddr_in dst;
char packet[sizeof (struct ip_header) * 2 +
- sizeof (struct icmp_ttl_exceeded_header) +
- sizeof (struct icmp_echo_header)];
+ sizeof (struct icmp_ttl_exceeded_header) +
+ sizeof (struct icmp_echo_header)];
size_t off;
int err;
@@ -347,11 +332,9 @@
ip_pkt.checksum = 0;
ip_pkt.src_ip = my_ip->s_addr;
ip_pkt.dst_ip = other->s_addr;
- ip_pkt.checksum = htons(calc_checksum((uint16_t*)&ip_pkt,
- sizeof (struct ip_header)));
- memcpy (&packet[off],
- &ip_pkt,
- sizeof (struct ip_header));
+ ip_pkt.checksum = htons (calc_checksum ((uint16_t *) & ip_pkt,
+ sizeof (struct ip_header)));
+ memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header));
off = sizeof (ip_pkt);
/* icmp reply: time exceeded */
@@ -359,48 +342,42 @@
icmp_ttl.code = 0;
icmp_ttl.checksum = 0;
icmp_ttl.unused = 0;
- memcpy (&packet[off],
- &icmp_ttl,
- sizeof (struct icmp_ttl_exceeded_header));
+ memcpy (&packet[off], &icmp_ttl, sizeof (struct icmp_ttl_exceeded_header));
off += sizeof (struct icmp_ttl_exceeded_header);
/* ip header of the presumably 'lost' udp packet */
ip_pkt.vers_ihl = 0x45;
ip_pkt.tos = 0;
- ip_pkt.pkt_len = htons (sizeof (struct ip_header) + sizeof (struct
icmp_echo_header));
+ ip_pkt.pkt_len =
+ htons (sizeof (struct ip_header) + sizeof (struct icmp_echo_header));
ip_pkt.id = htons (256);
ip_pkt.flags_frag_offset = 0;
- ip_pkt.ttl = 1; /* real TTL would be 1 on a time exceeded packet */
+ ip_pkt.ttl = 1; /* real TTL would be 1 on a time exceeded
packet */
ip_pkt.proto = IPPROTO_ICMP;
ip_pkt.src_ip = other->s_addr;
ip_pkt.dst_ip = dummy.s_addr;
ip_pkt.checksum = 0;
- ip_pkt.checksum = htons(calc_checksum((uint16_t*)&ip_pkt,
- sizeof (struct ip_header)));
- memcpy (&packet[off],
- &ip_pkt,
- sizeof (struct ip_header));
+ ip_pkt.checksum = htons (calc_checksum ((uint16_t *) & ip_pkt,
+ sizeof (struct ip_header)));
+ memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header));
off += sizeof (struct ip_header);
icmp_echo.type = ICMP_ECHO;
icmp_echo.code = 0;
icmp_echo.reserved = htonl (port);
icmp_echo.checksum = 0;
- icmp_echo.checksum = htons(calc_checksum((uint16_t*) &icmp_echo,
- sizeof (struct icmp_echo_header)));
- memcpy (&packet[off],
- &icmp_echo,
- sizeof(struct icmp_echo_header));
+ icmp_echo.checksum = htons (calc_checksum ((uint16_t *) & icmp_echo,
+ sizeof (struct
icmp_echo_header)));
+ memcpy (&packet[off], &icmp_echo, sizeof (struct icmp_echo_header));
/* no go back to calculate ICMP packet checksum */
off = sizeof (struct ip_header);
- icmp_ttl.checksum = htons(calc_checksum((uint16_t*) &packet[off],
- sizeof (struct
icmp_ttl_exceeded_header) +
- sizeof (struct ip_header) +
- sizeof (struct icmp_echo_header)));
- memcpy (&packet[off],
- &icmp_ttl,
- sizeof (struct icmp_ttl_exceeded_header));
+ icmp_ttl.checksum = htons (calc_checksum ((uint16_t *) & packet[off],
+ sizeof (struct
+ icmp_ttl_exceeded_header) +
+ sizeof (struct ip_header) +
+ sizeof (struct icmp_echo_header)));
+ memcpy (&packet[off], &icmp_ttl, sizeof (struct icmp_ttl_exceeded_header));
/* prepare for transmission */
memset (&dst, 0, sizeof (dst));
@@ -409,21 +386,17 @@
dst.sin_len = sizeof (struct sockaddr_in);
#endif
dst.sin_addr = *other;
- err = sendto(rawsock,
- packet,
- sizeof (packet), 0,
- (struct sockaddr*)&dst,
- sizeof(dst));
+ err = sendto (rawsock,
+ packet,
+ sizeof (packet), 0, (struct sockaddr *) &dst, sizeof (dst));
if (err < 0)
- {
- fprintf(stderr,
- "sendto failed: %s\n", strerror(errno));
- }
+ {
+ fprintf (stderr, "sendto failed: %s\n", strerror (errno));
+ }
else if (sizeof (packet) != (size_t) err)
- {
- fprintf(stderr,
- "Error: partial send of ICMP message\n");
- }
+ {
+ fprintf (stderr, "Error: partial send of ICMP message\n");
+ }
}
@@ -440,30 +413,24 @@
ret = socket (AF_INET, SOCK_RAW, IPPROTO_RAW);
if (-1 == ret)
- {
- fprintf (stderr,
- "Error opening RAW socket: %s\n",
- strerror (errno));
- return -1;
- }
- if (0 != setsockopt(ret, SOL_SOCKET, SO_BROADCAST,
- (char *)&one, sizeof(one)))
- {
- fprintf(stderr,
- "setsockopt failed: %s\n",
- strerror (errno));
- close (ret);
- return -1;
- }
- if (0 != setsockopt(ret, IPPROTO_IP, IP_HDRINCL,
- (char *)&one, sizeof(one)))
- {
- fprintf(stderr,
- "setsockopt failed: %s\n",
- strerror (errno));
- close (ret);
- return -1;
- }
+ {
+ fprintf (stderr, "Error opening RAW socket: %s\n", strerror (errno));
+ return -1;
+ }
+ if (0 != setsockopt (ret, SOL_SOCKET, SO_BROADCAST,
+ (char *) &one, sizeof (one)))
+ {
+ fprintf (stderr, "setsockopt failed: %s\n", strerror (errno));
+ close (ret);
+ return -1;
+ }
+ if (0 != setsockopt (ret, IPPROTO_IP, IP_HDRINCL,
+ (char *) &one, sizeof (one)))
+ {
+ fprintf (stderr, "setsockopt failed: %s\n", strerror (errno));
+ close (ret);
+ return -1;
+ }
return ret;
}
@@ -477,49 +444,38 @@
unsigned int p;
if (4 != argc)
- {
- fprintf (stderr,
- "This program must be started with our IP, the targets external
IP, and our port as arguments.\n");
- return 1;
- }
- if ( (1 != inet_pton (AF_INET, argv[1], &external)) ||
- (1 != inet_pton (AF_INET, argv[2], &target)) )
- {
- fprintf (stderr,
- "Error parsing IPv4 address: %s\n",
- strerror (errno));
- return 1;
- }
- if ( (1 != sscanf (argv[3], "%u", &p) ) ||
- (0 == p) ||
- (0xFFFF < p) )
- {
- fprintf (stderr,
- "Error parsing port value `%s'\n",
- argv[3]);
- return 1;
- }
+ {
+ fprintf (stderr,
+ "This program must be started with our IP, the targets external
IP, and our port as arguments.\n");
+ return 1;
+ }
+ if ((1 != inet_pton (AF_INET, argv[1], &external)) ||
+ (1 != inet_pton (AF_INET, argv[2], &target)))
+ {
+ fprintf (stderr, "Error parsing IPv4 address: %s\n", strerror (errno));
+ return 1;
+ }
+ if ((1 != sscanf (argv[3], "%u", &p)) || (0 == p) || (0xFFFF < p))
+ {
+ fprintf (stderr, "Error parsing port value `%s'\n", argv[3]);
+ return 1;
+ }
port = (uint16_t) p;
if (1 != inet_pton (AF_INET, DUMMY_IP, &dummy))
- {
- fprintf (stderr,
- "Internal error converting dummy IP to binary.\n");
- return 2;
- }
- if (-1 == (rawsock = make_raw_socket()))
+ {
+ fprintf (stderr, "Internal error converting dummy IP to binary.\n");
return 2;
+ }
+ if (-1 == (rawsock = make_raw_socket ()))
+ return 2;
uid = getuid ();
if (0 != setresuid (uid, uid, uid))
- {
- fprintf (stderr,
- "Failed to setresuid: %s\n",
- strerror (errno));
- /* not critical, continue anyway */
- }
- send_icmp (&external,
- &target);
- send_icmp_udp (&external,
- &target);
+ {
+ fprintf (stderr, "Failed to setresuid: %s\n", strerror (errno));
+ /* not critical, continue anyway */
+ }
+ send_icmp (&external, &target);
+ send_icmp_udp (&external, &target);
close (rawsock);
return 0;
}
Modified: gnunet/src/nat/gnunet-helper-nat-server-windows.c
===================================================================
--- gnunet/src/nat/gnunet-helper-nat-server-windows.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/nat/gnunet-helper-nat-server-windows.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -118,12 +118,12 @@
/**
* Time to live
*/
- uint8_t ttl;
+ uint8_t ttl;
/**
* Protocol
*/
- uint8_t proto;
+ uint8_t proto;
/**
* Header checksum
@@ -133,12 +133,12 @@
/**
* Source address
*/
- uint32_t src_ip;
+ uint32_t src_ip;
/**
* Destination address
*/
- uint32_t dst_ip;
+ uint32_t dst_ip;
};
/**
@@ -211,17 +211,16 @@
* @return the CRC 16.
*/
static uint16_t
-calc_checksum(const uint16_t *data,
- unsigned int bytes)
+calc_checksum (const uint16_t * data, unsigned int bytes)
{
uint32_t sum;
unsigned int i;
sum = 0;
- for (i=0;i<bytes/2;i++)
+ for (i = 0; i < bytes / 2; i++)
sum += data[i];
sum = (sum & 0xffff) + (sum >> 16);
- sum = htons(0xffff - sum);
+ sum = htons (0xffff - sum);
return sum;
}
@@ -235,19 +234,14 @@
* @return 1 on success
*/
static int
-inet_pton (int af,
- const char *cp,
- struct in_addr *buf)
+inet_pton (int af, const char *cp, struct in_addr *buf)
{
- buf->s_addr = inet_addr(cp);
+ buf->s_addr = inet_addr (cp);
if (buf->s_addr == INADDR_NONE)
- {
- fprintf(stderr,
- "Error %d handling address %s",
- WSAGetLastError(),
- cp);
- return 0;
- }
+ {
+ fprintf (stderr, "Error %d handling address %s", WSAGetLastError (), cp);
+ return 0;
+ }
return 1;
}
@@ -278,43 +272,35 @@
ip_pkt.checksum = 0;
ip_pkt.src_ip = my_ip->s_addr;
ip_pkt.dst_ip = dummy.s_addr;
- ip_pkt.checksum = htons(calc_checksum((uint16_t*)&ip_pkt,
- sizeof (struct ip_header)));
- memcpy (&packet[off],
- &ip_pkt,
- sizeof (struct ip_header));
+ ip_pkt.checksum = htons (calc_checksum ((uint16_t *) & ip_pkt,
+ sizeof (struct ip_header)));
+ memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header));
off += sizeof (struct ip_header);
icmp_echo.type = ICMP_ECHO;
icmp_echo.code = 0;
icmp_echo.reserved = 0;
icmp_echo.checksum = 0;
- icmp_echo.checksum = htons(calc_checksum((uint16_t*) &icmp_echo,
- sizeof (struct icmp_echo_header)));
- memcpy (&packet[off],
- &icmp_echo,
- sizeof (struct icmp_echo_header));
+ icmp_echo.checksum = htons (calc_checksum ((uint16_t *) & icmp_echo,
+ sizeof (struct
icmp_echo_header)));
+ memcpy (&packet[off], &icmp_echo, sizeof (struct icmp_echo_header));
off += sizeof (struct icmp_echo_header);
memset (&dst, 0, sizeof (dst));
dst.sin_family = AF_INET;
dst.sin_addr = dummy;
- err = sendto(rawsock,
- packet, off, 0,
- (struct sockaddr*)&dst,
- sizeof(dst));
+ err = sendto (rawsock,
+ packet, off, 0, (struct sockaddr *) &dst, sizeof (dst));
if (err < 0)
- {
+ {
#if VERBOSE
- fprintf(stderr,
- "sendto failed: %s\n", strerror(errno));
+ fprintf (stderr, "sendto failed: %s\n", strerror (errno));
#endif
- }
+ }
else if (err != off)
- {
- fprintf(stderr,
- "Error: partial send of ICMP message\n");
- }
+ {
+ fprintf (stderr, "Error: partial send of ICMP message\n");
+ }
}
@@ -331,22 +317,17 @@
dst.sin_family = AF_INET;
dst.sin_addr = dummy;
dst.sin_port = htons (NAT_TRAV_PORT);
- err = sendto(udpsock,
- NULL, 0, 0,
- (struct sockaddr*)&dst,
- sizeof(dst));
+ err = sendto (udpsock, NULL, 0, 0, (struct sockaddr *) &dst, sizeof (dst));
if (err < 0)
- {
+ {
#if VERBOSE
- fprintf(stderr,
- "sendto failed: %s\n", strerror(errno));
+ fprintf (stderr, "sendto failed: %s\n", strerror (errno));
#endif
- }
+ }
else if (0 != err)
- {
- fprintf(stderr,
- "Error: partial send of ICMP message\n");
- }
+ {
+ fprintf (stderr, "Error: partial send of ICMP message\n");
+ }
}
@@ -369,96 +350,74 @@
have = read (icmpsock, buf, sizeof (buf));
if (have == -1)
- {
- fprintf (stderr,
- "Error reading raw socket: %s\n",
- strerror (errno));
- return;
- }
+ {
+ fprintf (stderr, "Error reading raw socket: %s\n", strerror (errno));
+ return;
+ }
#if VERBOSE
- fprintf (stderr,
- "Received message of %u bytes\n",
- (unsigned int) have);
+ fprintf (stderr, "Received message of %u bytes\n", (unsigned int) have);
#endif
- if (have < (ssize_t) (sizeof (struct ip_header) + sizeof (struct
icmp_ttl_exceeded_header) + sizeof (struct ip_header)))
- {
- /* malformed */
- return;
- }
+ if (have <
+ (ssize_t) (sizeof (struct ip_header) +
+ sizeof (struct icmp_ttl_exceeded_header) +
+ sizeof (struct ip_header)))
+ {
+ /* malformed */
+ return;
+ }
off = 0;
- memcpy (&ip_pkt,
- &buf[off],
- sizeof (struct ip_header));
+ memcpy (&ip_pkt, &buf[off], sizeof (struct ip_header));
off += sizeof (struct ip_header);
- memcpy(&source_ip,
- &ip_pkt.src_ip,
- sizeof (source_ip));
- memcpy (&icmp_ttl,
- &buf[off],
- sizeof (struct icmp_ttl_exceeded_header));
+ memcpy (&source_ip, &ip_pkt.src_ip, sizeof (source_ip));
+ memcpy (&icmp_ttl, &buf[off], sizeof (struct icmp_ttl_exceeded_header));
off += sizeof (struct icmp_ttl_exceeded_header);
- if ( (ICMP_TIME_EXCEEDED != icmp_ttl.type) ||
- (0 != icmp_ttl.code) )
- {
- /* different type than what we want */
- return;
- }
+ if ((ICMP_TIME_EXCEEDED != icmp_ttl.type) || (0 != icmp_ttl.code))
+ {
+ /* different type than what we want */
+ return;
+ }
/* skip 2nd IP header */
- memcpy (&ip_pkt,
- &buf[off],
- sizeof (struct ip_header));
+ memcpy (&ip_pkt, &buf[off], sizeof (struct ip_header));
off += sizeof (struct ip_header);
switch (ip_pkt.proto)
+ {
+ case IPPROTO_ICMP:
+ if (have != (sizeof (struct ip_header) * 2 +
+ sizeof (struct icmp_ttl_exceeded_header) +
+ sizeof (struct icmp_echo_header)))
{
- case IPPROTO_ICMP:
- if (have != (sizeof (struct ip_header) * 2 +
- sizeof (struct icmp_ttl_exceeded_header) +
- sizeof (struct icmp_echo_header)) )
- {
- /* malformed */
- return;
- }
- /* grab ICMP ECHO content */
- memcpy (&icmp_echo,
- &buf[off],
- sizeof (struct icmp_echo_header));
- port = (uint16_t) ntohl (icmp_echo.reserved);
- break;
- case IPPROTO_UDP:
- if (have != (sizeof (struct ip_header) * 2 +
- sizeof (struct icmp_ttl_exceeded_header) +
- sizeof (struct udp_header)) )
- {
- /* malformed */
- return;
- }
- /* grab UDP content */
- memcpy (&udp_pkt,
- &buf[off],
- sizeof (struct udp_header));
- port = ntohs (udp_pkt.length);
- break;
- default:
- /* different type than what we want */
+ /* malformed */
return;
}
+ /* grab ICMP ECHO content */
+ memcpy (&icmp_echo, &buf[off], sizeof (struct icmp_echo_header));
+ port = (uint16_t) ntohl (icmp_echo.reserved);
+ break;
+ case IPPROTO_UDP:
+ if (have != (sizeof (struct ip_header) * 2 +
+ sizeof (struct icmp_ttl_exceeded_header) +
+ sizeof (struct udp_header)))
+ {
+ /* malformed */
+ return;
+ }
+ /* grab UDP content */
+ memcpy (&udp_pkt, &buf[off], sizeof (struct udp_header));
+ port = ntohs (udp_pkt.length);
+ break;
+ default:
+ /* different type than what we want */
+ return;
+ }
- ssize = sizeof(buf);
- WSAAddressToString((LPSOCKADDR)&source_ip,
- sizeof(source_ip),
- NULL,
- buf,
- &ssize);
+ ssize = sizeof (buf);
+ WSAAddressToString ((LPSOCKADDR) & source_ip,
+ sizeof (source_ip), NULL, buf, &ssize);
if (port == 0)
- fprintf (stdout,
- "%s\n",
- buf);
+ fprintf (stdout, "%s\n", buf);
else
- fprintf (stdout,
- "%s:%u\n",
- buf,
- (unsigned int) port);
+ fprintf (stdout, "%s:%u\n", buf, (unsigned int) port);
fflush (stdout);
}
@@ -475,12 +434,10 @@
ret = socket (AF_INET, SOCK_RAW, IPPROTO_ICMP);
if (INVALID_SOCKET == ret)
- {
- fprintf (stderr,
- "Error opening RAW socket: %s\n",
- strerror (errno));
- return INVALID_SOCKET;
- }
+ {
+ fprintf (stderr, "Error opening RAW socket: %s\n", strerror (errno));
+ return INVALID_SOCKET;
+ }
return ret;
}
@@ -494,39 +451,30 @@
make_raw_socket ()
{
DWORD bOptVal = TRUE;
- int bOptLen = sizeof(bOptVal);
+ int bOptLen = sizeof (bOptVal);
rawsock = socket (AF_INET, SOCK_RAW, IPPROTO_ICMP);
if (INVALID_SOCKET == rawsock)
- {
- fprintf (stderr,
- "Error opening RAW socket: %s\n",
- strerror (errno));
- return INVALID_SOCKET;
- }
+ {
+ fprintf (stderr, "Error opening RAW socket: %s\n", strerror (errno));
+ return INVALID_SOCKET;
+ }
- if (0 != setsockopt(rawsock,
- SOL_SOCKET,
- SO_BROADCAST,
- (char*)&bOptVal, bOptLen))
- {
- fprintf(stderr,
- "Error setting SO_BROADCAST to ON: %s\n",
- strerror (errno));
- closesocket(rawsock);
- return INVALID_SOCKET;
- }
- if (0 != setsockopt(rawsock,
- IPPROTO_IP,
- IP_HDRINCL,
- (char*)&bOptVal, bOptLen))
- {
- fprintf(stderr,
- "Error setting IP_HDRINCL to ON: %s\n",
- strerror (errno));
- closesocket(rawsock);
- return INVALID_SOCKET;
- }
+ if (0 != setsockopt (rawsock,
+ SOL_SOCKET, SO_BROADCAST, (char *) &bOptVal, bOptLen))
+ {
+ fprintf (stderr,
+ "Error setting SO_BROADCAST to ON: %s\n", strerror (errno));
+ closesocket (rawsock);
+ return INVALID_SOCKET;
+ }
+ if (0 != setsockopt (rawsock,
+ IPPROTO_IP, IP_HDRINCL, (char *) &bOptVal, bOptLen))
+ {
+ fprintf (stderr, "Error setting IP_HDRINCL to ON: %s\n", strerror (errno));
+ closesocket (rawsock);
+ return INVALID_SOCKET;
+ }
return rawsock;
}
@@ -545,33 +493,27 @@
ret = socket (AF_INET, SOCK_DGRAM, 0);
if (INVALID_SOCKET == ret)
- {
- fprintf (stderr,
- "Error opening UDP socket: %s\n",
- strerror (errno));
- return INVALID_SOCKET;
- }
+ {
+ fprintf (stderr, "Error opening UDP socket: %s\n", strerror (errno));
+ return INVALID_SOCKET;
+ }
memset (&addr, 0, sizeof (addr));
addr.sin_family = AF_INET;
addr.sin_addr = *my_ip;
addr.sin_port = htons (NAT_TRAV_PORT);
- if (0 != bind (ret,
- (struct sockaddr *)&addr,
- sizeof(addr)))
- {
- fprintf (stderr,
- "Error binding UDP socket to port %u: %s\n",
- NAT_TRAV_PORT,
- strerror (errno));
- /* likely problematic, but not certain, try to continue */
- }
+ if (0 != bind (ret, (struct sockaddr *) &addr, sizeof (addr)))
+ {
+ fprintf (stderr,
+ "Error binding UDP socket to port %u: %s\n",
+ NAT_TRAV_PORT, strerror (errno));
+ /* likely problematic, but not certain, try to continue */
+ }
return ret;
}
int
-main (int argc,
- char *const *argv)
+main (int argc, char *const *argv)
{
struct in_addr external;
fd_set rs;
@@ -581,70 +523,67 @@
alt = 0;
if (2 != argc)
- {
- fprintf (stderr,
- "This program must be started with our (internal NAT) IP as the
only argument.\n");
- return 1;
- }
+ {
+ fprintf (stderr,
+ "This program must be started with our (internal NAT) IP as the
only argument.\n");
+ return 1;
+ }
if (1 != inet_pton (AF_INET, argv[1], &external))
- {
- fprintf (stderr,
- "Error parsing IPv4 address: %s, error %s\n",
- argv[1], strerror (errno));
- return 1;
- }
+ {
+ fprintf (stderr,
+ "Error parsing IPv4 address: %s, error %s\n",
+ argv[1], strerror (errno));
+ return 1;
+ }
if (1 != inet_pton (AF_INET, DUMMY_IP, &dummy))
- {
- fprintf (stderr,
- "Internal error converting dummy IP to binary.\n");
- return 2;
- }
+ {
+ fprintf (stderr, "Internal error converting dummy IP to binary.\n");
+ return 2;
+ }
if (WSAStartup (MAKEWORD (2, 1), &wsaData) != 0)
- {
- fprintf (stderr, "Failed to find Winsock 2.1 or better.\n");
- return 2;
- }
- if (INVALID_SOCKET == (icmpsock = make_icmp_socket()))
- {
- return 3;
- }
- if (INVALID_SOCKET == (make_raw_socket()))
- {
- closesocket (icmpsock);
- return 3;
- }
- if (INVALID_SOCKET == (udpsock = make_udp_socket(&external)))
- {
- closesocket (icmpsock);
- closesocket (rawsock);
- return 3;
- }
+ {
+ fprintf (stderr, "Failed to find Winsock 2.1 or better.\n");
+ return 2;
+ }
+ if (INVALID_SOCKET == (icmpsock = make_icmp_socket ()))
+ {
+ return 3;
+ }
+ if (INVALID_SOCKET == (make_raw_socket ()))
+ {
+ closesocket (icmpsock);
+ return 3;
+ }
+ if (INVALID_SOCKET == (udpsock = make_udp_socket (&external)))
+ {
+ closesocket (icmpsock);
+ closesocket (rawsock);
+ return 3;
+ }
while (1)
+ {
+ FD_ZERO (&rs);
+ FD_SET (icmpsock, &rs);
+ tv.tv_sec = 0;
+ tv.tv_usec = ICMP_SEND_FREQUENCY_MS * 1000;
+ if (-1 == select (icmpsock + 1, &rs, NULL, NULL, &tv))
{
- FD_ZERO (&rs);
- FD_SET (icmpsock, &rs);
- tv.tv_sec = 0;
- tv.tv_usec = ICMP_SEND_FREQUENCY_MS * 1000;
- if (-1 == select (icmpsock + 1, &rs, NULL, NULL, &tv))
- {
- if (errno == EINTR)
- continue;
- fprintf (stderr,
- "select failed: %s\n",
- strerror (errno));
- break;
- }
- if (FD_ISSET (icmpsock, &rs))
- process_icmp_response ();
- if (0 == (++alt % 2))
- send_icmp_echo (&external);
- else
- send_udp ();
+ if (errno == EINTR)
+ continue;
+ fprintf (stderr, "select failed: %s\n", strerror (errno));
+ break;
}
+ if (FD_ISSET (icmpsock, &rs))
+ process_icmp_response ();
+ if (0 == (++alt % 2))
+ send_icmp_echo (&external);
+ else
+ send_udp ();
+ }
/* select failed (internal error or OS out of resources) */
- closesocket(icmpsock);
- closesocket(rawsock);
- closesocket(udpsock);
+ closesocket (icmpsock);
+ closesocket (rawsock);
+ closesocket (udpsock);
WSACleanup ();
return 4;
}
Modified: gnunet/src/nat/gnunet-helper-nat-server.c
===================================================================
--- gnunet/src/nat/gnunet-helper-nat-server.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/nat/gnunet-helper-nat-server.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -212,17 +212,16 @@
* @return the CRC 16.
*/
static uint16_t
-calc_checksum(const uint16_t *data,
- unsigned int bytes)
+calc_checksum (const uint16_t * data, unsigned int bytes)
{
uint32_t sum;
unsigned int i;
sum = 0;
- for (i=0;i<bytes/2;i++)
+ for (i = 0; i < bytes / 2; i++)
sum += data[i];
sum = (sum & 0xffff) + (sum >> 16);
- sum = htons(0xffff - sum);
+ sum = htons (0xffff - sum);
return sum;
}
@@ -253,22 +252,18 @@
ip_pkt.checksum = 0;
ip_pkt.src_ip = my_ip->s_addr;
ip_pkt.dst_ip = dummy.s_addr;
- ip_pkt.checksum = htons(calc_checksum((uint16_t*)&ip_pkt,
- sizeof (struct ip_header)));
- memcpy (&packet[off],
- &ip_pkt,
- sizeof (struct ip_header));
+ ip_pkt.checksum = htons (calc_checksum ((uint16_t *) & ip_pkt,
+ sizeof (struct ip_header)));
+ memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header));
off += sizeof (struct ip_header);
icmp_echo.type = ICMP_ECHO;
icmp_echo.code = 0;
icmp_echo.checksum = 0;
icmp_echo.reserved = 0;
- icmp_echo.checksum = htons(calc_checksum((uint16_t*)&icmp_echo,
- sizeof (struct icmp_echo_header)));
- memcpy (&packet[off],
- &icmp_echo,
- sizeof (struct icmp_echo_header));
+ icmp_echo.checksum = htons (calc_checksum ((uint16_t *) & icmp_echo,
+ sizeof (struct
icmp_echo_header)));
+ memcpy (&packet[off], &icmp_echo, sizeof (struct icmp_echo_header));
off += sizeof (struct icmp_echo_header);
memset (&dst, 0, sizeof (dst));
@@ -277,22 +272,18 @@
dst.sin_len = sizeof (struct sockaddr_in);
#endif
dst.sin_addr = dummy;
- err = sendto(rawsock,
- packet, off, 0,
- (struct sockaddr*)&dst,
- sizeof(dst));
+ err = sendto (rawsock,
+ packet, off, 0, (struct sockaddr *) &dst, sizeof (dst));
if (err < 0)
- {
+ {
#if VERBOSE
- fprintf(stderr,
- "sendto failed: %s\n", strerror(errno));
+ fprintf (stderr, "sendto failed: %s\n", strerror (errno));
#endif
- }
+ }
else if (sizeof (packet) != err)
- {
- fprintf(stderr,
- "Error: partial send of ICMP message\n");
- }
+ {
+ fprintf (stderr, "Error: partial send of ICMP message\n");
+ }
}
@@ -312,22 +303,17 @@
#endif
dst.sin_addr = dummy;
dst.sin_port = htons (NAT_TRAV_PORT);
- err = sendto(udpsock,
- NULL, 0, 0,
- (struct sockaddr*)&dst,
- sizeof(dst));
+ err = sendto (udpsock, NULL, 0, 0, (struct sockaddr *) &dst, sizeof (dst));
if (err < 0)
- {
+ {
#if VERBOSE
- fprintf(stderr,
- "sendto failed: %s\n", strerror(errno));
+ fprintf (stderr, "sendto failed: %s\n", strerror (errno));
#endif
- }
+ }
else if (0 != err)
- {
- fprintf(stderr,
- "Error: partial send of ICMP message\n");
- }
+ {
+ fprintf (stderr, "Error: partial send of ICMP message\n");
+ }
}
@@ -349,96 +335,75 @@
have = read (icmpsock, buf, sizeof (buf));
if (-1 == have)
- {
- fprintf (stderr,
- "Error reading raw socket: %s\n",
- strerror (errno));
- return;
- }
+ {
+ fprintf (stderr, "Error reading raw socket: %s\n", strerror (errno));
+ return;
+ }
#if VERBOSE
- fprintf (stderr,
- "Received message of %u bytes\n",
- (unsigned int) have);
+ fprintf (stderr, "Received message of %u bytes\n", (unsigned int) have);
#endif
- if (have < (ssize_t) (sizeof (struct ip_header) + sizeof (struct
icmp_ttl_exceeded_header) + sizeof (struct ip_header)))
- {
- /* malformed */
- return;
- }
+ if (have <
+ (ssize_t) (sizeof (struct ip_header) +
+ sizeof (struct icmp_ttl_exceeded_header) +
+ sizeof (struct ip_header)))
+ {
+ /* malformed */
+ return;
+ }
off = 0;
- memcpy (&ip_pkt,
- &buf[off],
- sizeof (struct ip_header));
+ memcpy (&ip_pkt, &buf[off], sizeof (struct ip_header));
off += sizeof (struct ip_header);
- memcpy(&source_ip,
- &ip_pkt.src_ip,
- sizeof (source_ip));
- memcpy (&icmp_ttl,
- &buf[off],
- sizeof (struct icmp_ttl_exceeded_header));
+ memcpy (&source_ip, &ip_pkt.src_ip, sizeof (source_ip));
+ memcpy (&icmp_ttl, &buf[off], sizeof (struct icmp_ttl_exceeded_header));
off += sizeof (struct icmp_ttl_exceeded_header);
- if ( (ICMP_TIME_EXCEEDED != icmp_ttl.type) ||
- (0 != icmp_ttl.code) )
- {
- /* different type than what we want */
- return;
- }
+ if ((ICMP_TIME_EXCEEDED != icmp_ttl.type) || (0 != icmp_ttl.code))
+ {
+ /* different type than what we want */
+ return;
+ }
/* skip 2nd IP header */
- memcpy (&ip_pkt,
- &buf[off],
- sizeof (struct ip_header));
+ memcpy (&ip_pkt, &buf[off], sizeof (struct ip_header));
off += sizeof (struct ip_header);
switch (ip_pkt.proto)
+ {
+ case IPPROTO_ICMP:
+ if (have != (sizeof (struct ip_header) * 2 +
+ sizeof (struct icmp_ttl_exceeded_header) +
+ sizeof (struct icmp_echo_header)))
{
- case IPPROTO_ICMP:
- if (have != (sizeof (struct ip_header) * 2 +
- sizeof (struct icmp_ttl_exceeded_header) +
- sizeof (struct icmp_echo_header)) )
- {
- /* malformed */
- return;
- }
- /* grab ICMP ECHO content */
- memcpy (&icmp_echo,
- &buf[off],
- sizeof (struct icmp_echo_header));
- port = (uint16_t) ntohl (icmp_echo.reserved);
- break;
- case IPPROTO_UDP:
- if (have != (sizeof (struct ip_header) * 2 +
- sizeof (struct icmp_ttl_exceeded_header) +
- sizeof (struct udp_header)) )
- {
- /* malformed */
- return;
- }
- /* grab UDP content */
- memcpy (&udp_pkt,
- &buf[off],
- sizeof (struct udp_header));
- port = ntohs (udp_pkt.length);
- break;
- default:
- /* different type than what we want */
+ /* malformed */
return;
}
+ /* grab ICMP ECHO content */
+ memcpy (&icmp_echo, &buf[off], sizeof (struct icmp_echo_header));
+ port = (uint16_t) ntohl (icmp_echo.reserved);
+ break;
+ case IPPROTO_UDP:
+ if (have != (sizeof (struct ip_header) * 2 +
+ sizeof (struct icmp_ttl_exceeded_header) +
+ sizeof (struct udp_header)))
+ {
+ /* malformed */
+ return;
+ }
+ /* grab UDP content */
+ memcpy (&udp_pkt, &buf[off], sizeof (struct udp_header));
+ port = ntohs (udp_pkt.length);
+ break;
+ default:
+ /* different type than what we want */
+ return;
+ }
if (port == 0)
fprintf (stdout,
- "%s\n",
- inet_ntop (AF_INET,
- &source_ip,
- buf,
- sizeof (buf)));
+ "%s\n", inet_ntop (AF_INET, &source_ip, buf, sizeof (buf)));
else
fprintf (stdout,
- "%s:%u\n",
- inet_ntop (AF_INET,
- &source_ip,
- buf,
- sizeof (buf)),
- (unsigned int) port);
+ "%s:%u\n",
+ inet_ntop (AF_INET,
+ &source_ip, buf, sizeof (buf)), (unsigned int) port);
fflush (stdout);
}
@@ -455,21 +420,18 @@
ret = socket (AF_INET, SOCK_RAW, IPPROTO_ICMP);
if (-1 == ret)
- {
- fprintf (stderr,
- "Error opening RAW socket: %s\n",
- strerror (errno));
- return -1;
- }
+ {
+ fprintf (stderr, "Error opening RAW socket: %s\n", strerror (errno));
+ return -1;
+ }
if (ret >= FD_SETSIZE)
- {
- fprintf (stderr,
- "Socket number too large (%d > %u)\n",
- ret,
- (unsigned int) FD_SETSIZE);
- close (ret);
- return -1;
- }
+ {
+ fprintf (stderr,
+ "Socket number too large (%d > %u)\n",
+ ret, (unsigned int) FD_SETSIZE);
+ close (ret);
+ return -1;
+ }
return ret;
}
@@ -487,34 +449,24 @@
ret = socket (AF_INET, SOCK_RAW, IPPROTO_RAW);
if (-1 == ret)
- {
- fprintf (stderr,
- "Error opening RAW socket: %s\n",
- strerror (errno));
- return -1;
- }
- if (-1 == setsockopt(ret,
- SOL_SOCKET,
- SO_BROADCAST,
- (char *)&one, sizeof(one)))
- {
- fprintf(stderr,
- "setsockopt failed: %s\n",
- strerror (errno));
- close (ret);
- return -1;
- }
- if (-1 == setsockopt(ret,
- IPPROTO_IP,
- IP_HDRINCL,
- (char *)&one, sizeof(one)))
- {
- fprintf(stderr,
- "setsockopt failed: %s\n",
- strerror (errno));
- close (ret);
- return -1;
- }
+ {
+ fprintf (stderr, "Error opening RAW socket: %s\n", strerror (errno));
+ return -1;
+ }
+ if (-1 == setsockopt (ret,
+ SOL_SOCKET, SO_BROADCAST, (char *) &one, sizeof (one)))
+ {
+ fprintf (stderr, "setsockopt failed: %s\n", strerror (errno));
+ close (ret);
+ return -1;
+ }
+ if (-1 == setsockopt (ret,
+ IPPROTO_IP, IP_HDRINCL, (char *) &one, sizeof (one)))
+ {
+ fprintf (stderr, "setsockopt failed: %s\n", strerror (errno));
+ close (ret);
+ return -1;
+ }
return ret;
}
@@ -533,15 +485,11 @@
ret = socket (AF_INET, SOCK_DGRAM, 0);
if (-1 == ret)
- {
- fprintf (stderr,
- "Error opening UDP socket: %s\n",
- strerror (errno));
- return -1;
- }
- memset (&addr,
- 0,
- sizeof (addr));
+ {
+ fprintf (stderr, "Error opening UDP socket: %s\n", strerror (errno));
+ return -1;
+ }
+ memset (&addr, 0, sizeof (addr));
addr.sin_family = AF_INET;
#if HAVE_SOCKADDR_IN_SIN_LEN
addr.sin_len = sizeof (struct sockaddr_in);
@@ -549,23 +497,19 @@
addr.sin_addr = *my_ip;
addr.sin_port = htons (NAT_TRAV_PORT);
- if (0 != bind (ret,
- &addr,
- sizeof(addr)))
- {
- fprintf (stderr,
- "Error binding UDP socket to port %u: %s\n",
- NAT_TRAV_PORT,
- strerror (errno));
- /* likely problematic, but not certain, try to continue */
- }
+ if (0 != bind (ret, &addr, sizeof (addr)))
+ {
+ fprintf (stderr,
+ "Error binding UDP socket to port %u: %s\n",
+ NAT_TRAV_PORT, strerror (errno));
+ /* likely problematic, but not certain, try to continue */
+ }
return ret;
}
int
-main (int argc,
- char *const *argv)
+main (int argc, char *const *argv)
{
struct in_addr external;
fd_set rs;
@@ -574,72 +518,65 @@
unsigned int alt;
if (2 != argc)
- {
- fprintf (stderr,
- "This program must be started with our (internal NAT) IP as the
only argument.\n");
- return 1;
- }
+ {
+ fprintf (stderr,
+ "This program must be started with our (internal NAT) IP as the
only argument.\n");
+ return 1;
+ }
if (1 != inet_pton (AF_INET, argv[1], &external))
- {
- fprintf (stderr,
- "Error parsing IPv4 address: %s\n",
- strerror (errno));
- return 1;
- }
+ {
+ fprintf (stderr, "Error parsing IPv4 address: %s\n", strerror (errno));
+ return 1;
+ }
if (1 != inet_pton (AF_INET, DUMMY_IP, &dummy))
- {
- fprintf (stderr,
- "Internal error converting dummy IP to binary.\n");
- return 2;
- }
- if (-1 == (icmpsock = make_icmp_socket()))
- {
- return 3;
- }
- if (-1 == (rawsock = make_raw_socket()))
- {
- close (icmpsock);
- return 3;
- }
+ {
+ fprintf (stderr, "Internal error converting dummy IP to binary.\n");
+ return 2;
+ }
+ if (-1 == (icmpsock = make_icmp_socket ()))
+ {
+ return 3;
+ }
+ if (-1 == (rawsock = make_raw_socket ()))
+ {
+ close (icmpsock);
+ return 3;
+ }
uid = getuid ();
if (0 != setresuid (uid, uid, uid))
- {
- fprintf (stderr,
- "Failed to setresuid: %s\n",
- strerror (errno));
- /* not critical, continue anyway */
- }
- if (-1 == (udpsock = make_udp_socket(&external)))
- {
- close (icmpsock);
- close (rawsock);
- return 3;
- }
+ {
+ fprintf (stderr, "Failed to setresuid: %s\n", strerror (errno));
+ /* not critical, continue anyway */
+ }
+ if (-1 == (udpsock = make_udp_socket (&external)))
+ {
+ close (icmpsock);
+ close (rawsock);
+ return 3;
+ }
alt = 0;
while (1)
+ {
+ FD_ZERO (&rs);
+ FD_SET (icmpsock, &rs);
+ tv.tv_sec = 0;
+ tv.tv_usec = ICMP_SEND_FREQUENCY_MS * 1000;
+ if (-1 == select (icmpsock + 1, &rs, NULL, NULL, &tv))
{
- FD_ZERO (&rs);
- FD_SET (icmpsock, &rs);
- tv.tv_sec = 0;
- tv.tv_usec = ICMP_SEND_FREQUENCY_MS * 1000;
- if (-1 == select (icmpsock + 1, &rs, NULL, NULL, &tv))
- {
- if (errno == EINTR)
- continue;
- fprintf (stderr,
- "select failed: %s\n",
- strerror (errno));
- break;
- }
- if (1 == getppid()) /* Check the parent process id, if 1 the parent has
died, so we should die too */
- break;
- if (FD_ISSET (icmpsock, &rs))
- process_icmp_response ();
- if (0 == (++alt % 2))
- send_icmp_echo (&external);
- else
- send_udp ();
+ if (errno == EINTR)
+ continue;
+ fprintf (stderr, "select failed: %s\n", strerror (errno));
+ break;
}
+ if (1 == getppid ()) /* Check the parent process id, if 1 the
parent has died, so we should die too */
+ break;
+ if (FD_ISSET (icmpsock, &rs))
+ process_icmp_response ();
+ if (0 == (++alt % 2))
+ send_icmp_echo (&external);
+ else
+ send_udp ();
+ }
/* select failed (internal error or OS out of resources) */
close (icmpsock);
close (rawsock);
Modified: gnunet/src/nat/gnunet-nat-server.c
===================================================================
--- gnunet/src/nat/gnunet-nat-server.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/nat/gnunet-nat-server.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -51,30 +51,23 @@
* @param is_tcp mark for TCP (GNUNET_YES) or UDP (GNUNET_NO)
*/
static void
-try_anat (uint32_t dst_ipv4,
- uint16_t dport,
- int is_tcp)
+try_anat (uint32_t dst_ipv4, uint16_t dport, int is_tcp)
{
struct GNUNET_NAT_Handle *h;
struct sockaddr_in sa;
#if DEBUG_NAT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Asking for connection reversal with %x and code %u\n",
- (unsigned int) dst_ipv4,
- (unsigned int) dport);
+ "Asking for connection reversal with %x and code %u\n",
+ (unsigned int) dst_ipv4, (unsigned int) dport);
#endif
- h = GNUNET_NAT_register (cfg,
- is_tcp,
- dport,
- 0, NULL, NULL,
- NULL, NULL, NULL);
+ h = GNUNET_NAT_register (cfg, is_tcp, dport, 0, NULL, NULL, NULL, NULL,
NULL);
memset (&sa, 0, sizeof (sa));
sa.sin_family = AF_INET;
#if HAVE_SOCKADDR_IN_SIN_LEN
sa.sin_len = sizeof (sa);
#endif
- sa.sin_addr.s_addr = dst_ipv4;
+ sa.sin_addr.s_addr = dst_ipv4;
GNUNET_NAT_run_client (h, &sa);
GNUNET_NAT_unregister (h);
}
@@ -83,7 +76,7 @@
/**
* Closure for 'tcp_send'.
*/
-struct TcpContext
+struct TcpContext
{
/**
* TCP socket.
@@ -92,7 +85,7 @@
/**
* Data to transmit.
- */
+ */
uint16_t data;
};
@@ -105,23 +98,22 @@
* @param tc scheduler context
*/
static void
-tcp_send (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+tcp_send (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct TcpContext *ctx = cls;
- if ( (NULL != tc->write_ready) &&
- (GNUNET_NETWORK_fdset_isset (tc->write_ready,
- ctx->s)) )
+ if ((NULL != tc->write_ready) &&
+ (GNUNET_NETWORK_fdset_isset (tc->write_ready, ctx->s)))
+ {
+ if (-1 ==
+ GNUNET_NETWORK_socket_send (ctx->s, &ctx->data, sizeof (ctx->data)))
{
- if (-1 == GNUNET_NETWORK_socket_send (ctx->s, &ctx->data, sizeof
(ctx->data)))
- {
#if DEBUG_NAT
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, "send");
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, "send");
#endif
- }
- GNUNET_NETWORK_socket_shutdown (ctx->s, SHUT_RDWR);
}
+ GNUNET_NETWORK_socket_shutdown (ctx->s, SHUT_RDWR);
+ }
GNUNET_NETWORK_socket_close (ctx->s);
GNUNET_free (ctx);
}
@@ -136,9 +128,7 @@
* @param data data to send
*/
static void
-try_send_tcp (uint32_t dst_ipv4,
- uint16_t dport,
- uint16_t data)
+try_send_tcp (uint32_t dst_ipv4, uint16_t dport, uint16_t data)
{
struct GNUNET_NETWORK_Handle *s;
struct sockaddr_in sa;
@@ -146,37 +136,35 @@
s = GNUNET_NETWORK_socket_create (AF_INET, SOCK_STREAM, 0);
if (NULL == s)
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "socket");
- return;
- }
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "socket");
+ return;
+ }
memset (&sa, 0, sizeof (sa));
sa.sin_family = AF_INET;
#if HAVE_SOCKADDR_IN_SIN_LEN
sa.sin_len = sizeof (sa);
#endif
- sa.sin_addr.s_addr = dst_ipv4;
+ sa.sin_addr.s_addr = dst_ipv4;
sa.sin_port = htons (dport);
#if DEBUG_NAT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending TCP message to `%s'\n",
- GNUNET_a2s ((struct sockaddr*) &sa, sizeof (sa)));
+ "Sending TCP message to `%s'\n",
+ GNUNET_a2s ((struct sockaddr *) &sa, sizeof (sa)));
#endif
- if ( (GNUNET_OK !=
- GNUNET_NETWORK_socket_connect (s,
- (const struct sockaddr*) &sa, sizeof
(sa))) &&
- (errno != EINPROGRESS) )
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "connect");
- GNUNET_NETWORK_socket_close (s);
- return;
- }
+ if ((GNUNET_OK !=
+ GNUNET_NETWORK_socket_connect (s,
+ (const struct sockaddr *) &sa,
+ sizeof (sa))) && (errno != EINPROGRESS))
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "connect");
+ GNUNET_NETWORK_socket_close (s);
+ return;
+ }
ctx = GNUNET_malloc (sizeof (struct TcpContext));
ctx->s = s;
ctx->data = data;
- GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_SECONDS,
- s,
- &tcp_send, ctx);
+ GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_SECONDS, s, &tcp_send, ctx);
}
@@ -189,34 +177,33 @@
* @param data data to send
*/
static void
-try_send_udp (uint32_t dst_ipv4,
- uint16_t dport,
- uint16_t data)
+try_send_udp (uint32_t dst_ipv4, uint16_t dport, uint16_t data)
{
struct GNUNET_NETWORK_Handle *s;
struct sockaddr_in sa;
s = GNUNET_NETWORK_socket_create (AF_INET, SOCK_DGRAM, 0);
if (NULL == s)
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "socket");
- return;
- }
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "socket");
+ return;
+ }
memset (&sa, 0, sizeof (sa));
sa.sin_family = AF_INET;
#if HAVE_SOCKADDR_IN_SIN_LEN
sa.sin_len = sizeof (sa);
#endif
- sa.sin_addr.s_addr = dst_ipv4;
+ sa.sin_addr.s_addr = dst_ipv4;
sa.sin_port = htons (dport);
#if DEBUG_NAT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending UDP packet to `%s'\n",
- GNUNET_a2s ((struct sockaddr*) &sa, sizeof (sa)));
+ "Sending UDP packet to `%s'\n",
+ GNUNET_a2s ((struct sockaddr *) &sa, sizeof (sa)));
#endif
- if (-1 == GNUNET_NETWORK_socket_sendto (s,
- &data, sizeof(data),
- (const struct sockaddr*) &sa, sizeof
(sa)))
+ if (-1 == GNUNET_NETWORK_socket_sendto (s,
+ &data, sizeof (data),
+ (const struct sockaddr *) &sa,
+ sizeof (sa)))
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "sendto");
GNUNET_NETWORK_socket_close (s);
}
@@ -239,21 +226,17 @@
uint16_t dport;
#if DEBUG_NAT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received test request\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received test request\n");
#endif
- tm = (const struct GNUNET_NAT_TestMessage*) msg;
+ tm = (const struct GNUNET_NAT_TestMessage *) msg;
dport = ntohs (tm->dport);
if (0 == dport)
- try_anat (tm->dst_ipv4,
- ntohs (tm->data),
- (int) ntohl (tm->is_tcp));
+ try_anat (tm->dst_ipv4, ntohs (tm->data), (int) ntohl (tm->is_tcp));
else if (GNUNET_YES == ntohl (tm->is_tcp))
try_send_tcp (tm->dst_ipv4, dport, tm->data);
else
try_send_udp (tm->dst_ipv4, dport, tm->data);
- GNUNET_SERVER_receive_done (client,
- GNUNET_NO);
+ GNUNET_SERVER_receive_done (client, GNUNET_NO);
}
@@ -264,8 +247,7 @@
* @param tc scheduler context
*/
static void
-shutdown_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GNUNET_SERVER_destroy (server);
server = NULL;
@@ -283,43 +265,40 @@
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *c)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
{
- static const struct GNUNET_SERVER_MessageHandler handlers[] =
- {
- { &test, NULL, GNUNET_MESSAGE_TYPE_NAT_TEST, sizeof (struct
GNUNET_NAT_TestMessage) },
- { NULL, NULL, 0, 0 }
- };
+ static const struct GNUNET_SERVER_MessageHandler handlers[] = {
+ {&test, NULL, GNUNET_MESSAGE_TYPE_NAT_TEST,
+ sizeof (struct GNUNET_NAT_TestMessage)},
+ {NULL, NULL, 0, 0}
+ };
unsigned int port;
struct sockaddr_in in4;
struct sockaddr_in6 in6;
- socklen_t slen[] =
- {
- sizeof (in4),
- sizeof (in6),
- 0
- };
- struct sockaddr *sa[] =
- {
- (struct sockaddr*) &in4,
- (struct sockaddr*) &in6,
- NULL
- };
+ socklen_t slen[] = {
+ sizeof (in4),
+ sizeof (in6),
+ 0
+ };
+ struct sockaddr *sa[] = {
+ (struct sockaddr *) &in4,
+ (struct sockaddr *) &in6,
+ NULL
+ };
+
cfg = c;
- if ( (args[0] == NULL) ||
- (1 != SSCANF (args[0], "%u", &port)) ||
- (0 == port) ||
- (65536 <= port) )
- {
- fprintf (stderr,
- _("Please pass valid port number as the first argument! (got
`%s')\n"),
- args[0]);
- return;
- }
- memset (&in4, 0, sizeof (in4));
- memset (&in6, 0, sizeof (in6));
+ if ((args[0] == NULL) ||
+ (1 != SSCANF (args[0], "%u", &port)) || (0 == port) || (65536 <= port))
+ {
+ fprintf (stderr,
+ _
+ ("Please pass valid port number as the first argument! (got
`%s')\n"),
+ args[0]);
+ return;
+ }
+ memset (&in4, 0, sizeof (in4));
+ memset (&in6, 0, sizeof (in6));
in4.sin_family = AF_INET;
in4.sin_port = htons ((uint16_t) port);
in6.sin6_family = AF_INET6;
@@ -329,15 +308,11 @@
in6.sin6_len = sizeof (in6);
#endif
server = GNUNET_SERVER_create (NULL, NULL,
- (struct sockaddr*const*) sa,
- slen,
- GNUNET_TIME_UNIT_SECONDS,
- GNUNET_YES);
- GNUNET_SERVER_add_handlers (server,
- handlers);
+ (struct sockaddr * const *) sa,
+ slen, GNUNET_TIME_UNIT_SECONDS, GNUNET_YES);
+ GNUNET_SERVER_add_handlers (server, handlers);
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task,
- NULL);
+ &shutdown_task, NULL);
}
@@ -356,11 +331,10 @@
};
if (GNUNET_OK !=
- GNUNET_PROGRAM_run (argc, argv,
- "gnunet-nat-server [options] PORT",
- _("GNUnet NAT traversal test helper daemon"),
- options,
- &run, NULL))
+ GNUNET_PROGRAM_run (argc, argv,
+ "gnunet-nat-server [options] PORT",
+ _("GNUnet NAT traversal test helper daemon"),
+ options, &run, NULL))
return 1;
return 0;
}
Modified: gnunet/src/nat/nat.c
===================================================================
--- gnunet/src/nat/nat.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/nat/nat.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -62,40 +62,39 @@
* we reevaluate the source.
*/
enum LocalAddressSource
- {
+{
/**
* Address was obtained by DNS resolution of the external hostname
* given in the configuration (i.e. hole-punched DynDNS setup).
*/
- LAL_EXTERNAL_IP,
+ LAL_EXTERNAL_IP,
/**
* Address was obtained by looking up our own hostname in DNS.
*/
- LAL_HOSTNAME_DNS,
+ LAL_HOSTNAME_DNS,
/**
* Address was obtained by scanning our hosts's network interfaces
* and taking their address (no DNS involved).
*/
- LAL_INTERFACE_ADDRESS,
-
+ LAL_INTERFACE_ADDRESS,
+
/**
* Addresses we were explicitly bound to.
*/
- LAL_BINDTO_ADDRESS,
+ LAL_BINDTO_ADDRESS,
/**
* Addresses from UPnP or PMP
*/
- LAL_UPNP,
+ LAL_UPNP,
/**
* End of the list.
*/
- LAL_END
-
- };
+ LAL_END
+};
/**
@@ -114,7 +113,7 @@
/**
* Previous entry.
- */
+ */
struct LocalAddressList *prev;
/**
@@ -168,7 +167,7 @@
* Configuration to use.
*/
const struct GNUNET_CONFIGURATION_Handle *cfg;
-
+
/**
* Function to call when we learn about a new address.
*/
@@ -345,7 +344,7 @@
/**
* Is this TCP or UDP?
- */
+ */
int is_tcp;
/**
@@ -362,8 +361,7 @@
*
* @param h handle to NAT
*/
-static void
-start_gnunet_nat_server (struct GNUNET_NAT_Handle *h);
+static void start_gnunet_nat_server (struct GNUNET_NAT_Handle *h);
/**
@@ -375,27 +373,24 @@
*/
static void
remove_from_address_list_by_source (struct GNUNET_NAT_Handle *h,
- enum LocalAddressSource src)
+ enum LocalAddressSource src)
{
struct LocalAddressList *pos;
struct LocalAddressList *next;
next = h->lal_head;
while (NULL != (pos = next))
- {
- next = pos->next;
- if (pos->source != src)
- continue;
- GNUNET_CONTAINER_DLL_remove (h->lal_head,
- h->lal_tail,
- pos);
- if (NULL != h->address_callback)
- h->address_callback (h->callback_cls,
- GNUNET_NO,
- (const struct sockaddr* ) &pos[1],
- pos->addrlen);
- GNUNET_free (pos);
- }
+ {
+ next = pos->next;
+ if (pos->source != src)
+ continue;
+ GNUNET_CONTAINER_DLL_remove (h->lal_head, h->lal_tail, pos);
+ if (NULL != h->address_callback)
+ h->address_callback (h->callback_cls,
+ GNUNET_NO,
+ (const struct sockaddr *) &pos[1], pos->addrlen);
+ GNUNET_free (pos);
+ }
}
@@ -410,9 +405,8 @@
*/
static void
add_to_address_list_as_is (struct GNUNET_NAT_Handle *h,
- enum LocalAddressSource src,
- const struct sockaddr *arg,
- socklen_t arg_size)
+ enum LocalAddressSource src,
+ const struct sockaddr *arg, socklen_t arg_size)
{
struct LocalAddressList *lal;
@@ -420,21 +414,15 @@
memcpy (&lal[1], arg, arg_size);
lal->addrlen = arg_size;
lal->source = src;
- GNUNET_CONTAINER_DLL_insert (h->lal_head,
- h->lal_tail,
- lal);
+ GNUNET_CONTAINER_DLL_insert (h->lal_head, h->lal_tail, lal);
#if DEBUG_NAT
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "nat",
- "Adding address `%s' from source %d\n",
- GNUNET_a2s (arg, arg_size),
- src);
+ "nat",
+ "Adding address `%s' from source %d\n",
+ GNUNET_a2s (arg, arg_size), src);
#endif
if (NULL != h->address_callback)
- h->address_callback (h->callback_cls,
- GNUNET_YES,
- arg,
- arg_size);
+ h->address_callback (h->callback_cls, GNUNET_YES, arg, arg_size);
}
@@ -451,9 +439,8 @@
*/
static void
add_to_address_list (struct GNUNET_NAT_Handle *h,
- enum LocalAddressSource src,
- const struct sockaddr *arg,
- socklen_t arg_size)
+ enum LocalAddressSource src,
+ const struct sockaddr *arg, socklen_t arg_size)
{
struct sockaddr_in s4;
const struct sockaddr_in *in4;
@@ -461,41 +448,41 @@
const struct sockaddr_in6 *in6;
if (arg_size == sizeof (struct sockaddr_in))
+ {
+ in4 = (const struct sockaddr_in *) arg;
+ s4 = *in4;
+ s4.sin_port = htons (h->adv_port);
+ add_to_address_list_as_is (h,
+ src,
+ (const struct sockaddr *) &s4,
+ sizeof (struct sockaddr_in));
+ if (GNUNET_YES == h->enable_nat_server)
{
- in4 = (const struct sockaddr_in *) arg;
- s4 = *in4;
- s4.sin_port = htons (h->adv_port);
- add_to_address_list_as_is (h,
- src,
- (const struct sockaddr*) &s4,
- sizeof (struct sockaddr_in));
- if (GNUNET_YES == h->enable_nat_server)
- {
- /* also add with PORT = 0 to indicate NAT server is enabled */
- s4.sin_port = htons(0);
- add_to_address_list_as_is (h,
- src,
- (const struct sockaddr*) &s4,
- sizeof (struct sockaddr_in));
- }
+ /* also add with PORT = 0 to indicate NAT server is enabled */
+ s4.sin_port = htons (0);
+ add_to_address_list_as_is (h,
+ src,
+ (const struct sockaddr *) &s4,
+ sizeof (struct sockaddr_in));
}
+ }
else if (arg_size == sizeof (struct sockaddr_in6))
+ {
+ if (GNUNET_YES != h->disable_ipv6)
{
- if (GNUNET_YES != h->disable_ipv6)
- {
- in6 = (const struct sockaddr_in6 *) arg;
- s6 = *in6;
- s6.sin6_port = htons(h->adv_port);
- add_to_address_list_as_is (h,
- src,
- (const struct sockaddr*) &s6,
- sizeof (struct sockaddr_in6));
- }
+ in6 = (const struct sockaddr_in6 *) arg;
+ s6 = *in6;
+ s6.sin6_port = htons (h->adv_port);
+ add_to_address_list_as_is (h,
+ src,
+ (const struct sockaddr *) &s6,
+ sizeof (struct sockaddr_in6));
}
+ }
else
- {
- GNUNET_assert (0);
- }
+ {
+ GNUNET_assert (0);
+ }
}
@@ -510,9 +497,8 @@
*/
static void
add_ip_to_address_list (struct GNUNET_NAT_Handle *h,
- enum LocalAddressSource src,
- const void *addr,
- socklen_t addrlen)
+ enum LocalAddressSource src,
+ const void *addr, socklen_t addrlen)
{
struct sockaddr_in s4;
const struct in_addr *in4;
@@ -520,52 +506,52 @@
const struct in6_addr *in6;
if (addrlen == sizeof (struct in_addr))
- {
- in4 = (const struct in_addr *) addr;
- memset (&s4, 0, sizeof (s4));
- s4.sin_family = AF_INET;
- s4.sin_port = 0;
+ {
+ in4 = (const struct in_addr *) addr;
+ memset (&s4, 0, sizeof (s4));
+ s4.sin_family = AF_INET;
+ s4.sin_port = 0;
#if HAVE_SOCKADDR_IN_SIN_LEN
- s4.sin_len = (u_char) sizeof (struct sockaddr_in);
+ s4.sin_len = (u_char) sizeof (struct sockaddr_in);
#endif
- s4.sin_addr = *in4;
- add_to_address_list (h,
- src,
- (const struct sockaddr*) &s4,
- sizeof (struct sockaddr_in));
- if (GNUNET_YES == h->enable_nat_server)
- {
- /* also add with PORT = 0 to indicate NAT server is enabled */
- s4.sin_port = htons(0);
- add_to_address_list (h,
- src,
- (const struct sockaddr*) &s4,
- sizeof (struct sockaddr_in));
+ s4.sin_addr = *in4;
+ add_to_address_list (h,
+ src,
+ (const struct sockaddr *) &s4,
+ sizeof (struct sockaddr_in));
+ if (GNUNET_YES == h->enable_nat_server)
+ {
+ /* also add with PORT = 0 to indicate NAT server is enabled */
+ s4.sin_port = htons (0);
+ add_to_address_list (h,
+ src,
+ (const struct sockaddr *) &s4,
+ sizeof (struct sockaddr_in));
- }
}
+ }
else if (addrlen == sizeof (struct in6_addr))
+ {
+ if (GNUNET_YES != h->disable_ipv6)
{
- if (GNUNET_YES != h->disable_ipv6)
- {
- in6 = (const struct in6_addr *) addr;
- memset (&s6, 0, sizeof (s6));
- s6.sin6_family = AF_INET6;
- s6.sin6_port = htons(h->adv_port);
+ in6 = (const struct in6_addr *) addr;
+ memset (&s6, 0, sizeof (s6));
+ s6.sin6_family = AF_INET6;
+ s6.sin6_port = htons (h->adv_port);
#if HAVE_SOCKADDR_IN_SIN_LEN
- s6.sin6_len = (u_char) sizeof (struct sockaddr_in6);
+ s6.sin6_len = (u_char) sizeof (struct sockaddr_in6);
#endif
- s6.sin6_addr = *in6;
- add_to_address_list (h,
- src,
- (const struct sockaddr*) &s6,
- sizeof (struct sockaddr_in6));
- }
+ s6.sin6_addr = *in6;
+ add_to_address_list (h,
+ src,
+ (const struct sockaddr *) &s6,
+ sizeof (struct sockaddr_in6));
}
+ }
else
- {
- GNUNET_assert (0);
- }
+ {
+ GNUNET_assert (0);
+ }
}
@@ -577,8 +563,7 @@
* @param tc scheduler context
*/
static void
-resolve_dns (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+resolve_dns (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
/**
@@ -590,24 +575,20 @@
* @param addrlen number of bytes in addr
*/
static void
-process_external_ip (void *cls,
- const struct sockaddr *addr,
- socklen_t addrlen)
+process_external_ip (void *cls, const struct sockaddr *addr, socklen_t addrlen)
{
struct GNUNET_NAT_Handle *h = cls;
struct in_addr dummy;
if (addr == NULL)
- {
- h->ext_dns = NULL;
- if (1 == inet_pton (AF_INET,
- h->external_address,
- &dummy))
- return; /* repated lookup pointless: was numeric! */
- h->dns_task = GNUNET_SCHEDULER_add_delayed (h->dyndns_frequency,
- &resolve_dns, h);
- return;
- }
+ {
+ h->ext_dns = NULL;
+ if (1 == inet_pton (AF_INET, h->external_address, &dummy))
+ return; /* repated lookup pointless: was numeric! */
+ h->dns_task = GNUNET_SCHEDULER_add_delayed (h->dyndns_frequency,
+ &resolve_dns, h);
+ return;
+ }
add_to_address_list (h, LAL_EXTERNAL_IP, addr, addrlen);
}
@@ -619,8 +600,7 @@
* @param tc scheduler context
*/
static void
-resolve_hostname (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+resolve_hostname (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
/**
@@ -633,18 +613,17 @@
* @param addrlen length of the address
*/
static void
-process_hostname_ip (void *cls,
- const struct sockaddr *addr, socklen_t addrlen)
+process_hostname_ip (void *cls, const struct sockaddr *addr, socklen_t addrlen)
{
struct GNUNET_NAT_Handle *h = cls;
-
+
if (addr == NULL)
- {
- h->hostname_dns = NULL;
- h->hostname_task = GNUNET_SCHEDULER_add_delayed
(h->hostname_dns_frequency,
- &resolve_hostname, h);
- return;
- }
+ {
+ h->hostname_dns = NULL;
+ h->hostname_task = GNUNET_SCHEDULER_add_delayed (h->hostname_dns_frequency,
+ &resolve_hostname, h);
+ return;
+ }
add_to_address_list (h, LAL_HOSTNAME_DNS, addr, addrlen);
}
@@ -673,48 +652,44 @@
char buf[INET6_ADDRSTRLEN];
switch (addr->sa_family)
+ {
+ case AF_INET:
+ s4 = (struct sockaddr_in *) addr;
+ ip = &s4->sin_addr;
+ if (GNUNET_YES == h->use_localaddresses)
+ add_ip_to_address_list (h,
+ LAL_INTERFACE_ADDRESS,
+ &s4->sin_addr, sizeof (struct in_addr));
+ break;
+ case AF_INET6:
+ s6 = (struct sockaddr_in6 *) addr;
+ if (IN6_IS_ADDR_LINKLOCAL (&((struct sockaddr_in6 *) addr)->sin6_addr))
{
- case AF_INET:
- s4 = (struct sockaddr_in *) addr;
- ip = &s4->sin_addr;
- if (GNUNET_YES == h->use_localaddresses)
- add_ip_to_address_list (h,
- LAL_INTERFACE_ADDRESS,
- &s4->sin_addr,
- sizeof (struct in_addr));
- break;
- case AF_INET6:
- s6 = (struct sockaddr_in6 *) addr;
- if (IN6_IS_ADDR_LINKLOCAL (&((struct sockaddr_in6 *) addr)->sin6_addr))
- {
- /* skip link local addresses */
- return GNUNET_OK;
- }
- ip = &s6->sin6_addr;
- if (GNUNET_YES == h->use_localaddresses)
- add_ip_to_address_list (h,
- LAL_INTERFACE_ADDRESS,
- &s6->sin6_addr,
- sizeof (struct in6_addr));
- break;
- default:
- GNUNET_break (0);
+ /* skip link local addresses */
return GNUNET_OK;
}
- if ( (h->internal_address == NULL) &&
- (h->server_proc == NULL) &&
- (h->server_read_task == GNUNET_SCHEDULER_NO_TASK) &&
- (GNUNET_YES == isDefault) &&
- ( (addr->sa_family == AF_INET) || (addr->sa_family == AF_INET6) ) )
- {
- /* no internal address configured, but we found a "default"
- interface, try using that as our 'internal' address */
- h->internal_address = GNUNET_strdup (inet_ntop (addr->sa_family,
- ip,
- buf,
- sizeof (buf)));
- start_gnunet_nat_server (h);
- }
+ ip = &s6->sin6_addr;
+ if (GNUNET_YES == h->use_localaddresses)
+ add_ip_to_address_list (h,
+ LAL_INTERFACE_ADDRESS,
+ &s6->sin6_addr, sizeof (struct in6_addr));
+ break;
+ default:
+ GNUNET_break (0);
+ return GNUNET_OK;
+ }
+ if ((h->internal_address == NULL) &&
+ (h->server_proc == NULL) &&
+ (h->server_read_task == GNUNET_SCHEDULER_NO_TASK) &&
+ (GNUNET_YES == isDefault) &&
+ ((addr->sa_family == AF_INET) || (addr->sa_family == AF_INET6)))
+ {
+ /* no internal address configured, but we found a "default"
+ * interface, try using that as our 'internal' address */
+ h->internal_address = GNUNET_strdup (inet_ntop (addr->sa_family,
+ ip, buf, sizeof (buf)));
+ start_gnunet_nat_server (h);
+ }
return GNUNET_OK;
}
@@ -725,16 +700,15 @@
*
* @param cls the 'struct GNUNET_NAT_Handle'
* @param tc scheduler context
- */
+ */
static void
-restart_nat_server (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+restart_nat_server (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_NAT_Handle *h = cls;
h->server_read_task = GNUNET_SCHEDULER_NO_TASK;
- if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
+ if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
+ return;
start_gnunet_nat_server (h);
}
@@ -748,8 +722,7 @@
* @param tc the scheduling context
*/
static void
-nat_server_read (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+nat_server_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_NAT_Handle *h = cls;
char mybuf[40];
@@ -760,52 +733,53 @@
struct sockaddr_in sin_addr;
h->server_read_task = GNUNET_SCHEDULER_NO_TASK;
- if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
+ if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
return;
- memset (mybuf, 0, sizeof(mybuf));
- bytes = GNUNET_DISK_file_read(h->server_stdout_handle,
- mybuf,
- sizeof(mybuf));
+ memset (mybuf, 0, sizeof (mybuf));
+ bytes = GNUNET_DISK_file_read (h->server_stdout_handle,
+ mybuf, sizeof (mybuf));
if (bytes < 1)
- {
+ {
#if DEBUG_NAT
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "nat",
- "Finished reading from server stdout with code: %d\n",
- bytes);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ "nat",
+ "Finished reading from server stdout with code: %d\n",
+ bytes);
#endif
- if (0 != GNUNET_OS_process_kill (h->server_proc, SIGTERM))
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
- GNUNET_OS_process_wait (h->server_proc);
- GNUNET_OS_process_close (h->server_proc);
- h->server_proc = NULL;
- GNUNET_DISK_pipe_close (h->server_stdout);
- h->server_stdout = NULL;
- h->server_stdout_handle = NULL;
- /* now try to restart it */
- h->server_retry_delay = GNUNET_TIME_relative_multiply
(h->server_retry_delay, 2);
- h->server_retry_delay = GNUNET_TIME_relative_max
(GNUNET_TIME_UNIT_HOURS,
- h->server_retry_delay);
- h->server_read_task = GNUNET_SCHEDULER_add_delayed
(h->server_retry_delay,
- &restart_nat_server,
- h);
- return;
- }
+ if (0 != GNUNET_OS_process_kill (h->server_proc, SIGTERM))
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
+ GNUNET_OS_process_wait (h->server_proc);
+ GNUNET_OS_process_close (h->server_proc);
+ h->server_proc = NULL;
+ GNUNET_DISK_pipe_close (h->server_stdout);
+ h->server_stdout = NULL;
+ h->server_stdout_handle = NULL;
+ /* now try to restart it */
+ h->server_retry_delay =
+ GNUNET_TIME_relative_multiply (h->server_retry_delay, 2);
+ h->server_retry_delay =
+ GNUNET_TIME_relative_max (GNUNET_TIME_UNIT_HOURS,
+ h->server_retry_delay);
+ h->server_read_task =
+ GNUNET_SCHEDULER_add_delayed (h->server_retry_delay,
+ &restart_nat_server, h);
+ return;
+ }
port_start = NULL;
- for (i = 0; i < sizeof(mybuf); i++)
+ for (i = 0; i < sizeof (mybuf); i++)
+ {
+ if (mybuf[i] == '\n')
{
- if (mybuf[i] == '\n')
- {
- mybuf[i] = '\0';
- break;
- }
- if ( (mybuf[i] == ':') && (i + 1 < sizeof(mybuf)) )
- {
- mybuf[i] = '\0';
- port_start = &mybuf[i + 1];
- }
+ mybuf[i] = '\0';
+ break;
}
+ if ((mybuf[i] == ':') && (i + 1 < sizeof (mybuf)))
+ {
+ mybuf[i] = '\0';
+ port_start = &mybuf[i + 1];
+ }
+ }
/* construct socket address of sender */
memset (&sin_addr, 0, sizeof (sin_addr));
@@ -813,37 +787,34 @@
#if HAVE_SOCKADDR_IN_SIN_LEN
sin_addr.sin_len = sizeof (sin_addr);
#endif
- if ( (NULL == port_start) ||
- (1 != sscanf (port_start, "%d", &port)) ||
- (-1 == inet_pton(AF_INET, mybuf, &sin_addr.sin_addr)) )
- {
- /* should we restart gnunet-helper-nat-server? */
- GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
- "nat",
- _("gnunet-helper-nat-server generated malformed address
`%s'\n"),
- mybuf);
- h->server_read_task
- = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- h->server_stdout_handle,
- &nat_server_read,
- h);
- return;
- }
- sin_addr.sin_port = htons((uint16_t) port);
+ if ((NULL == port_start) ||
+ (1 != sscanf (port_start, "%d", &port)) ||
+ (-1 == inet_pton (AF_INET, mybuf, &sin_addr.sin_addr)))
+ {
+ /* should we restart gnunet-helper-nat-server? */
+ GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
+ "nat",
+ _
+ ("gnunet-helper-nat-server generated malformed address
`%s'\n"),
+ mybuf);
+ h->server_read_task =
+ GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ h->server_stdout_handle,
+ &nat_server_read, h);
+ return;
+ }
+ sin_addr.sin_port = htons ((uint16_t) port);
#if DEBUG_NAT
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "nat",
- "gnunet-helper-nat-server read: %s:%d\n",
- mybuf, port);
+ "nat",
+ "gnunet-helper-nat-server read: %s:%d\n", mybuf, port);
#endif
h->reversal_callback (h->callback_cls,
- (const struct sockaddr*) &sin_addr,
- sizeof (sin_addr));
+ (const struct sockaddr *) &sin_addr, sizeof
(sin_addr));
h->server_read_task =
- GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- h->server_stdout_handle,
- &nat_server_read,
- h);
+ GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ h->server_stdout_handle,
+ &nat_server_read, h);
}
@@ -856,51 +827,45 @@
static void
start_gnunet_nat_server (struct GNUNET_NAT_Handle *h)
{
- if ( (h->behind_nat == GNUNET_YES) &&
- (h->enable_nat_server == GNUNET_YES) &&
- (h->internal_address != NULL) &&
- (NULL != (h->server_stdout = GNUNET_DISK_pipe (GNUNET_YES,
- GNUNET_NO,
- GNUNET_YES))) )
- {
+ if ((h->behind_nat == GNUNET_YES) &&
+ (h->enable_nat_server == GNUNET_YES) &&
+ (h->internal_address != NULL) &&
+ (NULL != (h->server_stdout = GNUNET_DISK_pipe (GNUNET_YES,
+ GNUNET_NO, GNUNET_YES))))
+ {
#if DEBUG_NAT
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "nat"
- "Starting %s at `%s'\n",
- "gnunet-helper-nat-server",
- h->internal_address);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ "nat"
+ "Starting %s at `%s'\n",
+ "gnunet-helper-nat-server", h->internal_address);
#endif
- /* Start the server process */
- h->server_proc = GNUNET_OS_start_process (NULL,
- h->server_stdout,
- "gnunet-helper-nat-server",
- "gnunet-helper-nat-server",
- h->internal_address,
- NULL);
- if (h->server_proc == NULL)
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
- "nat",
- _("Failed to start %s\n"),
- "gnunet-helper-nat-server");
- GNUNET_DISK_pipe_close (h->server_stdout);
- h->server_stdout = NULL;
- }
- else
- {
- /* Close the write end of the read pipe */
- GNUNET_DISK_pipe_close_end(h->server_stdout,
- GNUNET_DISK_PIPE_END_WRITE);
- h->server_stdout_handle
- = GNUNET_DISK_pipe_handle (h->server_stdout,
- GNUNET_DISK_PIPE_END_READ);
- h->server_read_task
- = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- h->server_stdout_handle,
- &nat_server_read,
- h);
- }
- }
+ /* Start the server process */
+ h->server_proc = GNUNET_OS_start_process (NULL,
+ h->server_stdout,
+ "gnunet-helper-nat-server",
+ "gnunet-helper-nat-server",
+ h->internal_address, NULL);
+ if (h->server_proc == NULL)
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
+ "nat",
+ _("Failed to start %s\n"), "gnunet-helper-nat-server");
+ GNUNET_DISK_pipe_close (h->server_stdout);
+ h->server_stdout = NULL;
+ }
+ else
+ {
+ /* Close the write end of the read pipe */
+ GNUNET_DISK_pipe_close_end (h->server_stdout,
GNUNET_DISK_PIPE_END_WRITE);
+ h->server_stdout_handle
+ = GNUNET_DISK_pipe_handle (h->server_stdout,
+ GNUNET_DISK_PIPE_END_READ);
+ h->server_read_task
+ = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ h->server_stdout_handle,
+ &nat_server_read, h);
+ }
+ }
}
@@ -911,16 +876,15 @@
* @param tc scheduler context
*/
static void
-list_interfaces (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+list_interfaces (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_NAT_Handle *h = cls;
h->ifc_task = GNUNET_SCHEDULER_NO_TASK;
remove_from_address_list_by_source (h, LAL_INTERFACE_ADDRESS);
- GNUNET_OS_network_interfaces_list (&process_interfaces, h);
+ GNUNET_OS_network_interfaces_list (&process_interfaces, h);
h->ifc_task = GNUNET_SCHEDULER_add_delayed (h->ifc_scan_frequency,
- &list_interfaces, h);
+ &list_interfaces, h);
}
@@ -931,17 +895,15 @@
* @param tc scheduler context
*/
static void
-resolve_hostname (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+resolve_hostname (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_NAT_Handle *h = cls;
-
+
h->hostname_task = GNUNET_SCHEDULER_NO_TASK;
remove_from_address_list_by_source (h, LAL_HOSTNAME_DNS);
h->hostname_dns = GNUNET_RESOLVER_hostname_resolve (AF_UNSPEC,
- HOSTNAME_RESOLVE_TIMEOUT,
- &process_hostname_ip,
- h);
+ HOSTNAME_RESOLVE_TIMEOUT,
+ &process_hostname_ip, h);
}
@@ -953,18 +915,16 @@
* @param tc scheduler context
*/
static void
-resolve_dns (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+resolve_dns (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_NAT_Handle *h = cls;
-
+
h->dns_task = GNUNET_SCHEDULER_NO_TASK;
remove_from_address_list_by_source (h, LAL_EXTERNAL_IP);
h->ext_dns = GNUNET_RESOLVER_ip_get (h->external_address,
- AF_INET,
- GNUNET_TIME_UNIT_MINUTES,
- &process_external_ip,
- h);
+ AF_INET,
+ GNUNET_TIME_UNIT_MINUTES,
+ &process_external_ip, h);
}
@@ -977,45 +937,35 @@
* @param addr either the previous or the new public IP address
* @param addrlen actual lenght of the address
*/
-static void
-upnp_add (void *cls,
- int add_remove,
- const struct sockaddr *addr,
- socklen_t addrlen)
+static void
+upnp_add (void *cls,
+ int add_remove, const struct sockaddr *addr, socklen_t addrlen)
{
struct GNUNET_NAT_Handle *h = cls;
struct LocalAddressList *pos;
struct LocalAddressList *next;
if (GNUNET_YES == add_remove)
- {
- add_to_address_list (h,
- LAL_UPNP,
- addr, addrlen);
- return;
- }
+ {
+ add_to_address_list (h, LAL_UPNP, addr, addrlen);
+ return;
+ }
/* remove address */
next = h->lal_head;
while (NULL != (pos = next))
- {
- next = pos->next;
- if ( (pos->source != LAL_UPNP) ||
- (pos->addrlen != addrlen) ||
- (0 != memcmp (&pos[1],
- addr,
- addrlen)) )
- continue;
- GNUNET_CONTAINER_DLL_remove (h->lal_head,
- h->lal_tail,
- pos);
- if (NULL != h->address_callback)
- h->address_callback (h->callback_cls,
- GNUNET_NO,
- (const struct sockaddr* ) &pos[1],
- pos->addrlen);
- GNUNET_free (pos);
- return; /* only remove once */
- }
+ {
+ next = pos->next;
+ if ((pos->source != LAL_UPNP) ||
+ (pos->addrlen != addrlen) || (0 != memcmp (&pos[1], addr, addrlen)))
+ continue;
+ GNUNET_CONTAINER_DLL_remove (h->lal_head, h->lal_tail, pos);
+ if (NULL != h->address_callback)
+ h->address_callback (h->callback_cls,
+ GNUNET_NO,
+ (const struct sockaddr *) &pos[1], pos->addrlen);
+ GNUNET_free (pos);
+ return; /* only remove once */
+ }
/* asked to remove address that does not exist */
GNUNET_break (0);
}
@@ -1028,26 +978,21 @@
* @param port port to map with UPnP
*/
static void
-add_minis (struct GNUNET_NAT_Handle *h,
- uint16_t port)
+add_minis (struct GNUNET_NAT_Handle *h, uint16_t port)
{
struct MiniList *ml;
ml = h->mini_head;
while (NULL != ml)
- {
- if (port == ml->port)
- return; /* already got this port */
- ml = ml->next;
- }
+ {
+ if (port == ml->port)
+ return; /* already got this port */
+ ml = ml->next;
+ }
ml = GNUNET_malloc (sizeof (struct MiniList));
ml->port = port;
- ml->mini = GNUNET_NAT_mini_map_start (port,
- h->is_tcp,
- &upnp_add, h);
- GNUNET_CONTAINER_DLL_insert (h->mini_head,
- h->mini_tail,
- ml);
+ ml->mini = GNUNET_NAT_mini_map_start (port, h->is_tcp, &upnp_add, h);
+ GNUNET_CONTAINER_DLL_insert (h->mini_head, h->mini_tail, ml);
}
@@ -1058,8 +1003,7 @@
* @param tc scheduler context
*/
static void
-add_from_bind (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+add_from_bind (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
static struct in6_addr any = IN6ADDR_ANY_INIT;
struct GNUNET_NAT_Handle *h = cls;
@@ -1068,38 +1012,39 @@
const struct sockaddr_in *v4;
h->bind_task = GNUNET_SCHEDULER_NO_TASK;
- for (i=0;i<h->num_local_addrs;i++)
+ for (i = 0; i < h->num_local_addrs; i++)
+ {
+ sa = h->local_addrs[i];
+ switch (sa->sa_family)
{
- sa = h->local_addrs[i];
- switch (sa->sa_family)
- {
- case AF_INET:
- if (sizeof (struct sockaddr_in) != h->local_addrlens[i])
- {
- GNUNET_break (0);
- break;
- }
- v4 = (const struct sockaddr_in*) sa;
- if (0 != v4->sin_addr.s_addr)
- add_to_address_list (h, LAL_BINDTO_ADDRESS, sa, sizeof (struct
sockaddr_in));
- if (h->enable_upnp)
- add_minis (h, ntohs (v4->sin_port));
- break;
- case AF_INET6:
- if (sizeof (struct sockaddr_in6) != h->local_addrlens[i])
- {
- GNUNET_break (0);
- break;
- }
- if (0 != memcmp (&((const struct sockaddr_in6*) sa)->sin6_addr,
- &any,
- sizeof (struct in6_addr)))
- add_to_address_list (h, LAL_BINDTO_ADDRESS, sa, sizeof (struct
sockaddr_in6));
- break;
- default:
- break;
- }
+ case AF_INET:
+ if (sizeof (struct sockaddr_in) != h->local_addrlens[i])
+ {
+ GNUNET_break (0);
+ break;
+ }
+ v4 = (const struct sockaddr_in *) sa;
+ if (0 != v4->sin_addr.s_addr)
+ add_to_address_list (h, LAL_BINDTO_ADDRESS, sa,
+ sizeof (struct sockaddr_in));
+ if (h->enable_upnp)
+ add_minis (h, ntohs (v4->sin_port));
+ break;
+ case AF_INET6:
+ if (sizeof (struct sockaddr_in6) != h->local_addrlens[i])
+ {
+ GNUNET_break (0);
+ break;
+ }
+ if (0 != memcmp (&((const struct sockaddr_in6 *) sa)->sin6_addr,
+ &any, sizeof (struct in6_addr)))
+ add_to_address_list (h, LAL_BINDTO_ADDRESS, sa,
+ sizeof (struct sockaddr_in6));
+ break;
+ default:
+ break;
}
+ }
}
@@ -1124,14 +1069,14 @@
*/
struct GNUNET_NAT_Handle *
GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg,
- int is_tcp,
- uint16_t adv_port,
- unsigned int num_addrs,
- const struct sockaddr **addrs,
- const socklen_t *addrlens,
- GNUNET_NAT_AddressCallback address_callback,
- GNUNET_NAT_ReversalCallback reversal_callback,
- void *callback_cls)
+ int is_tcp,
+ uint16_t adv_port,
+ unsigned int num_addrs,
+ const struct sockaddr **addrs,
+ const socklen_t * addrlens,
+ GNUNET_NAT_AddressCallback address_callback,
+ GNUNET_NAT_ReversalCallback reversal_callback,
+ void *callback_cls)
{
struct GNUNET_NAT_Handle *h;
struct in_addr in_addr;
@@ -1139,10 +1084,9 @@
#if DEBUG_NAT
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "nat",
- "Registered with NAT service at port %u with %u IP bound
local addresses\n",
- (unsigned int) adv_port,
- num_addrs);
+ "nat",
+ "Registered with NAT service at port %u with %u IP bound
local addresses\n",
+ (unsigned int) adv_port, num_addrs);
#endif
h = GNUNET_malloc (sizeof (struct GNUNET_NAT_Handle));
h->server_retry_delay = GNUNET_TIME_UNIT_SECONDS;
@@ -1154,147 +1098,140 @@
h->num_local_addrs = num_addrs;
h->adv_port = adv_port;
if (num_addrs != 0)
+ {
+ h->local_addrs = GNUNET_malloc (num_addrs * sizeof (struct sockaddr *));
+ h->local_addrlens = GNUNET_malloc (num_addrs * sizeof (socklen_t));
+ for (i = 0; i < num_addrs; i++)
{
- h->local_addrs = GNUNET_malloc (num_addrs * sizeof (struct sockaddr*));
- h->local_addrlens = GNUNET_malloc (num_addrs * sizeof (socklen_t));
- for (i=0;i<num_addrs;i++)
- {
- GNUNET_assert (addrlens[i] > 0);
- GNUNET_assert (addrs[i] != NULL);
- h->local_addrlens[i] = addrlens[i];
- h->local_addrs[i] = GNUNET_malloc (addrlens[i]);
- memcpy (h->local_addrs[i], addrs[i], addrlens[i]);
- }
+ GNUNET_assert (addrlens[i] > 0);
+ GNUNET_assert (addrs[i] != NULL);
+ h->local_addrlens[i] = addrlens[i];
+ h->local_addrs[i] = GNUNET_malloc (addrlens[i]);
+ memcpy (h->local_addrs[i], addrs[i], addrlens[i]);
}
+ }
h->bind_task = GNUNET_SCHEDULER_add_now (&add_from_bind, h);
if (GNUNET_OK ==
- GNUNET_CONFIGURATION_have_value (cfg,
- "nat",
- "INTERNAL_ADDRESS"))
- {
- (void) GNUNET_CONFIGURATION_get_value_string (cfg,
- "nat",
- "INTERNAL_ADDRESS",
- &h->internal_address);
- }
- if ( (h->internal_address != NULL) &&
- (inet_pton(AF_INET, h->internal_address, &in_addr) != 1) )
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
- "nat",
- _("Malformed %s `%s' given in configuration!\n"),
- "INTERNAL_ADDRESS",
- h->internal_address);
- GNUNET_free (h->internal_address);
- h->internal_address = NULL;
- }
+ GNUNET_CONFIGURATION_have_value (cfg, "nat", "INTERNAL_ADDRESS"))
+ {
+ (void) GNUNET_CONFIGURATION_get_value_string (cfg,
+ "nat",
+ "INTERNAL_ADDRESS",
+ &h->internal_address);
+ }
+ if ((h->internal_address != NULL) &&
+ (inet_pton (AF_INET, h->internal_address, &in_addr) != 1))
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
+ "nat",
+ _("Malformed %s `%s' given in configuration!\n"),
+ "INTERNAL_ADDRESS", h->internal_address);
+ GNUNET_free (h->internal_address);
+ h->internal_address = NULL;
+ }
if (GNUNET_OK ==
- GNUNET_CONFIGURATION_have_value (cfg,
- "nat",
- "EXTERNAL_ADDRESS"))
- {
- (void) GNUNET_CONFIGURATION_get_value_string (cfg,
- "nat",
- "EXTERNAL_ADDRESS",
- &h->external_address);
- }
- if ( (h->external_address != NULL) &&
- (inet_pton(AF_INET, h->external_address, &in_addr) != 1) )
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
- "nat",
- _("Malformed %s `%s' given in configuration!\n"),
- "EXTERNAL_ADDRESS",
- h->external_address);
- GNUNET_free (h->external_address);
- h->external_address = NULL;
- }
+ GNUNET_CONFIGURATION_have_value (cfg, "nat", "EXTERNAL_ADDRESS"))
+ {
+ (void) GNUNET_CONFIGURATION_get_value_string (cfg,
+ "nat",
+ "EXTERNAL_ADDRESS",
+ &h->external_address);
+ }
+ if ((h->external_address != NULL) &&
+ (inet_pton (AF_INET, h->external_address, &in_addr) != 1))
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
+ "nat",
+ _("Malformed %s `%s' given in configuration!\n"),
+ "EXTERNAL_ADDRESS", h->external_address);
+ GNUNET_free (h->external_address);
+ h->external_address = NULL;
+ }
h->behind_nat = GNUNET_CONFIGURATION_get_value_yesno (cfg,
- "nat",
- "BEHIND_NAT");
+ "nat", "BEHIND_NAT");
h->nat_punched = GNUNET_CONFIGURATION_get_value_yesno (cfg,
- "nat",
- "PUNCHED_NAT");
+ "nat", "PUNCHED_NAT");
h->enable_nat_client = GNUNET_CONFIGURATION_get_value_yesno (cfg,
- "nat",
-
"ENABLE_NAT_CLIENT");
+ "nat",
+
"ENABLE_NAT_CLIENT");
h->enable_nat_server = GNUNET_CONFIGURATION_get_value_yesno (cfg,
- "nat",
-
"ENABLE_NAT_SERVER");
+ "nat",
+
"ENABLE_NAT_SERVER");
h->enable_upnp = GNUNET_CONFIGURATION_get_value_yesno (cfg,
- "nat",
- "ENABLE_UPNP");
+ "nat", "ENABLE_UPNP");
h->use_localaddresses = GNUNET_CONFIGURATION_get_value_yesno (cfg,
- "nat",
-
"USE_LOCALADDR");
+ "nat",
+
"USE_LOCALADDR");
h->use_hostname = GNUNET_CONFIGURATION_get_value_yesno (cfg,
- "nat",
- "USE_HOSTNAME");
- h->disable_ipv6 = GNUNET_CONFIGURATION_get_value_yesno(cfg,
- "nat",
- "DISABLEV6");
+ "nat",
+ "USE_HOSTNAME");
+ h->disable_ipv6 = GNUNET_CONFIGURATION_get_value_yesno (cfg,
+ "nat", "DISABLEV6");
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_time (cfg,
- "nat",
- "DYNDNS_FREQUENCY",
- &h->dyndns_frequency))
+ "nat",
+ "DYNDNS_FREQUENCY",
+ &h->dyndns_frequency))
h->dyndns_frequency = DYNDNS_FREQUENCY;
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_time (cfg,
- "nat",
- "IFC_SCAN_FREQUENCY",
- &h->ifc_scan_frequency))
+ "nat",
+ "IFC_SCAN_FREQUENCY",
+ &h->ifc_scan_frequency))
h->ifc_scan_frequency = IFC_SCAN_FREQUENCY;
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_time (cfg,
- "nat",
- "HOSTNAME_DNS_FREQUENCY",
- &h->hostname_dns_frequency))
+ "nat",
+ "HOSTNAME_DNS_FREQUENCY",
+ &h->hostname_dns_frequency))
h->hostname_dns_frequency = HOSTNAME_DNS_FREQUENCY;
if (NULL == reversal_callback)
h->enable_nat_server = GNUNET_NO;
/* Check if NAT was hole-punched */
- if ( (NULL != h->address_callback) &&
- (h->external_address != NULL) &&
- (h->nat_punched == GNUNET_YES) )
- {
- h->dns_task = GNUNET_SCHEDULER_add_now (&resolve_dns, h);
- h->enable_nat_server = GNUNET_NO;
- h->enable_upnp = GNUNET_NO;
- }
+ if ((NULL != h->address_callback) &&
+ (h->external_address != NULL) && (h->nat_punched == GNUNET_YES))
+ {
+ h->dns_task = GNUNET_SCHEDULER_add_now (&resolve_dns, h);
+ h->enable_nat_server = GNUNET_NO;
+ h->enable_upnp = GNUNET_NO;
+ }
/* Test for SUID binaries */
- if ( (h->behind_nat == GNUNET_YES) &&
- (GNUNET_YES == h->enable_nat_server) &&
- (GNUNET_YES !=
GNUNET_OS_check_helper_binary("gnunet-helper-nat-server")) )
- {
- h->enable_nat_server = GNUNET_NO;
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Configuration requires `%s', but binary is not installed
properly (SUID bit not set). Option disabled.\n"),
- "gnunet-helper-nat-server");
- }
- if ( (GNUNET_YES == h->enable_nat_client) &&
- (GNUNET_YES !=
GNUNET_OS_check_helper_binary("gnunet-helper-nat-client")) )
- {
- h->enable_nat_client = GNUNET_NO;
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Configuration requires `%s', but binary is not installed
properly (SUID bit not set). Option disabled.\n"),
- "gnunet-helper-nat-client");
- }
+ if ((h->behind_nat == GNUNET_YES) &&
+ (GNUNET_YES == h->enable_nat_server) &&
+ (GNUNET_YES !=
+ GNUNET_OS_check_helper_binary ("gnunet-helper-nat-server")))
+ {
+ h->enable_nat_server = GNUNET_NO;
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Configuration requires `%s', but binary is not installed
properly (SUID bit not set). Option disabled.\n"),
+ "gnunet-helper-nat-server");
+ }
+ if ((GNUNET_YES == h->enable_nat_client) &&
+ (GNUNET_YES !=
+ GNUNET_OS_check_helper_binary ("gnunet-helper-nat-client")))
+ {
+ h->enable_nat_client = GNUNET_NO;
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Configuration requires `%s', but binary is not installed
properly (SUID bit not set). Option disabled.\n"),
+ "gnunet-helper-nat-client");
+ }
start_gnunet_nat_server (h);
/* FIXME: add support for UPnP, etc */
if (NULL != h->address_callback)
- {
- h->ifc_task = GNUNET_SCHEDULER_add_now (&list_interfaces, h);
- if (GNUNET_YES == h->use_hostname)
- h->hostname_task = GNUNET_SCHEDULER_add_now (&resolve_hostname, h);
- }
+ {
+ h->ifc_task = GNUNET_SCHEDULER_add_now (&list_interfaces, h);
+ if (GNUNET_YES == h->use_hostname)
+ h->hostname_task = GNUNET_SCHEDULER_add_now (&resolve_hostname, h);
+ }
return h;
}
@@ -1314,84 +1251,79 @@
struct MiniList *ml;
while (NULL != (ml = h->mini_head))
- {
- GNUNET_CONTAINER_DLL_remove (h->mini_head,
- h->mini_tail,
- ml);
- if (NULL != ml->mini)
- GNUNET_NAT_mini_map_stop (ml->mini);
- GNUNET_free (ml);
- }
+ {
+ GNUNET_CONTAINER_DLL_remove (h->mini_head, h->mini_tail, ml);
+ if (NULL != ml->mini)
+ GNUNET_NAT_mini_map_stop (ml->mini);
+ GNUNET_free (ml);
+ }
if (h->ext_dns != NULL)
- {
- GNUNET_RESOLVER_request_cancel (h->ext_dns);
- h->ext_dns = NULL;
- }
+ {
+ GNUNET_RESOLVER_request_cancel (h->ext_dns);
+ h->ext_dns = NULL;
+ }
if (NULL != h->hostname_dns)
- {
- GNUNET_RESOLVER_request_cancel (h->hostname_dns);
- h->hostname_dns = NULL;
- }
+ {
+ GNUNET_RESOLVER_request_cancel (h->hostname_dns);
+ h->hostname_dns = NULL;
+ }
if (GNUNET_SCHEDULER_NO_TASK != h->server_read_task)
- {
- GNUNET_SCHEDULER_cancel (h->server_read_task);
- h->server_read_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (h->server_read_task);
+ h->server_read_task = GNUNET_SCHEDULER_NO_TASK;
+ }
if (GNUNET_SCHEDULER_NO_TASK != h->bind_task)
- {
- GNUNET_SCHEDULER_cancel (h->bind_task);
- h->bind_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (h->bind_task);
+ h->bind_task = GNUNET_SCHEDULER_NO_TASK;
+ }
if (GNUNET_SCHEDULER_NO_TASK != h->ifc_task)
- {
- GNUNET_SCHEDULER_cancel (h->ifc_task);
- h->ifc_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (h->ifc_task);
+ h->ifc_task = GNUNET_SCHEDULER_NO_TASK;
+ }
if (GNUNET_SCHEDULER_NO_TASK != h->hostname_task)
- {
- GNUNET_SCHEDULER_cancel (h->hostname_task);
- h->hostname_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (h->hostname_task);
+ h->hostname_task = GNUNET_SCHEDULER_NO_TASK;
+ }
if (GNUNET_SCHEDULER_NO_TASK != h->dns_task)
- {
- GNUNET_SCHEDULER_cancel (h->dns_task);
- h->dns_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (h->dns_task);
+ h->dns_task = GNUNET_SCHEDULER_NO_TASK;
+ }
if (NULL != h->server_proc)
- {
- if (0 != GNUNET_OS_process_kill (h->server_proc, SIGTERM))
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
- GNUNET_OS_process_wait (h->server_proc);
- GNUNET_OS_process_close (h->server_proc);
- h->server_proc = NULL;
- GNUNET_DISK_pipe_close (h->server_stdout);
- h->server_stdout = NULL;
- h->server_stdout_handle = NULL;
- }
+ {
+ if (0 != GNUNET_OS_process_kill (h->server_proc, SIGTERM))
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
+ GNUNET_OS_process_wait (h->server_proc);
+ GNUNET_OS_process_close (h->server_proc);
+ h->server_proc = NULL;
+ GNUNET_DISK_pipe_close (h->server_stdout);
+ h->server_stdout = NULL;
+ h->server_stdout_handle = NULL;
+ }
if (NULL != h->server_stdout)
- {
- GNUNET_DISK_pipe_close (h->server_stdout);
- h->server_stdout = NULL;
- h->server_stdout_handle = NULL;
- }
+ {
+ GNUNET_DISK_pipe_close (h->server_stdout);
+ h->server_stdout = NULL;
+ h->server_stdout_handle = NULL;
+ }
while (NULL != (lal = h->lal_head))
- {
- GNUNET_CONTAINER_DLL_remove (h->lal_head,
- h->lal_tail,
- lal);
- if (NULL != h->address_callback)
- h->address_callback (h->callback_cls,
- GNUNET_NO,
- (const struct sockaddr*) &lal[1],
- lal->addrlen);
- GNUNET_free (lal);
- }
- for (i=0;i<h->num_local_addrs;i++)
+ {
+ GNUNET_CONTAINER_DLL_remove (h->lal_head, h->lal_tail, lal);
+ if (NULL != h->address_callback)
+ h->address_callback (h->callback_cls,
+ GNUNET_NO,
+ (const struct sockaddr *) &lal[1], lal->addrlen);
+ GNUNET_free (lal);
+ }
+ for (i = 0; i < h->num_local_addrs; i++)
GNUNET_free (h->local_addrs[i]);
GNUNET_free_non_null (h->local_addrs);
GNUNET_free_non_null (h->local_addrlens);
GNUNET_free_non_null (h->external_address);
- GNUNET_free_non_null (h->internal_address);
+ GNUNET_free_non_null (h->internal_address);
GNUNET_free (h);
}
@@ -1406,54 +1338,46 @@
*/
void
GNUNET_NAT_run_client (struct GNUNET_NAT_Handle *h,
- const struct sockaddr_in *sa)
+ const struct sockaddr_in *sa)
{
char inet4[INET_ADDRSTRLEN];
char port_as_string[6];
struct GNUNET_OS_Process *proc;
- if (GNUNET_YES != h->enable_nat_client)
- return; /* not permitted / possible */
+ if (GNUNET_YES != h->enable_nat_client)
+ return; /* not permitted / possible */
if (h->internal_address == NULL)
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
- "nat",
- _("Internal IP address not known, cannot use ICMP NAT
traversal method\n"));
- return;
- }
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
+ "nat",
+ _
+ ("Internal IP address not known, cannot use ICMP NAT
traversal method\n"));
+ return;
+ }
GNUNET_assert (sa->sin_family == AF_INET);
- if (NULL == inet_ntop (AF_INET,
- &sa->sin_addr,
- inet4, INET_ADDRSTRLEN))
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop");
- return;
- }
- GNUNET_snprintf (port_as_string,
- sizeof (port_as_string),
- "%d",
- h->adv_port);
+ if (NULL == inet_ntop (AF_INET, &sa->sin_addr, inet4, INET_ADDRSTRLEN))
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop");
+ return;
+ }
+ GNUNET_snprintf (port_as_string, sizeof (port_as_string), "%d", h->adv_port);
#if DEBUG_NAT
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "nat",
- _("Running gnunet-helper-nat-client %s %s %u\n"),
- h->internal_address,
- inet4,
- (unsigned int) h->adv_port);
+ "nat",
+ _("Running gnunet-helper-nat-client %s %s %u\n"),
+ h->internal_address, inet4, (unsigned int) h->adv_port);
#endif
- proc = GNUNET_OS_start_process (NULL,
- NULL,
- "gnunet-helper-nat-client",
- "gnunet-helper-nat-client",
- h->internal_address,
- inet4,
- port_as_string,
- NULL);
+ proc = GNUNET_OS_start_process (NULL,
+ NULL,
+ "gnunet-helper-nat-client",
+ "gnunet-helper-nat-client",
+ h->internal_address,
+ inet4, port_as_string, NULL);
if (NULL == proc)
return;
/* we know that the gnunet-helper-nat-client will terminate virtually
- instantly */
+ * instantly */
GNUNET_OS_process_wait (proc);
GNUNET_OS_process_close (proc);
}
@@ -1471,44 +1395,43 @@
*/
int
GNUNET_NAT_test_address (struct GNUNET_NAT_Handle *h,
- const void *addr,
- socklen_t addrlen)
+ const void *addr, socklen_t addrlen)
{
struct LocalAddressList *pos;
const struct sockaddr_in *in4;
const struct sockaddr_in6 *in6;
-
- if ( (addrlen != sizeof (struct in_addr)) &&
- (addrlen != sizeof (struct in6_addr)) )
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
+
+ if ((addrlen != sizeof (struct in_addr)) &&
+ (addrlen != sizeof (struct in6_addr)))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
pos = h->lal_head;
while (NULL != pos)
+ {
+ if (pos->addrlen == sizeof (struct sockaddr_in))
{
- if (pos->addrlen == sizeof (struct sockaddr_in))
- {
- in4 = (struct sockaddr_in* ) &pos[1];
- if ( (addrlen == sizeof (struct in_addr)) &&
- (0 == memcmp (&in4->sin_addr, addr, sizeof (struct in_addr))) )
- return GNUNET_YES;
- }
- else if (pos->addrlen == sizeof (struct sockaddr_in6))
- {
- in6 = (struct sockaddr_in6* ) &pos[1];
- if ( (addrlen == sizeof (struct in6_addr)) &&
- (0 == memcmp (&in6->sin6_addr, addr, sizeof (struct in6_addr))) )
- return GNUNET_YES;
- }
- else
- {
- GNUNET_assert (0);
- }
- pos = pos->next;
+ in4 = (struct sockaddr_in *) &pos[1];
+ if ((addrlen == sizeof (struct in_addr)) &&
+ (0 == memcmp (&in4->sin_addr, addr, sizeof (struct in_addr))))
+ return GNUNET_YES;
}
+ else if (pos->addrlen == sizeof (struct sockaddr_in6))
+ {
+ in6 = (struct sockaddr_in6 *) &pos[1];
+ if ((addrlen == sizeof (struct in6_addr)) &&
+ (0 == memcmp (&in6->sin6_addr, addr, sizeof (struct in6_addr))))
+ return GNUNET_YES;
+ }
+ else
+ {
+ GNUNET_assert (0);
+ }
+ pos = pos->next;
+ }
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Asked to validate one of my addresses and validation failed!\n");
+ "Asked to validate one of my addresses and validation
failed!\n");
return GNUNET_NO;
}
Modified: gnunet/src/nat/nat.h
===================================================================
--- gnunet/src/nat/nat.h 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/nat/nat.h 2011-08-15 21:46:35 UTC (rev 16581)
@@ -35,17 +35,17 @@
{
/**
* Header with type "GNUNET_MESSAGE_TYPE_NAT_TEST"
- */
+ */
struct GNUNET_MessageHeader header;
/**
* IPv4 target IP address
- */
+ */
uint32_t dst_ipv4;
/**
* Port to use, 0 to send dummy ICMP response.
- */
+ */
uint16_t dport;
/**
Modified: gnunet/src/nat/nat_mini.c
===================================================================
--- gnunet/src/nat/nat_mini.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/nat/nat_mini.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -109,8 +109,7 @@
* @param tc scheduler context
*/
static void
-read_external_ipv4 (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+read_external_ipv4 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_NAT_ExternalHandle *eh = cls;
ssize_t ret;
@@ -118,39 +117,34 @@
int iret;
eh->task = GNUNET_SCHEDULER_NO_TASK;
- if (GNUNET_YES ==
- GNUNET_NETWORK_fdset_handle_isset (tc->read_ready,
- eh->r))
+ if (GNUNET_YES == GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, eh->r))
ret = GNUNET_DISK_file_read (eh->r,
- &eh->buf[eh->off],
- sizeof (eh->buf)-eh->off);
+ &eh->buf[eh->off], sizeof (eh->buf) -
eh->off);
else
- ret = -1; /* error reading, timeout, etc. */
+ ret = -1; /* error reading, timeout, etc. */
if (ret > 0)
- {
- /* try to read more */
- eh->off += ret;
- eh->task = GNUNET_SCHEDULER_add_read_file
(GNUNET_TIME_absolute_get_remaining (eh->timeout),
- eh->r,
- &read_external_ipv4,
- eh);
- return;
- }
+ {
+ /* try to read more */
+ eh->off += ret;
+ eh->task =
+ GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_absolute_get_remaining
+ (eh->timeout), eh->r,
+ &read_external_ipv4, eh);
+ return;
+ }
iret = GNUNET_NO;
- if ( (eh->off > 7) &&
- (eh->buf[eh->off-1] == '\n') )
+ if ((eh->off > 7) && (eh->buf[eh->off - 1] == '\n'))
+ {
+ eh->buf[eh->off - 1] = '\0';
+ if (1 == inet_pton (AF_INET, eh->buf, &addr))
{
- eh->buf[eh->off-1] = '\0';
- if (1 == inet_pton (AF_INET, eh->buf, &addr))
- {
- if (addr.s_addr == 0)
- iret = GNUNET_NO; /* got 0.0.0.0 */
- else
- iret = GNUNET_OK;
- }
+ if (addr.s_addr == 0)
+ iret = GNUNET_NO; /* got 0.0.0.0 */
+ else
+ iret = GNUNET_OK;
}
- eh->cb (eh->cb_cls,
- (iret == GNUNET_OK) ? &addr : NULL);
+ }
+ eh->cb (eh->cb_cls, (iret == GNUNET_OK) ? &addr : NULL);
GNUNET_NAT_mini_get_external_ipv4_cancel (eh);
}
@@ -165,40 +159,33 @@
*/
struct GNUNET_NAT_ExternalHandle *
GNUNET_NAT_mini_get_external_ipv4 (struct GNUNET_TIME_Relative timeout,
- GNUNET_NAT_IPCallback cb,
- void *cb_cls)
+ GNUNET_NAT_IPCallback cb, void *cb_cls)
{
struct GNUNET_NAT_ExternalHandle *eh;
eh = GNUNET_malloc (sizeof (struct GNUNET_NAT_ExternalHandle));
eh->cb = cb;
eh->cb_cls = cb_cls;
- eh->opipe = GNUNET_DISK_pipe (GNUNET_YES,
- GNUNET_NO,
- GNUNET_YES);
+ eh->opipe = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_NO, GNUNET_YES);
if (NULL == eh->opipe)
- {
- GNUNET_free (eh);
- return NULL;
- }
+ {
+ GNUNET_free (eh);
+ return NULL;
+ }
eh->eip = GNUNET_OS_start_process (NULL,
- eh->opipe,
- "external-ip",
- "external-ip", NULL);
+ eh->opipe,
+ "external-ip", "external-ip", NULL);
if (NULL == eh->eip)
- {
- GNUNET_DISK_pipe_close (eh->opipe);
- GNUNET_free (eh);
- return NULL;
- }
+ {
+ GNUNET_DISK_pipe_close (eh->opipe);
+ GNUNET_free (eh);
+ return NULL;
+ }
GNUNET_DISK_pipe_close_end (eh->opipe, GNUNET_DISK_PIPE_END_WRITE);
eh->timeout = GNUNET_TIME_relative_to_absolute (timeout);
- eh->r = GNUNET_DISK_pipe_handle (eh->opipe,
- GNUNET_DISK_PIPE_END_READ);
+ eh->r = GNUNET_DISK_pipe_handle (eh->opipe, GNUNET_DISK_PIPE_END_READ);
eh->task = GNUNET_SCHEDULER_add_read_file (timeout,
- eh->r,
- &read_external_ipv4,
- eh);
+ eh->r, &read_external_ipv4, eh);
return eh;
}
@@ -222,7 +209,7 @@
/**
* Handle to a mapping created with upnpc.
- */
+ */
struct GNUNET_NAT_MiniHandle
{
@@ -274,7 +261,7 @@
/**
* Did we find our mapping during refresh scan?
- */
+ */
int found;
/**
@@ -292,8 +279,7 @@
* @param tc scheduler context
*/
static void
-do_refresh (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+do_refresh (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
/**
@@ -302,9 +288,7 @@
* @param cls the 'struct GNUNET_NAT_MiniHandle'
* @param line line of output, NULL at the end
*/
-static void
-process_map_output (void *cls,
- const char *line);
+static void process_map_output (void *cls, const char *line);
/**
@@ -315,8 +299,7 @@
* @param line line of output, NULL at the end
*/
static void
-process_refresh_output (void *cls,
- const char *line)
+process_refresh_output (void *cls, const char *line)
{
struct GNUNET_NAT_MiniHandle *mini = cls;
char pstr[9];
@@ -325,99 +308,92 @@
struct in_addr exip;
if (NULL == line)
+ {
+ GNUNET_OS_command_stop (mini->refresh_cmd);
+ mini->refresh_cmd = NULL;
+ if (mini->found == GNUNET_NO)
{
- GNUNET_OS_command_stop (mini->refresh_cmd);
- mini->refresh_cmd = NULL;
- if (mini->found == GNUNET_NO)
- {
- /* mapping disappeared, try to re-create */
- if (mini->did_map)
- {
- mini->ac (mini->ac_cls, GNUNET_NO,
- (const struct sockaddr*) &mini->current_addr,
- sizeof (mini->current_addr));
- mini->did_map = GNUNET_NO;
- }
- GNUNET_snprintf (pstr, sizeof (pstr),
- "%u",
- (unsigned int) mini->port);
- mini->map_cmd = GNUNET_OS_command_run (&process_map_output,
- mini,
- MAP_TIMEOUT,
- "upnpc",
- "upnpc",
- "-r", pstr,
- mini->is_tcp ? "tcp" : "udp",
- NULL);
- if (NULL != mini->map_cmd)
- return;
- }
- mini->refresh_task = GNUNET_SCHEDULER_add_delayed (MAP_REFRESH_FREQ,
- &do_refresh,
- mini);
- return;
+ /* mapping disappeared, try to re-create */
+ if (mini->did_map)
+ {
+ mini->ac (mini->ac_cls, GNUNET_NO,
+ (const struct sockaddr *) &mini->current_addr,
+ sizeof (mini->current_addr));
+ mini->did_map = GNUNET_NO;
+ }
+ GNUNET_snprintf (pstr, sizeof (pstr), "%u", (unsigned int) mini->port);
+ mini->map_cmd = GNUNET_OS_command_run (&process_map_output,
+ mini,
+ MAP_TIMEOUT,
+ "upnpc",
+ "upnpc",
+ "-r", pstr,
+ mini->is_tcp ? "tcp" : "udp",
+ NULL);
+ if (NULL != mini->map_cmd)
+ return;
}
- if (! mini->did_map)
- return; /* never mapped, won't find our mapping anyway */
+ mini->refresh_task = GNUNET_SCHEDULER_add_delayed (MAP_REFRESH_FREQ,
+ &do_refresh, mini);
+ return;
+ }
+ if (!mini->did_map)
+ return; /* never mapped, won't find our mapping anyway
*/
/* we're looking for output of the form:
- "ExternalIPAddress = 12.134.41.124" */
+ * "ExternalIPAddress = 12.134.41.124" */
s = strstr (line, "ExternalIPAddress = ");
if (NULL != s)
- {
- s += strlen ("ExternalIPAddress = ");
- if (1 != inet_pton (AF_INET,
- s, &exip))
- return; /* skip */
- if (exip.s_addr == mini->current_addr.sin_addr.s_addr)
- return; /* no change */
- /* update mapping */
- mini->ac (mini->ac_cls, GNUNET_NO,
- (const struct sockaddr*) &mini->current_addr,
- sizeof (mini->current_addr));
- mini->current_addr.sin_addr = exip;
- mini->ac (mini->ac_cls, GNUNET_YES,
- (const struct sockaddr*) &mini->current_addr,
- sizeof (mini->current_addr));
- return;
- }
+ {
+ s += strlen ("ExternalIPAddress = ");
+ if (1 != inet_pton (AF_INET, s, &exip))
+ return; /* skip */
+ if (exip.s_addr == mini->current_addr.sin_addr.s_addr)
+ return; /* no change */
+ /* update mapping */
+ mini->ac (mini->ac_cls, GNUNET_NO,
+ (const struct sockaddr *) &mini->current_addr,
+ sizeof (mini->current_addr));
+ mini->current_addr.sin_addr = exip;
+ mini->ac (mini->ac_cls, GNUNET_YES,
+ (const struct sockaddr *) &mini->current_addr,
+ sizeof (mini->current_addr));
+ return;
+ }
/*
- we're looking for output of the form:
-
- "0 TCP 3000->192.168.2.150:3000 'libminiupnpc' ''"
- "1 UDP 3001->192.168.2.150:3001 'libminiupnpc' ''"
-
- the pattern we look for is:
-
- "%s TCP PORT->STRING:OURPORT *" or
- "%s UDP PORT->STRING:OURPORT *"
- */
- GNUNET_snprintf (pstr, sizeof (pstr),
- ":%u ",
- mini->port);
+ * we're looking for output of the form:
+ *
+ * "0 TCP 3000->192.168.2.150:3000 'libminiupnpc' ''"
+ * "1 UDP 3001->192.168.2.150:3001 'libminiupnpc' ''"
+ *
+ * the pattern we look for is:
+ *
+ * "%s TCP PORT->STRING:OURPORT *" or
+ * "%s UDP PORT->STRING:OURPORT *"
+ */
+ GNUNET_snprintf (pstr, sizeof (pstr), ":%u ", mini->port);
if (NULL == (s = strstr (line, "->")))
- return; /* skip */
+ return; /* skip */
if (NULL == strstr (s, pstr))
- return; /* skip */
+ return; /* skip */
if (1 != sscanf (line,
- (mini->is_tcp)
- ? "%*u TCP %u->%*s:%*u %*s"
- : "%*u UDP %u->%*s:%*u %*s",
- &nport))
- return; /* skip */
+ (mini->is_tcp)
+ ? "%*u TCP %u->%*s:%*u %*s"
+ : "%*u UDP %u->%*s:%*u %*s", &nport))
+ return; /* skip */
mini->found = GNUNET_YES;
if (nport == ntohs (mini->current_addr.sin_port))
- return; /* no change */
+ return; /* no change */
/* external port changed, update mapping */
mini->ac (mini->ac_cls, GNUNET_NO,
- (const struct sockaddr*) &mini->current_addr,
- sizeof (mini->current_addr));
+ (const struct sockaddr *) &mini->current_addr,
+ sizeof (mini->current_addr));
mini->current_addr.sin_port = htons ((uint16_t) nport);
mini->ac (mini->ac_cls, GNUNET_YES,
- (const struct sockaddr*) &mini->current_addr,
- sizeof (mini->current_addr));
+ (const struct sockaddr *) &mini->current_addr,
+ sizeof (mini->current_addr));
}
@@ -428,20 +404,16 @@
* @param tc scheduler context
*/
static void
-do_refresh (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_refresh (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_NAT_MiniHandle *mini = cls;
mini->refresh_task = GNUNET_SCHEDULER_NO_TASK;
mini->found = GNUNET_NO;
mini->refresh_cmd = GNUNET_OS_command_run (&process_refresh_output,
- mini,
- MAP_TIMEOUT,
- "upnpc",
- "upnpc",
- "-l",
- NULL);
+ mini,
+ MAP_TIMEOUT,
+ "upnpc", "upnpc", "-l", NULL);
}
@@ -452,8 +424,7 @@
* @param line line of output, NULL at the end
*/
static void
-process_map_output (void *cls,
- const char *line)
+process_map_output (void *cls, const char *line)
{
struct GNUNET_NAT_MiniHandle *mini = cls;
const char *ipaddr;
@@ -462,35 +433,32 @@
unsigned int port;
if (NULL == line)
- {
- GNUNET_OS_command_stop (mini->map_cmd);
- mini->map_cmd = NULL;
- mini->refresh_task = GNUNET_SCHEDULER_add_delayed (MAP_REFRESH_FREQ,
- &do_refresh,
- mini);
- return;
- }
+ {
+ GNUNET_OS_command_stop (mini->map_cmd);
+ mini->map_cmd = NULL;
+ mini->refresh_task = GNUNET_SCHEDULER_add_delayed (MAP_REFRESH_FREQ,
+ &do_refresh, mini);
+ return;
+ }
/*
- The upnpc output we're after looks like this:
-
- "external 87.123.42.204:3000 TCP is redirected to internal
192.168.2.150:3000"
- */
- if ( (NULL == (ipaddr = strstr (line, " "))) ||
- (NULL == (pstr = strstr (ipaddr, ":"))) ||
- (1 != sscanf (pstr + 1, "%u", &port)) )
- {
- return; /* skip line */
- }
+ * The upnpc output we're after looks like this:
+ *
+ * "external 87.123.42.204:3000 TCP is redirected to internal
192.168.2.150:3000"
+ */
+ if ((NULL == (ipaddr = strstr (line, " "))) ||
+ (NULL == (pstr = strstr (ipaddr, ":"))) ||
+ (1 != sscanf (pstr + 1, "%u", &port)))
+ {
+ return; /* skip line */
+ }
ipa = GNUNET_strdup (ipaddr + 1);
strstr (ipa, ":")[0] = '\0';
- if (1 != inet_pton (AF_INET,
- ipa,
- &mini->current_addr.sin_addr))
- {
- GNUNET_free (ipa);
- return; /* skip line */
- }
- GNUNET_free (ipa);
+ if (1 != inet_pton (AF_INET, ipa, &mini->current_addr.sin_addr))
+ {
+ GNUNET_free (ipa);
+ return; /* skip line */
+ }
+ GNUNET_free (ipa);
mini->current_addr.sin_port = htons (port);
mini->current_addr.sin_family = AF_INET;
@@ -499,8 +467,8 @@
#endif
mini->did_map = GNUNET_YES;
mini->ac (mini->ac_cls, GNUNET_YES,
- (const struct sockaddr*) &mini->current_addr,
- sizeof (mini->current_addr));
+ (const struct sockaddr *) &mini->current_addr,
+ sizeof (mini->current_addr));
}
@@ -519,37 +487,31 @@
*/
struct GNUNET_NAT_MiniHandle *
GNUNET_NAT_mini_map_start (uint16_t port,
- int is_tcp,
- GNUNET_NAT_AddressCallback ac,
- void *ac_cls)
+ int is_tcp,
+ GNUNET_NAT_AddressCallback ac, void *ac_cls)
{
struct GNUNET_NAT_MiniHandle *ret;
char pstr[6];
- if (GNUNET_SYSERR ==
- GNUNET_OS_check_helper_binary ("upnpc"))
+ if (GNUNET_SYSERR == GNUNET_OS_check_helper_binary ("upnpc"))
return NULL;
ret = GNUNET_malloc (sizeof (struct GNUNET_NAT_MiniHandle));
ret->ac = ac;
ret->ac_cls = ac_cls;
ret->is_tcp = is_tcp;
ret->port = port;
- GNUNET_snprintf (pstr, sizeof (pstr),
- "%u",
- (unsigned int) port);
+ GNUNET_snprintf (pstr, sizeof (pstr), "%u", (unsigned int) port);
ret->map_cmd = GNUNET_OS_command_run (&process_map_output,
- ret,
- MAP_TIMEOUT,
- "upnpc",
- "upnpc",
- "-r", pstr,
- is_tcp ? "tcp" : "udp",
- NULL);
+ ret,
+ MAP_TIMEOUT,
+ "upnpc",
+ "upnpc",
+ "-r", pstr,
+ is_tcp ? "tcp" : "udp", NULL);
if (NULL != ret->map_cmd)
return ret;
ret->refresh_task = GNUNET_SCHEDULER_add_delayed (MAP_REFRESH_FREQ,
- &do_refresh,
- ret);
+ &do_refresh, ret);
return ret;
}
@@ -562,23 +524,20 @@
* @param line line of output, NULL at the end
*/
static void
-process_unmap_output (void *cls,
- const char *line)
+process_unmap_output (void *cls, const char *line)
{
struct GNUNET_NAT_MiniHandle *mini = cls;
if (NULL == line)
- {
+ {
#if DEBUG_NAT
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "nat",
- "UPnP unmap done\n");
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "nat", "UPnP unmap done\n");
#endif
- GNUNET_OS_command_stop (mini->unmap_cmd);
- mini->unmap_cmd = NULL;
- GNUNET_free (mini);
- return;
- }
+ GNUNET_OS_command_stop (mini->unmap_cmd);
+ mini->unmap_cmd = NULL;
+ GNUNET_free (mini);
+ return;
+ }
/* we don't really care about the output... */
}
@@ -597,48 +556,46 @@
char pstr[6];
if (GNUNET_SCHEDULER_NO_TASK != mini->refresh_task)
- {
- GNUNET_SCHEDULER_cancel (mini->refresh_task);
- mini->refresh_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (mini->refresh_task);
+ mini->refresh_task = GNUNET_SCHEDULER_NO_TASK;
+ }
if (mini->refresh_cmd != NULL)
+ {
+ GNUNET_OS_command_stop (mini->refresh_cmd);
+ mini->refresh_cmd = NULL;
+ }
+ if (!mini->did_map)
+ {
+ if (mini->map_cmd != NULL)
{
- GNUNET_OS_command_stop (mini->refresh_cmd);
- mini->refresh_cmd = NULL;
+ GNUNET_OS_command_stop (mini->map_cmd);
+ mini->map_cmd = NULL;
}
- if (! mini->did_map)
- {
- if (mini->map_cmd != NULL)
- {
- GNUNET_OS_command_stop (mini->map_cmd);
- mini->map_cmd = NULL;
- }
- GNUNET_free (mini);
- return;
- }
+ GNUNET_free (mini);
+ return;
+ }
mini->ac (mini->ac_cls, GNUNET_NO,
- (const struct sockaddr*) &mini->current_addr,
- sizeof (mini->current_addr));
+ (const struct sockaddr *) &mini->current_addr,
+ sizeof (mini->current_addr));
/* Note: oddly enough, deletion uses the external port whereas
- addition uses the internal port; this rarely matters since they
- often are the same, but it might... */
+ * addition uses the internal port; this rarely matters since they
+ * often are the same, but it might... */
GNUNET_snprintf (pstr, sizeof (pstr),
- "%u",
- (unsigned int) ntohs (mini->current_addr.sin_port));
+ "%u", (unsigned int) ntohs (mini->current_addr.sin_port));
#if DEBUG_NAT
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "nat",
- "Unmapping port %u with UPnP\n",
- ntohs (mini->current_addr.sin_port));
+ "nat",
+ "Unmapping port %u with UPnP\n",
+ ntohs (mini->current_addr.sin_port));
#endif
mini->unmap_cmd = GNUNET_OS_command_run (&process_unmap_output,
- mini,
- UNMAP_TIMEOUT,
- "upnpc",
- "upnpc",
- "-d", pstr,
- mini->is_tcp ? "tcp" : "udp",
- NULL);
+ mini,
+ UNMAP_TIMEOUT,
+ "upnpc",
+ "upnpc",
+ "-d", pstr,
+ mini->is_tcp ? "tcp" : "udp", NULL);
}
Modified: gnunet/src/nat/nat_test.c
===================================================================
--- gnunet/src/nat/nat_test.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/nat/nat_test.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -99,7 +99,7 @@
* Function to call with success report
*/
GNUNET_NAT_TestCallback report;
-
+
/**
* Closure for 'report'.
*/
@@ -167,9 +167,7 @@
* @param addrlen actual lenght of the address
*/
static void
-reversal_cb (void *cls,
- const struct sockaddr *addr,
- socklen_t addrlen)
+reversal_cb (void *cls, const struct sockaddr *addr, socklen_t addrlen)
{
struct GNUNET_NAT_Test *h = cls;
const struct sockaddr_in *sa;
@@ -178,14 +176,14 @@
return;
sa = (const struct sockaddr_in *) addr;
if (h->data != sa->sin_port)
- {
+ {
#if DEBUG_NAT
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "nat",
- "Received connection reversal request for wrong port\n");
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ "nat",
+ "Received connection reversal request for wrong port\n");
#endif
- return; /* wrong port */
- }
+ return; /* wrong port */
+ }
/* report success */
h->report (h->report_cls, GNUNET_OK);
}
@@ -199,38 +197,31 @@
* @param tc scheduler context
*/
static void
-do_udp_read (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_udp_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_NAT_Test *tst = cls;
uint16_t data;
tst->ltask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- tst->lsock,
- &do_udp_read,
- tst);
- if ( (NULL != tc->write_ready) &&
- (GNUNET_NETWORK_fdset_isset (tc->read_ready,
- tst->lsock)) &&
- (sizeof (data) ==
- GNUNET_NETWORK_socket_recv (tst->lsock,
- &data,
- sizeof (data))) )
- {
- if (data == tst->data)
- tst->report (tst->report_cls, GNUNET_OK);
+ tst->lsock, &do_udp_read, tst);
+ if ((NULL != tc->write_ready) &&
+ (GNUNET_NETWORK_fdset_isset (tc->read_ready,
+ tst->lsock)) &&
+ (sizeof (data) ==
+ GNUNET_NETWORK_socket_recv (tst->lsock, &data, sizeof (data))))
+ {
+ if (data == tst->data)
+ tst->report (tst->report_cls, GNUNET_OK);
#if DEBUG_NAT
- else
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "nat",
- "Received data mismatches expected value\n");
+ else
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ "nat", "Received data mismatches expected value\n");
#endif
- }
+ }
#if DEBUG_NAT
else
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "nat",
- "Failed to receive data from inbound connection\n");
+ "nat", "Failed to receive data from inbound
connection\n");
#endif
}
@@ -243,8 +234,7 @@
* @param tc scheduler context
*/
static void
-do_read (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct NatActivity *na = cls;
struct GNUNET_NAT_Test *tst;
@@ -252,31 +242,25 @@
na->rtask = GNUNET_SCHEDULER_NO_TASK;
tst = na->h;
- GNUNET_CONTAINER_DLL_remove (tst->na_head,
- tst->na_tail,
- na);
- if ( (NULL != tc->write_ready) &&
- (GNUNET_NETWORK_fdset_isset (tc->read_ready,
- na->sock)) &&
- (sizeof (data) ==
- GNUNET_NETWORK_socket_recv (na->sock,
- &data,
- sizeof (data))) )
- {
- if (data == tst->data)
- tst->report (tst->report_cls, GNUNET_OK);
+ GNUNET_CONTAINER_DLL_remove (tst->na_head, tst->na_tail, na);
+ if ((NULL != tc->write_ready) &&
+ (GNUNET_NETWORK_fdset_isset (tc->read_ready,
+ na->sock)) &&
+ (sizeof (data) ==
+ GNUNET_NETWORK_socket_recv (na->sock, &data, sizeof (data))))
+ {
+ if (data == tst->data)
+ tst->report (tst->report_cls, GNUNET_OK);
#if DEBUG_NAT
- else
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "nat"
- "Received data mismatches expected value\n");
+ else
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ "nat" "Received data mismatches expected value\n");
#endif
- }
+ }
#if DEBUG_NAT
else
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "nat",
- "Failed to receive data from inbound connection\n");
+ "nat", "Failed to receive data from inbound
connection\n");
#endif
GNUNET_NETWORK_socket_close (na->sock);
GNUNET_free (na);
@@ -291,8 +275,7 @@
* @param tc scheduler context
*/
static void
-do_accept (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_accept (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_NAT_Test *tst = cls;
struct GNUNET_NETWORK_Handle *s;
@@ -300,32 +283,25 @@
tst->ltask = GNUNET_SCHEDULER_NO_TASK;
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
+ return;
tst->ltask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- tst->lsock,
- &do_accept,
- tst);
+ tst->lsock, &do_accept, tst);
s = GNUNET_NETWORK_socket_accept (tst->lsock, NULL, NULL);
if (NULL == s)
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_INFO, "accept");
- return; /* odd error */
- }
-#if DEBUG_NAT
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_INFO, "accept");
+ return; /* odd error */
+ }
+#if DEBUG_NAT
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "nat",
- "Got an inbound connection, waiting for data\n");
+ "nat", "Got an inbound connection, waiting for data\n");
#endif
wl = GNUNET_malloc (sizeof (struct NatActivity));
wl->sock = s;
wl->h = tst;
wl->rtask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- wl->sock,
- &do_read,
- wl);
- GNUNET_CONTAINER_DLL_insert (tst->na_head,
- tst->na_tail,
- wl);
+ wl->sock, &do_read, wl);
+ GNUNET_CONTAINER_DLL_insert (tst->na_head, tst->na_tail, wl);
}
@@ -338,11 +314,9 @@
* @param addr either the previous or the new public IP address
* @param addrlen actual lenght of the address
*/
-static void
+static void
addr_cb (void *cls,
- int add_remove,
- const struct sockaddr *addr,
- socklen_t addrlen)
+ int add_remove, const struct sockaddr *addr, socklen_t addrlen)
{
struct GNUNET_NAT_Test *h = cls;
struct ClientActivity *ca;
@@ -353,40 +327,37 @@
if (GNUNET_YES != add_remove)
return;
if (addrlen != sizeof (struct sockaddr_in))
- return; /* ignore IPv6 here */
+ return; /* ignore IPv6 here */
#if DEBUG_NAT
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "nat",
- "Asking gnunet-nat-server to connect to `%s'\n",
- GNUNET_a2s (addr, addrlen));
+ "nat",
+ "Asking gnunet-nat-server to connect to `%s'\n",
+ GNUNET_a2s (addr, addrlen));
#endif
- sa = (const struct sockaddr_in*) addr;
- msg.header.size = htons (sizeof(struct GNUNET_NAT_TestMessage));
+ sa = (const struct sockaddr_in *) addr;
+ msg.header.size = htons (sizeof (struct GNUNET_NAT_TestMessage));
msg.header.type = htons (GNUNET_MESSAGE_TYPE_NAT_TEST);
msg.dst_ipv4 = sa->sin_addr.s_addr;
msg.dport = sa->sin_port;
msg.data = h->data;
msg.is_tcp = htonl ((uint32_t) h->is_tcp);
- client = GNUNET_CLIENT_connect ("gnunet-nat-server",
- h->cfg);
+ client = GNUNET_CLIENT_connect ("gnunet-nat-server", h->cfg);
if (NULL == client)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to connect to `gnunet-nat-server'\n"));
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to connect to `gnunet-nat-server'\n"));
+ return;
+ }
ca = GNUNET_malloc (sizeof (struct ClientActivity));
ca->client = client;
- GNUNET_CONTAINER_DLL_insert (h->ca_head,
- h->ca_tail,
- ca);
+ GNUNET_CONTAINER_DLL_insert (h->ca_head, h->ca_tail, ca);
GNUNET_break (GNUNET_OK ==
- GNUNET_CLIENT_transmit_and_get_response (client,
- &msg.header,
-
GNUNET_TIME_UNIT_SECONDS,
- GNUNET_YES,
- NULL, NULL));
+ GNUNET_CLIENT_transmit_and_get_response (client,
+ &msg.header,
+
GNUNET_TIME_UNIT_SECONDS,
+ GNUNET_YES,
+ NULL, NULL));
}
@@ -404,15 +375,14 @@
*/
struct GNUNET_NAT_Test *
GNUNET_NAT_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
- int is_tcp,
- uint16_t bnd_port,
- uint16_t adv_port,
- GNUNET_NAT_TestCallback report,
- void *report_cls)
+ int is_tcp,
+ uint16_t bnd_port,
+ uint16_t adv_port,
+ GNUNET_NAT_TestCallback report, void *report_cls)
{
struct GNUNET_NAT_Test *ret;
struct sockaddr_in sa;
- const struct sockaddr *addrs[] = { (const struct sockaddr*) &sa };
+ const struct sockaddr *addrs[] = { (const struct sockaddr *) &sa };
const socklen_t addrlens[] = { sizeof (sa) };
memset (&sa, 0, sizeof (sa));
@@ -421,7 +391,7 @@
#if HAVE_SOCKADDR_IN_SIN_LEN
sa.sin_len = sizeof (sa);
#endif
-
+
ret = GNUNET_malloc (sizeof (struct GNUNET_NAT_Test));
ret->cfg = cfg;
ret->is_tcp = is_tcp;
@@ -430,54 +400,47 @@
ret->report = report;
ret->report_cls = report_cls;
if (bnd_port == 0)
- {
- ret->nat = GNUNET_NAT_register (cfg, is_tcp,
- 0,
- 0, NULL, NULL,
- &addr_cb, &reversal_cb, ret);
- }
+ {
+ ret->nat = GNUNET_NAT_register (cfg, is_tcp,
+ 0,
+ 0, NULL, NULL, &addr_cb, &reversal_cb,
ret);
+ }
else
+ {
+ ret->lsock = GNUNET_NETWORK_socket_create (AF_INET,
+ (is_tcp == GNUNET_YES)
+ ? SOCK_STREAM : SOCK_DGRAM, 0);
+ if ((ret->lsock == NULL) ||
+ (GNUNET_OK != GNUNET_NETWORK_socket_bind (ret->lsock,
+ (const struct sockaddr *)
&sa,
+ sizeof (sa))))
{
- ret->lsock = GNUNET_NETWORK_socket_create (AF_INET,
- (is_tcp==GNUNET_YES)
- ? SOCK_STREAM
- : SOCK_DGRAM, 0);
- if ( (ret->lsock == NULL) ||
- (GNUNET_OK != GNUNET_NETWORK_socket_bind (ret->lsock,
- (const struct sockaddr*)
&sa,
- sizeof (sa))) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to create listen socket bound to `%s' for NAT
test: %s\n"),
- GNUNET_a2s ((const struct sockaddr*)&sa,
- sizeof(sa)),
- STRERROR (errno));
- if (NULL != ret->lsock)
- GNUNET_NETWORK_socket_close (ret->lsock);
- GNUNET_free (ret);
- return NULL;
- }
- if (GNUNET_YES == is_tcp)
- {
- GNUNET_break (GNUNET_OK ==
- GNUNET_NETWORK_socket_listen (ret->lsock, 5));
- ret->ltask = GNUNET_SCHEDULER_add_read_net
(GNUNET_TIME_UNIT_FOREVER_REL,
- ret->lsock,
- &do_accept,
- ret);
- }
- else
- {
- ret->ltask = GNUNET_SCHEDULER_add_read_net
(GNUNET_TIME_UNIT_FOREVER_REL,
- ret->lsock,
- &do_udp_read,
- ret);
- }
- ret->nat = GNUNET_NAT_register (cfg, is_tcp,
- adv_port,
- 1, addrs, addrlens,
- &addr_cb, NULL, ret);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _
+ ("Failed to create listen socket bound to `%s' for NAT test:
%s\n"),
+ GNUNET_a2s ((const struct sockaddr *) &sa, sizeof (sa)),
+ STRERROR (errno));
+ if (NULL != ret->lsock)
+ GNUNET_NETWORK_socket_close (ret->lsock);
+ GNUNET_free (ret);
+ return NULL;
}
+ if (GNUNET_YES == is_tcp)
+ {
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_listen (ret->lsock, 5));
+ ret->ltask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ ret->lsock, &do_accept, ret);
+ }
+ else
+ {
+ ret->ltask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ ret->lsock,
+ &do_udp_read, ret);
+ }
+ ret->nat = GNUNET_NAT_register (cfg, is_tcp,
+ adv_port,
+ 1, addrs, addrlens, &addr_cb, NULL, ret);
+ }
return ret;
}
@@ -494,22 +457,18 @@
struct ClientActivity *cpos;
while (NULL != (cpos = tst->ca_head))
- {
- GNUNET_CONTAINER_DLL_remove (tst->ca_head,
- tst->ca_tail,
- cpos);
- GNUNET_CLIENT_disconnect (cpos->client, GNUNET_NO);
- GNUNET_free (cpos);
- }
+ {
+ GNUNET_CONTAINER_DLL_remove (tst->ca_head, tst->ca_tail, cpos);
+ GNUNET_CLIENT_disconnect (cpos->client, GNUNET_NO);
+ GNUNET_free (cpos);
+ }
while (NULL != (pos = tst->na_head))
- {
- GNUNET_CONTAINER_DLL_remove (tst->na_head,
- tst->na_tail,
- pos);
- GNUNET_SCHEDULER_cancel (pos->rtask);
- GNUNET_NETWORK_socket_close (pos->sock);
- GNUNET_free (pos);
- }
+ {
+ GNUNET_CONTAINER_DLL_remove (tst->na_head, tst->na_tail, pos);
+ GNUNET_SCHEDULER_cancel (pos->rtask);
+ GNUNET_NETWORK_socket_close (pos->sock);
+ GNUNET_free (pos);
+ }
if (GNUNET_SCHEDULER_NO_TASK != tst->ltask)
GNUNET_SCHEDULER_cancel (tst->ltask);
if (NULL != tst->lsock)
Modified: gnunet/src/nat/test_nat.c
===================================================================
--- gnunet/src/nat/test_nat.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/nat/test_nat.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -58,11 +58,10 @@
addr_callback (void *cls, int add_remove,
const struct sockaddr *addr, socklen_t addrlen)
{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Address changed: %s `%s' (%u bytes)\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Address changed: %s `%s' (%u bytes)\n",
add_remove == GNUNET_YES ? "added" : "removed",
- GNUNET_a2s (addr, addrlen),
- (unsigned int) addrlen);
+ GNUNET_a2s (addr, addrlen), (unsigned int) addrlen);
}
@@ -74,8 +73,7 @@
{
struct GNUNET_NAT_Handle *nat = cls;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Stopping NAT and quitting...\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stopping NAT and quitting...\n");
GNUNET_NAT_unregister (nat);
}
@@ -132,11 +130,11 @@
data.addr = NULL;
GNUNET_OS_network_interfaces_list (process_if, &data);
if (NULL == data.addr)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Could not find a valid interface address!\n");
- exit (GNUNET_SYSERR);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Could not find a valid interface address!\n");
+ exit (GNUNET_SYSERR);
+ }
addr = data.addr;
GNUNET_assert (addr->sa_family == AF_INET || addr->sa_family == AF_INET6);
if (addr->sa_family == AF_INET)
@@ -148,13 +146,11 @@
"Requesting NAT redirection from address %s...\n",
GNUNET_a2s (addr, data.addrlen));
- nat = GNUNET_NAT_register (cfg,
- GNUNET_YES /* tcp */,
- 2086,
- 1,
- (const struct sockaddr**) &addr,
- &data.addrlen,
- &addr_callback, NULL, NULL);
+ nat = GNUNET_NAT_register (cfg, GNUNET_YES /* tcp */ ,
+ 2086,
+ 1,
+ (const struct sockaddr **) &addr,
+ &data.addrlen, &addr_callback, NULL, NULL);
GNUNET_free (addr);
GNUNET_SCHEDULER_add_delayed (TIMEOUT, &stop, nat);
}
Modified: gnunet/src/nat/test_nat_mini.c
===================================================================
--- gnunet/src/nat/test_nat_mini.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/nat/test_nat_mini.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -50,10 +50,9 @@
const struct sockaddr *addr, socklen_t addrlen)
{
fprintf (stderr,
- "Address changed: %s `%s' (%u bytes)\n",
- add_remove == GNUNET_YES ? "added" : "removed",
- GNUNET_a2s (addr, addrlen),
- (unsigned int) addrlen);
+ "Address changed: %s `%s' (%u bytes)\n",
+ add_remove == GNUNET_YES ? "added" : "removed",
+ GNUNET_a2s (addr, addrlen), (unsigned int) addrlen);
}
@@ -65,8 +64,7 @@
{
struct GNUNET_NAT_MiniHandle *mini = cls;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Stopping NAT and quitting...\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stopping NAT and quitting...\n");
GNUNET_NAT_mini_map_stop (mini);
}
@@ -83,17 +81,14 @@
struct GNUNET_NAT_MiniHandle *mini;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Requesting NAT redirection for port %u...\n",
- PORT);
- mini = GNUNET_NAT_mini_map_start (PORT,
- GNUNET_YES /* tcp */,
- &addr_callback, NULL);
+ "Requesting NAT redirection for port %u...\n", PORT);
+ mini = GNUNET_NAT_mini_map_start (PORT, GNUNET_YES /* tcp */ ,
+ &addr_callback, NULL);
if (NULL == mini)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Could not start UPnP interaction\n");
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Could not start UPnP interaction\n");
+ return;
+ }
GNUNET_SCHEDULER_add_delayed (TIMEOUT, &stop, mini);
}
@@ -127,9 +122,10 @@
NULL);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "UPnP test for NAT library, timeout set to %d seconds\n",
TIMEOUT);
- GNUNET_PROGRAM_run (5, argv_prog, "test-nat-mini",
- "nohelp", options, &run, NULL);
+ "UPnP test for NAT library, timeout set to %d seconds\n",
+ TIMEOUT);
+ GNUNET_PROGRAM_run (5, argv_prog, "test-nat-mini", "nohelp", options, &run,
+ NULL);
return 0;
}
Modified: gnunet/src/nat/test_nat_test.c
===================================================================
--- gnunet/src/nat/test_nat_test.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/nat/test_nat_test.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -47,15 +47,13 @@
static GNUNET_SCHEDULER_TaskIdentifier end;
static void
-end_test (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+end_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GNUNET_NAT_test_stop (tst);
}
static void
-report_success (void *cls,
- int success)
+report_success (void *cls, int success)
{
GNUNET_assert (GNUNET_OK == success);
ret = 0;
@@ -72,13 +70,10 @@
const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
tst = GNUNET_NAT_test_start (cfg, GNUNET_YES,
- 1285, 1285,
- &report_success, NULL);
+ 1285, 1285, &report_success, NULL);
if (NULL == tst)
return;
- end = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &end_test,
- NULL);
+ end = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_test, NULL);
}
@@ -89,6 +84,7 @@
GNUNET_GETOPT_OPTION_END
};
struct GNUNET_OS_Process *gns;
+
char *const argv_prog[] = {
"test-nat-test",
"-c",
@@ -110,23 +106,17 @@
#endif
NULL);
gns = GNUNET_OS_start_process (NULL, NULL,
- "gnunet-nat-server",
- "gnunet-nat-server",
+ "gnunet-nat-server", "gnunet-nat-server",
#if VERBOSE
- "-L",
- "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", "test_nat_test_data.conf",
- "12345",
- NULL);
+ "-c", "test_nat_test_data.conf",
+ "12345", NULL);
GNUNET_assert (NULL != gns);
- GNUNET_PROGRAM_run (5, argv_prog,
- "test-nat-test", "nohelp",
- options,
- &run, NULL);
+ GNUNET_PROGRAM_run (5, argv_prog,
+ "test-nat-test", "nohelp", options, &run, NULL);
GNUNET_break (0 == GNUNET_OS_process_kill (gns, SIGTERM));
- GNUNET_break (GNUNET_OK ==
- GNUNET_OS_process_wait (gns));
+ GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (gns));
GNUNET_OS_process_close (gns);
return ret;
}
Modified: gnunet/src/nse/gnunet-nse-profiler.c
===================================================================
--- gnunet/src/nse/gnunet-nse-profiler.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/nse/gnunet-nse-profiler.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -148,48 +148,47 @@
shutdown_callback (void *cls, const char *emsg)
{
if (emsg != NULL)
- {
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n");
#endif
- if (ok == 0)
- ok = 666;
- }
+ if (ok == 0)
+ ok = 666;
+ }
else
- {
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "All peers successfully shut down!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers successfully shut
down!\n");
#endif
- ok = 0;
- }
+ ok = 0;
+ }
}
static void
-shutdown_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct NSEPeer *pos;
+
#if VERBOSE
- fprintf(stderr, "Ending test.\n");
+ fprintf (stderr, "Ending test.\n");
#endif
if (disconnect_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel(disconnect_task);
- disconnect_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (disconnect_task);
+ disconnect_task = GNUNET_SCHEDULER_NO_TASK;
+ }
while (NULL != (pos = peer_head))
- {
- if (pos->nse_handle != NULL)
- GNUNET_NSE_disconnect(pos->nse_handle);
- GNUNET_CONTAINER_DLL_remove(peer_head, peer_tail, pos);
- GNUNET_free(pos);
- }
+ {
+ if (pos->nse_handle != NULL)
+ GNUNET_NSE_disconnect (pos->nse_handle);
+ GNUNET_CONTAINER_DLL_remove (peer_head, peer_tail, pos);
+ GNUNET_free (pos);
+ }
if (data_file != NULL)
- GNUNET_DISK_file_close(data_file);
+ GNUNET_DISK_file_close (data_file);
GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
}
@@ -205,72 +204,68 @@
*
*/
static void
-handle_estimate (void *cls, struct GNUNET_TIME_Absolute timestamp, double
estimate, double std_dev)
+handle_estimate (void *cls, struct GNUNET_TIME_Absolute timestamp,
+ double estimate, double std_dev)
{
struct NSEPeer *peer = cls;
char *output_buffer;
size_t size;
if (output_file != NULL)
- {
- size = GNUNET_asprintf(&output_buffer,
- "%s %llu %llu %f %f %f\n",
- GNUNET_i2s(&peer->daemon->id),
- peers_running,
- timestamp.abs_value,
- GNUNET_NSE_log_estimate_to_n(estimate),
- estimate,
- std_dev);
- if (size != GNUNET_DISK_file_write(output_file, output_buffer, size))
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
- "Unable to write to file!\n");
- GNUNET_free (output_buffer);
- }
+ {
+ size = GNUNET_asprintf (&output_buffer,
+ "%s %llu %llu %f %f %f\n",
+ GNUNET_i2s (&peer->daemon->id),
+ peers_running,
+ timestamp.abs_value,
+ GNUNET_NSE_log_estimate_to_n (estimate),
+ estimate, std_dev);
+ if (size != GNUNET_DISK_file_write (output_file, output_buffer, size))
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n");
+ GNUNET_free (output_buffer);
+ }
else
- fprintf(stderr,
- "Received network size estimate from peer %s. Size: %f std.dev.
%f\n",
- GNUNET_i2s(&peer->daemon->id),
- estimate,
- std_dev);
+ fprintf (stderr,
+ "Received network size estimate from peer %s. Size: %f std.dev.
%f\n",
+ GNUNET_i2s (&peer->daemon->id), estimate, std_dev);
}
static void
-connect_nse_service (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+connect_nse_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct NSEPeer *current_peer;
unsigned int i;
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connecting to nse service of peers\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting to nse service of peers\n");
#endif
for (i = 0; i < num_peers; i++)
- {
- if ((connection_limit > 0) && (i % (num_peers / connection_limit) != 0))
- continue;
+ {
+ if ((connection_limit > 0) && (i % (num_peers / connection_limit) != 0))
+ continue;
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "nse-profiler: connecting to nse
service of peer %d\n", i);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "nse-profiler: connecting to nse service of peer %d\n", i);
#endif
- current_peer = GNUNET_malloc(sizeof(struct NSEPeer));
- current_peer->daemon = GNUNET_TESTING_daemon_get(pg, i);
- if (GNUNET_YES ==
GNUNET_TESTING_daemon_running(GNUNET_TESTING_daemon_get(pg, i)))
- {
- current_peer->nse_handle = GNUNET_NSE_connect
(current_peer->daemon->cfg,
- &handle_estimate,
- current_peer);
- GNUNET_assert(current_peer->nse_handle != NULL);
- }
- GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, current_peer);
+ current_peer = GNUNET_malloc (sizeof (struct NSEPeer));
+ current_peer->daemon = GNUNET_TESTING_daemon_get (pg, i);
+ if (GNUNET_YES ==
+ GNUNET_TESTING_daemon_running (GNUNET_TESTING_daemon_get (pg, i)))
+ {
+ current_peer->nse_handle = GNUNET_NSE_connect (current_peer->daemon->cfg,
+ &handle_estimate,
+ current_peer);
+ GNUNET_assert (current_peer->nse_handle != NULL);
}
+ GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, current_peer);
+ }
}
static void
-churn_peers (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+churn_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
/**
@@ -280,31 +275,30 @@
* @param success GNUNET_OK if statistics were
* successfully obtained, GNUNET_SYSERR if not.
*/
-static void
+static void
stats_finished_callback (void *cls, int success)
{
struct StatsContext *stats_context = cls;
char *buf;
int buf_len;
- if ( (GNUNET_OK == success) &&
- (data_file != NULL) )
+ if ((GNUNET_OK == success) && (data_file != NULL))
+ {
+ /* Stats lookup successful, write out data */
+ buf = NULL;
+ buf_len = GNUNET_asprintf (&buf,
+ "TOTAL_NSE_BYTES: %u\n",
+ stats_context->total_nse_bytes);
+ if (buf_len > 0)
{
- /* Stats lookup successful, write out data */
- buf = NULL;
- buf_len = GNUNET_asprintf(&buf,
- "TOTAL_NSE_BYTES: %u\n",
- stats_context->total_nse_bytes);
- if (buf_len > 0)
- {
- GNUNET_DISK_file_write(data_file, buf, buf_len);
- }
- GNUNET_free_non_null(buf);
+ GNUNET_DISK_file_write (data_file, buf, buf_len);
}
+ GNUNET_free_non_null (buf);
+ }
GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == shutdown_handle);
- shutdown_handle = GNUNET_SCHEDULER_add_now(&shutdown_task, NULL);
- GNUNET_free(stats_context);
+ shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
+ GNUNET_free (stats_context);
}
@@ -319,69 +313,62 @@
* @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
* @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
*/
-static int
+static int
statistics_iterator (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- const char *subsystem,
- const char *name,
- uint64_t value,
- int is_persistent)
+ const struct GNUNET_PeerIdentity *peer,
+ const char *subsystem,
+ const char *name, uint64_t value, int is_persistent)
{
struct StatsContext *stats_context = cls;
- if ( (0 == strstr(subsystem, "nse")) &&
- (0 == strstr(name, "# flood messages received")) )
+ if ((0 == strstr (subsystem, "nse")) &&
+ (0 == strstr (name, "# flood messages received")))
stats_context->total_nse_bytes += value;
return GNUNET_OK;
}
static void
-disconnect_nse_peers (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+disconnect_nse_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct NSEPeer *pos;
char *buf;
struct StatsContext *stats_context;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "disconnecting nse service of peers\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "disconnecting nse service of peers\n");
disconnect_task = GNUNET_SCHEDULER_NO_TASK;
pos = peer_head;
while (NULL != (pos = peer_head))
+ {
+ if (pos->nse_handle != NULL)
{
- if (pos->nse_handle != NULL)
- {
- GNUNET_NSE_disconnect(pos->nse_handle);
- pos->nse_handle = NULL;
- }
- GNUNET_CONTAINER_DLL_remove(peer_head, peer_tail, pos);
- GNUNET_free(pos);
+ GNUNET_NSE_disconnect (pos->nse_handle);
+ pos->nse_handle = NULL;
}
+ GNUNET_CONTAINER_DLL_remove (peer_head, peer_tail, pos);
+ GNUNET_free (pos);
+ }
- GNUNET_asprintf(&buf,
- "round%llu",
- current_round);
- if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (testing_cfg,
- "nse-profiler",
- buf,
- &peers_next_round))
- {
- current_round++;
- GNUNET_assert(churn_task == GNUNET_SCHEDULER_NO_TASK);
- churn_task = GNUNET_SCHEDULER_add_now(&churn_peers, NULL);
- }
- else /* No more rounds, let's shut it down! */
- {
- stats_context = GNUNET_malloc(sizeof(struct StatsContext));
- GNUNET_SCHEDULER_cancel(shutdown_handle);
- shutdown_handle = GNUNET_SCHEDULER_NO_TASK;
- GNUNET_TESTING_get_statistics(pg,
- &stats_finished_callback,
- &statistics_iterator,
- stats_context);
- }
- GNUNET_free(buf);
+ GNUNET_asprintf (&buf, "round%llu", current_round);
+ if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (testing_cfg,
+ "nse-profiler",
+ buf,
+ &peers_next_round))
+ {
+ current_round++;
+ GNUNET_assert (churn_task == GNUNET_SCHEDULER_NO_TASK);
+ churn_task = GNUNET_SCHEDULER_add_now (&churn_peers, NULL);
+ }
+ else /* No more rounds, let's shut it down! */
+ {
+ stats_context = GNUNET_malloc (sizeof (struct StatsContext));
+ GNUNET_SCHEDULER_cancel (shutdown_handle);
+ shutdown_handle = GNUNET_SCHEDULER_NO_TASK;
+ GNUNET_TESTING_get_statistics (pg,
+ &stats_finished_callback,
+ &statistics_iterator, stats_context);
+ }
+ GNUNET_free (buf);
}
@@ -391,12 +378,12 @@
* @param cls unused
* @param emsg NULL on success
*/
-static void
+static void
topology_output_callback (void *cls, const char *emsg)
{
- disconnect_task = GNUNET_SCHEDULER_add_delayed(wait_time,
- &disconnect_nse_peers, NULL);
- GNUNET_SCHEDULER_add_now(&connect_nse_service, NULL);
+ disconnect_task = GNUNET_SCHEDULER_add_delayed (wait_time,
+ &disconnect_nse_peers, NULL);
+ GNUNET_SCHEDULER_add_now (&connect_nse_service, NULL);
}
@@ -411,131 +398,117 @@
{
char *temp_output_file;
- if (emsg == NULL) /* Everything is okay! */
- {
- peers_running = peers_next_round;
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Round %llu, churn finished successfully.\n",
- current_round);
- GNUNET_assert(disconnect_task == GNUNET_SCHEDULER_NO_TASK);
- GNUNET_asprintf(&temp_output_file,
- "%s_%llu.dot",
- topology_file,
- current_round);
- GNUNET_TESTING_peergroup_topology_to_file(pg,
- temp_output_file,
- &topology_output_callback,
- NULL);
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
- "Writing topology to file %s\n",
- temp_output_file);
- GNUNET_free(temp_output_file);
- }
+ if (emsg == NULL) /* Everything is okay! */
+ {
+ peers_running = peers_next_round;
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Round %llu, churn finished successfully.\n", current_round);
+ GNUNET_assert (disconnect_task == GNUNET_SCHEDULER_NO_TASK);
+ GNUNET_asprintf (&temp_output_file,
+ "%s_%llu.dot", topology_file, current_round);
+ GNUNET_TESTING_peergroup_topology_to_file (pg,
+ temp_output_file,
+ &topology_output_callback,
NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Writing topology to file %s\n", temp_output_file);
+ GNUNET_free (temp_output_file);
+ }
else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Round %llu, churn FAILED!!\n",
- current_round);
- GNUNET_SCHEDULER_cancel(shutdown_handle);
- shutdown_handle = GNUNET_SCHEDULER_add_now(&shutdown_task, NULL);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Round %llu, churn FAILED!!\n", current_round);
+ GNUNET_SCHEDULER_cancel (shutdown_handle);
+ shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
+ }
}
static void
-churn_peers (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+churn_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
/* peers_running = GNUNET_TESTING_daemons_running(pg); */
churn_task = GNUNET_SCHEDULER_NO_TASK;
if (peers_next_round == peers_running)
- {
- /* Nothing to do... */
- GNUNET_SCHEDULER_add_now(&connect_nse_service, NULL);
- GNUNET_assert(disconnect_task == GNUNET_SCHEDULER_NO_TASK);
- disconnect_task = GNUNET_SCHEDULER_add_delayed(wait_time,
- &disconnect_nse_peers,
NULL);
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
- "Round %lu, doing nothing!\n",
- current_round);
- }
+ {
+ /* Nothing to do... */
+ GNUNET_SCHEDULER_add_now (&connect_nse_service, NULL);
+ GNUNET_assert (disconnect_task == GNUNET_SCHEDULER_NO_TASK);
+ disconnect_task = GNUNET_SCHEDULER_add_delayed (wait_time,
+ &disconnect_nse_peers,
+ NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Round %lu, doing nothing!\n",
+ current_round);
+ }
else
+ {
+ if (peers_next_round > num_peers)
{
- if (peers_next_round > num_peers)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- "Asked to turn on more peers than we have!!\n");
- GNUNET_SCHEDULER_cancel(shutdown_handle);
- GNUNET_SCHEDULER_add_now(&shutdown_task, NULL);
- }
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Round %llu, turning off %llu peers, turning on %llu
peers!\n",
- current_round,
- (peers_running > peers_next_round)
- ? peers_running - peers_next_round
- : 0,
- (peers_next_round > peers_running)
- ? peers_next_round - peers_running
- : 0);
- GNUNET_TESTING_daemons_churn (pg, "nse",
- (peers_running > peers_next_round)
- ? peers_running - peers_next_round
- : 0,
- (peers_next_round > peers_running)
- ? peers_next_round - peers_running
- : 0,
- wait_time,
- &churn_callback, NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Asked to turn on more peers than we have!!\n");
+ GNUNET_SCHEDULER_cancel (shutdown_handle);
+ GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
}
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Round %llu, turning off %llu peers, turning on %llu peers!\n",
+ current_round,
+ (peers_running > peers_next_round)
+ ? peers_running - peers_next_round
+ : 0,
+ (peers_next_round > peers_running)
+ ? peers_next_round - peers_running : 0);
+ GNUNET_TESTING_daemons_churn (pg, "nse",
+ (peers_running > peers_next_round)
+ ? peers_running - peers_next_round
+ : 0,
+ (peers_next_round > peers_running)
+ ? peers_next_round - peers_running
+ : 0, wait_time, &churn_callback, NULL);
+ }
}
static void
-nse_started_cb(void *cls, const char *emsg)
+nse_started_cb (void *cls, const char *emsg)
{
- GNUNET_SCHEDULER_add_now(&connect_nse_service, NULL);
- disconnect_task = GNUNET_SCHEDULER_add_delayed(wait_time,
&disconnect_nse_peers, NULL);
+ GNUNET_SCHEDULER_add_now (&connect_nse_service, NULL);
+ disconnect_task =
+ GNUNET_SCHEDULER_add_delayed (wait_time, &disconnect_nse_peers, NULL);
}
static void
-my_cb (void *cls,
- const char *emsg)
+my_cb (void *cls, const char *emsg)
{
char *buf;
int buf_len;
+
if (emsg != NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peergroup callback called with error, aborting test!\n");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error from testing: `%s'\n");
- ok = 1;
- GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Peergroup callback called with error, aborting test!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error from testing: `%s'\n");
+ ok = 1;
+ GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
+ return;
+ }
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Peer Group started successfully, connecting to NSE service for
each peer!\n");
#endif
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Have %u connections\n",
- total_connections);
+ "Have %u connections\n", total_connections);
if (data_file != NULL)
- {
- buf = NULL;
- buf_len = GNUNET_asprintf(&buf,
- "CONNECTIONS_0: %u\n",
- total_connections);
- if (buf_len > 0)
- GNUNET_DISK_file_write(data_file, buf, buf_len);
- GNUNET_free (buf);
- }
- peers_running = GNUNET_TESTING_daemons_running(pg);
+ {
+ buf = NULL;
+ buf_len = GNUNET_asprintf (&buf, "CONNECTIONS_0: %u\n", total_connections);
+ if (buf_len > 0)
+ GNUNET_DISK_file_write (data_file, buf, buf_len);
+ GNUNET_free (buf);
+ }
+ peers_running = GNUNET_TESTING_daemons_running (pg);
GNUNET_TESTING_daemons_start_service (pg,
"nse",
- wait_time,
- &nse_started_cb,
- NULL);
+ wait_time, &nse_started_cb, NULL);
}
@@ -554,16 +527,15 @@
* @param second_daemon handle for the second daemon
* @param emsg error message (NULL on success)
*/
-static void
+static void
connect_cb (void *cls,
- const struct GNUNET_PeerIdentity *first,
- const struct GNUNET_PeerIdentity *second,
- uint32_t distance,
- const struct GNUNET_CONFIGURATION_Handle *first_cfg,
- const struct GNUNET_CONFIGURATION_Handle *second_cfg,
- struct GNUNET_TESTING_Daemon *first_daemon,
- struct GNUNET_TESTING_Daemon *second_daemon,
- const char *emsg)
+ const struct GNUNET_PeerIdentity *first,
+ const struct GNUNET_PeerIdentity *second,
+ uint32_t distance,
+ const struct GNUNET_CONFIGURATION_Handle *first_cfg,
+ const struct GNUNET_CONFIGURATION_Handle *second_cfg,
+ struct GNUNET_TESTING_Daemon *first_daemon,
+ struct GNUNET_TESTING_Daemon *second_daemon, const char *emsg)
{
if (emsg == NULL)
total_connections++;
@@ -580,109 +552,108 @@
struct GNUNET_TESTING_Host *hosts;
ok = 1;
- testing_cfg = GNUNET_CONFIGURATION_create();
+ testing_cfg = GNUNET_CONFIGURATION_create ();
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemons.\n");
GNUNET_CONFIGURATION_set_value_string (testing_cfg,
- "testing",
- "use_progressbars",
- "YES");
+ "testing", "use_progressbars", "YES");
#endif
- if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (testing_cfg,
- "testing",
- "num_peers",
&num_peers))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Option TESTING:NUM_PEERS is
required!\n");
- return;
- }
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (testing_cfg,
+ "testing",
+ "num_peers",
+ &num_peers))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Option TESTING:NUM_PEERS is required!\n");
+ return;
+ }
- if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (testing_cfg,
- "nse-profiler",
- "wait_time",
- &temp_wait))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- "Option nse-profiler:wait_time is required!\n");
- return;
- }
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (testing_cfg,
+ "nse-profiler",
+ "wait_time",
+ &temp_wait))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Option nse-profiler:wait_time is required!\n");
+ return;
+ }
- if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (testing_cfg,
- "nse-profiler",
"connection_limit",
- &connection_limit))
- {
- connection_limit = 0;
- }
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (testing_cfg,
+ "nse-profiler",
+ "connection_limit",
+ &connection_limit))
+ {
+ connection_limit = 0;
+ }
- if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (testing_cfg,
- "nse-profiler",
"topology_output_file",
- &topology_file))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- "Option nse-profiler:topology_output_file is required!\n");
- return;
- }
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (testing_cfg,
+ "nse-profiler",
+
"topology_output_file",
+ &topology_file))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Option nse-profiler:topology_output_file is required!\n");
+ return;
+ }
- if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (testing_cfg,
- "nse-profiler",
"data_output_file",
- &data_filename))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- "Option nse-profiler:data_output_file is required!\n");
- return;
- }
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (testing_cfg,
+ "nse-profiler",
+ "data_output_file",
+ &data_filename))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Option nse-profiler:data_output_file is required!\n");
+ return;
+ }
- if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (testing_cfg,
- "nse-profiler",
- "skew_clock"))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
- "Setting our clock as skewed...\n");
- clock_skew = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK,
- GNUNET_TIME_UNIT_MINUTES.rel_value);
- }
+ if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (testing_cfg,
+ "nse-profiler",
+ "skew_clock"))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Setting our clock as skewed...\n");
+ clock_skew = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
+ GNUNET_TIME_UNIT_MINUTES.rel_value);
+ }
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_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);
- wait_time = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
temp_wait);
+ wait_time =
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_wait);
- if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string(cfg,
- "nse-profiler",
- "output_file",
- &temp_str))
- {
- output_file = GNUNET_DISK_file_open (temp_str, GNUNET_DISK_OPEN_READWRITE
- |
GNUNET_DISK_OPEN_CREATE,
-
GNUNET_DISK_PERM_USER_READ |
-
GNUNET_DISK_PERM_USER_WRITE);
- if (output_file == NULL)
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
- "Failed to open %s for output!\n",
- temp_str);
- }
- GNUNET_free_non_null(temp_str);
+ if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (cfg,
+ "nse-profiler",
+ "output_file",
+ &temp_str))
+ {
+ output_file = GNUNET_DISK_file_open (temp_str, GNUNET_DISK_OPEN_READWRITE
+ | GNUNET_DISK_OPEN_CREATE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE);
+ if (output_file == NULL)
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to open %s for output!\n", temp_str);
+ }
+ GNUNET_free_non_null (temp_str);
hosts = GNUNET_TESTING_hosts_load (testing_cfg);
- pg = GNUNET_TESTING_peergroup_start(testing_cfg,
- num_peers,
- TIMEOUT,
- &connect_cb,
- &my_cb, NULL,
- hosts);
+ pg = GNUNET_TESTING_peergroup_start (testing_cfg,
+ num_peers,
+ TIMEOUT,
+ &connect_cb, &my_cb, NULL, hosts);
GNUNET_assert (pg != NULL);
- shutdown_handle = GNUNET_SCHEDULER_add_delayed
(GNUNET_TIME_relative_get_forever(),
- &shutdown_task,
- NULL);
+ shutdown_handle =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_get_forever (),
+ &shutdown_task, NULL);
}
@@ -709,10 +680,10 @@
#endif
NULL);
GNUNET_PROGRAM_run (argc,
- argv, "nse-profiler",
- gettext_noop ("Measure quality and performance of the NSE
service."),
- options,
- &run, NULL);
+ argv, "nse-profiler",
+ gettext_noop
+ ("Measure quality and performance of the NSE service."),
+ options, &run, NULL);
#if REMOVE_DIR
GNUNET_DISK_directory_remove ("/tmp/nse-profiler");
#endif
Modified: gnunet/src/nse/gnunet-service-nse.c
===================================================================
--- gnunet/src/nse/gnunet-service-nse.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/nse/gnunet-service-nse.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -314,35 +314,33 @@
sum = 0.0;
sumweight = 0.0;
for (i = 0; i < estimate_count; i++)
- {
- val = htonl (size_estimate_messages[(estimate_index - i + HISTORY_SIZE)
- % HISTORY_SIZE].matching_bits);
- weight = 1; /* was: estimate_count + 1 - i; */
+ {
+ val = htonl (size_estimate_messages[(estimate_index - i + HISTORY_SIZE)
+ % HISTORY_SIZE].matching_bits);
+ weight = 1; /* was: estimate_count + 1 - i; */
- temp = weight + sumweight;
- q = val - mean;
- r = q * weight / temp;
- sum += sumweight * q * r;
- mean += r;
- sumweight = temp;
- }
+ temp = weight + sumweight;
+ q = val - mean;
+ r = q * weight / temp;
+ sum += sumweight * q * r;
+ mean += r;
+ sumweight = temp;
+ }
variance = sum / (sumweight - 1.0);
GNUNET_assert (variance >= 0);
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->header.size = htons (sizeof (struct GNUNET_NSE_ClientMessage));
+ em->header.type = htons (GNUNET_MESSAGE_TYPE_NSE_ESTIMATE);
em->reserved = htonl (0);
- em->timestamp = GNUNET_TIME_absolute_hton(GNUNET_TIME_absolute_get());
- em->size_estimate = mean - 1.0/3.0;
+ em->timestamp = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ());
+ em->size_estimate = mean - 1.0 / 3.0;
em->std_deviation = std_dev;
- GNUNET_STATISTICS_set (stats,
- "# nodes in the network (estimate)",
- (uint64_t) pow (2, mean - 1.0/3.0), GNUNET_NO);
+ GNUNET_STATISTICS_set (stats,
+ "# nodes in the network (estimate)",
+ (uint64_t) pow (2, mean - 1.0 / 3.0), GNUNET_NO);
}
@@ -357,18 +355,18 @@
* @param message the message received
*/
static void
-handle_start_message(void *cls, struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+handle_start_message (void *cls, struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
struct GNUNET_NSE_ClientMessage em;
#if DEBUG_NSE
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Received START message from client\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received START message from client\n");
#endif
GNUNET_SERVER_notification_context_add (nc, client);
setup_estimate_message (&em);
- GNUNET_SERVER_notification_context_unicast (nc, client, &em.header,
GNUNET_YES);
+ GNUNET_SERVER_notification_context_unicast (nc, client, &em.header,
+ GNUNET_YES);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
@@ -382,13 +380,15 @@
static double
get_matching_bits_delay (uint32_t matching_bits)
{
- /* Calculated as: S + f/2 - (f / pi) * (atan(x - p'))*/
+ /* Calculated as: S + f/2 - (f / pi) * (atan(x - p')) */
// S is next_timestamp (ignored in return value)
// f is frequency (gnunet_nse_interval)
// x is matching_bits
// p' is current_size_estimate
return ((double) gnunet_nse_interval.rel_value / (double) 2.0)
- - ((gnunet_nse_interval.rel_value / M_PI) * atan (matching_bits -
current_size_estimate));
+ -
+ ((gnunet_nse_interval.rel_value / M_PI) *
+ atan (matching_bits - current_size_estimate));
}
@@ -398,7 +398,7 @@
* @param matching_bits number of matching bits
* @return random delay to apply
*/
-static struct GNUNET_TIME_Relative
+static struct GNUNET_TIME_Relative
get_delay_randomization (uint32_t matching_bits)
{
#if USE_RANDOM_DELAYS
@@ -407,7 +407,11 @@
if (matching_bits == 0)
return GNUNET_TIME_UNIT_ZERO;
ret.rel_value = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
- (uint32_t) (get_matching_bits_delay
(matching_bits - 1) / (double) (hop_count_max + 1)));
+ (uint32_t) (get_matching_bits_delay
+ (matching_bits -
+ 1) /
+ (double) (hop_count_max
+ + 1)));
return ret;
#else
return GNUNET_TIME_UNIT_ZERO;
@@ -424,15 +428,13 @@
*/
static uint32_t
get_matching_bits (struct GNUNET_TIME_Absolute timestamp,
- const struct GNUNET_PeerIdentity *id)
+ const struct GNUNET_PeerIdentity *id)
{
GNUNET_HashCode timestamp_hash;
GNUNET_CRYPTO_hash (×tamp.abs_value,
- sizeof(timestamp.abs_value),
- ×tamp_hash);
- return GNUNET_CRYPTO_hash_matching_bits (×tamp_hash,
- &id->hashPubKey);
+ sizeof (timestamp.abs_value), ×tamp_hash);
+ return GNUNET_CRYPTO_hash_matching_bits (×tamp_hash, &id->hashPubKey);
}
@@ -453,38 +455,38 @@
uint32_t matching_bits;
switch (round_offset)
- {
- case -1:
- /* previous round is randomized between 0 and 50 ms */
+ {
+ case -1:
+ /* previous round is randomized between 0 and 50 ms */
#if USE_RANDOM_DELAYS
- ret.rel_value = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
- 50);
+ ret.rel_value = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 50);
#else
- ret = GNUNET_TIME_UNIT_ZERO;
+ ret = GNUNET_TIME_UNIT_ZERO;
#endif
#if DEBUG_NSE
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Transmitting previous round behind schedule in %llu ms\n",
- (unsigned long long) ret.rel_value);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Transmitting previous round behind schedule in %llu ms\n",
+ (unsigned long long) ret.rel_value);
#endif
- return ret;
- case 0:
- /* current round is based on best-known matching_bits */
- matching_bits = ntohl
(size_estimate_messages[estimate_index].matching_bits);
- dist_delay = get_matching_bits_delay (matching_bits);
- dist_delay += get_delay_randomization (matching_bits).rel_value;
- ret.rel_value = (uint64_t) dist_delay;
+ return ret;
+ case 0:
+ /* current round is based on best-known matching_bits */
+ matching_bits =
+ ntohl (size_estimate_messages[estimate_index].matching_bits);
+ dist_delay = get_matching_bits_delay (matching_bits);
+ dist_delay += get_delay_randomization (matching_bits).rel_value;
+ ret.rel_value = (uint64_t) dist_delay;
#if DEBUG_NSE
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "For round %llu, delay for %u matching bits is %llu ms\n",
- (unsigned long long) current_timestamp.abs_value,
- (unsigned int) matching_bits,
- (unsigned long long) ret.rel_value);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "For round %llu, delay for %u matching bits is %llu ms\n",
+ (unsigned long long) current_timestamp.abs_value,
+ (unsigned int) matching_bits,
+ (unsigned long long) ret.rel_value);
#endif
- /* now consider round start time and add delay to it */
- tgt = GNUNET_TIME_absolute_add (current_timestamp, ret);
- return GNUNET_TIME_absolute_get_remaining (tgt);
- }
+ /* now consider round start time and add delay to it */
+ tgt = GNUNET_TIME_absolute_add (current_timestamp, ret);
+ return GNUNET_TIME_absolute_get_remaining (tgt);
+ }
GNUNET_break (0);
return GNUNET_TIME_UNIT_FOREVER_REL;
}
@@ -497,8 +499,7 @@
* @param tc scheduler context
*/
static void
-transmit_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+transmit_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
/**
@@ -518,52 +519,45 @@
peer_entry->th = NULL;
if (buf == NULL)
- {
- /* client disconnected */
- return 0;
- }
+ {
+ /* client disconnected */
+ return 0;
+ }
GNUNET_assert (size >= sizeof (struct GNUNET_NSE_FloodMessage));
idx = estimate_index;
if (peer_entry->previous_round == GNUNET_NO)
- {
- idx = (idx + HISTORY_SIZE - 1) % HISTORY_SIZE;
- peer_entry->previous_round = GNUNET_YES;
- peer_entry->transmit_task = GNUNET_SCHEDULER_add_delayed
(get_transmit_delay (0),
- &transmit_task,
- peer_entry);
- }
- if ( (ntohl (size_estimate_messages[idx].hop_count) == 0) &&
- (GNUNET_SCHEDULER_NO_TASK != proof_task) )
- {
- GNUNET_STATISTICS_update (stats,
- "# flood messages not generated (no proof
yet)",
- 1,
- GNUNET_NO);
- return 0;
- }
+ {
+ idx = (idx + HISTORY_SIZE - 1) % HISTORY_SIZE;
+ peer_entry->previous_round = GNUNET_YES;
+ peer_entry->transmit_task =
+ GNUNET_SCHEDULER_add_delayed (get_transmit_delay (0), &transmit_task,
+ peer_entry);
+ }
+ if ((ntohl (size_estimate_messages[idx].hop_count) == 0) &&
+ (GNUNET_SCHEDULER_NO_TASK != proof_task))
+ {
+ GNUNET_STATISTICS_update (stats,
+ "# flood messages not generated (no proof yet)",
+ 1, GNUNET_NO);
+ return 0;
+ }
#if DEBUG_NSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "In round %llu, sending to `%s' estimate with %u bits\n",
- (unsigned long long) GNUNET_TIME_absolute_ntoh
(size_estimate_messages[idx].timestamp).abs_value,
- GNUNET_i2s (&peer_entry->id),
- (unsigned int) ntohl (size_estimate_messages[idx].matching_bits));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "In round %llu, sending to `%s' estimate with %u bits\n",
+ (unsigned long long)
+ GNUNET_TIME_absolute_ntoh (size_estimate_messages[idx].
+ timestamp).abs_value,
+ GNUNET_i2s (&peer_entry->id),
+ (unsigned int) ntohl
(size_estimate_messages[idx].matching_bits));
#endif
- if (ntohl (size_estimate_messages[idx].hop_count) == 0)
- GNUNET_STATISTICS_update (stats,
- "# flood messages started",
- 1,
- GNUNET_NO);
- GNUNET_STATISTICS_update (stats,
- "# flood messages transmitted",
- 1,
- GNUNET_NO);
+ if (ntohl (size_estimate_messages[idx].hop_count) == 0)
+ GNUNET_STATISTICS_update (stats, "# flood messages started", 1, GNUNET_NO);
+ GNUNET_STATISTICS_update (stats,
+ "# flood messages transmitted", 1, GNUNET_NO);
memcpy (buf,
- &size_estimate_messages[idx],
- sizeof (struct GNUNET_NSE_FloodMessage));
- GNUNET_STATISTICS_update (stats,
- "# flood messages sent",
- 1,
- GNUNET_NO);
+ &size_estimate_messages[idx],
+ sizeof (struct GNUNET_NSE_FloodMessage));
+ GNUNET_STATISTICS_update (stats, "# flood messages sent", 1, GNUNET_NO);
return sizeof (struct GNUNET_NSE_FloodMessage);
}
@@ -575,21 +569,21 @@
* @param tc scheduler context
*/
static void
-transmit_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+transmit_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct NSEPeerEntry *peer_entry = cls;
-
+
peer_entry->transmit_task = GNUNET_SCHEDULER_NO_TASK;
GNUNET_assert (NULL == peer_entry->th);
peer_entry->th
- = GNUNET_CORE_notify_transmit_ready (coreAPI,
- GNUNET_NO,
- NSE_PRIORITY,
- GNUNET_TIME_UNIT_FOREVER_REL,
- &peer_entry->id,
- sizeof (struct
GNUNET_NSE_FloodMessage),
- &transmit_ready, peer_entry);
+ = GNUNET_CORE_notify_transmit_ready (coreAPI,
+ GNUNET_NO,
+ NSE_PRIORITY,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &peer_entry->id,
+ sizeof (struct
+ GNUNET_NSE_FloodMessage),
+ &transmit_ready, peer_entry);
}
@@ -605,9 +599,7 @@
struct GNUNET_NSE_ClientMessage em;
setup_estimate_message (&em);
- GNUNET_SERVER_notification_context_broadcast (nc,
- &em.header,
- GNUNET_YES);
+ GNUNET_SERVER_notification_context_broadcast (nc, &em.header, GNUNET_YES);
}
@@ -619,29 +611,26 @@
* @param ts timestamp to use
*/
static void
-setup_flood_message (unsigned int slot,
- struct GNUNET_TIME_Absolute ts)
+setup_flood_message (unsigned int slot, struct GNUNET_TIME_Absolute ts)
{
struct GNUNET_NSE_FloodMessage *fm;
uint32_t matching_bits;
matching_bits = get_matching_bits (ts, &my_identity);
fm = &size_estimate_messages[slot];
- fm->header.size = htons (sizeof(struct GNUNET_NSE_FloodMessage));
+ fm->header.size = htons (sizeof (struct GNUNET_NSE_FloodMessage));
fm->header.type = htons (GNUNET_MESSAGE_TYPE_NSE_P2P_FLOOD);
fm->hop_count = htonl (0);
fm->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_NSE_SEND);
- fm->purpose.size = htonl (sizeof(struct GNUNET_NSE_FloodMessage)
- - sizeof (struct GNUNET_MessageHeader)
- - sizeof (uint32_t)
- - sizeof (struct GNUNET_CRYPTO_RsaSignature));
+ fm->purpose.size = htonl (sizeof (struct GNUNET_NSE_FloodMessage)
+ - sizeof (struct GNUNET_MessageHeader)
+ - sizeof (uint32_t)
+ - sizeof (struct GNUNET_CRYPTO_RsaSignature));
fm->matching_bits = htonl (matching_bits);
fm->timestamp = GNUNET_TIME_absolute_hton (ts);
fm->pkey = my_public_key;
fm->proof_of_work = my_proof;
- GNUNET_CRYPTO_rsa_sign (my_private_key,
- &fm->purpose,
- &fm->signature);
+ GNUNET_CRYPTO_rsa_sign (my_private_key, &fm->purpose, &fm->signature);
}
@@ -655,27 +644,25 @@
* @return GNUNET_OK (continue to iterate)
*/
static int
-schedule_current_round (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+schedule_current_round (void *cls, const GNUNET_HashCode * key, void *value)
{
struct NSEPeerEntry *peer_entry = value;
struct GNUNET_TIME_Relative delay;
if (peer_entry->th != NULL)
- {
- peer_entry->previous_round = GNUNET_NO;
- return GNUNET_OK;
- }
+ {
+ peer_entry->previous_round = GNUNET_NO;
+ return GNUNET_OK;
+ }
if (peer_entry->transmit_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (peer_entry->transmit_task);
- peer_entry->previous_round = GNUNET_NO;
- }
- delay = get_transmit_delay ((peer_entry->previous_round == GNUNET_NO) ? -1 :
0);
- peer_entry->transmit_task = GNUNET_SCHEDULER_add_delayed (delay,
- &transmit_task,
- peer_entry);
+ {
+ GNUNET_SCHEDULER_cancel (peer_entry->transmit_task);
+ peer_entry->previous_round = GNUNET_NO;
+ }
+ delay =
+ get_transmit_delay ((peer_entry->previous_round == GNUNET_NO) ? -1 : 0);
+ peer_entry->transmit_task =
+ GNUNET_SCHEDULER_add_delayed (delay, &transmit_task, peer_entry);
return GNUNET_OK;
}
@@ -687,8 +674,7 @@
* @param tc context for this message
*/
static void
-update_flood_message(void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+update_flood_message (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_TIME_Relative offset;
unsigned int i;
@@ -696,40 +682,38 @@
flood_task = GNUNET_SCHEDULER_NO_TASK;
offset = GNUNET_TIME_absolute_get_remaining (next_timestamp);
if (0 != offset.rel_value)
- {
- /* somehow run early, delay more */
- flood_task
- = GNUNET_SCHEDULER_add_delayed (offset,
- &update_flood_message,
- NULL);
- return;
- }
+ {
+ /* somehow run early, delay more */
+ flood_task
+ = GNUNET_SCHEDULER_add_delayed (offset, &update_flood_message, NULL);
+ return;
+ }
current_timestamp = next_timestamp;
next_timestamp = GNUNET_TIME_absolute_add (current_timestamp,
- gnunet_nse_interval);
+ gnunet_nse_interval);
estimate_index = (estimate_index + 1) % HISTORY_SIZE;
if (estimate_count < HISTORY_SIZE)
estimate_count++;
- if (next_timestamp.abs_value ==
+ if (next_timestamp.abs_value ==
GNUNET_TIME_absolute_ntoh (next_message.timestamp).abs_value)
- {
- /* we received a message for this round way early, use it! */
- size_estimate_messages[estimate_index] = next_message;
- size_estimate_messages[estimate_index].hop_count
- = htonl (1 + ntohl (next_message.hop_count));
- }
+ {
+ /* we received a message for this round way early, use it! */
+ size_estimate_messages[estimate_index] = next_message;
+ size_estimate_messages[estimate_index].hop_count
+ = htonl (1 + ntohl (next_message.hop_count));
+ }
else
setup_flood_message (estimate_index, current_timestamp);
- next_message.matching_bits = htonl (0); /* reset for 'next' round */
+ next_message.matching_bits = htonl (0); /* reset for 'next' round */
hop_count_max = 0;
for (i = 0; i < HISTORY_SIZE; i++)
hop_count_max = GNUNET_MAX (ntohl (size_estimate_messages[i].hop_count),
- hop_count_max);
- GNUNET_CONTAINER_multihashmap_iterate (peers,
- &schedule_current_round,
- NULL);
- flood_task = GNUNET_SCHEDULER_add_delayed
(GNUNET_TIME_absolute_get_remaining (next_timestamp),
- &update_flood_message, NULL);
+ hop_count_max);
+ GNUNET_CONTAINER_multihashmap_iterate (peers, &schedule_current_round, NULL);
+ flood_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
+ (next_timestamp), &update_flood_message,
+ NULL);
}
@@ -739,13 +723,13 @@
* @param hash
* @return the number of leading zero bits.
*/
-static unsigned int
-count_leading_zeroes(const GNUNET_HashCode *hash)
+static unsigned int
+count_leading_zeroes (const GNUNET_HashCode * hash)
{
unsigned int hash_count;
-
+
hash_count = 0;
- while ((0 == GNUNET_CRYPTO_hash_get_bit(hash, hash_count)))
+ while ((0 == GNUNET_CRYPTO_hash_get_bit (hash, hash_count)))
hash_count++;
return hash_count;
}
@@ -761,20 +745,19 @@
* @return GNUNET_YES if valid, GNUNET_NO if not
*/
static int
-check_proof_of_work(const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pkey,
- uint64_t val)
-{
- char buf[sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) +
sizeof(val)];
+check_proof_of_work (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
*pkey,
+ uint64_t val)
+{
+ char buf[sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) +
+ sizeof (val)];
GNUNET_HashCode result;
-
- memcpy (buf,
- &val,
- sizeof (val));
- memcpy (&buf[sizeof(val)],
- pkey,
- sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
+
+ memcpy (buf, &val, sizeof (val));
+ memcpy (&buf[sizeof (val)],
+ pkey, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
GNUNET_CRYPTO_hash (buf, sizeof (buf), &result);
- return (count_leading_zeroes (&result) >= nse_work_required) ? GNUNET_YES :
GNUNET_NO;
+ return (count_leading_zeroes (&result) >=
+ nse_work_required) ? GNUNET_YES : GNUNET_NO;
}
@@ -786,19 +769,16 @@
{
char *proof;
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (cfg,
- "NSE", "PROOFFILE",
- &proof))
- return;
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_filename (cfg, "NSE", "PROOFFILE",
&proof))
+ return;
if (sizeof (my_proof) !=
GNUNET_DISK_fn_write (proof,
- &my_proof,
- sizeof (my_proof),
- GNUNET_DISK_PERM_USER_READ |
GNUNET_DISK_PERM_USER_WRITE))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
- "write",
- proof);
+ &my_proof,
+ sizeof (my_proof),
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", proof);
GNUNET_free (proof);
}
@@ -811,67 +791,64 @@
* @param tc task context
*/
static void
-find_proof (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+find_proof (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
#define ROUND_SIZE 10
uint64_t counter;
- char buf[sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) +
sizeof(uint64_t)];
+ char buf[sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) +
+ sizeof (uint64_t)];
GNUNET_HashCode result;
- unsigned int i;
-
+ unsigned int i;
+
proof_task = GNUNET_SCHEDULER_NO_TASK;
- memcpy (&buf[sizeof(uint64_t)],
- &my_public_key,
- sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
+ memcpy (&buf[sizeof (uint64_t)],
+ &my_public_key,
+ sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
i = 0;
counter = my_proof;
- while ( (counter != UINT64_MAX) && (i < ROUND_SIZE) )
+ while ((counter != UINT64_MAX) && (i < ROUND_SIZE))
+ {
+ memcpy (buf, &counter, sizeof (uint64_t));
+ GNUNET_CRYPTO_hash (buf, sizeof (buf), &result);
+ if (nse_work_required <= count_leading_zeroes (&result))
{
- memcpy (buf,
- &counter,
- sizeof(uint64_t));
- GNUNET_CRYPTO_hash (buf, sizeof (buf), &result);
- if (nse_work_required <= count_leading_zeroes(&result))
- {
- my_proof = counter;
+ my_proof = counter;
#if DEBUG_NSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Proof of work found: %llu!\n",
- (unsigned long long) GNUNET_ntohll (counter));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Proof of work found: %llu!\n",
+ (unsigned long long) GNUNET_ntohll (counter));
#endif
- for (i=0;i<HISTORY_SIZE;i++)
- if (ntohl (size_estimate_messages[i].hop_count) == 0)
- {
- size_estimate_messages[i].proof_of_work = my_proof;
- GNUNET_CRYPTO_rsa_sign (my_private_key,
- &size_estimate_messages[i].purpose,
- &size_estimate_messages[i].signature);
- }
- write_proof ();
- return;
- }
- counter++;
- i++;
+ for (i = 0; i < HISTORY_SIZE; i++)
+ if (ntohl (size_estimate_messages[i].hop_count) == 0)
+ {
+ size_estimate_messages[i].proof_of_work = my_proof;
+ GNUNET_CRYPTO_rsa_sign (my_private_key,
+ &size_estimate_messages[i].purpose,
+ &size_estimate_messages[i].signature);
+ }
+ write_proof ();
+ return;
}
+ counter++;
+ i++;
+ }
if (my_proof / (100 * ROUND_SIZE) < counter / (100 * ROUND_SIZE))
- {
+ {
#if DEBUG_NSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Testing proofs currently at %llu\n",
- (unsigned long long) counter);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Testing proofs currently at %llu\n",
+ (unsigned long long) counter);
#endif
- /* remember progress every 100 rounds */
- my_proof = counter;
- write_proof ();
- }
+ /* remember progress every 100 rounds */
+ my_proof = counter;
+ write_proof ();
+ }
else
- {
- my_proof = counter;
- }
+ {
+ my_proof = counter;
+ }
proof_task = GNUNET_SCHEDULER_add_delayed (proof_find_delay,
- &find_proof,
- NULL);
+ &find_proof, NULL);
}
@@ -885,28 +862,29 @@
* @return GNUNET_YES if the message is verified
* GNUNET_NO if the key/signature don't verify
*/
-static int
-verify_message_crypto(const struct GNUNET_NSE_FloodMessage *incoming_flood)
+static int
+verify_message_crypto (const struct GNUNET_NSE_FloodMessage *incoming_flood)
{
if (GNUNET_YES !=
check_proof_of_work (&incoming_flood->pkey,
- incoming_flood->proof_of_work))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Proof of work invalid: %llu!\n"),
- (unsigned long long) GNUNET_ntohll
(incoming_flood->proof_of_work));
- GNUNET_break_op (0);
- return GNUNET_NO;
- }
- if (GNUNET_OK !=
+ incoming_flood->proof_of_work))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Proof of work invalid: %llu!\n"),
+ (unsigned long long)
+ GNUNET_ntohll (incoming_flood->proof_of_work));
+ GNUNET_break_op (0);
+ return GNUNET_NO;
+ }
+ if (GNUNET_OK !=
GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_NSE_SEND,
- &incoming_flood->purpose,
- &incoming_flood->signature,
- &incoming_flood->pkey))
- {
- GNUNET_break_op (0);
- return GNUNET_NO;
- }
+ &incoming_flood->purpose,
+ &incoming_flood->signature,
+ &incoming_flood->pkey))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_NO;
+ }
return GNUNET_YES;
}
@@ -921,35 +899,33 @@
* @return GNUNET_OK (continue to iterate)
*/
static int
-update_flood_times (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+update_flood_times (void *cls, const GNUNET_HashCode * key, void *value)
{
struct NSEPeerEntry *exclude = cls;
struct NSEPeerEntry *peer_entry = value;
struct GNUNET_TIME_Relative delay;
if (peer_entry->th != NULL)
- return GNUNET_OK; /* already active */
+ return GNUNET_OK; /* already active */
if (peer_entry == exclude)
- return GNUNET_OK; /* trigger of the update */
+ return GNUNET_OK; /* trigger of the update */
if (peer_entry->previous_round == GNUNET_NO)
- {
- /* still stuck in previous round, no point to update, check that
- we are active here though... */
- GNUNET_break ( (peer_entry->transmit_task != GNUNET_SCHEDULER_NO_TASK) ||
- (peer_entry->th != NULL) );
- return GNUNET_OK;
- }
+ {
+ /* still stuck in previous round, no point to update, check that
+ * we are active here though... */
+ GNUNET_break ((peer_entry->transmit_task != GNUNET_SCHEDULER_NO_TASK) ||
+ (peer_entry->th != NULL));
+ return GNUNET_OK;
+ }
if (peer_entry->transmit_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (peer_entry->transmit_task);
- peer_entry->transmit_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (peer_entry->transmit_task);
+ peer_entry->transmit_task = GNUNET_SCHEDULER_NO_TASK;
+ }
delay = get_transmit_delay (0);
peer_entry->transmit_task = GNUNET_SCHEDULER_add_delayed (delay,
- &transmit_task,
- peer_entry);
+ &transmit_task,
+ peer_entry);
return GNUNET_OK;
}
@@ -964,15 +940,15 @@
*
*/
static int
-handle_p2p_size_estimate(void *cls,
- const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_MessageHeader *message,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+handle_p2p_size_estimate (void *cls,
+ const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_MessageHeader *message,
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
const struct GNUNET_NSE_FloodMessage *incoming_flood;
struct GNUNET_TIME_Absolute ts;
struct NSEPeerEntry *peer_entry;
- uint32_t matching_bits;
+ uint32_t matching_bits;
unsigned int idx;
#if ENABLE_HISTOGRAM
@@ -980,10 +956,7 @@
GNUNET_BIO_write_int64 (wh, GNUNET_TIME_absolute_get ().abs_value);
#endif
incoming_flood = (const struct GNUNET_NSE_FloodMessage *) message;
- GNUNET_STATISTICS_update (stats,
- "# flood messages received",
- 1,
- GNUNET_NO);
+ GNUNET_STATISTICS_update (stats, "# flood messages received", 1, GNUNET_NO);
matching_bits = ntohl (incoming_flood->matching_bits);
#if DEBUG_NSE
{
@@ -992,133 +965,124 @@
struct GNUNET_PeerIdentity os;
GNUNET_CRYPTO_hash (&incoming_flood->pkey,
- sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
- &os.hashPubKey);
- GNUNET_snprintf (origin, sizeof (origin),
- "%s",
- GNUNET_i2s (&os));
- GNUNET_snprintf (pred, sizeof (pred),
- "%s",
- GNUNET_i2s (peer));
+ sizeof (struct
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+ &os.hashPubKey);
+ GNUNET_snprintf (origin, sizeof (origin), "%s", GNUNET_i2s (&os));
+ GNUNET_snprintf (pred, sizeof (pred), "%s", GNUNET_i2s (peer));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Flood at %llu from `%s' via `%s' at `%s' with bits %u\n",
- (unsigned long long) GNUNET_TIME_absolute_ntoh
(incoming_flood->timestamp).abs_value,
- origin,
- pred,
- GNUNET_i2s (&my_identity),
- (unsigned int) matching_bits);
+ "Flood at %llu from `%s' via `%s' at `%s' with bits %u\n",
+ (unsigned long long)
+ GNUNET_TIME_absolute_ntoh
(incoming_flood->timestamp).abs_value,
+ origin, pred, GNUNET_i2s (&my_identity),
+ (unsigned int) matching_bits);
}
-#endif
+#endif
peer_entry = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey);
if (NULL == peer_entry)
- {
- GNUNET_break (0);
- return GNUNET_OK;
- }
+ {
+ GNUNET_break (0);
+ return GNUNET_OK;
+ }
ts = GNUNET_TIME_absolute_ntoh (incoming_flood->timestamp);
if (ts.abs_value == current_timestamp.abs_value)
idx = estimate_index;
- else if (ts.abs_value == current_timestamp.abs_value -
gnunet_nse_interval.rel_value)
+ else if (ts.abs_value ==
+ current_timestamp.abs_value - gnunet_nse_interval.rel_value)
idx = (estimate_index + HISTORY_SIZE - 1) % HISTORY_SIZE;
- else if (ts.abs_value == next_timestamp.abs_value -
gnunet_nse_interval.rel_value)
+ else if (ts.abs_value ==
+ next_timestamp.abs_value - gnunet_nse_interval.rel_value)
+ {
+ if (matching_bits <= ntohl (next_message.matching_bits))
+ return GNUNET_OK; /* ignore, simply too early/late */
+ if (GNUNET_YES != verify_message_crypto (incoming_flood))
{
- if (matching_bits <= ntohl (next_message.matching_bits))
- return GNUNET_OK; /* ignore, simply too early/late */
- if (GNUNET_YES !=
- verify_message_crypto (incoming_flood))
- {
- GNUNET_break_op (0);
- return GNUNET_OK;
- }
- next_message = *incoming_flood;
+ GNUNET_break_op (0);
return GNUNET_OK;
}
+ next_message = *incoming_flood;
+ return GNUNET_OK;
+ }
else
+ {
+ GNUNET_STATISTICS_update (stats,
+ "# flood messages discarded (clock skew too
large)",
+ 1, GNUNET_NO);
+ return GNUNET_OK;
+ }
+ if (0 == (memcmp (peer, &my_identity, sizeof (struct GNUNET_PeerIdentity))))
+ {
+ /* send to self, update our own estimate IF this also comes from us! */
+ if (0 == memcmp (&incoming_flood->pkey,
+ &my_public_key, sizeof (my_public_key)))
+ update_network_size_estimate ();
+ return GNUNET_OK;
+ }
+ if (matching_bits >= ntohl (size_estimate_messages[idx].matching_bits))
+ {
+ /* cancel transmission from us to this peer for this round */
+ if (idx == estimate_index)
{
- GNUNET_STATISTICS_update (stats,
- "# flood messages discarded (clock skew too
large)",
- 1,
- GNUNET_NO);
- return GNUNET_OK;
+ if (peer_entry->previous_round == GNUNET_YES)
+ {
+ /* cancel any activity for current round */
+ if (peer_entry->transmit_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (peer_entry->transmit_task);
+ peer_entry->transmit_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ if (peer_entry->th != NULL)
+ {
+ GNUNET_CORE_notify_transmit_ready_cancel (peer_entry->th);
+ peer_entry->th = NULL;
+ }
+ }
}
- if (0 == (memcmp (peer, &my_identity, sizeof(struct GNUNET_PeerIdentity))))
+ else
{
- /* send to self, update our own estimate IF this also comes from us! */
- if (0 == memcmp (&incoming_flood->pkey,
- &my_public_key,
- sizeof (my_public_key)))
- update_network_size_estimate ();
- return GNUNET_OK;
+ /* cancel previous round only */
+ peer_entry->previous_round = GNUNET_YES;
}
- if (matching_bits >= ntohl (size_estimate_messages[idx].matching_bits))
- {
- /* cancel transmission from us to this peer for this round */
- if (idx == estimate_index)
- {
- if (peer_entry->previous_round == GNUNET_YES)
- {
- /* cancel any activity for current round */
- if (peer_entry->transmit_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (peer_entry->transmit_task);
- peer_entry->transmit_task = GNUNET_SCHEDULER_NO_TASK;
- }
- if (peer_entry->th != NULL)
- {
- GNUNET_CORE_notify_transmit_ready_cancel (peer_entry->th);
- peer_entry->th = NULL;
- }
- }
- }
- else
- {
- /* cancel previous round only */
- peer_entry->previous_round = GNUNET_YES;
- }
- }
+ }
if (matching_bits == ntohl (size_estimate_messages[idx].matching_bits))
return GNUNET_OK;
- if (matching_bits <= ntohl (size_estimate_messages[idx].matching_bits))
+ if (matching_bits <= ntohl (size_estimate_messages[idx].matching_bits))
+ {
+ if ((idx < estimate_index) && (peer_entry->previous_round == GNUNET_YES))
+ peer_entry->previous_round = GNUNET_NO;
+ /* push back our result now, that peer is spreading bad information... */
+ if (NULL == peer_entry->th)
{
- if ( (idx < estimate_index) &&
- (peer_entry->previous_round == GNUNET_YES) )
- peer_entry->previous_round = GNUNET_NO;
- /* push back our result now, that peer is spreading bad information... */
- if (NULL == peer_entry->th)
- {
- if (peer_entry->transmit_task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel (peer_entry->transmit_task);
- peer_entry->transmit_task = GNUNET_SCHEDULER_add_now (&transmit_task,
- peer_entry);
- }
- /* Not closer than our most recent message, no need to do work here */
- GNUNET_STATISTICS_update (stats,
- "# flood messages ignored (had closer
already)",
- 1,
- GNUNET_NO);
- return GNUNET_OK;
+ if (peer_entry->transmit_task != GNUNET_SCHEDULER_NO_TASK)
+ GNUNET_SCHEDULER_cancel (peer_entry->transmit_task);
+ peer_entry->transmit_task = GNUNET_SCHEDULER_add_now (&transmit_task,
+ peer_entry);
}
- if (GNUNET_YES !=
- verify_message_crypto (incoming_flood))
- {
- GNUNET_break_op (0);
- return GNUNET_OK;
- }
+ /* Not closer than our most recent message, no need to do work here */
+ GNUNET_STATISTICS_update (stats,
+ "# flood messages ignored (had closer already)",
+ 1, GNUNET_NO);
+ return GNUNET_OK;
+ }
+ if (GNUNET_YES != verify_message_crypto (incoming_flood))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_OK;
+ }
size_estimate_messages[idx] = *incoming_flood;
- size_estimate_messages[idx].hop_count = htonl (ntohl
(incoming_flood->hop_count) + 1);
- hop_count_max = GNUNET_MAX (ntohl (incoming_flood->hop_count) + 1,
- hop_count_max);
+ size_estimate_messages[idx].hop_count =
+ htonl (ntohl (incoming_flood->hop_count) + 1);
+ hop_count_max =
+ GNUNET_MAX (ntohl (incoming_flood->hop_count) + 1, hop_count_max);
/* have a new, better size estimate, inform clients */
update_network_size_estimate ();
/* flood to rest */
GNUNET_CONTAINER_multihashmap_iterate (peers,
- &update_flood_times,
- peer_entry);
+ &update_flood_times, peer_entry);
return GNUNET_OK;
}
@@ -1132,25 +1096,24 @@
* @param atsi performance data
*/
static void
-handle_core_connect(void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
struct NSEPeerEntry *peer_entry;
- #if DEBUG_NSE
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Peer `%s' connected to us\n",
- GNUNET_i2s (peer));
+#if DEBUG_NSE
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Peer `%s' connected to us\n", GNUNET_i2s (peer));
#endif
- peer_entry = GNUNET_malloc(sizeof(struct NSEPeerEntry));
+ peer_entry = GNUNET_malloc (sizeof (struct NSEPeerEntry));
peer_entry->id = *peer;
GNUNET_CONTAINER_multihashmap_put (peers,
- &peer->hashPubKey,
- peer_entry,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
- peer_entry->transmit_task = GNUNET_SCHEDULER_add_delayed (get_transmit_delay
(-1),
- &transmit_task,
- peer_entry);
+ &peer->hashPubKey,
+ peer_entry,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+ peer_entry->transmit_task =
+ GNUNET_SCHEDULER_add_delayed (get_transmit_delay (-1), &transmit_task,
+ peer_entry);
}
@@ -1161,34 +1124,31 @@
* @param peer peer identity this notification is about
*/
static void
-handle_core_disconnect(void *cls, const struct GNUNET_PeerIdentity *peer)
+handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
{
struct NSEPeerEntry *pos;
- #if DEBUG_NSE
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Peer `%s' disconnected from us\n",
- GNUNET_i2s (peer));
+#if DEBUG_NSE
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Peer `%s' disconnected from us\n", GNUNET_i2s (peer));
#endif
- pos = GNUNET_CONTAINER_multihashmap_get (peers,
- &peer->hashPubKey);
+ pos = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey);
if (NULL == pos)
- {
- GNUNET_break (0);
- return;
- }
+ {
+ GNUNET_break (0);
+ return;
+ }
GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove (peers,
- &peer->hashPubKey,
- pos));
+ GNUNET_CONTAINER_multihashmap_remove (peers,
+ &peer->hashPubKey,
pos));
if (pos->transmit_task != GNUNET_SCHEDULER_NO_TASK)
GNUNET_SCHEDULER_cancel (pos->transmit_task);
if (pos->th != NULL)
- {
- GNUNET_CORE_notify_transmit_ready_cancel (pos->th);
- pos->th = NULL;
- }
- GNUNET_free(pos);
+ {
+ GNUNET_CORE_notify_transmit_ready_cancel (pos->th);
+ pos->th = NULL;
+ }
+ GNUNET_free (pos);
}
@@ -1199,51 +1159,50 @@
* @param tc unused
*/
static void
-shutdown_task(void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
if (flood_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (flood_task);
- flood_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (flood_task);
+ flood_task = GNUNET_SCHEDULER_NO_TASK;
+ }
if (proof_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (proof_task);
- proof_task = GNUNET_SCHEDULER_NO_TASK;
- write_proof (); /* remember progress */
- }
+ {
+ GNUNET_SCHEDULER_cancel (proof_task);
+ proof_task = GNUNET_SCHEDULER_NO_TASK;
+ write_proof (); /* remember progress */
+ }
if (nc != NULL)
- {
- GNUNET_SERVER_notification_context_destroy (nc);
- nc = NULL;
- }
+ {
+ GNUNET_SERVER_notification_context_destroy (nc);
+ nc = NULL;
+ }
if (coreAPI != NULL)
- {
- GNUNET_CORE_disconnect (coreAPI);
- coreAPI = NULL;
- }
+ {
+ GNUNET_CORE_disconnect (coreAPI);
+ coreAPI = NULL;
+ }
if (stats != NULL)
- {
- GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
- stats = NULL;
- }
+ {
+ GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
+ stats = NULL;
+ }
if (peers != NULL)
- {
- GNUNET_CONTAINER_multihashmap_destroy (peers);
- peers = NULL;
- }
+ {
+ GNUNET_CONTAINER_multihashmap_destroy (peers);
+ peers = NULL;
+ }
if (my_private_key != NULL)
- {
- GNUNET_CRYPTO_rsa_key_free (my_private_key);
- my_private_key = NULL;
- }
+ {
+ GNUNET_CRYPTO_rsa_key_free (my_private_key);
+ my_private_key = NULL;
+ }
#if ENABLE_HISTOGRAM
if (wh != NULL)
- {
- GNUNET_BIO_write_close (wh);
- wh = NULL;
- }
+ {
+ GNUNET_BIO_write_close (wh);
+ wh = NULL;
+ }
#endif
}
@@ -1258,37 +1217,45 @@
*/
static void
core_init (void *cls, struct GNUNET_CORE_Handle *server,
- const struct GNUNET_PeerIdentity *identity,
- const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
+ const struct GNUNET_PeerIdentity *identity,
+ const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
{
struct GNUNET_TIME_Absolute now;
struct GNUNET_TIME_Absolute prev_time;
unsigned int i;
if (server == NULL)
- {
+ {
#if DEBUG_NSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connection to core FAILED!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connection to core FAILED!\n");
#endif
- GNUNET_SCHEDULER_shutdown ();
- return;
- }
- GNUNET_assert (0 == memcmp (&my_identity, identity, sizeof (struct
GNUNET_PeerIdentity)));
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ GNUNET_assert (0 ==
+ memcmp (&my_identity, identity,
+ sizeof (struct GNUNET_PeerIdentity)));
now = GNUNET_TIME_absolute_get ();
- current_timestamp.abs_value = (now.abs_value /
gnunet_nse_interval.rel_value) * gnunet_nse_interval.rel_value;
- next_timestamp.abs_value = current_timestamp.abs_value +
gnunet_nse_interval.rel_value;
-
+ current_timestamp.abs_value =
+ (now.abs_value / gnunet_nse_interval.rel_value) *
+ gnunet_nse_interval.rel_value;
+ next_timestamp.abs_value =
+ current_timestamp.abs_value + gnunet_nse_interval.rel_value;
+
for (i = 0; i < HISTORY_SIZE; i++)
- {
- prev_time.abs_value = current_timestamp.abs_value - (HISTORY_SIZE - i -
1) * gnunet_nse_interval.rel_value;
- setup_flood_message (i, prev_time);
- }
+ {
+ prev_time.abs_value =
+ current_timestamp.abs_value - (HISTORY_SIZE - i -
+ 1) * gnunet_nse_interval.rel_value;
+ setup_flood_message (i, prev_time);
+ }
estimate_index = HISTORY_SIZE - 1;
estimate_count = 2;
flood_task
- = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
(next_timestamp),
- &update_flood_message, NULL);
+ =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
+ (next_timestamp), &update_flood_message,
+ NULL);
}
@@ -1300,131 +1267,128 @@
* @param c configuration to use
*/
static void
-run(void *cls, struct GNUNET_SERVER_Handle *server,
- const struct GNUNET_CONFIGURATION_Handle *c)
+run (void *cls, struct GNUNET_SERVER_Handle *server,
+ const struct GNUNET_CONFIGURATION_Handle *c)
{
char *keyfile;
char *proof;
- static const struct GNUNET_SERVER_MessageHandler handlers[] =
- {
- { &handle_start_message, NULL, GNUNET_MESSAGE_TYPE_NSE_START, sizeof
(struct GNUNET_MessageHeader) },
- { NULL, NULL, 0, 0 }
- };
- static const struct GNUNET_CORE_MessageHandler core_handlers[] =
- {
- { &handle_p2p_size_estimate, GNUNET_MESSAGE_TYPE_NSE_P2P_FLOOD, sizeof
(struct GNUNET_NSE_FloodMessage) },
- { NULL, 0, 0 }
- };
+ static const struct GNUNET_SERVER_MessageHandler handlers[] = {
+ {&handle_start_message, NULL, GNUNET_MESSAGE_TYPE_NSE_START,
+ sizeof (struct GNUNET_MessageHeader)},
+ {NULL, NULL, 0, 0}
+ };
+ static const struct GNUNET_CORE_MessageHandler core_handlers[] = {
+ {&handle_p2p_size_estimate, GNUNET_MESSAGE_TYPE_NSE_P2P_FLOOD,
+ sizeof (struct GNUNET_NSE_FloodMessage)},
+ {NULL, 0, 0}
+ };
cfg = c;
- if ( (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_time (cfg,
- "NSE", "INTERVAL",
- &gnunet_nse_interval)) ||
- (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_time (cfg,
- "NSE", "WORKDELAY",
- &proof_find_delay)) ||
- (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (cfg,
- "NSE", "WORKBITS",
- &nse_work_required)) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _ ("NSE service is lacking key configuration settings.
Exiting.\n"));
- GNUNET_SCHEDULER_shutdown ();
- return;
- }
+ if ((GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_time (cfg,
+ "NSE", "INTERVAL",
+ &gnunet_nse_interval)) ||
+ (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_time (cfg,
+ "NSE", "WORKDELAY",
+ &proof_find_delay)) ||
+ (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_number (cfg,
+ "NSE", "WORKBITS",
+ &nse_work_required)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _
+ ("NSE service is lacking key configuration settings.
Exiting.\n"));
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
if (nse_work_required >= sizeof (GNUNET_HashCode) * 8)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _ ("Invalid work requirement for NSE service. Exiting.\n"));
- GNUNET_SCHEDULER_shutdown ();
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Invalid work requirement for NSE service. Exiting.\n"));
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
- if (GNUNET_OK !=
+ if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_filename (cfg,
- "GNUNETD", "HOSTKEY",
- &keyfile))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _ ("NSE service is lacking key configuration settings.
Exiting.\n"));
- GNUNET_SCHEDULER_shutdown ();
- return;
- }
+ "GNUNETD", "HOSTKEY", &keyfile))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _
+ ("NSE service is lacking key configuration settings.
Exiting.\n"));
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
GNUNET_free (keyfile);
if (my_private_key == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("NSE service could not access hostkey. Exiting.\n"));
- GNUNET_SCHEDULER_shutdown ();
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("NSE service could not access hostkey. Exiting.\n"));
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key);
- GNUNET_CRYPTO_hash (&my_public_key, sizeof (my_public_key),
&my_identity.hashPubKey);
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (cfg,
- "NSE", "PROOFFILE",
- &proof))
+ GNUNET_CRYPTO_hash (&my_public_key, sizeof (my_public_key),
+ &my_identity.hashPubKey);
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_filename (cfg, "NSE", "PROOFFILE",
&proof))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _
+ ("NSE service is lacking key configuration settings.
Exiting.\n"));
+ if (my_private_key != NULL)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _ ("NSE service is lacking key configuration settings.
Exiting.\n"));
- if (my_private_key != NULL)
- {
- GNUNET_CRYPTO_rsa_key_free (my_private_key);
- my_private_key = NULL;
- }
- GNUNET_SCHEDULER_shutdown ();
- return;
+ GNUNET_CRYPTO_rsa_key_free (my_private_key);
+ my_private_key = NULL;
}
- if ( (GNUNET_YES != GNUNET_DISK_file_test (proof)) ||
- (sizeof (my_proof) !=
- GNUNET_DISK_fn_read (proof,
- &my_proof,
- sizeof (my_proof))) )
- my_proof = 0;
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ if ((GNUNET_YES != GNUNET_DISK_file_test (proof)) ||
+ (sizeof (my_proof) !=
+ GNUNET_DISK_fn_read (proof, &my_proof, sizeof (my_proof))))
+ my_proof = 0;
GNUNET_free (proof);
- proof_task = GNUNET_SCHEDULER_add_with_priority
(GNUNET_SCHEDULER_PRIORITY_IDLE,
- &find_proof,
- NULL);
+ proof_task =
+ GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
+ &find_proof, NULL);
peers = GNUNET_CONTAINER_multihashmap_create (128);
GNUNET_SERVER_add_handlers (server, handlers);
nc = GNUNET_SERVER_notification_context_create (server, 1);
/* Connect to core service and register core handlers */
- coreAPI = GNUNET_CORE_connect (cfg, /* Main configuration */
- CORE_QUEUE_SIZE, /* queue size */
- NULL, /* Closure passed to functions */
- &core_init, /* Call core_init once connected */
- &handle_core_connect, /* Handle connects */
- &handle_core_disconnect, /* Handle disconnects
*/
- NULL, /* Do we care about "status" updates? */
- NULL, /* Don't want notified about all
incoming messages */
- GNUNET_NO, /* For header only inbound
notification */
- NULL, /* Don't want notified about all
outbound messages */
- GNUNET_NO, /* For header only outbound
notification */
- core_handlers); /* Register these handlers */
+ coreAPI = GNUNET_CORE_connect (cfg, /* Main configuration */
+ CORE_QUEUE_SIZE, /* queue size */
+ NULL, /* Closure passed to functions */
+ &core_init, /* Call core_init once
connected */
+ &handle_core_connect, /* Handle connects */
+ &handle_core_disconnect, /* Handle
disconnects */
+ NULL, /* Do we care about "status" updates?
*/
+ NULL, /* Don't want notified about all
incoming messages */
+ GNUNET_NO, /* For header only inbound
notification */
+ NULL, /* Don't want notified about all
outbound messages */
+ GNUNET_NO, /* For header only outbound
notification */
+ core_handlers); /* Register these
handlers */
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task, NULL);
+ &shutdown_task, NULL);
#if ENABLE_HISTOGRAM
- if (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_filename (cfg,
- "NSE", "HISTOGRAM",
- &proof))
- {
- wh = GNUNET_BIO_write_open (proof);
- GNUNET_free (proof);
- }
+ if (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_filename (cfg, "NSE", "HISTOGRAM",
&proof))
+ {
+ wh = GNUNET_BIO_write_open (proof);
+ GNUNET_free (proof);
+ }
#endif
if (coreAPI == NULL)
- {
- GNUNET_SCHEDULER_shutdown ();
- return;
- }
+ {
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
stats = GNUNET_STATISTICS_create ("nse", cfg);
}
@@ -1437,13 +1401,12 @@
* @return 0 ok, 1 on error
*/
int
-main(int argc, char * const *argv)
+main (int argc, char *const *argv)
{
- return (GNUNET_OK == GNUNET_SERVICE_run (argc, argv,
- "nse",
+ return (GNUNET_OK == GNUNET_SERVICE_run (argc, argv,
+ "nse",
GNUNET_SERVICE_OPTION_NONE, &run,
NULL)) ? 0 : 1;
}
/* end of gnunet-service-nse.c */
-
Modified: gnunet/src/nse/nse_api.c
===================================================================
--- gnunet/src/nse/nse_api.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/nse/nse_api.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -86,8 +86,7 @@
* @param tc scheduler context
*/
static void
-reconnect (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
/**
@@ -97,38 +96,33 @@
* @param cls closure
* @param msg message received, NULL on timeout or fatal error
*/
-static void
-message_handler (void *cls,
- const struct GNUNET_MessageHeader * msg)
+static void
+message_handler (void *cls, const struct GNUNET_MessageHeader *msg)
{
struct GNUNET_NSE_Handle *h = cls;
const struct GNUNET_NSE_ClientMessage *client_msg;
if (msg == NULL)
- {
- /* Error, timeout, death */
- GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
- h->client = NULL;
- h->reconnect_task = GNUNET_SCHEDULER_add_delayed (h->reconnect_delay,
- &reconnect,
- h);
- return;
- }
- if ( (ntohs (msg->size) != sizeof(struct GNUNET_NSE_ClientMessage)) ||
- (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_NSE_ESTIMATE) )
- {
- GNUNET_break (0);
- return;
- }
- client_msg = (const struct GNUNET_NSE_ClientMessage *)msg;
- h->recv_cb (h->recv_cb_cls,
- GNUNET_TIME_absolute_ntoh(client_msg->timestamp),
- client_msg->size_estimate,
- client_msg->std_deviation);
+ {
+ /* Error, timeout, death */
+ GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
+ h->client = NULL;
+ h->reconnect_task = GNUNET_SCHEDULER_add_delayed (h->reconnect_delay,
+ &reconnect, h);
+ return;
+ }
+ if ((ntohs (msg->size) != sizeof (struct GNUNET_NSE_ClientMessage)) ||
+ (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_NSE_ESTIMATE))
+ {
+ GNUNET_break (0);
+ return;
+ }
+ client_msg = (const struct GNUNET_NSE_ClientMessage *) msg;
+ h->recv_cb (h->recv_cb_cls,
+ GNUNET_TIME_absolute_ntoh (client_msg->timestamp),
+ client_msg->size_estimate, client_msg->std_deviation);
GNUNET_CLIENT_receive (h->client,
- &message_handler,
- h,
- GNUNET_TIME_UNIT_FOREVER_REL);
+ &message_handler, h, GNUNET_TIME_UNIT_FOREVER_REL);
}
@@ -144,15 +138,15 @@
GNUNET_assert (h->reconnect_task == GNUNET_SCHEDULER_NO_TASK);
if (NULL != h->th)
- {
- GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
- h->th = NULL;
- }
+ {
+ GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
+ h->th = NULL;
+ }
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_NSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -160,18 +154,17 @@
h->reconnect_delay.rel_value);
#endif
h->reconnect_task
- = GNUNET_SCHEDULER_add_delayed (h->reconnect_delay,
- &reconnect, h);
+ = GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h);
if (h->reconnect_delay.rel_value == 0)
- {
- h->reconnect_delay = GNUNET_TIME_UNIT_MILLISECONDS;
- }
+ {
+ h->reconnect_delay = GNUNET_TIME_UNIT_MILLISECONDS;
+ }
else
- {
- h->reconnect_delay = GNUNET_TIME_relative_multiply (h->reconnect_delay,
2);
- h->reconnect_delay = GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_SECONDS,
- h->reconnect_delay);
- }
+ {
+ h->reconnect_delay = GNUNET_TIME_relative_multiply (h->reconnect_delay, 2);
+ h->reconnect_delay = GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_SECONDS,
+ h->reconnect_delay);
+ }
}
@@ -191,23 +184,21 @@
h->th = NULL;
if (buf == NULL)
- {
- /* Connect error... */
+ {
+ /* Connect error... */
#if DEBUG_NSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Shutdown while trying to transmit `%s' request.\n",
- "START");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Shutdown while trying to transmit `%s' request.\n", "START");
#endif
- reschedule_connect(h);
- return 0;
- }
+ reschedule_connect (h);
+ return 0;
+ }
#if DEBUG_NSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitting `%s' request.\n", "START");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting `%s' request.\n",
"START");
#endif
GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader));
- msg = (struct GNUNET_MessageHeader *)buf;
+ msg = (struct GNUNET_MessageHeader *) buf;
msg->size = htons (sizeof (struct GNUNET_MessageHeader));
msg->type = htons (GNUNET_MESSAGE_TYPE_NSE_START);
GNUNET_CLIENT_receive (h->client,
@@ -223,17 +214,16 @@
* @param tc scheduler context
*/
static void
-reconnect (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_NSE_Handle *h = cls;
h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- {
- /* shutdown, just give up */
- return;
- }
+ {
+ /* shutdown, just give up */
+ return;
+ }
#if DEBUG_NSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Connecting to network size estimation service.\n");
@@ -243,13 +233,11 @@
GNUNET_assert (h->client != NULL);
h->th =
- GNUNET_CLIENT_notify_transmit_ready (h->client,
- sizeof(struct GNUNET_MessageHeader),
- GNUNET_TIME_UNIT_FOREVER_REL,
- GNUNET_NO,
- &send_start,
- h);
- GNUNET_assert(h->th != NULL);
+ GNUNET_CLIENT_notify_transmit_ready (h->client,
+ sizeof (struct
GNUNET_MessageHeader),
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_NO, &send_start, h);
+ GNUNET_assert (h->th != NULL);
}
@@ -287,23 +275,23 @@
void
GNUNET_NSE_disconnect (struct GNUNET_NSE_Handle *h)
{
- GNUNET_assert(h != NULL);
+ GNUNET_assert (h != NULL);
if (h->reconnect_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel(h->reconnect_task);
- h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (h->reconnect_task);
+ h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
+ }
if (h->th != NULL)
- {
- GNUNET_CLIENT_notify_transmit_ready_cancel(h->th);
- h->th = NULL;
- }
+ {
+ GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
+ h->th = NULL;
+ }
if (h->client != NULL)
- {
- GNUNET_CLIENT_disconnect(h->client, GNUNET_NO);
- h->client = NULL;
- }
- GNUNET_free(h);
+ {
+ GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
+ h->client = NULL;
+ }
+ GNUNET_free (h);
}
/* end of nse_api.c */
Modified: gnunet/src/nse/test_nse_api.c
===================================================================
--- gnunet/src/nse/test_nse_api.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/nse/test_nse_api.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -68,15 +68,13 @@
* @param tc context information (why was this task triggered now)
*/
static void
-end_test (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext * tc)
+end_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
if (h != NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Disconnecting from NSE service.\n");
- GNUNET_NSE_disconnect (h);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from NSE service.\n");
+ GNUNET_NSE_disconnect (h);
+ }
}
/**
@@ -90,20 +88,20 @@
*
*/
static void
-check_nse_message (void *cls,
- struct GNUNET_TIME_Absolute timestamp,
- double estimate, double std_dev)
+check_nse_message (void *cls,
+ struct GNUNET_TIME_Absolute timestamp,
+ double estimate, double std_dev)
{
int *ok = cls;
fprintf (stderr,
- "Received NSE message, estimate %f, standard deviation %f.\n",
- estimate, std_dev);
+ "Received NSE message, estimate %f, standard deviation %f.\n",
+ estimate, std_dev);
/* Fantastic check below. Expect NaN, the only thing not equal to itself. */
(*ok) = 0;
if (die_task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel(die_task);
- die_task = GNUNET_SCHEDULER_add_now(&end_test, NULL);
+ GNUNET_SCHEDULER_cancel (die_task);
+ die_task = GNUNET_SCHEDULER_add_now (&end_test, NULL);
}
@@ -113,12 +111,12 @@
p->cfg = GNUNET_CONFIGURATION_create ();
#if START_ARM
p->arm_proc = GNUNET_OS_start_process (NULL, NULL,
- "gnunet-service-arm",
- "gnunet-service-arm",
+ "gnunet-service-arm",
+ "gnunet-service-arm",
#if VERBOSE_ARM
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", cfgname, NULL);
+ "-c", cfgname, NULL);
#endif
GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
@@ -129,8 +127,7 @@
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_MINUTES, 1),
@@ -138,8 +135,7 @@
setup_peer (&p1, cfgfile);
h = GNUNET_NSE_connect (cfg, &check_nse_message, cls);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connecting to NSE service.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting to NSE service.\n");
GNUNET_assert (h != NULL);
}
@@ -148,13 +144,14 @@
check ()
{
int ok = 1;
+
char *const argv[] = { "test-nse-api",
"-c",
"test_nse.conf",
#if DEBUG_NSE
- "-L", "DEBUG",
+ "-L", "DEBUG",
#else
- "-L", "WARNING",
+ "-L", "WARNING",
#endif
NULL
};
@@ -162,10 +159,8 @@
GNUNET_GETOPT_OPTION_END
};
- GNUNET_PROGRAM_run (5, argv, "test-nse-api", "nohelp",
- options, &run, &ok);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Stopping arm.\n");
+ GNUNET_PROGRAM_run (5, argv, "test-nse-api", "nohelp", options, &run, &ok);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping arm.\n");
stop_arm (&p1);
return ok;
}
Modified: gnunet/src/nse/test_nse_multipeer.c
===================================================================
--- gnunet/src/nse/test_nse_multipeer.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/nse/test_nse_multipeer.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -70,40 +70,38 @@
shutdown_callback (void *cls, const char *emsg)
{
if (emsg != NULL)
- {
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Shutdown of peers failed: %s!\n",
- emsg);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Shutdown of peers failed: %s!\n", emsg);
#endif
- if (ok == 0)
- ok = 666;
- }
+ if (ok == 0)
+ ok = 666;
+ }
else
- {
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "All peers successfully shut down!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers successfully shut
down!\n");
#endif
- ok = 0;
- }
+ ok = 0;
+ }
}
static void
-shutdown_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct NSEPeer *pos;
+
#if VERBOSE
- fprintf(stderr, "Ending test.\n");
+ fprintf (stderr, "Ending test.\n");
#endif
while (NULL != (pos = peer_head))
- {
- GNUNET_NSE_disconnect(pos->nse_handle);
- GNUNET_CONTAINER_DLL_remove(peer_head, peer_tail, pos);
- GNUNET_free(pos);
- }
+ {
+ GNUNET_NSE_disconnect (pos->nse_handle);
+ GNUNET_CONTAINER_DLL_remove (peer_head, peer_tail, pos);
+ GNUNET_free (pos);
+ }
GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
}
@@ -120,64 +118,61 @@
*/
static void
handle_estimate (void *cls,
- struct GNUNET_TIME_Absolute timestamp,
- double estimate, double std_dev)
+ struct GNUNET_TIME_Absolute timestamp,
+ double estimate, double std_dev)
{
struct NSEPeer *peer = cls;
fprintf (stderr,
- "Received network size estimate from peer %s. logSize: %f std.dev.
%f (%f/%u)\n",
- GNUNET_i2s(&peer->daemon->id),
- estimate,
- std_dev,
- GNUNET_NSE_log_estimate_to_n (estimate),
- num_peers);
+ "Received network size estimate from peer %s. logSize: %f std.dev.
%f (%f/%u)\n",
+ GNUNET_i2s (&peer->daemon->id),
+ estimate,
+ std_dev, GNUNET_NSE_log_estimate_to_n (estimate), num_peers);
}
static void
-connect_nse_service (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+connect_nse_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct NSEPeer *current_peer;
unsigned int i;
+
#if VERBOSE
- fprintf(stderr, "TEST_NSE_MULTIPEER: connecting to nse service of peers\n");
+ fprintf (stderr, "TEST_NSE_MULTIPEER: connecting to nse service of peers\n");
#endif
for (i = 0; i < num_peers; i++)
- {
- current_peer = GNUNET_malloc(sizeof(struct NSEPeer));
- current_peer->daemon = GNUNET_TESTING_daemon_get(pg, i);
- current_peer->nse_handle = GNUNET_NSE_connect (current_peer->daemon->cfg,
- &handle_estimate,
- current_peer);
- GNUNET_assert(current_peer->nse_handle != NULL);
- GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, current_peer);
- }
+ {
+ current_peer = GNUNET_malloc (sizeof (struct NSEPeer));
+ current_peer->daemon = GNUNET_TESTING_daemon_get (pg, i);
+ current_peer->nse_handle = GNUNET_NSE_connect (current_peer->daemon->cfg,
+ &handle_estimate,
+ current_peer);
+ GNUNET_assert (current_peer->nse_handle != NULL);
+ GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, current_peer);
+ }
}
static void
-my_cb (void *cls,
- const char *emsg)
+my_cb (void *cls, const char *emsg)
{
if (emsg != NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peergroup callback called with error, aborting test!\n");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error from testing: `%s'\n");
- ok = 1;
- GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Peergroup callback called with error, aborting test!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error from testing: `%s'\n");
+ ok = 1;
+ GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
+ return;
+ }
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Peer Group started successfully, connecting to NSE service for
each peer!\n");
#endif
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Have %u connections\n", total_connections);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Have %u connections\n", total_connections);
- GNUNET_SCHEDULER_add_now(&connect_nse_service, NULL);
+ GNUNET_SCHEDULER_add_now (&connect_nse_service, NULL);
}
@@ -195,22 +190,21 @@
* @param second_daemon handle for the second daemon
* @param emsg error message (NULL on success)
*/
-static void
+static void
connect_cb (void *cls,
- const struct GNUNET_PeerIdentity *first,
- const struct GNUNET_PeerIdentity *second,
- uint32_t distance,
- const struct GNUNET_CONFIGURATION_Handle *first_cfg,
- const struct GNUNET_CONFIGURATION_Handle *second_cfg,
- struct GNUNET_TESTING_Daemon *first_daemon,
- struct GNUNET_TESTING_Daemon *second_daemon,
- const char *emsg)
+ const struct GNUNET_PeerIdentity *first,
+ const struct GNUNET_PeerIdentity *second,
+ uint32_t distance,
+ const struct GNUNET_CONFIGURATION_Handle *first_cfg,
+ const struct GNUNET_CONFIGURATION_Handle *second_cfg,
+ struct GNUNET_TESTING_Daemon *first_daemon,
+ struct GNUNET_TESTING_Daemon *second_daemon, const char *emsg)
{
if (emsg == NULL)
- {
- //fprintf(stderr, "Connected %s -> %s\n", GNUNET_i2s(first), second_id);
- total_connections++;
- }
+ {
+ //fprintf(stderr, "Connected %s -> %s\n", GNUNET_i2s(first), second_id);
+ total_connections++;
+ }
}
@@ -224,30 +218,26 @@
unsigned long long total_peers;
ok = 1;
- testing_cfg = GNUNET_CONFIGURATION_create();
- GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_load(testing_cfg, cfgfile));
+ testing_cfg = GNUNET_CONFIGURATION_create ();
+ GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (testing_cfg,
cfgfile));
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemons.\n");
GNUNET_CONFIGURATION_set_value_string (testing_cfg,
- "testing",
- "use_progressbars",
- "YES");
+ "testing", "use_progressbars", "YES");
#endif
- if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (testing_cfg,
- "testing",
- "num_peers",
- &total_peers))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (testing_cfg,
+ "testing",
+ "num_peers",
+ &total_peers))
total_peers = NUM_PEERS;
peers_left = total_peers;
num_peers = peers_left;
- pg = GNUNET_TESTING_peergroup_start(testing_cfg,
- peers_left,
- TIMEOUT,
- &connect_cb,
- &my_cb, NULL,
- NULL);
+ pg = GNUNET_TESTING_peergroup_start (testing_cfg,
+ peers_left,
+ TIMEOUT,
+ &connect_cb, &my_cb, NULL, NULL);
GNUNET_assert (pg != NULL);
GNUNET_SCHEDULER_add_delayed (TIMEOUT, &shutdown_task, NULL);
}
@@ -268,8 +258,7 @@
GNUNET_GETOPT_OPTION_END
};
GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
- argv, "test-nse-multipeer", "nohelp",
- options, &run, &ok);
+ argv, "test-nse-multipeer", "nohelp", options, &run,
&ok);
return ok;
}
Modified: gnunet/src/peerinfo/gnunet-service-peerinfo.c
===================================================================
--- gnunet/src/peerinfo/gnunet-service-peerinfo.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/peerinfo/gnunet-service-peerinfo.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -130,13 +130,13 @@
const void *addr, uint16_t addrlen)
{
const struct GNUNET_TIME_Absolute *now = cls;
+
if (now->abs_value > expiration.abs_value)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Removing expired address of transport `%s'\n"),
- tname);
- return GNUNET_NO;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Removing expired address of transport `%s'\n"), tname);
+ return GNUNET_NO;
+ }
return GNUNET_OK;
}
@@ -153,8 +153,7 @@
char *fn;
GNUNET_CRYPTO_hash_to_enc (&id->hashPubKey, &fil);
- GNUNET_asprintf (&fn,
- "%s%s%s", networkIdDirectory, DIR_SEPARATOR_STR, &fil);
+ GNUNET_asprintf (&fn, "%s%s%s", networkIdDirectory, DIR_SEPARATOR_STR, &fil);
return fn;
}
@@ -172,8 +171,7 @@
msg = make_info_message (entry);
GNUNET_SERVER_notification_context_broadcast (notify_list,
- &msg->header,
- GNUNET_NO);
+ &msg->header, GNUNET_NO);
GNUNET_free (msg);
}
@@ -194,46 +192,41 @@
struct GNUNET_TIME_Absolute now;
char *fn;
- entry = GNUNET_CONTAINER_multihashmap_get (hostmap,
- &identity->hashPubKey);
+ entry = GNUNET_CONTAINER_multihashmap_get (hostmap, &identity->hashPubKey);
if (entry != NULL)
return;
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# peers known"),
- 1,
- GNUNET_NO);
+ gettext_noop ("# peers known"), 1, GNUNET_NO);
entry = GNUNET_malloc (sizeof (struct HostEntry));
entry->identity = *identity;
fn = get_host_filename (identity);
if (GNUNET_DISK_file_test (fn) == GNUNET_YES)
+ {
+ size = GNUNET_DISK_fn_read (fn, buffer, sizeof (buffer));
+ hello = (const struct GNUNET_HELLO_Message *) buffer;
+ if ((size < sizeof (struct GNUNET_MessageHeader)) ||
+ (size != ntohs ((((const struct GNUNET_MessageHeader *) hello)->size)))
+ || (size != GNUNET_HELLO_size (hello)))
{
- size = GNUNET_DISK_fn_read (fn, buffer, sizeof (buffer));
- hello = (const struct GNUNET_HELLO_Message *) buffer;
- if ( (size < sizeof (struct GNUNET_MessageHeader)) ||
- (size != ntohs((((const struct GNUNET_MessageHeader*)
hello)->size))) ||
- (size != GNUNET_HELLO_size (hello)) )
- {
- GNUNET_break (0);
- if (0 != UNLINK (fn))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
- "unlink",
- fn);
- }
- else
- {
- now = GNUNET_TIME_absolute_get ();
- hello_clean = GNUNET_HELLO_iterate_addresses (hello,
- GNUNET_YES,
- &discard_expired, &now);
- entry->hello = hello_clean;
- }
+ GNUNET_break (0);
+ if (0 != UNLINK (fn))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn);
}
+ else
+ {
+ now = GNUNET_TIME_absolute_get ();
+ hello_clean = GNUNET_HELLO_iterate_addresses (hello,
+ GNUNET_YES,
+ &discard_expired, &now);
+ entry->hello = hello_clean;
+ }
+ }
GNUNET_free (fn);
GNUNET_CONTAINER_multihashmap_put (hostmap,
- &identity->hashPubKey,
- entry,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+ &identity->hashPubKey,
+ entry,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
notify_all (entry);
}
@@ -257,8 +250,7 @@
static int
-hosts_directory_scan_callback (void *cls,
- const char *fullname)
+hosts_directory_scan_callback (void *cls, const char *fullname)
{
unsigned int *matched = cls;
struct GNUNET_PeerIdentity identity;
@@ -267,24 +259,24 @@
if (GNUNET_DISK_file_test (fullname) != GNUNET_YES)
return GNUNET_OK; /* ignore non-files */
if (strlen (fullname) < sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded))
- {
- remove_garbage (fullname);
- return GNUNET_OK;
- }
+ {
+ remove_garbage (fullname);
+ return GNUNET_OK;
+ }
filename =
- &fullname[strlen (fullname) -
- sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) + 1];
+ &fullname[strlen (fullname) -
+ sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) + 1];
if (filename[-1] != DIR_SEPARATOR)
- {
- remove_garbage (fullname);
- return GNUNET_OK;
- }
+ {
+ remove_garbage (fullname);
+ return GNUNET_OK;
+ }
if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (filename,
&identity.hashPubKey))
- {
- remove_garbage (fullname);
- return GNUNET_OK;
- }
+ {
+ remove_garbage (fullname);
+ return GNUNET_OK;
+ }
(*matched)++;
add_host_to_known_hosts (&identity);
return GNUNET_OK;
@@ -305,11 +297,11 @@
return;
count = 0;
if (GNUNET_SYSERR == GNUNET_DISK_directory_create (networkIdDirectory))
- {
- GNUNET_SCHEDULER_add_delayed (DATA_HOST_FREQ,
- &cron_scan_directory_data_hosts, NULL);
- return;
- }
+ {
+ GNUNET_SCHEDULER_add_delayed (DATA_HOST_FREQ,
+ &cron_scan_directory_data_hosts, NULL);
+ return;
+ }
GNUNET_DISK_directory_scan (networkIdDirectory,
&hosts_directory_scan_callback, &count);
if ((0 == count) && (0 == (++retries & 31)))
@@ -337,42 +329,39 @@
struct GNUNET_TIME_Absolute delta;
add_host_to_known_hosts (peer);
- host = GNUNET_CONTAINER_multihashmap_get (hostmap,
- &peer->hashPubKey);
+ host = GNUNET_CONTAINER_multihashmap_get (hostmap, &peer->hashPubKey);
GNUNET_assert (host != NULL);
if (host->hello == NULL)
- {
- host->hello = GNUNET_malloc (GNUNET_HELLO_size (hello));
- memcpy (host->hello, hello, GNUNET_HELLO_size (hello));
- }
+ {
+ host->hello = GNUNET_malloc (GNUNET_HELLO_size (hello));
+ memcpy (host->hello, hello, GNUNET_HELLO_size (hello));
+ }
else
+ {
+ mrg = GNUNET_HELLO_merge (host->hello, hello);
+ delta = GNUNET_HELLO_equals (mrg, host->hello, GNUNET_TIME_absolute_get
());
+ if (delta.abs_value == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value)
{
- mrg = GNUNET_HELLO_merge (host->hello, hello);
- delta = GNUNET_HELLO_equals (mrg,
- host->hello,
- GNUNET_TIME_absolute_get ());
- if (delta.abs_value == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value)
- {
- GNUNET_free (mrg);
- return;
- }
- GNUNET_free (host->hello);
- host->hello = mrg;
+ GNUNET_free (mrg);
+ return;
}
+ GNUNET_free (host->hello);
+ host->hello = mrg;
+ }
fn = get_host_filename (peer);
if (GNUNET_OK == GNUNET_DISK_directory_create_for_file (fn))
- {
- if (GNUNET_SYSERR ==
- GNUNET_DISK_fn_write (fn,
- host->hello,
- GNUNET_HELLO_size (host->hello),
- GNUNET_DISK_PERM_USER_READ |
GNUNET_DISK_PERM_USER_WRITE
- | GNUNET_DISK_PERM_GROUP_READ |
GNUNET_DISK_PERM_OTHER_READ))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
- "write",
- fn);
-
- }
+ {
+ if (GNUNET_SYSERR ==
+ GNUNET_DISK_fn_write (fn,
+ host->hello,
+ GNUNET_HELLO_size (host->hello),
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE |
+ GNUNET_DISK_PERM_GROUP_READ |
+ GNUNET_DISK_PERM_OTHER_READ))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", fn);
+
+ }
GNUNET_free (fn);
notify_all (host);
}
@@ -388,9 +377,7 @@
* @return GNUNET_YES (continue to iterate)
*/
static int
-add_to_tc (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+add_to_tc (void *cls, const GNUNET_HashCode * key, void *value)
{
struct GNUNET_SERVER_TransmitContext *tc = cls;
struct HostEntry *pos = value;
@@ -401,19 +388,18 @@
hs = 0;
im = (struct InfoMessage *) buf;
if (pos->hello != NULL)
- {
- hs = GNUNET_HELLO_size (pos->hello);
- GNUNET_assert (hs <
- GNUNET_SERVER_MAX_MESSAGE_SIZE -
- sizeof (struct InfoMessage));
- memcpy (&im[1], pos->hello, hs);
- }
+ {
+ hs = GNUNET_HELLO_size (pos->hello);
+ GNUNET_assert (hs <
+ GNUNET_SERVER_MAX_MESSAGE_SIZE -
+ sizeof (struct InfoMessage));
+ memcpy (&im[1], pos->hello, hs);
+ }
im->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_INFO);
im->header.size = htons (sizeof (struct InfoMessage) + hs);
im->reserved = htonl (0);
im->peer = pos->identity;
- GNUNET_SERVER_transmit_context_append_message (tc,
- &im->header);
+ GNUNET_SERVER_transmit_context_append_message (tc, &im->header);
return GNUNET_YES;
}
@@ -432,31 +418,33 @@
size = GNUNET_DISK_fn_read (fn, buffer, sizeof (buffer));
if (size < sizeof (struct GNUNET_MessageHeader))
- {
- if (0 != UNLINK (fn))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING |
- GNUNET_ERROR_TYPE_BULK, "unlink", fn);
- return GNUNET_OK;
- }
+ {
+ if (0 != UNLINK (fn))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING |
+ GNUNET_ERROR_TYPE_BULK, "unlink", fn);
+ return GNUNET_OK;
+ }
hello = (const struct GNUNET_HELLO_Message *) buffer;
new_hello = GNUNET_HELLO_iterate_addresses (hello,
GNUNET_YES,
&discard_expired, now);
if (new_hello != NULL)
- {
- GNUNET_DISK_fn_write (fn,
- new_hello,
- GNUNET_HELLO_size (new_hello),
- GNUNET_DISK_PERM_USER_READ |
GNUNET_DISK_PERM_USER_WRITE
- | GNUNET_DISK_PERM_GROUP_READ |
GNUNET_DISK_PERM_OTHER_READ);
- GNUNET_free (new_hello);
- }
+ {
+ GNUNET_DISK_fn_write (fn,
+ new_hello,
+ GNUNET_HELLO_size (new_hello),
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE |
+ GNUNET_DISK_PERM_GROUP_READ |
+ GNUNET_DISK_PERM_OTHER_READ);
+ GNUNET_free (new_hello);
+ }
else
- {
- if (0 != UNLINK (fn))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING |
- GNUNET_ERROR_TYPE_BULK, "unlink", fn);
- }
+ {
+ if (0 != UNLINK (fn))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING |
+ GNUNET_ERROR_TYPE_BULK, "unlink", fn);
+ }
return GNUNET_OK;
}
@@ -465,16 +453,14 @@
* Call this method periodically to scan data/hosts for new hosts.
*/
static void
-cron_clean_data_hosts (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+cron_clean_data_hosts (void *cls, const struct GNUNET_SCHEDULER_TaskContext
*tc)
{
struct GNUNET_TIME_Absolute now;
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
return;
now = GNUNET_TIME_absolute_get ();
- GNUNET_DISK_directory_scan (networkIdDirectory,
- &discard_hosts_helper, &now);
+ GNUNET_DISK_directory_scan (networkIdDirectory, &discard_hosts_helper, &now);
GNUNET_SCHEDULER_add_delayed (DATA_HOST_CLEAN_FREQ,
&cron_clean_data_hosts, NULL);
}
@@ -489,24 +475,23 @@
*/
static void
handle_hello (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
const struct GNUNET_HELLO_Message *hello;
struct GNUNET_PeerIdentity pid;
hello = (const struct GNUNET_HELLO_Message *) message;
- if (GNUNET_OK != GNUNET_HELLO_get_id (hello, &pid))
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ if (GNUNET_OK != GNUNET_HELLO_get_id (hello, &pid))
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
#if DEBUG_PEERINFO
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "`%s' message received for peer `%4s'\n",
- "HELLO",
- GNUNET_i2s (&pid));
+ "`%s' message received for peer `%4s'\n",
+ "HELLO", GNUNET_i2s (&pid));
#endif
bind_address (&pid, hello);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -532,17 +517,15 @@
GNUNET_break (0 == ntohl (lpm->reserved));
#if DEBUG_PEERINFO
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "`%s' message received for peer `%4s'\n",
- "GET",
- GNUNET_i2s (&lpm->peer));
+ "`%s' message received for peer `%4s'\n",
+ "GET", GNUNET_i2s (&lpm->peer));
#endif
tc = GNUNET_SERVER_transmit_context_create (client);
GNUNET_CONTAINER_multihashmap_get_multiple (hostmap,
- &lpm->peer.hashPubKey,
- &add_to_tc,
- tc);
+ &lpm->peer.hashPubKey,
+ &add_to_tc, tc);
GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
-
GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END);
+
GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END);
GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
}
@@ -562,24 +545,18 @@
struct GNUNET_SERVER_TransmitContext *tc;
#if DEBUG_PEERINFO
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "`%s' message received\n",
- "GET_ALL");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s' message received\n", "GET_ALL");
#endif
tc = GNUNET_SERVER_transmit_context_create (client);
- GNUNET_CONTAINER_multihashmap_iterate (hostmap,
- &add_to_tc,
- tc);
+ GNUNET_CONTAINER_multihashmap_iterate (hostmap, &add_to_tc, tc);
GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
-
GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END);
+
GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END);
GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
}
static int
-do_notify_entry (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+do_notify_entry (void *cls, const GNUNET_HashCode * key, void *value)
{
struct GNUNET_SERVER_Client *client = cls;
struct HostEntry *he = value;
@@ -587,9 +564,7 @@
msg = make_info_message (he);
GNUNET_SERVER_notification_context_unicast (notify_list,
- client,
- &msg->header,
- GNUNET_NO);
+ client, &msg->header, GNUNET_NO);
GNUNET_free (msg);
return GNUNET_YES;
}
@@ -604,27 +579,20 @@
*/
static void
handle_notify (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
#if DEBUG_PEERINFO
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "`%s' message received\n",
- "NOTIFY");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s' message received\n", "NOTIFY");
#endif
- GNUNET_SERVER_notification_context_add (notify_list,
- client);
- GNUNET_CONTAINER_multihashmap_iterate (hostmap,
- &do_notify_entry,
- client);
+ GNUNET_SERVER_notification_context_add (notify_list, client);
+ GNUNET_CONTAINER_multihashmap_iterate (hostmap, &do_notify_entry, client);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
static int
-free_host_entry (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+free_host_entry (void *cls, const GNUNET_HashCode * key, void *value)
{
struct HostEntry *he = value;
@@ -640,20 +608,17 @@
* @param tc scheduler task context, unused
*/
static void
-shutdown_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GNUNET_SERVER_notification_context_destroy (notify_list);
notify_list = NULL;
- GNUNET_CONTAINER_multihashmap_iterate (hostmap,
- &free_host_entry,
- NULL);
+ GNUNET_CONTAINER_multihashmap_iterate (hostmap, &free_host_entry, NULL);
GNUNET_CONTAINER_multihashmap_destroy (hostmap);
if (stats != NULL)
- {
- GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
- stats = NULL;
- }
+ {
+ GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
+ stats = NULL;
+ }
}
@@ -690,11 +655,11 @@
&networkIdDirectory));
GNUNET_DISK_directory_create (networkIdDirectory);
GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
- &cron_scan_directory_data_hosts, NULL);
+ &cron_scan_directory_data_hosts, NULL);
GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
- &cron_clean_data_hosts, NULL);
+ &cron_clean_data_hosts, NULL);
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task, NULL);
+ &shutdown_task, NULL);
GNUNET_SERVER_add_handlers (server, handlers);
}
@@ -712,11 +677,10 @@
int ret;
ret = (GNUNET_OK ==
- GNUNET_SERVICE_run (argc,
- argv,
- "peerinfo",
- GNUNET_SERVICE_OPTION_NONE,
- &run, NULL)) ? 0 : 1;
+ GNUNET_SERVICE_run (argc,
+ argv,
+ "peerinfo",
+ GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
GNUNET_free_non_null (networkIdDirectory);
return ret;
}
Modified: gnunet/src/peerinfo/peerinfo_api.c
===================================================================
--- gnunet/src/peerinfo/peerinfo_api.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/peerinfo/peerinfo_api.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -37,8 +37,7 @@
* @param cls closure
* @param success GNUNET_OK if transmission worked, GNUNET_SYSERR on error
*/
-typedef void (*TransmissionContinuation)(void *cls,
- int success);
+typedef void (*TransmissionContinuation) (void *cls, int success);
/**
@@ -50,7 +49,7 @@
* This is a linked list.
*/
struct TransmissionQueueEntry *next;
-
+
/**
* This is a linked list.
*/
@@ -61,7 +60,7 @@
* case we must consider sending the next entry immediately).
*/
TransmissionContinuation cont;
-
+
/**
* Closure for 'cont'.
*/
@@ -158,29 +157,27 @@
struct TransmissionQueueEntry *tqe;
while (NULL != (tqe = h->tq_head))
- {
- GNUNET_CONTAINER_DLL_remove (h->tq_head,
- h->tq_tail,
- tqe);
- if (tqe->cont != NULL)
- tqe->cont (tqe->cont_cls, GNUNET_SYSERR);
- GNUNET_free (tqe);
- }
+ {
+ GNUNET_CONTAINER_DLL_remove (h->tq_head, h->tq_tail, tqe);
+ if (tqe->cont != NULL)
+ tqe->cont (tqe->cont_cls, GNUNET_SYSERR);
+ GNUNET_free (tqe);
+ }
if (h->th != NULL)
- {
- GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
- h->th = NULL;
- }
+ {
+ GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
+ h->th = NULL;
+ }
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 (GNUNET_SCHEDULER_NO_TASK != h->r_task)
- {
- GNUNET_SCHEDULER_cancel (h->r_task);
- h->r_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (h->r_task);
+ h->r_task = GNUNET_SCHEDULER_NO_TASK;
+ }
GNUNET_free (h);
}
@@ -191,8 +188,7 @@
*
* @param h handle to the service
*/
-static void
-trigger_transmit (struct GNUNET_PEERINFO_Handle *h);
+static void trigger_transmit (struct GNUNET_PEERINFO_Handle *h);
/**
@@ -200,8 +196,7 @@
*
* @param h handle to the service
*/
-static void
-reconnect (struct GNUNET_PEERINFO_Handle *h);
+static void reconnect (struct GNUNET_PEERINFO_Handle *h);
/**
* Task scheduled to re-try connecting to the peerinfo service.
@@ -210,8 +205,7 @@
* @param ts 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_PEERINFO_Handle *h = cls;
@@ -229,28 +223,27 @@
reconnect (struct GNUNET_PEERINFO_Handle *h)
{
if (h->r_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (h->r_task);
- h->r_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (h->r_task);
+ h->r_task = GNUNET_SCHEDULER_NO_TASK;
+ }
if (NULL != h->th)
- {
- GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
- h->th = NULL;
- }
+ {
+ GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
+ h->th = NULL;
+ }
if (NULL != h->client)
- {
- GNUNET_CLIENT_disconnect (h->client, GNUNET_SYSERR);
- h->client = NULL;
- }
+ {
+ GNUNET_CLIENT_disconnect (h->client, GNUNET_SYSERR);
+ h->client = NULL;
+ }
h->client = GNUNET_CLIENT_connect ("peerinfo", h->cfg);
if (NULL == h->client)
- {
- h->r_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
- &reconnect_task,
- h);
- return;
- }
+ {
+ h->r_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &reconnect_task, h);
+ return;
+ }
trigger_transmit (h);
}
@@ -275,31 +268,25 @@
if (tqe == NULL)
return 0;
if (buf == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
- _("Failed to transmit message to `%s' service.\n"),
- "PEERINFO");
- GNUNET_CONTAINER_DLL_remove (h->tq_head,
- h->tq_tail,
- tqe);
- reconnect (h);
- if (tqe->cont != NULL)
- tqe->cont (tqe->cont_cls, GNUNET_SYSERR);
- GNUNET_free (tqe);
- return 0;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
+ _("Failed to transmit message to `%s' service.\n"),
"PEERINFO");
+ GNUNET_CONTAINER_DLL_remove (h->tq_head, h->tq_tail, tqe);
+ reconnect (h);
+ if (tqe->cont != NULL)
+ tqe->cont (tqe->cont_cls, GNUNET_SYSERR);
+ GNUNET_free (tqe);
+ return 0;
+ }
ret = tqe->size;
GNUNET_assert (size >= ret);
memcpy (buf, &tqe[1], ret);
#if DEBUG_PEERINFO
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitting request of size %u to `%s' service.\n",
- ret,
- "PEERINFO");
+ "Transmitting request of size %u to `%s' service.\n",
+ ret, "PEERINFO");
#endif
- GNUNET_CONTAINER_DLL_remove (h->tq_head,
- h->tq_tail,
- tqe);
+ GNUNET_CONTAINER_DLL_remove (h->tq_head, h->tq_tail, tqe);
if (tqe->cont != NULL)
tqe->cont (tqe->cont_cls, GNUNET_OK);
else
@@ -327,15 +314,15 @@
if (h->in_receive == GNUNET_YES)
return;
if (NULL == h->client)
- {
- reconnect (h);
- return;
- }
+ {
+ reconnect (h);
+ return;
+ }
h->th = GNUNET_CLIENT_notify_transmit_ready (h->client,
- tqe->size,
-
GNUNET_TIME_absolute_get_remaining (tqe->timeout),
- GNUNET_YES,
- &do_transmit, h);
+ tqe->size,
+
GNUNET_TIME_absolute_get_remaining
+ (tqe->timeout), GNUNET_YES,
+ &do_transmit, h);
}
@@ -352,28 +339,24 @@
*/
void
GNUNET_PEERINFO_add_peer (struct GNUNET_PEERINFO_Handle *h,
- const struct GNUNET_HELLO_Message *hello)
+ const struct GNUNET_HELLO_Message *hello)
{
uint16_t hs = GNUNET_HELLO_size (hello);
struct TransmissionQueueEntry *tqe;
-
+
#if DEBUG_PEERINFO
struct GNUNET_PeerIdentity peer;
+
GNUNET_assert (GNUNET_OK == GNUNET_HELLO_get_id (hello, &peer));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Adding peer `%s' to PEERINFO database (%u bytes of `%s')\n",
- GNUNET_i2s(&peer),
- hs,
- "HELLO");
+ "Adding peer `%s' to PEERINFO database (%u bytes of `%s')\n",
+ GNUNET_i2s (&peer), hs, "HELLO");
#endif
tqe = GNUNET_malloc (sizeof (struct TransmissionQueueEntry) + hs);
tqe->size = hs;
tqe->timeout = GNUNET_TIME_UNIT_FOREVER_ABS;
memcpy (&tqe[1], hello, hs);
- GNUNET_CONTAINER_DLL_insert_after (h->tq_head,
- h->tq_tail,
- h->tq_tail,
- tqe);
+ GNUNET_CONTAINER_DLL_insert_after (h->tq_head, h->tq_tail, h->tq_tail, tqe);
trigger_transmit (h);
}
@@ -428,8 +411,7 @@
* @param msg message received, NULL on timeout or fatal error
*/
static void
-peerinfo_handler (void *cls,
- const struct GNUNET_MessageHeader *msg)
+peerinfo_handler (void *cls, const struct GNUNET_MessageHeader *msg)
{
struct GNUNET_PEERINFO_IteratorContext *ic = cls;
const struct InfoMessage *im;
@@ -438,79 +420,76 @@
ic->h->in_receive = GNUNET_NO;
if (msg == NULL)
- {
- reconnect (ic->h);
- if (ic->timeout_task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel (ic->timeout_task);
- if (ic->callback != NULL)
- ic->callback (ic->callback_cls, NULL, NULL,
- _("Failed to receive response from `PEERINFO' service."));
- GNUNET_free (ic);
- return;
- }
+ {
+ reconnect (ic->h);
+ if (ic->timeout_task != GNUNET_SCHEDULER_NO_TASK)
+ GNUNET_SCHEDULER_cancel (ic->timeout_task);
+ if (ic->callback != NULL)
+ ic->callback (ic->callback_cls, NULL, NULL,
+ _("Failed to receive response from `PEERINFO' service."));
+ GNUNET_free (ic);
+ return;
+ }
if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END)
- {
+ {
#if DEBUG_PEERINFO
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received end of list of peers from `%s' service\n",
- "PEERINFO");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received end of list of peers from `%s' service\n",
+ "PEERINFO");
#endif
- trigger_transmit (ic->h);
- if (ic->timeout_task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel (ic->timeout_task);
- if (ic->callback != NULL)
- ic->callback (ic->callback_cls, NULL, NULL, NULL);
- GNUNET_free (ic);
- return;
- }
+ trigger_transmit (ic->h);
+ if (ic->timeout_task != GNUNET_SCHEDULER_NO_TASK)
+ GNUNET_SCHEDULER_cancel (ic->timeout_task);
+ if (ic->callback != NULL)
+ ic->callback (ic->callback_cls, NULL, NULL, NULL);
+ GNUNET_free (ic);
+ return;
+ }
ms = ntohs (msg->size);
if ((ms < sizeof (struct InfoMessage)) ||
(ntohs (msg->type) != GNUNET_MESSAGE_TYPE_PEERINFO_INFO))
+ {
+ GNUNET_break (0);
+ reconnect (ic->h);
+ if (ic->timeout_task != GNUNET_SCHEDULER_NO_TASK)
+ GNUNET_SCHEDULER_cancel (ic->timeout_task);
+ if (ic->callback != NULL)
+ ic->callback (ic->callback_cls, NULL, NULL,
+ _("Received invalid message from `PEERINFO' service.\n"));
+ GNUNET_free (ic);
+ return;
+ }
+ im = (const struct InfoMessage *) msg;
+ GNUNET_break (0 == ntohl (im->reserved));
+ hello = NULL;
+ if (ms > sizeof (struct InfoMessage) + sizeof (struct GNUNET_MessageHeader))
+ {
+ hello = (const struct GNUNET_HELLO_Message *) &im[1];
+ if (ms != sizeof (struct InfoMessage) + GNUNET_HELLO_size (hello))
{
GNUNET_break (0);
reconnect (ic->h);
if (ic->timeout_task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel (ic->timeout_task);
+ GNUNET_SCHEDULER_cancel (ic->timeout_task);
if (ic->callback != NULL)
- ic->callback (ic->callback_cls, NULL, NULL,
- _("Received invalid message from `PEERINFO' service.\n"));
+ ic->callback (ic->callback_cls, NULL, NULL,
+ _("Received invalid message from `PEERINFO'
service.\n"));
GNUNET_free (ic);
return;
}
- im = (const struct InfoMessage *) msg;
- GNUNET_break (0 == ntohl (im->reserved));
- hello = NULL;
- if (ms > sizeof (struct InfoMessage) + sizeof (struct GNUNET_MessageHeader))
- {
- hello = (const struct GNUNET_HELLO_Message *) &im[1];
- if (ms != sizeof (struct InfoMessage) + GNUNET_HELLO_size (hello))
- {
- GNUNET_break (0);
- reconnect (ic->h);
- if (ic->timeout_task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel (ic->timeout_task);
- if (ic->callback != NULL)
- ic->callback (ic->callback_cls, NULL, NULL,
- _("Received invalid message from `PEERINFO'
service.\n"));
- GNUNET_free (ic);
- return;
- }
- }
+ }
#if DEBUG_PEERINFO
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received %u bytes of `%s' information about peer `%s' from `%s'
service\n",
- (hello == NULL) ? 0 : (unsigned int) GNUNET_HELLO_size (hello),
- "HELLO",
- GNUNET_i2s (&im->peer),
- "PEERINFO");
+ "Received %u bytes of `%s' information about peer `%s' from `%s'
service\n",
+ (hello == NULL) ? 0 : (unsigned int) GNUNET_HELLO_size (hello),
+ "HELLO", GNUNET_i2s (&im->peer), "PEERINFO");
#endif
ic->h->in_receive = GNUNET_YES;
if (ic->callback != NULL)
ic->callback (ic->callback_cls, &im->peer, hello, NULL);
GNUNET_CLIENT_receive (ic->h->client,
&peerinfo_handler,
- ic,
- GNUNET_TIME_absolute_get_remaining (ic->timeout));
+ ic, GNUNET_TIME_absolute_get_remaining (ic->timeout));
}
@@ -522,37 +501,35 @@
* @param transmit_success GNUNET_OK if transmission worked
*/
static void
-iterator_start_receive (void *cls,
- int transmit_success)
+iterator_start_receive (void *cls, int transmit_success)
{
struct GNUNET_PEERINFO_IteratorContext *ic = cls;
if (GNUNET_OK != transmit_success)
+ {
+ if (ic->timeout_task != GNUNET_SCHEDULER_NO_TASK)
{
- if (ic->timeout_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (ic->timeout_task);
- ic->timeout_task = GNUNET_SCHEDULER_NO_TASK;
- }
- reconnect (ic->h);
- if (ic->callback != NULL)
- ic->callback (ic->callback_cls, NULL, NULL,
- _("Failed to transmit iteration request to `PEERINFO'
service\n"));
- GNUNET_free (ic);
- return;
- }
+ GNUNET_SCHEDULER_cancel (ic->timeout_task);
+ ic->timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ reconnect (ic->h);
+ if (ic->callback != NULL)
+ ic->callback (ic->callback_cls, NULL, NULL,
+ _
+ ("Failed to transmit iteration request to `PEERINFO'
service\n"));
+ GNUNET_free (ic);
+ return;
+ }
#if DEBUG_PEERINFO
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Waiting for response from `%s' service.\n",
- "PEERINFO");
+ "Waiting for response from `%s' service.\n", "PEERINFO");
#endif
ic->h->in_receive = GNUNET_YES;
ic->in_receive = GNUNET_YES;
ic->tqe = NULL;
GNUNET_CLIENT_receive (ic->h->client,
&peerinfo_handler,
- ic,
- GNUNET_TIME_absolute_get_remaining (ic->timeout));
+ ic, GNUNET_TIME_absolute_get_remaining (ic->timeout));
}
@@ -563,21 +540,19 @@
* @param tc scheduler context
*/
static void
-signal_timeout (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+signal_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_PEERINFO_IteratorContext *ic = cls;
ic->timeout_task = GNUNET_SCHEDULER_NO_TASK;
- if (! ic->in_receive)
- GNUNET_CONTAINER_DLL_remove (ic->h->tq_head,
- ic->h->tq_tail,
- ic->tqe);
+ if (!ic->in_receive)
+ GNUNET_CONTAINER_DLL_remove (ic->h->tq_head, ic->h->tq_tail, ic->tqe);
else
reconnect (ic->h);
ic->callback (ic->callback_cls,
- NULL, NULL,
- _("Timeout transmitting iteration request to `PEERINFO'
service.\n"));
+ NULL, NULL,
+ _
+ ("Timeout transmitting iteration request to `PEERINFO'
service.\n"));
ic->callback = NULL;
GNUNET_free_non_null (ic->tqe);
GNUNET_free (ic);
@@ -602,10 +577,9 @@
*/
struct GNUNET_PEERINFO_IteratorContext *
GNUNET_PEERINFO_iterate (struct GNUNET_PEERINFO_Handle *h,
- const struct GNUNET_PeerIdentity *peer,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_PEERINFO_Processor callback,
- void *callback_cls)
+ const struct GNUNET_PeerIdentity *peer,
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_PEERINFO_Processor callback, void
*callback_cls)
{
struct GNUNET_MessageHeader *lapm;
struct ListPeerMessage *lpm;
@@ -613,33 +587,33 @@
struct TransmissionQueueEntry *tqe;
if (peer == NULL)
- {
+ {
#if DEBUG_PEERINFO
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Requesting list of peers from PEERINFO service\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Requesting list of peers from PEERINFO service\n");
#endif
- tqe = GNUNET_malloc (sizeof (struct TransmissionQueueEntry) +
- sizeof (struct GNUNET_MessageHeader));
- tqe->size = sizeof (struct GNUNET_MessageHeader);
- lapm = (struct GNUNET_MessageHeader *) &tqe[1];
- lapm->size = htons (sizeof (struct GNUNET_MessageHeader));
- lapm->type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL);
- }
+ tqe = GNUNET_malloc (sizeof (struct TransmissionQueueEntry) +
+ sizeof (struct GNUNET_MessageHeader));
+ tqe->size = sizeof (struct GNUNET_MessageHeader);
+ lapm = (struct GNUNET_MessageHeader *) &tqe[1];
+ lapm->size = htons (sizeof (struct GNUNET_MessageHeader));
+ lapm->type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL);
+ }
else
- {
+ {
#if DEBUG_PEERINFO
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Requesting information on peer `%4s' from PEERINFO
service\n",
- GNUNET_i2s (peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Requesting information on peer `%4s' from PEERINFO service\n",
+ GNUNET_i2s (peer));
#endif
- tqe = GNUNET_malloc (sizeof (struct TransmissionQueueEntry) +
- sizeof (struct ListPeerMessage));
- tqe->size = sizeof (struct ListPeerMessage);
- lpm = (struct ListPeerMessage *) &tqe[1];
- lpm->header.size = htons (sizeof (struct ListPeerMessage));
- lpm->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_GET);
- memcpy (&lpm->peer, peer, sizeof (struct GNUNET_PeerIdentity));
- }
+ tqe = GNUNET_malloc (sizeof (struct TransmissionQueueEntry) +
+ sizeof (struct ListPeerMessage));
+ tqe->size = sizeof (struct ListPeerMessage);
+ lpm = (struct ListPeerMessage *) &tqe[1];
+ lpm->header.size = htons (sizeof (struct ListPeerMessage));
+ lpm->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_GET);
+ memcpy (&lpm->peer, peer, sizeof (struct GNUNET_PeerIdentity));
+ }
ic = GNUNET_malloc (sizeof (struct GNUNET_PEERINFO_IteratorContext));
ic->h = h;
ic->tqe = tqe;
@@ -647,16 +621,12 @@
ic->callback_cls = callback_cls;
ic->timeout = GNUNET_TIME_relative_to_absolute (timeout);
ic->timeout_task = GNUNET_SCHEDULER_add_delayed (timeout,
- &signal_timeout,
- ic);
+ &signal_timeout, ic);
tqe->timeout = ic->timeout;
tqe->cont = &iterator_start_receive;
tqe->cont_cls = ic;
tqe->timeout = ic->timeout;
- GNUNET_CONTAINER_DLL_insert_after (h->tq_head,
- h->tq_tail,
- h->tq_tail,
- tqe);
+ GNUNET_CONTAINER_DLL_insert_after (h->tq_head, h->tq_tail, h->tq_tail, tqe);
trigger_transmit (h);
return ic;
}
@@ -671,16 +641,14 @@
GNUNET_PEERINFO_iterate_cancel (struct GNUNET_PEERINFO_IteratorContext *ic)
{
if (ic->timeout_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (ic->timeout_task);
- ic->timeout_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (ic->timeout_task);
+ ic->timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ }
ic->callback = NULL;
if (GNUNET_YES == ic->in_receive)
- return; /* need to finish processing */
- GNUNET_CONTAINER_DLL_remove (ic->h->tq_head,
- ic->h->tq_tail,
- ic->tqe);
+ return; /* need to finish processing */
+ GNUNET_CONTAINER_DLL_remove (ic->h->tq_head, ic->h->tq_tail, ic->tqe);
GNUNET_free (ic->tqe);
GNUNET_free (ic);
}
Modified: gnunet/src/peerinfo/peerinfo_api_notify.c
===================================================================
--- gnunet/src/peerinfo/peerinfo_api_notify.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/peerinfo/peerinfo_api_notify.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -76,8 +76,7 @@
*
* @param nc our context
*/
-static void
-request_notifications (struct GNUNET_PEERINFO_NotifyContext *nc);
+static void request_notifications (struct GNUNET_PEERINFO_NotifyContext *nc);
/**
@@ -86,8 +85,7 @@
*
* @param nc our context
*/
-static void
-receive_notifications (struct GNUNET_PEERINFO_NotifyContext *nc);
+static void receive_notifications (struct GNUNET_PEERINFO_NotifyContext *nc);
/**
@@ -95,23 +93,21 @@
*
* @param cls the 'struct GNUNET_PEERINFO_NotifyContext'
* @param tc scheduler context
- */
+ */
static void
-reconnect (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_PEERINFO_NotifyContext *nc = cls;
nc->task = GNUNET_SCHEDULER_NO_TASK;
nc->client = GNUNET_CLIENT_connect ("peerinfo", nc->cfg);
if (NULL == nc->client)
- {
- /* ugh */
- nc->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
- &reconnect,
- nc);
- return;
- }
+ {
+ /* ugh */
+ nc->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &reconnect, nc);
+ return;
+ }
request_notifications (nc);
}
@@ -124,9 +120,7 @@
* @param msg message received, NULL on timeout or fatal error
*/
static void
-process_notification (void *cls,
- const struct
- GNUNET_MessageHeader * msg)
+process_notification (void *cls, const struct GNUNET_MessageHeader *msg)
{
struct GNUNET_PEERINFO_NotifyContext *nc = cls;
const struct InfoMessage *im;
@@ -134,14 +128,27 @@
uint16_t ms;
if (msg == NULL)
- {
- GNUNET_CLIENT_disconnect (nc->client, GNUNET_NO);
- reconnect (nc, NULL);
- return;
- }
+ {
+ GNUNET_CLIENT_disconnect (nc->client, GNUNET_NO);
+ reconnect (nc, NULL);
+ return;
+ }
ms = ntohs (msg->size);
if ((ms < sizeof (struct InfoMessage)) ||
(ntohs (msg->type) != GNUNET_MESSAGE_TYPE_PEERINFO_INFO))
+ {
+ GNUNET_break (0);
+ GNUNET_CLIENT_disconnect (nc->client, GNUNET_NO);
+ nc->client = GNUNET_CLIENT_connect ("peerinfo", nc->cfg);
+ request_notifications (nc);
+ return;
+ }
+ im = (const struct InfoMessage *) msg;
+ hello = NULL;
+ if (ms > sizeof (struct InfoMessage) + sizeof (struct GNUNET_MessageHeader))
+ {
+ hello = (const struct GNUNET_HELLO_Message *) &im[1];
+ if (ms != sizeof (struct InfoMessage) + GNUNET_HELLO_size (hello))
{
GNUNET_break (0);
GNUNET_CLIENT_disconnect (nc->client, GNUNET_NO);
@@ -149,24 +156,11 @@
request_notifications (nc);
return;
}
- im = (const struct InfoMessage *) msg;
- hello = NULL;
- if (ms > sizeof (struct InfoMessage) + sizeof (struct GNUNET_MessageHeader))
- {
- hello = (const struct GNUNET_HELLO_Message *) &im[1];
- if (ms != sizeof (struct InfoMessage) + GNUNET_HELLO_size (hello))
- {
- GNUNET_break (0);
- GNUNET_CLIENT_disconnect (nc->client, GNUNET_NO);
- nc->client = GNUNET_CLIENT_connect ("peerinfo", nc->cfg);
- request_notifications (nc);
- return;
- }
- }
+ }
#if DEBUG_PEERINFO
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received information about peer `%s' from peerinfo database\n",
- GNUNET_i2s (&im->peer));
+ "Received information about peer `%s' from peerinfo database\n",
+ GNUNET_i2s (&im->peer));
#endif
nc->callback (nc->callback_cls, &im->peer, hello, NULL);
receive_notifications (nc);
@@ -183,9 +177,8 @@
receive_notifications (struct GNUNET_PEERINFO_NotifyContext *nc)
{
GNUNET_CLIENT_receive (nc->client,
- &process_notification,
- nc,
- GNUNET_TIME_UNIT_FOREVER_REL);
+ &process_notification,
+ nc, GNUNET_TIME_UNIT_FOREVER_REL);
}
@@ -197,22 +190,20 @@
* @param buf where the callee should write the message
* @return number of bytes written to buf
*/
-static size_t
-transmit_notify_request (void *cls,
- size_t size,
- void *buf)
+static size_t
+transmit_notify_request (void *cls, size_t size, void *buf)
{
struct GNUNET_PEERINFO_NotifyContext *nc = cls;
struct GNUNET_MessageHeader hdr;
nc->init = NULL;
if (buf == NULL)
- {
- GNUNET_CLIENT_disconnect (nc->client, GNUNET_NO);
- nc->client = GNUNET_CLIENT_connect ("peerinfo", nc->cfg);
- request_notifications (nc);
- return 0;
- }
+ {
+ GNUNET_CLIENT_disconnect (nc->client, GNUNET_NO);
+ nc->client = GNUNET_CLIENT_connect ("peerinfo", nc->cfg);
+ request_notifications (nc);
+ return 0;
+ }
GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader));
hdr.size = htons (sizeof (struct GNUNET_MessageHeader));
hdr.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_NOTIFY);
@@ -232,12 +223,12 @@
request_notifications (struct GNUNET_PEERINFO_NotifyContext *nc)
{
GNUNET_assert (NULL == nc->init);
- nc->init =GNUNET_CLIENT_notify_transmit_ready (nc->client,
- sizeof (struct
GNUNET_MessageHeader),
- GNUNET_TIME_UNIT_FOREVER_REL,
- GNUNET_YES,
- &transmit_notify_request,
- nc);
+ nc->init = GNUNET_CLIENT_notify_transmit_ready (nc->client,
+ sizeof (struct
+
GNUNET_MessageHeader),
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_YES,
+ &transmit_notify_request,
nc);
}
@@ -253,24 +244,23 @@
*/
struct GNUNET_PEERINFO_NotifyContext *
GNUNET_PEERINFO_notify (const struct GNUNET_CONFIGURATION_Handle *cfg,
- GNUNET_PEERINFO_Processor callback,
- void *callback_cls)
+ GNUNET_PEERINFO_Processor callback, void *callback_cls)
{
struct GNUNET_PEERINFO_NotifyContext *nc;
struct GNUNET_CLIENT_Connection *client;
client = GNUNET_CLIENT_connect ("peerinfo", cfg);
if (client == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Could not connect to `%s' service.\n"), "peerinfo");
- return NULL;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Could not connect to `%s' service.\n"), "peerinfo");
+ return NULL;
+ }
nc = GNUNET_malloc (sizeof (struct GNUNET_PEERINFO_NotifyContext));
nc->cfg = cfg;
nc->client = client;
nc->callback = callback;
- nc->callback_cls = callback_cls;
+ nc->callback_cls = callback_cls;
request_notifications (nc);
return nc;
}
@@ -285,10 +275,10 @@
GNUNET_PEERINFO_notify_cancel (struct GNUNET_PEERINFO_NotifyContext *nc)
{
if (NULL != nc->init)
- {
- GNUNET_CLIENT_notify_transmit_ready_cancel (nc->init);
- nc->init = NULL;
- }
+ {
+ GNUNET_CLIENT_notify_transmit_ready_cancel (nc->init);
+ nc->init = NULL;
+ }
if (NULL != nc->client)
GNUNET_CLIENT_disconnect (nc->client, GNUNET_NO);
if (GNUNET_SCHEDULER_NO_TASK != nc->task)
Modified: gnunet/src/peerinfo/perf_peerinfo_api.c
===================================================================
--- gnunet/src/peerinfo/perf_peerinfo_api.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/peerinfo/perf_peerinfo_api.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -54,12 +54,9 @@
{
#if DEBUG
if (addrlen > 0)
- {
- fprintf (stderr,
- "name: %s, addr: %s\n",
- tname,
- (const char*) addr);
- }
+ {
+ fprintf (stderr, "name: %s, addr: %s\n", tname, (const char *) addr);
+ }
#endif
return GNUNET_OK;
}
@@ -75,13 +72,12 @@
if (*agc == 0)
return 0;
- GNUNET_asprintf(&address, "Address%d", *agc);
+ GNUNET_asprintf (&address, "Address%d", *agc);
ret = GNUNET_HELLO_add_address ("peerinfotest",
GNUNET_TIME_relative_to_absolute
- (GNUNET_TIME_UNIT_HOURS),
- address, strlen(address) + 1,
- buf, max);
+ (GNUNET_TIME_UNIT_HOURS),
+ address, strlen (address) + 1, buf, max);
GNUNET_free (address);
*agc = 0;
return ret;
@@ -106,53 +102,53 @@
static void
process (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)
{
if (peer == NULL)
- {
+ {
#if DEBUG
- fprintf(stderr, "Process received NULL response\n");
+ fprintf (stderr, "Process received NULL response\n");
#endif
- }
+ }
else
- {
+ {
#if DEBUG
- fprintf(stderr, "Processed a peer\n");
+ fprintf (stderr, "Processed a peer\n");
#endif
- numpeers++;
- if (0 && (hello != NULL))
- GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &check_it, NULL);
+ numpeers++;
+ if (0 && (hello != NULL))
+ GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &check_it, NULL);
- }
+ }
}
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *c)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
{
size_t i;
+
cfg = c;
h = GNUNET_PEERINFO_connect (cfg);
GNUNET_assert (h != NULL);
for (i = 0; i < NUM_REQUESTS; i++)
- {
- add_peer (i);
- ic[i] = GNUNET_PEERINFO_iterate (h,
- NULL,
- GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS, 30),
- &process, cls);
- }
+ {
+ add_peer (i);
+ ic[i] = GNUNET_PEERINFO_iterate (h,
+ NULL,
+ GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 30),
+ &process, cls);
+ }
}
static int
check ()
{
int ok = 0;
+
char *const argv[] = { "perf-peerinfo-api",
"-c",
"test_peerinfo_api_data.conf",
@@ -165,33 +161,32 @@
};
#if START_SERVICE
struct GNUNET_OS_Process *proc;
+
struct GNUNET_GETOPT_CommandLineOption options[] = {
GNUNET_GETOPT_OPTION_END
};
proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-peerinfo",
- "gnunet-service-peerinfo",
+ "gnunet-service-peerinfo",
#if DEBUG_PEERINFO
- "-L", "DEBUG",
+ "-L", "DEBUG",
#else
- "-L", "ERROR",
+ "-L", "ERROR",
#endif
- "-c", "test_peerinfo_api_data.conf", NULL);
+ "-c", "test_peerinfo_api_data.conf", NULL);
#endif
GNUNET_assert (NULL != proc);
GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
- argv, "perf-peerinfo-api", "nohelp",
- options, &run, &ok);
+ argv, "perf-peerinfo-api", "nohelp", options, &run, &ok);
fprintf (stderr,
- "Received %u/%u calls before timeout\n",
- numpeers,
- NUM_REQUESTS * NUM_REQUESTS / 2);
+ "Received %u/%u calls before timeout\n",
+ numpeers, NUM_REQUESTS * NUM_REQUESTS / 2);
GAUGER ("PEERINFO", "Peerinfo lookups", numpeers / 30, "peers/s");
#if START_SERVICE
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;
Modified: gnunet/src/peerinfo/test_peerinfo_api.c
===================================================================
--- gnunet/src/peerinfo/test_peerinfo_api.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/peerinfo/test_peerinfo_api.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -53,11 +53,11 @@
unsigned int *agc = cls;
if (addrlen > 0)
- {
- GNUNET_assert (0 == strcmp ("peerinfotest", tname));
- GNUNET_assert (0 == strncmp ("Address", addr, addrlen));
- (*agc) -= (1 << (addrlen - 1));
- }
+ {
+ GNUNET_assert (0 == strcmp ("peerinfotest", tname));
+ GNUNET_assert (0 == strncmp ("Address", addr, addrlen));
+ (*agc) -= (1 << (addrlen - 1));
+ }
return GNUNET_OK;
}
@@ -100,67 +100,63 @@
static void
process (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)
{
int *ok = cls;
unsigned int agc;
if (err_msg != NULL)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Error in communication with PEERINFO service\n"));
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Error in communication with PEERINFO service\n"));
}
if (peer == NULL)
+ {
+ ic = NULL;
+ if ((3 == *ok) && (retries < 50))
{
- ic = NULL;
- if ( (3 == *ok) &&
- (retries < 50) )
- {
- /* try again */
- retries++;
- add_peer ();
- ic = GNUNET_PEERINFO_iterate (h,
- NULL,
- GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS, 15),
- &process, cls);
- return;
- }
- GNUNET_assert (peer == NULL);
- GNUNET_assert (2 == *ok);
- GNUNET_PEERINFO_disconnect (h);
- h = NULL;
- *ok = 0;
+ /* try again */
+ retries++;
+ add_peer ();
+ ic = GNUNET_PEERINFO_iterate (h,
+ NULL,
+ GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 15),
+ &process, cls);
return;
}
+ GNUNET_assert (peer == NULL);
+ GNUNET_assert (2 == *ok);
+ GNUNET_PEERINFO_disconnect (h);
+ h = NULL;
+ *ok = 0;
+ return;
+ }
if (hello != NULL)
- {
- GNUNET_assert (3 == *ok);
- agc = 3;
- GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &check_it, &agc);
- GNUNET_assert (agc == 0);
- *ok = 2;
- }
+ {
+ GNUNET_assert (3 == *ok);
+ agc = 3;
+ GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &check_it, &agc);
+ GNUNET_assert (agc == 0);
+ *ok = 2;
+ }
}
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *c)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
{
cfg = c;
h = GNUNET_PEERINFO_connect (cfg);
GNUNET_assert (h != NULL);
add_peer ();
ic = GNUNET_PEERINFO_iterate (h,
- NULL,
- GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS, 15),
- &process, cls);
+ NULL,
+ GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 15), &process, cls);
}
@@ -169,6 +165,7 @@
{
int ok = 3;
struct GNUNET_OS_Process *proc;
+
char *const argv[] = { "test-peerinfo-api",
"-c",
"test_peerinfo_api_data.conf",
@@ -181,20 +178,19 @@
GNUNET_GETOPT_OPTION_END
};
proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-peerinfo",
- "gnunet-service-peerinfo",
+ "gnunet-service-peerinfo",
#if DEBUG_PEERINFO
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", "test_peerinfo_api_data.conf", NULL);
+ "-c", "test_peerinfo_api_data.conf", NULL);
GNUNET_assert (NULL != proc);
GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
- argv, "test-peerinfo-api", "nohelp",
- options, &run, &ok);
+ argv, "test-peerinfo-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;
Modified: gnunet/src/peerinfo-tool/gnunet-peerinfo.c
===================================================================
--- gnunet/src/peerinfo-tool/gnunet-peerinfo.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/peerinfo-tool/gnunet-peerinfo.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -57,18 +57,14 @@
unsigned int i;
GNUNET_CRYPTO_hash_to_enc (&pc->peer.hashPubKey, &enc);
- printf (_("Peer `%s'\n"),
- (const char *) &enc);
- for (i=0;i<pc->num_addresses;i++)
- {
- printf ("\t%s\n",
- pc->address_list[i]);
- GNUNET_free (pc->address_list[i]);
- }
+ printf (_("Peer `%s'\n"), (const char *) &enc);
+ for (i = 0; i < pc->num_addresses; i++)
+ {
+ printf ("\t%s\n", pc->address_list[i]);
+ GNUNET_free (pc->address_list[i]);
+ }
printf ("\n");
- GNUNET_array_grow (pc->address_list,
- pc->num_addresses,
- 0);
+ GNUNET_array_grow (pc->address_list, pc->num_addresses, 0);
GNUNET_free (pc);
}
@@ -80,21 +76,19 @@
* @param address NULL on error, otherwise 0-terminated printable UTF-8 string
*/
static void
-process_resolved_address (void *cls,
- const char *address)
+process_resolved_address (void *cls, const char *address)
{
struct PrintContext *pc = cls;
if (address == NULL)
- {
- pc->off--;
- if (pc->off == 0)
- dump_pc (pc);
- return;
- }
+ {
+ pc->off--;
+ if (pc->off == 0)
+ dump_pc (pc);
+ return;
+ }
GNUNET_array_append (pc->address_list,
- pc->num_addresses,
- GNUNET_strdup (address));
+ pc->num_addresses, GNUNET_strdup (address));
}
@@ -110,11 +104,12 @@
*/
static int
count_address (void *cls,
- const char *tname,
- struct GNUNET_TIME_Absolute expiration,
- const void *addr, uint16_t addrlen)
+ const char *tname,
+ struct GNUNET_TIME_Absolute expiration,
+ const void *addr, uint16_t addrlen)
{
struct PrintContext *pc = cls;
+
pc->off++;
return GNUNET_OK;
}
@@ -132,19 +127,20 @@
*/
static int
print_address (void *cls,
- const char *tname,
- struct GNUNET_TIME_Absolute expiration,
- const void *addr, uint16_t addrlen)
+ const char *tname,
+ struct GNUNET_TIME_Absolute expiration,
+ const void *addr, uint16_t addrlen)
{
struct PrintContext *pc = cls;
+
GNUNET_TRANSPORT_address_lookup (cfg,
- addr,
- addrlen,
- no_resolve,
- tname,
- GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_SECONDS, 10),
- &process_resolved_address,
- pc);
+ addr,
+ addrlen,
+ no_resolve,
+ tname,
+ GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 10),
+ &process_resolved_address, pc);
return GNUNET_OK;
}
@@ -157,32 +153,32 @@
static void
print_peer_info (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 GNUNET_CRYPTO_HashAsciiEncoded enc;
struct PrintContext *pc;
- if (peer == NULL)
- {
- if (err_msg != NULL) fprintf (stderr,_("Error in communication with
PEERINFO service\n"));
- GNUNET_PEERINFO_disconnect (peerinfo);
- return;
- }
+ if (peer == NULL)
+ {
+ if (err_msg != NULL)
+ fprintf (stderr, _("Error in communication with PEERINFO service\n"));
+ GNUNET_PEERINFO_disconnect (peerinfo);
+ return;
+ }
if (be_quiet)
- {
- GNUNET_CRYPTO_hash_to_enc (&peer->hashPubKey, &enc);
- printf ("%s\n", (const char *) &enc);
- return;
- }
+ {
+ GNUNET_CRYPTO_hash_to_enc (&peer->hashPubKey, &enc);
+ printf ("%s\n", (const char *) &enc);
+ return;
+ }
pc = GNUNET_malloc (sizeof (struct PrintContext));
- pc->peer = *peer;
+ pc->peer = *peer;
GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &count_address, pc);
if (0 == pc->off)
- {
- dump_pc (pc);
- return;
- }
+ {
+ dump_pc (pc);
+ return;
+ }
GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &print_address, pc);
}
@@ -198,8 +194,7 @@
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *c)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
{
struct GNUNET_CRYPTO_RsaPrivateKey *priv;
struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub;
@@ -209,57 +204,52 @@
cfg = c;
if (args[0] != NULL)
- {
- fprintf (stderr,
- _("Invalid command line argument `%s'\n"),
- args[0]);
- return;
- }
+ {
+ fprintf (stderr, _("Invalid command line argument `%s'\n"), args[0]);
+ return;
+ }
if (get_self != GNUNET_YES)
+ {
+ peerinfo = GNUNET_PEERINFO_connect (cfg);
+ if (peerinfo == NULL)
{
- peerinfo = GNUNET_PEERINFO_connect (cfg);
- if (peerinfo == NULL)
- {
- fprintf (stderr,
- _("Could not access PEERINFO service. Exiting.\n"));
- return;
- }
- GNUNET_PEERINFO_iterate (peerinfo,
- NULL,
- GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS, 5),
- &print_peer_info, NULL);
+ fprintf (stderr, _("Could not access PEERINFO service. Exiting.\n"));
+ return;
}
+ GNUNET_PEERINFO_iterate (peerinfo,
+ NULL,
+ GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 5),
+ &print_peer_info, NULL);
+ }
else
+ {
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_filename (cfg,
+ "GNUNETD", "HOSTKEY", &fn))
{
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (cfg,
- "GNUNETD",
- "HOSTKEY", &fn))
- {
- fprintf (stderr,
- _("Could not find option `%s:%s' in configuration.\n"),
- "GNUNETD",
- "HOSTKEYFILE");
- return;
- }
- priv = GNUNET_CRYPTO_rsa_key_create_from_file (fn);
- if (priv == NULL)
- {
- fprintf (stderr, _("Loading hostkey from `%s' failed.\n"), fn);
- GNUNET_free (fn);
- return;
- }
+ fprintf (stderr,
+ _("Could not find option `%s:%s' in configuration.\n"),
+ "GNUNETD", "HOSTKEYFILE");
+ return;
+ }
+ priv = GNUNET_CRYPTO_rsa_key_create_from_file (fn);
+ if (priv == NULL)
+ {
+ fprintf (stderr, _("Loading hostkey from `%s' failed.\n"), fn);
GNUNET_free (fn);
- GNUNET_CRYPTO_rsa_key_get_public (priv, &pub);
- GNUNET_CRYPTO_rsa_key_free (priv);
- GNUNET_CRYPTO_hash (&pub, sizeof (pub), &pid.hashPubKey);
- GNUNET_CRYPTO_hash_to_enc (&pid.hashPubKey, &enc);
- if (be_quiet)
- printf ("%s\n", (char *) &enc);
- else
- printf (_("I am peer `%s'.\n"), (const char *) &enc);
+ return;
}
+ GNUNET_free (fn);
+ GNUNET_CRYPTO_rsa_key_get_public (priv, &pub);
+ GNUNET_CRYPTO_rsa_key_free (priv);
+ GNUNET_CRYPTO_hash (&pub, sizeof (pub), &pid.hashPubKey);
+ GNUNET_CRYPTO_hash_to_enc (&pid.hashPubKey, &enc);
+ if (be_quiet)
+ printf ("%s\n", (char *) &enc);
+ else
+ printf (_("I am peer `%s'.\n"), (const char *) &enc);
+ }
}
Modified: gnunet/src/statistics/gnunet-service-statistics.c
===================================================================
--- gnunet/src/statistics/gnunet-service-statistics.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/statistics/gnunet-service-statistics.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -50,7 +50,7 @@
struct GNUNET_SERVER_Client *client;
uint64_t last_value;
-
+
uint32_t wid;
};
@@ -67,7 +67,7 @@
struct ClientEntry *prev;
struct GNUNET_SERVER_Client *client;
-
+
uint32_t max_wid;
};
@@ -156,9 +156,7 @@
static void
-inject_message (void *cls,
- void *client,
- const struct GNUNET_MessageHeader *msg)
+inject_message (void *cls, void *client, const struct GNUNET_MessageHeader
*msg)
{
struct GNUNET_SERVER_Handle *server = cls;
@@ -188,37 +186,33 @@
if (fn == NULL)
return;
if ((0 != stat (fn, &sb)) || (sb.st_size == 0))
- {
- GNUNET_free (fn);
- return;
- }
- fh = GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_READ,
- GNUNET_DISK_PERM_NONE);
+ {
+ GNUNET_free (fn);
+ return;
+ }
+ fh = GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_READ,
GNUNET_DISK_PERM_NONE);
if (!fh)
- {
- GNUNET_free (fn);
- return;
- }
+ {
+ GNUNET_free (fn);
+ return;
+ }
buf = GNUNET_DISK_file_map (fh, &mh, GNUNET_DISK_MAP_TYPE_READ, sb.st_size);
if (NULL == buf)
- {
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "mmap", fn);
- GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (fh));
- GNUNET_free (fn);
- return;
- }
+ {
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "mmap", fn);
+ GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (fh));
+ GNUNET_free (fn);
+ return;
+ }
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
_("Loading %llu bytes of statistics from `%s'\n"),
(unsigned long long) sb.st_size, fn);
- mst = GNUNET_SERVER_mst_create (&inject_message,
- server);
+ mst = GNUNET_SERVER_mst_create (&inject_message, server);
GNUNET_break (GNUNET_OK ==
- GNUNET_SERVER_mst_receive (mst,
- NULL,
- buf,
- sb.st_size,
- GNUNET_YES,
- GNUNET_NO));
+ GNUNET_SERVER_mst_receive (mst,
+ NULL,
+ buf,
+ sb.st_size, GNUNET_YES, GNUNET_NO));
GNUNET_SERVER_mst_destroy (mst);
GNUNET_break (GNUNET_OK == GNUNET_DISK_file_unmap (mh));
GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (fh));
@@ -229,7 +223,7 @@
* Write persistent statistics to disk.
*/
static void
-save ()
+save ()
{
struct StatsEntry *pos;
char *fn;
@@ -242,36 +236,37 @@
"statistics", "statistics.data", NULL);
if (fn != NULL)
fh = GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_WRITE
- | GNUNET_DISK_OPEN_CREATE | GNUNET_DISK_OPEN_TRUNCATE,
- GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
+ | GNUNET_DISK_OPEN_CREATE |
+ GNUNET_DISK_OPEN_TRUNCATE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE);
total = 0;
while (NULL != (pos = start))
+ {
+ start = pos->next;
+ if ((pos->persistent) && (NULL != fh))
{
- start = pos->next;
- if ((pos->persistent) && (NULL != fh))
- {
- size = htons (pos->msg->header.size);
- if (size != GNUNET_DISK_file_write (fh, pos->msg, size))
- {
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
- "write", fn);
- GNUNET_DISK_file_close (fh);
- fh = NULL;
- }
- else
- total += size;
- }
- GNUNET_free (pos);
- }
- if (NULL != fh)
- {
- GNUNET_DISK_file_close (fh);
- if (total == 0)
- GNUNET_break (0 == UNLINK (fn));
+ size = htons (pos->msg->header.size);
+ if (size != GNUNET_DISK_file_write (fh, pos->msg, size))
+ {
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", fn);
+ GNUNET_DISK_file_close (fh);
+ fh = NULL;
+ }
else
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Wrote %llu bytes of statistics to `%s'\n"), total, fn);
+ total += size;
}
+ GNUNET_free (pos);
+ }
+ if (NULL != fh)
+ {
+ GNUNET_DISK_file_close (fh);
+ if (total == 0)
+ GNUNET_break (0 == UNLINK (fn));
+ else
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Wrote %llu bytes of statistics to `%s'\n"), total, fn);
+ }
GNUNET_free_non_null (fn);
}
@@ -280,15 +275,14 @@
* Transmit the given stats value.
*/
static void
-transmit (struct GNUNET_SERVER_Client *client,
- const struct StatsEntry *e)
+transmit (struct GNUNET_SERVER_Client *client, const struct StatsEntry *e)
{
struct GNUNET_STATISTICS_ReplyMessage *m;
size_t size;
size =
- sizeof (struct GNUNET_STATISTICS_ReplyMessage) + strlen (e->service) + 1 +
- strlen (e->name) + 1;
+ sizeof (struct GNUNET_STATISTICS_ReplyMessage) + strlen (e->service) + 1
+
+ strlen (e->name) + 1;
GNUNET_assert (size < GNUNET_SERVER_MAX_MESSAGE_SIZE);
m = GNUNET_malloc (size);
m->header.type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_VALUE);
@@ -304,10 +298,10 @@
#if DEBUG_STATISTICS
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Transmitting value for `%s:%s' (%d): %llu\n",
- e->service, e->name,
- e->persistent, e->value);
+ e->service, e->name, e->persistent, e->value);
#endif
- GNUNET_SERVER_notification_context_unicast (nc, client, &m->header,
GNUNET_NO);
+ GNUNET_SERVER_notification_context_unicast (nc, client, &m->header,
+ GNUNET_NO);
GNUNET_free (m);
}
@@ -320,7 +314,7 @@
{
return ((0 == strlen (service)) ||
(0 == strcmp (service, e->service)))
- && ((0 == strlen (name)) || (0 == strcmp (name, e->name)));
+ && ((0 == strlen (name)) || (0 == strcmp (name, e->name)));
}
@@ -332,19 +326,16 @@
GNUNET_assert (client != NULL);
ce = client_head;
while (ce != NULL)
- {
- if (ce->client == client)
- return ce;
- ce = ce->next;
- }
+ {
+ if (ce->client == client)
+ return ce;
+ ce = ce->next;
+ }
ce = GNUNET_malloc (sizeof (struct ClientEntry));
ce->client = client;
GNUNET_SERVER_client_keep (client);
- GNUNET_CONTAINER_DLL_insert (client_head,
- client_tail,
- ce);
- GNUNET_SERVER_notification_context_add (nc,
- client);
+ GNUNET_CONTAINER_DLL_insert (client_head, client_tail, ce);
+ GNUNET_SERVER_notification_context_add (nc, client);
return ce;
}
@@ -374,11 +365,11 @@
size = ntohs (message->size) - sizeof (struct GNUNET_MessageHeader);
if (size != GNUNET_STRINGS_buffer_tokenize ((const char *) &message[1],
size, 2, &service, &name))
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
#if DEBUG_STATISTICS
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received request for statistics on `%s:%s'\n",
@@ -386,19 +377,15 @@
#endif
pos = start;
while (pos != NULL)
- {
- if (matches (pos, service, name))
- transmit (client, pos);
- pos = pos->next;
- }
+ {
+ if (matches (pos, service, name))
+ transmit (client, pos);
+ pos = pos->next;
+ }
end.size = htons (sizeof (struct GNUNET_MessageHeader));
end.type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_END);
- GNUNET_SERVER_notification_context_unicast (nc,
- client,
- &end,
- GNUNET_NO);
- GNUNET_SERVER_receive_done (client,
- GNUNET_OK);
+ GNUNET_SERVER_notification_context_unicast (nc, client, &end, GNUNET_NO);
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
@@ -410,23 +397,23 @@
pos = se->we_head;
while (pos != NULL)
+ {
+ if (pos->last_value != se->value)
{
- if (pos->last_value != se->value)
- {
- wvm.header.type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_WATCH_VALUE);
- wvm.header.size = htons (sizeof (struct
GNUNET_STATISTICS_WatchValueMessage));
- wvm.flags = htonl (se->persistent ? GNUNET_STATISTICS_PERSIST_BIT :
0);
- wvm.wid = htonl (pos->wid);
- wvm.reserved = htonl (0);
- wvm.value = GNUNET_htonll (se->value);
- GNUNET_SERVER_notification_context_unicast (nc,
- pos->client,
- &wvm.header,
- GNUNET_NO);
- pos->last_value = se->value;
- }
- pos = pos->next;
+ wvm.header.type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_WATCH_VALUE);
+ wvm.header.size =
+ htons (sizeof (struct GNUNET_STATISTICS_WatchValueMessage));
+ wvm.flags = htonl (se->persistent ? GNUNET_STATISTICS_PERSIST_BIT : 0);
+ wvm.wid = htonl (pos->wid);
+ wvm.reserved = htonl (0);
+ wvm.value = GNUNET_htonll (se->value);
+ GNUNET_SERVER_notification_context_unicast (nc,
+ pos->client,
+ &wvm.header, GNUNET_NO);
+ pos->last_value = se->value;
}
+ pos = pos->next;
+ }
}
/**
@@ -457,81 +444,77 @@
make_client_entry (client);
msize = ntohs (message->size);
if (msize < sizeof (struct GNUNET_STATISTICS_SetMessage))
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
size = msize - sizeof (struct GNUNET_STATISTICS_SetMessage);
msg = (const struct GNUNET_STATISTICS_SetMessage *) message;
if (size != GNUNET_STRINGS_buffer_tokenize ((const char *) &msg[1],
size, 2, &service, &name))
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
flags = ntohl (msg->flags);
value = GNUNET_ntohll (msg->value);
#if DEBUG_STATISTICS
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received request to update statistic on `%s:%s' (%u) to/by
%llu\n",
- service, name,
- (unsigned int) flags,
- (unsigned long long) value);
+ service, name, (unsigned int) flags, (unsigned long long) value);
#endif
pos = start;
prev = NULL;
while (pos != NULL)
+ {
+ if (matches (pos, service, name))
{
- if (matches (pos, service, name))
+ if ((flags & GNUNET_STATISTICS_SETFLAG_RELATIVE) == 0)
+ {
+ changed = (pos->value != value);
+ pos->value = value;
+ }
+ else
+ {
+ delta = (int64_t) value;
+ if ((delta < 0) && (pos->value < -delta))
{
- if ((flags & GNUNET_STATISTICS_SETFLAG_RELATIVE) == 0)
- {
- changed = (pos->value != value);
- pos->value = value;
- }
- else
- {
- delta = (int64_t) value;
- if ((delta < 0) && (pos->value < -delta))
- {
- changed = (pos->value != 0);
- pos->value = 0;
- }
- else
- {
- changed = (delta != 0);
- GNUNET_break ((delta <= 0) ||
- (pos->value + delta > pos->value));
- pos->value += delta;
- }
- }
- pos->msg->value = GNUNET_htonll (pos->value);
- pos->msg->flags = msg->flags;
- pos->persistent =
- (0 != (flags & GNUNET_STATISTICS_SETFLAG_PERSISTENT));
- if (prev != NULL)
- {
- /* move to front for faster setting next time! */
- prev->next = pos->next;
- pos->next = start;
- start = pos;
- }
+ changed = (pos->value != 0);
+ pos->value = 0;
+ }
+ else
+ {
+ changed = (delta != 0);
+ GNUNET_break ((delta <= 0) || (pos->value + delta > pos->value));
+ pos->value += delta;
+ }
+ }
+ pos->msg->value = GNUNET_htonll (pos->value);
+ pos->msg->flags = msg->flags;
+ pos->persistent = (0 != (flags & GNUNET_STATISTICS_SETFLAG_PERSISTENT));
+ if (prev != NULL)
+ {
+ /* move to front for faster setting next time! */
+ prev->next = pos->next;
+ pos->next = start;
+ start = pos;
+ }
#if DEBUG_STATISTICS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Statistic `%s:%s' updated to value %llu.\n",
- service, name, pos->value);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Statistic `%s:%s' updated to value %llu.\n",
+ service, name, pos->value);
#endif
- if (changed)
- notify_change (pos);
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
- return;
- }
- prev = pos;
- pos = pos->next;
+ if (changed)
+ notify_change (pos);
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ return;
}
+ prev = pos;
+ pos = pos->next;
+ }
pos = GNUNET_malloc (sizeof (struct StatsEntry) + msize);
pos->next = start;
if (((flags & GNUNET_STATISTICS_SETFLAG_RELATIVE) == 0) ||
@@ -563,8 +546,8 @@
*/
static void
handle_watch (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
char *service;
char *name;
@@ -578,19 +561,19 @@
ce = make_client_entry (client);
msize = ntohs (message->size);
if (msize < sizeof (struct GNUNET_MessageHeader))
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
size = msize - sizeof (struct GNUNET_MessageHeader);
if (size != GNUNET_STRINGS_buffer_tokenize ((const char *) &message[1],
size, 2, &service, &name))
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
#if DEBUG_STATISTICS
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received request to watch statistic on `%s:%s'\n",
@@ -598,40 +581,36 @@
#endif
pos = start;
while (pos != NULL)
- {
- if (matches (pos, service, name))
- break;
- pos = pos->next;
- }
+ {
+ if (matches (pos, service, name))
+ break;
+ pos = pos->next;
+ }
if (pos == NULL)
- {
- pos = GNUNET_malloc (sizeof (struct StatsEntry) +
- sizeof (struct GNUNET_STATISTICS_SetMessage) +
- size);
- pos->next = start;
- pos->uid = uidgen++;
- pos->msg = (void *) &pos[1];
- pos->msg->header.size = htons (sizeof (struct
GNUNET_STATISTICS_SetMessage) +
- size);
- pos->msg->header.type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_SET);
- pos->service = (const char *) &pos->msg[1];
- slen = strlen (service) + 1;
- memcpy ((void*) pos->service, service, slen);
- pos->name = &pos->service[slen];
- memcpy ((void*) pos->name, name, strlen (name)+1);
- start = pos;
- }
+ {
+ pos = GNUNET_malloc (sizeof (struct StatsEntry) +
+ sizeof (struct GNUNET_STATISTICS_SetMessage) + size);
+ pos->next = start;
+ pos->uid = uidgen++;
+ pos->msg = (void *) &pos[1];
+ pos->msg->header.size =
+ htons (sizeof (struct GNUNET_STATISTICS_SetMessage) + size);
+ pos->msg->header.type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_SET);
+ pos->service = (const char *) &pos->msg[1];
+ slen = strlen (service) + 1;
+ memcpy ((void *) pos->service, service, slen);
+ pos->name = &pos->service[slen];
+ memcpy ((void *) pos->name, name, strlen (name) + 1);
+ start = pos;
+ }
we = GNUNET_malloc (sizeof (struct WatchEntry));
we->client = client;
GNUNET_SERVER_client_keep (client);
we->wid = ce->max_wid++;
- GNUNET_CONTAINER_DLL_insert (pos->we_head,
- pos->we_tail,
- we);
+ GNUNET_CONTAINER_DLL_insert (pos->we_head, pos->we_tail, we);
if (pos->value != 0)
notify_change (pos);
- GNUNET_SERVER_receive_done (client,
- GNUNET_OK);
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
@@ -642,8 +621,7 @@
* @param tc unused
*/
static void
-shutdown_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct ClientEntry *ce;
struct WatchEntry *we;
@@ -653,26 +631,22 @@
GNUNET_SERVER_notification_context_destroy (nc);
nc = NULL;
while (NULL != (ce = client_head))
- {
- GNUNET_SERVER_client_drop (ce->client);
- GNUNET_CONTAINER_DLL_remove (client_head,
- client_tail,
- ce);
- GNUNET_free (ce);
- }
+ {
+ GNUNET_SERVER_client_drop (ce->client);
+ GNUNET_CONTAINER_DLL_remove (client_head, client_tail, ce);
+ GNUNET_free (ce);
+ }
while (NULL != (se = start))
+ {
+ start = se->next;
+ while (NULL != (we = se->we_head))
{
- start = se->next;
- while (NULL != (we = se->we_head))
- {
- GNUNET_SERVER_client_drop (we->client);
- GNUNET_CONTAINER_DLL_remove (se->we_head,
- se->we_tail,
- we);
- GNUNET_free (we);
- }
- GNUNET_free (se);
+ GNUNET_SERVER_client_drop (we->client);
+ GNUNET_CONTAINER_DLL_remove (se->we_head, se->we_tail, we);
+ GNUNET_free (we);
}
+ GNUNET_free (se);
+ }
}
@@ -683,46 +657,40 @@
* @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 ClientEntry *ce;
struct WatchEntry *we;
struct WatchEntry *wen;
struct StatsEntry *se;
-
+
ce = client_head;
while (NULL != ce)
+ {
+ if (ce->client == client)
{
- if (ce->client == client)
- {
- GNUNET_SERVER_client_drop (ce->client);
- GNUNET_CONTAINER_DLL_remove (client_head,
- client_tail,
- ce);
- GNUNET_free (ce);
- break;
- }
- ce = ce->next;
+ GNUNET_SERVER_client_drop (ce->client);
+ GNUNET_CONTAINER_DLL_remove (client_head, client_tail, ce);
+ GNUNET_free (ce);
+ break;
}
+ ce = ce->next;
+ }
se = start;
while (NULL != se)
+ {
+ wen = se->we_head;
+ while (NULL != (we = wen))
{
- wen = se->we_head;
- while (NULL != (we = wen))
- {
- wen = we->next;
- if (we->client != client)
- continue;
- GNUNET_SERVER_client_drop (we->client);
- GNUNET_CONTAINER_DLL_remove (se->we_head,
- se->we_tail,
- we);
- GNUNET_free (we);
- }
- se = se->next;
+ wen = we->next;
+ if (we->client != client)
+ continue;
+ GNUNET_SERVER_client_drop (we->client);
+ GNUNET_CONTAINER_DLL_remove (se->we_head, se->we_tail, we);
+ GNUNET_free (we);
}
+ se = se->next;
+ }
}
@@ -747,13 +715,10 @@
cfg = c;
GNUNET_SERVER_add_handlers (server, handlers);
nc = GNUNET_SERVER_notification_context_create (server, 16);
- GNUNET_SERVER_disconnect_notify (server,
- &handle_client_disconnect,
- NULL);
+ GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL);
load (server);
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task,
- NULL);
+ &shutdown_task, NULL);
}
@@ -771,8 +736,7 @@
GNUNET_SERVICE_run (argc,
argv,
"statistics",
- GNUNET_SERVICE_OPTION_NONE,
- &run, NULL)) ? 0 : 1;
+ GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
}
/* end of gnunet-service-statistics.c */
Modified: gnunet/src/statistics/gnunet-statistics.c
===================================================================
--- gnunet/src/statistics/gnunet-statistics.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/statistics/gnunet-statistics.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -65,13 +65,12 @@
static int
printer (void *cls,
const char *subsystem,
- const char *name,
- uint64_t value, int is_persistent)
+ const char *name, uint64_t value, int is_persistent)
{
FPRINTF (stdout,
"%s%-12s %-50s: %16llu\n",
is_persistent ? "!" : " ", subsystem, _(name),
- (unsigned long long) value);
+ (unsigned long long) value);
return GNUNET_OK;
}
@@ -89,14 +88,12 @@
struct GNUNET_STATISTICS_Handle *h = cls;
if (success != GNUNET_OK)
- {
- fprintf (stderr,
- _("Failed to obtain statistics.\n"));
- ret = 1;
- }
+ {
+ fprintf (stderr, _("Failed to obtain statistics.\n"));
+ ret = 1;
+ }
if (h != NULL)
- GNUNET_STATISTICS_destroy (h,
- GNUNET_NO);
+ GNUNET_STATISTICS_destroy (h, GNUNET_NO);
}
@@ -111,39 +108,39 @@
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
struct GNUNET_STATISTICS_Handle *h;
unsigned long long val;
if (args[0] != NULL)
+ {
+ if ((1 != SSCANF (args[0], "%llu", &val)) ||
+ (subsystem == NULL) || (name == NULL))
{
- if ((1 != SSCANF (args[0], "%llu", &val)) ||
- (subsystem == NULL) || (name == NULL))
- {
- FPRINTF (stderr, _("Invalid argument `%s'\n"), args[0]);
- ret = 1;
- return;
- }
- h = GNUNET_STATISTICS_create (subsystem, cfg);
- if (h == NULL)
- {
- ret = 1;
- return;
- }
- GNUNET_STATISTICS_set (h, name, (uint64_t) val, persistent);
- GNUNET_STATISTICS_destroy (h, GNUNET_YES);
+ FPRINTF (stderr, _("Invalid argument `%s'\n"), args[0]);
+ ret = 1;
return;
}
- h = GNUNET_STATISTICS_create ("gnunet-statistics", cfg);
- if (h == NULL)
+ h = GNUNET_STATISTICS_create (subsystem, cfg);
+ if (h == NULL)
{
ret = 1;
return;
}
+ GNUNET_STATISTICS_set (h, name, (uint64_t) val, persistent);
+ GNUNET_STATISTICS_destroy (h, GNUNET_YES);
+ return;
+ }
+ h = GNUNET_STATISTICS_create ("gnunet-statistics", cfg);
+ if (h == NULL)
+ {
+ ret = 1;
+ return;
+ }
if (NULL == GNUNET_STATISTICS_get (h,
- subsystem, name, GET_TIMEOUT, &cleanup,
&printer, h))
+ subsystem, name, GET_TIMEOUT, &cleanup,
+ &printer, h))
cleanup (h, GNUNET_SYSERR);
}
Modified: gnunet/src/statistics/statistics.h
===================================================================
--- gnunet/src/statistics/statistics.h 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/statistics/statistics.h 2011-08-15 21:46:35 UTC (rev 16581)
@@ -126,7 +126,7 @@
* be signed even though the type given here is unsigned.
*/
uint64_t value GNUNET_PACKED;
-
+
};
Modified: gnunet/src/statistics/statistics_api.c
===================================================================
--- gnunet/src/statistics/statistics_api.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/statistics/statistics_api.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -58,7 +58,7 @@
*/
struct GNUNET_STATISTICS_WatchEntry
{
-
+
/**
* What subsystem is this action about? (never NULL)
*/
@@ -102,7 +102,7 @@
* Main statistics handle.
*/
struct GNUNET_STATISTICS_Handle *sh;
-
+
/**
* What subsystem is this action about? (can be NULL)
*/
@@ -249,17 +249,15 @@
*
* @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)
+insert_ai (struct GNUNET_STATISTICS_Handle *h,
+ struct GNUNET_STATISTICS_GetHandle *ai)
{
GNUNET_CONTAINER_DLL_insert_after (h->action_head,
- h->action_tail,
- h->action_tail,
- ai);
+ h->action_tail, h->action_tail, ai);
if (h->action_head == ai)
schedule_action (h);
}
@@ -267,28 +265,28 @@
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;
size_t slen;
size_t nlen;
size_t nsize;
-
+
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);
@@ -311,15 +309,16 @@
try_connect (struct GNUNET_STATISTICS_Handle *ret)
{
unsigned int i;
+
if (ret->client != NULL)
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
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
_("Failed to connect to statistics service!\n"));
@@ -347,14 +346,15 @@
finish (struct GNUNET_STATISTICS_Handle *h, int code)
{
struct GNUNET_STATISTICS_GetHandle *pos = h->current;
+
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);
+ }
}
@@ -373,27 +373,27 @@
uint16_t size;
if (h->current->aborted)
- {
+ {
#if DEBUG_STATISTICS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Iteration was aborted, ignoring VALUE\n");
-#endif
- return GNUNET_OK; /* don't bother */
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Iteration was aborted, ignoring VALUE\n");
+#endif
+ 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;
- }
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
#if DEBUG_STATISTICS
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received valid statistic on `%s:%s': %llu\n",
@@ -401,55 +401,52 @@
#endif
if (GNUNET_OK !=
h->current->proc (h->current->cls,
- service,
- name,
- GNUNET_ntohll (smsg->value),
- 0 !=
- (ntohl (smsg->uid) & GNUNET_STATISTICS_PERSIST_BIT)))
- {
+ service,
+ name,
+ GNUNET_ntohll (smsg->value),
+ 0 !=
+ (ntohl (smsg->uid) & GNUNET_STATISTICS_PERSIST_BIT)))
+ {
#if DEBUG_STATISTICS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Processing of remaining statistics aborted by client.\n");
+ GNUNET_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
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "VALUE processed successfully\n");
-#endif
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "VALUE processed successfully\n");
+#endif
return GNUNET_OK;
}
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;
- }
- wvm = (const struct GNUNET_STATISTICS_WatchValueMessage *)msg;
+ 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));
+ w->subsystem,
+ w->name,
+ GNUNET_ntohll (wvm->value),
+ 0 != (ntohl (wvm->flags) & GNUNET_STATISTICS_PERSIST_BIT));
return GNUNET_OK;
}
@@ -466,82 +463,75 @@
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
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
- "Error receiving statistics from service, is the service
running?\n" );
+ GNUNET_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
+ GNUNET_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
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received end of statistics marker\n");
+ "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
- GNUNET_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);
}
@@ -559,15 +549,15 @@
uint16_t msize;
if (buf == NULL)
- {
- /* timeout / error */
+ {
+ /* timeout / error */
#if DEBUG_STATISTICS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmission of request for statistics failed!\n");
+ GNUNET_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);
@@ -581,19 +571,19 @@
2,
handle->current->subsystem,
handle->current->name));
- if (! handle->receiving)
- {
+ if (!handle->receiving)
+ {
#if DEBUG_STATISTICS
- GNUNET_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));
- }
+ GNUNET_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));
+ }
return msize;
}
@@ -611,19 +601,18 @@
uint16_t msize;
if (buf == NULL)
- {
- /* timeout / error */
+ {
+ /* timeout / error */
#if DEBUG_STATISTICS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmission of request for statistics failed!\n");
+ GNUNET_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
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitting watch request for `%s'\n",
- handle->current->name);
+ "Transmitting watch request for `%s'\n", handle->current->name);
#endif
slen1 = strlen (handle->current->subsystem) + 1;
slen2 = strlen (handle->current->name) + 1;
@@ -639,13 +628,12 @@
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;
}
@@ -663,20 +651,20 @@
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);
@@ -705,22 +693,22 @@
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;
}
@@ -745,11 +733,11 @@
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;
}
@@ -763,8 +751,7 @@
* be completed
*/
void
-GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h,
- int sync_first)
+GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h, int sync_first)
{
struct GNUNET_STATISTICS_GetHandle *pos;
struct GNUNET_STATISTICS_GetHandle *next;
@@ -772,101 +759,97 @@
struct GNUNET_TIME_Relative timeout;
int i;
- if (h == NULL)
+ if (h == NULL)
return;
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);
}
- 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_array_grow (h->watches,
- h->watches_size,
- 0);
+ 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_array_grow (h->watches, h->watches_size, 0);
GNUNET_free (h->subsystem);
GNUNET_free (h);
}
static void
-finish_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+finish_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_STATISTICS_Handle *h = cls;
@@ -886,44 +869,41 @@
if (h->current != NULL)
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);
}
- GNUNET_CONTAINER_DLL_remove (h->action_head,
- h->action_tail,
- h->current);
+ 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)))
- {
+ h->current->msize,
+ timeout,
+ GNUNET_YES,
+ &transmit_action, h)))
+ {
#if DEBUG_STATISTICS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Failed to transmit request to statistics service.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to transmit request to statistics service.\n");
#endif
- finish (h, GNUNET_SYSERR);
- }
+ finish (h, GNUNET_SYSERR);
+ }
}
@@ -956,15 +936,15 @@
GNUNET_assert (proc != NULL);
GNUNET_assert (GNUNET_NO == handle->do_destroy);
if (GNUNET_YES != try_connect (handle))
- {
+ {
#if DEBUG_STATISTICS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Failed to connect to statistics service, can not get value
`%s:%s'.\n",
- strlen (subsystem) ? subsystem : "*",
- strlen (name) ? name : "*");
+ GNUNET_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)
@@ -998,18 +978,16 @@
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);
+ }
}
@@ -1027,23 +1005,20 @@
*/
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;
- if (handle == NULL)
+ if (handle == NULL)
return GNUNET_SYSERR;
w = GNUNET_malloc (sizeof (struct GNUNET_STATISTICS_WatchEntry));
w->subsystem = GNUNET_strdup (subsystem);
w->name = GNUNET_strdup (name);
w->proc = proc;
w->proc_cls = proc_cls;
- GNUNET_array_append (handle->watches,
- handle->watches_size,
- w);
+ GNUNET_array_append (handle->watches, handle->watches_size, w);
schedule_watch_request (handle, w);
return GNUNET_OK;
}
@@ -1052,15 +1027,14 @@
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;
size_t nlen;
size_t nsize;
int64_t delta;
-
+
GNUNET_assert (h != NULL);
GNUNET_assert (name != NULL);
if (GNUNET_YES != try_connect (h))
@@ -1069,59 +1043,58 @@
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);
@@ -1146,8 +1119,7 @@
*/
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;
@@ -1167,8 +1139,7 @@
*/
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;
Modified: gnunet/src/statistics/test_statistics_api.c
===================================================================
--- gnunet/src/statistics/test_statistics_api.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/statistics/test_statistics_api.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -39,10 +39,8 @@
const char *name, uint64_t value, int is_persistent)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received value %llu for `%s:%s\n",
- (unsigned long long) value,
- subsystem,
- name);
+ "Received value %llu for `%s:%s\n",
+ (unsigned long long) value, subsystem, name);
GNUNET_assert (0 == strcmp (name, "test-1"));
GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api"));
GNUNET_assert (value == 1);
@@ -56,10 +54,8 @@
const char *name, uint64_t value, int is_persistent)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received value %llu for `%s:%s\n",
- (unsigned long long) value,
- subsystem,
- name);
+ "Received value %llu for `%s:%s\n",
+ (unsigned long long) value, subsystem, name);
GNUNET_assert (0 == strcmp (name, "test-2"));
GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api"));
GNUNET_assert (value == 2);
@@ -73,10 +69,8 @@
const char *name, uint64_t value, int is_persistent)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received value %llu for `%s:%s\n",
- (unsigned long long) value,
- subsystem,
- name);
+ "Received value %llu for `%s:%s\n",
+ (unsigned long long) value, subsystem, name);
GNUNET_assert (0 == strcmp (name, "test-3"));
GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api"));
GNUNET_assert (value == 3);
@@ -100,54 +94,54 @@
next (void *cls, int success)
{
GNUNET_assert (success == GNUNET_OK);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Issuing GET request\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Issuing GET request\n");
GNUNET_break (NULL !=
- GNUNET_STATISTICS_get (h, NULL, "test-2",
- GNUNET_TIME_UNIT_SECONDS, &next_fin,
&check_2, cls));
+ GNUNET_STATISTICS_get (h, NULL, "test-2",
+ GNUNET_TIME_UNIT_SECONDS, &next_fin,
+ &check_2, cls));
}
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
h = GNUNET_STATISTICS_create ("test-statistics-api", cfg);
GNUNET_STATISTICS_set (h, "test-1", 1, GNUNET_NO);
GNUNET_STATISTICS_set (h, "test-2", 2, GNUNET_NO);
GNUNET_STATISTICS_set (h, "test-3", 2, GNUNET_NO);
GNUNET_STATISTICS_update (h, "test-3", 1, GNUNET_YES);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Issuing GET request\n");
- GNUNET_break (NULL !=
- GNUNET_STATISTICS_get (h, NULL, "test-1",
- GNUNET_TIME_UNIT_SECONDS, &next,
&check_1, cls));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Issuing GET request\n");
+ GNUNET_break (NULL !=
+ GNUNET_STATISTICS_get (h, NULL, "test-1",
+ GNUNET_TIME_UNIT_SECONDS, &next,
+ &check_1, cls));
}
static void
run_more (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
h = GNUNET_STATISTICS_create ("test-statistics-api", cfg);
GNUNET_break (NULL !=
- GNUNET_STATISTICS_get (h, NULL, "test-3",
- GNUNET_TIME_UNIT_SECONDS, &next_fin,
&check_3, cls));
+ GNUNET_STATISTICS_get (h, NULL, "test-3",
+ GNUNET_TIME_UNIT_SECONDS, &next_fin,
+ &check_3, cls));
}
static int
check ()
{
int ok = 1;
+
char *const argv[] = { "test-statistics-api",
"-c",
"test_statistics_api_data.conf",
#if DEBUG_STATISTICS
- "-L", "DEBUG",
+ "-L", "DEBUG",
#else
- "-L", "WARNING",
+ "-L", "WARNING",
#endif
NULL
};
@@ -156,22 +150,23 @@
};
#if START_SERVICE
struct GNUNET_OS_Process *proc;
+
proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-statistics",
- "gnunet-service-statistics",
+ "gnunet-service-statistics",
#if DEBUG_STATISTICS
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", "test_statistics_api_data.conf", NULL);
+ "-c", "test_statistics_api_data.conf", NULL);
#endif
GNUNET_assert (NULL != proc);
GNUNET_PROGRAM_run (5, argv, "test-statistics-api", "nohelp",
options, &run, &ok);
#if START_SERVICE
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;
@@ -182,20 +177,20 @@
#if START_SERVICE
/* restart to check persistence! */
proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-statistics",
- "gnunet-service-statistics",
+ "gnunet-service-statistics",
#if DEBUG_STATISTICS
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", "test_statistics_api_data.conf", NULL);
+ "-c", "test_statistics_api_data.conf", NULL);
#endif
GNUNET_PROGRAM_run (5, argv, "test-statistics-api", "nohelp",
options, &run_more, &ok);
#if START_SERVICE
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;
@@ -208,13 +203,13 @@
{
int ret;
- GNUNET_log_setup ("test_statistics_api",
+ GNUNET_log_setup ("test_statistics_api",
#if DEBUG_STATISTICS
- "DEBUG",
+ "DEBUG",
#else
- "WARNING",
+ "WARNING",
#endif
- NULL);
+ NULL);
ret = check ();
return ret;
Modified: gnunet/src/statistics/test_statistics_api_loop.c
===================================================================
--- gnunet/src/statistics/test_statistics_api_loop.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/statistics/test_statistics_api_loop.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -61,24 +61,24 @@
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
int i;
char name[128];
h = GNUNET_STATISTICS_create ("test-statistics-api-loop", cfg);
- for (i=0;i<ROUNDS;i++)
- {
- GNUNET_snprintf (name, sizeof (name), "test-%d", i % 256);
- GNUNET_STATISTICS_set (h, name, i, GNUNET_NO);
- GNUNET_snprintf (name, sizeof (name), "test-%d", i % 128);
- GNUNET_STATISTICS_update (h, name, 1, GNUNET_NO);
- }
+ for (i = 0; i < ROUNDS; i++)
+ {
+ GNUNET_snprintf (name, sizeof (name), "test-%d", i % 256);
+ GNUNET_STATISTICS_set (h, name, i, GNUNET_NO);
+ GNUNET_snprintf (name, sizeof (name), "test-%d", i % 128);
+ GNUNET_STATISTICS_update (h, name, 1, GNUNET_NO);
+ }
i = 0;
- GNUNET_break (NULL !=
- GNUNET_STATISTICS_get (h, NULL, "test-0",
- GNUNET_TIME_UNIT_MINUTES, &next,
&check_1, cls));
+ GNUNET_break (NULL !=
+ GNUNET_STATISTICS_get (h, NULL, "test-0",
+ GNUNET_TIME_UNIT_MINUTES, &next,
+ &check_1, cls));
}
@@ -86,6 +86,7 @@
check ()
{
int ok = 1;
+
char *const argv[] = { "test-statistics-api",
"-c",
"test_statistics_api_data.conf",
@@ -96,22 +97,23 @@
};
#if START_SERVICE
struct GNUNET_OS_Process *proc;
+
proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-statistics",
- "gnunet-service-statistics",
+ "gnunet-service-statistics",
#if DEBUG_STATISTICS
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", "test_statistics_api_data.conf", NULL);
+ "-c", "test_statistics_api_data.conf", NULL);
#endif
GNUNET_assert (NULL != proc);
GNUNET_PROGRAM_run (3, argv, "test-statistics-api", "nohelp",
options, &run, &ok);
#if START_SERVICE
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;
Modified: gnunet/src/statistics/test_statistics_api_watch.c
===================================================================
--- gnunet/src/statistics/test_statistics_api_watch.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/statistics/test_statistics_api_watch.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -45,8 +45,7 @@
static void
-force_shutdown (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+force_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
fprintf (stderr, "Timeout, failed to receive notifications: %d\n", ok);
GNUNET_STATISTICS_destroy (h, GNUNET_NO);
@@ -56,8 +55,7 @@
static void
-normal_shutdown (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+normal_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GNUNET_STATISTICS_destroy (h, GNUNET_NO);
GNUNET_STATISTICS_destroy (h2, GNUNET_NO);
@@ -65,39 +63,35 @@
static int
-watch_1 (void *cls,
- const char *subsystem,
- const char *name,
- uint64_t value,
- int is_persistent)
+watch_1 (void *cls,
+ const char *subsystem,
+ const char *name, uint64_t value, int is_persistent)
{
GNUNET_assert (value == 42);
GNUNET_assert (0 == strcmp (name, "test-1"));
ok &= ~1;
if (0 == ok)
- {
- GNUNET_SCHEDULER_cancel (shutdown_task);
- GNUNET_SCHEDULER_add_now (&normal_shutdown, NULL);
- }
+ {
+ GNUNET_SCHEDULER_cancel (shutdown_task);
+ GNUNET_SCHEDULER_add_now (&normal_shutdown, NULL);
+ }
return GNUNET_OK;
}
static int
-watch_2 (void *cls,
- const char *subsystem,
- const char *name,
- uint64_t value,
- int is_persistent)
+watch_2 (void *cls,
+ const char *subsystem,
+ const char *name, uint64_t value, int is_persistent)
{
GNUNET_assert (value == 43);
GNUNET_assert (0 == strcmp (name, "test-2"));
ok &= ~2;
if (0 == ok)
- {
- GNUNET_SCHEDULER_cancel (shutdown_task);
- GNUNET_SCHEDULER_add_now (&normal_shutdown, NULL);
- }
+ {
+ GNUNET_SCHEDULER_cancel (shutdown_task);
+ GNUNET_SCHEDULER_add_now (&normal_shutdown, NULL);
+ }
return GNUNET_OK;
}
@@ -105,27 +99,22 @@
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
h = GNUNET_STATISTICS_create ("dummy", cfg);
GNUNET_assert (GNUNET_OK ==
- GNUNET_STATISTICS_watch (h,
- "test-statistics-api-watch",
- "test-1",
- &watch_1,
- NULL));
+ GNUNET_STATISTICS_watch (h,
+ "test-statistics-api-watch",
+ "test-1", &watch_1, NULL));
GNUNET_assert (GNUNET_OK ==
- GNUNET_STATISTICS_watch (h,
- "test-statistics-api-watch",
- "test-2",
- &watch_2,
- NULL));
+ GNUNET_STATISTICS_watch (h,
+ "test-statistics-api-watch",
+ "test-2", &watch_2, NULL));
h2 = GNUNET_STATISTICS_create ("test-statistics-api-watch", cfg);
GNUNET_STATISTICS_set (h2, "test-1", 42, GNUNET_NO);
GNUNET_STATISTICS_set (h2, "test-2", 43, GNUNET_NO);
shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
- &force_shutdown, NULL);
+ &force_shutdown, NULL);
}
@@ -142,12 +131,13 @@
};
#if START_SERVICE
struct GNUNET_OS_Process *proc;
+
proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-statistics",
- "gnunet-service-statistics",
+ "gnunet-service-statistics",
#if VERBOSE
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", "test_statistics_api_data.conf", NULL);
+ "-c", "test_statistics_api_data.conf", NULL);
#endif
GNUNET_assert (NULL != proc);
ok = 3;
@@ -155,10 +145,10 @@
options, &run, NULL);
#if START_SERVICE
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;
Modified: gnunet/src/template/gnunet-service-template.c
===================================================================
--- gnunet/src/template/gnunet-service-template.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/template/gnunet-service-template.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -35,8 +35,7 @@
* @param tc unused
*/
static void
-cleanup_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
/* FIXME: do clean up here */
}
@@ -61,8 +60,7 @@
/* FIXME: do setup here */
GNUNET_SERVER_add_handlers (server, handlers);
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &cleanup_task,
- NULL);
+ &cleanup_task, NULL);
}
@@ -80,8 +78,7 @@
GNUNET_SERVICE_run (argc,
argv,
"template",
- GNUNET_SERVICE_OPTION_NONE,
- &run, NULL)) ? 0 : 1;
+ GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
}
/* end of gnunet-service-template.c */
Modified: gnunet/src/template/gnunet-template.c
===================================================================
--- gnunet/src/template/gnunet-template.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/template/gnunet-template.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -44,8 +44,7 @@
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
/* main code here */
}
Modified: gnunet/src/testing/test_testing.c
===================================================================
--- gnunet/src/testing/test_testing.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/testing/test_testing.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -34,28 +34,27 @@
end_cb (void *cls, const char *emsg)
{
if (emsg != NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Ending with error: %s\n", emsg);
- ok = 1;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Ending with error: %s\n", emsg);
+ ok = 1;
+ }
else
- {
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Daemon terminated, will now exit.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Daemon terminated, will now
exit.\n");
#endif
- ok = 0;
- }
+ ok = 0;
+ }
}
-void do_shutdown (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext * tc)
+void
+do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_TESTING_Daemon *d = cls;
- GNUNET_TESTING_daemon_stop (d, TIMEOUT, &end_cb, NULL, GNUNET_YES,
- GNUNET_NO);
+
+ GNUNET_TESTING_daemon_stop (d, TIMEOUT, &end_cb, NULL, GNUNET_YES,
GNUNET_NO);
}
@@ -70,7 +69,7 @@
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Daemon `%s' started, will now stop it.\n", GNUNET_i2s (id));
#endif
- GNUNET_SCHEDULER_add_now(&do_shutdown, d);
+ GNUNET_SCHEDULER_add_now (&do_shutdown, d);
}
@@ -85,9 +84,8 @@
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemon.\n");
#endif
- d =
- GNUNET_TESTING_daemon_start (cfg, TIMEOUT, GNUNET_NO, NULL, NULL, 0, NULL,
NULL, NULL,
- &my_cb, NULL);
+ d = GNUNET_TESTING_daemon_start (cfg, TIMEOUT, GNUNET_NO, NULL, NULL, 0,
NULL,
+ NULL, NULL, &my_cb, NULL);
GNUNET_assert (d != NULL);
}
Modified: gnunet/src/testing/test_testing_connect.c
===================================================================
--- gnunet/src/testing/test_testing_connect.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/testing/test_testing_connect.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -48,33 +48,33 @@
{
if (emsg != NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Ending with error: %s\n", emsg);
- ok = 1;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Ending with error: %s\n", emsg);
+ ok = 1;
+ }
else
- {
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Both daemons terminated, will now exit.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Both daemons terminated, will now exit.\n");
#endif
- ok = 0;
- }
+ ok = 0;
+ }
}
static void
end1_cb (void *cls, const char *emsg)
{
if (emsg != NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Stopping daemon 1 gave: %s\n",
- emsg);
- ok = 1;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Stopping daemon 1 gave: %s\n",
+ emsg);
+ ok = 1;
+ }
else
- {
- ok = 0;
- }
+ {
+ ok = 0;
+ }
GNUNET_TESTING_daemon_stop (d2, TIMEOUT, &end2_cb, NULL, GNUNET_YES,
GNUNET_NO);
@@ -117,8 +117,7 @@
#endif
GNUNET_TESTING_daemons_connect (d1, d2,
TIMEOUT, CONNECT_ATTEMPTS,
- GNUNET_YES,
- &my_connect_complete, NULL);
+ GNUNET_YES, &my_connect_complete, NULL);
}
@@ -133,9 +132,8 @@
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Daemon `%s' started.\n", GNUNET_i2s (id));
#endif
- d2 =
- GNUNET_TESTING_daemon_start (c2, TIMEOUT, GNUNET_NO, NULL, NULL, 0, NULL,
NULL, NULL,
- &my_cb2, NULL);
+ d2 = GNUNET_TESTING_daemon_start (c2, TIMEOUT, GNUNET_NO, NULL, NULL, 0,
NULL,
+ NULL, NULL, &my_cb2, NULL);
GNUNET_assert (d2 != NULL);
}
@@ -154,9 +152,8 @@
GNUNET_CONFIGURATION_parse (c1, "test_testing_connect_peer1.conf");
c2 = GNUNET_CONFIGURATION_create ();
GNUNET_CONFIGURATION_parse (c2, "test_testing_connect_peer2.conf");
- d1 =
- GNUNET_TESTING_daemon_start (c1, TIMEOUT, GNUNET_NO, NULL, NULL, 0, NULL,
NULL, NULL,
- &my_cb1, NULL);
+ d1 = GNUNET_TESTING_daemon_start (c1, TIMEOUT, GNUNET_NO, NULL, NULL, 0,
NULL,
+ NULL, NULL, &my_cb1, NULL);
GNUNET_assert (d1 != NULL);
}
Modified: gnunet/src/testing/test_testing_group.c
===================================================================
--- gnunet/src/testing/test_testing_group.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/testing/test_testing_group.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -48,20 +48,19 @@
shutdown_callback (void *cls, const char *emsg)
{
if (emsg != NULL)
- {
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n");
#endif
- if (ok == 0)
- ok = 666;
- }
+ if (ok == 0)
+ ok = 666;
+ }
else
- {
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "All peers successfully shut down!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers successfully shut
down!\n");
#endif
- }
+ }
}
@@ -72,36 +71,36 @@
struct GNUNET_TESTING_Daemon *d, const char *emsg)
{
if (id == NULL)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Start callback called with error (too long starting peers),
aborting test!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error from testing: `%s'\n");
+ failed_peers++;
+ if (failed_peers == peers_left)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Start callback called with error (too long starting peers),
aborting test!\n");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error from testing: `%s'\n");
- failed_peers++;
- if (failed_peers == peers_left)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Too many peers failed, ending test!\n");
- ok = 1;
- GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
- }
- return;
+ "Too many peers failed, ending test!\n");
+ ok = 1;
+ GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
}
+ return;
+ }
peers_left--;
if (peers_left == 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "All peers started successfully, ending test!\n");
- GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
- ok = 0;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "All peers started successfully, ending test!\n");
+ GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
+ ok = 0;
+ }
else if (failed_peers == peers_left)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Too many peers failed, ending test!\n");
- ok = 1;
- GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Too many peers failed, ending test!\n");
+ ok = 1;
+ GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
+ }
}
@@ -115,10 +114,9 @@
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemons.\n");
#endif
peers_left = NUM_PEERS;
- pg = GNUNET_TESTING_daemons_start (cfg,
- peers_left, /* Total number of peers */
- peers_left, /* Number of outstanding
connections */
- peers_left, /* Number of parallel ssh
connections, or peers being started at once */
+ pg = GNUNET_TESTING_daemons_start (cfg, peers_left, /* Total number of
peers */
+ peers_left, /* Number of
outstanding connections */
+ peers_left, /* Number of parallel
ssh connections, or peers being started at once */
TIMEOUT,
NULL, NULL,
&my_cb, NULL, NULL, NULL, NULL);
@@ -140,8 +138,7 @@
GNUNET_GETOPT_OPTION_END
};
GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
- argv, "test-testing-group", "nohelp",
- options, &run, &ok);
+ argv, "test-testing-group", "nohelp", options, &run,
&ok);
return ok;
}
Modified: gnunet/src/testing/test_testing_group_remote.c
===================================================================
--- gnunet/src/testing/test_testing_group_remote.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/testing/test_testing_group_remote.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -54,20 +54,20 @@
shutdown_callback (void *cls, const char *emsg)
{
if (emsg != NULL)
- {
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed (error
%s)!\n", emsg);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Shutdown of peers failed (error %s)!\n", emsg);
#endif
- if (ok == 0)
- ok = 666;
- }
+ if (ok == 0)
+ ok = 666;
+ }
else
- {
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "All peers successfully shut down!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers successfully shut
down!\n");
#endif
- }
+ }
}
@@ -78,22 +78,22 @@
struct GNUNET_TESTING_Daemon *d, const char *emsg)
{
if (emsg != NULL)
- {
- peers_failed++;
- }
+ {
+ peers_failed++;
+ }
peers_left--;
if (peers_left == 0)
- {
- GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
- ok = 0;
- }
+ {
+ GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
+ ok = 0;
+ }
else if (peers_failed == peers_left)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Too many peers failed, ending test!\n");
- GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Too many peers failed, ending test!\n");
+ GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
+ }
}
@@ -111,6 +111,7 @@
char *data;
int count;
int ret;
+
ok = 1;
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemons.\n");
@@ -130,93 +131,89 @@
hosts = NULL;
data = NULL;
if (hostfile != NULL)
+ {
+ if (GNUNET_OK != GNUNET_DISK_file_test (hostfile))
+ GNUNET_DISK_fn_write (hostfile, NULL, 0, GNUNET_DISK_PERM_USER_READ
+ | GNUNET_DISK_PERM_USER_WRITE);
+ if ((0 != STAT (hostfile, &frstat)) || (frstat.st_size == 0))
{
- if (GNUNET_OK != GNUNET_DISK_file_test (hostfile))
- GNUNET_DISK_fn_write (hostfile, NULL, 0, GNUNET_DISK_PERM_USER_READ
- | GNUNET_DISK_PERM_USER_WRITE);
- if ((0 != STAT (hostfile, &frstat)) || (frstat.st_size == 0))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Could not open file specified for host list, ending
test!");
- ok = 1119;
- GNUNET_free (hostfile);
- return;
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Could not open file specified for host list, ending test!");
+ ok = 1119;
+ GNUNET_free (hostfile);
+ return;
+ }
- data = GNUNET_malloc_large (frstat.st_size);
- GNUNET_assert (data != NULL);
- if (frstat.st_size !=
- GNUNET_DISK_fn_read (hostfile, data, frstat.st_size))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Could not read file %s specified for host list, ending
test!",
- hostfile);
- GNUNET_free (hostfile);
- GNUNET_free (data);
- return;
- }
+ data = GNUNET_malloc_large (frstat.st_size);
+ GNUNET_assert (data != NULL);
+ if (frstat.st_size != GNUNET_DISK_fn_read (hostfile, data, frstat.st_size))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Could not read file %s specified for host list, ending
test!",
+ hostfile);
+ GNUNET_free (hostfile);
+ GNUNET_free (data);
+ return;
+ }
- GNUNET_free_non_null (hostfile);
+ GNUNET_free_non_null (hostfile);
- buf = data;
- count = 0;
- while (count < frstat.st_size)
- {
- count++;
- if (count >= frstat.st_size)
- break;
+ buf = data;
+ count = 0;
+ while (count < frstat.st_size)
+ {
+ count++;
+ if (count >= frstat.st_size)
+ break;
- /* if (((data[count] == '\n') || (data[count] == '\0')) && (buf !=
&data[count])) */
- if (((data[count] == '\n')) && (buf != &data[count]))
- {
- data[count] = '\0';
- temphost = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Host));
- ret =
- sscanf (buf, "address@hidden:%hd",
- &temphost->username, &temphost->hostname,
- &temphost->port);
- if (3 == ret)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Successfully read host %s, port %d and user %s
from file\n",
- temphost->hostname, temphost->port,
- temphost->username);
- }
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Error reading line `%s' in hostfile\n", buf);
- GNUNET_free (temphost);
- buf = &data[count + 1];
- continue;
- }
- /* temphost->hostname = buf; */
- temphost->next = hosts;
- hosts = temphost;
- buf = &data[count + 1];
- }
- else if ((data[count] == '\n') || (data[count] == '\0'))
- buf = &data[count + 1];
+ /* if (((data[count] == '\n') || (data[count] == '\0')) && (buf !=
&data[count])) */
+ if (((data[count] == '\n')) && (buf != &data[count]))
+ {
+ data[count] = '\0';
+ temphost = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Host));
+ ret =
+ sscanf (buf, "address@hidden:%hd",
+ &temphost->username, &temphost->hostname, &temphost->port);
+ if (3 == ret)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Successfully read host %s, port %d and user %s from
file\n",
+ temphost->hostname, temphost->port, temphost->username);
}
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Error reading line `%s' in hostfile\n", buf);
+ GNUNET_free (temphost);
+ buf = &data[count + 1];
+ continue;
+ }
+ /* temphost->hostname = buf; */
+ temphost->next = hosts;
+ hosts = temphost;
+ buf = &data[count + 1];
+ }
+ else if ((data[count] == '\n') || (data[count] == '\0'))
+ buf = &data[count + 1];
}
+ }
peers_left = num_peers;
- pg = GNUNET_TESTING_daemons_start (cfg,
- peers_left, /* Total number of peers */
- peers_left, /* Number of outstanding
connections */
- peers_left, /* Number of parallel ssh
connections, or peers being started at once */
+ pg = GNUNET_TESTING_daemons_start (cfg, peers_left, /* Total number of
peers */
+ peers_left, /* Number of
outstanding connections */
+ peers_left, /* Number of parallel
ssh connections, or peers being started at once */
TIMEOUT,
NULL,
NULL, &my_cb, NULL, NULL, NULL, hosts);
hostpos = hosts;
while (hostpos != NULL)
- {
- temphost = hostpos->next;
- GNUNET_free (hostpos->hostname);
- GNUNET_free (hostpos->username);
- GNUNET_free (hostpos);
- hostpos = temphost;
- }
+ {
+ temphost = hostpos->next;
+ GNUNET_free (hostpos->hostname);
+ GNUNET_free (hostpos->username);
+ GNUNET_free (hostpos);
+ hostpos = temphost;
+ }
GNUNET_free_non_null (data);
GNUNET_assert (pg != NULL);
@@ -237,8 +234,7 @@
GNUNET_GETOPT_OPTION_END
};
GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
- argv, "test-testing-group", "nohelp",
- options, &run, &ok);
+ argv, "test-testing-group", "nohelp", options, &run,
&ok);
return ok;
}
Modified: gnunet/src/testing/test_testing_large_topology.c
===================================================================
--- gnunet/src/testing/test_testing_large_topology.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/testing/test_testing_large_topology.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -99,7 +99,7 @@
static enum GNUNET_TESTING_Topology connection_topology =
GNUNET_TESTING_TOPOLOGY_NONE; /* NONE actually means connect all allowed peers
*/
static enum GNUNET_TESTING_TopologyOption connect_topology_option =
- GNUNET_TESTING_TOPOLOGY_OPTION_ALL;
+ GNUNET_TESTING_TOPOLOGY_OPTION_ALL;
static double connect_topology_option_modifier = 0.0;
@@ -160,20 +160,19 @@
shutdown_callback (void *cls, const char *emsg)
{
if (emsg != NULL)
- {
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n");
#endif
- if (ok == 0)
- ok = 666;
- }
+ if (ok == 0)
+ ok = 666;
+ }
else
- {
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "All peers successfully shut down!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers successfully shut
down!\n");
#endif
- }
+ }
}
#if DELAY_FOR_LOGGING
@@ -183,6 +182,7 @@
char *peer_number;
char *connect_number;
struct GNUNET_OS_Process *mem_process;
+
GNUNET_asprintf (&peer_number, "%llu", num_peers);
GNUNET_asprintf (&connect_number, "%llu", expected_connections);
mem_process = GNUNET_OS_start_process (NULL, NULL, "./memsize.pl",
@@ -201,6 +201,7 @@
GNUNET_assert (pg != NULL);
struct TestMessageContext *pos;
struct TestMessageContext *free_pos;
+
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Called finish testing, stopping daemons.\n");
@@ -208,25 +209,25 @@
pos = test_messages;
while (pos != NULL)
+ {
+ if (pos->peer1handle != NULL)
{
- if (pos->peer1handle != NULL)
- {
- GNUNET_CORE_disconnect (pos->peer1handle);
- pos->peer1handle = NULL;
- }
- if (pos->peer2handle != NULL)
- {
- GNUNET_CORE_disconnect (pos->peer2handle);
- pos->peer2handle = NULL;
- }
- free_pos = pos;
- pos = pos->next;
- if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (free_pos->disconnect_task);
- }
- GNUNET_free (free_pos);
+ GNUNET_CORE_disconnect (pos->peer1handle);
+ pos->peer1handle = NULL;
}
+ if (pos->peer2handle != NULL)
+ {
+ GNUNET_CORE_disconnect (pos->peer2handle);
+ pos->peer2handle = NULL;
+ }
+ free_pos = pos;
+ pos = pos->next;
+ if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (free_pos->disconnect_task);
+ }
+ GNUNET_free (free_pos);
+ }
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Transmit_ready's scheduled %d, failed %d, transmit_ready's
called %d\n",
@@ -240,10 +241,10 @@
GNUNET_TESTING_daemons_stop (pg, timeout, &shutdown_callback, NULL);
if (dotOutFile != NULL)
- {
- fprintf (dotOutFile, "}");
- fclose (dotOutFile);
- }
+ {
+ fprintf (dotOutFile, "}");
+ fclose (dotOutFile);
+ }
ok = 0;
}
@@ -284,27 +285,28 @@
const struct GNUNET_PeerIdentity *second, const char *emsg)
{
FILE *outfile = cls;
+
if (first != NULL)
+ {
+ if (outfile != NULL)
{
- if (outfile != NULL)
- {
- fprintf (outfile, "\t\"%s\" -- ", GNUNET_i2s (first));
- fprintf (outfile, "\"%s\";\n", GNUNET_i2s (second));
- }
- topology_connections++;
+ fprintf (outfile, "\t\"%s\" -- ", GNUNET_i2s (first));
+ fprintf (outfile, "\"%s\";\n", GNUNET_i2s (second));
}
+ topology_connections++;
+ }
else
+ {
+ fprintf (stderr,
+ "Finished iterating over topology, %d total connections!\n",
+ topology_connections);
+ if (outfile != NULL)
{
- fprintf (stderr,
- "Finished iterating over topology, %d total connections!\n",
- topology_connections);
- if (outfile != NULL)
- {
- fprintf (outfile, "}\n");
- fclose (outfile);
- GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
- }
+ fprintf (outfile, "}\n");
+ fclose (outfile);
+ GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
}
+ }
}
static int
@@ -317,24 +319,25 @@
FILE *dotOutFileFinished;
struct TestMessageContext *pos = cls;
struct GNUNET_TestMessage *msg = (struct GNUNET_TestMessage *) message;
+
if (pos->uid != ntohl (msg->uid))
return GNUNET_OK;
#if VERBOSE
if ((total_messages_received) % modnum == 0)
- {
- if (total_messages_received == 0)
- fprintf (stdout, "0%%");
- else
- fprintf (stdout, "%d%%",
- (int) (((float) total_messages_received /
- expected_messages) * 100));
+ {
+ if (total_messages_received == 0)
+ fprintf (stdout, "0%%");
+ else
+ fprintf (stdout, "%d%%",
+ (int) (((float) total_messages_received /
+ expected_messages) * 100));
- }
+ }
else if (total_messages_received % dotnum == 0)
- {
- fprintf (stdout, ".");
- }
+ {
+ fprintf (stdout, ".");
+ }
fflush (stdout);
#endif
@@ -350,27 +353,26 @@
#endif
if (total_messages_received == expected_messages)
- {
+ {
#if VERBOSE
- fprintf (stdout, "100%%]\n");
+ fprintf (stdout, "100%%]\n");
#endif
- GNUNET_SCHEDULER_cancel (die_task);
- GNUNET_asprintf (&dotOutFileNameFinished, "%s.dot", "final_topology");
- dotOutFileFinished = fopen (dotOutFileNameFinished, "w");
- GNUNET_free (dotOutFileNameFinished);
- if (dotOutFileFinished != NULL)
- {
- fprintf (dotOutFileFinished, "strict graph G {\n");
- }
- topology_connections = 0;
- GNUNET_TESTING_get_topology (pg, &topology_cb, dotOutFileFinished);
- //GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
+ GNUNET_SCHEDULER_cancel (die_task);
+ GNUNET_asprintf (&dotOutFileNameFinished, "%s.dot", "final_topology");
+ dotOutFileFinished = fopen (dotOutFileNameFinished, "w");
+ GNUNET_free (dotOutFileNameFinished);
+ if (dotOutFileFinished != NULL)
+ {
+ fprintf (dotOutFileFinished, "strict graph G {\n");
}
+ topology_connections = 0;
+ GNUNET_TESTING_get_topology (pg, &topology_cb, dotOutFileFinished);
+ //GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
+ }
else
- {
- pos->disconnect_task =
- GNUNET_SCHEDULER_add_now (&disconnect_cores, pos);
- }
+ {
+ pos->disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cores, pos);
+ }
return GNUNET_OK;
}
@@ -379,6 +381,7 @@
end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
char *msg = cls;
+
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"End badly was called (%s)... stopping daemons.\n", msg);
struct TestMessageContext *pos;
@@ -386,21 +389,21 @@
pos = test_messages;
while (pos != NULL)
+ {
+ if (pos->peer1handle != NULL)
{
- if (pos->peer1handle != NULL)
- {
- GNUNET_CORE_disconnect (pos->peer1handle);
- pos->peer1handle = NULL;
- }
- if (pos->peer2handle != NULL)
- {
- GNUNET_CORE_disconnect (pos->peer2handle);
- pos->peer2handle = NULL;
- }
- free_pos = pos;
- pos = pos->next;
- GNUNET_free (free_pos);
+ GNUNET_CORE_disconnect (pos->peer1handle);
+ pos->peer1handle = NULL;
}
+ if (pos->peer2handle != NULL)
+ {
+ GNUNET_CORE_disconnect (pos->peer2handle);
+ pos->peer2handle = NULL;
+ }
+ free_pos = pos;
+ pos = pos->next;
+ GNUNET_free (free_pos);
+ }
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -413,18 +416,18 @@
#endif
if (pg != NULL)
- {
- GNUNET_TESTING_daemons_stop (pg, timeout, &shutdown_callback, NULL);
- ok = 7331; /* Opposite of leet */
- }
+ {
+ GNUNET_TESTING_daemons_stop (pg, timeout, &shutdown_callback, NULL);
+ ok = 7331; /* Opposite of leet */
+ }
else
ok = 401; /* Never got peers started */
if (dotOutFile != NULL)
- {
- fprintf (dotOutFile, "}");
- fclose (dotOutFile);
- }
+ {
+ fprintf (dotOutFile, "}");
+ fclose (dotOutFile);
+ }
}
static size_t
@@ -471,30 +474,31 @@
pos->peer2connected = GNUNET_YES;
if (pos->peer1notified == GNUNET_YES) /* Peer 1 has been notified of
connection to peer 2 */
+ {
+#if VERBOSE > 1
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Scheduling message send to peer `%s' from peer `%s'
(init_notify_peer2)\n",
+ GNUNET_i2s (my_identity),
+ GNUNET_h2s (&pos->peer1->id.hashPubKey));
+#endif
+ if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle,
+ 0,
+ timeout,
+ &pos->peer2->id,
+ sizeof (struct
+ GNUNET_TestMessage),
+ &transmit_ready, pos))
{
-#if VERBOSE > 1
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Scheduling message send to peer `%s' from peer `%s'
(init_notify_peer2)\n",
- GNUNET_i2s (my_identity),
GNUNET_h2s(&pos->peer1->id.hashPubKey));
-#endif
- if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle,
- 0,
- timeout,
- &pos->peer2->id,
- sizeof (struct
-
GNUNET_TestMessage),
- &transmit_ready, pos))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "RECEIVED NULL when asking core (1) for transmission to
peer `%4s'\n",
- GNUNET_i2s (&pos->peer2->id));
- transmit_ready_failed++;
- }
- else
- {
- transmit_ready_scheduled++;
- }
+ "RECEIVED NULL when asking core (1) for transmission to peer
`%4s'\n",
+ GNUNET_i2s (&pos->peer2->id));
+ transmit_ready_failed++;
}
+ else
+ {
+ transmit_ready_scheduled++;
+ }
+ }
}
/**
@@ -504,50 +508,52 @@
* @param peer peer identity this notification is about
* @param atsi performance data for the connection
*/
-static void connect_notify_peers (void *cls,
- const struct
- GNUNET_PeerIdentity *peer,
- const struct
GNUNET_TRANSPORT_ATS_Information *atsi)
+static void
+connect_notify_peers (void *cls,
+ const struct
+ GNUNET_PeerIdentity *peer,
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
struct TestMessageContext *pos = cls;
- if (0 == memcmp(peer, &pos->peer2->id, sizeof(struct GNUNET_PeerIdentity)))
- {
- pos->peer1notified = GNUNET_YES;
+ if (0 == memcmp (peer, &pos->peer2->id, sizeof (struct GNUNET_PeerIdentity)))
+ {
+ pos->peer1notified = GNUNET_YES;
#if VERBOSE > 1
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Peer `%s' notified of connection to peer `%s'\n",
- GNUNET_i2s (&pos->peer1->id), GNUNET_h2s(&peer->hashPubKey));
+ GNUNET_i2s (&pos->peer1->id), GNUNET_h2s (&peer->hashPubKey));
#endif
- }
+ }
else
return;
- if (pos->peer2connected == GNUNET_YES) /* Already connected and notified of
connection, send message! */
- {
+ if (pos->peer2connected == GNUNET_YES) /* Already connected and
notified of connection, send message! */
+ {
#if VERBOSE > 1
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Scheduling message send to peer `%s' from peer `%s'
(init_notify_peer2)\n",
- GNUNET_i2s (&pos->peer2->id),
GNUNET_h2s(&pos->peer1->id.hashPubKey));
+ GNUNET_i2s (&pos->peer2->id),
+ GNUNET_h2s (&pos->peer1->id.hashPubKey));
#endif
- if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle,
- 0,
- timeout,
- &pos->peer2->id,
- sizeof (struct
-
GNUNET_TestMessage),
- &transmit_ready, pos))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "RECEIVED NULL when asking core (1) for transmission to
peer `%4s'\n",
- GNUNET_i2s (&pos->peer2->id));
- transmit_ready_failed++;
- }
- else
- {
- transmit_ready_scheduled++;
- }
+ if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle,
+ 0,
+ timeout,
+ &pos->peer2->id,
+ sizeof (struct
+ GNUNET_TestMessage),
+ &transmit_ready, pos))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "RECEIVED NULL when asking core (1) for transmission to peer
`%4s'\n",
+ GNUNET_i2s (&pos->peer2->id));
+ transmit_ready_failed++;
}
+ else
+ {
+ transmit_ready_scheduled++;
+ }
+ }
}
static void
@@ -558,6 +564,7 @@
*publicKey)
{
struct TestMessageContext *pos = cls;
+
total_server_connections++;
#if VERBOSE > 1
@@ -588,27 +595,27 @@
struct TestMessageContext *pos = cls;
if ((pos == test_messages) && (settle_time.rel_value > 0))
- {
- topology_connections = 0;
- GNUNET_TESTING_get_topology (pg, &topology_cb, NULL);
- }
- if (( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)|| (cls == NULL))
+ {
+ topology_connections = 0;
+ GNUNET_TESTING_get_topology (pg, &topology_cb, NULL);
+ }
+ if (((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) || (cls == NULL))
return;
if (die_task == GNUNET_SCHEDULER_NO_TASK)
- {
- die_task = GNUNET_SCHEDULER_add_delayed (test_timeout,
- &end_badly,
- "from send test messages
(timeout)");
- }
+ {
+ die_task = GNUNET_SCHEDULER_add_delayed (test_timeout,
+ &end_badly,
+ "from send test messages
(timeout)");
+ }
if (total_server_connections >= MAX_OUTSTANDING_CONNECTIONS)
- {
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS, 1),
- &send_test_messages, pos);
- return; /* Otherwise we'll double schedule messages
here! */
- }
+ {
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 1),
+ &send_test_messages, pos);
+ return; /* Otherwise we'll double schedule messages
here! */
+ }
/*
* Connect to the sending peer
@@ -626,15 +633,15 @@
GNUNET_assert (pos->peer1handle != NULL);
if (total_server_connections < MAX_OUTSTANDING_CONNECTIONS)
- {
- GNUNET_SCHEDULER_add_now (&send_test_messages, pos->next);
- }
+ {
+ GNUNET_SCHEDULER_add_now (&send_test_messages, pos->next);
+ }
else
- {
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS, 1),
- &send_test_messages, pos->next);
- }
+ {
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 1),
+ &send_test_messages, pos->next);
+ }
}
@@ -650,113 +657,114 @@
const char *emsg)
{
struct TestMessageContext *temp_context;
+
if (emsg == NULL)
+ {
+#if VERBOSE
+ if ((total_connections) % modnum == 0)
{
-#if VERBOSE
- if ((total_connections) % modnum == 0)
- {
- if (total_connections == 0)
- fprintf (stdout, "0%%");
- else
- fprintf (stdout, "%d%%",
- (int) (((float) total_connections /
- expected_connections) * 100));
+ if (total_connections == 0)
+ fprintf (stdout, "0%%");
+ else
+ fprintf (stdout, "%d%%",
+ (int) (((float) total_connections /
+ expected_connections) * 100));
- }
- else if (total_connections % dotnum == 0)
- {
- fprintf (stdout, ".");
- }
- fflush (stdout);
+ }
+ else if (total_connections % dotnum == 0)
+ {
+ fprintf (stdout, ".");
+ }
+ fflush (stdout);
#endif
- total_connections++;
+ total_connections++;
#if VERBOSE > 1
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "connected peer %s to peer %s\n",
- first_daemon->shortname, second_daemon->shortname);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "connected peer %s to peer %s\n",
+ first_daemon->shortname, second_daemon->shortname);
#endif
- temp_context = GNUNET_malloc (sizeof (struct TestMessageContext));
- temp_context->peer1 = first_daemon;
- temp_context->peer2 = second_daemon;
- temp_context->next = test_messages;
- temp_context->uid = total_connections;
- temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
- test_messages = temp_context;
+ temp_context = GNUNET_malloc (sizeof (struct TestMessageContext));
+ temp_context->peer1 = first_daemon;
+ temp_context->peer2 = second_daemon;
+ temp_context->next = test_messages;
+ temp_context->uid = total_connections;
+ temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
+ test_messages = temp_context;
- expected_messages++;
- if (dotOutFile != NULL)
- fprintf (dotOutFile, "\tn%s -- n%s;\n", first_daemon->shortname,
- second_daemon->shortname);
- }
+ expected_messages++;
+ if (dotOutFile != NULL)
+ fprintf (dotOutFile, "\tn%s -- n%s;\n", first_daemon->shortname,
+ second_daemon->shortname);
+ }
#if VERBOSE
else
- {
- failed_connections++;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Failed to connect peer %s to peer %s with error :\n%s\n",
- first_daemon->shortname, second_daemon->shortname, emsg);
- }
+ {
+ failed_connections++;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to connect peer %s to peer %s with error :\n%s\n",
+ first_daemon->shortname, second_daemon->shortname, emsg);
+ }
#endif
if (total_connections == expected_connections)
- {
+ {
#if VERBOSE
- fprintf (stdout, "100%%]\n");
+ fprintf (stdout, "100%%]\n");
#endif
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Created %d total connections, which is our target number!
Calling send messages.\n",
- total_connections);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Created %d total connections, which is our target number!
Calling send messages.\n",
+ total_connections);
#endif
- modnum = expected_messages / 4;
- dotnum = (expected_messages / 50) + 1;
- GNUNET_SCHEDULER_cancel (die_task);
- die_task = GNUNET_SCHEDULER_NO_TASK;
+ modnum = expected_messages / 4;
+ dotnum = (expected_messages / 50) + 1;
+ GNUNET_SCHEDULER_cancel (die_task);
+ die_task = GNUNET_SCHEDULER_NO_TASK;
#if DELAY_FOR_LOGGING
- fprintf (stdout, "Sending test messages in 10 seconds.\n");
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS, 10),
- &send_test_messages, test_messages);
- gather_log_data ();
+ fprintf (stdout, "Sending test messages in 10 seconds.\n");
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 10),
+ &send_test_messages, test_messages);
+ gather_log_data ();
#else
- if (settle_time.rel_value > 0)
- {
- GNUNET_TESTING_get_topology (pg, &topology_cb, NULL);
- }
- GNUNET_SCHEDULER_add_delayed (settle_time, &send_test_messages,
- test_messages);
+ if (settle_time.rel_value > 0)
+ {
+ GNUNET_TESTING_get_topology (pg, &topology_cb, NULL);
+ }
+ GNUNET_SCHEDULER_add_delayed (settle_time, &send_test_messages,
+ test_messages);
#endif
#if VERBOSE
- fprintf (stdout, "Test message progress: [");
+ fprintf (stdout, "Test message progress: [");
#endif
- }
+ }
else if (total_connections + failed_connections == expected_connections)
+ {
+ if (failed_connections <
+ (unsigned int) (fail_percentage * total_connections))
{
- if (failed_connections <
- (unsigned int) (fail_percentage * total_connections))
- {
- GNUNET_SCHEDULER_cancel (die_task);
- die_task = GNUNET_SCHEDULER_NO_TASK;
- GNUNET_SCHEDULER_add_now (&send_test_messages, test_messages);
- }
- else
- {
- GNUNET_SCHEDULER_cancel (die_task);
- die_task =
- GNUNET_SCHEDULER_add_now (&end_badly,
- "from topology_callback (too many failed
connections)");
- }
+ GNUNET_SCHEDULER_cancel (die_task);
+ die_task = GNUNET_SCHEDULER_NO_TASK;
+ GNUNET_SCHEDULER_add_now (&send_test_messages, test_messages);
}
+ else
+ {
+ GNUNET_SCHEDULER_cancel (die_task);
+ die_task =
+ GNUNET_SCHEDULER_add_now (&end_badly,
+ "from topology_callback (too many failed
connections)");
+ }
+ }
else
- {
+ {
#if VERBOSE > 1
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Have %d total connections, %d failed connections, Want %d
(at least %d)\n",
- total_connections, failed_connections, expected_connections,
- expected_connections -
- (unsigned int) (fail_percentage * expected_connections));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Have %d total connections, %d failed connections, Want %d (at
least %d)\n",
+ total_connections, failed_connections, expected_connections,
+ expected_connections -
+ (unsigned int) (fail_percentage * expected_connections));
#endif
- }
+ }
}
static void
@@ -774,8 +782,8 @@
{
expected_connections = -1;
if ((pg != NULL) && (peers_left == 0))
- {
- expected_connections =
+ {
+ expected_connections =
GNUNET_TESTING_connect_topology (pg, connection_topology,
connect_topology_option,
connect_topology_option_modifier,
@@ -783,18 +791,18 @@
connect_attempts,
&topology_creation_finished, NULL);
#if VERBOSE > 1
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Have %d expected connections\n", expected_connections);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Have %d expected connections\n", expected_connections);
#endif
- }
+ }
GNUNET_SCHEDULER_cancel (die_task);
if (expected_connections == GNUNET_SYSERR)
- {
- die_task =
+ {
+ die_task =
GNUNET_SCHEDULER_add_now (&end_badly,
"from connect topology (bad return)");
- }
+ }
die_task = GNUNET_SCHEDULER_add_delayed (test_timeout,
&end_badly,
@@ -811,23 +819,22 @@
{
peers_left = num_peers; /* Reset counter */
if (GNUNET_TESTING_create_topology
- (pg, topology, blacklist_topology,
- blacklist_transports) != GNUNET_SYSERR)
- {
+ (pg, topology, blacklist_topology, blacklist_transports) !=
GNUNET_SYSERR)
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Topology set up, now starting peers!\n");
- fprintf (stdout, "Daemon start progress [");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Topology set up, now starting peers!\n");
+ fprintf (stdout, "Daemon start progress [");
#endif
- GNUNET_TESTING_daemons_continue_startup (pg);
- }
+ GNUNET_TESTING_daemons_continue_startup (pg);
+ }
else
- {
- GNUNET_SCHEDULER_cancel (die_task);
- die_task =
+ {
+ GNUNET_SCHEDULER_cancel (die_task);
+ die_task =
GNUNET_SCHEDULER_add_now (&end_badly,
"from create topology (bad return)");
- }
+ }
GNUNET_SCHEDULER_cancel (die_task);
die_task = GNUNET_SCHEDULER_add_delayed (test_timeout,
&end_badly,
@@ -842,11 +849,11 @@
struct GNUNET_TESTING_Daemon *d, const char *emsg)
{
if (emsg != NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Failed to start daemon with error: `%s'\n", emsg);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to start daemon with error: `%s'\n", emsg);
+ return;
+ }
GNUNET_assert (id != NULL);
#if VERBOSE > 1
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n",
@@ -854,49 +861,47 @@
#endif
#if VERBOSE
if ((num_peers - peers_left) % modnum == 0)
- {
- if (num_peers - peers_left == 0)
- fprintf (stdout, "0%%");
- else
- fprintf (stdout, "%d%%",
- (int) (((float) (num_peers - peers_left) /
- num_peers) * 100));
+ {
+ if (num_peers - peers_left == 0)
+ fprintf (stdout, "0%%");
+ else
+ fprintf (stdout, "%d%%",
+ (int) (((float) (num_peers - peers_left) / num_peers) * 100));
- }
+ }
else if ((num_peers - peers_left) % dotnum == 0)
- {
- fprintf (stdout, ".");
- }
+ {
+ fprintf (stdout, ".");
+ }
fflush (stdout);
#endif
peers_left--;
if (peers_left == 0)
- {
+ {
#if VERBOSE
- fprintf (stdout, "100%%]\n");
+ fprintf (stdout, "100%%]\n");
#endif
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "All %d daemons started, now connecting peers!\n",
- num_peers);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "All %d daemons started, now connecting peers!\n", num_peers);
#endif
- GNUNET_SCHEDULER_cancel (die_task);
- /* Set up task in case topology creation doesn't finish
- * within a reasonable amount of time */
- die_task = GNUNET_SCHEDULER_add_delayed (timeout,
- &end_badly,
- "from peers_started_callback");
+ GNUNET_SCHEDULER_cancel (die_task);
+ /* Set up task in case topology creation doesn't finish
+ * within a reasonable amount of time */
+ die_task = GNUNET_SCHEDULER_add_delayed (timeout,
+ &end_badly,
+ "from peers_started_callback");
#if DELAY_FOR_LOGGING
- fprintf (stdout, "Connecting topology in 10 seconds\n");
- gather_log_data ();
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS, 10),
- &connect_topology, NULL);
+ fprintf (stdout, "Connecting topology in 10 seconds\n");
+ gather_log_data ();
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 10),
+ &connect_topology, NULL);
#else
- connect_topology ();
+ connect_topology ();
#endif
- ok = 0;
- }
+ ok = 0;
+ }
}
/**
@@ -913,10 +918,10 @@
struct GNUNET_TESTING_Daemon *d, const char *emsg)
{
if (emsg != NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Hostkey callback received error: %s\n", emsg);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Hostkey callback received error: %s\n", emsg);
+ }
#if VERBOSE > 1
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -926,39 +931,37 @@
#if VERBOSE
if ((num_peers - peers_left) % modnum == 0)
- {
- if (num_peers - peers_left == 0)
- fprintf (stdout, "0%%");
- else
- fprintf (stdout, "%d%%",
- (int) (((float) (num_peers - peers_left) /
- num_peers) * 100));
+ {
+ if (num_peers - peers_left == 0)
+ fprintf (stdout, "0%%");
+ else
+ fprintf (stdout, "%d%%",
+ (int) (((float) (num_peers - peers_left) / num_peers) * 100));
- }
+ }
else if ((num_peers - peers_left) % dotnum == 0)
- {
- fprintf (stdout, ".");
- }
+ {
+ fprintf (stdout, ".");
+ }
fflush (stdout);
#endif
peers_left--;
if (peers_left == 0)
- {
+ {
#if VERBOSE
- fprintf (stdout, "100%%]\n");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "All %d hostkeys created, now creating topology!\n",
- num_peers);
+ fprintf (stdout, "100%%]\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "All %d hostkeys created, now creating topology!\n",
num_peers);
#endif
- GNUNET_SCHEDULER_cancel (die_task);
- /* Set up task in case topology creation doesn't finish
- * within a reasonable amount of time */
- die_task = GNUNET_SCHEDULER_add_delayed (test_timeout,
- &end_badly,
- "from create_topology");
- GNUNET_SCHEDULER_add_now (&create_topology, NULL);
- ok = 0;
- }
+ GNUNET_SCHEDULER_cancel (die_task);
+ /* Set up task in case topology creation doesn't finish
+ * within a reasonable amount of time */
+ die_task = GNUNET_SCHEDULER_add_delayed (test_timeout,
+ &end_badly,
+ "from create_topology");
+ GNUNET_SCHEDULER_add_now (&create_topology, NULL);
+ ok = 0;
+ }
}
static void
@@ -972,13 +975,14 @@
char *connect_topology_option_str;
char *connect_topology_option_modifier_string;
unsigned long long temp_settle;
+
ok = 1;
dotOutFile = fopen (dotOutFileName, "w");
if (dotOutFile != NULL)
- {
- fprintf (dotOutFile, "strict graph G {\n");
- }
+ {
+ fprintf (dotOutFile, "strict graph G {\n");
+ }
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -988,21 +992,21 @@
if (GNUNET_YES !=
GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome",
&test_directory))
- {
- ok = 404;
- return;
- }
+ {
+ ok = 404;
+ return;
+ }
if ((GNUNET_YES ==
GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "topology",
&topology_str))
&& (GNUNET_NO == GNUNET_TESTING_topology_get (&topology, topology_str)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Invalid topology `%s' given for section %s option %s\n",
- topology_str, "TESTING", "TOPOLOGY");
- topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE,
so set better default here */
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Invalid topology `%s' given for section %s option %s\n",
+ topology_str, "TESTING", "TOPOLOGY");
+ topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set
better default here */
+ }
if ((GNUNET_YES ==
GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
@@ -1011,11 +1015,11 @@
&& (GNUNET_NO ==
GNUNET_TESTING_topology_get (&connection_topology,
connect_topology_str)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Invalid connect topology `%s' given for section %s option
%s\n",
- connect_topology_str, "TESTING", "CONNECT_TOPOLOGY");
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Invalid connect topology `%s' given for section %s option
%s\n",
+ connect_topology_str, "TESTING", "CONNECT_TOPOLOGY");
+ }
GNUNET_free_non_null (connect_topology_str);
if ((GNUNET_YES ==
GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
@@ -1024,31 +1028,31 @@
&& (GNUNET_NO ==
GNUNET_TESTING_topology_option_get (&connect_topology_option,
connect_topology_option_str)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Invalid connect topology option `%s' given for section %s
option %s\n",
- connect_topology_option_str, "TESTING",
- "CONNECT_TOPOLOGY_OPTION");
- connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /*
Defaults to NONE, set to ALL */
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Invalid connect topology option `%s' given for section %s
option %s\n",
+ connect_topology_option_str, "TESTING",
+ "CONNECT_TOPOLOGY_OPTION");
+ connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /*
Defaults to NONE, set to ALL */
+ }
GNUNET_free_non_null (connect_topology_option_str);
if (GNUNET_YES ==
GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
"connect_topology_option_modifier",
&connect_topology_option_modifier_string))
+ {
+ if (sscanf
+ (connect_topology_option_modifier_string, "%lf",
+ &connect_topology_option_modifier) != 1)
{
- if (sscanf
- (connect_topology_option_modifier_string, "%lf",
- &connect_topology_option_modifier) != 1)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _
- ("Invalid value `%s' for option `%s' in section `%s':
expected float\n"),
- connect_topology_option_modifier_string,
- "connect_topology_option_modifier", "TESTING");
- }
- GNUNET_free (connect_topology_option_modifier_string);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Invalid value `%s' for option `%s' in section `%s':
expected float\n"),
+ connect_topology_option_modifier_string,
+ "connect_topology_option_modifier", "TESTING");
}
+ GNUNET_free (connect_topology_option_modifier_string);
+ }
if (GNUNET_YES !=
GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
@@ -1063,11 +1067,11 @@
&& (GNUNET_NO ==
GNUNET_TESTING_topology_get (&blacklist_topology,
blacklist_topology_str)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Invalid topology `%s' given for section %s option %s\n",
- topology_str, "TESTING", "BLACKLIST_TOPOLOGY");
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Invalid topology `%s' given for section %s option %s\n",
+ topology_str, "TESTING", "BLACKLIST_TOPOLOGY");
+ }
GNUNET_free_non_null (topology_str);
GNUNET_free_non_null (blacklist_topology_str);
@@ -1075,7 +1079,7 @@
GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "settle_time",
&temp_settle))
settle_time =
- GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_settle);
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_settle);
if (GNUNET_SYSERR ==
GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers",
@@ -1086,21 +1090,23 @@
GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "connect_timeout",
&temp_settle))
connect_timeout =
- GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_settle);
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_settle);
else
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
"testing", "connect_timeout");
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
+ "testing", "connect_timeout");
+ return;
+ }
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (cfg, "testing",
"connect_attempts",
- &connect_attempts))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
"testing", "connect_attempts");
- return;
- }
+ GNUNET_CONFIGURATION_get_value_number (cfg, "testing",
"connect_attempts",
+ &connect_attempts))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
+ "testing", "connect_attempts");
+ return;
+ }
main_cfg = cfg;
@@ -1109,12 +1115,18 @@
/**
* How long until we fail the whole testcase?
*/
- test_timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_SECONDS, SECONDS_PER_PEER_START), num_peers * 2);
+ test_timeout =
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS,
+ SECONDS_PER_PEER_START), num_peers * 2);
/**
* How long until we give up on starting the peers?
*/
- timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_SECONDS, SECONDS_PER_PEER_START), num_peers);
+ timeout =
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS,
+ SECONDS_PER_PEER_START), num_peers);
modnum = num_peers / 4;
dotnum = (num_peers / 50) + 1;
@@ -1123,9 +1135,9 @@
#endif
/* Set up a task to end testing if peer start fails */
die_task =
- GNUNET_SCHEDULER_add_delayed (timeout,
- &end_badly,
- "didn't generate all hostkeys within a
reasonable amount of time!!!");
+ GNUNET_SCHEDULER_add_delayed (timeout,
+ &end_badly,
+ "didn't generate all hostkeys within a
reasonable amount of time!!!");
GNUNET_assert (num_peers > 0 && num_peers < (unsigned int) -1);
pg = GNUNET_TESTING_daemons_start (cfg,
@@ -1144,10 +1156,12 @@
{
char *binary_name;
char *config_file_name;
+
GNUNET_asprintf (&binary_name, "test-testing-topology-%s", topology_string);
GNUNET_asprintf (&config_file_name, "test_testing_data_topology_%s.conf",
topology_string);
int ret;
+
char *const argv[] = { binary_name,
"-c",
config_file_name,
@@ -1162,11 +1176,11 @@
ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
argv, binary_name, "nohelp", options, &run, &ok);
if (ret != GNUNET_OK)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "`test-testing-topology-%s': Failed with error code %d\n",
- topology_string, ret);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "`test-testing-topology-%s': Failed with error code %d\n",
+ topology_string, ret);
+ }
GNUNET_free (binary_name);
GNUNET_free (config_file_name);
return ok;
@@ -1206,10 +1220,10 @@
* of by the testing framework.
*/
if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Failed to remove testing directory %s\n", test_directory);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to remove testing directory %s\n", test_directory);
+ }
GNUNET_free (our_binary_name);
return ret;
}
Modified: gnunet/src/testing/test_testing_peergroup.c
===================================================================
--- gnunet/src/testing/test_testing_peergroup.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/testing/test_testing_peergroup.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -46,37 +46,35 @@
shutdown_callback (void *cls, const char *emsg)
{
if (emsg != NULL)
- {
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n");
#endif
- if (ok == 0)
- ok = 666;
- }
+ if (ok == 0)
+ ok = 666;
+ }
else
- {
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "All peers successfully shut down!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers successfully shut
down!\n");
#endif
- ok = 0;
- }
+ ok = 0;
+ }
}
static void
-my_cb (void *cls,
- const char *emsg)
+my_cb (void *cls, const char *emsg)
{
if (emsg != NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peergroup callback called with error, aborting test!\n");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error from testing: `%s'\n");
- ok = 1;
- GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Peergroup callback called with error, aborting test!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error from testing: `%s'\n");
+ ok = 1;
+ GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
+ return;
+ }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Peer Group started successfully, ending test!\n");
@@ -106,22 +104,19 @@
const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
struct GNUNET_CONFIGURATION_Handle *testing_cfg;
+
ok = 1;
- testing_cfg = GNUNET_CONFIGURATION_create();
- GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_load(testing_cfg, cfgfile));
+ testing_cfg = GNUNET_CONFIGURATION_create ();
+ GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (testing_cfg,
cfgfile));
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemons.\n");
GNUNET_CONFIGURATION_set_value_string (testing_cfg, "testing",
- "use_progressbars",
- "YES");
+ "use_progressbars", "YES");
#endif
peers_left = NUM_PEERS;
- pg = GNUNET_TESTING_peergroup_start(testing_cfg,
- peers_left,
- TIMEOUT,
- NULL,
- &my_cb, NULL,
- NULL);
+ pg = GNUNET_TESTING_peergroup_start (testing_cfg,
+ peers_left,
+ TIMEOUT, NULL, &my_cb, NULL, NULL);
GNUNET_assert (pg != NULL);
}
Modified: gnunet/src/testing/test_testing_reconnect.c
===================================================================
--- gnunet/src/testing/test_testing_reconnect.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/testing/test_testing_reconnect.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -54,51 +54,50 @@
* Run the next phase of starting daemons, connecting them and
* stopping them again.
*/
-static void
-run_phase ();
+static void run_phase ();
static void
end2_cb (void *cls, const char *emsg)
{
if (emsg != NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Ending with error: %s\n", emsg);
- ok = 1;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Ending with error: %s\n", emsg);
+ ok = 1;
+ }
else
+ {
+ if (phase < NUM_PHASES)
{
- if (phase < NUM_PHASES)
- {
- fprintf (stderr, ".");
- run_phase();
- return;
- }
- fprintf (stderr, ".\n");
+ fprintf (stderr, ".");
+ run_phase ();
+ return;
+ }
+ fprintf (stderr, ".\n");
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Both daemons terminated, will now exit.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Both daemons terminated, will now exit.\n");
#endif
- ok = 0;
- }
+ ok = 0;
+ }
}
static void
end1_cb (void *cls, const char *emsg)
{
if (emsg != NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Stopping daemon 1 gave: %s\n",
- emsg);
- ok = 1;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Stopping daemon 1 gave: %s\n",
+ emsg);
+ ok = 1;
+ }
else
- {
- ok = 0;
- }
+ {
+ ok = 0;
+ }
GNUNET_TESTING_daemon_stop (d2, TIMEOUT, &end2_cb, NULL,
- (phase == NUM_PHASES) ? GNUNET_YES : GNUNET_NO,
+ (phase == NUM_PHASES) ? GNUNET_YES : GNUNET_NO,
GNUNET_NO);
d2 = NULL;
}
@@ -106,8 +105,8 @@
static void
finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- GNUNET_TESTING_daemon_stop (d1, TIMEOUT, &end1_cb, NULL,
- (phase == NUM_PHASES) ? GNUNET_YES : GNUNET_NO,
+ GNUNET_TESTING_daemon_stop (d1, TIMEOUT, &end1_cb, NULL,
+ (phase == NUM_PHASES) ? GNUNET_YES : GNUNET_NO,
GNUNET_NO);
d1 = NULL;
}
@@ -147,8 +146,7 @@
#endif
GNUNET_TESTING_daemons_connect (d1, d2,
TIMEOUT, CONNECT_ATTEMPTS,
- GNUNET_YES,
- &my_connect_complete, NULL);
+ GNUNET_YES, &my_connect_complete, NULL);
}
@@ -163,9 +161,8 @@
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Daemon `%s' started.\n", GNUNET_i2s (id));
#endif
- d2 =
- GNUNET_TESTING_daemon_start (c2, TIMEOUT, GNUNET_NO, NULL, NULL, 0, NULL,
NULL, NULL,
- &my_cb2, NULL);
+ d2 = GNUNET_TESTING_daemon_start (c2, TIMEOUT, GNUNET_NO, NULL, NULL, 0,
NULL,
+ NULL, NULL, &my_cb2, NULL);
GNUNET_assert (d2 != NULL);
}
@@ -186,13 +183,12 @@
run_phase ();
}
-static void
+static void
run_phase ()
{
phase++;
- d1 =
- GNUNET_TESTING_daemon_start (c1, TIMEOUT, GNUNET_NO, NULL, NULL, 0, NULL,
NULL, NULL,
- &my_cb1, NULL);
+ d1 = GNUNET_TESTING_daemon_start (c1, TIMEOUT, GNUNET_NO, NULL, NULL, 0,
NULL,
+ NULL, NULL, &my_cb1, NULL);
GNUNET_assert (d1 != NULL);
}
Modified: gnunet/src/testing/test_testing_topology.c
===================================================================
--- gnunet/src/testing/test_testing_topology.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/testing/test_testing_topology.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -107,7 +107,7 @@
static enum GNUNET_TESTING_Topology connection_topology =
GNUNET_TESTING_TOPOLOGY_NONE; /* NONE actually means connect all allowed peers
*/
static enum GNUNET_TESTING_TopologyOption connect_topology_option =
- GNUNET_TESTING_TOPOLOGY_OPTION_ALL;
+ GNUNET_TESTING_TOPOLOGY_OPTION_ALL;
static double connect_topology_option_modifier = 0.0;
@@ -168,20 +168,19 @@
shutdown_callback (void *cls, const char *emsg)
{
if (emsg != NULL)
- {
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n");
#endif
- if (ok == 0)
- ok = 666;
- }
+ if (ok == 0)
+ ok = 666;
+ }
else
- {
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "All peers successfully shut down!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers successfully shut
down!\n");
#endif
- }
+ }
}
#if DELAY_FOR_LOGGING
@@ -191,6 +190,7 @@
char *peer_number;
char *connect_number;
struct GNUNET_OS_Process *mem_process;
+
GNUNET_asprintf (&peer_number, "%llu", num_peers);
GNUNET_asprintf (&connect_number, "%llu", expected_connections);
mem_process = GNUNET_OS_start_process (NULL, NULL, "./memsize.pl",
@@ -209,6 +209,7 @@
GNUNET_assert (pg != NULL);
struct TestMessageContext *pos;
struct TestMessageContext *free_pos;
+
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Called finish testing, stopping daemons.\n");
@@ -216,25 +217,25 @@
pos = test_messages;
while (pos != NULL)
+ {
+ if (pos->peer1handle != NULL)
{
- if (pos->peer1handle != NULL)
- {
- GNUNET_CORE_disconnect (pos->peer1handle);
- pos->peer1handle = NULL;
- }
- if (pos->peer2handle != NULL)
- {
- GNUNET_CORE_disconnect (pos->peer2handle);
- pos->peer2handle = NULL;
- }
- free_pos = pos;
- pos = pos->next;
- if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (free_pos->disconnect_task);
- }
- GNUNET_free (free_pos);
+ GNUNET_CORE_disconnect (pos->peer1handle);
+ pos->peer1handle = NULL;
}
+ if (pos->peer2handle != NULL)
+ {
+ GNUNET_CORE_disconnect (pos->peer2handle);
+ pos->peer2handle = NULL;
+ }
+ free_pos = pos;
+ pos = pos->next;
+ if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (free_pos->disconnect_task);
+ }
+ GNUNET_free (free_pos);
+ }
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Transmit_ready's scheduled %d, failed %d, transmit_ready's
called %d\n",
@@ -248,10 +249,10 @@
GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
if (dotOutFile != NULL)
- {
- fprintf (dotOutFile, "}");
- fclose (dotOutFile);
- }
+ {
+ fprintf (dotOutFile, "}");
+ fclose (dotOutFile);
+ }
ok = 0;
}
@@ -321,31 +322,31 @@
const struct GNUNET_PeerIdentity *second, const char *emsg)
{
FILE *outfile = cls;
+
if (first != NULL)
+ {
+ if (outfile != NULL)
{
- if (outfile != NULL)
- {
- fprintf (outfile, "\t\"%s\" -- ", GNUNET_i2s (first));
- fprintf (outfile, "\"%s\";\n", GNUNET_i2s (second));
- }
- topology_connections++;
+ fprintf (outfile, "\t\"%s\" -- ", GNUNET_i2s (first));
+ fprintf (outfile, "\"%s\";\n", GNUNET_i2s (second));
}
+ topology_connections++;
+ }
else
+ {
+ fprintf (stderr,
+ "Finished iterating over topology, %d total connections!\n",
+ topology_connections);
+ if (outfile != NULL)
{
- fprintf (stderr,
- "Finished iterating over topology, %d total connections!\n",
- topology_connections);
- if (outfile != NULL)
- {
- fprintf (outfile, "}\n");
- fclose (outfile);
+ fprintf (outfile, "}\n");
+ fclose (outfile);
#if DO_STATS
- GNUNET_TESTING_get_statistics (pg, &stats_finished, &stats_print,
- NULL);
+ GNUNET_TESTING_get_statistics (pg, &stats_finished, &stats_print, NULL);
#endif
- GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
- }
+ GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
}
+ }
}
static int
@@ -358,24 +359,25 @@
FILE *dotOutFileFinished;
struct TestMessageContext *pos = cls;
struct GNUNET_TestMessage *msg = (struct GNUNET_TestMessage *) message;
+
if (pos->uid != ntohl (msg->uid))
return GNUNET_OK;
#if PROGRESS_BARS
if ((total_messages_received) % modnum == 0)
- {
- if (total_messages_received == 0)
- fprintf (stdout, "0%%");
- else
- fprintf (stdout, "%d%%",
- (int) (((float) total_messages_received /
- expected_messages) * 100));
+ {
+ if (total_messages_received == 0)
+ fprintf (stdout, "0%%");
+ else
+ fprintf (stdout, "%d%%",
+ (int) (((float) total_messages_received /
+ expected_messages) * 100));
- }
+ }
else if (total_messages_received % dotnum == 0)
- {
- fprintf (stdout, ".");
- }
+ {
+ fprintf (stdout, ".");
+ }
fflush (stdout);
#endif
@@ -391,27 +393,26 @@
#endif
if (total_messages_received == expected_messages)
- {
+ {
#if PROGRESS_BARS
- fprintf (stdout, "100%%]\n");
+ fprintf (stdout, "100%%]\n");
#endif
- GNUNET_SCHEDULER_cancel (die_task);
- GNUNET_asprintf (&dotOutFileNameFinished, "%s.dot", "final_topology");
- dotOutFileFinished = fopen (dotOutFileNameFinished, "w");
- GNUNET_free (dotOutFileNameFinished);
- if (dotOutFileFinished != NULL)
- {
- fprintf (dotOutFileFinished, "strict graph G {\n");
- }
- topology_connections = 0;
- GNUNET_TESTING_get_topology (pg, &topology_cb, dotOutFileFinished);
- //GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
+ GNUNET_SCHEDULER_cancel (die_task);
+ GNUNET_asprintf (&dotOutFileNameFinished, "%s.dot", "final_topology");
+ dotOutFileFinished = fopen (dotOutFileNameFinished, "w");
+ GNUNET_free (dotOutFileNameFinished);
+ if (dotOutFileFinished != NULL)
+ {
+ fprintf (dotOutFileFinished, "strict graph G {\n");
}
+ topology_connections = 0;
+ GNUNET_TESTING_get_topology (pg, &topology_cb, dotOutFileFinished);
+ //GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
+ }
else
- {
- pos->disconnect_task =
- GNUNET_SCHEDULER_add_now (&disconnect_cores, pos);
- }
+ {
+ pos->disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cores, pos);
+ }
return GNUNET_OK;
}
@@ -420,6 +421,7 @@
end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
char *msg = cls;
+
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"End badly was called (%s)... stopping daemons.\n", msg);
struct TestMessageContext *pos;
@@ -427,21 +429,21 @@
pos = test_messages;
while (pos != NULL)
+ {
+ if (pos->peer1handle != NULL)
{
- if (pos->peer1handle != NULL)
- {
- GNUNET_CORE_disconnect (pos->peer1handle);
- pos->peer1handle = NULL;
- }
- if (pos->peer2handle != NULL)
- {
- GNUNET_CORE_disconnect (pos->peer2handle);
- pos->peer2handle = NULL;
- }
- free_pos = pos;
- pos = pos->next;
- GNUNET_free (free_pos);
+ GNUNET_CORE_disconnect (pos->peer1handle);
+ pos->peer1handle = NULL;
}
+ if (pos->peer2handle != NULL)
+ {
+ GNUNET_CORE_disconnect (pos->peer2handle);
+ pos->peer2handle = NULL;
+ }
+ free_pos = pos;
+ pos = pos->next;
+ GNUNET_free (free_pos);
+ }
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -454,18 +456,18 @@
#endif
if (pg != NULL)
- {
- GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
- ok = 7331; /* Opposite of leet */
- }
+ {
+ GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
+ ok = 7331; /* Opposite of leet */
+ }
else
ok = 401; /* Never got peers started */
if (dotOutFile != NULL)
- {
- fprintf (dotOutFile, "}");
- fclose (dotOutFile);
- }
+ {
+ fprintf (dotOutFile, "}");
+ fclose (dotOutFile);
+ }
}
static size_t
@@ -512,31 +514,32 @@
pos->peer2connected = GNUNET_YES;
if (pos->peer1notified == GNUNET_YES) /* Peer 1 has been notified of
connection to peer 2 */
+ {
+#if VERBOSE > 1
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Scheduling message send to peer `%s' from peer `%s'
(init_notify_peer2)\n",
+ GNUNET_i2s (my_identity),
+ GNUNET_h2s (&pos->peer1->id.hashPubKey));
+#endif
+ if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle,
+ GNUNET_YES,
+ 0,
+ TIMEOUT,
+ &pos->peer2->id,
+ sizeof (struct
+ GNUNET_TestMessage),
+ &transmit_ready, pos))
{
-#if VERBOSE > 1
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Scheduling message send to peer `%s' from peer `%s'
(init_notify_peer2)\n",
- GNUNET_i2s (my_identity),
GNUNET_h2s(&pos->peer1->id.hashPubKey));
-#endif
- if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle,
- GNUNET_YES,
- 0,
- TIMEOUT,
- &pos->peer2->id,
- sizeof (struct
-
GNUNET_TestMessage),
- &transmit_ready, pos))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "RECEIVED NULL when asking core (1) for transmission to
peer `%4s'\n",
- GNUNET_i2s (&pos->peer2->id));
- transmit_ready_failed++;
- }
- else
- {
- transmit_ready_scheduled++;
- }
+ "RECEIVED NULL when asking core (1) for transmission to peer
`%4s'\n",
+ GNUNET_i2s (&pos->peer2->id));
+ transmit_ready_failed++;
}
+ else
+ {
+ transmit_ready_scheduled++;
+ }
+ }
}
/**
@@ -546,51 +549,53 @@
* @param peer peer identity this notification is about
* @param atsi performance data for the connection
*/
-static void connect_notify_peers (void *cls,
- const struct
- GNUNET_PeerIdentity *peer,
- const struct
GNUNET_TRANSPORT_ATS_Information *atsi)
+static void
+connect_notify_peers (void *cls,
+ const struct
+ GNUNET_PeerIdentity *peer,
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
struct TestMessageContext *pos = cls;
- if (0 == memcmp(peer, &pos->peer2->id, sizeof(struct GNUNET_PeerIdentity)))
- {
- pos->peer1notified = GNUNET_YES;
+ if (0 == memcmp (peer, &pos->peer2->id, sizeof (struct GNUNET_PeerIdentity)))
+ {
+ pos->peer1notified = GNUNET_YES;
#if VERBOSE > 1
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Peer `%s' notified of connection to peer `%s'\n",
- GNUNET_i2s (&pos->peer1->id), GNUNET_h2s(&peer->hashPubKey));
+ GNUNET_i2s (&pos->peer1->id), GNUNET_h2s (&peer->hashPubKey));
#endif
- }
+ }
else
return;
- if (pos->peer2connected == GNUNET_YES) /* Already connected and notified of
connection, send message! */
- {
+ if (pos->peer2connected == GNUNET_YES) /* Already connected and
notified of connection, send message! */
+ {
#if VERBOSE > 1
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Scheduling message send to peer `%s' from peer `%s'
(init_notify_peer2)\n",
- GNUNET_i2s (&pos->peer2->id),
GNUNET_h2s(&pos->peer1->id.hashPubKey));
+ GNUNET_i2s (&pos->peer2->id),
+ GNUNET_h2s (&pos->peer1->id.hashPubKey));
#endif
- if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle,
- GNUNET_YES,
- 0,
- TIMEOUT,
- &pos->peer2->id,
- sizeof (struct
-
GNUNET_TestMessage),
- &transmit_ready, pos))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "RECEIVED NULL when asking core (1) for transmission to
peer `%4s'\n",
- GNUNET_i2s (&pos->peer2->id));
- transmit_ready_failed++;
- }
- else
- {
- transmit_ready_scheduled++;
- }
+ if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle,
+ GNUNET_YES,
+ 0,
+ TIMEOUT,
+ &pos->peer2->id,
+ sizeof (struct
+ GNUNET_TestMessage),
+ &transmit_ready, pos))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "RECEIVED NULL when asking core (1) for transmission to peer
`%4s'\n",
+ GNUNET_i2s (&pos->peer2->id));
+ transmit_ready_failed++;
}
+ else
+ {
+ transmit_ready_scheduled++;
+ }
+ }
}
static void
@@ -601,6 +606,7 @@
*publicKey)
{
struct TestMessageContext *pos = cls;
+
total_server_connections++;
#if VERBOSE > 1
@@ -631,27 +637,27 @@
struct TestMessageContext *pos = cls;
if ((pos == test_messages) && (settle_time.rel_value > 0))
- {
- topology_connections = 0;
- GNUNET_TESTING_get_topology (pg, &topology_cb, NULL);
- }
- if (( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)|| (cls == NULL))
+ {
+ topology_connections = 0;
+ GNUNET_TESTING_get_topology (pg, &topology_cb, NULL);
+ }
+ if (((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) || (cls == NULL))
return;
if (die_task == GNUNET_SCHEDULER_NO_TASK)
- {
- die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT,
- &end_badly,
- "from send test messages
(timeout)");
- }
+ {
+ die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT,
+ &end_badly,
+ "from send test messages
(timeout)");
+ }
if (total_server_connections >= MAX_OUTSTANDING_CONNECTIONS)
- {
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS, 1),
- &send_test_messages, pos);
- return; /* Otherwise we'll double schedule messages
here! */
- }
+ {
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 1),
+ &send_test_messages, pos);
+ return; /* Otherwise we'll double schedule messages
here! */
+ }
/*
* Connect to the sending peer
@@ -669,15 +675,15 @@
GNUNET_assert (pos->peer1handle != NULL);
if (total_server_connections < MAX_OUTSTANDING_CONNECTIONS)
- {
- GNUNET_SCHEDULER_add_now (&send_test_messages, pos->next);
- }
+ {
+ GNUNET_SCHEDULER_add_now (&send_test_messages, pos->next);
+ }
else
- {
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS, 1),
- &send_test_messages, pos->next);
- }
+ {
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 1),
+ &send_test_messages, pos->next);
+ }
}
@@ -693,117 +699,118 @@
const char *emsg)
{
struct TestMessageContext *temp_context;
+
if (emsg == NULL)
+ {
+#if PROGRESS_BARS
+ if ((total_connections) % modnum == 0)
{
-#if PROGRESS_BARS
- if ((total_connections) % modnum == 0)
- {
- if (total_connections == 0)
- fprintf (stdout, "0%%");
- else
- fprintf (stdout, "%d%%",
- (int) (((float) total_connections /
- expected_connections) * 100));
+ if (total_connections == 0)
+ fprintf (stdout, "0%%");
+ else
+ fprintf (stdout, "%d%%",
+ (int) (((float) total_connections /
+ expected_connections) * 100));
- }
- else if (total_connections % dotnum == 0)
- {
- fprintf (stdout, ".");
- }
- fflush (stdout);
+ }
+ else if (total_connections % dotnum == 0)
+ {
+ fprintf (stdout, ".");
+ }
+ fflush (stdout);
#endif
- total_connections++;
+ total_connections++;
#if VERBOSE > 1
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "connected peer %s to peer %s\n",
- first_daemon->shortname, second_daemon->shortname);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "connected peer %s to peer %s\n",
+ first_daemon->shortname, second_daemon->shortname);
#endif
- temp_context = GNUNET_malloc (sizeof (struct TestMessageContext));
- temp_context->peer1 = first_daemon;
- temp_context->peer2 = second_daemon;
- temp_context->next = test_messages;
- temp_context->uid = total_connections;
- temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
- test_messages = temp_context;
+ temp_context = GNUNET_malloc (sizeof (struct TestMessageContext));
+ temp_context->peer1 = first_daemon;
+ temp_context->peer2 = second_daemon;
+ temp_context->next = test_messages;
+ temp_context->uid = total_connections;
+ temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
+ test_messages = temp_context;
- expected_messages++;
- if (dotOutFile != NULL)
- fprintf (dotOutFile, "\tn%s -- n%s;\n", first_daemon->shortname,
- second_daemon->shortname);
- }
+ expected_messages++;
+ if (dotOutFile != NULL)
+ fprintf (dotOutFile, "\tn%s -- n%s;\n", first_daemon->shortname,
+ second_daemon->shortname);
+ }
#if VERBOSE
else
- {
- failed_connections++;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Failed to connect peer %s to peer %s with error :\n%s\n",
- first_daemon->shortname, second_daemon->shortname, emsg);
- }
+ {
+ failed_connections++;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to connect peer %s to peer %s with error :\n%s\n",
+ first_daemon->shortname, second_daemon->shortname, emsg);
+ }
#endif
if (total_connections == expected_connections)
- {
+ {
#if PROGRESS_BARS
- fprintf (stdout, "100%%]\n");
+ fprintf (stdout, "100%%]\n");
#endif
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Created %d total connections, which is our target number!
Calling send messages.\n",
- total_connections);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Created %d total connections, which is our target number!
Calling send messages.\n",
+ total_connections);
#endif
- modnum = expected_messages / 4;
- dotnum = (expected_messages / 50) + 1;
- if (modnum == 0)
- modnum = 1;
- if (dotnum == 0)
- dotnum = 1;
- GNUNET_SCHEDULER_cancel (die_task);
- die_task = GNUNET_SCHEDULER_NO_TASK;
+ modnum = expected_messages / 4;
+ dotnum = (expected_messages / 50) + 1;
+ if (modnum == 0)
+ modnum = 1;
+ if (dotnum == 0)
+ dotnum = 1;
+ GNUNET_SCHEDULER_cancel (die_task);
+ die_task = GNUNET_SCHEDULER_NO_TASK;
#if DELAY_FOR_LOGGING
- fprintf (stdout, "Sending test messages in 10 seconds.\n");
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS, 10),
- &send_test_messages, test_messages);
- gather_log_data ();
+ fprintf (stdout, "Sending test messages in 10 seconds.\n");
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 10),
+ &send_test_messages, test_messages);
+ gather_log_data ();
#else
- if (settle_time.rel_value > 0)
- {
- GNUNET_TESTING_get_topology (pg, &topology_cb, NULL);
- }
- GNUNET_SCHEDULER_add_delayed (settle_time, &send_test_messages,
- test_messages);
+ if (settle_time.rel_value > 0)
+ {
+ GNUNET_TESTING_get_topology (pg, &topology_cb, NULL);
+ }
+ GNUNET_SCHEDULER_add_delayed (settle_time, &send_test_messages,
+ test_messages);
#endif
#if PROGRESS_BARS
- fprintf (stdout, "Test message progress: [");
+ fprintf (stdout, "Test message progress: [");
#endif
- }
+ }
else if (total_connections + failed_connections == expected_connections)
+ {
+ if (failed_connections <
+ (unsigned int) (fail_percentage * total_connections))
{
- if (failed_connections <
- (unsigned int) (fail_percentage * total_connections))
- {
- GNUNET_SCHEDULER_cancel (die_task);
- die_task = GNUNET_SCHEDULER_NO_TASK;
- GNUNET_SCHEDULER_add_now (&send_test_messages, test_messages);
- }
- else
- {
- GNUNET_SCHEDULER_cancel (die_task);
- die_task =
- GNUNET_SCHEDULER_add_now (&end_badly,
- "from topology_callback (too many failed
connections)");
- }
+ GNUNET_SCHEDULER_cancel (die_task);
+ die_task = GNUNET_SCHEDULER_NO_TASK;
+ GNUNET_SCHEDULER_add_now (&send_test_messages, test_messages);
}
+ else
+ {
+ GNUNET_SCHEDULER_cancel (die_task);
+ die_task =
+ GNUNET_SCHEDULER_add_now (&end_badly,
+ "from topology_callback (too many failed
connections)");
+ }
+ }
else
- {
+ {
#if VERBOSE > 1
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Have %d total connections, %d failed connections, Want %d
(at least %d)\n",
- total_connections, failed_connections, expected_connections,
- expected_connections -
- (unsigned int) (fail_percentage * expected_connections));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Have %d total connections, %d failed connections, Want %d (at
least %d)\n",
+ total_connections, failed_connections, expected_connections,
+ expected_connections -
+ (unsigned int) (fail_percentage * expected_connections));
#endif
- }
+ }
}
static void
@@ -821,8 +828,8 @@
{
expected_connections = -1;
if ((pg != NULL) && (peers_left == 0))
- {
- expected_connections =
+ {
+ expected_connections =
GNUNET_TESTING_connect_topology (pg, connection_topology,
connect_topology_option,
connect_topology_option_modifier,
@@ -830,19 +837,19 @@
connect_attempts,
&topology_creation_finished, NULL);
#if PROGRESS_BARS
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Have %d expected connections\n", expected_connections);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Have %d expected connections\n", expected_connections);
#endif
- }
+ }
GNUNET_SCHEDULER_cancel (die_task);
if (expected_connections < 1)
- {
- die_task =
+ {
+ die_task =
GNUNET_SCHEDULER_add_now (&end_badly,
"from connect topology (bad return)");
- return;
- }
+ return;
+ }
die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_SECONDS,
@@ -865,23 +872,22 @@
{
peers_left = num_peers; /* Reset counter */
if (GNUNET_TESTING_create_topology
- (pg, topology, blacklist_topology,
- blacklist_transports) != GNUNET_SYSERR)
- {
+ (pg, topology, blacklist_topology, blacklist_transports) !=
GNUNET_SYSERR)
+ {
#if PROGRESS_BARS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Topology set up, now starting peers!\n");
- fprintf (stdout, "Daemon start progress [");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Topology set up, now starting peers!\n");
+ fprintf (stdout, "Daemon start progress [");
#endif
- GNUNET_TESTING_daemons_continue_startup (pg);
- }
+ GNUNET_TESTING_daemons_continue_startup (pg);
+ }
else
- {
- GNUNET_SCHEDULER_cancel (die_task);
- die_task =
+ {
+ GNUNET_SCHEDULER_cancel (die_task);
+ die_task =
GNUNET_SCHEDULER_add_now (&end_badly,
"from create topology (bad return)");
- }
+ }
GNUNET_SCHEDULER_cancel (die_task);
die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_SECONDS,
@@ -898,11 +904,11 @@
struct GNUNET_TESTING_Daemon *d, const char *emsg)
{
if (emsg != NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Failed to start daemon with error: `%s'\n", emsg);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to start daemon with error: `%s'\n", emsg);
+ return;
+ }
GNUNET_assert (id != NULL);
#if VERBOSE > 1
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n",
@@ -910,50 +916,48 @@
#endif
#if PROGRESS_BARS
if ((num_peers - peers_left) % modnum == 0)
- {
- if (num_peers - peers_left == 0)
- fprintf (stdout, "0%%");
- else
- fprintf (stdout, "%d%%",
- (int) (((float) (num_peers - peers_left) /
- num_peers) * 100));
+ {
+ if (num_peers - peers_left == 0)
+ fprintf (stdout, "0%%");
+ else
+ fprintf (stdout, "%d%%",
+ (int) (((float) (num_peers - peers_left) / num_peers) * 100));
- }
+ }
else if ((num_peers - peers_left) % dotnum == 0)
- {
- fprintf (stdout, ".");
- }
+ {
+ fprintf (stdout, ".");
+ }
fflush (stdout);
#endif
peers_left--;
if (peers_left == 0)
- {
+ {
#if PROGRESS_BARS
- fprintf (stdout, "100%%]\n");
+ fprintf (stdout, "100%%]\n");
#endif
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "All %d daemons started, now connecting peers!\n",
- num_peers);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "All %d daemons started, now connecting peers!\n", num_peers);
#endif
- GNUNET_SCHEDULER_cancel (die_task);
- /* Set up task in case topology creation doesn't finish
- * within a reasonable amount of time */
- die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_MINUTES, 8),
- &end_badly,
- "from peers_started_callback");
+ GNUNET_SCHEDULER_cancel (die_task);
+ /* Set up task in case topology creation doesn't finish
+ * within a reasonable amount of time */
+ die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MINUTES, 8),
+ &end_badly,
+ "from peers_started_callback");
#if DELAY_FOR_LOGGING
- fprintf (stdout, "Connecting topology in 10 seconds\n");
- gather_log_data ();
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS, 10),
- &connect_topology, NULL);
+ fprintf (stdout, "Connecting topology in 10 seconds\n");
+ gather_log_data ();
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 10),
+ &connect_topology, NULL);
#else
- connect_topology ();
+ connect_topology ();
#endif
- ok = 0;
- }
+ ok = 0;
+ }
}
/**
@@ -970,10 +974,10 @@
struct GNUNET_TESTING_Daemon *d, const char *emsg)
{
if (emsg != NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Hostkey callback received error: %s\n", emsg);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Hostkey callback received error: %s\n", emsg);
+ }
#if VERBOSE > 1
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -983,39 +987,37 @@
#if PROGRESS_BARS
if ((num_peers - peers_left) % modnum == 0)
- {
- if (num_peers - peers_left == 0)
- fprintf (stdout, "0%%");
- else
- fprintf (stdout, "%d%%",
- (int) (((float) (num_peers - peers_left) /
- num_peers) * 100));
+ {
+ if (num_peers - peers_left == 0)
+ fprintf (stdout, "0%%");
+ else
+ fprintf (stdout, "%d%%",
+ (int) (((float) (num_peers - peers_left) / num_peers) * 100));
- }
+ }
else if ((num_peers - peers_left) % dotnum == 0)
- {
- fprintf (stdout, ".");
- }
+ {
+ fprintf (stdout, ".");
+ }
fflush (stdout);
#endif
peers_left--;
if (peers_left == 0)
- {
+ {
#if PROGRESS_BARS
- fprintf (stdout, "100%%]\n");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "All %d hostkeys created, now creating topology!\n",
- num_peers);
+ fprintf (stdout, "100%%]\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "All %d hostkeys created, now creating topology!\n",
num_peers);
#endif
- GNUNET_SCHEDULER_cancel (die_task);
- /* Set up task in case topology creation doesn't finish
- * within a reasonable amount of time */
- die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &end_badly,
- "from create_topology");
- GNUNET_SCHEDULER_add_now (&create_topology, NULL);
- ok = 0;
- }
+ GNUNET_SCHEDULER_cancel (die_task);
+ /* Set up task in case topology creation doesn't finish
+ * within a reasonable amount of time */
+ die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+ &end_badly,
+ "from create_topology");
+ GNUNET_SCHEDULER_add_now (&create_topology, NULL);
+ ok = 0;
+ }
}
static void
@@ -1030,13 +1032,14 @@
char *connect_topology_option_modifier_string;
unsigned long long temp_settle;
unsigned long long max_outstanding_connections;
+
ok = 1;
dotOutFile = fopen (dotOutFileName, "w");
if (dotOutFile != NULL)
- {
- fprintf (dotOutFile, "strict graph G {\n");
- }
+ {
+ fprintf (dotOutFile, "strict graph G {\n");
+ }
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1046,21 +1049,21 @@
if (GNUNET_YES !=
GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome",
&test_directory))
- {
- ok = 404;
- return;
- }
+ {
+ ok = 404;
+ return;
+ }
if ((GNUNET_YES ==
GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "topology",
&topology_str))
&& (GNUNET_NO == GNUNET_TESTING_topology_get (&topology, topology_str)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Invalid topology `%s' given for section %s option %s\n",
- topology_str, "TESTING", "TOPOLOGY");
- topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE,
so set better default here */
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Invalid topology `%s' given for section %s option %s\n",
+ topology_str, "TESTING", "TOPOLOGY");
+ topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set
better default here */
+ }
if ((GNUNET_YES ==
GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
@@ -1069,11 +1072,11 @@
&& (GNUNET_NO ==
GNUNET_TESTING_topology_get (&connection_topology,
connect_topology_str)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Invalid connect topology `%s' given for section %s option
%s\n",
- connect_topology_str, "TESTING", "CONNECT_TOPOLOGY");
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Invalid connect topology `%s' given for section %s option
%s\n",
+ connect_topology_str, "TESTING", "CONNECT_TOPOLOGY");
+ }
GNUNET_free_non_null (connect_topology_str);
if ((GNUNET_YES ==
GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
@@ -1082,31 +1085,31 @@
&& (GNUNET_NO ==
GNUNET_TESTING_topology_option_get (&connect_topology_option,
connect_topology_option_str)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Invalid connect topology option `%s' given for section %s
option %s\n",
- connect_topology_option_str, "TESTING",
- "CONNECT_TOPOLOGY_OPTION");
- connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /*
Defaults to NONE, set to ALL */
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Invalid connect topology option `%s' given for section %s
option %s\n",
+ connect_topology_option_str, "TESTING",
+ "CONNECT_TOPOLOGY_OPTION");
+ connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /*
Defaults to NONE, set to ALL */
+ }
GNUNET_free_non_null (connect_topology_option_str);
if (GNUNET_YES ==
GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
"connect_topology_option_modifier",
&connect_topology_option_modifier_string))
+ {
+ if (sscanf
+ (connect_topology_option_modifier_string, "%lf",
+ &connect_topology_option_modifier) != 1)
{
- if (sscanf
- (connect_topology_option_modifier_string, "%lf",
- &connect_topology_option_modifier) != 1)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _
- ("Invalid value `%s' for option `%s' in section `%s':
expected float\n"),
- connect_topology_option_modifier_string,
- "connect_topology_option_modifier", "TESTING");
- }
- GNUNET_free (connect_topology_option_modifier_string);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Invalid value `%s' for option `%s' in section `%s':
expected float\n"),
+ connect_topology_option_modifier_string,
+ "connect_topology_option_modifier", "TESTING");
}
+ GNUNET_free (connect_topology_option_modifier_string);
+ }
if (GNUNET_YES !=
GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
@@ -1121,11 +1124,11 @@
&& (GNUNET_NO ==
GNUNET_TESTING_topology_get (&blacklist_topology,
blacklist_topology_str)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Invalid topology `%s' given for section %s option %s\n",
- topology_str, "TESTING", "BLACKLIST_TOPOLOGY");
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Invalid topology `%s' given for section %s option %s\n",
+ topology_str, "TESTING", "BLACKLIST_TOPOLOGY");
+ }
GNUNET_free_non_null (topology_str);
GNUNET_free_non_null (blacklist_topology_str);
@@ -1133,35 +1136,39 @@
GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "settle_time",
&temp_settle))
settle_time =
- GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_settle);
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_settle);
if (GNUNET_OK ==
GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "connect_timeout",
&temp_settle))
connect_timeout =
- GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_settle);
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_settle);
else
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
"testing", "connect_timeout");
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
+ "testing", "connect_timeout");
+ return;
+ }
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (cfg, "testing",
"connect_attempts",
- &connect_attempts))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
"testing", "connect_attempts");
- return;
- }
+ GNUNET_CONFIGURATION_get_value_number (cfg, "testing",
"connect_attempts",
+ &connect_attempts))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
+ "testing", "connect_attempts");
+ return;
+ }
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (cfg, "testing",
"max_outstanding_connections",
- &max_outstanding_connections))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
"testing", "max_outstanding_connections");
- return;
- }
+ GNUNET_CONFIGURATION_get_value_number (cfg, "testing",
+ "max_outstanding_connections",
+ &max_outstanding_connections))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
+ "testing", "max_outstanding_connections");
+ return;
+ }
if (GNUNET_SYSERR ==
GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers",
@@ -1182,11 +1189,11 @@
#endif
/* Set up a task to end testing if peer start fails */
die_task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS,
- SECONDS_PER_PEER_START * num_peers),
- &end_badly,
- "didn't generate all hostkeys within a
reasonable amount of time!!!");
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS,
+ SECONDS_PER_PEER_START * num_peers),
+ &end_badly,
+ "didn't generate all hostkeys within a
reasonable amount of time!!!");
GNUNET_assert (num_peers > 0 && num_peers < (unsigned int) -1);
pg = GNUNET_TESTING_daemons_start (cfg,
@@ -1207,10 +1214,12 @@
{
char *binary_name;
char *config_file_name;
+
GNUNET_asprintf (&binary_name, "test-testing-topology-%s", topology_string);
GNUNET_asprintf (&config_file_name, "test_testing_data_topology_%s.conf",
topology_string);
int ret;
+
char *const argv[] = { binary_name,
"-c",
config_file_name,
@@ -1225,11 +1234,11 @@
ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
argv, binary_name, "nohelp", options, &run, &ok);
if (ret != GNUNET_OK)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "`test-testing-topology-%s': Failed with error code %d\n",
- topology_string, ret);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "`test-testing-topology-%s': Failed with error code %d\n",
+ topology_string, ret);
+ }
GNUNET_free (binary_name);
GNUNET_free (config_file_name);
return ok;
@@ -1273,10 +1282,10 @@
* of by the testing framework.
*/
if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Failed to remove testing directory %s\n", test_directory);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to remove testing directory %s\n", test_directory);
+ }
GNUNET_free (our_binary_name);
return ret;
}
Modified: gnunet/src/testing/test_testing_topology_blacklist.c
===================================================================
--- gnunet/src/testing/test_testing_topology_blacklist.c 2011-08-15
21:40:08 UTC (rev 16580)
+++ gnunet/src/testing/test_testing_topology_blacklist.c 2011-08-15
21:46:35 UTC (rev 16581)
@@ -106,20 +106,19 @@
shutdown_callback (void *cls, const char *emsg)
{
if (emsg != NULL)
- {
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n");
#endif
- if (ok == 0)
- ok = 666;
- }
+ if (ok == 0)
+ ok = 666;
+ }
else
- {
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "All peers successfully shut down!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers successfully shut
down!\n");
#endif
- }
+ }
}
static void
@@ -140,10 +139,10 @@
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "daemons_stop finished\n");
#endif
if (dotOutFile != NULL)
- {
- fprintf (dotOutFile, "}");
- fclose (dotOutFile);
- }
+ {
+ fprintf (dotOutFile, "}");
+ fclose (dotOutFile);
+ }
ok = 0;
}
@@ -152,22 +151,23 @@
end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
char *msg = cls;
+
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"End badly was called (%s)... stopping daemons.\n", msg);
if (pg != NULL)
- {
- GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
- ok = 7331; /* Opposite of leet */
- }
+ {
+ GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
+ ok = 7331; /* Opposite of leet */
+ }
else
ok = 401; /* Never got peers started */
if (dotOutFile != NULL)
- {
- fprintf (dotOutFile, "}");
- fclose (dotOutFile);
- }
+ {
+ fprintf (dotOutFile, "}");
+ fclose (dotOutFile);
+ }
}
@@ -184,70 +184,70 @@
const char *emsg)
{
if (emsg == NULL)
- {
- total_connections++;
+ {
+ total_connections++;
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s\n",
- first_daemon->shortname, second_daemon->shortname);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s\n",
+ first_daemon->shortname, second_daemon->shortname);
#endif
- if (dotOutFile != NULL)
- fprintf (dotOutFile, "\tn%s -- n%s;\n", first_daemon->shortname,
- second_daemon->shortname);
- }
+ if (dotOutFile != NULL)
+ fprintf (dotOutFile, "\tn%s -- n%s;\n", first_daemon->shortname,
+ second_daemon->shortname);
+ }
else
- {
- failed_connections++;
+ {
+ failed_connections++;
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Failed to connect peer %s to peer %s with error :\n%s\n",
- first_daemon->shortname, second_daemon->shortname, emsg);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to connect peer %s to peer %s with error :\n%s\n",
+ first_daemon->shortname, second_daemon->shortname, emsg);
#endif
- }
+ }
if (total_connections == expected_connections)
- {
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Created %d total connections, which is our target number
(that's bad)!\n",
- total_connections);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Created %d total connections, which is our target number
(that's bad)!\n",
+ total_connections);
#endif
- GNUNET_SCHEDULER_cancel (die_task);
- die_task = GNUNET_SCHEDULER_NO_TASK;
- die_task =
+ GNUNET_SCHEDULER_cancel (die_task);
+ die_task = GNUNET_SCHEDULER_NO_TASK;
+ die_task =
GNUNET_SCHEDULER_add_now (&end_badly,
"from topology_callback (too many successful
connections)");
- }
+ }
else if (total_connections + failed_connections == expected_connections)
+ {
+ if ((failed_connections == expected_failed_connections)
+ && (total_connections ==
+ expected_connections - expected_failed_connections))
{
- if ((failed_connections == expected_failed_connections)
- && (total_connections ==
- expected_connections - expected_failed_connections))
- {
- GNUNET_SCHEDULER_cancel (die_task);
- die_task = GNUNET_SCHEDULER_NO_TASK;
- die_task = GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
- }
- else
- {
- GNUNET_SCHEDULER_cancel (die_task);
- die_task =
- GNUNET_SCHEDULER_add_now (&end_badly,
- "from topology_callback (wrong number of
failed connections)");
- }
+ GNUNET_SCHEDULER_cancel (die_task);
+ die_task = GNUNET_SCHEDULER_NO_TASK;
+ die_task = GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
}
- else
+ else
{
+ GNUNET_SCHEDULER_cancel (die_task);
+ die_task =
+ GNUNET_SCHEDULER_add_now (&end_badly,
+ "from topology_callback (wrong number of
failed connections)");
+ }
+ }
+ else
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Have %d total connections, %d failed connections, Want %d
(failed) and %d (successful)\n",
- total_connections, failed_connections,
- expected_failed_connections,
- expected_connections - expected_failed_connections);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Have %d total connections, %d failed connections, Want %d
(failed) and %d (successful)\n",
+ total_connections, failed_connections,
+ expected_failed_connections,
+ expected_connections - expected_failed_connections);
#endif
- }
+ }
}
static void
@@ -255,27 +255,26 @@
{
expected_connections = -1;
if ((pg != NULL) && (peers_left == 0))
- {
- expected_connections =
+ {
+ expected_connections =
GNUNET_TESTING_connect_topology (pg, connection_topology,
connect_topology_option,
connect_topology_option_modifier,
connect_timeout,
- connect_attempts,
- NULL, NULL);
+ connect_attempts, NULL, NULL);
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Have %d expected connections\n", expected_connections);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Have %d expected connections\n", expected_connections);
#endif
- }
+ }
GNUNET_SCHEDULER_cancel (die_task);
if (expected_connections == GNUNET_SYSERR)
- {
- die_task =
+ {
+ die_task =
GNUNET_SCHEDULER_add_now (&end_badly,
"from connect topology (bad return)");
- }
+ }
die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT,
&end_badly,
@@ -287,22 +286,21 @@
{
peers_left = num_peers; /* Reset counter */
if (GNUNET_TESTING_create_topology
- (pg, topology, blacklist_topology,
- blacklist_transports) != GNUNET_SYSERR)
- {
+ (pg, topology, blacklist_topology, blacklist_transports) !=
GNUNET_SYSERR)
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Topology set up, now starting peers!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Topology set up, now starting peers!\n");
#endif
- GNUNET_TESTING_daemons_continue_startup (pg);
- }
+ GNUNET_TESTING_daemons_continue_startup (pg);
+ }
else
- {
- GNUNET_SCHEDULER_cancel (die_task);
- die_task =
+ {
+ GNUNET_SCHEDULER_cancel (die_task);
+ die_task =
GNUNET_SCHEDULER_add_now (&end_badly,
"from create topology (bad return)");
- }
+ }
GNUNET_SCHEDULER_cancel (die_task);
die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT,
&end_badly,
@@ -317,11 +315,11 @@
struct GNUNET_TESTING_Daemon *d, const char *emsg)
{
if (emsg != NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Failed to start daemon with error: `%s'\n", emsg);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to start daemon with error: `%s'\n", emsg);
+ return;
+ }
GNUNET_assert (id != NULL);
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n",
@@ -329,22 +327,21 @@
#endif
peers_left--;
if (peers_left == 0)
- {
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "All %d daemons started, now creating topology!\n",
- num_peers);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "All %d daemons started, now creating topology!\n", num_peers);
#endif
- GNUNET_SCHEDULER_cancel (die_task);
- /* Set up task in case topology creation doesn't finish
- * within a reasonable amount of time */
- die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_MINUTES, 5),
- &end_badly,
- "from peers_started_callback");
- connect_topology ();
- ok = 0;
- }
+ GNUNET_SCHEDULER_cancel (die_task);
+ /* Set up task in case topology creation doesn't finish
+ * within a reasonable amount of time */
+ die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MINUTES, 5),
+ &end_badly,
+ "from peers_started_callback");
+ connect_topology ();
+ ok = 0;
+ }
}
/**
@@ -361,10 +358,10 @@
struct GNUNET_TESTING_Daemon *d, const char *emsg)
{
if (emsg != NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Hostkey callback received error: %s\n", emsg);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Hostkey callback received error: %s\n", emsg);
+ }
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -372,22 +369,21 @@
#endif
peers_left--;
if (peers_left == 0)
- {
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "All %d hostkeys created, now creating topology!\n",
- num_peers);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "All %d hostkeys created, now creating topology!\n",
num_peers);
#endif
- GNUNET_SCHEDULER_cancel (die_task);
- /* Set up task in case topology creation doesn't finish
- * within a reasonable amount of time */
- die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_MINUTES, 5),
- &end_badly,
- "from hostkey_callback");
- GNUNET_SCHEDULER_add_now (&create_topology, NULL);
- ok = 0;
- }
+ GNUNET_SCHEDULER_cancel (die_task);
+ /* Set up task in case topology creation doesn't finish
+ * within a reasonable amount of time */
+ die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MINUTES, 5),
+ &end_badly,
+ "from hostkey_callback");
+ GNUNET_SCHEDULER_add_now (&create_topology, NULL);
+ ok = 0;
+ }
}
static void
@@ -401,13 +397,14 @@
unsigned long long connect_topology_option_num;
unsigned long long temp_connect;
char *connect_topology_option_modifier_string;
+
ok = 1;
dotOutFile = fopen (dotOutFileName, "w");
if (dotOutFile != NULL)
- {
- fprintf (dotOutFile, "strict graph G {\n");
- }
+ {
+ fprintf (dotOutFile, "strict graph G {\n");
+ }
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -417,14 +414,14 @@
if (GNUNET_YES !=
GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome",
&test_directory))
+ {
+ ok = 404;
+ if (dotOutFile != NULL)
{
- ok = 404;
- if (dotOutFile != NULL)
- {
- fclose (dotOutFile);
- }
- return;
+ fclose (dotOutFile);
}
+ return;
+ }
if (GNUNET_YES ==
GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "topology",
@@ -447,41 +444,41 @@
GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
"connect_topology_option_modifier",
&connect_topology_option_modifier_string))
+ {
+ if (sscanf
+ (connect_topology_option_modifier_string, "%lf",
+ &connect_topology_option_modifier) != 1)
{
- if (sscanf
- (connect_topology_option_modifier_string, "%lf",
- &connect_topology_option_modifier) != 1)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _
- ("Invalid value `%s' for option `%s' in section `%s':
expected float\n"),
- connect_topology_option_modifier_string,
- "connect_topology_option_modifier", "TESTING");
- GNUNET_free (connect_topology_option_modifier_string);
- ok = 707;
- if (dotOutFile != NULL)
- {
- fclose (dotOutFile);
- }
- return;
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Invalid value `%s' for option `%s' in section `%s':
expected float\n"),
+ connect_topology_option_modifier_string,
+ "connect_topology_option_modifier", "TESTING");
GNUNET_free (connect_topology_option_modifier_string);
+ ok = 707;
+ if (dotOutFile != NULL)
+ {
+ fclose (dotOutFile);
+ }
+ return;
}
+ GNUNET_free (connect_topology_option_modifier_string);
+ }
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
"blacklist_transports",
&blacklist_transports))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "No transports specified for blacklisting in blacklist
testcase (this shouldn't happen!)\n");
+ ok = 808;
+ if (dotOutFile != NULL)
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "No transports specified for blacklisting in blacklist
testcase (this shouldn't happen!)\n");
- ok = 808;
- if (dotOutFile != NULL)
- {
- fclose (dotOutFile);
- }
- return;
+ fclose (dotOutFile);
}
+ return;
+ }
if (GNUNET_YES ==
GNUNET_CONFIGURATION_get_value_number (cfg, "testing",
@@ -498,21 +495,23 @@
GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "connect_timeout",
&temp_connect))
connect_timeout =
- GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_connect);
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_connect);
else
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
"testing", "connect_timeout");
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
+ "testing", "connect_timeout");
+ return;
+ }
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (cfg, "testing",
"connect_attempts",
- &connect_attempts))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
"testing", "connect_attempts");
- return;
- }
+ GNUNET_CONFIGURATION_get_value_number (cfg, "testing",
"connect_attempts",
+ &connect_attempts))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
+ "testing", "connect_attempts");
+ return;
+ }
main_cfg = cfg;
@@ -546,6 +545,7 @@
check ()
{
int ret;
+
char *const argv[] = { "test-testing-topology-blacklist",
"-c",
"test_testing_data_topology_blacklist.conf",
@@ -561,11 +561,11 @@
argv, "test-testing-topology-blacklist", "nohelp",
options, &run, &ok);
if (ret != GNUNET_OK)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "`test-testing-topology-blacklist': Failed with error code
%d\n",
- ret);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "`test-testing-topology-blacklist': Failed with error code
%d\n",
+ ret);
+ }
return ok;
}
@@ -589,14 +589,13 @@
* of by the testing framework.
*/
if (test_directory != NULL)
+ {
+ if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
{
- if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Failed to remove testing directory %s\n",
- test_directory);
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to remove testing directory %s\n", test_directory);
}
+ }
return ret;
}
Modified: gnunet/src/testing/test_testing_topology_churn.c
===================================================================
--- gnunet/src/testing/test_testing_topology_churn.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/testing/test_testing_topology_churn.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -79,20 +79,19 @@
shutdown_callback (void *cls, const char *emsg)
{
if (emsg != NULL)
- {
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n");
#endif
- if (ok == 0)
- ok = 666;
- }
+ if (ok == 0)
+ ok = 666;
+ }
else
- {
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "All peers successfully shut down!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers successfully shut
down!\n");
#endif
- }
+ }
}
static void
@@ -123,14 +122,15 @@
end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
char *msg = cls;
+
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"End badly was called (%s)... stopping daemons.\n", msg);
if (pg != NULL)
- {
- GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
- ok = 7331; /* Opposite of leet */
- }
+ {
+ GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
+ ok = 7331; /* Opposite of leet */
+ }
else
ok = 401; /* Never got peers started */
@@ -154,18 +154,18 @@
churn_callback (void *cls, const char *emsg)
{
if (emsg == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Successfully churned peers!\n",
- emsg);
- GNUNET_SCHEDULER_add_now (churn_ctx.next_task, NULL);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Successfully churned peers!\n",
+ emsg);
+ GNUNET_SCHEDULER_add_now (churn_ctx.next_task, NULL);
+ }
else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Failed to churn peers with error `%s'\n", emsg);
- GNUNET_SCHEDULER_cancel (die_task);
- die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to churn peers with error `%s'\n", emsg);
+ GNUNET_SCHEDULER_cancel (die_task);
+ die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
+ }
}
@@ -204,11 +204,11 @@
struct GNUNET_TESTING_Daemon *d, const char *emsg)
{
if (emsg != NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Failed to start daemon with error: `%s'\n", emsg);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to start daemon with error: `%s'\n", emsg);
+ return;
+ }
GNUNET_assert (id != NULL);
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n",
@@ -216,21 +216,21 @@
#endif
peers_left--;
if (peers_left == 0)
- {
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "All %d daemons started, now testing churn!\n", num_peers);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "All %d daemons started, now testing churn!\n", num_peers);
#endif
- GNUNET_SCHEDULER_cancel (die_task);
- /* Set up task in case topology creation doesn't finish
- * within a reasonable amount of time */
- die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_MINUTES, 5),
- &end_badly,
- "from peers_started_callback");
- churn_peers_off ();
- ok = 0;
- }
+ GNUNET_SCHEDULER_cancel (die_task);
+ /* Set up task in case topology creation doesn't finish
+ * within a reasonable amount of time */
+ die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MINUTES, 5),
+ &end_badly,
+ "from peers_started_callback");
+ churn_peers_off ();
+ ok = 0;
+ }
}
@@ -249,10 +249,10 @@
if (GNUNET_YES !=
GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome",
&test_directory))
- {
- ok = 404;
- return;
- }
+ {
+ ok = 404;
+ return;
+ }
if (GNUNET_SYSERR ==
GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers",
@@ -293,6 +293,7 @@
check ()
{
int ret;
+
char *const argv[] = { "test-testing-topology-churn",
"-c",
"test_testing_data_topology_churn.conf",
@@ -308,11 +309,11 @@
argv, "test-testing-topology-churn", "nohelp",
options, &run, &ok);
if (ret != GNUNET_OK)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "`test-testing-topology-churn': Failed with error code %d\n",
- ret);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "`test-testing-topology-churn': Failed with error code %d\n",
+ ret);
+ }
return ok;
}
@@ -336,14 +337,13 @@
* of by the testing framework.
*/
if (test_directory != NULL)
+ {
+ if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
{
- if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Failed to remove testing directory %s\n",
- test_directory);
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to remove testing directory %s\n", test_directory);
}
+ }
return ret;
}
Modified: gnunet/src/testing/testing.c
===================================================================
--- gnunet/src/testing/testing.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/testing/testing.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -67,13 +67,13 @@
#if EMPTY_HACK
static int
-test_address (void *cls,
- const char *tname,
- struct GNUNET_TIME_Absolute expiration,
- const void *addr,
- uint16_t addrlen)
+test_address (void *cls,
+ const char *tname,
+ struct GNUNET_TIME_Absolute expiration,
+ const void *addr, uint16_t addrlen)
{
int *empty = cls;
+
*empty = GNUNET_NO;
return GNUNET_OK;
}
@@ -87,11 +87,11 @@
* @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)
{
struct GNUNET_TESTING_Daemon *daemon = cls;
int msize;
+
#if WAIT_FOR_HELLO
GNUNET_TESTING_NotifyDaemonRunning cb;
#endif
@@ -100,50 +100,48 @@
empty = GNUNET_YES;
GNUNET_assert (message != NULL);
- GNUNET_HELLO_iterate_addresses ((const struct GNUNET_HELLO_Message*) message,
- GNUNET_NO,
- &test_address,
- &empty);
+ GNUNET_HELLO_iterate_addresses ((const struct GNUNET_HELLO_Message *)
message,
+ GNUNET_NO, &test_address, &empty);
if (GNUNET_YES == empty)
- {
+ {
#if DEBUG_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Skipping empty HELLO address\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Skipping empty HELLO address\n");
#endif
- return;
- }
+ return;
+ }
#endif
if (daemon == NULL)
return;
- GNUNET_assert (daemon->phase == SP_GET_HELLO || daemon->phase ==
SP_START_DONE);
+ GNUNET_assert (daemon->phase == SP_GET_HELLO ||
+ daemon->phase == SP_START_DONE);
#if WAIT_FOR_HELLO
cb = daemon->cb;
#endif
daemon->cb = NULL;
if (daemon->task != GNUNET_SCHEDULER_NO_TASK) /* Assertion here instead? */
- GNUNET_SCHEDULER_cancel(daemon->task);
+ GNUNET_SCHEDULER_cancel (daemon->task);
if (daemon->server != NULL)
- {
+ {
#if DEBUG_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received `%s' from transport service of `%4s',
disconnecting core!\n",
- "HELLO", GNUNET_i2s (&daemon->id));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received `%s' from transport service of `%4s', disconnecting
core!\n",
+ "HELLO", GNUNET_i2s (&daemon->id));
#endif
- GNUNET_CORE_disconnect (daemon->server);
- daemon->server = NULL;
- }
+ GNUNET_CORE_disconnect (daemon->server);
+ daemon->server = NULL;
+ }
msize = ntohs (message->size);
if (msize < 1)
- {
- return;
- }
+ {
+ return;
+ }
if (daemon->th != NULL)
- {
- GNUNET_TRANSPORT_get_hello_cancel (daemon->th, &process_hello, daemon);
- }
+ {
+ GNUNET_TRANSPORT_get_hello_cancel (daemon->th, &process_hello, daemon);
+ }
#if DEBUG_TESTING
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received `%s' from transport service of `%4s'\n",
@@ -155,18 +153,15 @@
memcpy (daemon->hello, message, msize);
if (daemon->th != NULL)
- {
- GNUNET_TRANSPORT_disconnect (daemon->th);
- daemon->th = NULL;
- }
+ {
+ GNUNET_TRANSPORT_disconnect (daemon->th);
+ daemon->th = NULL;
+ }
daemon->phase = SP_START_DONE;
#if WAIT_FOR_HELLO
- if (NULL != cb) /* FIXME: what happens when this callback calls
GNUNET_TESTING_daemon_stop? */
- cb (daemon->cb_cls,
- &daemon->id,
- daemon->cfg,
- daemon, NULL);
+ if (NULL != cb) /* FIXME: what happens when this callback
calls GNUNET_TESTING_daemon_stop? */
+ cb (daemon->cb_cls, &daemon->id, daemon->cfg, daemon, NULL);
#endif
}
@@ -198,36 +193,36 @@
d->phase = SP_GET_HELLO;
if (server == NULL)
- {
- d->server = NULL;
- if (GNUNET_YES == d->dead)
- GNUNET_TESTING_daemon_stop (d,
- GNUNET_TIME_absolute_get_remaining
- (d->max_timeout), d->dead_cb,
- d->dead_cb_cls, GNUNET_YES, GNUNET_NO);
- else if (NULL != d->cb)
- d->cb (d->cb_cls, NULL, d->cfg, d,
- _("Failed to connect to core service\n"));
- return;
- }
+ {
+ d->server = NULL;
+ if (GNUNET_YES == d->dead)
+ GNUNET_TESTING_daemon_stop (d,
+ GNUNET_TIME_absolute_get_remaining
+ (d->max_timeout), d->dead_cb,
+ d->dead_cb_cls, GNUNET_YES, GNUNET_NO);
+ else if (NULL != d->cb)
+ d->cb (d->cb_cls, NULL, d->cfg, d,
+ _("Failed to connect to core service\n"));
+ return;
+ }
#if DEBUG_TESTING
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Successfully started peer `%4s'.\n", GNUNET_i2s (my_identity));
#endif
- d->id = *my_identity; /* FIXME: shouldn't we already have this from reading
the hostkey file? */
+ d->id = *my_identity; /* FIXME: shouldn't we already have this from
reading the hostkey file? */
if (d->shortname == NULL)
d->shortname = strdup (GNUNET_i2s (my_identity));
d->server = server;
d->running = GNUNET_YES;
if (GNUNET_NO == d->running)
- {
+ {
#if DEBUG_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peer is dead (d->running == GNUNET_NO)\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Peer is dead (d->running == GNUNET_NO)\n");
#endif
- return;
- }
+ return;
+ }
#if DEBUG_TESTING
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Successfully started peer `%4s', connecting to transport
service.\n",
@@ -236,17 +231,17 @@
d->th = GNUNET_TRANSPORT_connect (d->cfg, &d->id, d, NULL, NULL, NULL);
if (d->th == NULL)
- {
- if (GNUNET_YES == d->dead)
- GNUNET_TESTING_daemon_stop (d,
- GNUNET_TIME_absolute_get_remaining
- (d->max_timeout), d->dead_cb,
- d->dead_cb_cls, GNUNET_YES, GNUNET_NO);
- else if (NULL != d->cb)
- d->cb (d->cb_cls, &d->id, d->cfg, d,
- _("Failed to connect to transport service!\n"));
- return;
- }
+ {
+ if (GNUNET_YES == d->dead)
+ GNUNET_TESTING_daemon_stop (d,
+ GNUNET_TIME_absolute_get_remaining
+ (d->max_timeout), d->dead_cb,
+ d->dead_cb_cls, GNUNET_YES, GNUNET_NO);
+ else if (NULL != d->cb)
+ d->cb (d->cb_cls, &d->id, d->cfg, d,
+ _("Failed to connect to transport service!\n"));
+ return;
+ }
#if DEBUG_TESTING
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Connected to transport service `%s', getting HELLO\n",
@@ -256,10 +251,10 @@
GNUNET_TRANSPORT_get_hello (d->th, &process_hello, d);
/* wait some more */
if (d->task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel(d->task);
+ GNUNET_SCHEDULER_cancel (d->task);
d->task
- = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT,
- &start_fsm, d);
+ = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT,
+ &start_fsm, d);
}
#endif
@@ -273,8 +268,7 @@
* @param tc task scheduler context
*/
static void
-notify_daemon_started (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+notify_daemon_started (void *cls, const struct GNUNET_SCHEDULER_TaskContext
*tc)
{
struct GNUNET_TESTING_Daemon *d = cls;
GNUNET_TESTING_NotifyDaemonRunning cb;
@@ -303,711 +297,697 @@
int bytes_read;
#if DEBUG_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peer FSM is in phase %u.\n", d->phase);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer FSM is in phase %u.\n", d->phase);
#endif
d->task = GNUNET_SCHEDULER_NO_TASK;
switch (d->phase)
+ {
+ case SP_COPYING:
+ /* confirm copying complete */
+ if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code))
{
- case SP_COPYING:
- /* confirm copying complete */
- if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code))
+ if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == 0)
+ {
+ cb = d->cb;
+ d->cb = NULL;
+ if (NULL != cb)
+ cb (d->cb_cls,
+ NULL,
+ d->cfg, d,
+ _
+ ("`scp' does not seem to terminate (timeout copying
config).\n"));
+ return;
+ }
+ /* wait some more */
+ d->task
+ = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT,
+ &start_fsm, d);
+ return;
+ }
+ if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0))
+ {
+ cb = d->cb;
+ d->cb = NULL;
+ if (NULL != cb)
+ cb (d->cb_cls, NULL, d->cfg, d, _("`scp' did not complete
cleanly.\n"));
+ return;
+ }
+ GNUNET_OS_process_close (d->proc);
+#if DEBUG_TESTING
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Successfully copied configuration file.\n");
+#endif
+ d->phase = SP_COPIED;
+ /* fall-through */
+ case SP_COPIED:
+ /* Start create hostkey process if we don't already know the peer
identity! */
+ if (GNUNET_NO == d->have_hostkey)
+ {
+ d->pipe_stdout = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_YES);
+ if (d->pipe_stdout == NULL)
+ {
+ cb = d->cb;
+ d->cb = NULL;
+ if (NULL != cb)
+ cb (d->cb_cls,
+ NULL,
+ d->cfg,
+ d,
+ (NULL == d->hostname)
+ ? _("Failed to create pipe for `gnunet-peerinfo' process.\n")
+ : _("Failed to create pipe for `ssh' process.\n"));
+ return;
+ }
+ if (NULL == d->hostname)
+ {
+#if DEBUG_TESTING
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Starting `%s', with command `%s %s %s %s'.\n",
+ "gnunet-peerinfo", "gnunet-peerinfo", "-c", d->cfgfile,
+ "-sq");
+#endif
+ d->proc =
+ GNUNET_OS_start_process (NULL, d->pipe_stdout, "gnunet-peerinfo",
+ "gnunet-peerinfo", "-c", d->cfgfile,
+ "-sq", NULL);
+ GNUNET_DISK_pipe_close_end (d->pipe_stdout,
GNUNET_DISK_PIPE_END_WRITE);
+ }
+ else
+ {
+ if (d->username != NULL)
+ GNUNET_asprintf (&dst, "address@hidden", d->username, d->hostname);
+ else
+ dst = GNUNET_strdup (d->hostname);
+
+#if DEBUG_TESTING
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Starting `%s', with command `%s %s %s %s %s %s'.\n",
+ "gnunet-peerinfo", "ssh", dst, "gnunet-peerinfo", "-c",
+ d->cfgfile, "-sq");
+#endif
+ if (d->ssh_port_str == NULL)
{
- if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value ==
- 0)
- {
- cb = d->cb;
- d->cb = NULL;
- if (NULL != cb)
- cb (d->cb_cls,
- NULL,
- d->cfg, d,
- _
- ("`scp' does not seem to terminate (timeout copying
config).\n"));
- return;
- }
- /* wait some more */
- d->task
- = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT,
- &start_fsm, d);
- return;
+ d->proc = GNUNET_OS_start_process (NULL, d->pipe_stdout, "ssh",
"ssh",
+#if !DEBUG_TESTING
+ "-q",
+#endif
+ dst,
+ "gnunet-peerinfo",
+ "-c", d->cfgfile, "-sq", NULL);
}
- if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0))
+ else
{
- cb = d->cb;
- d->cb = NULL;
- if (NULL != cb)
- cb (d->cb_cls,
- NULL, d->cfg, d, _("`scp' did not complete cleanly.\n"));
- return;
+ d->proc = GNUNET_OS_start_process (NULL, d->pipe_stdout, "ssh",
+ "ssh", "-p", d->ssh_port_str,
+#if !DEBUG_TESTING
+ "-q",
+#endif
+ dst,
+ "gnunet-peerinfo",
+ "-c", d->cfgfile, "-sq", NULL);
}
- GNUNET_OS_process_close(d->proc);
+ GNUNET_DISK_pipe_close_end (d->pipe_stdout,
GNUNET_DISK_PIPE_END_WRITE);
+ GNUNET_free (dst);
+ }
+ if (NULL == d->proc)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Could not start `%s' process to create hostkey.\n"),
+ (NULL == d->hostname) ? "gnunet-peerinfo" : "ssh");
+ cb = d->cb;
+ d->cb = NULL;
+ if (NULL != cb)
+ cb (d->cb_cls,
+ NULL,
+ d->cfg,
+ d,
+ (NULL == d->hostname)
+ ? _("Failed to start `gnunet-peerinfo' process.\n")
+ : _("Failed to start `ssh' process.\n"));
+ GNUNET_DISK_pipe_close (d->pipe_stdout);
+ return;
+ }
#if DEBUG_TESTING
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Successfully copied configuration file.\n");
+ "Started `%s', waiting for hostkey.\n", "gnunet-peerinfo");
#endif
- d->phase = SP_COPIED;
- /* fall-through */
- case SP_COPIED:
- /* Start create hostkey process if we don't already know the peer
identity!*/
- if (GNUNET_NO == d->have_hostkey)
- {
- d->pipe_stdout = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_YES);
- if (d->pipe_stdout == NULL)
- {
- cb = d->cb;
- d->cb = NULL;
- if (NULL != cb)
- cb (d->cb_cls,
- NULL,
- d->cfg,
- d,
- (NULL == d->hostname)
- ? _("Failed to create pipe for `gnunet-peerinfo'
process.\n")
- : _("Failed to create pipe for `ssh' process.\n"));
- return;
- }
- if (NULL == d->hostname)
- {
- #if DEBUG_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Starting `%s', with command `%s %s %s %s'.\n",
- "gnunet-peerinfo", "gnunet-peerinfo", "-c",
d->cfgfile,
- "-sq");
- #endif
- d->proc =
- GNUNET_OS_start_process (NULL, d->pipe_stdout,
"gnunet-peerinfo",
- "gnunet-peerinfo", "-c", d->cfgfile,
- "-sq", NULL);
- GNUNET_DISK_pipe_close_end (d->pipe_stdout,
- GNUNET_DISK_PIPE_END_WRITE);
- }
- else
- {
- if (d->username != NULL)
- GNUNET_asprintf (&dst, "address@hidden", d->username,
d->hostname);
- else
- dst = GNUNET_strdup (d->hostname);
+ d->phase = SP_HOSTKEY_CREATE;
+ d->task
+ =
+ GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_absolute_get_remaining
+ (d->max_timeout),
+ GNUNET_DISK_pipe_handle
+ (d->pipe_stdout,
+ GNUNET_DISK_PIPE_END_READ),
+ &start_fsm, d);
+ }
+ else /* Already have a hostkey! */
+ {
+ if (d->hostkey_callback != NULL)
+ {
+ d->hostkey_callback (d->hostkey_cls, &d->id, d, NULL);
+ d->hostkey_callback = NULL;
+ d->phase = SP_HOSTKEY_CREATED;
+ }
+ else
+ d->phase = SP_TOPOLOGY_SETUP;
- #if DEBUG_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Starting `%s', with command `%s %s %s %s %s %s'.\n",
- "gnunet-peerinfo", "ssh", dst, "gnunet-peerinfo",
"-c",
- d->cfgfile, "-sq");
- #endif
- if (d->ssh_port_str == NULL)
- {
- d->proc = GNUNET_OS_start_process (NULL, d->pipe_stdout,
"ssh",
- "ssh",
- #if !DEBUG_TESTING
- "-q",
- #endif
- dst,
- "gnunet-peerinfo",
- "-c", d->cfgfile, "-sq",
- NULL);
- }
- else
- {
- d->proc = GNUNET_OS_start_process (NULL, d->pipe_stdout,
"ssh",
- "ssh", "-p",
d->ssh_port_str,
- #if !DEBUG_TESTING
- "-q",
- #endif
- dst,
- "gnunet-peerinfo",
- "-c", d->cfgfile, "-sq",
- NULL);
- }
- GNUNET_DISK_pipe_close_end (d->pipe_stdout,
- GNUNET_DISK_PIPE_END_WRITE);
- GNUNET_free (dst);
- }
- if (NULL == d->proc)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Could not start `%s' process to create
hostkey.\n"),
- (NULL == d->hostname) ? "gnunet-peerinfo" : "ssh");
- cb = d->cb;
- d->cb = NULL;
- if (NULL != cb)
- cb (d->cb_cls,
- NULL,
- d->cfg,
- d,
- (NULL == d->hostname)
- ? _("Failed to start `gnunet-peerinfo' process.\n")
- : _("Failed to start `ssh' process.\n"));
- GNUNET_DISK_pipe_close (d->pipe_stdout);
- return;
- }
- #if DEBUG_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Started `%s', waiting for hostkey.\n",
"gnunet-peerinfo");
- #endif
- d->phase = SP_HOSTKEY_CREATE;
- d->task
- =
- GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_absolute_get_remaining
- (d->max_timeout),
- GNUNET_DISK_pipe_handle
- (d->pipe_stdout,
- GNUNET_DISK_PIPE_END_READ),
- &start_fsm, d);
- }
- else /* Already have a hostkey! */
- {
- if (d->hostkey_callback != NULL)
- {
- d->hostkey_callback (d->hostkey_cls, &d->id, d, NULL);
- d->hostkey_callback = NULL;
- d->phase = SP_HOSTKEY_CREATED;
- }
- else
- d->phase = SP_TOPOLOGY_SETUP;
-
- /* wait some more */
- d->task
- = GNUNET_SCHEDULER_add_now (&start_fsm, d);
- }
- break;
- case SP_HOSTKEY_CREATE:
- bytes_read =
+ /* wait some more */
+ d->task = GNUNET_SCHEDULER_add_now (&start_fsm, d);
+ }
+ break;
+ case SP_HOSTKEY_CREATE:
+ bytes_read =
GNUNET_DISK_file_read (GNUNET_DISK_pipe_handle
(d->pipe_stdout, GNUNET_DISK_PIPE_END_READ),
&d->hostkeybuf[d->hostkeybufpos],
sizeof (d->hostkeybuf) - d->hostkeybufpos);
- if (bytes_read > 0)
- d->hostkeybufpos += bytes_read;
+ if (bytes_read > 0)
+ d->hostkeybufpos += bytes_read;
- if ((d->hostkeybufpos < 104) && (bytes_read > 0))
- {
- /* keep reading */
- d->task
- =
- GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_absolute_get_remaining
- (d->max_timeout),
- GNUNET_DISK_pipe_handle
- (d->pipe_stdout,
- GNUNET_DISK_PIPE_END_READ),
- &start_fsm, d);
- return;
- }
- d->hostkeybuf[103] = '\0';
+ if ((d->hostkeybufpos < 104) && (bytes_read > 0))
+ {
+ /* keep reading */
+ d->task
+ =
+ GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_absolute_get_remaining
+ (d->max_timeout),
+ GNUNET_DISK_pipe_handle
+ (d->pipe_stdout,
+ GNUNET_DISK_PIPE_END_READ),
+ &start_fsm, d);
+ return;
+ }
+ d->hostkeybuf[103] = '\0';
- if ((bytes_read < 0) ||
- (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (d->hostkeybuf,
- &d->id.hashPubKey)))
- {
- /* error */
- if (bytes_read < 0)
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Error reading from gnunet-peerinfo: %s\n"),
- STRERROR (errno));
- else
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Malformed output from gnunet-peerinfo!\n"));
- cb = d->cb;
- d->cb = NULL;
- GNUNET_DISK_pipe_close (d->pipe_stdout);
- d->pipe_stdout = NULL;
- (void) GNUNET_OS_process_kill (d->proc, SIGKILL);
- GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (d->proc));
- GNUNET_OS_process_close (d->proc);
- d->proc = NULL;
- if (NULL != cb)
- cb (d->cb_cls, NULL, d->cfg, d, _("`Failed to get hostkey!\n"));
- return;
- }
- d->shortname = GNUNET_strdup(GNUNET_i2s(&d->id));
+ if ((bytes_read < 0) ||
+ (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (d->hostkeybuf,
+ &d->id.hashPubKey)))
+ {
+ /* error */
+ if (bytes_read < 0)
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Error reading from gnunet-peerinfo: %s\n"),
+ STRERROR (errno));
+ else
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Malformed output from gnunet-peerinfo!\n"));
+ cb = d->cb;
+ d->cb = NULL;
GNUNET_DISK_pipe_close (d->pipe_stdout);
d->pipe_stdout = NULL;
(void) GNUNET_OS_process_kill (d->proc, SIGKILL);
GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (d->proc));
GNUNET_OS_process_close (d->proc);
d->proc = NULL;
- d->have_hostkey = GNUNET_YES;
- if (d->hostkey_callback != NULL)
- {
- d->hostkey_callback (d->hostkey_cls, &d->id, d, NULL);
- d->hostkey_callback = NULL;
- d->phase = SP_HOSTKEY_CREATED;
- }
- else
- {
- d->phase = SP_TOPOLOGY_SETUP;
- }
+ if (NULL != cb)
+ cb (d->cb_cls, NULL, d->cfg, d, _("`Failed to get hostkey!\n"));
+ return;
+ }
+ d->shortname = GNUNET_strdup (GNUNET_i2s (&d->id));
+ GNUNET_DISK_pipe_close (d->pipe_stdout);
+ d->pipe_stdout = NULL;
+ (void) GNUNET_OS_process_kill (d->proc, SIGKILL);
+ GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (d->proc));
+ GNUNET_OS_process_close (d->proc);
+ d->proc = NULL;
+ d->have_hostkey = GNUNET_YES;
+ if (d->hostkey_callback != NULL)
+ {
+ d->hostkey_callback (d->hostkey_cls, &d->id, d, NULL);
+ d->hostkey_callback = NULL;
+ d->phase = SP_HOSTKEY_CREATED;
+ }
+ else
+ {
+ d->phase = SP_TOPOLOGY_SETUP;
+ }
#if DEBUG_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully got hostkey!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully got hostkey!\n");
#endif
- /* Fall through */
- case SP_HOSTKEY_CREATED:
- /* wait for topology finished */
- if ((GNUNET_YES == d->dead)
- || (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value ==
- 0))
- {
- cb = d->cb;
- d->cb = NULL;
- if (NULL != cb)
- cb (d->cb_cls,
- NULL,
- d->cfg, d, _("`Failed while waiting for topology setup!\n"));
- return;
- }
+ /* Fall through */
+ case SP_HOSTKEY_CREATED:
+ /* wait for topology finished */
+ if ((GNUNET_YES == d->dead)
+ || (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value ==
0))
+ {
+ cb = d->cb;
+ d->cb = NULL;
+ if (NULL != cb)
+ cb (d->cb_cls,
+ NULL, d->cfg, d, _("`Failed while waiting for topology setup!\n"));
+ return;
+ }
- d->task
+ d->task
= GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT,
&start_fsm, d);
- break;
- case SP_TOPOLOGY_SETUP: /* Indicates topology setup has completed! */
- /* start GNUnet on remote host */
- if (NULL == d->hostname)
- {
+ break;
+ case SP_TOPOLOGY_SETUP: /* Indicates topology setup has completed! */
+ /* start GNUnet on remote host */
+ if (NULL == d->hostname)
+ {
#if DEBUG_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Starting `%s', with command `%s %s %s %s %s %s'.\n",
- "gnunet-arm", "gnunet-arm", "-c", d->cfgfile,
- "-L", "DEBUG", "-s");
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Starting `%s', with command `%s %s %s %s %s %s'.\n",
+ "gnunet-arm", "gnunet-arm", "-c", d->cfgfile,
+ "-L", "DEBUG", "-s");
#endif
- d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm",
- "gnunet-arm", "-c", d->cfgfile,
+ d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm",
+ "gnunet-arm", "-c", d->cfgfile,
#if DEBUG_TESTING
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-s", "-q", "-T",
GNUNET_TIME_relative_to_string(GNUNET_TIME_absolute_get_remaining(d->max_timeout)),
NULL);
- }
+ "-s", "-q", "-T",
+ GNUNET_TIME_relative_to_string
+ (GNUNET_TIME_absolute_get_remaining
+ (d->max_timeout)), NULL);
+ }
+ else
+ {
+ if (d->username != NULL)
+ GNUNET_asprintf (&dst, "address@hidden", d->username, d->hostname);
else
- {
- if (d->username != NULL)
- GNUNET_asprintf (&dst, "address@hidden", d->username, d->hostname);
- else
- dst = GNUNET_strdup (d->hostname);
+ dst = GNUNET_strdup (d->hostname);
#if DEBUG_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Starting `%s', with command `%s %s %s %s %s %s %s
%s'.\n",
- "gnunet-arm", "ssh", dst, "gnunet-arm", "-c",
- d->cfgfile, "-L", "DEBUG", "-s", "-q");
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Starting `%s', with command `%s %s %s %s %s %s %s %s'.\n",
+ "gnunet-arm", "ssh", dst, "gnunet-arm", "-c",
+ d->cfgfile, "-L", "DEBUG", "-s", "-q");
#endif
- if (d->ssh_port_str == NULL)
- {
- d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh",
+ if (d->ssh_port_str == NULL)
+ {
+ d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh",
#if !DEBUG_TESTING
- "-q",
+ "-q",
#endif
- dst, "gnunet-arm",
+ dst, "gnunet-arm",
#if DEBUG_TESTING
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", d->cfgfile, "-s", "-q",
- "-T",
GNUNET_TIME_relative_to_string(GNUNET_TIME_absolute_get_remaining(d->max_timeout)),
- NULL);
- }
- else
- {
+ "-c", d->cfgfile, "-s", "-q",
+ "-T",
+ GNUNET_TIME_relative_to_string
+ (GNUNET_TIME_absolute_get_remaining
+ (d->max_timeout)), NULL);
+ }
+ else
+ {
- d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh",
- "ssh", "-p", d->ssh_port_str,
+ d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh",
+ "ssh", "-p", d->ssh_port_str,
#if !DEBUG_TESTING
- "-q",
+ "-q",
#endif
- dst, "gnunet-arm",
+ dst, "gnunet-arm",
#if DEBUG_TESTING
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", d->cfgfile, "-s", "-q",
- "-T",
GNUNET_TIME_relative_to_string(GNUNET_TIME_absolute_get_remaining(d->max_timeout)),
- NULL);
- }
- GNUNET_free (dst);
- }
- if (NULL == d->proc)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Could not start `%s' process to start GNUnet.\n"),
- (NULL == d->hostname) ? "gnunet-arm" : "ssh");
- cb = d->cb;
- d->cb = NULL;
- if (NULL != cb)
- cb (d->cb_cls,
- NULL,
- d->cfg,
- d,
- (NULL == d->hostname)
- ? _("Failed to start `gnunet-arm' process.\n")
- : _("Failed to start `ssh' process.\n"));
- return;
- }
+ "-c", d->cfgfile, "-s", "-q",
+ "-T",
+ GNUNET_TIME_relative_to_string
+ (GNUNET_TIME_absolute_get_remaining
+ (d->max_timeout)), NULL);
+ }
+ GNUNET_free (dst);
+ }
+ if (NULL == d->proc)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Could not start `%s' process to start GNUnet.\n"),
+ (NULL == d->hostname) ? "gnunet-arm" : "ssh");
+ cb = d->cb;
+ d->cb = NULL;
+ if (NULL != cb)
+ cb (d->cb_cls,
+ NULL,
+ d->cfg,
+ d,
+ (NULL == d->hostname)
+ ? _("Failed to start `gnunet-arm' process.\n")
+ : _("Failed to start `ssh' process.\n"));
+ return;
+ }
#if DEBUG_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Started `%s', waiting for `%s' to be up.\n",
- "gnunet-arm", "gnunet-service-core");
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Started `%s', waiting for `%s' to be up.\n",
+ "gnunet-arm", "gnunet-service-core");
#endif
- d->phase = SP_START_ARMING;
- d->task
+ d->phase = SP_START_ARMING;
+ d->task
= GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT,
&start_fsm, d);
- break;
- case SP_START_ARMING:
- if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code))
- {
- if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value ==
- 0)
- {
- cb = d->cb;
- d->cb = NULL;
- if (NULL != cb)
- cb (d->cb_cls,
- NULL,
- d->cfg,
- d,
- (NULL == d->hostname)
- ? _("`gnunet-arm' does not seem to terminate.\n")
- : _("`ssh' does not seem to terminate.\n"));
- GNUNET_CONFIGURATION_destroy (d->cfg);
- GNUNET_free (d->cfgfile);
- GNUNET_free_non_null (d->hostname);
- GNUNET_free_non_null (d->username);
- GNUNET_free(d->proc);
- GNUNET_free(d);
- return;
- }
- /* wait some more */
- d->task
- = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT,
- &start_fsm, d);
- return;
- }
+ break;
+ case SP_START_ARMING:
+ if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code))
+ {
+ if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == 0)
+ {
+ cb = d->cb;
+ d->cb = NULL;
+ if (NULL != cb)
+ cb (d->cb_cls,
+ NULL,
+ d->cfg,
+ d,
+ (NULL == d->hostname)
+ ? _("`gnunet-arm' does not seem to terminate.\n")
+ : _("`ssh' does not seem to terminate.\n"));
+ GNUNET_CONFIGURATION_destroy (d->cfg);
+ GNUNET_free (d->cfgfile);
+ GNUNET_free_non_null (d->hostname);
+ GNUNET_free_non_null (d->username);
+ GNUNET_free (d->proc);
+ GNUNET_free (d);
+ return;
+ }
+ /* wait some more */
+ d->task
+ = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT,
+ &start_fsm, d);
+ return;
+ }
#if DEBUG_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Successfully started `%s'.\n", "gnunet-arm");
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Successfully started `%s'.\n", "gnunet-arm");
#endif
- GNUNET_free(d->proc);
- d->phase = SP_START_CORE;
+ GNUNET_free (d->proc);
+ d->phase = SP_START_CORE;
#if DEBUG_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Calling CORE_connect\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Calling CORE_connect\n");
#endif
- /* Fall through */
- case SP_START_CORE:
- if (d->server != NULL)
- GNUNET_CORE_disconnect(d->server);
+ /* Fall through */
+ case SP_START_CORE:
+ if (d->server != NULL)
+ GNUNET_CORE_disconnect (d->server);
#if WAIT_FOR_HELLO
- if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value ==
- 0)
- {
- cb = d->cb;
- d->cb = NULL;
- if (NULL != cb)
- cb (d->cb_cls,
- NULL,
- d->cfg,
- d,
- _("Unable to connect to CORE service for peer!\n"));
- GNUNET_CONFIGURATION_destroy (d->cfg);
- GNUNET_free (d->cfgfile);
- GNUNET_free_non_null (d->hostname);
- GNUNET_free_non_null (d->username);
- GNUNET_free (d);
- return;
- }
- d->server = GNUNET_CORE_connect (d->cfg, 1,
- d,
- &testing_init,
- NULL, NULL, NULL,
- NULL, GNUNET_NO,
- NULL, GNUNET_NO, no_handlers);
- d->task
- = GNUNET_SCHEDULER_add_delayed
(GNUNET_TIME_relative_multiply(GNUNET_CONSTANTS_SERVICE_RETRY, 2),
- &start_fsm, d);
+ if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == 0)
+ {
+ cb = d->cb;
+ d->cb = NULL;
+ if (NULL != cb)
+ cb (d->cb_cls,
+ NULL,
+ d->cfg, d, _("Unable to connect to CORE service for peer!\n"));
+ GNUNET_CONFIGURATION_destroy (d->cfg);
+ GNUNET_free (d->cfgfile);
+ GNUNET_free_non_null (d->hostname);
+ GNUNET_free_non_null (d->username);
+ GNUNET_free (d);
+ return;
+ }
+ d->server = GNUNET_CORE_connect (d->cfg, 1,
+ d,
+ &testing_init,
+ NULL, NULL, NULL,
+ NULL, GNUNET_NO,
+ NULL, GNUNET_NO, no_handlers);
+ d->task
+ =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_CONSTANTS_SERVICE_RETRY, 2),
+ &start_fsm, d);
#else
- d->th = GNUNET_TRANSPORT_connect (d->cfg, &d->id, d, NULL, NULL, NULL);
- if (d->th == NULL)
- {
- if (GNUNET_YES == d->dead)
- GNUNET_TESTING_daemon_stop (d,
- GNUNET_TIME_absolute_get_remaining
- (d->max_timeout), d->dead_cb,
- d->dead_cb_cls, GNUNET_YES, GNUNET_NO);
- else if (NULL != d->cb)
- d->cb (d->cb_cls, &d->id, d->cfg, d,
- _("Failed to connect to transport service!\n"));
- return;
- }
+ d->th = GNUNET_TRANSPORT_connect (d->cfg, &d->id, d, NULL, NULL, NULL);
+ if (d->th == NULL)
+ {
+ if (GNUNET_YES == d->dead)
+ GNUNET_TESTING_daemon_stop (d,
+ GNUNET_TIME_absolute_get_remaining
+ (d->max_timeout), d->dead_cb,
+ d->dead_cb_cls, GNUNET_YES, GNUNET_NO);
+ else if (NULL != d->cb)
+ d->cb (d->cb_cls, &d->id, d->cfg, d,
+ _("Failed to connect to transport service!\n"));
+ return;
+ }
#if DEBUG_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connected to transport service `%s', getting HELLO\n",
- GNUNET_i2s (&d->id));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Connected to transport service `%s', getting HELLO\n",
+ GNUNET_i2s (&d->id));
#endif
- GNUNET_TRANSPORT_get_hello (d->th, &process_hello, d);
- GNUNET_SCHEDULER_add_now (¬ify_daemon_started, d);
- /*cb = d->cb;
+ GNUNET_TRANSPORT_get_hello (d->th, &process_hello, d);
+ GNUNET_SCHEDULER_add_now (¬ify_daemon_started, d);
+ /*cb = d->cb;
+ * d->cb = NULL;
+ * if (NULL != cb)
+ * cb (d->cb_cls, &d->id, d->cfg, d, NULL); */
+ d->running = GNUNET_YES;
+ d->phase = SP_GET_HELLO;
+#endif
+ break;
+ case SP_GET_HELLO:
+ if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == 0)
+ {
+ if (d->server != NULL)
+ GNUNET_CORE_disconnect (d->server);
+ if (d->th != NULL)
+ GNUNET_TRANSPORT_disconnect (d->th);
+ cb = d->cb;
d->cb = NULL;
if (NULL != cb)
- cb (d->cb_cls, &d->id, d->cfg, d, NULL);*/
- d->running = GNUNET_YES;
- d->phase = SP_GET_HELLO;
-#endif
- break;
- case SP_GET_HELLO:
- if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value ==
- 0)
- {
- if (d->server != NULL)
- GNUNET_CORE_disconnect(d->server);
- if (d->th != NULL)
- GNUNET_TRANSPORT_disconnect(d->th);
- cb = d->cb;
- d->cb = NULL;
- if (NULL != cb)
- cb (d->cb_cls,
- NULL,
- d->cfg,
- d,
- _("Unable to get HELLO for peer!\n"));
- GNUNET_CONFIGURATION_destroy (d->cfg);
- GNUNET_free (d->cfgfile);
- GNUNET_free_non_null (d->hostname);
- GNUNET_free_non_null (d->username);
- GNUNET_free (d);
- return;
- }
- if (d->hello != NULL)
+ cb (d->cb_cls, NULL, d->cfg, d, _("Unable to get HELLO for peer!\n"));
+ GNUNET_CONFIGURATION_destroy (d->cfg);
+ GNUNET_free (d->cfgfile);
+ GNUNET_free_non_null (d->hostname);
+ GNUNET_free_non_null (d->username);
+ GNUNET_free (d);
+ return;
+ }
+ if (d->hello != NULL)
+ return;
+ GNUNET_assert (d->task == GNUNET_SCHEDULER_NO_TASK);
+ d->task
+ =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_CONSTANTS_SERVICE_RETRY, 2),
+ &start_fsm, d);
+ break;
+ case SP_START_DONE:
+ GNUNET_break (0);
+ break;
+ case SP_SERVICE_START:
+ /* confirm gnunet-arm exited */
+ if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code))
+ {
+ if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == 0)
+ {
+ cb = d->cb;
+ d->cb = NULL;
+ if (NULL != cb)
+ cb (d->cb_cls,
+ NULL,
+ d->cfg,
+ d,
+ (NULL == d->hostname)
+ ? _("`gnunet-arm' does not seem to terminate.\n")
+ : _("`ssh' does not seem to terminate.\n"));
return;
- GNUNET_assert(d->task == GNUNET_SCHEDULER_NO_TASK);
+ }
+ /* wait some more */
d->task
- = GNUNET_SCHEDULER_add_delayed
(GNUNET_TIME_relative_multiply(GNUNET_CONSTANTS_SERVICE_RETRY, 2),
- &start_fsm, d);
- break;
- case SP_START_DONE:
- GNUNET_break (0);
- break;
- case SP_SERVICE_START:
- /* confirm gnunet-arm exited */
- if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code))
- {
- if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value ==
- 0)
- {
- cb = d->cb;
- d->cb = NULL;
- if (NULL != cb)
- cb (d->cb_cls,
- NULL,
- d->cfg,
- d,
- (NULL == d->hostname)
- ? _("`gnunet-arm' does not seem to terminate.\n")
- : _("`ssh' does not seem to terminate.\n"));
- return;
- }
- /* wait some more */
- d->task
- = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT,
- &start_fsm, d);
- return;
- }
+ = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT,
+ &start_fsm, d);
+ return;
+ }
#if EXTRA_CHECKS
- if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0))
- {
- cb = d->cb;
- d->cb = NULL;
- if (NULL != cb)
- cb (d->cb_cls,
- NULL,
- d->cfg,
- d,
- (NULL == d->hostname)
- ? _("`gnunet-arm' terminated with non-zero exit status (or
timed out)!\n")
- : _("`ssh' does not seem to terminate.\n"));
- return;
- }
-#endif
-#if DEBUG_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service startup complete!\n");
-#endif
+ if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0))
+ {
cb = d->cb;
d->cb = NULL;
- d->phase = SP_START_DONE;
if (NULL != cb)
- cb (d->cb_cls, &d->id, d->cfg, d, NULL);
- break;
- case SP_SERVICE_SHUTDOWN_START:
- /* confirm copying complete */
- if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code))
- {
- if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value ==
- 0)
- {
- if (NULL != d->dead_cb)
- d->dead_cb (d->dead_cb_cls,
- _
- ("either `gnunet-arm' or `ssh' does not seem to
terminate.\n"));
- return;
- }
- /* wait some more */
- d->task
- = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT,
- &start_fsm, d);
- return;
- }
-#if EXTRA_CHECKS
- if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0))
- {
- if (NULL != d->dead_cb)
- d->dead_cb (d->dead_cb_cls,
- _
- ("shutdown (either `gnunet-arm' or `ssh') did not
complete cleanly.\n"));
- return;
- }
+ cb (d->cb_cls,
+ NULL,
+ d->cfg,
+ d,
+ (NULL == d->hostname)
+ ?
+ _
+ ("`gnunet-arm' terminated with non-zero exit status (or timed
out)!\n")
+ : _("`ssh' does not seem to terminate.\n"));
+ return;
+ }
#endif
#if DEBUG_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service shutdown complete.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service startup complete!\n");
#endif
+ cb = d->cb;
+ d->cb = NULL;
+ d->phase = SP_START_DONE;
+ if (NULL != cb)
+ cb (d->cb_cls, &d->id, d->cfg, d, NULL);
+ break;
+ case SP_SERVICE_SHUTDOWN_START:
+ /* confirm copying complete */
+ if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code))
+ {
+ if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == 0)
+ {
+ if (NULL != d->dead_cb)
+ d->dead_cb (d->dead_cb_cls,
+ _
+ ("either `gnunet-arm' or `ssh' does not seem to
terminate.\n"));
+ return;
+ }
+ /* wait some more */
+ d->task
+ = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT,
+ &start_fsm, d);
+ return;
+ }
+#if EXTRA_CHECKS
+ if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0))
+ {
if (NULL != d->dead_cb)
- d->dead_cb (d->dead_cb_cls, NULL);
- break;
- case SP_SHUTDOWN_START:
- /* confirm copying complete */
- if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code))
- {
- if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value ==
- 0)
- {
- if (NULL != d->dead_cb)
- d->dead_cb (d->dead_cb_cls,
- _
- ("either `gnunet-arm' or `ssh' does not seem to
terminate.\n"));
- if (d->th != NULL)
- {
- GNUNET_TRANSPORT_get_hello_cancel (d->th, &process_hello,
- d);
- GNUNET_TRANSPORT_disconnect (d->th);
- d->th = NULL;
- }
- GNUNET_CONFIGURATION_destroy (d->cfg);
- GNUNET_free (d->cfgfile);
- GNUNET_free_non_null (d->hello);
- GNUNET_free_non_null (d->hostname);
- GNUNET_free_non_null (d->username);
- GNUNET_free_non_null (d->shortname);
- GNUNET_free_non_null (d->proc);
- d->proc = NULL;
- GNUNET_free (d);
- return;
- }
- /* wait some more */
- d->task
- = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT,
- &start_fsm, d);
- return;
- }
- if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0))
- {
- if (NULL != d->dead_cb)
- d->dead_cb (d->dead_cb_cls,
- _
- ("shutdown (either `gnunet-arm' or `ssh') did not
complete cleanly.\n"));
- if (d->th != NULL)
- {
- GNUNET_TRANSPORT_get_hello_cancel (d->th, &process_hello, d);
- GNUNET_TRANSPORT_disconnect (d->th);
- d->th = NULL;
- }
- if (d->server != NULL)
- {
- GNUNET_CORE_disconnect (d->server);
- d->server = NULL;
- }
- GNUNET_CONFIGURATION_destroy (d->cfg);
- GNUNET_free (d->cfgfile);
- GNUNET_free_non_null (d->hello);
- GNUNET_free_non_null (d->hostname);
- GNUNET_free_non_null (d->username);
- GNUNET_free_non_null (d->shortname);
- GNUNET_free_non_null (d->proc);
- d->proc = NULL;
- GNUNET_free (d);
- return;
- }
+ d->dead_cb (d->dead_cb_cls,
+ _
+ ("shutdown (either `gnunet-arm' or `ssh') did not complete
cleanly.\n"));
+ return;
+ }
+#endif
#if DEBUG_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer shutdown complete.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service shutdown complete.\n");
#endif
- if (d->server != NULL)
+ if (NULL != d->dead_cb)
+ d->dead_cb (d->dead_cb_cls, NULL);
+ break;
+ case SP_SHUTDOWN_START:
+ /* confirm copying complete */
+ if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code))
+ {
+ if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == 0)
+ {
+ if (NULL != d->dead_cb)
+ d->dead_cb (d->dead_cb_cls,
+ _
+ ("either `gnunet-arm' or `ssh' does not seem to
terminate.\n"));
+ if (d->th != NULL)
{
- GNUNET_CORE_disconnect (d->server);
- d->server = NULL;
- }
-
- if (d->th != NULL)
- {
GNUNET_TRANSPORT_get_hello_cancel (d->th, &process_hello, d);
GNUNET_TRANSPORT_disconnect (d->th);
d->th = NULL;
}
-
+ GNUNET_CONFIGURATION_destroy (d->cfg);
+ GNUNET_free (d->cfgfile);
+ GNUNET_free_non_null (d->hello);
+ GNUNET_free_non_null (d->hostname);
+ GNUNET_free_non_null (d->username);
+ GNUNET_free_non_null (d->shortname);
+ GNUNET_free_non_null (d->proc);
+ d->proc = NULL;
+ GNUNET_free (d);
+ return;
+ }
+ /* wait some more */
+ d->task
+ = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT,
+ &start_fsm, d);
+ return;
+ }
+ if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0))
+ {
if (NULL != d->dead_cb)
- d->dead_cb (d->dead_cb_cls, NULL);
-
- /* state clean up and notifications */
- if (d->churn == GNUNET_NO)
- {
- GNUNET_CONFIGURATION_destroy (d->cfg);
- GNUNET_free (d->cfgfile);
- GNUNET_free_non_null (d->hostname);
- GNUNET_free_non_null (d->username);
- }
-
+ d->dead_cb (d->dead_cb_cls,
+ _
+ ("shutdown (either `gnunet-arm' or `ssh') did not complete
cleanly.\n"));
+ if (d->th != NULL)
+ {
+ GNUNET_TRANSPORT_get_hello_cancel (d->th, &process_hello, d);
+ GNUNET_TRANSPORT_disconnect (d->th);
+ d->th = NULL;
+ }
+ if (d->server != NULL)
+ {
+ GNUNET_CORE_disconnect (d->server);
+ d->server = NULL;
+ }
+ GNUNET_CONFIGURATION_destroy (d->cfg);
+ GNUNET_free (d->cfgfile);
GNUNET_free_non_null (d->hello);
- d->hello = NULL;
+ GNUNET_free_non_null (d->hostname);
+ GNUNET_free_non_null (d->username);
GNUNET_free_non_null (d->shortname);
GNUNET_free_non_null (d->proc);
d->proc = NULL;
- d->shortname = NULL;
- if (d->churn == GNUNET_NO)
- GNUNET_free (d);
-
- break;
- case SP_CONFIG_UPDATE:
- /* confirm copying complete */
- if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code))
- {
- if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value ==
0) /* FIXME: config update should take timeout parameter! */
- {
- cb = d->cb;
- d->cb = NULL;
- if (NULL != cb)
- cb (d->cb_cls,
- NULL,
- d->cfg, d, _("`scp' does not seem to terminate.\n"));
- return;
- }
- /* wait some more */
- d->task
- = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT,
- &start_fsm, d);
- return;
- }
- if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0))
- {
- if (NULL != d->update_cb)
- d->update_cb (d->update_cb_cls,
- _("`scp' did not complete cleanly.\n"));
- return;
- }
+ GNUNET_free (d);
+ return;
+ }
#if DEBUG_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Successfully copied configuration file.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer shutdown complete.\n");
#endif
+ if (d->server != NULL)
+ {
+ GNUNET_CORE_disconnect (d->server);
+ d->server = NULL;
+ }
+
+ if (d->th != NULL)
+ {
+ GNUNET_TRANSPORT_get_hello_cancel (d->th, &process_hello, d);
+ GNUNET_TRANSPORT_disconnect (d->th);
+ d->th = NULL;
+ }
+
+ if (NULL != d->dead_cb)
+ d->dead_cb (d->dead_cb_cls, NULL);
+
+ /* state clean up and notifications */
+ if (d->churn == GNUNET_NO)
+ {
+ GNUNET_CONFIGURATION_destroy (d->cfg);
+ GNUNET_free (d->cfgfile);
+ GNUNET_free_non_null (d->hostname);
+ GNUNET_free_non_null (d->username);
+ }
+
+ GNUNET_free_non_null (d->hello);
+ d->hello = NULL;
+ GNUNET_free_non_null (d->shortname);
+ GNUNET_free_non_null (d->proc);
+ d->proc = NULL;
+ d->shortname = NULL;
+ if (d->churn == GNUNET_NO)
+ GNUNET_free (d);
+
+ break;
+ case SP_CONFIG_UPDATE:
+ /* confirm copying complete */
+ if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code))
+ {
+ if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == 0)
/* FIXME: config update should take timeout parameter! */
+ {
+ cb = d->cb;
+ d->cb = NULL;
+ if (NULL != cb)
+ cb (d->cb_cls,
+ NULL, d->cfg, d, _("`scp' does not seem to terminate.\n"));
+ return;
+ }
+ /* wait some more */
+ d->task
+ = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT,
+ &start_fsm, d);
+ return;
+ }
+ if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0))
+ {
if (NULL != d->update_cb)
- d->update_cb (d->update_cb_cls, NULL);
- d->phase = SP_START_DONE;
- break;
+ d->update_cb (d->update_cb_cls, _("`scp' did not complete
cleanly.\n"));
+ return;
}
+#if DEBUG_TESTING
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Successfully copied configuration file.\n");
+#endif
+ if (NULL != d->update_cb)
+ d->update_cb (d->update_cb_cls, NULL);
+ d->phase = SP_START_DONE;
+ break;
+ }
}
/**
@@ -1055,77 +1035,81 @@
*/
void
GNUNET_TESTING_daemon_start_stopped_service (struct GNUNET_TESTING_Daemon *d,
- char *service,
- struct GNUNET_TIME_Relative
timeout,
-
GNUNET_TESTING_NotifyDaemonRunning cb, void *cb_cls)
+ char *service,
+ struct GNUNET_TIME_Relative
+ timeout,
+ GNUNET_TESTING_NotifyDaemonRunning
+ cb, void *cb_cls)
{
char *arg;
+
d->cb = cb;
d->cb_cls = cb_cls;
- GNUNET_assert(d->running == GNUNET_YES);
+ GNUNET_assert (d->running == GNUNET_YES);
if (d->phase == SP_CONFIG_UPDATE)
- {
- GNUNET_SCHEDULER_cancel (d->task);
- d->phase = SP_START_DONE;
- }
+ {
+ GNUNET_SCHEDULER_cancel (d->task);
+ d->phase = SP_START_DONE;
+ }
if (d->churned_services == NULL)
- {
- d->cb(d->cb_cls, &d->id, d->cfg, d, "No service has been churned off
yet!!");
- return;
- }
+ {
+ d->cb (d->cb_cls, &d->id, d->cfg, d,
+ "No service has been churned off yet!!");
+ return;
+ }
d->phase = SP_SERVICE_START;
- GNUNET_free(d->churned_services);
+ GNUNET_free (d->churned_services);
d->churned_services = NULL;
- d->max_timeout = GNUNET_TIME_relative_to_absolute(timeout);
+ d->max_timeout = GNUNET_TIME_relative_to_absolute (timeout);
/* Check if this is a local or remote process */
if (NULL != d->hostname)
- {
+ {
#if DEBUG_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Starting gnunet-arm with config `%s' on host `%s'.\n",
- d->cfgfile, d->hostname);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Starting gnunet-arm with config `%s' on host `%s'.\n",
+ d->cfgfile, d->hostname);
#endif
- if (d->username != NULL)
- GNUNET_asprintf (&arg, "address@hidden", d->username, d->hostname);
- else
- arg = GNUNET_strdup (d->hostname);
+ if (d->username != NULL)
+ GNUNET_asprintf (&arg, "address@hidden", d->username, d->hostname);
+ else
+ arg = GNUNET_strdup (d->hostname);
- d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh",
+ d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh",
#if !DEBUG_TESTING
- "-q",
+ "-q",
#endif
- arg, "gnunet-arm",
+ arg, "gnunet-arm",
#if DEBUG_TESTING
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", d->cfgfile, "-i", service, "-q",
- "-T",
GNUNET_TIME_relative_to_string(timeout),
- NULL);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Starting gnunet-arm with command ssh %s gnunet-arm -c %s -i
%s -q\n",
- arg, "gnunet-arm", d->cfgfile, service);
- GNUNET_free (arg);
- }
+ "-c", d->cfgfile, "-i", service, "-q",
+ "-T",
+ GNUNET_TIME_relative_to_string
(timeout),
+ NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Starting gnunet-arm with command ssh %s gnunet-arm -c %s -i
%s -q\n",
+ arg, "gnunet-arm", d->cfgfile, service);
+ GNUNET_free (arg);
+ }
else
- {
+ {
#if DEBUG_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Starting gnunet-arm with config `%s' locally.\n",
- d->cfgfile);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Starting gnunet-arm with config `%s' locally.\n", d->cfgfile);
#endif
- d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm",
- "gnunet-arm",
+ d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", "gnunet-arm",
#if DEBUG_TESTING
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", d->cfgfile, "-i", service, "-q",
- "-T",
GNUNET_TIME_relative_to_string(timeout),
- NULL);
- }
+ "-c", d->cfgfile, "-i", service, "-q",
+ "-T",
+ GNUNET_TIME_relative_to_string
(timeout),
+ NULL);
+ }
d->max_timeout = GNUNET_TIME_relative_to_absolute (timeout);
d->task = GNUNET_SCHEDULER_add_now (&start_fsm, d);
@@ -1144,72 +1128,77 @@
GNUNET_TESTING_daemon_start_service (struct GNUNET_TESTING_Daemon *d,
char *service,
struct GNUNET_TIME_Relative timeout,
- GNUNET_TESTING_NotifyDaemonRunning cb,
void *cb_cls)
+ GNUNET_TESTING_NotifyDaemonRunning cb,
+ void *cb_cls)
{
char *arg;
+
d->cb = cb;
d->cb_cls = cb_cls;
- GNUNET_assert(service != NULL);
- GNUNET_assert(d->running == GNUNET_YES);
- GNUNET_assert(d->phase == SP_START_DONE);
+ GNUNET_assert (service != NULL);
+ GNUNET_assert (d->running == GNUNET_YES);
+ GNUNET_assert (d->phase == SP_START_DONE);
#if DEBUG_TESTING
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Starting service %s for peer `%4s'\n"), service, GNUNET_i2s
(&d->id));
+ _("Starting service %s for peer `%4s'\n"), service,
+ GNUNET_i2s (&d->id));
#endif
d->phase = SP_SERVICE_START;
- d->max_timeout = GNUNET_TIME_relative_to_absolute(timeout);
+ d->max_timeout = GNUNET_TIME_relative_to_absolute (timeout);
/* Check if this is a local or remote process */
if (NULL != d->hostname)
- {
+ {
#if DEBUG_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Starting gnunet-arm with config `%s' on host `%s'.\n",
- d->cfgfile, d->hostname);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Starting gnunet-arm with config `%s' on host `%s'.\n",
+ d->cfgfile, d->hostname);
#endif
- if (d->username != NULL)
- GNUNET_asprintf (&arg, "address@hidden", d->username, d->hostname);
- else
- arg = GNUNET_strdup (d->hostname);
+ if (d->username != NULL)
+ GNUNET_asprintf (&arg, "address@hidden", d->username, d->hostname);
+ else
+ arg = GNUNET_strdup (d->hostname);
- d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh",
+ d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh",
#if !DEBUG_TESTING
- "-q",
+ "-q",
#endif
- arg, "gnunet-arm",
+ arg, "gnunet-arm",
#if DEBUG_TESTING
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", d->cfgfile, "-i", service, "-q",
- "-T",
GNUNET_TIME_relative_to_string(timeout),
- NULL);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Starting gnunet-arm with command ssh %s gnunet-arm -c %s -i
%s -q -T %s\n",
- arg, "gnunet-arm", d->cfgfile, service,
GNUNET_TIME_relative_to_string(timeout));
- GNUNET_free (arg);
- }
+ "-c", d->cfgfile, "-i", service, "-q",
+ "-T",
+ GNUNET_TIME_relative_to_string
(timeout),
+ NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Starting gnunet-arm with command ssh %s gnunet-arm -c %s -i
%s -q -T %s\n",
+ arg, "gnunet-arm", d->cfgfile, service,
+ GNUNET_TIME_relative_to_string (timeout));
+ GNUNET_free (arg);
+ }
else
- {
+ {
#if DEBUG_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Starting gnunet-arm with config `%s' locally.\n",
- d->cfgfile);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Starting gnunet-arm with config `%s' locally.\n", d->cfgfile);
#endif
- d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm",
- "gnunet-arm",
+ d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", "gnunet-arm",
#if DEBUG_TESTING
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", d->cfgfile, "-i", service, "-q",
- "-T",
GNUNET_TIME_relative_to_string(timeout),
- NULL);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Starting gnunet-arm with command %s -c %s -i %s -q -T %s\n",
- "gnunet-arm", d->cfgfile, service,
GNUNET_TIME_relative_to_string(timeout));
- }
+ "-c", d->cfgfile, "-i", service, "-q",
+ "-T",
+ GNUNET_TIME_relative_to_string
(timeout),
+ NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Starting gnunet-arm with command %s -c %s -i %s -q -T %s\n",
+ "gnunet-arm", d->cfgfile, service,
+ GNUNET_TIME_relative_to_string (timeout));
+ }
d->max_timeout = GNUNET_TIME_relative_to_absolute (timeout);
d->task = GNUNET_SCHEDULER_add_now (&start_fsm, d);
@@ -1231,11 +1220,11 @@
void *cb_cls)
{
if (daemon->running == GNUNET_YES)
- {
- cb (cb_cls, &daemon->id, daemon->cfg, daemon,
- "Daemon already running, can't restart!");
- return;
- }
+ {
+ cb (cb_cls, &daemon->id, daemon->cfg, daemon,
+ "Daemon already running, can't restart!");
+ return;
+ }
daemon->cb = cb;
daemon->cb_cls = cb_cls;
@@ -1298,35 +1287,34 @@
ret = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Daemon));
ret->hostname = (hostname == NULL) ? NULL : GNUNET_strdup (hostname);
if (sshport != 0)
- {
- GNUNET_asprintf (&ret->ssh_port_str, "%d", sshport);
- }
+ {
+ GNUNET_asprintf (&ret->ssh_port_str, "%d", sshport);
+ }
else
ret->ssh_port_str = NULL;
/* Find service home and base service home directories, create it if it
doesn't exist */
- GNUNET_assert(GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "PATHS",
- "SERVICEHOME",
- &servicehome));
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_string (cfg,
+ "PATHS",
+ "SERVICEHOME",
+ &servicehome));
GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_create (servicehome));
- GNUNET_asprintf(&temp_file_name, "%s/gnunet-testing-config", servicehome);
+ GNUNET_asprintf (&temp_file_name, "%s/gnunet-testing-config", servicehome);
ret->cfgfile = GNUNET_DISK_mktemp (temp_file_name);
- GNUNET_free(temp_file_name);
+ GNUNET_free (temp_file_name);
#if DEBUG_TESTING
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Setting up peer with configuration file `%s'.\n",
- ret->cfgfile);
+ "Setting up peer with configuration file `%s'.\n", ret->cfgfile);
#endif
if (NULL == ret->cfgfile)
- {
- GNUNET_free_non_null (ret->ssh_port_str);
- GNUNET_free_non_null (ret->hostname);
- GNUNET_free (ret);
- return NULL;
- }
+ {
+ GNUNET_free_non_null (ret->ssh_port_str);
+ GNUNET_free_non_null (ret->hostname);
+ GNUNET_free (ret);
+ return NULL;
+ }
ret->hostkey_callback = hostkey_callback;
ret->hostkey_cls = hostkey_cls;
ret->cb = cb;
@@ -1337,46 +1325,47 @@
"PATHS",
"DEFAULTCONFIG", ret->cfgfile);
- if (hostkey != NULL) /* Get the peer identity from the hostkey */
- {
- private_key = GNUNET_CRYPTO_rsa_decode_key(hostkey, HOSTKEYFILESIZE);
- GNUNET_assert(private_key != NULL);
- GNUNET_CRYPTO_rsa_key_get_public (private_key,
- &public_key);
- GNUNET_CRYPTO_hash(&public_key, sizeof(struct
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &ret->id.hashPubKey);
- ret->shortname = GNUNET_strdup(GNUNET_i2s(&ret->id));
- ret->have_hostkey = GNUNET_YES;
- GNUNET_CRYPTO_rsa_key_free(private_key);
- }
+ if (hostkey != NULL) /* Get the peer identity from the hostkey */
+ {
+ private_key = GNUNET_CRYPTO_rsa_decode_key (hostkey, HOSTKEYFILESIZE);
+ GNUNET_assert (private_key != NULL);
+ GNUNET_CRYPTO_rsa_key_get_public (private_key, &public_key);
+ GNUNET_CRYPTO_hash (&public_key,
+ sizeof (struct
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+ &ret->id.hashPubKey);
+ ret->shortname = GNUNET_strdup (GNUNET_i2s (&ret->id));
+ ret->have_hostkey = GNUNET_YES;
+ GNUNET_CRYPTO_rsa_key_free (private_key);
+ }
/* Write hostkey to file, if we were given one */
hostkeyfile = NULL;
if (hostkey != NULL)
- {
- GNUNET_asprintf(&hostkeyfile, "%s/.hostkey", servicehome);
- fn =
- GNUNET_DISK_file_open (hostkeyfile,
- GNUNET_DISK_OPEN_READWRITE
- | GNUNET_DISK_OPEN_CREATE,
- GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE);
- GNUNET_assert(fn != NULL);
- GNUNET_assert(HOSTKEYFILESIZE == GNUNET_DISK_file_write(fn, hostkey,
HOSTKEYFILESIZE));
- GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_close(fn));
- }
+ {
+ GNUNET_asprintf (&hostkeyfile, "%s/.hostkey", servicehome);
+ fn = GNUNET_DISK_file_open (hostkeyfile,
+ GNUNET_DISK_OPEN_READWRITE
+ | GNUNET_DISK_OPEN_CREATE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE);
+ GNUNET_assert (fn != NULL);
+ GNUNET_assert (HOSTKEYFILESIZE ==
+ GNUNET_DISK_file_write (fn, hostkey, HOSTKEYFILESIZE));
+ GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fn));
+ }
/* write configuration to temporary file */
if (GNUNET_OK != GNUNET_CONFIGURATION_write (ret->cfg, ret->cfgfile))
- {
- if (0 != UNLINK (ret->cfgfile))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
- "unlink", ret->cfgfile);
- GNUNET_CONFIGURATION_destroy (ret->cfg);
- GNUNET_free_non_null (ret->hostname);
- GNUNET_free (ret->cfgfile);
- GNUNET_free (ret);
- return NULL;
- }
+ {
+ if (0 != UNLINK (ret->cfgfile))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
+ "unlink", ret->cfgfile);
+ GNUNET_CONFIGURATION_destroy (ret->cfg);
+ GNUNET_free_non_null (ret->hostname);
+ GNUNET_free (ret->cfgfile);
+ GNUNET_free (ret);
+ return NULL;
+ }
if (ssh_username != NULL)
username = GNUNET_strdup (ssh_username);
if ((ssh_username == NULL) && (GNUNET_OK !=
@@ -1384,103 +1373,103 @@
"TESTING",
"USERNAME",
&username)))
- {
- if (NULL != getenv ("USER"))
- username = GNUNET_strdup (getenv ("USER"));
- else
- username = NULL;
- }
+ {
+ if (NULL != getenv ("USER"))
+ username = GNUNET_strdup (getenv ("USER"));
+ else
+ username = NULL;
+ }
ret->username = username;
- if (GNUNET_NO == pretend) /* Copy files, enter finite state machine */
+ if (GNUNET_NO == pretend) /* Copy files, enter finite state machine */
+ {
+ /* copy directory to remote host */
+ if (NULL != hostname)
{
- /* copy directory to remote host */
- if (NULL != hostname)
- {
#if DEBUG_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Copying configuration directory to host `%s'.\n",
hostname);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Copying configuration directory to host `%s'.\n", hostname);
#endif
- baseservicehome = GNUNET_strdup(servicehome);
- /* Remove trailing /'s */
- while (baseservicehome[strlen(baseservicehome) - 1] == '/')
- baseservicehome[strlen(baseservicehome) - 1] = '\0';
- /* Find next directory /, jump one ahead */
- slash = strrchr(baseservicehome, '/');
- if (slash != NULL)
- *(++slash) = '\0';
+ baseservicehome = GNUNET_strdup (servicehome);
+ /* Remove trailing /'s */
+ while (baseservicehome[strlen (baseservicehome) - 1] == '/')
+ baseservicehome[strlen (baseservicehome) - 1] = '\0';
+ /* Find next directory /, jump one ahead */
+ slash = strrchr (baseservicehome, '/');
+ if (slash != NULL)
+ *(++slash) = '\0';
- ret->phase = SP_COPYING;
- if (NULL != username)
- GNUNET_asprintf (&arg, "address@hidden:%s", username, hostname,
baseservicehome);
- else
- GNUNET_asprintf (&arg, "%s:%s", hostname, baseservicehome);
- GNUNET_free(baseservicehome);
- if (ret->ssh_port_str == NULL)
- {
- ret->proc = GNUNET_OS_start_process (NULL, NULL, "scp", "scp",
"-r",
+ ret->phase = SP_COPYING;
+ if (NULL != username)
+ GNUNET_asprintf (&arg, "address@hidden:%s", username, hostname,
baseservicehome);
+ else
+ GNUNET_asprintf (&arg, "%s:%s", hostname, baseservicehome);
+ GNUNET_free (baseservicehome);
+ if (ret->ssh_port_str == NULL)
+ {
+ ret->proc = GNUNET_OS_start_process (NULL, NULL, "scp", "scp", "-r",
#if !DEBUG_TESTING
- "-q",
+ "-q",
#endif
- servicehome, arg, NULL);
+ servicehome, arg, NULL);
#if DEBUG_TESTING
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "copying directory with command scp -r %s %s\n",
- servicehome,
- arg);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "copying directory with command scp -r %s %s\n",
+ servicehome, arg);
#endif
- }
- else
- {
- ret->proc = GNUNET_OS_start_process (NULL, NULL, "scp",
- "scp", "-r", "-P",
ret->ssh_port_str,
- #if !DEBUG_TESTING
- "-q",
- #endif
- servicehome, arg, NULL);
- }
- GNUNET_free (arg);
- if (NULL == ret->proc)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _
- ("Could not start `%s' process to copy configuration
directory.\n"),
- "scp");
- if (0 != UNLINK (ret->cfgfile))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
- "unlink", ret->cfgfile);
- GNUNET_CONFIGURATION_destroy (ret->cfg);
- GNUNET_free_non_null (ret->hostname);
- GNUNET_free_non_null (ret->username);
- GNUNET_free (ret->cfgfile);
- GNUNET_free (ret);
- if ((hostkey != NULL) && (0 != UNLINK(hostkeyfile)))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
- "unlink", hostkeyfile);
- GNUNET_free_non_null(hostkeyfile);
- GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove
(servicehome));
- GNUNET_free(servicehome);
- return NULL;
- }
+ }
+ else
+ {
+ ret->proc = GNUNET_OS_start_process (NULL, NULL, "scp",
+ "scp", "-r", "-P",
+ ret->ssh_port_str,
+#if !DEBUG_TESTING
+ "-q",
+#endif
+ servicehome, arg, NULL);
+ }
+ GNUNET_free (arg);
+ if (NULL == ret->proc)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _
+ ("Could not start `%s' process to copy configuration
directory.\n"),
+ "scp");
+ if (0 != UNLINK (ret->cfgfile))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
+ "unlink", ret->cfgfile);
+ GNUNET_CONFIGURATION_destroy (ret->cfg);
+ GNUNET_free_non_null (ret->hostname);
+ GNUNET_free_non_null (ret->username);
+ GNUNET_free (ret->cfgfile);
+ GNUNET_free (ret);
+ if ((hostkey != NULL) && (0 != UNLINK (hostkeyfile)))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
+ "unlink", hostkeyfile);
+ GNUNET_free_non_null (hostkeyfile);
+ GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove
(servicehome));
+ GNUNET_free (servicehome);
+ return NULL;
+ }
- ret->task
- = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT,
- &start_fsm, ret);
- GNUNET_free_non_null(hostkeyfile);
- GNUNET_free(servicehome);
- return ret;
- }
+ ret->task
+ = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT,
+ &start_fsm, ret);
+ GNUNET_free_non_null (hostkeyfile);
+ GNUNET_free (servicehome);
+ return ret;
+ }
#if DEBUG_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "No need to copy configuration file since we are running
locally.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "No need to copy configuration file since we are running
locally.\n");
#endif
- ret->phase = SP_COPIED;
- GNUNET_SCHEDULER_add_continuation (&start_fsm,
- ret,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- }
- GNUNET_free_non_null(hostkeyfile);
- GNUNET_free(servicehome);
+ ret->phase = SP_COPIED;
+ GNUNET_SCHEDULER_add_continuation (&start_fsm,
+ ret,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ }
+ GNUNET_free_non_null (hostkeyfile);
+ GNUNET_free (servicehome);
return ret;
}
@@ -1502,31 +1491,31 @@
del_arg = NULL;
if (NULL != d->cb)
- {
- d->dead = GNUNET_YES;
- return;
- }
+ {
+ d->dead = GNUNET_YES;
+ return;
+ }
d->cb = cb;
d->cb_cls = cb_cls;
if (d->phase == SP_CONFIG_UPDATE)
- {
- GNUNET_SCHEDULER_cancel (d->task);
- d->phase = SP_START_DONE;
- }
+ {
+ GNUNET_SCHEDULER_cancel (d->task);
+ d->phase = SP_START_DONE;
+ }
if (d->server != NULL)
- {
- GNUNET_CORE_disconnect (d->server);
- d->server = NULL;
- }
+ {
+ GNUNET_CORE_disconnect (d->server);
+ d->server = NULL;
+ }
if (d->th != NULL)
- {
- GNUNET_TRANSPORT_get_hello_cancel (d->th, &process_hello, d);
- GNUNET_TRANSPORT_disconnect (d->th);
- d->th = NULL;
- }
+ {
+ GNUNET_TRANSPORT_get_hello_cancel (d->th, &process_hello, d);
+ GNUNET_TRANSPORT_disconnect (d->th);
+ d->th = NULL;
+ }
/* state clean up and notifications */
GNUNET_free_non_null (d->hello);
@@ -1539,50 +1528,48 @@
/* Check if this is a local or remote process */
if (NULL != d->hostname)
- {
+ {
#if DEBUG_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Stopping gnunet-arm with config `%s' on host `%s'.\n",
- d->cfgfile, d->hostname);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Stopping gnunet-arm with config `%s' on host `%s'.\n",
+ d->cfgfile, d->hostname);
#endif
- if (d->username != NULL)
- GNUNET_asprintf (&arg, "address@hidden", d->username, d->hostname);
- else
- arg = GNUNET_strdup (d->hostname);
+ if (d->username != NULL)
+ GNUNET_asprintf (&arg, "address@hidden", d->username, d->hostname);
+ else
+ arg = GNUNET_strdup (d->hostname);
- d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh",
+ d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh",
#if !DEBUG_TESTING
- "-q",
+ "-q",
#endif
- arg, "gnunet-arm",
+ arg, "gnunet-arm",
#if DEBUG_TESTING
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", d->cfgfile, "-e", "-r", NULL);
- /* Use -r to restart arm and all services */
+ "-c", d->cfgfile, "-e", "-r", NULL);
+ /* Use -r to restart arm and all services */
- GNUNET_free (arg);
- }
+ GNUNET_free (arg);
+ }
else
- {
+ {
#if DEBUG_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Stopping gnunet-arm with config `%s' locally.\n",
- d->cfgfile);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Stopping gnunet-arm with config `%s' locally.\n", d->cfgfile);
#endif
- d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm",
- "gnunet-arm",
+ d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", "gnunet-arm",
#if DEBUG_TESTING
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", d->cfgfile, "-e", "-r", NULL);
- }
+ "-c", d->cfgfile, "-e", "-r", NULL);
+ }
GNUNET_free_non_null (del_arg);
d->task
- = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT,
- &start_fsm, d);
+ = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT,
+ &start_fsm, d);
}
@@ -1604,78 +1591,80 @@
GNUNET_TESTING_daemon_stop_service (struct GNUNET_TESTING_Daemon *d,
char *service,
struct GNUNET_TIME_Relative timeout,
- GNUNET_TESTING_NotifyCompletion cb, void
*cb_cls)
+ GNUNET_TESTING_NotifyCompletion cb,
+ void *cb_cls)
{
char *arg;
+
d->dead_cb = cb;
d->dead_cb_cls = cb_cls;
- GNUNET_assert(d->running == GNUNET_YES);
+ GNUNET_assert (d->running == GNUNET_YES);
if (d->phase == SP_CONFIG_UPDATE)
- {
- GNUNET_SCHEDULER_cancel (d->task);
- d->phase = SP_START_DONE;
- }
+ {
+ GNUNET_SCHEDULER_cancel (d->task);
+ d->phase = SP_START_DONE;
+ }
#if DEBUG_TESTING
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
_("Terminating peer `%4s'\n"), GNUNET_i2s (&d->id));
#endif
if (d->churned_services != NULL)
- {
- d->dead_cb(d->dead_cb_cls, "A service has already been turned off!!");
- return;
- }
+ {
+ d->dead_cb (d->dead_cb_cls, "A service has already been turned off!!");
+ return;
+ }
d->phase = SP_SERVICE_SHUTDOWN_START;
- d->churned_services = GNUNET_strdup(service);
- d->max_timeout = GNUNET_TIME_relative_to_absolute(timeout);
+ d->churned_services = GNUNET_strdup (service);
+ d->max_timeout = GNUNET_TIME_relative_to_absolute (timeout);
/* Check if this is a local or remote process */
if (NULL != d->hostname)
- {
+ {
#if DEBUG_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Stopping gnunet-arm with config `%s' on host `%s'.\n",
- d->cfgfile, d->hostname);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Stopping gnunet-arm with config `%s' on host `%s'.\n",
+ d->cfgfile, d->hostname);
#endif
- if (d->username != NULL)
- GNUNET_asprintf (&arg, "address@hidden", d->username, d->hostname);
- else
- arg = GNUNET_strdup (d->hostname);
+ if (d->username != NULL)
+ GNUNET_asprintf (&arg, "address@hidden", d->username, d->hostname);
+ else
+ arg = GNUNET_strdup (d->hostname);
- d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh",
+ d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh",
#if !DEBUG_TESTING
- "-q",
+ "-q",
#endif
- arg, "gnunet-arm",
+ arg, "gnunet-arm",
#if DEBUG_TESTING
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", d->cfgfile, "-k", service, "-q",
- "-T",
GNUNET_TIME_relative_to_string(timeout),
- NULL);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Stopping gnunet-arm with command ssh %s gnunet-arm -c %s -k
%s -q\n",
- arg, "gnunet-arm", d->cfgfile, service);
- GNUNET_free (arg);
- }
+ "-c", d->cfgfile, "-k", service, "-q",
+ "-T",
+ GNUNET_TIME_relative_to_string
(timeout),
+ NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Stopping gnunet-arm with command ssh %s gnunet-arm -c %s -k
%s -q\n",
+ arg, "gnunet-arm", d->cfgfile, service);
+ GNUNET_free (arg);
+ }
else
- {
+ {
#if DEBUG_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Stopping gnunet-arm with config `%s' locally.\n",
- d->cfgfile);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Stopping gnunet-arm with config `%s' locally.\n", d->cfgfile);
#endif
- d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm",
- "gnunet-arm",
+ d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", "gnunet-arm",
#if DEBUG_TESTING
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", d->cfgfile, "-k", service, "-q",
- "-T",
GNUNET_TIME_relative_to_string(timeout),
- NULL);
- }
+ "-c", d->cfgfile, "-k", service, "-q",
+ "-T",
+ GNUNET_TIME_relative_to_string
(timeout),
+ NULL);
+ }
d->max_timeout = GNUNET_TIME_relative_to_absolute (timeout);
d->task = GNUNET_SCHEDULER_add_now (&start_fsm, d);
@@ -1702,51 +1691,52 @@
{
char *arg;
char *del_arg;
+
d->dead_cb = cb;
d->dead_cb_cls = cb_cls;
if (NULL != d->cb)
- {
+ {
#if DEBUG_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Setting d->dead on peer `%4s'\n"), GNUNET_i2s (&d->id));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ _("Setting d->dead on peer `%4s'\n"), GNUNET_i2s (&d->id));
#endif
- d->dead = GNUNET_YES;
- return;
- }
+ d->dead = GNUNET_YES;
+ return;
+ }
if ((d->running == GNUNET_NO) && (d->churn == GNUNET_YES)) /* Peer has
already been stopped in churn context! */
+ {
+ /* Free what was left from churning! */
+ GNUNET_assert (d->cfg != NULL);
+ GNUNET_CONFIGURATION_destroy (d->cfg);
+ if (delete_files == GNUNET_YES)
{
- /* Free what was left from churning! */
- GNUNET_assert (d->cfg != NULL);
- GNUNET_CONFIGURATION_destroy (d->cfg);
- if (delete_files == GNUNET_YES)
- {
- if (0 != UNLINK (d->cfgfile))
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "unlink");
- }
- }
- GNUNET_free (d->cfgfile);
- GNUNET_free_non_null (d->hostname);
- GNUNET_free_non_null (d->username);
- if (NULL != d->dead_cb)
- d->dead_cb (d->dead_cb_cls, NULL);
- GNUNET_free (d);
- return;
+ if (0 != UNLINK (d->cfgfile))
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "unlink");
+ }
}
+ GNUNET_free (d->cfgfile);
+ GNUNET_free_non_null (d->hostname);
+ GNUNET_free_non_null (d->username);
+ if (NULL != d->dead_cb)
+ d->dead_cb (d->dead_cb_cls, NULL);
+ GNUNET_free (d);
+ return;
+ }
del_arg = NULL;
if (delete_files == GNUNET_YES)
- {
- GNUNET_asprintf (&del_arg, "-d");
- }
+ {
+ GNUNET_asprintf (&del_arg, "-d");
+ }
if (d->phase == SP_CONFIG_UPDATE)
- {
- GNUNET_SCHEDULER_cancel (d->task);
- d->phase = SP_START_DONE;
- }
+ {
+ GNUNET_SCHEDULER_cancel (d->task);
+ d->phase = SP_START_DONE;
+ }
/** Move this call to scheduled shutdown as fix for CORE_connect calling
daemon_stop?
if (d->server != NULL)
{
@@ -1764,58 +1754,58 @@
if (allow_restart == GNUNET_YES)
d->churn = GNUNET_YES;
if (d->th != NULL)
- {
- GNUNET_TRANSPORT_get_hello_cancel (d->th, &process_hello, d);
- GNUNET_TRANSPORT_disconnect (d->th);
- d->th = NULL;
- }
+ {
+ GNUNET_TRANSPORT_get_hello_cancel (d->th, &process_hello, d);
+ GNUNET_TRANSPORT_disconnect (d->th);
+ d->th = NULL;
+ }
/* Check if this is a local or remote process */
if (NULL != d->hostname)
- {
+ {
#if DEBUG_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Stopping gnunet-arm with config `%s' on host `%s'.\n",
- d->cfgfile, d->hostname);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Stopping gnunet-arm with config `%s' on host `%s'.\n",
+ d->cfgfile, d->hostname);
#endif
- if (d->username != NULL)
- GNUNET_asprintf (&arg, "address@hidden", d->username, d->hostname);
- else
- arg = GNUNET_strdup (d->hostname);
+ if (d->username != NULL)
+ GNUNET_asprintf (&arg, "address@hidden", d->username, d->hostname);
+ else
+ arg = GNUNET_strdup (d->hostname);
- d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh",
+ d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh",
#if !DEBUG_TESTING
- "-q",
+ "-q",
#endif
- arg, "gnunet-arm",
+ arg, "gnunet-arm",
#if DEBUG_TESTING
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", d->cfgfile, "-e", "-q",
- "-T",
GNUNET_TIME_relative_to_string(timeout),
- del_arg, NULL);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Stopping gnunet-arm with command ssh %s gnunet-arm -c %s -e
-q %s\n",
- arg, "gnunet-arm", d->cfgfile, del_arg);
- /* Use -e to end arm, and -d to remove temp files */
- GNUNET_free (arg);
- }
+ "-c", d->cfgfile, "-e", "-q",
+ "-T",
+ GNUNET_TIME_relative_to_string
(timeout),
+ del_arg, NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Stopping gnunet-arm with command ssh %s gnunet-arm -c %s -e
-q %s\n",
+ arg, "gnunet-arm", d->cfgfile, del_arg);
+ /* Use -e to end arm, and -d to remove temp files */
+ GNUNET_free (arg);
+ }
else
- {
+ {
#if DEBUG_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Stopping gnunet-arm with config `%s' locally.\n",
- d->cfgfile);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Stopping gnunet-arm with config `%s' locally.\n", d->cfgfile);
#endif
- d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm",
- "gnunet-arm",
+ d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", "gnunet-arm",
#if DEBUG_TESTING
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", d->cfgfile, "-e", "-q",
- "-T",
GNUNET_TIME_relative_to_string(timeout),
- del_arg, NULL);
- }
+ "-c", d->cfgfile, "-e", "-q",
+ "-T",
+ GNUNET_TIME_relative_to_string
(timeout),
+ del_arg, NULL);
+ }
GNUNET_free_non_null (del_arg);
d->max_timeout = GNUNET_TIME_relative_to_absolute (timeout);
@@ -1840,30 +1830,30 @@
char *arg;
if (d->phase != SP_START_DONE)
- {
- if (NULL != cb)
- cb (cb_cls,
- _
- ("Peer not yet running, can not change configuration at this
point."));
- return;
- }
+ {
+ if (NULL != cb)
+ cb (cb_cls,
+ _
+ ("Peer not yet running, can not change configuration at this
point."));
+ return;
+ }
/* 1) write configuration to temporary file */
if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, d->cfgfile))
- {
- if (NULL != cb)
- cb (cb_cls, _("Failed to write new configuration to disk."));
- return;
- }
+ {
+ if (NULL != cb)
+ cb (cb_cls, _("Failed to write new configuration to disk."));
+ return;
+ }
/* 2) copy file to remote host (if necessary) */
if (NULL == d->hostname)
- {
- /* signal success */
- if (NULL != cb)
- cb (cb_cls, NULL);
- return;
- }
+ {
+ /* signal success */
+ if (NULL != cb)
+ cb (cb_cls, NULL);
+ return;
+ }
#if DEBUG_TESTING
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Copying updated configuration file to remote host `%s'.\n",
@@ -1881,21 +1871,21 @@
d->cfgfile, arg, NULL);
GNUNET_free (arg);
if (NULL == d->proc)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _
- ("Could not start `%s' process to copy configuration
file.\n"),
- "scp");
- if (NULL != cb)
- cb (cb_cls, _("Failed to copy new configuration to remote machine."));
- d->phase = SP_START_DONE;
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _
+ ("Could not start `%s' process to copy configuration file.\n"),
+ "scp");
+ if (NULL != cb)
+ cb (cb_cls, _("Failed to copy new configuration to remote machine."));
+ d->phase = SP_START_DONE;
+ return;
+ }
d->update_cb = cb;
d->update_cb_cls = cb_cls;
d->task
- = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT,
- &start_fsm, d);
+ = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT,
+ &start_fsm, d);
}
@@ -2004,39 +1994,39 @@
* @param tc reason tells us if we succeeded or failed
*/
static void
-notify_connect_result (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+notify_connect_result (void *cls, const struct GNUNET_SCHEDULER_TaskContext
*tc)
{
struct ConnectContext *ctx = cls;
+
ctx->timeout_task = GNUNET_SCHEDULER_NO_TASK;
if (ctx->hello_send_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (ctx->hello_send_task);
- ctx->hello_send_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (ctx->hello_send_task);
+ ctx->hello_send_task = GNUNET_SCHEDULER_NO_TASK;
+ }
if (ctx->connect_request_handle != NULL)
- {
- GNUNET_CORE_peer_request_connect_cancel (ctx->connect_request_handle);
- ctx->connect_request_handle = NULL;
- }
+ {
+ GNUNET_CORE_peer_request_connect_cancel (ctx->connect_request_handle);
+ ctx->connect_request_handle = NULL;
+ }
- if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- {
- if (ctx->d1th != NULL)
- GNUNET_TRANSPORT_disconnect (ctx->d1th);
- ctx->d1th = NULL;
- if (ctx->d1core != NULL)
- GNUNET_CORE_disconnect (ctx->d1core);
+ if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
+ {
+ if (ctx->d1th != NULL)
+ GNUNET_TRANSPORT_disconnect (ctx->d1th);
+ ctx->d1th = NULL;
+ if (ctx->d1core != NULL)
+ GNUNET_CORE_disconnect (ctx->d1core);
#if CONNECT_CORE2
- if (ctx->d2core != NULL)
- GNUNET_CORE_disconnect (ctx->d2core);
- ctx->d2core = NULL;
+ if (ctx->d2core != NULL)
+ GNUNET_CORE_disconnect (ctx->d2core);
+ ctx->d2core = NULL;
#endif
- ctx->d1core = NULL;
- GNUNET_free (ctx);
- return;
- }
+ ctx->d1core = NULL;
+ GNUNET_free (ctx);
+ return;
+ }
if (ctx->d1th != NULL)
GNUNET_TRANSPORT_disconnect (ctx->d1th);
@@ -2046,38 +2036,37 @@
ctx->d1core = NULL;
if (ctx->connected == GNUNET_YES)
+ {
+ if (ctx->cb != NULL)
{
- if (ctx->cb != NULL)
- {
- ctx->cb (ctx->cb_cls,
- &ctx->d1->id,
- &ctx->d2->id,
- ctx->distance,
- ctx->d1->cfg, ctx->d2->cfg, ctx->d1, ctx->d2, NULL);
- }
+ ctx->cb (ctx->cb_cls,
+ &ctx->d1->id,
+ &ctx->d2->id,
+ ctx->distance,
+ ctx->d1->cfg, ctx->d2->cfg, ctx->d1, ctx->d2, NULL);
}
+ }
else if (ctx->connect_attempts > 0)
+ {
+ ctx->d1core_ready = GNUNET_NO;
+#if CONNECT_CORE2
+ if (ctx->d2core != NULL)
{
- ctx->d1core_ready = GNUNET_NO;
-#if CONNECT_CORE2
- if (ctx->d2core != NULL)
- {
- GNUNET_CORE_disconnect (ctx->d2core);
- ctx->d2core = NULL;
- }
+ GNUNET_CORE_disconnect (ctx->d2core);
+ ctx->d2core = NULL;
+ }
#endif
- GNUNET_SCHEDULER_add_now (&reattempt_daemons_connect, ctx);
- return;
- }
+ GNUNET_SCHEDULER_add_now (&reattempt_daemons_connect, ctx);
+ return;
+ }
else
+ {
+ if (ctx->cb != NULL)
{
- if (ctx->cb != NULL)
- {
- ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg,
- ctx->d2->cfg, ctx->d1, ctx->d2,
- _("Peers failed to connect"));
- }
+ ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg,
+ ctx->d2->cfg, ctx->d1, ctx->d2, _("Peers failed to connect"));
}
+ }
GNUNET_free (ctx);
}
@@ -2100,24 +2089,23 @@
#if DEBUG_TESTING
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Connected peer %s to peer %s\n",
- ctx->d1->shortname, GNUNET_i2s(peer));
+ "Connected peer %s to peer %s\n",
+ ctx->d1->shortname, GNUNET_i2s (peer));
#endif
if (0 == memcmp (&ctx->d2->id, peer, sizeof (struct GNUNET_PeerIdentity)))
+ {
+
+ ctx->connected = GNUNET_YES;
+ ctx->distance = 0; /* FIXME: distance */
+ if (ctx->hello_send_task != GNUNET_SCHEDULER_NO_TASK)
{
-
- ctx->connected = GNUNET_YES;
- ctx->distance = 0; /* FIXME: distance */
- if (ctx->hello_send_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel(ctx->hello_send_task);
- ctx->hello_send_task = GNUNET_SCHEDULER_NO_TASK;
- }
- GNUNET_SCHEDULER_cancel (ctx->timeout_task);
- ctx->timeout_task = GNUNET_SCHEDULER_add_now (¬ify_connect_result,
- ctx);
+ GNUNET_SCHEDULER_cancel (ctx->hello_send_task);
+ ctx->hello_send_task = GNUNET_SCHEDULER_NO_TASK;
}
+ GNUNET_SCHEDULER_cancel (ctx->timeout_task);
+ ctx->timeout_task = GNUNET_SCHEDULER_add_now (¬ify_connect_result, ctx);
+ }
}
#if CONNECT_CORE2
@@ -2137,13 +2125,12 @@
struct ConnectContext *ctx = cls;
if (memcmp (&ctx->d2->id, peer, sizeof (struct GNUNET_PeerIdentity)) == 0)
- {
- ctx->connected = GNUNET_YES;
- ctx->distance = 0; /* FIXME: distance */
- GNUNET_SCHEDULER_cancel (ctx->timeout_task);
- ctx->timeout_task = GNUNET_SCHEDULER_add_now (¬ify_connect_result,
- ctx);
- }
+ {
+ ctx->connected = GNUNET_YES;
+ ctx->distance = 0; /* FIXME: distance */
+ GNUNET_SCHEDULER_cancel (ctx->timeout_task);
+ ctx->timeout_task = GNUNET_SCHEDULER_add_now (¬ify_connect_result, ctx);
+ }
}
#endif
@@ -2155,8 +2142,7 @@
* @param success was the request successful?
*/
void
-core_connect_request_cont (void *cls,
- int success)
+core_connect_request_cont (void *cls, int success)
{
struct ConnectContext *ctx = cls;
@@ -2168,37 +2154,38 @@
{
struct ConnectContext *ctx = cls;
struct GNUNET_MessageHeader *hello;
+
ctx->hello_send_task = GNUNET_SCHEDULER_NO_TASK;
- if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
+ if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
return;
if ((ctx->d1core_ready == GNUNET_YES) && (ctx->d2->hello != NULL)
&& (NULL != GNUNET_HELLO_get_header (ctx->d2->hello))
- && (ctx->d1->phase == SP_START_DONE)
- && (ctx->d2->phase == SP_START_DONE))
- {
- hello = GNUNET_HELLO_get_header (ctx->d2->hello);
- GNUNET_assert (hello != NULL);
+ && (ctx->d1->phase == SP_START_DONE) && (ctx->d2->phase ==
SP_START_DONE))
+ {
+ hello = GNUNET_HELLO_get_header (ctx->d2->hello);
+ GNUNET_assert (hello != NULL);
#if DEBUG_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Offering hello of %s to %s\n",
ctx->d2->shortname, ctx->d1->shortname);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Offering hello of %s to %s\n",
+ ctx->d2->shortname, ctx->d1->shortname);
#endif
- GNUNET_TRANSPORT_offer_hello (ctx->d1th, hello, NULL, NULL);
- GNUNET_assert (ctx->d1core != NULL);
- ctx->connect_request_handle =
+ GNUNET_TRANSPORT_offer_hello (ctx->d1th, hello, NULL, NULL);
+ GNUNET_assert (ctx->d1core != NULL);
+ ctx->connect_request_handle =
GNUNET_CORE_peer_request_connect (ctx->d1core,
&ctx->d2->id,
&core_connect_request_cont, ctx);
#if DEBUG_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Sending connect request to CORE of %s for peer %s\n",
- GNUNET_i2s (&ctx->d1->id),
- GNUNET_h2s (&ctx->d2->id.hashPubKey));
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Sending connect request to CORE of %s for peer %s\n",
+ GNUNET_i2s (&ctx->d1->id),
+ GNUNET_h2s (&ctx->d2->id.hashPubKey));
#endif
- ctx->timeout_hello =
+ ctx->timeout_hello =
GNUNET_TIME_relative_add (ctx->timeout_hello,
GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_MILLISECONDS, 500));
- }
+ }
ctx->hello_send_task = GNUNET_SCHEDULER_add_delayed (ctx->timeout_hello,
&send_hello, ctx);
}
@@ -2213,30 +2200,29 @@
*/
void
core_init_notify (void *cls,
- struct GNUNET_CORE_Handle * server,
- const struct GNUNET_PeerIdentity *
- my_identity,
+ struct GNUNET_CORE_Handle *server,
+ const struct GNUNET_PeerIdentity *my_identity,
const struct
- GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *
- publicKey)
+ GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
{
struct ConnectContext *connect_ctx = cls;
+
connect_ctx->d1core_ready = GNUNET_YES;
if (connect_ctx->send_hello == GNUNET_NO)
- {
- connect_ctx->connect_request_handle =
- GNUNET_CORE_peer_request_connect (connect_ctx->d1core,
- &connect_ctx->d2->id,
- &core_connect_request_cont,
connect_ctx);
- GNUNET_assert(connect_ctx->connect_request_handle != NULL);
+ {
+ connect_ctx->connect_request_handle =
+ GNUNET_CORE_peer_request_connect (connect_ctx->d1core,
+ &connect_ctx->d2->id,
+ &core_connect_request_cont,
+ connect_ctx);
+ GNUNET_assert (connect_ctx->connect_request_handle != NULL);
#if DEBUG_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending connect request to CORE of %s for peer %s\n",
- connect_ctx->d1->shortname,
- connect_ctx->d2->shortname);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending connect request to CORE of %s for peer %s\n",
+ connect_ctx->d1->shortname, connect_ctx->d2->shortname);
#endif
- }
+ }
}
@@ -2246,11 +2232,12 @@
const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct ConnectContext *ctx = cls;
- if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- {
- GNUNET_free(ctx);
- return;
- }
+
+ if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
+ {
+ GNUNET_free (ctx);
+ return;
+ }
#if DEBUG_TESTING_RECONNECT
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"re-attempting connect of peer %s to peer %s\n",
@@ -2266,72 +2253,77 @@
NULL, GNUNET_NO,
NULL, GNUNET_NO, no_handlers);
if (ctx->d1core == NULL)
- {
- if (NULL != ctx->cb)
- ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg,
- ctx->d2->cfg, ctx->d1, ctx->d2,
- _("Failed to connect to core service of first peer!\n"));
- GNUNET_free (ctx);
- return;
- }
+ {
+ if (NULL != ctx->cb)
+ ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg,
+ ctx->d2->cfg, ctx->d1, ctx->d2,
+ _("Failed to connect to core service of first peer!\n"));
+ GNUNET_free (ctx);
+ return;
+ }
/* Don't know reason for initial connect failure, update the HELLO for the
second peer */
if (NULL != ctx->d2->hello)
+ {
+ GNUNET_free (ctx->d2->hello);
+ ctx->d2->hello = NULL;
+ if (NULL != ctx->d2->th)
{
- GNUNET_free(ctx->d2->hello);
- ctx->d2->hello = NULL;
- if (NULL != ctx->d2->th)
- {
- GNUNET_TRANSPORT_get_hello_cancel(ctx->d2->th, &process_hello,
ctx->d2);
- GNUNET_TRANSPORT_disconnect(ctx->d2->th);
- }
- ctx->d2->th = GNUNET_TRANSPORT_connect (ctx->d2->cfg, &ctx->d2->id,
NULL, NULL, NULL, NULL);
- GNUNET_assert(ctx->d2->th != NULL);
- GNUNET_TRANSPORT_get_hello (ctx->d2->th, &process_hello, ctx->d2);
+ GNUNET_TRANSPORT_get_hello_cancel (ctx->d2->th, &process_hello, ctx->d2);
+ GNUNET_TRANSPORT_disconnect (ctx->d2->th);
}
+ ctx->d2->th =
+ GNUNET_TRANSPORT_connect (ctx->d2->cfg, &ctx->d2->id, NULL, NULL, NULL,
+ NULL);
+ GNUNET_assert (ctx->d2->th != NULL);
+ GNUNET_TRANSPORT_get_hello (ctx->d2->th, &process_hello, ctx->d2);
+ }
if ((NULL == ctx->d2->hello) && (ctx->d2->th == NULL))
+ {
+ ctx->d2->th =
+ GNUNET_TRANSPORT_connect (ctx->d2->cfg, &ctx->d2->id, NULL, NULL, NULL,
+ NULL);
+ if (ctx->d2->th == NULL)
{
- ctx->d2->th = GNUNET_TRANSPORT_connect (ctx->d2->cfg, &ctx->d2->id,
NULL, NULL, NULL, NULL);
- if (ctx->d2->th == NULL)
- {
- GNUNET_CORE_disconnect (ctx->d1core);
- GNUNET_free (ctx);
- if (NULL != ctx->cb)
- ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg,
ctx->d2->cfg, ctx->d1, ctx->d2,
- _("Failed to connect to transport service!\n"));
- return;
- }
- GNUNET_TRANSPORT_get_hello (ctx->d2->th, &process_hello, ctx->d2);
+ GNUNET_CORE_disconnect (ctx->d1core);
+ GNUNET_free (ctx);
+ if (NULL != ctx->cb)
+ ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg,
+ ctx->d2->cfg, ctx->d1, ctx->d2,
+ _("Failed to connect to transport service!\n"));
+ return;
}
+ GNUNET_TRANSPORT_get_hello (ctx->d2->th, &process_hello, ctx->d2);
+ }
if (ctx->send_hello == GNUNET_YES)
+ {
+ ctx->d1th = GNUNET_TRANSPORT_connect (ctx->d1->cfg,
+ &ctx->d1->id,
+ ctx->d1, NULL, NULL, NULL);
+ if (ctx->d1th == NULL)
{
- ctx->d1th = GNUNET_TRANSPORT_connect (ctx->d1->cfg,
- &ctx->d1->id,
- ctx->d1, NULL, NULL, NULL);
- if (ctx->d1th == NULL)
- {
- GNUNET_CORE_disconnect (ctx->d1core);
- GNUNET_free (ctx);
- if (NULL != ctx->cb)
- ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg,
- ctx->d2->cfg, ctx->d1, ctx->d2,
- _("Failed to connect to transport service!\n"));
- return;
- }
- ctx->hello_send_task = GNUNET_SCHEDULER_add_now (&send_hello, ctx);
+ GNUNET_CORE_disconnect (ctx->d1core);
+ GNUNET_free (ctx);
+ if (NULL != ctx->cb)
+ ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg,
+ ctx->d2->cfg, ctx->d1, ctx->d2,
+ _("Failed to connect to transport service!\n"));
+ return;
}
+ ctx->hello_send_task = GNUNET_SCHEDULER_add_now (&send_hello, ctx);
+ }
else
- {
- ctx->connect_request_handle =
+ {
+ ctx->connect_request_handle =
GNUNET_CORE_peer_request_connect (ctx->d1core,
&ctx->d2->id,
&core_connect_request_cont, ctx);
- }
+ }
ctx->timeout_task =
- GNUNET_SCHEDULER_add_delayed (ctx->relative_timeout,
- ¬ify_connect_result, ctx);
+ GNUNET_SCHEDULER_add_delayed (ctx->relative_timeout,
+ ¬ify_connect_result, ctx);
}
/**
@@ -2354,79 +2346,85 @@
if ((peer != NULL) &&
(0 == memcmp (&ctx->d2->id, peer, sizeof (struct GNUNET_PeerIdentity))))
+ {
+ ctx->connected = GNUNET_YES;
+ ctx->distance = 0; /* FIXME: distance */
+ return;
+ }
+ else if (peer == NULL) /* End of iteration over peers */
+ {
+ if (ctx->connected == GNUNET_YES)
{
- ctx->connected = GNUNET_YES;
- ctx->distance = 0; /* FIXME: distance */
+ ctx->timeout_task = GNUNET_SCHEDULER_add_now (¬ify_connect_result,
+ ctx);
return;
}
- else if (peer == NULL) /* End of iteration over peers */
+
+ /* Peer not already connected, need to schedule connect request! */
+ if (ctx->d1core == NULL)
{
- if (ctx->connected == GNUNET_YES)
- {
- ctx->timeout_task = GNUNET_SCHEDULER_add_now (¬ify_connect_result,
- ctx);
- return;
- }
-
- /* Peer not already connected, need to schedule connect request! */
- if (ctx->d1core == NULL)
- {
#if DEBUG_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peers are NOT connected, connecting to core!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Peers are NOT connected, connecting to core!\n");
#endif
- ctx->d1core = GNUNET_CORE_connect (ctx->d1->cfg, 1,
- ctx,
- &core_init_notify,
- &connect_notify, NULL, NULL,
- NULL, GNUNET_NO,
- NULL, GNUNET_NO, no_handlers);
- }
+ ctx->d1core = GNUNET_CORE_connect (ctx->d1->cfg, 1,
+ ctx,
+ &core_init_notify,
+ &connect_notify, NULL, NULL,
+ NULL, GNUNET_NO,
+ NULL, GNUNET_NO, no_handlers);
+ }
- if (ctx->d1core == NULL)
- {
- GNUNET_free (ctx);
- if (NULL != ctx->cb)
- ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg,
ctx->d2->cfg, ctx->d1, ctx->d2,
- _("Failed to connect to core service of first peer!\n"));
- return;
- }
+ if (ctx->d1core == NULL)
+ {
+ GNUNET_free (ctx);
+ if (NULL != ctx->cb)
+ ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg,
+ ctx->d2->cfg, ctx->d1, ctx->d2,
+ _("Failed to connect to core service of first peer!\n"));
+ return;
+ }
- if ((NULL == ctx->d2->hello) && (ctx->d2->th == NULL)) /* Do not yet
have the second peer's hello, set up a task to get it */
- {
- ctx->d2->th = GNUNET_TRANSPORT_connect (ctx->d2->cfg, &ctx->d2->id,
NULL, NULL, NULL, NULL);
- if (ctx->d2->th == NULL)
- {
- GNUNET_CORE_disconnect (ctx->d1core);
- GNUNET_free (ctx);
- if (NULL != ctx->cb)
- ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0,
ctx->d1->cfg, ctx->d2->cfg, ctx->d1, ctx->d2,
- _("Failed to connect to transport service!\n"));
- return;
- }
- GNUNET_TRANSPORT_get_hello (ctx->d2->th, &process_hello, ctx->d2);
- }
+ if ((NULL == ctx->d2->hello) && (ctx->d2->th == NULL)) /* Do not yet
have the second peer's hello, set up a task to get it */
+ {
+ ctx->d2->th =
+ GNUNET_TRANSPORT_connect (ctx->d2->cfg, &ctx->d2->id, NULL, NULL,
+ NULL, NULL);
+ if (ctx->d2->th == NULL)
+ {
+ GNUNET_CORE_disconnect (ctx->d1core);
+ GNUNET_free (ctx);
+ if (NULL != ctx->cb)
+ ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg,
+ ctx->d2->cfg, ctx->d1, ctx->d2,
+ _("Failed to connect to transport service!\n"));
+ return;
+ }
+ GNUNET_TRANSPORT_get_hello (ctx->d2->th, &process_hello, ctx->d2);
+ }
- if (ctx->send_hello == GNUNET_YES)
- {
- ctx->d1th = GNUNET_TRANSPORT_connect (ctx->d1->cfg,
- &ctx->d1->id, ctx->d1, NULL,
NULL, NULL);
- if (ctx->d1th == NULL)
- {
- GNUNET_CORE_disconnect (ctx->d1core);
- GNUNET_free (ctx);
- if (NULL != ctx->cb)
- ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0,
ctx->d1->cfg, ctx->d2->cfg, ctx->d1, ctx->d2,
- _("Failed to connect to transport service!\n"));
- return;
- }
- ctx->hello_send_task = GNUNET_SCHEDULER_add_now (&send_hello, ctx);
- }
+ if (ctx->send_hello == GNUNET_YES)
+ {
+ ctx->d1th = GNUNET_TRANSPORT_connect (ctx->d1->cfg,
+ &ctx->d1->id, ctx->d1, NULL, NULL,
+ NULL);
+ if (ctx->d1th == NULL)
+ {
+ GNUNET_CORE_disconnect (ctx->d1core);
+ GNUNET_free (ctx);
+ if (NULL != ctx->cb)
+ ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg,
+ ctx->d2->cfg, ctx->d1, ctx->d2,
+ _("Failed to connect to transport service!\n"));
+ return;
+ }
+ ctx->hello_send_task = GNUNET_SCHEDULER_add_now (&send_hello, ctx);
+ }
- ctx->timeout_task =
+ ctx->timeout_task =
GNUNET_SCHEDULER_add_delayed (ctx->relative_timeout,
¬ify_connect_result, ctx);
- }
+ }
}
@@ -2456,20 +2454,21 @@
struct ConnectContext *ctx;
if ((d1->running == GNUNET_NO) || (d2->running == GNUNET_NO))
- {
- if (NULL != cb)
- cb (cb_cls, &d1->id, &d2->id, 0, d1->cfg, d2->cfg, d1, d2,
- _("Peers are not fully running yet, can not connect!\n"));
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Peers are not up!\n");
- return;
- }
+ {
+ if (NULL != cb)
+ cb (cb_cls, &d1->id, &d2->id, 0, d1->cfg, d2->cfg, d1, d2,
+ _("Peers are not fully running yet, can not connect!\n"));
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Peers are not up!\n");
+ return;
+ }
ctx = GNUNET_malloc (sizeof (struct ConnectContext));
ctx->d1 = d1;
ctx->d2 = d2;
ctx->timeout_hello =
- GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 500);
- ctx->relative_timeout = GNUNET_TIME_relative_divide(timeout,
max_connect_attempts);
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 500);
+ ctx->relative_timeout =
+ GNUNET_TIME_relative_divide (timeout, max_connect_attempts);
ctx->cb = cb;
ctx->cb_cls = cb_cls;
ctx->connect_attempts = max_connect_attempts;
@@ -2482,8 +2481,10 @@
#endif
/* Core is up! Iterate over all _known_ peers first to check if we are
already connected to the peer! */
- GNUNET_assert(GNUNET_OK == GNUNET_CORE_is_peer_connected (ctx->d1->cfg,
&ctx->d2->id, &core_initial_iteration, ctx));
- /*GNUNET_assert(GNUNET_OK == GNUNET_CORE_iterate_peers (ctx->d1->cfg,
&core_initial_iteration, ctx));*/
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CORE_is_peer_connected (ctx->d1->cfg, &ctx->d2->id,
+ &core_initial_iteration, ctx));
+ /*GNUNET_assert(GNUNET_OK == GNUNET_CORE_iterate_peers (ctx->d1->cfg,
&core_initial_iteration, ctx)); */
}
/* end of testing.c */
Modified: gnunet/src/testing/testing_group.c
===================================================================
--- gnunet/src/testing/testing_group.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/testing/testing_group.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -88,9 +88,11 @@
* in a certain topology.
*/
typedef unsigned int
-(*GNUNET_TESTING_ConnectionProcessor)(struct GNUNET_TESTING_PeerGroup * pg,
- unsigned int first, unsigned int second,
- enum PeerLists list, unsigned int check);
+ (*GNUNET_TESTING_ConnectionProcessor) (struct GNUNET_TESTING_PeerGroup *
pg,
+ unsigned int first,
+ unsigned int second,
+ enum PeerLists list,
+ unsigned int check);
/**
* Context for handling churning a peer group
@@ -1015,10 +1017,10 @@
*/
static void
hash_from_uid (uint32_t uid, GNUNET_HashCode * hash)
- {
- memset (hash, 0, sizeof (GNUNET_HashCode));
- *((uint32_t *) hash) = uid;
- }
+{
+ memset (hash, 0, sizeof (GNUNET_HashCode));
+ *((uint32_t *) hash) = uid;
+}
/**
* Convert hash code to unique ID.
@@ -1028,15 +1030,15 @@
*/
static void
uid_from_hash (const GNUNET_HashCode * hash, uint32_t * uid)
- {
- memcpy (uid, hash, sizeof (uint32_t));
- }
+{
+ memcpy (uid, hash, sizeof (uint32_t));
+}
#endif
#if USE_SEND_HELLOS
-static struct GNUNET_CORE_MessageHandler no_handlers[] =
- {
- { NULL, 0, 0}};
+static struct GNUNET_CORE_MessageHandler no_handlers[] = {
+ {NULL, 0, 0}
+};
#endif
/**
@@ -1050,20 +1052,21 @@
* @return the progress meter
*/
static struct ProgressMeter *
-create_meter(unsigned int total, char * start_string, int print)
+create_meter (unsigned int total, char *start_string, int print)
{
struct ProgressMeter *ret;
- ret = GNUNET_malloc(sizeof(struct ProgressMeter));
+
+ ret = GNUNET_malloc (sizeof (struct ProgressMeter));
ret->print = print;
ret->total = total;
ret->modnum = total / 4;
- if (ret->modnum == 0) /* Divide by zero check */
+ if (ret->modnum == 0) /* Divide by zero check */
ret->modnum = 1;
ret->dotnum = (total / 50) + 1;
if (start_string != NULL)
- ret->startup_string = GNUNET_strdup(start_string);
+ ret->startup_string = GNUNET_strdup (start_string);
else
- ret->startup_string = GNUNET_strdup("");
+ ret->startup_string = GNUNET_strdup ("");
return ret;
}
@@ -1077,27 +1080,27 @@
* GNUNET_NO if more items expected
*/
static int
-update_meter(struct ProgressMeter *meter)
+update_meter (struct ProgressMeter *meter)
{
if (meter->print == GNUNET_YES)
+ {
+ if (meter->completed % meter->modnum == 0)
{
- if (meter->completed % meter->modnum == 0)
- {
- if (meter->completed == 0)
- {
- fprintf (stdout, "%sProgress: [0%%", meter->startup_string);
- }
- else
- fprintf (stdout, "%d%%", (int) (((float) meter->completed
- / meter->total) * 100));
- }
- else if (meter->completed % meter->dotnum == 0)
- fprintf (stdout, ".");
+ if (meter->completed == 0)
+ {
+ fprintf (stdout, "%sProgress: [0%%", meter->startup_string);
+ }
+ else
+ fprintf (stdout, "%d%%", (int) (((float) meter->completed
+ / meter->total) * 100));
+ }
+ else if (meter->completed % meter->dotnum == 0)
+ fprintf (stdout, ".");
- if (meter->completed + 1 == meter->total)
- fprintf (stdout, "%d%%]\n", 100);
- fflush (stdout);
- }
+ if (meter->completed + 1 == meter->total)
+ fprintf (stdout, "%d%%]\n", 100);
+ fflush (stdout);
+ }
meter->completed++;
if (meter->completed == meter->total)
@@ -1116,7 +1119,7 @@
* GNUNET_SYSERR on error
*/
static int
-reset_meter(struct ProgressMeter *meter)
+reset_meter (struct ProgressMeter *meter)
{
if (meter == NULL)
return GNUNET_SYSERR;
@@ -1131,7 +1134,7 @@
* @param meter the meter to free
*/
static void
-free_meter(struct ProgressMeter *meter)
+free_meter (struct ProgressMeter *meter)
{
GNUNET_free_non_null (meter->startup_string);
GNUNET_free (meter);
@@ -1147,14 +1150,13 @@
* known topology, GNUNET_NO if not
*/
int
-GNUNET_TESTING_topology_get(enum GNUNET_TESTING_Topology *topology,
- const char *topology_string)
+GNUNET_TESTING_topology_get (enum GNUNET_TESTING_Topology *topology,
+ const char *topology_string)
{
/**
* Strings representing topologies in enum
*/
- static const char *topology_strings[] =
- {
+ static const char *topology_strings[] = {
/**
* A clique (everyone connected to everyone else).
*/
@@ -1211,20 +1213,22 @@
*/
"FROM_FILE",
- NULL };
+ NULL
+ };
int curr = 0;
+
if (topology_string == NULL)
return GNUNET_NO;
while (topology_strings[curr] != NULL)
+ {
+ if (strcasecmp (topology_strings[curr], topology_string) == 0)
{
- if (strcasecmp (topology_strings[curr], topology_string) == 0)
- {
- *topology = curr;
- return GNUNET_YES;
- }
- curr++;
+ *topology = curr;
+ return GNUNET_YES;
}
+ curr++;
+ }
*topology = GNUNET_TESTING_TOPOLOGY_NONE;
return GNUNET_NO;
}
@@ -1239,15 +1243,14 @@
* topology option, GNUNET_NO if not
*/
int
-GNUNET_TESTING_topology_option_get(
- enum GNUNET_TESTING_TopologyOption
*topology_option,
- const char *topology_string)
+GNUNET_TESTING_topology_option_get (enum GNUNET_TESTING_TopologyOption
+ *topology_option,
+ const char *topology_string)
{
/**
* Options for connecting a topology as strings.
*/
- static const char *topology_option_strings[] =
- {
+ static const char *topology_option_strings[] = {
/**
* Try to connect all peers specified in the topology.
*/
@@ -1283,20 +1286,21 @@
*/
"CONNECT_NONE",
- NULL };
+ NULL
+ };
int curr = 0;
if (topology_string == NULL)
return GNUNET_NO;
while (NULL != topology_option_strings[curr])
+ {
+ if (strcasecmp (topology_option_strings[curr], topology_string) == 0)
{
- if (strcasecmp (topology_option_strings[curr], topology_string) == 0)
- {
- *topology_option = curr;
- return GNUNET_YES;
- }
- curr++;
+ *topology_option = curr;
+ return GNUNET_YES;
}
+ curr++;
+ }
*topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_NONE;
return GNUNET_NO;
}
@@ -1312,8 +1316,8 @@
* @param value value of the option
*/
static void
-update_config(void *cls, const char *section, const char *option,
- const char *value)
+update_config (void *cls, const char *section, const char *option,
+ const char *value)
{
struct UpdateContext *ctx = cls;
unsigned int ival;
@@ -1327,58 +1331,61 @@
GNUNET_asprintf (&per_host_variable, "num_%s_per_host", section);
if ((0 == strcmp (option, "PORT")) && (1 == sscanf (value, "%u", &ival)))
+ {
+ if ((ival != 0) && (GNUNET_YES
+ != GNUNET_CONFIGURATION_get_value_yesno (ctx->orig,
+ "testing",
+
single_variable)))
{
- if ((ival != 0) && (GNUNET_YES
- != GNUNET_CONFIGURATION_get_value_yesno (ctx->orig, "testing",
- single_variable)))
- {
- GNUNET_snprintf (cval, sizeof(cval), "%u", ctx->nport++);
- value = cval;
- }
- else if ((ival != 0) && (GNUNET_YES
- == GNUNET_CONFIGURATION_get_value_yesno (ctx->orig, "testing",
- single_variable))
- && GNUNET_CONFIGURATION_get_value_number (ctx->orig, "testing",
- per_host_variable,
- &num_per_host))
- {
- GNUNET_snprintf (cval, sizeof(cval), "%u", ival + ctx->fdnum
- % num_per_host);
- value = cval;
- }
-
- /* FIXME: REMOVE FOREVER HACK HACK HACK */
- if (0 == strcasecmp (section, "transport-tcp"))
- GNUNET_CONFIGURATION_set_value_string (ctx->ret, section,
"ADVERTISED_PORT", value);
+ GNUNET_snprintf (cval, sizeof (cval), "%u", ctx->nport++);
+ value = cval;
}
+ else if ((ival != 0) && (GNUNET_YES
+ == GNUNET_CONFIGURATION_get_value_yesno
(ctx->orig,
+
"testing",
+
single_variable))
+ && GNUNET_CONFIGURATION_get_value_number (ctx->orig, "testing",
+ per_host_variable,
+ &num_per_host))
+ {
+ GNUNET_snprintf (cval, sizeof (cval), "%u", ival + ctx->fdnum
+ % num_per_host);
+ value = cval;
+ }
+ /* FIXME: REMOVE FOREVER HACK HACK HACK */
+ if (0 == strcasecmp (section, "transport-tcp"))
+ GNUNET_CONFIGURATION_set_value_string (ctx->ret, section,
+ "ADVERTISED_PORT", value);
+ }
+
if (0 == strcmp (option, "UNIXPATH"))
+ {
+ if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_yesno (ctx->orig,
+ "testing",
+ single_variable))
{
- if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_yesno (ctx->orig,
- "testing",
- single_variable))
- {
- GNUNET_snprintf (uval, sizeof(uval), "/tmp/test-service-%s-%u",
- section, ctx->upnum++);
- value = uval;
- }
- else if ((GNUNET_YES
- == GNUNET_CONFIGURATION_get_value_number (ctx->orig, "testing",
- per_host_variable,
- &num_per_host))
- && (num_per_host > 0))
+ GNUNET_snprintf (uval, sizeof (uval), "/tmp/test-service-%s-%u",
+ section, ctx->upnum++);
+ value = uval;
+ }
+ else if ((GNUNET_YES
+ == GNUNET_CONFIGURATION_get_value_number (ctx->orig, "testing",
+ per_host_variable,
+ &num_per_host))
+ && (num_per_host > 0))
- {
- GNUNET_snprintf (uval, sizeof(uval), "/tmp/test-service-%s-%u",
- section, ctx->fdnum % num_per_host);
- value = uval;
- }
+ {
+ GNUNET_snprintf (uval, sizeof (uval), "/tmp/test-service-%s-%u",
+ section, ctx->fdnum % num_per_host);
+ value = uval;
}
+ }
if ((0 == strcmp (option, "HOSTNAME")) && (ctx->hostname != NULL))
- {
- value = ctx->hostname;
- }
+ {
+ value = ctx->hostname;
+ }
GNUNET_free (single_variable);
GNUNET_free (per_host_variable);
GNUNET_CONFIGURATION_set_value_string (ctx->ret, section, option, value);
@@ -1402,9 +1409,9 @@
* @return new configuration, NULL on error
*/
static struct GNUNET_CONFIGURATION_Handle *
-make_config(const struct GNUNET_CONFIGURATION_Handle *cfg, uint32_t off,
- uint16_t * port, uint32_t * upnum, const char *hostname,
- uint32_t * fdnum)
+make_config (const struct GNUNET_CONFIGURATION_Handle *cfg, uint32_t off,
+ uint16_t * port, uint32_t * upnum, const char *hostname,
+ uint32_t * fdnum)
{
struct UpdateContext uc;
uint16_t orig;
@@ -1424,98 +1431,101 @@
GNUNET_CONFIGURATION_iterate (cfg, &update_config, &uc);
if (uc.nport >= HIGH_PORT)
- {
- *port = orig;
- GNUNET_CONFIGURATION_destroy (uc.ret);
- return NULL;
- }
+ {
+ *port = orig;
+ GNUNET_CONFIGURATION_destroy (uc.ret);
+ return NULL;
+ }
if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "testing",
"skew_variance",
&skew_variance))
&& (skew_variance > 0))
- {
- skew_offset = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK,
skew_variance + 1);
- actual_offset = skew_offset -
GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, skew_variance + 1);
- /* Min is -skew_variance, Max is skew_variance */
- skew_offset = skew_variance + actual_offset; /* Normal distribution
around 0 */
- GNUNET_CONFIGURATION_set_value_number(uc.ret, "testing", "skew_offset",
skew_offset);
- }
+ {
+ skew_offset =
+ GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
+ skew_variance + 1);
+ actual_offset =
+ skew_offset - GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
+ skew_variance + 1);
+ /* Min is -skew_variance, Max is skew_variance */
+ skew_offset = skew_variance + actual_offset; /* Normal distribution
around 0 */
+ GNUNET_CONFIGURATION_set_value_number (uc.ret, "testing", "skew_offset",
+ skew_offset);
+ }
if (GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "control_host",
&control_host) == GNUNET_OK)
- {
- if (hostname != NULL)
- GNUNET_asprintf (&allowed_hosts, "%s; 127.0.0.1; %s;", control_host,
- hostname);
- else
- GNUNET_asprintf (&allowed_hosts, "%s; 127.0.0.1;", control_host);
+ {
+ if (hostname != NULL)
+ GNUNET_asprintf (&allowed_hosts, "%s; 127.0.0.1; %s;", control_host,
+ hostname);
+ else
+ GNUNET_asprintf (&allowed_hosts, "%s; 127.0.0.1;", control_host);
- GNUNET_CONFIGURATION_set_value_string (uc.ret, "core", "ACCEPT_FROM",
- allowed_hosts);
+ GNUNET_CONFIGURATION_set_value_string (uc.ret, "core", "ACCEPT_FROM",
+ allowed_hosts);
- GNUNET_CONFIGURATION_set_value_string (uc.ret, "nse", "ACCEPT_FROM",
- allowed_hosts);
+ GNUNET_CONFIGURATION_set_value_string (uc.ret, "nse", "ACCEPT_FROM",
+ allowed_hosts);
- GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport",
- "ACCEPT_FROM", allowed_hosts);
- GNUNET_CONFIGURATION_set_value_string (uc.ret, "dht", "ACCEPT_FROM",
- allowed_hosts);
- GNUNET_CONFIGURATION_set_value_string (uc.ret, "statistics",
- "ACCEPT_FROM", allowed_hosts);
+ GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport",
+ "ACCEPT_FROM", allowed_hosts);
+ GNUNET_CONFIGURATION_set_value_string (uc.ret, "dht", "ACCEPT_FROM",
+ allowed_hosts);
+ GNUNET_CONFIGURATION_set_value_string (uc.ret, "statistics",
+ "ACCEPT_FROM", allowed_hosts);
- GNUNET_CONFIGURATION_set_value_string (uc.ret, "core", "UNIXPATH", "");
- GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport", "UNIXPATH",
- "");
- GNUNET_CONFIGURATION_set_value_string (uc.ret, "dht", "UNIXPATH", "");
- GNUNET_CONFIGURATION_set_value_string (uc.ret, "statistics", "UNIXPATH",
- "");
- GNUNET_CONFIGURATION_set_value_string (uc.ret, "nse", "UNIXPATH", "");
+ GNUNET_CONFIGURATION_set_value_string (uc.ret, "core", "UNIXPATH", "");
+ GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport", "UNIXPATH",
"");
+ GNUNET_CONFIGURATION_set_value_string (uc.ret, "dht", "UNIXPATH", "");
+ GNUNET_CONFIGURATION_set_value_string (uc.ret, "statistics", "UNIXPATH",
+ "");
+ GNUNET_CONFIGURATION_set_value_string (uc.ret, "nse", "UNIXPATH", "");
- GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-tcp",
"USE_LOCALADDR",
- "YES");
- GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-udp",
"USE_LOCALADDR",
- "YES");
- GNUNET_free_non_null (control_host);
- GNUNET_free (allowed_hosts);
- }
+ GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-tcp",
+ "USE_LOCALADDR", "YES");
+ GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-udp",
+ "USE_LOCALADDR", "YES");
+ GNUNET_free_non_null (control_host);
+ GNUNET_free (allowed_hosts);
+ }
/* arm needs to know to allow connections from the host on which it is
running,
* otherwise gnunet-arm is unable to connect to it in some instances */
if (hostname != NULL)
- {
- GNUNET_asprintf (&allowed_hosts, "%s; 127.0.0.1;", hostname);
- GNUNET_CONFIGURATION_set_value_string (uc.ret, "nat", "BINDTO",
- hostname);
- GNUNET_CONFIGURATION_set_value_string (uc.ret, "nat", "INTERNAL_ADDRESS",
- hostname);
- GNUNET_CONFIGURATION_set_value_string (uc.ret, "nat", "EXTERNAL_ADDRESS",
- hostname);
- GNUNET_CONFIGURATION_set_value_string (uc.ret, "disablev6", "BINDTO",
- "YES");
- GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-tcp",
"USE_LOCALADDR",
- "YES");
- GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-udp",
"USE_LOCALADDR",
- "YES");
- GNUNET_CONFIGURATION_set_value_string (uc.ret, "arm", "ACCEPT_FROM",
- allowed_hosts);
- GNUNET_free (allowed_hosts);
- }
+ {
+ GNUNET_asprintf (&allowed_hosts, "%s; 127.0.0.1;", hostname);
+ GNUNET_CONFIGURATION_set_value_string (uc.ret, "nat", "BINDTO", hostname);
+ GNUNET_CONFIGURATION_set_value_string (uc.ret, "nat", "INTERNAL_ADDRESS",
+ hostname);
+ GNUNET_CONFIGURATION_set_value_string (uc.ret, "nat", "EXTERNAL_ADDRESS",
+ hostname);
+ GNUNET_CONFIGURATION_set_value_string (uc.ret, "disablev6", "BINDTO",
+ "YES");
+ GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-tcp",
+ "USE_LOCALADDR", "YES");
+ GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-udp",
+ "USE_LOCALADDR", "YES");
+ GNUNET_CONFIGURATION_set_value_string (uc.ret, "arm", "ACCEPT_FROM",
+ allowed_hosts);
+ GNUNET_free (allowed_hosts);
+ }
else
- {
- GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-tcp",
"USE_LOCALADDR",
- "YES");
- GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-udp",
"USE_LOCALADDR",
- "YES");
- GNUNET_CONFIGURATION_set_value_string (uc.ret, "nat", "BINDTO",
- "127.0.0.1");
- GNUNET_CONFIGURATION_set_value_string (uc.ret, "nat", "INTERNAL_ADDRESS",
- "127.0.0.1");
- GNUNET_CONFIGURATION_set_value_string (uc.ret, "nat", "EXTERNAL_ADDRESS",
- "127.0.0.1");
- GNUNET_CONFIGURATION_set_value_string (uc.ret, "disablev6", "BINDTO",
- "YES");
- }
+ {
+ GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-tcp",
+ "USE_LOCALADDR", "YES");
+ GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-udp",
+ "USE_LOCALADDR", "YES");
+ GNUNET_CONFIGURATION_set_value_string (uc.ret, "nat", "BINDTO",
+ "127.0.0.1");
+ GNUNET_CONFIGURATION_set_value_string (uc.ret, "nat", "INTERNAL_ADDRESS",
+ "127.0.0.1");
+ GNUNET_CONFIGURATION_set_value_string (uc.ret, "nat", "EXTERNAL_ADDRESS",
+ "127.0.0.1");
+ GNUNET_CONFIGURATION_set_value_string (uc.ret, "disablev6", "BINDTO",
+ "YES");
+ }
*port = (uint16_t) uc.nport;
*upnum = uc.upnum;
@@ -1537,10 +1547,12 @@
*
*/
static unsigned int
-remove_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first,
- unsigned int second, enum PeerLists list, unsigned int
check)
+remove_connections (struct GNUNET_TESTING_PeerGroup *pg, unsigned int first,
+ unsigned int second, enum PeerLists list,
+ unsigned int check)
{
int removed;
+
#if OLD
struct PeerConnection **first_list;
struct PeerConnection **second_list;
@@ -1560,7 +1572,7 @@
removed = 0;
#if OLD
switch (list)
- {
+ {
case ALLOWED:
first_list = &pg->peers[first].allowed_peers_head;
second_list = &pg->peers[second].allowed_peers_head;
@@ -1586,51 +1598,55 @@
second_tail = &pg->peers[second].connect_peers_working_set_tail;
break;
default:
- GNUNET_break(0);
+ GNUNET_break (0);
return 0;
- }
+ }
first_iter = *first_list;
while (first_iter != NULL)
+ {
+ if (first_iter->index == second)
{
- if (first_iter->index == second)
- {
- GNUNET_CONTAINER_DLL_remove(*first_list, *first_tail, first_iter);
- GNUNET_free(first_iter);
- removed++;
- break;
- }
- first_iter = first_iter->next;
+ GNUNET_CONTAINER_DLL_remove (*first_list, *first_tail, first_iter);
+ GNUNET_free (first_iter);
+ removed++;
+ break;
}
+ first_iter = first_iter->next;
+ }
second_iter = *second_list;
while (second_iter != NULL)
+ {
+ if (second_iter->index == first)
{
- if (second_iter->index == first)
- {
- GNUNET_CONTAINER_DLL_remove(*second_list, *second_tail, second_iter);
- GNUNET_free(second_iter);
- removed++;
- break;
- }
- second_iter = second_iter->next;
+ GNUNET_CONTAINER_DLL_remove (*second_list, *second_tail, second_iter);
+ GNUNET_free (second_iter);
+ removed++;
+ break;
}
+ second_iter = second_iter->next;
+ }
#else
if (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_contains
(pg->peers[first].blacklisted_peers,
- &hash_second))
- {
- GNUNET_CONTAINER_multihashmap_remove_all
(pg->peers[first].blacklisted_peers,
- &hash_second);
- }
+ GNUNET_CONTAINER_multihashmap_contains (pg->
+ peers[first].blacklisted_peers,
+ &hash_second))
+ {
+ GNUNET_CONTAINER_multihashmap_remove_all (pg->
+ peers[first].blacklisted_peers,
+ &hash_second);
+ }
if (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_contains
(pg->peers[second].blacklisted_peers,
- &hash_first))
- {
- GNUNET_CONTAINER_multihashmap_remove_all
(pg->peers[second].blacklisted_peers,
- &hash_first);
- }
+ GNUNET_CONTAINER_multihashmap_contains (pg->
+ peers[second].blacklisted_peers,
+ &hash_first))
+ {
+ GNUNET_CONTAINER_multihashmap_remove_all (pg->
+ peers[second].blacklisted_peers,
+ &hash_first);
+ }
#endif
return removed;
@@ -1650,8 +1666,8 @@
*
*/
static unsigned int
-add_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first,
- unsigned int second, enum PeerLists list, unsigned int check)
+add_connections (struct GNUNET_TESTING_PeerGroup *pg, unsigned int first,
+ unsigned int second, enum PeerLists list, unsigned int check)
{
int added;
int add_first;
@@ -1667,7 +1683,7 @@
struct PeerConnection **second_tail;
switch (list)
- {
+ {
case ALLOWED:
first_list = &pg->peers[first].allowed_peers_head;
second_list = &pg->peers[second].allowed_peers_head;
@@ -1693,56 +1709,56 @@
second_tail = &pg->peers[second].connect_peers_working_set_tail;
break;
default:
- GNUNET_break(0);
+ GNUNET_break (0);
return 0;
- }
+ }
add_first = GNUNET_YES;
add_second = GNUNET_YES;
if (check == GNUNET_YES)
+ {
+ first_iter = *first_list;
+ while (first_iter != NULL)
{
- first_iter = *first_list;
- while (first_iter != NULL)
- {
- if (first_iter->index == second)
- {
- add_first = GNUNET_NO;
- break;
- }
- first_iter = first_iter->next;
- }
+ if (first_iter->index == second)
+ {
+ add_first = GNUNET_NO;
+ break;
+ }
+ first_iter = first_iter->next;
+ }
- second_iter = *second_list;
- while (second_iter != NULL)
- {
- if (second_iter->index == first)
- {
- add_second = GNUNET_NO;
- break;
- }
- second_iter = second_iter->next;
- }
+ second_iter = *second_list;
+ while (second_iter != NULL)
+ {
+ if (second_iter->index == first)
+ {
+ add_second = GNUNET_NO;
+ break;
+ }
+ second_iter = second_iter->next;
}
+ }
added = 0;
if (add_first)
- {
- new_first = GNUNET_malloc (sizeof (struct PeerConnection));
- new_first->index = second;
- GNUNET_CONTAINER_DLL_insert(*first_list, *first_tail, new_first);
- pg->peers[first].num_connections++;
- added++;
- }
+ {
+ new_first = GNUNET_malloc (sizeof (struct PeerConnection));
+ new_first->index = second;
+ GNUNET_CONTAINER_DLL_insert (*first_list, *first_tail, new_first);
+ pg->peers[first].num_connections++;
+ added++;
+ }
if (add_second)
- {
- new_second = GNUNET_malloc (sizeof (struct PeerConnection));
- new_second->index = first;
- GNUNET_CONTAINER_DLL_insert(*second_list, *second_tail, new_second);
- pg->peers[second].num_connections++;
- added++;
- }
+ {
+ new_second = GNUNET_malloc (sizeof (struct PeerConnection));
+ new_second->index = first;
+ GNUNET_CONTAINER_DLL_insert (*second_list, *second_tail, new_second);
+ pg->peers[second].num_connections++;
+ added++;
+ }
return added;
}
@@ -1764,8 +1780,8 @@
* @return the number of connections created
*/
static unsigned int
-create_scale_free(struct GNUNET_TESTING_PeerGroup *pg,
- GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list)
+create_scale_free (struct GNUNET_TESTING_PeerGroup *pg,
+ GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists
list)
{
unsigned int total_connections;
@@ -1781,31 +1797,31 @@
total_connections = proc (pg, 0, 1, list, GNUNET_YES);
for (outer_count = 1; outer_count < pg->total; outer_count++)
+ {
+ previous_total_connections = total_connections;
+ for (i = 0; i < outer_count; i++)
{
- previous_total_connections = total_connections;
- for (i = 0; i < outer_count; i++)
- {
- probability = pg->peers[i].num_connections
- / (double) previous_total_connections;
- random
- = ((double) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
- UINT64_MAX))
- / ((double) UINT64_MAX);
+ probability = pg->peers[i].num_connections
+ / (double) previous_total_connections;
+ random
+ = ((double) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
+ UINT64_MAX))
+ / ((double) UINT64_MAX);
#if VERBOSE_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Considering connecting peer %d to peer %d\n",
- outer_count, i);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Considering connecting peer %d to peer %d\n",
+ outer_count, i);
#endif
- if (random < probability)
- {
+ if (random < probability)
+ {
#if VERBOSE_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connecting peer %d to peer %d\n", outer_count, i);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Connecting peer %d to peer %d\n", outer_count, i);
#endif
- total_connections += proc (pg, outer_count, i, list, GNUNET_YES);
- }
- }
+ total_connections += proc (pg, outer_count, i, list, GNUNET_YES);
+ }
}
+ }
return total_connections;
}
@@ -1838,9 +1854,9 @@
*
*/
static unsigned int
-create_small_world_ring(struct GNUNET_TESTING_PeerGroup *pg,
- GNUNET_TESTING_ConnectionProcessor proc,
- enum PeerLists list)
+create_small_world_ring (struct GNUNET_TESTING_PeerGroup *pg,
+ GNUNET_TESTING_ConnectionProcessor proc,
+ enum PeerLists list)
{
unsigned int i, j;
int nodeToConnect;
@@ -1855,32 +1871,30 @@
unsigned int useAnd;
int connect_attempts;
- logNModifier = 0.5; /* FIXME: default value? */
+ logNModifier = 0.5; /* FIXME: default value? */
if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING",
"PERCENTAGE",
&p_string))
- {
- if (sscanf (p_string, "%lf", &logNModifier) != 1)
- GNUNET_log (
- GNUNET_ERROR_TYPE_WARNING,
- _
- ("Invalid value `%s' for option `%s' in section `%s':
expected float\n"),
- p_string, "LOGNMODIFIER", "TESTING");
- GNUNET_free (p_string);
- }
- probability = 0.5; /* FIXME: default percentage? */
+ {
+ if (sscanf (p_string, "%lf", &logNModifier) != 1)
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Invalid value `%s' for option `%s' in section `%s':
expected float\n"),
+ p_string, "LOGNMODIFIER", "TESTING");
+ GNUNET_free (p_string);
+ }
+ probability = 0.5; /* FIXME: default percentage? */
if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING",
"PROBABILITY",
&p_string))
- {
- if (sscanf (p_string, "%lf", &probability) != 1)
- GNUNET_log (
- GNUNET_ERROR_TYPE_WARNING,
- _
- ("Invalid value `%s' for option `%s' in section `%s':
expected float\n"),
- p_string, "PERCENTAGE", "TESTING");
- GNUNET_free (p_string);
- }
+ {
+ if (sscanf (p_string, "%lf", &probability) != 1)
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Invalid value `%s' for option `%s' in section `%s':
expected float\n"),
+ p_string, "PERCENTAGE", "TESTING");
+ GNUNET_free (p_string);
+ }
natLog = log (pg->total);
connsPerPeer = ceil (natLog * logNModifier);
@@ -1893,59 +1907,57 @@
smallWorldConnections = 0;
connect_attempts = 0;
for (i = 0; i < pg->total; i++)
+ {
+ useAnd = 0;
+ max = i + connsPerPeer / 2;
+ min = i - connsPerPeer / 2;
+
+ if (max > pg->total - 1)
{
- useAnd = 0;
- max = i + connsPerPeer / 2;
- min = i - connsPerPeer / 2;
+ max = max - pg->total;
+ useAnd = 1;
+ }
- if (max > pg->total - 1)
- {
- max = max - pg->total;
- useAnd = 1;
- }
+ if (min < 0)
+ {
+ min = pg->total - 1 + min;
+ useAnd = 1;
+ }
- if (min < 0)
+ for (j = 0; j < connsPerPeer / 2; j++)
+ {
+ random
+ = ((double) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
+ UINT64_MAX)
+ / ((double) UINT64_MAX));
+ if (random < probability)
+ {
+ /* Connect to uniformly selected random peer */
+ randomPeer
+ = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, pg->total);
+ while ((((randomPeer < max) && (randomPeer > min)) && (useAnd
+ == 0)) ||
+ (((randomPeer > min) || (randomPeer < max)) && (useAnd == 1)))
{
- min = pg->total - 1 + min;
- useAnd = 1;
+ randomPeer
+ = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
+ pg->total);
}
-
- for (j = 0; j < connsPerPeer / 2; j++)
+ smallWorldConnections += proc (pg, i, randomPeer, list, GNUNET_YES);
+ }
+ else
+ {
+ nodeToConnect = i + j + 1;
+ if (nodeToConnect > pg->total - 1)
{
- random
- = ((double) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
- UINT64_MAX)
- / ((double) UINT64_MAX));
- if (random < probability)
- {
- /* Connect to uniformly selected random peer */
- randomPeer
- = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
- pg->total);
- while ((((randomPeer < max) && (randomPeer > min)) && (useAnd
- == 0)) || (((randomPeer > min) || (randomPeer < max))
- && (useAnd == 1)))
- {
- randomPeer
- = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
- pg->total);
- }
- smallWorldConnections += proc (pg, i, randomPeer, list,
- GNUNET_YES);
- }
- else
- {
- nodeToConnect = i + j + 1;
- if (nodeToConnect > pg->total - 1)
- {
- nodeToConnect = nodeToConnect - pg->total;
- }
- connect_attempts += proc (pg, i, nodeToConnect, list,
GNUNET_YES);
- }
+ nodeToConnect = nodeToConnect - pg->total;
}
-
+ connect_attempts += proc (pg, i, nodeToConnect, list, GNUNET_YES);
+ }
}
+ }
+
connect_attempts += smallWorldConnections;
return connect_attempts;
@@ -1964,9 +1976,9 @@
*
*/
static unsigned int
-create_nated_internet(struct GNUNET_TESTING_PeerGroup *pg,
- GNUNET_TESTING_ConnectionProcessor proc,
- enum PeerLists list)
+create_nated_internet (struct GNUNET_TESTING_PeerGroup *pg,
+ GNUNET_TESTING_ConnectionProcessor proc,
+ enum PeerLists list)
{
unsigned int outer_count, inner_count;
unsigned int cutoff;
@@ -1974,38 +1986,37 @@
double nat_percentage;
char *p_string;
- nat_percentage = 0.6; /* FIXME: default percentage? */
+ nat_percentage = 0.6; /* FIXME: default percentage? */
if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING",
"PERCENTAGE",
&p_string))
- {
- if (sscanf (p_string, "%lf", &nat_percentage) != 1)
- GNUNET_log (
- GNUNET_ERROR_TYPE_WARNING,
- _
- ("Invalid value `%s' for option `%s' in section `%s':
expected float\n"),
- p_string, "PERCENTAGE", "TESTING");
- GNUNET_free (p_string);
- }
+ {
+ if (sscanf (p_string, "%lf", &nat_percentage) != 1)
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Invalid value `%s' for option `%s' in section `%s':
expected float\n"),
+ p_string, "PERCENTAGE", "TESTING");
+ GNUNET_free (p_string);
+ }
cutoff = (unsigned int) (nat_percentage * pg->total);
connect_attempts = 0;
for (outer_count = 0; outer_count < pg->total - 1; outer_count++)
+ {
+ for (inner_count = outer_count + 1; inner_count < pg->total; inner_count++)
{
- for (inner_count = outer_count + 1; inner_count < pg->total;
inner_count++)
- {
- if ((outer_count > cutoff) || (inner_count > cutoff))
- {
+ if ((outer_count > cutoff) || (inner_count > cutoff))
+ {
#if VERBOSE_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connecting peer %d to peer %d\n",
- outer_count, inner_count);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Connecting peer %d to peer %d\n",
+ outer_count, inner_count);
#endif
- connect_attempts += proc (pg, outer_count, inner_count, list,
- GNUNET_YES);
- }
- }
+ connect_attempts += proc (pg, outer_count, inner_count, list,
+ GNUNET_YES);
+ }
}
+ }
return connect_attempts;
}
@@ -2023,9 +2034,9 @@
*
*/
static unsigned int
-create_nated_internet_copy(struct GNUNET_TESTING_PeerGroup *pg,
- GNUNET_TESTING_ConnectionProcessor proc,
- enum PeerLists list)
+create_nated_internet_copy (struct GNUNET_TESTING_PeerGroup *pg,
+ GNUNET_TESTING_ConnectionProcessor proc,
+ enum PeerLists list)
{
unsigned int outer_count, inner_count;
unsigned int cutoff;
@@ -2035,52 +2046,51 @@
unsigned int count;
struct ProgressMeter *conn_meter;
- nat_percentage = 0.6; /* FIXME: default percentage? */
+ nat_percentage = 0.6; /* FIXME: default percentage? */
if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING",
"PERCENTAGE",
&p_string))
- {
- if (sscanf (p_string, "%lf", &nat_percentage) != 1)
- GNUNET_log (
- GNUNET_ERROR_TYPE_WARNING,
- _
- ("Invalid value `%s' for option `%s' in section `%s':
expected float\n"),
- p_string, "PERCENTAGE", "TESTING");
- GNUNET_free (p_string);
- }
+ {
+ if (sscanf (p_string, "%lf", &nat_percentage) != 1)
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Invalid value `%s' for option `%s' in section `%s':
expected float\n"),
+ p_string, "PERCENTAGE", "TESTING");
+ GNUNET_free (p_string);
+ }
cutoff = (unsigned int) (nat_percentage * pg->total);
count = 0;
for (outer_count = 0; outer_count < pg->total - 1; outer_count++)
+ {
+ for (inner_count = outer_count + 1; inner_count < pg->total; inner_count++)
{
- for (inner_count = outer_count + 1; inner_count < pg->total;
inner_count++)
- {
- if ((outer_count > cutoff) || (inner_count > cutoff))
- {
- count++;
- }
- }
+ if ((outer_count > cutoff) || (inner_count > cutoff))
+ {
+ count++;
+ }
}
+ }
conn_meter = create_meter (count, "NAT COPY", GNUNET_YES);
connect_attempts = 0;
for (outer_count = 0; outer_count < pg->total - 1; outer_count++)
+ {
+ for (inner_count = outer_count + 1; inner_count < pg->total; inner_count++)
{
- for (inner_count = outer_count + 1; inner_count < pg->total;
inner_count++)
- {
- if ((outer_count > cutoff) || (inner_count > cutoff))
- {
+ if ((outer_count > cutoff) || (inner_count > cutoff))
+ {
#if VERBOSE_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connecting peer %d to peer %d\n",
- outer_count, inner_count);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Connecting peer %d to peer %d\n",
+ outer_count, inner_count);
#endif
- connect_attempts += proc (pg, outer_count, inner_count, list,
- GNUNET_YES);
- add_connections (pg, outer_count, inner_count, ALLOWED,
GNUNET_NO);
- update_meter (conn_meter);
- }
- }
+ connect_attempts += proc (pg, outer_count, inner_count, list,
+ GNUNET_YES);
+ add_connections (pg, outer_count, inner_count, ALLOWED, GNUNET_NO);
+ update_meter (conn_meter);
+ }
}
+ }
free_meter (conn_meter);
return connect_attempts;
@@ -2100,8 +2110,9 @@
*
*/
static unsigned int
-create_small_world(struct GNUNET_TESTING_PeerGroup *pg,
- GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists
list)
+create_small_world (struct GNUNET_TESTING_PeerGroup *pg,
+ GNUNET_TESTING_ConnectionProcessor proc,
+ enum PeerLists list)
{
unsigned int i, j, k;
unsigned int square;
@@ -2120,62 +2131,60 @@
unsigned int small_world_it;
char *p_string;
int connect_attempts;
+
square = floor (sqrt (pg->total));
rows = square;
cols = square;
- percentage = 0.5; /* FIXME: default percentage? */
+ percentage = 0.5; /* FIXME: default percentage? */
if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING",
"PERCENTAGE",
&p_string))
- {
- if (sscanf (p_string, "%lf", &percentage) != 1)
- GNUNET_log (
- GNUNET_ERROR_TYPE_WARNING,
- _
- ("Invalid value `%s' for option `%s' in section `%s':
expected float\n"),
- p_string, "PERCENTAGE", "TESTING");
- GNUNET_free (p_string);
- }
+ {
+ if (sscanf (p_string, "%lf", &percentage) != 1)
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Invalid value `%s' for option `%s' in section `%s':
expected float\n"),
+ p_string, "PERCENTAGE", "TESTING");
+ GNUNET_free (p_string);
+ }
if (percentage < 0.0)
- {
- GNUNET_log (
- GNUNET_ERROR_TYPE_WARNING,
- _
- ("Invalid value `%s' for option `%s' in section `%s': got
%f, needed value greater than 0\n"),
- "PERCENTAGE", "TESTING", percentage);
- percentage = 0.5;
- }
- probability = 0.5; /* FIXME: default percentage? */
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Invalid value `%s' for option `%s' in section `%s': got %f,
needed value greater than 0\n"),
+ "PERCENTAGE", "TESTING", percentage);
+ percentage = 0.5;
+ }
+ probability = 0.5; /* FIXME: default percentage? */
if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING",
"PROBABILITY",
&p_string))
- {
- if (sscanf (p_string, "%lf", &probability) != 1)
- GNUNET_log (
- GNUNET_ERROR_TYPE_WARNING,
- _
- ("Invalid value `%s' for option `%s' in section `%s':
expected float\n"),
- p_string, "PROBABILITY", "TESTING");
- GNUNET_free (p_string);
- }
+ {
+ if (sscanf (p_string, "%lf", &probability) != 1)
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Invalid value `%s' for option `%s' in section `%s':
expected float\n"),
+ p_string, "PROBABILITY", "TESTING");
+ GNUNET_free (p_string);
+ }
if (square * square != pg->total)
+ {
+ while (rows * cols < pg->total)
{
- while (rows * cols < pg->total)
- {
- if (toggle % 2 == 0)
- rows++;
- else
- cols++;
+ if (toggle % 2 == 0)
+ rows++;
+ else
+ cols++;
- toggle++;
- }
+ toggle++;
}
+ }
#if VERBOSE_TESTING
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _
- ("Connecting nodes in 2d torus topology: %u rows %u columns\n"),
- rows, cols);
+ _
+ ("Connecting nodes in 2d torus topology: %u rows %u columns\n"),
+ rows, cols);
#endif
connect_attempts = 0;
@@ -2185,36 +2194,36 @@
* to the first in the row to maintain topology.
*/
for (i = 0; i < pg->total; i++)
+ {
+ /* First connect to the node to the right */
+ if (((i + 1) % cols != 0) && (i + 1 != pg->total))
+ nodeToConnect = i + 1;
+ else if (i + 1 == pg->total)
+ nodeToConnect = rows * cols - cols;
+ else
+ nodeToConnect = i - cols + 1;
+
+ connect_attempts += proc (pg, i, nodeToConnect, list, GNUNET_YES);
+
+ if (i < cols)
{
- /* First connect to the node to the right */
- if (((i + 1) % cols != 0) && (i + 1 != pg->total))
- nodeToConnect = i + 1;
- else if (i + 1 == pg->total)
- nodeToConnect = rows * cols - cols;
- else
- nodeToConnect = i - cols + 1;
+ nodeToConnect = (rows * cols) - cols + i;
+ if (nodeToConnect >= pg->total)
+ nodeToConnect -= cols;
+ }
+ else
+ nodeToConnect = i - cols;
+ if (nodeToConnect < pg->total)
connect_attempts += proc (pg, i, nodeToConnect, list, GNUNET_YES);
-
- if (i < cols)
- {
- nodeToConnect = (rows * cols) - cols + i;
- if (nodeToConnect >= pg->total)
- nodeToConnect -= cols;
- }
- else
- nodeToConnect = i - cols;
-
- if (nodeToConnect < pg->total)
- connect_attempts += proc (pg, i, nodeToConnect, list, GNUNET_YES);
- }
+ }
natLog = log (pg->total);
#if VERBOSE_TESTING > 2
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("natural log of %d is %d, will run %d iterations\n"),
- pg->total, natLog, (int) (natLog * percentage));
+ _("natural log of %d is %d, will run %d iterations\n"),
+ pg->total, natLog, (int) (natLog * percentage));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Total connections added thus far: %u!\n"), connect_attempts);
+ _("Total connections added thus far: %u!\n"), connect_attempts);
#endif
smallWorldConnections = 0;
small_world_it = (unsigned int) (natLog * percentage);
@@ -2222,42 +2231,41 @@
small_world_it = 1;
GNUNET_assert (small_world_it > 0 && small_world_it < (unsigned int) -1);
for (i = 0; i < small_world_it; i++)
+ {
+ for (j = 0; j < pg->total; j++)
{
- for (j = 0; j < pg->total; j++)
+ /* Determine the row and column of node at position j on the 2d torus */
+ node1Row = j / cols;
+ node1Col = j - (node1Row * cols);
+ for (k = 0; k < pg->total; k++)
+ {
+ /* Determine the row and column of node at position k on the 2d torus
*/
+ node2Row = k / cols;
+ node2Col = k - (node2Row * cols);
+ /* Simple Cartesian distance */
+ distance = abs (node1Row - node2Row) + abs (node1Col - node2Col);
+ if (distance > 1)
{
- /* Determine the row and column of node at position j on the 2d
torus */
- node1Row = j / cols;
- node1Col = j - (node1Row * cols);
- for (k = 0; k < pg->total; k++)
- {
- /* Determine the row and column of node at position k on the 2d
torus */
- node2Row = k / cols;
- node2Col = k - (node2Row * cols);
- /* Simple Cartesian distance */
- distance = abs (node1Row - node2Row) + abs (node1Col - node2Col);
- if (distance > 1)
- {
- /* Calculate probability as 1 over the square of the
distance */
- probability = 1.0 / (distance * distance);
- /* Choose a random value between 0 and 1 */
- random
- = ((double) GNUNET_CRYPTO_random_u64 (
-
GNUNET_CRYPTO_QUALITY_WEAK,
- UINT64_MAX))
- / ((double) UINT64_MAX);
- /* If random < probability, then connect the two nodes */
- if (random < probability)
- smallWorldConnections += proc (pg, j, k, list, GNUNET_YES);
+ /* Calculate probability as 1 over the square of the distance */
+ probability = 1.0 / (distance * distance);
+ /* Choose a random value between 0 and 1 */
+ random
+ = ((double) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
+ UINT64_MAX))
+ / ((double) UINT64_MAX);
+ /* If random < probability, then connect the two nodes */
+ if (random < probability)
+ smallWorldConnections += proc (pg, j, k, list, GNUNET_YES);
- }
- }
}
+ }
}
+ }
connect_attempts += smallWorldConnections;
#if VERBOSE_TESTING > 2
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Total connections added for small world: %d!\n"),
- smallWorldConnections);
+ _("Total connections added for small world: %d!\n"),
+ smallWorldConnections);
#endif
return connect_attempts;
}
@@ -2275,8 +2283,9 @@
*
*/
static unsigned int
-create_erdos_renyi(struct GNUNET_TESTING_PeerGroup *pg,
- GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists
list)
+create_erdos_renyi (struct GNUNET_TESTING_PeerGroup *pg,
+ GNUNET_TESTING_ConnectionProcessor proc,
+ enum PeerLists list)
{
double temp_rand;
unsigned int outer_count;
@@ -2285,40 +2294,38 @@
double probability;
char *p_string;
- probability = 0.5; /* FIXME: default percentage? */
+ probability = 0.5; /* FIXME: default percentage? */
if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING",
"PROBABILITY",
&p_string))
- {
- if (sscanf (p_string, "%lf", &probability) != 1)
- GNUNET_log (
- GNUNET_ERROR_TYPE_WARNING,
- _
- ("Invalid value `%s' for option `%s' in section `%s':
expected float\n"),
- p_string, "PROBABILITY", "TESTING");
- GNUNET_free (p_string);
- }
+ {
+ if (sscanf (p_string, "%lf", &probability) != 1)
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Invalid value `%s' for option `%s' in section `%s':
expected float\n"),
+ p_string, "PROBABILITY", "TESTING");
+ GNUNET_free (p_string);
+ }
connect_attempts = 0;
for (outer_count = 0; outer_count < pg->total - 1; outer_count++)
+ {
+ for (inner_count = outer_count + 1; inner_count < pg->total; inner_count++)
{
- for (inner_count = outer_count + 1; inner_count < pg->total;
inner_count++)
- {
- temp_rand
- = ((double) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
- UINT64_MAX))
- / ((double) UINT64_MAX);
+ temp_rand
+ = ((double) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
+ UINT64_MAX))
+ / ((double) UINT64_MAX);
#if VERBOSE_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("rand is %f probability is %f\n"), temp_rand,
- probability);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ _("rand is %f probability is %f\n"), temp_rand, probability);
#endif
- if (temp_rand < probability)
- {
- connect_attempts += proc (pg, outer_count, inner_count, list,
- GNUNET_YES);
- }
- }
+ if (temp_rand < probability)
+ {
+ connect_attempts += proc (pg, outer_count, inner_count, list,
+ GNUNET_YES);
+ }
}
+ }
return connect_attempts;
}
@@ -2338,8 +2345,8 @@
*
*/
static unsigned int
-create_2d_torus(struct GNUNET_TESTING_PeerGroup *pg,
- GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list)
+create_2d_torus (struct GNUNET_TESTING_PeerGroup *pg,
+ GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list)
{
unsigned int i;
unsigned int square;
@@ -2356,22 +2363,22 @@
cols = square;
if (square * square != pg->total)
+ {
+ while (rows * cols < pg->total)
{
- while (rows * cols < pg->total)
- {
- if (toggle % 2 == 0)
- rows++;
- else
- cols++;
+ if (toggle % 2 == 0)
+ rows++;
+ else
+ cols++;
- toggle++;
- }
+ toggle++;
}
+ }
#if VERBOSE_TESTING
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _
- ("Connecting nodes in 2d torus topology: %u rows %u columns\n"),
- rows, cols);
+ _
+ ("Connecting nodes in 2d torus topology: %u rows %u columns\n"),
+ rows, cols);
#endif
/* Rows and columns are all sorted out, now iterate over all nodes and
connect each
* to the node to its right and above. Once this is over, we'll have our
torus!
@@ -2379,41 +2386,41 @@
* to the first in the row to maintain topology.
*/
for (i = 0; i < pg->total; i++)
- {
- /* First connect to the node to the right */
- if (((i + 1) % cols != 0) && (i + 1 != pg->total))
- nodeToConnect = i + 1;
- else if (i + 1 == pg->total)
- nodeToConnect = rows * cols - cols;
- else
- nodeToConnect = i - cols + 1;
+ {
+ /* First connect to the node to the right */
+ if (((i + 1) % cols != 0) && (i + 1 != pg->total))
+ nodeToConnect = i + 1;
+ else if (i + 1 == pg->total)
+ nodeToConnect = rows * cols - cols;
+ else
+ nodeToConnect = i - cols + 1;
#if VERBOSE_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connecting peer %d to peer %d\n", i, nodeToConnect);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Connecting peer %d to peer %d\n", i, nodeToConnect);
#endif
- connect_attempts += proc (pg, i, nodeToConnect, list, GNUNET_YES);
+ connect_attempts += proc (pg, i, nodeToConnect, list, GNUNET_YES);
- /* Second connect to the node immediately above */
- if (i < cols)
- {
- nodeToConnect = (rows * cols) - cols + i;
- if (nodeToConnect >= pg->total)
- nodeToConnect -= cols;
- }
- else
- nodeToConnect = i - cols;
+ /* Second connect to the node immediately above */
+ if (i < cols)
+ {
+ nodeToConnect = (rows * cols) - cols + i;
+ if (nodeToConnect >= pg->total)
+ nodeToConnect -= cols;
+ }
+ else
+ nodeToConnect = i - cols;
- if (nodeToConnect < pg->total)
- {
+ if (nodeToConnect < pg->total)
+ {
#if VERBOSE_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connecting peer %d to peer %d\n", i, nodeToConnect);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Connecting peer %d to peer %d\n", i, nodeToConnect);
#endif
- connect_attempts += proc (pg, i, nodeToConnect, list, GNUNET_YES);
- }
-
+ connect_attempts += proc (pg, i, nodeToConnect, list, GNUNET_YES);
}
+ }
+
return connect_attempts;
}
@@ -2432,31 +2439,31 @@
*
*/
static unsigned int
-create_clique(struct GNUNET_TESTING_PeerGroup *pg,
- GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list,
- unsigned int check)
+create_clique (struct GNUNET_TESTING_PeerGroup *pg,
+ GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list,
+ unsigned int check)
{
unsigned int outer_count;
unsigned int inner_count;
int connect_attempts;
struct ProgressMeter *conn_meter;
+
connect_attempts = 0;
conn_meter = create_meter ((((pg->total * pg->total) + pg->total) / 2)
- - pg->total, "Create Clique ", GNUNET_NO);
+ - pg->total, "Create Clique ", GNUNET_NO);
for (outer_count = 0; outer_count < pg->total - 1; outer_count++)
+ {
+ for (inner_count = outer_count + 1; inner_count < pg->total; inner_count++)
{
- for (inner_count = outer_count + 1; inner_count < pg->total;
inner_count++)
- {
#if VERBOSE_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connecting peer %d to peer %d\n",
- outer_count, inner_count);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Connecting peer %d to peer %d\n", outer_count, inner_count);
#endif
- connect_attempts += proc (pg, outer_count, inner_count, list, check);
- update_meter (conn_meter);
- }
+ connect_attempts += proc (pg, outer_count, inner_count, list, check);
+ update_meter (conn_meter);
}
+ }
reset_meter (conn_meter);
free_meter (conn_meter);
return connect_attempts;
@@ -2475,19 +2482,17 @@
* GNUNET_NO if not.
*/
static int
-unblacklist_iterator (void *cls,
- const GNUNET_HashCode * key,
- void *value)
- {
- struct UnblacklistContext *un_ctx = cls;
- uint32_t second_pos;
+unblacklist_iterator (void *cls, const GNUNET_HashCode * key, void *value)
+{
+ struct UnblacklistContext *un_ctx = cls;
+ uint32_t second_pos;
- uid_from_hash (key, &second_pos);
+ uid_from_hash (key, &second_pos);
- unblacklist_connections(un_ctx->pg, un_ctx->first_uid, second_pos);
+ unblacklist_connections (un_ctx->pg, un_ctx->first_uid, second_pos);
- return GNUNET_YES;
- }
+ return GNUNET_YES;
+}
#endif
#if !OLD
@@ -2510,6 +2515,7 @@
unsigned int count;
unsigned int total;
struct PeerConnection *iter;
+
#if !OLD
struct UnblacklistContext un_ctx;
@@ -2517,25 +2523,23 @@
#endif
total = 0;
for (count = 0; count < pg->total - 1; count++)
+ {
+#if OLD
+ iter = pg->peers[count].allowed_peers_head;
+ while (iter != NULL)
{
-#if OLD
- iter = pg->peers[count].allowed_peers_head;
- while (iter != NULL)
- {
- remove_connections (pg, count, iter->index, BLACKLIST, GNUNET_YES);
- //unblacklist_connections(pg, count, iter->index);
- iter = iter->next;
- }
+ remove_connections (pg, count, iter->index, BLACKLIST, GNUNET_YES);
+ //unblacklist_connections(pg, count, iter->index);
+ iter = iter->next;
+ }
#else
- un_ctx.first_uid = count;
- total +=
GNUNET_CONTAINER_multihashmap_iterate(pg->peers[count].allowed_peers,
- &unblacklist_iterator,
- &un_ctx);
+ un_ctx.first_uid = count;
+ total +=
+ GNUNET_CONTAINER_multihashmap_iterate (pg->peers[count].allowed_peers,
+ &unblacklist_iterator, &un_ctx);
#endif
- }
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Unblacklisted %u peers\n",
- total);
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Unblacklisted %u peers\n", total);
return total;
}
#endif
@@ -2553,8 +2557,8 @@
*
*/
static unsigned int
-create_line(struct GNUNET_TESTING_PeerGroup *pg,
- GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list)
+create_line (struct GNUNET_TESTING_PeerGroup *pg,
+ GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list)
{
unsigned int count;
unsigned int connect_attempts;
@@ -2562,14 +2566,13 @@
connect_attempts = 0;
/* Connect each peer to the next highest numbered peer */
for (count = 0; count < pg->total - 1; count++)
- {
+ {
#if VERBOSE_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connecting peer %d to peer %d\n",
- count, count + 1);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Connecting peer %d to peer %d\n", count, count + 1);
#endif
- connect_attempts += proc (pg, count, count + 1, list, GNUNET_YES);
- }
+ connect_attempts += proc (pg, count, count + 1, list, GNUNET_YES);
+ }
return connect_attempts;
}
@@ -2588,8 +2591,8 @@
*
*/
static unsigned int
-create_from_file(struct GNUNET_TESTING_PeerGroup *pg, char *filename,
- GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list)
+create_from_file (struct GNUNET_TESTING_PeerGroup *pg, char *filename,
+ GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list)
{
int connect_attempts;
unsigned int first_peer_index;
@@ -2606,23 +2609,22 @@
GNUNET_DISK_fn_write (filename, NULL, 0, GNUNET_DISK_PERM_USER_READ);
if ((0 != STAT (filename, &frstat)) || (frstat.st_size == 0))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Could not open file `%s' specified for topology!",
filename);
- return connect_attempts;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Could not open file `%s' specified for topology!", filename);
+ return connect_attempts;
+ }
data = GNUNET_malloc_large (frstat.st_size);
- GNUNET_assert(data != NULL);
+ GNUNET_assert (data != NULL);
if (frstat.st_size != GNUNET_DISK_fn_read (filename, data, frstat.st_size))
- {
- GNUNET_log (
- GNUNET_ERROR_TYPE_ERROR,
- "Could not read file %s specified for host list, ending
test!",
- filename);
- GNUNET_free (data);
- return connect_attempts;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Could not read file %s specified for host list, ending test!",
+ filename);
+ GNUNET_free (data);
+ return connect_attempts;
+ }
buf = data;
count = 0;
@@ -2631,88 +2633,90 @@
/* Each subsequent line should contain this format
PEER_INDEX:OTHER_PEER_INDEX[,...] */
curr_state = NUM_PEERS;
while (count < frstat.st_size - 1)
+ {
+ if ((buf[count] == '\n') || (buf[count] == ' '))
{
- if ((buf[count] == '\n') || (buf[count] == ' '))
- {
- count++;
- continue;
- }
+ count++;
+ continue;
+ }
- switch (curr_state)
- {
- case NUM_PEERS:
- errno = 0;
- total_peers = strtoul(&buf[count], NULL, 10);
- if (errno != 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Failed to read number of peers from topology
file!\n");
- GNUNET_free (data);
- return connect_attempts;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Read %u total peers in topology\n", total_peers);
- GNUNET_assert(total_peers == pg->total);
- curr_state = PEER_INDEX;
- while ((buf[count] != '\n') && (count < frstat.st_size - 1))
- count++;
- count++;
- break;
- case PEER_INDEX:
- errno = 0;
- first_peer_index = strtoul(&buf[count], NULL, 10);
- if (errno != 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Failed to read peer index from topology file!\n");
- GNUNET_free (data);
- return connect_attempts;
- }
- while ((buf[count] != ':') && (count < frstat.st_size - 1))
- count++;
- count++;
- curr_state = OTHER_PEER_INDEX;
- break;
- case COLON:
- if (1 == sscanf (&buf[count], ":"))
- curr_state = OTHER_PEER_INDEX;
- count++;
- break;
- case OTHER_PEER_INDEX:
- errno = 0;
- second_peer_index = strtoul(&buf[count], NULL, 10);
- if (errno != 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Failed to peer index from topology file!\n");
- GNUNET_free (data);
- return connect_attempts;
- }
- /* Assume file is written with first peer 1, but array index is 0 */
- connect_attempts += proc (pg, first_peer_index - 1, second_peer_index
- - 1, list, GNUNET_YES);
- while ((buf[count] != '\n') && (buf[count] != ',') && (count
- <
frstat.st_size - 1))
- count++;
- if (buf[count] == '\n')
- {
- curr_state = PEER_INDEX;
- }
- else if (buf[count] != ',')
- {
- curr_state = OTHER_PEER_INDEX;
- }
- count++;
- break;
- default:
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Found bad data in topology file while in state %d!\n",
- curr_state);
- GNUNET_break(0);
- GNUNET_free (data);
- return connect_attempts;
- }
+ switch (curr_state)
+ {
+ case NUM_PEERS:
+ errno = 0;
+ total_peers = strtoul (&buf[count], NULL, 10);
+ if (errno != 0)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to read number of peers from topology file!\n");
+ GNUNET_free (data);
+ return connect_attempts;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Read %u total peers in topology\n", total_peers);
+ GNUNET_assert (total_peers == pg->total);
+ curr_state = PEER_INDEX;
+ while ((buf[count] != '\n') && (count < frstat.st_size - 1))
+ count++;
+ count++;
+ break;
+ case PEER_INDEX:
+ errno = 0;
+ first_peer_index = strtoul (&buf[count], NULL, 10);
+ if (errno != 0)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to read peer index from topology file!\n");
+ GNUNET_free (data);
+ return connect_attempts;
+ }
+ while ((buf[count] != ':') && (count < frstat.st_size - 1))
+ count++;
+ count++;
+ curr_state = OTHER_PEER_INDEX;
+ break;
+ case COLON:
+ if (1 == sscanf (&buf[count], ":"))
+ curr_state = OTHER_PEER_INDEX;
+ count++;
+ break;
+ case OTHER_PEER_INDEX:
+ errno = 0;
+ second_peer_index = strtoul (&buf[count], NULL, 10);
+ if (errno != 0)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to peer index from topology file!\n");
+ GNUNET_free (data);
+ return connect_attempts;
+ }
+ /* Assume file is written with first peer 1, but array index is 0 */
+ connect_attempts += proc (pg, first_peer_index - 1, second_peer_index
+ - 1, list, GNUNET_YES);
+ while ((buf[count] != '\n') && (buf[count] != ',') && (count
+ <
+ frstat.st_size -
+ 1))
+ count++;
+ if (buf[count] == '\n')
+ {
+ curr_state = PEER_INDEX;
+ }
+ else if (buf[count] != ',')
+ {
+ curr_state = OTHER_PEER_INDEX;
+ }
+ count++;
+ break;
+ default:
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Found bad data in topology file while in state %d!\n",
+ curr_state);
+ GNUNET_break (0);
+ GNUNET_free (data);
+ return connect_attempts;
}
+ }
GNUNET_free (data);
return connect_attempts;
}
@@ -2730,8 +2734,8 @@
*
*/
static unsigned int
-create_ring(struct GNUNET_TESTING_PeerGroup *pg,
- GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list)
+create_ring (struct GNUNET_TESTING_PeerGroup *pg,
+ GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list)
{
unsigned int count;
int connect_attempts;
@@ -2740,13 +2744,13 @@
/* Connect each peer to the next highest numbered peer */
for (count = 0; count < pg->total - 1; count++)
- {
+ {
#if VERBOSE_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connecting peer %d to peer %d\n", count, count + 1);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Connecting peer %d to peer %d\n", count, count + 1);
#endif
- connect_attempts += proc (pg, count, count + 1, list, GNUNET_YES);
- }
+ connect_attempts += proc (pg, count, count + 1, list, GNUNET_YES);
+ }
/* Connect the last peer to the first peer */
connect_attempts += proc (pg, pg->total - 1, 0, list, GNUNET_YES);
@@ -2774,31 +2778,31 @@
*/
static int
friend_file_iterator (void *cls, const GNUNET_HashCode * key, void *value)
- {
- FILE *temp_friend_handle = cls;
- struct GNUNET_TESTING_Daemon *peer = value;
- struct GNUNET_PeerIdentity *temppeer;
- struct GNUNET_CRYPTO_HashAsciiEncoded peer_enc;
+{
+ FILE *temp_friend_handle = cls;
+ struct GNUNET_TESTING_Daemon *peer = value;
+ struct GNUNET_PeerIdentity *temppeer;
+ struct GNUNET_CRYPTO_HashAsciiEncoded peer_enc;
- temppeer = &peer->id;
- GNUNET_CRYPTO_hash_to_enc (&temppeer->hashPubKey, &peer_enc);
- fprintf (temp_friend_handle, "%s\n", (char *) &peer_enc);
+ temppeer = &peer->id;
+ GNUNET_CRYPTO_hash_to_enc (&temppeer->hashPubKey, &peer_enc);
+ fprintf (temp_friend_handle, "%s\n", (char *) &peer_enc);
- return GNUNET_YES;
- }
+ return GNUNET_YES;
+}
struct BlacklistContext
- {
- /*
- * The (open) file handle to write to
- */
- FILE *temp_file_handle;
+{
+ /*
+ * The (open) file handle to write to
+ */
+ FILE *temp_file_handle;
- /*
- * The transport that this peer will be blacklisted on.
- */
- char *transport;
- };
+ /*
+ * The transport that this peer will be blacklisted on.
+ */
+ char *transport;
+};
/**
* Iterator for writing blacklist data to appropriate files.
@@ -2811,20 +2815,21 @@
*/
static int
blacklist_file_iterator (void *cls, const GNUNET_HashCode * key, void *value)
- {
- struct BlacklistContext *blacklist_ctx = cls;
- struct GNUNET_TESTING_Daemon *peer = value;
- struct GNUNET_PeerIdentity *temppeer;
- struct GNUNET_CRYPTO_HashAsciiEncoded peer_enc;
+{
+ struct BlacklistContext *blacklist_ctx = cls;
+ struct GNUNET_TESTING_Daemon *peer = value;
+ struct GNUNET_PeerIdentity *temppeer;
+ struct GNUNET_CRYPTO_HashAsciiEncoded peer_enc;
- temppeer = &peer->id;
- GNUNET_CRYPTO_hash_to_enc (&temppeer->hashPubKey, &peer_enc);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Writing entry %s:%s to file\n",
blacklist_ctx->transport, (char *) &peer_enc);
- fprintf (blacklist_ctx->temp_file_handle, "%s:%s\n",
- blacklist_ctx->transport, (char *) &peer_enc);
+ temppeer = &peer->id;
+ GNUNET_CRYPTO_hash_to_enc (&temppeer->hashPubKey, &peer_enc);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Writing entry %s:%s to file\n",
+ blacklist_ctx->transport, (char *) &peer_enc);
+ fprintf (blacklist_ctx->temp_file_handle, "%s:%s\n",
blacklist_ctx->transport,
+ (char *) &peer_enc);
- return GNUNET_YES;
- }
+ return GNUNET_YES;
+}
#endif
/*
@@ -2835,7 +2840,7 @@
* @param pg the peer group we are dealing with
*/
static int
-create_and_copy_friend_files(struct GNUNET_TESTING_PeerGroup *pg)
+create_and_copy_friend_files (struct GNUNET_TESTING_PeerGroup *pg)
{
FILE *temp_friend_handle;
unsigned int pg_iter;
@@ -2843,6 +2848,7 @@
struct GNUNET_OS_Process **procarr;
char *arg;
char *mytemp;
+
#if NOT_STUPID
enum GNUNET_OS_ProcessStatusType type;
unsigned long return_code;
@@ -2858,147 +2864,137 @@
#endif
procarr = GNUNET_malloc (sizeof (struct GNUNET_OS_Process *) * pg->total);
for (pg_iter = 0; pg_iter < pg->total; pg_iter++)
+ {
+ mytemp = GNUNET_DISK_mktemp ("friends");
+ GNUNET_assert (mytemp != NULL);
+ temp_friend_handle = fopen (mytemp, "wt");
+ GNUNET_assert (temp_friend_handle != NULL);
+#if OLD
+ conn_iter = pg->peers[pg_iter].allowed_peers_head;
+ while (conn_iter != NULL)
{
- mytemp = GNUNET_DISK_mktemp ("friends");
- GNUNET_assert (mytemp != NULL);
- temp_friend_handle = fopen (mytemp, "wt");
- GNUNET_assert (temp_friend_handle != NULL);
-#if OLD
- conn_iter = pg->peers[pg_iter].allowed_peers_head;
- while (conn_iter != NULL)
- {
- GNUNET_CRYPTO_hash_to_enc (
-
&pg->peers[conn_iter->index].daemon->id.hashPubKey,
- &peer_enc);
- fprintf (temp_friend_handle, "%s\n", (char *) &peer_enc);
- conn_iter = conn_iter->next;
- }
+ GNUNET_CRYPTO_hash_to_enc (&pg->peers[conn_iter->index].daemon->
+ id.hashPubKey, &peer_enc);
+ fprintf (temp_friend_handle, "%s\n", (char *) &peer_enc);
+ conn_iter = conn_iter->next;
+ }
#else
- GNUNET_CONTAINER_multihashmap_iterate (pg->peers[pg_iter].allowed_peers,
- &friend_file_iterator,
- temp_friend_handle);
+ GNUNET_CONTAINER_multihashmap_iterate (pg->peers[pg_iter].allowed_peers,
+ &friend_file_iterator,
+ temp_friend_handle);
#endif
- fclose (temp_friend_handle);
+ fclose (temp_friend_handle);
- if (GNUNET_OK
- != GNUNET_CONFIGURATION_get_value_string (pg->peers[pg_iter].
- daemon->cfg,
- "PATHS", "SERVICEHOME",
- &temp_service_path))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("No `%s' specified in peer configuration in section
`%s', cannot copy friends file!\n"),
- "SERVICEHOME", "PATHS");
- if (UNLINK (mytemp) != 0)
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
- "unlink",
- mytemp);
- GNUNET_free (mytemp);
- break;
- }
+ if (GNUNET_OK
+ !=
+ GNUNET_CONFIGURATION_get_value_string (pg->peers[pg_iter].daemon->cfg,
+ "PATHS", "SERVICEHOME",
+ &temp_service_path))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("No `%s' specified in peer configuration in section `%s',
cannot copy friends file!\n"),
+ "SERVICEHOME", "PATHS");
+ if (UNLINK (mytemp) != 0)
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", mytemp);
+ GNUNET_free (mytemp);
+ break;
+ }
- if (pg->peers[pg_iter].daemon->hostname == NULL) /* Local, just copy the
file */
- {
- GNUNET_asprintf (&arg, "%s/friends", temp_service_path);
- procarr[pg_iter] = GNUNET_OS_start_process (NULL, NULL, "mv", "mv",
- mytemp, arg, NULL);
- GNUNET_assert(procarr[pg_iter] != NULL);
+ if (pg->peers[pg_iter].daemon->hostname == NULL) /* Local, just copy
the file */
+ {
+ GNUNET_asprintf (&arg, "%s/friends", temp_service_path);
+ procarr[pg_iter] = GNUNET_OS_start_process (NULL, NULL, "mv", "mv",
+ mytemp, arg, NULL);
+ GNUNET_assert (procarr[pg_iter] != NULL);
#if VERBOSE_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Copying file with command cp %s %s\n",
- mytemp,
- arg);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Copying file with command cp %s %s\n", mytemp, arg);
#endif
- ret = GNUNET_OS_process_wait (procarr[pg_iter]); /* FIXME: schedule
this, throttle! */
- GNUNET_OS_process_close (procarr[pg_iter]);
- GNUNET_free (arg);
- }
- else /* Remote, scp the file to the correct place */
- {
- if (NULL != pg->peers[pg_iter].daemon->username)
- GNUNET_asprintf (&arg, "address@hidden:%s/friends",
- pg->peers[pg_iter].daemon->username,
- pg->peers[pg_iter].daemon->hostname,
- temp_service_path);
- else
- GNUNET_asprintf (&arg, "%s:%s/friends",
- pg->peers[pg_iter].daemon->hostname,
- temp_service_path);
- procarr[pg_iter] = GNUNET_OS_start_process (NULL, NULL, "scp", "scp",
- mytemp, arg, NULL);
- GNUNET_assert(procarr[pg_iter] != NULL);
- ret = GNUNET_OS_process_wait (procarr[pg_iter]); /* FIXME: schedule
this, throttle! */
- GNUNET_OS_process_close (procarr[pg_iter]);
- if (ret != GNUNET_OK)
- {
- /* FIXME: free contents of 'procarr' array */
- GNUNET_free (procarr);
- GNUNET_free (temp_service_path);
- GNUNET_free (mytemp);
- GNUNET_free (arg);
- return ret;
- }
- procarr[pg_iter] = NULL;
+ ret = GNUNET_OS_process_wait (procarr[pg_iter]); /* FIXME: schedule
this, throttle! */
+ GNUNET_OS_process_close (procarr[pg_iter]);
+ GNUNET_free (arg);
+ }
+ else /* Remote, scp the file to the correct place */
+ {
+ if (NULL != pg->peers[pg_iter].daemon->username)
+ GNUNET_asprintf (&arg, "address@hidden:%s/friends",
+ pg->peers[pg_iter].daemon->username,
+ pg->peers[pg_iter].daemon->hostname,
+ temp_service_path);
+ else
+ GNUNET_asprintf (&arg, "%s:%s/friends",
+ pg->peers[pg_iter].daemon->hostname,
+ temp_service_path);
+ procarr[pg_iter] = GNUNET_OS_start_process (NULL, NULL, "scp", "scp",
+ mytemp, arg, NULL);
+ GNUNET_assert (procarr[pg_iter] != NULL);
+ ret = GNUNET_OS_process_wait (procarr[pg_iter]); /* FIXME: schedule
this, throttle! */
+ GNUNET_OS_process_close (procarr[pg_iter]);
+ if (ret != GNUNET_OK)
+ {
+ /* FIXME: free contents of 'procarr' array */
+ GNUNET_free (procarr);
+ GNUNET_free (temp_service_path);
+ GNUNET_free (mytemp);
+ GNUNET_free (arg);
+ return ret;
+ }
+ procarr[pg_iter] = NULL;
#if VERBOSE_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Copying file with command scp %s %s\n",
- mytemp,
- arg);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Copying file with command scp %s %s\n", mytemp, arg);
#endif
- GNUNET_free (arg);
- }
- GNUNET_free (temp_service_path);
- GNUNET_free (mytemp);
+ GNUNET_free (arg);
}
+ GNUNET_free (temp_service_path);
+ GNUNET_free (mytemp);
+ }
#if NOT_STUPID
count = 0;
ret = GNUNET_SYSERR;
while ((count < max_wait) && (ret != GNUNET_OK))
+ {
+ ret = GNUNET_OK;
+ for (pg_iter = 0; pg_iter < pg->total; pg_iter++)
{
- ret = GNUNET_OK;
- for (pg_iter = 0; pg_iter < pg->total; pg_iter++)
- {
#if VERBOSE_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Checking copy status of file %d\n",
- pg_iter);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Checking copy status of file %d\n", pg_iter);
#endif
- if (procarr[pg_iter] != NULL) /* Check for already completed! */
- {
- if (GNUNET_OS_process_status
- (procarr[pg_iter], &type, &return_code) != GNUNET_OK)
- {
- ret = GNUNET_SYSERR;
- }
- else if ((type != GNUNET_OS_PROCESS_EXITED)
- || (return_code != 0))
- {
- ret = GNUNET_SYSERR;
- }
- else
- {
- GNUNET_OS_process_close (procarr[pg_iter]);
- procarr[pg_iter] = NULL;
+ if (procarr[pg_iter] != NULL) /* Check for already completed! */
+ {
+ if (GNUNET_OS_process_status
+ (procarr[pg_iter], &type, &return_code) != GNUNET_OK)
+ {
+ ret = GNUNET_SYSERR;
+ }
+ else if ((type != GNUNET_OS_PROCESS_EXITED) || (return_code != 0))
+ {
+ ret = GNUNET_SYSERR;
+ }
+ else
+ {
+ GNUNET_OS_process_close (procarr[pg_iter]);
+ procarr[pg_iter] = NULL;
#if VERBOSE_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "File %d copied\n",
- pg_iter);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "File %d copied\n", pg_iter);
#endif
- }
- }
}
- count++;
- if (ret == GNUNET_SYSERR)
- {
- /* FIXME: why sleep here? -CG */
- sleep (1);
- }
+ }
}
+ count++;
+ if (ret == GNUNET_SYSERR)
+ {
+ /* FIXME: why sleep here? -CG */
+ sleep (1);
+ }
+ }
#if VERBOSE_TESTING
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Finished copying all friend files!\n"));
+ _("Finished copying all friend files!\n"));
#endif
#endif
GNUNET_free (procarr);
@@ -3014,8 +3010,8 @@
* @param transports space delimited list of transports to blacklist
*/
static int
-create_and_copy_blacklist_files(struct GNUNET_TESTING_PeerGroup *pg,
- const char *transports)
+create_and_copy_blacklist_files (struct GNUNET_TESTING_PeerGroup *pg,
+ const char *transports)
{
FILE *temp_file_handle;
unsigned int pg_iter;
@@ -3032,6 +3028,7 @@
unsigned int i;
char *pos;
char *temp_transports;
+
#if OLD
struct GNUNET_CRYPTO_HashAsciiEncoded peer_enc;
struct PeerConnection *conn_iter;
@@ -3041,155 +3038,149 @@
procarr = GNUNET_malloc (sizeof (struct GNUNET_OS_Process *) * pg->total);
for (pg_iter = 0; pg_iter < pg->total; pg_iter++)
- {
- mytemp = GNUNET_DISK_mktemp ("blacklist");
- GNUNET_assert (mytemp != NULL);
- temp_file_handle = fopen (mytemp, "wt");
- GNUNET_assert (temp_file_handle != NULL);
- temp_transports = GNUNET_strdup (transports);
+ {
+ mytemp = GNUNET_DISK_mktemp ("blacklist");
+ GNUNET_assert (mytemp != NULL);
+ temp_file_handle = fopen (mytemp, "wt");
+ GNUNET_assert (temp_file_handle != NULL);
+ temp_transports = GNUNET_strdup (transports);
#if !OLD
- blacklist_ctx.temp_file_handle = temp_file_handle;
+ blacklist_ctx.temp_file_handle = temp_file_handle;
#endif
- transport_len = strlen (temp_transports) + 1;
- pos = NULL;
+ transport_len = strlen (temp_transports) + 1;
+ pos = NULL;
- for (i = 0; i < transport_len; i++)
+ for (i = 0; i < transport_len; i++)
+ {
+ if ((temp_transports[i] == ' ') && (pos == NULL))
+ continue; /* At start of string (whitespace) */
+ else if ((temp_transports[i] == ' ') || (temp_transports[i] == '\0'))
/* At end of string */
+ {
+ temp_transports[i] = '\0';
+#if OLD
+ conn_iter = pg->peers[pg_iter].blacklisted_peers_head;
+ while (conn_iter != NULL)
{
- if ((temp_transports[i] == ' ') && (pos == NULL))
- continue; /* At start of string (whitespace) */
- else if ((temp_transports[i] == ' ') || (temp_transports[i] ==
'\0')) /* At end of string */
- {
- temp_transports[i] = '\0';
-#if OLD
- conn_iter = pg->peers[pg_iter].blacklisted_peers_head;
- while (conn_iter != NULL)
- {
- GNUNET_CRYPTO_hash_to_enc (
-
&pg->peers[conn_iter->index].daemon->id.hashPubKey,
- &peer_enc);
- fprintf (temp_file_handle, "%s:%s\n", pos, (char *)
&peer_enc);
- conn_iter = conn_iter->next;
- }
+ GNUNET_CRYPTO_hash_to_enc (&pg->peers[conn_iter->index].daemon->
+ id.hashPubKey, &peer_enc);
+ fprintf (temp_file_handle, "%s:%s\n", pos, (char *) &peer_enc);
+ conn_iter = conn_iter->next;
+ }
#else
- blacklist_ctx.transport = pos;
- (void) GNUNET_CONTAINER_multihashmap_iterate (pg->
- peers
-
[pg_iter].blacklisted_peers,
-
&blacklist_file_iterator,
- &blacklist_ctx);
+ blacklist_ctx.transport = pos;
+ (void) GNUNET_CONTAINER_multihashmap_iterate (pg->peers
+
[pg_iter].blacklisted_peers,
+ &blacklist_file_iterator,
+ &blacklist_ctx);
#endif
- pos = NULL;
- } /* At beginning of actual string */
- else if (pos == NULL)
- {
- pos = &temp_transports[i];
- }
- }
+ pos = NULL;
+ } /* At beginning of actual string */
+ else if (pos == NULL)
+ {
+ pos = &temp_transports[i];
+ }
+ }
- GNUNET_free (temp_transports);
- fclose (temp_file_handle);
+ GNUNET_free (temp_transports);
+ fclose (temp_file_handle);
- if (GNUNET_OK
- != GNUNET_CONFIGURATION_get_value_string (
- pg->peers[pg_iter].
daemon->cfg,
- "PATHS", "SERVICEHOME",
- &temp_service_path))
- {
- GNUNET_log (
- GNUNET_ERROR_TYPE_WARNING,
- _
- ("No `%s' specified in peer configuration in section
`%s', cannot copy friends file!\n"),
- "SERVICEHOME", "PATHS");
- if (UNLINK (mytemp) != 0)
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink",
- mytemp);
- GNUNET_free (mytemp);
- break;
- }
+ if (GNUNET_OK
+ !=
+ GNUNET_CONFIGURATION_get_value_string (pg->peers[pg_iter].daemon->cfg,
+ "PATHS", "SERVICEHOME",
+ &temp_service_path))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("No `%s' specified in peer configuration in section `%s',
cannot copy friends file!\n"),
+ "SERVICEHOME", "PATHS");
+ if (UNLINK (mytemp) != 0)
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", mytemp);
+ GNUNET_free (mytemp);
+ break;
+ }
- if (pg->peers[pg_iter].daemon->hostname == NULL) /* Local, just copy the
file */
- {
- GNUNET_asprintf (&arg, "%s/blacklist", temp_service_path);
- procarr[pg_iter] = GNUNET_OS_start_process (NULL, NULL, "mv", "mv",
- mytemp, arg, NULL);
+ if (pg->peers[pg_iter].daemon->hostname == NULL) /* Local, just copy
the file */
+ {
+ GNUNET_asprintf (&arg, "%s/blacklist", temp_service_path);
+ procarr[pg_iter] = GNUNET_OS_start_process (NULL, NULL, "mv", "mv",
+ mytemp, arg, NULL);
#if VERBOSE_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Copying file with command cp %s %s\n"), mytemp, arg);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ _("Copying file with command cp %s %s\n"), mytemp, arg);
#endif
- GNUNET_free (arg);
- }
- else /* Remote, scp the file to the correct place */
- {
- if (NULL != pg->peers[pg_iter].daemon->username)
- GNUNET_asprintf (&arg, "address@hidden:%s/blacklist",
- pg->peers[pg_iter].daemon->username,
- pg->peers[pg_iter].daemon->hostname,
- temp_service_path);
- else
- GNUNET_asprintf (&arg, "%s:%s/blacklist",
- pg->peers[pg_iter].daemon->hostname,
- temp_service_path);
- procarr[pg_iter] = GNUNET_OS_start_process (NULL, NULL, "scp", "scp",
- mytemp, arg, NULL);
- GNUNET_assert(procarr[pg_iter] != NULL);
- GNUNET_OS_process_wait (procarr[pg_iter]); /* FIXME: add scheduled
blacklist file copy that parallelizes file copying! */
+ GNUNET_free (arg);
+ }
+ else /* Remote, scp the file to the correct place */
+ {
+ if (NULL != pg->peers[pg_iter].daemon->username)
+ GNUNET_asprintf (&arg, "address@hidden:%s/blacklist",
+ pg->peers[pg_iter].daemon->username,
+ pg->peers[pg_iter].daemon->hostname,
+ temp_service_path);
+ else
+ GNUNET_asprintf (&arg, "%s:%s/blacklist",
+ pg->peers[pg_iter].daemon->hostname,
+ temp_service_path);
+ procarr[pg_iter] = GNUNET_OS_start_process (NULL, NULL, "scp", "scp",
+ mytemp, arg, NULL);
+ GNUNET_assert (procarr[pg_iter] != NULL);
+ GNUNET_OS_process_wait (procarr[pg_iter]); /* FIXME: add
scheduled blacklist file copy that parallelizes file copying! */
#if VERBOSE_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Copying file with command scp %s %s\n"), mytemp,
- arg);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ _("Copying file with command scp %s %s\n"), mytemp, arg);
#endif
- GNUNET_free (arg);
- }
- GNUNET_free (temp_service_path);
- GNUNET_free (mytemp);
+ GNUNET_free (arg);
}
+ GNUNET_free (temp_service_path);
+ GNUNET_free (mytemp);
+ }
count = 0;
ret = GNUNET_SYSERR;
while ((count < max_wait) && (ret != GNUNET_OK))
+ {
+ ret = GNUNET_OK;
+ for (pg_iter = 0; pg_iter < pg->total; pg_iter++)
{
- ret = GNUNET_OK;
- for (pg_iter = 0; pg_iter < pg->total; pg_iter++)
- {
#if VERBOSE_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Checking copy status of file %d\n"), pg_iter);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ _("Checking copy status of file %d\n"), pg_iter);
#endif
- if (procarr[pg_iter] != NULL) /* Check for already completed! */
- {
- if (GNUNET_OS_process_status (procarr[pg_iter], &type,
- &return_code) != GNUNET_OK)
- {
- ret = GNUNET_SYSERR;
- }
- else if ((type != GNUNET_OS_PROCESS_EXITED) || (return_code !=
0))
- {
- ret = GNUNET_SYSERR;
- }
- else
- {
- GNUNET_OS_process_close (procarr[pg_iter]);
- procarr[pg_iter] = NULL;
+ if (procarr[pg_iter] != NULL) /* Check for already completed! */
+ {
+ if (GNUNET_OS_process_status (procarr[pg_iter], &type,
+ &return_code) != GNUNET_OK)
+ {
+ ret = GNUNET_SYSERR;
+ }
+ else if ((type != GNUNET_OS_PROCESS_EXITED) || (return_code != 0))
+ {
+ ret = GNUNET_SYSERR;
+ }
+ else
+ {
+ GNUNET_OS_process_close (procarr[pg_iter]);
+ procarr[pg_iter] = NULL;
#if VERBOSE_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("File %d copied\n"), pg_iter);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("File %d copied\n"), pg_iter);
#endif
- }
- }
}
- count++;
- if (ret == GNUNET_SYSERR)
- {
- /* FIXME: why sleep here? -CG */
- sleep (1);
- }
+ }
}
+ count++;
+ if (ret == GNUNET_SYSERR)
+ {
+ /* FIXME: why sleep here? -CG */
+ sleep (1);
+ }
+ }
#if VERBOSE_TESTING
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Finished copying all blacklist files!\n"));
+ _("Finished copying all blacklist files!\n"));
#endif
GNUNET_free (procarr);
return ret;
@@ -3197,7 +3188,7 @@
/* Forward Declaration */
static void
-schedule_connect(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
+schedule_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
/**
* Choose a random peer's next connection to create, and
@@ -3206,7 +3197,7 @@
* @param ct_ctx the overall connection context
*/
static void
-preschedule_connect(struct GNUNET_TESTING_PeerGroup *pg)
+preschedule_connect (struct GNUNET_TESTING_PeerGroup *pg)
{
struct ConnectTopologyContext *ct_ctx = &pg->ct_ctx;
struct PeerConnection *connection_iter;
@@ -3227,14 +3218,18 @@
connect_context->second_index = connection_iter->index;
connect_context->ct_ctx = ct_ctx;
GNUNET_SCHEDULER_add_now (&schedule_connect, connect_context);
- GNUNET_CONTAINER_DLL_remove(pg->peers[random_peer].connect_peers_head,
pg->peers[random_peer].connect_peers_tail, connection_iter);
- GNUNET_free(connection_iter);
+ GNUNET_CONTAINER_DLL_remove (pg->peers[random_peer].connect_peers_head,
+ pg->peers[random_peer].connect_peers_tail,
+ connection_iter);
+ GNUNET_free (connection_iter);
ct_ctx->remaining_connections--;
}
#if USE_SEND_HELLOS
/* Forward declaration */
-static void schedule_send_hellos (void *cls, const struct
GNUNET_SCHEDULER_TaskContext *tc);
+static void schedule_send_hellos (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext
+ *tc);
/**
* Close connections and free the hello context.
@@ -3244,26 +3239,27 @@
*/
static void
free_hello_context (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ struct SendHelloContext *send_hello_context = cls;
+
+ if (send_hello_context->peer->daemon->server != NULL)
{
- struct SendHelloContext *send_hello_context = cls;
- if (send_hello_context->peer->daemon->server != NULL)
- {
- GNUNET_CORE_disconnect(send_hello_context->peer->daemon->server);
- send_hello_context->peer->daemon->server = NULL;
- }
- if (send_hello_context->peer->daemon->th != NULL)
- {
- GNUNET_TRANSPORT_disconnect(send_hello_context->peer->daemon->th);
- send_hello_context->peer->daemon->th = NULL;
- }
- if (send_hello_context->core_connect_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel(send_hello_context->core_connect_task);
- send_hello_context->core_connect_task = GNUNET_SCHEDULER_NO_TASK;
- }
- send_hello_context->pg->outstanding_connects--;
- GNUNET_free(send_hello_context);
+ GNUNET_CORE_disconnect (send_hello_context->peer->daemon->server);
+ send_hello_context->peer->daemon->server = NULL;
}
+ if (send_hello_context->peer->daemon->th != NULL)
+ {
+ GNUNET_TRANSPORT_disconnect (send_hello_context->peer->daemon->th);
+ send_hello_context->peer->daemon->th = NULL;
+ }
+ if (send_hello_context->core_connect_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (send_hello_context->core_connect_task);
+ send_hello_context->core_connect_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ send_hello_context->pg->outstanding_connects--;
+ GNUNET_free (send_hello_context);
+}
/**
* For peers that haven't yet connected, notify
@@ -3273,40 +3269,41 @@
* @param tc scheduler context
*/
static void
-notify_remaining_connections_failed (void *cls, const struct
GNUNET_SCHEDULER_TaskContext *tc)
- {
- struct SendHelloContext *send_hello_context = cls;
- struct GNUNET_TESTING_PeerGroup *pg = send_hello_context->pg;
- struct PeerConnection *connection;
+notify_remaining_connections_failed (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext
+ *tc)
+{
+ struct SendHelloContext *send_hello_context = cls;
+ struct GNUNET_TESTING_PeerGroup *pg = send_hello_context->pg;
+ struct PeerConnection *connection;
- GNUNET_CORE_disconnect(send_hello_context->peer->daemon->server);
- send_hello_context->peer->daemon->server = NULL;
+ GNUNET_CORE_disconnect (send_hello_context->peer->daemon->server);
+ send_hello_context->peer->daemon->server = NULL;
- connection = send_hello_context->peer->connect_peers_head;
+ connection = send_hello_context->peer->connect_peers_head;
- while (connection != NULL)
- {
- if (pg->notify_connection != NULL)
- {
- pg->notify_connection(pg->notify_connection_cls,
- &send_hello_context->peer->daemon->id,
- &pg->peers[connection->index].daemon->id,
- 0, /* FIXME */
- send_hello_context->peer->daemon->cfg,
- pg->peers[connection->index].daemon->cfg,
- send_hello_context->peer->daemon,
- pg->peers[connection->index].daemon,
- "Peers failed to connect (timeout)");
- }
-
GNUNET_CONTAINER_DLL_remove(send_hello_context->peer->connect_peers_head,
send_hello_context->peer->connect_peers_tail, connection);
- GNUNET_free(connection);
- connection = connection->next;
- }
- GNUNET_SCHEDULER_add_now(&free_hello_context, send_hello_context);
+ while (connection != NULL)
+ {
+ if (pg->notify_connection != NULL)
+ {
+ pg->notify_connection (pg->notify_connection_cls,
&send_hello_context->peer->daemon->id,
&pg->peers[connection->index].daemon->id, 0, /* FIXME */
+ send_hello_context->peer->daemon->cfg,
+ pg->peers[connection->index].daemon->cfg,
+ send_hello_context->peer->daemon,
+ pg->peers[connection->index].daemon,
+ "Peers failed to connect (timeout)");
+ }
+ GNUNET_CONTAINER_DLL_remove (send_hello_context->peer->connect_peers_head,
+ send_hello_context->peer->connect_peers_tail,
+ connection);
+ GNUNET_free (connection);
+ connection = connection->next;
+ }
+ GNUNET_SCHEDULER_add_now (&free_hello_context, send_hello_context);
#if BAD
- other_peer = &pg->peers[connection->index];
+ other_peer = &pg->peers[connection->index];
#endif
- }
+}
/**
* For peers that haven't yet connected, send
@@ -3316,38 +3313,49 @@
* @param tc scheduler context
*/
static void
-send_core_connect_requests (void *cls, const struct
GNUNET_SCHEDULER_TaskContext *tc)
- {
- struct SendHelloContext *send_hello_context = cls;
- struct PeerConnection *conn;
- GNUNET_assert(send_hello_context->peer->daemon->server != NULL);
+send_core_connect_requests (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ struct SendHelloContext *send_hello_context = cls;
+ struct PeerConnection *conn;
- send_hello_context->core_connect_task = GNUNET_SCHEDULER_NO_TASK;
+ GNUNET_assert (send_hello_context->peer->daemon->server != NULL);
- send_hello_context->connect_attempts++;
- if (send_hello_context->connect_attempts <
send_hello_context->pg->ct_ctx.connect_attempts)
- {
- conn = send_hello_context->peer->connect_peers_head;
- while (conn != NULL)
- {
-
GNUNET_CORE_peer_request_connect(send_hello_context->peer->daemon->server,
- &send_hello_context->pg->peers[conn->index].daemon->id,
- NULL,
- NULL);
- conn = conn->next;
- }
- send_hello_context->core_connect_task =
GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_divide(send_hello_context->pg->ct_ctx.connect_timeout,
send_hello_context->pg->ct_ctx.connect_attempts) ,
- &send_core_connect_requests,
- send_hello_context);
- }
- else
- {
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Timeout before all connections
created, marking rest as failed!\n");
- GNUNET_SCHEDULER_add_now(¬ify_remaining_connections_failed,
send_hello_context);
- }
+ send_hello_context->core_connect_task = GNUNET_SCHEDULER_NO_TASK;
+ send_hello_context->connect_attempts++;
+ if (send_hello_context->connect_attempts <
+ send_hello_context->pg->ct_ctx.connect_attempts)
+ {
+ conn = send_hello_context->peer->connect_peers_head;
+ while (conn != NULL)
+ {
+ GNUNET_CORE_peer_request_connect (send_hello_context->peer->
+ daemon->server,
+ &send_hello_context->pg->
+ peers[conn->index].daemon->id, NULL,
+ NULL);
+ conn = conn->next;
+ }
+ send_hello_context->core_connect_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide
+ (send_hello_context->pg->
+ ct_ctx.connect_timeout,
+ send_hello_context->pg->
+ ct_ctx.connect_attempts),
+ &send_core_connect_requests,
+ send_hello_context);
}
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Timeout before all connections created, marking rest as
failed!\n");
+ GNUNET_SCHEDULER_add_now (¬ify_remaining_connections_failed,
+ send_hello_context);
+ }
+}
+
/**
* Success, connection is up. Signal client our success.
*
@@ -3361,96 +3369,101 @@
*/
static void
core_connect_notify (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi)
- {
- struct SendHelloContext *send_hello_context = cls;
- struct PeerConnection *connection;
- struct GNUNET_TESTING_PeerGroup *pg = send_hello_context->pg;
+ const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+{
+ struct SendHelloContext *send_hello_context = cls;
+ struct PeerConnection *connection;
+ struct GNUNET_TESTING_PeerGroup *pg = send_hello_context->pg;
+
#if BAD
- struct PeerData *other_peer;
+ struct PeerData *other_peer;
#endif
#if DEBUG_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Connected peer %s to peer %s\n",
- ctx->d1->shortname, GNUNET_i2s(peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Connected peer %s to peer %s\n",
+ ctx->d1->shortname, GNUNET_i2s (peer));
#endif
- if (0 == memcmp(&send_hello_context->peer->daemon->id, peer, sizeof(struct
GNUNET_PeerIdentity)))
+ if (0 ==
+ memcmp (&send_hello_context->peer->daemon->id, peer,
+ sizeof (struct GNUNET_PeerIdentity)))
return;
- connection = send_hello_context->peer->connect_peers_head;
+ connection = send_hello_context->peer->connect_peers_head;
#if BAD
- other_peer = NULL;
+ other_peer = NULL;
#endif
- while ((connection != NULL) &&
- (0 != memcmp(&pg->peers[connection->index].daemon->id, peer,
sizeof(struct GNUNET_PeerIdentity))))
- {
- connection = connection->next;
- }
+ while ((connection != NULL) &&
+ (0 !=
+ memcmp (&pg->peers[connection->index].daemon->id, peer,
+ sizeof (struct GNUNET_PeerIdentity))))
+ {
+ connection = connection->next;
+ }
- if (connection == NULL)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Connected peer %s to %s, not in
list (no problem(?))\n", GNUNET_i2s(peer),
send_hello_context->peer->daemon->shortname);
- }
- else
- {
+ if (connection == NULL)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Connected peer %s to %s, not in list (no problem(?))\n",
+ GNUNET_i2s (peer),
send_hello_context->peer->daemon->shortname);
+ }
+ else
+ {
#if BAD
- other_peer = &pg->peers[connection->index];
+ other_peer = &pg->peers[connection->index];
#endif
- if (pg->notify_connection != NULL)
- {
- pg->notify_connection(pg->notify_connection_cls,
- &send_hello_context->peer->daemon->id,
- peer,
- 0, /* FIXME */
- send_hello_context->peer->daemon->cfg,
- pg->peers[connection->index].daemon->cfg,
- send_hello_context->peer->daemon,
- pg->peers[connection->index].daemon,
- NULL);
- }
-
GNUNET_CONTAINER_DLL_remove(send_hello_context->peer->connect_peers_head,
send_hello_context->peer->connect_peers_tail, connection);
- GNUNET_free(connection);
- }
+ if (pg->notify_connection != NULL)
+ {
+ pg->notify_connection (pg->notify_connection_cls,
&send_hello_context->peer->daemon->id, peer, 0, /* FIXME */
+ send_hello_context->peer->daemon->cfg,
+ pg->peers[connection->index].daemon->cfg,
+ send_hello_context->peer->daemon,
+ pg->peers[connection->index].daemon, NULL);
+ }
+ GNUNET_CONTAINER_DLL_remove (send_hello_context->peer->connect_peers_head,
+ send_hello_context->peer->connect_peers_tail,
+ connection);
+ GNUNET_free (connection);
+ }
#if BAD
- /* Notify of reverse connection and remove from other peers list of
outstanding */
- if (other_peer != NULL)
+ /* Notify of reverse connection and remove from other peers list of
outstanding */
+ if (other_peer != NULL)
+ {
+ connection = other_peer->connect_peers_head;
+ while ((connection != NULL) &&
+ (0 !=
+ memcmp (&send_hello_context->peer->daemon->id,
+ &pg->peers[connection->index].daemon->id,
+ sizeof (struct GNUNET_PeerIdentity))))
+ {
+ connection = connection->next;
+ }
+ if (connection != NULL)
+ {
+ if (pg->notify_connection != NULL)
{
- connection = other_peer->connect_peers_head;
- while ((connection != NULL) &&
- (0 != memcmp(&send_hello_context->peer->daemon->id,
&pg->peers[connection->index].daemon->id, sizeof(struct GNUNET_PeerIdentity))))
- {
- connection = connection->next;
- }
- if (connection != NULL)
- {
- if (pg->notify_connection != NULL)
- {
- pg->notify_connection(pg->notify_connection_cls,
- peer,
- &send_hello_context->peer->daemon->id,
- 0, /* FIXME */
- pg->peers[connection->index].daemon->cfg,
- send_hello_context->peer->daemon->cfg,
- pg->peers[connection->index].daemon,
- send_hello_context->peer->daemon,
- NULL);
- }
+ pg->notify_connection (pg->notify_connection_cls, peer,
&send_hello_context->peer->daemon->id, 0, /* FIXME */
+ pg->peers[connection->index].daemon->cfg,
+ send_hello_context->peer->daemon->cfg,
+ pg->peers[connection->index].daemon,
+ send_hello_context->peer->daemon, NULL);
+ }
- GNUNET_CONTAINER_DLL_remove(other_peer->connect_peers_head,
other_peer->connect_peers_tail, connection);
- GNUNET_free(connection);
- }
- }
+ GNUNET_CONTAINER_DLL_remove (other_peer->connect_peers_head,
+ other_peer->connect_peers_tail, connection);
+ GNUNET_free (connection);
+ }
+ }
#endif
- if (send_hello_context->peer->connect_peers_head == NULL)
- {
- GNUNET_SCHEDULER_add_now(&free_hello_context, send_hello_context);
- }
+ if (send_hello_context->peer->connect_peers_head == NULL)
+ {
+ GNUNET_SCHEDULER_add_now (&free_hello_context, send_hello_context);
}
+}
/**
* Notify of a successful connection to the core service.
@@ -3462,17 +3475,15 @@
*/
void
core_init (void *cls,
- struct GNUNET_CORE_Handle * server,
- const struct GNUNET_PeerIdentity *
- my_identity,
- const struct
- GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *
- publicKey)
- {
- struct SendHelloContext *send_hello_context = cls;
- send_hello_context->core_ready = GNUNET_YES;
- }
+ struct GNUNET_CORE_Handle *server,
+ const struct GNUNET_PeerIdentity *my_identity,
+ const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
+{
+ struct SendHelloContext *send_hello_context = cls;
+ send_hello_context->core_ready = GNUNET_YES;
+}
+
/**
* Function called once a hello has been sent
* to the transport, move on to the next one
@@ -3483,55 +3494,58 @@
*/
static void
hello_sent_callback (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ struct SendHelloContext *send_hello_context = cls;
+
+ //unsigned int pg_iter;
+ if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
{
- struct SendHelloContext *send_hello_context = cls;
- //unsigned int pg_iter;
- if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- {
- GNUNET_free(send_hello_context);
- return;
- }
+ GNUNET_free (send_hello_context);
+ return;
+ }
- send_hello_context->pg->remaining_hellos--;
+ send_hello_context->pg->remaining_hellos--;
#if DEBUG_TESTING
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Sent HELLO, have %d remaining!\n",
send_hello_context->pg->remaining_hellos);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Sent HELLO, have %d remaining!\n",
+ send_hello_context->pg->remaining_hellos);
#endif
- if (send_hello_context->peer_pos == NULL) /* All HELLOs (for this peer!)
have been transmitted! */
- {
+ if (send_hello_context->peer_pos == NULL) /* All HELLOs (for this peer!)
have been transmitted! */
+ {
#if DEBUG_TESTING
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "All hellos for this peer sent,
disconnecting transport!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "All hellos for this peer sent, disconnecting transport!\n");
#endif
- GNUNET_assert(send_hello_context->peer->daemon->th != NULL);
- GNUNET_TRANSPORT_disconnect(send_hello_context->peer->daemon->th);
- send_hello_context->peer->daemon->th = NULL;
+ GNUNET_assert (send_hello_context->peer->daemon->th != NULL);
+ GNUNET_TRANSPORT_disconnect (send_hello_context->peer->daemon->th);
+ send_hello_context->peer->daemon->th = NULL;
- /*if (send_hello_context->pg->remaining_hellos == 0)
- {
- for (pg_iter = 0; pg_iter <
send_hello_context->pg->max_outstanding_connections; pg_iter++)
- {
- preschedule_connect(&send_hello_context->pg->ct_ctx);
- }
- }
- */
- GNUNET_assert (send_hello_context->peer->daemon->server == NULL);
- send_hello_context->peer->daemon->server =
GNUNET_CORE_connect(send_hello_context->peer->cfg,
- 1,
- send_hello_context,
- &core_init,
- &core_connect_notify,
- NULL,
- NULL,
- NULL, GNUNET_NO,
- NULL, GNUNET_NO,
- no_handlers);
+ /*if (send_hello_context->pg->remaining_hellos == 0)
+ * {
+ * for (pg_iter = 0; pg_iter <
send_hello_context->pg->max_outstanding_connections; pg_iter++)
+ * {
+ * preschedule_connect(&send_hello_context->pg->ct_ctx);
+ * }
+ * }
+ */
+ GNUNET_assert (send_hello_context->peer->daemon->server == NULL);
+ send_hello_context->peer->daemon->server =
+ GNUNET_CORE_connect (send_hello_context->peer->cfg, 1,
+ send_hello_context, &core_init,
+ &core_connect_notify, NULL, NULL, NULL, GNUNET_NO,
+ NULL, GNUNET_NO, no_handlers);
- send_hello_context->core_connect_task =
GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_divide(send_hello_context->pg->ct_ctx.connect_timeout,
send_hello_context->pg->ct_ctx.connect_attempts),
- &send_core_connect_requests,
- send_hello_context);
- }
- else
- GNUNET_SCHEDULER_add_now(&schedule_send_hellos, send_hello_context);
+ send_hello_context->core_connect_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide
+ (send_hello_context->pg->
+ ct_ctx.connect_timeout,
+ send_hello_context->pg->
+ ct_ctx.connect_attempts),
+ &send_core_connect_requests,
+ send_hello_context);
}
+ else
+ GNUNET_SCHEDULER_add_now (&schedule_send_hellos, send_hello_context);
+}
/**
* Connect to a peer, give it all the HELLO's of those peers
@@ -3539,59 +3553,63 @@
*
* @param ct_ctx the overall connection context
*/
-static void schedule_send_hellos (void *cls, const struct
GNUNET_SCHEDULER_TaskContext *tc)
+static void
+schedule_send_hellos (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ struct SendHelloContext *send_hello_context = cls;
+ struct GNUNET_TESTING_PeerGroup *pg = send_hello_context->pg;
+
+ if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
{
- struct SendHelloContext *send_hello_context = cls;
- struct GNUNET_TESTING_PeerGroup *pg = send_hello_context->pg;
+ GNUNET_free (send_hello_context);
+ return;
+ }
- if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- {
- GNUNET_free(send_hello_context);
- return;
- }
+ GNUNET_assert (send_hello_context->peer_pos != NULL); /* All of the HELLO
sends to be scheduled have been scheduled! */
- GNUNET_assert(send_hello_context->peer_pos != NULL); /* All of the HELLO
sends to be scheduled have been scheduled! */
-
- if (((send_hello_context->peer->daemon->th == NULL) &&
- (pg->outstanding_connects > pg->max_outstanding_connections)) ||
- (pg->stop_connects == GNUNET_YES))
- {
+ if (((send_hello_context->peer->daemon->th == NULL) &&
+ (pg->outstanding_connects > pg->max_outstanding_connections)) ||
+ (pg->stop_connects == GNUNET_YES))
+ {
#if VERBOSE_TESTING > 2
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _
- ("Delaying connect, we have too many outstanding connections!\n"));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ _
+ ("Delaying connect, we have too many outstanding
connections!\n"));
#endif
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_MILLISECONDS, 100),
- &schedule_send_hellos, send_hello_context);
- }
- else
- {
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MILLISECONDS, 100),
+ &schedule_send_hellos, send_hello_context);
+ }
+ else
+ {
#if VERBOSE_TESTING > 2
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Creating connection, outstanding_connections is %d\n"),
- outstanding_connects);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ _("Creating connection, outstanding_connections is %d\n"),
+ outstanding_connects);
#endif
- if (send_hello_context->peer->daemon->th == NULL)
- {
- pg->outstanding_connects++; /* Actual TRANSPORT, CORE connections!
*/
- send_hello_context->peer->daemon->th
- = GNUNET_TRANSPORT_connect (send_hello_context->peer->cfg,
NULL,
- send_hello_context, NULL, NULL,
NULL);
- }
+ if (send_hello_context->peer->daemon->th == NULL)
+ {
+ pg->outstanding_connects++; /* Actual TRANSPORT, CORE connections!
*/
+ send_hello_context->peer->daemon->th
+ = GNUNET_TRANSPORT_connect (send_hello_context->peer->cfg, NULL,
+ send_hello_context, NULL, NULL, NULL);
+ }
#if DEBUG_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Offering Hello of peer %s to peer %s\n"),
- send_hello_context->peer->daemon->shortname,
pg->peers[send_hello_context->peer_pos->index].daemon->shortname);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Offering Hello of peer %s to peer %s\n"),
+ send_hello_context->peer->daemon->shortname,
+ pg->peers[send_hello_context->peer_pos->index].
+ daemon->shortname);
#endif
- GNUNET_TRANSPORT_offer_hello(send_hello_context->peer->daemon->th,
- (const struct GNUNET_MessageHeader
*)pg->peers[send_hello_context->peer_pos->index].daemon->hello,
- &hello_sent_callback,
- send_hello_context);
- send_hello_context->peer_pos = send_hello_context->peer_pos->next;
- GNUNET_assert(send_hello_context->peer->daemon->th != NULL);
- }
+ GNUNET_TRANSPORT_offer_hello (send_hello_context->peer->daemon->th,
+ (const struct GNUNET_MessageHeader *)
+ pg->peers[send_hello_context->peer_pos->
+ index].daemon->hello,
+ &hello_sent_callback, send_hello_context);
+ send_hello_context->peer_pos = send_hello_context->peer_pos->next;
+ GNUNET_assert (send_hello_context->peer->daemon->th != NULL);
}
+}
#endif
/**
@@ -3599,14 +3617,14 @@
* happen instead of flooding all testing daemons with requests to connect.
*/
static void
-internal_connect_notify(void *cls, const struct GNUNET_PeerIdentity *first,
- const struct GNUNET_PeerIdentity *second,
- uint32_t distance,
- const struct GNUNET_CONFIGURATION_Handle *first_cfg,
- const struct GNUNET_CONFIGURATION_Handle *second_cfg,
- struct GNUNET_TESTING_Daemon *first_daemon,
- struct GNUNET_TESTING_Daemon *second_daemon,
- const char *emsg)
+internal_connect_notify (void *cls, const struct GNUNET_PeerIdentity *first,
+ const struct GNUNET_PeerIdentity *second,
+ uint32_t distance,
+ const struct GNUNET_CONFIGURATION_Handle *first_cfg,
+ const struct GNUNET_CONFIGURATION_Handle *second_cfg,
+ struct GNUNET_TESTING_Daemon *first_daemon,
+ struct GNUNET_TESTING_Daemon *second_daemon,
+ const char *emsg)
{
struct ConnectContext *connect_ctx = cls;
struct ConnectTopologyContext *ct_ctx = connect_ctx->ct_ctx;
@@ -3627,33 +3645,41 @@
#endif
while ((connection != NULL) && (0
- != memcmp (first, &pg->peers[connection->index].daemon->id,
- sizeof(struct GNUNET_PeerIdentity))))
- {
- connection = connection->next;
- }
+ != memcmp (first,
+ &pg->peers[connection->
+ index].daemon->id,
+ sizeof (struct
+ GNUNET_PeerIdentity))))
+ {
+ connection = connection->next;
+ }
- if (connection != NULL) /* Can safely remove! */
- {
- GNUNET_assert (0 < ct_ctx->remaining_connections);
- ct_ctx->remaining_connections--;
- if (pg->notify_connection != NULL) /* Notify of reverse connection */
- pg->notify_connection (pg->notify_connection_cls, second, first,
- distance, second_cfg, first_cfg, second_daemon,
- first_daemon, emsg);
+ if (connection != NULL) /* Can safely remove! */
+ {
+ GNUNET_assert (0 < ct_ctx->remaining_connections);
+ ct_ctx->remaining_connections--;
+ if (pg->notify_connection != NULL) /* Notify of reverse connection */
+ pg->notify_connection (pg->notify_connection_cls, second, first,
+ distance, second_cfg, first_cfg, second_daemon,
+ first_daemon, emsg);
-
GNUNET_CONTAINER_DLL_remove(pg->peers[connect_ctx->second_index].connect_peers_head,
pg->peers[connect_ctx->second_index].connect_peers_tail, connection);
- GNUNET_free(connection);
- }
+ GNUNET_CONTAINER_DLL_remove (pg->
+ peers[connect_ctx->
+ second_index].connect_peers_head,
+ pg->peers[connect_ctx->
+ second_index].connect_peers_tail,
+ connection);
+ GNUNET_free (connection);
+ }
if (ct_ctx->remaining_connections == 0)
+ {
+ if (ct_ctx->notify_connections_done != NULL)
{
- if (ct_ctx->notify_connections_done != NULL)
- {
- ct_ctx->notify_connections_done (ct_ctx->notify_cls, NULL);
- ct_ctx->notify_connections_done = NULL;
- }
+ ct_ctx->notify_connections_done (ct_ctx->notify_cls, NULL);
+ ct_ctx->notify_connections_done = NULL;
}
+ }
else
preschedule_connect (pg);
@@ -3662,7 +3688,7 @@
first_cfg, second_cfg, first_daemon, second_daemon,
emsg);
- GNUNET_free(connect_ctx);
+ GNUNET_free (connect_ctx);
}
/**
@@ -3673,49 +3699,49 @@
* @param tc the task runtime context
*/
static void
-schedule_connect(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+schedule_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct ConnectContext *connect_context = cls;
struct GNUNET_TESTING_PeerGroup *pg = connect_context->ct_ctx->pg;
- if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
+ if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
return;
if ((pg->outstanding_connects > pg->max_outstanding_connections)
|| (pg->stop_connects == GNUNET_YES))
- {
+ {
#if VERBOSE_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _
- ("Delaying connect, we have too many outstanding connections!\n"));
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Delaying connect, we have too many outstanding
connections!\n"));
#endif
- GNUNET_SCHEDULER_add_delayed (
- GNUNET_TIME_relative_multiply (
-
GNUNET_TIME_UNIT_MILLISECONDS,
- 100),
- &schedule_connect, connect_context);
- }
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MILLISECONDS, 100),
+ &schedule_connect, connect_context);
+ }
else
- {
+ {
#if VERBOSE_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Creating connection, outstanding_connections is %d (max %d)\n"),
- pg->outstanding_connects, pg->max_outstanding_connections);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Creating connection, outstanding_connections is %d (max
%d)\n"),
+ pg->outstanding_connects, pg->max_outstanding_connections);
#endif
- pg->outstanding_connects++;
- pg->total_connects_scheduled++;
- GNUNET_TESTING_daemons_connect (
-
pg->peers[connect_context->first_index].daemon,
-
pg->peers[connect_context->second_index].daemon,
- connect_context->ct_ctx->connect_timeout,
-
connect_context->ct_ctx->connect_attempts,
+ pg->outstanding_connects++;
+ pg->total_connects_scheduled++;
+ GNUNET_TESTING_daemons_connect (pg->
+ peers[connect_context->first_index].daemon,
+ pg->peers[connect_context->
+ second_index].daemon,
+ connect_context->ct_ctx->connect_timeout,
+ connect_context->ct_ctx->connect_attempts,
#if USE_SEND_HELLOS
- GNUNET_NO,
+ GNUNET_NO,
#else
- GNUNET_YES,
+ GNUNET_YES,
#endif
- &internal_connect_notify,
connect_context); /* FIXME: free connect context! */
- }
+ &internal_connect_notify,
connect_context); /* FIXME: free connect context! */
+ }
}
#if !OLD
@@ -3731,20 +3757,20 @@
*/
static int
connect_iterator (void *cls, const GNUNET_HashCode * key, void *value)
- {
- struct ConnectTopologyContext *ct_ctx = cls;
- struct PeerData *first = ct_ctx->first;
- struct GNUNET_TESTING_Daemon *second = value;
- struct ConnectContext *connect_context;
+{
+ struct ConnectTopologyContext *ct_ctx = cls;
+ struct PeerData *first = ct_ctx->first;
+ struct GNUNET_TESTING_Daemon *second = value;
+ struct ConnectContext *connect_context;
- connect_context = GNUNET_malloc (sizeof (struct ConnectContext));
- connect_context->first = first->daemon;
- connect_context->second = second;
- connect_context->ct_ctx = ct_ctx;
- GNUNET_SCHEDULER_add_now (&schedule_connect, connect_context);
+ connect_context = GNUNET_malloc (sizeof (struct ConnectContext));
+ connect_context->first = first->daemon;
+ connect_context->second = second;
+ connect_context->ct_ctx = ct_ctx;
+ GNUNET_SCHEDULER_add_now (&schedule_connect, connect_context);
- return GNUNET_YES;
- }
+ return GNUNET_YES;
+}
#endif
#if !OLD
@@ -3760,16 +3786,16 @@
*/
static int
copy_topology_iterator (void *cls, const GNUNET_HashCode * key, void *value)
- {
- struct PeerData *first = cls;
+{
+ struct PeerData *first = cls;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_put (first->connect_peers, key,
- value,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONTAINER_multihashmap_put (first->connect_peers, key,
+ value,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
- return GNUNET_YES;
- }
+ return GNUNET_YES;
+}
#endif
/**
@@ -3779,42 +3805,41 @@
* @param pg the peer group
*/
static int
-copy_allowed_topology(struct GNUNET_TESTING_PeerGroup *pg)
+copy_allowed_topology (struct GNUNET_TESTING_PeerGroup *pg)
{
unsigned int pg_iter;
int ret;
int total;
+
#if OLD
struct PeerConnection *iter;
#endif
total = 0;
ret = 0;
for (pg_iter = 0; pg_iter < pg->total; pg_iter++)
+ {
+#if OLD
+ iter = pg->peers[pg_iter].allowed_peers_head;
+ while (iter != NULL)
{
-#if OLD
- iter = pg->peers[pg_iter].allowed_peers_head;
- while (iter != NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Creating connection between %d and %d\n", pg_iter,
- iter->index);
- total += add_connections (pg, pg_iter, iter->index, CONNECT,
- GNUNET_YES);
- //total += add_actual_connections(pg, pg_iter, iter->index);
- iter = iter->next;
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Creating connection between %d and %d\n", pg_iter,
+ iter->index);
+ total += add_connections (pg, pg_iter, iter->index, CONNECT, GNUNET_YES);
+ //total += add_actual_connections(pg, pg_iter, iter->index);
+ iter = iter->next;
+ }
#else
- ret =
- GNUNET_CONTAINER_multihashmap_iterate (pg->
- peers[pg_iter].allowed_peers,
- ©_topology_iterator,
- &pg->peers[pg_iter]);
+ ret =
+ GNUNET_CONTAINER_multihashmap_iterate
(pg->peers[pg_iter].allowed_peers,
+ ©_topology_iterator,
+ &pg->peers[pg_iter]);
#endif
- if (GNUNET_SYSERR == ret)
- return GNUNET_SYSERR;
+ if (GNUNET_SYSERR == ret)
+ return GNUNET_SYSERR;
- total = total + ret;
- }
+ total = total + ret;
+ }
return total;
}
@@ -3832,11 +3857,11 @@
* @return the number of connections that will be attempted
*/
static int
-connect_topology(struct GNUNET_TESTING_PeerGroup *pg,
- struct GNUNET_TIME_Relative connect_timeout,
- unsigned int connect_attempts,
- GNUNET_TESTING_NotifyCompletion notify_callback,
- void *notify_cls)
+connect_topology (struct GNUNET_TESTING_PeerGroup *pg,
+ struct GNUNET_TIME_Relative connect_timeout,
+ unsigned int connect_attempts,
+ GNUNET_TESTING_NotifyCompletion notify_callback,
+ void *notify_cls)
{
unsigned int pg_iter;
unsigned int total;
@@ -3854,19 +3879,19 @@
pg->ct_ctx.pg = pg;
for (pg_iter = 0; pg_iter < pg->total; pg_iter++)
+ {
+#if OLD
+ connection_iter = pg->peers[pg_iter].connect_peers_head;
+ while (connection_iter != NULL)
{
-#if OLD
- connection_iter = pg->peers[pg_iter].connect_peers_head;
- while (connection_iter != NULL)
- {
- connection_iter = connection_iter->next;
- total++;
- }
+ connection_iter = connection_iter->next;
+ total++;
+ }
#else
- total +=
- GNUNET_CONTAINER_multihashmap_size (pg->peers[pg_iter].connect_peers);
+ total +=
+ GNUNET_CONTAINER_multihashmap_size (pg->peers[pg_iter].connect_peers);
#endif
- }
+ }
if (total == 0)
return total;
@@ -3879,18 +3904,18 @@
/* First give all peers the HELLO's of other peers (connect to first peer's
transport service, give HELLO's of other peers, continue...) */
pg->remaining_hellos = total;
for (pg_iter = 0; pg_iter < pg->total; pg_iter++)
- {
- send_hello_context = GNUNET_malloc(sizeof(struct SendHelloContext));
- send_hello_context->peer = &pg->peers[pg_iter];
- send_hello_context->peer_pos = pg->peers[pg_iter].connect_peers_head;
- send_hello_context->pg = pg;
- GNUNET_SCHEDULER_add_now(&schedule_send_hellos, send_hello_context);
- }
+ {
+ send_hello_context = GNUNET_malloc (sizeof (struct SendHelloContext));
+ send_hello_context->peer = &pg->peers[pg_iter];
+ send_hello_context->peer_pos = pg->peers[pg_iter].connect_peers_head;
+ send_hello_context->pg = pg;
+ GNUNET_SCHEDULER_add_now (&schedule_send_hellos, send_hello_context);
+ }
#else
for (pg_iter = 0; pg_iter < pg->max_outstanding_connections; pg_iter++)
- {
- preschedule_connect (pg);
- }
+ {
+ preschedule_connect (pg);
+ }
#endif
return total;
@@ -3918,10 +3943,10 @@
* connected to each other
*/
unsigned int
-GNUNET_TESTING_create_topology(struct GNUNET_TESTING_PeerGroup *pg,
- enum GNUNET_TESTING_Topology topology,
- enum GNUNET_TESTING_Topology restrict_topology,
- const char *restrict_transports)
+GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg,
+ enum GNUNET_TESTING_Topology topology,
+ enum GNUNET_TESTING_Topology restrict_topology,
+ const char *restrict_transports)
{
int ret;
@@ -3934,20 +3959,18 @@
#if !OLD
unsigned int i;
+
for (i = 0; i < pg->total; i++)
- {
- pg->peers[i].allowed_peers =
- GNUNET_CONTAINER_multihashmap_create (100);
- pg->peers[i].connect_peers =
- GNUNET_CONTAINER_multihashmap_create (100);
- pg->peers[i].blacklisted_peers =
- GNUNET_CONTAINER_multihashmap_create (100);
- pg->peers[i].pg = pg;
- }
+ {
+ pg->peers[i].allowed_peers = GNUNET_CONTAINER_multihashmap_create (100);
+ pg->peers[i].connect_peers = GNUNET_CONTAINER_multihashmap_create (100);
+ pg->peers[i].blacklisted_peers = GNUNET_CONTAINER_multihashmap_create
(100);
+ pg->peers[i].pg = pg;
+ }
#endif
switch (topology)
- {
+ {
case GNUNET_TESTING_TOPOLOGY_CLIQUE:
#if VERBOSE_TESTING
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Creating clique topology\n"));
@@ -3957,14 +3980,14 @@
case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD_RING:
#if VERBOSE_TESTING
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Creating small world (ring) topology\n"));
+ _("Creating small world (ring) topology\n"));
#endif
num_connections = create_small_world_ring (pg, &add_connections, ALLOWED);
break;
case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD:
#if VERBOSE_TESTING
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Creating small world (2d-torus) topology\n"));
+ _("Creating small world (2d-torus) topology\n"));
#endif
num_connections = create_small_world (pg, &add_connections, ALLOWED);
break;
@@ -3982,8 +4005,7 @@
break;
case GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI:
#if VERBOSE_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Creating Erdos-Renyi topology\n"));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Creating Erdos-Renyi topology\n"));
#endif
num_connections = create_erdos_renyi (pg, &add_connections, ALLOWED);
break;
@@ -3995,22 +4017,20 @@
break;
case GNUNET_TESTING_TOPOLOGY_SCALE_FREE:
#if VERBOSE_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Creating Scale Free topology\n"));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Creating Scale Free topology\n"));
#endif
num_connections = create_scale_free (pg, &add_connections, ALLOWED);
break;
case GNUNET_TESTING_TOPOLOGY_LINE:
#if VERBOSE_TESTING
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Creating straight line topology\n"));
+ _("Creating straight line topology\n"));
#endif
num_connections = create_line (pg, &add_connections, ALLOWED);
break;
case GNUNET_TESTING_TOPOLOGY_FROM_FILE:
#if VERBOSE_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Creating topology from file!\n"));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Creating topology from file!\n"));
#endif
if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "testing",
"topology_file",
@@ -4018,50 +4038,50 @@
num_connections = create_from_file (pg, filename, &add_connections,
ALLOWED);
else
- {
- GNUNET_log (
- GNUNET_ERROR_TYPE_WARNING,
- "Missing configuration option TESTING:TOPOLOGY_FILE for
creating topology from file!\n");
- num_connections = 0;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Missing configuration option TESTING:TOPOLOGY_FILE for
creating topology from file!\n");
+ num_connections = 0;
+ }
break;
case GNUNET_TESTING_TOPOLOGY_NONE:
#if VERBOSE_TESTING
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _
- ("Creating no allowed topology (all peers can connect at core
level)\n"));
+ _
+ ("Creating no allowed topology (all peers can connect at core
level)\n"));
#endif
- num_connections = pg->total * pg->total; /* Clique is allowed! */
+ num_connections = pg->total * pg->total; /* Clique is allowed! */
break;
default:
num_connections = 0;
break;
- }
+ }
if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (pg->cfg, "TESTING",
"F2F"))
+ {
+ ret = create_and_copy_friend_files (pg);
+ if (ret != GNUNET_OK)
{
- ret = create_and_copy_friend_files (pg);
- if (ret != GNUNET_OK)
- {
#if VERBOSE_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Failed during friend file copying!\n"));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ _("Failed during friend file copying!\n"));
#endif
- return GNUNET_SYSERR;
- }
- else
- {
+ return GNUNET_SYSERR;
+ }
+ else
+ {
#if VERBOSE_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Friend files created/copied successfully!\n"));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ _("Friend files created/copied successfully!\n"));
#endif
- }
}
+ }
/* Use the create clique method to initially set all connections as
blacklisted. */
if ((restrict_topology != GNUNET_TESTING_TOPOLOGY_NONE) && (restrict_topology
- != GNUNET_TESTING_TOPOLOGY_FROM_FILE))
+ !=
+
GNUNET_TESTING_TOPOLOGY_FROM_FILE))
create_clique (pg, &add_connections, BLACKLIST, GNUNET_NO);
else
return num_connections;
@@ -4069,11 +4089,11 @@
unblacklisted_connections = 0;
/* Un-blacklist connections as per the topology specified */
switch (restrict_topology)
- {
+ {
case GNUNET_TESTING_TOPOLOGY_CLIQUE:
#if VERBOSE_TESTING
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Blacklisting all but clique topology\n"));
+ _("Blacklisting all but clique topology\n"));
#endif
unblacklisted_connections = create_clique (pg, &remove_connections,
BLACKLIST, GNUNET_NO);
@@ -4081,7 +4101,7 @@
case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD_RING:
#if VERBOSE_TESTING
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Blacklisting all but small world (ring) topology\n"));
+ _("Blacklisting all but small world (ring) topology\n"));
#endif
unblacklisted_connections = create_small_world_ring (pg,
&remove_connections,
@@ -4090,8 +4110,7 @@
case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD:
#if VERBOSE_TESTING
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _
- ("Blacklisting all but small world (2d-torus) topology\n"));
+ _("Blacklisting all but small world (2d-torus) topology\n"));
#endif
unblacklisted_connections = create_small_world (pg, &remove_connections,
BLACKLIST);
@@ -4099,7 +4118,7 @@
case GNUNET_TESTING_TOPOLOGY_RING:
#if VERBOSE_TESTING
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Blacklisting all but ring topology\n"));
+ _("Blacklisting all but ring topology\n"));
#endif
unblacklisted_connections
= create_ring (pg, &remove_connections, BLACKLIST);
@@ -4107,7 +4126,7 @@
case GNUNET_TESTING_TOPOLOGY_2D_TORUS:
#if VERBOSE_TESTING
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Blacklisting all but 2d torus topology\n"));
+ _("Blacklisting all but 2d torus topology\n"));
#endif
unblacklisted_connections = create_2d_torus (pg, &remove_connections,
BLACKLIST);
@@ -4115,7 +4134,7 @@
case GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI:
#if VERBOSE_TESTING
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Blacklisting all but Erdos-Renyi topology\n"));
+ _("Blacklisting all but Erdos-Renyi topology\n"));
#endif
unblacklisted_connections = create_erdos_renyi (pg, &remove_connections,
BLACKLIST);
@@ -4123,44 +4142,44 @@
case GNUNET_TESTING_TOPOLOGY_INTERNAT:
#if VERBOSE_TESTING
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Blacklisting all but InterNAT topology\n"));
+ _("Blacklisting all but InterNAT topology\n"));
#endif
#if TOPOLOGY_HACK
for (off = 0; off < pg->total; off++)
+ {
+ conn_iter = pg->peers[off].allowed_peers_head;
+ while (conn_iter != NULL)
{
- conn_iter = pg->peers[off].allowed_peers_head;
- while (conn_iter != NULL)
- {
- temp_conn = conn_iter->next;
- GNUNET_free(conn_iter);
- conn_iter = temp_conn;
- }
- pg->peers[off].allowed_peers_head = NULL;
- pg->peers[off].allowed_peers_tail = NULL;
+ temp_conn = conn_iter->next;
+ GNUNET_free (conn_iter);
+ conn_iter = temp_conn;
+ }
+ pg->peers[off].allowed_peers_head = NULL;
+ pg->peers[off].allowed_peers_tail = NULL;
- conn_iter = pg->peers[off].connect_peers_head;
- while (conn_iter != NULL)
- {
- temp_conn = conn_iter->next;
- GNUNET_free(conn_iter);
- conn_iter = temp_conn;
- }
- pg->peers[off].connect_peers_head = NULL;
- pg->peers[off].connect_peers_tail = NULL;
+ conn_iter = pg->peers[off].connect_peers_head;
+ while (conn_iter != NULL)
+ {
+ temp_conn = conn_iter->next;
+ GNUNET_free (conn_iter);
+ conn_iter = temp_conn;
}
+ pg->peers[off].connect_peers_head = NULL;
+ pg->peers[off].connect_peers_tail = NULL;
+ }
unblacklisted_connections
= create_nated_internet_copy (pg, &remove_connections, BLACKLIST);
#else
unblacklisted_connections =
- create_nated_internet (pg, &remove_connections, BLACKLIST);
+ create_nated_internet (pg, &remove_connections, BLACKLIST);
#endif
break;
case GNUNET_TESTING_TOPOLOGY_SCALE_FREE:
#if VERBOSE_TESTING
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Blacklisting all but Scale Free topology\n"));
+ _("Blacklisting all but Scale Free topology\n"));
#endif
unblacklisted_connections = create_scale_free (pg, &remove_connections,
BLACKLIST);
@@ -4168,35 +4187,35 @@
case GNUNET_TESTING_TOPOLOGY_LINE:
#if VERBOSE_TESTING
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Blacklisting all but straight line topology\n"));
+ _("Blacklisting all but straight line topology\n"));
#endif
unblacklisted_connections
= create_line (pg, &remove_connections, BLACKLIST);
default:
break;
- }
+ }
if ((unblacklisted_connections > 0) && (restrict_transports != NULL))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Creating blacklist with `%s'\n",
+ restrict_transports);
+ ret = create_and_copy_blacklist_files (pg, restrict_transports);
+ if (ret != GNUNET_OK)
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Creating blacklist with `%s'\n",
- restrict_transports);
- ret = create_and_copy_blacklist_files (pg, restrict_transports);
- if (ret != GNUNET_OK)
- {
#if VERBOSE_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Failed during blacklist file copying!\n"));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ _("Failed during blacklist file copying!\n"));
#endif
- return 0;
- }
- else
- {
+ return 0;
+ }
+ else
+ {
#if VERBOSE_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Blacklist files created/copied successfully!\n"));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ _("Blacklist files created/copied successfully!\n"));
#endif
- }
}
+ }
return num_connections;
}
@@ -4212,38 +4231,38 @@
*/
static int
random_connect_iterator (void *cls, const GNUNET_HashCode * key, void *value)
+{
+ struct RandomContext *random_ctx = cls;
+ double random_number;
+ uint32_t second_pos;
+ GNUNET_HashCode first_hash;
+
+ random_number =
+ ((double)
+ GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
+ UINT64_MAX)) / ((double) UINT64_MAX);
+ if (random_number < random_ctx->percentage)
{
- struct RandomContext *random_ctx = cls;
- double random_number;
- uint32_t second_pos;
- GNUNET_HashCode first_hash;
- random_number =
- ((double)
- GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
- UINT64_MAX)) / ((double) UINT64_MAX);
- if (random_number < random_ctx->percentage)
- {
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_put (random_ctx->
- first->connect_peers_working_set,
- key, value,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
- }
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONTAINER_multihashmap_put (random_ctx->
+
first->connect_peers_working_set,
+ key, value,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+ }
- /* Now we have considered this particular connection, remove it from the
second peer so it's not double counted */
- uid_from_hash (key, &second_pos);
- hash_from_uid (random_ctx->first_uid, &first_hash);
- GNUNET_assert (random_ctx->pg->total > second_pos);
- GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove (random_ctx->
- pg->peers
- [second_pos].connect_peers,
- &first_hash,
- random_ctx->
- first->daemon));
+ /* Now we have considered this particular connection, remove it from the
second peer so it's not double counted */
+ uid_from_hash (key, &second_pos);
+ hash_from_uid (random_ctx->first_uid, &first_hash);
+ GNUNET_assert (random_ctx->pg->total > second_pos);
+ GNUNET_assert (GNUNET_YES ==
+ GNUNET_CONTAINER_multihashmap_remove (random_ctx->pg->peers
+
[second_pos].connect_peers,
+ &first_hash,
+ random_ctx->
+ first->daemon));
- return GNUNET_YES;
- }
+ return GNUNET_YES;
+}
/**
* Iterator for adding at least X peers to a peers connection set.
@@ -4256,50 +4275,49 @@
*/
static int
minimum_connect_iterator (void *cls, const GNUNET_HashCode * key, void *value)
+{
+ struct MinimumContext *min_ctx = cls;
+ uint32_t second_pos;
+ GNUNET_HashCode first_hash;
+ unsigned int i;
+
+ if (GNUNET_CONTAINER_multihashmap_size
+ (min_ctx->first->connect_peers_working_set) < min_ctx->num_to_add)
{
- struct MinimumContext *min_ctx = cls;
- uint32_t second_pos;
- GNUNET_HashCode first_hash;
- unsigned int i;
-
- if (GNUNET_CONTAINER_multihashmap_size
- (min_ctx->first->connect_peers_working_set) < min_ctx->num_to_add)
+ for (i = 0; i < min_ctx->num_to_add; i++)
+ {
+ if (min_ctx->pg_array[i] == min_ctx->current)
{
- for (i = 0; i < min_ctx->num_to_add; i++)
- {
- if (min_ctx->pg_array[i] == min_ctx->current)
- {
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_put
- (min_ctx->first->connect_peers_working_set, key,
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONTAINER_multihashmap_put
+ (min_ctx->first->connect_peers_working_set, key,
value,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
- uid_from_hash (key, &second_pos);
- hash_from_uid (min_ctx->first_uid, &first_hash);
- GNUNET_assert (min_ctx->pg->total > second_pos);
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_put (min_ctx->
- pg->peers
- [second_pos].connect_peers_working_set,
- &first_hash,
- min_ctx->first->
- daemon,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
- /* Now we have added this particular connection, remove it
from the second peer's map so it's not double counted */
- GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove
- (min_ctx->pg->peers[second_pos].connect_peers,
+ uid_from_hash (key, &second_pos);
+ hash_from_uid (min_ctx->first_uid, &first_hash);
+ GNUNET_assert (min_ctx->pg->total > second_pos);
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONTAINER_multihashmap_put (min_ctx->pg->peers
+
[second_pos].connect_peers_working_set,
+ &first_hash,
+ min_ctx->first->
+ daemon,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+ /* Now we have added this particular connection, remove it from the
second peer's map so it's not double counted */
+ GNUNET_assert (GNUNET_YES ==
+ GNUNET_CONTAINER_multihashmap_remove
+ (min_ctx->pg->peers[second_pos].connect_peers,
&first_hash, min_ctx->first->daemon));
- }
- }
- min_ctx->current++;
- return GNUNET_YES;
}
- else
- return GNUNET_NO; /* We can stop iterating, we have enough peers! */
-
+ }
+ min_ctx->current++;
+ return GNUNET_YES;
}
+ else
+ return GNUNET_NO; /* We can stop iterating, we have enough
peers! */
+}
+
/**
* Iterator for adding peers to a connection set based on a depth first search.
*
@@ -4311,41 +4329,40 @@
*/
static int
dfs_connect_iterator (void *cls, const GNUNET_HashCode * key, void *value)
+{
+ struct DFSContext *dfs_ctx = cls;
+ GNUNET_HashCode first_hash;
+
+ if (dfs_ctx->current == dfs_ctx->chosen)
{
- struct DFSContext *dfs_ctx = cls;
- GNUNET_HashCode first_hash;
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONTAINER_multihashmap_put (dfs_ctx->
+
first->connect_peers_working_set,
+ key, value,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+ uid_from_hash (key, &dfs_ctx->second_uid);
+ hash_from_uid (dfs_ctx->first_uid, &first_hash);
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONTAINER_multihashmap_put (dfs_ctx->pg->peers
+ [dfs_ctx->
+
second_uid].connect_peers_working_set,
+ &first_hash,
+ dfs_ctx->first->daemon,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+ GNUNET_assert (GNUNET_YES ==
+ GNUNET_CONTAINER_multihashmap_remove (dfs_ctx->
+ pg->peers
+
[dfs_ctx->second_uid].connect_peers,
+ &first_hash,
+ dfs_ctx->
+ first->daemon));
+ /* Can't remove second from first yet because we are currently iterating,
hence the return value in the DFSContext! */
+ return GNUNET_NO; /* We have found our peer, don't iterate more
*/
+ }
- if (dfs_ctx->current == dfs_ctx->chosen)
- {
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_put (dfs_ctx->
- first->connect_peers_working_set,
- key, value,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
- uid_from_hash (key, &dfs_ctx->second_uid);
- hash_from_uid (dfs_ctx->first_uid, &first_hash);
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_put (dfs_ctx->
- pg->peers
- [dfs_ctx->second_uid].connect_peers_working_set,
- &first_hash,
- dfs_ctx->
- first->daemon,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
- GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove (dfs_ctx->
- pg->peers
- [dfs_ctx->second_uid].connect_peers,
- &first_hash,
- dfs_ctx->
- first->daemon));
- /* Can't remove second from first yet because we are currently
iterating, hence the return value in the DFSContext! */
- return GNUNET_NO; /* We have found our peer, don't iterate more */
- }
-
- dfs_ctx->current++;
- return GNUNET_YES;
- }
+ dfs_ctx->current++;
+ return GNUNET_YES;
+}
#endif
/**
@@ -4356,10 +4373,11 @@
* @param percentage what percent of total connections to make
*/
void
-choose_random_connections(struct GNUNET_TESTING_PeerGroup *pg,
- double percentage)
+choose_random_connections (struct GNUNET_TESTING_PeerGroup *pg,
+ double percentage)
{
uint32_t pg_iter;
+
#if OLD
struct PeerConnection *conn_iter;
double random_number;
@@ -4368,56 +4386,55 @@
#endif
for (pg_iter = 0; pg_iter < pg->total; pg_iter++)
+ {
+#if OLD
+ conn_iter = pg->peers[pg_iter].connect_peers_head;
+ while (conn_iter != NULL)
{
-#if OLD
- conn_iter = pg->peers[pg_iter].connect_peers_head;
- while (conn_iter != NULL)
- {
- random_number
- = ((double) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
- UINT64_MAX))
- / ((double) UINT64_MAX);
- if (random_number < percentage)
- {
- add_connections (pg, pg_iter, conn_iter->index, WORKING_SET,
- GNUNET_YES);
- }
- conn_iter = conn_iter->next;
- }
+ random_number
+ = ((double) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
+ UINT64_MAX))
+ / ((double) UINT64_MAX);
+ if (random_number < percentage)
+ {
+ add_connections (pg, pg_iter, conn_iter->index, WORKING_SET,
+ GNUNET_YES);
+ }
+ conn_iter = conn_iter->next;
+ }
#else
- random_ctx.first_uid = pg_iter;
- random_ctx.first = &pg->peers[pg_iter];
- random_ctx.percentage = percentage;
- random_ctx.pg = pg;
- pg->peers[pg_iter].connect_peers_working_set
- = GNUNET_CONTAINER_multihashmap_create (pg->total);
- GNUNET_CONTAINER_multihashmap_iterate (pg->peers[pg_iter].connect_peers,
- &random_connect_iterator,
- &random_ctx);
- /* Now remove the old connections */
- GNUNET_CONTAINER_multihashmap_destroy (pg->
- peers[pg_iter].connect_peers);
- /* And replace with the random set */
- pg->peers[pg_iter].connect_peers
- = pg->peers[pg_iter].connect_peers_working_set;
+ random_ctx.first_uid = pg_iter;
+ random_ctx.first = &pg->peers[pg_iter];
+ random_ctx.percentage = percentage;
+ random_ctx.pg = pg;
+ pg->peers[pg_iter].connect_peers_working_set
+ = GNUNET_CONTAINER_multihashmap_create (pg->total);
+ GNUNET_CONTAINER_multihashmap_iterate (pg->peers[pg_iter].connect_peers,
+ &random_connect_iterator,
+ &random_ctx);
+ /* Now remove the old connections */
+ GNUNET_CONTAINER_multihashmap_destroy (pg->peers[pg_iter].connect_peers);
+ /* And replace with the random set */
+ pg->peers[pg_iter].connect_peers
+ = pg->peers[pg_iter].connect_peers_working_set;
#endif
- }
+ }
for (pg_iter = 0; pg_iter < pg->total; pg_iter++)
- {
- conn_iter = pg->peers[pg_iter].connect_peers_head;
- while (pg->peers[pg_iter].connect_peers_head != NULL)
- remove_connections (pg, pg_iter,
- pg->peers[pg_iter].connect_peers_head->index,
- CONNECT, GNUNET_YES);
+ {
+ conn_iter = pg->peers[pg_iter].connect_peers_head;
+ while (pg->peers[pg_iter].connect_peers_head != NULL)
+ remove_connections (pg, pg_iter,
+ pg->peers[pg_iter].connect_peers_head->index,
+ CONNECT, GNUNET_YES);
- pg->peers[pg_iter].connect_peers_head
- = pg->peers[pg_iter].connect_peers_working_set_head;
- pg->peers[pg_iter].connect_peers_tail
- = pg->peers[pg_iter].connect_peers_working_set_tail;
- pg->peers[pg_iter].connect_peers_working_set_head = NULL;
- pg->peers[pg_iter].connect_peers_working_set_tail = NULL;
- }
+ pg->peers[pg_iter].connect_peers_head
+ = pg->peers[pg_iter].connect_peers_working_set_head;
+ pg->peers[pg_iter].connect_peers_tail
+ = pg->peers[pg_iter].connect_peers_working_set_tail;
+ pg->peers[pg_iter].connect_peers_working_set_head = NULL;
+ pg->peers[pg_iter].connect_peers_working_set_tail = NULL;
+ }
}
/**
@@ -4428,76 +4445,76 @@
* @return the number of elements in the list
*/
static unsigned int
-count_connections(struct PeerConnection *conn_list)
+count_connections (struct PeerConnection *conn_list)
{
struct PeerConnection *iter;
unsigned int count;
+
count = 0;
iter = conn_list;
while (iter != NULL)
- {
- iter = iter->next;
- count++;
- }
+ {
+ iter = iter->next;
+ count++;
+ }
return count;
}
static unsigned int
-count_workingset_connections(struct GNUNET_TESTING_PeerGroup *pg)
+count_workingset_connections (struct GNUNET_TESTING_PeerGroup *pg)
{
unsigned int count;
unsigned int pg_iter;
+
#if OLD
struct PeerConnection *conn_iter;
#endif
count = 0;
for (pg_iter = 0; pg_iter < pg->total; pg_iter++)
+ {
+#if OLD
+ conn_iter = pg->peers[pg_iter].connect_peers_working_set_head;
+ while (conn_iter != NULL)
{
-#if OLD
- conn_iter = pg->peers[pg_iter].connect_peers_working_set_head;
- while (conn_iter != NULL)
- {
- count++;
- conn_iter = conn_iter->next;
- }
+ count++;
+ conn_iter = conn_iter->next;
+ }
#else
- count +=
- GNUNET_CONTAINER_multihashmap_size (pg->
- peers
- [pg_iter].connect_peers_working_set);
+ count +=
+ GNUNET_CONTAINER_multihashmap_size (pg->peers
+
[pg_iter].connect_peers_working_set);
#endif
- }
+ }
return count;
}
static unsigned int
-count_allowed_connections(struct GNUNET_TESTING_PeerGroup *pg)
+count_allowed_connections (struct GNUNET_TESTING_PeerGroup *pg)
{
unsigned int count;
unsigned int pg_iter;
+
#if OLD
struct PeerConnection *conn_iter;
#endif
count = 0;
for (pg_iter = 0; pg_iter < pg->total; pg_iter++)
+ {
+#if OLD
+ conn_iter = pg->peers[pg_iter].allowed_peers_head;
+ while (conn_iter != NULL)
{
-#if OLD
- conn_iter = pg->peers[pg_iter].allowed_peers_head;
- while (conn_iter != NULL)
- {
- count++;
- conn_iter = conn_iter->next;
- }
+ count++;
+ conn_iter = conn_iter->next;
+ }
#else
- count +=
- GNUNET_CONTAINER_multihashmap_size (pg->
- peers
- [pg_iter].allowed_peers);
+ count +=
+ GNUNET_CONTAINER_multihashmap_size (pg->peers[pg_iter].allowed_peers);
#endif
- }
+ }
return count;
}
@@ -4510,7 +4527,7 @@
* @param num how many connections at least should each peer have (if
possible)?
*/
static void
-choose_minimum(struct GNUNET_TESTING_PeerGroup *pg, unsigned int num)
+choose_minimum (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num)
{
#if !OLD
struct MinimumContext minimum_ctx;
@@ -4519,113 +4536,110 @@
unsigned int temp_list_size;
unsigned int i;
unsigned int count;
- uint32_t random; /* Random list entry to connect peer to */
+ uint32_t random; /* Random list entry to connect peer to */
#endif
uint32_t pg_iter;
#if OLD
for (pg_iter = 0; pg_iter < pg->total; pg_iter++)
+ {
+ temp_list_size = count_connections (pg->peers[pg_iter].connect_peers_head);
+ if (temp_list_size == 0)
{
- temp_list_size
- = count_connections (pg->peers[pg_iter].connect_peers_head);
- if (temp_list_size == 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Peer %d has 0 connections!?!?\n", pg_iter);
- break;
- }
- for (i = 0; i < num; i++)
- {
- random = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
- temp_list_size);
- conn_iter = pg->peers[pg_iter].connect_peers_head;
- for (count = 0; count < random; count++)
- conn_iter = conn_iter->next;
- /* We now have a random connection, connect it! */
- GNUNET_assert(conn_iter != NULL);
- add_connections (pg, pg_iter, conn_iter->index, WORKING_SET,
- GNUNET_YES);
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Peer %d has 0 connections!?!?\n", pg_iter);
+ break;
}
+ for (i = 0; i < num; i++)
+ {
+ random = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
+ temp_list_size);
+ conn_iter = pg->peers[pg_iter].connect_peers_head;
+ for (count = 0; count < random; count++)
+ conn_iter = conn_iter->next;
+ /* We now have a random connection, connect it! */
+ GNUNET_assert (conn_iter != NULL);
+ add_connections (pg, pg_iter, conn_iter->index, WORKING_SET, GNUNET_YES);
+ }
+ }
#else
for (pg_iter = 0; pg_iter < pg->total; pg_iter++)
- {
- pg->peers[pg_iter].connect_peers_working_set =
- GNUNET_CONTAINER_multihashmap_create (num);
- }
+ {
+ pg->peers[pg_iter].connect_peers_working_set =
+ GNUNET_CONTAINER_multihashmap_create (num);
+ }
for (pg_iter = 0; pg_iter < pg->total; pg_iter++)
- {
- minimum_ctx.first_uid = pg_iter;
- minimum_ctx.pg_array =
- GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK,
- GNUNET_CONTAINER_multihashmap_size
- (pg->peers[pg_iter].connect_peers));
- minimum_ctx.first = &pg->peers[pg_iter];
- minimum_ctx.pg = pg;
- minimum_ctx.num_to_add = num;
- minimum_ctx.current = 0;
- GNUNET_CONTAINER_multihashmap_iterate (pg->peers[pg_iter].connect_peers,
- &minimum_connect_iterator,
- &minimum_ctx);
- }
+ {
+ minimum_ctx.first_uid = pg_iter;
+ minimum_ctx.pg_array =
+ GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK,
+ GNUNET_CONTAINER_multihashmap_size
+ (pg->peers[pg_iter].connect_peers));
+ minimum_ctx.first = &pg->peers[pg_iter];
+ minimum_ctx.pg = pg;
+ minimum_ctx.num_to_add = num;
+ minimum_ctx.current = 0;
+ GNUNET_CONTAINER_multihashmap_iterate (pg->peers[pg_iter].connect_peers,
+ &minimum_connect_iterator,
+ &minimum_ctx);
+ }
for (pg_iter = 0; pg_iter < pg->total; pg_iter++)
- {
- /* Remove the "old" connections */
- GNUNET_CONTAINER_multihashmap_destroy (pg->
- peers[pg_iter].connect_peers);
- /* And replace with the working set */
- pg->peers[pg_iter].connect_peers =
- pg->peers[pg_iter].connect_peers_working_set;
- }
+ {
+ /* Remove the "old" connections */
+ GNUNET_CONTAINER_multihashmap_destroy (pg->peers[pg_iter].connect_peers);
+ /* And replace with the working set */
+ pg->peers[pg_iter].connect_peers =
+ pg->peers[pg_iter].connect_peers_working_set;
+ }
#endif
for (pg_iter = 0; pg_iter < pg->total; pg_iter++)
+ {
+ while (pg->peers[pg_iter].connect_peers_head != NULL)
{
- while (pg->peers[pg_iter].connect_peers_head != NULL)
- {
- conn_iter = pg->peers[pg_iter].connect_peers_head;
- GNUNET_CONTAINER_DLL_remove(pg->peers[pg_iter].connect_peers_head,
- pg->peers[pg_iter].connect_peers_tail,
- conn_iter);
- GNUNET_free(conn_iter);
- /*remove_connections(pg, pg_iter,
pg->peers[pg_iter].connect_peers_head->index, CONNECT, GNUNET_YES);*/
- }
+ conn_iter = pg->peers[pg_iter].connect_peers_head;
+ GNUNET_CONTAINER_DLL_remove (pg->peers[pg_iter].connect_peers_head,
+ pg->peers[pg_iter].connect_peers_tail,
+ conn_iter);
+ GNUNET_free (conn_iter);
+ /*remove_connections(pg, pg_iter,
pg->peers[pg_iter].connect_peers_head->index, CONNECT, GNUNET_YES); */
+ }
- pg->peers[pg_iter].connect_peers_head
- = pg->peers[pg_iter].connect_peers_working_set_head;
- pg->peers[pg_iter].connect_peers_tail
- = pg->peers[pg_iter].connect_peers_working_set_tail;
- pg->peers[pg_iter].connect_peers_working_set_head = NULL;
- pg->peers[pg_iter].connect_peers_working_set_tail = NULL;
- }
+ pg->peers[pg_iter].connect_peers_head
+ = pg->peers[pg_iter].connect_peers_working_set_head;
+ pg->peers[pg_iter].connect_peers_tail
+ = pg->peers[pg_iter].connect_peers_working_set_tail;
+ pg->peers[pg_iter].connect_peers_working_set_head = NULL;
+ pg->peers[pg_iter].connect_peers_working_set_tail = NULL;
+ }
}
#if !OLD
struct FindClosestContext
- {
+{
/**
* The currently known closest peer.
*/
- struct GNUNET_TESTING_Daemon *closest;
+ struct GNUNET_TESTING_Daemon *closest;
/**
* The info for the peer we are adding connections for.
*/
- struct PeerData *curr_peer;
+ struct PeerData *curr_peer;
/**
* The distance (bits) between the current
* peer and the currently known closest.
*/
- unsigned int closest_dist;
+ unsigned int closest_dist;
/**
* The offset of the closest known peer in
* the peer group.
*/
- unsigned int closest_num;
- };
+ unsigned int closest_num;
+};
/**
* Iterator over hash map entries of the allowed
@@ -4641,29 +4655,29 @@
*/
static int
find_closest_peers (void *cls, const GNUNET_HashCode * key, void *value)
+{
+ struct FindClosestContext *closest_ctx = cls;
+ struct GNUNET_TESTING_Daemon *daemon = value;
+
+ if (((closest_ctx->closest == NULL) ||
+ (GNUNET_CRYPTO_hash_matching_bits
+ (&daemon->id.hashPubKey,
+ &closest_ctx->curr_peer->daemon->id.hashPubKey) >
+ closest_ctx->closest_dist))
+ && (GNUNET_YES !=
+ GNUNET_CONTAINER_multihashmap_contains (closest_ctx->
+ curr_peer->connect_peers,
+ key)))
{
- struct FindClosestContext *closest_ctx = cls;
- struct GNUNET_TESTING_Daemon *daemon = value;
-
- if (((closest_ctx->closest == NULL) ||
- (GNUNET_CRYPTO_hash_matching_bits
- (&daemon->id.hashPubKey,
- &closest_ctx->curr_peer->daemon->id.hashPubKey) >
- closest_ctx->closest_dist))
- && (GNUNET_YES !=
- GNUNET_CONTAINER_multihashmap_contains (closest_ctx->
- curr_peer->connect_peers,
- key)))
- {
- closest_ctx->closest_dist =
+ closest_ctx->closest_dist =
GNUNET_CRYPTO_hash_matching_bits (&daemon->id.hashPubKey,
- &closest_ctx->curr_peer->daemon->
- id.hashPubKey);
- closest_ctx->closest = daemon;
- uid_from_hash (key, &closest_ctx->closest_num);
- }
- return GNUNET_YES;
+ &closest_ctx->curr_peer->daemon->
+ id.hashPubKey);
+ closest_ctx->closest = daemon;
+ uid_from_hash (key, &closest_ctx->closest_num);
}
+ return GNUNET_YES;
+}
/**
* From the set of connections possible, choose at num connections per
@@ -4678,36 +4692,34 @@
*/
void
add_closest (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num,
- GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list)
- {
+ GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list)
+{
#if OLD
#else
- struct FindClosestContext closest_ctx;
+ struct FindClosestContext closest_ctx;
#endif
- uint32_t pg_iter;
- uint32_t i;
+ uint32_t pg_iter;
+ uint32_t i;
- for (i = 0; i < num; i++) /* Each time find a closest peer (from those
available) */
+ for (i = 0; i < num; i++) /* Each time find a closest peer (from those
available) */
+ {
+ for (pg_iter = 0; pg_iter < pg->total; pg_iter++)
+ {
+ closest_ctx.curr_peer = &pg->peers[pg_iter];
+ closest_ctx.closest = NULL;
+ closest_ctx.closest_dist = 0;
+ closest_ctx.closest_num = 0;
+ GNUNET_CONTAINER_multihashmap_iterate (pg->peers[pg_iter].allowed_peers,
+ &find_closest_peers,
&closest_ctx);
+ if (closest_ctx.closest != NULL)
{
- for (pg_iter = 0; pg_iter < pg->total; pg_iter++)
- {
- closest_ctx.curr_peer = &pg->peers[pg_iter];
- closest_ctx.closest = NULL;
- closest_ctx.closest_dist = 0;
- closest_ctx.closest_num = 0;
- GNUNET_CONTAINER_multihashmap_iterate (pg->
- peers[pg_iter].allowed_peers,
- &find_closest_peers,
- &closest_ctx);
- if (closest_ctx.closest != NULL)
- {
- GNUNET_assert (closest_ctx.closest_num < pg->total);
- proc (pg, pg_iter, closest_ctx.closest_num, list);
- }
- }
+ GNUNET_assert (closest_ctx.closest_num < pg->total);
+ proc (pg, pg_iter, closest_ctx.closest_num, list);
}
+ }
}
+}
#endif
/**
@@ -4719,13 +4731,14 @@
* @param num how many connections at least should each peer have (if
possible)?
*/
void
-perform_dfs(struct GNUNET_TESTING_PeerGroup *pg, unsigned int num)
+perform_dfs (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num)
{
uint32_t pg_iter;
uint32_t dfs_count;
uint32_t starting_peer;
uint32_t least_connections;
uint32_t random_connection;
+
#if OLD
unsigned int temp_count;
struct PeerConnection *peer_iter;
@@ -4738,118 +4751,115 @@
starting_peer = 0;
dfs_count = 0;
while ((count_workingset_connections (pg) < num * pg->total)
- && (count_allowed_connections (pg) > 0))
+ && (count_allowed_connections (pg) > 0))
+ {
+ if (dfs_count % pg->total == 0) /* Restart the DFS at some weakly
connected peer */
{
- if (dfs_count % pg->total == 0) /* Restart the DFS at some weakly
connected peer */
+ least_connections = -1; /* Set to very high number */
+ for (pg_iter = 0; pg_iter < pg->total; pg_iter++)
+ {
+ temp_count
+ =
+ count_connections (pg->
+ peers[pg_iter].connect_peers_working_set_head);
+ if (temp_count < least_connections)
{
- least_connections = -1; /* Set to very high number */
- for (pg_iter = 0; pg_iter < pg->total; pg_iter++)
- {
- temp_count
- = count_connections (
-
pg->peers[pg_iter].connect_peers_working_set_head);
- if (temp_count < least_connections)
- {
- starting_peer = pg_iter;
- least_connections = temp_count;
- }
- }
+ starting_peer = pg_iter;
+ least_connections = temp_count;
}
+ }
+ }
- temp_count
- = count_connections (pg->peers[starting_peer].connect_peers_head);
- if (temp_count == 0)
- continue; /* FIXME: infinite loop? */
+ temp_count
+ = count_connections (pg->peers[starting_peer].connect_peers_head);
+ if (temp_count == 0)
+ continue; /* FIXME: infinite loop? */
- random_connection = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
- temp_count);
- temp_count = 0;
- peer_iter = pg->peers[starting_peer].connect_peers_head;
- while (temp_count < random_connection)
- {
- peer_iter = peer_iter->next;
- temp_count++;
- }
- GNUNET_assert(peer_iter != NULL);
- add_connections (pg, starting_peer, peer_iter->index, WORKING_SET,
- GNUNET_NO);
- remove_connections (pg, starting_peer, peer_iter->index, CONNECT,
- GNUNET_YES);
- starting_peer = peer_iter->index;
- dfs_count++;
+ random_connection = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
+ temp_count);
+ temp_count = 0;
+ peer_iter = pg->peers[starting_peer].connect_peers_head;
+ while (temp_count < random_connection)
+ {
+ peer_iter = peer_iter->next;
+ temp_count++;
}
+ GNUNET_assert (peer_iter != NULL);
+ add_connections (pg, starting_peer, peer_iter->index, WORKING_SET,
+ GNUNET_NO);
+ remove_connections (pg, starting_peer, peer_iter->index, CONNECT,
+ GNUNET_YES);
+ starting_peer = peer_iter->index;
+ dfs_count++;
+ }
#else
for (pg_iter = 0; pg_iter < pg->total; pg_iter++)
- {
- pg->peers[pg_iter].connect_peers_working_set =
- GNUNET_CONTAINER_multihashmap_create (num);
- }
+ {
+ pg->peers[pg_iter].connect_peers_working_set =
+ GNUNET_CONTAINER_multihashmap_create (num);
+ }
starting_peer = 0;
dfs_count = 0;
while ((count_workingset_connections (pg) < num * pg->total)
- && (count_allowed_connections (pg) > 0))
+ && (count_allowed_connections (pg) > 0))
+ {
+ if (dfs_count % pg->total == 0) /* Restart the DFS at some weakly
connected peer */
{
- if (dfs_count % pg->total == 0) /* Restart the DFS at some weakly
connected peer */
+ least_connections = -1; /* Set to very high number */
+ for (pg_iter = 0; pg_iter < pg->total; pg_iter++)
+ {
+ if (GNUNET_CONTAINER_multihashmap_size
+ (pg->peers[pg_iter].connect_peers_working_set) < least_connections)
{
- least_connections = -1; /* Set to very high number */
- for (pg_iter = 0; pg_iter < pg->total; pg_iter++)
- {
- if (GNUNET_CONTAINER_multihashmap_size
- (pg->peers[pg_iter].connect_peers_working_set) <
- least_connections)
- {
- starting_peer = pg_iter;
- least_connections =
- GNUNET_CONTAINER_multihashmap_size (pg->
- peers
- [pg_iter].connect_peers_working_set);
- }
- }
+ starting_peer = pg_iter;
+ least_connections =
+ GNUNET_CONTAINER_multihashmap_size (pg->peers
+
[pg_iter].connect_peers_working_set);
}
+ }
+ }
- if (GNUNET_CONTAINER_multihashmap_size
(pg->peers[starting_peer].connect_peers) == 0) /* Ensure there is at least one
peer left to connect! */
- {
- dfs_count = 0;
- continue;
- }
+ if (GNUNET_CONTAINER_multihashmap_size
(pg->peers[starting_peer].connect_peers) == 0) /* Ensure there is at
least one peer left to connect! */
+ {
+ dfs_count = 0;
+ continue;
+ }
- /* Choose a random peer from the chosen peers set of connections to add
*/
- dfs_ctx.chosen =
- GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
- GNUNET_CONTAINER_multihashmap_size
- (pg->peers[starting_peer].connect_peers));
- dfs_ctx.first_uid = starting_peer;
- dfs_ctx.first = &pg->peers[starting_peer];
- dfs_ctx.pg = pg;
- dfs_ctx.current = 0;
+ /* Choose a random peer from the chosen peers set of connections to add */
+ dfs_ctx.chosen =
+ GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
+ GNUNET_CONTAINER_multihashmap_size
+ (pg->peers[starting_peer].connect_peers));
+ dfs_ctx.first_uid = starting_peer;
+ dfs_ctx.first = &pg->peers[starting_peer];
+ dfs_ctx.pg = pg;
+ dfs_ctx.current = 0;
- GNUNET_CONTAINER_multihashmap_iterate (pg->
- peers
- [starting_peer].connect_peers,
- &dfs_connect_iterator, &dfs_ctx);
- /* Remove the second from the first, since we will be continuing the
search and may encounter the first peer again! */
- hash_from_uid (dfs_ctx.second_uid, &second_hash);
- GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove (pg->peers
- [starting_peer].connect_peers,
- &second_hash,
- pg->
- peers
- [dfs_ctx.second_uid].daemon));
- starting_peer = dfs_ctx.second_uid;
- }
+ GNUNET_CONTAINER_multihashmap_iterate (pg->peers
+ [starting_peer].connect_peers,
+ &dfs_connect_iterator, &dfs_ctx);
+ /* Remove the second from the first, since we will be continuing the
search and may encounter the first peer again! */
+ hash_from_uid (dfs_ctx.second_uid, &second_hash);
+ GNUNET_assert (GNUNET_YES ==
+ GNUNET_CONTAINER_multihashmap_remove (pg->peers
+
[starting_peer].connect_peers,
+ &second_hash,
+ pg->
+ peers
+
[dfs_ctx.second_uid].daemon));
+ starting_peer = dfs_ctx.second_uid;
+ }
for (pg_iter = 0; pg_iter < pg->total; pg_iter++)
- {
- /* Remove the "old" connections */
- GNUNET_CONTAINER_multihashmap_destroy (pg->
- peers[pg_iter].connect_peers);
- /* And replace with the working set */
- pg->peers[pg_iter].connect_peers =
- pg->peers[pg_iter].connect_peers_working_set;
- }
+ {
+ /* Remove the "old" connections */
+ GNUNET_CONTAINER_multihashmap_destroy (pg->peers[pg_iter].connect_peers);
+ /* And replace with the working set */
+ pg->peers[pg_iter].connect_peers =
+ pg->peers[pg_iter].connect_peers_working_set;
+ }
#endif
}
@@ -4857,30 +4867,30 @@
* Internal callback for topology information for a particular peer.
*/
static void
-internal_topology_callback(void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+internal_topology_callback (void *cls, const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_TRANSPORT_ATS_Information
*atsi)
{
struct CoreContext *core_ctx = cls;
struct TopologyIterateContext *iter_ctx = core_ctx->iter_context;
- if (peer == NULL) /* Either finished, or something went wrong */
- {
- iter_ctx->completed++;
- iter_ctx->connected--;
- /* One core context allocated per iteration, must free! */
- GNUNET_free (core_ctx);
- }
+ if (peer == NULL) /* Either finished, or something went wrong */
+ {
+ iter_ctx->completed++;
+ iter_ctx->connected--;
+ /* One core context allocated per iteration, must free! */
+ GNUNET_free (core_ctx);
+ }
else
- {
- iter_ctx->topology_cb (iter_ctx->cls, &core_ctx->daemon->id, peer, NULL);
- }
+ {
+ iter_ctx->topology_cb (iter_ctx->cls, &core_ctx->daemon->id, peer, NULL);
+ }
if (iter_ctx->completed == iter_ctx->total)
- {
- iter_ctx->topology_cb (iter_ctx->cls, NULL, NULL, NULL);
- /* Once all are done, free the iteration context */
- GNUNET_free (iter_ctx);
- }
+ {
+ iter_ctx->topology_cb (iter_ctx->cls, NULL, NULL, NULL);
+ /* Once all are done, free the iteration context */
+ GNUNET_free (iter_ctx);
+ }
}
/**
@@ -4888,45 +4898,43 @@
* schedule for some time in the future.
*/
static void
-schedule_get_topology(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+schedule_get_topology (void *cls, const struct GNUNET_SCHEDULER_TaskContext
*tc)
{
struct CoreContext *core_context = cls;
struct TopologyIterateContext *topology_context =
(struct TopologyIterateContext *) core_context->iter_context;
- if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
+ if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
return;
if (topology_context->connected
> topology_context->pg->max_outstanding_connections)
- {
+ {
#if VERBOSE_TESTING > 2
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _
- ("Delaying connect, we have too many outstanding connections!\n"));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ _
+ ("Delaying connect, we have too many outstanding
connections!\n"));
#endif
- GNUNET_SCHEDULER_add_delayed (
- GNUNET_TIME_relative_multiply (
-
GNUNET_TIME_UNIT_MILLISECONDS,
- 100),
- &schedule_get_topology, core_context);
- }
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MILLISECONDS, 100),
+ &schedule_get_topology, core_context);
+ }
else
- {
+ {
#if VERBOSE_TESTING > 2
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Creating connection, outstanding_connections is %d\n"),
- outstanding_connects);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ _("Creating connection, outstanding_connections is %d\n"),
+ outstanding_connects);
#endif
- topology_context->connected++;
+ topology_context->connected++;
- if (GNUNET_OK != GNUNET_CORE_iterate_peers (core_context->daemon->cfg,
- &internal_topology_callback,
- core_context))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Topology iteration
failed.\n");
- internal_topology_callback (core_context, NULL, NULL);
- }
+ if (GNUNET_OK != GNUNET_CORE_iterate_peers (core_context->daemon->cfg,
+ &internal_topology_callback,
+ core_context))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Topology iteration failed.\n");
+ internal_topology_callback (core_context, NULL, NULL);
}
+ }
}
/**
@@ -4934,8 +4942,8 @@
* all connections that each currently has.
*/
void
-GNUNET_TESTING_get_topology(struct GNUNET_TESTING_PeerGroup *pg,
- GNUNET_TESTING_NotifyTopology cb, void *cls)
+GNUNET_TESTING_get_topology (struct GNUNET_TESTING_PeerGroup *pg,
+ GNUNET_TESTING_NotifyTopology cb, void *cls)
{
struct TopologyIterateContext *topology_context;
struct CoreContext *core_ctx;
@@ -4949,23 +4957,23 @@
topology_context->pg = pg;
total_count = 0;
for (i = 0; i < pg->total; i++)
+ {
+ if (pg->peers[i].daemon->running == GNUNET_YES)
{
- if (pg->peers[i].daemon->running == GNUNET_YES)
- {
- /* Allocate one core context per core we need to connect to */
- core_ctx = GNUNET_malloc (sizeof (struct CoreContext));
- core_ctx->daemon = pg->peers[i].daemon;
- /* Set back pointer to topology iteration context */
- core_ctx->iter_context = topology_context;
- GNUNET_SCHEDULER_add_now (&schedule_get_topology, core_ctx);
- total_count++;
- }
+ /* Allocate one core context per core we need to connect to */
+ core_ctx = GNUNET_malloc (sizeof (struct CoreContext));
+ core_ctx->daemon = pg->peers[i].daemon;
+ /* Set back pointer to topology iteration context */
+ core_ctx->iter_context = topology_context;
+ GNUNET_SCHEDULER_add_now (&schedule_get_topology, core_ctx);
+ total_count++;
}
+ }
if (total_count == 0)
- {
- cb (cls, NULL, NULL, "Cannot iterate over topology, no running peers!");
- GNUNET_free (topology_context);
- }
+ {
+ cb (cls, NULL, NULL, "Cannot iterate over topology, no running peers!");
+ GNUNET_free (topology_context);
+ }
else
topology_context->total = total_count;
return;
@@ -4985,8 +4993,8 @@
* @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
*/
static int
-internal_stats_callback(void *cls, const char *subsystem, const char *name,
- uint64_t value, int is_persistent)
+internal_stats_callback (void *cls, const char *subsystem, const char *name,
+ uint64_t value, int is_persistent)
{
struct StatsCoreContext *core_context = cls;
struct StatsIterateContext *stats_context =
@@ -5004,7 +5012,7 @@
* was canceled or not (we don't care)
*/
static void
-internal_stats_cont(void *cls, int success)
+internal_stats_cont (void *cls, int success)
{
struct StatsCoreContext *core_context = cls;
struct StatsIterateContext *stats_context =
@@ -5014,10 +5022,10 @@
stats_context->completed++;
if (stats_context->completed == stats_context->total)
- {
- stats_context->cont (stats_context->cls, GNUNET_YES);
- GNUNET_free (stats_context);
- }
+ {
+ stats_context->cont (stats_context->cls, GNUNET_YES);
+ GNUNET_free (stats_context);
+ }
if (core_context->stats_handle != NULL)
GNUNET_STATISTICS_destroy (core_context->stats_handle, GNUNET_NO);
@@ -5030,55 +5038,53 @@
* schedule for some time in the future.
*/
static void
-schedule_get_statistics(void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+schedule_get_statistics (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct StatsCoreContext *core_context = cls;
struct StatsIterateContext *stats_context =
(struct StatsIterateContext *) core_context->iter_context;
- if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
+ if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
return;
if (stats_context->connected >
stats_context->pg->max_outstanding_connections)
- {
+ {
#if VERBOSE_TESTING > 2
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _
- ("Delaying connect, we have too many outstanding connections!\n"));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ _
+ ("Delaying connect, we have too many outstanding
connections!\n"));
#endif
- GNUNET_SCHEDULER_add_delayed (
- GNUNET_TIME_relative_multiply (
-
GNUNET_TIME_UNIT_MILLISECONDS,
- 100),
- &schedule_get_statistics, core_context);
- }
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MILLISECONDS, 100),
+ &schedule_get_statistics, core_context);
+ }
else
- {
+ {
#if VERBOSE_TESTING > 2
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Creating connection, outstanding_connections is %d\n"),
- outstanding_connects);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ _("Creating connection, outstanding_connections is %d\n"),
+ outstanding_connects);
#endif
- stats_context->connected++;
- core_context->stats_handle
- = GNUNET_STATISTICS_create ("testing", core_context->daemon->cfg);
- if (core_context->stats_handle == NULL)
- {
- internal_stats_cont (core_context, GNUNET_NO);
- return;
- }
+ stats_context->connected++;
+ core_context->stats_handle
+ = GNUNET_STATISTICS_create ("testing", core_context->daemon->cfg);
+ if (core_context->stats_handle == NULL)
+ {
+ internal_stats_cont (core_context, GNUNET_NO);
+ return;
+ }
- core_context->stats_get_handle
- = GNUNET_STATISTICS_get (core_context->stats_handle, NULL, NULL,
- GNUNET_TIME_relative_get_forever (),
- &internal_stats_cont,
- &internal_stats_callback, core_context);
- if (core_context->stats_get_handle == NULL)
- internal_stats_cont (core_context, GNUNET_NO);
+ core_context->stats_get_handle
+ = GNUNET_STATISTICS_get (core_context->stats_handle, NULL, NULL,
+ GNUNET_TIME_relative_get_forever (),
+ &internal_stats_cont,
+ &internal_stats_callback, core_context);
+ if (core_context->stats_get_handle == NULL)
+ internal_stats_cont (core_context, GNUNET_NO);
- }
+ }
}
struct DuplicateStats
@@ -5106,18 +5112,19 @@
* GNUNET_NO if not (and we may have added it to the list)
*/
static int
-stats_check_existing(struct GNUNET_TESTING_PeerGroup *pg,
- struct PeerData *specific_peer,
- struct DuplicateStats **stats_list)
+stats_check_existing (struct GNUNET_TESTING_PeerGroup *pg,
+ struct PeerData *specific_peer,
+ struct DuplicateStats **stats_list)
{
struct DuplicateStats *pos;
char *unix_domain_socket;
unsigned long long port;
char *to_match;
+
if (GNUNET_YES
!= GNUNET_CONFIGURATION_get_value_yesno (pg->cfg, "testing",
"single_statistics_per_host"))
- return GNUNET_NO; /* Each peer has its own statistics instance, do
nothing! */
+ return GNUNET_NO; /* Each peer has its own statistics instance,
do nothing! */
pos = *stats_list;
if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (specific_peer->cfg,
@@ -5129,10 +5136,10 @@
if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (specific_peer->cfg,
"statistics", "port",
&port))
- {
- GNUNET_free(unix_domain_socket);
- return GNUNET_NO;
- }
+ {
+ GNUNET_free (unix_domain_socket);
+ return GNUNET_NO;
+ }
if (specific_peer->daemon->hostname != NULL)
GNUNET_asprintf (&to_match, "%s%s%llu", specific_peer->daemon->hostname,
@@ -5141,15 +5148,15 @@
GNUNET_asprintf (&to_match, "%s%llu", unix_domain_socket, port);
while (pos != NULL)
+ {
+ if (0 == strcmp (to_match, pos->unique_string))
{
- if (0 == strcmp (to_match, pos->unique_string))
- {
- GNUNET_free (unix_domain_socket);
- GNUNET_free (to_match);
- return GNUNET_YES;
- }
- pos = pos->next;
+ GNUNET_free (unix_domain_socket);
+ GNUNET_free (to_match);
+ return GNUNET_YES;
}
+ pos = pos->next;
+ }
pos = GNUNET_malloc (sizeof (struct DuplicateStats));
pos->unique_string = to_match;
pos->next = *stats_list;
@@ -5169,10 +5176,10 @@
*
*/
void
-GNUNET_TESTING_get_statistics(struct GNUNET_TESTING_PeerGroup *pg,
- GNUNET_STATISTICS_Callback cont,
- GNUNET_TESTING_STATISTICS_Iterator proc,
- void *cls)
+GNUNET_TESTING_get_statistics (struct GNUNET_TESTING_PeerGroup *pg,
+ GNUNET_STATISTICS_Callback cont,
+ GNUNET_TESTING_STATISTICS_Iterator proc,
+ void *cls)
{
struct StatsIterateContext *stats_context;
struct StatsCoreContext *core_ctx;
@@ -5180,6 +5187,7 @@
unsigned int total_count;
struct DuplicateStats *stats_list;
struct DuplicateStats *pos;
+
stats_list = NULL;
/* Allocate a single stats iteration context */
@@ -5191,34 +5199,37 @@
total_count = 0;
for (i = 0; i < pg->total; i++)
+ {
+ if ((pg->peers[i].daemon->running == GNUNET_YES) && (GNUNET_NO
+ ==
+ stats_check_existing
+ (pg, &pg->peers[i],
+ &stats_list)))
{
- if ((pg->peers[i].daemon->running == GNUNET_YES) && (GNUNET_NO
- == stats_check_existing (pg, &pg->peers[i], &stats_list)))
- {
- /* Allocate one core context per core we need to connect to */
- core_ctx = GNUNET_malloc (sizeof (struct StatsCoreContext));
- core_ctx->daemon = pg->peers[i].daemon;
- /* Set back pointer to topology iteration context */
- core_ctx->iter_context = stats_context;
- GNUNET_SCHEDULER_add_now (&schedule_get_statistics, core_ctx);
- total_count++;
- }
+ /* Allocate one core context per core we need to connect to */
+ core_ctx = GNUNET_malloc (sizeof (struct StatsCoreContext));
+ core_ctx->daemon = pg->peers[i].daemon;
+ /* Set back pointer to topology iteration context */
+ core_ctx->iter_context = stats_context;
+ GNUNET_SCHEDULER_add_now (&schedule_get_statistics, core_ctx);
+ total_count++;
}
+ }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Retrieving stats from %u total instances.\n", total_count);
stats_context->total = total_count;
if (stats_list != NULL)
+ {
+ pos = stats_list;
+ while (pos != NULL)
{
- pos = stats_list;
- while (pos != NULL)
- {
- GNUNET_free (pos->unique_string);
- stats_list = pos->next;
- GNUNET_free (pos);
- pos = stats_list->next;
- }
+ GNUNET_free (pos->unique_string);
+ stats_list = pos->next;
+ GNUNET_free (pos);
+ pos = stats_list->next;
}
+ }
return;
}
@@ -5228,7 +5239,7 @@
* @param pg the peer group to stop connecting
*/
void
-GNUNET_TESTING_stop_connections(struct GNUNET_TESTING_PeerGroup *pg)
+GNUNET_TESTING_stop_connections (struct GNUNET_TESTING_PeerGroup *pg)
{
pg->stop_connects = GNUNET_YES;
}
@@ -5239,7 +5250,7 @@
* @param pg the peer group to resume connecting
*/
void
-GNUNET_TESTING_resume_connections(struct GNUNET_TESTING_PeerGroup *pg)
+GNUNET_TESTING_resume_connections (struct GNUNET_TESTING_PeerGroup *pg)
{
pg->stop_connects = GNUNET_NO;
}
@@ -5267,18 +5278,17 @@
* @return the number of connections that will be attempted, GNUNET_SYSERR on
error
*/
int
-GNUNET_TESTING_connect_topology(
- struct GNUNET_TESTING_PeerGroup *pg,
- enum GNUNET_TESTING_Topology topology,
- enum GNUNET_TESTING_TopologyOption options,
- double option_modifier,
- struct GNUNET_TIME_Relative connect_timeout,
- unsigned int connect_attempts,
- GNUNET_TESTING_NotifyCompletion
notify_callback,
- void *notify_cls)
+GNUNET_TESTING_connect_topology (struct GNUNET_TESTING_PeerGroup *pg,
+ enum GNUNET_TESTING_Topology topology,
+ enum GNUNET_TESTING_TopologyOption options,
+ double option_modifier,
+ struct GNUNET_TIME_Relative connect_timeout,
+ unsigned int connect_attempts,
+ GNUNET_TESTING_NotifyCompletion
+ notify_callback, void *notify_cls)
{
switch (topology)
- {
+ {
case GNUNET_TESTING_TOPOLOGY_CLIQUE:
#if VERBOSE_TOPOLOGY
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -5349,17 +5359,17 @@
break;
default:
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _
- ("Unknown topology specification, can't connect peers!\n"));
+ ("Unknown topology specification, can't connect peers!\n"));
return GNUNET_SYSERR;
- }
+ }
switch (options)
- {
+ {
case GNUNET_TESTING_TOPOLOGY_OPTION_RANDOM:
#if VERBOSE_TOPOLOGY
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _
- ("Connecting random subset (%'.2f percent) of possible peers\n"), 100
- * option_modifier);
+ ("Connecting random subset (%'.2f percent) of possible
peers\n"),
+ 100 * option_modifier);
#endif
choose_random_connections (pg, option_modifier);
break;
@@ -5374,7 +5384,7 @@
case GNUNET_TESTING_TOPOLOGY_OPTION_DFS:
#if VERBOSE_TOPOLOGY
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _
- ("Using DFS to connect a minimum of %u peers each (if possible)\n"),
+ ("Using DFS to connect a minimum of %u peers each (if
possible)\n"),
(unsigned int) option_modifier);
#endif
#if FIXME
@@ -5384,12 +5394,11 @@
case GNUNET_TESTING_TOPOLOGY_OPTION_ADD_CLOSEST:
#if VERBOSE_TOPOLOGY
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _
- ("Finding additional %u closest peers each (if possible)\n"),
+ ("Finding additional %u closest peers each (if possible)\n"),
(unsigned int) option_modifier);
#endif
#if FIXME
- add_closest (pg, (unsigned int) option_modifier,
- &add_connections, CONNECT);
+ add_closest (pg, (unsigned int) option_modifier, &add_connections,
CONNECT);
#endif
break;
case GNUNET_TESTING_TOPOLOGY_OPTION_NONE:
@@ -5398,7 +5407,7 @@
break;
default:
break;
- }
+ }
return connect_topology (pg, connect_timeout, connect_attempts,
notify_callback, notify_cls);
@@ -5413,14 +5422,15 @@
* @return the number of current ssh connections to the host
*/
static unsigned int
-count_outstanding_at_host(const char *hostname,
- struct GNUNET_TESTING_PeerGroup *pg)
+count_outstanding_at_host (const char *hostname,
+ struct GNUNET_TESTING_PeerGroup *pg)
{
struct OutstandingSSH *pos;
+
pos = pg->ssh_head;
while ((pos != NULL) && (strcmp (pos->hostname, hostname) != 0))
pos = pos->next;
- GNUNET_assert(pos != NULL);
+ GNUNET_assert (pos != NULL);
return pos->outstanding;
}
@@ -5432,14 +5442,15 @@
*
*/
static void
-increment_outstanding_at_host(const char *hostname,
- struct GNUNET_TESTING_PeerGroup *pg)
+increment_outstanding_at_host (const char *hostname,
+ struct GNUNET_TESTING_PeerGroup *pg)
{
struct OutstandingSSH *pos;
+
pos = pg->ssh_head;
while ((pos != NULL) && (strcmp (pos->hostname, hostname) != 0))
pos = pos->next;
- GNUNET_assert(pos != NULL);
+ GNUNET_assert (pos != NULL);
pos->outstanding++;
}
@@ -5451,14 +5462,15 @@
*
*/
static void
-decrement_outstanding_at_host(const char *hostname,
- struct GNUNET_TESTING_PeerGroup *pg)
+decrement_outstanding_at_host (const char *hostname,
+ struct GNUNET_TESTING_PeerGroup *pg)
{
struct OutstandingSSH *pos;
+
pos = pg->ssh_head;
while ((pos != NULL) && (strcmp (pos->hostname, hostname) != 0))
pos = pos->next;
- GNUNET_assert(pos != NULL);
+ GNUNET_assert (pos != NULL);
pos->outstanding--;
}
@@ -5473,10 +5485,11 @@
* @param emsg error message (NULL on success)
*/
static void
-internal_hostkey_callback(void *cls, const struct GNUNET_PeerIdentity *id,
- struct GNUNET_TESTING_Daemon *d, const char *emsg)
+internal_hostkey_callback (void *cls, const struct GNUNET_PeerIdentity *id,
+ struct GNUNET_TESTING_Daemon *d, const char *emsg)
{
struct InternalStartContext *internal_context = cls;
+
internal_context->peer->pg->starting--;
internal_context->peer->pg->started++;
if (internal_context->hostname != NULL)
@@ -5486,11 +5499,11 @@
internal_context->hostkey_callback (internal_context->hostkey_cls, id, d,
emsg);
else if (internal_context->peer->pg->started
- == internal_context->peer->pg->total)
- {
- internal_context->peer->pg->started = 0; /* Internal startup may use
this counter! */
- GNUNET_TESTING_daemons_continue_startup (internal_context->peer->pg);
- }
+ == internal_context->peer->pg->total)
+ {
+ internal_context->peer->pg->started = 0; /* Internal startup may use
this counter! */
+ GNUNET_TESTING_daemons_continue_startup (internal_context->peer->pg);
+ }
}
/**
@@ -5505,11 +5518,12 @@
* @param emsg error message (NULL on success)
*/
static void
-internal_startup_callback(void *cls, const struct GNUNET_PeerIdentity *id,
- const struct GNUNET_CONFIGURATION_Handle *cfg,
- struct GNUNET_TESTING_Daemon *d, const char *emsg)
+internal_startup_callback (void *cls, const struct GNUNET_PeerIdentity *id,
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ struct GNUNET_TESTING_Daemon *d, const char *emsg)
{
struct InternalStartContext *internal_context = cls;
+
internal_context->peer->pg->starting--;
if (internal_context->hostname != NULL)
decrement_outstanding_at_host (internal_context->hostname,
@@ -5520,38 +5534,35 @@
}
static void
-internal_continue_startup(void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+internal_continue_startup (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct InternalStartContext *internal_context = cls;
- if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- {
- return;
- }
+ if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
+ {
+ return;
+ }
if ((internal_context->peer->pg->starting
- < internal_context->peer->pg->max_concurrent_ssh)
+ < internal_context->peer->pg->max_concurrent_ssh)
|| ((internal_context->hostname != NULL)
&& (count_outstanding_at_host (internal_context->hostname,
internal_context->peer->pg)
< internal_context->peer->pg->max_concurrent_ssh)))
- {
- if (internal_context->hostname != NULL)
- increment_outstanding_at_host (internal_context->hostname,
- internal_context->peer->pg);
- internal_context->peer->pg->starting++;
- GNUNET_TESTING_daemon_continue_startup (internal_context->peer->daemon);
- }
+ {
+ if (internal_context->hostname != NULL)
+ increment_outstanding_at_host (internal_context->hostname,
+ internal_context->peer->pg);
+ internal_context->peer->pg->starting++;
+ GNUNET_TESTING_daemon_continue_startup (internal_context->peer->daemon);
+ }
else
- {
- GNUNET_SCHEDULER_add_delayed (
- GNUNET_TIME_relative_multiply (
-
GNUNET_TIME_UNIT_MILLISECONDS,
- 100),
- &internal_continue_startup,
- internal_context);
- }
+ {
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MILLISECONDS, 100),
+ &internal_continue_startup,
internal_context);
+ }
}
/**
@@ -5566,9 +5577,9 @@
*
*/
void
-churn_start_callback(void *cls, const struct GNUNET_PeerIdentity *id,
- const struct GNUNET_CONFIGURATION_Handle *cfg,
- struct GNUNET_TESTING_Daemon *d, const char *emsg)
+churn_start_callback (void *cls, const struct GNUNET_PeerIdentity *id,
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ struct GNUNET_TESTING_Daemon *d, const char *emsg)
{
struct ChurnRestartContext *startup_ctx = cls;
struct ChurnContext *churn_ctx = startup_ctx->churn_ctx;
@@ -5578,59 +5589,58 @@
error_message = NULL;
if (emsg != NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Churn stop callback failed with error `%s'\n", emsg);
- churn_ctx->num_failed_start++;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Churn stop callback failed with error `%s'\n", emsg);
+ churn_ctx->num_failed_start++;
+ }
else
- {
- churn_ctx->num_to_start--;
- }
+ {
+ churn_ctx->num_to_start--;
+ }
total_left = (churn_ctx->num_to_stop - churn_ctx->num_failed_stop)
+ (churn_ctx->num_to_start - churn_ctx->num_failed_start);
if (total_left == 0)
- {
- if ((churn_ctx->num_failed_stop > 0) || (churn_ctx->num_failed_start >
0))
- GNUNET_asprintf (
- &error_message,
- "Churn didn't complete successfully, %u peers failed
to start %u peers failed to be stopped!",
- churn_ctx->num_failed_start,
- churn_ctx->num_failed_stop);
- churn_ctx->cb (churn_ctx->cb_cls, error_message);
- GNUNET_free_non_null (error_message);
- GNUNET_free (churn_ctx);
- GNUNET_free (startup_ctx);
- }
+ {
+ if ((churn_ctx->num_failed_stop > 0) || (churn_ctx->num_failed_start > 0))
+ GNUNET_asprintf (&error_message,
+ "Churn didn't complete successfully, %u peers failed to
start %u peers failed to be stopped!",
+ churn_ctx->num_failed_start,
churn_ctx->num_failed_stop);
+ churn_ctx->cb (churn_ctx->cb_cls, error_message);
+ GNUNET_free_non_null (error_message);
+ GNUNET_free (churn_ctx);
+ GNUNET_free (startup_ctx);
+ }
}
static void
-schedule_churn_restart(void *cls, const struct GNUNET_SCHEDULER_TaskContext
*tc)
+schedule_churn_restart (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct PeerRestartContext *peer_restart_ctx = cls;
struct ChurnRestartContext *startup_ctx =
peer_restart_ctx->churn_restart_ctx;
if (startup_ctx->outstanding > startup_ctx->pg->max_concurrent_ssh)
- GNUNET_SCHEDULER_add_delayed (
- GNUNET_TIME_relative_multiply (
-
GNUNET_TIME_UNIT_MILLISECONDS,
- 100),
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MILLISECONDS, 100),
&schedule_churn_restart, peer_restart_ctx);
else
- {
- if (startup_ctx->churn_ctx->service != NULL)
- GNUNET_TESTING_daemon_start_stopped_service (peer_restart_ctx->daemon,
-
startup_ctx->churn_ctx->service,
- startup_ctx->timeout,
- &churn_start_callback,
startup_ctx);
- else
- GNUNET_TESTING_daemon_start_stopped (peer_restart_ctx->daemon,
- startup_ctx->timeout,
- &churn_start_callback,
startup_ctx);
- GNUNET_free (peer_restart_ctx);
- }
+ {
+ if (startup_ctx->churn_ctx->service != NULL)
+ GNUNET_TESTING_daemon_start_stopped_service (peer_restart_ctx->daemon,
+ startup_ctx->
+ churn_ctx->service,
+ startup_ctx->timeout,
+ &churn_start_callback,
+ startup_ctx);
+ else
+ GNUNET_TESTING_daemon_start_stopped (peer_restart_ctx->daemon,
+ startup_ctx->timeout,
+ &churn_start_callback, startup_ctx);
+ GNUNET_free (peer_restart_ctx);
+ }
}
/**
@@ -5645,98 +5655,95 @@
*
*/
void
-service_start_callback(void *cls,
- const struct GNUNET_PeerIdentity *id,
- const struct GNUNET_CONFIGURATION_Handle *cfg,
- struct GNUNET_TESTING_Daemon *d,
- const char *emsg)
+service_start_callback (void *cls,
+ const struct GNUNET_PeerIdentity *id,
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ struct GNUNET_TESTING_Daemon *d, const char *emsg)
{
- struct ServiceStartContext *startup_ctx = (struct ServiceStartContext *)cls;
+ struct ServiceStartContext *startup_ctx = (struct ServiceStartContext *) cls;
if (emsg != NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Service start failed with error `%s'\n", emsg);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Service start failed with error `%s'\n", emsg);
+ }
startup_ctx->outstanding--;
startup_ctx->remaining--;
if (startup_ctx->remaining == 0)
- {
- startup_ctx->cb (startup_ctx->cb_cls, NULL);
- GNUNET_free (startup_ctx->service);
- GNUNET_free (startup_ctx);
- }
+ {
+ startup_ctx->cb (startup_ctx->cb_cls, NULL);
+ GNUNET_free (startup_ctx->service);
+ GNUNET_free (startup_ctx);
+ }
}
static void
-schedule_service_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext
*tc)
+schedule_service_start (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct PeerServiceStartContext *peer_ctx = cls;
struct ServiceStartContext *startup_ctx = peer_ctx->start_ctx;
if (startup_ctx->outstanding > startup_ctx->pg->max_concurrent_ssh)
- GNUNET_SCHEDULER_add_delayed (
- GNUNET_TIME_relative_multiply (
-
GNUNET_TIME_UNIT_MILLISECONDS,
- 100),
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MILLISECONDS, 100),
&schedule_service_start, peer_ctx);
else
- {
+ {
- GNUNET_TESTING_daemon_start_service (peer_ctx->daemon,
- startup_ctx->service,
- startup_ctx->timeout,
- &service_start_callback,
startup_ctx);
- GNUNET_free (peer_ctx);
- }
+ GNUNET_TESTING_daemon_start_service (peer_ctx->daemon,
+ startup_ctx->service,
+ startup_ctx->timeout,
+ &service_start_callback, startup_ctx);
+ GNUNET_free (peer_ctx);
+ }
}
static void
-internal_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+internal_start (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct InternalStartContext *internal_context = cls;
- if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- {
- return;
- }
+ if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
+ {
+ return;
+ }
if ((internal_context->peer->pg->starting
- < internal_context->peer->pg->max_concurrent_ssh)
+ < internal_context->peer->pg->max_concurrent_ssh)
|| ((internal_context->hostname != NULL)
&& (count_outstanding_at_host (internal_context->hostname,
internal_context->peer->pg)
< internal_context->peer->pg->max_concurrent_ssh)))
- {
- if (internal_context->hostname != NULL)
- increment_outstanding_at_host (internal_context->hostname,
- internal_context->peer->pg);
- internal_context->peer->pg->starting++;
- internal_context->peer->daemon
- = GNUNET_TESTING_daemon_start (internal_context->peer->cfg,
- internal_context->timeout,
- GNUNET_NO,
- internal_context->hostname,
- internal_context->username,
- internal_context->sshport,
- internal_context->hostkey,
- &internal_hostkey_callback,
- internal_context,
- &internal_startup_callback,
- internal_context);
- }
+ {
+ if (internal_context->hostname != NULL)
+ increment_outstanding_at_host (internal_context->hostname,
+ internal_context->peer->pg);
+ internal_context->peer->pg->starting++;
+ internal_context->peer->daemon
+ = GNUNET_TESTING_daemon_start (internal_context->peer->cfg,
+ internal_context->timeout,
+ GNUNET_NO,
+ internal_context->hostname,
+ internal_context->username,
+ internal_context->sshport,
+ internal_context->hostkey,
+ &internal_hostkey_callback,
+ internal_context,
+ &internal_startup_callback,
+ internal_context);
+ }
else
- {
- GNUNET_SCHEDULER_add_delayed (
- GNUNET_TIME_relative_multiply (
-
GNUNET_TIME_UNIT_MILLISECONDS,
- 100),
- &internal_start, internal_context);
- }
+ {
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MILLISECONDS, 100),
+ &internal_start, internal_context);
+ }
}
+
#if USE_START_HELPER
struct PeerStartHelperContext
@@ -5757,40 +5764,41 @@
unsigned int i;
GNUNET_TESTING_NotifyDaemonRunning cb;
- if (GNUNET_NO == GNUNET_OS_process_status (helper->proc, &type, &code)) /*
Still running, wait some more! */
+ if (GNUNET_NO == GNUNET_OS_process_status (helper->proc, &type, &code))
/* Still running, wait some more! */
{
- GNUNET_SCHEDULER_add_delayed(GNUNET_CONSTANTS_EXEC_WAIT,
&check_peers_started, helper);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT,
+ &check_peers_started, helper);
return;
}
helper->pg->starting--;
- if (helper->pg->starting == 0) /* All peers have finished starting! */
+ if (helper->pg->starting == 0) /* All peers have finished starting! */
+ {
+ /* Call the peer started callback for each peer, set proper FSM state (?)
*/
+ for (i = 0; i < helper->pg->total; i++)
{
- /* Call the peer started callback for each peer, set proper FSM state
(?) */
- for (i = 0; i < helper->pg->total; i++)
- {
- cb = helper->pg->peers[i].daemon->cb;
- helper->pg->peers[i].daemon->cb = NULL;
- helper->pg->peers[i].daemon->running = GNUNET_YES;
- helper->pg->peers[i].daemon->phase = SP_START_DONE;
- if (NULL != cb)
- {
- if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0))
- cb (helper->pg->peers[i].daemon->cb_cls,
- &helper->pg->peers[i].daemon->id,
- helper->pg->peers[i].daemon->cfg,
helper->pg->peers[i].daemon,
- "Failed to execute peerStartHelper.pl, or return code bad!");
- else
- cb (helper->pg->peers[i].daemon->cb_cls,
- &helper->pg->peers[i].daemon->id,
- helper->pg->peers[i].daemon->cfg,
helper->pg->peers[i].daemon,
- NULL);
+ cb = helper->pg->peers[i].daemon->cb;
+ helper->pg->peers[i].daemon->cb = NULL;
+ helper->pg->peers[i].daemon->running = GNUNET_YES;
+ helper->pg->peers[i].daemon->phase = SP_START_DONE;
+ if (NULL != cb)
+ {
+ if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0))
+ cb (helper->pg->peers[i].daemon->cb_cls,
+ &helper->pg->peers[i].daemon->id,
+ helper->pg->peers[i].daemon->cfg, helper->pg->peers[i].daemon,
+ "Failed to execute peerStartHelper.pl, or return code bad!");
+ else
+ cb (helper->pg->peers[i].daemon->cb_cls,
+ &helper->pg->peers[i].daemon->id,
+ helper->pg->peers[i].daemon->cfg, helper->pg->peers[i].daemon,
+ NULL);
- }
+ }
- }
}
- GNUNET_OS_process_close(helper->proc);
+ }
+ GNUNET_OS_process_close (helper->proc);
}
static void
@@ -5800,20 +5808,26 @@
char *baseservicehome;
char *tempdir;
char *arg;
+
/* ssh address@hidden peerStartHelper /path/to/basedirectory */
- GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_get_value_string
(helper->pg->cfg, "PATHS", "SERVICEHOME",
-
&baseservicehome));
- GNUNET_asprintf(&tempdir, "%s/%s/", baseservicehome, helper->host->hostname);
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_string (helper->pg->cfg,
+ "PATHS", "SERVICEHOME",
+ &baseservicehome));
+ GNUNET_asprintf (&tempdir, "%s/%s/", baseservicehome,
helper->host->hostname);
if (NULL != helper->host->username)
- GNUNET_asprintf (&arg, "address@hidden", helper->host->username,
helper->host->hostname);
+ GNUNET_asprintf (&arg, "address@hidden", helper->host->username,
+ helper->host->hostname);
else
GNUNET_asprintf (&arg, "%s", helper->host->hostname);
/* FIXME: Doesn't support ssh_port option! */
helper->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", arg,
- "peerStartHelper.pl", tempdir, NULL);
- GNUNET_assert(helper->proc != NULL);
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "starting peers with cmd ssh %s %s
%s\n", arg, "peerStartHelper.pl", tempdir);
+ "peerStartHelper.pl", tempdir, NULL);
+ GNUNET_assert (helper->proc != NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "starting peers with cmd ssh %s %s %s\n", arg,
+ "peerStartHelper.pl", tempdir);
GNUNET_SCHEDULER_add_now (&check_peers_started, helper);
GNUNET_free (tempdir);
GNUNET_free (baseservicehome);
@@ -5829,56 +5843,61 @@
*
*/
void
-GNUNET_TESTING_daemons_continue_startup(struct GNUNET_TESTING_PeerGroup *pg)
+GNUNET_TESTING_daemons_continue_startup (struct GNUNET_TESTING_PeerGroup *pg)
{
unsigned int i;
#if USE_START_HELPER
if ((pg->num_hosts > 0) && (pg->hostkey_data != NULL))
+ {
+ struct PeerStartHelperContext *helper;
+
+ pg->starting = pg->num_hosts;
+ for (i = 0; i < pg->num_hosts; i++)
{
- struct PeerStartHelperContext *helper;
- pg->starting = pg->num_hosts;
- for (i = 0; i < pg->num_hosts; i++)
- {
- helper = GNUNET_malloc(sizeof(struct PeerStartHelperContext));
- helper->pg = pg;
- helper->host = &pg->hosts[i];
- GNUNET_SCHEDULER_add_now(&start_peer_helper, helper);
- }
+ helper = GNUNET_malloc (sizeof (struct PeerStartHelperContext));
+ helper->pg = pg;
+ helper->host = &pg->hosts[i];
+ GNUNET_SCHEDULER_add_now (&start_peer_helper, helper);
}
+ }
else
+ {
+ pg->starting = 0;
+ for (i = 0; i < pg->total; i++)
{
- pg->starting = 0;
- for (i = 0; i < pg->total; i++)
- {
- GNUNET_SCHEDULER_add_now (&internal_continue_startup,
- &pg->peers[i].internal_context);
- }
+ GNUNET_SCHEDULER_add_now (&internal_continue_startup,
+ &pg->peers[i].internal_context);
}
+ }
#else
pg->starting = 0;
for (i = 0; i < pg->total; i++)
- {
- GNUNET_SCHEDULER_add_now (&internal_continue_startup,
- &pg->peers[i].internal_context);
- }
+ {
+ GNUNET_SCHEDULER_add_now (&internal_continue_startup,
+ &pg->peers[i].internal_context);
+ }
#endif
}
#if USE_START_HELPER
static void
-call_hostkey_callbacks (void *cls, const struct GNUNET_SCHEDULER_TaskContext
*tc)
+call_hostkey_callbacks (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_TESTING_PeerGroup *pg = cls;
unsigned int i;
+
for (i = 0; i < pg->total; i++)
- {
- if (pg->peers[i].internal_context.hostkey_callback != NULL)
- pg->peers[i].internal_context.hostkey_callback
(pg->peers[i].internal_context.hostkey_cls,
-
&pg->peers[i].daemon->id,
- pg->peers[i].daemon,
- NULL);
- }
+ {
+ if (pg->peers[i].internal_context.hostkey_callback != NULL)
+ pg->peers[i].internal_context.hostkey_callback (pg->peers
+ [i].
+
internal_context.hostkey_cls,
+ &pg->peers[i].daemon->id,
+ pg->peers[i].daemon,
+ NULL);
+ }
if (pg->peers[0].internal_context.hostkey_callback == NULL)
GNUNET_TESTING_daemons_continue_startup (pg);
@@ -5913,18 +5932,18 @@
* @return NULL on error, otherwise handle to control peer group
*/
struct GNUNET_TESTING_PeerGroup *
-GNUNET_TESTING_daemons_start(const struct GNUNET_CONFIGURATION_Handle *cfg,
- unsigned int total,
- unsigned int max_concurrent_connections,
- unsigned int max_concurrent_ssh,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_TESTING_NotifyHostkeyCreated
hostkey_callback,
- void *hostkey_cls,
- GNUNET_TESTING_NotifyDaemonRunning cb,
- void *cb_cls,
- GNUNET_TESTING_NotifyConnection connect_callback,
- void *connect_callback_cls,
- const struct GNUNET_TESTING_Host *hostnames)
+GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
+ unsigned int total,
+ unsigned int max_concurrent_connections,
+ unsigned int max_concurrent_ssh,
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_TESTING_NotifyHostkeyCreated
+ hostkey_callback, void *hostkey_cls,
+ GNUNET_TESTING_NotifyDaemonRunning cb,
+ void *cb_cls,
+ GNUNET_TESTING_NotifyConnection connect_callback,
+ void *connect_callback_cls,
+ const struct GNUNET_TESTING_Host *hostnames)
{
struct GNUNET_TESTING_PeerGroup *pg;
const struct GNUNET_TESTING_Host *hostpos;
@@ -5952,10 +5971,10 @@
username = NULL;
if (0 == total)
- {
- GNUNET_break (0);
- return NULL;
- }
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
upnum = 0;
fdnum = 0;
@@ -5969,227 +5988,225 @@
pg->max_outstanding_connections = max_concurrent_connections;
pg->max_concurrent_ssh = max_concurrent_ssh;
if (NULL != hostnames)
+ {
+ off = 0;
+ hostpos = hostnames;
+ while (hostpos != NULL)
{
- off = 0;
- hostpos = hostnames;
- while (hostpos != NULL)
- {
- hostpos = hostpos->next;
- off++;
- }
- pg->hosts = GNUNET_malloc (off * sizeof (struct HostData));
- off = 0;
+ hostpos = hostpos->next;
+ off++;
+ }
+ pg->hosts = GNUNET_malloc (off * sizeof (struct HostData));
+ off = 0;
- hostpos = hostnames;
- while (hostpos != NULL)
- {
- pg->hosts[off].minport = LOW_PORT;
- pg->hosts[off].hostname = GNUNET_strdup (hostpos->hostname);
- if (hostpos->username != NULL)
- pg->hosts[off].username = GNUNET_strdup (hostpos->username);
- pg->hosts[off].sshport = hostpos->port;
- hostpos = hostpos->next;
- off++;
- }
+ hostpos = hostnames;
+ while (hostpos != NULL)
+ {
+ pg->hosts[off].minport = LOW_PORT;
+ pg->hosts[off].hostname = GNUNET_strdup (hostpos->hostname);
+ if (hostpos->username != NULL)
+ pg->hosts[off].username = GNUNET_strdup (hostpos->username);
+ pg->hosts[off].sshport = hostpos->port;
+ hostpos = hostpos->next;
+ off++;
+ }
- if (off == 0)
- {
- pg->hosts = NULL;
- }
- hostcnt = off;
- minport = 0;
- pg->num_hosts = off;
+ if (off == 0)
+ {
+ pg->hosts = NULL;
}
+ hostcnt = off;
+ minport = 0;
+ pg->num_hosts = off;
+ }
else
- {
- hostcnt = 0;
- minport = LOW_PORT;
- }
+ {
+ hostcnt = 0;
+ minport = LOW_PORT;
+ }
/* Create the servicehome directory for each remote peer */
- GNUNET_assert(GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS",
"SERVICEHOME",
- &baseservicehome));
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS",
+ "SERVICEHOME",
+ &baseservicehome));
for (i = 0; i < pg->num_hosts; i++)
+ {
+ ssh_entry = GNUNET_malloc (sizeof (struct OutstandingSSH));
+ ssh_entry->hostname = pg->hosts[i].hostname; /* Don't free! */
+ GNUNET_CONTAINER_DLL_insert (pg->ssh_head, pg->ssh_tail, ssh_entry);
+ GNUNET_asprintf (&tmpdir, "%s/%s", baseservicehome, pg->hosts[i].hostname);
+ if (NULL != pg->hosts[i].username)
+ GNUNET_asprintf (&arg, "address@hidden", pg->hosts[i].username,
+ pg->hosts[i].hostname);
+ else
+ GNUNET_asprintf (&arg, "%s", pg->hosts[i].hostname);
+ if (pg->hosts[i].sshport != 0)
{
- ssh_entry = GNUNET_malloc(sizeof(struct OutstandingSSH));
- ssh_entry->hostname = pg->hosts[i].hostname; /* Don't free! */
- GNUNET_CONTAINER_DLL_insert(pg->ssh_head, pg->ssh_tail, ssh_entry);
- GNUNET_asprintf(&tmpdir, "%s/%s", baseservicehome,
pg->hosts[i].hostname);
- if (NULL != pg->hosts[i].username)
- GNUNET_asprintf (&arg, "address@hidden", pg->hosts[i].username,
- pg->hosts[i].hostname);
- else
- GNUNET_asprintf (&arg, "%s", pg->hosts[i].hostname);
- if (pg->hosts[i].sshport != 0)
- {
- GNUNET_asprintf (&ssh_port_str, "%d", pg->hosts[i].sshport);
- proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", "-P",
- ssh_port_str,
+ GNUNET_asprintf (&ssh_port_str, "%d", pg->hosts[i].sshport);
+ proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", "-P",
+ ssh_port_str,
#if !DEBUG_TESTING
- "-q",
+ "-q",
#endif
- arg, "mkdir -p", tmpdir,
- NULL);
- }
- else
- proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", arg,
- "mkdir -p", tmpdir, NULL);
- GNUNET_assert(proc != NULL);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Creating remote dir with command ssh %s %s %s\n", arg,
- " mkdir -p ", tmpdir);
- GNUNET_free(tmpdir);
- GNUNET_free(arg);
- GNUNET_OS_process_wait (proc);
- GNUNET_OS_process_close(proc);
+ arg, "mkdir -p", tmpdir, NULL);
}
- GNUNET_free(baseservicehome);
+ else
+ proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", arg,
+ "mkdir -p", tmpdir, NULL);
+ GNUNET_assert (proc != NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Creating remote dir with command ssh %s %s %s\n", arg,
+ " mkdir -p ", tmpdir);
+ GNUNET_free (tmpdir);
+ GNUNET_free (arg);
+ GNUNET_OS_process_wait (proc);
+ GNUNET_OS_process_close (proc);
+ }
+ GNUNET_free (baseservicehome);
baseservicehome = NULL;
if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (cfg, "TESTING",
"HOSTKEYSFILE",
&hostkeys_file))
+ {
+ if (GNUNET_YES != GNUNET_DISK_file_test (hostkeys_file))
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Could not read hostkeys file!\n"));
+ else
{
- if (GNUNET_YES != GNUNET_DISK_file_test (hostkeys_file))
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Could not read hostkeys file!\n"));
- else
+ /* Check hostkey file size, read entire thing into memory */
+ fd = GNUNET_DISK_file_open (hostkeys_file,
+ GNUNET_DISK_OPEN_READ,
GNUNET_DISK_PERM_NONE);
+ if (NULL == fd)
+ {
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
+ "open", hostkeys_file);
+ GNUNET_free (hostkeys_file);
+ for (i = 0; i < pg->num_hosts; i++)
{
- /* Check hostkey file size, read entire thing into memory */
- fd = GNUNET_DISK_file_open (hostkeys_file,
- GNUNET_DISK_OPEN_READ,
- GNUNET_DISK_PERM_NONE);
- if (NULL == fd)
- {
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
- "open",
- hostkeys_file);
- GNUNET_free (hostkeys_file);
- for (i=0;i<pg->num_hosts;i++)
- {
- GNUNET_free (pg->hosts[i].hostname);
- GNUNET_free_non_null (pg->hosts[i].username);
- }
- GNUNET_free (pg->peers);
- GNUNET_free (pg->hosts);
- GNUNET_free (pg);
- return NULL;
- }
+ GNUNET_free (pg->hosts[i].hostname);
+ GNUNET_free_non_null (pg->hosts[i].username);
+ }
+ GNUNET_free (pg->peers);
+ GNUNET_free (pg->hosts);
+ GNUNET_free (pg);
+ return NULL;
+ }
- if (GNUNET_YES != GNUNET_DISK_file_size (hostkeys_file, &fs,
- GNUNET_YES))
- fs = 0;
+ if (GNUNET_YES != GNUNET_DISK_file_size (hostkeys_file, &fs, GNUNET_YES))
+ fs = 0;
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Found file size %llu for hostkeys, expect hostkeys to
be size %d\n",
- fs, HOSTKEYFILESIZE);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Found file size %llu for hostkeys, expect hostkeys to be
size %d\n",
+ fs, HOSTKEYFILESIZE);
- if (0 != (fs % HOSTKEYFILESIZE))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "File size %llu seems incorrect for hostkeys...\n",
- fs);
- }
- else
- {
- total_hostkeys = fs / HOSTKEYFILESIZE;
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Will read %llu hostkeys from file\n",
- total_hostkeys);
- pg->hostkey_data = GNUNET_malloc_large (fs);
- GNUNET_assert (fs == GNUNET_DISK_file_read (fd,
pg->hostkey_data, fs));
- }
- GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_close(fd));
- }
- GNUNET_free(hostkeys_file);
+ if (0 != (fs % HOSTKEYFILESIZE))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "File size %llu seems incorrect for hostkeys...\n", fs);
+ }
+ else
+ {
+ total_hostkeys = fs / HOSTKEYFILESIZE;
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Will read %llu hostkeys from file\n", total_hostkeys);
+ pg->hostkey_data = GNUNET_malloc_large (fs);
+ GNUNET_assert (fs == GNUNET_DISK_file_read (fd, pg->hostkey_data, fs));
+ }
+ GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd));
}
+ GNUNET_free (hostkeys_file);
+ }
for (off = 0; off < total; off++)
+ {
+ if (hostcnt > 0)
{
- if (hostcnt > 0)
- {
- hostname = pg->hosts[off % hostcnt].hostname;
- username = pg->hosts[off % hostcnt].username;
- sshport = pg->hosts[off % hostcnt].sshport;
- pcfg = make_config (cfg, off, &pg->hosts[off % hostcnt].minport,
- &upnum, hostname, &fdnum);
- }
- else
- {
- hostname = NULL;
- username = NULL;
- sshport = 0;
- pcfg = make_config (cfg, off, &minport, &upnum, hostname, &fdnum);
- }
+ hostname = pg->hosts[off % hostcnt].hostname;
+ username = pg->hosts[off % hostcnt].username;
+ sshport = pg->hosts[off % hostcnt].sshport;
+ pcfg = make_config (cfg, off, &pg->hosts[off % hostcnt].minport,
+ &upnum, hostname, &fdnum);
+ }
+ else
+ {
+ hostname = NULL;
+ username = NULL;
+ sshport = 0;
+ pcfg = make_config (cfg, off, &minport, &upnum, hostname, &fdnum);
+ }
- if (NULL == pcfg)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Could not create configuration for peer number %u on
`%s'!\n"),
- off,
- hostname == NULL ? "localhost" : hostname);
- continue;
- }
+ if (NULL == pcfg)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Could not create configuration for peer number %u on
`%s'!\n"),
+ off, hostname == NULL ? "localhost" : hostname);
+ continue;
+ }
- if (GNUNET_YES
- == GNUNET_CONFIGURATION_get_value_string (pcfg, "PATHS",
- "SERVICEHOME",
- &baseservicehome))
- {
- if (hostname != NULL)
- GNUNET_asprintf (&newservicehome, "%s/%s/%d/", baseservicehome,
hostname, off);
- else
- GNUNET_asprintf (&newservicehome, "%s/%d/", baseservicehome, off);
- GNUNET_free (baseservicehome);
- baseservicehome = NULL;
- }
+ if (GNUNET_YES
+ == GNUNET_CONFIGURATION_get_value_string (pcfg, "PATHS",
+ "SERVICEHOME",
+ &baseservicehome))
+ {
+ if (hostname != NULL)
+ GNUNET_asprintf (&newservicehome, "%s/%s/%d/", baseservicehome,
+ hostname, off);
else
- {
- tmpdir = getenv ("TMPDIR");
- tmpdir = tmpdir ? tmpdir : "/tmp";
- if (hostname != NULL)
- GNUNET_asprintf (&newservicehome, "%s/%s/%s/%d/", tmpdir, hostname,
- "gnunet-testing-test-test", off);
- else
- GNUNET_asprintf (&newservicehome, "%s/%s/%d/", tmpdir,
- "gnunet-testing-test-test", off);
- }
- GNUNET_CONFIGURATION_set_value_string (pcfg, "PATHS", "SERVICEHOME",
- newservicehome);
- GNUNET_free (newservicehome);
- pg->peers[off].cfg = pcfg;
- pg->peers[off].pg = pg;
- pg->peers[off].internal_context.peer = &pg->peers[off];
- pg->peers[off].internal_context.timeout = timeout;
- pg->peers[off].internal_context.hostname = hostname;
- pg->peers[off].internal_context.username = username;
- pg->peers[off].internal_context.sshport = sshport;
- if (pg->hostkey_data != NULL)
- pg->peers[off].internal_context.hostkey = &pg->hostkey_data[off
- * HOSTKEYFILESIZE];
- pg->peers[off].internal_context.hostkey_callback = hostkey_callback;
- pg->peers[off].internal_context.hostkey_cls = hostkey_cls;
- pg->peers[off].internal_context.start_cb = cb;
- pg->peers[off].internal_context.start_cb_cls = cb_cls;
+ GNUNET_asprintf (&newservicehome, "%s/%d/", baseservicehome, off);
+ GNUNET_free (baseservicehome);
+ baseservicehome = NULL;
+ }
+ else
+ {
+ tmpdir = getenv ("TMPDIR");
+ tmpdir = tmpdir ? tmpdir : "/tmp";
+ if (hostname != NULL)
+ GNUNET_asprintf (&newservicehome, "%s/%s/%s/%d/", tmpdir, hostname,
+ "gnunet-testing-test-test", off);
+ else
+ GNUNET_asprintf (&newservicehome, "%s/%s/%d/", tmpdir,
+ "gnunet-testing-test-test", off);
+ }
+ GNUNET_CONFIGURATION_set_value_string (pcfg, "PATHS", "SERVICEHOME",
+ newservicehome);
+ GNUNET_free (newservicehome);
+ pg->peers[off].cfg = pcfg;
+ pg->peers[off].pg = pg;
+ pg->peers[off].internal_context.peer = &pg->peers[off];
+ pg->peers[off].internal_context.timeout = timeout;
+ pg->peers[off].internal_context.hostname = hostname;
+ pg->peers[off].internal_context.username = username;
+ pg->peers[off].internal_context.sshport = sshport;
+ if (pg->hostkey_data != NULL)
+ pg->peers[off].internal_context.hostkey = &pg->hostkey_data[off
+ *
+
HOSTKEYFILESIZE];
+ pg->peers[off].internal_context.hostkey_callback = hostkey_callback;
+ pg->peers[off].internal_context.hostkey_cls = hostkey_cls;
+ pg->peers[off].internal_context.start_cb = cb;
+ pg->peers[off].internal_context.start_cb_cls = cb_cls;
#if !USE_START_HELPER
- GNUNET_SCHEDULER_add_now (&internal_start,
- &pg->peers[off].internal_context);
+ GNUNET_SCHEDULER_add_now (&internal_start,
+ &pg->peers[off].internal_context);
#else
- if ((pg->hostkey_data != NULL) && (hostcnt > 0))
- {
- pg->peers[off].daemon
- = GNUNET_TESTING_daemon_start (pcfg,
- timeout,
- GNUNET_YES,
- hostname,
- username,
- sshport,
-
pg->peers[off].internal_context.hostkey,
- &internal_hostkey_callback,
- &pg->peers[off].internal_context,
- &internal_startup_callback,
- &pg->peers[off].internal_context);
+ if ((pg->hostkey_data != NULL) && (hostcnt > 0))
+ {
+ pg->peers[off].daemon
+ = GNUNET_TESTING_daemon_start (pcfg,
+ timeout,
+ GNUNET_YES,
+ hostname,
+ username,
+ sshport,
+ pg->peers[off].
+ internal_context.hostkey,
+ &internal_hostkey_callback,
+ &pg->peers[off].internal_context,
+ &internal_startup_callback,
+ &pg->peers[off].internal_context);
/**
* At this point, given that we had a hostkeyfile,
* we can call the hostkey callback!
@@ -6199,95 +6216,94 @@
* then set pg->whatever_phase for each peer and let them
* enter the fsm to get the HELLO's for peers and start connecting.
*/
- }
- else
- {
- GNUNET_SCHEDULER_add_now (&internal_start,
- &pg->peers[off].internal_context);
- }
+ }
+ else
+ {
+ GNUNET_SCHEDULER_add_now (&internal_start,
+ &pg->peers[off].internal_context);
+ }
#endif
- }
+ }
-#if USE_START_HELPER /* Now the peergroup has been set up, hostkeys and
configs written to files. */
+#if USE_START_HELPER /* Now the peergroup has been set up, hostkeys
and configs written to files. */
if ((pg->hostkey_data != NULL) && (hostcnt > 0))
+ {
+ for (off = 0; off < hostcnt; off++)
{
- for (off = 0; off < hostcnt; off++)
- {
- if (hostcnt > 0)
- {
- hostname = pg->hosts[off % hostcnt].hostname;
- username = pg->hosts[off % hostcnt].username;
- sshport = pg->hosts[off % hostcnt].sshport;
- }
- else
- {
- hostname = NULL;
- username = NULL;
- sshport = 0;
- }
+ if (hostcnt > 0)
+ {
+ hostname = pg->hosts[off % hostcnt].hostname;
+ username = pg->hosts[off % hostcnt].username;
+ sshport = pg->hosts[off % hostcnt].sshport;
+ }
+ else
+ {
+ hostname = NULL;
+ username = NULL;
+ sshport = 0;
+ }
- if (GNUNET_YES
- == GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS",
- "SERVICEHOME",
- &baseservicehome))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "baseservice home is
%s\n", baseservicehome);
- if (hostname != NULL)
- GNUNET_asprintf (&newservicehome, "%s/%s/", baseservicehome,
hostname);
- else
- GNUNET_asprintf (&newservicehome, "%s/", baseservicehome);
- GNUNET_free (baseservicehome);
- baseservicehome = NULL;
- }
- else
- {
- tmpdir = getenv ("TMPDIR");
- tmpdir = tmpdir ? tmpdir : "/tmp";
- if (hostname != NULL)
- GNUNET_asprintf (&newservicehome, "%s/%s/%s/", tmpdir,
hostname,
- "gnunet-testing-test-test");
- else
- GNUNET_asprintf (&newservicehome, "%s/%s/", tmpdir,
- "gnunet-testing-test-test", off);
- }
+ if (GNUNET_YES
+ == GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS",
+ "SERVICEHOME",
+ &baseservicehome))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "baseservice home is %s\n",
+ baseservicehome);
+ if (hostname != NULL)
+ GNUNET_asprintf (&newservicehome, "%s/%s/", baseservicehome,
+ hostname);
+ else
+ GNUNET_asprintf (&newservicehome, "%s/", baseservicehome);
+ GNUNET_free (baseservicehome);
+ baseservicehome = NULL;
+ }
+ else
+ {
+ tmpdir = getenv ("TMPDIR");
+ tmpdir = tmpdir ? tmpdir : "/tmp";
+ if (hostname != NULL)
+ GNUNET_asprintf (&newservicehome, "%s/%s/%s/", tmpdir, hostname,
+ "gnunet-testing-test-test");
+ else
+ GNUNET_asprintf (&newservicehome, "%s/%s/", tmpdir,
+ "gnunet-testing-test-test", off);
+ }
- if (NULL != username)
- GNUNET_asprintf (&arg,
- "address@hidden:%s",
- username,
- pg->hosts[off].hostname,
- newservicehome);
- else
- GNUNET_asprintf (&arg,
- "%s:%s",
- pg->hosts[off].hostname,
- newservicehome);
-
- /* FIXME: Doesn't support ssh_port option! */
- proc = GNUNET_OS_start_process (NULL, NULL,
- "rsync",
- "rsync", "-r", newservicehome, arg,
NULL);
+ if (NULL != username)
+ GNUNET_asprintf (&arg,
+ "address@hidden:%s",
+ username, pg->hosts[off].hostname, newservicehome);
+ else
+ GNUNET_asprintf (&arg,
+ "%s:%s", pg->hosts[off].hostname, newservicehome);
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "copying directory with command rsync -r %s %s\n",
- newservicehome, arg);
- GNUNET_free(newservicehome);
- GNUNET_free (arg);
- if (NULL == proc)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Could not start `%s' process to copy
configuration directory.\n"),
- "scp");
- GNUNET_assert(0);
- }
- GNUNET_OS_process_wait (proc);
- GNUNET_OS_process_close (proc);
- }
- /* Now all the configuration files and hostkeys are copied to the remote
host. Call the hostkey callback for each peer! */
- GNUNET_SCHEDULER_add_now (&call_hostkey_callbacks, pg);
+ /* FIXME: Doesn't support ssh_port option! */
+ proc = GNUNET_OS_start_process (NULL, NULL,
+ "rsync",
+ "rsync", "-r", newservicehome, arg,
NULL);
+
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "copying directory with command rsync -r %s %s\n",
+ newservicehome, arg);
+ GNUNET_free (newservicehome);
+ GNUNET_free (arg);
+ if (NULL == proc)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _
+ ("Could not start `%s' process to copy configuration
directory.\n"),
+ "scp");
+ GNUNET_assert (0);
+ }
+ GNUNET_OS_process_wait (proc);
+ GNUNET_OS_process_close (proc);
}
+ /* Now all the configuration files and hostkeys are copied to the remote
host. Call the hostkey callback for each peer! */
+ GNUNET_SCHEDULER_add_now (&call_hostkey_callbacks, pg);
+ }
#endif
return pg;
}
@@ -6297,8 +6313,8 @@
* offsetting operation.
*/
struct GNUNET_TESTING_Daemon *
-GNUNET_TESTING_daemon_get(struct GNUNET_TESTING_PeerGroup *pg,
- unsigned int position)
+GNUNET_TESTING_daemon_get (struct GNUNET_TESTING_PeerGroup *pg,
+ unsigned int position)
{
if (position < pg->total)
return pg->peers[position].daemon;
@@ -6315,17 +6331,17 @@
* @return the daemon on success, or NULL if no such peer identity is found
*/
struct GNUNET_TESTING_Daemon *
-GNUNET_TESTING_daemon_get_by_id(struct GNUNET_TESTING_PeerGroup *pg,
- struct GNUNET_PeerIdentity *peer_id)
+GNUNET_TESTING_daemon_get_by_id (struct GNUNET_TESTING_PeerGroup *pg,
+ struct GNUNET_PeerIdentity *peer_id)
{
unsigned int i;
for (i = 0; i < pg->total; i++)
- {
- if (0 == memcmp (&pg->peers[i].daemon->id, peer_id,
- sizeof(struct GNUNET_PeerIdentity)))
- return pg->peers[i].daemon;
- }
+ {
+ if (0 == memcmp (&pg->peers[i].daemon->id, peer_id,
+ sizeof (struct GNUNET_PeerIdentity)))
+ return pg->peers[i].daemon;
+ }
return NULL;
}
@@ -6340,33 +6356,34 @@
* @param emsg NULL on success
*/
static void
-restart_callback(void *cls, const struct GNUNET_PeerIdentity *id,
- const struct GNUNET_CONFIGURATION_Handle *cfg,
- struct GNUNET_TESTING_Daemon *d, const char *emsg)
+restart_callback (void *cls, const struct GNUNET_PeerIdentity *id,
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ struct GNUNET_TESTING_Daemon *d, const char *emsg)
{
struct RestartContext *restart_context = cls;
if (emsg == NULL)
- {
- restart_context->peers_restarted++;
- }
+ {
+ restart_context->peers_restarted++;
+ }
else
- {
- restart_context->peers_restart_failed++;
- }
+ {
+ restart_context->peers_restart_failed++;
+ }
if (restart_context->peers_restarted == restart_context->peer_group->total)
- {
- restart_context->callback (restart_context->callback_cls, NULL);
- GNUNET_free (restart_context);
- }
+ {
+ restart_context->callback (restart_context->callback_cls, NULL);
+ GNUNET_free (restart_context);
+ }
else if (restart_context->peers_restart_failed
- + restart_context->peers_restarted == restart_context->peer_group->total)
- {
- restart_context->callback (restart_context->callback_cls,
- "Failed to restart peers!");
- GNUNET_free (restart_context);
- }
+ + restart_context->peers_restarted ==
+ restart_context->peer_group->total)
+ {
+ restart_context->callback (restart_context->callback_cls,
+ "Failed to restart peers!");
+ GNUNET_free (restart_context);
+ }
}
@@ -6379,7 +6396,7 @@
*
*/
static void
-churn_stop_callback(void *cls, const char *emsg)
+churn_stop_callback (void *cls, const char *emsg)
{
struct ShutdownContext *shutdown_ctx = cls;
struct ChurnContext *churn_ctx = shutdown_ctx->cb_cls;
@@ -6390,34 +6407,32 @@
shutdown_ctx->outstanding--;
if (emsg != NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Churn stop callback failed with error `%s'\n", emsg);
- churn_ctx->num_failed_stop++;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Churn stop callback failed with error `%s'\n", emsg);
+ churn_ctx->num_failed_stop++;
+ }
else
- {
- churn_ctx->num_to_stop--;
- }
+ {
+ churn_ctx->num_to_stop--;
+ }
total_left = (churn_ctx->num_to_stop - churn_ctx->num_failed_stop)
+ (churn_ctx->num_to_start - churn_ctx->num_failed_start);
if (total_left == 0)
+ {
+ if ((churn_ctx->num_failed_stop > 0) || (churn_ctx->num_failed_start > 0))
{
- if ((churn_ctx->num_failed_stop > 0) || (churn_ctx->num_failed_start >
0))
- {
- GNUNET_asprintf (
- &error_message,
- "Churn didn't complete successfully, %u peers
failed to start %u peers failed to be stopped!",
- churn_ctx->num_failed_start,
- churn_ctx->num_failed_stop);
- }
- churn_ctx->cb (churn_ctx->cb_cls, error_message);
- GNUNET_free_non_null (error_message);
- GNUNET_free (churn_ctx);
- GNUNET_free (shutdown_ctx);
+ GNUNET_asprintf (&error_message,
+ "Churn didn't complete successfully, %u peers failed to
start %u peers failed to be stopped!",
+ churn_ctx->num_failed_start,
churn_ctx->num_failed_stop);
}
+ churn_ctx->cb (churn_ctx->cb_cls, error_message);
+ GNUNET_free_non_null (error_message);
+ GNUNET_free (churn_ctx);
+ GNUNET_free (shutdown_ctx);
+ }
}
/**
@@ -6428,18 +6443,19 @@
* @return the number of currently running peers in the peer group
*/
unsigned int
-GNUNET_TESTING_daemons_running(struct GNUNET_TESTING_PeerGroup *pg)
+GNUNET_TESTING_daemons_running (struct GNUNET_TESTING_PeerGroup *pg)
{
unsigned int i;
unsigned int running = 0;
+
for (i = 0; i < pg->total; i++)
+ {
+ if (pg->peers[i].daemon->running == GNUNET_YES)
{
- if (pg->peers[i].daemon->running == GNUNET_YES)
- {
- GNUNET_assert (running != -1);
- running++;
- }
+ GNUNET_assert (running != -1);
+ running++;
}
+ }
return running;
}
@@ -6451,37 +6467,36 @@
* to calling gnunet-arm N times all at once).
*/
static void
-schedule_churn_shutdown_task(void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+schedule_churn_shutdown_task (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct PeerShutdownContext *peer_shutdown_ctx = cls;
struct ShutdownContext *shutdown_ctx;
struct ChurnContext *churn_ctx;
+
GNUNET_assert (peer_shutdown_ctx != NULL);
shutdown_ctx = peer_shutdown_ctx->shutdown_ctx;
GNUNET_assert (shutdown_ctx != NULL);
churn_ctx = (struct ChurnContext *) shutdown_ctx->cb_cls;
if (shutdown_ctx->outstanding > churn_ctx->pg->max_concurrent_ssh)
- GNUNET_SCHEDULER_add_delayed (
- GNUNET_TIME_relative_multiply (
-
GNUNET_TIME_UNIT_MILLISECONDS,
- 100),
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MILLISECONDS, 100),
&schedule_churn_shutdown_task,
peer_shutdown_ctx);
else
- {
- shutdown_ctx->outstanding++;
- if (churn_ctx->service != NULL)
- GNUNET_TESTING_daemon_stop_service (peer_shutdown_ctx->daemon,
- churn_ctx->service,
- shutdown_ctx->timeout,
shutdown_ctx->cb,
- shutdown_ctx);
- else
- GNUNET_TESTING_daemon_stop (peer_shutdown_ctx->daemon,
- shutdown_ctx->timeout, shutdown_ctx->cb,
- shutdown_ctx, GNUNET_NO, GNUNET_YES);
- GNUNET_free (peer_shutdown_ctx);
- }
+ {
+ shutdown_ctx->outstanding++;
+ if (churn_ctx->service != NULL)
+ GNUNET_TESTING_daemon_stop_service (peer_shutdown_ctx->daemon,
+ churn_ctx->service,
+ shutdown_ctx->timeout,
+ shutdown_ctx->cb, shutdown_ctx);
+ else
+ GNUNET_TESTING_daemon_stop (peer_shutdown_ctx->daemon,
+ shutdown_ctx->timeout, shutdown_ctx->cb,
+ shutdown_ctx, GNUNET_NO, GNUNET_YES);
+ GNUNET_free (peer_shutdown_ctx);
+ }
}
@@ -6507,11 +6522,11 @@
* @param cb_cls closure for cb
*/
void
-GNUNET_TESTING_daemons_churn(struct GNUNET_TESTING_PeerGroup *pg,
- char *service,
- unsigned int voff, unsigned int von,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_TESTING_NotifyCompletion cb, void *cb_cls)
+GNUNET_TESTING_daemons_churn (struct GNUNET_TESTING_PeerGroup *pg,
+ char *service,
+ unsigned int voff, unsigned int von,
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_TESTING_NotifyCompletion cb, void *cb_cls)
{
struct ChurnContext *churn_ctx;
struct ShutdownContext *shutdown_ctx;
@@ -6538,73 +6553,75 @@
running = 0;
stopped = 0;
- if ((von == 0) && (voff == 0)) /* No peers at all? */
- {
- cb (cb_cls, NULL);
- return;
- }
+ if ((von == 0) && (voff == 0)) /* No peers at all? */
+ {
+ cb (cb_cls, NULL);
+ return;
+ }
for (i = 0; i < pg->total; i++)
+ {
+ if (service == NULL)
{
- if (service == NULL)
- {
- if (pg->peers[i].daemon->running == GNUNET_YES)
- {
- GNUNET_assert (running != -1);
- running++;
- }
- else
- {
- GNUNET_assert (stopped != -1);
- stopped++;
- }
- }
+ if (pg->peers[i].daemon->running == GNUNET_YES)
+ {
+ GNUNET_assert (running != -1);
+ running++;
+ }
else
+ {
+ GNUNET_assert (stopped != -1);
+ stopped++;
+ }
+ }
+ else
+ {
+ /* FIXME: make churned services a list! */
+ pos = pg->peers[i].daemon->churned_services;
+ /* FIXME: while (pos != NULL) */
+ if (pos != NULL)
+ {
+#if FIXME
+ if (0 == strcasecmp (pos, service))
{
- /* FIXME: make churned services a list! */
- pos = pg->peers[i].daemon->churned_services;
- /* FIXME: while (pos != NULL) */
- if (pos != NULL)
- {
-#if FIXME
- if (0 == strcasecmp(pos, service))
- {
- break;
- }
+ break;
+ }
#endif
- GNUNET_assert (stopped != -1);
- stopped++;
- /* FIXME: pos = pos->next; */
- }
- if (pos == NULL)
- {
- GNUNET_assert (running != -1);
- running++;
- }
- }
+ GNUNET_assert (stopped != -1);
+ stopped++;
+ /* FIXME: pos = pos->next; */
+ }
+ if (pos == NULL)
+ {
+ GNUNET_assert (running != -1);
+ running++;
+ }
}
+ }
if (voff > running)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Trying to stop more peers (%d) than are currently running
(%d)!\n", voff, running);
- cb (cb_cls, "Trying to stop more peers than are currently running!");
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Trying to stop more peers (%d) than are currently running
(%d)!\n",
+ voff, running);
+ cb (cb_cls, "Trying to stop more peers than are currently running!");
+ return;
+ }
if (von > stopped)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Trying to start more peers (%d) than are currently stopped
(%d)!\n", von, stopped);
- cb (cb_cls, "Trying to start more peers than are currently stopped!");
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Trying to start more peers (%d) than are currently stopped
(%d)!\n",
+ von, stopped);
+ cb (cb_cls, "Trying to start more peers than are currently stopped!");
+ return;
+ }
churn_ctx = GNUNET_malloc (sizeof (struct ChurnContext));
if (service != NULL)
- churn_ctx->service = GNUNET_strdup(service);
+ churn_ctx->service = GNUNET_strdup (service);
running_arr = NULL;
if (running > 0)
running_arr = GNUNET_malloc (running * sizeof (unsigned int));
@@ -6635,87 +6652,88 @@
churn_ctx->pg = pg;
for (i = 0; i < pg->total; i++)
+ {
+ if (service == NULL)
{
- if (service == NULL)
- {
- if (pg->peers[i].daemon->running == GNUNET_YES)
- {
- GNUNET_assert ((running_arr != NULL) && (total_running >
running));
- running_arr[running] = i;
- running++;
- }
- else
- {
- GNUNET_assert ((stopped_arr != NULL) && (total_stopped >
stopped));
- stopped_arr[stopped] = i;
- stopped++;
- }
- }
+ if (pg->peers[i].daemon->running == GNUNET_YES)
+ {
+ GNUNET_assert ((running_arr != NULL) && (total_running > running));
+ running_arr[running] = i;
+ running++;
+ }
else
- {
- /* FIXME: make churned services a list! */
- pos = pg->peers[i].daemon->churned_services;
- /* FIXME: while (pos != NULL) */
- if (pos != NULL)
- {
- GNUNET_assert ((stopped_arr != NULL) && (total_stopped >
stopped));
- stopped_arr[stopped] = i;
- stopped++;
- /* FIXME: pos = pos->next; */
- }
- if (pos == NULL)
- {
- GNUNET_assert ((running_arr != NULL) && (total_running >
running));
- running_arr[running] = i;
- running++;
- }
- }
+ {
+ GNUNET_assert ((stopped_arr != NULL) && (total_stopped > stopped));
+ stopped_arr[stopped] = i;
+ stopped++;
+ }
}
+ else
+ {
+ /* FIXME: make churned services a list! */
+ pos = pg->peers[i].daemon->churned_services;
+ /* FIXME: while (pos != NULL) */
+ if (pos != NULL)
+ {
+ GNUNET_assert ((stopped_arr != NULL) && (total_stopped > stopped));
+ stopped_arr[stopped] = i;
+ stopped++;
+ /* FIXME: pos = pos->next; */
+ }
+ if (pos == NULL)
+ {
+ GNUNET_assert ((running_arr != NULL) && (total_running > running));
+ running_arr[running] = i;
+ running++;
+ }
+ }
+ }
GNUNET_assert (running >= voff);
if (voff > 0)
- {
- shutdown_ctx = GNUNET_malloc (sizeof (struct ShutdownContext));
- shutdown_ctx->cb = &churn_stop_callback;
- shutdown_ctx->cb_cls = churn_ctx;
- shutdown_ctx->total_peers = voff;
- shutdown_ctx->timeout = timeout;
- }
+ {
+ shutdown_ctx = GNUNET_malloc (sizeof (struct ShutdownContext));
+ shutdown_ctx->cb = &churn_stop_callback;
+ shutdown_ctx->cb_cls = churn_ctx;
+ shutdown_ctx->total_peers = voff;
+ shutdown_ctx->timeout = timeout;
+ }
for (i = 0; i < voff; i++)
- {
+ {
#if DEBUG_CHURN
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Stopping peer %d!\n",
running_arr[running_permute[i]]);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Stopping peer %d!\n",
+ running_arr[running_permute[i]]);
#endif
- GNUNET_assert (running_arr != NULL);
- peer_shutdown_ctx = GNUNET_malloc (sizeof (struct PeerShutdownContext));
- peer_shutdown_ctx->daemon
- = pg->peers[running_arr[running_permute[i]]].daemon;
- peer_shutdown_ctx->shutdown_ctx = shutdown_ctx;
- GNUNET_SCHEDULER_add_now (&schedule_churn_shutdown_task,
- peer_shutdown_ctx);
- }
+ GNUNET_assert (running_arr != NULL);
+ peer_shutdown_ctx = GNUNET_malloc (sizeof (struct PeerShutdownContext));
+ peer_shutdown_ctx->daemon
+ = pg->peers[running_arr[running_permute[i]]].daemon;
+ peer_shutdown_ctx->shutdown_ctx = shutdown_ctx;
+ GNUNET_SCHEDULER_add_now (&schedule_churn_shutdown_task,
peer_shutdown_ctx);
+ }
GNUNET_assert (stopped >= von);
if (von > 0)
- {
- churn_startup_ctx = GNUNET_malloc (sizeof (struct ChurnRestartContext));
- churn_startup_ctx->churn_ctx = churn_ctx;
- churn_startup_ctx->timeout = timeout;
- churn_startup_ctx->pg = pg;
- }
+ {
+ churn_startup_ctx = GNUNET_malloc (sizeof (struct ChurnRestartContext));
+ churn_startup_ctx->churn_ctx = churn_ctx;
+ churn_startup_ctx->timeout = timeout;
+ churn_startup_ctx->pg = pg;
+ }
for (i = 0; i < von; i++)
- {
+ {
#if DEBUG_CHURN
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Starting up peer %d!\n",
stopped_arr[stopped_permute[i]]);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Starting up peer %d!\n",
+ stopped_arr[stopped_permute[i]]);
#endif
- GNUNET_assert (stopped_arr != NULL);
- peer_restart_ctx = GNUNET_malloc (sizeof (struct PeerRestartContext));
- peer_restart_ctx->churn_restart_ctx = churn_startup_ctx;
- peer_restart_ctx->daemon
- = pg->peers[stopped_arr[stopped_permute[i]]].daemon;
- GNUNET_SCHEDULER_add_now (&schedule_churn_restart, peer_restart_ctx);
- }
+ GNUNET_assert (stopped_arr != NULL);
+ peer_restart_ctx = GNUNET_malloc (sizeof (struct PeerRestartContext));
+ peer_restart_ctx->churn_restart_ctx = churn_startup_ctx;
+ peer_restart_ctx->daemon
+ = pg->peers[stopped_arr[stopped_permute[i]]].daemon;
+ GNUNET_SCHEDULER_add_now (&schedule_churn_restart, peer_restart_ctx);
+ }
GNUNET_free_non_null (running_arr);
GNUNET_free_non_null (stopped_arr);
@@ -6745,26 +6763,28 @@
struct PeerServiceStartContext *peer_start_ctx;
unsigned int i;
- GNUNET_assert(service != NULL);
+ GNUNET_assert (service != NULL);
- start_ctx = GNUNET_malloc(sizeof(struct ServiceStartContext));
+ start_ctx = GNUNET_malloc (sizeof (struct ServiceStartContext));
start_ctx->pg = pg;
start_ctx->remaining = pg->total;
start_ctx->cb = cb;
start_ctx->cb_cls = cb_cls;
- start_ctx->service = GNUNET_strdup(service);
+ start_ctx->service = GNUNET_strdup (service);
start_ctx->timeout = timeout;
for (i = 0; i < pg->total; i++)
- {
+ {
#if DEBUG_START
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Starting up service %s on peer
%d!\n", service, stopped_arr[stopped_permute[i]]);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "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;
- peer_start_ctx->daemon = pg->peers[i].daemon;
- GNUNET_SCHEDULER_add_now (&schedule_service_start, peer_start_ctx);
- }
+ peer_start_ctx = GNUNET_malloc (sizeof (struct PeerServiceStartContext));
+ peer_start_ctx->start_ctx = start_ctx;
+ peer_start_ctx->daemon = pg->peers[i].daemon;
+ GNUNET_SCHEDULER_add_now (&schedule_service_start, peer_start_ctx);
+ }
}
/**
@@ -6775,27 +6795,27 @@
* @param callback_cls closure for the callback function
*/
void
-GNUNET_TESTING_daemons_restart(struct GNUNET_TESTING_PeerGroup *pg,
- GNUNET_TESTING_NotifyCompletion callback,
- void *callback_cls)
+GNUNET_TESTING_daemons_restart (struct GNUNET_TESTING_PeerGroup *pg,
+ GNUNET_TESTING_NotifyCompletion callback,
+ void *callback_cls)
{
struct RestartContext *restart_context;
unsigned int off;
if (pg->total > 0)
+ {
+ restart_context = GNUNET_malloc (sizeof (struct RestartContext));
+ restart_context->peer_group = pg;
+ restart_context->peers_restarted = 0;
+ restart_context->callback = callback;
+ restart_context->callback_cls = callback_cls;
+
+ for (off = 0; off < pg->total; off++)
{
- restart_context = GNUNET_malloc (sizeof (struct RestartContext));
- restart_context->peer_group = pg;
- restart_context->peers_restarted = 0;
- restart_context->callback = callback;
- restart_context->callback_cls = callback_cls;
-
- for (off = 0; off < pg->total; off++)
- {
- GNUNET_TESTING_daemon_restart (pg->peers[off].daemon,
- &restart_callback, restart_context);
- }
+ GNUNET_TESTING_daemon_restart (pg->peers[off].daemon,
+ &restart_callback, restart_context);
}
+ }
}
@@ -6810,47 +6830,47 @@
* @param cb_cls closure for cb
*/
void
-GNUNET_TESTING_daemons_vary(struct GNUNET_TESTING_PeerGroup *pg,
- unsigned int offset, int desired_status,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_TESTING_NotifyCompletion cb, void *cb_cls)
+GNUNET_TESTING_daemons_vary (struct GNUNET_TESTING_PeerGroup *pg,
+ unsigned int offset, int desired_status,
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_TESTING_NotifyCompletion cb, void *cb_cls)
{
struct ShutdownContext *shutdown_ctx;
struct ChurnRestartContext *startup_ctx;
struct ChurnContext *churn_ctx;
if (GNUNET_NO == desired_status)
+ {
+ if (NULL != pg->peers[offset].daemon)
{
- if (NULL != pg->peers[offset].daemon)
- {
- shutdown_ctx = GNUNET_malloc (sizeof (struct ShutdownContext));
- churn_ctx = GNUNET_malloc (sizeof (struct ChurnContext));
- churn_ctx->num_to_start = 0;
- churn_ctx->num_to_stop = 1;
- churn_ctx->cb = cb;
- churn_ctx->cb_cls = cb_cls;
- shutdown_ctx->cb_cls = churn_ctx;
- GNUNET_TESTING_daemon_stop (pg->peers[offset].daemon, timeout,
- &churn_stop_callback, shutdown_ctx,
- GNUNET_NO, GNUNET_YES);
- }
+ shutdown_ctx = GNUNET_malloc (sizeof (struct ShutdownContext));
+ churn_ctx = GNUNET_malloc (sizeof (struct ChurnContext));
+ churn_ctx->num_to_start = 0;
+ churn_ctx->num_to_stop = 1;
+ churn_ctx->cb = cb;
+ churn_ctx->cb_cls = cb_cls;
+ shutdown_ctx->cb_cls = churn_ctx;
+ GNUNET_TESTING_daemon_stop (pg->peers[offset].daemon, timeout,
+ &churn_stop_callback, shutdown_ctx,
+ GNUNET_NO, GNUNET_YES);
}
+ }
else if (GNUNET_YES == desired_status)
+ {
+ if (NULL == pg->peers[offset].daemon)
{
- if (NULL == pg->peers[offset].daemon)
- {
- startup_ctx = GNUNET_malloc (sizeof (struct ChurnRestartContext));
- churn_ctx = GNUNET_malloc (sizeof (struct ChurnContext));
- churn_ctx->num_to_start = 1;
- churn_ctx->num_to_stop = 0;
- churn_ctx->cb = cb;
- churn_ctx->cb_cls = cb_cls;
- startup_ctx->churn_ctx = churn_ctx;
- GNUNET_TESTING_daemon_start_stopped (pg->peers[offset].daemon,
- timeout, &churn_start_callback,
- startup_ctx);
- }
+ startup_ctx = GNUNET_malloc (sizeof (struct ChurnRestartContext));
+ churn_ctx = GNUNET_malloc (sizeof (struct ChurnContext));
+ churn_ctx->num_to_start = 1;
+ churn_ctx->num_to_stop = 0;
+ churn_ctx->cb = cb;
+ churn_ctx->cb_cls = cb_cls;
+ startup_ctx->churn_ctx = churn_ctx;
+ GNUNET_TESTING_daemon_start_stopped (pg->peers[offset].daemon,
+ timeout, &churn_start_callback,
+ startup_ctx);
}
+ }
else
GNUNET_break (0);
}
@@ -6863,7 +6883,7 @@
* @param emsg NULL on success
*/
static void
-internal_shutdown_callback(void *cls, const char *emsg)
+internal_shutdown_callback (void *cls, const char *emsg)
{
struct PeerShutdownContext *peer_shutdown_ctx = cls;
struct ShutdownContext *shutdown_ctx = peer_shutdown_ctx->shutdown_ctx;
@@ -6876,44 +6896,46 @@
shutdown_ctx->pg);
if (emsg == NULL)
- {
- shutdown_ctx->peers_down++;
- }
+ {
+ shutdown_ctx->peers_down++;
+ }
else
- {
+ {
#if VERBOSE_TESTING
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "internal_shutdown_callback",
- "Failed to stop a peer: %s\n", emsg);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "internal_shutdown_callback",
+ "Failed to stop a peer: %s\n", emsg);
#endif
- shutdown_ctx->peers_failed++;
- }
+ shutdown_ctx->peers_failed++;
+ }
if ((shutdown_ctx->cb != NULL) && (shutdown_ctx->peers_down
- + shutdown_ctx->peers_failed == shutdown_ctx->total_peers))
+ + shutdown_ctx->peers_failed ==
+ shutdown_ctx->total_peers))
+ {
+ if (shutdown_ctx->peers_failed > 0)
+ shutdown_ctx->cb (shutdown_ctx->cb_cls,
+ "Not all peers successfully shut down!");
+ else
+ shutdown_ctx->cb (shutdown_ctx->cb_cls, NULL);
+
+ GNUNET_free (shutdown_ctx->pg->peers);
+ GNUNET_free_non_null (shutdown_ctx->pg->hostkey_data);
+ for (off = 0; off < shutdown_ctx->pg->num_hosts; off++)
{
- if (shutdown_ctx->peers_failed > 0)
- shutdown_ctx->cb (shutdown_ctx->cb_cls,
- "Not all peers successfully shut down!");
- else
- shutdown_ctx->cb (shutdown_ctx->cb_cls, NULL);
-
- GNUNET_free (shutdown_ctx->pg->peers);
- GNUNET_free_non_null(shutdown_ctx->pg->hostkey_data);
- for (off = 0; off < shutdown_ctx->pg->num_hosts; off++)
- {
- GNUNET_free (shutdown_ctx->pg->hosts[off].hostname);
- GNUNET_free_non_null (shutdown_ctx->pg->hosts[off].username);
- }
- GNUNET_free_non_null (shutdown_ctx->pg->hosts);
- while (NULL != (ssh_pos = shutdown_ctx->pg->ssh_head))
- {
- GNUNET_CONTAINER_DLL_remove(shutdown_ctx->pg->ssh_head,
shutdown_ctx->pg->ssh_tail, ssh_pos);
- GNUNET_free(ssh_pos);
- }
- GNUNET_free (shutdown_ctx->pg);
- GNUNET_free (shutdown_ctx);
+ GNUNET_free (shutdown_ctx->pg->hosts[off].hostname);
+ GNUNET_free_non_null (shutdown_ctx->pg->hosts[off].username);
}
- GNUNET_free(peer_shutdown_ctx);
+ GNUNET_free_non_null (shutdown_ctx->pg->hosts);
+ while (NULL != (ssh_pos = shutdown_ctx->pg->ssh_head))
+ {
+ GNUNET_CONTAINER_DLL_remove (shutdown_ctx->pg->ssh_head,
+ shutdown_ctx->pg->ssh_tail, ssh_pos);
+ GNUNET_free (ssh_pos);
+ }
+ GNUNET_free (shutdown_ctx->pg);
+ GNUNET_free (shutdown_ctx);
+ }
+ GNUNET_free (peer_shutdown_ctx);
}
@@ -6925,7 +6947,8 @@
* to calling gnunet-arm N times all at once).
*/
static void
-schedule_shutdown_task(void *cls, const struct GNUNET_SCHEDULER_TaskContext
*tc)
+schedule_shutdown_task (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct PeerShutdownContext *peer_shutdown_ctx = cls;
struct ShutdownContext *shutdown_ctx;
@@ -6939,19 +6962,19 @@
&& (count_outstanding_at_host (peer_shutdown_ctx->daemon->hostname,
shutdown_ctx->pg)
< shutdown_ctx->pg->max_concurrent_ssh)))
- {
- if (peer_shutdown_ctx->daemon->hostname != NULL)
- increment_outstanding_at_host (peer_shutdown_ctx->daemon->hostname,
- shutdown_ctx->pg);
- shutdown_ctx->outstanding++;
- GNUNET_TESTING_daemon_stop (peer_shutdown_ctx->daemon,
- shutdown_ctx->timeout,
- &internal_shutdown_callback,
peer_shutdown_ctx,
- shutdown_ctx->delete_files, GNUNET_NO);
- }
+ {
+ if (peer_shutdown_ctx->daemon->hostname != NULL)
+ increment_outstanding_at_host (peer_shutdown_ctx->daemon->hostname,
+ shutdown_ctx->pg);
+ shutdown_ctx->outstanding++;
+ GNUNET_TESTING_daemon_stop (peer_shutdown_ctx->daemon,
+ shutdown_ctx->timeout,
+ &internal_shutdown_callback, peer_shutdown_ctx,
+ shutdown_ctx->delete_files, GNUNET_NO);
+ }
else
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_MILLISECONDS,
- 100),
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MILLISECONDS, 100),
&schedule_shutdown_task, peer_shutdown_ctx);
}
@@ -6987,71 +7010,67 @@
temphost = NULL;
data = NULL;
if (hostfile != NULL)
+ {
+ if (GNUNET_OK != GNUNET_DISK_file_test (hostfile))
+ GNUNET_DISK_fn_write (hostfile, NULL, 0, GNUNET_DISK_PERM_USER_READ
+ | GNUNET_DISK_PERM_USER_WRITE);
+ if ((0 != STAT (hostfile, &frstat)) || (frstat.st_size == 0))
{
- if (GNUNET_OK != GNUNET_DISK_file_test (hostfile))
- GNUNET_DISK_fn_write (hostfile, NULL, 0, GNUNET_DISK_PERM_USER_READ
- | GNUNET_DISK_PERM_USER_WRITE);
- if ((0 != STAT (hostfile, &frstat)) || (frstat.st_size == 0))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Could not open file specified for host list, ending
test!");
- GNUNET_free(hostfile);
- return NULL;
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Could not open file specified for host list, ending test!");
+ GNUNET_free (hostfile);
+ return NULL;
+ }
- data = GNUNET_malloc_large (frstat.st_size);
- GNUNET_assert(data != NULL);
- if (frstat.st_size
- != GNUNET_DISK_fn_read (hostfile, data, frstat.st_size))
- {
- GNUNET_log (
- GNUNET_ERROR_TYPE_ERROR,
- "Could not read file %s specified for host list, ending
test!",
- hostfile);
- GNUNET_free (hostfile);
- GNUNET_free (data);
- return NULL;
- }
+ data = GNUNET_malloc_large (frstat.st_size);
+ GNUNET_assert (data != NULL);
+ if (frstat.st_size != GNUNET_DISK_fn_read (hostfile, data, frstat.st_size))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Could not read file %s specified for host list, ending
test!",
+ hostfile);
+ GNUNET_free (hostfile);
+ GNUNET_free (data);
+ return NULL;
+ }
- GNUNET_free_non_null(hostfile);
+ GNUNET_free_non_null (hostfile);
- buf = data;
- count = 0;
- while (count < frstat.st_size - 1)
+ buf = data;
+ count = 0;
+ while (count < frstat.st_size - 1)
+ {
+ count++;
+ if (((data[count] == '\n')) && (buf != &data[count]))
+ {
+ data[count] = '\0';
+ temphost = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Host));
+ ret = sscanf (buf, "address@hidden:%hd",
+ &temphost->username, &temphost->hostname,
+ &temphost->port);
+ if (3 == ret)
{
- count++;
- if (((data[count] == '\n')) && (buf != &data[count]))
- {
- data[count] = '\0';
- temphost = GNUNET_malloc(sizeof(struct GNUNET_TESTING_Host));
- ret = sscanf (buf, "address@hidden:%hd",
- &temphost->username, &temphost->hostname,
- &temphost->port);
- if (3 == ret)
- {
- GNUNET_log (
- GNUNET_ERROR_TYPE_DEBUG,
- "Successfully read host %s, port %d and user %s
from file\n",
- temphost->hostname, temphost->port,
- temphost->username);
- }
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Error reading line `%s' in hostfile\n", buf);
- GNUNET_free(temphost);
- buf = &data[count + 1];
- continue;
- }
- temphost->next = hosts;
- hosts = temphost;
- buf = &data[count + 1];
- }
- else if ((data[count] == '\n') || (data[count] == '\0'))
- buf = &data[count + 1];
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Successfully read host %s, port %d and user %s from
file\n",
+ temphost->hostname, temphost->port, temphost->username);
}
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Error reading line `%s' in hostfile\n", buf);
+ GNUNET_free (temphost);
+ buf = &data[count + 1];
+ continue;
+ }
+ temphost->next = hosts;
+ hosts = temphost;
+ buf = &data[count + 1];
+ }
+ else if ((data[count] == '\n') || (data[count] == '\0'))
+ buf = &data[count + 1];
}
- GNUNET_free_non_null(data);
+ }
+ GNUNET_free_non_null (data);
return hosts;
}
@@ -7065,13 +7084,14 @@
* @param cb_cls closure for cb
*/
void
-GNUNET_TESTING_daemons_stop(struct GNUNET_TESTING_PeerGroup *pg,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_TESTING_NotifyCompletion cb, void *cb_cls)
+GNUNET_TESTING_daemons_stop (struct GNUNET_TESTING_PeerGroup *pg,
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_TESTING_NotifyCompletion cb, void *cb_cls)
{
unsigned int off;
struct ShutdownContext *shutdown_ctx;
struct PeerShutdownContext *peer_shutdown_ctx;
+
#if OLD
struct PeerConnection *conn_iter;
struct PeerConnection *temp_conn;
@@ -7081,8 +7101,8 @@
shutdown_ctx = GNUNET_malloc (sizeof (struct ShutdownContext));
shutdown_ctx->delete_files = GNUNET_CONFIGURATION_get_value_yesno (pg->cfg,
- "TESTING",
-
"DELETE_FILES");
+ "TESTING",
+
"DELETE_FILES");
shutdown_ctx->cb = cb;
shutdown_ctx->cb_cls = cb_cls;
shutdown_ctx->total_peers = pg->total;
@@ -7091,60 +7111,59 @@
/* shtudown_ctx->outstanding = 0; */
for (off = 0; off < pg->total; off++)
+ {
+ GNUNET_assert (NULL != pg->peers[off].daemon);
+ peer_shutdown_ctx = GNUNET_malloc (sizeof (struct PeerShutdownContext));
+ peer_shutdown_ctx->daemon = pg->peers[off].daemon;
+ peer_shutdown_ctx->shutdown_ctx = shutdown_ctx;
+ GNUNET_SCHEDULER_add_now (&schedule_shutdown_task, peer_shutdown_ctx);
+
+ if (NULL != pg->peers[off].cfg)
{
- GNUNET_assert (NULL != pg->peers[off].daemon);
- peer_shutdown_ctx = GNUNET_malloc (sizeof (struct PeerShutdownContext));
- peer_shutdown_ctx->daemon = pg->peers[off].daemon;
- peer_shutdown_ctx->shutdown_ctx = shutdown_ctx;
- GNUNET_SCHEDULER_add_now (&schedule_shutdown_task, peer_shutdown_ctx);
-
- if (NULL != pg->peers[off].cfg)
- {
- GNUNET_CONFIGURATION_destroy (pg->peers[off].cfg);
- pg->peers[off].cfg = NULL;
- }
+ GNUNET_CONFIGURATION_destroy (pg->peers[off].cfg);
+ pg->peers[off].cfg = NULL;
+ }
#if OLD
- conn_iter = pg->peers[off].allowed_peers_head;
- while (conn_iter != NULL)
- {
- temp_conn = conn_iter->next;
- GNUNET_free(conn_iter);
- conn_iter = temp_conn;
- }
+ conn_iter = pg->peers[off].allowed_peers_head;
+ while (conn_iter != NULL)
+ {
+ temp_conn = conn_iter->next;
+ GNUNET_free (conn_iter);
+ conn_iter = temp_conn;
+ }
- conn_iter = pg->peers[off].connect_peers_head;
- while (conn_iter != NULL)
- {
- temp_conn = conn_iter->next;
- GNUNET_free(conn_iter);
- conn_iter = temp_conn;
- }
+ conn_iter = pg->peers[off].connect_peers_head;
+ while (conn_iter != NULL)
+ {
+ temp_conn = conn_iter->next;
+ GNUNET_free (conn_iter);
+ conn_iter = temp_conn;
+ }
- conn_iter = pg->peers[off].blacklisted_peers_head;
- while (conn_iter != NULL)
- {
- temp_conn = conn_iter->next;
- GNUNET_free(conn_iter);
- conn_iter = temp_conn;
- }
+ conn_iter = pg->peers[off].blacklisted_peers_head;
+ while (conn_iter != NULL)
+ {
+ temp_conn = conn_iter->next;
+ GNUNET_free (conn_iter);
+ conn_iter = temp_conn;
+ }
- conn_iter = pg->peers[off].connect_peers_working_set_head;
- while (conn_iter != NULL)
- {
- temp_conn = conn_iter->next;
- GNUNET_free(conn_iter);
- conn_iter = temp_conn;
- }
+ conn_iter = pg->peers[off].connect_peers_working_set_head;
+ while (conn_iter != NULL)
+ {
+ temp_conn = conn_iter->next;
+ GNUNET_free (conn_iter);
+ conn_iter = temp_conn;
+ }
#else
- if (pg->peers[off].allowed_peers != NULL)
- GNUNET_CONTAINER_multihashmap_destroy (pg->peers[off].allowed_peers);
- if (pg->peers[off].connect_peers != NULL)
- GNUNET_CONTAINER_multihashmap_destroy (pg->peers[off].connect_peers);
- if (pg->peers[off].blacklisted_peers != NULL)
- GNUNET_CONTAINER_multihashmap_destroy (pg->
- peers[off].blacklisted_peers);
+ if (pg->peers[off].allowed_peers != NULL)
+ GNUNET_CONTAINER_multihashmap_destroy (pg->peers[off].allowed_peers);
+ if (pg->peers[off].connect_peers != NULL)
+ GNUNET_CONTAINER_multihashmap_destroy (pg->peers[off].connect_peers);
+ if (pg->peers[off].blacklisted_peers != NULL)
+ GNUNET_CONTAINER_multihashmap_destroy (pg->peers[off].blacklisted_peers);
#endif
- }
+ }
}
/* end of testing_group.c */
Modified: gnunet/src/testing/testing_peergroup.c
===================================================================
--- gnunet/src/testing/testing_peergroup.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/testing/testing_peergroup.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -166,18 +166,19 @@
* @return the progress meter
*/
static struct ProgressMeter *
-create_meter(unsigned int total, char * start_string, int print)
+create_meter (unsigned int total, char *start_string, int print)
{
struct ProgressMeter *ret;
- ret = GNUNET_malloc(sizeof(struct ProgressMeter));
+
+ ret = GNUNET_malloc (sizeof (struct ProgressMeter));
ret->print = print;
ret->total = total;
ret->modnum = total / 4;
ret->dotnum = (total / 50) + 1;
if (start_string != NULL)
- ret->startup_string = GNUNET_strdup(start_string);
+ ret->startup_string = GNUNET_strdup (start_string);
else
- ret->startup_string = GNUNET_strdup("");
+ ret->startup_string = GNUNET_strdup ("");
return ret;
}
@@ -191,27 +192,27 @@
* GNUNET_NO if more items expected
*/
static int
-update_meter(struct ProgressMeter *meter)
+update_meter (struct ProgressMeter *meter)
{
if (meter->print == GNUNET_YES)
+ {
+ if (meter->completed % meter->modnum == 0)
{
- if (meter->completed % meter->modnum == 0)
- {
- if (meter->completed == 0)
- {
- fprintf (stdout, "%sProgress: [0%%", meter->startup_string);
- }
- else
- fprintf (stdout, "%d%%", (int) (((float) meter->completed
- / meter->total) * 100));
- }
- else if (meter->completed % meter->dotnum == 0)
- fprintf (stdout, ".");
+ if (meter->completed == 0)
+ {
+ fprintf (stdout, "%sProgress: [0%%", meter->startup_string);
+ }
+ else
+ fprintf (stdout, "%d%%", (int) (((float) meter->completed
+ / meter->total) * 100));
+ }
+ else if (meter->completed % meter->dotnum == 0)
+ fprintf (stdout, ".");
- if (meter->completed + 1 == meter->total)
- fprintf (stdout, "%d%%]\n", 100);
- fflush (stdout);
- }
+ if (meter->completed + 1 == meter->total)
+ fprintf (stdout, "%d%%]\n", 100);
+ fflush (stdout);
+ }
meter->completed++;
if (meter->completed == meter->total)
@@ -228,7 +229,7 @@
* GNUNET_SYSERR on error
*/
static int
-reset_meter(struct ProgressMeter *meter)
+reset_meter (struct ProgressMeter *meter)
{
if (meter == NULL)
return GNUNET_SYSERR;
@@ -243,7 +244,7 @@
* @param meter the meter to free
*/
static void
-free_meter(struct ProgressMeter *meter)
+free_meter (struct ProgressMeter *meter)
{
GNUNET_free_non_null (meter->startup_string);
GNUNET_free (meter);
@@ -256,13 +257,14 @@
* Check whether peers successfully shut down.
*/
static void
-internal_shutdown_callback(void *cls, const char *emsg)
+internal_shutdown_callback (void *cls, const char *emsg)
{
struct PeerGroupStartupContext *pg_start_ctx = cls;
+
if (emsg != NULL)
- pg_start_ctx->peergroup_cb(pg_start_ctx->cls, emsg);
+ pg_start_ctx->peergroup_cb (pg_start_ctx->cls, emsg);
else
- pg_start_ctx->peergroup_cb(pg_start_ctx->cls, pg_start_ctx->fail_reason);
+ pg_start_ctx->peergroup_cb (pg_start_ctx->cls, pg_start_ctx->fail_reason);
}
/**
@@ -271,13 +273,18 @@
* test.
*/
static void
-end_badly(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
+end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct PeerGroupStartupContext *pg_start_ctx = cls;
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failing peer group startup with
error: `%s'!\n",
+
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failing peer group startup with error: `%s'!\n",
pg_start_ctx->fail_reason);
- GNUNET_TESTING_daemons_stop (pg_start_ctx->pg,
GNUNET_TIME_absolute_get_remaining(pg_start_ctx->timeout),
&internal_shutdown_callback, pg_start_ctx);
+ GNUNET_TESTING_daemons_stop (pg_start_ctx->pg,
+ GNUNET_TIME_absolute_get_remaining
+ (pg_start_ctx->timeout),
+ &internal_shutdown_callback, pg_start_ctx);
if (pg_start_ctx->hostkey_meter != NULL)
free_meter (pg_start_ctx->hostkey_meter);
@@ -297,21 +304,22 @@
* failure (peers failed to connect).
*/
static void
-internal_topology_callback(
- void *cls,
- const struct GNUNET_PeerIdentity *first,
- const struct GNUNET_PeerIdentity *second,
- uint32_t distance,
- const struct GNUNET_CONFIGURATION_Handle *first_cfg,
- const struct GNUNET_CONFIGURATION_Handle
*second_cfg,
- struct GNUNET_TESTING_Daemon *first_daemon,
- struct GNUNET_TESTING_Daemon *second_daemon,
- const char *emsg)
+internal_topology_callback (void *cls,
+ const struct GNUNET_PeerIdentity *first,
+ const struct GNUNET_PeerIdentity *second,
+ uint32_t distance,
+ const struct GNUNET_CONFIGURATION_Handle
*first_cfg,
+ const struct GNUNET_CONFIGURATION_Handle
+ *second_cfg,
+ struct GNUNET_TESTING_Daemon *first_daemon,
+ struct GNUNET_TESTING_Daemon *second_daemon,
+ const char *emsg)
{
struct PeerGroupStartupContext *pg_start_ctx = cls;
char *temp_str;
char *second_str;
int temp;
+
#if TIMING
unsigned long long duration;
unsigned long long total_duration;
@@ -325,201 +333,201 @@
#if TIMING
if (GNUNET_TIME_absolute_get_difference (connect_last_time,
- GNUNET_TIME_absolute_get
()).rel_value
- > GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
- CONN_UPDATE_DURATION).rel_value)
- {
- /* Get number of new connections */
- new_connections = total_connections - previous_connections;
+ GNUNET_TIME_absolute_get
+ ()).rel_value >
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
+ CONN_UPDATE_DURATION).rel_value)
+ {
+ /* Get number of new connections */
+ new_connections = total_connections - previous_connections;
- /* Get number of new FAILED connections */
- new_failed_connections = failed_connections -
previous_failed_connections;
+ /* Get number of new FAILED connections */
+ new_failed_connections = failed_connections - previous_failed_connections;
- /* Get duration in seconds */
- duration
- = GNUNET_TIME_absolute_get_difference (connect_last_time,
- GNUNET_TIME_absolute_get
()).rel_value
- / 1000;
- total_duration
- = GNUNET_TIME_absolute_get_difference (connect_start_time,
- GNUNET_TIME_absolute_get
()).rel_value
- / 1000;
+ /* Get duration in seconds */
+ duration
+ = GNUNET_TIME_absolute_get_difference (connect_last_time,
+ GNUNET_TIME_absolute_get
+ ()).rel_value / 1000;
+ total_duration =
+ GNUNET_TIME_absolute_get_difference (connect_start_time,
+ GNUNET_TIME_absolute_get
+ ()).rel_value / 1000;
- failed_conns_per_sec_recent = (double) new_failed_connections / duration;
- failed_conns_per_sec_total = (double) failed_connections /
total_duration;
- conns_per_sec_recent = (double) new_connections / duration;
- conns_per_sec_total = (double) total_connections / total_duration;
- GNUNET_log (
- GNUNET_ERROR_TYPE_WARNING,
- "Recent: %.2f/s, Total: %.2f/s, Recent failed: %.2f/s, total
failed %.2f/s\n",
- conns_per_sec_recent, CONN_UPDATE_DURATION,
- conns_per_sec_total, failed_conns_per_sec_recent,
- failed_conns_per_sec_total);
- connect_last_time = GNUNET_TIME_absolute_get ();
- previous_connections = total_connections;
- previous_failed_connections = failed_connections;
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "have %u total_connections, %u failed\n", total_connections,
- failed_connections);
- }
+ failed_conns_per_sec_recent = (double) new_failed_connections / duration;
+ failed_conns_per_sec_total = (double) failed_connections / total_duration;
+ conns_per_sec_recent = (double) new_connections / duration;
+ conns_per_sec_total = (double) total_connections / total_duration;
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Recent: %.2f/s, Total: %.2f/s, Recent failed: %.2f/s, total
failed %.2f/s\n",
+ conns_per_sec_recent, CONN_UPDATE_DURATION,
+ conns_per_sec_total, failed_conns_per_sec_recent,
+ failed_conns_per_sec_total);
+ connect_last_time = GNUNET_TIME_absolute_get ();
+ previous_connections = total_connections;
+ previous_failed_connections = failed_connections;
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "have %u total_connections, %u failed\n", total_connections,
+ failed_connections);
+ }
#endif
if (emsg == NULL)
- {
- pg_start_ctx->total_connections++;
+ {
+ pg_start_ctx->total_connections++;
#if VERBOSE > 1
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s,
distance %u\n",
- first_daemon->shortname,
- second_daemon->shortname,
- distance);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "connected peer %s to peer %s, distance %u\n",
+ first_daemon->shortname, second_daemon->shortname, distance);
#endif
- if (pg_start_ctx->topology_output_file != NULL)
- {
- second_str = GNUNET_strdup(GNUNET_i2s(second));
- temp = GNUNET_asprintf(&temp_str, "\t\"%s\" -- \"%s\"\n",
GNUNET_i2s(first), second_str);
- GNUNET_free(second_str);
- if (temp > 0)
- GNUNET_DISK_file_write(pg_start_ctx->topology_output_file,
temp_str, temp);
- GNUNET_free(temp_str);
- }
+ if (pg_start_ctx->topology_output_file != NULL)
+ {
+ second_str = GNUNET_strdup (GNUNET_i2s (second));
+ temp =
+ GNUNET_asprintf (&temp_str, "\t\"%s\" -- \"%s\"\n",
+ GNUNET_i2s (first), second_str);
+ GNUNET_free (second_str);
+ if (temp > 0)
+ GNUNET_DISK_file_write (pg_start_ctx->topology_output_file, temp_str,
+ temp);
+ GNUNET_free (temp_str);
}
+ }
else
- {
- pg_start_ctx->failed_connections++;
+ {
+ pg_start_ctx->failed_connections++;
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to connect peer %s to
peer %s with error :\n%s\n",
- first_daemon->shortname,
- second_daemon->shortname, emsg);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to connect peer %s to peer %s with error :\n%s\n",
+ first_daemon->shortname, second_daemon->shortname, emsg);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to connect peer %s to peer
%s with error :\n%s\n",
- first_daemon->shortname,
- second_daemon->shortname, emsg);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to connect peer %s to peer %s with error :\n%s\n",
+ first_daemon->shortname, second_daemon->shortname, emsg);
#endif
- }
+ }
- GNUNET_assert(pg_start_ctx->connect_meter != NULL);
+ GNUNET_assert (pg_start_ctx->connect_meter != NULL);
if (pg_start_ctx->connect_cb != NULL)
- pg_start_ctx->connect_cb(pg_start_ctx->cls, first,
- second,
- distance,
- first_cfg,
- second_cfg,
- first_daemon,
- second_daemon,
- emsg);
+ pg_start_ctx->connect_cb (pg_start_ctx->cls, first,
+ second,
+ distance,
+ first_cfg,
+ second_cfg, first_daemon, second_daemon, emsg);
if (GNUNET_YES == update_meter (pg_start_ctx->connect_meter))
- {
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Created %d total connections, which is our target number! Starting
next phase of testing.\n",
- total_connections);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Created %d total connections, which is our target number!
Starting next phase of testing.\n",
+ total_connections);
#endif
#if TIMING
- total_duration
- = GNUNET_TIME_absolute_get_difference (connect_start_time,
- GNUNET_TIME_absolute_get
()).rel_value
- / 1000;
- failed_conns_per_sec_total = (double) failed_connections /
total_duration;
- conns_per_sec_total = (double) total_connections / total_duration;
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Overall connection info --- Total: %u, Total Failed %u/s\n",
- total_connections, failed_connections);
- GNUNET_log (
- GNUNET_ERROR_TYPE_WARNING,
- "Overall connection info --- Total: %.2f/s, Total Failed
%.2f/s\n",
- conns_per_sec_total, failed_conns_per_sec_total);
+ total_duration
+ = GNUNET_TIME_absolute_get_difference (connect_start_time,
+ GNUNET_TIME_absolute_get
+ ()).rel_value / 1000;
+ failed_conns_per_sec_total = (double) failed_connections / total_duration;
+ conns_per_sec_total = (double) total_connections / total_duration;
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Overall connection info --- Total: %u, Total Failed %u/s\n",
+ total_connections, failed_connections);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Overall connection info --- Total: %.2f/s, Total Failed
%.2f/s\n",
+ conns_per_sec_total, failed_conns_per_sec_total);
#endif
- GNUNET_assert(pg_start_ctx->die_task != GNUNET_SCHEDULER_NO_TASK);
- GNUNET_SCHEDULER_cancel (pg_start_ctx->die_task);
+ GNUNET_assert (pg_start_ctx->die_task != GNUNET_SCHEDULER_NO_TASK);
+ GNUNET_SCHEDULER_cancel (pg_start_ctx->die_task);
- /* Call final callback, signifying that the peer group has been started
and connected */
- if (pg_start_ctx->peergroup_cb != NULL)
- pg_start_ctx->peergroup_cb(pg_start_ctx->cls, NULL);
+ /* Call final callback, signifying that the peer group has been started
and connected */
+ if (pg_start_ctx->peergroup_cb != NULL)
+ pg_start_ctx->peergroup_cb (pg_start_ctx->cls, NULL);
- if (pg_start_ctx->topology_output_file != NULL)
- {
- temp = GNUNET_asprintf(&temp_str, "}\n");
- if (temp > 0)
- GNUNET_DISK_file_write(pg_start_ctx->topology_output_file,
temp_str, temp);
- GNUNET_free(temp_str);
- GNUNET_DISK_file_close(pg_start_ctx->topology_output_file);
- }
+ if (pg_start_ctx->topology_output_file != NULL)
+ {
+ temp = GNUNET_asprintf (&temp_str, "}\n");
+ if (temp > 0)
+ GNUNET_DISK_file_write (pg_start_ctx->topology_output_file, temp_str,
+ temp);
+ GNUNET_free (temp_str);
+ GNUNET_DISK_file_close (pg_start_ctx->topology_output_file);
}
+ }
}
static void
-internal_peers_started_callback(void *cls, const struct GNUNET_PeerIdentity
*id,
- const struct GNUNET_CONFIGURATION_Handle *cfg,
- struct GNUNET_TESTING_Daemon *d, const char *emsg)
+internal_peers_started_callback (void *cls,
+ const struct GNUNET_PeerIdentity *id,
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ struct GNUNET_TESTING_Daemon *d,
+ const char *emsg)
{
struct PeerGroupStartupContext *pg_start_ctx = cls;
+
if (emsg != NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Failed to start daemon with error: `%s'\n", emsg);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to start daemon with error: `%s'\n", emsg);
+ return;
+ }
GNUNET_assert (id != NULL);
#if VERBOSE > 1
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n",
- (num_peers - peers_left) + 1, num_peers);
+ (num_peers - peers_left) + 1, num_peers);
#endif
pg_start_ctx->peers_left--;
if (GNUNET_YES == update_meter (pg_start_ctx->peer_start_meter))
- {
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "All %d daemons started, now connecting peers!\n",
- num_peers);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "All %d daemons started, now connecting peers!\n", num_peers);
#endif
- GNUNET_assert(pg_start_ctx->die_task != GNUNET_SCHEDULER_NO_TASK);
- GNUNET_SCHEDULER_cancel (pg_start_ctx->die_task);
+ GNUNET_assert (pg_start_ctx->die_task != GNUNET_SCHEDULER_NO_TASK);
+ GNUNET_SCHEDULER_cancel (pg_start_ctx->die_task);
- pg_start_ctx->expected_connections = UINT_MAX;
- if ((pg_start_ctx->pg != NULL) && (pg_start_ctx->peers_left == 0))
- {
- pg_start_ctx->connect_start_time = GNUNET_TIME_absolute_get ();
- pg_start_ctx->expected_connections
- = GNUNET_TESTING_connect_topology (
- pg_start_ctx->pg,
-
pg_start_ctx->connect_topology,
-
pg_start_ctx->connect_topology_option,
-
pg_start_ctx->connect_topology_option_modifier,
- DEFAULT_CONNECT_TIMEOUT,
-
pg_start_ctx->connect_attempts,
- NULL, NULL);
+ pg_start_ctx->expected_connections = UINT_MAX;
+ if ((pg_start_ctx->pg != NULL) && (pg_start_ctx->peers_left == 0))
+ {
+ pg_start_ctx->connect_start_time = GNUNET_TIME_absolute_get ();
+ pg_start_ctx->expected_connections
+ = GNUNET_TESTING_connect_topology (pg_start_ctx->pg,
+ pg_start_ctx->connect_topology,
+
pg_start_ctx->connect_topology_option,
+
pg_start_ctx->connect_topology_option_modifier,
+ DEFAULT_CONNECT_TIMEOUT,
+ pg_start_ctx->connect_attempts,
+ NULL, NULL);
- pg_start_ctx->connect_meter
- = create_meter (pg_start_ctx->expected_connections,
- "Peer connection ", pg_start_ctx->verbose);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Have %d expected connections\n",
- pg_start_ctx->expected_connections);
- }
+ pg_start_ctx->connect_meter
+ = create_meter (pg_start_ctx->expected_connections,
+ "Peer connection ", pg_start_ctx->verbose);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Have %d expected connections\n",
+ pg_start_ctx->expected_connections);
+ }
- if (pg_start_ctx->expected_connections == 0)
- {
- GNUNET_free_non_null(pg_start_ctx->fail_reason);
- pg_start_ctx->fail_reason = GNUNET_strdup("from connect topology
(bad return)");
- pg_start_ctx->die_task
- = GNUNET_SCHEDULER_add_now (&end_badly,
- pg_start_ctx);
- }
+ if (pg_start_ctx->expected_connections == 0)
+ {
+ GNUNET_free_non_null (pg_start_ctx->fail_reason);
+ pg_start_ctx->fail_reason =
+ GNUNET_strdup ("from connect topology (bad return)");
+ pg_start_ctx->die_task =
+ GNUNET_SCHEDULER_add_now (&end_badly, pg_start_ctx);
+ }
- GNUNET_free_non_null(pg_start_ctx->fail_reason);
- pg_start_ctx->fail_reason = GNUNET_strdup("from connect topology
(timeout)");
- pg_start_ctx->die_task
- = GNUNET_SCHEDULER_add_delayed (
- GNUNET_TIME_absolute_get_remaining
(pg_start_ctx->timeout),
- &end_badly,
- pg_start_ctx);
- }
+ GNUNET_free_non_null (pg_start_ctx->fail_reason);
+ pg_start_ctx->fail_reason =
+ GNUNET_strdup ("from connect topology (timeout)");
+ pg_start_ctx->die_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
+ (pg_start_ctx->timeout), &end_badly,
+ pg_start_ctx);
+ }
}
/**
@@ -531,56 +539,61 @@
* @param emsg non-null on failure
*/
static void
-internal_hostkey_callback(void *cls, const struct GNUNET_PeerIdentity *id,
- struct GNUNET_TESTING_Daemon *d, const char *emsg)
+internal_hostkey_callback (void *cls, const struct GNUNET_PeerIdentity *id,
+ struct GNUNET_TESTING_Daemon *d, const char *emsg)
{
struct PeerGroupStartupContext *pg_start_ctx = cls;
unsigned int create_expected_connections;
if (emsg != NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Hostkey callback received error: %s\n", emsg);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Hostkey callback received error: %s\n", emsg);
+ }
#if VERBOSE > 1
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Hostkey (%d/%d) created for peer `%s'\n",
- num_peers - peers_left, num_peers, GNUNET_i2s(id));
+ "Hostkey (%d/%d) created for peer `%s'\n",
+ num_peers - peers_left, num_peers, GNUNET_i2s (id));
#endif
pg_start_ctx->peers_left--;
if (GNUNET_YES == update_meter (pg_start_ctx->hostkey_meter))
+ {
+ GNUNET_SCHEDULER_cancel (pg_start_ctx->die_task);
+ /* Set up task in case topology creation doesn't finish
+ * within a reasonable amount of time */
+ pg_start_ctx->die_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
+ (pg_start_ctx->timeout), &end_badly,
+ "from create_topology");
+ pg_start_ctx->peers_left = pg_start_ctx->total; /* Reset counter */
+ create_expected_connections =
+ GNUNET_TESTING_create_topology (pg_start_ctx->pg,
+ pg_start_ctx->topology,
+ pg_start_ctx->restrict_topology,
+ pg_start_ctx->restrict_transports);
+ if (create_expected_connections > 0)
{
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Topology set up, have %u expected connections, now starting
peers!\n",
+ create_expected_connections);
+ GNUNET_TESTING_daemons_continue_startup (pg_start_ctx->pg);
+ }
+ else
+ {
GNUNET_SCHEDULER_cancel (pg_start_ctx->die_task);
- /* Set up task in case topology creation doesn't finish
- * within a reasonable amount of time */
- pg_start_ctx->die_task = GNUNET_SCHEDULER_add_delayed
(GNUNET_TIME_absolute_get_remaining(pg_start_ctx->timeout),
- &end_badly,
- "from
create_topology");
- pg_start_ctx->peers_left = pg_start_ctx->total; /* Reset counter */
- create_expected_connections = GNUNET_TESTING_create_topology
(pg_start_ctx->pg, pg_start_ctx->topology, pg_start_ctx->restrict_topology,
-
pg_start_ctx->restrict_transports);
- if (create_expected_connections > 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Topology set up, have %u expected connections, now
starting peers!\n", create_expected_connections);
- GNUNET_TESTING_daemons_continue_startup (pg_start_ctx->pg);
- }
- else
- {
- GNUNET_SCHEDULER_cancel (pg_start_ctx->die_task);
- pg_start_ctx->die_task = GNUNET_SCHEDULER_add_now (&end_badly,
- "from create topology (bad
return)");
- }
+ pg_start_ctx->die_task = GNUNET_SCHEDULER_add_now (&end_badly,
+ "from create topology
(bad return)");
+ }
- GNUNET_SCHEDULER_cancel (pg_start_ctx->die_task);
- pg_start_ctx->die_task
- = GNUNET_SCHEDULER_add_delayed (
-
GNUNET_TIME_absolute_get_remaining(pg_start_ctx->timeout),
- &end_badly,
- "from continue startup (timeout)");
- }
+ GNUNET_SCHEDULER_cancel (pg_start_ctx->die_task);
+ pg_start_ctx->die_task
+ =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
+ (pg_start_ctx->timeout), &end_badly,
+ "from continue startup (timeout)");
+ }
}
@@ -597,41 +610,42 @@
void
write_topology_cb (void *cls,
const struct GNUNET_PeerIdentity *first,
- const struct GNUNET_PeerIdentity *second,
- const char *emsg)
+ const struct GNUNET_PeerIdentity *second, const char *emsg)
{
struct TopologyOutputContext *topo_ctx;
int temp;
char *temp_str;
char *temp_pid2;
- topo_ctx = (struct TopologyOutputContext *)cls;
- GNUNET_assert(topo_ctx->file != NULL);
+ topo_ctx = (struct TopologyOutputContext *) cls;
+ GNUNET_assert (topo_ctx->file != NULL);
if ((emsg == NULL) && (first != NULL) && (second != NULL))
- {
- GNUNET_assert(first != NULL);
- GNUNET_assert(second != NULL);
- temp_pid2 = GNUNET_strdup(GNUNET_i2s(second));
- temp = GNUNET_asprintf(&temp_str, "\t\"%s\" -- \"%s\"\n",
GNUNET_i2s(first), temp_pid2);
- GNUNET_free(temp_pid2);
- GNUNET_DISK_file_write(topo_ctx->file, temp_str, temp);
- }
+ {
+ GNUNET_assert (first != NULL);
+ GNUNET_assert (second != NULL);
+ temp_pid2 = GNUNET_strdup (GNUNET_i2s (second));
+ temp =
+ GNUNET_asprintf (&temp_str, "\t\"%s\" -- \"%s\"\n", GNUNET_i2s (first),
+ temp_pid2);
+ GNUNET_free (temp_pid2);
+ GNUNET_DISK_file_write (topo_ctx->file, temp_str, temp);
+ }
else if ((emsg == NULL) && (first == NULL) && (second == NULL))
- {
- temp = GNUNET_asprintf(&temp_str, "}\n");
- GNUNET_DISK_file_write(topo_ctx->file, temp_str, temp);
- GNUNET_DISK_file_close(topo_ctx->file);
- topo_ctx->notify_cb(topo_ctx->notify_cb_cls, NULL);
- GNUNET_free(topo_ctx);
- }
+ {
+ temp = GNUNET_asprintf (&temp_str, "}\n");
+ GNUNET_DISK_file_write (topo_ctx->file, temp_str, temp);
+ GNUNET_DISK_file_close (topo_ctx->file);
+ topo_ctx->notify_cb (topo_ctx->notify_cb_cls, NULL);
+ GNUNET_free (topo_ctx);
+ }
else
- {
- temp = GNUNET_asprintf(&temp_str, "}\n");
- GNUNET_DISK_file_write(topo_ctx->file, temp_str, temp);
- GNUNET_DISK_file_close(topo_ctx->file);
- topo_ctx->notify_cb(topo_ctx->notify_cb_cls, emsg);
- GNUNET_free(topo_ctx);
- }
+ {
+ temp = GNUNET_asprintf (&temp_str, "}\n");
+ GNUNET_DISK_file_write (topo_ctx->file, temp_str, temp);
+ GNUNET_DISK_file_close (topo_ctx->file);
+ topo_ctx->notify_cb (topo_ctx->notify_cb_cls, emsg);
+ GNUNET_free (topo_ctx);
+ }
}
/**
@@ -644,34 +658,37 @@
*
*/
void
-GNUNET_TESTING_peergroup_topology_to_file(struct GNUNET_TESTING_PeerGroup *pg,
- const char *output_filename,
- GNUNET_TESTING_NotifyCompletion
notify_cb,
- void *notify_cb_cls)
+GNUNET_TESTING_peergroup_topology_to_file (struct GNUNET_TESTING_PeerGroup *pg,
+ const char *output_filename,
+ GNUNET_TESTING_NotifyCompletion
+ notify_cb, void *notify_cb_cls)
{
struct TopologyOutputContext *topo_ctx;
int temp;
char *temp_str;
- topo_ctx = GNUNET_malloc(sizeof(struct TopologyOutputContext));
+ topo_ctx = GNUNET_malloc (sizeof (struct TopologyOutputContext));
+
topo_ctx->notify_cb = notify_cb;
topo_ctx->notify_cb_cls = notify_cb_cls;
- topo_ctx->file = GNUNET_DISK_file_open (output_filename,
GNUNET_DISK_OPEN_READWRITE
- |
GNUNET_DISK_OPEN_CREATE,
-
GNUNET_DISK_PERM_USER_READ |
-
GNUNET_DISK_PERM_USER_WRITE);
+ topo_ctx->file =
+ GNUNET_DISK_file_open (output_filename,
+ GNUNET_DISK_OPEN_READWRITE |
+ GNUNET_DISK_OPEN_CREATE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE);
if (topo_ctx->file == NULL)
- {
- notify_cb (notify_cb_cls, "Failed to open output file!");
- GNUNET_free (topo_ctx);
- return;
- }
+ {
+ notify_cb (notify_cb_cls, "Failed to open output file!");
+ GNUNET_free (topo_ctx);
+ return;
+ }
- temp = GNUNET_asprintf(&temp_str, "strict graph G {\n");
+ temp = GNUNET_asprintf (&temp_str, "strict graph G {\n");
if (temp > 0)
- GNUNET_DISK_file_write(topo_ctx->file, temp_str, temp);
- GNUNET_free_non_null(temp_str);
- GNUNET_TESTING_get_topology(pg, &write_topology_cb, topo_ctx);
+ GNUNET_DISK_file_write (topo_ctx->file, temp_str, temp);
+ GNUNET_free_non_null (temp_str);
+ GNUNET_TESTING_get_topology (pg, &write_topology_cb, topo_ctx);
}
/**
@@ -692,75 +709,80 @@
* @return NULL on error, otherwise handle to control peer group
*/
struct GNUNET_TESTING_PeerGroup *
-GNUNET_TESTING_peergroup_start(const struct GNUNET_CONFIGURATION_Handle *cfg,
- unsigned int total,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_TESTING_NotifyConnection connect_cb,
- GNUNET_TESTING_NotifyCompletion peergroup_cb,
- void *peergroup_cls,
- const struct GNUNET_TESTING_Host *hostnames)
+GNUNET_TESTING_peergroup_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
+ unsigned int total,
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_TESTING_NotifyConnection connect_cb,
+ GNUNET_TESTING_NotifyCompletion peergroup_cb,
+ void *peergroup_cls,
+ const struct GNUNET_TESTING_Host *hostnames)
{
struct PeerGroupStartupContext *pg_start_ctx;
unsigned long long temp_config_number;
char *temp_str;
int temp;
- GNUNET_assert(total > 0);
- GNUNET_assert(cfg != NULL);
- pg_start_ctx = GNUNET_malloc(sizeof(struct PeerGroupStartupContext));
+ GNUNET_assert (total > 0);
+ GNUNET_assert (cfg != NULL);
+ pg_start_ctx = GNUNET_malloc (sizeof (struct PeerGroupStartupContext));
+
if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "testing",
"connect_attempts",
&pg_start_ctx->connect_attempts))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
- "testing", "connect_attempts");
- GNUNET_free(pg_start_ctx);
- return NULL;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
+ "testing", "connect_attempts");
+ GNUNET_free (pg_start_ctx);
+ return NULL;
+ }
if (GNUNET_OK
!= GNUNET_CONFIGURATION_get_value_number (cfg, "testing",
"max_outstanding_connections",
&pg_start_ctx->max_concurrent_connections))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
- "testing", "max_outstanding_connections");
- GNUNET_free(pg_start_ctx);
- return NULL;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
+ "testing", "max_outstanding_connections");
+ GNUNET_free (pg_start_ctx);
+ return NULL;
+ }
if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "testing",
"max_concurrent_ssh",
&pg_start_ctx->max_concurrent_ssh))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
- "testing", "max_concurrent_ssh");
- GNUNET_free(pg_start_ctx);
- return NULL;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
+ "testing", "max_concurrent_ssh");
+ GNUNET_free (pg_start_ctx);
+ return NULL;
+ }
- if (GNUNET_SYSERR == (pg_start_ctx->verbose =
GNUNET_CONFIGURATION_get_value_yesno (cfg, "testing",
- "use_progressbars")))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
- "testing", "use_progressbars");
- GNUNET_free(pg_start_ctx);
- return NULL;
- }
+ if (GNUNET_SYSERR ==
+ (pg_start_ctx->verbose =
+ GNUNET_CONFIGURATION_get_value_yesno (cfg, "testing",
+ "use_progressbars")))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
+ "testing", "use_progressbars");
+ GNUNET_free (pg_start_ctx);
+ return NULL;
+ }
if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "testing",
"peergroup_timeout",
&temp_config_number))
- pg_start_ctx->timeout =
GNUNET_TIME_relative_to_absolute(GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_SECONDS,
- temp_config_number));
+ pg_start_ctx->timeout =
+ GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS,
+ temp_config_number));
else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
- "testing", "peergroup_timeout");
- GNUNET_free(pg_start_ctx);
- return NULL;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
+ "testing", "peergroup_timeout");
+ GNUNET_free (pg_start_ctx);
+ return NULL;
+ }
/* Read topology related options from the configuration file */
@@ -768,102 +790,106 @@
if ((GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
"topology",
&temp_str))
- && (GNUNET_NO == GNUNET_TESTING_topology_get (&pg_start_ctx->topology,
temp_str)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Invalid topology `%s' given for section %s option %s\n",
- temp_str, "TESTING", "TOPOLOGY");
- pg_start_ctx->topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to
NONE, so set better default here */
- }
- GNUNET_free_non_null(temp_str);
+ && (GNUNET_NO ==
+ GNUNET_TESTING_topology_get (&pg_start_ctx->topology, temp_str)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Invalid topology `%s' given for section %s option %s\n",
+ temp_str, "TESTING", "TOPOLOGY");
+ pg_start_ctx->topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to
NONE, so set better default here */
+ }
+ GNUNET_free_non_null (temp_str);
- if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string(cfg, "testing",
"topology_output_file", &temp_str))
+ if (GNUNET_YES ==
+ GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
+ "topology_output_file",
&temp_str))
+ {
+ pg_start_ctx->topology_output_file =
+ GNUNET_DISK_file_open (temp_str,
+ GNUNET_DISK_OPEN_READWRITE |
+ GNUNET_DISK_OPEN_CREATE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE);
+ if (pg_start_ctx->topology_output_file != NULL)
{
- pg_start_ctx->topology_output_file = GNUNET_DISK_file_open (temp_str,
GNUNET_DISK_OPEN_READWRITE
- |
GNUNET_DISK_OPEN_CREATE,
-
GNUNET_DISK_PERM_USER_READ |
-
GNUNET_DISK_PERM_USER_WRITE);
- if (pg_start_ctx->topology_output_file != NULL)
- {
- GNUNET_free(temp_str);
- temp = GNUNET_asprintf(&temp_str, "strict graph G {\n");
- if (temp > 0)
- GNUNET_DISK_file_write(pg_start_ctx->topology_output_file,
temp_str, temp);
- }
- GNUNET_free(temp_str);
+ GNUNET_free (temp_str);
+ temp = GNUNET_asprintf (&temp_str, "strict graph G {\n");
+ if (temp > 0)
+ GNUNET_DISK_file_write (pg_start_ctx->topology_output_file, temp_str,
+ temp);
}
+ GNUNET_free (temp_str);
+ }
if (GNUNET_OK
!= GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "percentage",
&temp_str))
pg_start_ctx->topology_percentage = 0.5;
else
- {
- pg_start_ctx->topology_percentage = atof (temp_str);
- GNUNET_free(temp_str);
- }
+ {
+ pg_start_ctx->topology_percentage = atof (temp_str);
+ GNUNET_free (temp_str);
+ }
if (GNUNET_OK
!= GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "probability",
&temp_str))
pg_start_ctx->topology_probability = 0.5;
else
- {
- pg_start_ctx->topology_probability = atof (temp_str);
- GNUNET_free(temp_str);
- }
+ {
+ pg_start_ctx->topology_probability = atof (temp_str);
+ GNUNET_free (temp_str);
+ }
if ((GNUNET_YES
- == GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
- "connect_topology",
- &temp_str))
- && (GNUNET_NO == GNUNET_TESTING_topology_get
(&pg_start_ctx->connect_topology,
- temp_str)))
- {
- GNUNET_log (
- GNUNET_ERROR_TYPE_WARNING,
- "Invalid connect topology `%s' given for section %s option
%s\n",
- temp_str, "TESTING", "CONNECT_TOPOLOGY");
- }
- GNUNET_free_non_null(temp_str);
+ == GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
+ "connect_topology",
+ &temp_str))
+ && (GNUNET_NO ==
+ GNUNET_TESTING_topology_get (&pg_start_ctx->connect_topology,
+ temp_str)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Invalid connect topology `%s' given for section %s option
%s\n",
+ temp_str, "TESTING", "CONNECT_TOPOLOGY");
+ }
+ GNUNET_free_non_null (temp_str);
if ((GNUNET_YES
- == GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
- "connect_topology_option",
- &temp_str))
+ == GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
+ "connect_topology_option",
+ &temp_str))
&& (GNUNET_NO
- == GNUNET_TESTING_topology_option_get
(&pg_start_ctx->connect_topology_option,
- temp_str)))
- {
- GNUNET_log (
- GNUNET_ERROR_TYPE_WARNING,
- "Invalid connect topology option `%s' given for section %s
option %s\n",
- temp_str, "TESTING",
- "CONNECT_TOPOLOGY_OPTION");
- pg_start_ctx->connect_topology_option =
GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /* Defaults to NONE, set to ALL */
- }
- GNUNET_free_non_null(temp_str);
+ ==
+ GNUNET_TESTING_topology_option_get
+ (&pg_start_ctx->connect_topology_option, temp_str)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Invalid connect topology option `%s' given for section %s
option %s\n",
+ temp_str, "TESTING", "CONNECT_TOPOLOGY_OPTION");
+ pg_start_ctx->connect_topology_option =
GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /* Defaults to NONE, set to ALL */
+ }
+ GNUNET_free_non_null (temp_str);
if (GNUNET_YES
== GNUNET_CONFIGURATION_get_value_string (cfg,
"testing",
"connect_topology_option_modifier",
&temp_str))
+ {
+ if (sscanf (temp_str, "%lf",
+ &pg_start_ctx->connect_topology_option_modifier) != 1)
{
- if (sscanf (temp_str, "%lf",
- &pg_start_ctx->connect_topology_option_modifier) != 1)
- {
- GNUNET_log (
- GNUNET_ERROR_TYPE_WARNING,
- _("Invalid value `%s' for option `%s' in section `%s':
expected float\n"),
- temp_str,
- "connect_topology_option_modifier", "TESTING");
- GNUNET_free (temp_str);
- GNUNET_free(pg_start_ctx);
- return NULL;
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Invalid value `%s' for option `%s' in section `%s':
expected float\n"),
+ temp_str, "connect_topology_option_modifier", "TESTING");
GNUNET_free (temp_str);
+ GNUNET_free (pg_start_ctx);
+ return NULL;
}
+ GNUNET_free (temp_str);
+ }
if (GNUNET_YES
!= GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
@@ -873,18 +899,19 @@
pg_start_ctx->restrict_topology = GNUNET_TESTING_TOPOLOGY_NONE;
if ((GNUNET_YES
- == GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
- "blacklist_topology",
- &temp_str))
- && (GNUNET_NO == GNUNET_TESTING_topology_get
(&pg_start_ctx->restrict_topology,
- temp_str)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Invalid topology `%s' given for section %s option %s\n",
- temp_str, "TESTING", "BLACKLIST_TOPOLOGY");
- }
+ == GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
+ "blacklist_topology",
+ &temp_str))
+ && (GNUNET_NO ==
+ GNUNET_TESTING_topology_get (&pg_start_ctx->restrict_topology,
+ temp_str)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Invalid topology `%s' given for section %s option %s\n",
+ temp_str, "TESTING", "BLACKLIST_TOPOLOGY");
+ }
- GNUNET_free_non_null(temp_str);
+ GNUNET_free_non_null (temp_str);
pg_start_ctx->cfg = cfg;
pg_start_ctx->total = total;
@@ -893,28 +920,30 @@
pg_start_ctx->peergroup_cb = peergroup_cb;
pg_start_ctx->cls = peergroup_cls;
pg_start_ctx->hostnames = hostnames;
- pg_start_ctx->hostkey_meter = create_meter (pg_start_ctx->peers_left,
"Hostkeys created ", pg_start_ctx->verbose);
- pg_start_ctx->peer_start_meter = create_meter (pg_start_ctx->peers_left,
"Peers started ", pg_start_ctx->verbose);
+ pg_start_ctx->hostkey_meter =
+ create_meter (pg_start_ctx->peers_left, "Hostkeys created ",
+ pg_start_ctx->verbose);
+ pg_start_ctx->peer_start_meter =
+ create_meter (pg_start_ctx->peers_left, "Peers started ",
+ pg_start_ctx->verbose);
/* Make compilers happy */
- reset_meter(pg_start_ctx->peer_start_meter);
+ reset_meter (pg_start_ctx->peer_start_meter);
pg_start_ctx->die_task
- = GNUNET_SCHEDULER_add_delayed (
- GNUNET_TIME_absolute_get_remaining (
-
pg_start_ctx->timeout),
- &end_badly,
- "didn't generate all hostkeys within
allowed startup time!");
+ =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
+ (pg_start_ctx->timeout), &end_badly,
+ "didn't generate all hostkeys within
allowed startup time!");
pg_start_ctx->pg
- = GNUNET_TESTING_daemons_start (
- pg_start_ctx->cfg,
+ = GNUNET_TESTING_daemons_start (pg_start_ctx->cfg,
pg_start_ctx->peers_left,
pg_start_ctx->max_concurrent_connections,
pg_start_ctx->max_concurrent_ssh,
-
GNUNET_TIME_absolute_get_remaining(pg_start_ctx->timeout),
+ GNUNET_TIME_absolute_get_remaining
+ (pg_start_ctx->timeout),
&internal_hostkey_callback, pg_start_ctx,
&internal_peers_started_callback,
- pg_start_ctx,
- &internal_topology_callback,
+ pg_start_ctx,
&internal_topology_callback,
pg_start_ctx, pg_start_ctx->hostnames);
return pg_start_ctx->pg;
Modified: gnunet/src/topology/gnunet-daemon-topology.c
===================================================================
--- gnunet/src/topology/gnunet-daemon-topology.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/topology/gnunet-daemon-topology.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -86,13 +86,13 @@
* Our handle for the request to transmit HELLOs to this peer; NULL
* if no such request is pending.
*/
- struct GNUNET_CORE_TransmitHandle *hello_req;
+ struct GNUNET_CORE_TransmitHandle *hello_req;
/**
* Our handle for the request to connect to this peer; NULL if no
* such request is pending.
*/
- struct GNUNET_CORE_PeerRequestHandle *connect_req;
+ struct GNUNET_CORE_PeerRequestHandle *connect_req;
/**
* Pointer to the HELLO message of this peer; can be NULL.
@@ -240,19 +240,15 @@
* @return GNUNET_OK if the connection is allowed
*/
static int
-blacklist_check (void *cls,
- const struct GNUNET_PeerIdentity *pid)
+blacklist_check (void *cls, const struct GNUNET_PeerIdentity *pid)
{
struct Peer *pos;
pos = GNUNET_CONTAINER_multihashmap_get (peers, &pid->hashPubKey);
- if ( (pos != NULL) &&
- (pos->is_friend == GNUNET_YES) )
+ if ((pos != NULL) && (pos->is_friend == GNUNET_YES))
return GNUNET_OK;
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# peers blacklisted"),
- 1,
- GNUNET_NO);
+ gettext_noop ("# peers blacklisted"), 1,
GNUNET_NO);
return GNUNET_SYSERR;
}
@@ -265,10 +261,10 @@
whitelist_peers ()
{
if (blacklist != NULL)
- {
- GNUNET_TRANSPORT_blacklist_cancel (blacklist);
- blacklist = NULL;
- }
+ {
+ GNUNET_TRANSPORT_blacklist_cancel (blacklist);
+ blacklist = NULL;
+ }
}
@@ -279,8 +275,7 @@
* @param success was the request transmitted
*/
static void
-connect_completed_callback (void *cls,
- int success)
+connect_completed_callback (void *cls, int success)
{
struct Peer *pos = cls;
@@ -297,28 +292,27 @@
static int
is_connection_allowed (struct Peer *peer)
{
- if (0 == memcmp (&my_identity,
- &peer->pid,
- sizeof (struct GNUNET_PeerIdentity)))
+ if (0 == memcmp (&my_identity,
+ &peer->pid, sizeof (struct GNUNET_PeerIdentity)))
return GNUNET_SYSERR; /* disallow connections to self */
if (peer->is_friend)
return GNUNET_OK;
if (GNUNET_YES == friends_only)
- {
+ {
#if DEBUG_TOPOLOGY
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Determined that `%s' is not allowed to connect (not a
friend)\n",
- GNUNET_i2s (&peer->pid));
-#endif
- return GNUNET_SYSERR;
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Determined that `%s' is not allowed to connect (not a
friend)\n",
+ GNUNET_i2s (&peer->pid));
+#endif
+ return GNUNET_SYSERR;
+ }
if (friend_count >= minimum_friend_count)
return GNUNET_OK;
#if DEBUG_TOPOLOGY
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Determined that `%s' is not allowed to connect (not enough
connected friends)\n",
- GNUNET_i2s (&peer->pid));
-#endif
+ "Determined that `%s' is not allowed to connect (not enough
connected friends)\n",
+ GNUNET_i2s (&peer->pid));
+#endif
return GNUNET_SYSERR;
}
@@ -332,25 +326,21 @@
* @return GNUNET_YES (always: continue to iterate)
*/
static int
-free_peer (void *cls,
- const GNUNET_HashCode *pid,
- void *value)
+free_peer (void *cls, const GNUNET_HashCode * pid, void *value)
{
struct Peer *pos = value;
- GNUNET_break (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_remove (peers,
- pid,
- pos));
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_CONTAINER_multihashmap_remove (peers, pid, pos));
if (pos->hello_req != NULL)
GNUNET_CORE_notify_transmit_ready_cancel (pos->hello_req);
if (pos->connect_req != NULL)
- GNUNET_CORE_peer_request_connect_cancel (pos->connect_req);
+ GNUNET_CORE_peer_request_connect_cancel (pos->connect_req);
if (pos->hello_delay_task != GNUNET_SCHEDULER_NO_TASK)
GNUNET_SCHEDULER_cancel (pos->hello_delay_task);
if (pos->greylist_clean_task != GNUNET_SCHEDULER_NO_TASK)
GNUNET_SCHEDULER_cancel (pos->greylist_clean_task);
- GNUNET_free_non_null (pos->hello);
+ GNUNET_free_non_null (pos->hello);
if (pos->filter != NULL)
GNUNET_CONTAINER_bloomfilter_free (pos->filter);
GNUNET_free (pos);
@@ -366,8 +356,7 @@
* @param tc scheduler context
*/
static void
-remove_from_greylist (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+remove_from_greylist (void *cls, const struct GNUNET_SCHEDULER_TaskContext
*tc);
/**
@@ -379,9 +368,9 @@
attempt_connect (struct Peer *pos)
{
struct GNUNET_TIME_Relative rem;
-
- if ( (connection_count >= target_connection_count) &&
- (friend_count >= minimum_friend_count) )
+
+ if ((connection_count >= target_connection_count) &&
+ (friend_count >= minimum_friend_count))
return;
if (GNUNET_YES == pos->is_connected)
return;
@@ -398,30 +387,24 @@
if (pos->connect_attempts > 30)
pos->connect_attempts = 30;
rem = GNUNET_TIME_relative_multiply (rem, 1 << (++pos->connect_attempts));
- rem = GNUNET_TIME_relative_max (rem,
- GREYLIST_AFTER_ATTEMPT_MIN);
- rem = GNUNET_TIME_relative_min (rem,
- GREYLIST_AFTER_ATTEMPT_MAX);
+ rem = GNUNET_TIME_relative_max (rem, GREYLIST_AFTER_ATTEMPT_MIN);
+ rem = GNUNET_TIME_relative_min (rem, GREYLIST_AFTER_ATTEMPT_MAX);
pos->greylisted_until = GNUNET_TIME_relative_to_absolute (rem);
if (pos->greylist_clean_task != GNUNET_SCHEDULER_NO_TASK)
GNUNET_SCHEDULER_cancel (pos->greylist_clean_task);
- pos->greylist_clean_task
- = GNUNET_SCHEDULER_add_delayed (rem,
- &remove_from_greylist,
- pos);
+ pos->greylist_clean_task
+ = GNUNET_SCHEDULER_add_delayed (rem, &remove_from_greylist, pos);
#if DEBUG_TOPOLOGY
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Asking to connect to `%s'\n",
- GNUNET_i2s (&pos->pid));
+ "Asking to connect to `%s'\n", GNUNET_i2s (&pos->pid));
#endif
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# connect requests issued to core"),
- 1,
- GNUNET_NO);
+ gettext_noop ("# connect requests issued to core"),
+ 1, GNUNET_NO);
pos->connect_req = GNUNET_CORE_peer_request_connect (handle,
- &pos->pid,
-
&connect_completed_callback,
- pos);
+ &pos->pid,
+
&connect_completed_callback,
+ pos);
}
@@ -433,8 +416,7 @@
* @param tc scheduler context
*/
static void
-remove_from_greylist (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+remove_from_greylist (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct Peer *pos = cls;
struct GNUNET_TIME_Relative rem;
@@ -442,23 +424,20 @@
pos->greylist_clean_task = GNUNET_SCHEDULER_NO_TASK;
rem = GNUNET_TIME_absolute_get_remaining (pos->greylisted_until);
if (rem.rel_value == 0)
- {
- attempt_connect (pos);
- }
+ {
+ attempt_connect (pos);
+ }
else
- {
- pos->greylist_clean_task
- = GNUNET_SCHEDULER_add_delayed (rem,
- &remove_from_greylist,
- pos);
- }
- if ( (GNUNET_NO == pos->is_friend) &&
- (GNUNET_NO == pos->is_connected) &&
- (NULL == pos->hello) )
- {
- free_peer (NULL, &pos->pid.hashPubKey, pos);
- return;
- }
+ {
+ pos->greylist_clean_task
+ = GNUNET_SCHEDULER_add_delayed (rem, &remove_from_greylist, pos);
+ }
+ if ((GNUNET_NO == pos->is_friend) &&
+ (GNUNET_NO == pos->is_connected) && (NULL == pos->hello))
+ {
+ free_peer (NULL, &pos->pid.hashPubKey, pos);
+ return;
+ }
}
@@ -472,26 +451,24 @@
*/
static struct Peer *
make_peer (const struct
- GNUNET_PeerIdentity * peer,
- const struct GNUNET_HELLO_Message *hello,
- int is_friend)
+ GNUNET_PeerIdentity *peer,
+ const struct GNUNET_HELLO_Message *hello, int is_friend)
{
struct Peer *ret;
-
+
ret = GNUNET_malloc (sizeof (struct Peer));
ret->pid = *peer;
ret->is_friend = is_friend;
if (hello != NULL)
- {
- ret->hello = GNUNET_malloc (GNUNET_HELLO_size (hello));
- memcpy (ret->hello, hello,
- GNUNET_HELLO_size (hello));
- }
+ {
+ ret->hello = GNUNET_malloc (GNUNET_HELLO_size (hello));
+ memcpy (ret->hello, hello, GNUNET_HELLO_size (hello));
+ }
GNUNET_break (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_put (peers,
- &peer->hashPubKey,
- ret,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+ GNUNET_CONTAINER_multihashmap_put (peers,
+ &peer->hashPubKey,
+ ret,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
return ret;
}
@@ -505,14 +482,16 @@
setup_filter (struct Peer *peer)
{
/* 2^{-5} chance of not sending a HELLO to a peer is
- acceptably small (if the filter is 50% full);
- 64 bytes of memory are small compared to the rest
- of the data structure and would only really become
- "useless" once a HELLO has been passed on to ~100
- other peers, which is likely more than enough in
- any case; hence 64, 5 as bloomfilter parameters. */
+ * acceptably small (if the filter is 50% full);
+ * 64 bytes of memory are small compared to the rest
+ * of the data structure and would only really become
+ * "useless" once a HELLO has been passed on to ~100
+ * other peers, which is likely more than enough in
+ * any case; hence 64, 5 as bloomfilter parameters. */
peer->filter = GNUNET_CONTAINER_bloomfilter_init (NULL, 64, 5);
- peer->filter_expiration = GNUNET_TIME_relative_to_absolute
(HELLO_ADVERTISEMENT_MIN_REPEAT_FREQUENCY);
+ peer->filter_expiration =
+ GNUNET_TIME_relative_to_absolute
+ (HELLO_ADVERTISEMENT_MIN_REPEAT_FREQUENCY);
/* never send a peer its own HELLO */
GNUNET_CONTAINER_bloomfilter_add (peer->filter, &peer->pid.hashPubKey);
}
@@ -526,16 +505,14 @@
* @param buf where the callee should write the message
* @return number of bytes written to buf
*/
-static size_t
-hello_advertising_ready (void *cls,
- size_t size,
- void *buf);
+static size_t hello_advertising_ready (void *cls, size_t size, void *buf);
/**
* Closure for 'find_advertisable_hello'.
*/
-struct FindAdvHelloContext {
+struct FindAdvHelloContext
+{
/**
* Peer we want to advertise to.
@@ -565,9 +542,7 @@
* @return GNUNET_YES (continue iteration)
*/
static int
-find_advertisable_hello (void *cls,
- const GNUNET_HashCode *pid,
- void *value)
+find_advertisable_hello (void *cls, const GNUNET_HashCode * pid, void *value)
{
struct FindAdvHelloContext *fah = cls;
struct Peer *pos = value;
@@ -580,20 +555,19 @@
return GNUNET_YES;
rst_time = GNUNET_TIME_absolute_get_remaining (pos->filter_expiration);
if (0 == rst_time.rel_value)
- {
- /* time to discard... */
- GNUNET_CONTAINER_bloomfilter_free (pos->filter);
- setup_filter (pos);
- }
- fah->next_adv = GNUNET_TIME_relative_min (rst_time,
- fah->next_adv);
+ {
+ /* time to discard... */
+ GNUNET_CONTAINER_bloomfilter_free (pos->filter);
+ setup_filter (pos);
+ }
+ fah->next_adv = GNUNET_TIME_relative_min (rst_time, fah->next_adv);
hs = GNUNET_HELLO_size (pos->hello);
if (hs > fah->max_size)
return GNUNET_YES;
if (GNUNET_NO ==
GNUNET_CONTAINER_bloomfilter_test (pos->filter,
- &fah->peer->pid.hashPubKey))
- fah->result = pos;
+ &fah->peer->pid.hashPubKey))
+ fah->result = pos;
return GNUNET_YES;
}
@@ -606,48 +580,43 @@
* @param tc task context
*/
static void
-schedule_next_hello (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+schedule_next_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct Peer *pl = cls;
struct FindAdvHelloContext fah;
size_t next_want;
struct GNUNET_TIME_Relative delay;
-
+
pl->hello_delay_task = GNUNET_SCHEDULER_NO_TASK;
- GNUNET_assert (GNUNET_YES == pl->is_connected);
+ GNUNET_assert (GNUNET_YES == pl->is_connected);
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return; /* we're out of here */
+ return; /* we're out of here */
if (pl->hello_req != NULL)
- return; /* did not finish sending the previous one */
+ return; /* did not finish sending the previous one */
/* find applicable HELLOs */
fah.peer = pl;
fah.result = NULL;
fah.max_size = GNUNET_SERVER_MAX_MESSAGE_SIZE - 1;
fah.next_adv = GNUNET_TIME_UNIT_FOREVER_REL;
- GNUNET_CONTAINER_multihashmap_iterate (peers,
- &find_advertisable_hello,
- &fah);
- pl->hello_delay_task
- = GNUNET_SCHEDULER_add_delayed (fah.next_adv,
- &schedule_next_hello,
- pl);
+ GNUNET_CONTAINER_multihashmap_iterate (peers, &find_advertisable_hello,
&fah);
+ pl->hello_delay_task
+ = GNUNET_SCHEDULER_add_delayed (fah.next_adv, &schedule_next_hello, pl);
if (fah.result == NULL)
- return;
+ return;
next_want = GNUNET_HELLO_size (fah.result->hello);
delay = GNUNET_TIME_absolute_get_remaining (pl->next_hello_allowed);
if (delay.rel_value == 0)
- {
- /* now! */
- pl->hello_req = GNUNET_CORE_notify_transmit_ready (handle,
- GNUNET_YES,
- 0,
-
GNUNET_CONSTANTS_SERVICE_TIMEOUT,
- &pl->pid,
- next_want,
-
&hello_advertising_ready,
- pl);
- }
+ {
+ /* now! */
+ pl->hello_req = GNUNET_CORE_notify_transmit_ready (handle,
+ GNUNET_YES,
+ 0,
+
GNUNET_CONSTANTS_SERVICE_TIMEOUT,
+ &pl->pid,
+ next_want,
+
&hello_advertising_ready,
+ pl);
+ }
}
@@ -662,30 +631,27 @@
* @return GNUNET_YES (always)
*/
static int
-reschedule_hellos (void *cls,
- const GNUNET_HashCode *pid,
- void *value)
+reschedule_hellos (void *cls, const GNUNET_HashCode * pid, void *value)
{
struct Peer *peer = value;
struct Peer *skip = cls;
if (skip == peer)
return GNUNET_YES;
- if (! peer->is_connected)
+ if (!peer->is_connected)
return GNUNET_YES;
if (peer->hello_req != NULL)
- {
- GNUNET_CORE_notify_transmit_ready_cancel (peer->hello_req);
- peer->hello_req = NULL;
- }
+ {
+ GNUNET_CORE_notify_transmit_ready_cancel (peer->hello_req);
+ peer->hello_req = NULL;
+ }
if (peer->hello_delay_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (peer->hello_delay_task);
- peer->hello_delay_task = GNUNET_SCHEDULER_NO_TASK;
- }
- peer->hello_delay_task
- = GNUNET_SCHEDULER_add_now (&schedule_next_hello,
- peer);
+ {
+ GNUNET_SCHEDULER_cancel (peer->hello_delay_task);
+ peer->hello_delay_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ peer->hello_delay_task
+ = GNUNET_SCHEDULER_add_now (&schedule_next_hello, peer);
return GNUNET_YES;
}
@@ -697,51 +663,49 @@
* @param peer peer identity this notification is about
* @param atsi performance data
*/
-static void
+static void
connect_notify (void *cls,
- const struct
- GNUNET_PeerIdentity * peer,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+ const struct
+ GNUNET_PeerIdentity *peer,
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
struct Peer *pos;
#if DEBUG_TOPOLOGY
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Core told us that we are connecting to `%s'\n",
- GNUNET_i2s (peer));
+ "Core told us that we are connecting to `%s'\n",
+ GNUNET_i2s (peer));
#endif
- if (0 == memcmp(&my_identity, peer, sizeof(struct GNUNET_PeerIdentity)))
+ if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity)))
return;
connection_count++;
GNUNET_STATISTICS_set (stats,
- gettext_noop ("# peers connected"),
- connection_count,
- GNUNET_NO);
+ gettext_noop ("# peers connected"),
+ connection_count, GNUNET_NO);
pos = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey);
- if (pos == NULL)
- {
- pos = make_peer (peer, NULL, GNUNET_NO);
- GNUNET_break (GNUNET_OK == is_connection_allowed (pos));
- }
+ if (pos == NULL)
+ {
+ pos = make_peer (peer, NULL, GNUNET_NO);
+ GNUNET_break (GNUNET_OK == is_connection_allowed (pos));
+ }
else
- {
- GNUNET_assert (GNUNET_NO == pos->is_connected);
- pos->greylisted_until.abs_value = 0; /* remove greylisting */
- }
+ {
+ GNUNET_assert (GNUNET_NO == pos->is_connected);
+ pos->greylisted_until.abs_value = 0; /* remove greylisting */
+ }
pos->is_connected = GNUNET_YES;
- pos->connect_attempts = 0; /* re-set back-off factor */
+ pos->connect_attempts = 0; /* re-set back-off factor */
if (pos->is_friend)
- {
- if ( (friend_count == minimum_friend_count - 1) &&
- (GNUNET_YES != friends_only) )
- whitelist_peers ();
- friend_count++;
- GNUNET_STATISTICS_set (stats,
- gettext_noop ("# friends connected"),
- friend_count,
- GNUNET_NO);
- }
+ {
+ if ((friend_count == minimum_friend_count - 1) &&
+ (GNUNET_YES != friends_only))
+ whitelist_peers ();
+ friend_count++;
+ GNUNET_STATISTICS_set (stats,
+ gettext_noop ("# friends connected"),
+ friend_count, GNUNET_NO);
+ }
reschedule_hellos (NULL, &peer->hashPubKey, pos);
}
@@ -755,9 +719,7 @@
* @return GNUNET_YES (continue to iterate)
*/
static int
-try_add_peers (void *cls,
- const GNUNET_HashCode *pid,
- void *value)
+try_add_peers (void *cls, const GNUNET_HashCode * pid, void *value)
{
struct Peer *pos = value;
@@ -774,14 +736,11 @@
* @param tc scheduler context
*/
static void
-add_peer_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+add_peer_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
add_task = GNUNET_SCHEDULER_NO_TASK;
- GNUNET_CONTAINER_multihashmap_iterate (peers,
- &try_add_peers,
- NULL);
+ GNUNET_CONTAINER_multihashmap_iterate (peers, &try_add_peers, NULL);
}
/**
@@ -790,64 +749,57 @@
* @param cls closure
* @param peer peer identity this notification is about
*/
-static void
-disconnect_notify (void *cls,
- const struct
- GNUNET_PeerIdentity * peer)
+static void
+disconnect_notify (void *cls, const struct GNUNET_PeerIdentity *peer)
{
struct Peer *pos;
- if (0 == memcmp(&my_identity, peer, sizeof(struct GNUNET_PeerIdentity)))
+ if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity)))
return;
#if DEBUG_TOPOLOGY
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Core told us that we disconnected from `%s'\n",
- GNUNET_i2s (peer));
-#endif
- pos = GNUNET_CONTAINER_multihashmap_get (peers,
- &peer->hashPubKey);
+ "Core told us that we disconnected from `%s'\n",
+ GNUNET_i2s (peer));
+#endif
+ pos = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey);
if (pos == NULL)
- {
- GNUNET_break (0);
- return;
- }
+ {
+ GNUNET_break (0);
+ return;
+ }
if (pos->is_connected != GNUNET_YES)
- {
- GNUNET_break (0);
- return;
- }
+ {
+ GNUNET_break (0);
+ return;
+ }
pos->is_connected = GNUNET_NO;
connection_count--;
if (NULL != pos->hello_req)
- {
- GNUNET_CORE_notify_transmit_ready_cancel (pos->hello_req);
- pos->hello_req = NULL;
- }
+ {
+ GNUNET_CORE_notify_transmit_ready_cancel (pos->hello_req);
+ pos->hello_req = NULL;
+ }
if (GNUNET_SCHEDULER_NO_TASK != pos->hello_delay_task)
- {
- GNUNET_SCHEDULER_cancel (pos->hello_delay_task);
- pos->hello_delay_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (pos->hello_delay_task);
+ pos->hello_delay_task = GNUNET_SCHEDULER_NO_TASK;
+ }
GNUNET_STATISTICS_set (stats,
- gettext_noop ("# peers connected"),
- connection_count,
- GNUNET_NO);
+ gettext_noop ("# peers connected"),
+ connection_count, GNUNET_NO);
if (pos->is_friend)
- {
- friend_count--;
- GNUNET_STATISTICS_set (stats,
- gettext_noop ("# friends connected"),
- friend_count,
- GNUNET_NO);
- }
- if ( ( (connection_count < target_connection_count) ||
- (friend_count < minimum_friend_count) ) &&
- (GNUNET_SCHEDULER_NO_TASK == add_task) )
+ {
+ friend_count--;
+ GNUNET_STATISTICS_set (stats,
+ gettext_noop ("# friends connected"),
+ friend_count, GNUNET_NO);
+ }
+ if (((connection_count < target_connection_count) ||
+ (friend_count < minimum_friend_count)) &&
+ (GNUNET_SCHEDULER_NO_TASK == add_task))
add_task = GNUNET_SCHEDULER_add_now (&add_peer_task, NULL);
- if ( (friend_count < minimum_friend_count) &&
- (blacklist == NULL) )
- blacklist = GNUNET_TRANSPORT_blacklist (cfg,
- &blacklist_check, NULL);
+ if ((friend_count < minimum_friend_count) && (blacklist == NULL))
+ blacklist = GNUNET_TRANSPORT_blacklist (cfg, &blacklist_check, NULL);
}
@@ -863,12 +815,12 @@
*/
static int
address_iterator (void *cls,
- const char *tname,
- struct GNUNET_TIME_Absolute expiration,
- const void *addr,
- uint16_t addrlen)
+ const char *tname,
+ struct GNUNET_TIME_Absolute expiration,
+ const void *addr, uint16_t addrlen)
{
int *flag = cls;
+
*flag = GNUNET_YES;
return GNUNET_SYSERR;
}
@@ -891,62 +843,51 @@
uint16_t size;
if (GNUNET_OK != GNUNET_HELLO_get_id (hello, &pid))
- {
- GNUNET_break (0);
- return;
- }
- if (0 == memcmp (&pid,
- &my_identity,
- sizeof (struct GNUNET_PeerIdentity)))
- return; /* that's me! */
+ {
+ GNUNET_break (0);
+ return;
+ }
+ if (0 == memcmp (&pid, &my_identity, sizeof (struct GNUNET_PeerIdentity)))
+ return; /* that's me! */
have_address = GNUNET_NO;
GNUNET_HELLO_iterate_addresses (hello,
- GNUNET_NO,
- &address_iterator,
- &have_address);
+ GNUNET_NO, &address_iterator, &have_address);
if (GNUNET_NO == have_address)
- return; /* no point in advertising this one... */
- peer = GNUNET_CONTAINER_multihashmap_get (peers,
- &pid.hashPubKey);
+ return; /* no point in advertising this one... */
+ peer = GNUNET_CONTAINER_multihashmap_get (peers, &pid.hashPubKey);
if (peer == NULL)
- {
- peer = make_peer (&pid, hello, GNUNET_NO);
- }
+ {
+ peer = make_peer (&pid, hello, GNUNET_NO);
+ }
else if (peer->hello != NULL)
- {
- dt = GNUNET_HELLO_equals (peer->hello,
- hello,
- GNUNET_TIME_absolute_get());
- if (dt.abs_value == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value)
- return; /* nothing new here */
- }
+ {
+ dt = GNUNET_HELLO_equals (peer->hello, hello, GNUNET_TIME_absolute_get ());
+ if (dt.abs_value == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value)
+ return; /* nothing new here */
+ }
#if DEBUG_TOPOLOGY
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Found `%s' from peer `%s' for advertising\n",
- "HELLO",
- GNUNET_i2s (&pid));
-#endif
+ "Found `%s' from peer `%s' for advertising\n",
+ "HELLO", GNUNET_i2s (&pid));
+#endif
if (peer->hello != NULL)
- {
- nh = GNUNET_HELLO_merge (peer->hello,
- hello);
- GNUNET_free (peer->hello);
- peer->hello = nh;
- }
+ {
+ nh = GNUNET_HELLO_merge (peer->hello, hello);
+ GNUNET_free (peer->hello);
+ peer->hello = nh;
+ }
else
- {
- size = GNUNET_HELLO_size (hello);
- peer->hello = GNUNET_malloc (size);
- memcpy (peer->hello, hello, size);
- }
+ {
+ size = GNUNET_HELLO_size (hello);
+ peer->hello = GNUNET_malloc (size);
+ memcpy (peer->hello, hello, size);
+ }
if (peer->filter != NULL)
GNUNET_CONTAINER_bloomfilter_free (peer->filter);
setup_filter (peer);
/* since we have a new HELLO to pick from, re-schedule all
- HELLO requests that are not bound by the HELLO send rate! */
- GNUNET_CONTAINER_multihashmap_iterate (peers,
- &reschedule_hellos,
- peer);
+ * HELLO requests that are not bound by the HELLO send rate! */
+ GNUNET_CONTAINER_multihashmap_iterate (peers, &reschedule_hellos, peer);
}
@@ -961,76 +902,70 @@
*/
static void
process_peer (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_HELLO_Message *hello,
- const char *err_msg)
+ const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_HELLO_Message *hello, const char *err_msg)
{
struct Peer *pos;
if (err_msg != NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Error in communication with PEERINFO service: %s\n"),
- err_msg);
- GNUNET_PEERINFO_notify_cancel (peerinfo_notify);
- peerinfo_notify = GNUNET_PEERINFO_notify (cfg, &process_peer,
- NULL);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ _("Error in communication with PEERINFO service: %s\n"),
+ err_msg);
+ GNUNET_PEERINFO_notify_cancel (peerinfo_notify);
+ peerinfo_notify = GNUNET_PEERINFO_notify (cfg, &process_peer, NULL);
+ return;
+ }
GNUNET_assert (peer != NULL);
- if (0 == memcmp (&my_identity,
- peer, sizeof (struct GNUNET_PeerIdentity)))
- return; /* that's me! */
+ if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity)))
+ return; /* that's me! */
if (hello == NULL)
+ {
+ /* free existing HELLO, if any */
+ pos = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey);
+ if (NULL != pos)
{
- /* free existing HELLO, if any */
- pos = GNUNET_CONTAINER_multihashmap_get (peers,
- &peer->hashPubKey);
- if (NULL != pos)
- {
- GNUNET_free_non_null (pos->hello);
- pos->hello = NULL;
- if (pos->filter != NULL)
- {
- GNUNET_CONTAINER_bloomfilter_free (pos->filter);
- pos->filter = NULL;
- }
- if ( (! pos->is_connected) &&
- (! pos->is_friend) &&
- (0 == GNUNET_TIME_absolute_get_remaining
(pos->greylisted_until).rel_value) )
- free_peer (NULL, &pos->pid.hashPubKey, pos);
- }
- return;
+ GNUNET_free_non_null (pos->hello);
+ pos->hello = NULL;
+ if (pos->filter != NULL)
+ {
+ GNUNET_CONTAINER_bloomfilter_free (pos->filter);
+ pos->filter = NULL;
+ }
+ if ((!pos->is_connected) &&
+ (!pos->is_friend) &&
+ (0 ==
+ GNUNET_TIME_absolute_get_remaining (pos->
+ greylisted_until).rel_value))
+ free_peer (NULL, &pos->pid.hashPubKey, pos);
}
+ return;
+ }
consider_for_advertising (hello);
- pos = GNUNET_CONTAINER_multihashmap_get (peers,
- &peer->hashPubKey);
+ pos = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey);
if (pos == NULL)
pos = make_peer (peer, hello, GNUNET_NO);
GNUNET_assert (NULL != pos);
if (GNUNET_YES == pos->is_connected)
- {
+ {
#if DEBUG_TOPOLOGY
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Already connected to peer `%s'\n",
- GNUNET_i2s (peer));
-#endif
- return;
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Already connected to peer `%s'\n", GNUNET_i2s (peer));
+#endif
+ return;
+ }
if (GNUNET_TIME_absolute_get_remaining (pos->greylisted_until).rel_value > 0)
- {
+ {
#if DEBUG_TOPOLOGY
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Already tried peer `%s' recently\n",
- GNUNET_i2s (peer));
-#endif
- return; /* peer still greylisted */
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Already tried peer `%s' recently\n", GNUNET_i2s (peer));
+#endif
+ return; /* peer still greylisted */
+ }
#if DEBUG_TOPOLOGY
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Considering connecting to peer `%s'\n",
- GNUNET_i2s (peer));
-#endif
+ "Considering connecting to peer `%s'\n", GNUNET_i2s (peer));
+#endif
attempt_connect (pos);
}
@@ -1046,29 +981,24 @@
*/
static void
core_init (void *cls,
- struct GNUNET_CORE_Handle * server,
- const struct GNUNET_PeerIdentity *
- my_id,
- const struct
- GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *
- publicKey)
+ struct GNUNET_CORE_Handle *server,
+ const struct GNUNET_PeerIdentity *my_id,
+ const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
{
if (server == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to connect to core service, can not manage
topology!\n"));
- GNUNET_SCHEDULER_shutdown ();
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _
+ ("Failed to connect to core service, can not manage
topology!\n"));
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
handle = server;
my_identity = *my_id;
#if DEBUG_TOPOLOGY
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "I am peer `%s'\n",
- GNUNET_i2s (my_id));
-#endif
- peerinfo_notify = GNUNET_PEERINFO_notify (cfg, &process_peer,
- NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "I am peer `%s'\n", GNUNET_i2s (my_id));
+#endif
+ peerinfo_notify = GNUNET_PEERINFO_notify (cfg, &process_peer, NULL);
}
@@ -1088,123 +1018,119 @@
struct Peer *fl;
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (cfg,
- "TOPOLOGY",
- "FRIENDS",
- &fn))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Option `%s' in section `%s' not specified!\n"),
- "FRIENDS",
- "TOPOLOGY");
- return;
- }
+ GNUNET_CONFIGURATION_get_value_filename (cfg, "TOPOLOGY", "FRIENDS",
&fn))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Option `%s' in section `%s' not specified!\n"),
+ "FRIENDS", "TOPOLOGY");
+ return;
+ }
if (GNUNET_OK != GNUNET_DISK_file_test (fn))
- GNUNET_DISK_fn_write (fn, NULL, 0,
- GNUNET_DISK_PERM_USER_READ
- | GNUNET_DISK_PERM_USER_WRITE);
+ GNUNET_DISK_fn_write (fn, NULL, 0,
+ GNUNET_DISK_PERM_USER_READ
+ | GNUNET_DISK_PERM_USER_WRITE);
if (0 != STAT (fn, &frstat))
- {
- if ((friends_only) || (minimum_friend_count > 0))
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Could not read friends list `%s'\n"), fn);
- GNUNET_free (fn);
- return;
- }
+ {
+ if ((friends_only) || (minimum_friend_count > 0))
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Could not read friends list `%s'\n"), fn);
+ GNUNET_free (fn);
+ return;
+ }
if (frstat.st_size == 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Friends file `%s' is empty.\n"),
- fn);
- GNUNET_free (fn);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Friends file `%s' is empty.\n"), fn);
+ GNUNET_free (fn);
+ return;
+ }
data = GNUNET_malloc_large (frstat.st_size);
if (data == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to read friends list from `%s': out of memory\n"),
fn);
- GNUNET_free (fn);
- return;
- }
- if (frstat.st_size !=
- GNUNET_DISK_fn_read (fn, data, frstat.st_size))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to read friends list from `%s'\n"), fn);
- GNUNET_free (fn);
- GNUNET_free (data);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to read friends list from `%s': out of memory\n"),
+ fn);
+ GNUNET_free (fn);
+ return;
+ }
+ if (frstat.st_size != GNUNET_DISK_fn_read (fn, data, frstat.st_size))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to read friends list from `%s'\n"), fn);
+ GNUNET_free (fn);
+ GNUNET_free (data);
+ return;
+ }
entries_found = 0;
pos = 0;
- while ((pos < frstat.st_size) && isspace ( (unsigned char) data[pos]))
+ while ((pos < frstat.st_size) && isspace ((unsigned char) data[pos]))
pos++;
while ((frstat.st_size >= sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)) &&
- (pos <= frstat.st_size - sizeof (struct
GNUNET_CRYPTO_HashAsciiEncoded)))
+ (pos <=
+ frstat.st_size - sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)))
+ {
+ memcpy (&enc, &data[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded));
+ if (!isspace
+ ((unsigned char)
+ enc.encoding[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1]))
{
- memcpy (&enc, &data[pos], sizeof (struct
GNUNET_CRYPTO_HashAsciiEncoded));
- if (!isspace ( (unsigned char) enc.encoding[sizeof (struct
GNUNET_CRYPTO_HashAsciiEncoded) - 1]))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Syntax error in topology specification at offset %llu,
skipping bytes.\n"),
- (unsigned long long) pos);
- pos++;
- while ((pos < frstat.st_size) && (!isspace ( (unsigned char)
data[pos])))
- pos++;
- continue;
- }
- enc.encoding[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0';
- if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string ((char *) &enc,
&pid.hashPubKey))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Syntax error in topology specification at offset %llu,
skipping bytes `%s'.\n"),
- (unsigned long long) pos,
- &enc);
- }
- else
- {
- if (0 != memcmp (&pid,
- &my_identity,
- sizeof (struct GNUNET_PeerIdentity)))
- {
- entries_found++;
- fl = make_peer (&pid,
- NULL,
- GNUNET_YES);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Found friend `%s' in configuration\n"),
- GNUNET_i2s (&fl->pid));
- }
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Found myself `%s' in friend list (useless,
ignored)\n"),
- GNUNET_i2s (&pid));
- }
- }
- pos = pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded);
- while ((pos < frstat.st_size) && isspace ( (unsigned char) data[pos]))
- pos++;
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Syntax error in topology specification at offset %llu,
skipping bytes.\n"),
+ (unsigned long long) pos);
+ pos++;
+ while ((pos < frstat.st_size) && (!isspace ((unsigned char) data[pos])))
+ pos++;
+ continue;
}
- GNUNET_free (data);
- GNUNET_free (fn);
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# friends in configuration"),
- entries_found,
- GNUNET_NO);
- if ( (minimum_friend_count > entries_found) &&
- (friends_only == GNUNET_NO) )
+ enc.encoding[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0';
+ if (GNUNET_OK !=
+ GNUNET_CRYPTO_hash_from_string ((char *) &enc, &pid.hashPubKey))
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Fewer friends specified than required by minimum friend
count. Will only connect to friends.\n"));
+ _
+ ("Syntax error in topology specification at offset %llu,
skipping bytes `%s'.\n"),
+ (unsigned long long) pos, &enc);
}
- if ( (minimum_friend_count > target_connection_count) &&
- (friends_only == GNUNET_NO) )
+ else
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("More friendly connections required than target total
number of connections.\n"));
+ if (0 != memcmp (&pid, &my_identity, sizeof (struct
GNUNET_PeerIdentity)))
+ {
+ entries_found++;
+ fl = make_peer (&pid, NULL, GNUNET_YES);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Found friend `%s' in configuration\n"),
+ GNUNET_i2s (&fl->pid));
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Found myself `%s' in friend list (useless, ignored)\n"),
+ GNUNET_i2s (&pid));
+ }
}
+ pos = pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded);
+ while ((pos < frstat.st_size) && isspace ((unsigned char) data[pos]))
+ pos++;
+ }
+ GNUNET_free (data);
+ GNUNET_free (fn);
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# friends in configuration"),
+ entries_found, GNUNET_NO);
+ if ((minimum_friend_count > entries_found) && (friends_only == GNUNET_NO))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Fewer friends specified than required by minimum friend
count. Will only connect to friends.\n"));
+ }
+ if ((minimum_friend_count > target_connection_count) &&
+ (friends_only == GNUNET_NO))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("More friendly connections required than target total number
of connections.\n"));
+ }
}
@@ -1222,51 +1148,43 @@
*/
static int
handle_encrypted_hello (void *cls,
- const struct GNUNET_PeerIdentity * other,
- const struct GNUNET_MessageHeader *
- message,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+ const struct GNUNET_PeerIdentity *other,
+ const struct GNUNET_MessageHeader *message,
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
struct Peer *peer;
struct GNUNET_PeerIdentity pid;
#if DEBUG_TOPOLOGY
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received encrypted `%s' from peer `%s'",
- "HELLO",
- GNUNET_i2s (other));
-#endif
+ "Received encrypted `%s' from peer `%s'",
+ "HELLO", GNUNET_i2s (other));
+#endif
if (GNUNET_OK !=
- GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message*) message,
- &pid))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
+ GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) message,
&pid))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# HELLO messages received"),
- 1,
- GNUNET_NO);
- peer = GNUNET_CONTAINER_multihashmap_get (peers,
- &pid.hashPubKey);
+ gettext_noop ("# HELLO messages received"),
+ 1, GNUNET_NO);
+ peer = GNUNET_CONTAINER_multihashmap_get (peers, &pid.hashPubKey);
if (peer == NULL)
- {
- if ( (GNUNET_YES == friends_only) ||
- (friend_count < minimum_friend_count) )
- return GNUNET_OK;
- }
+ {
+ if ((GNUNET_YES == friends_only) || (friend_count < minimum_friend_count))
+ return GNUNET_OK;
+ }
else
- {
- if ( (GNUNET_YES != peer->is_friend) &&
- (GNUNET_YES == friends_only) )
- return GNUNET_OK;
- if ( (GNUNET_YES != peer->is_friend) &&
- (friend_count < minimum_friend_count) )
- return GNUNET_OK;
- }
+ {
+ if ((GNUNET_YES != peer->is_friend) && (GNUNET_YES == friends_only))
+ return GNUNET_OK;
+ if ((GNUNET_YES != peer->is_friend) &&
+ (friend_count < minimum_friend_count))
+ return GNUNET_OK;
+ }
if (transport != NULL)
- GNUNET_TRANSPORT_offer_hello (transport,
- message, NULL, NULL);
+ GNUNET_TRANSPORT_offer_hello (transport, message, NULL, NULL);
return GNUNET_OK;
}
@@ -1280,50 +1198,41 @@
* @return number of bytes written to buf
*/
static size_t
-hello_advertising_ready (void *cls,
- size_t size,
- void *buf)
+hello_advertising_ready (void *cls, size_t size, void *buf)
{
struct Peer *pl = cls;
struct FindAdvHelloContext fah;
size_t want;
pl->hello_req = NULL;
- GNUNET_assert (GNUNET_YES == pl->is_connected);
+ GNUNET_assert (GNUNET_YES == pl->is_connected);
/* find applicable HELLOs */
fah.peer = pl;
fah.result = NULL;
fah.max_size = size;
fah.next_adv = GNUNET_TIME_UNIT_FOREVER_REL;
- GNUNET_CONTAINER_multihashmap_iterate (peers,
- &find_advertisable_hello,
- &fah);
+ GNUNET_CONTAINER_multihashmap_iterate (peers, &find_advertisable_hello,
&fah);
want = 0;
if (fah.result != NULL)
- {
- want = GNUNET_HELLO_size (fah.result->hello);
- GNUNET_assert (want <= size);
- memcpy (buf, fah.result->hello, want);
- GNUNET_CONTAINER_bloomfilter_add (fah.result->filter,
- &pl->pid.hashPubKey);
+ {
+ want = GNUNET_HELLO_size (fah.result->hello);
+ GNUNET_assert (want <= size);
+ memcpy (buf, fah.result->hello, want);
+ GNUNET_CONTAINER_bloomfilter_add (fah.result->filter, &pl->pid.hashPubKey);
#if DEBUG_TOPOLOGY
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending `%s' with %u bytes",
- "HELLO",
- (unsigned int) want);
-#endif
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# HELLO messages gossipped"),
- 1,
- GNUNET_NO);
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending `%s' with %u bytes", "HELLO", (unsigned int) want);
+#endif
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# HELLO messages gossipped"),
+ 1, GNUNET_NO);
+ }
if (pl->hello_delay_task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel(pl->hello_delay_task);
- pl->next_hello_allowed = GNUNET_TIME_relative_to_absolute
(HELLO_ADVERTISEMENT_MIN_FREQUENCY);
- pl->hello_delay_task
- = GNUNET_SCHEDULER_add_now (&schedule_next_hello,
- pl);
+ GNUNET_SCHEDULER_cancel (pl->hello_delay_task);
+ pl->next_hello_allowed =
+ GNUNET_TIME_relative_to_absolute (HELLO_ADVERTISEMENT_MIN_FREQUENCY);
+ pl->hello_delay_task = GNUNET_SCHEDULER_add_now (&schedule_next_hello, pl);
return want;
}
@@ -1336,36 +1245,33 @@
* @param tc scheduler context
*/
static void
-cleaning_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
if (NULL != peerinfo_notify)
- {
- GNUNET_PEERINFO_notify_cancel (peerinfo_notify);
- peerinfo_notify = NULL;
- }
+ {
+ GNUNET_PEERINFO_notify_cancel (peerinfo_notify);
+ peerinfo_notify = NULL;
+ }
if (GNUNET_SCHEDULER_NO_TASK != add_task)
- {
- GNUNET_SCHEDULER_cancel (add_task);
- add_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (add_task);
+ add_task = GNUNET_SCHEDULER_NO_TASK;
+ }
GNUNET_TRANSPORT_disconnect (transport);
transport = NULL;
- GNUNET_CONTAINER_multihashmap_iterate (peers,
- &free_peer,
- NULL);
+ GNUNET_CONTAINER_multihashmap_iterate (peers, &free_peer, NULL);
GNUNET_CONTAINER_multihashmap_destroy (peers);
if (handle != NULL)
- {
- GNUNET_CORE_disconnect (handle);
- handle = NULL;
- }
+ {
+ GNUNET_CORE_disconnect (handle);
+ handle = NULL;
+ }
whitelist_peers ();
if (stats != NULL)
- {
- GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
- stats = NULL;
- }
+ {
+ GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
+ stats = NULL;
+ }
}
@@ -1380,88 +1286,72 @@
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle * c)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
{
- static struct GNUNET_CORE_MessageHandler handlers[] =
- {
- { &handle_encrypted_hello, GNUNET_MESSAGE_TYPE_HELLO, 0},
- { NULL, 0, 0 }
- };
+ static struct GNUNET_CORE_MessageHandler handlers[] = {
+ {&handle_encrypted_hello, GNUNET_MESSAGE_TYPE_HELLO, 0},
+ {NULL, 0, 0}
+ };
unsigned long long opt;
cfg = c;
stats = GNUNET_STATISTICS_create ("topology", cfg);
autoconnect = GNUNET_CONFIGURATION_get_value_yesno (cfg,
- "TOPOLOGY",
- "AUTOCONNECT");
+ "TOPOLOGY",
+ "AUTOCONNECT");
friends_only = GNUNET_CONFIGURATION_get_value_yesno (cfg,
- "TOPOLOGY",
- "FRIENDS-ONLY");
+ "TOPOLOGY",
+ "FRIENDS-ONLY");
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_number (cfg,
- "TOPOLOGY",
- "MINIMUM-FRIENDS",
- &opt))
+ "TOPOLOGY",
+ "MINIMUM-FRIENDS", &opt))
opt = 0;
minimum_friend_count = (unsigned int) opt;
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_number (cfg,
- "TOPOLOGY",
- "TARGET-CONNECTION-COUNT",
- &opt))
+ "TOPOLOGY",
+ "TARGET-CONNECTION-COUNT", &opt))
opt = 16;
target_connection_count = (unsigned int) opt;
peers = GNUNET_CONTAINER_multihashmap_create (target_connection_count * 2);
- if ( (friends_only == GNUNET_YES) ||
- (minimum_friend_count > 0) )
+ if ((friends_only == GNUNET_YES) || (minimum_friend_count > 0))
read_friends_file (cfg);
#if DEBUG_TOPOLOGY
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Topology would like %u connections with at least %u friends
(%s)\n",
- target_connection_count,
- minimum_friend_count,
- autoconnect ? "autoconnect enabled" : "autoconnect disabled");
-#endif
- if ( (friend_count < minimum_friend_count) &&
- (blacklist == NULL) )
- blacklist = GNUNET_TRANSPORT_blacklist (cfg,
- &blacklist_check, NULL);
- transport = GNUNET_TRANSPORT_connect (cfg,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL);
+ "Topology would like %u connections with at least %u friends
(%s)\n",
+ target_connection_count,
+ minimum_friend_count,
+ autoconnect ? "autoconnect enabled" : "autoconnect disabled");
+#endif
+ if ((friend_count < minimum_friend_count) && (blacklist == NULL))
+ blacklist = GNUNET_TRANSPORT_blacklist (cfg, &blacklist_check, NULL);
+ transport = GNUNET_TRANSPORT_connect (cfg, NULL, NULL, NULL, NULL, NULL);
handle = GNUNET_CORE_connect (cfg,
- 1,
- NULL,
- &core_init,
- &connect_notify,
- &disconnect_notify,
- NULL,
- NULL, GNUNET_NO,
- NULL, GNUNET_NO,
- handlers);
+ 1,
+ NULL,
+ &core_init,
+ &connect_notify,
+ &disconnect_notify,
+ NULL,
+ NULL, GNUNET_NO, NULL, GNUNET_NO, handlers);
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
&cleaning_task, NULL);
if (NULL == transport)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to connect to `%s' service.\n"),
- "transport");
- GNUNET_SCHEDULER_shutdown ();
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to connect to `%s' service.\n"), "transport");
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
if (NULL == handle)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to connect to `%s' service.\n"),
- "core");
- GNUNET_SCHEDULER_shutdown ();
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to connect to `%s' service.\n"), "core");
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
}
@@ -1484,9 +1374,9 @@
GNUNET_PROGRAM_run (argc,
argv,
"gnunet-daemon-topology",
- _("GNUnet topology control (maintaining P2P mesh
and F2F constraints)"),
- options,
- &run, NULL)) ? 0 : 1;
+ _
+ ("GNUnet topology control (maintaining P2P mesh
and F2F constraints)"),
+ options, &run, NULL)) ? 0 : 1;
return ret;
}
Modified: gnunet/src/topology/test_gnunet_daemon_topology.c
===================================================================
--- gnunet/src/topology/test_gnunet_daemon_topology.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/topology/test_gnunet_daemon_topology.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -51,119 +51,105 @@
/**
* Check whether peers successfully shut down.
*/
-static void
-shutdown_callback (void *cls,
- const char *emsg)
+static void
+shutdown_callback (void *cls, const char *emsg)
{
if (emsg != NULL)
- {
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Shutdown of peers failed!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n");
#endif
- if (ok == 0)
- ok = 666;
- }
+ if (ok == 0)
+ ok = 666;
+ }
else
- {
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "All peers successfully shut down!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers successfully shut
down!\n");
#endif
- }
+ }
}
static void
-clean_up_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+clean_up_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
- ok = 0;
+ ok = 0;
}
-static void
-notify_connect_complete(void *cls,
- const struct GNUNET_PeerIdentity *first,
- const struct GNUNET_PeerIdentity *second,
- unsigned int distance,
- const struct GNUNET_CONFIGURATION_Handle *first_cfg,
- const struct GNUNET_CONFIGURATION_Handle *second_cfg,
- struct GNUNET_TESTING_Daemon *first_daemon,
- struct GNUNET_TESTING_Daemon *second_daemon,
- const char *emsg)
+static void
+notify_connect_complete (void *cls,
+ const struct GNUNET_PeerIdentity *first,
+ const struct GNUNET_PeerIdentity *second,
+ unsigned int distance,
+ const struct GNUNET_CONFIGURATION_Handle *first_cfg,
+ const struct GNUNET_CONFIGURATION_Handle *second_cfg,
+ struct GNUNET_TESTING_Daemon *first_daemon,
+ struct GNUNET_TESTING_Daemon *second_daemon,
+ const char *emsg)
{
if (NULL != emsg)
- {
- fprintf (stderr,
- "Failed to connect two peers: %s\n",
- emsg);
- GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
- GNUNET_assert (0);
- return;
- }
+ {
+ fprintf (stderr, "Failed to connect two peers: %s\n", emsg);
+ GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
+ GNUNET_assert (0);
+ return;
+ }
connect_left--;
if (connect_left == 0)
- {
- /* FIXME: check that topology adds a few more links
- in addition to those that were seeded */
- GNUNET_SCHEDULER_add_now (&clean_up_task,
- NULL);
- }
+ {
+ /* FIXME: check that topology adds a few more links
+ * in addition to those that were seeded */
+ GNUNET_SCHEDULER_add_now (&clean_up_task, NULL);
+ }
}
-static
-void my_cb(void *cls,
- const struct GNUNET_PeerIdentity *id,
- const struct GNUNET_CONFIGURATION_Handle *cfg,
- struct GNUNET_TESTING_Daemon *d,
- const char *emsg)
+static void
+my_cb (void *cls,
+ const struct GNUNET_PeerIdentity *id,
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ struct GNUNET_TESTING_Daemon *d, const char *emsg)
{
GNUNET_assert (id != NULL);
- peers_left--;
+ peers_left--;
if (first == NULL)
- {
- connect_left = NUM_PEERS;
- first = d;
- last = d;
- return;
- }
+ {
+ connect_left = NUM_PEERS;
+ first = d;
+ last = d;
+ return;
+ }
GNUNET_TESTING_daemons_connect (last, d, TIMEOUT, CONNECT_ATTEMPTS,
- GNUNET_YES,
- ¬ify_connect_complete,
- NULL);
+ GNUNET_YES, ¬ify_connect_complete, NULL);
if (peers_left == 0)
- {
- /* close circle */
- GNUNET_TESTING_daemons_connect (d, first, TIMEOUT, CONNECT_ATTEMPTS,
- GNUNET_YES,
- ¬ify_connect_complete,
- NULL);
- }
+ {
+ /* close circle */
+ GNUNET_TESTING_daemons_connect (d, first, TIMEOUT, CONNECT_ATTEMPTS,
+ GNUNET_YES, ¬ify_connect_complete,
NULL);
+ }
}
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
ok = 1;
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Starting daemons.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemons.\n");
#endif
peers_left = NUM_PEERS;
pg = GNUNET_TESTING_daemons_start (cfg,
- peers_left,
- peers_left,
- peers_left,
- TIMEOUT,
- NULL, NULL,
- &my_cb, NULL, NULL, NULL, NULL);
+ peers_left,
+ peers_left,
+ peers_left,
+ TIMEOUT,
+ NULL, NULL,
+ &my_cb, NULL, NULL, NULL, NULL);
GNUNET_assert (pg != NULL);
}
@@ -171,7 +157,7 @@
static int
check ()
{
- char *const argv[] = {
+ char *const argv[] = {
"test-gnunet-daemon-topology",
"-c",
"test_gnunet_daemon_topology_data.conf",
Modified: gnunet/src/transport/gnunet-service-transport-new.c
===================================================================
--- gnunet/src/transport/gnunet-service-transport-new.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/transport/gnunet-service-transport-new.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -86,17 +86,16 @@
*/
static void
transmit_our_hello (void *cls,
- const struct GNUNET_PeerIdentity *target,
- const struct GNUNET_TRANSPORT_ATS_Information *ats,
- uint32_t ats_count)
+ const struct GNUNET_PeerIdentity *target,
+ const struct GNUNET_TRANSPORT_ATS_Information *ats,
+ uint32_t ats_count)
{
const struct GNUNET_MessageHeader *hello = cls;
GST_neighbours_send (target,
- (const char*) hello,
- ntohs (hello->size),
- GST_HELLO_ADDRESS_EXPIRATION,
- NULL, NULL);
+ (const char *) hello,
+ ntohs (hello->size),
+ GST_HELLO_ADDRESS_EXPIRATION, NULL, NULL);
}
@@ -107,12 +106,10 @@
* @param hello new HELLO
*/
static void
-process_hello_update (void *cls,
- const struct GNUNET_MessageHeader *hello)
+process_hello_update (void *cls, const struct GNUNET_MessageHeader *hello)
{
GST_clients_broadcast (hello, GNUNET_NO);
- GST_neighbours_iterate (&transmit_our_hello,
- (void*) hello);
+ GST_neighbours_iterate (&transmit_our_hello, (void *) hello);
}
@@ -127,11 +124,10 @@
*/
static void
try_connect_if_allowed (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- int result)
+ const struct GNUNET_PeerIdentity *peer, int result)
{
if (GNUNET_OK != result)
- return; /* not allowed */
+ return; /* not allowed */
GST_neighbours_try_connect (peer);
}
@@ -159,14 +155,14 @@
* @return how long the plugin should wait until receiving more data
* (plugins that do not support this, can ignore the return value)
*/
-static struct GNUNET_TIME_Relative
+static struct GNUNET_TIME_Relative
plugin_env_receive_callback (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_MessageHeader *message,
- const struct GNUNET_TRANSPORT_ATS_Information
*ats, uint32_t ats_count,
- struct Session *session,
- const char *sender_address,
- uint16_t sender_address_len)
+ const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_MessageHeader *message,
+ const struct GNUNET_TRANSPORT_ATS_Information
*ats,
+ uint32_t ats_count, struct Session *session,
+ const char *sender_address,
+ uint16_t sender_address_len)
{
const char *plugin_name = cls;
int do_forward;
@@ -176,80 +172,72 @@
ret = GNUNET_TIME_UNIT_ZERO;
if (NULL != message)
+ {
+ type = ntohs (message->type);
+ switch (type)
{
- type = ntohs (message->type);
- switch (type)
- {
- case GNUNET_MESSAGE_TYPE_HELLO:
- GST_validation_handle_hello (message);
- break;
- case GNUNET_MESSAGE_TYPE_TRANSPORT_PING:
+ case GNUNET_MESSAGE_TYPE_HELLO:
+ GST_validation_handle_hello (message);
+ break;
+ 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)
- : "<inbound>");
+ 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) : "<inbound>");
#endif
- GST_validation_handle_ping (peer,
- message,
- plugin_name,
- session,
- sender_address, sender_address_len);
- break;
- case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG:
+ GST_validation_handle_ping (peer,
+ message,
+ plugin_name,
+ session, 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)
- : "<inbound>");
+ 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) : "<inbound>");
#endif
- GST_validation_handle_pong (peer,
- message);
- break;
- case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT:
- (void) GST_blacklist_test_allowed (peer,
- NULL,
- &try_connect_if_allowed, NULL);
- /* TODO: if 'session != NULL', maybe notify ATS that this is now the
preferred
- way to communicate with this peer (other peer switched transport)
*/
- break;
- case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT:
- /* TODO: do some validation to prevent an attacker from sending
- a fake disconnect message... */
- GST_neighbours_force_disconnect (peer);
- break;
- case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE:
- GST_neighbours_keepalive (peer);
- break;
- default:
- /* should be payload */
- do_forward = GNUNET_SYSERR;
- ret = GST_neighbours_calculate_receive_delay (peer,
- (message == NULL)
- ? 0
- : ntohs (message->size),
- &do_forward);
- if (do_forward == GNUNET_YES)
- GST_clients_broadcast (message, GNUNET_YES);
- break;
- }
+ GST_validation_handle_pong (peer, message);
+ break;
+ case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT:
+ (void) GST_blacklist_test_allowed (peer,
+ NULL, &try_connect_if_allowed, NULL);
+ /* TODO: if 'session != NULL', maybe notify ATS that this is now the
preferred
+ * way to communicate with this peer (other peer switched transport) */
+ break;
+ case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT:
+ /* TODO: do some validation to prevent an attacker from sending
+ * a fake disconnect message... */
+ GST_neighbours_force_disconnect (peer);
+ break;
+ case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE:
+ GST_neighbours_keepalive (peer);
+ break;
+ default:
+ /* should be payload */
+ do_forward = GNUNET_SYSERR;
+ ret = GST_neighbours_calculate_receive_delay (peer,
+ (message == NULL)
+ ? 0
+ : ntohs (message->size),
+ &do_forward);
+ if (do_forward == GNUNET_YES)
+ GST_clients_broadcast (message, GNUNET_YES);
+ break;
}
- GNUNET_ATS_address_update (GST_ats,
- peer,
- GNUNET_TIME_absolute_get (), /* valid at least
until right now... */
- plugin_name,
- session,
- sender_address,
- sender_address_len,
- ats, ats_count);
+ }
+ GNUNET_ATS_address_update (GST_ats, peer, GNUNET_TIME_absolute_get (),
/* valid at least until right now... */
+ plugin_name,
+ session,
+ sender_address,
+ sender_address_len, ats, ats_count);
return ret;
}
@@ -266,18 +254,14 @@
* the specific address format depends on the transport
* @param addrlen length of the address
*/
-static void
+static void
plugin_env_address_change_notification (void *cls,
- int add_remove,
- const void *addr,
- size_t addrlen)
+ int add_remove,
+ const void *addr, size_t addrlen)
{
const char *plugin_name = cls;
- GST_hello_modify_addresses (add_remove,
- plugin_name,
- addr,
- addrlen);
+ GST_hello_modify_addresses (add_remove, plugin_name, addr, addrlen);
}
@@ -296,11 +280,10 @@
*/
static void
plugin_env_session_end (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- struct Session *session)
+ const struct GNUNET_PeerIdentity *peer,
+ struct Session *session)
{
- GST_neighbours_session_terminated (peer,
- session);
+ GST_neighbours_session_terminated (peer, session);
}
@@ -319,23 +302,20 @@
* @param plugin_addr_len number of bytes in addr
* @param bandwidth assigned outbound bandwidth for the connection
*/
-static void
+static void
ats_request_address_change (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- const char *plugin_name,
- struct Session *session,
- const void *plugin_addr,
- size_t plugin_addr_len,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth)
+ const struct GNUNET_PeerIdentity *peer,
+ const char *plugin_name,
+ struct Session *session,
+ const void *plugin_addr,
+ size_t plugin_addr_len,
+ struct GNUNET_BANDWIDTH_Value32NBO bandwidth)
{
- GST_neighbours_switch_to_address (peer,
- plugin_name,
- plugin_addr,
- plugin_addr_len,
- session,
- NULL, 0);
- GST_neighbours_set_incoming_quota (peer,
- bandwidth);
+ GST_neighbours_switch_to_address (peer,
+ plugin_name,
+ plugin_addr,
+ plugin_addr_len, session, NULL, 0);
+ GST_neighbours_set_incoming_quota (peer, bandwidth);
}
@@ -350,23 +330,24 @@
*/
static void
neighbours_connect_notification (void *cls,
- const struct GNUNET_PeerIdentity * peer,
- const struct GNUNET_TRANSPORT_ATS_Information
*ats,
- uint32_t ats_count)
+ const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_TRANSPORT_ATS_Information
+ *ats, uint32_t ats_count)
{
- char buf[sizeof(struct ConnectInfoMessage) + ats_count * sizeof (struct
GNUNET_TRANSPORT_ATS_Information)];
- struct ConnectInfoMessage *connect_msg = (struct ConnectInfoMessage*) buf;
+ char buf[sizeof (struct ConnectInfoMessage) +
+ ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)];
+ struct ConnectInfoMessage *connect_msg = (struct ConnectInfoMessage *) buf;
struct GNUNET_TRANSPORT_ATS_Information *atsm = &connect_msg->ats;
connect_msg->header.size = htons (sizeof (buf));
connect_msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
connect_msg->ats_count = htonl (ats_count);
connect_msg->id = *peer;
- memcpy (&connect_msg->ats, ats, ats_count * sizeof (struct
GNUNET_TRANSPORT_ATS_Information));
+ memcpy (&connect_msg->ats, ats,
+ ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
atsm[ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
atsm[ats_count].value = htonl (0);
- GST_clients_broadcast (&connect_msg->header,
- GNUNET_NO);
+ GST_clients_broadcast (&connect_msg->header, GNUNET_NO);
}
@@ -379,7 +360,7 @@
*/
static void
neighbours_disconnect_notification (void *cls,
- const struct GNUNET_PeerIdentity *peer)
+ const struct GNUNET_PeerIdentity *peer)
{
struct DisconnectInfoMessage disconnect_msg;
@@ -387,8 +368,7 @@
disconnect_msg.header.type = htons
(GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT);
disconnect_msg.reserved = htonl (0);
disconnect_msg.peer = *peer;
- GST_clients_broadcast (&disconnect_msg.header,
- GNUNET_NO);
+ GST_clients_broadcast (&disconnect_msg.header, GNUNET_NO);
}
@@ -400,32 +380,32 @@
* @param tc task context (unused)
*/
static void
-shutdown_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
+shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
GST_validation_stop ();
GST_neighbours_stop ();
- GNUNET_ATS_shutdown (GST_ats); GST_ats = NULL;
+ GNUNET_ATS_shutdown (GST_ats);
+ GST_ats = NULL;
GST_clients_stop ();
GST_blacklist_stop ();
GST_plugins_unload ();
GST_hello_stop ();
if (GST_peerinfo != NULL)
- {
- GNUNET_PEERINFO_disconnect (GST_peerinfo);
- GST_peerinfo = NULL;
- }
+ {
+ GNUNET_PEERINFO_disconnect (GST_peerinfo);
+ GST_peerinfo = NULL;
+ }
if (GST_stats != NULL)
- {
- GNUNET_STATISTICS_destroy (GST_stats, GNUNET_NO);
- GST_stats = NULL;
- }
+ {
+ GNUNET_STATISTICS_destroy (GST_stats, GNUNET_NO);
+ GST_stats = NULL;
+ }
if (GST_my_private_key != NULL)
- {
- GNUNET_CRYPTO_rsa_key_free (GST_my_private_key);
- GST_my_private_key = NULL;
- }
+ {
+ GNUNET_CRYPTO_rsa_key_free (GST_my_private_key);
+ GST_my_private_key = NULL;
+ }
}
@@ -447,24 +427,23 @@
GST_cfg = c;
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_filename (c,
- "GNUNETD",
- "HOSTKEY", &keyfile))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _
- ("Transport service is lacking key configuration settings.
Exiting.\n"));
- GNUNET_SCHEDULER_shutdown ();
- return;
- }
+ "GNUNETD", "HOSTKEY", &keyfile))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _
+ ("Transport service is lacking key configuration settings.
Exiting.\n"));
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
GST_my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
GNUNET_free (keyfile);
if (GST_my_private_key == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Transport service could not access hostkey.
Exiting.\n"));
- GNUNET_SCHEDULER_shutdown ();
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Transport service could not access hostkey. Exiting.\n"));
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
GST_stats = GNUNET_STATISTICS_create ("transport", c);
GST_peerinfo = GNUNET_PEERINFO_connect (c);
GNUNET_CRYPTO_rsa_key_get_public (GST_my_private_key, &GST_my_public_key);
@@ -473,25 +452,23 @@
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
&shutdown_task, NULL);
if (GST_peerinfo == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Could not access PEERINFO service. Exiting.\n"));
- GNUNET_SCHEDULER_shutdown ();
- return;
- }
-
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Could not access PEERINFO service. Exiting.\n"));
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+
/* start subsystems */
GST_hello_start (&process_hello_update, NULL);
GST_blacklist_start (server);
GST_plugins_load (&plugin_env_receive_callback,
- &plugin_env_address_change_notification,
- &plugin_env_session_end);
- GST_ats = GNUNET_ATS_init (GST_cfg,
- &ats_request_address_change,
- NULL);
+ &plugin_env_address_change_notification,
+ &plugin_env_session_end);
+ GST_ats = GNUNET_ATS_init (GST_cfg, &ats_request_address_change, NULL);
GST_neighbours_start (NULL,
- &neighbours_connect_notification,
- &neighbours_disconnect_notification);
+ &neighbours_connect_notification,
+ &neighbours_disconnect_notification);
GST_clients_start (server);
GST_validation_start ();
}
@@ -511,8 +488,7 @@
GNUNET_SERVICE_run (argc,
argv,
"transport",
- GNUNET_SERVICE_OPTION_NONE,
- &run, NULL)) ? 0 : 1;
+ GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
}
/* end of file gnunet-service-transport-new.c */
Modified: gnunet/src/transport/gnunet-service-transport.c
===================================================================
--- gnunet/src/transport/gnunet-service-transport.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/transport/gnunet-service-transport.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -178,9 +178,9 @@
*/
struct Session *session;
- struct ATS_ressource_entry * ressources;
+ struct ATS_ressource_entry *ressources;
- struct ATS_quality_entry * quality;
+ struct ATS_quality_entry *quality;
/**
* What was the last latency observed for this address, plugin and peer?
@@ -325,7 +325,7 @@
*/
int rebuild;
- struct ATS_plugin * rc;
+ struct ATS_plugin *rc;
/**
* Hashmap of blacklisted peers for this particular transport.
@@ -735,7 +735,7 @@
/**
* Entry in map of all HELLOs awaiting validation.
*/
-struct ValidationEntry
+struct ValidationEntry
{
/**
@@ -929,10 +929,12 @@
* Time of last ats execution
*/
struct GNUNET_TIME_Absolute last_ats_execution;
+
/**
* Minimum interval between two ATS executions
*/
struct GNUNET_TIME_Relative ats_minimum_interval;
+
/**
* Regular interval when ATS execution is triggered
*/
@@ -961,8 +963,8 @@
*/
static void try_transmission_to_peer (struct NeighbourMapEntry *n);
-struct ForeignAddressList * get_preferred_ats_address (
- struct NeighbourMapEntry *n);
+struct ForeignAddressList *get_preferred_ats_address (struct NeighbourMapEntry
+ *n);
/**
* Find an entry in the neighbour list for a particular peer.
@@ -975,11 +977,14 @@
return GNUNET_CONTAINER_multihashmap_get (neighbours, &key->hashPubKey);
}
-static int update_addr_value (struct ForeignAddressList *fal, uint32_t value ,
int ats_index)
+static int
+update_addr_value (struct ForeignAddressList *fal, uint32_t value,
+ int ats_index)
{
int c;
int set = GNUNET_NO;
- for (c=0; c<available_quality_metrics; c++)
+
+ for (c = 0; c < available_quality_metrics; c++)
{
if (ats_index == qm[c].atis_index)
{
@@ -994,7 +999,7 @@
}
if (set == GNUNET_NO)
{
- for (c=0; c<available_ressources; c++)
+ for (c = 0; c < available_ressources; c++)
{
if (ats_index == ressources[c].atis_index)
{
@@ -1010,16 +1015,19 @@
}
static int
-update_addr_ats (struct ForeignAddressList *fal,
- const struct GNUNET_TRANSPORT_ATS_Information *ats_data,
- int ats_count)
+update_addr_ats (struct ForeignAddressList *fal,
+ const struct GNUNET_TRANSPORT_ATS_Information *ats_data,
+ int ats_count)
{
int c1, set;
+
set = GNUNET_NO;
- for (c1=0; c1<ats_count; c1++)
- {
- set = update_addr_value(fal, ntohl(ats_data[c1].value),
ntohl(ats_data[c1].type));
- }
+ for (c1 = 0; c1 < ats_count; c1++)
+ {
+ set =
+ update_addr_value (fal, ntohl (ats_data[c1].value),
+ ntohl (ats_data[c1].type));
+ }
return set;
}
@@ -1032,6 +1040,7 @@
find_transport (const char *short_name)
{
struct TransportPlugin *head = plugins;
+
while ((head != NULL) && (0 != strcmp (short_name, head->short_name)))
head = head->next;
return head;
@@ -1046,49 +1055,51 @@
* @return GNUNET_YES if the peer is blacklisted, GNUNET_NO if not
*/
static int
-is_blacklisted (const struct GNUNET_PeerIdentity *peer, struct TransportPlugin
*plugin)
+is_blacklisted (const struct GNUNET_PeerIdentity *peer,
+ struct TransportPlugin *plugin)
{
if (plugin->blacklist != NULL)
+ {
+ if (GNUNET_CONTAINER_multihashmap_contains
+ (plugin->blacklist, &peer->hashPubKey) == GNUNET_YES)
{
- if (GNUNET_CONTAINER_multihashmap_contains (plugin->blacklist,
&peer->hashPubKey) == GNUNET_YES)
- {
#if DEBUG_BLACKLIST
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peer `%s:%s' is blacklisted!\n",
- plugin->short_name, GNUNET_i2s (peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Peer `%s:%s' is blacklisted!\n",
+ plugin->short_name, GNUNET_i2s (peer));
#endif
- if (stats != NULL)
- GNUNET_STATISTICS_update (stats, "# blacklisted peers refused", 1,
GNUNET_NO);
- return GNUNET_YES;
- }
+ if (stats != NULL)
+ GNUNET_STATISTICS_update (stats, "# blacklisted peers refused", 1,
+ GNUNET_NO);
+ return GNUNET_YES;
}
+ }
return GNUNET_NO;
}
static void
-add_peer_to_blacklist (struct GNUNET_PeerIdentity *peer,
- char *transport_name)
+add_peer_to_blacklist (struct GNUNET_PeerIdentity *peer, char *transport_name)
{
struct TransportPlugin *plugin;
- plugin = find_transport(transport_name);
- if (plugin == NULL) /* Nothing to do */
+ plugin = find_transport (transport_name);
+ if (plugin == NULL) /* Nothing to do */
return;
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Adding peer `%s' with plugin `%s' to blacklist\n",
- GNUNET_i2s (peer),
- transport_name);
+ "Adding peer `%s' with plugin `%s' to blacklist\n",
+ GNUNET_i2s (peer), transport_name);
#endif
if (plugin->blacklist == NULL)
- plugin->blacklist =
GNUNET_CONTAINER_multihashmap_create(TRANSPORT_BLACKLIST_HT_SIZE);
- GNUNET_assert(plugin->blacklist != NULL);
- GNUNET_CONTAINER_multihashmap_put(plugin->blacklist, &peer->hashPubKey,
- NULL,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
+ plugin->blacklist =
+ GNUNET_CONTAINER_multihashmap_create (TRANSPORT_BLACKLIST_HT_SIZE);
+ GNUNET_assert (plugin->blacklist != NULL);
+ GNUNET_CONTAINER_multihashmap_put (plugin->blacklist, &peer->hashPubKey,
+ NULL,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
}
@@ -1115,145 +1126,148 @@
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_filename (cfg,
"TRANSPORT",
- "BLACKLIST_FILE",
- &fn))
- {
+ "BLACKLIST_FILE", &fn))
+ {
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Option `%s' in section `%s' not specified!\n",
- "BLACKLIST_FILE",
- "TRANSPORT");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Option `%s' in section `%s' not specified!\n",
+ "BLACKLIST_FILE", "TRANSPORT");
#endif
- return;
- }
+ return;
+ }
if (GNUNET_OK != GNUNET_DISK_file_test (fn))
GNUNET_DISK_fn_write (fn, NULL, 0, GNUNET_DISK_PERM_USER_READ
- | GNUNET_DISK_PERM_USER_WRITE);
+ | GNUNET_DISK_PERM_USER_WRITE);
if (0 != STAT (fn, &frstat))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Could not read blacklist file `%s'\n"), fn);
- GNUNET_free (fn);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Could not read blacklist file `%s'\n"), fn);
+ GNUNET_free (fn);
+ return;
+ }
if (frstat.st_size == 0)
- {
+ {
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Blacklist file `%s' is empty.\n"),
- fn);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ _("Blacklist file `%s' is empty.\n"), fn);
#endif
- GNUNET_free (fn);
- return;
- }
+ GNUNET_free (fn);
+ return;
+ }
/* FIXME: use mmap */
data = GNUNET_malloc_large (frstat.st_size);
- GNUNET_assert(data != NULL);
- if (frstat.st_size !=
- GNUNET_DISK_fn_read (fn, data, frstat.st_size))
+ GNUNET_assert (data != NULL);
+ if (frstat.st_size != GNUNET_DISK_fn_read (fn, data, frstat.st_size))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to read blacklist from `%s'\n"), fn);
+ GNUNET_free (fn);
+ GNUNET_free (data);
+ return;
+ }
+ entries_found = 0;
+ pos = 0;
+ while ((pos < frstat.st_size) && isspace ((unsigned char) data[pos]))
+ pos++;
+ while ((frstat.st_size >= sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)) &&
+ (pos <=
+ frstat.st_size - sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)))
+ {
+ colon_pos = pos;
+ while ((colon_pos < frstat.st_size) && (data[colon_pos] != ':') &&
+ !isspace ((unsigned char) data[colon_pos]))
+ colon_pos++;
+
+ if (colon_pos >= frstat.st_size)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to read blacklist from `%s'\n"), fn);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Syntax error in blacklist file at offset %llu, giving
up!\n"),
+ (unsigned long long) colon_pos);
GNUNET_free (fn);
GNUNET_free (data);
return;
}
- entries_found = 0;
- pos = 0;
- while ((pos < frstat.st_size) && isspace ( (unsigned char) data[pos]))
- pos++;
- while ((frstat.st_size >= sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)) &&
- (pos <= frstat.st_size - sizeof (struct
GNUNET_CRYPTO_HashAsciiEncoded)))
+
+ if (isspace ((unsigned char) data[colon_pos]))
{
- colon_pos = pos;
- while ((colon_pos < frstat.st_size) && (data[colon_pos] != ':') &&
!isspace ( (unsigned char) data[colon_pos]))
- colon_pos++;
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Syntax error in blacklist file at offset %llu, skipping
bytes.\n"),
+ (unsigned long long) colon_pos);
+ pos = colon_pos;
+ while ((pos < frstat.st_size) && isspace ((unsigned char) data[pos]))
+ pos++;
+ continue;
+ }
+ tsize = colon_pos - pos;
+ if ((pos >= frstat.st_size) || (pos + tsize >= frstat.st_size) ||
+ (tsize == 0))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Syntax error in blacklist file at offset %llu, giving
up!\n"),
+ (unsigned long long) colon_pos);
+ GNUNET_free (fn);
+ GNUNET_free (data);
+ return;
+ }
- if (colon_pos >= frstat.st_size)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Syntax error in blacklist file at offset %llu, giving
up!\n"),
- (unsigned long long) colon_pos);
- GNUNET_free (fn);
- GNUNET_free (data);
- return;
- }
+ if (tsize < 1)
+ continue;
- if (isspace( (unsigned char) data[colon_pos]))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Syntax error in blacklist file at offset %llu, skipping
bytes.\n"),
- (unsigned long long) colon_pos);
- pos = colon_pos;
- while ((pos < frstat.st_size) && isspace ( (unsigned char) data[pos]))
- pos++;
- continue;
- }
- tsize = colon_pos - pos;
- if ((pos >= frstat.st_size) || (pos + tsize >= frstat.st_size) || (tsize
== 0))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Syntax error in blacklist file at offset %llu, giving
up!\n"),
- (unsigned long long) colon_pos);
- GNUNET_free (fn);
- GNUNET_free (data);
- return;
- }
-
- if (tsize < 1)
- continue;
-
- transport_name = GNUNET_malloc(tsize + 1);
- memcpy(transport_name, &data[pos], tsize);
- pos = colon_pos + 1;
+ transport_name = GNUNET_malloc (tsize + 1);
+ memcpy (transport_name, &data[pos], tsize);
+ pos = colon_pos + 1;
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Read transport name %s in blacklist file.\n",
- transport_name);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Read transport name %s in blacklist file.\n", transport_name);
#endif
- memcpy (&enc, &data[pos], sizeof (struct
GNUNET_CRYPTO_HashAsciiEncoded));
- if (!isspace ( (unsigned char) enc.encoding[sizeof (struct
GNUNET_CRYPTO_HashAsciiEncoded) - 1]))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Syntax error in blacklist file at offset %llu,
skipping bytes.\n"),
- (unsigned long long) pos);
- pos++;
- while ((pos < frstat.st_size) && (!isspace ( (unsigned char)
data[pos])))
- pos++;
- GNUNET_free_non_null(transport_name);
- continue;
- }
- enc.encoding[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0';
- if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string ((char *) &enc,
&pid.hashPubKey))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Syntax error in blacklist file at offset %llu,
skipping bytes `%s'.\n"),
- (unsigned long long) pos,
- &enc);
- }
- else
- {
- if (0 != memcmp (&pid,
- &my_identity,
- sizeof (struct GNUNET_PeerIdentity)))
- {
- entries_found++;
- add_peer_to_blacklist (&pid,
- transport_name);
- }
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Found myself `%s' in blacklist (useless,
ignored)\n"),
- GNUNET_i2s (&pid));
- }
- }
- pos = pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded);
- GNUNET_free_non_null(transport_name);
- while ((pos < frstat.st_size) && isspace ( (unsigned char) data[pos]))
+ memcpy (&enc, &data[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded));
+ if (!isspace
+ ((unsigned char)
+ enc.encoding[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1]))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Syntax error in blacklist file at offset %llu, skipping
bytes.\n"),
+ (unsigned long long) pos);
+ pos++;
+ while ((pos < frstat.st_size) && (!isspace ((unsigned char) data[pos])))
pos++;
+ GNUNET_free_non_null (transport_name);
+ continue;
}
- GNUNET_STATISTICS_update (stats, "# Transport entries blacklisted",
entries_found, GNUNET_NO);
+ enc.encoding[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0';
+ if (GNUNET_OK !=
+ GNUNET_CRYPTO_hash_from_string ((char *) &enc, &pid.hashPubKey))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Syntax error in blacklist file at offset %llu, skipping
bytes `%s'.\n"),
+ (unsigned long long) pos, &enc);
+ }
+ else
+ {
+ if (0 != memcmp (&pid, &my_identity, sizeof (struct
GNUNET_PeerIdentity)))
+ {
+ entries_found++;
+ add_peer_to_blacklist (&pid, transport_name);
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Found myself `%s' in blacklist (useless, ignored)\n"),
+ GNUNET_i2s (&pid));
+ }
+ }
+ pos = pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded);
+ GNUNET_free_non_null (transport_name);
+ while ((pos < frstat.st_size) && isspace ((unsigned char) data[pos]))
+ pos++;
+ }
+ GNUNET_STATISTICS_update (stats, "# Transport entries blacklisted",
+ entries_found, GNUNET_NO);
GNUNET_free (data);
GNUNET_free (fn);
}
@@ -1281,57 +1295,56 @@
client->th = NULL;
if (buf == NULL)
- {
-#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmission to client failed, closing connection.\n");
+ {
+#if DEBUG_TRANSPORT
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Transmission to client failed, closing connection.\n");
#endif
- /* fatal error with client, free message queue! */
- while (NULL != (q = client->message_queue_head))
- {
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# bytes discarded (could not
transmit to client)"),
- ntohs (((const struct
GNUNET_MessageHeader*)&q[1])->size),
- GNUNET_NO);
- GNUNET_CONTAINER_DLL_remove (client->message_queue_head,
- client->message_queue_tail,
- q);
- GNUNET_free (q);
- }
- client->message_count = 0;
- return 0;
+ /* fatal error with client, free message queue! */
+ while (NULL != (q = client->message_queue_head))
+ {
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# bytes discarded (could not transmit to
client)"),
+ ntohs (((const struct GNUNET_MessageHeader *)
+ &q[1])->size), GNUNET_NO);
+ GNUNET_CONTAINER_DLL_remove (client->message_queue_head,
+ client->message_queue_tail, q);
+ GNUNET_free (q);
}
+ client->message_count = 0;
+ return 0;
+ }
cbuf = buf;
tsize = 0;
while (NULL != (q = client->message_queue_head))
- {
- msg = (const struct GNUNET_MessageHeader *) &q[1];
- msize = ntohs (msg->size);
- if (msize + tsize > size)
- break;
+ {
+ msg = (const struct GNUNET_MessageHeader *) &q[1];
+ msize = ntohs (msg->size);
+ if (msize + tsize > size)
+ break;
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitting message of type %u to client.\n",
- ntohs (msg->type));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Transmitting message of type %u to client.\n",
+ ntohs (msg->type));
#endif
- GNUNET_CONTAINER_DLL_remove (client->message_queue_head,
- client->message_queue_tail,
- q);
- memcpy (&cbuf[tsize], msg, msize);
- tsize += msize;
- GNUNET_free (q);
- client->message_count--;
- }
+ GNUNET_CONTAINER_DLL_remove (client->message_queue_head,
+ client->message_queue_tail, q);
+ memcpy (&cbuf[tsize], msg, msize);
+ tsize += msize;
+ GNUNET_free (q);
+ client->message_count--;
+ }
if (NULL != q)
- {
- GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader));
- client->th = GNUNET_SERVER_notify_transmit_ready (client->client,
- msize,
-
GNUNET_TIME_UNIT_FOREVER_REL,
-
&transmit_to_client_callback,
- client);
- GNUNET_assert (client->th != NULL);
- }
+ {
+ GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader));
+ client->th = GNUNET_SERVER_notify_transmit_ready (client->client,
+ msize,
+
GNUNET_TIME_UNIT_FOREVER_REL,
+
&transmit_to_client_callback,
+ client);
+ GNUNET_assert (client->th != NULL);
+ }
return tsize;
}
@@ -1344,10 +1357,8 @@
* @param addr_len number of bytes in addr
* @return NULL on error, otherwise address string
*/
-static const char*
-a2s (const char *plugin,
- const void *addr,
- uint16_t addr_len)
+static const char *
+a2s (const char *plugin, const void *addr, uint16_t addr_len)
{
struct TransportPlugin *p;
@@ -1356,9 +1367,7 @@
p = find_transport (plugin);
if ((p == NULL) || (addr_len == 0) || (addr == NULL))
return NULL;
- return p->api->address_to_string (NULL,
- addr,
- addr_len);
+ return p->api->address_to_string (NULL, addr, addr_len);
}
@@ -1373,9 +1382,7 @@
* @return GNUNET_YES (always)
*/
static int
-abort_validation (void *cls,
- const GNUNET_HashCode * key,
- void *value)
+abort_validation (void *cls, const GNUNET_HashCode * key, void *value)
{
struct ValidationEntry *va = value;
@@ -1383,17 +1390,15 @@
GNUNET_SCHEDULER_cancel (va->timeout_task);
GNUNET_free (va->transport_name);
if (va->chvc != NULL)
+ {
+ va->chvc->ve_count--;
+ if (va->chvc->ve_count == 0)
{
- va->chvc->ve_count--;
- if (va->chvc->ve_count == 0)
- {
- GNUNET_CONTAINER_DLL_remove (chvc_head,
- chvc_tail,
- va->chvc);
- GNUNET_free (va->chvc);
- }
- va->chvc = NULL;
+ GNUNET_CONTAINER_DLL_remove (chvc_head, chvc_tail, va->chvc);
+ GNUNET_free (va->chvc);
}
+ va->chvc = NULL;
+ }
GNUNET_free (va);
return GNUNET_YES;
}
@@ -1406,24 +1411,23 @@
* @param tc scheduler context (unused)
*/
static void
-timeout_hello_validation (void *cls, const struct GNUNET_SCHEDULER_TaskContext
*tc)
+timeout_hello_validation (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct ValidationEntry *va = cls;
struct GNUNET_PeerIdentity pid;
va->timeout_task = GNUNET_SCHEDULER_NO_TASK;
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# address validation timeouts"),
- 1,
- GNUNET_NO);
+ gettext_noop ("# address validation timeouts"),
+ 1, GNUNET_NO);
GNUNET_CRYPTO_hash (&va->publicKey,
- sizeof (struct
- GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
- &pid.hashPubKey);
+ sizeof (struct
+ GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+ &pid.hashPubKey);
GNUNET_break (GNUNET_OK ==
GNUNET_CONTAINER_multihashmap_remove (validation_map,
- &pid.hashPubKey,
- va));
+ &pid.hashPubKey, va));
abort_validation (NULL, NULL, va);
}
@@ -1450,43 +1454,40 @@
* freed in client_disconnect_notification
*/
if (client->client == NULL)
- {
- GNUNET_break (0);
- return;
- }
+ {
+ GNUNET_break (0);
+ return;
+ }
if ((client->message_count >= MAX_PENDING) && (GNUNET_YES == may_drop))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _
- ("Dropping message of type %u and size %u, have %u messages
pending (%u is the soft limit)\n"),
- ntohs (msg->type),
- ntohs (msg->size),
- client->message_count,
- MAX_PENDING);
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# messages dropped due to slow
client"),
- 1,
- GNUNET_NO);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _
+ ("Dropping message of type %u and size %u, have %u messages
pending (%u is the soft limit)\n"),
+ ntohs (msg->type),
+ ntohs (msg->size), client->message_count, MAX_PENDING);
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# messages dropped due to slow client"), 1,
+ GNUNET_NO);
+ return;
+ }
msize = ntohs (msg->size);
GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader));
q = GNUNET_malloc (sizeof (struct ClientMessageQueueEntry) + msize);
memcpy (&q[1], msg, msize);
GNUNET_CONTAINER_DLL_insert_tail (client->message_queue_head,
- client->message_queue_tail,
- q);
+ client->message_queue_tail, q);
client->message_count++;
if (client->th == NULL)
- {
- client->th = GNUNET_SERVER_notify_transmit_ready (client->client,
- msize,
-
GNUNET_TIME_UNIT_FOREVER_REL,
-
&transmit_to_client_callback,
- client);
- GNUNET_assert (client->th != NULL);
- }
+ {
+ client->th = GNUNET_SERVER_notify_transmit_ready (client->client,
+ msize,
+
GNUNET_TIME_UNIT_FOREVER_REL,
+
&transmit_to_client_callback,
+ client);
+ GNUNET_assert (client->th != NULL);
+ }
}
@@ -1501,9 +1502,8 @@
*/
static void
transmit_send_ok (struct TransportClient *client,
- struct NeighbourMapEntry *n,
- const struct GNUNET_PeerIdentity *target,
- int result)
+ struct NeighbourMapEntry *n,
+ const struct GNUNET_PeerIdentity *target, int result)
{
struct SendOkMessage send_ok_msg;
@@ -1513,7 +1513,8 @@
if (n != NULL)
send_ok_msg.latency = GNUNET_TIME_relative_hton (n->latency);
else
- send_ok_msg.latency = GNUNET_TIME_relative_hton
(GNUNET_TIME_UNIT_FOREVER_REL);
+ send_ok_msg.latency =
+ GNUNET_TIME_relative_hton (GNUNET_TIME_UNIT_FOREVER_REL);
send_ok_msg.peer = *target;
transmit_to_client (client, &send_ok_msg.header, GNUNET_NO);
}
@@ -1526,8 +1527,7 @@
*
* @param fal address to set to 'connected'
*/
-static void
-mark_address_connected (struct ForeignAddressList *fal);
+static void mark_address_connected (struct ForeignAddressList *fal);
@@ -1537,7 +1537,7 @@
*/
static void
retry_transmission_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct NeighbourMapEntry *n = cls;
@@ -1569,67 +1569,62 @@
struct NeighbourMapEntry *n;
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# bytes pending with plugins"),
- - (int64_t) mq->message_buf_size,
- GNUNET_NO);
+ gettext_noop ("# bytes pending with plugins"),
+ -(int64_t) mq->message_buf_size, GNUNET_NO);
if (result == GNUNET_OK)
- {
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# bytes successfully transmitted
by plugins"),
- mq->message_buf_size,
- GNUNET_NO);
- }
+ {
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# bytes successfully transmitted by plugins"),
+ mq->message_buf_size, GNUNET_NO);
+ }
else
+ {
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# bytes with transmission failure by plugins"),
+ mq->message_buf_size, GNUNET_NO);
+ }
+ if (mq->specific_address != NULL)
+ {
+ if (result == GNUNET_OK)
{
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# bytes with transmission
failure by plugins"),
- mq->message_buf_size,
- GNUNET_NO);
+ mq->specific_address->timeout =
+ GNUNET_TIME_relative_to_absolute
+ (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
+ if (mq->specific_address->validated == GNUNET_YES)
+ mark_address_connected (mq->specific_address);
}
- if (mq->specific_address != NULL)
+ else
{
- if (result == GNUNET_OK)
- {
- mq->specific_address->timeout =
- GNUNET_TIME_relative_to_absolute
- (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
- if (mq->specific_address->validated == GNUNET_YES)
- mark_address_connected (mq->specific_address);
- }
- else
- {
- if (mq->specific_address->connected == GNUNET_YES)
- {
+ if (mq->specific_address->connected == GNUNET_YES)
+ {
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Marking address `%s' as no longer connected (due to
transmission problem)\n",
- a2s
(mq->specific_address->ready_list->plugin->short_name,
- mq->specific_address->addr,
- mq->specific_address->addrlen));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Marking address `%s' as no longer connected (due to
transmission problem)\n",
+ a2s (mq->specific_address->ready_list->plugin->short_name,
+ mq->specific_address->addr,
+ mq->specific_address->addrlen));
#endif
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# connected addresses"),
- -1,
- GNUNET_NO);
- mq->specific_address->connected = GNUNET_NO;
- }
- }
- if (! mq->internal_msg)
- mq->specific_address->in_transmit = GNUNET_NO;
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# connected addresses"),
+ -1, GNUNET_NO);
+ mq->specific_address->connected = GNUNET_NO;
+ }
}
+ if (!mq->internal_msg)
+ mq->specific_address->in_transmit = GNUNET_NO;
+ }
n = find_neighbour (&mq->neighbour_id);
if (mq->client != NULL)
transmit_send_ok (mq->client, n, target, result);
GNUNET_assert (n != NULL);
- GNUNET_CONTAINER_DLL_remove (n->cont_head,
- n->cont_tail,
- mq);
+ GNUNET_CONTAINER_DLL_remove (n->cont_head, n->cont_tail, mq);
GNUNET_free (mq);
- if (result == GNUNET_OK)
+ if (result == GNUNET_OK)
try_transmission_to_peer (n);
else if (GNUNET_SCHEDULER_NO_TASK == n->retry_task)
- n->retry_task = GNUNET_SCHEDULER_add_now (&retry_transmission_task,
- n);
+ n->retry_task = GNUNET_SCHEDULER_add_now (&retry_transmission_task, n);
}
@@ -1649,81 +1644,73 @@
int force_address;
if (n->messages_head == NULL)
- {
+ {
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmission queue for `%4s' is empty\n",
- GNUNET_i2s (&n->id));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Transmission queue for `%4s' is empty\n", GNUNET_i2s
(&n->id));
#endif
- return; /* nothing to do */
- }
+ return; /* nothing to do */
+ }
rl = NULL;
mq = n->messages_head;
force_address = GNUNET_YES;
if (mq->specific_address == NULL)
- {
- /* TODO: ADD ATS */
- mq->specific_address = get_preferred_ats_address(n);
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# transport selected peer
address freely"),
- 1,
- GNUNET_NO);
- force_address = GNUNET_NO;
- }
+ {
+ /* TODO: ADD ATS */
+ mq->specific_address = get_preferred_ats_address (n);
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# transport selected peer address freely"), 1,
+ GNUNET_NO);
+ force_address = GNUNET_NO;
+ }
if (mq->specific_address == NULL)
+ {
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# transport failed to selected peer address"),
+ 1, GNUNET_NO);
+ timeout = GNUNET_TIME_absolute_get_remaining (mq->timeout);
+ if (timeout.rel_value == 0)
{
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# transport failed to selected
peer address"),
- 1,
- GNUNET_NO);
- timeout = GNUNET_TIME_absolute_get_remaining (mq->timeout);
- if (timeout.rel_value == 0)
- {
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "No destination address available to transmit message of
size %u to peer `%4s'\n",
- mq->message_buf_size,
- GNUNET_i2s (&mq->neighbour_id));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "No destination address available to transmit message of
size %u to peer `%4s'\n",
+ mq->message_buf_size, GNUNET_i2s (&mq->neighbour_id));
#endif
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# bytes in message queue for
other peers"),
- - (int64_t) mq->message_buf_size,
- GNUNET_NO);
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# bytes discarded (no
destination address available)"),
- mq->message_buf_size,
- GNUNET_NO);
- if (mq->client != NULL)
- transmit_send_ok (mq->client, n, &n->id, GNUNET_NO);
- GNUNET_CONTAINER_DLL_remove (n->messages_head,
- n->messages_tail,
- mq);
- GNUNET_free (mq);
- return; /* nobody ready */
- }
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# message delivery deferred (no
address)"),
- 1,
- GNUNET_NO);
- if (n->retry_task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel (n->retry_task);
- n->retry_task = GNUNET_SCHEDULER_add_delayed (timeout,
- &retry_transmission_task,
- n);
+ gettext_noop
+ ("# bytes in message queue for other peers"),
+ -(int64_t) mq->message_buf_size, GNUNET_NO);
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# bytes discarded (no destination address
available)"),
+ mq->message_buf_size, GNUNET_NO);
+ if (mq->client != NULL)
+ transmit_send_ok (mq->client, n, &n->id, GNUNET_NO);
+ GNUNET_CONTAINER_DLL_remove (n->messages_head, n->messages_tail, mq);
+ GNUNET_free (mq);
+ return; /* nobody ready */
+ }
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# message delivery deferred (no address)"), 1,
+ GNUNET_NO);
+ if (n->retry_task != GNUNET_SCHEDULER_NO_TASK)
+ GNUNET_SCHEDULER_cancel (n->retry_task);
+ n->retry_task = GNUNET_SCHEDULER_add_delayed (timeout,
+ &retry_transmission_task, n);
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "No validated destination address available to transmit
message of size %u to peer `%4s', will wait %llums to find an address.\n",
- mq->message_buf_size,
- GNUNET_i2s (&mq->neighbour_id),
- timeout.rel_value);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "No validated destination address available to transmit
message of size %u to peer `%4s', will wait %llums to find an address.\n",
+ mq->message_buf_size,
+ GNUNET_i2s (&mq->neighbour_id), timeout.rel_value);
#endif
- /* FIXME: might want to trigger peerinfo lookup here
- (unless that's already pending...) */
- return;
- }
- GNUNET_CONTAINER_DLL_remove (n->messages_head,
- n->messages_tail,
- mq);
+ /* FIXME: might want to trigger peerinfo lookup here
+ * (unless that's already pending...) */
+ return;
+ }
+ GNUNET_CONTAINER_DLL_remove (n->messages_head, n->messages_tail, mq);
if (mq->specific_address->connected == GNUNET_NO)
mq->specific_address->connect_attempts++;
rl = mq->specific_address->ready_list;
@@ -1735,45 +1722,38 @@
"Sending message of size %u for `%4s' to `%s' via plugin `%s'\n",
mq->message_buf_size,
GNUNET_i2s (&n->id),
- (mq->specific_address->addr != NULL)
- ? a2s (mq->plugin->short_name,
- mq->specific_address->addr,
- mq->specific_address->addrlen)
- : "<inbound>",
- rl->plugin->short_name);
+ (mq->specific_address->addr != NULL)
+ ? a2s (mq->plugin->short_name,
+ mq->specific_address->addr,
+ mq->specific_address->addrlen)
+ : "<inbound>", rl->plugin->short_name);
#endif
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# bytes in message queue for other
peers"),
- - (int64_t) mq->message_buf_size,
- GNUNET_NO);
+ gettext_noop
+ ("# bytes in message queue for other peers"),
+ -(int64_t) mq->message_buf_size, GNUNET_NO);
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# bytes pending with plugins"),
- mq->message_buf_size,
- GNUNET_NO);
+ gettext_noop ("# bytes pending with plugins"),
+ mq->message_buf_size, GNUNET_NO);
- GNUNET_CONTAINER_DLL_insert (n->cont_head,
- n->cont_tail,
- mq);
+ GNUNET_CONTAINER_DLL_insert (n->cont_head, n->cont_tail, mq);
ret = rl->plugin->api->send (rl->plugin->api->cls,
- &mq->neighbour_id,
- mq->message_buf,
- mq->message_buf_size,
- mq->priority,
- GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
- mq->specific_address->session,
- mq->specific_address->addr,
- mq->specific_address->addrlen,
- force_address,
- &transmit_send_continuation, mq);
+ &mq->neighbour_id,
+ mq->message_buf,
+ mq->message_buf_size,
+ mq->priority,
+ GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
+ mq->specific_address->session,
+ mq->specific_address->addr,
+ mq->specific_address->addrlen,
+ force_address, &transmit_send_continuation, mq);
if (ret == -1)
- {
- /* failure, but 'send' would not call continuation in this case,
- so we need to do it here! */
- transmit_send_continuation (mq,
- &mq->neighbour_id,
- GNUNET_SYSERR);
- }
+ {
+ /* failure, but 'send' would not call continuation in this case,
+ * so we need to do it here! */
+ transmit_send_continuation (mq, &mq->neighbour_id, GNUNET_SYSERR);
+ }
}
@@ -1794,7 +1774,7 @@
transmit_to_peer (struct TransportClient *client,
struct ForeignAddressList *peer_address,
unsigned int priority,
- struct GNUNET_TIME_Relative timeout,
+ struct GNUNET_TIME_Relative timeout,
const char *message_buf,
size_t message_buf_size,
int is_internal, struct NeighbourMapEntry *neighbour)
@@ -1803,46 +1783,45 @@
#if EXTRA_CHECKS
if (client != NULL)
+ {
+ /* check for duplicate submission */
+ mq = neighbour->messages_head;
+ while (NULL != mq)
{
- /* check for duplicate submission */
- mq = neighbour->messages_head;
- while (NULL != mq)
- {
- if (mq->client == client)
- {
- /* client transmitted to same peer twice
- before getting SEND_OK! */
- GNUNET_break (0);
- return;
- }
- mq = mq->next;
- }
+ if (mq->client == client)
+ {
+ /* client transmitted to same peer twice
+ * before getting SEND_OK! */
+ GNUNET_break (0);
+ return;
+ }
+ mq = mq->next;
}
+ }
#endif
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# bytes in message queue for other
peers"),
- message_buf_size,
- GNUNET_NO);
+ gettext_noop
+ ("# bytes in message queue for other peers"),
+ message_buf_size, GNUNET_NO);
mq = GNUNET_malloc (sizeof (struct MessageQueue) + message_buf_size);
mq->specific_address = peer_address;
mq->client = client;
/* FIXME: this memcpy can be up to 7% of our total runtime! */
memcpy (&mq[1], message_buf, message_buf_size);
- mq->message_buf = (const char*) &mq[1];
+ mq->message_buf = (const char *) &mq[1];
mq->message_buf_size = message_buf_size;
- memcpy(&mq->neighbour_id, &neighbour->id, sizeof(struct
GNUNET_PeerIdentity));
+ memcpy (&mq->neighbour_id, &neighbour->id,
+ sizeof (struct GNUNET_PeerIdentity));
mq->internal_msg = is_internal;
mq->priority = priority;
mq->timeout = GNUNET_TIME_relative_to_absolute (timeout);
if (is_internal)
GNUNET_CONTAINER_DLL_insert (neighbour->messages_head,
- neighbour->messages_tail,
- mq);
+ neighbour->messages_tail, mq);
else
GNUNET_CONTAINER_DLL_insert_after (neighbour->messages_head,
- neighbour->messages_tail,
- neighbour->messages_tail,
- mq);
+ neighbour->messages_tail,
+ neighbour->messages_tail, mq);
try_transmission_to_peer (neighbour);
}
@@ -1863,62 +1842,56 @@
struct TransportPlugin *plugin;
struct ForeignAddressList *fal;
- if (! n->public_key_valid)
- {
- /* This should not happen since the other peer
- should send us a HELLO prior to sending his
- PING */
- GNUNET_break_op (0);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Could not transmit plain PING to `%s': public key not
known\n",
- GNUNET_i2s (&n->id));
- return;
- }
+ if (!n->public_key_valid)
+ {
+ /* This should not happen since the other peer
+ * should send us a HELLO prior to sending his
+ * PING */
+ GNUNET_break_op (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Could not transmit plain PING to `%s': public key not
known\n",
+ GNUNET_i2s (&n->id));
+ return;
+ }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Looking for addresses to transmit plain PING to `%s'\n",
- GNUNET_i2s (&n->id));
+ "Looking for addresses to transmit plain PING to `%s'\n",
+ GNUNET_i2s (&n->id));
for (rl = n->plugins; rl != NULL; rl = rl->next)
+ {
+ plugin = rl->plugin;
+ for (fal = rl->addresses; fal != NULL; fal = fal->next)
{
- plugin = rl->plugin;
- for (fal = rl->addresses; fal != NULL; fal = fal->next)
- {
- if (! fal->connected)
- continue;
- ve = GNUNET_malloc (sizeof (struct ValidationEntry));
- ve->transport_name = GNUNET_strdup (plugin->short_name);
- ve->challenge = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
- UINT_MAX);
- ve->send_time = GNUNET_TIME_absolute_get();
- ve->session = fal->session;
- memcpy(&ve->publicKey,
- &n->publicKey,
- sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
- ve->timeout_task = GNUNET_SCHEDULER_add_delayed
(HELLO_VERIFICATION_TIMEOUT,
-
&timeout_hello_validation,
- ve);
- GNUNET_CONTAINER_multihashmap_put (validation_map,
- &n->id.hashPubKey,
- ve,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
- ping.header.size = htons(sizeof(struct TransportPingMessage));
- ping.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_PING);
- ping.challenge = htonl(ve->challenge);
- memcpy(&ping.target, &n->id, sizeof(struct GNUNET_PeerIdentity));
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# PING without HELLO
messages sent"),
- 1,
- GNUNET_NO);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitting plain PING to `%s'\n",
- GNUNET_i2s (&n->id));
- transmit_to_peer (NULL,
- fal,
- GNUNET_SCHEDULER_PRIORITY_DEFAULT,
- HELLO_VERIFICATION_TIMEOUT,
- (const char*) &ping, sizeof (ping),
- GNUNET_YES, n);
- }
+ if (!fal->connected)
+ continue;
+ ve = GNUNET_malloc (sizeof (struct ValidationEntry));
+ ve->transport_name = GNUNET_strdup (plugin->short_name);
+ ve->challenge = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
+ UINT_MAX);
+ ve->send_time = GNUNET_TIME_absolute_get ();
+ ve->session = fal->session;
+ memcpy (&ve->publicKey,
+ &n->publicKey,
+ sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
+ ve->timeout_task =
+ GNUNET_SCHEDULER_add_delayed (HELLO_VERIFICATION_TIMEOUT,
+ &timeout_hello_validation, ve);
+ GNUNET_CONTAINER_multihashmap_put (validation_map, &n->id.hashPubKey, ve,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
+ ping.header.size = htons (sizeof (struct TransportPingMessage));
+ ping.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PING);
+ ping.challenge = htonl (ve->challenge);
+ memcpy (&ping.target, &n->id, sizeof (struct GNUNET_PeerIdentity));
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# PING without HELLO messages sent"), 1,
+ GNUNET_NO);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting plain PING to `%s'\n",
+ GNUNET_i2s (&n->id));
+ transmit_to_peer (NULL, fal, GNUNET_SCHEDULER_PRIORITY_DEFAULT,
+ HELLO_VERIFICATION_TIMEOUT, (const char *) &ping,
+ sizeof (ping), GNUNET_YES, n);
}
+ }
}
@@ -1930,7 +1903,7 @@
* @param fal address to set to 'connected'
*/
static void
-mark_address_connected(struct ForeignAddressList *fal)
+mark_address_connected (struct ForeignAddressList *fal)
{
struct ForeignAddressList *pos;
struct ForeignAddressList *inbound;
@@ -1938,92 +1911,102 @@
GNUNET_assert (GNUNET_YES == fal->validated);
if (fal->connected == GNUNET_YES)
- return; /* nothing to do */
+ return; /* nothing to do */
inbound = NULL;
outbound = NULL;
pos = fal->ready_list->addresses;
while (pos != NULL)
- {
- /* Already have inbound address, and this is also an inbound address,
don't switch!! */
- if ( (GNUNET_YES == pos->connected) &&
- (0 == pos->addrlen) &&
- (0 == fal->addrlen) )
- return;
- if ( (0 == pos->addrlen) &&
- (GNUNET_YES == pos->connected) )
- inbound = pos;
- pos = pos->next;
- }
+ {
+ /* Already have inbound address, and this is also an inbound address,
don't switch!! */
+ if ((GNUNET_YES == pos->connected) &&
+ (0 == pos->addrlen) && (0 == fal->addrlen))
+ return;
+ if ((0 == pos->addrlen) && (GNUNET_YES == pos->connected))
+ inbound = pos;
+ pos = pos->next;
+ }
pos = fal->ready_list->addresses;
while (pos != NULL)
- {
- /* Already have outbound address, and this is also an outbound address,
don't switch!! */
- if ( (GNUNET_YES == pos->connected) &&
- (0 < pos->addrlen) &&
- (0 < fal->addrlen) )
- return;
- if ( (0 < pos->addrlen) && (GNUNET_YES == pos->connected) )
- outbound = pos;
- pos = pos->next;
- }
+ {
+ /* Already have outbound address, and this is also an outbound address,
don't switch!! */
+ if ((GNUNET_YES == pos->connected) &&
+ (0 < pos->addrlen) && (0 < fal->addrlen))
+ return;
+ if ((0 < pos->addrlen) && (GNUNET_YES == pos->connected))
+ outbound = pos;
+ pos = pos->next;
+ }
#if DEBUG_INBOUND
if (inbound != NULL)
- fprintf(stderr, "Peer: %s, have inbound connection.\n",
GNUNET_i2s(&my_identity));
+ fprintf (stderr, "Peer: %s, have inbound connection.\n",
+ GNUNET_i2s (&my_identity));
if (outbound != NULL)
- fprintf(stderr, "Peer: %s, have outbound connection.\n",
GNUNET_i2s(&my_identity));
+ fprintf (stderr, "Peer: %s, have outbound connection.\n",
+ GNUNET_i2s (&my_identity));
#endif
/* Have an inbound connection to this peer which is valid; our id is lower,
ignore outbound connection! */
if ((inbound != NULL) && (0 != fal->addrlen) && (1
- == GNUNET_CRYPTO_hash_xorcmp
(&inbound->ready_list->neighbour->id.hashPubKey,
- &my_identity.hashPubKey, &null_hash)))
- {
+ ==
+ GNUNET_CRYPTO_hash_xorcmp
+ (&inbound->
+ ready_list->neighbour->id.
+ hashPubKey,
+ &my_identity.hashPubKey,
+ &null_hash)))
+ {
#if DEBUG_INBOUND
- fprintf(stderr, "Peer: %s, had inbound connection, ignoring
outbound!\n", GNUNET_i2s(&my_identity));
+ fprintf (stderr, "Peer: %s, had inbound connection, ignoring outbound!\n",
+ GNUNET_i2s (&my_identity));
#endif
- return;
- }
+ return;
+ }
else if ((outbound != NULL) && (0 == fal->addrlen) && ((-1
- == GNUNET_CRYPTO_hash_xorcmp
(&outbound->ready_list->neighbour->id.hashPubKey,
- &my_identity.hashPubKey, &null_hash))))
- {
+ ==
+
GNUNET_CRYPTO_hash_xorcmp
+
(&outbound->ready_list->neighbour->
+ id.hashPubKey,
+
&my_identity.hashPubKey,
+ &null_hash))))
+ {
#if DEBUG_INBOUND
- fprintf(stderr, "Peer: %s, have outbound connection, ignoring
inbound!\n", GNUNET_i2s(&my_identity));
+ fprintf (stderr, "Peer: %s, have outbound connection, ignoring inbound!\n",
+ GNUNET_i2s (&my_identity));
#endif
- return;
- }
+ return;
+ }
pos = fal->ready_list->addresses;
while (pos != NULL)
+ {
+ if ((GNUNET_YES == pos->connected) && (0 < pos->addrlen))
{
- if ((GNUNET_YES == pos->connected) && (0 < pos->addrlen))
- {
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Marking address `%s' as no longer connected (due to
connect on other address)\n",
- a2s (pos->ready_list->plugin->short_name, pos->addr,
- pos->addrlen));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Marking address `%s' as no longer connected (due to connect
on other address)\n",
+ a2s (pos->ready_list->plugin->short_name, pos->addr,
+ pos->addrlen));
#endif
#if DEBUG_INBOUND
- fprintf(stderr,
- "Peer: %s, setting %s connection to disconnected.\n",
- GNUNET_i2s(&my_identity),
- (0 == pos->addrlen) ? "INBOUND" : "OUTBOUND");
+ fprintf (stderr,
+ "Peer: %s, setting %s connection to disconnected.\n",
+ GNUNET_i2s (&my_identity),
+ (0 == pos->addrlen) ? "INBOUND" : "OUTBOUND");
#endif
- pos->connected = GNUNET_NO;
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# connected addresses"), -1,
- GNUNET_NO);
- }
- pos = pos->next;
+ pos->connected = GNUNET_NO;
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# connected addresses"), -1,
+ GNUNET_NO);
}
+ pos = pos->next;
+ }
GNUNET_assert (GNUNET_NO == fal->connected);
fal->connected = GNUNET_YES;
GNUNET_STATISTICS_update (stats, gettext_noop ("# connected addresses"),
- 1, GNUNET_NO);
+ 1, GNUNET_NO);
}
@@ -2037,7 +2020,7 @@
* @return selected address, NULL if we have none
*/
struct ForeignAddressList *
-find_ready_address(struct NeighbourMapEntry *neighbour)
+find_ready_address (struct NeighbourMapEntry *neighbour)
{
struct ReadyList *head = neighbour->plugins;
struct ForeignAddressList *addresses;
@@ -2049,95 +2032,93 @@
best_address = NULL;
while (head != NULL)
+ {
+ addresses = head->addresses;
+ while (addresses != NULL)
{
- addresses = head->addresses;
- while (addresses != NULL)
- {
- if ( (addresses->timeout.abs_value < now.abs_value) &&
- (addresses->connected == GNUNET_YES) )
- {
+ if ((addresses->timeout.abs_value < now.abs_value) &&
+ (addresses->connected == GNUNET_YES))
+ {
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Marking long-time inactive connection to `%4s' as
down.\n",
- GNUNET_i2s (&neighbour->id));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Marking long-time inactive connection to `%4s' as
down.\n",
+ GNUNET_i2s (&neighbour->id));
#endif
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# connected addresses"),
- -1,
- GNUNET_NO);
- addresses->connected = GNUNET_NO;
- }
- addresses = addresses->next;
- }
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# connected addresses"),
+ -1, GNUNET_NO);
+ addresses->connected = GNUNET_NO;
+ }
+ addresses = addresses->next;
+ }
- addresses = head->addresses;
- while (addresses != NULL)
- {
+ addresses = head->addresses;
+ while (addresses != NULL)
+ {
#if DEBUG_TRANSPORT
- if (addresses->addr != NULL)
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Have address `%s' for peer `%4s' (status: %d, %d, %d,
%u, %llums, %u)\n",
- a2s (head->plugin->short_name,
- addresses->addr,
- addresses->addrlen),
- GNUNET_i2s (&neighbour->id),
- addresses->connected,
- addresses->in_transmit,
- addresses->validated,
- addresses->connect_attempts,
- (unsigned long long) addresses->timeout.abs_value,
- (unsigned int) addresses->distance);
+ if (addresses->addr != NULL)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Have address `%s' for peer `%4s' (status: %d, %d, %d, %u,
%llums, %u)\n",
+ a2s (head->plugin->short_name,
+ addresses->addr,
+ addresses->addrlen),
+ GNUNET_i2s (&neighbour->id),
+ addresses->connected,
+ addresses->in_transmit,
+ addresses->validated,
+ addresses->connect_attempts,
+ (unsigned long long) addresses->timeout.abs_value,
+ (unsigned int) addresses->distance);
#endif
- if (0==strcmp(head->plugin->short_name,"unix"))
- {
- if ( (unix_address == NULL) ||
- ( (unix_address != NULL) &&
- (addresses->latency.rel_value <
unix_address->latency.rel_value) ) )
- unix_address = addresses;
- }
- if ( ( (best_address == NULL) ||
- (addresses->connected == GNUNET_YES) ||
- (best_address->connected == GNUNET_NO) ) &&
- (addresses->in_transmit == GNUNET_NO) &&
- ( (best_address == NULL) ||
- (addresses->latency.rel_value <
best_address->latency.rel_value)) )
- best_address = addresses;
- /* FIXME: also give lower-latency addresses that are not
- connected a chance some times... */
- addresses = addresses->next;
- }
- if (unix_address != NULL)
- break;
- head = head->next;
+ if (0 == strcmp (head->plugin->short_name, "unix"))
+ {
+ if ((unix_address == NULL) ||
+ ((unix_address != NULL) &&
+ (addresses->latency.rel_value < unix_address->latency.rel_value)))
+ unix_address = addresses;
+ }
+ if (((best_address == NULL) ||
+ (addresses->connected == GNUNET_YES) ||
+ (best_address->connected == GNUNET_NO)) &&
+ (addresses->in_transmit == GNUNET_NO) &&
+ ((best_address == NULL) ||
+ (addresses->latency.rel_value < best_address->latency.rel_value)))
+ best_address = addresses;
+ /* FIXME: also give lower-latency addresses that are not
+ * connected a chance some times... */
+ addresses = addresses->next;
}
+ if (unix_address != NULL)
+ break;
+ head = head->next;
+ }
if (unix_address != NULL)
- {
- best_address = unix_address;
+ {
+ best_address = unix_address;
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Found UNIX address, forced this address\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Found UNIX address, forced this address\n");
#endif
- }
+ }
if (best_address != NULL)
- {
+ {
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Best address found (`%s') has latency of %llu ms.\n",
- (best_address->addrlen > 0)
- ? a2s (best_address->ready_list->plugin->short_name,
- best_address->addr,
- best_address->addrlen)
- : "<inbound>",
- best_address->latency.rel_value);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Best address found (`%s') has latency of %llu ms.\n",
+ (best_address->addrlen > 0)
+ ? a2s (best_address->ready_list->plugin->short_name,
+ best_address->addr,
+ best_address->addrlen)
+ : "<inbound>", best_address->latency.rel_value);
#endif
- }
+ }
else
- {
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# transmission attempts failed
(no address)"),
- 1,
- GNUNET_NO);
- }
+ {
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# transmission attempts failed (no address)"),
+ 1, GNUNET_NO);
+ }
return best_address;
}
@@ -2164,15 +2145,15 @@
size_t ret;
while ((gc->addr_pos == NULL) && (gc->plug_pos != NULL))
- {
- gc->plug_pos = gc->plug_pos->next;
- gc->addr_pos = (gc->plug_pos != NULL) ? gc->plug_pos->addresses : NULL;
- }
+ {
+ gc->plug_pos = gc->plug_pos->next;
+ gc->addr_pos = (gc->plug_pos != NULL) ? gc->plug_pos->addresses : NULL;
+ }
if (NULL == gc->plug_pos)
- {
+ {
- return 0;
- }
+ return 0;
+ }
ret = GNUNET_HELLO_add_address (gc->plug_pos->short_name,
gc->expiration,
&gc->addr_pos[1],
@@ -2184,9 +2165,7 @@
static int
-transmit_our_hello_if_pong (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+transmit_our_hello_if_pong (void *cls, const GNUNET_HashCode * key, void
*value)
{
struct NeighbourMapEntry *npos = value;
@@ -2194,18 +2173,16 @@
return GNUNET_OK;
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
- "Transmitting updated `%s' to neighbour `%4s'\n",
- "HELLO", GNUNET_i2s (&npos->id));
+ "Transmitting updated `%s' to neighbour `%4s'\n",
+ "HELLO", GNUNET_i2s (&npos->id));
#endif
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# transmitted my HELLO to other
peers"),
- 1,
- GNUNET_NO);
- transmit_to_peer (NULL, NULL, 0,
- HELLO_ADDRESS_EXPIRATION,
- (const char *) our_hello,
- GNUNET_HELLO_size(our_hello),
- GNUNET_NO, npos);
+ gettext_noop
+ ("# transmitted my HELLO to other peers"), 1,
+ GNUNET_NO);
+ transmit_to_peer (NULL, NULL, 0, HELLO_ADDRESS_EXPIRATION,
+ (const char *) our_hello, GNUNET_HELLO_size (our_hello),
+ GNUNET_NO, npos);
return GNUNET_OK;
}
@@ -2218,8 +2195,7 @@
* @param tc scheduler context
*/
static void
-refresh_hello_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+refresh_hello_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_HELLO_Message *hello;
struct TransportClient *cpos;
@@ -2232,29 +2208,26 @@
hello = GNUNET_HELLO_create (&my_public_key, &address_generator, &gc);
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
- "Refreshed my `%s', new size is %d\n", "HELLO",
GNUNET_HELLO_size(hello));
+ "Refreshed my `%s', new size is %d\n", "HELLO",
+ GNUNET_HELLO_size (hello));
#endif
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# refreshed my HELLO"),
- 1,
- GNUNET_NO);
+ gettext_noop ("# refreshed my HELLO"),
+ 1, GNUNET_NO);
cpos = clients;
while (cpos != NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitting my HELLO to client!\n");
- transmit_to_client (cpos,
- (const struct GNUNET_MessageHeader *) hello,
- GNUNET_NO);
- cpos = cpos->next;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting my HELLO to client!\n");
+ transmit_to_client (cpos,
+ (const struct GNUNET_MessageHeader *) hello,
GNUNET_NO);
+ cpos = cpos->next;
+ }
GNUNET_free_non_null (our_hello);
our_hello = hello;
GNUNET_PEERINFO_add_peer (peerinfo, our_hello);
GNUNET_CONTAINER_multihashmap_iterate (neighbours,
- &transmit_our_hello_if_pong,
- NULL);
+ &transmit_our_hello_if_pong, NULL);
}
@@ -2266,14 +2239,11 @@
refresh_hello ()
{
#if DEBUG_TRANSPORT_HELLO
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "refresh_hello() called!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "refresh_hello() called!\n");
#endif
if (hello_task != GNUNET_SCHEDULER_NO_TASK)
return;
- hello_task
- = GNUNET_SCHEDULER_add_now (&refresh_hello_task,
- NULL);
+ hello_task = GNUNET_SCHEDULER_add_now (&refresh_hello_task, NULL);
}
@@ -2287,9 +2257,7 @@
* @return GNUNET_YES (we should continue to iterate)
*/
static int
-remove_session_validations (void *cls,
- const GNUNET_HashCode * key,
- void *value)
+remove_session_validations (void *cls, const GNUNET_HashCode * key, void
*value)
{
struct Session *session = cls;
struct ValidationEntry *ve = value;
@@ -2313,35 +2281,33 @@
* @param nl neighbour that was disconnected
*/
static void
-try_fast_reconnect (struct TransportPlugin *p,
- struct NeighbourMapEntry *nl)
+try_fast_reconnect (struct TransportPlugin *p, struct NeighbourMapEntry *nl)
{
/* FIXME-MW: fast reconnect / transport switching not implemented... */
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "try_fast_reconnect not implemented!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "try_fast_reconnect not implemented!\n");
/* Note: the idea here is to hide problems with transports (or
- switching between plugins) from the core to eliminate the need to
- re-negotiate session keys and the like; OTOH, we should tell core
- quickly (much faster than timeout) `if a connection was lost and
- could not be re-established (i.e. other peer went down or is
- unable / refuses to communicate);
+ * switching between plugins) from the core to eliminate the need to
+ * re-negotiate session keys and the like; OTOH, we should tell core
+ * quickly (much faster than timeout) `if a connection was lost and
+ * could not be re-established (i.e. other peer went down or is
+ * unable / refuses to communicate);
+ *
+ * So we should consider:
+ * 1) ideally: our own willingness / need to connect
+ * 2) prior failures to connect to this peer (by plugin)
+ * 3) ideally: reasons why other peer terminated (as far as knowable)
+ *
+ * Most importantly, it must be POSSIBLE for another peer to terminate
+ * a connection for a while (without us instantly re-establishing it).
+ * Similarly, if another peer is gone we should quickly notify CORE.
+ * OTOH, if there was a minor glitch (i.e. crash of gnunet-service-transport
+ * on the other end), we should reconnect in such a way that BOTH CORE
+ * services never even notice.
+ * Furthermore, the same mechanism (or small variation) could be used
+ * to switch to a better-performing plugin (ATS).
+ *
+ * Finally, this needs to be tested throughly... */
- So we should consider:
- 1) ideally: our own willingness / need to connect
- 2) prior failures to connect to this peer (by plugin)
- 3) ideally: reasons why other peer terminated (as far as knowable)
-
- Most importantly, it must be POSSIBLE for another peer to terminate
- a connection for a while (without us instantly re-establishing it).
- Similarly, if another peer is gone we should quickly notify CORE.
- OTOH, if there was a minor glitch (i.e. crash of gnunet-service-transport
- on the other end), we should reconnect in such a way that BOTH CORE
- services never even notice.
- Furthermore, the same mechanism (or small variation) could be used
- to switch to a better-performing plugin (ATS).
-
- Finally, this needs to be tested throughly... */
-
/*
* GNUNET_NO in the call below makes transport disconnect the peer,
* even if only a single address (out of say, six) went away. This
@@ -2355,12 +2321,12 @@
#if DEBUG_TRANSPORT
#endif
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Disconnecting peer `%4s', %s\n", GNUNET_i2s(&nl->id),
- "try_fast_reconnect");
+ "Disconnecting peer `%4s', %s\n", GNUNET_i2s (&nl->id),
+ "try_fast_reconnect");
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# disconnects due to
try_fast_reconnect"),
- 1,
+ gettext_noop
+ ("# disconnects due to try_fast_reconnect"), 1,
GNUNET_NO);
#if DISCONNECT || 1
disconnect_neighbour (nl, GNUNET_YES);
@@ -2380,9 +2346,9 @@
* @param session which session is being destoyed
*/
static void
-plugin_env_session_end (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- struct Session *session)
+plugin_env_session_end (void *cls,
+ const struct GNUNET_PeerIdentity *peer,
+ struct Session *session)
{
struct TransportPlugin *p = cls;
struct NeighbourMapEntry *nl;
@@ -2392,179 +2358,173 @@
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Session ended with peer `%4s', %s\n",
- GNUNET_i2s(peer),
- "plugin_env_session_end");
+ "Session ended with peer `%4s', %s\n",
+ GNUNET_i2s (peer), "plugin_env_session_end");
#endif
GNUNET_CONTAINER_multihashmap_iterate (validation_map,
- &remove_session_validations,
- session);
+ &remove_session_validations, session);
nl = find_neighbour (peer);
if (nl == NULL)
- {
+ {
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "No neighbour record found for peer `%4s'\n",
- GNUNET_i2s(peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "No neighbour record found for peer `%4s'\n",
+ GNUNET_i2s (peer));
#endif
- return; /* was never marked as connected */
- }
+ return; /* was never marked as connected */
+ }
rl = nl->plugins;
while (rl != NULL)
- {
- if (rl->plugin == p)
- break;
- rl = rl->next;
- }
+ {
+ if (rl->plugin == p)
+ break;
+ rl = rl->next;
+ }
if (rl == NULL)
- {
+ {
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Plugin was associated with peer `%4s'\n",
- GNUNET_i2s(peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Plugin was associated with peer `%4s'\n", GNUNET_i2s (peer));
#endif
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# disconnects due to session
end"),
- 1,
- GNUNET_NO);
- disconnect_neighbour (nl, GNUNET_YES);
- return;
- }
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# disconnects due to session
end"),
+ 1, GNUNET_NO);
+ disconnect_neighbour (nl, GNUNET_YES);
+ return;
+ }
prev = NULL;
pos = rl->addresses;
- while ( (pos != NULL) &&
- (pos->session != session) )
- {
- prev = pos;
- pos = pos->next;
- }
+ while ((pos != NULL) && (pos->session != session))
+ {
+ prev = pos;
+ pos = pos->next;
+ }
if (pos == NULL)
- {
+ {
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Session was never marked as ready for peer `%4s'\n",
- GNUNET_i2s(peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Session was never marked as ready for peer `%4s'\n",
+ GNUNET_i2s (peer));
#endif
- int validations_pending = GNUNET_CONTAINER_multihashmap_contains
(validation_map, &peer->hashPubKey);
+ int validations_pending =
+ GNUNET_CONTAINER_multihashmap_contains (validation_map,
+ &peer->hashPubKey);
- /* No session was marked as ready, but we have pending validations so do
not disconnect from neighbour */
- if (validations_pending ==GNUNET_YES)
- {
+ /* No session was marked as ready, but we have pending validations so do
not disconnect from neighbour */
+ if (validations_pending == GNUNET_YES)
+ {
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Not disconnecting from peer `%4s due to pending address
validations\n", GNUNET_i2s(peer));
+ "Not disconnecting from peer `%4s due to pending address
validations\n",
+ GNUNET_i2s (peer));
#endif
- return;
- }
+ return;
+ }
- //FIXME: This conflicts with inbound tcp connections and tcp nat ...
debugging in progress
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# disconnects due to unready
session"),
- 1,
- GNUNET_NO);
+ //FIXME: This conflicts with inbound tcp connections and tcp nat ...
debugging in progress
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# disconnects due to unready session"), 1,
+ GNUNET_NO);
- disconnect_neighbour (nl, GNUNET_YES);
- return; /* was never marked as connected */
- }
+ disconnect_neighbour (nl, GNUNET_YES);
+ return; /* was never marked as connected */
+ }
pos->session = NULL;
if (GNUNET_YES == pos->connected)
+ {
+ pos->connected = GNUNET_NO;
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# connected addresses"),
+ -1, GNUNET_NO);
+ }
+ if (GNUNET_SCHEDULER_NO_TASK != pos->revalidate_task)
+ {
+ GNUNET_SCHEDULER_cancel (pos->revalidate_task);
+ pos->revalidate_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+
+ if (pos->addrlen != 0)
+ {
+ if (nl->received_pong != GNUNET_NO)
{
- pos->connected = GNUNET_NO;
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# connected addresses"),
- -1,
- GNUNET_NO);
+ gettext_noop
+ ("# try_fast_reconnect thanks to
plugin_env_session_end"),
+ 1, GNUNET_NO);
+ if (GNUNET_YES == pos->connected)
+ try_fast_reconnect (p, nl);
}
- if (GNUNET_SCHEDULER_NO_TASK != pos->revalidate_task)
+ else
{
- GNUNET_SCHEDULER_cancel (pos->revalidate_task);
- pos->revalidate_task = GNUNET_SCHEDULER_NO_TASK;
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# disconnects due to missing pong"), 1,
+ GNUNET_NO);
+ /* FIXME this is never true?! See: line 2416 */
+ if (GNUNET_YES == pos->connected)
+ disconnect_neighbour (nl, GNUNET_YES);
}
+ return;
+ }
- if (pos->addrlen != 0)
- {
- if (nl->received_pong != GNUNET_NO)
- {
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# try_fast_reconnect thanks
to plugin_env_session_end"),
- 1,
- GNUNET_NO);
- if (GNUNET_YES == pos->connected)
- try_fast_reconnect (p, nl);
- }
- else
- {
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# disconnects due to
missing pong"),
- 1,
- GNUNET_NO);
- /* FIXME this is never true?! See: line 2416*/
- if (GNUNET_YES == pos->connected)
- disconnect_neighbour (nl, GNUNET_YES);
- }
- return;
- }
-
/* was inbound connection, free 'pos' */
if (prev == NULL)
rl->addresses = pos->next;
else
prev->next = pos->next;
if (GNUNET_SCHEDULER_NO_TASK != pos->revalidate_task)
- {
- GNUNET_SCHEDULER_cancel (pos->revalidate_task);
- pos->revalidate_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (pos->revalidate_task);
+ pos->revalidate_task = GNUNET_SCHEDULER_NO_TASK;
+ }
GNUNET_free_non_null (pos->ressources);
GNUNET_free_non_null (pos->quality);
#if HAVE_LIBGLPK
ats_modify_problem_state (ats, ATS_MODIFIED);
#endif
if (GNUNET_YES != pos->connected)
- {
- /* nothing else to do, connection was never up... */
- GNUNET_free (pos);
- return;
- }
+ {
+ /* nothing else to do, connection was never up... */
+ GNUNET_free (pos);
+ return;
+ }
pos->connected = GNUNET_NO;
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# connected addresses"),
- -1,
- GNUNET_NO);
+ gettext_noop ("# connected addresses"),
+ -1, GNUNET_NO);
GNUNET_free (pos);
if (nl->received_pong == GNUNET_NO)
- {
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# disconnects due to NO pong"),
- 1,
- GNUNET_NO);
- disconnect_neighbour (nl, GNUNET_YES);
- return; /* nothing to do, never connected... */
- }
+ {
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# disconnects due to NO pong"),
+ 1, GNUNET_NO);
+ disconnect_neighbour (nl, GNUNET_YES);
+ return; /* nothing to do, never connected... */
+ }
/* check if we have any validated addresses left */
pos = rl->addresses;
while (pos != NULL)
+ {
+ if (GNUNET_YES == pos->validated)
{
- if (GNUNET_YES == pos->validated)
- {
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# try_fast_reconnect thanks
to validated_address"),
- 1,
- GNUNET_NO);
- try_fast_reconnect (p, nl);
- return;
- }
- pos = pos->next;
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# try_fast_reconnect thanks to
validated_address"),
+ 1, GNUNET_NO);
+ try_fast_reconnect (p, nl);
+ return;
}
+ pos = pos->next;
+ }
/* no valid addresses left, signal disconnect! */
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Disconnecting peer `%4s', %s\n",
- GNUNET_i2s(peer),
- "plugin_env_session_end");
+ "Disconnecting peer `%4s', %s\n",
+ GNUNET_i2s (peer), "plugin_env_session_end");
#endif
/* FIXME: This doesn't mean there are no addresses left for this PEER,
* it means there aren't any left for this PLUGIN/PEER combination! So
@@ -2574,8 +2534,8 @@
* --NE
*/
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# disconnects due to
plugin_env_session_end"),
- 1,
+ gettext_noop
+ ("# disconnects due to plugin_env_session_end"), 1,
GNUNET_NO);
disconnect_neighbour (nl, GNUNET_YES);
}
@@ -2594,9 +2554,7 @@
*/
static void
plugin_env_notify_address (void *cls,
- int add_remove,
- const void *addr,
- size_t addrlen)
+ int add_remove, const void *addr, size_t addrlen)
{
struct TransportPlugin *p = cls;
struct OwnAddressList *al;
@@ -2605,37 +2563,34 @@
GNUNET_assert (p->api != NULL);
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- (add_remove == GNUNET_YES)
- ? "Adding `%s':%s to the set of our addresses\n"
- : "Removing `%s':%s from the set of our addresses\n",
- a2s (p->short_name,
- addr, addrlen),
- p->short_name);
+ (add_remove == GNUNET_YES)
+ ? "Adding `%s':%s to the set of our addresses\n"
+ : "Removing `%s':%s from the set of our addresses\n",
+ a2s (p->short_name, addr, addrlen), p->short_name);
#endif
GNUNET_assert (addr != NULL);
if (GNUNET_NO == add_remove)
+ {
+ prev = NULL;
+ al = p->addresses;
+ while (al != NULL)
{
- prev = NULL;
- al = p->addresses;
- while (al != NULL)
- {
- if ( (addrlen == al->addrlen) &&
- (0 == memcmp (addr, &al[1], addrlen)) )
- {
- if (prev == NULL)
- p->addresses = al->next;
- else
- prev->next = al->next;
- GNUNET_free (al);
- refresh_hello ();
- return;
- }
- prev = al;
- al = al->next;
- }
- GNUNET_break (0);
- return;
+ if ((addrlen == al->addrlen) && (0 == memcmp (addr, &al[1], addrlen)))
+ {
+ if (prev == NULL)
+ p->addresses = al->next;
+ else
+ prev->next = al->next;
+ GNUNET_free (al);
+ refresh_hello ();
+ return;
+ }
+ prev = al;
+ al = al->next;
}
+ GNUNET_break (0);
+ return;
+ }
al = GNUNET_malloc (sizeof (struct OwnAddressList) + addrlen);
al->next = p->addresses;
p->addresses = al;
@@ -2650,38 +2605,35 @@
*/
static void
notify_clients_connect (const struct GNUNET_PeerIdentity *peer,
- struct GNUNET_TIME_Relative latency,
- uint32_t distance)
+ struct GNUNET_TIME_Relative latency, uint32_t distance)
{
- struct ConnectInfoMessage * cim;
+ struct ConnectInfoMessage *cim;
struct TransportClient *cpos;
uint32_t ats_count;
size_t size;
- if (0 == memcmp (peer,
- &my_identity,
- sizeof (struct GNUNET_PeerIdentity)))
- {
- GNUNET_break (0);
- return;
- }
+ if (0 == memcmp (peer, &my_identity, sizeof (struct GNUNET_PeerIdentity)))
+ {
+ GNUNET_break (0);
+ return;
+ }
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Notifying clients about connection with `%s'\n",
- GNUNET_i2s (peer));
+ "Notifying clients about connection with `%s'\n",
+ GNUNET_i2s (peer));
#endif
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# peers connected"),
- 1,
- GNUNET_NO);
+ gettext_noop ("# peers connected"), 1, GNUNET_NO);
ats_count = 2;
- size = sizeof (struct ConnectInfoMessage) + ats_count * sizeof (struct
GNUNET_TRANSPORT_ATS_Information);
+ size =
+ sizeof (struct ConnectInfoMessage) +
+ ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
GNUNET_assert (size < GNUNET_SERVER_MAX_MESSAGE_SIZE);
cim = GNUNET_malloc (size);
cim->header.size = htons (size);
cim->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
- cim->ats_count = htonl(2);
+ cim->ats_count = htonl (2);
(&cim->ats)[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE);
(&cim->ats)[0].value = htonl (distance);
(&cim->ats)[1].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY);
@@ -2692,18 +2644,18 @@
/* notify ats about connecting peer */
if ((ats != NULL) && (shutdown_in_progress == GNUNET_NO))
- {
+ {
#if HAVE_LIBGLPK
- ats_modify_problem_state(ats, ATS_MODIFIED);
- ats_calculate_bandwidth_distribution (ats);
+ ats_modify_problem_state (ats, ATS_MODIFIED);
+ ats_calculate_bandwidth_distribution (ats);
#endif
- }
+ }
cpos = clients;
while (cpos != NULL)
- {
- transmit_to_client (cpos, &cim->header, GNUNET_NO);
- cpos = cpos->next;
- }
+ {
+ transmit_to_client (cpos, &cim->header, GNUNET_NO);
+ cpos = cpos->next;
+ }
GNUNET_free (cim);
}
@@ -2717,22 +2669,18 @@
struct DisconnectInfoMessage dim;
struct TransportClient *cpos;
- if (0 == memcmp (peer,
- &my_identity,
- sizeof (struct GNUNET_PeerIdentity)))
- {
- GNUNET_break (0);
- return;
- }
+ if (0 == memcmp (peer, &my_identity, sizeof (struct GNUNET_PeerIdentity)))
+ {
+ GNUNET_break (0);
+ return;
+ }
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Notifying clients about lost connection to `%s'\n",
- GNUNET_i2s (peer));
+ "Notifying clients about lost connection to `%s'\n",
+ GNUNET_i2s (peer));
#endif
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# peers connected"),
- -1,
- GNUNET_NO);
+ gettext_noop ("# peers connected"), -1, GNUNET_NO);
dim.header.size = htons (sizeof (struct DisconnectInfoMessage));
dim.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT);
dim.reserved = htonl (0);
@@ -2742,17 +2690,17 @@
if ((ats != NULL) && (shutdown_in_progress == GNUNET_NO))
{
#if HAVE_LIBGLPK
- ats_modify_problem_state(ats, ATS_MODIFIED);
+ ats_modify_problem_state (ats, ATS_MODIFIED);
ats_calculate_bandwidth_distribution (ats);
#endif
}
cpos = clients;
while (cpos != NULL)
- {
- transmit_to_client (cpos, &dim.header, GNUNET_NO);
- cpos = cpos->next;
- }
+ {
+ transmit_to_client (cpos, &dim.header, GNUNET_NO);
+ cpos = cpos->next;
+ }
}
@@ -2770,36 +2718,33 @@
* @return NULL if no such entry exists
*/
static struct ForeignAddressList *
-find_peer_address(struct NeighbourMapEntry *neighbour,
- const char *tname,
- struct Session *session,
- const char *addr,
- uint16_t addrlen)
+find_peer_address (struct NeighbourMapEntry *neighbour,
+ const char *tname,
+ struct Session *session, const char *addr, uint16_t addrlen)
{
struct ReadyList *head;
struct ForeignAddressList *pos;
head = neighbour->plugins;
while (head != NULL)
- {
- if (0 == strcmp (tname, head->plugin->short_name))
- break;
- head = head->next;
- }
+ {
+ if (0 == strcmp (tname, head->plugin->short_name))
+ break;
+ head = head->next;
+ }
if (head == NULL)
return NULL;
pos = head->addresses;
- while ( (pos != NULL) &&
- ( (pos->addrlen != addrlen) ||
- (memcmp(pos->addr, addr, addrlen) != 0) ) )
- {
- if ( (session != NULL) &&
- (pos->session == session) )
- return pos;
- pos = pos->next;
- }
- if ( (session != NULL) && (pos != NULL) )
- pos->session = session; /* learn it! */
+ while ((pos != NULL) &&
+ ((pos->addrlen != addrlen) ||
+ (memcmp (pos->addr, addr, addrlen) != 0)))
+ {
+ if ((session != NULL) && (pos->session == session))
+ return pos;
+ pos = pos->next;
+ }
+ if ((session != NULL) && (pos != NULL))
+ pos->session = session; /* learn it! */
return pos;
}
@@ -2817,10 +2762,8 @@
*/
static struct ForeignAddressList *
add_peer_address (struct NeighbourMapEntry *neighbour,
- const char *tname,
- struct Session *session,
- const char *addr,
- uint16_t addrlen)
+ const char *tname,
+ struct Session *session, const char *addr, uint16_t addrlen)
{
struct ReadyList *head;
struct ForeignAddressList *ret;
@@ -2832,73 +2775,78 @@
head = neighbour->plugins;
while (head != NULL)
- {
- if (0 == strcmp (tname, head->plugin->short_name))
- break;
- head = head->next;
- }
+ {
+ if (0 == strcmp (tname, head->plugin->short_name))
+ break;
+ head = head->next;
+ }
if (head == NULL)
return NULL;
- ret = GNUNET_malloc(sizeof(struct ForeignAddressList) + addrlen);
+ ret = GNUNET_malloc (sizeof (struct ForeignAddressList) + addrlen);
ret->session = session;
if ((addrlen > 0) && (addr != NULL))
+ {
+ ret->addr = (const char *) &ret[1];
+ memcpy (&ret[1], addr, addrlen);
+ }
+ else
+ {
+ ret->addr = NULL;
+ }
+
+ ret->ressources =
+ GNUNET_malloc (available_ressources *
+ sizeof (struct ATS_ressource_entry));
+ for (c = 0; c < available_ressources; c++)
+ {
+ struct ATS_ressource_entry *r = ret->ressources;
+
+ r[c].index = c;
+ r[c].atis_index = ressources[c].atis_index;
+ if (0 == strcmp (neighbour->plugins->plugin->short_name, "unix"))
{
- ret->addr = (const char*) &ret[1];
- memcpy (&ret[1], addr, addrlen);
+ r[c].c = ressources[c].c_unix;
}
- else
+ else if (0 == strcmp (neighbour->plugins->plugin->short_name, "udp"))
{
- ret->addr = NULL;
+ r[c].c = ressources[c].c_udp;
}
-
- ret->ressources = GNUNET_malloc(available_ressources * sizeof (struct
ATS_ressource_entry));
- for (c=0; c<available_ressources; c++)
+ else if (0 == strcmp (neighbour->plugins->plugin->short_name, "tcp"))
{
- struct ATS_ressource_entry *r = ret->ressources;
- r[c].index = c;
- r[c].atis_index = ressources[c].atis_index;
- if (0 == strcmp(neighbour->plugins->plugin->short_name,"unix"))
- {
- r[c].c = ressources[c].c_unix;
- }
- else if (0 == strcmp(neighbour->plugins->plugin->short_name,"udp"))
- {
- r[c].c = ressources[c].c_udp;
- }
- else if (0 == strcmp(neighbour->plugins->plugin->short_name,"tcp"))
- {
- r[c].c = ressources[c].c_tcp;
- }
- else if (0 == strcmp(neighbour->plugins->plugin->short_name,"http"))
- {
- r[c].c = ressources[c].c_http;
- }
- else if (0 == strcmp(neighbour->plugins->plugin->short_name,"https"))
- {
- r[c].c = ressources[c].c_https;
- }
- else if (0 == strcmp(neighbour->plugins->plugin->short_name,"wlan"))
- {
- r[c].c = ressources[c].c_wlan;
- }
- else
- {
- r[c].c = ressources[c].c_default;
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Assigning default cost to peer `%s' addr plugin `%s'!
This should not happen!\n",
- GNUNET_i2s(&neighbour->id),
- neighbour->plugins->plugin->short_name);
- }
+ r[c].c = ressources[c].c_tcp;
}
+ else if (0 == strcmp (neighbour->plugins->plugin->short_name, "http"))
+ {
+ r[c].c = ressources[c].c_http;
+ }
+ else if (0 == strcmp (neighbour->plugins->plugin->short_name, "https"))
+ {
+ r[c].c = ressources[c].c_https;
+ }
+ else if (0 == strcmp (neighbour->plugins->plugin->short_name, "wlan"))
+ {
+ r[c].c = ressources[c].c_wlan;
+ }
+ else
+ {
+ r[c].c = ressources[c].c_default;
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Assigning default cost to peer `%s' addr plugin `%s'! This
should not happen!\n",
+ GNUNET_i2s (&neighbour->id),
+ neighbour->plugins->plugin->short_name);
+ }
+ }
- ret->quality = GNUNET_malloc (available_quality_metrics * sizeof (struct
ATS_quality_entry));
+ ret->quality =
+ GNUNET_malloc (available_quality_metrics *
+ sizeof (struct ATS_quality_entry));
ret->addrlen = addrlen;
ret->expires = GNUNET_TIME_relative_to_absolute
- (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
- ret->latency = GNUNET_TIME_relative_get_forever();
+ (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
+ ret->latency = GNUNET_TIME_relative_get_forever ();
ret->distance = -1;
ret->timeout = GNUNET_TIME_relative_to_absolute
- (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
+ (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
ret->ready_list = head;
ret->next = head->addresses;
head->addresses = ret;
@@ -2936,8 +2884,7 @@
* end of the iteration.
*/
static size_t
-add_validated_address (void *cls,
- size_t max, void *buf)
+add_validated_address (void *cls, size_t max, void *buf)
{
struct AddValidatedAddressContext *avac = cls;
const struct ValidationEntry *ve = avac->ve;
@@ -2946,11 +2893,9 @@
return 0;
avac->done = GNUNET_YES;
return GNUNET_HELLO_add_address (ve->transport_name,
- GNUNET_TIME_relative_to_absolute
(HELLO_ADDRESS_EXPIRATION),
- ve->addr,
- ve->addrlen,
- buf,
- max);
+ GNUNET_TIME_relative_to_absolute
+ (HELLO_ADDRESS_EXPIRATION), ve->addr,
+ ve->addrlen, buf, max);
}
@@ -3000,36 +2945,31 @@
* iterate (mismatch), GNUNET_NO if not (entry matched)
*/
static int
-check_address_exists (void *cls,
- const GNUNET_HashCode * key,
- void *value)
+check_address_exists (void *cls, const GNUNET_HashCode * key, void *value)
{
struct CheckAddressExistsClosure *caec = cls;
struct ValidationEntry *ve = value;
- if ( (0 == strcmp (caec->tname,
- ve->transport_name)) &&
- (caec->addrlen == ve->addrlen) &&
- (0 == memcmp (caec->addr,
- ve->addr,
- caec->addrlen)) )
- {
- caec->exists = GNUNET_YES;
- return GNUNET_NO;
- }
- if ( (ve->session != NULL) &&
- (caec->session == ve->session) )
- {
- caec->exists = GNUNET_YES;
- return GNUNET_NO;
- }
+ if ((0 == strcmp (caec->tname,
+ ve->transport_name)) &&
+ (caec->addrlen == ve->addrlen) &&
+ (0 == memcmp (caec->addr, ve->addr, caec->addrlen)))
+ {
+ caec->exists = GNUNET_YES;
+ return GNUNET_NO;
+ }
+ if ((ve->session != NULL) && (caec->session == ve->session))
+ {
+ caec->exists = GNUNET_YES;
+ return GNUNET_NO;
+ }
return GNUNET_YES;
}
static void
neighbour_timeout_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct NeighbourMapEntry *n = cls;
@@ -3038,9 +2978,8 @@
"Neighbour `%4s' has timed out!\n", GNUNET_i2s (&n->id));
#endif
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# disconnects due to timeout"),
- 1,
- GNUNET_NO);
+ gettext_noop ("# disconnects due to timeout"),
+ 1, GNUNET_NO);
n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
disconnect_neighbour (n, GNUNET_NO);
}
@@ -3052,8 +2991,7 @@
*
* @param fal address to PING
*/
-static void
-schedule_next_ping (struct ForeignAddressList *fal);
+static void schedule_next_ping (struct ForeignAddressList *fal);
/**
@@ -3069,77 +3007,71 @@
*/
static int
add_to_foreign_address_list (void *cls,
- const char *tname,
- struct GNUNET_TIME_Absolute expiration,
- const void *addr,
- uint16_t addrlen)
+ const char *tname,
+ struct GNUNET_TIME_Absolute expiration,
+ const void *addr, uint16_t addrlen)
{
struct NeighbourMapEntry *n = cls;
struct ForeignAddressList *fal;
int try;
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# valid peer addresses returned by
PEERINFO"),
- 1,
- GNUNET_NO);
+ gettext_noop
+ ("# valid peer addresses returned by PEERINFO"), 1,
+ GNUNET_NO);
try = GNUNET_NO;
fal = find_peer_address (n, tname, NULL, addr, addrlen);
if (fal == NULL)
- {
+ {
#if DEBUG_TRANSPORT_HELLO
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Adding address `%s' (%s) for peer `%4s' due to PEERINFO data
for %llums.\n",
- a2s (tname, addr, addrlen),
- tname,
- GNUNET_i2s (&n->id),
- expiration.abs_value);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Adding address `%s' (%s) for peer `%4s' due to PEERINFO data
for %llums.\n",
+ a2s (tname, addr, addrlen),
+ tname, GNUNET_i2s (&n->id), expiration.abs_value);
#endif
- fal = add_peer_address (n, tname, NULL, addr, addrlen);
- if (fal == NULL)
- {
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# previously validated
addresses lacking transport"),
- 1,
- GNUNET_NO);
- }
- else
- {
- fal->expires = GNUNET_TIME_absolute_max (expiration,
- fal->expires);
- schedule_next_ping (fal);
- }
- try = GNUNET_YES;
+ fal = add_peer_address (n, tname, NULL, addr, addrlen);
+ if (fal == NULL)
+ {
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# previously validated addresses lacking
transport"),
+ 1, GNUNET_NO);
}
- else
+ else
{
- fal->expires = GNUNET_TIME_absolute_max (expiration,
- fal->expires);
+ fal->expires = GNUNET_TIME_absolute_max (expiration, fal->expires);
+ schedule_next_ping (fal);
}
+ try = GNUNET_YES;
+ }
+ else
+ {
+ fal->expires = GNUNET_TIME_absolute_max (expiration, fal->expires);
+ }
if (fal == NULL)
- {
+ {
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Failed to add new address for `%4s'\n",
- GNUNET_i2s (&n->id));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to add new address for `%4s'\n", GNUNET_i2s (&n->id));
#endif
- return GNUNET_OK;
- }
+ return GNUNET_OK;
+ }
if (fal->validated == GNUNET_NO)
- {
- fal->validated = GNUNET_YES;
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# peer addresses considered
valid"),
- 1,
- GNUNET_NO);
- }
+ {
+ fal->validated = GNUNET_YES;
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# peer addresses considered valid"), 1,
+ GNUNET_NO);
+ }
if (try == GNUNET_YES)
- {
+ {
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Have new addresses, will try to trigger transmissions.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Have new addresses, will try to trigger transmissions.\n");
#endif
- try_transmission_to_peer (n);
- }
+ try_transmission_to_peer (n);
+ }
return GNUNET_OK;
}
@@ -3155,47 +3087,43 @@
*/
static void
add_hello_for_peer (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_HELLO_Message *h,
- const char *err_msg)
+ const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_HELLO_Message *h, const char *err_msg)
{
struct NeighbourMapEntry *n = cls;
if (err_msg != NULL)
- {
+ {
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Error in communication with PEERINFO service: %s\n"),
- err_msg);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ _("Error in communication with PEERINFO service: %s\n"),
+ err_msg);
#endif
- /* return; */
- }
+ /* return; */
+ }
if (peer == NULL)
- {
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# outstanding peerinfo iterate
requests"),
- -1,
- GNUNET_NO);
- n->piter = NULL;
- return;
- }
+ {
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# outstanding peerinfo iterate requests"), -1,
+ GNUNET_NO);
+ n->piter = NULL;
+ return;
+ }
if (h == NULL)
- return; /* no HELLO available */
+ return; /* no HELLO available */
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peerinfo had `%s' message for peer `%4s', adding existing
addresses.\n",
- "HELLO",
- GNUNET_i2s (peer));
+ "Peerinfo had `%s' message for peer `%4s', adding existing
addresses.\n",
+ "HELLO", GNUNET_i2s (peer));
#endif
if (GNUNET_YES != n->public_key_valid)
- {
- GNUNET_HELLO_get_key (h, &n->publicKey);
- n->public_key_valid = GNUNET_YES;
- }
+ {
+ GNUNET_HELLO_get_key (h, &n->publicKey);
+ n->public_key_valid = GNUNET_YES;
+ }
GNUNET_HELLO_iterate_addresses (h,
- GNUNET_NO,
- &add_to_foreign_address_list,
- n);
+ GNUNET_NO, &add_to_foreign_address_list, n);
}
@@ -3209,79 +3137,73 @@
* @return the new neighbour list entry
*/
static struct NeighbourMapEntry *
-setup_new_neighbour (const struct GNUNET_PeerIdentity *peer,
- int do_hello)
+setup_new_neighbour (const struct GNUNET_PeerIdentity *peer, int do_hello)
{
struct NeighbourMapEntry *n;
struct TransportPlugin *tp;
struct ReadyList *rl;
GNUNET_assert (0 != memcmp (peer,
- &my_identity,
- sizeof (struct GNUNET_PeerIdentity)));
+ &my_identity,
+ sizeof (struct GNUNET_PeerIdentity)));
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Setting up state for neighbour `%4s'\n",
- GNUNET_i2s (peer));
+ "Setting up state for neighbour `%4s'\n", GNUNET_i2s (peer));
#endif
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# active neighbours"),
- 1,
- GNUNET_NO);
+ gettext_noop ("# active neighbours"), 1,
GNUNET_NO);
n = GNUNET_malloc (sizeof (struct NeighbourMapEntry));
n->id = *peer;
n->peer_timeout =
- GNUNET_TIME_relative_to_absolute
- (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
+ GNUNET_TIME_relative_to_absolute
+ (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
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);
tp = plugins;
while (tp != NULL)
+ {
+ if ((tp->api->send != NULL) && (!is_blacklisted (peer, tp)))
{
- if ((tp->api->send != NULL) && (!is_blacklisted(peer, tp)))
- {
- rl = GNUNET_malloc (sizeof (struct ReadyList));
- rl->neighbour = n;
- rl->next = n->plugins;
- n->plugins = rl;
- rl->plugin = tp;
- rl->addresses = NULL;
- }
- tp = tp->next;
+ rl = GNUNET_malloc (sizeof (struct ReadyList));
+ rl->neighbour = n;
+ rl->next = n->plugins;
+ n->plugins = rl;
+ rl->plugin = tp;
+ rl->addresses = NULL;
}
+ tp = tp->next;
+ }
n->latency = GNUNET_TIME_UNIT_FOREVER_REL;
n->distance = -1;
- n->timeout_task = GNUNET_SCHEDULER_add_delayed
(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
- &neighbour_timeout_task, n);
- GNUNET_CONTAINER_multihashmap_put (neighbours,
- &n->id.hashPubKey,
- n,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+ n->timeout_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
+ &neighbour_timeout_task, n);
+ GNUNET_CONTAINER_multihashmap_put (neighbours, &n->id.hashPubKey, n,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
if (do_hello)
- {
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# peerinfo new neighbor iterate
requests"),
- 1,
- GNUNET_NO);
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# outstanding peerinfo iterate
requests"),
- 1,
- GNUNET_NO);
- n->piter = GNUNET_PEERINFO_iterate (peerinfo, peer,
- GNUNET_TIME_UNIT_FOREVER_REL,
- &add_hello_for_peer, n);
+ {
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# peerinfo new neighbor iterate requests"), 1,
+ GNUNET_NO);
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# outstanding peerinfo iterate requests"), 1,
+ GNUNET_NO);
+ n->piter =
+ GNUNET_PEERINFO_iterate (peerinfo, peer, GNUNET_TIME_UNIT_FOREVER_REL,
+ &add_hello_for_peer, n);
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# HELLO's sent to new
neighbors"),
- 1,
- GNUNET_NO);
- if (NULL != our_hello)
- transmit_to_peer (NULL, NULL, 0,
- HELLO_ADDRESS_EXPIRATION,
- (const char *) our_hello,
GNUNET_HELLO_size(our_hello),
- GNUNET_NO, n);
- }
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# HELLO's sent to new neighbors"),
+ 1, GNUNET_NO);
+ if (NULL != our_hello)
+ transmit_to_peer (NULL, NULL, 0,
+ HELLO_ADDRESS_EXPIRATION,
+ (const char *) our_hello, GNUNET_HELLO_size
(our_hello),
+ GNUNET_NO, n);
+ }
return n;
}
@@ -3293,8 +3215,7 @@
* @param cls closure
* @param n NULL if communication is not acceptable
*/
-typedef void (*SetupContinuation)(void *cls,
- struct NeighbourMapEntry *n);
+typedef void (*SetupContinuation) (void *cls, struct NeighbourMapEntry * n);
/**
@@ -3409,8 +3330,7 @@
* @param tc unused
*/
static void
-do_blacklist_check (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+do_blacklist_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
/**
* Transmit blacklist query to the client.
@@ -3421,9 +3341,7 @@
* @return number of bytes copied to buf
*/
static size_t
-transmit_blacklist_message (void *cls,
- size_t size,
- void *buf)
+transmit_blacklist_message (void *cls, size_t size, void *buf)
{
struct BlacklistCheck *bc = cls;
struct Blacklisters *bl;
@@ -3431,19 +3349,18 @@
bc->th = NULL;
if (size == 0)
- {
- GNUNET_assert (bc->task == GNUNET_SCHEDULER_NO_TASK);
- bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check,
- bc);
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Failed to send blacklist test for peer `%s' to client\n",
- GNUNET_i2s (&bc->peer));
- return 0;
- }
+ {
+ GNUNET_assert (bc->task == GNUNET_SCHEDULER_NO_TASK);
+ bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to send blacklist test for peer `%s' to client\n",
+ GNUNET_i2s (&bc->peer));
+ return 0;
+ }
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending blacklist test for peer `%s' to client\n",
- GNUNET_i2s (&bc->peer));
+ "Sending blacklist test for peer `%s' to client\n",
+ GNUNET_i2s (&bc->peer));
#endif
bl = bc->bl_pos;
bm.header.size = htons (sizeof (struct BlacklistMessage));
@@ -3463,8 +3380,7 @@
* @param tc unused
*/
static void
-do_blacklist_check (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_blacklist_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct BlacklistCheck *bc = cls;
struct Blacklisters *bl;
@@ -3472,26 +3388,26 @@
bc->task = GNUNET_SCHEDULER_NO_TASK;
bl = bc->bl_pos;
if (bl == NULL)
- {
+ {
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "No blacklist clients active, will now setup neighbour record
for peer `%s'\n",
- GNUNET_i2s (&bc->peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "No blacklist clients active, will now setup neighbour record
for peer `%s'\n",
+ GNUNET_i2s (&bc->peer));
#endif
- bc->cont (bc->cont_cls,
- setup_new_neighbour (&bc->peer, bc->do_hello));
- GNUNET_free (bc);
- return;
- }
+ bc->cont (bc->cont_cls, setup_new_neighbour (&bc->peer, bc->do_hello));
+ GNUNET_free (bc);
+ return;
+ }
if (bl->bc == NULL)
- {
- bl->bc = bc;
- bc->th = GNUNET_SERVER_notify_transmit_ready (bl->client,
- sizeof (struct
BlacklistMessage),
-
GNUNET_TIME_UNIT_FOREVER_REL,
- &transmit_blacklist_message,
- bc);
- }
+ {
+ bl->bc = bc;
+ bc->th = GNUNET_SERVER_notify_transmit_ready (bl->client,
+ sizeof (struct
+ BlacklistMessage),
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &transmit_blacklist_message,
+ bc);
+ }
}
@@ -3509,33 +3425,31 @@
*/
static void
setup_peer_check_blacklist (const struct GNUNET_PeerIdentity *peer,
- int do_hello,
- SetupContinuation cont,
- void *cont_cls)
+ int do_hello,
+ SetupContinuation cont, void *cont_cls)
{
struct NeighbourMapEntry *n;
struct BlacklistCheck *bc;
- n = find_neighbour(peer);
+ n = find_neighbour (peer);
if (n != NULL)
- {
+ {
#if DEBUG_TRANSPORT
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Neighbour record exists for peer `%s'\n",
- GNUNET_i2s(peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Neighbour record exists for peer `%s'\n", GNUNET_i2s (peer));
#endif
- if (cont != NULL)
- cont (cont_cls, n);
- return;
- }
+ if (cont != NULL)
+ cont (cont_cls, n);
+ return;
+ }
if (bl_head == NULL)
- {
- if (cont != NULL)
- cont (cont_cls, setup_new_neighbour (peer, do_hello));
- else
- setup_new_neighbour(peer, do_hello);
- return;
- }
+ {
+ if (cont != NULL)
+ cont (cont_cls, setup_new_neighbour (peer, do_hello));
+ else
+ setup_new_neighbour (peer, do_hello);
+ return;
+ }
bc = GNUNET_malloc (sizeof (struct BlacklistCheck));
GNUNET_CONTAINER_DLL_insert (bc_head, bc_tail, bc);
bc->peer = *peer;
@@ -3543,8 +3457,7 @@
bc->cont = cont;
bc->cont_cls = cont_cls;
bc->bl_pos = bl_head;
- bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check,
- bc);
+ bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc);
}
@@ -3556,24 +3469,22 @@
* @param n NULL if we need to disconnect
*/
static void
-confirm_or_drop_neighbour (void *cls,
- struct NeighbourMapEntry *n)
+confirm_or_drop_neighbour (void *cls, struct NeighbourMapEntry *n)
{
- struct NeighbourMapEntry * orig = cls;
+ struct NeighbourMapEntry *orig = cls;
if (n == NULL)
- {
+ {
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Disconnecting peer `%4s', %s\n", GNUNET_i2s(&orig->id),
- "confirm_or_drop_neighboUr");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Disconnecting peer `%4s', %s\n", GNUNET_i2s (&orig->id),
+ "confirm_or_drop_neighboUr");
#endif
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# disconnects due to
blacklist"),
- 1,
- GNUNET_NO);
- disconnect_neighbour (orig, GNUNET_NO);
- }
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# disconnects due to blacklist"),
+ 1, GNUNET_NO);
+ disconnect_neighbour (orig, GNUNET_NO);
+ }
}
@@ -3586,15 +3497,13 @@
static int
-test_connection_ok (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+test_connection_ok (void *cls, const GNUNET_HashCode * key, void *value)
{
struct TestConnectionContext *tcc = cls;
struct NeighbourMapEntry *n = value;
struct BlacklistCheck *bc;
-
+
bc = GNUNET_malloc (sizeof (struct BlacklistCheck));
GNUNET_CONTAINER_DLL_insert (bc_head, bc_tail, bc);
bc->peer = n->id;
@@ -3603,13 +3512,12 @@
bc->cont_cls = n;
bc->bl_pos = tcc->bl;
if (GNUNET_YES == tcc->first)
- {
- /* all would wait for the same client, no need to
- create more than just the first task right now */
- bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check,
- bc);
- tcc->first = GNUNET_NO;
- }
+ {
+ /* all would wait for the same client, no need to
+ * create more than just the first task right now */
+ bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc);
+ tcc->first = GNUNET_NO;
+ }
return GNUNET_OK;
}
@@ -3623,23 +3531,23 @@
*/
static void
handle_blacklist_init (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
struct Blacklisters *bl;
struct TestConnectionContext tcc;
bl = bl_head;
while (bl != NULL)
+ {
+ if (bl->client == client)
{
- if (bl->client == client)
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
- bl = bl->next;
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
}
+ bl = bl->next;
+ }
bl = GNUNET_malloc (sizeof (struct Blacklisters));
bl->client = client;
GNUNET_SERVER_client_keep (client);
@@ -3647,9 +3555,7 @@
/* confirm that all existing connections are OK! */
tcc.bl = bl;
tcc.first = GNUNET_YES;
- GNUNET_CONTAINER_multihashmap_iterate (neighbours,
- &test_connection_ok,
- &tcc);
+ GNUNET_CONTAINER_multihashmap_iterate (neighbours, &test_connection_ok,
&tcc);
}
@@ -3662,59 +3568,55 @@
*/
static void
handle_blacklist_reply (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
- const struct BlacklistMessage *msg = (const struct BlacklistMessage*)
message;
+ const struct BlacklistMessage *msg =
+ (const struct BlacklistMessage *) message;
struct Blacklisters *bl;
struct BlacklistCheck *bc;
bl = bl_head;
- while ( (bl != NULL) &&
- (bl->client != client) )
+ while ((bl != NULL) && (bl->client != client))
bl = bl->next;
if (bl == NULL)
- {
+ {
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Blacklist client disconnected\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Blacklist client disconnected\n");
#endif
- /* FIXME: other error handling here!? */
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ /* FIXME: other error handling here!? */
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
bc = bl->bc;
bl->bc = NULL;
if (ntohl (msg->is_allowed) == GNUNET_SYSERR)
- {
+ {
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Blacklist check failed, peer not allowed\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Blacklist check failed, peer not allowed\n");
#endif
- bc->cont (bc->cont_cls, NULL);
- GNUNET_CONTAINER_DLL_remove (bc_head, bc_tail, bc);
- GNUNET_free (bc);
- }
+ bc->cont (bc->cont_cls, NULL);
+ GNUNET_CONTAINER_DLL_remove (bc_head, bc_tail, bc);
+ GNUNET_free (bc);
+ }
else
- {
+ {
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Blacklist check succeeded, continuing with checks\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Blacklist check succeeded, continuing with checks\n");
#endif
- bc->bl_pos = bc->bl_pos->next;
- bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check,
- bc);
- }
+ bc->bl_pos = bc->bl_pos->next;
+ bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc);
+ }
/* check if any other bc's are waiting for this blacklister */
bc = bc_head;
while (bc != NULL)
- {
- if ( (bc->bl_pos == bl) &&
- (GNUNET_SCHEDULER_NO_TASK == bc->task) )
- bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check,
- bc);
- bc = bc->next;
- }
+ {
+ if ((bc->bl_pos == bl) && (GNUNET_SCHEDULER_NO_TASK == bc->task))
+ bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc);
+ bc = bc->next;
+ }
}
@@ -3725,8 +3627,7 @@
* @param tc task context
*/
static void
-send_periodic_ping (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+send_periodic_ping (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct ForeignAddressList *peer_address = cls;
struct TransportPlugin *tp;
@@ -3734,23 +3635,23 @@
struct NeighbourMapEntry *neighbour;
struct TransportPingMessage ping;
struct CheckAddressExistsClosure caec;
- char * message_buf;
+ char *message_buf;
uint16_t hello_size;
size_t slen;
size_t tsize;
peer_address->revalidate_task = GNUNET_SCHEDULER_NO_TASK;
- if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
+ if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
return;
GNUNET_assert (peer_address != NULL);
tp = peer_address->ready_list->plugin;
neighbour = peer_address->ready_list->neighbour;
if (GNUNET_YES != neighbour->public_key_valid)
- {
- /* no public key yet, try again later */
- schedule_next_ping (peer_address);
- return;
- }
+ {
+ /* no public key yet, try again later */
+ schedule_next_ping (peer_address);
+ return;
+ }
caec.addr = peer_address->addr;
caec.addrlen = peer_address->addrlen;
caec.tname = tp->short_name;
@@ -3758,43 +3659,40 @@
caec.exists = GNUNET_NO;
GNUNET_CONTAINER_multihashmap_iterate (validation_map,
- &check_address_exists,
- &caec);
+ &check_address_exists, &caec);
if (caec.exists == GNUNET_YES)
- {
- /* During validation attempts we will likely trigger the other
- peer trying to validate our address which in turn will cause
- it to send us its HELLO, so we expect to hit this case rather
- frequently. Only print something if we are very verbose. */
+ {
+ /* During validation attempts we will likely trigger the other
+ * peer trying to validate our address which in turn will cause
+ * it to send us its HELLO, so we expect to hit this case rather
+ * frequently. Only print something if we are very verbose. */
#if DEBUG_TRANSPORT > 1
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Some validation of address `%s' via `%s' for peer `%4s'
already in progress.\n",
- (peer_address->addr != NULL)
- ? a2s (tp->short_name,
- peer_address->addr,
- peer_address->addrlen)
- : "<inbound>",
- tp->short_name,
- GNUNET_i2s (&neighbour->id));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Some validation of address `%s' via `%s' for peer `%4s'
already in progress.\n",
+ (peer_address->addr != NULL)
+ ? a2s (tp->short_name,
+ peer_address->addr,
+ peer_address->addrlen)
+ : "<inbound>", tp->short_name, GNUNET_i2s (&neighbour->id));
#endif
- schedule_next_ping (peer_address);
- return;
- }
+ schedule_next_ping (peer_address);
+ return;
+ }
va = GNUNET_malloc (sizeof (struct ValidationEntry) + peer_address->addrlen);
va->transport_name = GNUNET_strdup (tp->short_name);
va->challenge = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
UINT_MAX);
- va->send_time = GNUNET_TIME_absolute_get();
+ va->send_time = GNUNET_TIME_absolute_get ();
va->session = peer_address->session;
if (peer_address->addr != NULL)
- {
- va->addr = (const void*) &va[1];
- memcpy (&va[1], peer_address->addr, peer_address->addrlen);
- va->addrlen = peer_address->addrlen;
- }
- memcpy(&va->publicKey,
- &neighbour->publicKey,
- sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
+ {
+ va->addr = (const void *) &va[1];
+ memcpy (&va[1], peer_address->addr, peer_address->addrlen);
+ va->addrlen = peer_address->addrlen;
+ }
+ memcpy (&va->publicKey,
+ &neighbour->publicKey,
+ sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
va->timeout_task = GNUNET_SCHEDULER_add_delayed (HELLO_VERIFICATION_TIMEOUT,
&timeout_hello_validation,
@@ -3805,83 +3703,75 @@
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
if (peer_address->validated != GNUNET_YES)
- hello_size = GNUNET_HELLO_size(our_hello);
+ hello_size = GNUNET_HELLO_size (our_hello);
else
hello_size = 0;
- tsize = sizeof(struct TransportPingMessage) + hello_size;
+ tsize = sizeof (struct TransportPingMessage) + hello_size;
if (peer_address->addr != NULL)
- {
- slen = strlen (tp->short_name) + 1;
- tsize += slen + peer_address->addrlen;
- }
+ {
+ slen = strlen (tp->short_name) + 1;
+ tsize += slen + peer_address->addrlen;
+ }
else
- {
- slen = 0; /* make gcc happy */
- }
- message_buf = GNUNET_malloc(tsize);
- ping.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_PING);
- ping.challenge = htonl(va->challenge);
- memcpy(&ping.target, &neighbour->id, sizeof(struct GNUNET_PeerIdentity));
+ {
+ slen = 0; /* make gcc happy */
+ }
+ message_buf = GNUNET_malloc (tsize);
+ ping.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PING);
+ ping.challenge = htonl (va->challenge);
+ memcpy (&ping.target, &neighbour->id, sizeof (struct GNUNET_PeerIdentity));
if (peer_address->validated != GNUNET_YES)
- {
- memcpy(message_buf, our_hello, hello_size);
- }
+ {
+ memcpy (message_buf, our_hello, hello_size);
+ }
if (peer_address->addr != NULL)
- {
- ping.header.size = htons(sizeof(struct TransportPingMessage) +
- peer_address->addrlen +
- slen);
- memcpy(&message_buf[hello_size + sizeof (struct TransportPingMessage)],
- tp->short_name,
- slen);
- memcpy(&message_buf[hello_size + sizeof (struct TransportPingMessage) +
slen],
- peer_address->addr,
- peer_address->addrlen);
- }
+ {
+ ping.header.size = htons (sizeof (struct TransportPingMessage) +
+ peer_address->addrlen + slen);
+ memcpy (&message_buf[hello_size + sizeof (struct TransportPingMessage)],
+ tp->short_name, slen);
+ memcpy (&message_buf
+ [hello_size + sizeof (struct TransportPingMessage) + slen],
+ peer_address->addr, peer_address->addrlen);
+ }
else
- {
- ping.header.size = htons(sizeof(struct TransportPingMessage));
- }
+ {
+ ping.header.size = htons (sizeof (struct TransportPingMessage));
+ }
- memcpy(&message_buf[hello_size],
- &ping,
- sizeof(struct TransportPingMessage));
+ memcpy (&message_buf[hello_size],
+ &ping, sizeof (struct TransportPingMessage));
#if DEBUG_TRANSPORT_REVALIDATION
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Performing re-validation of address `%s' via `%s' for peer
`%4s' sending `%s' (%u bytes) and `%s'\n",
(peer_address->addr != NULL)
- ? a2s (peer_address->plugin->short_name,
- peer_address->addr,
- peer_address->addrlen)
- : "<inbound>",
+ ? a2s (peer_address->plugin->short_name,
+ peer_address->addr,
+ peer_address->addrlen)
+ : "<inbound>",
tp->short_name,
- GNUNET_i2s (&neighbour->id),
- "HELLO", hello_size,
- "PING");
+ GNUNET_i2s (&neighbour->id), "HELLO", hello_size, "PING");
#endif
if (peer_address->validated != GNUNET_YES)
GNUNET_STATISTICS_update (stats,
gettext_noop ("# PING with HELLO messages sent"),
- 1,
- GNUNET_NO);
+ 1, GNUNET_NO);
else
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# PING without HELLO messages
sent"),
- 1,
+ gettext_noop
+ ("# PING without HELLO messages sent"), 1,
GNUNET_NO);
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# PING messages sent for
re-validation"),
- 1,
- GNUNET_NO);
- transmit_to_peer (NULL, peer_address,
- GNUNET_SCHEDULER_PRIORITY_DEFAULT,
- HELLO_VERIFICATION_TIMEOUT,
- message_buf, tsize,
- GNUNET_YES, neighbour);
+ gettext_noop
+ ("# PING messages sent for re-validation"), 1,
+ GNUNET_NO);
+ transmit_to_peer (NULL, peer_address, GNUNET_SCHEDULER_PRIORITY_DEFAULT,
+ HELLO_VERIFICATION_TIMEOUT, message_buf, tsize, GNUNET_YES,
+ neighbour);
GNUNET_free (message_buf);
schedule_next_ping (peer_address);
}
@@ -3899,37 +3789,36 @@
struct GNUNET_TIME_Relative delay;
if (fal->revalidate_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel(fal->revalidate_task);
- fal->revalidate_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (fal->revalidate_task);
+ fal->revalidate_task = GNUNET_SCHEDULER_NO_TASK;
+ }
delay = GNUNET_TIME_absolute_get_remaining (fal->expires);
- delay.rel_value /= 2; /* do before expiration */
- delay = GNUNET_TIME_relative_min (delay,
- LATENCY_EVALUATION_MAX_DELAY);
+ delay.rel_value /= 2; /* do before expiration */
+ delay = GNUNET_TIME_relative_min (delay, LATENCY_EVALUATION_MAX_DELAY);
if (GNUNET_YES != fal->estimated)
- {
- delay = GNUNET_TIME_UNIT_ZERO;
- fal->estimated = GNUNET_YES;
- }
+ {
+ delay = GNUNET_TIME_UNIT_ZERO;
+ fal->estimated = GNUNET_YES;
+ }
if (GNUNET_YES == fal->connected)
- {
- delay = GNUNET_TIME_relative_min (delay,
- CONNECTED_LATENCY_EVALUATION_MAX_DELAY);
- }
+ {
+ delay = GNUNET_TIME_relative_min (delay,
+ CONNECTED_LATENCY_EVALUATION_MAX_DELAY);
+ }
/* FIXME: also adjust delay based on how close the last
- observed latency is to the latency of the best alternative */
+ * observed latency is to the latency of the best alternative */
/* bound how fast we can go */
- delay = GNUNET_TIME_relative_max (delay,
- GNUNET_TIME_UNIT_SECONDS);
+ delay = GNUNET_TIME_relative_max (delay, GNUNET_TIME_UNIT_SECONDS);
/* randomize a bit (to avoid doing all at the same time) */
- delay.rel_value += GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
1000);
+ delay.rel_value +=
+ GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1000);
GNUNET_assert (fal->revalidate_task == GNUNET_SCHEDULER_NO_TASK);
- fal->revalidate_task = GNUNET_SCHEDULER_add_delayed(delay,
- &send_periodic_ping,
- fal);
+ fal->revalidate_task = GNUNET_SCHEDULER_add_delayed (delay,
+ &send_periodic_ping,
+ fal);
}
@@ -3944,7 +3833,7 @@
*/
static void
handle_payload_message (const struct GNUNET_MessageHeader *message,
- struct NeighbourMapEntry *n)
+ struct NeighbourMapEntry *n)
{
struct InboundMessage *im;
struct TransportClient *cpos;
@@ -3952,66 +3841,64 @@
msize = ntohs (message->size);
if (n->received_pong == GNUNET_NO)
- {
+ {
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received message of type %u and size %u from `%4s', but no
pong yet!\n",
- ntohs (message->type),
- ntohs (message->size),
- GNUNET_i2s (&n->id));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received message of type %u and size %u from `%4s', but no
pong yet!\n",
+ ntohs (message->type),
+ ntohs (message->size), GNUNET_i2s (&n->id));
#endif
- GNUNET_free_non_null (n->pre_connect_message_buffer);
- n->pre_connect_message_buffer = GNUNET_malloc (msize);
- memcpy (n->pre_connect_message_buffer, message, msize);
- return;
- }
+ GNUNET_free_non_null (n->pre_connect_message_buffer);
+ n->pre_connect_message_buffer = GNUNET_malloc (msize);
+ memcpy (n->pre_connect_message_buffer, message, msize);
+ return;
+ }
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received message of type %u and size %u from `%4s', sending to
all clients.\n",
- ntohs (message->type),
- ntohs (message->size),
- GNUNET_i2s (&n->id));
+ "Received message of type %u and size %u from `%4s', sending to
all clients.\n",
+ ntohs (message->type),
+ ntohs (message->size), GNUNET_i2s (&n->id));
#endif
if (GNUNET_YES == GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker,
- (ssize_t) msize))
- {
- n->quota_violation_count++;
+ (ssize_t) msize))
+ {
+ n->quota_violation_count++;
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Bandwidth quota (%u b/s) violation detected (total of
%u).\n",
- n->in_tracker.available_bytes_per_s__,
- n->quota_violation_count);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Bandwidth quota (%u b/s) violation detected (total of %u).\n",
+ n->in_tracker.available_bytes_per_s__,
+ n->quota_violation_count);
#endif
- /* Discount 32k per violation */
- GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker,
- - 32 * 1024);
- }
+ /* Discount 32k per violation */
+ GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker, -32 * 1024);
+ }
else
+ {
+ if (n->quota_violation_count > 0)
{
- if (n->quota_violation_count > 0)
- {
- /* try to add 32k back */
- GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker,
- 32 * 1024);
- n->quota_violation_count--;
- }
+ /* try to add 32k back */
+ GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker, 32 * 1024);
+ n->quota_violation_count--;
}
+ }
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# payload received from other
peers"),
- msize,
- GNUNET_NO);
+ gettext_noop
+ ("# payload received from other peers"), msize,
+ GNUNET_NO);
/* transmit message to all clients */
uint32_t ats_count = 2;
- size_t size = sizeof (struct InboundMessage) + ats_count * sizeof (struct
GNUNET_TRANSPORT_ATS_Information) + msize;
+ size_t size =
+ sizeof (struct InboundMessage) +
+ ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information) + msize;
if (size > GNUNET_SERVER_MAX_MESSAGE_SIZE)
- GNUNET_break(0);
+ GNUNET_break (0);
im = GNUNET_malloc (size);
im->header.size = htons (size);
im->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RECV);
im->peer = n->id;
- im->ats_count = htonl(ats_count);
+ im->ats_count = htonl (ats_count);
/* Setting ATS data */
(&(im->ats))[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE);
(&(im->ats))[0].value = htonl (n->distance);
@@ -4020,13 +3907,13 @@
(&(im->ats))[ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
(&(im->ats))[ats_count].value = htonl (0);
- memcpy (&((&(im->ats))[ats_count+1]), message, msize);
+ memcpy (&((&(im->ats))[ats_count + 1]), message, msize);
cpos = clients;
while (cpos != NULL)
- {
- transmit_to_client (cpos, &im->header, GNUNET_YES);
- cpos = cpos->next;
- }
+ {
+ transmit_to_client (cpos, &im->header, GNUNET_YES);
+ cpos = cpos->next;
+ }
GNUNET_free (im);
}
@@ -4042,14 +3929,12 @@
* iterate (mismatch), GNUNET_NO if not (entry matched)
*/
static int
-check_pending_validation (void *cls,
- const GNUNET_HashCode * key,
- void *value)
+check_pending_validation (void *cls, const GNUNET_HashCode * key, void *value)
{
const struct TransportPongMessage *pong = cls;
struct ValidationEntry *ve = value;
struct AddValidatedAddressContext avac;
- unsigned int challenge = ntohl(pong->challenge);
+ unsigned int challenge = ntohl (pong->challenge);
struct GNUNET_HELLO_Message *hello;
struct GNUNET_PeerIdentity target;
struct NeighbourMapEntry *n;
@@ -4064,217 +3949,201 @@
ps = ntohs (pong->header.size);
if (ps < sizeof (struct TransportPongMessage))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_NO;
+ }
+ addr = (const char *) &pong[1];
+ slen = strlen (ve->transport_name) + 1;
+ if ((ps - sizeof (struct TransportPongMessage) < slen) ||
+ (ve->challenge != challenge) ||
+ (addr[slen - 1] != '\0') ||
+ (0 != strcmp (addr, ve->transport_name)) ||
+ (ntohl (pong->purpose.size)
+ != sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
+ sizeof (uint32_t) +
+ sizeof (struct GNUNET_TIME_AbsoluteNBO) +
+ sizeof (struct GNUNET_PeerIdentity) + ps -
+ sizeof (struct TransportPongMessage)))
+ {
+ return GNUNET_YES;
+ }
+
+ alen = ps - sizeof (struct TransportPongMessage) - slen;
+ switch (ntohl (pong->purpose.purpose))
+ {
+ case GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN:
+ if ((ve->addrlen + slen != ntohl (pong->addrlen)) ||
+ (0 != memcmp (&addr[slen], ve->addr, ve->addrlen)))
{
+ return GNUNET_YES; /* different entry, keep trying! */
+ }
+ if (0 != memcmp (&pong->pid, key, sizeof (struct GNUNET_PeerIdentity)))
+ {
GNUNET_break_op (0);
return GNUNET_NO;
}
- addr = (const char*) &pong[1];
- slen = strlen (ve->transport_name) + 1;
- if ( (ps - sizeof (struct TransportPongMessage) < slen) ||
- (ve->challenge != challenge) ||
- (addr[slen-1] != '\0') ||
- (0 != strcmp (addr, ve->transport_name)) ||
- (ntohl (pong->purpose.size)
- != sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
- sizeof (uint32_t) +
- sizeof (struct GNUNET_TIME_AbsoluteNBO) +
- sizeof (struct GNUNET_PeerIdentity) + ps - sizeof (struct
TransportPongMessage)) )
+ if (GNUNET_OK !=
+ GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN,
+ &pong->purpose,
+ &pong->signature, &ve->publicKey))
{
- return GNUNET_YES;
+ GNUNET_break_op (0);
+ return GNUNET_NO;
}
- alen = ps - sizeof (struct TransportPongMessage) - slen;
- switch (ntohl (pong->purpose.purpose))
- {
- case GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN:
- if ( (ve->addrlen + slen != ntohl (pong->addrlen)) ||
- (0 != memcmp (&addr[slen],
- ve->addr,
- ve->addrlen)) )
- {
- return GNUNET_YES; /* different entry, keep trying! */
- }
- if (0 != memcmp (&pong->pid,
- key,
- sizeof (struct GNUNET_PeerIdentity)))
- {
- GNUNET_break_op (0);
- return GNUNET_NO;
- }
- if (GNUNET_OK !=
- GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN,
- &pong->purpose,
- &pong->signature,
- &ve->publicKey))
- {
- GNUNET_break_op (0);
- return GNUNET_NO;
- }
-
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Confirmed validity of address, peer `%4s' has address `%s'
(%s).\n",
- GNUNET_h2s (key),
- a2s (ve->transport_name,
- (const struct sockaddr *) ve->addr,
- ve->addrlen),
- ve->transport_name);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Confirmed validity of address, peer `%4s' has address `%s'
(%s).\n",
+ GNUNET_h2s (key),
+ a2s (ve->transport_name,
+ (const struct sockaddr *) ve->addr,
+ ve->addrlen), ve->transport_name);
#endif
- break;
- case GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_USING:
- if (0 != memcmp (&pong->pid,
- &my_identity,
- sizeof (struct GNUNET_PeerIdentity)))
- {
- char * peer;
+ break;
+ case GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_USING:
+ if (0 != memcmp (&pong->pid,
+ &my_identity, sizeof (struct GNUNET_PeerIdentity)))
+ {
+ char *peer;
- GNUNET_asprintf(&peer, "%s",GNUNET_i2s (&pong->pid));
+ GNUNET_asprintf (&peer, "%s", GNUNET_i2s (&pong->pid));
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received PONG for different identity: I am `%s', PONG
identity: `%s'\n",
- GNUNET_i2s (&my_identity),
- peer );
-#endif
- GNUNET_free (peer);
- return GNUNET_NO;
- }
- if (ve->addrlen != 0)
- {
- /* must have been for a different validation entry */
- return GNUNET_YES;
- }
- tp = find_transport (ve->transport_name);
- if (tp == NULL)
- {
- GNUNET_break (0);
- return GNUNET_YES;
- }
- oal = tp->addresses;
- while (NULL != oal)
- {
- if ( (oal->addrlen == alen) &&
- (0 == memcmp (&oal[1],
- &addr[slen],
- alen)) )
- break;
- oal = oal->next;
- }
- if (oal == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Not accepting PONG from `%s' with address `%s' since I
cannot confirm using this address.\n"),
- GNUNET_i2s (&pong->pid),
- a2s (ve->transport_name,
- &addr[slen],
- alen));
- /* FIXME: since the sender of the PONG currently uses the
- wrong address (see FIMXE there!), we cannot run a
- proper check here... */
-#if FIXME_URGENT
- return GNUNET_NO;
-#endif
- }
- if (GNUNET_OK !=
- GNUNET_CRYPTO_rsa_verify
(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_USING,
- &pong->purpose,
- &pong->signature,
- &ve->publicKey))
- {
- GNUNET_break_op (0);
- return GNUNET_NO;
- }
-
-#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Confirmed that peer `%4s' is talking to us using address
`%s' (%s) for us.\n",
- GNUNET_h2s (key),
- a2s (ve->transport_name,
- &addr[slen],
- alen),
- ve->transport_name);
+ "Received PONG for different identity: I am `%s', PONG
identity: `%s'\n",
+ GNUNET_i2s (&my_identity), peer);
#endif
- break;
- default:
- GNUNET_break_op (0);
+ GNUNET_free (peer);
return GNUNET_NO;
}
- if (GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh
(pong->expiration)).rel_value == 0)
+ if (ve->addrlen != 0)
{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Received expired signature. Check system time.\n"));
+ /* must have been for a different validation entry */
+ return GNUNET_YES;
+ }
+ tp = find_transport (ve->transport_name);
+ if (tp == NULL)
+ {
+ GNUNET_break (0);
+ return GNUNET_YES;
+ }
+ oal = tp->addresses;
+ while (NULL != oal)
+ {
+ if ((oal->addrlen == alen) && (0 == memcmp (&oal[1], &addr[slen], alen)))
+ break;
+ oal = oal->next;
+ }
+ if (oal == NULL)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Not accepting PONG from `%s' with address `%s' since I
cannot confirm using this address.\n"),
+ GNUNET_i2s (&pong->pid), a2s (ve->transport_name,
&addr[slen],
+ alen));
+ /* FIXME: since the sender of the PONG currently uses the
+ * wrong address (see FIMXE there!), we cannot run a
+ * proper check here... */
+#if FIXME_URGENT
return GNUNET_NO;
+#endif
}
+ if (GNUNET_OK !=
+ GNUNET_CRYPTO_rsa_verify
(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_USING,
+ &pong->purpose,
+ &pong->signature, &ve->publicKey))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_NO;
+ }
+
+#if DEBUG_TRANSPORT
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Confirmed that peer `%4s' is talking to us using address `%s'
(%s) for us.\n",
+ GNUNET_h2s (key),
+ a2s (ve->transport_name,
+ &addr[slen], alen), ve->transport_name);
+#endif
+ break;
+ default:
+ GNUNET_break_op (0);
+ return GNUNET_NO;
+ }
+ if (GNUNET_TIME_absolute_get_remaining
+ (GNUNET_TIME_absolute_ntoh (pong->expiration)).rel_value == 0)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Received expired signature. Check system time.\n"));
+ return GNUNET_NO;
+ }
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# address validation successes"),
- 1,
- GNUNET_NO);
+ gettext_noop ("# address validation successes"),
+ 1, GNUNET_NO);
/* create the updated HELLO */
GNUNET_CRYPTO_hash (&ve->publicKey,
sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
&target.hashPubKey);
if (ve->addr != NULL)
- {
- avac.done = GNUNET_NO;
- avac.ve = ve;
- hello = GNUNET_HELLO_create (&ve->publicKey,
- &add_validated_address,
- &avac);
- GNUNET_PEERINFO_add_peer (peerinfo,
- hello);
- GNUNET_free (hello);
- }
+ {
+ avac.done = GNUNET_NO;
+ avac.ve = ve;
+ hello = GNUNET_HELLO_create (&ve->publicKey, &add_validated_address,
&avac);
+ GNUNET_PEERINFO_add_peer (peerinfo, hello);
+ GNUNET_free (hello);
+ }
n = find_neighbour (&target);
if (n != NULL)
- {
- n->publicKey = ve->publicKey;
- n->public_key_valid = GNUNET_YES;
- fal = add_peer_address (n,
- ve->transport_name,
- ve->session,
- ve->addr,
- ve->addrlen);
- GNUNET_assert (fal != NULL);
- fal->expires = GNUNET_TIME_relative_to_absolute
(HELLO_ADDRESS_EXPIRATION);
- fal->validated = GNUNET_YES;
- mark_address_connected (fal);
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# peer addresses considered
valid"),
- 1,
- GNUNET_NO);
- fal->latency = GNUNET_TIME_absolute_get_duration (ve->send_time);
- update_addr_value (fal, GNUNET_TIME_absolute_get_duration
(ve->send_time).rel_value, GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY);
+ {
+ n->publicKey = ve->publicKey;
+ n->public_key_valid = GNUNET_YES;
+ fal = add_peer_address (n,
+ ve->transport_name,
+ ve->session, ve->addr, ve->addrlen);
+ GNUNET_assert (fal != NULL);
+ fal->expires = GNUNET_TIME_relative_to_absolute (HELLO_ADDRESS_EXPIRATION);
+ fal->validated = GNUNET_YES;
+ mark_address_connected (fal);
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# peer addresses considered valid"), 1,
+ GNUNET_NO);
+ fal->latency = GNUNET_TIME_absolute_get_duration (ve->send_time);
+ update_addr_value (fal,
+ GNUNET_TIME_absolute_get_duration (ve->
+ send_time).rel_value,
+ GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY);
- schedule_next_ping (fal);
- if (n->latency.rel_value == GNUNET_TIME_UNIT_FOREVER_REL.rel_value)
- n->latency = fal->latency;
- else
- n->latency.rel_value = (fal->latency.rel_value + n->latency.rel_value)
/ 2;
+ schedule_next_ping (fal);
+ if (n->latency.rel_value == GNUNET_TIME_UNIT_FOREVER_REL.rel_value)
+ n->latency = fal->latency;
+ else
+ n->latency.rel_value =
+ (fal->latency.rel_value + n->latency.rel_value) / 2;
- n->distance = fal->distance;
- if (GNUNET_NO == n->received_pong)
- {
- n->received_pong = GNUNET_YES;
- notify_clients_connect (&target, n->latency, n->distance);
- if (NULL != (prem = n->pre_connect_message_buffer))
- {
- n->pre_connect_message_buffer = NULL;
- handle_payload_message (prem, n);
- GNUNET_free (prem);
- }
- }
- if (n->retry_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (n->retry_task);
- n->retry_task = GNUNET_SCHEDULER_NO_TASK;
- try_transmission_to_peer (n);
- }
+ n->distance = fal->distance;
+ if (GNUNET_NO == n->received_pong)
+ {
+ n->received_pong = GNUNET_YES;
+ notify_clients_connect (&target, n->latency, n->distance);
+ if (NULL != (prem = n->pre_connect_message_buffer))
+ {
+ n->pre_connect_message_buffer = NULL;
+ handle_payload_message (prem, n);
+ GNUNET_free (prem);
+ }
}
+ if (n->retry_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (n->retry_task);
+ n->retry_task = GNUNET_SCHEDULER_NO_TASK;
+ try_transmission_to_peer (n);
+ }
+ }
/* clean up validation entry */
GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove (validation_map,
- key,
- ve));
+ GNUNET_CONTAINER_multihashmap_remove (validation_map,
+ key, ve));
abort_validation (NULL, NULL, ve);
return GNUNET_NO;
}
@@ -4298,51 +4167,44 @@
static void
handle_pong (void *cls, const struct GNUNET_MessageHeader *message,
const struct GNUNET_PeerIdentity *peer,
- const char *sender_address,
- size_t sender_address_len)
+ const char *sender_address, size_t sender_address_len)
{
- if (0 == memcmp (peer,
- &my_identity,
- sizeof (struct GNUNET_PeerIdentity)))
- {
- /* PONG send to self, ignore */
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Receiving `%s' message from myself\n",
- "PONG");
- return;
- }
+ if (0 == memcmp (peer, &my_identity, sizeof (struct GNUNET_PeerIdentity)))
+ {
+ /* PONG send to self, ignore */
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Receiving `%s' message from myself\n", "PONG");
+ return;
+ }
#if DEBUG_TRANSPORT > 1
/* we get tons of these that just get discarded, only log
- if we are quite verbose */
+ * if we are quite verbose */
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Receiving `%s' message from `%4s'.\n", "PONG",
- GNUNET_i2s (peer));
+ "Receiving `%s' message from `%4s'.\n", "PONG",
+ GNUNET_i2s (peer));
#endif
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# PONG messages received"),
- 1,
- GNUNET_NO);
+ gettext_noop ("# PONG messages received"),
+ 1, GNUNET_NO);
if (GNUNET_SYSERR !=
GNUNET_CONTAINER_multihashmap_get_multiple (validation_map,
- &peer->hashPubKey,
- &check_pending_validation,
- (void*) message))
- {
- /* This is *expected* to happen a lot since we send
- PONGs to *all* known addresses of the sender of
- the PING, so most likely we get multiple PONGs
- per PING, and all but the first PONG will end up
- here. So really we should not print anything here
- unless we want to be very, very verbose... */
+ &peer->hashPubKey,
+ &check_pending_validation,
+ (void *) message))
+ {
+ /* This is *expected* to happen a lot since we send
+ * PONGs to *all* known addresses of the sender of
+ * the PING, so most likely we get multiple PONGs
+ * per PING, and all but the first PONG will end up
+ * here. So really we should not print anything here
+ * unless we want to be very, very verbose... */
#if DEBUG_TRANSPORT > 2
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received `%s' message from `%4s' but have no record of a
matching `%s' message. Ignoring.\n",
- "PONG",
- GNUNET_i2s (peer),
- "PING");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received `%s' message from `%4s' but have no record of a
matching `%s' message. Ignoring.\n",
+ "PONG", GNUNET_i2s (peer), "PING");
#endif
- return;
- }
+ return;
+ }
}
@@ -4354,92 +4216,86 @@
* @param neighbour neighbour to validate, NULL if validation failed
*/
static void
-transmit_hello_and_ping (void *cls,
- struct NeighbourMapEntry *neighbour)
+transmit_hello_and_ping (void *cls, struct NeighbourMapEntry *neighbour)
{
struct ValidationEntry *va = cls;
struct ForeignAddressList *peer_address;
struct TransportPingMessage ping;
uint16_t hello_size;
size_t tsize;
- char * message_buf;
+ char *message_buf;
struct GNUNET_PeerIdentity id;
size_t slen;
GNUNET_CRYPTO_hash (&va->publicKey,
- sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
- &id.hashPubKey);
+ sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+ &id.hashPubKey);
if (neighbour == NULL)
- {
- /* FIXME: stats... */
- GNUNET_break (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_remove (validation_map,
- &id.hashPubKey,
- va));
- abort_validation (NULL, NULL, va);
- return;
- }
+ {
+ /* FIXME: stats... */
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_CONTAINER_multihashmap_remove (validation_map,
+ &id.hashPubKey, va));
+ abort_validation (NULL, NULL, va);
+ return;
+ }
neighbour->publicKey = va->publicKey;
neighbour->public_key_valid = GNUNET_YES;
peer_address = add_peer_address (neighbour,
- va->transport_name, NULL,
- (const void*) &va[1],
- va->addrlen);
+ va->transport_name, NULL,
+ (const void *) &va[1], va->addrlen);
if (peer_address == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Failed to add peer `%4s' for plugin `%s'\n",
- GNUNET_i2s (&neighbour->id),
- va->transport_name);
- GNUNET_break (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_remove (validation_map,
- &id.hashPubKey,
- va));
- abort_validation (NULL, NULL, va);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to add peer `%4s' for plugin `%s'\n",
+ GNUNET_i2s (&neighbour->id), va->transport_name);
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_CONTAINER_multihashmap_remove (validation_map,
+ &id.hashPubKey, va));
+ abort_validation (NULL, NULL, va);
+ return;
+ }
if (NULL == our_hello)
refresh_hello_task (NULL, NULL);
- hello_size = GNUNET_HELLO_size(our_hello);
- slen = strlen(va->transport_name) + 1;
- tsize = sizeof(struct TransportPingMessage) + hello_size + va->addrlen +
slen;
- message_buf = GNUNET_malloc(tsize);
- ping.challenge = htonl(va->challenge);
- ping.header.size = htons(sizeof(struct TransportPingMessage) + slen +
va->addrlen);
- ping.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_PING);
- memcpy(&ping.target, &neighbour->id, sizeof(struct GNUNET_PeerIdentity));
- memcpy(message_buf, our_hello, hello_size);
- memcpy(&message_buf[hello_size],
- &ping,
- sizeof(struct TransportPingMessage));
- memcpy(&message_buf[hello_size + sizeof (struct TransportPingMessage)],
- va->transport_name,
- slen);
- memcpy(&message_buf[hello_size + sizeof (struct TransportPingMessage) +
slen],
- &va[1],
- va->addrlen);
+ hello_size = GNUNET_HELLO_size (our_hello);
+ slen = strlen (va->transport_name) + 1;
+ tsize =
+ sizeof (struct TransportPingMessage) + hello_size + va->addrlen + slen;
+ message_buf = GNUNET_malloc (tsize);
+ ping.challenge = htonl (va->challenge);
+ ping.header.size =
+ htons (sizeof (struct TransportPingMessage) + slen + va->addrlen);
+ ping.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PING);
+ memcpy (&ping.target, &neighbour->id, sizeof (struct GNUNET_PeerIdentity));
+ memcpy (message_buf, our_hello, hello_size);
+ memcpy (&message_buf[hello_size],
+ &ping, sizeof (struct TransportPingMessage));
+ memcpy (&message_buf[hello_size + sizeof (struct TransportPingMessage)],
+ va->transport_name, slen);
+ memcpy (&message_buf
+ [hello_size + sizeof (struct TransportPingMessage) + slen], &va[1],
+ va->addrlen);
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Performing validation of address `%s' via `%s' for peer `%4s'
sending `%s' (%u bytes) and `%s' (%u bytes)\n",
- (va->addrlen == 0)
- ? "<inbound>"
- : a2s (va->transport_name,
- (const void*) &va[1], va->addrlen),
- va->transport_name,
- GNUNET_i2s (&neighbour->id),
- "HELLO", hello_size,
- "PING", sizeof (struct TransportPingMessage) + va->addrlen +
slen);
+ (va->addrlen == 0)
+ ? "<inbound>"
+ : a2s (va->transport_name,
+ (const void *) &va[1], va->addrlen),
+ va->transport_name,
+ GNUNET_i2s (&neighbour->id),
+ "HELLO", hello_size,
+ "PING",
+ sizeof (struct TransportPingMessage) + va->addrlen + slen);
#endif
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# PING messages sent for initial
validation"),
- 1,
- GNUNET_NO);
- transmit_to_peer (NULL, peer_address,
- GNUNET_SCHEDULER_PRIORITY_DEFAULT,
- HELLO_VERIFICATION_TIMEOUT,
- message_buf, tsize,
- GNUNET_YES, neighbour);
+ gettext_noop
+ ("# PING messages sent for initial validation"), 1,
+ GNUNET_NO);
+ transmit_to_peer (NULL, peer_address, GNUNET_SCHEDULER_PRIORITY_DEFAULT,
+ HELLO_VERIFICATION_TIMEOUT, message_buf, tsize, GNUNET_YES,
+ neighbour);
GNUNET_free (message_buf);
}
@@ -4460,8 +4316,7 @@
run_validation (void *cls,
const char *tname,
struct GNUNET_TIME_Absolute expiration,
- const void *addr,
- uint16_t addrlen)
+ const void *addr, uint16_t addrlen)
{
struct CheckHelloValidatedContext *chvc = cls;
struct GNUNET_PeerIdentity id;
@@ -4474,57 +4329,53 @@
GNUNET_assert (addr != NULL);
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# peer addresses scheduled for
validation"),
- 1,
- GNUNET_NO);
+ gettext_noop
+ ("# peer addresses scheduled for validation"), 1,
+ GNUNET_NO);
tp = find_transport (tname);
if (tp == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO |
- GNUNET_ERROR_TYPE_BULK,
- _
- ("Transport `%s' not loaded, will not try to validate peer
address using this transport.\n"),
- tname);
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# peer addresses not validated
(plugin not available)"),
- 1,
- GNUNET_NO);
- return GNUNET_OK;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO |
+ GNUNET_ERROR_TYPE_BULK,
+ _
+ ("Transport `%s' not loaded, will not try to validate peer
address using this transport.\n"),
+ tname);
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# peer addresses not validated (plugin not
available)"),
+ 1, GNUNET_NO);
+ return GNUNET_OK;
+ }
/* check if this is one of our own addresses */
oal = tp->addresses;
while (NULL != oal)
+ {
+ if ((oal->addrlen == addrlen) && (0 == memcmp (&oal[1], addr, addrlen)))
{
- if ( (oal->addrlen == addrlen) &&
- (0 == memcmp (&oal[1],
- addr,
- addrlen)) )
- {
- /* not plausible, this address is equivalent to our own address! */
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# peer addresses not
validated (loopback)"),
- 1,
- GNUNET_NO);
- return GNUNET_OK;
- }
- oal = oal->next;
+ /* not plausible, this address is equivalent to our own address! */
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# peer addresses not validated (loopback)"),
+ 1, GNUNET_NO);
+ return GNUNET_OK;
}
+ oal = oal->next;
+ }
GNUNET_HELLO_get_key (chvc->hello, &pk);
GNUNET_CRYPTO_hash (&pk,
sizeof (struct
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
&id.hashPubKey);
- if (is_blacklisted(&id, tp))
- {
+ if (is_blacklisted (&id, tp))
+ {
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Attempted to validate blacklisted peer `%s' using `%s'!\n",
- GNUNET_i2s(&id),
- tname);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Attempted to validate blacklisted peer `%s' using `%s'!\n",
+ GNUNET_i2s (&id), tname);
#endif
- return GNUNET_OK;
- }
+ return GNUNET_OK;
+ }
caec.addr = addr;
caec.addrlen = addrlen;
@@ -4532,49 +4383,43 @@
caec.tname = tname;
caec.exists = GNUNET_NO;
GNUNET_CONTAINER_multihashmap_iterate (validation_map,
- &check_address_exists,
- &caec);
+ &check_address_exists, &caec);
if (caec.exists == GNUNET_YES)
- {
- /* During validation attempts we will likely trigger the other
- peer trying to validate our address which in turn will cause
- it to send us its HELLO, so we expect to hit this case rather
- frequently. Only print something if we are very verbose. */
+ {
+ /* During validation attempts we will likely trigger the other
+ * peer trying to validate our address which in turn will cause
+ * it to send us its HELLO, so we expect to hit this case rather
+ * frequently. Only print something if we are very verbose. */
#if DEBUG_TRANSPORT > 1
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Validation of address `%s' via `%s' for peer `%4s' already
in progress.\n",
- a2s (tname, addr, addrlen),
- tname,
- GNUNET_i2s (&id));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Validation of address `%s' via `%s' for peer `%4s' already in
progress.\n",
+ a2s (tname, addr, addrlen), tname, GNUNET_i2s (&id));
#endif
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# peer addresses not validated
(in progress)"),
- 1,
- GNUNET_NO);
- return GNUNET_OK;
- }
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# peer addresses not validated (in progress)"),
+ 1, GNUNET_NO);
+ return GNUNET_OK;
+ }
va = GNUNET_malloc (sizeof (struct ValidationEntry) + addrlen);
va->chvc = chvc;
chvc->ve_count++;
va->transport_name = GNUNET_strdup (tname);
va->challenge = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
UINT_MAX);
- va->send_time = GNUNET_TIME_absolute_get();
- va->addr = (const void*) &va[1];
+ va->send_time = GNUNET_TIME_absolute_get ();
+ va->addr = (const void *) &va[1];
memcpy (&va[1], addr, addrlen);
va->addrlen = addrlen;
- GNUNET_HELLO_get_key (chvc->hello,
- &va->publicKey);
+ GNUNET_HELLO_get_key (chvc->hello, &va->publicKey);
va->timeout_task = GNUNET_SCHEDULER_add_delayed (HELLO_VERIFICATION_TIMEOUT,
- &timeout_hello_validation,
- va);
+ &timeout_hello_validation,
+ va);
GNUNET_CONTAINER_multihashmap_put (validation_map,
- &id.hashPubKey,
- va,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
- setup_peer_check_blacklist (&id, GNUNET_NO,
- &transmit_hello_and_ping,
- va);
+ &id.hashPubKey,
+ va,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
+ setup_peer_check_blacklist (&id, GNUNET_NO, &transmit_hello_and_ping, va);
return GNUNET_OK;
}
@@ -4601,111 +4446,98 @@
struct NeighbourMapEntry *n;
if (err_msg != NULL)
- {
+ {
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Error in communication with PEERINFO service: %s\n"),
- err_msg);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ _("Error in communication with PEERINFO service: %s\n"),
+ err_msg);
#endif
- /* return; */
+ /* return; */
}
if (peer == NULL)
+ {
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# outstanding peerinfo iterate requests"), -1,
+ GNUNET_NO);
+ chvc->piter = NULL;
+ if (GNUNET_NO == chvc->hello_known)
{
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# outstanding peerinfo iterate
requests"),
- -1,
- GNUNET_NO);
- chvc->piter = NULL;
- if (GNUNET_NO == chvc->hello_known)
- {
- /* notify PEERINFO about the peer now, so that we at least
- have the public key if some other component needs it */
- GNUNET_HELLO_get_key (chvc->hello, &pk);
- GNUNET_CRYPTO_hash (&pk,
- sizeof (struct
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
- &target.hashPubKey);
- plain_hello = GNUNET_HELLO_create (&pk,
- NULL,
- NULL);
- GNUNET_PEERINFO_add_peer (peerinfo, plain_hello);
- GNUNET_free (plain_hello);
+ /* notify PEERINFO about the peer now, so that we at least
+ * have the public key if some other component needs it */
+ GNUNET_HELLO_get_key (chvc->hello, &pk);
+ GNUNET_CRYPTO_hash (&pk,
+ sizeof (struct
+ GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+ &target.hashPubKey);
+ plain_hello = GNUNET_HELLO_create (&pk, NULL, NULL);
+ GNUNET_PEERINFO_add_peer (peerinfo, plain_hello);
+ GNUNET_free (plain_hello);
#if DEBUG_TRANSPORT_HELLO
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "PEERINFO had no `%s' message for peer `%4s', full
validation needed.\n",
- "HELLO",
- GNUNET_i2s (&target));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "PEERINFO had no `%s' message for peer `%4s', full
validation needed.\n",
+ "HELLO", GNUNET_i2s (&target));
#endif
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# new HELLOs requiring full
validation"),
- 1,
- GNUNET_NO);
- GNUNET_HELLO_iterate_addresses (chvc->hello,
- GNUNET_NO,
- &run_validation,
- chvc);
- }
- else
- {
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# duplicate HELLO (peer
known)"),
- 1,
- GNUNET_NO);
- }
- chvc->ve_count--;
- if (chvc->ve_count == 0)
- {
- GNUNET_CONTAINER_DLL_remove (chvc_head,
- chvc_tail,
- chvc);
- GNUNET_free (chvc);
- }
- return;
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# new HELLOs requiring full validation"), 1,
+ GNUNET_NO);
+ GNUNET_HELLO_iterate_addresses (chvc->hello, GNUNET_NO, &run_validation,
+ chvc);
}
+ else
+ {
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# duplicate HELLO (peer
known)"),
+ 1, GNUNET_NO);
+ }
+ chvc->ve_count--;
+ if (chvc->ve_count == 0)
+ {
+ GNUNET_CONTAINER_DLL_remove (chvc_head, chvc_tail, chvc);
+ GNUNET_free (chvc);
+ }
+ return;
+ }
if (h == NULL)
return;
#if DEBUG_TRANSPORT_HELLO
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "PEERINFO had `%s' message for peer `%4s', validating only new
addresses.\n",
- "HELLO",
- GNUNET_i2s (peer));
+ "PEERINFO had `%s' message for peer `%4s', validating only new
addresses.\n",
+ "HELLO", GNUNET_i2s (peer));
#endif
chvc->hello_known = GNUNET_YES;
n = find_neighbour (peer);
if (n != NULL)
- {
+ {
#if DEBUG_TRANSPORT_HELLO
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Calling hello_iterate_addresses for %s!\n",
- GNUNET_i2s (peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Calling hello_iterate_addresses for %s!\n", GNUNET_i2s
(peer));
#endif
- GNUNET_HELLO_iterate_addresses (h,
- GNUNET_NO,
- &add_to_foreign_address_list,
- n);
- try_transmission_to_peer (n);
- }
+ GNUNET_HELLO_iterate_addresses (h,
+ GNUNET_NO, &add_to_foreign_address_list,
n);
+ try_transmission_to_peer (n);
+ }
else
- {
+ {
#if DEBUG_TRANSPORT_HELLO
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "No existing neighbor record for %s!\n",
- GNUNET_i2s (peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "No existing neighbor record for %s!\n", GNUNET_i2s (peer));
#endif
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# no existing neighbour record
(validating HELLO)"),
- 1,
- GNUNET_NO);
- }
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# no existing neighbour record (validating
HELLO)"),
+ 1, GNUNET_NO);
+ }
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# HELLO validations (update case)"),
- 1,
- GNUNET_NO);
+ gettext_noop ("# HELLO validations (update case)"),
+ 1, GNUNET_NO);
GNUNET_HELLO_iterate_new_addresses (chvc->hello,
- h,
- GNUNET_TIME_relative_to_absolute
(HELLO_REVALIDATION_START_TIME),
- &run_validation,
- chvc);
+ h,
+ GNUNET_TIME_relative_to_absolute
+ (HELLO_REVALIDATION_START_TIME),
+ &run_validation, chvc);
}
@@ -4726,6 +4558,7 @@
struct CheckHelloValidatedContext *chvc;
struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded publicKey;
struct NeighbourMapEntry *n;
+
#if DEBUG_TRANSPORT_HELLO > 2
char *my_id;
#endif
@@ -4733,27 +4566,25 @@
hsize = ntohs (message->size);
if ((ntohs (message->type) != GNUNET_MESSAGE_TYPE_HELLO) ||
(hsize < sizeof (struct GNUNET_MessageHeader)))
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# HELLOs received for validation"),
- 1,
- GNUNET_NO);
+ gettext_noop ("# HELLOs received for validation"),
+ 1, GNUNET_NO);
hello = (const struct GNUNET_HELLO_Message *) message;
if (GNUNET_OK != GNUNET_HELLO_get_key (hello, &publicKey))
- {
+ {
#if DEBUG_TRANSPORT_HELLO
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Unable to get public key from `%s' for `%4s'!\n",
- "HELLO",
- GNUNET_i2s (&target));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Unable to get public key from `%s' for `%4s'!\n",
+ "HELLO", GNUNET_i2s (&target));
#endif
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
GNUNET_CRYPTO_hash (&publicKey,
sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
&target.hashPubKey);
@@ -4761,111 +4592,103 @@
#if DEBUG_TRANSPORT_HELLO
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received `%s' message for `%4s'\n",
- "HELLO",
- GNUNET_i2s (&target));
+ "HELLO", GNUNET_i2s (&target));
#endif
- if (0 == memcmp (&my_identity,
- &target,
- sizeof (struct GNUNET_PeerIdentity)))
- {
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# HELLOs ignored for validation
(is my own HELLO)"),
- 1,
- GNUNET_NO);
- return GNUNET_OK;
- }
+ if (0 == memcmp (&my_identity, &target, sizeof (struct GNUNET_PeerIdentity)))
+ {
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# HELLOs ignored for validation (is my own
HELLO)"),
+ 1, GNUNET_NO);
+ return GNUNET_OK;
+ }
n = find_neighbour (&target);
- if ( (NULL != n) &&
- (! n->public_key_valid) )
- {
- GNUNET_HELLO_get_key (hello, &n->publicKey);
- n->public_key_valid = GNUNET_YES;
- }
+ if ((NULL != n) && (!n->public_key_valid))
+ {
+ GNUNET_HELLO_get_key (hello, &n->publicKey);
+ n->public_key_valid = GNUNET_YES;
+ }
/* check if load is too high before doing expensive stuff */
- if (GNUNET_SCHEDULER_get_load (GNUNET_SCHEDULER_PRIORITY_BACKGROUND) >
MAX_HELLO_LOAD)
- {
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# HELLOs ignored due to high
load"),
- 1,
- GNUNET_NO);
+ if (GNUNET_SCHEDULER_get_load (GNUNET_SCHEDULER_PRIORITY_BACKGROUND) >
+ MAX_HELLO_LOAD)
+ {
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# HELLOs ignored due to high load"), 1,
+ GNUNET_NO);
#if DEBUG_TRANSPORT_HELLO
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Ignoring `%s' for `%4s', load too high.\n",
- "HELLO",
- GNUNET_i2s (&target));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Ignoring `%s' for `%4s', load too high.\n",
+ "HELLO", GNUNET_i2s (&target));
#endif
- return GNUNET_OK;
- }
+ return GNUNET_OK;
+ }
chvc = chvc_head;
while (NULL != chvc)
+ {
+ if (GNUNET_HELLO_equals (hello,
+ chvc->hello,
+ GNUNET_TIME_absolute_get ()).abs_value > 0)
{
- if (GNUNET_HELLO_equals (hello,
- chvc->hello,
- GNUNET_TIME_absolute_get ()).abs_value > 0)
- {
#if DEBUG_TRANSPORT_HELLO > 2
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received duplicate `%s' message for `%4s'; ignored\n",
- "HELLO",
- GNUNET_i2s (&target));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received duplicate `%s' message for `%4s'; ignored\n",
+ "HELLO", GNUNET_i2s (&target));
#endif
- return GNUNET_OK; /* validation already pending */
- }
- if (GNUNET_HELLO_size (hello) == GNUNET_HELLO_size (chvc->hello))
- GNUNET_break (0 != memcmp (hello, chvc->hello,
- GNUNET_HELLO_size(hello)));
- chvc = chvc->next;
+ return GNUNET_OK; /* validation already pending */
}
+ if (GNUNET_HELLO_size (hello) == GNUNET_HELLO_size (chvc->hello))
+ GNUNET_break (0 != memcmp (hello, chvc->hello,
+ GNUNET_HELLO_size (hello)));
+ chvc = chvc->next;
+ }
#if BREAK_TESTS
- struct NeighbourMapEntry *temp_neighbor = find_neighbour(&target);
+ struct NeighbourMapEntry *temp_neighbor = find_neighbour (&target);
+
if ((NULL != temp_neighbor))
- {
- fprintf(stderr, "Already know peer, ignoring hello\n");
- return GNUNET_OK;
- }
+ {
+ fprintf (stderr, "Already know peer, ignoring hello\n");
+ return GNUNET_OK;
+ }
#endif
#if DEBUG_TRANSPORT_HELLO > 2
if (plugin != NULL)
- {
+ {
#if DEBUG_TRANSPORT
- my_id = GNUNET_strdup(GNUNET_i2s(plugin->env.my_identity));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "%s: Starting validation of `%s' message for `%4s' via '%s'
of size %u\n",
- my_id,
- "HELLO",
- GNUNET_i2s (&target),
- plugin->short_name,
- GNUNET_HELLO_size(hello));
- GNUNET_free (my_id);
+ my_id = GNUNET_strdup (GNUNET_i2s (plugin->env.my_identity));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "%s: Starting validation of `%s' message for `%4s' via '%s' of
size %u\n",
+ my_id,
+ "HELLO",
+ GNUNET_i2s (&target),
+ plugin->short_name, GNUNET_HELLO_size (hello));
+ GNUNET_free (my_id);
#endif
- }
+ }
#endif
chvc = GNUNET_malloc (sizeof (struct CheckHelloValidatedContext) + hsize);
chvc->ve_count = 1;
chvc->hello = (const struct GNUNET_HELLO_Message *) &chvc[1];
memcpy (&chvc[1], hello, hsize);
- GNUNET_CONTAINER_DLL_insert (chvc_head,
- chvc_tail,
- chvc);
+ GNUNET_CONTAINER_DLL_insert (chvc_head, chvc_tail, chvc);
/* finally, check if HELLO was previously validated
- (continuation will then schedule actual validation) */
+ * (continuation will then schedule actual validation) */
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# peerinfo process hello iterate
requests"),
- 1,
+ gettext_noop
+ ("# peerinfo process hello iterate requests"), 1,
GNUNET_NO);
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# outstanding peerinfo iterate
requests"),
- 1,
+ gettext_noop
+ ("# outstanding peerinfo iterate requests"), 1,
GNUNET_NO);
- chvc->piter = GNUNET_PEERINFO_iterate (peerinfo,
- &target,
- HELLO_VERIFICATION_TIMEOUT,
- &check_hello_validated, chvc);
+ chvc->piter =
+ GNUNET_PEERINFO_iterate (peerinfo, &target, HELLO_VERIFICATION_TIMEOUT,
+ &check_hello_validated, chvc);
return GNUNET_OK;
}
@@ -4894,144 +4717,134 @@
if (GNUNET_YES == n->in_disconnect)
return;
if (GNUNET_YES == check)
+ {
+ rpos = n->plugins;
+ while (NULL != rpos)
{
- rpos = n->plugins;
- while (NULL != rpos)
+ peer_addresses = rpos->addresses;
+ while (peer_addresses != NULL)
+ {
+ /* Do not disconnect if: an address is connected or an inbound address
exists */
+ if ((GNUNET_YES == peer_addresses->connected) ||
+ (peer_addresses->addrlen == 0))
{
- peer_addresses = rpos->addresses;
- while (peer_addresses != NULL)
- {
- /* Do not disconnect if: an address is connected or an inbound
address exists */
- if ((GNUNET_YES == peer_addresses->connected) ||
(peer_addresses->addrlen == 0))
- {
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "NOT Disconnecting from `%4s', still have live
address `%s'!\n",
- GNUNET_i2s (&n->id),
- a2s
(peer_addresses->ready_list->plugin->short_name,
- peer_addresses->addr,
- peer_addresses->addrlen));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "NOT Disconnecting from `%4s', still have live address
`%s'!\n",
+ GNUNET_i2s (&n->id),
+ a2s (peer_addresses->ready_list->plugin->short_name,
+ peer_addresses->addr, peer_addresses->addrlen));
#endif
- return; /* still connected */
- }
- peer_addresses = peer_addresses->next;
- }
- rpos = rpos->next;
+ return; /* still connected */
}
+ peer_addresses = peer_addresses->next;
+ }
+ rpos = rpos->next;
}
+ }
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
- "Disconnecting from `%4s'\n",
- GNUNET_i2s (&n->id));
+ "Disconnecting from `%4s'\n", GNUNET_i2s (&n->id));
#endif
- n->in_disconnect = GNUNET_YES; /* prevent recursive entry */
+ n->in_disconnect = GNUNET_YES; /* prevent recursive entry */
/* notify all clients about disconnect */
if (GNUNET_YES == n->received_pong)
- {
- n->received_pong = GNUNET_NO;
- notify_clients_disconnect (&n->id);
- }
+ {
+ n->received_pong = GNUNET_NO;
+ notify_clients_disconnect (&n->id);
+ }
#if HAVE_LIBGLPK
- ats_modify_problem_state(ats, ATS_MODIFIED);
+ ats_modify_problem_state (ats, ATS_MODIFIED);
#endif
/* clean up all plugins, cancel connections and pending transmissions */
while (NULL != (rpos = n->plugins))
+ {
+ n->plugins = rpos->next;
+ rpos->plugin->api->disconnect (rpos->plugin->api->cls, &n->id);
+ while (rpos->addresses != NULL)
{
- n->plugins = rpos->next;
- rpos->plugin->api->disconnect (rpos->plugin->api->cls, &n->id);
- while (rpos->addresses != NULL)
- {
- peer_pos = rpos->addresses;
- rpos->addresses = peer_pos->next;
- if (peer_pos->connected == GNUNET_YES)
- {
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# connected addresses"),
- -1,
- GNUNET_NO);
- peer_pos->connected = GNUNET_NO;
- }
- if (GNUNET_YES == peer_pos->validated)
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# peer addresses
considered valid"),
- -1,
- GNUNET_NO);
- if (GNUNET_SCHEDULER_NO_TASK != peer_pos->revalidate_task)
- {
- GNUNET_SCHEDULER_cancel (peer_pos->revalidate_task);
- peer_pos->revalidate_task = GNUNET_SCHEDULER_NO_TASK;
- }
- GNUNET_free (peer_pos->ressources);
- peer_pos->ressources = NULL;
- GNUNET_free (peer_pos->quality);
- peer_pos->ressources = NULL;
- GNUNET_free (peer_pos);
- }
- GNUNET_free (rpos);
+ peer_pos = rpos->addresses;
+ rpos->addresses = peer_pos->next;
+ if (peer_pos->connected == GNUNET_YES)
+ {
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# connected addresses"),
+ -1, GNUNET_NO);
+ peer_pos->connected = GNUNET_NO;
+ }
+ if (GNUNET_YES == peer_pos->validated)
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# peer addresses considered valid"), -1,
+ GNUNET_NO);
+ if (GNUNET_SCHEDULER_NO_TASK != peer_pos->revalidate_task)
+ {
+ GNUNET_SCHEDULER_cancel (peer_pos->revalidate_task);
+ peer_pos->revalidate_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ GNUNET_free (peer_pos->ressources);
+ peer_pos->ressources = NULL;
+ GNUNET_free (peer_pos->quality);
+ peer_pos->ressources = NULL;
+ GNUNET_free (peer_pos);
}
+ GNUNET_free (rpos);
+ }
/* free all messages on the queue */
while (NULL != (mq = n->messages_head))
- {
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# bytes in message queue for
other peers"),
- - (int64_t) mq->message_buf_size,
- GNUNET_NO);
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# bytes discarded due to
disconnect"),
- mq->message_buf_size,
- GNUNET_NO);
- GNUNET_CONTAINER_DLL_remove (n->messages_head,
- n->messages_tail,
- mq);
- GNUNET_assert (0 == memcmp(&mq->neighbour_id,
- &n->id,
- sizeof(struct GNUNET_PeerIdentity)));
- GNUNET_free (mq);
- }
+ {
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# bytes in message queue for other peers"),
+ -(int64_t) mq->message_buf_size, GNUNET_NO);
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# bytes discarded due to disconnect"),
+ mq->message_buf_size, GNUNET_NO);
+ GNUNET_CONTAINER_DLL_remove (n->messages_head, n->messages_tail, mq);
+ GNUNET_assert (0 == memcmp (&mq->neighbour_id,
+ &n->id, sizeof (struct GNUNET_PeerIdentity)));
+ GNUNET_free (mq);
+ }
while (NULL != (mq = n->cont_head))
- {
+ {
- GNUNET_CONTAINER_DLL_remove (n->cont_head,
- n->cont_tail,
- mq);
- GNUNET_assert (0 == memcmp(&mq->neighbour_id,
- &n->id,
- sizeof(struct GNUNET_PeerIdentity)));
- GNUNET_free (mq);
- }
+ GNUNET_CONTAINER_DLL_remove (n->cont_head, n->cont_tail, mq);
+ GNUNET_assert (0 == memcmp (&mq->neighbour_id,
+ &n->id, sizeof (struct GNUNET_PeerIdentity)));
+ GNUNET_free (mq);
+ }
if (n->timeout_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (n->timeout_task);
- n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (n->timeout_task);
+ n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ }
if (n->retry_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (n->retry_task);
- n->retry_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (n->retry_task);
+ n->retry_task = GNUNET_SCHEDULER_NO_TASK;
+ }
if (n->piter != NULL)
- {
- GNUNET_PEERINFO_iterate_cancel (n->piter);
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# outstanding peerinfo iterate
requests"),
- -1,
- GNUNET_NO);
- n->piter = NULL;
- }
+ {
+ GNUNET_PEERINFO_iterate_cancel (n->piter);
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# outstanding peerinfo iterate requests"), -1,
+ GNUNET_NO);
+ n->piter = NULL;
+ }
GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_remove (neighbours,
- &n->id.hashPubKey,
- n));
+ GNUNET_CONTAINER_multihashmap_remove (neighbours,
+ &n->id.hashPubKey, n));
/* finally, free n itself */
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# active neighbours"),
- -1,
- GNUNET_NO);
+ gettext_noop ("# active neighbours"),
+ -1, GNUNET_NO);
GNUNET_free_non_null (n->pre_connect_message_buffer);
GNUNET_free (n);
}
@@ -5043,13 +4856,12 @@
*/
static int
handle_ping (void *cls, const struct GNUNET_MessageHeader *message,
- const struct GNUNET_PeerIdentity *peer,
- struct Session *session,
- const char *sender_address,
- uint16_t sender_address_len)
+ const struct GNUNET_PeerIdentity *peer,
+ struct Session *session,
+ const char *sender_address, uint16_t sender_address_len)
{
struct TransportPlugin *plugin = cls;
- struct SessionHeader *session_header = (struct SessionHeader*) session;
+ struct SessionHeader *session_header = (struct SessionHeader *) session;
struct TransportPingMessage *ping;
struct TransportPongMessage *pong;
struct NeighbourMapEntry *n;
@@ -5062,266 +4874,252 @@
int did_pong;
if (ntohs (message->size) < sizeof (struct TransportPingMessage))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
ping = (struct TransportPingMessage *) message;
if (0 != memcmp (&ping->target,
plugin->env.my_identity,
sizeof (struct GNUNET_PeerIdentity)))
- {
+ {
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Received `%s' message from `%s' destined for `%s' which
is not me!\n"),
- "PING",
- (sender_address != NULL)
- ? a2s (plugin->short_name,
- (const struct sockaddr *)sender_address,
- sender_address_len)
- : "<inbound>",
- GNUNET_i2s (&ping->target));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ _
+ ("Received `%s' message from `%s' destined for `%s' which is
not me!\n"),
+ "PING", (sender_address != NULL) ? a2s (plugin->short_name,
+ (const struct sockaddr
+ *) sender_address,
+ sender_address_len) :
+ "<inbound>", GNUNET_i2s (&ping->target));
#endif
- return GNUNET_SYSERR;
- }
+ return GNUNET_SYSERR;
+ }
#if DEBUG_PING_PONG
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
- "Processing `%s' from `%s'\n",
- "PING",
- (sender_address != NULL)
- ? a2s (plugin->short_name,
- (const struct sockaddr *)sender_address,
- sender_address_len)
- : "<inbound>");
+ "Processing `%s' from `%s'\n",
+ "PING",
+ (sender_address != NULL)
+ ? a2s (plugin->short_name,
+ (const struct sockaddr *) sender_address,
+ sender_address_len) : "<inbound>");
#endif
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# PING messages received"),
- 1,
- GNUNET_NO);
- addr = (const char*) &ping[1];
+ gettext_noop ("# PING messages received"),
+ 1, GNUNET_NO);
+ addr = (const char *) &ping[1];
alen = ntohs (message->size) - sizeof (struct TransportPingMessage);
slen = strlen (plugin->short_name) + 1;
if (alen == 0)
+ {
+ /* peer wants to confirm that we have an outbound connection to him */
+ if (session == NULL)
{
- /* peer wants to confirm that we have an outbound connection to him */
- if (session == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Refusing to create PONG since I do not have a session
with `%s'.\n"),
- GNUNET_i2s (peer));
- return GNUNET_SYSERR;
- }
- /* FIXME-urg: the use of 'sender_address' in the code below is
doubly-wrong:
- 1) it is NULL when we need to have a real value
- 2) it is documented to be the address of the sender (source-IP), where
- what we actually want is our LISTEN IP (what we 'bound' to); which we
don't even
- have...
- */
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Creating PONG indicating that we received a connection at
our address `%s' from `%s'.\n",
- a2s (plugin->short_name,
- sender_address,
- sender_address_len),
- GNUNET_i2s (peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _
+ ("Refusing to create PONG since I do not have a session with
`%s'.\n"),
+ GNUNET_i2s (peer));
+ return GNUNET_SYSERR;
+ }
+ /* FIXME-urg: the use of 'sender_address' in the code below is
doubly-wrong:
+ * 1) it is NULL when we need to have a real value
+ * 2) it is documented to be the address of the sender (source-IP), where
+ * what we actually want is our LISTEN IP (what we 'bound' to); which we
don't even
+ * have...
+ */
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Creating PONG indicating that we received a connection at our
address `%s' from `%s'.\n",
+ a2s (plugin->short_name,
+ sender_address, sender_address_len), GNUNET_i2s (peer));
- pong = GNUNET_malloc (sizeof (struct TransportPongMessage) +
sender_address_len + slen);
- pong->header.size = htons (sizeof (struct TransportPongMessage) +
sender_address_len + slen);
- pong->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PONG);
- pong->purpose.size =
- htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
- sizeof (uint32_t) +
- sizeof (struct GNUNET_TIME_AbsoluteNBO) +
- sizeof (struct GNUNET_PeerIdentity) + sender_address_len + slen);
- pong->purpose.purpose = htonl
(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_USING);
- pong->challenge = ping->challenge;
- pong->addrlen = htonl(sender_address_len + slen);
- memcpy(&pong->pid,
- peer,
- sizeof(struct GNUNET_PeerIdentity));
- memcpy (&pong[1],
- plugin->short_name,
- slen);
- if ((sender_address!=NULL) && (sender_address_len > 0))
- memcpy (&((char*)&pong[1])[slen],
- sender_address,
- sender_address_len);
- if (GNUNET_TIME_absolute_get_remaining
(session_header->pong_sig_expires).rel_value <
PONG_SIGNATURE_LIFETIME.rel_value / 4)
- {
- /* create / update cached sig */
+ pong =
+ GNUNET_malloc (sizeof (struct TransportPongMessage) +
+ sender_address_len + slen);
+ pong->header.size =
+ htons (sizeof (struct TransportPongMessage) + sender_address_len +
+ slen);
+ pong->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PONG);
+ pong->purpose.size =
+ htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
+ sizeof (uint32_t) +
+ sizeof (struct GNUNET_TIME_AbsoluteNBO) +
+ sizeof (struct GNUNET_PeerIdentity) + sender_address_len +
slen);
+ pong->purpose.purpose =
+ htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_USING);
+ pong->challenge = ping->challenge;
+ pong->addrlen = htonl (sender_address_len + slen);
+ memcpy (&pong->pid, peer, sizeof (struct GNUNET_PeerIdentity));
+ memcpy (&pong[1], plugin->short_name, slen);
+ if ((sender_address != NULL) && (sender_address_len > 0))
+ memcpy (&((char *) &pong[1])[slen], sender_address, sender_address_len);
+ if (GNUNET_TIME_absolute_get_remaining
+ (session_header->pong_sig_expires).rel_value <
+ PONG_SIGNATURE_LIFETIME.rel_value / 4)
+ {
+ /* create / update cached sig */
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Creating PONG signature to indicate active
connection.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Creating PONG signature to indicate active connection.\n");
#endif
- session_header->pong_sig_expires = GNUNET_TIME_relative_to_absolute
(PONG_SIGNATURE_LIFETIME);
- pong->expiration = GNUNET_TIME_absolute_hton
(session_header->pong_sig_expires);
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CRYPTO_rsa_sign (my_private_key,
- &pong->purpose,
-
&session_header->pong_signature));
- }
- else
- {
- pong->expiration = GNUNET_TIME_absolute_hton
(session_header->pong_sig_expires);
- }
- memcpy (&pong->signature,
- &session_header->pong_signature,
- sizeof (struct GNUNET_CRYPTO_RsaSignature));
+ session_header->pong_sig_expires =
+ GNUNET_TIME_relative_to_absolute (PONG_SIGNATURE_LIFETIME);
+ pong->expiration =
+ GNUNET_TIME_absolute_hton (session_header->pong_sig_expires);
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CRYPTO_rsa_sign (my_private_key, &pong->purpose,
+ &session_header->pong_signature));
+ }
+ else
+ {
+ pong->expiration =
+ GNUNET_TIME_absolute_hton (session_header->pong_sig_expires);
+ }
+ memcpy (&pong->signature,
+ &session_header->pong_signature,
+ sizeof (struct GNUNET_CRYPTO_RsaSignature));
- }
+ }
else
+ {
+ /* peer wants to confirm that this is one of our addresses */
+ addr += slen;
+ alen -= slen;
+ if (GNUNET_OK != plugin->api->check_address (plugin->api->cls, addr, alen))
{
- /* peer wants to confirm that this is one of our addresses */
- addr += slen;
- alen -= slen;
- if (GNUNET_OK !=
- plugin->api->check_address (plugin->api->cls,
- addr,
- alen))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Not confirming PING with address `%s' since I cannot
confirm having this address.\n"),
- a2s (plugin->short_name,
- addr,
- alen));
- return GNUNET_NO;
- }
- oal = plugin->addresses;
- while (NULL != oal)
- {
- if ( (oal->addrlen == alen) &&
- (0 == memcmp (addr,
- &oal[1],
- alen)) )
- break;
- oal = oal->next;
- }
- pong = GNUNET_malloc (sizeof (struct TransportPongMessage) + alen +
slen);
- pong->header.size = htons (sizeof (struct TransportPongMessage) + alen +
slen);
- pong->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PONG);
- pong->purpose.size =
- htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
- sizeof (uint32_t) +
- sizeof (struct GNUNET_TIME_AbsoluteNBO) +
- sizeof (struct GNUNET_PeerIdentity) + alen + slen);
- pong->purpose.purpose = htonl
(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN);
- pong->challenge = ping->challenge;
- pong->addrlen = htonl(alen + slen);
- memcpy(&pong->pid,
- &my_identity,
- sizeof(struct GNUNET_PeerIdentity));
- memcpy (&pong[1], plugin->short_name, slen);
- memcpy (&((char*)&pong[1])[slen], addr, alen);
- if ( (oal != NULL) &&
- (GNUNET_TIME_absolute_get_remaining
(oal->pong_sig_expires).rel_value < PONG_SIGNATURE_LIFETIME.rel_value / 4) )
- {
- /* create / update cached sig */
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _
+ ("Not confirming PING with address `%s' since I cannot
confirm having this address.\n"),
+ a2s (plugin->short_name, addr, alen));
+ return GNUNET_NO;
+ }
+ oal = plugin->addresses;
+ while (NULL != oal)
+ {
+ if ((oal->addrlen == alen) && (0 == memcmp (addr, &oal[1], alen)))
+ break;
+ oal = oal->next;
+ }
+ pong = GNUNET_malloc (sizeof (struct TransportPongMessage) + alen + slen);
+ pong->header.size =
+ htons (sizeof (struct TransportPongMessage) + alen + slen);
+ pong->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PONG);
+ pong->purpose.size =
+ htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
+ sizeof (uint32_t) +
+ sizeof (struct GNUNET_TIME_AbsoluteNBO) +
+ sizeof (struct GNUNET_PeerIdentity) + alen + slen);
+ pong->purpose.purpose = htonl
(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN);
+ pong->challenge = ping->challenge;
+ pong->addrlen = htonl (alen + slen);
+ memcpy (&pong->pid, &my_identity, sizeof (struct GNUNET_PeerIdentity));
+ memcpy (&pong[1], plugin->short_name, slen);
+ memcpy (&((char *) &pong[1])[slen], addr, alen);
+ if ((oal != NULL) &&
+ (GNUNET_TIME_absolute_get_remaining (oal->pong_sig_expires).rel_value <
+ PONG_SIGNATURE_LIFETIME.rel_value / 4))
+ {
+ /* create / update cached sig */
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Creating PONG signature to indicate ownership.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Creating PONG signature to indicate ownership.\n");
#endif
- oal->pong_sig_expires = GNUNET_TIME_relative_to_absolute
(PONG_SIGNATURE_LIFETIME);
- pong->expiration = GNUNET_TIME_absolute_hton (oal->pong_sig_expires);
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CRYPTO_rsa_sign (my_private_key,
- &pong->purpose,
- &oal->pong_signature));
- memcpy (&pong->signature,
- &oal->pong_signature,
- sizeof (struct GNUNET_CRYPTO_RsaSignature));
- }
- else if (oal == NULL)
- {
- /* not using cache (typically DV-only) */
- pong->expiration = GNUNET_TIME_absolute_hton
(GNUNET_TIME_relative_to_absolute (PONG_SIGNATURE_LIFETIME));
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CRYPTO_rsa_sign (my_private_key,
- &pong->purpose,
- &pong->signature));
- }
- else
- {
- /* can used cached version */
- pong->expiration = GNUNET_TIME_absolute_hton (oal->pong_sig_expires);
- memcpy (&pong->signature,
- &oal->pong_signature,
- sizeof (struct GNUNET_CRYPTO_RsaSignature));
- }
+ oal->pong_sig_expires =
+ GNUNET_TIME_relative_to_absolute (PONG_SIGNATURE_LIFETIME);
+ pong->expiration = GNUNET_TIME_absolute_hton (oal->pong_sig_expires);
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CRYPTO_rsa_sign (my_private_key,
+ &pong->purpose,
+ &oal->pong_signature));
+ memcpy (&pong->signature,
+ &oal->pong_signature, sizeof (struct
GNUNET_CRYPTO_RsaSignature));
}
- n = find_neighbour(peer);
+ else if (oal == NULL)
+ {
+ /* not using cache (typically DV-only) */
+ pong->expiration =
+ GNUNET_TIME_absolute_hton (GNUNET_TIME_relative_to_absolute
+ (PONG_SIGNATURE_LIFETIME));
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CRYPTO_rsa_sign (my_private_key, &pong->purpose,
+ &pong->signature));
+ }
+ else
+ {
+ /* can used cached version */
+ pong->expiration = GNUNET_TIME_absolute_hton (oal->pong_sig_expires);
+ memcpy (&pong->signature,
+ &oal->pong_signature, sizeof (struct
GNUNET_CRYPTO_RsaSignature));
+ }
+ }
+ n = find_neighbour (peer);
GNUNET_assert (n != NULL);
did_pong = GNUNET_NO;
/* first try reliable response transmission */
rl = n->plugins;
while (rl != NULL)
+ {
+ fal = rl->addresses;
+ while (fal != NULL)
{
- fal = rl->addresses;
- while (fal != NULL)
- {
- if (-1 != rl->plugin->api->send (rl->plugin->api->cls,
- peer,
- (const char*) pong,
- ntohs (pong->header.size),
- TRANSPORT_PONG_PRIORITY,
- HELLO_VERIFICATION_TIMEOUT,
- fal->session,
- fal->addr,
- fal->addrlen,
- GNUNET_SYSERR,
- NULL, NULL))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitted PONG to `%s' via reliable mechanism\n",
- GNUNET_i2s (peer));
- /* done! */
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# PONGs unicast via
reliable transport"),
- 1,
- GNUNET_NO);
- GNUNET_free (pong);
- return GNUNET_OK;
- }
- did_pong = GNUNET_YES;
- fal = fal->next;
- }
- rl = rl->next;
+ if (-1 != rl->plugin->api->send (rl->plugin->api->cls,
+ peer,
+ (const char *) pong,
+ ntohs (pong->header.size),
+ TRANSPORT_PONG_PRIORITY,
+ HELLO_VERIFICATION_TIMEOUT,
+ fal->session,
+ fal->addr,
+ fal->addrlen, GNUNET_SYSERR, NULL,
NULL))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Transmitted PONG to `%s' via reliable mechanism\n",
+ GNUNET_i2s (peer));
+ /* done! */
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# PONGs unicast via reliable transport"),
1,
+ GNUNET_NO);
+ GNUNET_free (pong);
+ return GNUNET_OK;
+ }
+ did_pong = GNUNET_YES;
+ fal = fal->next;
}
+ rl = rl->next;
+ }
/* no reliable method found, do multicast */
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# PONGs multicast to all available
addresses"),
- 1,
- GNUNET_NO);
+ gettext_noop
+ ("# PONGs multicast to all available addresses"),
1,
+ GNUNET_NO);
rl = n->plugins;
while (rl != NULL)
+ {
+ fal = rl->addresses;
+ while (fal != NULL)
{
- fal = rl->addresses;
- while (fal != NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitting PONG to `%s' via unreliable mechanism
`%s':%s\n",
- GNUNET_i2s (peer),
- a2s (rl->plugin->short_name,
- fal->addr,
- fal->addrlen),
- rl->plugin->short_name);
- transmit_to_peer(NULL, fal,
- TRANSPORT_PONG_PRIORITY,
- HELLO_VERIFICATION_TIMEOUT,
- (const char *)pong,
- ntohs(pong->header.size),
- GNUNET_YES,
- n);
- did_pong = GNUNET_YES;
- fal = fal->next;
- }
- rl = rl->next;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Transmitting PONG to `%s' via unreliable mechanism
`%s':%s\n",
+ GNUNET_i2s (peer),
+ a2s (rl->plugin->short_name,
+ fal->addr, fal->addrlen), rl->plugin->short_name);
+ transmit_to_peer (NULL, fal,
+ TRANSPORT_PONG_PRIORITY,
+ HELLO_VERIFICATION_TIMEOUT,
+ (const char *) pong,
+ ntohs (pong->header.size), GNUNET_YES, n);
+ did_pong = GNUNET_YES;
+ fal = fal->next;
}
- GNUNET_free(pong);
+ rl = rl->next;
+ }
+ GNUNET_free (pong);
if (GNUNET_YES != did_pong)
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Could not send PONG to `%s': no address available\n"),
- GNUNET_i2s (peer));
+ _("Could not send PONG to `%s': no address available\n"),
+ GNUNET_i2s (peer));
return GNUNET_OK;
}
@@ -5350,8 +5148,7 @@
const struct GNUNET_TRANSPORT_ATS_Information *ats_data,
uint32_t ats_count,
struct Session *session,
- const char *sender_address,
- uint16_t sender_address_len)
+ const char *sender_address, uint16_t sender_address_len)
{
struct TransportPlugin *plugin = cls;
struct ReadyList *service_context;
@@ -5362,14 +5159,12 @@
uint32_t distance;
int c;
- if (0 == memcmp (peer,
- &my_identity,
- sizeof (struct GNUNET_PeerIdentity)))
- {
- /* refuse to receive from myself */
- GNUNET_break (0);
- return GNUNET_TIME_UNIT_FOREVER_REL;
- }
+ if (0 == memcmp (peer, &my_identity, sizeof (struct GNUNET_PeerIdentity)))
+ {
+ /* refuse to receive from myself */
+ GNUNET_break (0);
+ return GNUNET_TIME_UNIT_FOREVER_REL;
+ }
if (is_blacklisted (peer, plugin))
return GNUNET_TIME_UNIT_FOREVER_REL;
n = find_neighbour (peer);
@@ -5382,157 +5177,160 @@
peer_address = NULL;
distance = 1;
- for (c=0; c<ats_count; c++)
- if (ntohl(ats_data[c].type) == GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE)
- distance = ntohl(ats_data[c].value);
+ for (c = 0; c < ats_count; c++)
+ if (ntohl (ats_data[c].type) == GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE)
+ distance = ntohl (ats_data[c].value);
if (message != NULL)
+ {
+ if ((session != NULL) || (sender_address != NULL))
+ peer_address = add_peer_address (n,
+ plugin->short_name,
+ session,
+ sender_address, sender_address_len);
+ if (peer_address != NULL)
{
- if ( (session != NULL) ||
- (sender_address != NULL) )
- peer_address = add_peer_address (n,
- plugin->short_name,
- session,
- sender_address,
- sender_address_len);
- if (peer_address != NULL)
- {
- update_addr_ats(peer_address, ats_data, ats_count);
- update_addr_value(peer_address, distance,
GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE);
-
- peer_address->distance = distance;
- if (GNUNET_YES == peer_address->validated)
- {
- mark_address_connected (peer_address);
- schedule_next_ping (peer_address);
- }
- else
- {
+ update_addr_ats (peer_address, ats_data, ats_count);
+ update_addr_value (peer_address, distance,
+ GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE);
+
+ peer_address->distance = distance;
+ if (GNUNET_YES == peer_address->validated)
+ {
+ mark_address_connected (peer_address);
+ schedule_next_ping (peer_address);
+ }
+ else
+ {
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "New address is unvalidated, trying to validate it
now\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "New address is unvalidated, trying to validate it now\n");
#endif
- if (peer_address->revalidate_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (peer_address->revalidate_task);
- peer_address->revalidate_task = GNUNET_SCHEDULER_NO_TASK;
- }
- peer_address->revalidate_task = GNUNET_SCHEDULER_add_now
(&send_periodic_ping, peer_address);
+ if (peer_address->revalidate_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (peer_address->revalidate_task);
+ peer_address->revalidate_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ peer_address->revalidate_task =
+ GNUNET_SCHEDULER_add_now (&send_periodic_ping, peer_address);
- }
- peer_address->timeout
- = GNUNET_TIME_relative_to_absolute
(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
- }
- /* update traffic received amount ... */
- msize = ntohs (message->size);
+ }
+ peer_address->timeout
+ =
+ GNUNET_TIME_relative_to_absolute
+ (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
+ }
+ /* update traffic received amount ... */
+ msize = ntohs (message->size);
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# bytes received from other peers"), msize,
+ GNUNET_NO);
+ n->distance = distance;
+ n->peer_timeout =
+ GNUNET_TIME_relative_to_absolute
+ (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
+ GNUNET_SCHEDULER_cancel (n->timeout_task);
+ n->timeout_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
+ &neighbour_timeout_task, n);
+ if (n->quota_violation_count > QUOTA_VIOLATION_DROP_THRESHOLD)
+ {
+ /* dropping message due to frequent inbound volume violations! */
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING |
+ GNUNET_ERROR_TYPE_BULK,
+ _
+ ("Dropping incoming message due to repeated bandwidth quota
(%u b/s) violations (total of %u).\n"),
+ n->in_tracker.available_bytes_per_s__,
+ n->quota_violation_count);
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# bytes received from other
peers"),
- msize,
- GNUNET_NO);
- n->distance = distance;
- n->peer_timeout =
- GNUNET_TIME_relative_to_absolute
- (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
- GNUNET_SCHEDULER_cancel (n->timeout_task);
- n->timeout_task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
- &neighbour_timeout_task, n);
- if (n->quota_violation_count > QUOTA_VIOLATION_DROP_THRESHOLD)
- {
- /* dropping message due to frequent inbound volume violations! */
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING |
- GNUNET_ERROR_TYPE_BULK,
- _
- ("Dropping incoming message due to repeated bandwidth
quota (%u b/s) violations (total of %u).\n"),
- n->in_tracker.available_bytes_per_s__,
- n->quota_violation_count);
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# bandwidth quota violations
by other peers"),
- 1,
- GNUNET_NO);
- return GNUNET_CONSTANTS_QUOTA_VIOLATION_TIMEOUT;
- }
- if ((ntohs(message->type) == GNUNET_MESSAGE_TYPE_TRANSPORT_ATS) &&
- (ntohs(message->size) == (sizeof (struct GNUNET_MessageHeader) + sizeof
(uint32_t))))
- {
+ gettext_noop
+ ("# bandwidth quota violations by other
peers"),
+ 1, GNUNET_NO);
+ return GNUNET_CONSTANTS_QUOTA_VIOLATION_TIMEOUT;
+ }
+ if ((ntohs (message->type) == GNUNET_MESSAGE_TYPE_TRANSPORT_ATS) &&
+ (ntohs (message->size) ==
+ (sizeof (struct GNUNET_MessageHeader) + sizeof (uint32_t))))
+ {
#if HAVE_LIBGLPK
- uint32_t value = ntohl(*((uint32_t *) &message[1]));
- //GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"GNUNET_MESSAGE_TYPE_TRANSPORT_ATS: %i \n", value);
- /* Force ressource and quality update */
- if ((value == 4) && (ats != NULL))
- ats_modify_problem_state(ats, ATS_QUALITY_COST_UPDATED);
- /* Force cost update */
- if ((value == 3) && (ats != NULL))
- ats_modify_problem_state(ats, ATS_COST_UPDATED);
- /* Force quality update */
- if ((value == 2) && (ats != NULL))
- ats_modify_problem_state(ats, ATS_QUALITY_UPDATED);
- /* Force full rebuild */
- if ((value == 1) && (ats != NULL))
- ats_modify_problem_state(ats, ATS_MODIFIED);
+ uint32_t value = ntohl (*((uint32_t *) & message[1]));
+
+ //GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"GNUNET_MESSAGE_TYPE_TRANSPORT_ATS: %i \n", value);
+ /* Force ressource and quality update */
+ if ((value == 4) && (ats != NULL))
+ ats_modify_problem_state (ats, ATS_QUALITY_COST_UPDATED);
+ /* Force cost update */
+ if ((value == 3) && (ats != NULL))
+ ats_modify_problem_state (ats, ATS_COST_UPDATED);
+ /* Force quality update */
+ if ((value == 2) && (ats != NULL))
+ ats_modify_problem_state (ats, ATS_QUALITY_UPDATED);
+ /* Force full rebuild */
+ if ((value == 1) && (ats != NULL))
+ ats_modify_problem_state (ats, ATS_MODIFIED);
#endif
- }
-
+ }
+
#if DEBUG_PING_PONG
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received message of type %u and size %u from `%4s', sending to
all clients.\n",
- ntohs (message->type),
- ntohs (message->size),
- GNUNET_i2s (peer));
+ "Received message of type %u and size %u from `%4s', sending
to all clients.\n",
+ ntohs (message->type),
+ ntohs (message->size), GNUNET_i2s (peer));
#endif
- switch (ntohs (message->type))
- {
- case GNUNET_MESSAGE_TYPE_HELLO:
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# HELLO messages received
from other peers"),
- 1,
- GNUNET_NO);
- process_hello (plugin, message);
- break;
- case GNUNET_MESSAGE_TYPE_TRANSPORT_PING:
- handle_ping (plugin, message, peer, session, sender_address,
sender_address_len);
- if (GNUNET_YES != n->received_pong)
- transmit_plain_ping (n);
- break;
- case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG:
- handle_pong (plugin, message, peer, sender_address,
sender_address_len);
- break;
- case GNUNET_MESSAGE_TYPE_TRANSPORT_ATS:
- break;
- default:
- handle_payload_message (message, n);
- break;
- }
+ switch (ntohs (message->type))
+ {
+ case GNUNET_MESSAGE_TYPE_HELLO:
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# HELLO messages received from other peers"),
+ 1, GNUNET_NO);
+ process_hello (plugin, message);
+ break;
+ case GNUNET_MESSAGE_TYPE_TRANSPORT_PING:
+ handle_ping (plugin, message, peer, session, sender_address,
+ sender_address_len);
+ if (GNUNET_YES != n->received_pong)
+ transmit_plain_ping (n);
+ break;
+ case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG:
+ handle_pong (plugin, message, peer, sender_address, sender_address_len);
+ break;
+ case GNUNET_MESSAGE_TYPE_TRANSPORT_ATS:
+ break;
+ default:
+ handle_payload_message (message, n);
+ break;
}
+ }
ret = GNUNET_BANDWIDTH_tracker_get_delay (&n->in_tracker, 0);
if (ret.rel_value > 0)
- {
-#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Throttling read (%llu bytes excess at %u b/s), waiting %llu
ms before reading more.\n",
- (unsigned long long)
n->in_tracker.consumption_since_last_update__,
- (unsigned int) n->in_tracker.available_bytes_per_s__,
- (unsigned long long) ret.rel_value);
+ {
+#if DEBUG_TRANSPORT
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Throttling read (%llu bytes excess at %u b/s), waiting %llu
ms before reading more.\n",
+ (unsigned long long) n->
+ in_tracker.consumption_since_last_update__,
+ (unsigned int) n->in_tracker.available_bytes_per_s__,
+ (unsigned long long) ret.rel_value);
#endif
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# ms throttling suggested"),
- (int64_t) ret.rel_value,
- GNUNET_NO);
- }
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# ms throttling suggested"),
+ (int64_t) ret.rel_value, GNUNET_NO);
+ }
return ret;
}
static int
notify_client_about_neighbour (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+ const GNUNET_HashCode * key, void *value)
{
struct TransportClient *c = cls;
struct NeighbourMapEntry *n = value;
- struct ConnectInfoMessage * cim;
+ struct ConnectInfoMessage *cim;
uint32_t ats_count;
size_t size;
@@ -5540,23 +5338,25 @@
return GNUNET_OK;
ats_count = 2;
- size = sizeof (struct ConnectInfoMessage) + ats_count * sizeof (struct
GNUNET_TRANSPORT_ATS_Information);
+ size =
+ sizeof (struct ConnectInfoMessage) +
+ ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
GNUNET_assert (size < GNUNET_SERVER_MAX_MESSAGE_SIZE);
cim = GNUNET_malloc (size);
cim->header.size = htons (size);
cim->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
- cim->ats_count = htonl(ats_count);
+ cim->ats_count = htonl (ats_count);
(&(cim->ats))[2].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
- (&(cim->ats))[2].value = htonl (0);
+ (&(cim->ats))[2].value = htonl (0);
if (GNUNET_YES == n->received_pong)
- {
- (&cim->ats)[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE);
- (&cim->ats)[0].value = htonl (n->distance);
- (&cim->ats)[1].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY);
- (&cim->ats)[1].value = htonl ((uint32_t) n->latency.rel_value);
- cim->id = n->id;
- transmit_to_client (c, &cim->header, GNUNET_NO);
- }
+ {
+ (&cim->ats)[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE);
+ (&cim->ats)[0].value = htonl (n->distance);
+ (&cim->ats)[1].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY);
+ (&cim->ats)[1].value = htonl ((uint32_t) n->latency.rel_value);
+ cim->id = n->id;
+ transmit_to_client (c, &cim->header, GNUNET_NO);
+ }
GNUNET_free (cim);
return GNUNET_OK;
}
@@ -5578,60 +5378,59 @@
const struct StartMessage *start;
struct TransportClient *c;
- start = (const struct StartMessage*) message;
+ start = (const struct StartMessage *) message;
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received `%s' request from client\n", "START");
#endif
c = clients;
while (c != NULL)
+ {
+ if (c->client == client)
{
- if (c->client == client)
- {
- /* client already on our list! */
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
- c = c->next;
- }
- if ( (GNUNET_NO != ntohl (start->do_check)) &&
- (0 != memcmp (&start->self,
- &my_identity,
- sizeof (struct GNUNET_PeerIdentity))) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Rejecting control connection from peer `%s', which is not
me!\n"),
- GNUNET_i2s (&start->self));
+ /* client already on our list! */
+ GNUNET_break (0);
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
+ c = c->next;
+ }
+ if ((GNUNET_NO != ntohl (start->do_check)) &&
+ (0 != memcmp (&start->self,
+ &my_identity, sizeof (struct GNUNET_PeerIdentity))))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _
+ ("Rejecting control connection from peer `%s', which is not
me!\n"),
+ GNUNET_i2s (&start->self));
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
c = GNUNET_malloc (sizeof (struct TransportClient));
c->next = clients;
clients = c;
c->client = client;
if (our_hello != NULL)
- {
+ {
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending our own `%s' to new client\n", "HELLO");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending our own `%s' to new client\n", "HELLO");
#endif
- transmit_to_client (c,
- (const struct GNUNET_MessageHeader *) our_hello,
- GNUNET_NO);
- /* tell new client about all existing connections */
- GNUNET_CONTAINER_multihashmap_iterate (neighbours,
- ¬ify_client_about_neighbour,
- c);
- }
+ transmit_to_client (c,
+ (const struct GNUNET_MessageHeader *) our_hello,
+ GNUNET_NO);
+ /* tell new client about all existing connections */
+ GNUNET_CONTAINER_multihashmap_iterate (neighbours,
+ ¬ify_client_about_neighbour, c);
+ }
else
- {
+ {
#if DEBUG_TRANSPORT_HELLO
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "No HELLO created yet, will transmit HELLO to client
later!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "No HELLO created yet, will transmit HELLO to client
later!\n");
#endif
- refresh_hello ();
- }
+ refresh_hello ();
+ }
GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
@@ -5651,9 +5450,8 @@
int ret;
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# HELLOs received from clients"),
- 1,
- GNUNET_NO);
+ gettext_noop ("# HELLOs received from clients"),
+ 1, GNUNET_NO);
ret = process_hello (NULL, message);
GNUNET_SERVER_receive_done (client, ret);
}
@@ -5694,8 +5492,7 @@
* @param n destination, or NULL on error (in that case, drop the message)
*/
static void
-transmit_client_message (void *cls,
- struct NeighbourMapEntry *n)
+transmit_client_message (void *cls, struct NeighbourMapEntry *n)
{
struct TransmitClientMessageContext *tcmc = cls;
struct TransportClient *tc;
@@ -5705,12 +5502,11 @@
tc = tc->next;
if (n != NULL)
- {
- transmit_to_peer (tc, NULL, tcmc->priority,
- GNUNET_TIME_absolute_get_remaining (tcmc->timeout),
- (char *)&tcmc[1],
- tcmc->msize, GNUNET_NO, n);
- }
+ {
+ transmit_to_peer (tc, NULL, tcmc->priority,
+ GNUNET_TIME_absolute_get_remaining (tcmc->timeout),
+ (char *) &tcmc[1], tcmc->msize, GNUNET_NO, n);
+ }
GNUNET_SERVER_receive_done (tcmc->client, GNUNET_OK);
GNUNET_SERVER_client_drop (tcmc->client);
GNUNET_free (tcmc);
@@ -5738,36 +5534,34 @@
size = ntohs (message->size);
if (size <
sizeof (struct OutboundMessage) + sizeof (struct GNUNET_MessageHeader))
- {
- 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 (stats,
- gettext_noop ("# payload received for other peers"),
- size,
- GNUNET_NO);
+ gettext_noop ("# payload received for other
peers"),
+ size, GNUNET_NO);
obm = (const struct OutboundMessage *) message;
obmm = (const struct GNUNET_MessageHeader *) &obm[1];
msize = size - sizeof (struct OutboundMessage);
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received `%s' request from client with target `%4s' and message
of type %u and size %u\n",
- "SEND", GNUNET_i2s (&obm->peer),
- ntohs (obmm->type),
- msize);
+ "SEND", GNUNET_i2s (&obm->peer), ntohs (obmm->type), msize);
#endif
tcmc = GNUNET_malloc (sizeof (struct TransmitClientMessageContext) + msize);
tcmc->client = client;
tcmc->priority = ntohl (obm->priority);
- tcmc->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_ntoh
(obm->timeout));
+ tcmc->timeout =
+ GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_ntoh
+ (obm->timeout));
tcmc->msize = msize;
/* FIXME: this memcpy can be up to 7% of our total runtime */
memcpy (&tcmc[1], obmm, msize);
GNUNET_SERVER_client_keep (client);
setup_peer_check_blacklist (&obm->peer, GNUNET_YES,
- &transmit_client_message,
- tcmc);
+ &transmit_client_message, tcmc);
}
@@ -5784,19 +5578,18 @@
const struct GNUNET_MessageHeader *message)
{
const struct TransportRequestConnectMessage *trcm =
- (const struct TransportRequestConnectMessage *) message;
+ (const struct TransportRequestConnectMessage *) message;
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# REQUEST CONNECT messages
received"),
- 1,
+ gettext_noop
+ ("# REQUEST CONNECT messages received"), 1,
GNUNET_NO);
#if DEBUG_TRANSPORT
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Received a request connect message for peer `%s'\n",
- GNUNET_i2s(&trcm->peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received a request connect message for peer `%s'\n",
+ GNUNET_i2s (&trcm->peer));
#endif
- setup_peer_check_blacklist (&trcm->peer, GNUNET_YES,
- NULL, NULL);
+ setup_peer_check_blacklist (&trcm->peer, GNUNET_YES, NULL, NULL);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
@@ -5813,47 +5606,43 @@
struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
- const struct QuotaSetMessage *qsm =
- (const struct QuotaSetMessage *) message;
+ const struct QuotaSetMessage *qsm = (const struct QuotaSetMessage *) message;
struct NeighbourMapEntry *n;
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# SET QUOTA messages received"),
- 1,
- GNUNET_NO);
+ gettext_noop ("# SET QUOTA messages received"),
+ 1, GNUNET_NO);
n = find_neighbour (&qsm->peer);
if (n == NULL)
- {
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# SET QUOTA messages ignored (no
such peer)"),
- 1,
- GNUNET_NO);
- return;
- }
-#if DEBUG_TRANSPORT
+ {
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# SET QUOTA messages ignored (no such peer)"),
+ 1, GNUNET_NO);
+ return;
+ }
+#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received `%s' request (new quota %u, old quota %u) from client
for peer `%4s'\n",
"SET_QUOTA",
- (unsigned int) ntohl (qsm->quota.value__),
- (unsigned int) n->in_tracker.available_bytes_per_s__,
- GNUNET_i2s (&qsm->peer));
+ (unsigned int) ntohl (qsm->quota.value__),
+ (unsigned int) n->in_tracker.available_bytes_per_s__,
+ GNUNET_i2s (&qsm->peer));
#endif
- GNUNET_BANDWIDTH_tracker_update_quota (&n->in_tracker,
- qsm->quota);
+ GNUNET_BANDWIDTH_tracker_update_quota (&n->in_tracker, qsm->quota);
if (0 == ntohl (qsm->quota.value__))
- {
+ {
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Disconnecting peer `%4s', %s\n", GNUNET_i2s(&n->id),
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Disconnecting peer `%4s', %s\n", GNUNET_i2s (&n->id),
"SET_QUOTA");
#endif
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# disconnects due to quota of
0"),
- 1,
- GNUNET_NO);
- disconnect_neighbour (n, GNUNET_NO);
- }
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# disconnects due to quota of 0"),
+ 1, GNUNET_NO);
+ disconnect_neighbour (n, GNUNET_NO);
+ }
GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
@@ -5872,17 +5661,17 @@
size_t slen;
if (NULL != address)
- {
- slen = strlen (address) + 1;
- GNUNET_SERVER_transmit_context_append_data (tc, address, slen,
-
GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
- }
+ {
+ slen = strlen (address) + 1;
+ GNUNET_SERVER_transmit_context_append_data (tc, address, slen,
+
GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
+ }
else
- {
- GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
-
GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
- GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
- }
+ {
+ GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
+
GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
+ GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
+ }
}
@@ -5909,45 +5698,46 @@
size = ntohs (message->size);
if (size < sizeof (struct AddressLookupMessage))
- {
- GNUNET_break_op (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ {
+ GNUNET_break_op (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
alum = (const struct AddressLookupMessage *) message;
uint32_t addressLen = ntohl (alum->addrlen);
+
if (size <= sizeof (struct AddressLookupMessage) + addressLen)
- {
- GNUNET_break_op (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ {
+ GNUNET_break_op (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
address = (const char *) &alum[1];
nameTransport = (const char *) &address[addressLen];
if (nameTransport
[size - sizeof (struct AddressLookupMessage) - addressLen - 1] != '\0')
- {
- GNUNET_break_op (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ {
+ GNUNET_break_op (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
rtimeout = GNUNET_TIME_relative_ntoh (alum->timeout);
numeric = ntohl (alum->numeric_only);
lsPlugin = find_transport (nameTransport);
if (NULL == lsPlugin)
- {
- tc = GNUNET_SERVER_transmit_context_create (client);
- GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
-
GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
- GNUNET_SERVER_transmit_context_run (tc, rtimeout);
- return;
- }
+ {
+ tc = GNUNET_SERVER_transmit_context_create (client);
+ GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
+
GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
+ GNUNET_SERVER_transmit_context_run (tc, rtimeout);
+ return;
+ }
GNUNET_SERVER_disable_receive_done_warning (client);
tc = GNUNET_SERVER_transmit_context_create (client);
lsPlugin->api->address_pretty_printer (lsPlugin->api->cls,
- nameTransport,
+ nameTransport,
address, addressLen,
- numeric,
+ numeric,
rtimeout,
&transmit_address_to_client, tc);
}
@@ -5961,8 +5751,8 @@
*/
static void
handle_peer_address_lookup (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
const struct PeerAddressLookupMessage *peer_address_lookup;
struct NeighbourMapEntry *neighbor_iterator;
@@ -5977,11 +5767,11 @@
size = ntohs (message->size);
if (size < sizeof (struct PeerAddressLookupMessage))
- {
- GNUNET_break_op (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ {
+ GNUNET_break_op (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
peer_address_lookup = (const struct PeerAddressLookupMessage *) message;
rtimeout = GNUNET_TIME_relative_ntoh (peer_address_lookup->timeout);
@@ -5990,56 +5780,54 @@
/* Found no neighbor matching this peer id (shouldn't be possible, but...) */
if (neighbor_iterator == NULL)
- {
- GNUNET_break(0);
- tc = GNUNET_SERVER_transmit_context_create (client);
- GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
-
GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
- GNUNET_SERVER_transmit_context_run (tc, rtimeout);
- return;
- }
+ {
+ GNUNET_break (0);
+ tc = GNUNET_SERVER_transmit_context_create (client);
+ GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
+
GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
+ GNUNET_SERVER_transmit_context_run (tc, rtimeout);
+ return;
+ }
ready_iterator = neighbor_iterator->plugins;
GNUNET_SERVER_disable_receive_done_warning (client);
tc = GNUNET_SERVER_transmit_context_create (client);
- while(ready_iterator != NULL)
+ while (ready_iterator != NULL)
+ {
+ foreign_address_iterator = ready_iterator->addresses;
+ while (foreign_address_iterator != NULL)
{
- foreign_address_iterator = ready_iterator->addresses;
- while (foreign_address_iterator != NULL)
- {
- transport_plugin = foreign_address_iterator->ready_list->plugin;
- if (foreign_address_iterator->addr != NULL)
- {
- GNUNET_asprintf (&addr_buf, "%s --- %s, %s",
- a2s (transport_plugin->short_name,
- foreign_address_iterator->addr,
- foreign_address_iterator->addrlen),
- (foreign_address_iterator->connected
- == GNUNET_YES) ? "CONNECTED"
- : "DISCONNECTED",
- (foreign_address_iterator->validated
- == GNUNET_YES) ? "VALIDATED"
- : "UNVALIDATED");
- transmit_address_to_client(tc, addr_buf);
- GNUNET_free (addr_buf);
- }
- else if (foreign_address_iterator->addrlen == 0)
- {
- GNUNET_asprintf (&addr_buf, "%s --- %s, %s", "<inbound>",
- (foreign_address_iterator->connected
- == GNUNET_YES) ? "CONNECTED"
- : "DISCONNECTED",
- (foreign_address_iterator->validated
- == GNUNET_YES) ? "VALIDATED"
- : "UNVALIDATED");
- transmit_address_to_client (tc, addr_buf);
- GNUNET_free (addr_buf);
- }
+ transport_plugin = foreign_address_iterator->ready_list->plugin;
+ if (foreign_address_iterator->addr != NULL)
+ {
+ GNUNET_asprintf (&addr_buf, "%s --- %s, %s",
+ a2s (transport_plugin->short_name,
+ foreign_address_iterator->addr,
+ foreign_address_iterator->addrlen),
+ (foreign_address_iterator->connected
+ == GNUNET_YES) ? "CONNECTED"
+ : "DISCONNECTED",
+ (foreign_address_iterator->validated
+ == GNUNET_YES) ? "VALIDATED" : "UNVALIDATED");
+ transmit_address_to_client (tc, addr_buf);
+ GNUNET_free (addr_buf);
+ }
+ else if (foreign_address_iterator->addrlen == 0)
+ {
+ GNUNET_asprintf (&addr_buf, "%s --- %s, %s", "<inbound>",
+ (foreign_address_iterator->connected
+ == GNUNET_YES) ? "CONNECTED"
+ : "DISCONNECTED",
+ (foreign_address_iterator->validated
+ == GNUNET_YES) ? "VALIDATED" : "UNVALIDATED");
+ transmit_address_to_client (tc, addr_buf);
+ GNUNET_free (addr_buf);
+ }
- foreign_address_iterator = foreign_address_iterator->next;
- }
- ready_iterator = ready_iterator->next;
+ foreign_address_iterator = foreign_address_iterator->next;
}
+ ready_iterator = ready_iterator->next;
+ }
GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
@@ -6048,9 +5836,7 @@
static int
-output_addresses (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+output_addresses (void *cls, const GNUNET_HashCode * key, void *value)
{
struct GNUNET_SERVER_TransmitContext *tc = cls;
struct NeighbourMapEntry *neighbor_iterator = value;
@@ -6061,46 +5847,44 @@
ready_iterator = neighbor_iterator->plugins;
while (ready_iterator != NULL)
+ {
+ foreign_address_iterator = ready_iterator->addresses;
+ while (foreign_address_iterator != NULL)
{
- foreign_address_iterator = ready_iterator->addresses;
- while (foreign_address_iterator != NULL)
- {
- transport_plugin = foreign_address_iterator->ready_list->plugin;
- if (foreign_address_iterator->addr != NULL)
- {
- GNUNET_asprintf (&addr_buf, "%s:%s --- %s, %s",
- GNUNET_i2s(&neighbor_iterator->id),
- a2s (transport_plugin->short_name,
- foreign_address_iterator->addr,
- foreign_address_iterator->addrlen),
- (foreign_address_iterator->connected
- == GNUNET_YES) ? "CONNECTED"
- : "DISCONNECTED",
- (foreign_address_iterator->validated
- == GNUNET_YES) ? "VALIDATED"
- : "UNVALIDATED");
- transmit_address_to_client (tc, addr_buf);
- GNUNET_free (addr_buf);
- }
- else if (foreign_address_iterator->addrlen == 0)
- {
- GNUNET_asprintf (&addr_buf, "%s:%s --- %s, %s",
- GNUNET_i2s (&neighbor_iterator->id),
- "<inbound>",
- (foreign_address_iterator->connected
- == GNUNET_YES) ? "CONNECTED"
- : "DISCONNECTED",
- (foreign_address_iterator->validated
- == GNUNET_YES) ? "VALIDATED"
- : "UNVALIDATED");
- transmit_address_to_client (tc, addr_buf);
- GNUNET_free (addr_buf);
- }
-
- foreign_address_iterator = foreign_address_iterator->next;
- }
- ready_iterator = ready_iterator->next;
+ transport_plugin = foreign_address_iterator->ready_list->plugin;
+ if (foreign_address_iterator->addr != NULL)
+ {
+ GNUNET_asprintf (&addr_buf, "%s:%s --- %s, %s",
+ GNUNET_i2s (&neighbor_iterator->id),
+ a2s (transport_plugin->short_name,
+ foreign_address_iterator->addr,
+ foreign_address_iterator->addrlen),
+ (foreign_address_iterator->connected
+ == GNUNET_YES) ? "CONNECTED"
+ : "DISCONNECTED",
+ (foreign_address_iterator->validated
+ == GNUNET_YES) ? "VALIDATED" : "UNVALIDATED");
+ transmit_address_to_client (tc, addr_buf);
+ GNUNET_free (addr_buf);
+ }
+ else if (foreign_address_iterator->addrlen == 0)
+ {
+ GNUNET_asprintf (&addr_buf, "%s:%s --- %s, %s",
+ GNUNET_i2s (&neighbor_iterator->id),
+ "<inbound>",
+ (foreign_address_iterator->connected
+ == GNUNET_YES) ? "CONNECTED"
+ : "DISCONNECTED",
+ (foreign_address_iterator->validated
+ == GNUNET_YES) ? "VALIDATED" : "UNVALIDATED");
+ transmit_address_to_client (tc, addr_buf);
+ GNUNET_free (addr_buf);
+ }
+
+ foreign_address_iterator = foreign_address_iterator->next;
}
+ ready_iterator = ready_iterator->next;
+ }
return GNUNET_OK;
}
@@ -6122,16 +5906,14 @@
size = ntohs (message->size);
if (size < sizeof (struct AddressIterateMessage))
- {
- GNUNET_break_op (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ {
+ GNUNET_break_op (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
GNUNET_SERVER_disable_receive_done_warning (client);
tc = GNUNET_SERVER_transmit_context_create (client);
- GNUNET_CONTAINER_multihashmap_iterate (neighbours,
- &output_addresses,
- tc);
+ GNUNET_CONTAINER_multihashmap_iterate (neighbours, &output_addresses, tc);
GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
@@ -6141,7 +5923,7 @@
static const struct GNUNET_MessageHeader *
do_get_our_hello ()
{
- return (const struct GNUNET_MessageHeader*) our_hello;
+ return (const struct GNUNET_MessageHeader *) our_hello;
}
@@ -6167,8 +5949,7 @@
* Start the specified transport (load the plugin).
*/
static void
-start_transport (struct GNUNET_SERVER_Handle *server,
- const char *name)
+start_transport (struct GNUNET_SERVER_Handle *server, const char *name)
{
struct TransportPlugin *plug;
char *libname;
@@ -6184,31 +5965,29 @@
plugins = plug;
plug->api = GNUNET_PLUGIN_load (libname, &plug->env);
if (plug->api == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to load transport plugin for `%s'\n"), name);
- GNUNET_free (plug->short_name);
- plugins = plug->next;
- GNUNET_free (libname);
- GNUNET_free (plug);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to load transport plugin for `%s'\n"), name);
+ GNUNET_free (plug->short_name);
+ plugins = plug->next;
+ GNUNET_free (libname);
+ GNUNET_free (plug);
+ }
}
static int
-null_mq_client_pointers (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+null_mq_client_pointers (void *cls, const GNUNET_HashCode * key, void *value)
{
struct TransportClient *pos = cls;
struct NeighbourMapEntry *n = value;
struct MessageQueue *mq;
for (mq = n->messages_head; mq != NULL; mq = mq->next)
- {
- if (mq->client == pos)
- mq->client = NULL; /* do not use anymore! */
- }
+ {
+ if (mq->client == pos)
+ mq->client = NULL; /* do not use anymore! */
+ }
return GNUNET_OK;
}
@@ -6221,8 +6000,7 @@
* @param client identification of the client
*/
static void
-client_disconnect_notification (void *cls,
- struct GNUNET_SERVER_Client *client)
+client_disconnect_notification (void *cls, struct GNUNET_SERVER_Client *client)
{
struct TransportClient *pos;
struct TransportClient *prev;
@@ -6239,89 +6017,81 @@
/* clean up blacklister */
bl = bl_head;
while (bl != NULL)
+ {
+ if (bl->client == client)
{
- if (bl->client == client)
- {
- bc = bc_head;
- while (bc != NULL)
- {
- if (bc->bl_pos == bl)
- {
- bc->bl_pos = bl->next;
- if (bc->th != NULL)
- {
- GNUNET_CONNECTION_notify_transmit_ready_cancel (bc->th);
- bc->th = NULL;
- }
- if (bc->task == GNUNET_SCHEDULER_NO_TASK)
- bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check,
- bc);
- break;
- }
- bc = bc->next;
- }
- GNUNET_CONTAINER_DLL_remove (bl_head,
- bl_tail,
- bl);
- GNUNET_SERVER_client_drop (bl->client);
- GNUNET_free (bl);
- break;
- }
- bl = bl->next;
+ bc = bc_head;
+ while (bc != NULL)
+ {
+ if (bc->bl_pos == bl)
+ {
+ bc->bl_pos = bl->next;
+ if (bc->th != NULL)
+ {
+ GNUNET_CONNECTION_notify_transmit_ready_cancel (bc->th);
+ bc->th = NULL;
+ }
+ if (bc->task == GNUNET_SCHEDULER_NO_TASK)
+ bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc);
+ break;
+ }
+ bc = bc->next;
+ }
+ GNUNET_CONTAINER_DLL_remove (bl_head, bl_tail, bl);
+ GNUNET_SERVER_client_drop (bl->client);
+ GNUNET_free (bl);
+ break;
}
+ bl = bl->next;
+ }
/* clean up 'normal' clients */
prev = NULL;
pos = clients;
while ((pos != NULL) && (pos->client != client))
- {
- prev = pos;
- pos = pos->next;
- }
+ {
+ prev = pos;
+ pos = pos->next;
+ }
if (pos == NULL)
return;
while (NULL != (mqe = pos->message_queue_head))
- {
- GNUNET_CONTAINER_DLL_remove (pos->message_queue_head,
- pos->message_queue_tail,
- mqe);
- pos->message_count--;
- GNUNET_free (mqe);
- }
+ {
+ GNUNET_CONTAINER_DLL_remove (pos->message_queue_head,
+ pos->message_queue_tail, mqe);
+ pos->message_count--;
+ GNUNET_free (mqe);
+ }
if (NULL != neighbours)
GNUNET_CONTAINER_multihashmap_iterate (neighbours,
- &null_mq_client_pointers,
- pos);
+ &null_mq_client_pointers, pos);
if (prev == NULL)
clients = pos->next;
else
prev->next = pos->next;
if (GNUNET_YES == pos->tcs_pending)
- {
- pos->client = NULL;
- return;
- }
+ {
+ pos->client = NULL;
+ return;
+ }
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_break (0 == pos->message_count);
GNUNET_free (pos);
}
static int
-disconnect_all_neighbours (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+disconnect_all_neighbours (void *cls, const GNUNET_HashCode * key, void *value)
{
struct NeighbourMapEntry *n = value;
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Disconnecting peer `%4s', %s\n",
- GNUNET_i2s(&n->id),
- "SHUTDOWN_TASK");
+ "Disconnecting peer `%4s', %s\n",
+ GNUNET_i2s (&n->id), "SHUTDOWN_TASK");
#endif
disconnect_neighbour (n, GNUNET_NO);
return GNUNET_OK;
@@ -6344,44 +6114,42 @@
shutdown_in_progress = GNUNET_YES;
GNUNET_CONTAINER_multihashmap_iterate (neighbours,
- &disconnect_all_neighbours,
- NULL);
+ &disconnect_all_neighbours, NULL);
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Transport service is unloading plugins...\n");
#endif
while (NULL != (plug = plugins))
+ {
+ if (plug->address_update_task != GNUNET_SCHEDULER_NO_TASK)
{
- if (plug->address_update_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (plug->address_update_task);
- plug->address_update_task = GNUNET_SCHEDULER_NO_TASK;
- }
- GNUNET_break (NULL == GNUNET_PLUGIN_unload (plug->lib_name, plug->api));
- GNUNET_free (plug->lib_name);
- GNUNET_free (plug->short_name);
- while (NULL != (al = plug->addresses))
- {
- plug->addresses = al->next;
- GNUNET_free (al);
- }
- plugins = plug->next;
- GNUNET_free (plug);
+ GNUNET_SCHEDULER_cancel (plug->address_update_task);
+ plug->address_update_task = GNUNET_SCHEDULER_NO_TASK;
}
+ GNUNET_break (NULL == GNUNET_PLUGIN_unload (plug->lib_name, plug->api));
+ GNUNET_free (plug->lib_name);
+ GNUNET_free (plug->short_name);
+ while (NULL != (al = plug->addresses))
+ {
+ plug->addresses = al->next;
+ GNUNET_free (al);
+ }
+ plugins = plug->next;
+ GNUNET_free (plug);
+ }
if (my_private_key != NULL)
GNUNET_CRYPTO_rsa_key_free (my_private_key);
GNUNET_free_non_null (our_hello);
GNUNET_CONTAINER_multihashmap_iterate (validation_map,
- &abort_validation,
- NULL);
+ &abort_validation, NULL);
GNUNET_CONTAINER_multihashmap_destroy (validation_map);
validation_map = NULL;
if (ats_task != GNUNET_SCHEDULER_NO_TASK)
{
- GNUNET_SCHEDULER_cancel(ats_task);
+ GNUNET_SCHEDULER_cancel (ats_task);
ats_task = GNUNET_SCHEDULER_NO_TASK;
}
#if HAVE_LIBGLPK
@@ -6391,41 +6159,41 @@
/* free 'chvc' data structure */
while (NULL != (chvc = chvc_head))
+ {
+ chvc_head = chvc->next;
+ if (chvc->piter != NULL)
{
- chvc_head = chvc->next;
- if (chvc->piter != NULL)
- {
- GNUNET_PEERINFO_iterate_cancel (chvc->piter);
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# outstanding peerinfo
iterate requests"),
- -1,
- GNUNET_NO);
- chvc->ve_count --;
- }
- else
- GNUNET_break (0);
- GNUNET_assert (chvc->ve_count == 0);
- GNUNET_free (chvc);
+ GNUNET_PEERINFO_iterate_cancel (chvc->piter);
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# outstanding peerinfo iterate requests"),
-1,
+ GNUNET_NO);
+ chvc->ve_count--;
}
+ else
+ GNUNET_break (0);
+ GNUNET_assert (chvc->ve_count == 0);
+ GNUNET_free (chvc);
+ }
chvc_tail = NULL;
if (stats != NULL)
- {
- GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
- stats = NULL;
- }
+ {
+ GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
+ stats = NULL;
+ }
if (peerinfo != NULL)
- {
- GNUNET_PEERINFO_disconnect (peerinfo);
- peerinfo = NULL;
- }
+ {
+ GNUNET_PEERINFO_disconnect (peerinfo);
+ peerinfo = NULL;
+ }
if (GNUNET_SCHEDULER_NO_TASK != hello_task)
- {
- GNUNET_SCHEDULER_cancel (hello_task);
- hello_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (hello_task);
+ hello_task = GNUNET_SCHEDULER_NO_TASK;
+ }
/* Can we assume those are gone by now, or do we need to clean up
- explicitly!? */
+ * explicitly!? */
GNUNET_break (bl_head == NULL);
GNUNET_break (bc_head == NULL);
GNUNET_CONTAINER_multihashmap_destroy (neighbours);
@@ -6433,17 +6201,17 @@
}
-void ats_result_cb ()
+void
+ats_result_cb ()
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "ATS Result callback\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS Result callback\n");
}
#if HAVE_LIBGLPK
struct AtsBuildContext
{
- struct ATS_mechanism * mechanisms;
+ struct ATS_mechanism *mechanisms;
struct ATS_peer *peers;
int c_peers;
int c_mechs;
@@ -6451,70 +6219,70 @@
static int
-find_and_count_addresses (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+find_and_count_addresses (void *cls, const GNUNET_HashCode * key, void *value)
{
struct AtsBuildContext *abc = cls;
- struct NeighbourMapEntry *next = value;
+ struct NeighbourMapEntry *next = value;
int found_addresses = GNUNET_NO;
-
+
struct ReadyList *r_next = next->plugins;
+
while (r_next != NULL)
+ {
+ struct ForeignAddressList *a_next = r_next->addresses;
+
+ while (a_next != NULL)
{
- struct ForeignAddressList * a_next = r_next->addresses;
- while (a_next != NULL)
- {
- abc->c_mechs++;
- found_addresses = GNUNET_YES;
- a_next = a_next->next;
- }
- r_next = r_next->next;
+ abc->c_mechs++;
+ found_addresses = GNUNET_YES;
+ a_next = a_next->next;
}
- if (found_addresses)
+ r_next = r_next->next;
+ }
+ if (found_addresses)
abc->c_peers++;
return GNUNET_OK;
}
static int
-setup_ats_problem (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+setup_ats_problem (void *cls, const GNUNET_HashCode * key, void *value)
{
struct AtsBuildContext *abc = cls;
- struct NeighbourMapEntry *next = value;
+ struct NeighbourMapEntry *next = value;
int found_addresses = GNUNET_NO;
struct ReadyList *r_next = next->plugins;
+
while (r_next != NULL)
+ {
+ struct ForeignAddressList *a_next = r_next->addresses;
+
+ while (a_next != NULL)
{
- struct ForeignAddressList * a_next = r_next->addresses;
- while (a_next != NULL)
- {
- if (found_addresses == GNUNET_NO)
- {
- abc->peers[abc->c_peers].peer = next->id;
- abc->peers[abc->c_peers].m_head = NULL;
- abc->peers[abc->c_peers].m_tail = NULL;
- abc->peers[abc->c_peers].f = 1.0 / abc->c_mechs;
- }
- abc->mechanisms[abc->c_mechs].addr = a_next;
- abc->mechanisms[abc->c_mechs].col_index = abc->c_mechs;
- abc->mechanisms[abc->c_mechs].peer = &abc->peers[abc->c_peers];
- abc->mechanisms[abc->c_mechs].next = NULL;
- abc->mechanisms[abc->c_mechs].plugin = r_next->plugin;
- abc->mechanisms[abc->c_mechs].ressources = a_next->ressources;
- abc->mechanisms[abc->c_mechs].quality = a_next->quality;
- GNUNET_CONTAINER_DLL_insert_tail(abc->peers[abc->c_peers].m_head,
- abc->peers[abc->c_peers].m_tail,
- &abc->mechanisms[abc->c_mechs]);
- found_addresses = GNUNET_YES;
- abc->c_mechs++;
- a_next = a_next->next;
- }
- r_next = r_next->next;
+ if (found_addresses == GNUNET_NO)
+ {
+ abc->peers[abc->c_peers].peer = next->id;
+ abc->peers[abc->c_peers].m_head = NULL;
+ abc->peers[abc->c_peers].m_tail = NULL;
+ abc->peers[abc->c_peers].f = 1.0 / abc->c_mechs;
+ }
+ abc->mechanisms[abc->c_mechs].addr = a_next;
+ abc->mechanisms[abc->c_mechs].col_index = abc->c_mechs;
+ abc->mechanisms[abc->c_mechs].peer = &abc->peers[abc->c_peers];
+ abc->mechanisms[abc->c_mechs].next = NULL;
+ abc->mechanisms[abc->c_mechs].plugin = r_next->plugin;
+ abc->mechanisms[abc->c_mechs].ressources = a_next->ressources;
+ abc->mechanisms[abc->c_mechs].quality = a_next->quality;
+ GNUNET_CONTAINER_DLL_insert_tail (abc->peers[abc->c_peers].m_head,
+ abc->peers[abc->c_peers].m_tail,
+ &abc->mechanisms[abc->c_mechs]);
+ found_addresses = GNUNET_YES;
+ abc->c_mechs++;
+ a_next = a_next->next;
}
+ r_next = r_next->next;
+ }
if (found_addresses == GNUNET_YES)
abc->c_peers++;
return GNUNET_OK;
@@ -6522,43 +6290,40 @@
static void
-create_ats_information ( struct ATS_peer **p,
- int * c_p,
- struct ATS_mechanism ** m,
- int * c_m )
+create_ats_information (struct ATS_peer **p,
+ int *c_p, struct ATS_mechanism **m, int *c_m)
{
struct AtsBuildContext abc;
#if VERBOSE_ATS
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "ATS requires clean address information\n");
+ "ATS requires clean address information\n");
#endif
abc.c_peers = 0;
abc.c_mechs = 0;
GNUNET_CONTAINER_multihashmap_iterate (neighbours,
- &find_and_count_addresses,
- &abc);
+ &find_and_count_addresses, &abc);
#if VERBOSE_ATS
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Found %u peers with % u transport mechanisms\n", c_peers, c_mechs);
+ "Found %u peers with % u transport mechanisms\n", c_peers,
+ c_mechs);
#endif
- if ( (abc.c_peers == 0) && (abc.c_mechs == 0) )
- {
- *p = NULL;
- (*c_p) = 0;
- *m = NULL;
- (*c_m) = 0;
- return;
- }
+ if ((abc.c_peers == 0) && (abc.c_mechs == 0))
+ {
+ *p = NULL;
+ (*c_p) = 0;
+ *m = NULL;
+ (*c_m) = 0;
+ return;
+ }
- abc.mechanisms = GNUNET_malloc((1+abc.c_mechs) * sizeof (struct
ATS_mechanism));
- abc.peers = GNUNET_malloc((1+abc.c_peers) * sizeof (struct ATS_peer));
+ abc.mechanisms =
+ GNUNET_malloc ((1 + abc.c_mechs) * sizeof (struct ATS_mechanism));
+ abc.peers = GNUNET_malloc ((1 + abc.c_peers) * sizeof (struct ATS_peer));
abc.c_mechs = 1;
abc.c_peers = 1;
- GNUNET_CONTAINER_multihashmap_iterate (neighbours,
- &setup_ats_problem,
- &abc);
+ GNUNET_CONTAINER_multihashmap_iterate (neighbours, &setup_ats_problem, &abc);
abc.c_mechs--;
abc.c_peers--;
(*c_m) = abc.c_mechs;
@@ -6569,27 +6334,29 @@
static void
-schedule_ats (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+schedule_ats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct ATS_Handle *ats = (struct ATS_Handle *) cls;
- if (ats==NULL)
+
+ if (ats == NULL)
return;
ats_task = GNUNET_SCHEDULER_NO_TASK;
- if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
+ if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
+ return;
if (shutdown_in_progress == GNUNET_YES)
- return;
+ return;
struct GNUNET_TIME_Relative delta =
- GNUNET_TIME_absolute_get_difference (last_ats_execution,
GNUNET_TIME_absolute_get());
+ GNUNET_TIME_absolute_get_difference (last_ats_execution,
+ GNUNET_TIME_absolute_get ());
+
if (delta.rel_value < ats_minimum_interval.rel_value)
{
#if DEBUG_ATS
GNUNET_log (GNUNET_ERROR_TYPE_BULK,
- "Minimum time between cycles not reached\n");
+ "Minimum time between cycles not reached\n");
#endif
return;
}
@@ -6600,19 +6367,19 @@
#if HAVE_LIBGLPK
ats_calculate_bandwidth_distribution (ats);
#endif
- last_ats_execution = GNUNET_TIME_absolute_get();
+ last_ats_execution = GNUNET_TIME_absolute_get ();
ats_task = GNUNET_SCHEDULER_add_delayed (ats_regular_interval,
- &schedule_ats, ats);
+ &schedule_ats, ats);
}
#endif
-struct ForeignAddressList * get_preferred_ats_address (
- struct NeighbourMapEntry *n)
+struct ForeignAddressList *
+get_preferred_ats_address (struct NeighbourMapEntry *n)
{
// TODO get ATS prefered address
- return find_ready_address(n);
+ return find_ready_address (n);
}
/**
@@ -6635,7 +6402,8 @@
{&handle_send, NULL,
GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, 0},
{&handle_request_connect, NULL,
- GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT, sizeof(struct
TransportRequestConnectMessage)},
+ GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT,
+ sizeof (struct TransportRequestConnectMessage)},
{&handle_set_quota, NULL,
GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA, sizeof (struct QuotaSetMessage)},
{&handle_address_lookup, NULL,
@@ -6648,9 +6416,11 @@
GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE,
0},
{&handle_blacklist_init, NULL,
- GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT, sizeof (struct
GNUNET_MessageHeader)},
+ GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT,
+ sizeof (struct GNUNET_MessageHeader)},
{&handle_blacklist_reply, NULL,
- GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY, sizeof (struct
BlacklistMessage)},
+ GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY,
+ sizeof (struct BlacklistMessage)},
{NULL, NULL, 0, 0}
};
char *plugs;
@@ -6674,61 +6444,60 @@
GNUNET_CONFIGURATION_get_value_filename (c,
"GNUNETD",
"HOSTKEY", &keyfile)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _
+ ("Transport service is lacking key configuration settings.
Exiting.\n"));
+ GNUNET_SCHEDULER_shutdown ();
+ if (stats != NULL)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _
- ("Transport service is lacking key configuration settings.
Exiting.\n"));
- GNUNET_SCHEDULER_shutdown ();
- if (stats != NULL)
- {
- GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
- stats = NULL;
- }
- GNUNET_CONTAINER_multihashmap_destroy (validation_map);
- validation_map = NULL;
- GNUNET_CONTAINER_multihashmap_destroy (neighbours);
- neighbours = NULL;
- return;
+ GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
+ stats = NULL;
}
+ GNUNET_CONTAINER_multihashmap_destroy (validation_map);
+ validation_map = NULL;
+ GNUNET_CONTAINER_multihashmap_destroy (neighbours);
+ neighbours = NULL;
+ return;
+ }
max_connect_per_transport = (uint32_t) tneigh;
peerinfo = GNUNET_PEERINFO_connect (cfg);
if (peerinfo == NULL)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Could not access PEERINFO service. Exiting.\n"));
+ GNUNET_SCHEDULER_shutdown ();
+ if (stats != NULL)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Could not access PEERINFO service. Exiting.\n"));
- GNUNET_SCHEDULER_shutdown ();
- if (stats != NULL)
- {
- GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
- stats = NULL;
- }
- GNUNET_CONTAINER_multihashmap_destroy (validation_map);
- validation_map = NULL;
- GNUNET_CONTAINER_multihashmap_destroy (neighbours);
- neighbours = NULL;
- GNUNET_free (keyfile);
- return;
+ GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
+ stats = NULL;
}
+ GNUNET_CONTAINER_multihashmap_destroy (validation_map);
+ validation_map = NULL;
+ GNUNET_CONTAINER_multihashmap_destroy (neighbours);
+ neighbours = NULL;
+ GNUNET_free (keyfile);
+ return;
+ }
my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
GNUNET_free (keyfile);
if (my_private_key == NULL)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Transport service could not access hostkey. Exiting.\n"));
+ GNUNET_SCHEDULER_shutdown ();
+ if (stats != NULL)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _
- ("Transport service could not access hostkey. Exiting.\n"));
- GNUNET_SCHEDULER_shutdown ();
- if (stats != NULL)
- {
- GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
- stats = NULL;
- }
- GNUNET_CONTAINER_multihashmap_destroy (validation_map);
- validation_map = NULL;
- GNUNET_CONTAINER_multihashmap_destroy (neighbours);
- neighbours = NULL;
- return;
+ GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
+ stats = NULL;
}
+ GNUNET_CONTAINER_multihashmap_destroy (validation_map);
+ validation_map = NULL;
+ GNUNET_CONTAINER_multihashmap_destroy (neighbours);
+ neighbours = NULL;
+ return;
+ }
GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key);
GNUNET_CRYPTO_hash (&my_public_key,
sizeof (my_public_key), &my_identity.hashPubKey);
@@ -6738,20 +6507,19 @@
/* load plugins... */
no_transports = 1;
if (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (c,
- "TRANSPORT", "PLUGINS", &plugs))
+ GNUNET_CONFIGURATION_get_value_string (c, "TRANSPORT", "PLUGINS",
&plugs))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Starting transport plugins `%s'\n"), plugs);
+ pos = strtok (plugs, " ");
+ while (pos != NULL)
{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Starting transport plugins `%s'\n"), plugs);
- pos = strtok (plugs, " ");
- while (pos != NULL)
- {
- start_transport (server, pos);
- no_transports = 0;
- pos = strtok (NULL, " ");
- }
- GNUNET_free (plugs);
+ start_transport (server, pos);
+ no_transports = 0;
+ pos = strtok (NULL, " ");
}
+ GNUNET_free (plugs);
+ }
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
&shutdown_task, NULL);
if (no_transports)
@@ -6759,8 +6527,9 @@
/* Initializing ATS */
int co;
- char * section;
- unsigned long long value;
+ char *section;
+ unsigned long long value;
+
#if HAVE_LIBGLPK
double D = 1.0;
double U = 1.0;
@@ -6773,39 +6542,35 @@
ats_regular_interval = ATS_EXEC_INTERVAL;
/* loading cost ressources */
- for (co=0; co<available_ressources; co++)
+ for (co = 0; co < available_ressources; co++)
{
- GNUNET_asprintf(§ion,"%s_UP",ressources[co].cfg_param);
- if (GNUNET_CONFIGURATION_have_value(cfg, "transport", section))
+ GNUNET_asprintf (§ion, "%s_UP", ressources[co].cfg_param);
+ if (GNUNET_CONFIGURATION_have_value (cfg, "transport", section))
{
- if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(cfg,
- "transport",
- section,
- &value))
+ if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg,
+ "transport",
+ section, &value))
{
#if DEBUG_ATS
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Found ressource cost: [%s] = %llu\n",
- section, value);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Found ressource cost: [%s] = %llu\n", section, value);
#endif
- ressources[co].c_max = value;
+ ressources[co].c_max = value;
}
}
GNUNET_free (section);
- GNUNET_asprintf(§ion,"%s_DOWN",ressources[co].cfg_param);
- if (GNUNET_CONFIGURATION_have_value(cfg, "transport", section))
+ GNUNET_asprintf (§ion, "%s_DOWN", ressources[co].cfg_param);
+ if (GNUNET_CONFIGURATION_have_value (cfg, "transport", section))
{
- if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(cfg,
- "transport",
- section,
- &value))
+ if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg,
+ "transport",
+ section, &value))
{
#if DEBUG_ATS
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Found ressource cost: [%s] = %llu\n",
- section, value);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Found ressource cost: [%s] = %llu\n", section, value);
#endif
- ressources[co].c_min = value;
+ ressources[co].c_min = value;
}
}
GNUNET_free (section);
@@ -6813,32 +6578,28 @@
#if HAVE_LIBGLPK
ats = ats_init (D, U, R, v_b_min, v_n_min,
ATS_MAX_ITERATIONS, ATS_MAX_EXEC_DURATION,
- &create_ats_information,
- ats_result_cb);
- ats_set_logging_options (ats,
- stats,
- cfg);
+ &create_ats_information, ats_result_cb);
+ ats_set_logging_options (ats, stats, cfg);
GNUNET_break (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_time (cfg,
- "transport",
- "ATS_EXEC_INTERVAL",
- &ats_regular_interval));
+ GNUNET_CONFIGURATION_get_value_time (cfg,
+ "transport",
+ "ATS_EXEC_INTERVAL",
+ &ats_regular_interval));
GNUNET_break (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_time (cfg,
- "transport",
- "ATS_MIN_INTERVAL",
- &ats_minimum_interval));
+ GNUNET_CONFIGURATION_get_value_time (cfg,
+ "transport",
+ "ATS_MIN_INTERVAL",
+ &ats_minimum_interval));
if (ats != NULL)
ats_task = GNUNET_SCHEDULER_add_now (&schedule_ats, ats);
#endif
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Transport service ready.\n"));
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Transport service ready.\n"));
#endif
/* If we have a blacklist file, read from it */
- read_blacklist_file(cfg);
+ read_blacklist_file (cfg);
/* process client requests */
GNUNET_SERVER_add_handlers (server, handlers);
}
@@ -6854,13 +6615,12 @@
int
main (int argc, char *const *argv)
{
- a2s (NULL, NULL, 0); /* make compiler happy */
+ a2s (NULL, NULL, 0); /* make compiler happy */
return (GNUNET_OK ==
GNUNET_SERVICE_run (argc,
argv,
"transport",
- GNUNET_SERVICE_OPTION_NONE,
- &run, NULL)) ? 0 : 1;
+ GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
}
/* end of gnunet-service-transport.c */
Modified: gnunet/src/transport/gnunet-service-transport_ats.c
===================================================================
--- gnunet/src/transport/gnunet-service-transport_ats.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/transport/gnunet-service-transport_ats.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -41,133 +41,136 @@
#ifndef GLP_PROB_DEFINED
#define GLP_PROB_DEFINED
- typedef struct { double _opaque_prob[100]; } glp_prob;
+typedef struct
+{
+ double _opaque_prob[100];
+} glp_prob;
#endif
typedef struct
-{ /* integer optimizer control parameters */
- int msg_lev; /* message level (see glp_smcp) */
- int br_tech; /* branching technique: */
-#define GLP_BR_FFV 1 /* first fractional variable */
-#define GLP_BR_LFV 2 /* last fractional variable */
-#define GLP_BR_MFV 3 /* most fractional variable */
-#define GLP_BR_DTH 4 /* heuristic by Driebeck and Tomlin */
-#define GLP_BR_PCH 5 /* hybrid pseudocost heuristic */
- int bt_tech; /* backtracking technique: */
-#define GLP_BT_DFS 1 /* depth first search */
-#define GLP_BT_BFS 2 /* breadth first search */
-#define GLP_BT_BLB 3 /* best local bound */
-#define GLP_BT_BPH 4 /* best projection heuristic */
- double tol_int; /* mip.tol_int */
- double tol_obj; /* mip.tol_obj */
- int tm_lim; /* mip.tm_lim (milliseconds) */
- int out_frq; /* mip.out_frq (milliseconds) */
- int out_dly; /* mip.out_dly (milliseconds) */
- /* mip.cb_func */
- void *cb_info; /* mip.cb_info */
- int cb_size; /* mip.cb_size */
- int pp_tech; /* preprocessing technique: */
-#define GLP_PP_NONE 0 /* disable preprocessing */
-#define GLP_PP_ROOT 1 /* preprocessing only on root level */
-#define GLP_PP_ALL 2 /* preprocessing on all levels */
- double mip_gap; /* relative MIP gap tolerance */
- int mir_cuts; /* MIR cuts (GLP_ON/GLP_OFF) */
- int gmi_cuts; /* Gomory's cuts (GLP_ON/GLP_OFF) */
- int cov_cuts; /* cover cuts (GLP_ON/GLP_OFF) */
- int clq_cuts; /* clique cuts (GLP_ON/GLP_OFF) */
- int presolve; /* enable/disable using MIP presolver */
- int binarize; /* try to binarize integer variables */
- int fp_heur; /* feasibility pump heuristic */
-#if 1 /* 28/V-2010 */
- int alien; /* use alien solver */
+{ /* integer optimizer control parameters */
+ int msg_lev; /* message level (see glp_smcp) */
+ int br_tech; /* branching technique: */
+#define GLP_BR_FFV 1 /* first fractional variable */
+#define GLP_BR_LFV 2 /* last fractional variable */
+#define GLP_BR_MFV 3 /* most fractional variable */
+#define GLP_BR_DTH 4 /* heuristic by Driebeck and Tomlin */
+#define GLP_BR_PCH 5 /* hybrid pseudocost heuristic */
+ int bt_tech; /* backtracking technique: */
+#define GLP_BT_DFS 1 /* depth first search */
+#define GLP_BT_BFS 2 /* breadth first search */
+#define GLP_BT_BLB 3 /* best local bound */
+#define GLP_BT_BPH 4 /* best projection heuristic */
+ double tol_int; /* mip.tol_int */
+ double tol_obj; /* mip.tol_obj */
+ int tm_lim; /* mip.tm_lim (milliseconds) */
+ int out_frq; /* mip.out_frq (milliseconds) */
+ int out_dly; /* mip.out_dly (milliseconds) */
+ /* mip.cb_func */
+ void *cb_info; /* mip.cb_info */
+ int cb_size; /* mip.cb_size */
+ int pp_tech; /* preprocessing technique: */
+#define GLP_PP_NONE 0 /* disable preprocessing */
+#define GLP_PP_ROOT 1 /* preprocessing only on root level */
+#define GLP_PP_ALL 2 /* preprocessing on all levels */
+ double mip_gap; /* relative MIP gap tolerance */
+ int mir_cuts; /* MIR cuts (GLP_ON/GLP_OFF) */
+ int gmi_cuts; /* Gomory's cuts (GLP_ON/GLP_OFF) */
+ int cov_cuts; /* cover cuts (GLP_ON/GLP_OFF) */
+ int clq_cuts; /* clique cuts (GLP_ON/GLP_OFF) */
+ int presolve; /* enable/disable using MIP presolver */
+ int binarize; /* try to binarize integer variables */
+ int fp_heur; /* feasibility pump heuristic */
+#if 1 /* 28/V-2010 */
+ int alien; /* use alien solver */
#endif
- double foo_bar[29]; /* (reserved) */
+ double foo_bar[29]; /* (reserved) */
} glp_iocp;
typedef struct
-{ /* simplex method control parameters */
- int msg_lev; /* message level: */
-#define GLP_MSG_OFF 0 /* no output */
-#define GLP_MSG_ERR 1 /* warning and error messages only */
-#define GLP_MSG_ON 2 /* normal output */
-#define GLP_MSG_ALL 3 /* full output */
-#define GLP_MSG_DBG 4 /* debug output */
- int meth; /* simplex method option: */
-#define GLP_PRIMAL 1 /* use primal simplex */
-#define GLP_DUALP 2 /* use dual; if it fails, use primal */
-#define GLP_DUAL 3 /* use dual simplex */
- int pricing; /* pricing technique: */
-#define GLP_PT_STD 0x11 /* standard (Dantzig rule) */
-#define GLP_PT_PSE 0x22 /* projected steepest edge */
- int r_test; /* ratio test technique: */
-#define GLP_RT_STD 0x11 /* standard (textbook) */
-#define GLP_RT_HAR 0x22 /* two-pass Harris' ratio test */
- double tol_bnd; /* spx.tol_bnd */
- double tol_dj; /* spx.tol_dj */
- double tol_piv; /* spx.tol_piv */
- double obj_ll; /* spx.obj_ll */
- double obj_ul; /* spx.obj_ul */
- int it_lim; /* spx.it_lim */
- int tm_lim; /* spx.tm_lim (milliseconds) */
- int out_frq; /* spx.out_frq */
- int out_dly; /* spx.out_dly (milliseconds) */
- int presolve; /* enable/disable using LP presolver */
- double foo_bar[36]; /* (reserved) */
+{ /* simplex method control parameters */
+ int msg_lev; /* message level: */
+#define GLP_MSG_OFF 0 /* no output */
+#define GLP_MSG_ERR 1 /* warning and error messages only */
+#define GLP_MSG_ON 2 /* normal output */
+#define GLP_MSG_ALL 3 /* full output */
+#define GLP_MSG_DBG 4 /* debug output */
+ int meth; /* simplex method option: */
+#define GLP_PRIMAL 1 /* use primal simplex */
+#define GLP_DUALP 2 /* use dual; if it fails, use primal */
+#define GLP_DUAL 3 /* use dual simplex */
+ int pricing; /* pricing technique: */
+#define GLP_PT_STD 0x11 /* standard (Dantzig rule) */
+#define GLP_PT_PSE 0x22 /* projected steepest edge */
+ int r_test; /* ratio test technique: */
+#define GLP_RT_STD 0x11 /* standard (textbook) */
+#define GLP_RT_HAR 0x22 /* two-pass Harris' ratio test */
+ double tol_bnd; /* spx.tol_bnd */
+ double tol_dj; /* spx.tol_dj */
+ double tol_piv; /* spx.tol_piv */
+ double obj_ll; /* spx.obj_ll */
+ double obj_ul; /* spx.obj_ul */
+ int it_lim; /* spx.it_lim */
+ int tm_lim; /* spx.tm_lim (milliseconds) */
+ int out_frq; /* spx.out_frq */
+ int out_dly; /* spx.out_dly (milliseconds) */
+ int presolve; /* enable/disable using LP presolver */
+ double foo_bar[36]; /* (reserved) */
} glp_smcp;
/* optimization direction flag: */
-#define GLP_MIN 1 /* minimization */
-#define GLP_MAX 2 /* maximization */
+#define GLP_MIN 1 /* minimization */
+#define GLP_MAX 2 /* maximization */
/* kind of structural variable: */
-#define GLP_CV 1 /* continuous variable */
-#define GLP_IV 2 /* integer variable */
-#define GLP_BV 3 /* binary variable */
+#define GLP_CV 1 /* continuous variable */
+#define GLP_IV 2 /* integer variable */
+#define GLP_BV 3 /* binary variable */
/* type of auxiliary/structural variable: */
-#define GLP_FR 1 /* free variable */
-#define GLP_LO 2 /* variable with lower bound */
-#define GLP_UP 3 /* variable with upper bound */
-#define GLP_DB 4 /* double-bounded variable */
-#define GLP_FX 5 /* fixed variable */
+#define GLP_FR 1 /* free variable */
+#define GLP_LO 2 /* variable with lower bound */
+#define GLP_UP 3 /* variable with upper bound */
+#define GLP_DB 4 /* double-bounded variable */
+#define GLP_FX 5 /* fixed variable */
/* solution indicator: */
-#define GLP_SOL 1 /* basic solution */
-#define GLP_IPT 2 /* interior-point solution */
-#define GLP_MIP 3 /* mixed integer solution */
+#define GLP_SOL 1 /* basic solution */
+#define GLP_IPT 2 /* interior-point solution */
+#define GLP_MIP 3 /* mixed integer solution */
/* solution status: */
-#define GLP_UNDEF 1 /* solution is undefined */
-#define GLP_FEAS 2 /* solution is feasible */
-#define GLP_INFEAS 3 /* solution is infeasible */
-#define GLP_NOFEAS 4 /* no feasible solution exists */
-#define GLP_OPT 5 /* solution is optimal */
-#define GLP_UNBND 6 /* solution is unbounded */
+#define GLP_UNDEF 1 /* solution is undefined */
+#define GLP_FEAS 2 /* solution is feasible */
+#define GLP_INFEAS 3 /* solution is infeasible */
+#define GLP_NOFEAS 4 /* no feasible solution exists */
+#define GLP_OPT 5 /* solution is optimal */
+#define GLP_UNBND 6 /* solution is unbounded */
/* return codes: */
-#define GLP_EBADB 0x01 /* invalid basis */
-#define GLP_ESING 0x02 /* singular matrix */
-#define GLP_ECOND 0x03 /* ill-conditioned matrix */
-#define GLP_EBOUND 0x04 /* invalid bounds */
-#define GLP_EFAIL 0x05 /* solver failed */
-#define GLP_EOBJLL 0x06 /* objective lower limit reached */
-#define GLP_EOBJUL 0x07 /* objective upper limit reached */
-#define GLP_EITLIM 0x08 /* iteration limit exceeded */
-#define GLP_ETMLIM 0x09 /* time limit exceeded */
-#define GLP_ENOPFS 0x0A /* no primal feasible solution */
-#define GLP_ENODFS 0x0B /* no dual feasible solution */
-#define GLP_EROOT 0x0C /* root LP optimum not provided */
-#define GLP_ESTOP 0x0D /* search terminated by application */
-#define GLP_EMIPGAP 0x0E /* relative mip gap tolerance reached */
-#define GLP_ENOFEAS 0x0F /* no primal/dual feasible solution */
-#define GLP_ENOCVG 0x10 /* no convergence */
-#define GLP_EINSTAB 0x11 /* numerical instability */
-#define GLP_EDATA 0x12 /* invalid data */
-#define GLP_ERANGE 0x13 /* result out of range */
+#define GLP_EBADB 0x01 /* invalid basis */
+#define GLP_ESING 0x02 /* singular matrix */
+#define GLP_ECOND 0x03 /* ill-conditioned matrix */
+#define GLP_EBOUND 0x04 /* invalid bounds */
+#define GLP_EFAIL 0x05 /* solver failed */
+#define GLP_EOBJLL 0x06 /* objective lower limit reached */
+#define GLP_EOBJUL 0x07 /* objective upper limit reached */
+#define GLP_EITLIM 0x08 /* iteration limit exceeded */
+#define GLP_ETMLIM 0x09 /* time limit exceeded */
+#define GLP_ENOPFS 0x0A /* no primal feasible solution */
+#define GLP_ENODFS 0x0B /* no dual feasible solution */
+#define GLP_EROOT 0x0C /* root LP optimum not provided */
+#define GLP_ESTOP 0x0D /* search terminated by application */
+#define GLP_EMIPGAP 0x0E /* relative mip gap tolerance reached */
+#define GLP_ENOFEAS 0x0F /* no primal/dual feasible solution */
+#define GLP_ENOCVG 0x10 /* no convergence */
+#define GLP_EINSTAB 0x11 /* numerical instability */
+#define GLP_EDATA 0x12 /* invalid data */
+#define GLP_ERANGE 0x13 /* result out of range */
/* enable/disable flag: */
-#define GLP_ON 1 /* enable something */
-#define GLP_OFF 0 /* disable something */
+#define GLP_ON 1 /* enable something */
+#define GLP_OFF 0 /* disable something */
#endif
@@ -176,10 +179,11 @@
*/
-void * _lp_create_prob ( void )
+void *
+_lp_create_prob (void)
{
#if HAVE_LIBGLPK
- return glp_create_prob( );
+ return glp_create_prob ();
#else
// Function not implemented
GNUNET_break (0);
@@ -187,7 +191,8 @@
return NULL;
}
-void _lp_set_obj_dir (glp_prob *P, int dir)
+void
+_lp_set_obj_dir (glp_prob *P, int dir)
{
#if HAVE_LIBGLPK
return glp_set_obj_dir (P, dir);
@@ -197,20 +202,22 @@
#endif
}
-void _lp_set_prob_name (glp_prob *P, const char *name)
+void
+_lp_set_prob_name (glp_prob *P, const char *name)
{
#if HAVE_LIBGLPK
- glp_set_prob_name(P, name);
+ glp_set_prob_name (P, name);
#else
// Function not implemented
GNUNET_break (0);
#endif
}
-int _lp_add_cols (glp_prob *P, int ncs)
+int
+_lp_add_cols (glp_prob *P, int ncs)
{
#if HAVE_LIBGLPK
- return glp_add_cols(P, ncs);
+ return glp_add_cols (P, ncs);
#else
// Function not implemented
GNUNET_break (0);
@@ -218,7 +225,8 @@
return 0;
}
-int _lp_add_rows (glp_prob *P, int nrs)
+int
+_lp_add_rows (glp_prob *P, int nrs)
{
#if HAVE_LIBGLPK
return glp_add_rows (P, nrs);
@@ -230,27 +238,30 @@
}
-void _lp_set_row_bnds (glp_prob *P, int i, int type, double lb, double ub)
+void
+_lp_set_row_bnds (glp_prob *P, int i, int type, double lb, double ub)
{
#if HAVE_LIBGLPK
- glp_set_row_bnds(P, i , type, lb, ub);
+ glp_set_row_bnds (P, i, type, lb, ub);
#else
// Function not implemented
GNUNET_break (0);
#endif
}
-void _lp_init_smcp (void * parm)
+void
+_lp_init_smcp (void *parm)
{
#if HAVE_LIBGLPK
- glp_init_smcp(parm);
+ glp_init_smcp (parm);
#else
// Function not implemented
GNUNET_break (0);
#endif
}
-void _lp_set_col_name (glp_prob *P, int j, const char *name)
+void
+_lp_set_col_name (glp_prob *P, int j, const char *name)
{
#if HAVE_LIBGLPK
glp_set_col_name (P, j, name);
@@ -260,28 +271,30 @@
#endif
}
-void _lp_set_col_bnds (glp_prob *P, int j, int type, double lb,
- double ub)
+void
+_lp_set_col_bnds (glp_prob *P, int j, int type, double lb, double ub)
{
#if HAVE_LIBGLPK
- glp_set_col_bnds(P, j, type, lb, ub);
+ glp_set_col_bnds (P, j, type, lb, ub);
#else
// Function not implemented
GNUNET_break (0);
#endif
}
-void _lp_set_obj_coef(glp_prob *P, int j, double coef)
+void
+_lp_set_obj_coef (glp_prob *P, int j, double coef)
{
#if HAVE_LIBGLPK
- glp_set_obj_coef(P, j, coef);
+ glp_set_obj_coef (P, j, coef);
#else
// Function not implemented
GNUNET_break (0);
#endif
}
-void _lp_delete_prob (void * P)
+void
+_lp_delete_prob (void *P)
{
#if HAVE_LIBGLPK
glp_delete_prob (P);
@@ -291,7 +304,8 @@
#endif
}
-static int _lp_simplex(glp_prob *P, void *parm)
+static int
+_lp_simplex (glp_prob *P, void *parm)
{
#if HAVE_LIBGLPK
return glp_simplex (P, parm);
@@ -302,19 +316,21 @@
return 0;
}
-static void _lp_load_matrix (glp_prob *P, int ne, const int ia[],
- const int ja[], const double ar[])
+static void
+_lp_load_matrix (glp_prob *P, int ne, const int ia[],
+ const int ja[], const double ar[])
{
#if HAVE_LIBGLPK
- glp_load_matrix(P, ne, ia, ja, ar);
+ glp_load_matrix (P, ne, ia, ja, ar);
#else
// Function not implemented
GNUNET_break (0);
#endif
}
-static void _lp_set_mat_row (glp_prob *P, int i, int len, const int ind[],
- const double val[])
+static void
+_lp_set_mat_row (glp_prob *P, int i, int len, const int ind[],
+ const double val[])
{
#if HAVE_LIBGLPK
glp_set_mat_row (P, i, len, ind, val);
@@ -324,10 +340,11 @@
#endif
}
-static int _lp_write_lp (glp_prob *P, const void *parm, const char *fname)
+static int
+_lp_write_lp (glp_prob *P, const void *parm, const char *fname)
{
#if HAVE_LIBGLPK
- return glp_write_lp ( P, parm, fname);
+ return glp_write_lp (P, parm, fname);
#else
// Function not implemented
GNUNET_break (0);
@@ -335,7 +352,8 @@
return 0;
}
-static void _lp_init_iocp (void *parm)
+static void
+_lp_init_iocp (void *parm)
{
#if HAVE_LIBGLPK
glp_init_iocp (parm);
@@ -345,7 +363,8 @@
#endif
}
-static int _lp_intopt (glp_prob *P, const void *parm)
+static int
+_lp_intopt (glp_prob *P, const void *parm)
{
#if HAVE_LIBGLPK
return glp_intopt (P, parm);
@@ -356,7 +375,8 @@
return 0;
}
-static int _lp_get_status (glp_prob *P)
+static int
+_lp_get_status (glp_prob *P)
{
#if HAVE_LIBGLPK
return glp_get_status (P);
@@ -367,7 +387,8 @@
return 0;
}
-static int _lp_mip_status (glp_prob *P)
+static int
+_lp_mip_status (glp_prob *P)
{
#if HAVE_LIBGLPK
return glp_mip_status (P);
@@ -378,7 +399,8 @@
return 0;
}
-static void _lp_set_col_kind (glp_prob *P, int j, int kind)
+static void
+_lp_set_col_kind (glp_prob *P, int j, int kind)
{
#if HAVE_LIBGLPK
glp_set_col_kind (P, j, kind);
@@ -388,7 +410,8 @@
#endif
}
-static void _lp_free_env (void)
+static void
+_lp_free_env (void)
{
#if HAVE_LIBGLPK
glp_free_env ();
@@ -398,7 +421,8 @@
#endif
}
-static const char * _lp_get_col_name ( glp_prob *P, int j)
+static const char *
+_lp_get_col_name (glp_prob *P, int j)
{
#if HAVE_LIBGLPK
return glp_get_col_name (P, j);
@@ -409,7 +433,8 @@
return NULL;
}
-static double _lp_mip_obj_val (glp_prob *P)
+static double
+_lp_mip_obj_val (glp_prob *P)
{
#if HAVE_LIBGLPK
return glp_mip_obj_val (P);
@@ -421,10 +446,11 @@
}
-static double _lp_get_col_prim (glp_prob *P, int j)
+static double
+_lp_get_col_prim (glp_prob *P, int j)
{
#if HAVE_LIBGLPK
- return glp_get_col_prim (P , j);
+ return glp_get_col_prim (P, j);
#else
// Function not implemented
GNUNET_break (0);
@@ -432,7 +458,8 @@
return 0.0;
}
-static int _lp_print_sol(glp_prob *P, const char *fname)
+static int
+_lp_print_sol (glp_prob *P, const char *fname)
{
#if HAVE_LIBGLPK
#else
@@ -447,24 +474,27 @@
*/
static void _dummy2 ();
-static void _dummy ()
+static void
+_dummy ()
{
return;
_lp_get_col_name (NULL, 0);
_lp_mip_obj_val (NULL);
_lp_get_col_prim (NULL, 0);
- _lp_set_mat_row(NULL,0,0,NULL,NULL);
- _dummy2();
+ _lp_set_mat_row (NULL, 0, 0, NULL, NULL);
+ _dummy2 ();
}
-static void _dummy2 ()
+static void
+_dummy2 ()
{
ats_modify_problem_state (NULL, 0);
qm[1].atis_index = 0;
- _dummy();
+ _dummy ();
int t = ATS_COST_UPDATED + ATS_MODIFIED + ATS_NEW;
+
t++;
}
@@ -479,19 +509,20 @@
* @return
*/
-struct ATS_Handle * ats_init (double D,
- double U,
- double R,
- int v_b_min,
- int v_n_min,
- int max_iterations,
- struct GNUNET_TIME_Relative max_duration,
- GNUNET_TRANSPORT_ATS_AddressNotification
address_not,
- GNUNET_TRANSPORT_ATS_ResultCallback res_cb)
+struct ATS_Handle *
+ats_init (double D,
+ double U,
+ double R,
+ int v_b_min,
+ int v_n_min,
+ int max_iterations,
+ struct GNUNET_TIME_Relative max_duration,
+ GNUNET_TRANSPORT_ATS_AddressNotification address_not,
+ GNUNET_TRANSPORT_ATS_ResultCallback res_cb)
{
- struct ATS_Handle * ats = NULL;
+ struct ATS_Handle *ats = NULL;
- ats = GNUNET_malloc(sizeof (struct ATS_Handle));
+ ats = GNUNET_malloc (sizeof (struct ATS_Handle));
ats->prob = NULL;
@@ -507,7 +538,7 @@
ats->v_b_min = v_b_min;
ats->v_n_min = v_n_min;
ats->dump_min_peers = 0;
- ats->dump_min_addr = 0;
+ ats->dump_min_addr = 0;
ats->dump_overwrite = GNUNET_NO;
ats->mechanisms = NULL;
ats->peers = NULL;
@@ -529,181 +560,165 @@
* @param stat result struct
* @return GNUNET_SYSERR if glpk is not available, number of mechanisms used
*/
-int ats_create_problem (struct ATS_Handle *ats,
- struct ATS_internals *stat,
- struct ATS_peer *peers,
- int c_p,
- struct ATS_mechanism *mechanisms,
- int c_m)
+int
+ats_create_problem (struct ATS_Handle *ats,
+ struct ATS_internals *stat,
+ struct ATS_peer *peers,
+ int c_p, struct ATS_mechanism *mechanisms, int c_m)
{
if ((c_p == 0) || (c_m == 0))
return GNUNET_SYSERR;
- ats->prob = _lp_create_prob();
+ ats->prob = _lp_create_prob ();
int c;
int c_c_ressources = available_ressources;
int c_q_metrics = available_quality_metrics;
double M = VERY_BIG_DOUBLE_VALUE;
- double Q[c_q_metrics+1];
- for (c=1; c<=c_q_metrics; c++)
+ double Q[c_q_metrics + 1];
+
+ for (c = 1; c <= c_q_metrics; c++)
{
- Q[c] = 1;
+ Q[c] = 1;
}
if (ats->v_n_min > c_p)
- ats->v_n_min = c_p;
+ ats->v_n_min = c_p;
#if VERBOSE_ATS
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Creating problem with: %i peers, %i
mechanisms, %i resource entries, %i quality metrics \n",
- c_p,
- c_m,
- c_c_ressources,
- c_q_metrics);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Creating problem with: %i peers, %i mechanisms, %i resource
entries, %i quality metrics \n",
+ c_p, c_m, c_c_ressources, c_q_metrics);
#endif
- int size = 1 + 3 + 10 *c_m + c_p +
- (c_q_metrics*c_m)+ c_q_metrics + c_c_ressources * c_m ;
+ int size = 1 + 3 + 10 * c_m + c_p +
+ (c_q_metrics * c_m) + c_q_metrics + c_c_ressources * c_m;
int row_index;
- int array_index=1;
- int * ia = GNUNET_malloc (size * sizeof (int));
- int * ja = GNUNET_malloc (size * sizeof (int));
- double * ar = GNUNET_malloc(size* sizeof (double));
+ int array_index = 1;
+ int *ia = GNUNET_malloc (size * sizeof (int));
+ int *ja = GNUNET_malloc (size * sizeof (int));
+ double *ar = GNUNET_malloc (size * sizeof (double));
_lp_set_prob_name (ats->prob, "gnunet ats bandwidth distribution");
- _lp_set_obj_dir(ats->prob, GLP_MAX);
+ _lp_set_obj_dir (ats->prob, GLP_MAX);
/* adding columns */
- char * name;
- _lp_add_cols(ats->prob, 2 * c_m);
+ char *name;
+
+ _lp_add_cols (ats->prob, 2 * c_m);
/* adding b_t cols */
- for (c=1; c <= c_m; c++)
+ for (c = 1; c <= c_m; c++)
{
- GNUNET_asprintf(&name,
- "p_%s_b%i",GNUNET_i2s(&(mechanisms[c].peer->peer)), c);
- _lp_set_col_name(ats->prob, c, name);
+ GNUNET_asprintf (&name,
+ "p_%s_b%i", GNUNET_i2s (&(mechanisms[c].peer->peer)), c);
+ _lp_set_col_name (ats->prob, c, name);
GNUNET_free (name);
- _lp_set_col_bnds(ats->prob, c, GLP_LO, 0.0, 0.0);
- _lp_set_col_kind(ats->prob, c, GLP_CV);
- _lp_set_obj_coef(ats->prob, c, 0);
+ _lp_set_col_bnds (ats->prob, c, GLP_LO, 0.0, 0.0);
+ _lp_set_col_kind (ats->prob, c, GLP_CV);
+ _lp_set_obj_coef (ats->prob, c, 0);
}
/* adding n_t cols */
- for (c=c_m+1; c <= 2*c_m; c++)
+ for (c = c_m + 1; c <= 2 * c_m; c++)
{
- GNUNET_asprintf(&name,
- "p_%s_n%i",GNUNET_i2s(&(mechanisms[c-c_m].peer->peer)),(c-c_m));
- _lp_set_col_name(ats->prob, c, name);
+ GNUNET_asprintf (&name,
+ "p_%s_n%i", GNUNET_i2s (&(mechanisms[c -
c_m].peer->peer)),
+ (c - c_m));
+ _lp_set_col_name (ats->prob, c, name);
GNUNET_free (name);
- _lp_set_col_bnds(ats->prob, c, GLP_DB, 0.0, 1.0);
- _lp_set_col_kind(ats->prob, c, GLP_IV);
- _lp_set_obj_coef(ats->prob, c, 0);
+ _lp_set_col_bnds (ats->prob, c, GLP_DB, 0.0, 1.0);
+ _lp_set_col_kind (ats->prob, c, GLP_IV);
+ _lp_set_obj_coef (ats->prob, c, 0);
}
/* feasibility constraints */
- /* Constraint 1: one address per peer*/
+ /* Constraint 1: one address per peer */
row_index = 1;
- _lp_add_rows(ats->prob, c_p);
+ _lp_add_rows (ats->prob, c_p);
- for (c=1; c<=c_p; c++)
+ for (c = 1; c <= c_p; c++)
{
#if VERBOSE_ATS
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n",
- row_index);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n", row_index);
#endif
- _lp_set_row_bnds(ats->prob, row_index, GLP_FX, 1.0, 1.0);
- struct ATS_mechanism *m = peers[c].m_head;
- while (m!=NULL)
- {
- ia[array_index] = row_index;
- ja[array_index] = (c_m + m->col_index);
- ar[array_index] = 1;
+ _lp_set_row_bnds (ats->prob, row_index, GLP_FX, 1.0, 1.0);
+ struct ATS_mechanism *m = peers[c].m_head;
+
+ while (m != NULL)
+ {
+ ia[array_index] = row_index;
+ ja[array_index] = (c_m + m->col_index);
+ ar[array_index] = 1;
#if VERBOSE_ATS
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
- array_index,
- ia[array_index],
- ja[array_index],
- ar[array_index]);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
+ array_index,
+ ia[array_index], ja[array_index], ar[array_index]);
#endif
- array_index++;
- m = m->next;
- }
- row_index++;
+ array_index++;
+ m = m->next;
+ }
+ row_index++;
}
/* Constraint 2: only active mechanism gets bandwidth assigned */
- _lp_add_rows(ats->prob, c_m);
- for (c=1; c<=c_m; c++)
+ _lp_add_rows (ats->prob, c_m);
+ for (c = 1; c <= c_m; c++)
{
- /* b_t - n_t * M <= 0 */
+ /* b_t - n_t * M <= 0 */
#if VERBOSE_ATS
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n",
- row_index);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n", row_index);
#endif
- _lp_set_row_bnds(ats->prob, row_index, GLP_UP, 0.0, 0.0);
- ia[array_index] = row_index;
- ja[array_index] = mechanisms[c].col_index;
- ar[array_index] = 1;
+ _lp_set_row_bnds (ats->prob, row_index, GLP_UP, 0.0, 0.0);
+ ia[array_index] = row_index;
+ ja[array_index] = mechanisms[c].col_index;
+ ar[array_index] = 1;
#if VERBOSE_ATS
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
- array_index,
- ia[array_index],
- ja[array_index],
- ar[array_index]);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
+ array_index, ia[array_index], ja[array_index],
ar[array_index]);
#endif
- array_index++;
- ia[array_index] = row_index;
- ja[array_index] = c_m + mechanisms[c].col_index;
- ar[array_index] = -M;
+ array_index++;
+ ia[array_index] = row_index;
+ ja[array_index] = c_m + mechanisms[c].col_index;
+ ar[array_index] = -M;
#if VERBOSE_ATS
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
- array_index,
- ia[array_index],
- ja[array_index],
- ar[array_index]);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
+ array_index, ia[array_index], ja[array_index],
ar[array_index]);
#endif
- array_index++;
- row_index ++;
+ array_index++;
+ row_index++;
}
- /* Constraint 3: minimum bandwidth*/
- _lp_add_rows(ats->prob, c_m);
+ /* Constraint 3: minimum bandwidth */
+ _lp_add_rows (ats->prob, c_m);
- for (c=1; c<=c_m; c++)
+ for (c = 1; c <= c_m; c++)
{
- /* b_t - n_t * b_min <= 0 */
+ /* b_t - n_t * b_min <= 0 */
#if VERBOSE_ATS
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n",
- row_index);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n", row_index);
#endif
#if HAVE_LIBGLPK
- _lp_set_row_bnds(ats->prob, row_index, GLP_LO, 0.0, 0.0);
+ _lp_set_row_bnds (ats->prob, row_index, GLP_LO, 0.0, 0.0);
#endif
- ia[array_index] = row_index;
- ja[array_index] = mechanisms[c].col_index;
- ar[array_index] = 1;
+ ia[array_index] = row_index;
+ ja[array_index] = mechanisms[c].col_index;
+ ar[array_index] = 1;
#if VERBOSE_ATS
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
- array_index,
- ia[array_index],
- ja[array_index],
- ar[array_index]);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
+ array_index, ia[array_index], ja[array_index],
ar[array_index]);
#endif
- array_index++;
- ia[array_index] = row_index;
- ja[array_index] = c_m + mechanisms[c].col_index;
- ar[array_index] = -ats->v_b_min;
+ array_index++;
+ ia[array_index] = row_index;
+ ja[array_index] = c_m + mechanisms[c].col_index;
+ ar[array_index] = -ats->v_b_min;
#if VERBOSE_ATS
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
- array_index,
- ia[array_index],
- ja[array_index],
- ar[array_index]);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
+ array_index, ia[array_index], ja[array_index],
ar[array_index]);
#endif
- array_index++;
- row_index ++;
+ array_index++;
+ row_index++;
}
int c2;
@@ -711,69 +726,63 @@
/* V cr: bt * ct_r <= cr_max
* */
- _lp_add_rows(ats->prob, available_ressources);
+ _lp_add_rows (ats->prob, available_ressources);
double ct_max = VERY_BIG_DOUBLE_VALUE;
double ct_min = 0.0;
stat->begin_cr = array_index;
- for (c=0; c<available_ressources; c++)
+ for (c = 0; c < available_ressources; c++)
{
- ct_max = ressources[c].c_max;
- ct_min = ressources[c].c_min;
+ ct_max = ressources[c].c_max;
+ ct_min = ressources[c].c_min;
#if VERBOSE_ATS
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] %f..%f\n",
- row_index,
- ct_min,
- ct_max);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] %f..%f\n",
+ row_index, ct_min, ct_max);
#endif
#if HAVE_LIBGLPK
- _lp_set_row_bnds(ats->prob, row_index, GLP_DB, ct_min, ct_max);
+ _lp_set_row_bnds (ats->prob, row_index, GLP_DB, ct_min, ct_max);
#endif
- for (c2=1; c2<=c_m; c2++)
- {
- double value = 0;
- ia[array_index] = row_index;
- ja[array_index] = c2;
- value = mechanisms[c2].ressources[c].c;
- ar[array_index] = value;
+ for (c2 = 1; c2 <= c_m; c2++)
+ {
+ double value = 0;
+
+ ia[array_index] = row_index;
+ ja[array_index] = c2;
+ value = mechanisms[c2].ressources[c].c;
+ ar[array_index] = value;
#if VERBOSE_ATS
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
- array_index, ia[array_index],
- ja[array_index],
- ar[array_index]);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
+ array_index, ia[array_index],
+ ja[array_index], ar[array_index]);
#endif
- array_index++;
- }
- row_index ++;
+ array_index++;
+ }
+ row_index++;
}
stat->end_cr = array_index--;
- /* Constraint 5: min number of connections*/
- _lp_add_rows(ats->prob, 1);
+ /* Constraint 5: min number of connections */
+ _lp_add_rows (ats->prob, 1);
- for (c=1; c<=c_m; c++)
+ for (c = 1; c <= c_m; c++)
{
- // b_t - n_t * b_min >= 0
+ // b_t - n_t * b_min >= 0
#if VERBOSE_ATS
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n",
- row_index);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n", row_index);
#endif
- _lp_set_row_bnds(ats->prob, row_index, GLP_LO, ats->v_n_min, 0.0);
- ia[array_index] = row_index;
- ja[array_index] = c_m + mechanisms[c].col_index;
- ar[array_index] = 1;
+ _lp_set_row_bnds (ats->prob, row_index, GLP_LO, ats->v_n_min, 0.0);
+ ia[array_index] = row_index;
+ ja[array_index] = c_m + mechanisms[c].col_index;
+ ar[array_index] = 1;
#if VERBOSE_ATS
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
- array_index,
- ia[array_index],
- ja[array_index],
- ar[array_index]);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
+ array_index, ia[array_index], ja[array_index],
ar[array_index]);
#endif
- array_index++;
+ array_index++;
}
- row_index ++;
+ row_index++;
// optimisation constraints
@@ -781,29 +790,27 @@
// Constraint 6: optimize for diversity
int col_d;
- col_d = _lp_add_cols(ats->prob, 1);
- _lp_set_col_name(ats->prob, col_d, "d");
- _lp_set_obj_coef(ats->prob, col_d, ats->D);
- _lp_set_col_bnds(ats->prob, col_d, GLP_LO, 0.0, 0.0);
- _lp_add_rows(ats->prob, 1);
- _lp_set_row_bnds(ats->prob, row_index, GLP_FX, 0.0, 0.0);
+ col_d = _lp_add_cols (ats->prob, 1);
+ _lp_set_col_name (ats->prob, col_d, "d");
+ _lp_set_obj_coef (ats->prob, col_d, ats->D);
+ _lp_set_col_bnds (ats->prob, col_d, GLP_LO, 0.0, 0.0);
+ _lp_add_rows (ats->prob, 1);
+ _lp_set_row_bnds (ats->prob, row_index, GLP_FX, 0.0, 0.0);
+
stat->col_d = col_d;
#if VERBOSE_ATS
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n",row_index);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n", row_index);
#endif
- for (c=1; c<=c_m; c++)
+ for (c = 1; c <= c_m; c++)
{
ia[array_index] = row_index;
ja[array_index] = c_m + mechanisms[c].col_index;
ar[array_index] = 1;
#if VERBOSE_ATS
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
- array_index,
- ia[array_index],
- ja[array_index],
- ar[array_index]);
+ array_index, ia[array_index], ja[array_index],
ar[array_index]);
#endif
array_index++;
}
@@ -812,122 +819,120 @@
ar[array_index] = -1;
#if VERBOSE_ATS
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
- array_index,
- ia[array_index],
- ja[array_index],
- ar[array_index]);
+ array_index, ia[array_index], ja[array_index], ar[array_index]);
#endif
array_index++;
- row_index ++;
+ row_index++;
// Constraint 7: optimize for quality
int col_qm;
- col_qm = _lp_add_cols(ats->prob, c_q_metrics);
+ col_qm = _lp_add_cols (ats->prob, c_q_metrics);
+
stat->col_qm = col_qm;
//GNUNET_assert (col_qm == (2*c_mechs) + 3 + 1);
- for (c=0; c< c_q_metrics; c++)
+ for (c = 0; c < c_q_metrics; c++)
{
- GNUNET_asprintf(&name, "Q_%s",qm[c].name);
+ GNUNET_asprintf (&name, "Q_%s", qm[c].name);
_lp_set_col_name (ats->prob, col_qm + c, name);
_lp_set_col_bnds (ats->prob, col_qm + c, GLP_LO, 0.0, 0.0);
GNUNET_free (name);
_lp_set_obj_coef (ats->prob, col_qm + c, Q[c]);
}
- _lp_add_rows(ats->prob, available_quality_metrics);
+ _lp_add_rows (ats->prob, available_quality_metrics);
stat->begin_qm = row_index;
- for (c=1; c <= c_q_metrics; c++)
+ for (c = 1; c <= c_q_metrics; c++)
{
#if VERBOSE_ATS
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n",
- row_index);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n", row_index);
#endif
- double value = 1;
- _lp_set_row_bnds(ats->prob, row_index, GLP_FX, 0.0, 0.0);
- for (c2=1; c2<=c_m; c2++)
+ double value = 1;
+
+ _lp_set_row_bnds (ats->prob, row_index, GLP_FX, 0.0, 0.0);
+ for (c2 = 1; c2 <= c_m; c2++)
+ {
+ ia[array_index] = row_index;
+ ja[array_index] = c2;
+ if (qm[c - 1].atis_index == GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY)
{
- ia[array_index] = row_index;
- ja[array_index] = c2;
- if (qm[c-1].atis_index == GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY)
- {
- double v0 = 0, v1 = 0, v2 = 0;
- v0 = mechanisms[c2].quality[c-1].values[0];
- if (v1 < 1) v0 = 0.1;
- v1 = mechanisms[c2].quality[c-1].values[1];
- if (v1 < 1) v0 = 0.1;
- v2 = mechanisms[c2].quality[c-1].values[2];
- if (v1 < 1) v0 = 0.1;
- value = 100.0 / ((v0 + 2 * v1 + 3 * v2) / 6.0);
- value = 1;
- }
- if (qm[c-1].atis_index == GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE)
- {
- double v0 = 0, v1 = 0, v2 = 0;
- v0 = mechanisms[c2].quality[c-1].values[0];
- if (v0 < 1) v0 = 1;
- v1 = mechanisms[c2].quality[c-1].values[1];
- if (v1 < 1) v1 = 1;
- v2 = mechanisms[c2].quality[c-1].values[2];
- if (v2 < 1) v2 = 1;
- value = (v0 + 2 * v1 + 3 * v2) / 6.0;
- if (value >= 1)
- value = (double) 10 / value;
- else
- value = 10;
- }
- ar[array_index] = (mechanisms[c2].peer->f) * value ;
-#if VERBOSE_ATS
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: %s [%i,%i]=%f
\n",
- array_index,
- qm[c-1].name,
- ia[array_index],
- ja[array_index],
- ar[array_index]);
-#endif
- array_index++;
+ double v0 = 0, v1 = 0, v2 = 0;
+
+ v0 = mechanisms[c2].quality[c - 1].values[0];
+ if (v1 < 1)
+ v0 = 0.1;
+ v1 = mechanisms[c2].quality[c - 1].values[1];
+ if (v1 < 1)
+ v0 = 0.1;
+ v2 = mechanisms[c2].quality[c - 1].values[2];
+ if (v1 < 1)
+ v0 = 0.1;
+ value = 100.0 / ((v0 + 2 * v1 + 3 * v2) / 6.0);
+ value = 1;
}
- ia[array_index] = row_index;
- ja[array_index] = col_qm + c - 1;
- ar[array_index] = -1;
+ if (qm[c - 1].atis_index == GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE)
+ {
+ double v0 = 0, v1 = 0, v2 = 0;
+
+ v0 = mechanisms[c2].quality[c - 1].values[0];
+ if (v0 < 1)
+ v0 = 1;
+ v1 = mechanisms[c2].quality[c - 1].values[1];
+ if (v1 < 1)
+ v1 = 1;
+ v2 = mechanisms[c2].quality[c - 1].values[2];
+ if (v2 < 1)
+ v2 = 1;
+ value = (v0 + 2 * v1 + 3 * v2) / 6.0;
+ if (value >= 1)
+ value = (double) 10 / value;
+ else
+ value = 10;
+ }
+ ar[array_index] = (mechanisms[c2].peer->f) * value;
#if VERBOSE_ATS
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
- array_index,
- ia[array_index],
- ja[array_index],
- ar[array_index]);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: %s [%i,%i]=%f \n",
+ array_index,
+ qm[c - 1].name,
+ ia[array_index], ja[array_index], ar[array_index]);
#endif
array_index++;
- row_index++;
+ }
+ ia[array_index] = row_index;
+ ja[array_index] = col_qm + c - 1;
+ ar[array_index] = -1;
+#if VERBOSE_ATS
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
+ array_index, ia[array_index], ja[array_index],
ar[array_index]);
+#endif
+ array_index++;
+ row_index++;
}
- stat->end_qm = row_index-1;
+ stat->end_qm = row_index - 1;
// Constraint 8: optimize bandwidth utility
int col_u;
- col_u = _lp_add_cols(ats->prob, 1);
+ col_u = _lp_add_cols (ats->prob, 1);
- _lp_set_col_name(ats->prob, col_u, "u");
- _lp_set_obj_coef(ats->prob, col_u, ats->U);
- _lp_set_col_bnds(ats->prob, col_u, GLP_LO, 0.0, 0.0);
- _lp_add_rows(ats->prob, 1);
+ _lp_set_col_name (ats->prob, col_u, "u");
+ _lp_set_obj_coef (ats->prob, col_u, ats->U);
+ _lp_set_col_bnds (ats->prob, col_u, GLP_LO, 0.0, 0.0);
+ _lp_add_rows (ats->prob, 1);
stat->col_u = col_u;
#if VERBOSE_ATS
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n",row_index);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n", row_index);
#endif
- _lp_set_row_bnds(ats->prob, row_index, GLP_FX, 0.0, 0.0);
- for (c=1; c<=c_m; c++)
+ _lp_set_row_bnds (ats->prob, row_index, GLP_FX, 0.0, 0.0);
+ for (c = 1; c <= c_m; c++)
{
ia[array_index] = row_index;
ja[array_index] = c;
ar[array_index] = mechanisms[c].peer->f;
#if VERBOSE_ATS
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
- array_index,
- ia[array_index],
- ja[array_index],
- ar[array_index]);
+ array_index, ia[array_index], ja[array_index],
ar[array_index]);
#endif
array_index++;
}
@@ -936,40 +941,37 @@
ar[array_index] = -1;
#if VERBOSE_ATS
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
- array_index, ia[array_index],
- ja[array_index],
- ar[array_index]);
+ array_index, ia[array_index], ja[array_index], ar[array_index]);
#endif
array_index++;
- row_index ++;
+ row_index++;
// Constraint 9: optimize relativity
int col_r;
- col_r = _lp_add_cols(ats->prob, 1);
+ col_r = _lp_add_cols (ats->prob, 1);
- _lp_set_col_name(ats->prob, col_r, "r");
- _lp_set_obj_coef(ats->prob, col_r, ats->R);
- _lp_set_col_bnds(ats->prob, col_r, GLP_LO, 0.0, 0.0);
- _lp_add_rows(ats->prob, c_p);
+ _lp_set_col_name (ats->prob, col_r, "r");
+ _lp_set_obj_coef (ats->prob, col_r, ats->R);
+ _lp_set_col_bnds (ats->prob, col_r, GLP_LO, 0.0, 0.0);
+ _lp_add_rows (ats->prob, c_p);
stat->col_r = col_r;
- for (c=1; c<=c_p; c++)
+ for (c = 1; c <= c_p; c++)
{
- _lp_set_row_bnds(ats->prob, row_index, GLP_LO, 0.0, 0.0);
+ _lp_set_row_bnds (ats->prob, row_index, GLP_LO, 0.0, 0.0);
struct ATS_mechanism *m = peers[c].m_head;
- while (m!=NULL)
+
+ while (m != NULL)
{
ia[array_index] = row_index;
ja[array_index] = m->col_index;
ar[array_index] = 1 / mechanisms[c].peer->f;
#if VERBOSE_ATS
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
- array_index,
- ia[array_index],
- ja[array_index],
- ar[array_index]);
+ array_index,
+ ia[array_index], ja[array_index], ar[array_index]);
#endif
array_index++;
m = m->next;
@@ -979,17 +981,14 @@
ar[array_index] = -1;
#if VERBOSE_ATS
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
- array_index,
- ia[array_index],
- ja[array_index],
- ar[array_index]);
+ array_index, ia[array_index], ja[array_index],
ar[array_index]);
#endif
array_index++;
row_index++;
}
/* Loading the matrix */
- _lp_load_matrix(ats->prob, array_index-1, ia, ja, ar);
+ _lp_load_matrix (ats->prob, array_index - 1, ia, ja, ar);
stat->c_mechs = c_m;
stat->c_peers = c_p;
@@ -1005,30 +1004,31 @@
}
-void ats_delete_problem (struct ATS_Handle * ats)
+void
+ats_delete_problem (struct ATS_Handle *ats)
{
#if DEBUG_ATS
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Deleting problem\n");
#endif
int c;
- for (c=0; c< (ats->internal).c_mechs; c++)
- GNUNET_free_non_null (ats->mechanisms[c].rc);
- if (ats->mechanisms!=NULL)
+ for (c = 0; c < (ats->internal).c_mechs; c++)
+ GNUNET_free_non_null (ats->mechanisms[c].rc);
+ if (ats->mechanisms != NULL)
{
- GNUNET_free(ats->mechanisms);
+ GNUNET_free (ats->mechanisms);
ats->mechanisms = NULL;
}
- if (ats->peers!=NULL)
+ if (ats->peers != NULL)
{
- GNUNET_free(ats->peers);
+ GNUNET_free (ats->peers);
ats->peers = NULL;
}
if (ats->prob != NULL)
{
- _lp_delete_prob(ats->prob);
+ _lp_delete_prob (ats->prob);
ats->prob = NULL;
}
@@ -1042,13 +1042,14 @@
ats->internal.valid = GNUNET_SYSERR;
}
-void ats_modify_problem_state (struct ATS_Handle * ats, enum ATS_problem_state
s)
+void
+ats_modify_problem_state (struct ATS_Handle *ats, enum ATS_problem_state s)
{
if (ats == NULL)
return;
switch (s)
{
- case ATS_NEW :
+ case ATS_NEW:
ats->internal.recreate_problem = GNUNET_NO;
ats->internal.modified_quality = GNUNET_NO;
ats->internal.modified_resources = GNUNET_NO;
@@ -1056,10 +1057,10 @@
case ATS_MODIFIED:
ats->internal.recreate_problem = GNUNET_YES;
break;
- case ATS_QUALITY_UPDATED :
+ case ATS_QUALITY_UPDATED:
ats->internal.modified_quality = GNUNET_YES;
break;
- case ATS_COST_UPDATED :
+ case ATS_COST_UPDATED:
ats->internal.modified_resources = GNUNET_YES;
break;
case ATS_QUALITY_COST_UPDATED:
@@ -1074,12 +1075,12 @@
}
-void ats_solve_problem (struct ATS_Handle * ats,
- unsigned int max_it,
- unsigned int max_dur,
- unsigned int c_peers,
- unsigned int c_mechs,
- struct ATS_internals *stat)
+void
+ats_solve_problem (struct ATS_Handle *ats,
+ unsigned int max_it,
+ unsigned int max_dur,
+ unsigned int c_peers,
+ unsigned int c_mechs, struct ATS_internals *stat)
{
int result = GNUNET_SYSERR;
int lp_solution = GNUNET_SYSERR;
@@ -1088,7 +1089,8 @@
// Solving simplex
glp_smcp opt_lp;
- _lp_init_smcp(&opt_lp);
+
+ _lp_init_smcp (&opt_lp);
#if VERBOSE_ATS
opt_lp.msg_lev = GLP_MSG_ALL;
#else
@@ -1100,20 +1102,20 @@
opt_lp.tm_lim = max_dur;
if (ats->internal.recreate_problem == GNUNET_YES)
- opt_lp.presolve = GLP_ON;
+ opt_lp.presolve = GLP_ON;
- result = _lp_simplex(ats->prob, &opt_lp);
- lp_solution = _lp_get_status (ats->prob);
+ result = _lp_simplex (ats->prob, &opt_lp);
+ lp_solution = _lp_get_status (ats->prob);
if ((result == GLP_ETMLIM) || (result == GLP_EITLIM))
{
ats->internal.valid = GNUNET_NO;
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "ATS exceeded time or iteration limit!\n");
+ "ATS exceeded time or iteration limit!\n");
return;
}
- if (ats_evaluate_results(result, lp_solution, "LP") == GNUNET_YES)
+ if (ats_evaluate_results (result, lp_solution, "LP") == GNUNET_YES)
{
stat->valid = GNUNET_YES;
}
@@ -1121,36 +1123,37 @@
{
ats->internal.simplex_rerun_required = GNUNET_YES;
opt_lp.presolve = GLP_ON;
- result = _lp_simplex(ats->prob, &opt_lp);
- lp_solution = _lp_get_status (ats->prob);
+ result = _lp_simplex (ats->prob, &opt_lp);
+ lp_solution = _lp_get_status (ats->prob);
// TODO: Remove if this does not appear until release
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, ""
- "EXECUTED SIMPLEX WITH PRESOLVER! %i \n",
- lp_solution);
+ "EXECUTED SIMPLEX WITH PRESOLVER! %i \n", lp_solution);
- if (ats_evaluate_results(result, lp_solution, "LP") != GNUNET_YES)
+ if (ats_evaluate_results (result, lp_solution, "LP") != GNUNET_YES)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "After execution simplex with presolver: STILL INVALID!\n");
- char * filename;
- GNUNET_asprintf (&filename,
- "ats_mlp_p%i_m%i_%llu.mlp",
- ats->internal.c_peers,
- ats->internal.c_mechs,
- GNUNET_TIME_absolute_get().abs_value);
- _lp_write_lp ((void *)ats->prob, NULL, filename);
- GNUNET_free (filename);
- stat->valid = GNUNET_NO;
- ats->internal.recreate_problem = GNUNET_YES;
- return;
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "After execution simplex with presolver: STILL INVALID!\n");
+ char *filename;
+
+ GNUNET_asprintf (&filename,
+ "ats_mlp_p%i_m%i_%llu.mlp",
+ ats->internal.c_peers,
+ ats->internal.c_mechs,
+ GNUNET_TIME_absolute_get ().abs_value);
+ _lp_write_lp ((void *) ats->prob, NULL, filename);
+ GNUNET_free (filename);
+ stat->valid = GNUNET_NO;
+ ats->internal.recreate_problem = GNUNET_YES;
+ return;
}
stat->valid = GNUNET_YES;
}
// Solving mlp
glp_iocp opt_mlp;
- _lp_init_iocp(&opt_mlp);
+
+ _lp_init_iocp (&opt_mlp);
// maximum duration
opt_mlp.tm_lim = max_dur;
// output level
@@ -1161,342 +1164,351 @@
#endif
result = _lp_intopt (ats->prob, &opt_mlp);
- mlp_solution = _lp_mip_status (ats->prob);
+ mlp_solution = _lp_mip_status (ats->prob);
stat->solution = mlp_solution;
- if (ats_evaluate_results(result, mlp_solution, "MLP") == GNUNET_YES)
+ if (ats_evaluate_results (result, mlp_solution, "MLP") == GNUNET_YES)
{
- stat->valid = GNUNET_YES;
+ stat->valid = GNUNET_YES;
}
else
{
- // TODO: Remove if this does not appear until release
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "MLP solution for %i peers, %i mechs is invalid: %i\n",
- ats->internal.c_peers,
- ats->internal.c_mechs,
- mlp_solution);
- stat->valid = GNUNET_NO;
+ // TODO: Remove if this does not appear until release
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "MLP solution for %i peers, %i mechs is invalid: %i\n",
+ ats->internal.c_peers, ats->internal.c_mechs, mlp_solution);
+ stat->valid = GNUNET_NO;
}
#if VERBOSE_ATS
- if (_lp_get_col_prim(ats->prob,2*c_mechs+1) != 1)
+ if (_lp_get_col_prim (ats->prob, 2 * c_mechs + 1) != 1)
{
- int c;
- for (c=1; c<= available_quality_metrics; c++ )
- {
+ int c;
+
+ for (c = 1; c <= available_quality_metrics; c++)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s %f\n",
+ _lp_get_col_name (ats->prob, 2 * c_mechs + 3 + c),
+ _lp_get_col_prim (ats->prob, 2 * c_mechs + 3 + c));
+ }
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s %f\n",
- _lp_get_col_name(ats->prob,2*c_mechs+3+c),
- _lp_get_col_prim(ats->prob,2*c_mechs+3+c));
+ _lp_get_col_name (ats->prob, 2 * c_mechs + 1),
+ _lp_get_col_prim (ats->prob, 2 * c_mechs + 1));
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s %f\n",
+ _lp_get_col_name (ats->prob, 2 * c_mechs + 2),
+ _lp_get_col_prim (ats->prob, 2 * c_mechs + 2));
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s %f\n",
+ _lp_get_col_name (ats->prob, 2 * c_mechs + 3),
+ _lp_get_col_prim (ats->prob, 2 * c_mechs + 3));
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "objective value: %f\n",
+ _lp_mip_obj_val (ats->prob));
}
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s %f\n",
- _lp_get_col_name(ats->prob,2*c_mechs+1),
- _lp_get_col_prim(ats->prob,2*c_mechs+1));
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s %f\n",
- _lp_get_col_name(ats->prob,2*c_mechs+2),
- _lp_get_col_prim(ats->prob,2*c_mechs+2));
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s %f\n",
- _lp_get_col_name(ats->prob,2*c_mechs+3),
- _lp_get_col_prim(ats->prob,2*c_mechs+3));
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "objective value: %f\n",
- _lp_mip_obj_val(ats->prob));
- }
#endif
}
-void ats_shutdown (struct ATS_Handle * ats)
+void
+ats_shutdown (struct ATS_Handle *ats)
{
#if DEBUG_ATS
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ATS shutdown\n");
#endif
ats_delete_problem (ats);
- _lp_free_env();
+ _lp_free_env ();
GNUNET_free (ats);
}
-void ats_update_problem_qm (struct ATS_Handle * ats)
+void
+ats_update_problem_qm (struct ATS_Handle *ats)
{
- int array_index;
- int row_index;
- int c, c2;
- int c_q_metrics = available_quality_metrics;
+ int array_index;
+ int row_index;
+ int c, c2;
+ int c_q_metrics = available_quality_metrics;
- int *ja = GNUNET_malloc ((1 + ats->internal.c_mechs*2 + 3 +
- available_quality_metrics) * sizeof (int));
- double *ar = GNUNET_malloc ((1 + ats->internal.c_mechs*2 + 3 +
- available_quality_metrics) * sizeof (double));
+ int *ja = GNUNET_malloc ((1 + ats->internal.c_mechs * 2 + 3 +
+ available_quality_metrics) * sizeof (int));
+ double *ar = GNUNET_malloc ((1 + ats->internal.c_mechs * 2 + 3 +
+ available_quality_metrics) * sizeof (double));
#if DEBUG_ATS
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Updating problem quality metrics\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Updating problem quality metrics\n");
#endif
- row_index = ats->internal.begin_qm;
+ row_index = ats->internal.begin_qm;
- for (c=1; c <= c_q_metrics; c++)
- {
- array_index = 1;
- double value = 1;
+ for (c = 1; c <= c_q_metrics; c++)
+ {
+ array_index = 1;
+ double value = 1;
+
#if VERBOSE_ATS
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n",row_index);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n", row_index);
#endif
- _lp_set_row_bnds(ats->prob, row_index, GLP_FX, 0.0, 0.0);
- for (c2=1; c2<=ats->internal.c_mechs; c2++)
- {
- ja[array_index] = c2;
- GNUNET_assert (ats->mechanisms[c2].addr != NULL);
- GNUNET_assert (ats->mechanisms[c2].peer != NULL);
+ _lp_set_row_bnds (ats->prob, row_index, GLP_FX, 0.0, 0.0);
+ for (c2 = 1; c2 <= ats->internal.c_mechs; c2++)
+ {
+ ja[array_index] = c2;
+ GNUNET_assert (ats->mechanisms[c2].addr != NULL);
+ GNUNET_assert (ats->mechanisms[c2].peer != NULL);
- if (qm[c-1].atis_index == GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY)
- {
- double v0 = 0, v1 = 0, v2 = 0;
+ if (qm[c - 1].atis_index == GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY)
+ {
+ double v0 = 0, v1 = 0, v2 = 0;
- v0 = ats->mechanisms[c2].quality[c-1].values[0];
- if (v1 < 1) v0 = 0.1;
- v1 = ats->mechanisms[c2].quality[c-1].values[1];
- if (v1 < 1) v0 = 0.1;
- v2 = ats->mechanisms[c2].quality[c-1].values[2];
- if (v1 < 1) v0 = 0.1;
- value = 100.0 / ((v0 + 2 * v1 + 3 * v2) / 6.0);
- //value = 1;
- }
- if (qm[c-1].atis_index == GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE)
- {
- double v0 = 0, v1 = 0, v2 = 0;
- v0 = ats->mechanisms[c2].quality[c-1].values[0];
- if (v0 < 1) v0 = 1;
- v1 = ats->mechanisms[c2].quality[c-1].values[1];
- if (v1 < 1) v1 = 1;
- v2 = ats->mechanisms[c2].quality[c-1].values[2];
- if (v2 < 1) v2 = 1;
- value = (v0 + 2 * v1 + 3 * v2) / 6.0;
- if (value >= 1)
- value = (double) 10 / value;
- else
- value = 10;
- }
- ar[array_index] = (ats->mechanisms[c2].peer->f) * value;
+ v0 = ats->mechanisms[c2].quality[c - 1].values[0];
+ if (v1 < 1)
+ v0 = 0.1;
+ v1 = ats->mechanisms[c2].quality[c - 1].values[1];
+ if (v1 < 1)
+ v0 = 0.1;
+ v2 = ats->mechanisms[c2].quality[c - 1].values[2];
+ if (v1 < 1)
+ v0 = 0.1;
+ value = 100.0 / ((v0 + 2 * v1 + 3 * v2) / 6.0);
+ //value = 1;
+ }
+ if (qm[c - 1].atis_index == GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE)
+ {
+ double v0 = 0, v1 = 0, v2 = 0;
+
+ v0 = ats->mechanisms[c2].quality[c - 1].values[0];
+ if (v0 < 1)
+ v0 = 1;
+ v1 = ats->mechanisms[c2].quality[c - 1].values[1];
+ if (v1 < 1)
+ v1 = 1;
+ v2 = ats->mechanisms[c2].quality[c - 1].values[2];
+ if (v2 < 1)
+ v2 = 1;
+ value = (v0 + 2 * v1 + 3 * v2) / 6.0;
+ if (value >= 1)
+ value = (double) 10 / value;
+ else
+ value = 10;
+ }
+ ar[array_index] = (ats->mechanisms[c2].peer->f) * value;
#if VERBOSE_ATS
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: %s [%i,%i]=%f
\n",
- array_index,
- qm[c-1].name,
- row_index,
- ja[array_index],
- ar[array_index]);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: %s [%i,%i]=%f \n",
+ array_index,
+ qm[c - 1].name, row_index, ja[array_index], ar[array_index]);
#endif
- array_index++;
- }
- ja[array_index] = ats->internal.col_qm + c - 1;
- ar[array_index] = -1;
+ array_index++;
+ }
+ ja[array_index] = ats->internal.col_qm + c - 1;
+ ar[array_index] = -1;
#if VERBOSE_ATS
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
- array_index,
- row_index,
- ja[array_index],
- ar[array_index]);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
+ array_index, row_index, ja[array_index], ar[array_index]);
#endif
- _lp_set_mat_row (ats->prob, row_index, array_index, ja, ar);
- array_index = 1;
- row_index++;
- }
- GNUNET_free_non_null (ja);
- GNUNET_free_non_null (ar);
+ _lp_set_mat_row (ats->prob, row_index, array_index, ja, ar);
+ array_index = 1;
+ row_index++;
+ }
+ GNUNET_free_non_null (ja);
+ GNUNET_free_non_null (ar);
}
void
-ats_calculate_bandwidth_distribution (struct ATS_Handle * ats)
+ats_calculate_bandwidth_distribution (struct ATS_Handle *ats)
{
- struct GNUNET_TIME_Absolute start;
- struct GNUNET_TIME_Relative creation;
- struct GNUNET_TIME_Relative solving;
- int c_m;
- int c_p;
- char *text = "unmodified";
+ struct GNUNET_TIME_Absolute start;
+ struct GNUNET_TIME_Relative creation;
+ struct GNUNET_TIME_Relative solving;
+ int c_m;
+ int c_p;
+ char *text = "unmodified";
#if FIXME_WACHS
- int dur;
- if (INT_MAX < ats->max_exec_duration.rel_value)
- dur = INT_MAX;
- else
- dur = (int) ats->max_exec_duration.rel_value;
+ int dur;
+
+ if (INT_MAX < ats->max_exec_duration.rel_value)
+ dur = INT_MAX;
+ else
+ dur = (int) ats->max_exec_duration.rel_value;
#endif
- ats->internal.simplex_rerun_required = GNUNET_NO;
- start = GNUNET_TIME_absolute_get();
- if ((ats->internal.recreate_problem == GNUNET_YES) ||
- (ats->prob==NULL) ||
- (ats->internal.valid == GNUNET_NO))
- {
- text = "new";
- ats->internal.recreate_problem = GNUNET_YES;
- ats_delete_problem (ats);
- ats->addr_notification(&ats->peers , &c_p, &ats->mechanisms, &c_m);
+ ats->internal.simplex_rerun_required = GNUNET_NO;
+ start = GNUNET_TIME_absolute_get ();
+ if ((ats->internal.recreate_problem == GNUNET_YES) ||
+ (ats->prob == NULL) || (ats->internal.valid == GNUNET_NO))
+ {
+ text = "new";
+ ats->internal.recreate_problem = GNUNET_YES;
+ ats_delete_problem (ats);
+ ats->addr_notification (&ats->peers, &c_p, &ats->mechanisms, &c_m);
#if DEBUG_ATS
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Service returned: %i peer, %i mechs\n",
- c_p,
- c_m);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Service returned: %i peer, %i mechs\n", c_p, c_m);
#endif
- ats_create_problem (ats, &ats->internal, ats->peers, c_p,
ats->mechanisms, c_m);
+ ats_create_problem (ats, &ats->internal, ats->peers, c_p, ats->mechanisms,
+ c_m);
#if DEBUG_ATS
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Peers/Addresses were modified... new problem: %i peer, %i mechs\n",
- ats->internal.c_peers,
- ats->internal.c_mechs);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Peers/Addresses were modified... new problem: %i peer, %i
mechs\n",
+ ats->internal.c_peers, ats->internal.c_mechs);
#endif
- }
+ }
- else if ((ats->internal.recreate_problem == GNUNET_NO) &&
- (ats->internal.modified_resources == GNUNET_YES) &&
- (ats->internal.valid == GNUNET_YES))
- {
- text = "modified resources";
- ats_update_problem_cr (ats);
- }
- else if ((ats->internal.recreate_problem == GNUNET_NO) &&
- (ats->internal.modified_quality == GNUNET_YES) &&
- (ats->internal.valid == GNUNET_YES))
- {
- text = "modified quality";
- ats_update_problem_qm (ats);
- //ats_update_problem_qm_TEST ();
- }
+ else if ((ats->internal.recreate_problem == GNUNET_NO) &&
+ (ats->internal.modified_resources == GNUNET_YES) &&
+ (ats->internal.valid == GNUNET_YES))
+ {
+ text = "modified resources";
+ ats_update_problem_cr (ats);
+ }
+ else if ((ats->internal.recreate_problem == GNUNET_NO) &&
+ (ats->internal.modified_quality == GNUNET_YES) &&
+ (ats->internal.valid == GNUNET_YES))
+ {
+ text = "modified quality";
+ ats_update_problem_qm (ats);
+ //ats_update_problem_qm_TEST ();
+ }
#if DEBUG_ATS
- else GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Problem is %s\n", text);
+ else
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Problem is %s\n", text);
#endif
- creation =
GNUNET_TIME_absolute_get_difference(start,GNUNET_TIME_absolute_get());
- start = GNUNET_TIME_absolute_get();
+ creation =
+ GNUNET_TIME_absolute_get_difference (start, GNUNET_TIME_absolute_get ());
+ start = GNUNET_TIME_absolute_get ();
- ats->internal.solution = GLP_UNDEF;
- if (ats->internal.valid == GNUNET_YES)
- {
- ats_solve_problem(ats,
- ats->max_iterations,
- ats->max_exec_duration.rel_value,
- ats->internal.c_peers,
- ats->internal.c_mechs,
- &ats->internal);
- }
- solving =
GNUNET_TIME_absolute_get_difference(start,GNUNET_TIME_absolute_get());
+ ats->internal.solution = GLP_UNDEF;
+ if (ats->internal.valid == GNUNET_YES)
+ {
+ ats_solve_problem (ats,
+ ats->max_iterations,
+ ats->max_exec_duration.rel_value,
+ ats->internal.c_peers,
+ ats->internal.c_mechs, &ats->internal);
+ }
+ solving =
+ GNUNET_TIME_absolute_get_difference (start, GNUNET_TIME_absolute_get ());
- if (ats->internal.valid == GNUNET_YES)
- {
- /* Telling about new distribution*/
- ats->result_cb ();
+ if (ats->internal.valid == GNUNET_YES)
+ {
+ /* Telling about new distribution */
+ ats->result_cb ();
- int msg_type = GNUNET_ERROR_TYPE_DEBUG;
+ int msg_type = GNUNET_ERROR_TYPE_DEBUG;
+
#if DEBUG_ATS
- msg_type = GNUNET_ERROR_TYPE_ERROR;
+ msg_type = GNUNET_ERROR_TYPE_ERROR;
#endif
- GNUNET_log (msg_type,
- "MLP %s: creation time: %llu, execution time: %llu, %i peers, %i
mechanisms, simplex rerun: %s, solution %s\n",
- text,
- creation.rel_value,
- solving.rel_value,
- ats->internal.c_peers,
- ats->internal.c_mechs,
- (ats->internal.simplex_rerun_required == GNUNET_NO) ? "NO" : "YES",
- (ats->internal.solution == 5) ? "OPTIMAL" : "INVALID");
- ats->successful_executions ++;
- GNUNET_STATISTICS_set (ats->stats, "# ATS successful executions",
- ats->successful_executions,
- GNUNET_NO);
+ GNUNET_log (msg_type,
+ "MLP %s: creation time: %llu, execution time: %llu, %i peers,
%i mechanisms, simplex rerun: %s, solution %s\n",
+ text,
+ creation.rel_value,
+ solving.rel_value,
+ ats->internal.c_peers,
+ ats->internal.c_mechs,
+ (ats->internal.simplex_rerun_required ==
+ GNUNET_NO) ? "NO" : "YES",
+ (ats->internal.solution == 5) ? "OPTIMAL" : "INVALID");
+ ats->successful_executions++;
+ GNUNET_STATISTICS_set (ats->stats, "# ATS successful executions",
+ ats->successful_executions, GNUNET_NO);
- if ((ats->internal.recreate_problem == GNUNET_YES) || (ats->prob==NULL))
- GNUNET_STATISTICS_set (ats->stats, "ATS state",ATS_NEW, GNUNET_NO);
- else if ((ats->internal.modified_resources == GNUNET_YES) &&
- (ats->internal.modified_quality == GNUNET_NO))
- GNUNET_STATISTICS_set (ats->stats, "ATS state", ATS_COST_UPDATED,
GNUNET_NO);
- else if ((ats->internal.modified_resources == GNUNET_NO) &&
- (ats->internal.modified_quality == GNUNET_YES) &&
- (ats->internal.simplex_rerun_required == GNUNET_NO))
- GNUNET_STATISTICS_set (ats->stats, "ATS state", ATS_QUALITY_UPDATED,
GNUNET_NO);
- else if ((ats->internal.modified_resources == GNUNET_YES) &&
- (ats->internal.modified_quality == GNUNET_YES) &&
- (ats->internal.simplex_rerun_required == GNUNET_NO))
- GNUNET_STATISTICS_set (ats->stats, "ATS state",
ATS_QUALITY_COST_UPDATED, GNUNET_NO);
- else if (ats->internal.simplex_rerun_required == GNUNET_NO)
- GNUNET_STATISTICS_set (ats->stats, "ATS state", ATS_UNMODIFIED,
GNUNET_NO);
+ if ((ats->internal.recreate_problem == GNUNET_YES) || (ats->prob == NULL))
+ GNUNET_STATISTICS_set (ats->stats, "ATS state", ATS_NEW, GNUNET_NO);
+ else if ((ats->internal.modified_resources == GNUNET_YES) &&
+ (ats->internal.modified_quality == GNUNET_NO))
+ GNUNET_STATISTICS_set (ats->stats, "ATS state", ATS_COST_UPDATED,
+ GNUNET_NO);
+ else if ((ats->internal.modified_resources == GNUNET_NO) &&
+ (ats->internal.modified_quality == GNUNET_YES) &&
+ (ats->internal.simplex_rerun_required == GNUNET_NO))
+ GNUNET_STATISTICS_set (ats->stats, "ATS state", ATS_QUALITY_UPDATED,
+ GNUNET_NO);
+ else if ((ats->internal.modified_resources == GNUNET_YES) &&
+ (ats->internal.modified_quality == GNUNET_YES) &&
+ (ats->internal.simplex_rerun_required == GNUNET_NO))
+ GNUNET_STATISTICS_set (ats->stats, "ATS state", ATS_QUALITY_COST_UPDATED,
+ GNUNET_NO);
+ else if (ats->internal.simplex_rerun_required == GNUNET_NO)
+ GNUNET_STATISTICS_set (ats->stats, "ATS state", ATS_UNMODIFIED,
+ GNUNET_NO);
+ }
+ else
+ {
+ if (ats->internal.c_peers != 0)
+ {
+ ats->invalid_executions++;
+ GNUNET_STATISTICS_set (ats->stats, "# ATS invalid executions",
+ ats->invalid_executions, GNUNET_NO);
}
else
{
- if (ats->internal.c_peers != 0)
- {
- ats->invalid_executions ++;
- GNUNET_STATISTICS_set (ats->stats, "# ATS invalid executions",
- ats->invalid_executions, GNUNET_NO);
- }
- else
- {
- GNUNET_STATISTICS_set (ats->stats, "# ATS successful executions",
- ats->successful_executions, GNUNET_NO);
- }
+ GNUNET_STATISTICS_set (ats->stats, "# ATS successful executions",
+ ats->successful_executions, GNUNET_NO);
}
+ }
- GNUNET_STATISTICS_set (ats->stats,
- "ATS duration", solving.rel_value + creation.rel_value, GNUNET_NO);
- GNUNET_STATISTICS_set (ats->stats,
- "ATS mechanisms", ats->internal.c_mechs, GNUNET_NO);
- GNUNET_STATISTICS_set (ats->stats,
- "ATS peers", ats->internal.c_peers, GNUNET_NO);
- GNUNET_STATISTICS_set (ats->stats,
- "ATS solution", ats->internal.solution, GNUNET_NO);
- GNUNET_STATISTICS_set (ats->stats,
- "ATS timestamp", start.abs_value, GNUNET_NO);
+ GNUNET_STATISTICS_set (ats->stats,
+ "ATS duration", solving.rel_value +
creation.rel_value,
+ GNUNET_NO);
+ GNUNET_STATISTICS_set (ats->stats, "ATS mechanisms", ats->internal.c_mechs,
+ GNUNET_NO);
+ GNUNET_STATISTICS_set (ats->stats, "ATS peers", ats->internal.c_peers,
+ GNUNET_NO);
+ GNUNET_STATISTICS_set (ats->stats, "ATS solution", ats->internal.solution,
+ GNUNET_NO);
+ GNUNET_STATISTICS_set (ats->stats, "ATS timestamp", start.abs_value,
+ GNUNET_NO);
- if ((ats->save_mlp == GNUNET_YES) &&
- (ats->internal.c_mechs >= ats->dump_min_peers) &&
- (ats->internal.c_mechs >= ats->dump_min_addr))
+ if ((ats->save_mlp == GNUNET_YES) &&
+ (ats->internal.c_mechs >= ats->dump_min_peers) &&
+ (ats->internal.c_mechs >= ats->dump_min_addr))
+ {
+ char *filename;
+
+ if (ats->dump_overwrite == GNUNET_NO)
{
- char * filename;
- if (ats->dump_overwrite == GNUNET_NO)
- {
- GNUNET_asprintf (&filename, "ats_mlp_p%i_m%i_%s_%llu.mlp",
- ats->internal.c_peers,
- ats->internal.c_mechs,
- text,
- GNUNET_TIME_absolute_get().abs_value);
- _lp_write_lp ((void *) ats->prob, NULL, filename);
- }
- else
- {
- GNUNET_asprintf (&filename, "ats_mlp_p%i_m%i.mlp",
- ats->internal.c_peers, ats->internal.c_mechs );
- _lp_write_lp ((void *) ats->prob, NULL, filename);
- }
- GNUNET_free (filename);
+ GNUNET_asprintf (&filename, "ats_mlp_p%i_m%i_%s_%llu.mlp",
+ ats->internal.c_peers,
+ ats->internal.c_mechs,
+ text, GNUNET_TIME_absolute_get ().abs_value);
+ _lp_write_lp ((void *) ats->prob, NULL, filename);
}
- if ((ats->save_solution == GNUNET_YES) &&
- (ats->internal.c_mechs >= ats->dump_min_peers) &&
- (ats->internal.c_mechs >= ats->dump_min_addr))
+ else
{
- char * filename;
- if (ats->dump_overwrite == GNUNET_NO)
- {
- GNUNET_asprintf (&filename, "ats_mlp_p%i_m%i_%s_%llu.sol",
- ats->internal.c_peers,
- ats->internal.c_mechs,
- text,
- GNUNET_TIME_absolute_get().abs_value);
- _lp_print_sol (ats->prob, filename);
- }
- else
- {
- GNUNET_asprintf (&filename, "ats_mlp_p%i_m%i.sol",
- ats->internal.c_peers, ats->internal.c_mechs);
- _lp_print_sol (ats->prob, filename);
- }
- GNUNET_free (filename);
+ GNUNET_asprintf (&filename, "ats_mlp_p%i_m%i.mlp",
+ ats->internal.c_peers, ats->internal.c_mechs);
+ _lp_write_lp ((void *) ats->prob, NULL, filename);
}
+ GNUNET_free (filename);
+ }
+ if ((ats->save_solution == GNUNET_YES) &&
+ (ats->internal.c_mechs >= ats->dump_min_peers) &&
+ (ats->internal.c_mechs >= ats->dump_min_addr))
+ {
+ char *filename;
- ats->internal.recreate_problem = GNUNET_NO;
- ats->internal.modified_resources = GNUNET_NO;
- ats->internal.modified_quality = GNUNET_NO;
+ if (ats->dump_overwrite == GNUNET_NO)
+ {
+ GNUNET_asprintf (&filename, "ats_mlp_p%i_m%i_%s_%llu.sol",
+ ats->internal.c_peers,
+ ats->internal.c_mechs,
+ text, GNUNET_TIME_absolute_get ().abs_value);
+ _lp_print_sol (ats->prob, filename);
+ }
+ else
+ {
+ GNUNET_asprintf (&filename, "ats_mlp_p%i_m%i.sol",
+ ats->internal.c_peers, ats->internal.c_mechs);
+ _lp_print_sol (ats->prob, filename);
+ }
+ GNUNET_free (filename);
+ }
+
+ ats->internal.recreate_problem = GNUNET_NO;
+ ats->internal.modified_resources = GNUNET_NO;
+ ats->internal.modified_quality = GNUNET_NO;
}
/**
@@ -1508,198 +1520,188 @@
* valid
*/
-int ats_evaluate_results (int result, int solution, char * problem)
+int
+ats_evaluate_results (int result, int solution, char *problem)
{
- int cont = GNUNET_NO;
+ int cont = GNUNET_NO;
+
#if DEBUG_ATS || VERBOSE_ATS
- int error_kind = GNUNET_ERROR_TYPE_DEBUG;
+ int error_kind = GNUNET_ERROR_TYPE_DEBUG;
#endif
#if VERBOSE_ATS
- error_kind = GNUNET_ERROR_TYPE_ERROR;
+ error_kind = GNUNET_ERROR_TYPE_ERROR;
#endif
- switch (result) {
- case GNUNET_SYSERR : /* GNUNET problem, not GLPK related */
+ switch (result)
+ {
+ case GNUNET_SYSERR: /* GNUNET problem, not GLPK related */
#if DEBUG_ATS || VERBOSE_ATS
- GNUNET_log (error_kind,
- "%s, GLPK solving not executed\n", problem);
+ GNUNET_log (error_kind, "%s, GLPK solving not executed\n", problem);
#endif
- break;
- case GLP_ESTOP : /* search terminated by application */
+ break;
+ case GLP_ESTOP: /* search terminated by application */
#if DEBUG_ATS || VERBOSE_ATS
- GNUNET_log (error_kind,
- "%s , Search terminated by application\n", problem);
+ GNUNET_log (error_kind, "%s , Search terminated by application\n",
problem);
#endif
- break;
- case GLP_EITLIM : /* iteration limit exceeded */
+ break;
+ case GLP_EITLIM: /* iteration limit exceeded */
#if DEBUG_ATS || VERBOSE_ATS
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "%s Iteration limit exceeded\n", problem);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "%s Iteration limit exceeded\n", problem);
#endif
- break;
- case GLP_ETMLIM : /* time limit exceeded */
+ break;
+ case GLP_ETMLIM: /* time limit exceeded */
#if DEBUG_ATS || VERBOSE_ATS
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "%s Time limit exceeded\n", problem);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%s Time limit exceeded\n",
problem);
#endif
- break;
- case GLP_ENOPFS : /* no primal feasible solution */
- case GLP_ENODFS : /* no dual feasible solution */
+ break;
+ case GLP_ENOPFS: /* no primal feasible solution */
+ case GLP_ENODFS: /* no dual feasible solution */
#if DEBUG_ATS || VERBOSE_ATS
- GNUNET_log (error_kind,
- "%s No feasible solution\n", problem);
+ GNUNET_log (error_kind, "%s No feasible solution\n", problem);
#endif
- break;
- case GLP_EBADB : /* invalid basis */
- case GLP_ESING : /* singular matrix */
- case GLP_ECOND : /* ill-conditioned matrix */
- case GLP_EBOUND : /* invalid bounds */
- case GLP_EFAIL : /* solver failed */
- case GLP_EOBJLL : /* objective lower limit reached */
- case GLP_EOBJUL : /* objective upper limit reached */
- case GLP_EROOT : /* root LP optimum not provided */
+ break;
+ case GLP_EBADB: /* invalid basis */
+ case GLP_ESING: /* singular matrix */
+ case GLP_ECOND: /* ill-conditioned matrix */
+ case GLP_EBOUND: /* invalid bounds */
+ case GLP_EFAIL: /* solver failed */
+ case GLP_EOBJLL: /* objective lower limit reached */
+ case GLP_EOBJUL: /* objective upper limit reached */
+ case GLP_EROOT: /* root LP optimum not provided */
#if DEBUG_ATS || VERBOSE_ATS
- GNUNET_log (error_kind,
- "%s Invalid Input data: %i\n",
- problem, result);
+ GNUNET_log (error_kind, "%s Invalid Input data: %i\n", problem, result);
#endif
- break;
- case 0:
+ break;
+ case 0:
#if DEBUG_ATS || VERBOSE_ATS
- GNUNET_log (error_kind,
- "%s Problem has been solved\n", problem);
+ GNUNET_log (error_kind, "%s Problem has been solved\n", problem);
#endif
break;
}
- switch (solution) {
- case GLP_UNDEF:
+ switch (solution)
+ {
+ case GLP_UNDEF:
#if DEBUG_ATS || VERBOSE_ATS
- GNUNET_log (error_kind,
- "%s solution is undefined\n", problem);
+ GNUNET_log (error_kind, "%s solution is undefined\n", problem);
#endif
- break;
- case GLP_OPT:
+ break;
+ case GLP_OPT:
#if DEBUG_ATS || VERBOSE_ATS
- GNUNET_log (error_kind,
- "%s solution is optimal\n", problem);
+ GNUNET_log (error_kind, "%s solution is optimal\n", problem);
#endif
- cont=GNUNET_YES;
- break;
- case GLP_FEAS:
+ cont = GNUNET_YES;
+ break;
+ case GLP_FEAS:
#if DEBUG_ATS || VERBOSE_ATS
- GNUNET_log (error_kind,
- "%s solution is %s feasible, however, its optimality (or
non-optimality) has not been proven\n",
- problem, (0==strcmp(problem,"LP")?"":"integer"));
+ GNUNET_log (error_kind,
+ "%s solution is %s feasible, however, its optimality (or
non-optimality) has not been proven\n",
+ problem, (0 == strcmp (problem, "LP") ? "" : "integer"));
#endif
- cont=GNUNET_YES;
- break;
- case GLP_NOFEAS:
+ cont = GNUNET_YES;
+ break;
+ case GLP_NOFEAS:
#if DEBUG_ATS || VERBOSE_ATS
- GNUNET_log (error_kind, "%s problem has no %sfeasible solution\n",
- problem, (0==strcmp(problem,"LP")?"":"integer "));
+ GNUNET_log (error_kind, "%s problem has no %sfeasible solution\n",
+ problem, (0 == strcmp (problem, "LP") ? "" : "integer "));
#endif
- break;
- case GLP_INFEAS:
+ break;
+ case GLP_INFEAS:
#if DEBUG_ATS || VERBOSE_ATS
- GNUNET_log (error_kind, "%s problem is infeasible \n", problem);
+ GNUNET_log (error_kind, "%s problem is infeasible \n", problem);
#endif
- break;
- case GLP_UNBND:
+ break;
+ case GLP_UNBND:
#if DEBUG_ATS || VERBOSE_ATS
- GNUNET_log (error_kind, "%s problem is unbounded \n", problem);
+ GNUNET_log (error_kind, "%s problem is unbounded \n", problem);
#endif
- default:
- break;
+ default:
+ break;
}
-return cont;
+ return cont;
}
-void ats_update_problem_cr (struct ATS_Handle * ats)
+void
+ats_update_problem_cr (struct ATS_Handle *ats)
{
- int array_index;
- int row_index;
- int c, c2;
- double ct_max, ct_min;
+ int array_index;
+ int row_index;
+ int c, c2;
+ double ct_max, ct_min;
- int *ja = GNUNET_malloc ((1 + ats->internal.c_mechs*2 + 3 +
- available_quality_metrics) * sizeof (int));
- double *ar = GNUNET_malloc ((1 + ats->internal.c_mechs*2 + 3 +
- available_quality_metrics) * sizeof (double));
+ int *ja = GNUNET_malloc ((1 + ats->internal.c_mechs * 2 + 3 +
+ available_quality_metrics) * sizeof (int));
+ double *ar = GNUNET_malloc ((1 + ats->internal.c_mechs * 2 + 3 +
+ available_quality_metrics) * sizeof (double));
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Updating problem quality metrics\n");
- row_index = ats->internal.begin_cr;
- array_index = 1;
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Updating problem quality metrics\n");
+ row_index = ats->internal.begin_cr;
+ array_index = 1;
- for (c=0; c<available_ressources; c++)
- {
- ct_max = ressources[c].c_max;
- ct_min = ressources[c].c_min;
+ for (c = 0; c < available_ressources; c++)
+ {
+ ct_max = ressources[c].c_max;
+ ct_min = ressources[c].c_min;
#if VERBOSE_ATS
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] %f..%f\n",
- row_index,
- ct_min,
- ct_max);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] %f..%f\n",
+ row_index, ct_min, ct_max);
#endif
- _lp_set_row_bnds(ats->prob, row_index, GLP_DB, ct_min, ct_max);
- for (c2=1; c2<=ats->internal.c_mechs; c2++)
- {
- double value = 0;
- GNUNET_assert (ats->mechanisms[c2].addr != NULL);
- GNUNET_assert (ats->mechanisms[c2].peer != NULL);
+ _lp_set_row_bnds (ats->prob, row_index, GLP_DB, ct_min, ct_max);
+ for (c2 = 1; c2 <= ats->internal.c_mechs; c2++)
+ {
+ double value = 0;
- ja[array_index] = c2;
- value = ats->mechanisms[c2].ressources[c].c;
- ar[array_index] = value;
+ GNUNET_assert (ats->mechanisms[c2].addr != NULL);
+ GNUNET_assert (ats->mechanisms[c2].peer != NULL);
+
+ ja[array_index] = c2;
+ value = ats->mechanisms[c2].ressources[c].c;
+ ar[array_index] = value;
#if VERBOSE_ATS
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
- array_index,
- row_index,
- ja[array_index],
- ar[array_index]);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
+ array_index, row_index, ja[array_index], ar[array_index]);
#endif
- array_index++;
- }
- _lp_set_mat_row (ats->prob, row_index, array_index, ja, ar);
- row_index ++;
+ array_index++;
}
- GNUNET_free_non_null (ja);
- GNUNET_free_non_null (ar);
+ _lp_set_mat_row (ats->prob, row_index, array_index, ja, ar);
+ row_index++;
+ }
+ GNUNET_free_non_null (ja);
+ GNUNET_free_non_null (ar);
}
-void ats_set_logging_options (struct ATS_Handle * ats,
- struct GNUNET_STATISTICS_Handle * stats,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+void
+ats_set_logging_options (struct ATS_Handle *ats,
+ struct GNUNET_STATISTICS_Handle *stats,
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
{
int minimum_addresses;
int minimum_peers;
int overwrite_dump;
int log_solution;
int log_problem;
- unsigned long long value;
+ unsigned long long value;
if (ats == NULL)
return;
log_problem = GNUNET_CONFIGURATION_get_value_yesno (cfg,
- "transport",
- "DUMP_MLP");
+ "transport", "DUMP_MLP");
log_solution = GNUNET_CONFIGURATION_get_value_yesno (cfg,
- "transport",
- "DUMP_SOLUTION");
+ "transport",
+ "DUMP_SOLUTION");
overwrite_dump = GNUNET_CONFIGURATION_get_value_yesno (cfg,
- "transport",
- "DUMP_OVERWRITE");
+ "transport",
+ "DUMP_OVERWRITE");
if (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_number(cfg,
- "transport",
- "DUMP_MIN_PEERS",
- &value))
+ GNUNET_CONFIGURATION_get_value_number (cfg,
+ "transport",
+ "DUMP_MIN_PEERS", &value))
minimum_peers = (int) value;
if (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_number(cfg,
- "transport",
- "DUMP_MIN_ADDRS",
- &value))
+ GNUNET_CONFIGURATION_get_value_number (cfg,
+ "transport",
+ "DUMP_MIN_ADDRS", &value))
minimum_addresses = (int) value;
@@ -1712,64 +1714,58 @@
}
#if 0
-static void ats_update_problem_qm_TEST ()
+static void
+ats_update_problem_qm_TEST ()
{
- int row_index;
- int c
- int c2;
- int c_old;
- int changed = 0;
+ int row_index;
+ int c int c2;
+ int c_old;
+ int changed = 0;
- int old_ja[ats->internal.c_mechs + 2];
- double old_ar[ats->internal.c_mechs + 2];
+ int old_ja[ats->internal.c_mechs + 2];
+ double old_ar[ats->internal.c_mechs + 2];
- int *ja = GNUNET_malloc ((1 + ats->internal.c_mechs*2 + 3 +
- available_quality_metrics) * sizeof (int));
- double *ar = GNUNET_malloc ((1 + ats->internal.c_mechs*2 + 3 +
- available_quality_metrics) * sizeof (double));
+ int *ja = GNUNET_malloc ((1 + ats->internal.c_mechs * 2 + 3 +
+ available_quality_metrics) * sizeof (int));
+ double *ar = GNUNET_malloc ((1 + ats->internal.c_mechs * 2 + 3 +
+ available_quality_metrics) * sizeof (double));
#if DEBUG_ATS
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Updating problem quality metrics TEST\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Updating problem quality metrics TEST\n");
#endif
- if (ats->internal.begin_qm >0)
- row_index = ats->internal.begin_qm;
- else
- return;
- for (c=0; c<available_quality_metrics; c++)
+ if (ats->internal.begin_qm > 0)
+ row_index = ats->internal.begin_qm;
+ else
+ return;
+ for (c = 0; c < available_quality_metrics; c++)
+ {
+ c_old = _lp_get_mat_row (ats->prob, row_index, old_ja, old_ar);
+ _lp_set_row_bnds (ats->prob, row_index, GLP_FX, 0.0, 0.0);
+ for (c2 = 1; c2 <= c_old; c2++)
{
- c_old = _lp_get_mat_row (ats->prob, row_index, old_ja, old_ar);
- _lp_set_row_bnds(ats->prob, row_index, GLP_FX, 0.0, 0.0);
- for (c2=1; c2<=c_old; c2++)
+ ja[c2] = old_ja[c2];
+ if ((changed < 3) && (c2 > 2) && (old_ar[c2] != -1))
{
- ja[c2] = old_ja[c2];
- if ((changed < 3) && (c2>2) && (old_ar[c2] != -1))
- {
- ar[c2] = old_ar[c2] + 5 - changed;
- changed ++;
- }
- else
- ar[c2] = old_ar[c2];
+ ar[c2] = old_ar[c2] + 5 - changed;
+ changed++;
+ }
+ else
+ ar[c2] = old_ar[c2];
#if VERBOSE_ATS
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "[index]=[%i]: old [%i,%i]=%f new [%i,%i]=%f\n",
- c2,
- row_index,
- old_ja[c2],
- old_ar[c2],
- row_index,
- ja[c2],
- ar[c2]);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "[index]=[%i]: old [%i,%i]=%f new [%i,%i]=%f\n",
+ c2,
+ row_index, old_ja[c2], old_ar[c2], row_index, ja[c2],
ar[c2]);
#endif
- }
- _lp_set_mat_row (ats->prob, row_index, c_old, ja, ar);
- row_index ++;
}
- GNUNET_free_non_null (ja);
- GNUNET_free_non_null (ar);
+ _lp_set_mat_row (ats->prob, row_index, c_old, ja, ar);
+ row_index++;
+ }
+ GNUNET_free_non_null (ja);
+ GNUNET_free_non_null (ar);
}
#endif
/* end of transport_ats.c */
-
Modified: gnunet/src/transport/gnunet-service-transport_ats.h
===================================================================
--- gnunet/src/transport/gnunet-service-transport_ats.h 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/transport/gnunet-service-transport_ats.h 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -68,10 +68,8 @@
struct ATS_peer;
typedef void (*GNUNET_TRANSPORT_ATS_AddressNotification)
- (struct ATS_peer **peers,
- int * c_p,
- struct ATS_mechanism ** mechanisms,
- int * c_m );
+ (struct ATS_peer ** peers,
+ int *c_p, struct ATS_mechanism ** mechanisms, int *c_m);
typedef void (*GNUNET_TRANSPORT_ATS_ResultCallback) (void);
@@ -119,192 +117,192 @@
* result of last GLPK run
* 5 == OPTIMAL
*/
- int solution;
+ int solution;
/**
* Ressource costs or quality metrics changed
* update problem before solving
*/
- int modified_resources;
+ int modified_resources;
/**
* Ressource costs or quality metrics changed, update matrix
* update problem before solving
*/
- int modified_quality;
+ int modified_quality;
/**
* Peers have connected or disconnected
* problem has to be recreated
*/
- int recreate_problem;
+ int recreate_problem;
/**
* Was the available basis invalid and we needed to rerun simplex?
*/
- int simplex_rerun_required;
+ int simplex_rerun_required;
/**
* is problem currently valid and can it be solved
*/
- int valid;
+ int valid;
/**
* Number of transport mechanisms in the problem
*/
- int c_mechs;
+ int c_mechs;
/**
* Number of transport mechanisms in the problem
*/
- int c_peers;
+ int c_peers;
/**
* row index where quality related rows start
*/
- int begin_qm;
+ int begin_qm;
/**
* row index where quality related rows end
*/
- int end_qm;
+ int end_qm;
/**
* row index where ressource cost related rows start
*/
- int begin_cr;
+ int begin_cr;
/**
* row index where ressource cost related rows end
*/
- int end_cr;
+ int end_cr;
/**
* column index for objective function value d
*/
- int col_d;
+ int col_d;
/**
* column index for objective function value u
*/
- int col_u;
+ int col_u;
/**
* column index for objective function value r
*/
- int col_r;
+ int col_r;
/**
* column index for objective function value quality metrics
*/
- int col_qm;
+ int col_qm;
/**
* column index for objective function value cost ressources
*/
- int col_cr;
+ int col_cr;
};
struct ATS_Handle
{
- /*
- * Callback functions
- */
+ /*
+ * Callback functions
+ */
- GNUNET_TRANSPORT_ATS_AddressNotification addr_notification;
+ GNUNET_TRANSPORT_ATS_AddressNotification addr_notification;
- GNUNET_TRANSPORT_ATS_ResultCallback result_cb;
+ GNUNET_TRANSPORT_ATS_ResultCallback result_cb;
/**
* Statistics handle
*/
- struct GNUNET_STATISTICS_Handle *stats;
+ struct GNUNET_STATISTICS_Handle *stats;
/**
* Maximum execution time per calculation
*/
- struct GNUNET_TIME_Relative max_exec_duration;
+ struct GNUNET_TIME_Relative max_exec_duration;
/**
* GLPK (MLP) problem object
*/
#if HAVE_LIBGLPK
- glp_prob *prob;
+ glp_prob *prob;
#else
- void * prob;
+ void *prob;
#endif
/**
* Internal information state of the GLPK problem
*/
- struct ATS_internals internal;
+ struct ATS_internals internal;
/**
* mechanisms used in current problem
* needed for problem modification
*/
- struct ATS_mechanism * mechanisms;
+ struct ATS_mechanism *mechanisms;
/**
* peers used in current problem
* needed for problem modification
*/
- struct ATS_peer * peers;
+ struct ATS_peer *peers;
/**
* State of the MLP problem
* value of ATS_problem_state
*
*/
- int state;
+ int state;
/**
* number of successful executions
*/
- int successful_executions;
+ int successful_executions;
/**
* number with an invalid result
*/
- int invalid_executions;
+ int invalid_executions;
/**
* Maximum number of LP iterations per calculation
*/
- int max_iterations;
+ int max_iterations;
- /*
- * ATS configuration
- */
+ /*
+ * ATS configuration
+ */
/**
* Diversity weight
*/
- double D;
+ double D;
/**
* Utility weight
*/
- double U;
+ double U;
/**
* Relativity weight
*/
- double R;
+ double R;
/**
* Minimum bandwidth per peer
*/
- int v_b_min;
+ int v_b_min;
/**
* Minimum number of connections per peer
*/
- int v_n_min;
+ int v_n_min;
/**
@@ -315,104 +313,104 @@
/**
* Dump problem to a file?
*/
- int save_mlp;
+ int save_mlp;
/**
* Dump solution to a file
*/
- int save_solution;
+ int save_solution;
/**
* Dump solution when minimum peers:
*/
- int dump_min_peers;
+ int dump_min_peers;
/**
* Dump solution when minimum addresses:
*/
- int dump_min_addr;
+ int dump_min_addr;
/**
* Dump solution overwrite file:
*/
- int dump_overwrite;
+ int dump_overwrite;
};
struct ATS_mechanism
{
- struct ATS_mechanism * prev;
- struct ATS_mechanism * next;
- struct ForeignAddressList * addr;
- struct ATS_quality_entry * quality;
- struct ATS_ressource_entry * ressources;
- struct TransportPlugin * plugin;
- struct ATS_peer * peer;
- int col_index;
- int id;
- struct ATS_ressource_cost * rc;
+ struct ATS_mechanism *prev;
+ struct ATS_mechanism *next;
+ struct ForeignAddressList *addr;
+ struct ATS_quality_entry *quality;
+ struct ATS_ressource_entry *ressources;
+ struct TransportPlugin *plugin;
+ struct ATS_peer *peer;
+ int col_index;
+ int id;
+ struct ATS_ressource_cost *rc;
};
struct ATS_peer
{
- struct GNUNET_PeerIdentity peer;
+ struct GNUNET_PeerIdentity peer;
- struct ATS_mechanism * m_head;
- struct ATS_mechanism * m_tail;
+ struct ATS_mechanism *m_head;
+ struct ATS_mechanism *m_tail;
- /* preference value f */
- double f;
+ /* preference value f */
+ double f;
- //struct NeighbourList * n;
+ //struct NeighbourList * n;
};
struct ATS_ressource
{
- /* index in ressources array */
- int index;
- /* depending ATSi parameter to calculcate limits */
- int atis_index;
- /* cfg option to load limits */
- char * cfg_param;
- /* lower bound */
- double c_min;
- /* upper bound */
- double c_max;
+ /* index in ressources array */
+ int index;
+ /* depending ATSi parameter to calculcate limits */
+ int atis_index;
+ /* cfg option to load limits */
+ char *cfg_param;
+ /* lower bound */
+ double c_min;
+ /* upper bound */
+ double c_max;
- /* cofficients for the specific plugins */
- double c_unix;
- double c_tcp;
- double c_udp;
- double c_http;
- double c_https;
- double c_wlan;
- double c_default;
+ /* cofficients for the specific plugins */
+ double c_unix;
+ double c_tcp;
+ double c_udp;
+ double c_http;
+ double c_https;
+ double c_wlan;
+ double c_default;
};
struct ATS_ressource_entry
{
- /* index in ressources array */
- int index;
- /* depending ATSi parameter to calculcate limits */
- int atis_index;
- /* lower bound */
- double c;
+ /* index in ressources array */
+ int index;
+ /* depending ATSi parameter to calculcate limits */
+ int atis_index;
+ /* lower bound */
+ double c;
};
struct ATS_quality_metric
{
- int index;
- int atis_index;
- char * name;
+ int index;
+ int atis_index;
+ char *name;
};
struct ATS_quality_entry
{
- int index;
- int atsi_index;
- uint32_t values[3];
- int current;
+ int index;
+ int atsi_index;
+ uint32_t values[3];
+ int current;
};
/*
@@ -420,12 +418,11 @@
*/
-static struct ATS_ressource ressources[] =
-{
- /* FIXME: the coefficients for the specific plugins */
- {1, 7, "LAN_BW_LIMIT", 0, VERY_BIG_DOUBLE_VALUE, 0, 1, 1, 2, 2, 1, 3},
- {2, 7, "WAN_BW_LIMIT", 0, VERY_BIG_DOUBLE_VALUE, 0, 1, 1, 2, 2, 2, 3},
- {3, 4, "WLAN_ENERGY_LIMIT", 0, VERY_BIG_DOUBLE_VALUE, 0, 0, 0, 0, 0, 2, 1}
+static struct ATS_ressource ressources[] = {
+ /* FIXME: the coefficients for the specific plugins */
+ {1, 7, "LAN_BW_LIMIT", 0, VERY_BIG_DOUBLE_VALUE, 0, 1, 1, 2, 2, 1, 3},
+ {2, 7, "WAN_BW_LIMIT", 0, VERY_BIG_DOUBLE_VALUE, 0, 1, 1, 2, 2, 2, 3},
+ {3, 4, "WLAN_ENERGY_LIMIT", 0, VERY_BIG_DOUBLE_VALUE, 0, 0, 0, 0, 0, 2, 1}
/*
{4, 4, "COST_ENERGY_CONSUMPTION", VERY_BIG_DOUBLE_VALUE},
{5, 5, "COST_CONNECT", VERY_BIG_DOUBLE_VALUE},
@@ -439,8 +436,7 @@
* ATS quality metrics
*/
-static struct ATS_quality_metric qm[] =
-{
+static struct ATS_quality_metric qm[] = {
{1, 1028, "QUALITY_NET_DISTANCE"},
{2, 1034, "QUALITY_NET_DELAY"},
};
@@ -451,61 +447,50 @@
/*
* ATS functions
*/
-struct ATS_Handle *
-ats_init (double D,
- double U,
- double R,
- int v_b_min,
- int v_n_min,
- int max_iterations,
- struct GNUNET_TIME_Relative max_duration,
- GNUNET_TRANSPORT_ATS_AddressNotification address_not,
- GNUNET_TRANSPORT_ATS_ResultCallback res_cb);
+struct ATS_Handle *ats_init (double D,
+ double U,
+ double R,
+ int v_b_min,
+ int v_n_min,
+ int max_iterations,
+ struct GNUNET_TIME_Relative max_duration,
+ GNUNET_TRANSPORT_ATS_AddressNotification
+ address_not,
+ GNUNET_TRANSPORT_ATS_ResultCallback res_cb);
-void
-ats_shutdown (struct ATS_Handle * ats);
+void ats_shutdown (struct ATS_Handle *ats);
-void
-ats_delete_problem (struct ATS_Handle * ats);
+void ats_delete_problem (struct ATS_Handle *ats);
int
ats_create_problem (struct ATS_Handle *ats,
struct ATS_internals *stat,
struct ATS_peer *peers,
- int c_p,
- struct ATS_mechanism *mechanisms,
- int c_m);
+ int c_p, struct ATS_mechanism *mechanisms, int c_m);
-void ats_modify_problem_state (struct ATS_Handle * ats,
- enum ATS_problem_state s);
+void ats_modify_problem_state (struct ATS_Handle *ats,
+ enum ATS_problem_state s);
-void
-ats_calculate_bandwidth_distribution (struct ATS_Handle * ats);
+void ats_calculate_bandwidth_distribution (struct ATS_Handle *ats);
void
-ats_solve_problem (struct ATS_Handle * ats,
- unsigned int max_it,
- unsigned int max_dur,
- unsigned int c_peers,
- unsigned int c_mechs,
- struct ATS_internals *stat);
+ats_solve_problem (struct ATS_Handle *ats,
+ unsigned int max_it,
+ unsigned int max_dur,
+ unsigned int c_peers,
+ unsigned int c_mechs, struct ATS_internals *stat);
-int
-ats_evaluate_results (int result,
- int solution,
- char * problem);
+int ats_evaluate_results (int result, int solution, char *problem);
-void
-ats_update_problem_qm (struct ATS_Handle * ats);
+void ats_update_problem_qm (struct ATS_Handle *ats);
-void
-ats_update_problem_cr (struct ATS_Handle * ats);
+void ats_update_problem_cr (struct ATS_Handle *ats);
void
-ats_set_logging_options (struct ATS_Handle * ats,
- struct GNUNET_STATISTICS_Handle *stats,
- const struct GNUNET_CONFIGURATION_Handle *cfg);
+ats_set_logging_options (struct ATS_Handle *ats,
+ struct GNUNET_STATISTICS_Handle *stats,
+ const struct GNUNET_CONFIGURATION_Handle *cfg);
#endif
/* end of file gnunet-service-transport_ats.h */
Modified: gnunet/src/transport/gnunet-service-transport_blacklist.c
===================================================================
--- gnunet/src/transport/gnunet-service-transport_blacklist.c 2011-08-15
21:40:08 UTC (rev 16580)
+++ gnunet/src/transport/gnunet-service-transport_blacklist.c 2011-08-15
21:46:35 UTC (rev 16581)
@@ -162,8 +162,7 @@
* @param tc unused
*/
static void
-do_blacklist_check (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+do_blacklist_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
/**
@@ -174,8 +173,7 @@
* @param client identification of the client
*/
static void
-client_disconnect_notification (void *cls,
- struct GNUNET_SERVER_Client *client)
+client_disconnect_notification (void *cls, struct GNUNET_SERVER_Client *client)
{
struct Blacklisters *bl;
struct GST_BlacklistCheck *bc;
@@ -183,31 +181,28 @@
if (client == NULL)
return;
for (bl = bl_head; bl != NULL; bl = bl->next)
+ {
+ if (bl->client != client)
+ continue;
+ for (bc = bc_head; bc != NULL; bc = bc->next)
{
- if (bl->client != client)
- continue;
- for (bc = bc_head; bc != NULL; bc = bc->next)
- {
- if (bc->bl_pos != bl)
- continue;
- bc->bl_pos = bl->next;
- if (bc->th != NULL)
- {
- GNUNET_CONNECTION_notify_transmit_ready_cancel (bc->th);
- bc->th = NULL;
- }
- if (bc->task == GNUNET_SCHEDULER_NO_TASK)
- bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check,
- bc);
- break;
- }
- GNUNET_CONTAINER_DLL_remove (bl_head,
- bl_tail,
- bl);
- GNUNET_SERVER_client_drop (bl->client);
- GNUNET_free (bl);
+ if (bc->bl_pos != bl)
+ continue;
+ bc->bl_pos = bl->next;
+ if (bc->th != NULL)
+ {
+ GNUNET_CONNECTION_notify_transmit_ready_cancel (bc->th);
+ bc->th = NULL;
+ }
+ if (bc->task == GNUNET_SCHEDULER_NO_TASK)
+ bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc);
break;
}
+ GNUNET_CONTAINER_DLL_remove (bl_head, bl_tail, bl);
+ GNUNET_SERVER_client_drop (bl->client);
+ GNUNET_free (bl);
+ break;
+ }
}
@@ -234,153 +229,152 @@
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_filename (GST_cfg,
"TRANSPORT",
- "BLACKLIST_FILE",
- &fn))
- {
+ "BLACKLIST_FILE", &fn))
+ {
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Option `%s' in section `%s' not specified!\n",
- "BLACKLIST_FILE",
- "TRANSPORT");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Option `%s' in section `%s' not specified!\n",
+ "BLACKLIST_FILE", "TRANSPORT");
#endif
- return;
- }
+ return;
+ }
if (GNUNET_OK != GNUNET_DISK_file_test (fn))
- GNUNET_DISK_fn_write (fn, NULL, 0,
- GNUNET_DISK_PERM_USER_READ |
GNUNET_DISK_PERM_USER_WRITE);
+ GNUNET_DISK_fn_write (fn, NULL, 0,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE);
if (0 != STAT (fn, &frstat))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Could not read blacklist file `%s'\n"),
- fn);
- GNUNET_free (fn);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Could not read blacklist file `%s'\n"), fn);
+ GNUNET_free (fn);
+ return;
+ }
if (frstat.st_size == 0)
- {
+ {
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Blacklist file `%s' is empty.\n"),
- fn);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ _("Blacklist file `%s' is empty.\n"), fn);
#endif
- GNUNET_free (fn);
- return;
- }
+ GNUNET_free (fn);
+ return;
+ }
/* FIXME: use mmap */
data = GNUNET_malloc_large (frstat.st_size);
- GNUNET_assert(data != NULL);
- if (frstat.st_size !=
- GNUNET_DISK_fn_read (fn, data, frstat.st_size))
+ GNUNET_assert (data != NULL);
+ if (frstat.st_size != GNUNET_DISK_fn_read (fn, data, frstat.st_size))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to read blacklist from `%s'\n"), fn);
+ GNUNET_free (fn);
+ GNUNET_free (data);
+ return;
+ }
+ entries_found = 0;
+ pos = 0;
+ while ((pos < frstat.st_size) && isspace ((unsigned char) data[pos]))
+ pos++;
+ while ((frstat.st_size >= sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)) &&
+ (pos <=
+ frstat.st_size - sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)))
+ {
+ colon_pos = pos;
+ while ((colon_pos < frstat.st_size) &&
+ (data[colon_pos] != ':') &&
+ (!isspace ((unsigned char) data[colon_pos])))
+ colon_pos++;
+ if (colon_pos >= frstat.st_size)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to read blacklist from `%s'\n"),
- fn);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Syntax error in blacklist file at offset %llu, giving
up!\n"),
+ (unsigned long long) colon_pos);
GNUNET_free (fn);
GNUNET_free (data);
return;
}
- entries_found = 0;
- pos = 0;
- while ((pos < frstat.st_size) && isspace ( (unsigned char) data[pos]))
- pos++;
- while ((frstat.st_size >= sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)) &&
- (pos <= frstat.st_size - sizeof (struct
GNUNET_CRYPTO_HashAsciiEncoded)))
+
+ if (isspace ((unsigned char) data[colon_pos]))
{
- colon_pos = pos;
- while ( (colon_pos < frstat.st_size) &&
- (data[colon_pos] != ':') &&
- (! isspace ( (unsigned char) data[colon_pos])) )
- colon_pos++;
- if (colon_pos >= frstat.st_size)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Syntax error in blacklist file at offset %llu, giving
up!\n"),
- (unsigned long long) colon_pos);
- GNUNET_free (fn);
- GNUNET_free (data);
- return;
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Syntax error in blacklist file at offset %llu, skipping
bytes.\n"),
+ (unsigned long long) colon_pos);
+ pos = colon_pos;
+ while ((pos < frstat.st_size) && isspace ((unsigned char) data[pos]))
+ pos++;
+ continue;
+ }
+ tsize = colon_pos - pos;
+ if ((pos >= frstat.st_size) || (pos + tsize >= frstat.st_size) ||
+ (tsize == 0))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Syntax error in blacklist file at offset %llu, giving
up!\n"),
+ (unsigned long long) colon_pos);
+ GNUNET_free (fn);
+ GNUNET_free (data);
+ return;
+ }
- if (isspace( (unsigned char) data[colon_pos]))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Syntax error in blacklist file at offset %llu, skipping
bytes.\n"),
- (unsigned long long) colon_pos);
- pos = colon_pos;
- while ((pos < frstat.st_size) && isspace ( (unsigned char) data[pos]))
- pos++;
- continue;
- }
- tsize = colon_pos - pos;
- if ((pos >= frstat.st_size) || (pos + tsize >= frstat.st_size) || (tsize
== 0))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Syntax error in blacklist file at offset %llu, giving
up!\n"),
- (unsigned long long) colon_pos);
- GNUNET_free (fn);
- GNUNET_free (data);
- return;
- }
+ if (tsize < 1)
+ continue;
- if (tsize < 1)
- continue;
-
- transport_name = GNUNET_malloc(tsize + 1);
- memcpy(transport_name, &data[pos], tsize);
- pos = colon_pos + 1;
+ transport_name = GNUNET_malloc (tsize + 1);
+ memcpy (transport_name, &data[pos], tsize);
+ pos = colon_pos + 1;
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Read transport name `%s' in blacklist file.\n",
- transport_name);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Read transport name `%s' in blacklist file.\n",
+ transport_name);
#endif
- memcpy (&enc,
- &data[pos],
- sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded));
- if (! isspace ( (unsigned char) enc.encoding[sizeof (struct
GNUNET_CRYPTO_HashAsciiEncoded) - 1]))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Syntax error in blacklist file at offset %llu,
skipping bytes.\n"),
- (unsigned long long) pos);
- pos++;
- while ((pos < frstat.st_size) && (!isspace ( (unsigned char)
data[pos])))
- pos++;
- GNUNET_free_non_null(transport_name);
- continue;
- }
- enc.encoding[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0';
- if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string ((char *) &enc,
&pid.hashPubKey))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Syntax error in blacklist file at offset %llu,
skipping bytes `%s'.\n"),
- (unsigned long long) pos,
- &enc);
- }
- else
- {
- if (0 != memcmp (&pid,
- &GST_my_identity,
- sizeof (struct GNUNET_PeerIdentity)))
- {
- entries_found++;
- GST_blacklist_add_peer (&pid,
- transport_name);
- }
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Found myself `%s' in blacklist (useless,
ignored)\n"),
- GNUNET_i2s (&pid));
- }
- }
- pos = pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded);
- GNUNET_free_non_null(transport_name);
- while ((pos < frstat.st_size) && isspace ( (unsigned char) data[pos]))
+ memcpy (&enc, &data[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded));
+ if (!isspace
+ ((unsigned char)
+ enc.encoding[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1]))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Syntax error in blacklist file at offset %llu, skipping
bytes.\n"),
+ (unsigned long long) pos);
+ pos++;
+ while ((pos < frstat.st_size) && (!isspace ((unsigned char) data[pos])))
pos++;
+ GNUNET_free_non_null (transport_name);
+ continue;
}
- GNUNET_STATISTICS_update (GST_stats,
- "# Transport entries blacklisted",
- entries_found,
- GNUNET_NO);
+ enc.encoding[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0';
+ if (GNUNET_OK !=
+ GNUNET_CRYPTO_hash_from_string ((char *) &enc, &pid.hashPubKey))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Syntax error in blacklist file at offset %llu, skipping
bytes `%s'.\n"),
+ (unsigned long long) pos, &enc);
+ }
+ else
+ {
+ if (0 != memcmp (&pid,
+ &GST_my_identity, sizeof (struct GNUNET_PeerIdentity)))
+ {
+ entries_found++;
+ GST_blacklist_add_peer (&pid, transport_name);
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Found myself `%s' in blacklist (useless, ignored)\n"),
+ GNUNET_i2s (&pid));
+ }
+ }
+ pos = pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded);
+ GNUNET_free_non_null (transport_name);
+ while ((pos < frstat.st_size) && isspace ((unsigned char) data[pos]))
+ pos++;
+ }
+ GNUNET_STATISTICS_update (GST_stats,
+ "# Transport entries blacklisted",
+ entries_found, GNUNET_NO);
GNUNET_free (data);
GNUNET_free (fn);
}
@@ -396,8 +390,7 @@
{
read_blacklist_file ();
GNUNET_SERVER_disconnect_notify (server,
- &client_disconnect_notification,
- NULL);
+ &client_disconnect_notification, NULL);
}
@@ -410,9 +403,7 @@
* @return GNUNET_OK (continue to iterate)
*/
static int
-free_blacklist_entry (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+free_blacklist_entry (void *cls, const GNUNET_HashCode * key, void *value)
{
char *be = value;
@@ -428,13 +419,12 @@
GST_blacklist_stop ()
{
if (NULL != blacklist)
- {
- GNUNET_CONTAINER_multihashmap_iterate (blacklist,
- &free_blacklist_entry,
- NULL);
- GNUNET_CONTAINER_multihashmap_destroy (blacklist);
- blacklist = NULL;
- }
+ {
+ GNUNET_CONTAINER_multihashmap_iterate (blacklist,
+ &free_blacklist_entry, NULL);
+ GNUNET_CONTAINER_multihashmap_destroy (blacklist);
+ blacklist = NULL;
+ }
}
@@ -447,9 +437,7 @@
* @return number of bytes copied to buf
*/
static size_t
-transmit_blacklist_message (void *cls,
- size_t size,
- void *buf)
+transmit_blacklist_message (void *cls, size_t size, void *buf)
{
struct GST_BlacklistCheck *bc = cls;
struct Blacklisters *bl;
@@ -457,19 +445,18 @@
bc->th = NULL;
if (size == 0)
- {
- GNUNET_assert (bc->task == GNUNET_SCHEDULER_NO_TASK);
- bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check,
- bc);
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Failed to send blacklist test for peer `%s' to client\n",
- GNUNET_i2s (&bc->peer));
- return 0;
- }
+ {
+ GNUNET_assert (bc->task == GNUNET_SCHEDULER_NO_TASK);
+ bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to send blacklist test for peer `%s' to client\n",
+ GNUNET_i2s (&bc->peer));
+ return 0;
+ }
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending blacklist test for peer `%s' to client\n",
- GNUNET_i2s (&bc->peer));
+ "Sending blacklist test for peer `%s' to client\n",
+ GNUNET_i2s (&bc->peer));
#endif
bl = bc->bl_pos;
bm.header.size = htons (sizeof (struct BlacklistMessage));
@@ -490,8 +477,7 @@
* @param tc unused
*/
static void
-do_blacklist_check (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_blacklist_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GST_BlacklistCheck *bc = cls;
struct Blacklisters *bl;
@@ -499,27 +485,25 @@
bc->task = GNUNET_SCHEDULER_NO_TASK;
bl = bc->bl_pos;
if (bl == NULL)
- {
+ {
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "No other blacklist clients active, will allow neighbour
`%s'\n",
- GNUNET_i2s (&bc->peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "No other blacklist clients active, will allow neighbour
`%s'\n",
+ GNUNET_i2s (&bc->peer));
#endif
- bc->cont (bc->cont_cls,
- &bc->peer,
- GNUNET_OK);
- GNUNET_free (bc);
- return;
- }
- if ( (bl->bc != NULL) ||
- (bl->waiting_for_reply != GNUNET_NO) )
- return; /* someone else busy with this client */
+ bc->cont (bc->cont_cls, &bc->peer, GNUNET_OK);
+ GNUNET_free (bc);
+ return;
+ }
+ if ((bl->bc != NULL) || (bl->waiting_for_reply != GNUNET_NO))
+ return; /* someone else busy with this client */
bl->bc = bc;
bc->th = GNUNET_SERVER_notify_transmit_ready (bl->client,
- sizeof (struct
BlacklistMessage),
- GNUNET_TIME_UNIT_FOREVER_REL,
- &transmit_blacklist_message,
- bc);
+ sizeof (struct
+ BlacklistMessage),
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &transmit_blacklist_message,
+ bc);
}
@@ -534,15 +518,13 @@
*/
static void
confirm_or_drop_neighbour (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- int allowed)
+ const struct GNUNET_PeerIdentity *peer, int allowed)
{
if (GNUNET_OK == allowed)
- return; /* we're done */
+ return; /* we're done */
GNUNET_STATISTICS_update (GST_stats,
- gettext_noop ("# disconnects due to blacklist"),
- 1,
- GNUNET_NO);
+ gettext_noop ("# disconnects due to blacklist"),
+ 1, GNUNET_NO);
GST_neighbours_force_disconnect (peer);
}
@@ -554,7 +536,7 @@
{
/**
* Is this the first neighbour we're checking?
- */
+ */
int first;
/**
@@ -575,9 +557,9 @@
*/
static void
test_connection_ok (void *cls,
- const struct GNUNET_PeerIdentity *neighbour,
- const struct GNUNET_TRANSPORT_ATS_Information *ats,
- uint32_t ats_count)
+ const struct GNUNET_PeerIdentity *neighbour,
+ const struct GNUNET_TRANSPORT_ATS_Information *ats,
+ uint32_t ats_count)
{
struct TestConnectionContext *tcc = cls;
struct GST_BlacklistCheck *bc;
@@ -589,13 +571,12 @@
bc->cont_cls = NULL;
bc->bl_pos = tcc->bl;
if (GNUNET_YES == tcc->first)
- {
- /* all would wait for the same client, no need to
- create more than just the first task right now */
- bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check,
- bc);
- tcc->first = GNUNET_NO;
- }
+ {
+ /* all would wait for the same client, no need to
+ * create more than just the first task right now */
+ bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc);
+ tcc->first = GNUNET_NO;
+ }
}
@@ -611,23 +592,23 @@
*/
void
GST_blacklist_handle_init (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
struct Blacklisters *bl;
struct TestConnectionContext tcc;
bl = bl_head;
while (bl != NULL)
+ {
+ if (bl->client == client)
{
- if (bl->client == client)
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
- bl = bl->next;
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
}
+ bl = bl->next;
+ }
bl = GNUNET_malloc (sizeof (struct Blacklisters));
bl->client = client;
GNUNET_SERVER_client_keep (client);
@@ -636,8 +617,7 @@
/* confirm that all existing connections are OK! */
tcc.bl = bl;
tcc.first = GNUNET_YES;
- GST_neighbours_iterate (&test_connection_ok,
- &tcc);
+ GST_neighbours_iterate (&test_connection_ok, &tcc);
}
@@ -650,65 +630,61 @@
*/
void
GST_blacklist_handle_reply (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
- const struct BlacklistMessage *msg = (const struct BlacklistMessage*)
message;
+ const struct BlacklistMessage *msg =
+ (const struct BlacklistMessage *) message;
struct Blacklisters *bl;
struct GST_BlacklistCheck *bc;
bl = bl_head;
- while ( (bl != NULL) &&
- (bl->client != client) )
+ while ((bl != NULL) && (bl->client != client))
bl = bl->next;
if (bl == NULL)
- {
+ {
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Blacklist client disconnected\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Blacklist client disconnected\n");
#endif
- /* FIXME: other error handling here!? */
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ /* FIXME: other error handling here!? */
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
bc = bl->bc;
bl->bc = NULL;
bl->waiting_for_reply = GNUNET_NO;
if (NULL != bc)
+ {
+ /* only run this if the blacklist check has not been
+ * cancelled in the meantime... */
+ if (ntohl (msg->is_allowed) == GNUNET_SYSERR)
{
- /* only run this if the blacklist check has not been
- cancelled in the meantime... */
- if (ntohl (msg->is_allowed) == GNUNET_SYSERR)
- {
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Blacklist check failed, peer not allowed\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Blacklist check failed, peer not allowed\n");
#endif
- bc->cont (bc->cont_cls, &bc->peer, GNUNET_NO);
- GNUNET_CONTAINER_DLL_remove (bc_head, bc_tail, bc);
- GNUNET_free (bc);
- }
- else
- {
+ bc->cont (bc->cont_cls, &bc->peer, GNUNET_NO);
+ GNUNET_CONTAINER_DLL_remove (bc_head, bc_tail, bc);
+ GNUNET_free (bc);
+ }
+ else
+ {
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Blacklist check succeeded, continuing with checks\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Blacklist check succeeded, continuing with checks\n");
#endif
- bc->bl_pos = bc->bl_pos->next;
- bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check,
- bc);
- }
+ bc->bl_pos = bc->bl_pos->next;
+ bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc);
}
+ }
/* check if any other bc's are waiting for this blacklister */
bc = bc_head;
for (bc = bc_head; bc != NULL; bc = bc->next)
- if ( (bc->bl_pos == bl) &&
- (GNUNET_SCHEDULER_NO_TASK == bc->task) )
- {
- bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check,
- bc);
- break;
- }
+ if ((bc->bl_pos == bl) && (GNUNET_SCHEDULER_NO_TASK == bc->task))
+ {
+ bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc);
+ break;
+ }
}
@@ -720,20 +696,19 @@
*/
void
GST_blacklist_add_peer (const struct GNUNET_PeerIdentity *peer,
- const char *transport_name)
+ const char *transport_name)
{
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Adding peer `%s' with plugin `%s' to blacklist\n",
- GNUNET_i2s (peer),
- transport_name);
+ "Adding peer `%s' with plugin `%s' to blacklist\n",
+ GNUNET_i2s (peer), transport_name);
#endif
if (blacklist == NULL)
- blacklist =
GNUNET_CONTAINER_multihashmap_create(TRANSPORT_BLACKLIST_HT_SIZE);
- GNUNET_CONTAINER_multihashmap_put (blacklist,
- &peer->hashPubKey,
- GNUNET_strdup (transport_name),
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
+ blacklist =
+ GNUNET_CONTAINER_multihashmap_create (TRANSPORT_BLACKLIST_HT_SIZE);
+ GNUNET_CONTAINER_multihashmap_put (blacklist, &peer->hashPubKey,
+ GNUNET_strdup (transport_name),
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
}
@@ -747,16 +722,13 @@
* @return GNUNET_OK if the entry does not match, GNUNET_NO if it matches
*/
static int
-test_blacklisted (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+test_blacklisted (void *cls, const GNUNET_HashCode * key, void *value)
{
const char *transport_name = cls;
char *be = value;
- if (0 == strcmp (transport_name,
- be))
- return GNUNET_NO; /* abort iteration! */
+ if (0 == strcmp (transport_name, be))
+ return GNUNET_NO; /* abort iteration! */
return GNUNET_OK;
}
@@ -773,36 +745,34 @@
*/
struct GST_BlacklistCheck *
GST_blacklist_test_allowed (const struct GNUNET_PeerIdentity *peer,
- const char *transport_name,
- GST_BlacklistTestContinuation cont,
- void *cont_cls)
+ const char *transport_name,
+ GST_BlacklistTestContinuation cont, void *cont_cls)
{
struct GST_BlacklistCheck *bc;
-
- if ( (blacklist != NULL) &&
- (GNUNET_SYSERR ==
- GNUNET_CONTAINER_multihashmap_get_multiple (blacklist,
- &peer->hashPubKey,
- &test_blacklisted,
- (void*) transport_name)) )
- {
- /* disallowed by config, disapprove instantly */
- GNUNET_STATISTICS_update (GST_stats,
- gettext_noop ("# disconnects due to
blacklist"),
- 1,
- GNUNET_NO);
- if (cont != NULL)
- cont (cont_cls, peer, GNUNET_NO);
- return NULL;
- }
+ if ((blacklist != NULL) &&
+ (GNUNET_SYSERR ==
+ GNUNET_CONTAINER_multihashmap_get_multiple (blacklist,
+ &peer->hashPubKey,
+ &test_blacklisted,
+ (void *) transport_name)))
+ {
+ /* disallowed by config, disapprove instantly */
+ GNUNET_STATISTICS_update (GST_stats,
+ gettext_noop ("# disconnects due to blacklist"),
+ 1, GNUNET_NO);
+ if (cont != NULL)
+ cont (cont_cls, peer, GNUNET_NO);
+ return NULL;
+ }
+
if (bl_head == NULL)
- {
- /* no blacklist clients, approve instantly */
- if (cont != NULL)
- cont (cont_cls, peer, GNUNET_OK);
- return NULL;
- }
+ {
+ /* no blacklist clients, approve instantly */
+ if (cont != NULL)
+ cont (cont_cls, peer, GNUNET_OK);
+ return NULL;
+ }
/* need to query blacklist clients */
bc = GNUNET_malloc (sizeof (struct GST_BlacklistCheck));
@@ -811,12 +781,11 @@
bc->cont = cont;
bc->cont_cls = cont_cls;
bc->bl_pos = bl_head;
- bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check,
- bc);
+ bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc);
return bc;
}
-
+
/**
* Cancel a blacklist check.
*
@@ -827,25 +796,25 @@
{
GNUNET_CONTAINER_DLL_remove (bc_head, bc_tail, bc);
if (bc->bl_pos != NULL)
+ {
+ if (bc->bl_pos->bc == bc)
{
- if (bc->bl_pos->bc == bc)
- {
- /* we're at the head of the queue, remove us! */
- bc->bl_pos->bc = NULL;
- }
+ /* we're at the head of the queue, remove us! */
+ bc->bl_pos->bc = NULL;
}
+ }
if (GNUNET_SCHEDULER_NO_TASK != bc->task)
- {
- GNUNET_SCHEDULER_cancel (bc->task);
- bc->task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (bc->task);
+ bc->task = GNUNET_SCHEDULER_NO_TASK;
+ }
if (NULL != bc->th)
- {
- GNUNET_CONNECTION_notify_transmit_ready_cancel (bc->th);
- bc->th = NULL;
- }
+ {
+ GNUNET_CONNECTION_notify_transmit_ready_cancel (bc->th);
+ bc->th = NULL;
+ }
GNUNET_free (bc);
-}
+}
/* end of file gnunet-service-transport_blacklist.c */
Modified: gnunet/src/transport/gnunet-service-transport_blacklist.h
===================================================================
--- gnunet/src/transport/gnunet-service-transport_blacklist.h 2011-08-15
21:40:08 UTC (rev 16580)
+++ gnunet/src/transport/gnunet-service-transport_blacklist.h 2011-08-15
21:46:35 UTC (rev 16581)
@@ -34,15 +34,13 @@
*
* @param server server used to accept clients from
*/
-void
-GST_blacklist_start (struct GNUNET_SERVER_Handle *server);
+void GST_blacklist_start (struct GNUNET_SERVER_Handle *server);
/**
* Stop blacklist subsystem.
*/
-void
-GST_blacklist_stop (void);
+void GST_blacklist_stop (void);
/**
@@ -56,8 +54,8 @@
*/
void
GST_blacklist_handle_init (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message);
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message);
/**
* A blacklisting client has sent us reply. Process it.
@@ -68,8 +66,8 @@
*/
void
GST_blacklist_handle_reply (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message);
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message);
/**
* Add the given peer to the blacklist (for the given transport).
@@ -79,15 +77,15 @@
*/
void
GST_blacklist_add_peer (const struct GNUNET_PeerIdentity *peer,
- const char *transport_name);
+ const char *transport_name);
/**
* Handle to an active blacklist check.
*/
-struct GST_BlacklistCheck;
-
+struct GST_BlacklistCheck;
+
/**
* Continuation called from a blacklist test.
*
@@ -96,9 +94,9 @@
* @param result GNUNET_OK if the connection is allowed,
* GNUNET_NO if not
*/
-typedef void (*GST_BlacklistTestContinuation)(void *cls,
- const struct GNUNET_PeerIdentity
*peer,
- int result);
+typedef void (*GST_BlacklistTestContinuation) (void *cls,
+ const struct GNUNET_PeerIdentity
+ * peer, int result);
/**
@@ -111,20 +109,21 @@
* @return handle to the blacklist check, NULL if the decision
* was made instantly and 'cont' was already called
*/
-struct GST_BlacklistCheck *
-GST_blacklist_test_allowed (const struct GNUNET_PeerIdentity *peer,
- const char *transport_name,
- GST_BlacklistTestContinuation cont,
- void *cont_cls);
-
+struct GST_BlacklistCheck *GST_blacklist_test_allowed (const struct
+ GNUNET_PeerIdentity
+ *peer,
+ const char
+ *transport_name,
+
GST_BlacklistTestContinuation
+ cont, void *cont_cls);
+
/**
* Cancel a blacklist check.
*
* @param bc check to cancel
*/
-void
-GST_blacklist_test_cancel (struct GST_BlacklistCheck *bc);
+void GST_blacklist_test_cancel (struct GST_BlacklistCheck *bc);
#endif
/* end of file gnunet-service-transport_blacklist.h */
Modified: gnunet/src/transport/gnunet-service-transport_clients.c
===================================================================
--- gnunet/src/transport/gnunet-service-transport_clients.c 2011-08-15
21:40:08 UTC (rev 16580)
+++ gnunet/src/transport/gnunet-service-transport_clients.c 2011-08-15
21:46:35 UTC (rev 16581)
@@ -134,13 +134,13 @@
{
struct TransportClient *tc;
- tc = clients_head;
+ tc = clients_head;
while (tc != NULL)
- {
- if (tc->client == client)
- return tc;
- tc = tc->next;
- }
+ {
+ if (tc->client == client)
+ return tc;
+ tc = tc->next;
+ }
return NULL;
}
@@ -155,12 +155,10 @@
setup_client (struct GNUNET_SERVER_Client *client)
{
struct TransportClient *tc;
-
+
tc = GNUNET_malloc (sizeof (struct TransportClient));
tc->client = client;
- GNUNET_CONTAINER_DLL_insert (clients_head,
- clients_tail,
- tc);
+ GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, tc);
return tc;
}
@@ -176,9 +174,7 @@
* @return number of bytes written to buf
*/
static size_t
-transmit_to_client_callback (void *cls,
- size_t size,
- void *buf)
+transmit_to_client_callback (void *cls, size_t size, void *buf)
{
struct TransportClient *tc = cls;
struct ClientMessageQueueEntry *q;
@@ -189,46 +185,43 @@
tc->th = NULL;
if (buf == NULL)
- {
-#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmission to client failed, closing connection.\n");
+ {
+#if DEBUG_TRANSPORT
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Transmission to client failed, closing connection.\n");
#endif
- return 0;
- }
+ return 0;
+ }
cbuf = buf;
tsize = 0;
while (NULL != (q = tc->message_queue_head))
- {
- msg = (const struct GNUNET_MessageHeader *) &q[1];
- msize = ntohs (msg->size);
- if (msize + tsize > size)
- break;
+ {
+ msg = (const struct GNUNET_MessageHeader *) &q[1];
+ msize = ntohs (msg->size);
+ if (msize + tsize > size)
+ break;
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitting message of type %u to client.\n",
- ntohs (msg->type));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Transmitting message of type %u to client.\n",
+ ntohs (msg->type));
#endif
- GNUNET_CONTAINER_DLL_remove (tc->message_queue_head,
- tc->message_queue_tail,
- q);
- tc->message_count--;
- memcpy (&cbuf[tsize],
- msg,
- msize);
- GNUNET_free (q);
- tsize += msize;
- }
+ GNUNET_CONTAINER_DLL_remove (tc->message_queue_head,
+ tc->message_queue_tail, q);
+ tc->message_count--;
+ memcpy (&cbuf[tsize], msg, msize);
+ GNUNET_free (q);
+ tsize += msize;
+ }
if (NULL != q)
- {
- GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader));
- tc->th = GNUNET_SERVER_notify_transmit_ready (tc->client,
- msize,
-
GNUNET_TIME_UNIT_FOREVER_REL,
-
&transmit_to_client_callback,
- tc);
- GNUNET_assert (tc->th != NULL);
- }
+ {
+ GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader));
+ tc->th = GNUNET_SERVER_notify_transmit_ready (tc->client,
+ msize,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &transmit_to_client_callback,
+ tc);
+ GNUNET_assert (tc->th != NULL);
+ }
return tsize;
}
@@ -242,43 +235,39 @@
*/
static void
unicast (struct TransportClient *tc,
- const struct GNUNET_MessageHeader *msg,
- int may_drop)
+ const struct GNUNET_MessageHeader *msg, int may_drop)
{
struct ClientMessageQueueEntry *q;
uint16_t msize;
- if ( (tc->message_count >= MAX_PENDING) &&
- (GNUNET_YES == may_drop) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Dropping message of type %u and size %u, have %u/%u
messages pending\n"),
- ntohs (msg->type),
- ntohs (msg->size),
- tc->message_count,
- MAX_PENDING);
- GNUNET_STATISTICS_update (GST_stats,
- gettext_noop ("# messages dropped due to slow
client"),
- 1,
- GNUNET_NO);
- return;
- }
+ if ((tc->message_count >= MAX_PENDING) && (GNUNET_YES == may_drop))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _
+ ("Dropping message of type %u and size %u, have %u/%u messages
pending\n"),
+ ntohs (msg->type), ntohs (msg->size), tc->message_count,
+ MAX_PENDING);
+ GNUNET_STATISTICS_update (GST_stats,
+ gettext_noop
+ ("# messages dropped due to slow client"), 1,
+ GNUNET_NO);
+ return;
+ }
msize = ntohs (msg->size);
GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader));
q = GNUNET_malloc (sizeof (struct ClientMessageQueueEntry) + msize);
memcpy (&q[1], msg, msize);
GNUNET_CONTAINER_DLL_insert_tail (tc->message_queue_head,
- tc->message_queue_tail,
- q);
+ tc->message_queue_tail, q);
tc->message_count++;
if (tc->th != NULL)
return;
tc->th = GNUNET_SERVER_notify_transmit_ready (tc->client,
- msize,
- GNUNET_TIME_UNIT_FOREVER_REL,
- &transmit_to_client_callback,
- tc);
- GNUNET_assert (tc->th != NULL);
+ msize,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &transmit_to_client_callback,
+ tc);
+ GNUNET_assert (tc->th != NULL);
}
@@ -290,8 +279,7 @@
* @param client identification of the client
*/
static void
-client_disconnect_notification (void *cls,
- struct GNUNET_SERVER_Client *client)
+client_disconnect_notification (void *cls, struct GNUNET_SERVER_Client *client)
{
struct TransportClient *tc;
struct ClientMessageQueueEntry *mqe;
@@ -306,21 +294,18 @@
"Client disconnected, cleaning up.\n");
#endif
while (NULL != (mqe = tc->message_queue_head))
- {
- GNUNET_CONTAINER_DLL_remove (tc->message_queue_head,
- tc->message_queue_tail,
- mqe);
- tc->message_count--;
- GNUNET_free (mqe);
- }
- GNUNET_CONTAINER_DLL_remove (clients_head,
- clients_tail,
- tc);
+ {
+ GNUNET_CONTAINER_DLL_remove (tc->message_queue_head,
+ tc->message_queue_tail, mqe);
+ tc->message_count--;
+ GNUNET_free (mqe);
+ }
+ GNUNET_CONTAINER_DLL_remove (clients_head, clients_tail, tc);
if (tc->th != NULL)
- {
- GNUNET_CONNECTION_notify_transmit_ready_cancel (tc->th);
- tc->th = NULL;
- }
+ {
+ GNUNET_CONNECTION_notify_transmit_ready_cancel (tc->th);
+ tc->th = NULL;
+ }
GNUNET_break (0 == tc->message_count);
GNUNET_free (tc);
}
@@ -337,24 +322,25 @@
*/
static void
notify_client_about_neighbour (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_TRANSPORT_ATS_Information
*ats,
- uint32_t ats_count)
+ const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_TRANSPORT_ATS_Information
+ *ats, uint32_t ats_count)
{
struct TransportClient *tc = cls;
struct ConnectInfoMessage *cim;
size_t size;
- size = sizeof (struct ConnectInfoMessage) + ats_count * sizeof (struct
GNUNET_TRANSPORT_ATS_Information);
+ size =
+ sizeof (struct ConnectInfoMessage) +
+ ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
GNUNET_assert (size < GNUNET_SERVER_MAX_MESSAGE_SIZE);
cim = GNUNET_malloc (size);
cim->header.size = htons (size);
cim->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
- cim->ats_count = htonl(ats_count);
+ cim->ats_count = htonl (ats_count);
cim->id = *peer;
memcpy (&cim->ats,
- ats,
- ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
+ ats, ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
unicast (tc, &cim->header, GNUNET_NO);
GNUNET_free (cim);
}
@@ -371,35 +357,35 @@
*/
static void
clients_handle_start (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
const struct StartMessage *start;
struct TransportClient *tc;
tc = lookup_client (client);
if (tc != NULL)
- {
- /* got 'start' twice from the same client, not allowed */
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
- start = (const struct StartMessage*) message;
- if ( (GNUNET_NO != ntohl (start->do_check)) &&
- (0 != memcmp (&start->self,
- &GST_my_identity,
- sizeof (struct GNUNET_PeerIdentity))) )
- {
- /* client thinks this is a different peer, reject */
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Rejecting control connection from peer `%s', which is not
me!\n"),
- GNUNET_i2s (&start->self));
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ {
+ /* got 'start' twice from the same client, not allowed */
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
+ start = (const struct StartMessage *) message;
+ if ((GNUNET_NO != ntohl (start->do_check)) &&
+ (0 != memcmp (&start->self,
+ &GST_my_identity, sizeof (struct GNUNET_PeerIdentity))))
+ {
+ /* client thinks this is a different peer, reject */
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _
+ ("Rejecting control connection from peer `%s', which is not
me!\n"),
+ GNUNET_i2s (&start->self));
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
tc = setup_client (client);
- unicast (tc, GST_hello_get(), GNUNET_NO);
+ unicast (tc, GST_hello_get (), GNUNET_NO);
GST_neighbours_iterate (¬ify_client_about_neighbour, tc);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
@@ -414,8 +400,8 @@
*/
static void
clients_handle_hello (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
GST_validation_handle_hello (message);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -447,8 +433,7 @@
* @param success GNUNET_OK on success, GNUNET_NO on failure, GNUNET_SYSERR if
we're not connected
*/
static void
-handle_send_transmit_continuation (void *cls,
- int success)
+handle_send_transmit_continuation (void *cls, int success)
{
struct SendTransmitContinuationContext *stcc = cls;
struct SendOkMessage send_ok_msg;
@@ -456,9 +441,10 @@
send_ok_msg.header.size = htons (sizeof (send_ok_msg));
send_ok_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK);
send_ok_msg.success = htonl (success);
- send_ok_msg.latency = GNUNET_TIME_relative_hton
(GNUNET_TIME_UNIT_FOREVER_REL);
+ send_ok_msg.latency =
+ GNUNET_TIME_relative_hton (GNUNET_TIME_UNIT_FOREVER_REL);
send_ok_msg.peer = stcc->target;
- GST_clients_unicast (stcc->client, &send_ok_msg.header, GNUNET_NO);
+ GST_clients_unicast (stcc->client, &send_ok_msg.header, GNUNET_NO);
GNUNET_SERVER_client_drop (stcc->client);
GNUNET_free (stcc);
}
@@ -473,8 +459,8 @@
*/
static void
clients_handle_send (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
const struct OutboundMessage *obm;
const struct GNUNET_MessageHeader *obmm;
@@ -483,57 +469,53 @@
uint16_t msize;
size = ntohs (message->size);
- if (size < sizeof (struct OutboundMessage) + sizeof (struct
GNUNET_MessageHeader))
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ if (size <
+ sizeof (struct OutboundMessage) + sizeof (struct GNUNET_MessageHeader))
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
obm = (const struct OutboundMessage *) message;
obmm = (const struct GNUNET_MessageHeader *) &obm[1];
msize = size - sizeof (struct OutboundMessage);
if (msize < sizeof (struct GNUNET_MessageHeader))
- {
- 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 (GST_stats,
- gettext_noop ("# bytes payload received for other
peers"),
- msize,
- GNUNET_NO);
+ gettext_noop
+ ("# bytes payload received for other peers"),
msize,
+ GNUNET_NO);
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received `%s' request from client with target `%4s' and first
message of type %u and total size %u\n",
- "SEND",
- GNUNET_i2s (&obm->peer),
- ntohs (obmm->type),
- msize);
+ "SEND", GNUNET_i2s (&obm->peer), ntohs (obmm->type), msize);
#endif
- if (GNUNET_NO ==
- GST_neighbours_test_connected (&obm->peer))
- {
- /* not connected, not allowed to send; can happen due to asynchronous
operations */
- GNUNET_STATISTICS_update (GST_stats,
- gettext_noop ("# bytes payload dropped (other
peer was not connected)"),
- msize,
- GNUNET_NO);
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
- return;
- }
+ if (GNUNET_NO == GST_neighbours_test_connected (&obm->peer))
+ {
+ /* not connected, not allowed to send; can happen due to asynchronous
operations */
+ GNUNET_STATISTICS_update (GST_stats,
+ gettext_noop
+ ("# bytes payload dropped (other peer was not
connected)"),
+ msize, GNUNET_NO);
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ return;
+ }
GNUNET_SERVER_receive_done (client, GNUNET_OK);
stcc = GNUNET_malloc (sizeof (struct SendTransmitContinuationContext));
stcc->target = obm->peer;
stcc->client = client;
GNUNET_SERVER_client_keep (client);
GST_neighbours_send (&obm->peer,
- obmm, msize,
- GNUNET_TIME_relative_ntoh (obm->timeout),
- &handle_send_transmit_continuation,
- stcc);
+ obmm, msize,
+ GNUNET_TIME_relative_ntoh (obm->timeout),
+ &handle_send_transmit_continuation, stcc);
}
-
+
/**
* Try to initiate a connection to the given peer if the blacklist
* allowed it.
@@ -545,11 +527,10 @@
*/
static void
try_connect_if_allowed (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- int result)
+ const struct GNUNET_PeerIdentity *peer, int result)
{
if (GNUNET_OK != result)
- return; /* not allowed */
+ return; /* not allowed */
GST_neighbours_try_connect (peer);
}
@@ -563,23 +544,23 @@
*/
static void
clients_handle_request_connect (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
const struct TransportRequestConnectMessage *trcm =
- (const struct TransportRequestConnectMessage *) message;
+ (const struct TransportRequestConnectMessage *) message;
GNUNET_STATISTICS_update (GST_stats,
- gettext_noop ("# REQUEST CONNECT messages
received"),
- 1,
+ gettext_noop
+ ("# REQUEST CONNECT messages received"), 1,
GNUNET_NO);
#if DEBUG_TRANSPORT
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Received a request connect message for peer `%s'\n",
- GNUNET_i2s(&trcm->peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received a request connect message for peer `%s'\n",
+ GNUNET_i2s (&trcm->peer));
#endif
(void) GST_blacklist_test_allowed (&trcm->peer, NULL,
- &try_connect_if_allowed, NULL);
+ &try_connect_if_allowed, NULL);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
@@ -593,25 +574,23 @@
*/
static void
clients_handle_set_quota (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
const struct QuotaSetMessage *qsm;
qsm = (const struct QuotaSetMessage *) message;
GNUNET_STATISTICS_update (GST_stats,
- gettext_noop ("# SET QUOTA messages received"),
- 1,
- GNUNET_NO);
-#if DEBUG_TRANSPORT
+ gettext_noop ("# SET QUOTA messages received"),
+ 1, GNUNET_NO);
+#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received `%s' request (new quota %u) from client for peer
`%4s'\n",
"SET_QUOTA",
- (unsigned int) ntohl (qsm->quota.value__),
- GNUNET_i2s (&qsm->peer));
+ (unsigned int) ntohl (qsm->quota.value__),
+ GNUNET_i2s (&qsm->peer));
#endif
- GST_neighbours_set_incoming_quota (&qsm->peer,
- qsm->quota);
+ GST_neighbours_set_incoming_quota (&qsm->peer, qsm->quota);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
@@ -624,22 +603,20 @@
* @param address the resolved name, NULL to indicate the last response
*/
static void
-transmit_address_to_client (void *cls,
- const char *address)
+transmit_address_to_client (void *cls, const char *address)
{
struct GNUNET_SERVER_TransmitContext *tc = cls;
if (NULL == address)
- {
- GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
-
GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
- GNUNET_SERVER_transmit_context_run (tc,
- GNUNET_TIME_UNIT_FOREVER_REL);
- return;
- }
- GNUNET_SERVER_transmit_context_append_data (tc,
- address, strlen (address) + 1,
-
GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
+ {
+ GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
+
GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
+ GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
+ return;
+ }
+ GNUNET_SERVER_transmit_context_append_data (tc,
+ address, strlen (address) + 1,
+
GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
}
@@ -652,8 +629,8 @@
*/
static void
clients_handle_address_lookup (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
const struct AddressLookupMessage *alum;
struct GNUNET_TRANSPORT_PluginFunctions *papi;
@@ -667,46 +644,45 @@
size = ntohs (message->size);
if (size < sizeof (struct AddressLookupMessage))
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
alum = (const struct AddressLookupMessage *) message;
address_len = ntohl (alum->addrlen);
if (size <= sizeof (struct AddressLookupMessage) + address_len)
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
address = (const char *) &alum[1];
plugin_name = (const char *) &address[address_len];
if (plugin_name
[size - sizeof (struct AddressLookupMessage) - address_len - 1] != '\0')
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
rtimeout = GNUNET_TIME_relative_ntoh (alum->timeout);
numeric = ntohl (alum->numeric_only);
tc = GNUNET_SERVER_transmit_context_create (client);
papi = GST_plugins_find (plugin_name);
if (NULL == papi)
- {
- GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
-
GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
- GNUNET_SERVER_transmit_context_run (tc, rtimeout);
- return;
- }
+ {
+ GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
+
GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
+ GNUNET_SERVER_transmit_context_run (tc, rtimeout);
+ return;
+ }
GNUNET_SERVER_disable_receive_done_warning (client);
papi->address_pretty_printer (papi->cls,
- plugin_name,
- address, address_len,
- numeric,
- rtimeout,
- &transmit_address_to_client, tc);
+ plugin_name,
+ address, address_len,
+ numeric,
+ rtimeout, &transmit_address_to_client, tc);
}
@@ -726,28 +702,26 @@
*/
static void
send_address_to_client (void *cls,
- const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
*public_key,
- const struct GNUNET_PeerIdentity *target,
- struct GNUNET_TIME_Absolute valid_until,
- struct GNUNET_TIME_Absolute validation_block,
- const char *plugin_name,
- const void *plugin_address,
- size_t plugin_address_len)
+ const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
+ *public_key, const struct GNUNET_PeerIdentity *target,
+ struct GNUNET_TIME_Absolute valid_until,
+ struct GNUNET_TIME_Absolute validation_block,
+ const char *plugin_name, const void *plugin_address,
+ size_t plugin_address_len)
{
struct GNUNET_SERVER_TransmitContext *tc = cls;
char *addr_buf;
/* FIXME: move to a binary format!!! */
GNUNET_asprintf (&addr_buf, "%s --- %s, %s",
- GST_plugins_a2s (plugin_name,
- plugin_address,
- plugin_address_len),
- (GNUNET_YES == GST_neighbours_test_connected (target))
- ? "CONNECTED"
- : "DISCONNECTED",
- (GNUNET_TIME_absolute_get_remaining (valid_until).rel_value
> 0)
- ? "VALIDATED"
- : "UNVALIDATED");
+ GST_plugins_a2s (plugin_name,
+ plugin_address,
+ plugin_address_len),
+ (GNUNET_YES == GST_neighbours_test_connected (target))
+ ? "CONNECTED"
+ : "DISCONNECTED",
+ (GNUNET_TIME_absolute_get_remaining (valid_until).rel_value
>
+ 0) ? "VALIDATED" : "UNVALIDATED");
transmit_address_to_client (tc, addr_buf);
GNUNET_free (addr_buf);
}
@@ -764,8 +738,8 @@
*/
static void
clients_handle_peer_address_lookup (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
const struct PeerAddressLookupMessage *peer_address_lookup;
struct GNUNET_SERVER_TransmitContext *tc;
@@ -774,13 +748,11 @@
GNUNET_break (ntohl (peer_address_lookup->reserved) == 0);
tc = GNUNET_SERVER_transmit_context_create (client);
GST_validation_get_addresses (&peer_address_lookup->peer,
- &send_address_to_client,
- tc);
+ &send_address_to_client, tc);
GNUNET_SERVER_transmit_context_append_data (tc,
- NULL, 0,
-
GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
- GNUNET_SERVER_transmit_context_run (tc,
- GNUNET_TIME_UNIT_FOREVER_REL);
+ NULL, 0,
+
GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
+ GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
}
@@ -794,18 +766,17 @@
*/
static void
output_addresses (void *cls,
- const struct GNUNET_PeerIdentity *neighbour,
- const struct GNUNET_TRANSPORT_ATS_Information *ats,
- uint32_t ats_count)
+ const struct GNUNET_PeerIdentity *neighbour,
+ const struct GNUNET_TRANSPORT_ATS_Information *ats,
+ uint32_t ats_count)
{
struct GNUNET_SERVER_TransmitContext *tc = cls;
char *addr_buf;
/* FIXME: move to a binary format!!! */
- GNUNET_asprintf (&addr_buf,
- "%s: %s",
- GNUNET_i2s(neighbour),
- GST_plugins_a2s ("FIXME", NULL, 0));
+ GNUNET_asprintf (&addr_buf,
+ "%s: %s",
+ GNUNET_i2s (neighbour), GST_plugins_a2s ("FIXME", NULL, 0));
transmit_address_to_client (tc, addr_buf);
GNUNET_free (addr_buf);
}
@@ -821,15 +792,14 @@
*/
static void
clients_handle_address_iterate (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
-{
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
+{
struct GNUNET_SERVER_TransmitContext *tc;
GNUNET_SERVER_disable_receive_done_warning (client);
tc = GNUNET_SERVER_transmit_context_create (client);
- GST_neighbours_iterate (&output_addresses,
- tc);
+ GST_neighbours_iterate (&output_addresses, tc);
GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
@@ -841,30 +811,35 @@
*
* @param server server used to accept clients from.
*/
-void
+void
GST_clients_start (struct GNUNET_SERVER_Handle *server)
{
static const struct GNUNET_SERVER_MessageHandler handlers[] = {
- { &clients_handle_start, NULL,
- GNUNET_MESSAGE_TYPE_TRANSPORT_START, sizeof (struct StartMessage)},
- { &clients_handle_hello, NULL,
- GNUNET_MESSAGE_TYPE_HELLO, 0},
- { &clients_handle_send, NULL,
- GNUNET_MESSAGE_TYPE_TRANSPORT_SEND , 0},
- { &clients_handle_request_connect, NULL,
- GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT, sizeof (struct
TransportRequestConnectMessage)},
- { &clients_handle_set_quota, NULL,
- GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA, sizeof (struct
QuotaSetMessage)},
- { &clients_handle_address_lookup, NULL,
- GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP , 0},
- { &clients_handle_peer_address_lookup, NULL,
- GNUNET_MESSAGE_TYPE_TRANSPORT_PEER_ADDRESS_LOOKUP, sizeof (struct
PeerAddressLookupMessage)},
- { &clients_handle_address_iterate, NULL,
- GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE, sizeof (struct
GNUNET_MessageHeader)},
- { &GST_blacklist_handle_init, NULL,
- GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT, sizeof (struct
GNUNET_MessageHeader)},
- { &GST_blacklist_handle_reply, NULL,
- GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY, sizeof (struct
BlacklistMessage)},
+ {&clients_handle_start, NULL,
+ GNUNET_MESSAGE_TYPE_TRANSPORT_START, sizeof (struct StartMessage)},
+ {&clients_handle_hello, NULL,
+ GNUNET_MESSAGE_TYPE_HELLO, 0},
+ {&clients_handle_send, NULL,
+ GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, 0},
+ {&clients_handle_request_connect, NULL,
+ GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT,
+ sizeof (struct TransportRequestConnectMessage)},
+ {&clients_handle_set_quota, NULL,
+ GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA, sizeof (struct QuotaSetMessage)},
+ {&clients_handle_address_lookup, NULL,
+ GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP, 0},
+ {&clients_handle_peer_address_lookup, NULL,
+ GNUNET_MESSAGE_TYPE_TRANSPORT_PEER_ADDRESS_LOOKUP,
+ sizeof (struct PeerAddressLookupMessage)},
+ {&clients_handle_address_iterate, NULL,
+ GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE,
+ sizeof (struct GNUNET_MessageHeader)},
+ {&GST_blacklist_handle_init, NULL,
+ GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT,
+ sizeof (struct GNUNET_MessageHeader)},
+ {&GST_blacklist_handle_reply, NULL,
+ GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY,
+ sizeof (struct BlacklistMessage)},
{NULL, NULL, 0, 0}
};
GNUNET_SERVER_add_handlers (server, handlers);
@@ -890,8 +865,7 @@
* @param may_drop GNUNET_YES if the message can be dropped
*/
void
-GST_clients_broadcast (const struct GNUNET_MessageHeader *msg,
- int may_drop)
+GST_clients_broadcast (const struct GNUNET_MessageHeader *msg, int may_drop)
{
struct TransportClient *tc;
@@ -909,8 +883,7 @@
*/
void
GST_clients_unicast (struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *msg,
- int may_drop)
+ const struct GNUNET_MessageHeader *msg, int may_drop)
{
struct TransportClient *tc;
Modified: gnunet/src/transport/gnunet-service-transport_clients.h
===================================================================
--- gnunet/src/transport/gnunet-service-transport_clients.h 2011-08-15
21:40:08 UTC (rev 16580)
+++ gnunet/src/transport/gnunet-service-transport_clients.h 2011-08-15
21:46:35 UTC (rev 16581)
@@ -35,15 +35,13 @@
*
* @param server server used to accept clients from.
*/
-void
-GST_clients_start (struct GNUNET_SERVER_Handle *server);
+void GST_clients_start (struct GNUNET_SERVER_Handle *server);
/**
* Stop processing clients.
*/
-void
-GST_clients_stop (void);
+void GST_clients_stop (void);
/**
@@ -53,8 +51,7 @@
* @param may_drop GNUNET_YES if the message can be dropped
*/
void
-GST_clients_broadcast (const struct GNUNET_MessageHeader *msg,
- int may_drop);
+GST_clients_broadcast (const struct GNUNET_MessageHeader *msg, int may_drop);
/**
@@ -66,8 +63,7 @@
*/
void
GST_clients_unicast (struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *msg,
- int may_drop);
+ const struct GNUNET_MessageHeader *msg, int may_drop);
Modified: gnunet/src/transport/gnunet-service-transport_hello.c
===================================================================
--- gnunet/src/transport/gnunet-service-transport_hello.c 2011-08-15
21:40:08 UTC (rev 16580)
+++ gnunet/src/transport/gnunet-service-transport_hello.c 2011-08-15
21:46:35 UTC (rev 16581)
@@ -90,7 +90,7 @@
/**
* Closure for 'hello_cb'.
- */
+ */
static void *hello_cb_cls;
/**
@@ -118,7 +118,7 @@
* Where are we in the DLL?
*/
struct OwnAddressList *addr_pos;
-
+
/**
* When do addresses expire?
*/
@@ -140,12 +140,11 @@
size_t ret;
if (NULL == gc->addr_pos)
- return 0;
+ return 0;
ret = GNUNET_HELLO_add_address (gc->addr_pos->plugin_name,
gc->expiration,
&gc->addr_pos[1],
- gc->addr_pos->addrlen,
- buf, max);
+ gc->addr_pos->addrlen, buf, max);
gc->addr_pos = gc->addr_pos->next;
return ret;
}
@@ -159,34 +158,30 @@
* @param tc scheduler context
*/
static void
-refresh_hello_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+refresh_hello_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GeneratorContext gc;
hello_task = GNUNET_SCHEDULER_NO_TASK;
gc.addr_pos = oal_head;
- gc.expiration = GNUNET_TIME_relative_to_absolute
(GST_HELLO_ADDRESS_EXPIRATION);
+ gc.expiration =
+ GNUNET_TIME_relative_to_absolute (GST_HELLO_ADDRESS_EXPIRATION);
GNUNET_free (our_hello);
- our_hello = GNUNET_HELLO_create (&GST_my_public_key,
- &address_generator,
- &gc);
+ our_hello = GNUNET_HELLO_create (&GST_my_public_key, &address_generator,
&gc);
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
- "Refreshed my `%s', new size is %d\n", "HELLO",
- GNUNET_HELLO_size(our_hello));
+ "Refreshed my `%s', new size is %d\n", "HELLO",
+ GNUNET_HELLO_size (our_hello));
#endif
GNUNET_STATISTICS_update (GST_stats,
- gettext_noop ("# refreshed my HELLO"),
- 1,
- GNUNET_NO);
+ gettext_noop ("# refreshed my HELLO"),
+ 1, GNUNET_NO);
if (NULL != hello_cb)
- hello_cb (hello_cb_cls, GST_hello_get());
+ hello_cb (hello_cb_cls, GST_hello_get ());
GNUNET_PEERINFO_add_peer (GST_peerinfo, our_hello);
hello_task
- = GNUNET_SCHEDULER_add_delayed (HELLO_REFRESH_PERIOD,
- &refresh_hello_task,
- NULL);
+ = GNUNET_SCHEDULER_add_delayed (HELLO_REFRESH_PERIOD,
+ &refresh_hello_task, NULL);
}
@@ -200,9 +195,7 @@
{
if (hello_task != GNUNET_SCHEDULER_NO_TASK)
GNUNET_SCHEDULER_cancel (hello_task);
- hello_task
- = GNUNET_SCHEDULER_add_now (&refresh_hello_task,
- NULL);
+ hello_task = GNUNET_SCHEDULER_add_now (&refresh_hello_task, NULL);
}
@@ -212,14 +205,12 @@
* @param cb function to call whenever our HELLO changes
* @param cb_cls closure for cb
*/
-void
-GST_hello_start (GST_HelloCallback cb,
- void *cb_cls)
+void
+GST_hello_start (GST_HelloCallback cb, void *cb_cls)
{
hello_cb = cb;
hello_cb_cls = cb_cls;
- our_hello = GNUNET_HELLO_create (&GST_my_public_key,
- NULL, NULL);
+ our_hello = GNUNET_HELLO_create (&GST_my_public_key, NULL, NULL);
refresh_hello ();
}
@@ -233,15 +224,15 @@
hello_cb = NULL;
hello_cb_cls = NULL;
if (GNUNET_SCHEDULER_NO_TASK != hello_task)
- {
- GNUNET_SCHEDULER_cancel (hello_task);
- hello_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (hello_task);
+ hello_task = GNUNET_SCHEDULER_NO_TASK;
+ }
if (NULL != our_hello)
- {
- GNUNET_free (our_hello);
- our_hello = NULL;
- }
+ {
+ GNUNET_free (our_hello);
+ our_hello = NULL;
+ }
}
@@ -253,7 +244,7 @@
const struct GNUNET_MessageHeader *
GST_hello_get ()
{
- return (struct GNUNET_MessageHeader*) our_hello;
+ return (struct GNUNET_MessageHeader *) our_hello;
}
@@ -267,45 +258,39 @@
*/
void
GST_hello_modify_addresses (int addremove,
- const char *plugin_name,
- const void *plugin_address,
- size_t plugin_address_len)
+ const char *plugin_name,
+ const void *plugin_address,
+ size_t plugin_address_len)
{
struct OwnAddressList *al;
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- (add_remove == GNUNET_YES)
- ? "Adding `%s':%s to the set of our addresses\n"
- : "Removing `%s':%s from the set of our addresses\n",
- GST_plugins_a2s (plugin_name,
- addr, addrlen),
- p->short_name);
+ (add_remove == GNUNET_YES)
+ ? "Adding `%s':%s to the set of our addresses\n"
+ : "Removing `%s':%s from the set of our addresses\n",
+ GST_plugins_a2s (plugin_name, addr, addrlen), p->short_name);
#endif
GNUNET_assert (plugin_address != NULL);
if (GNUNET_NO == addremove)
- {
- for (al = oal_head; al != NULL; al = al->next)
- if ( (plugin_address_len == al->addrlen) &&
- (0 == strcmp (al->plugin_name, plugin_name)) &&
- (0 == memcmp (plugin_address, &al[1], plugin_address_len)) )
- {
- GNUNET_CONTAINER_DLL_remove (oal_head,
- oal_tail,
- al);
- GNUNET_free (al->plugin_name);
- GNUNET_free (al);
- refresh_hello ();
- return;
- }
- /* address to be removed not found!? */
- GNUNET_break (0);
- return;
- }
+ {
+ for (al = oal_head; al != NULL; al = al->next)
+ if ((plugin_address_len == al->addrlen) &&
+ (0 == strcmp (al->plugin_name, plugin_name)) &&
+ (0 == memcmp (plugin_address, &al[1], plugin_address_len)))
+ {
+ GNUNET_CONTAINER_DLL_remove (oal_head, oal_tail, al);
+ GNUNET_free (al->plugin_name);
+ GNUNET_free (al);
+ refresh_hello ();
+ return;
+ }
+ /* address to be removed not found!? */
+ GNUNET_break (0);
+ return;
+ }
al = GNUNET_malloc (sizeof (struct OwnAddressList) + plugin_address_len);
- GNUNET_CONTAINER_DLL_insert (oal_head,
- oal_tail,
- al);
+ GNUNET_CONTAINER_DLL_insert (oal_head, oal_tail, al);
al->plugin_name = GNUNET_strdup (plugin_name);
al->addrlen = plugin_address_len;
memcpy (&al[1], plugin_address, plugin_address_len);
@@ -327,22 +312,22 @@
*/
int
GST_hello_test_address (const char *plugin_name,
- const void *plugin_address,
- size_t plugin_address_len,
- struct GNUNET_CRYPTO_RsaSignature **sig,
- struct GNUNET_TIME_Absolute **sig_expiration)
+ const void *plugin_address,
+ size_t plugin_address_len,
+ struct GNUNET_CRYPTO_RsaSignature **sig,
+ struct GNUNET_TIME_Absolute **sig_expiration)
{
struct OwnAddressList *al;
for (al = oal_head; al != NULL; al = al->next)
- if ( (plugin_address_len == al->addrlen) &&
- (0 == strcmp (al->plugin_name, plugin_name)) &&
- (0 == memcmp (plugin_address, &al[1], plugin_address_len)) )
- {
- *sig = &al->pong_signature;
- *sig_expiration = &al->pong_sig_expires;
- return GNUNET_YES;
- }
+ if ((plugin_address_len == al->addrlen) &&
+ (0 == strcmp (al->plugin_name, plugin_name)) &&
+ (0 == memcmp (plugin_address, &al[1], plugin_address_len)))
+ {
+ *sig = &al->pong_signature;
+ *sig_expiration = &al->pong_sig_expires;
+ return GNUNET_YES;
+ }
*sig = NULL;
*sig_expiration = NULL;
return GNUNET_NO;
Modified: gnunet/src/transport/gnunet-service-transport_hello.h
===================================================================
--- gnunet/src/transport/gnunet-service-transport_hello.h 2011-08-15
21:40:08 UTC (rev 16580)
+++ gnunet/src/transport/gnunet-service-transport_hello.h 2011-08-15
21:46:35 UTC (rev 16581)
@@ -45,8 +45,8 @@
* @param cls closure
* @param hello updated HELLO
*/
-typedef void (*GST_HelloCallback)(void *cls,
- const struct GNUNET_MessageHeader *hello);
+typedef void (*GST_HelloCallback) (void *cls,
+ const struct GNUNET_MessageHeader * hello);
/**
@@ -55,16 +55,13 @@
* @param cb function to call whenever our HELLO changes
* @param cb_cls closure for cb
*/
-void
-GST_hello_start (GST_HelloCallback cb,
- void *cb_cls);
+void GST_hello_start (GST_HelloCallback cb, void *cb_cls);
/**
* Shutdown the HELLO module.
*/
-void
-GST_hello_stop (void);
+void GST_hello_stop (void);
/**
@@ -72,8 +69,7 @@
*
* @return our HELLO message
*/
-const struct GNUNET_MessageHeader *
-GST_hello_get (void);
+const struct GNUNET_MessageHeader *GST_hello_get (void);
/**
@@ -86,9 +82,9 @@
*/
void
GST_hello_modify_addresses (int addremove,
- const char *plugin_name,
- const void *plugin_address,
- size_t plugin_address_len);
+ const char *plugin_name,
+ const void *plugin_address,
+ size_t plugin_address_len);
/**
@@ -105,10 +101,10 @@
*/
int
GST_hello_test_address (const char *plugin_name,
- const void *plugin_address,
- size_t plugin_address_len,
- struct GNUNET_CRYPTO_RsaSignature **sig,
- struct GNUNET_TIME_Absolute **sig_expiration);
+ const void *plugin_address,
+ size_t plugin_address_len,
+ struct GNUNET_CRYPTO_RsaSignature **sig,
+ struct GNUNET_TIME_Absolute **sig_expiration);
#endif
Modified: gnunet/src/transport/gnunet-service-transport_neighbours.c
===================================================================
--- gnunet/src/transport/gnunet-service-transport_neighbours.c 2011-08-15
21:40:08 UTC (rev 16580)
+++ gnunet/src/transport/gnunet-service-transport_neighbours.c 2011-08-15
21:46:35 UTC (rev 16581)
@@ -152,7 +152,7 @@
* Address used for communicating with the peer, NULL for inbound
connections.
*/
void *addr;
-
+
/**
* Number of bytes in 'addr'.
*/
@@ -236,8 +236,7 @@
static struct NeighbourMapEntry *
lookup_neighbour (const struct GNUNET_PeerIdentity *pid)
{
- return GNUNET_CONTAINER_multihashmap_get (neighbours,
- &pid->hashPubKey);
+ return GNUNET_CONTAINER_multihashmap_get (neighbours, &pid->hashPubKey);
}
@@ -248,8 +247,7 @@
* @param tc scheduler context
*/
static void
-transmission_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+transmission_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
/**
@@ -261,25 +259,23 @@
*/
static void
transmit_send_continuation (void *cls,
- const struct GNUNET_PeerIdentity *receiver,
- int success)
+ const struct GNUNET_PeerIdentity *receiver,
+ int success)
{
struct MessageQueue *mq;
struct NeighbourMapEntry *n;
-
+
mq = cls;
n = mq->n;
- if (NULL != n)
- {
- GNUNET_assert (n->is_active == mq);
- n->is_active = NULL;
- GNUNET_assert (n->transmission_task == GNUNET_SCHEDULER_NO_TASK);
- n->transmission_task = GNUNET_SCHEDULER_add_now (&transmission_task,
- n);
- }
+ if (NULL != n)
+ {
+ GNUNET_assert (n->is_active == mq);
+ n->is_active = NULL;
+ GNUNET_assert (n->transmission_task == GNUNET_SCHEDULER_NO_TASK);
+ n->transmission_task = GNUNET_SCHEDULER_add_now (&transmission_task, n);
+ }
if (NULL != mq->cont)
- mq->cont (mq->cont_cls,
- success);
+ mq->cont (mq->cont_cls, success);
GNUNET_free (mq);
}
@@ -299,52 +295,45 @@
struct GNUNET_TRANSPORT_PluginFunctions *papi;
if (n->is_active != NULL)
- return; /* transmission already pending */
+ return; /* transmission already pending */
if (n->transmission_task != GNUNET_SCHEDULER_NO_TASK)
- return; /* currently waiting for bandwidth */
+ return; /* currently waiting for bandwidth */
mq = n->messages_head;
while (NULL != (mq = n->messages_head))
- {
- timeout = GNUNET_TIME_absolute_get_remaining (mq->timeout);
- if (timeout.rel_value > 0)
- break;
- transmit_send_continuation (mq, &n->id, GNUNET_SYSERR); /* timeout */
- }
+ {
+ timeout = GNUNET_TIME_absolute_get_remaining (mq->timeout);
+ if (timeout.rel_value > 0)
+ break;
+ transmit_send_continuation (mq, &n->id, GNUNET_SYSERR); /* timeout */
+ }
if (NULL == mq)
- return; /* no more messages */
+ return; /* no more messages */
papi = GST_plugins_find (n->plugin_name);
if (papi == NULL)
- {
- GNUNET_break (0);
- return;
- }
- GNUNET_CONTAINER_DLL_remove (n->messages_head,
- n->messages_tail,
- mq);
+ {
+ GNUNET_break (0);
+ return;
+ }
+ GNUNET_CONTAINER_DLL_remove (n->messages_head, n->messages_tail, mq);
n->is_active = mq;
mq->n = n;
ret = papi->send (papi->cls,
- &n->id,
- mq->message_buf,
- mq->message_buf_size,
- 0 /* priority -- remove from plugin API? */,
- timeout,
- n->session,
- n->addr,
- n->addrlen,
- GNUNET_YES,
- &transmit_send_continuation, mq);
+ &n->id,
+ mq->message_buf,
+ mq->message_buf_size,
+ 0 /* priority -- remove from plugin API? */ ,
+ timeout,
+ n->session,
+ n->addr,
+ n->addrlen, GNUNET_YES, &transmit_send_continuation, mq);
if (ret == -1)
- {
- /* failure, but 'send' would not call continuation in this case,
- so we need to do it here! */
- transmit_send_continuation (mq,
- &n->id,
- GNUNET_SYSERR);
- n->transmission_task = GNUNET_SCHEDULER_add_now (&transmission_task,
- n);
- }
+ {
+ /* failure, but 'send' would not call continuation in this case,
+ * so we need to do it here! */
+ transmit_send_continuation (mq, &n->id, GNUNET_SYSERR);
+ n->transmission_task = GNUNET_SCHEDULER_add_now (&transmission_task, n);
+ }
}
@@ -355,8 +344,7 @@
* @param tc scheduler context
*/
static void
-transmission_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+transmission_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct NeighbourMapEntry *n = cls;
@@ -372,10 +360,10 @@
* @param connect_cb function to call if we connect to a peer
* @param disconnect_cb function to call if we disconnect from a peer
*/
-void
+void
GST_neighbours_start (void *cls,
- GNUNET_TRANSPORT_NotifyConnect connect_cb,
- GNUNET_TRANSPORT_NotifyDisconnect disconnect_cb)
+ GNUNET_TRANSPORT_NotifyConnect connect_cb,
+ GNUNET_TRANSPORT_NotifyDisconnect disconnect_cb)
{
callback_cls = cls;
connect_notify_cb = connect_cb;
@@ -398,57 +386,51 @@
return;
n->in_disconnect = GNUNET_YES;
while (NULL != (mq = n->messages_head))
- {
- GNUNET_CONTAINER_DLL_remove (n->messages_head,
- n->messages_tail,
- mq);
- mq->cont (mq->cont_cls, GNUNET_SYSERR);
- GNUNET_free (mq);
- }
+ {
+ GNUNET_CONTAINER_DLL_remove (n->messages_head, n->messages_tail, mq);
+ mq->cont (mq->cont_cls, GNUNET_SYSERR);
+ GNUNET_free (mq);
+ }
if (NULL != n->is_active)
- {
- n->is_active->n = NULL;
- n->is_active = NULL;
- }
+ {
+ n->is_active->n = NULL;
+ n->is_active = NULL;
+ }
if (GNUNET_YES == n->is_connected)
- {
- n->is_connected = GNUNET_NO;
- disconnect_notify_cb (callback_cls,
- &n->id);
- }
+ {
+ n->is_connected = GNUNET_NO;
+ disconnect_notify_cb (callback_cls, &n->id);
+ }
GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove (neighbours,
- &n->id.hashPubKey,
- n));
+ GNUNET_CONTAINER_multihashmap_remove (neighbours,
+ &n->id.hashPubKey, n));
if (GNUNET_SCHEDULER_NO_TASK != n->timeout_task)
- {
- GNUNET_SCHEDULER_cancel (n->timeout_task);
- n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (n->timeout_task);
+ n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ }
if (GNUNET_SCHEDULER_NO_TASK != n->transmission_task)
- {
- GNUNET_SCHEDULER_cancel (n->timeout_task);
- n->transmission_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (n->timeout_task);
+ n->transmission_task = GNUNET_SCHEDULER_NO_TASK;
+ }
if (NULL != n->asc)
- {
- GNUNET_ATS_suggest_address_cancel (n->asc);
- n->asc = NULL;
- }
- GNUNET_array_grow (n->ats,
- n->ats_count,
- 0);
+ {
+ GNUNET_ATS_suggest_address_cancel (n->asc);
+ n->asc = NULL;
+ }
+ GNUNET_array_grow (n->ats, n->ats_count, 0);
if (NULL != n->plugin_name)
- {
- GNUNET_free (n->plugin_name);
- n->plugin_name = NULL;
- }
+ {
+ GNUNET_free (n->plugin_name);
+ n->plugin_name = NULL;
+ }
if (NULL != n->addr)
- {
- GNUNET_free (n->addr);
- n->addr = NULL;
- n->addrlen = 0;
- }
+ {
+ GNUNET_free (n->addr);
+ n->addr = NULL;
+ n->addrlen = 0;
+ }
n->session = NULL;
GNUNET_free (n);
}
@@ -462,7 +444,7 @@
*/
static void
neighbour_timeout_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct NeighbourMapEntry *n = cls;
@@ -479,17 +461,14 @@
* @param value the 'struct NeighbourMapEntry' of the neighbour
*/
static int
-disconnect_all_neighbours (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+disconnect_all_neighbours (void *cls, const GNUNET_HashCode * key, void *value)
{
struct NeighbourMapEntry *n = value;
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Disconnecting peer `%4s', %s\n",
- GNUNET_i2s(&n->id),
- "SHUTDOWN_TASK");
+ "Disconnecting peer `%4s', %s\n",
+ GNUNET_i2s (&n->id), "SHUTDOWN_TASK");
#endif
disconnect_neighbour (n);
return GNUNET_OK;
@@ -503,8 +482,7 @@
GST_neighbours_stop ()
{
GNUNET_CONTAINER_multihashmap_iterate (neighbours,
- &disconnect_all_neighbours,
- NULL);
+ &disconnect_all_neighbours, NULL);
GNUNET_CONTAINER_multihashmap_destroy (neighbours);
neighbours = NULL;
callback_cls = NULL;
@@ -528,46 +506,42 @@
*/
void
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_TRANSPORT_ATS_Information
*ats,
- uint32_t ats_count)
+ const char *plugin_name,
+ const void *address,
+ size_t address_len,
+ struct Session *session,
+ const struct GNUNET_TRANSPORT_ATS_Information
+ *ats, uint32_t ats_count)
{
struct NeighbourMapEntry *n;
struct GNUNET_MessageHeader connect_msg;
n = lookup_neighbour (peer);
if (NULL == n)
- {
- GNUNET_break (0);
- return;
- }
+ {
+ GNUNET_break (0);
+ return;
+ }
GNUNET_free_non_null (n->addr);
n->addr = GNUNET_malloc (address_len);
memcpy (n->addr, address, address_len);
n->addrlen = address_len;
n->session = session;
- GNUNET_array_grow (n->ats,
- n->ats_count,
- ats_count);
+ GNUNET_array_grow (n->ats, n->ats_count, ats_count);
memcpy (n->ats,
- ats,
- ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
+ ats, ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
GNUNET_free_non_null (n->plugin_name);
n->plugin_name = GNUNET_strdup (plugin_name);
GNUNET_SCHEDULER_cancel (n->timeout_task);
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);
connect_msg.size = htons (sizeof (struct GNUNET_MessageHeader));
connect_msg.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
GST_neighbours_send (peer,
- &connect_msg,
- sizeof (connect_msg),
- GNUNET_TIME_UNIT_FOREVER_REL,
- NULL, NULL);
+ &connect_msg,
+ sizeof (connect_msg),
+ GNUNET_TIME_UNIT_FOREVER_REL, NULL, NULL);
}
@@ -585,30 +559,25 @@
*/
static void
try_connect_using_address (void *cls,
- const struct GNUNET_PeerIdentity *target,
- const char *plugin_name,
- const void *plugin_address,
- size_t plugin_address_len,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth,
- const struct GNUNET_TRANSPORT_ATS_Information *ats,
- uint32_t ats_count)
+ const struct GNUNET_PeerIdentity *target,
+ const char *plugin_name,
+ const void *plugin_address,
+ size_t plugin_address_len,
+ struct GNUNET_BANDWIDTH_Value32NBO bandwidth,
+ const struct GNUNET_TRANSPORT_ATS_Information *ats,
+ uint32_t ats_count)
{
struct NeighbourMapEntry *n = cls;
n->asc = NULL;
GST_neighbours_switch_to_address (target,
- plugin_name,
- plugin_address,
- plugin_address_len,
- NULL,
- ats, ats_count);
+ plugin_name,
+ plugin_address,
+ plugin_address_len, NULL, ats, ats_count);
if (GNUNET_YES == n->is_connected)
return;
- n->is_connected = GNUNET_YES;
- connect_notify_cb (callback_cls,
- target,
- n->ats,
- n->ats_count);
+ n->is_connected = GNUNET_YES;
+ connect_notify_cb (callback_cls, target, n->ats, n->ats_count);
}
@@ -623,33 +592,30 @@
struct NeighbourMapEntry *n;
GNUNET_assert (0 != memcmp (target,
- &GST_my_identity,
- sizeof (struct GNUNET_PeerIdentity)));
+ &GST_my_identity,
+ sizeof (struct GNUNET_PeerIdentity)));
n = lookup_neighbour (target);
- if ( (NULL != n) &&
- (GNUNET_YES == n->is_connected) )
- return; /* already connected */
+ if ((NULL != n) && (GNUNET_YES == n->is_connected))
+ return; /* already connected */
if (n == NULL)
- {
- n = GNUNET_malloc (sizeof (struct NeighbourMapEntry));
- n->id = *target;
- GNUNET_BANDWIDTH_tracker_init (&n->in_tracker,
- 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_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_put (neighbours,
- &n->id.hashPubKey,
- n,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
- }
+ {
+ n = GNUNET_malloc (sizeof (struct NeighbourMapEntry));
+ n->id = *target;
+ GNUNET_BANDWIDTH_tracker_init (&n->in_tracker,
+ 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_assert (GNUNET_OK ==
+ GNUNET_CONTAINER_multihashmap_put (neighbours,
+ &n->id.hashPubKey, n,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+ }
if (n->asc != NULL)
- return; /* already trying */
+ return; /* already trying */
n->asc = GNUNET_ATS_suggest_address (GST_ats,
- target,
- &try_connect_using_address,
- n);
+ target, &try_connect_using_address, n);
}
@@ -665,9 +631,8 @@
struct NeighbourMapEntry *n;
n = lookup_neighbour (target);
- if ( (NULL == n) ||
- (n->is_connected == GNUNET_YES) )
- return GNUNET_NO; /* not connected */
+ if ((NULL == n) || (n->is_connected == GNUNET_YES))
+ return GNUNET_NO; /* not connected */
return GNUNET_YES;
}
@@ -680,7 +645,7 @@
*/
void
GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer,
- struct Session *session)
+ struct Session *session)
{
struct NeighbourMapEntry *n;
@@ -688,24 +653,23 @@
if (NULL == n)
return;
if (session != n->session)
- return; /* doesn't affect us */
+ return; /* doesn't affect us */
n->session = NULL;
if (GNUNET_YES != n->is_connected)
- return; /* not connected anymore anyway, shouldn't matter */
+ return; /* not connected anymore anyway, shouldn't
matter */
/* try QUICKLY to re-establish a connection, reduce timeout! */
if (NULL != n->ats)
- {
- /* how can this be!? */
- GNUNET_break (0);
- return;
- }
+ {
+ /* how can this be!? */
+ GNUNET_break (0);
+ return;
+ }
GNUNET_SCHEDULER_cancel (n->timeout_task);
- n->timeout_task = GNUNET_SCHEDULER_add_delayed
(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
- &neighbour_timeout_task, n);
- n->asc = GNUNET_ATS_suggest_address (GST_ats,
- peer,
- &try_connect_using_address,
- n);
+ n->timeout_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
+ &neighbour_timeout_task, n);
+ n->asc =
+ GNUNET_ATS_suggest_address (GST_ats, peer, &try_connect_using_address,
n);
}
@@ -721,48 +685,42 @@
*/
void
GST_neighbours_send (const struct GNUNET_PeerIdentity *target,
- const void *msg,
- size_t msg_size,
- struct GNUNET_TIME_Relative timeout,
- GST_NeighbourSendContinuation cont,
- void *cont_cls)
+ const void *msg,
+ size_t msg_size,
+ struct GNUNET_TIME_Relative timeout,
+ GST_NeighbourSendContinuation cont, void *cont_cls)
{
struct NeighbourMapEntry *n;
struct MessageQueue *mq;
n = lookup_neighbour (target);
- if ( (n == NULL) ||
- (GNUNET_YES != n->is_connected) )
- {
- GNUNET_STATISTICS_update (GST_stats,
- gettext_noop ("# SET QUOTA messages ignored (no
such peer)"),
- 1,
- GNUNET_NO);
- if (NULL != cont)
- cont (cont_cls,
- GNUNET_SYSERR);
- return;
- }
+ if ((n == NULL) || (GNUNET_YES != n->is_connected))
+ {
+ GNUNET_STATISTICS_update (GST_stats,
+ gettext_noop
+ ("# SET QUOTA messages ignored (no such peer)"),
+ 1, GNUNET_NO);
+ if (NULL != cont)
+ cont (cont_cls, GNUNET_SYSERR);
+ return;
+ }
GNUNET_assert (msg_size >= sizeof (struct GNUNET_MessageHeader));
GNUNET_STATISTICS_update (GST_stats,
- gettext_noop ("# bytes in message queue for other
peers"),
- msg_size,
- GNUNET_NO);
+ gettext_noop
+ ("# bytes in message queue for other peers"),
+ msg_size, GNUNET_NO);
mq = GNUNET_malloc (sizeof (struct MessageQueue) + msg_size);
mq->cont = cont;
mq->cont_cls = cont_cls;
/* FIXME: this memcpy can be up to 7% of our total runtime! */
memcpy (&mq[1], msg, msg_size);
- mq->message_buf = (const char*) &mq[1];
+ mq->message_buf = (const char *) &mq[1];
mq->message_buf_size = msg_size;
mq->timeout = GNUNET_TIME_relative_to_absolute (timeout);
- GNUNET_CONTAINER_DLL_insert_tail (n->messages_head,
- n->messages_tail,
- mq);
- if ( (GNUNET_SCHEDULER_NO_TASK == n->transmission_task) &&
- (NULL == n->is_active) )
- n->transmission_task = GNUNET_SCHEDULER_add_now (&transmission_task,
- n);
+ GNUNET_CONTAINER_DLL_insert_tail (n->messages_head, n->messages_tail, mq);
+ if ((GNUNET_SCHEDULER_NO_TASK == n->transmission_task) &&
+ (NULL == n->is_active))
+ n->transmission_task = GNUNET_SCHEDULER_add_now (&transmission_task, n);
}
@@ -778,68 +736,64 @@
* @return how long to wait before reading more from this sender
*/
struct GNUNET_TIME_Relative
-GST_neighbours_calculate_receive_delay (const struct GNUNET_PeerIdentity
*sender,
- ssize_t size,
- int *do_forward)
+GST_neighbours_calculate_receive_delay (const struct GNUNET_PeerIdentity
+ *sender, ssize_t size, int *do_forward)
{
struct NeighbourMapEntry *n;
struct GNUNET_TIME_Relative ret;
n = lookup_neighbour (sender);
if (n == NULL)
- {
- *do_forward = GNUNET_NO;
- return GNUNET_TIME_UNIT_ZERO;
- }
- if (GNUNET_YES == GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker,
- size))
- {
- n->quota_violation_count++;
+ {
+ *do_forward = GNUNET_NO;
+ return GNUNET_TIME_UNIT_ZERO;
+ }
+ if (GNUNET_YES == GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker, size))
+ {
+ n->quota_violation_count++;
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Bandwidth quota (%u b/s) violation detected (total of
%u).\n",
- n->in_tracker.available_bytes_per_s__,
- n->quota_violation_count);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Bandwidth quota (%u b/s) violation detected (total of %u).\n",
+ n->in_tracker.available_bytes_per_s__,
+ n->quota_violation_count);
#endif
- /* Discount 32k per violation */
- GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker,
- - 32 * 1024);
- }
+ /* Discount 32k per violation */
+ GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker, -32 * 1024);
+ }
else
+ {
+ if (n->quota_violation_count > 0)
{
- if (n->quota_violation_count > 0)
- {
- /* try to add 32k back */
- GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker,
- 32 * 1024);
- n->quota_violation_count--;
- }
+ /* try to add 32k back */
+ GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker, 32 * 1024);
+ n->quota_violation_count--;
}
+ }
if (n->quota_violation_count > QUOTA_VIOLATION_DROP_THRESHOLD)
- {
- GNUNET_STATISTICS_update (GST_stats,
- gettext_noop ("# bandwidth quota violations by
other peers"),
- 1,
- GNUNET_NO);
- *do_forward = GNUNET_NO;
- return GNUNET_CONSTANTS_QUOTA_VIOLATION_TIMEOUT;
- }
+ {
+ GNUNET_STATISTICS_update (GST_stats,
+ gettext_noop
+ ("# bandwidth quota violations by other peers"),
+ 1, GNUNET_NO);
+ *do_forward = GNUNET_NO;
+ return GNUNET_CONSTANTS_QUOTA_VIOLATION_TIMEOUT;
+ }
*do_forward = GNUNET_YES;
ret = GNUNET_BANDWIDTH_tracker_get_delay (&n->in_tracker, 0);
if (ret.rel_value > 0)
- {
-#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Throttling read (%llu bytes excess at %u b/s), waiting %llu
ms before reading more.\n",
- (unsigned long long)
n->in_tracker.consumption_since_last_update__,
- (unsigned int) n->in_tracker.available_bytes_per_s__,
- (unsigned long long) ret.rel_value);
+ {
+#if DEBUG_TRANSPORT
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Throttling read (%llu bytes excess at %u b/s), waiting %llu
ms before reading more.\n",
+ (unsigned long long) n->
+ in_tracker.consumption_since_last_update__,
+ (unsigned int) n->in_tracker.available_bytes_per_s__,
+ (unsigned long long) ret.rel_value);
#endif
- GNUNET_STATISTICS_update (GST_stats,
- gettext_noop ("# ms throttling suggested"),
- (int64_t) ret.rel_value,
- GNUNET_NO);
- }
+ GNUNET_STATISTICS_update (GST_stats,
+ gettext_noop ("# ms throttling suggested"),
+ (int64_t) ret.rel_value, GNUNET_NO);
+ }
return ret;
}
@@ -857,17 +811,17 @@
n = lookup_neighbour (neighbour);
if (NULL == n)
- {
- GNUNET_STATISTICS_update (GST_stats,
- gettext_noop ("# KEEPALIVE messages discarded
(not connected)"),
- 1,
- GNUNET_NO);
- return;
- }
+ {
+ GNUNET_STATISTICS_update (GST_stats,
+ gettext_noop
+ ("# KEEPALIVE messages discarded (not
connected)"),
+ 1, GNUNET_NO);
+ return;
+ }
GNUNET_SCHEDULER_cancel (n->timeout_task);
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);
}
@@ -879,33 +833,30 @@
*/
void
GST_neighbours_set_incoming_quota (const struct GNUNET_PeerIdentity *neighbour,
- struct GNUNET_BANDWIDTH_Value32NBO quota)
+ struct GNUNET_BANDWIDTH_Value32NBO quota)
{
struct NeighbourMapEntry *n;
n = lookup_neighbour (neighbour);
if (n == NULL)
- {
- GNUNET_STATISTICS_update (GST_stats,
- gettext_noop ("# SET QUOTA messages ignored (no
such peer)"),
- 1,
- GNUNET_NO);
- return;
- }
- GNUNET_BANDWIDTH_tracker_update_quota (&n->in_tracker,
- quota);
+ {
+ GNUNET_STATISTICS_update (GST_stats,
+ gettext_noop
+ ("# SET QUOTA messages ignored (no such peer)"),
+ 1, GNUNET_NO);
+ return;
+ }
+ GNUNET_BANDWIDTH_tracker_update_quota (&n->in_tracker, quota);
if (0 != ntohl (quota.value__))
return;
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Disconnecting peer `%4s' due to `%s'\n",
- GNUNET_i2s(&n->id),
- "SET_QUOTA");
+ "Disconnecting peer `%4s' due to `%s'\n",
+ GNUNET_i2s (&n->id), "SET_QUOTA");
#endif
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);
}
@@ -936,20 +887,15 @@
* @return GNUNET_OK (continue to iterate)
*/
static int
-neighbours_iterate (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+neighbours_iterate (void *cls, const GNUNET_HashCode * key, void *value)
{
struct IteratorContext *ic = cls;
struct NeighbourMapEntry *n = value;
if (GNUNET_YES != n->is_connected)
- return GNUNET_OK;
+ return GNUNET_OK;
GNUNET_assert (n->ats_count > 0);
- ic->cb (ic->cb_cls,
- &n->id,
- n->ats,
- n->ats_count - 1);
+ ic->cb (ic->cb_cls, &n->id, n->ats, n->ats_count - 1);
return GNUNET_OK;
}
@@ -961,16 +907,13 @@
* @param cb_cls closure for cb
*/
void
-GST_neighbours_iterate (GST_NeighbourIterator cb,
- void *cb_cls)
+GST_neighbours_iterate (GST_NeighbourIterator cb, void *cb_cls)
{
struct IteratorContext ic;
ic.cb = cb;
ic.cb_cls = cb_cls;
- GNUNET_CONTAINER_multihashmap_iterate (neighbours,
- &neighbours_iterate,
- &ic);
+ GNUNET_CONTAINER_multihashmap_iterate (neighbours, &neighbours_iterate, &ic);
}
@@ -987,27 +930,23 @@
struct GNUNET_MessageHeader disconnect_msg;
n = lookup_neighbour (target);
- if (NULL == n)
- return; /* not active */
+ if (NULL == n)
+ return; /* not active */
if (GNUNET_YES == n->is_connected)
- {
- /* we're actually connected, send DISCONNECT message */
- disconnect_msg.size = htons (sizeof (struct GNUNET_MessageHeader));
- disconnect_msg.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
- papi = GST_plugins_find (n->plugin_name);
- if (papi != NULL)
- papi->send (papi->cls,
- target,
- (const void*) &disconnect_msg,
- sizeof (struct GNUNET_MessageHeader),
- UINT32_MAX /* priority */,
- GNUNET_TIME_UNIT_FOREVER_REL,
- n->session,
- n->addr,
- n->addrlen,
- GNUNET_YES,
- NULL, NULL);
- }
+ {
+ /* we're actually connected, send DISCONNECT message */
+ disconnect_msg.size = htons (sizeof (struct GNUNET_MessageHeader));
+ disconnect_msg.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
+ papi = GST_plugins_find (n->plugin_name);
+ if (papi != NULL)
+ papi->send (papi->cls,
+ target,
+ (const void *) &disconnect_msg,
+ sizeof (struct GNUNET_MessageHeader),
+ UINT32_MAX /* priority */ ,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ n->session, n->addr, n->addrlen, GNUNET_YES, NULL, NULL);
+ }
disconnect_neighbour (n);
}
Modified: gnunet/src/transport/gnunet-service-transport_neighbours.h
===================================================================
--- gnunet/src/transport/gnunet-service-transport_neighbours.h 2011-08-15
21:40:08 UTC (rev 16580)
+++ gnunet/src/transport/gnunet-service-transport_neighbours.h 2011-08-15
21:46:35 UTC (rev 16581)
@@ -43,17 +43,16 @@
* @param connect_cb function to call if we connect to a peer
* @param disconnect_cb function to call if we disconnect from a peer
*/
-void
+void
GST_neighbours_start (void *cls,
- GNUNET_TRANSPORT_NotifyConnect connect_cb,
- GNUNET_TRANSPORT_NotifyDisconnect disconnect_cb);
+ GNUNET_TRANSPORT_NotifyConnect connect_cb,
+ GNUNET_TRANSPORT_NotifyDisconnect disconnect_cb);
/**
* Cleanup the neighbours subsystem.
*/
-void
-GST_neighbours_stop (void);
+void GST_neighbours_stop (void);
/**
@@ -61,8 +60,7 @@
*
* @param target peer to try to connect to
*/
-void
-GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target);
+void GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target);
/**
@@ -71,8 +69,7 @@
* @param target peer to test
* @return GNUNET_YES if we are connected, GNUNET_NO if not
*/
-int
-GST_neighbours_test_connected (const struct GNUNET_PeerIdentity *target);
+int GST_neighbours_test_connected (const struct GNUNET_PeerIdentity *target);
/**
@@ -81,8 +78,7 @@
* @param cls closure
* @param success GNUNET_OK on success, GNUNET_NO on failure, GNUNET_SYSERR if
we're not connected
*/
-typedef void (*GST_NeighbourSendContinuation)(void *cls,
- int success);
+typedef void (*GST_NeighbourSendContinuation) (void *cls, int success);
/**
@@ -97,11 +93,10 @@
*/
void
GST_neighbours_send (const struct GNUNET_PeerIdentity *target,
- const void *msg,
- size_t msg_size,
- struct GNUNET_TIME_Relative timeout,
- GST_NeighbourSendContinuation cont,
- void *cont_cls);
+ const void *msg,
+ size_t msg_size,
+ struct GNUNET_TIME_Relative timeout,
+ GST_NeighbourSendContinuation cont, void *cont_cls);
/**
@@ -116,9 +111,8 @@
* @return how long to wait before reading more from this sender
*/
struct GNUNET_TIME_Relative
-GST_neighbours_calculate_receive_delay (const struct GNUNET_PeerIdentity
*sender,
- ssize_t size,
- int *do_forward);
+GST_neighbours_calculate_receive_delay (const struct GNUNET_PeerIdentity
+ *sender, ssize_t size, int
*do_forward);
/**
@@ -127,8 +121,7 @@
*
* @param neighbour neighbour to keep alive
*/
-void
-GST_neighbours_keepalive (const struct GNUNET_PeerIdentity *neighbour);
+void GST_neighbours_keepalive (const struct GNUNET_PeerIdentity *neighbour);
/**
@@ -139,7 +132,7 @@
*/
void
GST_neighbours_set_incoming_quota (const struct GNUNET_PeerIdentity *neighbour,
- struct GNUNET_BANDWIDTH_Value32NBO quota);
+ struct GNUNET_BANDWIDTH_Value32NBO quota);
/**
@@ -147,8 +140,7 @@
*
* @param target peer to disconnect from
*/
-void
-GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity *target);
+void GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity
*target);
/**
@@ -159,10 +151,12 @@
* @param ats performance data
* @param ats_count number of entries in ats (excluding 0-termination)
*/
-typedef void (*GST_NeighbourIterator)(void *cls,
- const struct GNUNET_PeerIdentity
*neighbour,
- const struct
GNUNET_TRANSPORT_ATS_Information *ats,
- uint32_t ats_count);
+typedef void (*GST_NeighbourIterator) (void *cls,
+ const struct GNUNET_PeerIdentity *
+ neighbour,
+ const struct
+ GNUNET_TRANSPORT_ATS_Information * ats,
+ uint32_t ats_count);
/**
@@ -171,9 +165,7 @@
* @param cb function to call
* @param cb_cls closure for cb
*/
-void
-GST_neighbours_iterate (GST_NeighbourIterator cb,
- void *cb_cls);
+void GST_neighbours_iterate (GST_NeighbourIterator cb, void *cb_cls);
/**
@@ -184,7 +176,7 @@
*/
void
GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer,
- struct Session *session);
+ struct Session *session);
/**
@@ -202,12 +194,12 @@
*/
void
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_TRANSPORT_ATS_Information
*ats,
- uint32_t ats_count);
+ const char *plugin_name,
+ const void *address,
+ size_t address_len,
+ struct Session *session,
+ const struct GNUNET_TRANSPORT_ATS_Information
+ *ats, uint32_t ats_count);
#endif
Modified: gnunet/src/transport/gnunet-service-transport_plugins.c
===================================================================
--- gnunet/src/transport/gnunet-service-transport_plugins.c 2011-08-15
21:40:08 UTC (rev 16580)
+++ gnunet/src/transport/gnunet-service-transport_plugins.c 2011-08-15
21:46:35 UTC (rev 16581)
@@ -90,10 +90,10 @@
* @param traffic_cb function to call for flow control
* @param session_end_cb function to call when a session was terminated
*/
-void
+void
GST_plugins_load (GNUNET_TRANSPORT_PluginReceiveCallback recv_cb,
- GNUNET_TRANSPORT_AddressNotification address_cb,
- GNUNET_TRANSPORT_SessionEnd session_end_cb)
+ GNUNET_TRANSPORT_AddressNotification address_cb,
+ GNUNET_TRANSPORT_SessionEnd session_end_cb)
{
struct TransportPlugin *plug;
unsigned long long tneigh;
@@ -103,57 +103,48 @@
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_number (GST_cfg,
- "TRANSPORT",
- "NEIGHBOUR_LIMIT",
- &tneigh))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Transport service is lacking NEIGHBOUR_LIMIT option.\n"));
- return;
- }
+ "TRANSPORT",
+ "NEIGHBOUR_LIMIT", &tneigh))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Transport service is lacking NEIGHBOUR_LIMIT option.\n"));
+ return;
+ }
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (GST_cfg,
"TRANSPORT", "PLUGINS", &plugs))
return;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Starting transport plugins `%s'\n"),
- plugs);
+ _("Starting transport plugins `%s'\n"), plugs);
for (pos = strtok (plugs, " "); pos != NULL; pos = strtok (NULL, " "))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Loading `%s' transport plugin\n"), pos);
- GNUNET_asprintf (&libname,
- "libgnunet_plugin_transport_%s",
- pos);
- plug = GNUNET_malloc (sizeof (struct TransportPlugin));
- plug->short_name = GNUNET_strdup (pos);
- plug->lib_name = libname;
- plug->env.cfg = GST_cfg;
- plug->env.my_identity = &GST_my_identity;
- plug->env.get_our_hello = &GST_hello_get;
- plug->env.cls = plug->short_name;
- plug->env.receive = recv_cb;
- plug->env.notify_address = address_cb;
- plug->env.session_end = session_end_cb;
- plug->env.max_connections = tneigh;
- plug->env.stats = GST_stats;
- GNUNET_CONTAINER_DLL_insert (plugins_head,
- plugins_tail,
- plug);
- plug->api = GNUNET_PLUGIN_load (libname, &plug->env);
- if (plug->api == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to load transport plugin for `%s'\n"),
- pos);
- GNUNET_CONTAINER_DLL_remove (plugins_head,
- plugins_tail,
- plug);
- GNUNET_free (plug->short_name);
- GNUNET_free (plug->lib_name);
- GNUNET_free (plug);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Loading `%s' transport plugin\n"), pos);
+ GNUNET_asprintf (&libname, "libgnunet_plugin_transport_%s", pos);
+ plug = GNUNET_malloc (sizeof (struct TransportPlugin));
+ plug->short_name = GNUNET_strdup (pos);
+ plug->lib_name = libname;
+ plug->env.cfg = GST_cfg;
+ plug->env.my_identity = &GST_my_identity;
+ plug->env.get_our_hello = &GST_hello_get;
+ plug->env.cls = plug->short_name;
+ plug->env.receive = recv_cb;
+ plug->env.notify_address = address_cb;
+ plug->env.session_end = session_end_cb;
+ plug->env.max_connections = tneigh;
+ plug->env.stats = GST_stats;
+ GNUNET_CONTAINER_DLL_insert (plugins_head, plugins_tail, plug);
+ plug->api = GNUNET_PLUGIN_load (libname, &plug->env);
+ if (plug->api == NULL)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to load transport plugin for `%s'\n"), pos);
+ GNUNET_CONTAINER_DLL_remove (plugins_head, plugins_tail, plug);
+ GNUNET_free (plug->short_name);
+ GNUNET_free (plug->lib_name);
+ GNUNET_free (plug);
}
+ }
GNUNET_free (plugs);
}
@@ -167,15 +158,13 @@
struct TransportPlugin *plug;
while (NULL != (plug = plugins_head))
- {
- GNUNET_break (NULL == GNUNET_PLUGIN_unload (plug->lib_name, plug->api));
- GNUNET_free (plug->lib_name);
- GNUNET_free (plug->short_name);
- GNUNET_CONTAINER_DLL_remove (plugins_head,
- plugins_tail,
- plug);
- GNUNET_free (plug);
- }
+ {
+ GNUNET_break (NULL == GNUNET_PLUGIN_unload (plug->lib_name, plug->api));
+ GNUNET_free (plug->lib_name);
+ GNUNET_free (plug->short_name);
+ GNUNET_CONTAINER_DLL_remove (plugins_head, plugins_tail, plug);
+ GNUNET_free (plug);
+ }
}
@@ -208,20 +197,16 @@
* @return statically allocated (!) human-readable address
*/
const char *
-GST_plugins_a2s (const char *name,
- const void *addr,
- size_t addrlen)
+GST_plugins_a2s (const char *name, const void *addr, size_t addrlen)
{
struct GNUNET_TRANSPORT_PluginFunctions *api;
if (name == NULL)
return NULL;
api = GST_plugins_find (name);
- if ( (api == NULL) || (addrlen == 0) || (addr == NULL) )
+ if ((api == NULL) || (addrlen == 0) || (addr == NULL))
return NULL;
- return api->address_to_string (NULL,
- addr,
- addrlen);
+ return api->address_to_string (NULL, addr, addrlen);
}
Modified: gnunet/src/transport/gnunet-service-transport_plugins.h
===================================================================
--- gnunet/src/transport/gnunet-service-transport_plugins.h 2011-08-15
21:40:08 UTC (rev 16580)
+++ gnunet/src/transport/gnunet-service-transport_plugins.h 2011-08-15
21:46:35 UTC (rev 16581)
@@ -42,17 +42,16 @@
* @param address_cb function to call when our public addresses changed
* @param session_end_cb function to call when a session was terminated
*/
-void
+void
GST_plugins_load (GNUNET_TRANSPORT_PluginReceiveCallback recv_cb,
- GNUNET_TRANSPORT_AddressNotification address_cb,
- GNUNET_TRANSPORT_SessionEnd session_end_cb);
+ GNUNET_TRANSPORT_AddressNotification address_cb,
+ GNUNET_TRANSPORT_SessionEnd session_end_cb);
/**
* Unload all plugins
*/
-void
-GST_plugins_unload (void);
+void GST_plugins_unload (void);
/**
@@ -61,8 +60,7 @@
* @param name name of the plugin
* @return the plugin's API, NULL if the plugin is not loaded
*/
-struct GNUNET_TRANSPORT_PluginFunctions *
-GST_plugins_find (const char *name);
+struct GNUNET_TRANSPORT_PluginFunctions *GST_plugins_find (const char *name);
/**
@@ -74,10 +72,8 @@
* @param addrlen number of bytes in 'addr'
* @return statically allocated (!) human-readable address
*/
-const char *
-GST_plugins_a2s (const char *name,
- const void *addr,
- size_t addrlen);
+const char *GST_plugins_a2s (const char *name,
+ const void *addr, size_t addrlen);
#endif
Modified: gnunet/src/transport/gnunet-service-transport_validation.c
===================================================================
--- gnunet/src/transport/gnunet-service-transport_validation.c 2011-08-15
21:40:08 UTC (rev 16580)
+++ gnunet/src/transport/gnunet-service-transport_validation.c 2011-08-15
21:46:35 UTC (rev 16581)
@@ -66,12 +66,12 @@
/**
* Priority to use for PINGs
- */
+ */
#define PING_PRIORITY 2
/**
* Priority to use for PONGs
- */
+ */
#define PONG_PRIORITY 4
@@ -154,7 +154,7 @@
/**
* Information about an address under validation
*/
-struct ValidationEntry
+struct ValidationEntry
{
/**
@@ -176,7 +176,7 @@
/**
* Public key of the peer.
*/
- struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key;
+ struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key;
/**
* The identity of the peer.
@@ -206,7 +206,7 @@
* otherwise a time in the future if we're currently denying re-validation
*/
struct GNUNET_TIME_Absolute validation_block;
-
+
/**
* Challenge number we used.
*/
@@ -277,7 +277,7 @@
* Where to store the result?
*/
struct ValidationEntry *ve;
-
+
/**
* Transport name we're looking for.
*/
@@ -305,20 +305,18 @@
* GNUNET_NO if the entry does match
*/
static int
-validation_entry_match (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+validation_entry_match (void *cls, const GNUNET_HashCode * key, void *value)
{
struct ValidationEntryMatchContext *vemc = cls;
struct ValidationEntry *ve = value;
- if ( (ve->addrlen == vemc->addrlen) &&
- (0 == memcmp (ve->addr, vemc->addr, ve->addrlen)) &&
- (0 == strcmp (ve->transport_name, vemc->transport_name)) )
- {
- vemc->ve = ve;
- return GNUNET_NO;
- }
+ if ((ve->addrlen == vemc->addrlen) &&
+ (0 == memcmp (ve->addr, vemc->addr, ve->addrlen)) &&
+ (0 == strcmp (ve->transport_name, vemc->transport_name)))
+ {
+ vemc->ve = ve;
+ return GNUNET_NO;
+ }
return GNUNET_YES;
}
@@ -340,11 +338,9 @@
* if we don't have an existing entry and no public key was given
*/
static struct ValidationEntry *
-find_validation_entry (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
*public_key,
- const struct GNUNET_PeerIdentity *neighbour,
- const char *tname,
- const char *addr,
- size_t addrlen)
+find_validation_entry (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
+ *public_key, const struct GNUNET_PeerIdentity
*neighbour,
+ const char *tname, const char *addr, size_t addrlen)
{
struct ValidationEntryMatchContext vemc;
struct ValidationEntry *ve;
@@ -354,26 +350,25 @@
vemc.addr = addr;
vemc.addrlen = addrlen;
GNUNET_CONTAINER_multihashmap_get_multiple (validation_map,
- &neighbour->hashPubKey,
- &validation_entry_match,
- &vemc);
+ &neighbour->hashPubKey,
+ &validation_entry_match, &vemc);
if (NULL != (ve = vemc.ve))
return ve;
if (public_key == NULL)
return NULL;
ve = GNUNET_malloc (sizeof (struct ValidationEntry) + addrlen);
ve->transport_name = GNUNET_strdup (tname);
- ve->addr = (void*) &ve[1];
+ ve->addr = (void *) &ve[1];
ve->public_key = *public_key;
ve->pid = *neighbour;
ve->challenge = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
- UINT32_MAX);
+ UINT32_MAX);
memcpy (&ve[1], addr, addrlen);
ve->addrlen = addrlen;
GNUNET_CONTAINER_multihashmap_put (validation_map,
- &neighbour->hashPubKey,
- ve,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
+ &neighbour->hashPubKey,
+ ve,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
return ve;
}
@@ -391,10 +386,9 @@
*/
static int
add_valid_address (void *cls,
- const char *tname,
- struct GNUNET_TIME_Absolute expiration,
- const void *addr,
- uint16_t addrlen)
+ const char *tname,
+ struct GNUNET_TIME_Absolute expiration,
+ const void *addr, uint16_t addrlen)
{
const struct GNUNET_HELLO_Message *hello = cls;
struct ValidationEntry *ve;
@@ -402,26 +396,20 @@
struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key;
if (GNUNET_TIME_absolute_get_remaining (expiration).rel_value == 0)
- return GNUNET_OK; /* expired */
- if ( (GNUNET_OK !=
- GNUNET_HELLO_get_id (hello, &pid)) ||
- (GNUNET_OK !=
- GNUNET_HELLO_get_key (hello, &public_key)) )
- {
- GNUNET_break (0);
- return GNUNET_OK; /* invalid HELLO !? */
- }
+ return GNUNET_OK; /* expired */
+ if ((GNUNET_OK !=
+ GNUNET_HELLO_get_id (hello, &pid)) ||
+ (GNUNET_OK != GNUNET_HELLO_get_key (hello, &public_key)))
+ {
+ GNUNET_break (0);
+ return GNUNET_OK; /* invalid HELLO !? */
+ }
ve = find_validation_entry (&public_key, &pid, tname, addr, addrlen);
- ve->valid_until = GNUNET_TIME_absolute_max (ve->valid_until,
- expiration);
+ ve->valid_until = GNUNET_TIME_absolute_max (ve->valid_until, expiration);
GNUNET_ATS_address_update (GST_ats,
- &pid,
- ve->valid_until,
- tname,
- NULL,
- addr,
- addrlen,
- NULL, 0);
+ &pid,
+ ve->valid_until,
+ tname, NULL, addr, addrlen, NULL, 0);
return GNUNET_OK;
}
@@ -436,31 +424,29 @@
*/
static void
process_peerinfo_hello (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_HELLO_Message *hello,
- const char *err_msg)
+ const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_HELLO_Message *hello,
+ const char *err_msg)
{
GNUNET_assert (NULL != peer);
if (NULL == hello)
return;
GNUNET_assert (NULL ==
- GNUNET_HELLO_iterate_addresses (hello,
- GNUNET_NO,
- &add_valid_address,
- (void*) hello));
+ GNUNET_HELLO_iterate_addresses (hello,
+ GNUNET_NO,
+ &add_valid_address,
+ (void *) hello));
}
/**
* Start the validation subsystem.
*/
-void
+void
GST_validation_start ()
{
validation_map = GNUNET_CONTAINER_multihashmap_create (VALIDATION_MAP_SIZE);
- pnc = GNUNET_PEERINFO_notify (GST_cfg,
- &process_peerinfo_hello,
- NULL);
+ pnc = GNUNET_PEERINFO_notify (GST_cfg, &process_peerinfo_hello, NULL);
}
@@ -473,27 +459,24 @@
* @return GNUNET_YES (continue to iterate)
*/
static int
-cleanup_validation_entry (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+cleanup_validation_entry (void *cls, const GNUNET_HashCode * key, void *value)
{
struct ValidationEntry *ve = value;
-
+
if (NULL != ve->bc)
- {
- GST_blacklist_test_cancel (ve->bc);
- ve->bc = NULL;
- }
+ {
+ GST_blacklist_test_cancel (ve->bc);
+ ve->bc = NULL;
+ }
GNUNET_break (GNUNET_OK ==
GNUNET_CONTAINER_multihashmap_remove (validation_map,
- &ve->pid.hashPubKey,
- ve));
+ &ve->pid.hashPubKey,
ve));
GNUNET_free (ve->transport_name);
if (GNUNET_SCHEDULER_NO_TASK != ve->timeout_task)
- {
- GNUNET_SCHEDULER_cancel (ve->timeout_task);
- ve->timeout_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (ve->timeout_task);
+ ve->timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ }
GNUNET_free (ve);
return GNUNET_OK;
}
@@ -508,17 +491,14 @@
struct CheckHelloValidatedContext *chvc;
GNUNET_CONTAINER_multihashmap_iterate (validation_map,
- &cleanup_validation_entry,
- NULL);
+ &cleanup_validation_entry, NULL);
GNUNET_CONTAINER_multihashmap_destroy (validation_map);
validation_map = NULL;
while (NULL != (chvc = chvc_head))
- {
- GNUNET_CONTAINER_DLL_remove (chvc_head,
- chvc_tail,
- chvc);
- GNUNET_free (chvc);
- }
+ {
+ GNUNET_CONTAINER_DLL_remove (chvc_head, chvc_tail, chvc);
+ GNUNET_free (chvc);
+ }
GNUNET_PEERINFO_notify_cancel (pnc);
}
@@ -530,16 +510,15 @@
* @param tc scheduler context (unused)
*/
static void
-timeout_hello_validation (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+timeout_hello_validation (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct ValidationEntry *ve = cls;
ve->timeout_task = GNUNET_SCHEDULER_NO_TASK;
GNUNET_STATISTICS_update (GST_stats,
- gettext_noop ("# address records discarded"),
- 1,
- GNUNET_NO);
+ gettext_noop ("# address records discarded"),
+ 1, GNUNET_NO);
cleanup_validation_entry (NULL, &ve->pid.hashPubKey, ve);
}
@@ -561,13 +540,12 @@
*/
static void
multicast_pong (void *cls,
- const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
*public_key,
- const struct GNUNET_PeerIdentity *target,
- struct GNUNET_TIME_Absolute valid_until,
- struct GNUNET_TIME_Absolute validation_block,
- const char *plugin_name,
- const void *plugin_address,
- size_t plugin_address_len)
+ const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
+ *public_key, const struct GNUNET_PeerIdentity *target,
+ struct GNUNET_TIME_Absolute valid_until,
+ struct GNUNET_TIME_Absolute validation_block,
+ const char *plugin_name, const void *plugin_address,
+ size_t plugin_address_len)
{
struct TransportPongMessage *pong = cls;
struct GNUNET_TRANSPORT_PluginFunctions *papi;
@@ -576,16 +554,14 @@
if (papi == NULL)
return;
(void) papi->send (papi->cls,
- target,
- (const char*) pong,
- ntohs (pong->header.size),
- PONG_PRIORITY,
- HELLO_REVALIDATION_START_TIME,
- NULL,
- plugin_address,
- plugin_address_len,
- GNUNET_YES,
- NULL, NULL);
+ target,
+ (const char *) pong,
+ ntohs (pong->header.size),
+ PONG_PRIORITY,
+ HELLO_REVALIDATION_START_TIME,
+ NULL,
+ plugin_address,
+ plugin_address_len, GNUNET_YES, NULL, NULL);
}
@@ -602,11 +578,11 @@
*/
void
GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
- const struct GNUNET_MessageHeader *hdr,
- const char *plugin_name,
- struct Session *session,
- const void *sender_address,
- size_t sender_address_len)
+ const struct GNUNET_MessageHeader *hdr,
+ const char *plugin_name,
+ struct Session *session,
+ const void *sender_address,
+ size_t sender_address_len)
{
const struct TransportPingMessage *ping;
struct TransportPongMessage *pong;
@@ -620,124 +596,113 @@
ssize_t ret;
if (ntohs (hdr->size) < sizeof (struct TransportPingMessage))
- {
- GNUNET_break_op (0);
- return;
- }
+ {
+ GNUNET_break_op (0);
+ return;
+ }
ping = (const struct TransportPingMessage *) hdr;
if (0 != memcmp (&ping->target,
- &GST_my_identity,
- sizeof (struct GNUNET_PeerIdentity)))
- {
- GNUNET_break_op (0);
- return;
- }
+ &GST_my_identity, sizeof (struct GNUNET_PeerIdentity)))
+ {
+ GNUNET_break_op (0);
+ return;
+ }
GNUNET_STATISTICS_update (GST_stats,
- gettext_noop ("# PING messages received"),
- 1,
- GNUNET_NO);
- addr = (const char*) &ping[1];
+ gettext_noop ("# PING messages received"),
+ 1, GNUNET_NO);
+ addr = (const char *) &ping[1];
alen = ntohs (hdr->size) - sizeof (struct TransportPingMessage);
/* peer wants to confirm that this is one of our addresses, this is what is
- used for address validation */
-
+ * used for address validation */
+
addrend = memchr (addr, '\0', alen);
if (NULL == addrend)
- {
- GNUNET_break_op (0);
- return;
- }
+ {
+ GNUNET_break_op (0);
+ return;
+ }
addrend++;
- slen = strlen(addr);
+ slen = strlen (addr);
alen -= slen;
-
+
if (GNUNET_YES !=
- 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));
- return;
- }
-
+ 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));
+ return;
+ }
+
pong = GNUNET_malloc (sizeof (struct TransportPongMessage) + alen + slen);
- pong->header.size = htons (sizeof (struct TransportPongMessage) + alen +
slen);
+ pong->header.size =
+ htons (sizeof (struct TransportPongMessage) + alen + slen);
pong->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PONG);
pong->purpose.size =
- htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
- sizeof (uint32_t) +
- sizeof (struct GNUNET_TIME_AbsoluteNBO) +
- alen + slen);
+ htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
+ sizeof (uint32_t) +
+ sizeof (struct GNUNET_TIME_AbsoluteNBO) + alen + slen);
pong->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN);
pong->challenge = ping->challenge;
- pong->addrlen = htonl(alen + slen);
+ pong->addrlen = htonl (alen + slen);
memcpy (&pong[1], addr, slen);
- memcpy (&((char*)&pong[1])[slen], addrend, alen);
- if (GNUNET_TIME_absolute_get_remaining (*sig_cache_exp).rel_value <
PONG_SIGNATURE_LIFETIME.rel_value / 4)
- {
- /* create / update cached sig */
+ memcpy (&((char *) &pong[1])[slen], addrend, alen);
+ if (GNUNET_TIME_absolute_get_remaining (*sig_cache_exp).rel_value <
+ PONG_SIGNATURE_LIFETIME.rel_value / 4)
+ {
+ /* create / update cached sig */
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Creating PONG signature to indicate ownership.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Creating PONG signature to indicate ownership.\n");
#endif
- *sig_cache_exp = GNUNET_TIME_relative_to_absolute
(PONG_SIGNATURE_LIFETIME);
- pong->expiration = GNUNET_TIME_absolute_hton (*sig_cache_exp);
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CRYPTO_rsa_sign (GST_my_private_key,
- &pong->purpose,
- sig_cache));
- }
+ *sig_cache_exp = GNUNET_TIME_relative_to_absolute
(PONG_SIGNATURE_LIFETIME);
+ pong->expiration = GNUNET_TIME_absolute_hton (*sig_cache_exp);
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CRYPTO_rsa_sign (GST_my_private_key,
+ &pong->purpose, sig_cache));
+ }
else
- {
- pong->expiration = GNUNET_TIME_absolute_hton (*sig_cache_exp);
- }
+ {
+ pong->expiration = GNUNET_TIME_absolute_hton (*sig_cache_exp);
+ }
pong->signature = *sig_cache;
/* first see if the session we got this PING from can be used to transmit
- a response reliably */
+ * a response reliably */
papi = GST_plugins_find (plugin_name);
if (papi == NULL)
ret = -1;
else
ret = papi->send (papi->cls,
- sender,
- (const char*) pong,
- ntohs (pong->header.size),
- PONG_PRIORITY,
- HELLO_REVALIDATION_START_TIME,
- session,
- sender_address,
- sender_address_len,
- GNUNET_SYSERR,
- NULL, NULL);
+ sender,
+ (const char *) pong,
+ ntohs (pong->header.size),
+ PONG_PRIORITY,
+ HELLO_REVALIDATION_START_TIME,
+ session,
+ sender_address,
+ sender_address_len, GNUNET_SYSERR, NULL, NULL);
if (ret != -1)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitted PONG to `%s' via reliable mechanism\n",
- GNUNET_i2s (sender));
- /* done! */
- GNUNET_STATISTICS_update (GST_stats,
- gettext_noop ("# PONGs unicast via reliable
transport"),
- 1,
- GNUNET_NO);
- GNUNET_free (pong);
- return;
- }
-
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Transmitted PONG to `%s' via reliable mechanism\n",
+ GNUNET_i2s (sender));
+ /* done! */
+ GNUNET_STATISTICS_update (GST_stats,
+ gettext_noop
+ ("# PONGs unicast via reliable transport"), 1,
+ GNUNET_NO);
+ GNUNET_free (pong);
+ return;
+ }
+
/* no reliable method found, try transmission via all known addresses */
GNUNET_STATISTICS_update (GST_stats,
- gettext_noop ("# PONGs multicast to all available
addresses"),
- 1,
- GNUNET_NO);
- GST_validation_get_addresses (sender,
- &multicast_pong,
- pong);
+ gettext_noop
+ ("# PONGs multicast to all available addresses"),
1,
+ GNUNET_NO);
+ GST_validation_get_addresses (sender, &multicast_pong, pong);
GNUNET_free (pong);
}
@@ -749,7 +714,7 @@
{
/**
* Hash of the public key of the peer whose address is being validated.
- */
+ */
struct GNUNET_PeerIdentity pid;
/**
@@ -769,8 +734,7 @@
*/
static void
transmit_ping_if_allowed (void *cls,
- const struct GNUNET_PeerIdentity *pid,
- int result)
+ const struct GNUNET_PeerIdentity *pid, int result)
{
struct ValidationEntry *ve = cls;
struct TransportPingMessage ping;
@@ -783,63 +747,55 @@
ve->bc = NULL;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitting plain PING to `%s'\n",
- GNUNET_i2s (pid));
- ping.header.size = htons(sizeof(struct TransportPingMessage));
- ping.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_PING);
- ping.challenge = htonl(ve->challenge);
+ "Transmitting plain PING to `%s'\n", GNUNET_i2s (pid));
+ ping.header.size = htons (sizeof (struct TransportPingMessage));
+ ping.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PING);
+ ping.challenge = htonl (ve->challenge);
ping.target = *pid;
-
- slen = strlen(ve->transport_name) + 1;
+
+ slen = strlen (ve->transport_name) + 1;
hello = GST_hello_get ();
hsize = ntohs (hello->size);
- tsize = sizeof(struct TransportPingMessage) + ve->addrlen + slen + hsize;
+ tsize = sizeof (struct TransportPingMessage) + ve->addrlen + slen + hsize;
if (tsize >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Not transmitting `%s' with `%s', message too big (%u
bytes!). This should not happen.\n"),
- "HELLO",
- "PING",
- (unsigned int) tsize);
- /* message too big (!?), get rid of HELLO */
- hsize = 0;
- tsize = sizeof(struct TransportPingMessage) + ve->addrlen + slen + hsize;
- }
{
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _
+ ("Not transmitting `%s' with `%s', message too big (%u
bytes!). This should not happen.\n"),
+ "HELLO", "PING", (unsigned int) tsize);
+ /* message too big (!?), get rid of HELLO */
+ hsize = 0;
+ tsize = sizeof (struct TransportPingMessage) + ve->addrlen + slen + hsize;
+ }
+ {
char message_buf[tsize];
- memcpy(message_buf, hello, hsize);
- memcpy(&message_buf[hsize], &ping, sizeof (struct TransportPingMessage));
- memcpy(&message_buf[sizeof (struct TransportPingMessage) + hsize],
- ve->transport_name,
- slen);
- memcpy(&message_buf[sizeof (struct TransportPingMessage) + slen + hsize],
- ve->addr,
- ve->addrlen);
+ memcpy (message_buf, hello, hsize);
+ memcpy (&message_buf[hsize], &ping, sizeof (struct TransportPingMessage));
+ memcpy (&message_buf[sizeof (struct TransportPingMessage) + hsize],
+ ve->transport_name, slen);
+ memcpy (&message_buf[sizeof (struct TransportPingMessage) + slen + hsize],
+ ve->addr, ve->addrlen);
papi = GST_plugins_find (ve->transport_name);
if (papi == NULL)
ret = -1;
else
ret = papi->send (papi->cls,
- pid,
- message_buf,
- tsize,
- PING_PRIORITY,
- HELLO_REVALIDATION_START_TIME,
- NULL /* no session */,
- ve->addr,
- ve->addrlen,
- GNUNET_YES,
- NULL, NULL);
+ pid,
+ message_buf,
+ tsize,
+ PING_PRIORITY,
+ HELLO_REVALIDATION_START_TIME, NULL /* no session */ ,
+ ve->addr, ve->addrlen, GNUNET_YES, NULL, NULL);
}
if (-1 != ret)
- {
- ve->send_time = GNUNET_TIME_absolute_get ();
- GNUNET_STATISTICS_update (GST_stats,
- gettext_noop ("# PING without HELLO messages
sent"),
- 1,
- GNUNET_NO);
- }
+ {
+ ve->send_time = GNUNET_TIME_absolute_get ();
+ GNUNET_STATISTICS_update (GST_stats,
+ gettext_noop
+ ("# PING without HELLO messages sent"), 1,
+ GNUNET_NO);
+ }
}
@@ -856,10 +812,9 @@
*/
static int
validate_address (void *cls,
- const char *tname,
- struct GNUNET_TIME_Absolute expiration,
- const void *addr,
- uint16_t addrlen)
+ const char *tname,
+ struct GNUNET_TIME_Absolute expiration,
+ const void *addr, uint16_t addrlen)
{
const struct ValidateAddressContext *vac = cls;
const struct GNUNET_PeerIdentity *pid = &vac->pid;
@@ -867,23 +822,21 @@
struct GST_BlacklistCheck *bc;
if (GNUNET_TIME_absolute_get_remaining (expiration).rel_value == 0)
- return GNUNET_OK; /* expired */
+ return GNUNET_OK; /* expired */
ve = find_validation_entry (&vac->public_key, pid, tname, addr, addrlen);
if (GNUNET_TIME_absolute_get_remaining (ve->validation_block).rel_value > 0)
- return GNUNET_OK; /* blocked */
- if ( (GNUNET_SCHEDULER_NO_TASK != ve->timeout_task) &&
- (GNUNET_TIME_absolute_get_remaining (ve->valid_until).rel_value > 0) )
- return GNUNET_OK; /* revalidation task already scheduled & still valid */
- ve->validation_block = GNUNET_TIME_relative_to_absolute
(HELLO_REVALIDATION_START_TIME);
+ return GNUNET_OK; /* blocked */
+ if ((GNUNET_SCHEDULER_NO_TASK != ve->timeout_task) &&
+ (GNUNET_TIME_absolute_get_remaining (ve->valid_until).rel_value > 0))
+ return GNUNET_OK; /* revalidation task already scheduled & still
valid */
+ ve->validation_block =
+ GNUNET_TIME_relative_to_absolute (HELLO_REVALIDATION_START_TIME);
if (GNUNET_SCHEDULER_NO_TASK != ve->timeout_task)
GNUNET_SCHEDULER_cancel (ve->timeout_task);
- ve->timeout_task = GNUNET_SCHEDULER_add_delayed
(HELLO_REVALIDATION_START_TIME,
- &timeout_hello_validation,
- ve);
- bc = GST_blacklist_test_allowed (pid,
- tname,
- &transmit_ping_if_allowed,
- ve);
+ ve->timeout_task =
+ GNUNET_SCHEDULER_add_delayed (HELLO_REVALIDATION_START_TIME,
+ &timeout_hello_validation, ve);
+ bc = GST_blacklist_test_allowed (pid, tname, &transmit_ping_if_allowed, ve);
if (NULL != bc)
ve->bc = bc;
return GNUNET_OK;
@@ -897,8 +850,7 @@
* @param tc scheduler context (unused)
*/
static void
-revalidate_address (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+revalidate_address (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct ValidationEntry *ve = cls;
struct GNUNET_TIME_Relative delay;
@@ -907,24 +859,20 @@
ve->timeout_task = GNUNET_SCHEDULER_NO_TASK;
delay = GNUNET_TIME_absolute_get_remaining (ve->validation_block);
if (delay.rel_value > 0)
- {
- /* should wait a bit longer */
- ve->timeout_task = GNUNET_SCHEDULER_add_delayed (delay,
- &revalidate_address,
- ve);
- return;
- }
+ {
+ /* should wait a bit longer */
+ ve->timeout_task = GNUNET_SCHEDULER_add_delayed (delay,
+ &revalidate_address, ve);
+ return;
+ }
GNUNET_STATISTICS_update (GST_stats,
- gettext_noop ("# address revalidations started"),
- 1,
- GNUNET_NO);
+ gettext_noop ("# address revalidations started"),
+ 1, GNUNET_NO);
vac.pid = ve->pid;
vac.public_key = ve->public_key;
validate_address (&vac,
- ve->transport_name,
- ve->valid_until,
- ve->addr,
- (uint16_t) ve->addrlen);
+ ve->transport_name,
+ ve->valid_until, ve->addr, (uint16_t) ve->addrlen);
}
@@ -936,18 +884,13 @@
* @param buf where to add the address
*/
static size_t
-add_valid_peer_address (void *cls,
- size_t max,
- void *buf)
+add_valid_peer_address (void *cls, size_t max, void *buf)
{
struct ValidationEntry *ve = cls;
return GNUNET_HELLO_add_address (ve->transport_name,
- ve->valid_until,
- ve->addr,
- ve->addrlen,
- buf,
- max);
+ ve->valid_until,
+ ve->addr, ve->addrlen, buf, max);
}
@@ -960,7 +903,7 @@
*/
void
GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
- const struct GNUNET_MessageHeader *hdr)
+ const struct GNUNET_MessageHeader *hdr)
{
const struct TransportPongMessage *pong;
struct ValidationEntry *ve;
@@ -973,97 +916,78 @@
struct GNUNET_HELLO_Message *hello;
if (ntohs (hdr->size) < sizeof (struct TransportPongMessage))
- {
- GNUNET_break_op (0);
- return;
- }
+ {
+ GNUNET_break_op (0);
+ return;
+ }
GNUNET_STATISTICS_update (GST_stats,
- gettext_noop ("# PONG messages received"),
- 1,
- GNUNET_NO);
+ gettext_noop ("# PONG messages received"),
+ 1, GNUNET_NO);
pong = (const struct TransportPongMessage *) hdr;
- addr = (const char*) &pong[1];
+ addr = (const char *) &pong[1];
alen = ntohs (hdr->size) - sizeof (struct TransportPongMessage);
addrend = memchr (addr, '\0', alen);
if (NULL == addrend)
- {
- GNUNET_break_op (0);
- return;
- }
+ {
+ GNUNET_break_op (0);
+ return;
+ }
addrend++;
- slen = strlen(addr);
+ slen = strlen (addr);
alen -= slen;
- ve = find_validation_entry (NULL,
- sender,
- addr,
- addrend,
- alen);
+ ve = find_validation_entry (NULL, sender, addr, addrend, alen);
if (NULL == ve)
- {
- GNUNET_STATISTICS_update (GST_stats,
- gettext_noop ("# PONGs dropped, no matching
pending validation"),
- 1,
- GNUNET_NO);
- return;
- }
+ {
+ GNUNET_STATISTICS_update (GST_stats,
+ gettext_noop
+ ("# PONGs dropped, no matching pending
validation"),
+ 1, GNUNET_NO);
+ return;
+ }
/* now check that PONG is well-formed */
- if (0 != memcmp (&ve->pid,
- sender,
- sizeof (struct GNUNET_PeerIdentity)))
- {
- GNUNET_break_op (0);
- return;
- }
+ if (0 != memcmp (&ve->pid, sender, sizeof (struct GNUNET_PeerIdentity)))
+ {
+ GNUNET_break_op (0);
+ return;
+ }
- if (GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh
(pong->expiration)).rel_value == 0)
- {
- GNUNET_STATISTICS_update (GST_stats,
- gettext_noop ("# PONGs dropped, signature
expired"),
- 1,
- GNUNET_NO);
- return;
- }
+ if (GNUNET_TIME_absolute_get_remaining
+ (GNUNET_TIME_absolute_ntoh (pong->expiration)).rel_value == 0)
+ {
+ GNUNET_STATISTICS_update (GST_stats,
+ gettext_noop
+ ("# PONGs dropped, signature expired"), 1,
+ GNUNET_NO);
+ return;
+ }
if (GNUNET_OK !=
GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN,
- &pong->purpose,
- &pong->signature,
- &ve->public_key))
- {
- GNUNET_break_op (0);
- return;
- }
-
+ &pong->purpose,
+ &pong->signature, &ve->public_key))
+ {
+ GNUNET_break_op (0);
+ return;
+ }
+
/* validity achieved, remember it! */
ve->valid_until = GNUNET_TIME_relative_to_absolute
(HELLO_ADDRESS_EXPIRATION);
- GNUNET_ATS_address_update (GST_ats,
- &ve->pid,
- ve->valid_until,
- ve->transport_name,
- NULL,
- ve->addr,
- ve->addrlen,
- NULL, 0); /* FIXME: compute and add latency
here... */
+ GNUNET_ATS_address_update (GST_ats, &ve->pid, ve->valid_until,
ve->transport_name, NULL, ve->addr, ve->addrlen, NULL, 0); /* FIXME:
compute and add latency here... */
/* build HELLO to store in PEERINFO */
- hello = GNUNET_HELLO_create (&ve->public_key,
- &add_valid_peer_address,
- ve);
- GNUNET_PEERINFO_add_peer (GST_peerinfo,
- hello);
+ hello = GNUNET_HELLO_create (&ve->public_key, &add_valid_peer_address, ve);
+ GNUNET_PEERINFO_add_peer (GST_peerinfo, hello);
GNUNET_free (hello);
if (GNUNET_SCHEDULER_NO_TASK != ve->timeout_task)
GNUNET_SCHEDULER_cancel (ve->timeout_task);
/* randomly delay by up to 1h to avoid synchronous validations */
- rdelay = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
- 60 * 60);
+ rdelay = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 60 * 60);
delay = GNUNET_TIME_relative_add (HELLO_REVALIDATION_START_TIME,
- GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_SECONDS,
- rdelay));
- ve->timeout_task = GNUNET_SCHEDULER_add_delayed (delay,
- &revalidate_address,
- ve);
+ GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, rdelay));
+ ve->timeout_task =
+ GNUNET_SCHEDULER_add_delayed (delay, &revalidate_address, ve);
}
@@ -1076,23 +1000,22 @@
void
GST_validation_handle_hello (const struct GNUNET_MessageHeader *hello)
{
- const struct GNUNET_HELLO_Message* hm = (const struct GNUNET_HELLO_Message*)
hello;
+ const struct GNUNET_HELLO_Message *hm =
+ (const struct GNUNET_HELLO_Message *) hello;
struct ValidateAddressContext vac;
- if ( (GNUNET_OK !=
- GNUNET_HELLO_get_id (hm, &vac.pid)) ||
- (GNUNET_OK !=
- GNUNET_HELLO_get_key (hm, &vac.public_key)) )
- {
- /* malformed HELLO */
- GNUNET_break (0);
- return;
- }
+ if ((GNUNET_OK !=
+ GNUNET_HELLO_get_id (hm, &vac.pid)) ||
+ (GNUNET_OK != GNUNET_HELLO_get_key (hm, &vac.public_key)))
+ {
+ /* malformed HELLO */
+ GNUNET_break (0);
+ return;
+ }
GNUNET_assert (NULL ==
- GNUNET_HELLO_iterate_addresses (hm,
- GNUNET_NO,
- &validate_address,
- &vac));
+ GNUNET_HELLO_iterate_addresses (hm,
+ GNUNET_NO,
+ &validate_address, &vac));
}
@@ -1123,21 +1046,16 @@
* @return GNUNET_OK (continue to iterate)
*/
static int
-iterate_addresses (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+iterate_addresses (void *cls, const GNUNET_HashCode * key, void *value)
{
struct IteratorContext *ic = cls;
struct ValidationEntry *ve = value;
ic->cb (ic->cb_cls,
- &ve->public_key,
- &ve->pid,
- ve->valid_until,
- ve->validation_block,
- ve->transport_name,
- ve->addr,
- ve->addrlen);
+ &ve->public_key,
+ &ve->pid,
+ ve->valid_until,
+ ve->validation_block, ve->transport_name, ve->addr, ve->addrlen);
return GNUNET_OK;
}
@@ -1156,17 +1074,15 @@
*/
void
GST_validation_get_addresses (const struct GNUNET_PeerIdentity *target,
- GST_ValidationAddressCallback cb,
- void *cb_cls)
+ GST_ValidationAddressCallback cb, void *cb_cls)
{
- struct IteratorContext ic;
+ struct IteratorContext ic;
ic.cb = cb;
ic.cb_cls = cb_cls;
GNUNET_CONTAINER_multihashmap_get_multiple (validation_map,
- &target->hashPubKey,
- &iterate_addresses,
- &ic);
+ &target->hashPubKey,
+ &iterate_addresses, &ic);
}
Modified: gnunet/src/transport/gnunet-service-transport_validation.h
===================================================================
--- gnunet/src/transport/gnunet-service-transport_validation.h 2011-08-15
21:40:08 UTC (rev 16580)
+++ gnunet/src/transport/gnunet-service-transport_validation.h 2011-08-15
21:46:35 UTC (rev 16581)
@@ -34,15 +34,13 @@
/**
* Start the validation subsystem.
*/
-void
-GST_validation_start (void);
+void GST_validation_start (void);
/**
* Stop the validation subsystem.
*/
-void
-GST_validation_stop (void);
+void GST_validation_stop (void);
/**
@@ -58,11 +56,11 @@
*/
void
GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
- const struct GNUNET_MessageHeader *hdr,
- const char *plugin_name,
- struct Session *session,
- const void *sender_address,
- size_t sender_address_len);
+ const struct GNUNET_MessageHeader *hdr,
+ const char *plugin_name,
+ struct Session *session,
+ const void *sender_address,
+ size_t sender_address_len);
/**
@@ -74,7 +72,7 @@
*/
void
GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
- const struct GNUNET_MessageHeader *hdr);
+ const struct GNUNET_MessageHeader *hdr);
/**
@@ -83,8 +81,7 @@
*
* @param hello the HELLO we received
*/
-void
-GST_validation_handle_hello (const struct GNUNET_MessageHeader *hello);
+void GST_validation_handle_hello (const struct GNUNET_MessageHeader *hello);
/**
@@ -103,14 +100,19 @@
* @param plugin_address binary address
* @param plugin_address_len length of address
*/
-typedef void (*GST_ValidationAddressCallback)(void *cls,
- const struct
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key,
- const struct GNUNET_PeerIdentity
*target,
- struct GNUNET_TIME_Absolute
valid_until,
- struct GNUNET_TIME_Absolute
validation_block,
- const char *plugin_name,
- const void *plugin_address,
- size_t plugin_address_len);
+typedef void (*GST_ValidationAddressCallback) (void *cls,
+ const struct
+
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
+ * public_key,
+ const struct GNUNET_PeerIdentity
+ * target,
+ struct GNUNET_TIME_Absolute
+ valid_until,
+ struct GNUNET_TIME_Absolute
+ validation_block,
+ const char *plugin_name,
+ const void *plugin_address,
+ size_t plugin_address_len);
/**
@@ -124,8 +126,7 @@
*/
void
GST_validation_get_addresses (const struct GNUNET_PeerIdentity *target,
- GST_ValidationAddressCallback cb,
- void *cb_cls);
+ GST_ValidationAddressCallback cb, void *cb_cls);
#endif
Modified: gnunet/src/transport/gnunet-transport-certificate-creation.c
===================================================================
--- gnunet/src/transport/gnunet-transport-certificate-creation.c
2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/transport/gnunet-transport-certificate-creation.c
2011-08-15 21:46:35 UTC (rev 16581)
@@ -29,20 +29,19 @@
#include "gnunet_os_lib.h"
-static void
-removecerts (const char *file1,
- const char *file2)
+static void
+removecerts (const char *file1, const char *file2)
{
if (GNUNET_DISK_file_test (file1) == GNUNET_YES)
- {
- CHMOD (file1, S_IWUSR | S_IRUSR);
- REMOVE (file1);
- }
+ {
+ CHMOD (file1, S_IWUSR | S_IRUSR);
+ REMOVE (file1);
+ }
if (GNUNET_DISK_file_test (file2) == GNUNET_YES)
- {
- CHMOD (file2, S_IWUSR | S_IRUSR);
- REMOVE (file2);
- }
+ {
+ CHMOD (file2, S_IWUSR | S_IRUSR);
+ REMOVE (file2);
+ }
}
@@ -54,27 +53,26 @@
if (argc != 3)
return 1;
removecerts (argv[1], argv[2]);
- close (2); /* eliminate stderr */
+ close (2); /* eliminate stderr */
/* Create RSA Private Key */
/* openssl genrsa -out $1 1024 2> /dev/null */
openssl = GNUNET_OS_start_process (NULL, NULL,
- "openssl",
- "openssl",
- "genrsa", "-out", argv[1], "1024",
- NULL);
+ "openssl",
+ "openssl",
+ "genrsa", "-out", argv[1], "1024", NULL);
if (openssl == NULL)
return 2;
GNUNET_assert (GNUNET_OS_process_wait (openssl) == GNUNET_OK);
GNUNET_OS_process_close (openssl);
-
- /* Create a self-signed certificate in batch mode using rsa key*/
+
+ /* Create a self-signed certificate in batch mode using rsa key */
/* openssl req -batch -days 365 -out $2 -new -x509 -key $1 2> /dev/null */
- openssl = GNUNET_OS_start_process (NULL, NULL,
- "openssl",
- "openssl",
- "req", "-batch", "-days", "365",
- "-out", argv[2], "-new", "-x509", "-key",
argv[1],
- NULL);
+ openssl = GNUNET_OS_start_process (NULL, NULL,
+ "openssl",
+ "openssl",
+ "req", "-batch", "-days", "365",
+ "-out", argv[2], "-new", "-x509", "-key",
+ argv[1], NULL);
if (openssl == NULL)
return 3;
GNUNET_assert (GNUNET_OS_process_wait (openssl) == GNUNET_OK);
Modified: gnunet/src/transport/gnunet-transport-list-connections.c
===================================================================
--- gnunet/src/transport/gnunet-transport-list-connections.c 2011-08-15
21:40:08 UTC (rev 16580)
+++ gnunet/src/transport/gnunet-transport-list-connections.c 2011-08-15
21:46:35 UTC (rev 16581)
@@ -41,7 +41,7 @@
static int no_resolve;
#if VERBOSE
- static unsigned int connection_count;
+static unsigned int connection_count;
#endif
static const struct GNUNET_CONFIGURATION_Handle *cfg;
@@ -53,14 +53,13 @@
* @param address NULL on error, otherwise 0-terminated printable UTF-8 string
*/
static void
-process_address (void *cls,
- const char *address)
+process_address (void *cls, const char *address)
{
#if VERBOSE
connection_count++;
#endif
if (address != NULL)
- fprintf(stdout, "%s\n", address);
+ fprintf (stdout, "%s\n", address);
}
@@ -75,18 +74,15 @@
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *c)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
{
cfg = c;
if (args[0] != NULL)
- {
- fprintf (stderr,
- _("Invalid command line argument `%s'\n"),
- args[0]);
- return;
- }
+ {
+ fprintf (stderr, _("Invalid command line argument `%s'\n"), args[0]);
+ return;
+ }
GNUNET_TRANSPORT_address_iterate (cfg,
GNUNET_TIME_UNIT_MINUTES,
@@ -114,7 +110,8 @@
GNUNET_PROGRAM_run (argc,
argv,
"gnunet-list-connections",
- gettext_noop ("Print information about connected
peers."),
+ gettext_noop
+ ("Print information about connected peers."),
options, &run, NULL)) ? 0 : 1;
}
Modified: gnunet/src/transport/gnunet-transport-wlan-helper.c
===================================================================
--- gnunet/src/transport/gnunet-transport-wlan-helper.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/transport/gnunet-transport-wlan-helper.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -108,11 +108,11 @@
};
// FIXME: inline?
-int getChannelFromFrequency(int frequency);
+int getChannelFromFrequency (int frequency);
// FIXME: make nice...
static unsigned long
-calc_crc_osdep(unsigned char * buf, int len)
+calc_crc_osdep (unsigned char *buf, int len)
{
unsigned long crc = 0xFFFFFFFF;
@@ -126,44 +126,46 @@
// FIXME: make nice...
static int
-check_crc_buf_osdep(unsigned char *buf, int len)
+check_crc_buf_osdep (unsigned char *buf, int len)
{
unsigned long crc;
if (0 > len)
return 0;
- crc = calc_crc_osdep(buf, len);
+ crc = calc_crc_osdep (buf, len);
buf += len;
return (((crc) & 0xFF) == buf[0] && ((crc >> 8) & 0xFF) == buf[1] && ((crc
- >> 16) & 0xFF) == buf[2] && ((crc >> 24) & 0xFF) == buf[3]);
+ >> 16)
+ & 0xFF)
+ == buf[2] && ((crc >> 24) & 0xFF) == buf[3]);
}
// FIXME: make nice...
static int
-linux_get_channel(struct Hardware_Infos *dev)
+linux_get_channel (struct Hardware_Infos *dev)
{
struct iwreq wrq;
int fd, frequency;
int chan = 0;
- memset(&wrq, 0, sizeof(struct iwreq));
+ memset (&wrq, 0, sizeof (struct iwreq));
- strncpy(wrq.ifr_name, dev->iface, IFNAMSIZ );
+ strncpy (wrq.ifr_name, dev->iface, IFNAMSIZ);
fd = dev->fd_raw;
- if (0 > ioctl(fd, SIOCGIWFREQ, &wrq))
+ if (0 > ioctl (fd, SIOCGIWFREQ, &wrq))
return (-1);
frequency = wrq.u.freq.m;
- if (100000000 < frequency )
+ if (100000000 < frequency)
frequency /= 100000;
- else if (1000000 < frequency )
+ else if (1000000 < frequency)
frequency /= 1000;
if (1000 < frequency)
- chan = getChannelFromFrequency(frequency);
+ chan = getChannelFromFrequency (frequency);
else
chan = frequency;
@@ -173,10 +175,8 @@
// FIXME: make nice...
static ssize_t
-linux_read (struct Hardware_Infos *dev,
- unsigned char *buf, /* FIXME: void*? */
- size_t buf_size,
- struct Radiotap_rx *ri)
+linux_read (struct Hardware_Infos *dev, unsigned char *buf, /* FIXME:
void*? */
+ size_t buf_size, struct Radiotap_rx *ri)
{
unsigned char tmpbuf[buf_size];
ssize_t caplen;
@@ -184,178 +184,175 @@
n = got_signal = got_noise = got_channel = fcs_removed = 0;
- caplen = read(dev->fd_raw, tmpbuf, buf_size);
+ caplen = read (dev->fd_raw, tmpbuf, buf_size);
if (0 > caplen)
+ {
+ if (EAGAIN == errno)
+ return 0;
+ fprintf (stderr, "Failed to read from RAW socket: %s\n", strerror (errno));
+ return -1;
+ }
+
+ memset (buf, 0, buf_size);
+ memset (ri, 0, sizeof (*ri));
+
+ switch (dev->arptype_in)
+ {
+ case ARPHRD_IEEE80211_PRISM:
+ {
+ /* skip the prism header */
+ if (tmpbuf[7] == 0x40)
{
- if (EAGAIN == errno)
- return 0;
- fprintf (stderr,
- "Failed to read from RAW socket: %s\n",
- strerror (errno));
- return -1;
+ /* prism54 uses a different format */
+ ri->ri_power = tmpbuf[0x33];
+ ri->ri_noise = *(unsigned int *) (tmpbuf + 0x33 + 12);
+ ri->ri_rate = (*(unsigned int *) (tmpbuf + 0x33 + 24)) * 500000;
+ got_signal = 1;
+ got_noise = 1;
+ n = 0x40;
}
+ else
+ {
+ ri->ri_mactime = *(u_int64_t *) (tmpbuf + 0x5C - 48);
+ ri->ri_channel = *(unsigned int *) (tmpbuf + 0x5C - 36);
+ ri->ri_power = *(unsigned int *) (tmpbuf + 0x5C);
+ ri->ri_noise = *(unsigned int *) (tmpbuf + 0x5C + 12);
+ ri->ri_rate = (*(unsigned int *) (tmpbuf + 0x5C + 24)) * 500000;
+ got_channel = 1;
+ got_signal = 1;
+ got_noise = 1;
+ n = *(int *) (tmpbuf + 4);
+ }
- memset(buf, 0, buf_size);
- memset(ri, 0, sizeof(*ri));
+ if (n < 8 || n >= caplen)
+ return (0);
+ }
+ break;
- switch (dev->arptype_in)
+ case ARPHRD_IEEE80211_FULL:
+ {
+ struct ieee80211_radiotap_iterator iterator;
+ struct ieee80211_radiotap_header *rthdr;
+
+ rthdr = (struct ieee80211_radiotap_header *) tmpbuf;
+
+ if (ieee80211_radiotap_iterator_init (&iterator, rthdr, caplen) < 0)
+ return (0);
+
+ /* go through the radiotap arguments we have been given
+ * by the driver
+ */
+
+ while (ieee80211_radiotap_iterator_next (&iterator) >= 0)
{
- case ARPHRD_IEEE80211_PRISM:
- {
- /* skip the prism header */
- if (tmpbuf[7] == 0x40)
- {
- /* prism54 uses a different format */
- ri->ri_power = tmpbuf[0x33];
- ri->ri_noise = *(unsigned int *) (tmpbuf + 0x33 + 12);
- ri->ri_rate = (*(unsigned int *) (tmpbuf + 0x33 + 24)) * 500000;
- got_signal = 1;
- got_noise = 1;
- n = 0x40;
- }
- else
- {
- ri->ri_mactime = *(u_int64_t*) (tmpbuf + 0x5C - 48);
- ri->ri_channel = *(unsigned int *) (tmpbuf + 0x5C - 36);
- ri->ri_power = *(unsigned int *) (tmpbuf + 0x5C);
- ri->ri_noise = *(unsigned int *) (tmpbuf + 0x5C + 12);
- ri->ri_rate = (*(unsigned int *) (tmpbuf + 0x5C + 24)) * 500000;
- got_channel = 1;
- got_signal = 1;
- got_noise = 1;
- n = *(int *) (tmpbuf + 4);
- }
-
- if (n < 8 || n >= caplen)
- return (0);
- }
- break;
- case ARPHRD_IEEE80211_FULL:
+ switch (iterator.this_arg_index)
{
- struct ieee80211_radiotap_iterator iterator;
- struct ieee80211_radiotap_header *rthdr;
-
- rthdr = (struct ieee80211_radiotap_header *) tmpbuf;
-
- if (ieee80211_radiotap_iterator_init(&iterator, rthdr, caplen) < 0)
- return (0);
-
- /* go through the radiotap arguments we have been given
- * by the driver
- */
-
- while (ieee80211_radiotap_iterator_next(&iterator) >= 0)
- {
-
- switch (iterator.this_arg_index)
- {
-
- case IEEE80211_RADIOTAP_TSFT:
- ri->ri_mactime = le64_to_cpu(*((uint64_t*) iterator.this_arg));
- break;
-
- case IEEE80211_RADIOTAP_DBM_ANTSIGNAL:
- if (!got_signal)
- {
- if (*iterator.this_arg < 127)
- ri->ri_power = *iterator.this_arg;
- else
- ri->ri_power = *iterator.this_arg - 255;
-
- got_signal = 1;
- }
- break;
-
- case IEEE80211_RADIOTAP_DB_ANTSIGNAL:
- if (!got_signal)
- {
- if (*iterator.this_arg < 127)
- ri->ri_power = *iterator.this_arg;
- else
- ri->ri_power = *iterator.this_arg - 255;
-
- got_signal = 1;
- }
- break;
-
- case IEEE80211_RADIOTAP_DBM_ANTNOISE:
- if (!got_noise)
- {
- if (*iterator.this_arg < 127)
- ri->ri_noise = *iterator.this_arg;
- else
- ri->ri_noise = *iterator.this_arg - 255;
-
- got_noise = 1;
- }
- break;
-
- case IEEE80211_RADIOTAP_DB_ANTNOISE:
- if (!got_noise)
- {
- if (*iterator.this_arg < 127)
- ri->ri_noise = *iterator.this_arg;
- else
- ri->ri_noise = *iterator.this_arg - 255;
-
- got_noise = 1;
- }
- break;
-
- case IEEE80211_RADIOTAP_ANTENNA:
- ri->ri_antenna = *iterator.this_arg;
- break;
-
- case IEEE80211_RADIOTAP_CHANNEL:
- ri->ri_channel = *iterator.this_arg;
- got_channel = 1;
- break;
-
- case IEEE80211_RADIOTAP_RATE:
- ri->ri_rate = (*iterator.this_arg) * 500000;
- break;
-
- case IEEE80211_RADIOTAP_FLAGS:
- /* is the CRC visible at the end?
- * remove
- */
- if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FCS)
- {
- fcs_removed = 1;
- caplen -= 4;
- }
-
- if (*iterator.this_arg & IEEE80211_RADIOTAP_F_RX_BADFCS)
- return (0);
-
- break;
- }
- }
- n = le16_to_cpu(rthdr->it_len);
- if (n <= 0 || n >= caplen)
- return 0;
+
+ case IEEE80211_RADIOTAP_TSFT:
+ ri->ri_mactime = le64_to_cpu (*((uint64_t *) iterator.this_arg));
+ break;
+
+ case IEEE80211_RADIOTAP_DBM_ANTSIGNAL:
+ if (!got_signal)
+ {
+ if (*iterator.this_arg < 127)
+ ri->ri_power = *iterator.this_arg;
+ else
+ ri->ri_power = *iterator.this_arg - 255;
+
+ got_signal = 1;
+ }
+ break;
+
+ case IEEE80211_RADIOTAP_DB_ANTSIGNAL:
+ if (!got_signal)
+ {
+ if (*iterator.this_arg < 127)
+ ri->ri_power = *iterator.this_arg;
+ else
+ ri->ri_power = *iterator.this_arg - 255;
+
+ got_signal = 1;
+ }
+ break;
+
+ case IEEE80211_RADIOTAP_DBM_ANTNOISE:
+ if (!got_noise)
+ {
+ if (*iterator.this_arg < 127)
+ ri->ri_noise = *iterator.this_arg;
+ else
+ ri->ri_noise = *iterator.this_arg - 255;
+
+ got_noise = 1;
+ }
+ break;
+
+ case IEEE80211_RADIOTAP_DB_ANTNOISE:
+ if (!got_noise)
+ {
+ if (*iterator.this_arg < 127)
+ ri->ri_noise = *iterator.this_arg;
+ else
+ ri->ri_noise = *iterator.this_arg - 255;
+
+ got_noise = 1;
+ }
+ break;
+
+ case IEEE80211_RADIOTAP_ANTENNA:
+ ri->ri_antenna = *iterator.this_arg;
+ break;
+
+ case IEEE80211_RADIOTAP_CHANNEL:
+ ri->ri_channel = *iterator.this_arg;
+ got_channel = 1;
+ break;
+
+ case IEEE80211_RADIOTAP_RATE:
+ ri->ri_rate = (*iterator.this_arg) * 500000;
+ break;
+
+ case IEEE80211_RADIOTAP_FLAGS:
+ /* is the CRC visible at the end?
+ * remove
+ */
+ if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FCS)
+ {
+ fcs_removed = 1;
+ caplen -= 4;
+ }
+
+ if (*iterator.this_arg & IEEE80211_RADIOTAP_F_RX_BADFCS)
+ return (0);
+
+ break;
}
- break;
- case ARPHRD_IEEE80211:
- /* do nothing? */
- break;
- default:
- errno = ENOTSUP;
- return -1;
}
+ n = le16_to_cpu (rthdr->it_len);
+ if (n <= 0 || n >= caplen)
+ return 0;
+ }
+ break;
+ case ARPHRD_IEEE80211:
+ /* do nothing? */
+ break;
+ default:
+ errno = ENOTSUP;
+ return -1;
+ }
caplen -= n;
//detect fcs at the end, even if the flag wasn't set and remove it
- if ( (0 == fcs_removed) &&
- (1 == check_crc_buf_osdep(tmpbuf + n, caplen - 4)) )
- {
- caplen -= 4;
- }
- memcpy(buf, tmpbuf + n, caplen);
- if (! got_channel)
- ri->ri_channel = linux_get_channel(dev);
+ if ((0 == fcs_removed) && (1 == check_crc_buf_osdep (tmpbuf + n, caplen -
4)))
+ {
+ caplen -= 4;
+ }
+ memcpy (buf, tmpbuf + n, caplen);
+ if (!got_channel)
+ ri->ri_channel = linux_get_channel (dev);
return caplen;
}
@@ -373,122 +370,108 @@
struct sockaddr_ll sll;
/* find the interface index */
- memset(&ifr, 0, sizeof(ifr));
- strncpy(ifr.ifr_name, dev->iface, IFNAMSIZ);
- if (-1 == ioctl(dev->fd_raw, SIOCGIFINDEX, &ifr))
- {
- fprintf (stderr,
- "Line: 381 ioctl(SIOCGIFINDEX) on interface `%.*s' failed: %s\n",
- IFNAMSIZ,
- dev->iface,
- strerror (errno));
- return 1;
- }
+ memset (&ifr, 0, sizeof (ifr));
+ strncpy (ifr.ifr_name, dev->iface, IFNAMSIZ);
+ if (-1 == ioctl (dev->fd_raw, SIOCGIFINDEX, &ifr))
+ {
+ fprintf (stderr,
+ "Line: 381 ioctl(SIOCGIFINDEX) on interface `%.*s' failed: %s\n",
+ IFNAMSIZ, dev->iface, strerror (errno));
+ return 1;
+ }
/* lookup the hardware type */
- memset (&sll, 0, sizeof(sll));
+ memset (&sll, 0, sizeof (sll));
sll.sll_family = AF_PACKET;
sll.sll_ifindex = ifr.ifr_ifindex;
- sll.sll_protocol = htons(ETH_P_ALL);
- if (-1 == ioctl(dev->fd_raw, SIOCGIFHWADDR, &ifr))
- {
- fprintf (stderr,
- "ioctl(SIOCGIFHWADDR) on interface `%.*s' failed: %s\n",
- IFNAMSIZ,
- dev->iface,
- strerror (errno));
- return 1;
- }
+ sll.sll_protocol = htons (ETH_P_ALL);
+ if (-1 == ioctl (dev->fd_raw, SIOCGIFHWADDR, &ifr))
+ {
+ fprintf (stderr,
+ "ioctl(SIOCGIFHWADDR) on interface `%.*s' failed: %s\n",
+ IFNAMSIZ, dev->iface, strerror (errno));
+ return 1;
+ }
/* lookup iw mode */
- memset(&wrq, 0, sizeof(struct iwreq));
- strncpy(wrq.ifr_name, dev->iface, IFNAMSIZ);
- if (-1 == ioctl(dev->fd_raw, SIOCGIWMODE, &wrq))
- {
- /* most probably not supported (ie for rtap ipw interface) *
- * so just assume its correctly set... */
- wrq.u.mode = IW_MODE_MONITOR;
- }
+ memset (&wrq, 0, sizeof (struct iwreq));
+ strncpy (wrq.ifr_name, dev->iface, IFNAMSIZ);
+ if (-1 == ioctl (dev->fd_raw, SIOCGIWMODE, &wrq))
+ {
+ /* most probably not supported (ie for rtap ipw interface) *
+ * so just assume its correctly set... */
+ wrq.u.mode = IW_MODE_MONITOR;
+ }
- if ( ( (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211) &&
- (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_PRISM) &&
- (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_FULL) ) ||
- (wrq.u.mode != IW_MODE_MONITOR) )
- {
- fprintf (stderr,
- "Error: interface `%.*s' is not in monitor mode\n",
- IFNAMSIZ,
- dev->iface);
- return 1;
- }
+ if (((ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211) &&
+ (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_PRISM) &&
+ (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_FULL)) ||
+ (wrq.u.mode != IW_MODE_MONITOR))
+ {
+ fprintf (stderr,
+ "Error: interface `%.*s' is not in monitor mode\n",
+ IFNAMSIZ, dev->iface);
+ return 1;
+ }
/* Is interface st to up, broadcast & running ? */
if ((ifr.ifr_flags | IFF_UP | IFF_BROADCAST | IFF_RUNNING) != ifr.ifr_flags)
- {
- /* Bring interface up*/
- ifr.ifr_flags |= IFF_UP | IFF_BROADCAST | IFF_RUNNING;
+ {
+ /* Bring interface up */
+ ifr.ifr_flags |= IFF_UP | IFF_BROADCAST | IFF_RUNNING;
- if (-1 == ioctl(dev->fd_raw, SIOCSIFFLAGS, &ifr))
- {
- fprintf (stderr,
- "Line: 434 ioctl(SIOCSIFFLAGS) on interface `%.*s' failed:
%s\n",
- IFNAMSIZ,
- dev->iface,
- strerror (errno));
- return 1;
- }
- }
-
- /* bind the raw socket to the interface */
- if (-1 == bind(dev->fd_raw, (struct sockaddr *) &sll, sizeof(sll)))
+ if (-1 == ioctl (dev->fd_raw, SIOCSIFFLAGS, &ifr))
{
fprintf (stderr,
- "Failed to bind interface `%.*s': %s\n",
- IFNAMSIZ,
- dev->iface,
- strerror (errno));
+ "Line: 434 ioctl(SIOCSIFFLAGS) on interface `%.*s' failed:
%s\n",
+ IFNAMSIZ, dev->iface, strerror (errno));
return 1;
}
+ }
+ /* bind the raw socket to the interface */
+ if (-1 == bind (dev->fd_raw, (struct sockaddr *) &sll, sizeof (sll)))
+ {
+ fprintf (stderr,
+ "Failed to bind interface `%.*s': %s\n",
+ IFNAMSIZ, dev->iface, strerror (errno));
+ return 1;
+ }
+
/* lookup the hardware type */
- if (-1 == ioctl(dev->fd_raw, SIOCGIFHWADDR, &ifr))
- {
- fprintf (stderr,
- "Line: 457 ioctl(SIOCGIFHWADDR) on interface `%.*s' failed:
%s\n",
- IFNAMSIZ,
- dev->iface,
- strerror (errno));
- return 1;
- }
+ if (-1 == ioctl (dev->fd_raw, SIOCGIFHWADDR, &ifr))
+ {
+ fprintf (stderr,
+ "Line: 457 ioctl(SIOCGIFHWADDR) on interface `%.*s' failed: %s\n",
+ IFNAMSIZ, dev->iface, strerror (errno));
+ return 1;
+ }
- memcpy (dev->pl_mac,
- ifr.ifr_hwaddr.sa_data,
- MAC_ADDR_SIZE);
+ memcpy (dev->pl_mac, ifr.ifr_hwaddr.sa_data, MAC_ADDR_SIZE);
dev->arptype_in = ifr.ifr_hwaddr.sa_family;
- if ( (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211) &&
- (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_PRISM) &&
- (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_FULL) )
- {
- fprintf (stderr,
- "Unsupported hardware link type %d on interface `%.*s'\n",
- ifr.ifr_hwaddr.sa_family,
- IFNAMSIZ,
- dev->iface);
- return 1;
- }
+ if ((ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211) &&
+ (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_PRISM) &&
+ (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_FULL))
+ {
+ fprintf (stderr,
+ "Unsupported hardware link type %d on interface `%.*s'\n",
+ ifr.ifr_hwaddr.sa_family, IFNAMSIZ, dev->iface);
+ return 1;
+ }
/* enable promiscuous mode */
- memset(&mr, 0, sizeof(mr));
+ memset (&mr, 0, sizeof (mr));
mr.mr_ifindex = sll.sll_ifindex;
mr.mr_type = PACKET_MR_PROMISC;
- if (0 != setsockopt(dev->fd_raw, SOL_PACKET, PACKET_ADD_MEMBERSHIP, &mr,
sizeof(mr)))
- {
- fprintf (stderr,
- "Failed to enable promiscuous mode on interface `%.*s'\n",
- IFNAMSIZ,
- dev->iface);
- return 1;
- }
+ if (0 !=
+ setsockopt (dev->fd_raw, SOL_PACKET, PACKET_ADD_MEMBERSHIP, &mr,
+ sizeof (mr)))
+ {
+ fprintf (stderr,
+ "Failed to enable promiscuous mode on interface `%.*s'\n",
+ IFNAMSIZ, dev->iface);
+ return 1;
+ }
return 0;
}
@@ -497,52 +480,43 @@
* @return 0 on success
*/
static int
-wlaninit (struct Hardware_Infos *dev,
- const char *iface)
+wlaninit (struct Hardware_Infos *dev, const char *iface)
{
char strbuf[512];
struct stat sbuf;
int ret;
- dev->fd_raw = socket (PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
+ dev->fd_raw = socket (PF_PACKET, SOCK_RAW, htons (ETH_P_ALL));
if (0 > dev->fd_raw)
- {
- fprintf (stderr,
- "Failed to create raw socket: %s\n",
- strerror (errno));
- return 1;
- }
+ {
+ fprintf (stderr, "Failed to create raw socket: %s\n", strerror (errno));
+ return 1;
+ }
if (dev->fd_raw >= FD_SETSIZE)
- {
- fprintf (stderr,
- "File descriptor too large for select (%d > %d)\n",
- dev->fd_raw,
- FD_SETSIZE);
- close (dev->fd_raw);
- return 1;
- }
+ {
+ fprintf (stderr,
+ "File descriptor too large for select (%d > %d)\n",
+ dev->fd_raw, FD_SETSIZE);
+ close (dev->fd_raw);
+ return 1;
+ }
/* mac80211 stack detection */
- ret = snprintf(strbuf,
- sizeof(strbuf),
- "/sys/class/net/%s/phy80211/subsystem",
- iface);
- if ( (ret < 0) ||
- (ret >= sizeof (strbuf)) ||
- (0 != stat(strbuf, &sbuf)) )
- {
- fprintf(stderr,
- "Did not find 802.11 interface `%s'. Exiting.\n",
- iface);
- close (dev->fd_raw);
- return 1;
- }
- strncpy(dev->iface, iface, IFNAMSIZ);
- if (0 != openraw(dev))
- {
- close(dev->fd_raw);
- return 1;
- }
+ ret = snprintf (strbuf,
+ sizeof (strbuf),
+ "/sys/class/net/%s/phy80211/subsystem", iface);
+ if ((ret < 0) || (ret >= sizeof (strbuf)) || (0 != stat (strbuf, &sbuf)))
+ {
+ fprintf (stderr, "Did not find 802.11 interface `%s'. Exiting.\n", iface);
+ close (dev->fd_raw);
+ return 1;
+ }
+ strncpy (dev->iface, iface, IFNAMSIZ);
+ if (0 != openraw (dev))
+ {
+ close (dev->fd_raw);
+ return 1;
+ }
return 0;
}
@@ -555,14 +529,14 @@
* @return 0 if mac belongs to us, 1 if mac is for another target
*/
static int
-mac_test (const struct ieee80211_frame *u8aIeeeHeader,
- const struct Hardware_Infos *dev)
+mac_test (const struct ieee80211_frame *u8aIeeeHeader,
+ const struct Hardware_Infos *dev)
{
- if (0 != memcmp(u8aIeeeHeader->i_addr3, &mac_bssid, MAC_ADDR_SIZE))
+ if (0 != memcmp (u8aIeeeHeader->i_addr3, &mac_bssid, MAC_ADDR_SIZE))
return 1;
- if (0 == memcmp(u8aIeeeHeader->i_addr1, dev->pl_mac, MAC_ADDR_SIZE))
+ if (0 == memcmp (u8aIeeeHeader->i_addr1, dev->pl_mac, MAC_ADDR_SIZE))
return 0;
- if (0 == memcmp(u8aIeeeHeader->i_addr1, &bc_all_mac, MAC_ADDR_SIZE))
+ if (0 == memcmp (u8aIeeeHeader->i_addr1, &bc_all_mac, MAC_ADDR_SIZE))
return 0;
return 1;
}
@@ -574,17 +548,13 @@
* @param dev pointer to the Hardware_Infos struct
*/
static void
-mac_set (struct ieee80211_frame *u8aIeeeHeader,
- const struct Hardware_Infos * dev)
+mac_set (struct ieee80211_frame *u8aIeeeHeader,
+ const struct Hardware_Infos *dev)
{
u8aIeeeHeader->i_fc[0] = 0x08;
u8aIeeeHeader->i_fc[1] = 0x00;
- memcpy(u8aIeeeHeader->i_addr2,
- dev->pl_mac,
- MAC_ADDR_SIZE);
- memcpy(u8aIeeeHeader->i_addr3,
- &mac_bssid,
- MAC_ADDR_SIZE);
+ memcpy (u8aIeeeHeader->i_addr2, dev->pl_mac, MAC_ADDR_SIZE);
+ memcpy (u8aIeeeHeader->i_addr3, &mac_bssid, MAC_ADDR_SIZE);
}
@@ -597,138 +567,140 @@
};
static void
-stdin_send_hw (void *cls,
- void *client,
- const struct GNUNET_MessageHeader *hdr)
+stdin_send_hw (void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
{
- struct Hardware_Infos * dev = cls;
+ struct Hardware_Infos *dev = cls;
struct sendbuf *write_pout = &dev->write_pout;
- struct Radiotap_Send * header = (struct Radiotap_Send *) &hdr[1];
- struct ieee80211_frame * wlanheader;
+ struct Radiotap_Send *header = (struct Radiotap_Send *) &hdr[1];
+ struct ieee80211_frame *wlanheader;
size_t sendsize;
// struct? // FIXME: make nice...
struct RadioTapheader rtheader;
+
rtheader.header.it_version = 0;
- rtheader.header.it_len = htole16(0x0c);
- rtheader.header.it_present = htole32(0x00008004);
+ rtheader.header.it_len = htole16 (0x0c);
+ rtheader.header.it_present = htole32 (0x00008004);
rtheader.rate = 0x00;
- rtheader.txflags = htole16(IEEE80211_RADIOTAP_F_TX_NOACK |
IEEE80211_RADIOTAP_F_TX_NOSEQ);
+ rtheader.txflags =
+ htole16 (IEEE80211_RADIOTAP_F_TX_NOACK | IEEE80211_RADIOTAP_F_TX_NOSEQ);
/* { 0x00, 0x00, <-- radiotap version
- 0x0c, 0x00, <- radiotap header length
- 0x04, 0x80, 0x00, 0x00, <-- bitmap
- 0x00, <-- rate
- 0x00, <-- padding for natural alignment
- 0x18, 0x00, <-- TX flags
- };*/
+ * 0x0c, 0x00, <- radiotap header length
+ * 0x04, 0x80, 0x00, 0x00, <-- bitmap
+ * 0x00, <-- rate
+ * 0x00, <-- padding for natural alignment
+ * 0x18, 0x00, <-- TX flags
+ * }; */
- sendsize = ntohs(hdr->size);
- if (sendsize < sizeof(struct Radiotap_Send) + sizeof(struct
GNUNET_MessageHeader))
- {
- fprintf(stderr,
- "Function stdin_send_hw: mailformed packet (too small)\n");
- exit (1);
- }
- sendsize -= sizeof(struct Radiotap_Send) + sizeof(struct
GNUNET_MessageHeader);
+ sendsize = ntohs (hdr->size);
+ if (sendsize <
+ sizeof (struct Radiotap_Send) + sizeof (struct GNUNET_MessageHeader))
+ {
+ fprintf (stderr, "Function stdin_send_hw: mailformed packet (too
small)\n");
+ exit (1);
+ }
+ sendsize -=
+ sizeof (struct Radiotap_Send) + sizeof (struct GNUNET_MessageHeader);
if (MAXLINE < sendsize)
- {
- fprintf(stderr,
- "Function stdin_send_hw: Packet too big for buffer\n");
- exit(1);
- }
- if (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA != ntohs(hdr->type))
- {
- fprintf(stderr, "Function stdin_send: wrong packet type\n");
- exit(1);
- }
+ {
+ fprintf (stderr, "Function stdin_send_hw: Packet too big for buffer\n");
+ exit (1);
+ }
+ if (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA != ntohs (hdr->type))
+ {
+ fprintf (stderr, "Function stdin_send: wrong packet type\n");
+ exit (1);
+ }
- rtheader.header.it_len = htole16(sizeof(rtheader));
+ rtheader.header.it_len = htole16 (sizeof (rtheader));
rtheader.rate = header->rate;
- memcpy(write_pout->buf, &rtheader, sizeof(rtheader));
- memcpy(write_pout->buf + sizeof(rtheader), &header[1], sendsize);
+ memcpy (write_pout->buf, &rtheader, sizeof (rtheader));
+ memcpy (write_pout->buf + sizeof (rtheader), &header[1], sendsize);
/* payload contains MAC address, but we don't trust it, so we'll
- overwrite it with OUR MAC address again to prevent mischief */
- wlanheader = (struct ieee80211_frame *) (write_pout->buf + sizeof(rtheader));
- mac_set(wlanheader, dev);
- write_pout->size = sendsize + sizeof(rtheader);
+ * overwrite it with OUR MAC address again to prevent mischief */
+ wlanheader = (struct ieee80211_frame *) (write_pout->buf + sizeof
(rtheader));
+ mac_set (wlanheader, dev);
+ write_pout->size = sendsize + sizeof (rtheader);
}
#if 0
static int
-maketest(unsigned char * buf, struct Hardware_Infos * dev)
+maketest (unsigned char *buf, struct Hardware_Infos *dev)
{
- uint16_t * tmp16;
+ uint16_t *tmp16;
static uint16_t seqenz = 0;
static int first = 0;
const int rate = 11000000;
static const char
txt[] =
- "Hallo1Hallo2 Hallo3 Hallo4...998877665544332211Hallo1Hallo2 Hallo3
Hallo4...998877665544332211";
+ "Hallo1Hallo2 Hallo3 Hallo4...998877665544332211Hallo1Hallo2 Hallo3
Hallo4...998877665544332211";
- unsigned char u8aRadiotap[] =
- { 0x00, 0x00, // <-- radiotap version
- 0x00, 0x00, // <- radiotap header length
- 0x04, 0x80, 0x02, 0x00, // <-- bitmap
- 0x00, // <-- rate
- 0x00, // <-- padding for natural alignment
- 0x10, 0x00, // <-- TX flags
- 0x04 //retries
- };
+ unsigned char u8aRadiotap[] = { 0x00, 0x00, // <-- radiotap version
+ 0x00, 0x00, // <- radiotap header length
+ 0x04, 0x80, 0x02, 0x00, // <-- bitmap
+ 0x00, // <-- rate
+ 0x00, // <-- padding for natural alignment
+ 0x10, 0x00, // <-- TX flags
+ 0x04 //retries
+ };
/*uint8_t u8aRadiotap[] =
- {
- 0x00, 0x00, // <-- radiotap version
- 0x19, 0x00, // <- radiotap header length
- 0x6f, 0x08, 0x00, 0x00, // <-- bitmap
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // <-- timestamp
- 0x00, // <-- flags (Offset +0x10)
- 0x6c, // <-- rate (0ffset +0x11)
- 0x71, 0x09, 0xc0, 0x00, // <-- channel
- 0xde, // <-- antsignal
- 0x00, // <-- antnoise
- 0x01, // <-- antenna
- };*/
+ * {
+ * 0x00, 0x00, // <-- radiotap version
+ * 0x19, 0x00, // <- radiotap header length
+ * 0x6f, 0x08, 0x00, 0x00, // <-- bitmap
+ * 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // <-- timestamp
+ * 0x00, // <-- flags (Offset +0x10)
+ * 0x6c, // <-- rate (0ffset +0x11)
+ * 0x71, 0x09, 0xc0, 0x00, // <-- channel
+ * 0xde, // <-- antsignal
+ * 0x00, // <-- antnoise
+ * 0x01, // <-- antenna
+ * }; */
u8aRadiotap[8] = (rate / 500000);
- u8aRadiotap[2] = htole16(sizeof(u8aRadiotap));
+ u8aRadiotap[2] = htole16 (sizeof (u8aRadiotap));
static struct ieee80211_frame u8aIeeeHeader;
- uint8_t u8aIeeeHeader_def[] =
- { 0x08, 0x00, // Frame Control 0x08= 00001000 -> | b1,2 = 0 -> Version 0;
- // b3,4 = 10 -> Data; b5-8 = 0 -> Normal Data
- // 0x01 = 00000001 -> | b1 = 1 to DS; b2 = 0 not from DS;
- 0x00, 0x00, // Duration/ID
+ uint8_t u8aIeeeHeader_def[] = { 0x08, 0x00, // Frame Control 0x08=
00001000 -> | b1,2 = 0 -> Version 0;
+ // b3,4 = 10 -> Data; b5-8 = 0 -> Normal Data
+ // 0x01 = 00000001 -> | b1 = 1 to DS; b2 = 0 not from DS;
+ 0x00, 0x00, // Duration/ID
- //0x00, 0x1f, 0x3f, 0xd1, 0x8e, 0xe6, // mac1 - in this case receiver
- 0x00, 0x1d, 0xe0, 0xb0, 0x17, 0xdf, // mac1 - in this case receiver
- 0xC0, 0x3F, 0x0E, 0x44, 0x2D, 0x51, // mac2 - in this case sender
- //0x02, 0x1d, 0xe0, 0x00, 0x01, 0xc4,
- 0x13, 0x22, 0x33, 0x44, 0x55, 0x66, // mac3 - in this case bssid
- 0x10, 0x86, //Sequence Control
- };
+ //0x00, 0x1f, 0x3f, 0xd1, 0x8e, 0xe6, // mac1 - in this case receiver
+ 0x00, 0x1d, 0xe0, 0xb0, 0x17, 0xdf, // mac1 - in this case receiver
+ 0xC0, 0x3F, 0x0E, 0x44, 0x2D, 0x51, // mac2 - in this case sender
+ //0x02, 0x1d, 0xe0, 0x00, 0x01, 0xc4,
+ 0x13, 0x22, 0x33, 0x44, 0x55, 0x66, // mac3 - in this case bssid
+ 0x10, 0x86, //Sequence Control
+ };
if (0 == first)
- {
- memcpy(&u8aIeeeHeader, u8aIeeeHeader_def, sizeof(struct
ieee80211_frame));
- memcpy(u8aIeeeHeader.i_addr2, dev->pl_mac, MAC_ADDR_SIZE);
- first = 1;
- }
+ {
+ memcpy (&u8aIeeeHeader, u8aIeeeHeader_def, sizeof (struct
ieee80211_frame));
+ memcpy (u8aIeeeHeader.i_addr2, dev->pl_mac, MAC_ADDR_SIZE);
+ first = 1;
+ }
- tmp16 = (uint16_t*) u8aIeeeHeader.i_dur;
+ tmp16 = (uint16_t *) u8aIeeeHeader.i_dur;
*tmp16
- = (uint16_t) htole16((sizeof(txt) + sizeof(struct ieee80211_frame) *
1000000) / rate + 290);
- tmp16 = (uint16_t*) u8aIeeeHeader.i_seq;
- *tmp16 = (*tmp16 & IEEE80211_SEQ_FRAG_MASK) | (htole16(seqenz)
- << IEEE80211_SEQ_SEQ_SHIFT);
+ =
+ (uint16_t)
+ htole16 ((sizeof (txt) +
+ sizeof (struct ieee80211_frame) * 1000000) / rate + 290);
+ tmp16 = (uint16_t *) u8aIeeeHeader.i_seq;
+ *tmp16 = (*tmp16 & IEEE80211_SEQ_FRAG_MASK) | (htole16 (seqenz)
+ << IEEE80211_SEQ_SEQ_SHIFT);
seqenz++;
- memcpy(buf, u8aRadiotap, sizeof(u8aRadiotap));
- memcpy(buf + sizeof(u8aRadiotap), &u8aIeeeHeader, sizeof(u8aIeeeHeader));
- memcpy(buf + sizeof(u8aRadiotap) + sizeof(u8aIeeeHeader), txt, sizeof(txt));
- return sizeof(u8aRadiotap) + sizeof(u8aIeeeHeader) + sizeof(txt);
+ memcpy (buf, u8aRadiotap, sizeof (u8aRadiotap));
+ memcpy (buf + sizeof (u8aRadiotap), &u8aIeeeHeader, sizeof (u8aIeeeHeader));
+ memcpy (buf + sizeof (u8aRadiotap) + sizeof (u8aIeeeHeader), txt,
+ sizeof (txt));
+ return sizeof (u8aRadiotap) + sizeof (u8aIeeeHeader) + sizeof (txt);
}
#endif
@@ -742,21 +714,20 @@
*/
// FIXME: use 'struct MacAddress' for 'mac' (everywhere in this file)
static int
-send_mac_to_plugin(char * buffer, uint8_t * mac)
+send_mac_to_plugin (char *buffer, uint8_t * mac)
{
struct Wlan_Helper_Control_Message macmsg;
- macmsg.hdr.size = htons(sizeof(struct Wlan_Helper_Control_Message));
- macmsg.hdr.type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL);
- memcpy(macmsg.mac.mac, mac, sizeof(struct MacAddress));
- memcpy(buffer, &macmsg, sizeof(struct Wlan_Helper_Control_Message));
- return sizeof(struct Wlan_Helper_Control_Message);
+ macmsg.hdr.size = htons (sizeof (struct Wlan_Helper_Control_Message));
+ macmsg.hdr.type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL);
+ memcpy (macmsg.mac.mac, mac, sizeof (struct MacAddress));
+ memcpy (buffer, &macmsg, sizeof (struct Wlan_Helper_Control_Message));
+ return sizeof (struct Wlan_Helper_Control_Message);
}
static int
-hardwaremode (int argc,
- char *argv[])
+hardwaremode (int argc, char *argv[])
{
uid_t uid;
struct Hardware_Infos dev;
@@ -768,18 +739,16 @@
fd_set wfds;
int retval;
int stdin_open;
- struct GNUNET_SERVER_MessageStreamTokenizer * stdin_mst;
+ struct GNUNET_SERVER_MessageStreamTokenizer *stdin_mst;
- if (0 != wlaninit(&dev, argv[1]))
- return 1;
- uid = getuid();
- if (0 != setresuid(uid, uid, uid))
- {
- fprintf(stderr,
- "Failed to setresuid: %s\n",
- strerror(errno));
- /* not critical, continue anyway */
- }
+ if (0 != wlaninit (&dev, argv[1]))
+ return 1;
+ uid = getuid ();
+ if (0 != setresuid (uid, uid, uid))
+ {
+ fprintf (stderr, "Failed to setresuid: %s\n", strerror (errno));
+ /* not critical, continue anyway */
+ }
dev.write_pout.size = 0;
dev.write_pout.pos = 0;
@@ -787,162 +756,148 @@
/* send mac to STDOUT first */
write_std.pos = 0;
- write_std.size = send_mac_to_plugin((char *) &write_std.buf, dev.pl_mac);
+ write_std.size = send_mac_to_plugin ((char *) &write_std.buf, dev.pl_mac);
stdin_open = 1;
while (1)
+ {
+ maxfd = -1;
+ FD_ZERO (&rfds);
+ if ((0 == dev.write_pout.size) && (1 == stdin_open))
{
- maxfd = -1;
- FD_ZERO (&rfds);
- if ( (0 == dev.write_pout.size) &&
- (1 == stdin_open) )
- {
- FD_SET (STDIN_FILENO, &rfds);
- maxfd = MAX (maxfd, STDIN_FILENO);
- }
- if (0 == write_std.size)
- {
- FD_SET (dev.fd_raw, &rfds);
- maxfd = MAX(maxfd, dev.fd_raw);
- }
- FD_ZERO(&wfds);
- if (0 < write_std.size)
- {
- FD_SET (STDOUT_FILENO, &wfds);
- maxfd = MAX(maxfd, STDOUT_FILENO);
- }
- if (0 < dev.write_pout.size)
- {
- FD_SET(dev.fd_raw, &wfds);
- maxfd = MAX(maxfd, dev.fd_raw);
- }
- retval = select(maxfd + 1, &rfds, &wfds, NULL, NULL);
- if ( (-1 == retval) &&
- (EINTR == errno) )
- continue;
- if (0 > retval)
- {
- fprintf(stderr,
- "select failed: %s\n",
- strerror(errno));
- break;
- }
+ FD_SET (STDIN_FILENO, &rfds);
+ maxfd = MAX (maxfd, STDIN_FILENO);
+ }
+ if (0 == write_std.size)
+ {
+ FD_SET (dev.fd_raw, &rfds);
+ maxfd = MAX (maxfd, dev.fd_raw);
+ }
+ FD_ZERO (&wfds);
+ if (0 < write_std.size)
+ {
+ FD_SET (STDOUT_FILENO, &wfds);
+ maxfd = MAX (maxfd, STDOUT_FILENO);
+ }
+ if (0 < dev.write_pout.size)
+ {
+ FD_SET (dev.fd_raw, &wfds);
+ maxfd = MAX (maxfd, dev.fd_raw);
+ }
+ retval = select (maxfd + 1, &rfds, &wfds, NULL, NULL);
+ if ((-1 == retval) && (EINTR == errno))
+ continue;
+ if (0 > retval)
+ {
+ fprintf (stderr, "select failed: %s\n", strerror (errno));
+ break;
+ }
- if (FD_ISSET(STDOUT_FILENO, &wfds))
- {
- ret = write(STDOUT_FILENO,
- write_std.buf + write_std.pos,
- write_std.size - write_std.pos);
- if (0 > ret)
- {
- fprintf (stderr,
- "Failed to write to STDOUT: %s\n",
- strerror (errno));
- break;
- }
- write_std.pos += ret;
- if (write_std.pos == write_std.size)
- {
- write_std.pos = 0;
- write_std.size = 0;
- }
- }
+ if (FD_ISSET (STDOUT_FILENO, &wfds))
+ {
+ ret = write (STDOUT_FILENO,
+ write_std.buf + write_std.pos,
+ write_std.size - write_std.pos);
+ if (0 > ret)
+ {
+ fprintf (stderr, "Failed to write to STDOUT: %s\n", strerror (errno));
+ break;
+ }
+ write_std.pos += ret;
+ if (write_std.pos == write_std.size)
+ {
+ write_std.pos = 0;
+ write_std.size = 0;
+ }
+ }
- if (FD_ISSET(dev.fd_raw, &wfds))
- {
- ret = write (dev.fd_raw,
- dev.write_pout.buf,
- dev.write_pout.size);
- if (0 > ret)
- {
- fprintf (stderr,
- "Line %u: Failed to write to WLAN device: %s,
Message-Size: %u\n",__LINE__,
- strerror (errno), dev.write_pout.size);
- break;
- }
- dev.write_pout.pos += ret;
- if ( (dev.write_pout.pos != dev.write_pout.size) &&
- (ret != 0) )
- {
- fprintf(stderr,
- "Line %u: Write error, partial send: %u/%u\n",__LINE__,
- dev.write_pout.pos, dev.write_pout.size);
- break;
- }
- if (dev.write_pout.pos == dev.write_pout.size)
- {
- dev.write_pout.pos = 0;
- dev.write_pout.size = 0;
- }
- }
+ if (FD_ISSET (dev.fd_raw, &wfds))
+ {
+ ret = write (dev.fd_raw, dev.write_pout.buf, dev.write_pout.size);
+ if (0 > ret)
+ {
+ fprintf (stderr,
+ "Line %u: Failed to write to WLAN device: %s, Message-Size:
%u\n",
+ __LINE__, strerror (errno), dev.write_pout.size);
+ break;
+ }
+ dev.write_pout.pos += ret;
+ if ((dev.write_pout.pos != dev.write_pout.size) && (ret != 0))
+ {
+ fprintf (stderr,
+ "Line %u: Write error, partial send: %u/%u\n", __LINE__,
+ dev.write_pout.pos, dev.write_pout.size);
+ break;
+ }
+ if (dev.write_pout.pos == dev.write_pout.size)
+ {
+ dev.write_pout.pos = 0;
+ dev.write_pout.size = 0;
+ }
+ }
- if (FD_ISSET(STDIN_FILENO, &rfds))
- {
- ret = read(STDIN_FILENO, readbuf, sizeof(readbuf));
- if (0 > ret)
- {
- fprintf(stderr,
- "Read error from STDIN: %s\n",
- strerror (errno));
- break;
- }
- if (0 == ret)
- {
- /* stop reading... */
- stdin_open = 0;
- }
- GNUNET_SERVER_mst_receive (stdin_mst, NULL,
- readbuf, ret,
- GNUNET_NO, GNUNET_NO);
- }
+ if (FD_ISSET (STDIN_FILENO, &rfds))
+ {
+ ret = read (STDIN_FILENO, readbuf, sizeof (readbuf));
+ if (0 > ret)
+ {
+ fprintf (stderr, "Read error from STDIN: %s\n", strerror (errno));
+ break;
+ }
+ if (0 == ret)
+ {
+ /* stop reading... */
+ stdin_open = 0;
+ }
+ GNUNET_SERVER_mst_receive (stdin_mst, NULL,
+ readbuf, ret, GNUNET_NO, GNUNET_NO);
+ }
- if (FD_ISSET(dev.fd_raw, &rfds))
- {
- struct GNUNET_MessageHeader * header;
- struct Radiotap_rx * rxinfo;
- struct ieee80211_frame * datastart;
+ if (FD_ISSET (dev.fd_raw, &rfds))
+ {
+ struct GNUNET_MessageHeader *header;
+ struct Radiotap_rx *rxinfo;
+ struct ieee80211_frame *datastart;
- header = (struct GNUNET_MessageHeader *) write_std.buf;
- rxinfo = (struct Radiotap_rx *) &header[1];
- datastart = (struct ieee80211_frame *) &rxinfo[1];
- ret = linux_read (&dev,
- (unsigned char *) datastart,
- sizeof(write_std.buf) - sizeof(struct Radiotap_rx)
- sizeof(struct GNUNET_MessageHeader),
- rxinfo);
- if (0 > ret)
- {
- fprintf(stderr,
- "Read error from raw socket: %s\n",
- strerror(errno));
- break;
- }
- if ( (0 < ret) &&
- (0 == mac_test(datastart, &dev)) )
- {
- write_std.size = ret + sizeof(struct GNUNET_MessageHeader) +
sizeof(struct Radiotap_rx);
- header->size = htons(write_std.size);
- header->type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
- }
- }
-
+ header = (struct GNUNET_MessageHeader *) write_std.buf;
+ rxinfo = (struct Radiotap_rx *) &header[1];
+ datastart = (struct ieee80211_frame *) &rxinfo[1];
+ ret = linux_read (&dev,
+ (unsigned char *) datastart,
+ sizeof (write_std.buf) - sizeof (struct Radiotap_rx) -
+ sizeof (struct GNUNET_MessageHeader), rxinfo);
+ if (0 > ret)
+ {
+ fprintf (stderr, "Read error from raw socket: %s\n", strerror (errno));
+ break;
+ }
+ if ((0 < ret) && (0 == mac_test (datastart, &dev)))
+ {
+ write_std.size =
+ ret + sizeof (struct GNUNET_MessageHeader) +
+ sizeof (struct Radiotap_rx);
+ header->size = htons (write_std.size);
+ header->type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
+ }
}
+
+ }
/* Error handling, try to clean up a bit at least */
- GNUNET_SERVER_mst_destroy(stdin_mst);
+ GNUNET_SERVER_mst_destroy (stdin_mst);
close (dev.fd_raw);
- return 1;
+ return 1;
}
int
-main(int argc, char *argv[])
+main (int argc, char *argv[])
{
if (2 != argc)
- {
- fprintf (stderr,
- "This program must be started with the interface as
argument.\nThis program was compiled at ----- %s ----\n", __TIMESTAMP__ );
- fprintf (stderr,
- "Usage: interface-name\n"
- "\n");
- return 1;
- }
- return hardwaremode(argc , argv);
+ {
+ fprintf (stderr,
+ "This program must be started with the interface as
argument.\nThis program was compiled at ----- %s ----\n",
+ __TIMESTAMP__);
+ fprintf (stderr, "Usage: interface-name\n" "\n");
+ return 1;
+ }
+ return hardwaremode (argc, argv);
}
Modified: gnunet/src/transport/gnunet-transport-wlan-helper.h
===================================================================
--- gnunet/src/transport/gnunet-transport-wlan-helper.h 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/transport/gnunet-transport-wlan-helper.h 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -23,7 +23,7 @@
* @brief common internal definitions for the wlan mediator
* @author David Brodski
*/
-
+
#ifndef gnunet_wlan_H
#define gnunet_wlan_H
@@ -72,4 +72,3 @@
#endif /* gnunet_wlan_H */
-
Modified: gnunet/src/transport/ieee80211_radiotap.h
===================================================================
--- gnunet/src/transport/ieee80211_radiotap.h 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/transport/ieee80211_radiotap.h 2011-08-15 21:46:35 UTC (rev
16581)
@@ -61,25 +61,26 @@
* The radio capture header precedes the 802.11 header.
* All data in the header is little endian on all platforms.
*/
-struct ieee80211_radiotap_header {
- u8 it_version; /* Version 0. Only increases
- * for drastic changes,
- * introduction of compatible
- * new fields does not count.
- */
- u8 it_pad;
- __le16 it_len; /* length of the whole
- * header in bytes, including
- * it_version, it_pad,
- * it_len, and data fields.
- */
- __le32 it_present; /* A bitmap telling which
- * fields are present. Set bit 31
- * (0x80000000) to extend the
- * bitmap by another 32 bits.
- * Additional extensions are made
- * by setting bit 31.
- */
+struct ieee80211_radiotap_header
+{
+ u8 it_version; /* Version 0. Only increases
+ * for drastic changes,
+ * introduction of compatible
+ * new fields does not count.
+ */
+ u8 it_pad;
+ __le16 it_len; /* length of the whole
+ * header in bytes, including
+ * it_version, it_pad,
+ * it_len, and data fields.
+ */
+ __le32 it_present; /* A bitmap telling which
+ * fields are present. Set bit 31
+ * (0x80000000) to extend the
+ * bitmap by another 32 bits.
+ * Additional extensions are made
+ * by setting bit 31.
+ */
} __packed;
/* Name Data type Units
@@ -179,71 +180,72 @@
* Number of unicast retries a transmitted frame used.
*
*/
-enum ieee80211_radiotap_type {
- IEEE80211_RADIOTAP_TSFT = 0,
- IEEE80211_RADIOTAP_FLAGS = 1,
- IEEE80211_RADIOTAP_RATE = 2,
- IEEE80211_RADIOTAP_CHANNEL = 3,
- IEEE80211_RADIOTAP_FHSS = 4,
- IEEE80211_RADIOTAP_DBM_ANTSIGNAL = 5,
- IEEE80211_RADIOTAP_DBM_ANTNOISE = 6,
- IEEE80211_RADIOTAP_LOCK_QUALITY = 7,
- IEEE80211_RADIOTAP_TX_ATTENUATION = 8,
- IEEE80211_RADIOTAP_DB_TX_ATTENUATION = 9,
- IEEE80211_RADIOTAP_DBM_TX_POWER = 10,
- IEEE80211_RADIOTAP_ANTENNA = 11,
- IEEE80211_RADIOTAP_DB_ANTSIGNAL = 12,
- IEEE80211_RADIOTAP_DB_ANTNOISE = 13,
- IEEE80211_RADIOTAP_RX_FLAGS = 14,
- IEEE80211_RADIOTAP_TX_FLAGS = 15,
- IEEE80211_RADIOTAP_RTS_RETRIES = 16,
- IEEE80211_RADIOTAP_DATA_RETRIES = 17,
+enum ieee80211_radiotap_type
+{
+ IEEE80211_RADIOTAP_TSFT = 0,
+ IEEE80211_RADIOTAP_FLAGS = 1,
+ IEEE80211_RADIOTAP_RATE = 2,
+ IEEE80211_RADIOTAP_CHANNEL = 3,
+ IEEE80211_RADIOTAP_FHSS = 4,
+ IEEE80211_RADIOTAP_DBM_ANTSIGNAL = 5,
+ IEEE80211_RADIOTAP_DBM_ANTNOISE = 6,
+ IEEE80211_RADIOTAP_LOCK_QUALITY = 7,
+ IEEE80211_RADIOTAP_TX_ATTENUATION = 8,
+ IEEE80211_RADIOTAP_DB_TX_ATTENUATION = 9,
+ IEEE80211_RADIOTAP_DBM_TX_POWER = 10,
+ IEEE80211_RADIOTAP_ANTENNA = 11,
+ IEEE80211_RADIOTAP_DB_ANTSIGNAL = 12,
+ IEEE80211_RADIOTAP_DB_ANTNOISE = 13,
+ IEEE80211_RADIOTAP_RX_FLAGS = 14,
+ IEEE80211_RADIOTAP_TX_FLAGS = 15,
+ IEEE80211_RADIOTAP_RTS_RETRIES = 16,
+ IEEE80211_RADIOTAP_DATA_RETRIES = 17,
- /* valid in every it_present bitmap, even vendor namespaces */
- IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE = 29,
- IEEE80211_RADIOTAP_VENDOR_NAMESPACE = 30,
- IEEE80211_RADIOTAP_EXT = 31
+ /* valid in every it_present bitmap, even vendor namespaces */
+ IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE = 29,
+ IEEE80211_RADIOTAP_VENDOR_NAMESPACE = 30,
+ IEEE80211_RADIOTAP_EXT = 31
};
/* Channel flags. */
-#define IEEE80211_CHAN_TURBO 0x0010 /* Turbo channel */
-#define IEEE80211_CHAN_CCK 0x0020 /* CCK channel */
-#define IEEE80211_CHAN_OFDM 0x0040 /* OFDM channel */
-#define IEEE80211_CHAN_2GHZ 0x0080 /* 2 GHz spectrum channel. */
-#define IEEE80211_CHAN_5GHZ 0x0100 /* 5 GHz spectrum channel */
-#define IEEE80211_CHAN_PASSIVE 0x0200 /* Only passive scan allowed */
-#define IEEE80211_CHAN_DYN 0x0400 /* Dynamic CCK-OFDM channel */
-#define IEEE80211_CHAN_GFSK 0x0800 /* GFSK channel (FHSS PHY) */
+#define IEEE80211_CHAN_TURBO 0x0010 /* Turbo channel */
+#define IEEE80211_CHAN_CCK 0x0020 /* CCK channel */
+#define IEEE80211_CHAN_OFDM 0x0040 /* OFDM channel */
+#define IEEE80211_CHAN_2GHZ 0x0080 /* 2 GHz spectrum channel. */
+#define IEEE80211_CHAN_5GHZ 0x0100 /* 5 GHz spectrum channel */
+#define IEEE80211_CHAN_PASSIVE 0x0200 /* Only passive scan allowed */
+#define IEEE80211_CHAN_DYN 0x0400 /* Dynamic CCK-OFDM channel */
+#define IEEE80211_CHAN_GFSK 0x0800 /* GFSK channel (FHSS PHY) */
/* For IEEE80211_RADIOTAP_FLAGS */
-#define IEEE80211_RADIOTAP_F_CFP 0x01 /* sent/received
- * during CFP
- */
-#define IEEE80211_RADIOTAP_F_SHORTPRE 0x02 /* sent/received
- * with short
- * preamble
- */
-#define IEEE80211_RADIOTAP_F_WEP 0x04 /* sent/received
- * with WEP encryption
- */
-#define IEEE80211_RADIOTAP_F_FRAG 0x08 /* sent/received
- * with fragmentation
- */
-#define IEEE80211_RADIOTAP_F_FCS 0x10 /* frame includes FCS */
-#define IEEE80211_RADIOTAP_F_DATAPAD 0x20 /* frame has padding
between
- * 802.11 header and payload
- * (to 32-bit boundary)
- */
-#define IEEE80211_RADIOTAP_F_BADFCS 0x40 /* bad FCS */
+#define IEEE80211_RADIOTAP_F_CFP 0x01 /* sent/received
+ * during CFP
+ */
+#define IEEE80211_RADIOTAP_F_SHORTPRE 0x02 /* sent/received
+ * with short
+ * preamble
+ */
+#define IEEE80211_RADIOTAP_F_WEP 0x04 /* sent/received
+ * with WEP encryption
+ */
+#define IEEE80211_RADIOTAP_F_FRAG 0x08 /* sent/received
+ * with fragmentation
+ */
+#define IEEE80211_RADIOTAP_F_FCS 0x10 /* frame includes FCS */
+#define IEEE80211_RADIOTAP_F_DATAPAD 0x20 /* frame has padding
between
+ * 802.11 header and payload
+ * (to 32-bit boundary)
+ */
+#define IEEE80211_RADIOTAP_F_BADFCS 0x40 /* bad FCS */
/* For IEEE80211_RADIOTAP_RX_FLAGS */
-#define IEEE80211_RADIOTAP_F_RX_BADPLCP 0x0002 /* frame has bad PLCP */
+#define IEEE80211_RADIOTAP_F_RX_BADPLCP 0x0002 /* frame has bad PLCP */
/* For IEEE80211_RADIOTAP_TX_FLAGS */
-#define IEEE80211_RADIOTAP_F_TX_FAIL 0x0001 /* failed due to excessive
- * retries */
-#define IEEE80211_RADIOTAP_F_TX_CTS 0x0002 /* used cts 'protection' */
-#define IEEE80211_RADIOTAP_F_TX_RTS 0x0004 /* used rts/cts handshake */
+#define IEEE80211_RADIOTAP_F_TX_FAIL 0x0001 /* failed due to excessive
+ * retries */
+#define IEEE80211_RADIOTAP_F_TX_CTS 0x0002 /* used cts 'protection' */
+#define IEEE80211_RADIOTAP_F_TX_RTS 0x0004 /* used rts/cts handshake */
/* Ugly macro to convert literal channel numbers into their mhz equivalents
* There are certianly some conditions that will break this (like feeding it
'30')
@@ -254,18 +256,20 @@
((x) + 1000) * 5)
/* helpers */
-static inline u16 get_unaligned_le16(const u8 *p)
+static inline u16
+get_unaligned_le16 (const u8 *p)
{
return p[0] | p[1] << 8;
}
-static inline int ieee80211_get_radiotap_len(unsigned char *data)
+static inline int
+ieee80211_get_radiotap_len (unsigned char *data)
{
- struct ieee80211_radiotap_header *hdr =
- (struct ieee80211_radiotap_header *)data;
+ struct ieee80211_radiotap_header *hdr =
+ (struct ieee80211_radiotap_header *) data;
- return get_unaligned_le16( (const u8 *) &hdr->it_len);
+ return get_unaligned_le16 ((const u8 *) &hdr->it_len);
}
-#endif /* IEEE80211_RADIOTAP_H */
+#endif /* IEEE80211_RADIOTAP_H */
Modified: gnunet/src/transport/perf_transport_ats.c
===================================================================
--- gnunet/src/transport/perf_transport_ats.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/transport/perf_transport_ats.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -40,48 +40,51 @@
static uint64_t mlp_no_opt_avg;
static uint64_t mlp_with_opt_avg;
-static glp_prob * prob;
+static glp_prob *prob;
static struct GNUNET_TIME_Absolute start;
static struct GNUNET_TIME_Absolute end;
-static void
-solve_mlp(int presolve)
+static void
+solve_mlp (int presolve)
{
int result, solution;
glp_iocp opt_mlp;
- glp_init_iocp(&opt_mlp);
+ glp_init_iocp (&opt_mlp);
opt_mlp.msg_lev = GLP_MSG_OFF;
opt_mlp.presolve = GLP_OFF;
result = glp_intopt (prob, &opt_mlp);
- solution = glp_mip_status (prob);
- GNUNET_assert ((solution == 5) && (result==0));
+ solution = glp_mip_status (prob);
+ GNUNET_assert ((solution == 5) && (result == 0));
}
static void
-solve_lp(int presolve)
+solve_lp (int presolve)
{
int result;
int solution;
glp_smcp opt_lp;
- glp_init_smcp(&opt_lp);
+ glp_init_smcp (&opt_lp);
+
opt_lp.msg_lev = GLP_MSG_OFF;
- if (presolve==GNUNET_YES) opt_lp.presolve = GLP_ON;
- else opt_lp.presolve = GLP_OFF;
+ if (presolve == GNUNET_YES)
+ opt_lp.presolve = GLP_ON;
+ else
+ opt_lp.presolve = GLP_OFF;
- result = glp_simplex(prob, &opt_lp);
- solution = glp_get_status (prob);
- GNUNET_assert ((solution == 5) && (result==0));
+ result = glp_simplex (prob, &opt_lp);
+ solution = glp_get_status (prob);
+ GNUNET_assert ((solution == 5) && (result == 0));
}
#if 0
/* Modify quality constraint */
-static void
-modify_qm(int start, int length, int values_to_change)
+static void
+modify_qm (int start, int length, int values_to_change)
{
//int * ind = GNUNET_malloc (length * sizeof (int));
//double *val = GNUNET_malloc (length * sizeof (double));
@@ -89,15 +92,16 @@
double val[1000];
int res = 0;
- int c = start, c2=1;
- while (c<=(start+values_to_change))
+ int c = start, c2 = 1;
+
+ while (c <= (start + values_to_change))
{
- res = glp_get_mat_row(prob, c, ind, val);
+ res = glp_get_mat_row (prob, c, ind, val);
- printf("%i %i \n", c, res);
- for (c2=0; c2<res; c2++)
+ printf ("%i %i \n", c, res);
+ for (c2 = 0; c2 < res; c2++)
{
- printf("%i = %f \n", ind[c2], val[c2]);
+ printf ("%i = %f \n", ind[c2], val[c2]);
}
c++;
}
@@ -107,162 +111,158 @@
-static void
-bench_simplex_optimization(char * file, int executions)
+static void
+bench_simplex_optimization (char *file, int executions)
{
int c;
int res;
- prob = glp_create_prob();
- res = glp_read_lp(prob, NULL, file);
+ prob = glp_create_prob ();
+ res = glp_read_lp (prob, NULL, file);
if (res != 0)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Problem file `%s' not found\n", file);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Problem file `%s' not found\n",
file);
ret = 1;
return;
}
- solve_lp(GNUNET_YES);
+ solve_lp (GNUNET_YES);
- for (c=0; c<executions;c++)
+ for (c = 0; c < executions; c++)
{
- start = GNUNET_TIME_absolute_get();
- solve_lp(GNUNET_NO);
- end = GNUNET_TIME_absolute_get();
+ start = GNUNET_TIME_absolute_get ();
+ solve_lp (GNUNET_NO);
+ end = GNUNET_TIME_absolute_get ();
- exec_time[c] = GNUNET_TIME_absolute_get_difference(start, end).rel_value;
+ exec_time[c] = GNUNET_TIME_absolute_get_difference (start, end).rel_value;
sim_with_opt_avg += exec_time[c];
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Simplex /w optimization iterations %i: %llu \n", c, exec_time[c]);
+ "Simplex /w optimization iterations %i: %llu \n", c,
+ exec_time[c]);
}
- glp_delete_prob(prob);
+ glp_delete_prob (prob);
}
static void
-bench_simplex_no_optimization(char * file, int executions)
+bench_simplex_no_optimization (char *file, int executions)
{
int c;
int res;
- prob = glp_create_prob();
- res = glp_read_lp(prob, NULL, file);
+ prob = glp_create_prob ();
+ res = glp_read_lp (prob, NULL, file);
if (res != 0)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Problem file `%s' not found\n", file);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Problem file `%s' not found\n",
file);
ret = 1;
return;
}
- for (c=0; c<executions;c++)
+ for (c = 0; c < executions; c++)
{
- start = GNUNET_TIME_absolute_get();
- solve_lp(GNUNET_YES);
- end = GNUNET_TIME_absolute_get();
+ start = GNUNET_TIME_absolute_get ();
+ solve_lp (GNUNET_YES);
+ end = GNUNET_TIME_absolute_get ();
- exec_time[c] = GNUNET_TIME_absolute_get_difference(start, end).rel_value;
+ exec_time[c] = GNUNET_TIME_absolute_get_difference (start, end).rel_value;
sim_no_opt_avg += exec_time[c];
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Simplex iterations %i: %llu \n",
- c, exec_time[c]);
+ "Simplex iterations %i: %llu \n", c, exec_time[c]);
}
- glp_delete_prob(prob);
+ glp_delete_prob (prob);
}
static void
-bench_mlp_no_optimization(char * file, int executions)
+bench_mlp_no_optimization (char *file, int executions)
{
int c;
int res;
- prob = glp_create_prob();
- res = glp_read_lp(prob, NULL, file);
+ prob = glp_create_prob ();
+ res = glp_read_lp (prob, NULL, file);
if (res != 0)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Problem file `%s' not found\n", file);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Problem file `%s' not found\n",
file);
ret = 1;
return;
}
- for (c=0; c<executions;c++)
+ for (c = 0; c < executions; c++)
{
- start = GNUNET_TIME_absolute_get();
- solve_lp(GNUNET_YES);
- solve_mlp (GNUNET_NO);
- end = GNUNET_TIME_absolute_get();
+ start = GNUNET_TIME_absolute_get ();
+ solve_lp (GNUNET_YES);
+ solve_mlp (GNUNET_NO);
+ end = GNUNET_TIME_absolute_get ();
- exec_time[c] = GNUNET_TIME_absolute_get_difference(start, end).rel_value;
+ exec_time[c] = GNUNET_TIME_absolute_get_difference (start, end).rel_value;
- mlp_no_opt_avg += exec_time[c];
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "MLP iterations no optimization %i: %llu \n",
- c, exec_time[c]);
+ mlp_no_opt_avg += exec_time[c];
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "MLP iterations no optimization %i: %llu \n", c, exec_time[c]);
}
- glp_delete_prob(prob);
+ glp_delete_prob (prob);
}
-static void
-bench_mlp_with_optimization(char * file, int executions, int changes)
+static void
+bench_mlp_with_optimization (char *file, int executions, int changes)
{
int c;
int res;
- prob = glp_create_prob();
- res = glp_read_lp(prob, NULL, file);
+ prob = glp_create_prob ();
+ res = glp_read_lp (prob, NULL, file);
if (res != 0)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Problem file `%s' not found\n", file);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Problem file `%s' not found\n",
file);
ret = 1;
return;
}
- solve_lp(GNUNET_YES);
+ solve_lp (GNUNET_YES);
- for (c=0; c<executions;c++)
+ for (c = 0; c < executions; c++)
{
- start = GNUNET_TIME_absolute_get();
+ start = GNUNET_TIME_absolute_get ();
//modify_qm(906, 0, 0);
- solve_lp(GNUNET_NO);
+ solve_lp (GNUNET_NO);
solve_mlp (GNUNET_NO);
- end = GNUNET_TIME_absolute_get();
+ end = GNUNET_TIME_absolute_get ();
- exec_time[c] = GNUNET_TIME_absolute_get_difference(start, end).rel_value;
+ exec_time[c] = GNUNET_TIME_absolute_get_difference (start, end).rel_value;
mlp_with_opt_avg += exec_time[c];
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "MLP /w optimization iterations %i: %llu \n",
- c, exec_time[c]);
+ "MLP /w optimization iterations %i: %llu \n", c, exec_time[c]);
}
- glp_delete_prob(prob);
+ glp_delete_prob (prob);
}
#if 0
-void modify_cr (int start, int length, int count)
+void
+modify_cr (int start, int length, int count)
{
//int * ind = GNUNET_malloc (length * sizeof (int));
//double *val = GNUNET_malloc (length * sizeof (double));
int ind[500];
double val[500];
int res = 0;
- int c = start, c2=1;
- while (c<=(start+count))
+ int c = start, c2 = 1;
+
+ while (c <= (start + count))
{
- res = glp_get_mat_row(prob, c, ind, val);
+ res = glp_get_mat_row (prob, c, ind, val);
- printf("row index: %i non-zero elements: %i \n", c, res);
- for (c2=1; c2<=res; c2++)
+ printf ("row index: %i non-zero elements: %i \n", c, res);
+ for (c2 = 1; c2 <= res; c2++)
{
- printf("%i = %f ", ind[c2], val[c2]);
+ printf ("%i = %f ", ind[c2], val[c2]);
}
c++;
printf ("\n----\n");
@@ -272,7 +272,8 @@
#endif
-int main (int argc, char *argv[])
+int
+main (int argc, char *argv[])
{
GNUNET_log_setup ("perf-transport-ats",
@@ -283,6 +284,7 @@
#endif
NULL);
int nullfd = OPEN ("/dev/null", O_RDWR | O_APPEND);
+
if (nullfd < 0)
return GNUNET_SYSERR;
if (dup2 (nullfd, 1) < 0)
@@ -293,7 +295,7 @@
}
- char * file = "ats_mlp_p100_m400.problem";
+ char *file = "ats_mlp_p100_m400.problem";
bench_simplex_no_optimization (file, executions);
bench_simplex_optimization (file, executions);
@@ -305,33 +307,32 @@
// -> 400 addresses
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Simplex, no optimization, average per address: %f\n",
- ((double) sim_no_opt_avg / EXECS) / 400);
- GAUGER ("TRANSPORT","GLPK simplex no optimization",
- ((double) sim_no_opt_avg / EXECS) / 400, "ms/address");
+ "Simplex, no optimization, average per address: %f\n",
+ ((double) sim_no_opt_avg / EXECS) / 400);
+ GAUGER ("TRANSPORT", "GLPK simplex no optimization",
+ ((double) sim_no_opt_avg / EXECS) / 400, "ms/address");
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Simplex, with optimization, average per address: %f\n",
- ((double) sim_with_opt_avg / EXECS) / 400);
+ "Simplex, with optimization, average per address: %f\n",
+ ((double) sim_with_opt_avg / EXECS) / 400);
GAUGER ("TRANSPORT",
- "GLPK simplex, 100 peers 400 addresses with optimization",
- ((double) sim_with_opt_avg / EXECS) / 400, "ms/address");
+ "GLPK simplex, 100 peers 400 addresses with optimization",
+ ((double) sim_with_opt_avg / EXECS) / 400, "ms/address");
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "MLP no optimization average per address: %f\n",
- ((double) mlp_no_opt_avg / EXECS) / 400);
- GAUGER ("TRANSPORT","GLPK MLP 100 peers 400 addresses no optimization",
- ((double) mlp_no_opt_avg / EXECS) / 400, "ms/address");
+ "MLP no optimization average per address: %f\n",
+ ((double) mlp_no_opt_avg / EXECS) / 400);
+ GAUGER ("TRANSPORT", "GLPK MLP 100 peers 400 addresses no optimization",
+ ((double) mlp_no_opt_avg / EXECS) / 400, "ms/address");
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "MLP optimization average per address: %f\n",
- ((double) mlp_with_opt_avg/ EXECS) / 400);
+ "MLP optimization average per address: %f\n",
+ ((double) mlp_with_opt_avg / EXECS) / 400);
GAUGER ("TRANSPORT",
- "GLPK MLP 100 peers 400 addresses with optimization",
- ((double) mlp_with_opt_avg / EXECS) / 400, "ms/address");
+ "GLPK MLP 100 peers 400 addresses with optimization",
+ ((double) mlp_with_opt_avg / EXECS) / 400, "ms/address");
(void) CLOSE (nullfd);
return ret;
}
/* end of perf_transport_ats.c*/
-
Modified: gnunet/src/transport/plugin_transport_http.c
===================================================================
--- gnunet/src/transport/plugin_transport_http.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/transport/plugin_transport_http.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -114,14 +114,14 @@
/**
* Linked list next
*/
- struct IPv4HttpAddressWrapper * next;
+ struct IPv4HttpAddressWrapper *next;
/**
* Linked list previous
*/
- struct IPv4HttpAddressWrapper * prev;
+ struct IPv4HttpAddressWrapper *prev;
- struct IPv4HttpAddress * addr;
+ struct IPv4HttpAddress *addr;
};
/**
@@ -149,14 +149,14 @@
/**
* Linked list next
*/
- struct IPv6HttpAddressWrapper * next;
+ struct IPv6HttpAddressWrapper *next;
/**
* Linked list previous
*/
- struct IPv6HttpAddressWrapper * prev;
+ struct IPv6HttpAddressWrapper *prev;
- struct IPv6HttpAddress * addr;
+ struct IPv6HttpAddress *addr;
};
/**
@@ -167,12 +167,12 @@
/**
* next pointer for double linked list
*/
- struct HTTP_Message * next;
+ struct HTTP_Message *next;
/**
* previous pointer for double linked list
*/
- struct HTTP_Message * prev;
+ struct HTTP_Message *prev;
/**
* buffer containing data to send
@@ -219,13 +219,13 @@
* Linked list of connections with this peer
* head
*/
- struct Session * head;
+ struct Session *head;
/**
* Linked list of connections with this peer
* tail
*/
- struct Session * tail;
+ struct Session *tail;
/**
* id for next session
@@ -235,7 +235,7 @@
/**
* Last session used to send data
*/
- struct Session * last_session;
+ struct Session *last_session;
/**
* The task resetting inbound quota delay
@@ -259,17 +259,17 @@
/**
* next session in linked list
*/
- struct Session * next;
+ struct Session *next;
/**
* previous session in linked list
*/
- struct Session * prev;
+ struct Session *prev;
/**
* address of this session
*/
- void * addr;
+ void *addr;
/**
* address length
@@ -279,24 +279,24 @@
/**
* target url
*/
- char * url;
+ char *url;
/**
* Message queue for outbound messages
* head of queue
*/
- struct HTTP_Message * pending_msgs_head;
+ struct HTTP_Message *pending_msgs_head;
/**
* Message queue for outbound messages
* tail of queue
*/
- struct HTTP_Message * pending_msgs_tail;
+ struct HTTP_Message *pending_msgs_tail;
/**
* partner peer this connection belongs to
*/
- struct HTTP_PeerContext * peercontext;
+ struct HTTP_PeerContext *peercontext;
/**
* message stream tokenizer for incoming data
@@ -352,14 +352,14 @@
* outbound session: CURL *
* inbound session: mhd_connection *
*/
- void * send_endpoint;
+ void *send_endpoint;
/**
* entity managing recieving data
* outbound session: CURL *
* inbound session: mhd_connection *
*/
- void * recv_endpoint;
+ void *recv_endpoint;
/**
* Current queue size
@@ -423,7 +423,7 @@
/**
* cURL Multihandle
*/
- CURLM * multi_handle;
+ CURLM *multi_handle;
/**
* Our handle to the NAT module.
@@ -433,22 +433,22 @@
/**
* ipv4 DLL head
*/
- struct IPv4HttpAddressWrapper * ipv4_addr_head;
+ struct IPv4HttpAddressWrapper *ipv4_addr_head;
/**
* ipv4 DLL tail
*/
- struct IPv4HttpAddressWrapper * ipv4_addr_tail;
+ struct IPv4HttpAddressWrapper *ipv4_addr_tail;
/**
* ipv6 DLL head
*/
- struct IPv6HttpAddressWrapper * ipv6_addr_head;
+ struct IPv6HttpAddressWrapper *ipv6_addr_head;
/**
* ipv6 DLL tail
*/
- struct IPv6HttpAddressWrapper * ipv6_addr_tail;
+ struct IPv6HttpAddressWrapper *ipv6_addr_tail;
/**
* Our ASCII encoded, hashed peer identity
@@ -459,17 +459,17 @@
/**
* IPv4 Address the plugin binds to
*/
- struct sockaddr_in * bind4_address;
+ struct sockaddr_in *bind4_address;
/**
* IPv6 Address the plugins binds to
*/
- struct sockaddr_in6 * bind6_address;
+ struct sockaddr_in6 *bind6_address;
/**
* Hostname to bind to
*/
- char * bind_hostname;
+ char *bind_hostname;
/**
* Is IPv4 enabled?
@@ -499,18 +499,18 @@
/**
* Closure passed by MHD to the mhd_logger function
*/
- void * mhd_log;
+ void *mhd_log;
/* only needed for HTTPS plugin */
#if BUILD_HTTPS
/* The certificate MHD uses as an \0 terminated string */
- char * cert;
+ char *cert;
/* The private key MHD uses as an \0 terminated string */
- char * key;
+ char *key;
/* crypto init string */
- char * crypto_init;
+ char *crypto_init;
#endif
};
@@ -547,22 +547,25 @@
* @param addrlen length of the address
* @return string representing the same address
*/
-static const char*
-http_plugin_address_to_string (void *cls,
- const void *addr,
- size_t addrlen);
+static const char *http_plugin_address_to_string (void *cls,
+ const void *addr,
+ size_t addrlen);
/**
* Call MHD to process pending ipv4 requests and then go back
* and schedule the next run.
*/
-static void http_server_daemon_v4_run (void *cls, const struct
GNUNET_SCHEDULER_TaskContext *tc);
+static void http_server_daemon_v4_run (void *cls,
+ const struct
GNUNET_SCHEDULER_TaskContext
+ *tc);
/**
* Call MHD to process pending ipv6 requests and then go back
* and schedule the next run.
*/
-static void http_server_daemon_v6_run (void *cls, const struct
GNUNET_SCHEDULER_TaskContext *tc);
+static void http_server_daemon_v6_run (void *cls,
+ const struct
GNUNET_SCHEDULER_TaskContext
+ *tc);
/**
* Function setting up curl handle and selecting message to send
@@ -586,12 +589,13 @@
* @param cls plugin as closure
* @param tc task context
*/
-static void reset_inbound_quota_delay (void *cls,
- const struct
GNUNET_SCHEDULER_TaskContext *tc)
+static void
+reset_inbound_quota_delay (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- struct HTTP_PeerContext * pc = cls;
-
- GNUNET_assert(cls != NULL);
+ struct HTTP_PeerContext *pc = cls;
+
+ GNUNET_assert (cls != NULL);
pc->reset_task = GNUNET_SCHEDULER_NO_TASK;
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
return;
@@ -607,18 +611,16 @@
* @param id session id
* @return the created url
*/
-static char *
-create_url(struct Plugin *plugin,
- const void * addr, size_t addrlen,
- size_t id)
+static char *
+create_url (struct Plugin *plugin, const void *addr, size_t addrlen, size_t id)
{
char *url = NULL;
- char *addr_str = (char *) http_plugin_address_to_string(NULL, addr, addrlen);
+ char *addr_str = (char *) http_plugin_address_to_string (NULL, addr,
addrlen);
- GNUNET_assert ((addr!=NULL) && (addrlen != 0));
- GNUNET_asprintf(&url,
- "%s://%s/%s;%u", PROTOCOL_PREFIX, addr_str,
- (char *) (&plugin->my_ascii_hash_ident),id);
+ GNUNET_assert ((addr != NULL) && (addrlen != 0));
+ GNUNET_asprintf (&url,
+ "%s://%s/%s;%u", PROTOCOL_PREFIX, addr_str,
+ (char *) (&plugin->my_ascii_hash_ident), id);
return url;
}
@@ -629,14 +631,12 @@
* @param msg message
* @return GNUNET_SYSERR if msg not found, GNUNET_OK on success
*/
-static int
-remove_http_message (struct Session * ps,
- struct HTTP_Message * msg)
+static int
+remove_http_message (struct Session *ps, struct HTTP_Message *msg)
{
- GNUNET_CONTAINER_DLL_remove(ps->pending_msgs_head,
- ps->pending_msgs_tail,
- msg);
- GNUNET_free(msg);
+ GNUNET_CONTAINER_DLL_remove (ps->pending_msgs_head,
+ ps->pending_msgs_tail, msg);
+ GNUNET_free (msg);
return GNUNET_OK;
}
@@ -647,59 +647,56 @@
* @param value the peer context
* @return GNUNET_YES on success
*/
-static int
+static int
remove_peer_context_Iterator (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+ const GNUNET_HashCode * key, void *value)
{
struct Plugin *plugin = cls;
- struct HTTP_PeerContext * pc = value;
- struct Session * ps = pc->head;
- struct Session * tmp = NULL;
- struct HTTP_Message * msg = NULL;
- struct HTTP_Message * msg_tmp = NULL;
+ struct HTTP_PeerContext *pc = value;
+ struct Session *ps = pc->head;
+ struct Session *tmp = NULL;
+ struct HTTP_Message *msg = NULL;
+ struct HTTP_Message *msg_tmp = NULL;
#if DEBUG_HTTP
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Freeing context for peer `%s'\n",
- GNUNET_i2s(&pc->identity));
+ "Freeing context for peer `%s'\n", GNUNET_i2s (&pc->identity));
#endif
GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove (plugin->peers,
-
&pc->identity.hashPubKey,
- pc));
- while (ps!=NULL)
+ GNUNET_CONTAINER_multihashmap_remove (plugin->peers,
+
&pc->identity.hashPubKey,
+ pc));
+ while (ps != NULL)
+ {
+ plugin->env->session_end (plugin, &pc->identity, ps);
+ tmp = ps->next;
+
+ GNUNET_free_non_null (ps->addr);
+ GNUNET_free (ps->url);
+ if (ps->msgtok != NULL)
+ GNUNET_SERVER_mst_destroy (ps->msgtok);
+
+ msg = ps->pending_msgs_head;
+ while (msg != NULL)
{
- plugin->env->session_end(plugin, &pc->identity, ps);
- tmp = ps->next;
-
- GNUNET_free_non_null (ps->addr);
- GNUNET_free(ps->url);
- if (ps->msgtok != NULL)
- GNUNET_SERVER_mst_destroy (ps->msgtok);
-
- msg = ps->pending_msgs_head;
- while (msg!=NULL)
- {
- msg_tmp = msg->next;
- GNUNET_free(msg);
- msg = msg_tmp;
- }
- if (ps->direction==OUTBOUND)
- {
- if (ps->send_endpoint!=NULL)
- curl_easy_cleanup(ps->send_endpoint);
- if (ps->recv_endpoint!=NULL)
- curl_easy_cleanup(ps->recv_endpoint);
- }
- GNUNET_free(ps);
- ps=tmp;
+ msg_tmp = msg->next;
+ GNUNET_free (msg);
+ msg = msg_tmp;
}
- GNUNET_free(pc);
+ if (ps->direction == OUTBOUND)
+ {
+ if (ps->send_endpoint != NULL)
+ curl_easy_cleanup (ps->send_endpoint);
+ if (ps->recv_endpoint != NULL)
+ curl_easy_cleanup (ps->recv_endpoint);
+ }
+ GNUNET_free (ps);
+ ps = tmp;
+ }
+ GNUNET_free (pc);
GNUNET_STATISTICS_update (plugin->env->stats,
- gettext_noop ("# HTTP peers active"),
- -1,
- GNUNET_NO);
+ gettext_noop ("# HTTP peers active"),
+ -1, GNUNET_NO);
return GNUNET_YES;
}
@@ -712,115 +709,114 @@
* @param call_msg_cont_result result to call message continuations with
* @return GNUNET_SYSERR if msg not found, GNUNET_OK on success
*/
-static int
-remove_session (struct HTTP_PeerContext * pc,
- struct Session * ps,
- int call_msg_cont,
- int call_msg_cont_result)
+static int
+remove_session (struct HTTP_PeerContext *pc,
+ struct Session *ps, int call_msg_cont, int
call_msg_cont_result)
{
- struct HTTP_Message * msg;
- struct Plugin * plugin = ps->peercontext->plugin;
+ struct HTTP_Message *msg;
+ struct Plugin *plugin = ps->peercontext->plugin;
#if DEBUG_CONNECTIONS
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connection %X: removing %s session %X with id %u\n",
- ps,
- (ps->direction == INBOUND)
- ? "inbound"
- : "outbound",
- ps, ps->session_id);
+ "Connection %X: removing %s session %X with id %u\n",
+ ps,
+ (ps->direction == INBOUND)
+ ? "inbound" : "outbound", ps, ps->session_id);
#endif
- plugin->env->session_end(plugin, &pc->identity, ps);
+ plugin->env->session_end (plugin, &pc->identity, ps);
GNUNET_free_non_null (ps->addr);
GNUNET_SERVER_mst_destroy (ps->msgtok);
- GNUNET_free(ps->url);
- if (ps->direction==INBOUND)
+ GNUNET_free (ps->url);
+ if (ps->direction == INBOUND)
+ {
+ if (ps->recv_endpoint != NULL)
{
- if (ps->recv_endpoint != NULL)
- {
- curl_easy_cleanup(ps->recv_endpoint);
- ps->recv_endpoint = NULL;
- }
- if (ps->send_endpoint != NULL)
- {
- curl_easy_cleanup(ps->send_endpoint);
- ps->send_endpoint = NULL;
- }
+ curl_easy_cleanup (ps->recv_endpoint);
+ ps->recv_endpoint = NULL;
}
-
+ if (ps->send_endpoint != NULL)
+ {
+ curl_easy_cleanup (ps->send_endpoint);
+ ps->send_endpoint = NULL;
+ }
+ }
+
msg = ps->pending_msgs_head;
- while (msg!=NULL)
+ while (msg != NULL)
+ {
+ if ((call_msg_cont == GNUNET_YES) && (msg->transmit_cont != NULL))
{
- if ((call_msg_cont == GNUNET_YES) && (msg->transmit_cont!=NULL))
- {
- msg->transmit_cont (msg->transmit_cont_cls,
- &pc->identity,
- call_msg_cont_result);
- }
- GNUNET_CONTAINER_DLL_remove(ps->pending_msgs_head,
- ps->pending_msgs_head,
- msg);
- GNUNET_free(msg);
- msg = ps->pending_msgs_head;
+ msg->transmit_cont (msg->transmit_cont_cls,
+ &pc->identity, call_msg_cont_result);
}
-
- GNUNET_CONTAINER_DLL_remove(pc->head,pc->tail,ps);
- GNUNET_free(ps);
+ GNUNET_CONTAINER_DLL_remove (ps->pending_msgs_head,
+ ps->pending_msgs_head, msg);
+ GNUNET_free (msg);
+ msg = ps->pending_msgs_head;
+ }
+
+ GNUNET_CONTAINER_DLL_remove (pc->head, pc->tail, ps);
+ GNUNET_free (ps);
ps = NULL;
/* no sessions left remove peer */
- if (pc->head==NULL)
- {
+ if (pc->head == NULL)
+ {
#if DEBUG_HTTP
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "No sessions left for peer `%s', removing context\n",
- GNUNET_i2s(&pc->identity));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "No sessions left for peer `%s', removing context\n",
+ GNUNET_i2s (&pc->identity));
#endif
- remove_peer_context_Iterator(plugin, &pc->identity.hashPubKey, pc);
- }
-
+ remove_peer_context_Iterator (plugin, &pc->identity.hashPubKey, pc);
+ }
+
return GNUNET_OK;
}
#if 0
-static int check_localaddress (const struct sockaddr *addr, socklen_t addrlen)
+static int
+check_localaddress (const struct sockaddr *addr, socklen_t addrlen)
{
- uint32_t res = 0;
- int local = GNUNET_NO;
- int af = addr->sa_family;
- switch (af)
- {
- case AF_INET:
- {
- uint32_t netmask = 0x7F000000;
- uint32_t address = ntohl (((struct sockaddr_in *)
addr)->sin_addr.s_addr);
- res = (address >> 24) ^ (netmask >> 24);
- if (res != 0)
- local = GNUNET_NO;
- else
- local = GNUNET_YES;
+ uint32_t res = 0;
+ int local = GNUNET_NO;
+ int af = addr->sa_family;
+
+ switch (af)
+ {
+ case AF_INET:
+ {
+ uint32_t netmask = 0x7F000000;
+ uint32_t address = ntohl (((struct sockaddr_in *) addr)->sin_addr.s_addr);
+
+ res = (address >> 24) ^ (netmask >> 24);
+ if (res != 0)
+ local = GNUNET_NO;
+ else
+ local = GNUNET_YES;
#if DEBUG_HTTP
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Checking IPv4 address `%s': %s\n", GNUNET_a2s (addr,
addrlen), (local==GNUNET_YES) ? "local" : "global");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Checking IPv4 address `%s': %s\n", GNUNET_a2s (addr, addrlen),
+ (local == GNUNET_YES) ? "local" : "global");
#endif
- break;
- }
- case AF_INET6:
- {
- if (IN6_IS_ADDR_LOOPBACK (&((struct sockaddr_in6 *)
addr)->sin6_addr) ||
- IN6_IS_ADDR_LINKLOCAL (&((struct sockaddr_in6 *)
addr)->sin6_addr))
- local = GNUNET_YES;
- else
- local = GNUNET_NO;
+ break;
+ }
+ case AF_INET6:
+ {
+ if (IN6_IS_ADDR_LOOPBACK (&((struct sockaddr_in6 *) addr)->sin6_addr) ||
+ IN6_IS_ADDR_LINKLOCAL (&((struct sockaddr_in6 *) addr)->sin6_addr))
+ local = GNUNET_YES;
+ else
+ local = GNUNET_NO;
#if DEBUG_HTTP
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Checking IPv6 address `%s' : %s\n", GNUNET_a2s
(addr, addrlen), (local==GNUNET_YES) ? "local" : "global");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Checking IPv6 address `%s' : %s\n", GNUNET_a2s (addr,
addrlen),
+ (local == GNUNET_YES) ? "local" : "global");
#endif
- break;
- }
- }
- return local;
+ break;
+ }
+ }
+ return local;
}
@@ -842,99 +838,103 @@
const struct sockaddr *addr, socklen_t addrlen)
{
struct Plugin *plugin = cls;
- struct IPv4HttpAddress * t4;
- struct IPv6HttpAddress * t6;
+ struct IPv4HttpAddress *t4;
+ struct IPv6HttpAddress *t6;
int af;
if (plugin->use_localaddresses == GNUNET_NO)
{
- if (GNUNET_YES == check_localaddress (addr, addrlen))
- {
+ if (GNUNET_YES == check_localaddress (addr, addrlen))
+ {
#if DEBUG_HTTP
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
- PROTOCOL_PREFIX,
- "Not notifying transport of address `%s' (local
address)\n",
- GNUNET_a2s (addr, addrlen));
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
+ PROTOCOL_PREFIX,
+ "Not notifying transport of address `%s' (local
address)\n",
+ GNUNET_a2s (addr, addrlen));
#endif
- return GNUNET_OK;
- }
+ return GNUNET_OK;
+ }
}
- GNUNET_assert(cls !=NULL);
+ GNUNET_assert (cls != NULL);
af = addr->sa_family;
if ((af == AF_INET) &&
- (plugin->use_ipv4 == GNUNET_YES) &&
- (plugin->bind6_address == NULL) ) {
+ (plugin->use_ipv4 == GNUNET_YES) && (plugin->bind6_address == NULL))
+ {
- struct in_addr bnd_cmp = ((struct sockaddr_in *) addr)->sin_addr;
- t4 = GNUNET_malloc(sizeof(struct IPv4HttpAddress));
- // Not skipping loopback addresses
+ struct in_addr bnd_cmp = ((struct sockaddr_in *) addr)->sin_addr;
+ t4 = GNUNET_malloc (sizeof (struct IPv4HttpAddress));
+ // Not skipping loopback addresses
- t4->ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr;
- t4->port = htons (plugin->port_inbound);
- if (plugin->bind4_address != NULL) {
- if (0 == memcmp(&plugin->bind4_address->sin_addr, &bnd_cmp, sizeof
(struct in_addr)))
- {
- GNUNET_CONTAINER_DLL_insert(plugin->ipv4_addr_head,
- plugin->ipv4_addr_tail,t4);
- plugin->env->notify_address(plugin->env->cls,
- GNUNET_YES,
- t4, sizeof (struct
IPv4HttpAddress));
- return GNUNET_OK;
- }
- GNUNET_free (t4);
- return GNUNET_OK;
+
+ t4->ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr;
+ t4->port = htons (plugin->port_inbound);
+ if (plugin->bind4_address != NULL)
+ {
+ if (0 ==
+ memcmp (&plugin->bind4_address->sin_addr, &bnd_cmp,
+ sizeof (struct in_addr)))
+ {
+ GNUNET_CONTAINER_DLL_insert (plugin->ipv4_addr_head,
+ plugin->ipv4_addr_tail, t4);
+ plugin->env->notify_address (plugin->env->cls,
+ GNUNET_YES,
+ t4, sizeof (struct IPv4HttpAddress));
+ return GNUNET_OK;
}
- else
- {
- GNUNET_CONTAINER_DLL_insert (plugin->ipv4_addr_head,
- plugin->ipv4_addr_tail,
- t4);
- plugin->env->notify_address(plugin->env->cls,
- GNUNET_YES,
- t4, sizeof (struct IPv4HttpAddress));
- return GNUNET_OK;
- }
- }
- if ((af == AF_INET6) &&
- (plugin->use_ipv6 == GNUNET_YES) &&
- (plugin->bind4_address == NULL) ) {
+ GNUNET_free (t4);
+ return GNUNET_OK;
+ }
+ else
+ {
+ GNUNET_CONTAINER_DLL_insert (plugin->ipv4_addr_head,
+ plugin->ipv4_addr_tail, t4);
+ plugin->env->notify_address (plugin->env->cls,
+ GNUNET_YES,
+ t4, sizeof (struct IPv4HttpAddress));
+ return GNUNET_OK;
+ }
+ }
+ if ((af == AF_INET6) &&
+ (plugin->use_ipv6 == GNUNET_YES) && (plugin->bind4_address == NULL))
+ {
- struct in6_addr bnd_cmp6 = ((struct sockaddr_in6 *) addr)->sin6_addr;
+ struct in6_addr bnd_cmp6 = ((struct sockaddr_in6 *) addr)->sin6_addr;
- t6 = GNUNET_malloc(sizeof(struct IPv6HttpAddress));
- GNUNET_assert(t6 != NULL);
+ t6 = GNUNET_malloc (sizeof (struct IPv6HttpAddress));
+ GNUNET_assert (t6 != NULL);
- if (plugin->bind6_address != NULL) {
- if (0 == memcmp(&plugin->bind6_address->sin6_addr,
- &bnd_cmp6,
- sizeof (struct in6_addr))) {
- memcpy (&t6->ipv6_addr,
- &((struct sockaddr_in6 *) addr)->sin6_addr,
- sizeof (struct in6_addr));
- t6->port = htons (plugin->port_inbound);
- plugin->env->notify_address(plugin->env->cls,
- GNUNET_YES,
- t6, sizeof (struct IPv6HttpAddress));
- GNUNET_CONTAINER_DLL_insert(plugin->ipv6_addr_head,
- plugin->ipv6_addr_tail,
- t6);
- return GNUNET_OK;
- }
- GNUNET_free (t6);
- return GNUNET_OK;
- }
- memcpy (&t6->ipv6_addr,
- &((struct sockaddr_in6 *) addr)->sin6_addr,
- sizeof (struct in6_addr));
- t6->port = htons (plugin->port_inbound);
-
GNUNET_CONTAINER_DLL_insert(plugin->ipv6_addr_head,plugin->ipv6_addr_tail,t6);
+ if (plugin->bind6_address != NULL)
+ {
+ if (0 == memcmp (&plugin->bind6_address->sin6_addr,
+ &bnd_cmp6, sizeof (struct in6_addr)))
+ {
+ memcpy (&t6->ipv6_addr,
+ &((struct sockaddr_in6 *) addr)->sin6_addr,
+ sizeof (struct in6_addr));
+ t6->port = htons (plugin->port_inbound);
+ plugin->env->notify_address (plugin->env->cls,
+ GNUNET_YES,
+ t6, sizeof (struct IPv6HttpAddress));
+ GNUNET_CONTAINER_DLL_insert (plugin->ipv6_addr_head,
+ plugin->ipv6_addr_tail, t6);
+ return GNUNET_OK;
+ }
+ GNUNET_free (t6);
+ return GNUNET_OK;
+ }
+ memcpy (&t6->ipv6_addr,
+ &((struct sockaddr_in6 *) addr)->sin6_addr,
+ sizeof (struct in6_addr));
+ t6->port = htons (plugin->port_inbound);
+ GNUNET_CONTAINER_DLL_insert (plugin->ipv6_addr_head,
plugin->ipv6_addr_tail,
+ t6);
- plugin->env->notify_address(plugin->env->cls,
- GNUNET_YES,
- t6, sizeof (struct IPv6HttpAddress));
+ plugin->env->notify_address (plugin->env->cls,
+ GNUNET_YES,
+ t6, sizeof (struct IPv6HttpAddress));
}
return GNUNET_OK;
}
@@ -946,69 +946,62 @@
* @param fmt format string
* @param ap list of arguments
*/
-static void
-mhd_logger (void * arg,
- const char * fmt,
- va_list ap)
+static void
+mhd_logger (void *arg, const char *fmt, va_list ap)
{
char text[1024];
- vsnprintf(text, sizeof(text), fmt, ap);
- va_end(ap);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "MHD: %s\n",
- text);
+ vsnprintf (text, sizeof (text), fmt, ap);
+ va_end (ap);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "MHD: %s\n", text);
}
-static void
-mhd_termination_cb (void *cls,
- struct MHD_Connection * connection,
- void **httpSessionCache)
+static void
+mhd_termination_cb (void *cls,
+ struct MHD_Connection *connection, void **httpSessionCache)
{
- struct Session * ps = *httpSessionCache;
+ struct Session *ps = *httpSessionCache;
+
if (ps == NULL)
return;
- struct HTTP_PeerContext * pc = ps->peercontext;
+ struct HTTP_PeerContext *pc = ps->peercontext;
struct Plugin *plugin = cls;
GNUNET_assert (cls != NULL);
- plugin->current_connections--;
+ plugin->current_connections--;
- if (connection==ps->recv_endpoint)
- {
+ if (connection == ps->recv_endpoint)
+ {
#if DEBUG_CONNECTIONS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connection %X: inbound connection from peer `%s' was
terminated\n",
- ps,
- GNUNET_i2s(&pc->identity));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Connection %X: inbound connection from peer `%s' was
terminated\n",
+ ps, GNUNET_i2s (&pc->identity));
#endif
- ps->recv_active = GNUNET_NO;
- ps->recv_connected = GNUNET_NO;
- ps->recv_endpoint = NULL;
- }
- if (connection==ps->send_endpoint)
- {
- ps->send_active = GNUNET_NO;
- ps->send_connected = GNUNET_NO;
- ps->send_endpoint = NULL;
+ ps->recv_active = GNUNET_NO;
+ ps->recv_connected = GNUNET_NO;
+ ps->recv_endpoint = NULL;
+ }
+ if (connection == ps->send_endpoint)
+ {
+ ps->send_active = GNUNET_NO;
+ ps->send_connected = GNUNET_NO;
+ ps->send_endpoint = NULL;
#if DEBUG_CONNECTIONS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connection %X: outbound connection from peer `%s' was
terminated\n",
- ps,
- GNUNET_i2s(&pc->identity));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Connection %X: outbound connection from peer `%s' was
terminated\n",
+ ps, GNUNET_i2s (&pc->identity));
#endif
- }
+ }
/* if both connections disconnected, remove session */
- if ( (ps->send_connected == GNUNET_NO) &&
- (ps->recv_connected == GNUNET_NO) )
+ if ((ps->send_connected == GNUNET_NO) && (ps->recv_connected == GNUNET_NO))
{
GNUNET_STATISTICS_update (pc->plugin->env->stats,
- gettext_noop ("# HTTP inbound sessions for peers
active"),
- -1,
- GNUNET_NO);
- remove_session(pc,ps,GNUNET_YES,GNUNET_SYSERR);
+ gettext_noop
+ ("# HTTP inbound sessions for peers active"), -1,
+ GNUNET_NO);
+ remove_session (pc, ps, GNUNET_YES, GNUNET_SYSERR);
}
}
@@ -1019,54 +1012,52 @@
* @param client clien
* @param message the message to be forwarded to transport service
*/
-static void
+static void
mhd_write_mst_cb (void *cls,
- void *client,
- const struct GNUNET_MessageHeader *message)
+ void *client, const struct GNUNET_MessageHeader *message)
{
- struct Session *ps = cls;
+ struct Session *ps = cls;
struct HTTP_PeerContext *pc;
struct GNUNET_TIME_Relative delay;
- GNUNET_assert(ps != NULL);
+ GNUNET_assert (ps != NULL);
pc = ps->peercontext;
- GNUNET_assert(pc != NULL);
+ GNUNET_assert (pc != NULL);
#if DEBUG_HTTP
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connection %X: Forwarding message to transport service, type %u
and size %u from `%s' (`%s')\n",
- ps,
- ntohs(message->type),
- ntohs(message->size),
- GNUNET_i2s(&(ps->peercontext)->identity),
- http_plugin_address_to_string(NULL,ps->addr,ps->addrlen));
+ "Connection %X: Forwarding message to transport service, type %u
and size %u from `%s' (`%s')\n",
+ ps,
+ ntohs (message->type),
+ ntohs (message->size),
+ GNUNET_i2s (&(ps->peercontext)->identity),
+ http_plugin_address_to_string (NULL, ps->addr, ps->addrlen));
#endif
struct GNUNET_TRANSPORT_ATS_Information distance[2];
+
distance[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE);
distance[0].value = htonl (1);
distance[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
distance[1].value = htonl (0);
delay = pc->plugin->env->receive (ps->peercontext->plugin->env->cls,
- &pc->identity,
- message,
- (const struct
GNUNET_TRANSPORT_ATS_Information *) &distance,
- 2,
- ps,
- NULL,
- 0);
+ &pc->identity,
+ message,
+ (const struct
+ GNUNET_TRANSPORT_ATS_Information *)
+ &distance, 2, ps, NULL, 0);
pc->delay = delay;
if (pc->reset_task != GNUNET_SCHEDULER_NO_TASK)
GNUNET_SCHEDULER_cancel (pc->reset_task);
-
+
if (delay.rel_value > 0)
- {
+ {
#if DEBUG_HTTP
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connection %X: Inbound quota management: delay next read for
%llu ms \n",
- ps,
- delay.rel_value);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Connection %X: Inbound quota management: delay next read for
%llu ms \n",
+ ps, delay.rel_value);
#endif
- pc->reset_task = GNUNET_SCHEDULER_add_delayed (delay,
&reset_inbound_quota_delay, pc);
- }
+ pc->reset_task =
+ GNUNET_SCHEDULER_add_delayed (delay, &reset_inbound_quota_delay, pc);
+ }
}
@@ -1080,19 +1071,19 @@
*
*/
static int
-mhd_accept_cb (void *cls,
- const struct sockaddr *addr,
- socklen_t addr_len)
+mhd_accept_cb (void *cls, const struct sockaddr *addr, socklen_t addr_len)
{
struct Plugin *plugin = cls;
+
GNUNET_assert (cls != NULL);
if (plugin->max_connect_per_transport > plugin->current_connections)
{
- plugin->current_connections ++;
+ plugin->current_connections++;
return MHD_YES;
}
- else return MHD_NO;
+ else
+ return MHD_NO;
}
@@ -1107,55 +1098,52 @@
static ssize_t
mhd_send_callback (void *cls, uint64_t pos, char *buf, size_t max)
{
- struct Session * ps = cls;
- struct HTTP_PeerContext * pc;
- struct HTTP_Message * msg;
+ struct Session *ps = cls;
+ struct HTTP_PeerContext *pc;
+ struct HTTP_Message *msg;
int bytes_read = 0;
- GNUNET_assert (ps!=NULL);
+ GNUNET_assert (ps != NULL);
pc = ps->peercontext;
msg = ps->pending_msgs_tail;
- if (ps->send_force_disconnect==GNUNET_YES)
- {
+ if (ps->send_force_disconnect == GNUNET_YES)
+ {
#if DEBUG_CONNECTIONS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connection %X: outbound forced to disconnect\n",
- ps);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Connection %X: outbound forced to disconnect\n", ps);
#endif
- return -1;
+ return -1;
+ }
+
+ if (msg != NULL)
+ {
+ /* sending */
+ if ((msg->size - msg->pos) <= max)
+ {
+ memcpy (buf, &msg->buf[msg->pos], (msg->size - msg->pos));
+ bytes_read = msg->size - msg->pos;
+ msg->pos += (msg->size - msg->pos);
}
-
- if (msg!=NULL)
+ else
{
- /* sending */
- if ((msg->size-msg->pos) <= max)
- {
- memcpy(buf,&msg->buf[msg->pos],(msg->size-msg->pos));
- bytes_read = msg->size-msg->pos;
- msg->pos+=(msg->size-msg->pos);
- }
- else
- {
- memcpy(buf,&msg->buf[msg->pos],max);
- msg->pos+=max;
- bytes_read = max;
- }
-
- /* removing message */
- if (msg->pos==msg->size)
- {
- if (NULL!=msg->transmit_cont)
- msg->transmit_cont (msg->transmit_cont_cls,&pc->identity,GNUNET_OK);
- ps->queue_length_cur -= msg->size;
- remove_http_message(ps,msg);
- }
+ memcpy (buf, &msg->buf[msg->pos], max);
+ msg->pos += max;
+ bytes_read = max;
}
+
+ /* removing message */
+ if (msg->pos == msg->size)
+ {
+ if (NULL != msg->transmit_cont)
+ msg->transmit_cont (msg->transmit_cont_cls, &pc->identity, GNUNET_OK);
+ ps->queue_length_cur -= msg->size;
+ remove_http_message (ps, msg);
+ }
+ }
#if DEBUG_CONNECTIONS
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connection %X: MHD has sent %u bytes\n",
- ps,
- bytes_read);
+ "Connection %X: MHD has sent %u bytes\n", ps, bytes_read);
#endif
return bytes_read;
}
@@ -1170,21 +1158,20 @@
*/
static int
mhd_access_cb (void *cls,
- struct MHD_Connection *mhd_connection,
- const char *url,
- const char *method,
- const char *version,
- const char *upload_data,
- size_t * upload_data_size,
- void **httpSessionCache)
+ struct MHD_Connection *mhd_connection,
+ const char *url,
+ const char *method,
+ const char *version,
+ const char *upload_data,
+ size_t * upload_data_size, void **httpSessionCache)
{
struct Plugin *plugin = cls;
struct MHD_Response *response;
- const union MHD_ConnectionInfo * conn_info;
+ const union MHD_ConnectionInfo *conn_info;
const struct sockaddr *client_addr;
- const struct sockaddr_in *addrin;
+ const struct sockaddr_in *addrin;
const struct sockaddr_in6 *addrin6;
- char address[INET6_ADDRSTRLEN+14];
+ char address[INET6_ADDRSTRLEN + 14];
struct GNUNET_PeerIdentity pi_in;
size_t id_num = 0;
struct IPv4HttpAddress ipv4addr;
@@ -1193,251 +1180,259 @@
struct Session *ps = NULL;
struct Session *ps_tmp = NULL;
int res = GNUNET_NO;
- void * addr = NULL;
- size_t addr_len = 0 ;
+ void *addr = NULL;
+ size_t addr_len = 0;
- GNUNET_assert(cls !=NULL);
+ GNUNET_assert (cls != NULL);
if (NULL == *httpSessionCache)
+ {
+ /* check url for peer identity , if invalid send HTTP 404 */
+ size_t len = strlen (&url[1]);
+ char *peer = GNUNET_malloc (104 + 1);
+
+ if ((len > 104) && (url[104] == ';'))
{
- /* check url for peer identity , if invalid send HTTP 404*/
- size_t len = strlen(&url[1]);
- char * peer = GNUNET_malloc(104+1);
-
- if ( (len>104) && (url[104]==';'))
- {
- char * id = GNUNET_malloc((len-104)+1);
- strcpy(id,&url[105]);
- memcpy(peer,&url[1],103);
- peer[103] = '\0';
- id_num = strtoul ( id, NULL , 10);
- GNUNET_free(id);
+ char *id = GNUNET_malloc ((len - 104) + 1);
+
+ strcpy (id, &url[105]);
+ memcpy (peer, &url[1], 103);
+ peer[103] = '\0';
+ id_num = strtoul (id, NULL, 10);
+ GNUNET_free (id);
}
res = GNUNET_CRYPTO_hash_from_string (peer, &(pi_in.hashPubKey));
- GNUNET_free(peer);
- if ( GNUNET_SYSERR == res )
- {
- 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);
+ GNUNET_free (peer);
+ if (GNUNET_SYSERR == res)
+ {
+ 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);
#if DEBUG_CONNECTIONS
if (res == MHD_YES)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peer has no valid ident, sent HTTP 1.1/404\n");
+ "Peer has no valid ident, sent HTTP 1.1/404\n");
else
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peer has no valid ident, could not send error\n");
+ "Peer has no valid ident, could not send error\n");
#endif
return res;
- }
}
+ }
else
+ {
+ ps = *httpSessionCache;
+ pc = ps->peercontext;
+ }
+
+ if (NULL == *httpSessionCache)
+ {
+ /* get peer context */
+ pc = GNUNET_CONTAINER_multihashmap_get (plugin->peers, &pi_in.hashPubKey);
+ /* Peer unknown */
+ if (pc == NULL)
{
- ps = *httpSessionCache;
- pc = ps->peercontext;
+ pc = GNUNET_malloc (sizeof (struct HTTP_PeerContext));
+ pc->plugin = plugin;
+ pc->session_id_counter = 1;
+ pc->last_session = NULL;
+ memcpy (&pc->identity, &pi_in, sizeof (struct GNUNET_PeerIdentity));
+ GNUNET_CONTAINER_multihashmap_put (plugin->peers,
+ &pc->identity.hashPubKey,
+ pc,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+ GNUNET_STATISTICS_update (plugin->env->stats,
+ gettext_noop ("# HTTP peers active"),
+ 1, GNUNET_NO);
}
-
- if (NULL == *httpSessionCache)
+
+ conn_info =
+ MHD_get_connection_info (mhd_connection,
+ MHD_CONNECTION_INFO_CLIENT_ADDRESS);
+ /* Incoming IPv4 connection */
+ /* cast required for legacy MHD API < 0.9.6 */
+ client_addr = (const struct sockaddr *) conn_info->client_addr;
+ if (AF_INET == client_addr->sa_family)
{
- /* get peer context */
- pc = GNUNET_CONTAINER_multihashmap_get (plugin->peers,
&pi_in.hashPubKey);
- /* Peer unknown */
- if (pc==NULL)
- {
- pc = GNUNET_malloc(sizeof (struct HTTP_PeerContext));
- pc->plugin = plugin;
- pc->session_id_counter=1;
- pc->last_session = NULL;
- memcpy(&pc->identity, &pi_in, sizeof(struct GNUNET_PeerIdentity));
- GNUNET_CONTAINER_multihashmap_put(plugin->peers,
- &pc->identity.hashPubKey,
- pc,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
- GNUNET_STATISTICS_update (plugin->env->stats,
- gettext_noop ("# HTTP peers active"),
- 1,
- GNUNET_NO);
- }
+ addrin = (const struct sockaddr_in *) client_addr;
+ inet_ntop (addrin->sin_family, &(addrin->sin_addr), address,
+ INET_ADDRSTRLEN);
+ memcpy (&ipv4addr.ipv4_addr, &(addrin->sin_addr),
+ sizeof (struct in_addr));
+ ipv4addr.port = addrin->sin_port;
+ addr = &ipv4addr;
+ addr_len = sizeof (struct IPv4HttpAddress);
+ }
+ /* Incoming IPv6 connection */
+ if (AF_INET6 == client_addr->sa_family)
+ {
+ addrin6 = (const struct sockaddr_in6 *) client_addr;
+ inet_ntop (addrin6->sin6_family, &(addrin6->sin6_addr), address,
+ INET6_ADDRSTRLEN);
+ memcpy (&ipv6addr.ipv6_addr, &(addrin6->sin6_addr),
+ sizeof (struct in6_addr));
+ ipv6addr.port = addrin6->sin6_port;
+ addr = &ipv6addr;
+ addr_len = sizeof (struct IPv6HttpAddress);
+ }
- conn_info = MHD_get_connection_info(mhd_connection,
MHD_CONNECTION_INFO_CLIENT_ADDRESS );
- /* Incoming IPv4 connection */
- /* cast required for legacy MHD API < 0.9.6 */
- client_addr = (const struct sockaddr *) conn_info->client_addr;
- if ( AF_INET == client_addr->sa_family)
- {
- addrin = (const struct sockaddr_in*) client_addr;
- inet_ntop(addrin->sin_family,
&(addrin->sin_addr),address,INET_ADDRSTRLEN);
- memcpy(&ipv4addr.ipv4_addr,&(addrin->sin_addr),sizeof(struct
in_addr));
- ipv4addr.port = addrin->sin_port;
- addr = &ipv4addr;
- addr_len = sizeof(struct IPv4HttpAddress);
- }
- /* Incoming IPv6 connection */
- if ( AF_INET6 == client_addr->sa_family)
- {
- addrin6 = (const struct sockaddr_in6 *) client_addr;
- inet_ntop(addrin6->sin6_family,
&(addrin6->sin6_addr),address,INET6_ADDRSTRLEN);
- memcpy(&ipv6addr.ipv6_addr,&(addrin6->sin6_addr),sizeof(struct
in6_addr));
- ipv6addr.port = addrin6->sin6_port;
- addr = &ipv6addr;
- addr_len = sizeof(struct IPv6HttpAddress);
- }
-
- GNUNET_assert (addr != NULL);
- GNUNET_assert (addr_len != 0);
-
- ps = NULL;
- /* only inbound sessions here */
-
- ps_tmp = pc->head;
- while (ps_tmp!=NULL)
- {
- if ((ps_tmp->direction==INBOUND) && (ps_tmp->session_id == id_num) &&
(id_num!=0))
- {
- if ((ps_tmp->recv_force_disconnect!=GNUNET_YES) &&
(ps_tmp->send_force_disconnect!=GNUNET_YES))
- ps=ps_tmp;
- break;
- }
- ps_tmp=ps_tmp->next;
- }
-
- if (ps==NULL)
- {
- ps = GNUNET_malloc(sizeof (struct Session));
- ps->addr = GNUNET_malloc(addr_len);
- memcpy(ps->addr,addr,addr_len);
- ps->addrlen = addr_len;
- ps->direction=INBOUND;
- ps->pending_msgs_head = NULL;
- ps->pending_msgs_tail = NULL;
- ps->send_connected=GNUNET_NO;
- ps->send_active=GNUNET_NO;
- ps->recv_connected=GNUNET_NO;
- ps->recv_active=GNUNET_NO;
- ps->peercontext=pc;
- ps->session_id =id_num;
- ps->queue_length_cur = 0;
- ps->queue_length_max = GNUNET_SERVER_MAX_MESSAGE_SIZE;
- ps->url = create_url (plugin, ps->addr, ps->addrlen, ps->session_id);
- GNUNET_CONTAINER_DLL_insert(pc->head,pc->tail,ps);
- GNUNET_STATISTICS_update (plugin->env->stats,
- gettext_noop ("# HTTP inbound sessions for
peers active"),
- 1,
- GNUNET_NO);
- }
-
- *httpSessionCache = ps;
- if (ps->msgtok==NULL)
- ps->msgtok = GNUNET_SERVER_mst_create (&mhd_write_mst_cb, ps);
+ GNUNET_assert (addr != NULL);
+ GNUNET_assert (addr_len != 0);
+
+ ps = NULL;
+ /* only inbound sessions here */
+
+ ps_tmp = pc->head;
+ while (ps_tmp != NULL)
+ {
+ if ((ps_tmp->direction == INBOUND) && (ps_tmp->session_id == id_num) &&
+ (id_num != 0))
+ {
+ if ((ps_tmp->recv_force_disconnect != GNUNET_YES) &&
+ (ps_tmp->send_force_disconnect != GNUNET_YES))
+ ps = ps_tmp;
+ break;
+ }
+ ps_tmp = ps_tmp->next;
+ }
+
+ if (ps == NULL)
+ {
+ ps = GNUNET_malloc (sizeof (struct Session));
+ ps->addr = GNUNET_malloc (addr_len);
+ memcpy (ps->addr, addr, addr_len);
+ ps->addrlen = addr_len;
+ ps->direction = INBOUND;
+ ps->pending_msgs_head = NULL;
+ ps->pending_msgs_tail = NULL;
+ ps->send_connected = GNUNET_NO;
+ ps->send_active = GNUNET_NO;
+ ps->recv_connected = GNUNET_NO;
+ ps->recv_active = GNUNET_NO;
+ ps->peercontext = pc;
+ ps->session_id = id_num;
+ ps->queue_length_cur = 0;
+ ps->queue_length_max = GNUNET_SERVER_MAX_MESSAGE_SIZE;
+ ps->url = create_url (plugin, ps->addr, ps->addrlen, ps->session_id);
+ GNUNET_CONTAINER_DLL_insert (pc->head, pc->tail, ps);
+ GNUNET_STATISTICS_update (plugin->env->stats,
+ gettext_noop
+ ("# HTTP inbound sessions for peers active"),
1,
+ GNUNET_NO);
+ }
+
+ *httpSessionCache = ps;
+ if (ps->msgtok == NULL)
+ ps->msgtok = GNUNET_SERVER_mst_create (&mhd_write_mst_cb, ps);
#if DEBUG_HTTP
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connection %X: HTTP Daemon has new an incoming `%s' request
from peer `%s' (`%s')\n",
- ps,
- method,
- GNUNET_i2s(&pc->identity),
- http_plugin_address_to_string(NULL, ps->addr, ps->addrlen));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Connection %X: HTTP Daemon has new an incoming `%s' request
from peer `%s' (`%s')\n",
+ ps,
+ method,
+ GNUNET_i2s (&pc->identity),
+ http_plugin_address_to_string (NULL, ps->addr, ps->addrlen));
#endif
- }
-
+ }
+
/* Is it a PUT or a GET request */
if (0 == strcmp (MHD_HTTP_METHOD_PUT, method))
+ {
+ if (ps->recv_force_disconnect == GNUNET_YES)
{
- if (ps->recv_force_disconnect == GNUNET_YES)
- {
#if DEBUG_CONNECTIONS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connection %X: inbound connection was forced to
disconnect\n",ps);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Connection %X: inbound connection was forced to
disconnect\n",
+ ps);
#endif
- ps->recv_active = GNUNET_NO;
- return MHD_NO;
- }
- if ((*upload_data_size == 0) && (ps->recv_active==GNUNET_NO))
- {
- ps->recv_endpoint = mhd_connection;
- ps->recv_connected = GNUNET_YES;
- ps->recv_active = GNUNET_YES;
- ps->recv_force_disconnect = GNUNET_NO;
+ ps->recv_active = GNUNET_NO;
+ return MHD_NO;
+ }
+ if ((*upload_data_size == 0) && (ps->recv_active == GNUNET_NO))
+ {
+ ps->recv_endpoint = mhd_connection;
+ ps->recv_connected = GNUNET_YES;
+ ps->recv_active = GNUNET_YES;
+ ps->recv_force_disconnect = GNUNET_NO;
#if DEBUG_CONNECTIONS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connection %X: inbound PUT connection connected\n",ps);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Connection %X: inbound PUT connection connected\n", ps);
#endif
- return MHD_YES;
- }
-
- /* Transmission of all data complete */
- if ((*upload_data_size == 0) && (ps->recv_active == GNUNET_YES))
- {
- response = MHD_create_response_from_data (strlen (HTTP_PUT_RESPONSE),
- HTTP_PUT_RESPONSE,
- MHD_NO, MHD_NO);
- res = MHD_queue_response (mhd_connection, MHD_HTTP_OK, response);
+ return MHD_YES;
+ }
+
+ /* Transmission of all data complete */
+ if ((*upload_data_size == 0) && (ps->recv_active == GNUNET_YES))
+ {
+ response = MHD_create_response_from_data (strlen (HTTP_PUT_RESPONSE),
+ HTTP_PUT_RESPONSE,
+ MHD_NO, MHD_NO);
+ res = MHD_queue_response (mhd_connection, MHD_HTTP_OK, response);
#if DEBUG_CONNECTIONS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connection %X: Sent HTTP/1.1: 200 OK as PUT Response\n",
- ps);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Connection %X: Sent HTTP/1.1: 200 OK as PUT Response\n",
ps);
#endif
- MHD_destroy_response (response);
- ps->recv_active=GNUNET_NO;
- return MHD_YES;
- }
-
- /* Recieving data */
- if ((*upload_data_size > 0) && (ps->recv_active == GNUNET_YES))
- {
- if (pc->delay.rel_value == 0)
- {
+ MHD_destroy_response (response);
+ ps->recv_active = GNUNET_NO;
+ return MHD_YES;
+ }
+
+ /* Recieving data */
+ if ((*upload_data_size > 0) && (ps->recv_active == GNUNET_YES))
+ {
+ if (pc->delay.rel_value == 0)
+ {
#if DEBUG_HTTP
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connection %X: PUT with %u bytes forwarded to
MST\n",
- ps, *upload_data_size);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Connection %X: PUT with %u bytes forwarded to MST\n",
+ ps, *upload_data_size);
#endif
- res = GNUNET_SERVER_mst_receive(ps->msgtok, ps,
- upload_data, *upload_data_size,
- GNUNET_NO, GNUNET_NO);
- (*upload_data_size) = 0;
- }
- else
- {
+ res = GNUNET_SERVER_mst_receive (ps->msgtok, ps,
+ upload_data, *upload_data_size,
+ GNUNET_NO, GNUNET_NO);
+ (*upload_data_size) = 0;
+ }
+ else
+ {
#if DEBUG_HTTP
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connection %X: no inbound bandwidth available! Next
read was delayed for %llu ms\n",
- ps,
- ps->peercontext->delay.rel_value);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Connection %X: no inbound bandwidth available! Next read
was delayed for %llu ms\n",
+ ps, ps->peercontext->delay.rel_value);
#endif
- }
- return MHD_YES;
- }
- else
- return MHD_NO;
+ }
+ return MHD_YES;
}
- if ( 0 == strcmp (MHD_HTTP_METHOD_GET, method) )
+ else
+ return MHD_NO;
+ }
+ if (0 == strcmp (MHD_HTTP_METHOD_GET, method))
+ {
+ if (ps->send_force_disconnect == GNUNET_YES)
{
- if (ps->send_force_disconnect == GNUNET_YES)
- {
#if DEBUG_CONNECTIONS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connection %X: outbound connection was forced to
disconnect\n",
- ps);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Connection %X: outbound connection was forced to
disconnect\n",
+ ps);
#endif
- ps->send_active = GNUNET_NO;
- return MHD_NO;
- }
- ps->send_connected = GNUNET_YES;
- ps->send_active = GNUNET_YES;
- ps->send_endpoint = mhd_connection;
- ps->send_force_disconnect = GNUNET_NO;
+ ps->send_active = GNUNET_NO;
+ return MHD_NO;
+ }
+ ps->send_connected = GNUNET_YES;
+ ps->send_active = GNUNET_YES;
+ ps->send_endpoint = mhd_connection;
+ ps->send_force_disconnect = GNUNET_NO;
#if DEBUG_CONNECTIONS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connection %X: inbound GET connection connected\n",
- ps);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Connection %X: inbound GET connection connected\n", ps);
#endif
- response = MHD_create_response_from_callback(-1,32 * 1024,
&mhd_send_callback, ps, NULL);
- res = MHD_queue_response (mhd_connection, MHD_HTTP_OK, response);
- MHD_destroy_response (response);
- return MHD_YES;
- }
+ response =
+ MHD_create_response_from_callback (-1, 32 * 1024, &mhd_send_callback,
+ ps, NULL);
+ res = MHD_queue_response (mhd_connection, MHD_HTTP_OK, response);
+ MHD_destroy_response (response);
+ return MHD_YES;
+ }
return MHD_NO;
}
@@ -1451,7 +1446,7 @@
*/
static GNUNET_SCHEDULER_TaskIdentifier
http_server_daemon_prepare (struct Plugin *plugin,
- struct MHD_Daemon *daemon_handle)
+ struct MHD_Daemon *daemon_handle)
{
GNUNET_SCHEDULER_TaskIdentifier ret;
fd_set rs;
@@ -1466,19 +1461,14 @@
struct GNUNET_TIME_Relative tv;
ret = GNUNET_SCHEDULER_NO_TASK;
- FD_ZERO(&rs);
- FD_ZERO(&ws);
- FD_ZERO(&es);
+ FD_ZERO (&rs);
+ FD_ZERO (&ws);
+ FD_ZERO (&es);
wrs = GNUNET_NETWORK_fdset_create ();
wes = GNUNET_NETWORK_fdset_create ();
wws = GNUNET_NETWORK_fdset_create ();
max = -1;
- GNUNET_assert (MHD_YES ==
- MHD_get_fdset (daemon_handle,
- &rs,
- &ws,
- &es,
- &max));
+ GNUNET_assert (MHD_YES == MHD_get_fdset (daemon_handle, &rs, &ws, &es,
&max));
haveto = MHD_get_timeout (daemon_handle, &timeout);
if (haveto == MHD_YES)
tv.rel_value = (uint64_t) timeout;
@@ -1488,37 +1478,33 @@
GNUNET_NETWORK_fdset_copy_native (wws, &ws, max + 1);
GNUNET_NETWORK_fdset_copy_native (wes, &es, max + 1);
if (daemon_handle == plugin->http_server_daemon_v4)
+ {
+ if (plugin->http_server_task_v4 != GNUNET_SCHEDULER_NO_TASK)
{
- if (plugin->http_server_task_v4 != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel(plugin->http_server_task_v4);
- plugin->http_server_daemon_v4 = GNUNET_SCHEDULER_NO_TASK;
- }
-
- ret = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
- GNUNET_SCHEDULER_NO_TASK,
- tv,
- wrs,
- wws,
- &http_server_daemon_v4_run,
- plugin);
+ GNUNET_SCHEDULER_cancel (plugin->http_server_task_v4);
+ plugin->http_server_daemon_v4 = GNUNET_SCHEDULER_NO_TASK;
}
+
+ ret = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
+ GNUNET_SCHEDULER_NO_TASK,
+ tv,
+ wrs,
+ wws, &http_server_daemon_v4_run,
plugin);
+ }
if (daemon_handle == plugin->http_server_daemon_v6)
+ {
+ if (plugin->http_server_task_v6 != GNUNET_SCHEDULER_NO_TASK)
{
- if (plugin->http_server_task_v6 != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel(plugin->http_server_task_v6);
- plugin->http_server_task_v6 = GNUNET_SCHEDULER_NO_TASK;
- }
-
- ret = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
- GNUNET_SCHEDULER_NO_TASK,
- tv,
- wrs,
- wws,
- &http_server_daemon_v6_run,
- plugin);
+ GNUNET_SCHEDULER_cancel (plugin->http_server_task_v6);
+ plugin->http_server_task_v6 = GNUNET_SCHEDULER_NO_TASK;
}
+
+ ret = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
+ GNUNET_SCHEDULER_NO_TASK,
+ tv,
+ wrs,
+ wws, &http_server_daemon_v6_run,
plugin);
+ }
GNUNET_NETWORK_fdset_destroy (wrs);
GNUNET_NETWORK_fdset_destroy (wws);
GNUNET_NETWORK_fdset_destroy (wes);
@@ -1532,39 +1518,40 @@
* @param cls plugin as closure
* @param tc task context
*/
-static void
+static void
http_server_daemon_v4_run (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct Plugin *plugin = cls;
#if DEBUG_SCHEDULING
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY))
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "http_server_daemon_v4_run:
GNUNET_SCHEDULER_REASON_READ_READY\n");
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY))
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "http_server_daemon_v4_run:
GNUNET_SCHEDULER_REASON_WRITE_READY\n");
+ "http_server_daemon_v4_run:
GNUNET_SCHEDULER_REASON_READ_READY\n");
+ if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY))
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "http_server_daemon_v4_run:
GNUNET_SCHEDULER_REASON_WRITE_READY\n");
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT))
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "http_server_daemon_v4_run:
GNUNET_SCHEDULER_REASON_TIMEOUT\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "http_server_daemon_v4_run:
GNUNET_SCHEDULER_REASON_TIMEOUT\n");
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_STARTUP))
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "http_server_daemon_v4_run:
GGNUNET_SCHEDULER_REASON_STARTUP\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "http_server_daemon_v4_run:
GGNUNET_SCHEDULER_REASON_STARTUP\n");
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "http_server_daemon_v4_run:
GGNUNET_SCHEDULER_REASON_SHUTDOWN\n");
-#endif
-
- GNUNET_assert(cls !=NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "http_server_daemon_v4_run:
GGNUNET_SCHEDULER_REASON_SHUTDOWN\n");
+#endif
+
+ GNUNET_assert (cls != NULL);
plugin->http_server_task_v4 = GNUNET_SCHEDULER_NO_TASK;
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
return;
GNUNET_assert (MHD_YES == MHD_run (plugin->http_server_daemon_v4));
- plugin->http_server_task_v4 = http_server_daemon_prepare (plugin,
plugin->http_server_daemon_v4);
- }
+ plugin->http_server_task_v4 =
+ http_server_daemon_prepare (plugin, plugin->http_server_daemon_v4);
+}
/**
@@ -1573,92 +1560,95 @@
* @param cls plugin as closure
* @param tc task context
*/
-static void
+static void
http_server_daemon_v6_run (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct Plugin *plugin = cls;
-
-#if DEBUG_SCHEDULING
+
+#if DEBUG_SCHEDULING
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY))
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "http_server_daemon_v6_run:
GNUNET_SCHEDULER_REASON_READ_READY\n");
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY))
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "http_server_daemon_v6_run:
GNUNET_SCHEDULER_REASON_WRITE_READY\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "http_server_daemon_v6_run:
GNUNET_SCHEDULER_REASON_READ_READY\n");
+ if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY))
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "http_server_daemon_v6_run:
GNUNET_SCHEDULER_REASON_WRITE_READY\n");
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT))
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "http_server_daemon_v6_run:
GNUNET_SCHEDULER_REASON_TIMEOUT\n");
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_STARTUP))
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "http_server_daemon_v6_run:
GGNUNET_SCHEDULER_REASON_STARTUP\n");
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "http_server_daemon_v6_run:
GGNUNET_SCHEDULER_REASON_SHUTDOWN\n");
-#endif
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "http_server_daemon_v6_run:
GNUNET_SCHEDULER_REASON_TIMEOUT\n");
+ if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_STARTUP))
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "http_server_daemon_v6_run:
GGNUNET_SCHEDULER_REASON_STARTUP\n");
+ if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "http_server_daemon_v6_run:
GGNUNET_SCHEDULER_REASON_SHUTDOWN\n");
+#endif
- GNUNET_assert(cls !=NULL);
+ GNUNET_assert (cls != NULL);
plugin->http_server_task_v6 = GNUNET_SCHEDULER_NO_TASK;
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
return;
GNUNET_assert (MHD_YES == MHD_run (plugin->http_server_daemon_v6));
- plugin->http_server_task_v6 = http_server_daemon_prepare (plugin,
plugin->http_server_daemon_v6);
+ plugin->http_server_task_v6 =
+ http_server_daemon_prepare (plugin, plugin->http_server_daemon_v6);
}
-static size_t
-curl_get_header_cb( void *ptr,
- size_t size, size_t nmemb,
- void *stream)
+static size_t
+curl_get_header_cb (void *ptr, size_t size, size_t nmemb, void *stream)
{
- struct Session * ps = stream;
+ struct Session *ps = stream;
long http_result = 0;
int res;
+
/* Getting last http result code */
- GNUNET_assert(NULL!=ps);
- if (ps->recv_connected==GNUNET_NO)
+ GNUNET_assert (NULL != ps);
+ if (ps->recv_connected == GNUNET_NO)
+ {
+ res =
+ curl_easy_getinfo (ps->recv_endpoint, CURLINFO_RESPONSE_CODE,
+ &http_result);
+ if (CURLE_OK == res)
{
- res = curl_easy_getinfo(ps->recv_endpoint, CURLINFO_RESPONSE_CODE,
&http_result);
- if (CURLE_OK == res)
- {
- if (http_result == 200)
- {
- ps->recv_connected = GNUNET_YES;
- ps->recv_active = GNUNET_YES;
+ if (http_result == 200)
+ {
+ ps->recv_connected = GNUNET_YES;
+ ps->recv_active = GNUNET_YES;
#if DEBUG_CONNECTIONS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection %X: connected to
recieve data\n",ps);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Connection %X: connected to recieve data\n", ps);
#endif
- // Calling send_check_connections again since receive is
established
- send_check_connections (ps->peercontext->plugin, ps);
- }
- }
+ // Calling send_check_connections again since receive is established
+ send_check_connections (ps->peercontext->plugin, ps);
+ }
}
-
+ }
+
#if DEBUG_CURL
- char * tmp;
+ char *tmp;
size_t len = size * nmemb;
+
tmp = NULL;
if ((size * nmemb) < SIZE_MAX)
- tmp = GNUNET_malloc (len+1);
+ tmp = GNUNET_malloc (len + 1);
if ((tmp != NULL) && (len > 0))
+ {
+ memcpy (tmp, ptr, len);
+ if (len >= 2)
{
- memcpy(tmp,ptr,len);
- if (len>=2)
- {
- if (tmp[len-2] == 13)
- tmp[len-2]= '\0';
- }
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connection %X: Header: %s\n",
- ps, tmp);
+ if (tmp[len - 2] == 13)
+ tmp[len - 2] = '\0';
}
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Connection %X: Header: %s\n", ps, tmp);
+ }
GNUNET_free_non_null (tmp);
#endif
-
+
return size * nmemb;
}
@@ -1672,59 +1662,56 @@
* @param stream closure set by user
* @return bytes read by function
*/
-static size_t
-curl_put_header_cb(void *ptr,
- size_t size,
- size_t nmemb,
- void *stream)
+static size_t
+curl_put_header_cb (void *ptr, size_t size, size_t nmemb, void *stream)
{
- struct Session * ps = stream;
+ struct Session *ps = stream;
- char * tmp;
+ char *tmp;
size_t len = size * nmemb;
long http_result = 0;
int res;
/* Getting last http result code */
- GNUNET_assert(NULL!=ps);
- res = curl_easy_getinfo (ps->send_endpoint, CURLINFO_RESPONSE_CODE,
&http_result);
+ GNUNET_assert (NULL != ps);
+ res =
+ curl_easy_getinfo (ps->send_endpoint, CURLINFO_RESPONSE_CODE,
+ &http_result);
if (CURLE_OK == res)
+ {
+ if ((http_result == 100) && (ps->send_connected == GNUNET_NO))
{
- if ((http_result == 100) && (ps->send_connected==GNUNET_NO))
- {
- ps->send_connected = GNUNET_YES;
- ps->send_active = GNUNET_YES;
+ ps->send_connected = GNUNET_YES;
+ ps->send_active = GNUNET_YES;
#if DEBUG_CONNECTIONS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connection %X: connected to send data\n",
- ps);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Connection %X: connected to send data\n", ps);
#endif
- }
- if ((http_result == 200) && (ps->send_connected==GNUNET_YES))
- {
- ps->send_connected = GNUNET_NO;
- ps->send_active = GNUNET_NO;
+ }
+ if ((http_result == 200) && (ps->send_connected == GNUNET_YES))
+ {
+ ps->send_connected = GNUNET_NO;
+ ps->send_active = GNUNET_NO;
#if DEBUG_CONNECTIONS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connection %X: sending disconnected\n",
- ps);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Connection %X: sending disconnected\n", ps);
#endif
- }
}
-
+ }
+
tmp = NULL;
if ((size * nmemb) < SIZE_MAX)
- tmp = GNUNET_malloc (len+1);
-
+ tmp = GNUNET_malloc (len + 1);
+
if ((tmp != NULL) && (len > 0))
+ {
+ memcpy (tmp, ptr, len);
+ if (len >= 2)
{
- memcpy(tmp,ptr,len);
- if (len>=2)
- {
- if (tmp[len-2] == 13)
- tmp[len-2]= '\0';
- }
+ if (tmp[len - 2] == 13)
+ tmp[len - 2] = '\0';
}
+ }
GNUNET_free_non_null (tmp);
return size * nmemb;
}
@@ -1738,123 +1725,119 @@
* @param ptr source pointer, passed to the libcurl handle
* @return bytes written to stream
*/
-static size_t
-curl_send_cb(void *stream,
- size_t size, size_t nmemb,
- void *ptr)
+static size_t
+curl_send_cb (void *stream, size_t size, size_t nmemb, void *ptr)
{
- struct Session * ps = ptr;
- struct HTTP_Message * msg = ps->pending_msgs_tail;
+ struct Session *ps = ptr;
+ struct HTTP_Message *msg = ps->pending_msgs_tail;
size_t bytes_sent;
size_t len;
if (ps->send_active == GNUNET_NO)
return CURL_READFUNC_PAUSE;
- if ( (ps->pending_msgs_tail == NULL) &&
- (ps->send_active == GNUNET_YES) )
- {
+ if ((ps->pending_msgs_tail == NULL) && (ps->send_active == GNUNET_YES))
+ {
#if DEBUG_CONNECTIONS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connection %X: No Message to send, pausing connection\n",
- ps);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Connection %X: No Message to send, pausing connection\n", ps);
#endif
- ps->send_active = GNUNET_NO;
+ ps->send_active = GNUNET_NO;
return CURL_READFUNC_PAUSE;
- }
-
- GNUNET_assert (msg!=NULL);
-
+ }
+
+ GNUNET_assert (msg != NULL);
+
/* data to send */
if (msg->pos < msg->size)
+ {
+ /* data fit in buffer */
+ if ((msg->size - msg->pos) <= (size * nmemb))
{
- /* data fit in buffer */
- if ((msg->size - msg->pos) <= (size * nmemb))
- {
- len = (msg->size - msg->pos);
- memcpy(stream, &msg->buf[msg->pos], len);
- msg->pos += len;
- bytes_sent = len;
- }
- else
- {
- len = size*nmemb;
- memcpy(stream, &msg->buf[msg->pos], len);
- msg->pos += len;
- bytes_sent = len;
- }
+ len = (msg->size - msg->pos);
+ memcpy (stream, &msg->buf[msg->pos], len);
+ msg->pos += len;
+ bytes_sent = len;
}
+ else
+ {
+ len = size * nmemb;
+ memcpy (stream, &msg->buf[msg->pos], len);
+ msg->pos += len;
+ bytes_sent = len;
+ }
+ }
/* no data to send */
else
- {
- bytes_sent = 0;
- }
-
- if ( msg->pos == msg->size)
- {
+ {
+ bytes_sent = 0;
+ }
+
+ if (msg->pos == msg->size)
+ {
#if DEBUG_CONNECTIONS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connection %X: Message with %u bytes sent, removing message
from queue\n",
- ps,
- msg->pos);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Connection %X: Message with %u bytes sent, removing message
from queue\n",
+ ps, msg->pos);
#endif
- /* Calling transmit continuation */
- if (NULL != ps->pending_msgs_tail->transmit_cont)
- msg->transmit_cont (ps->pending_msgs_tail->transmit_cont_cls,
- &(ps->peercontext)->identity,
- GNUNET_OK);
- ps->queue_length_cur -= msg->size;
- remove_http_message(ps, msg);
- }
+ /* Calling transmit continuation */
+ if (NULL != ps->pending_msgs_tail->transmit_cont)
+ msg->transmit_cont (ps->pending_msgs_tail->transmit_cont_cls,
+ &(ps->peercontext)->identity, GNUNET_OK);
+ ps->queue_length_cur -= msg->size;
+ remove_http_message (ps, msg);
+ }
return bytes_sent;
}
-static void
-curl_receive_mst_cb (void *cls,
- void *client,
- const struct GNUNET_MessageHeader *message)
+static void
+curl_receive_mst_cb (void *cls,
+ void *client, const struct GNUNET_MessageHeader *message)
{
- struct Session *ps = cls;
+ struct Session *ps = cls;
struct GNUNET_TIME_Relative delay;
- GNUNET_assert(ps != NULL);
+ GNUNET_assert (ps != NULL);
+
struct HTTP_PeerContext *pc = ps->peercontext;
- GNUNET_assert(pc != NULL);
+
+ GNUNET_assert (pc != NULL);
#if DEBUG_HTTP
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Connection %X: Forwarding message to transport service, type %u
and size %u from `%s' (`%s')\n",
ps,
- ntohs(message->type),
- ntohs(message->size),
- GNUNET_i2s(&(pc->identity)),
- http_plugin_address_to_string(NULL,ps->addr,ps->addrlen));
+ ntohs (message->type),
+ ntohs (message->size),
+ GNUNET_i2s (&(pc->identity)),
+ http_plugin_address_to_string (NULL, ps->addr, ps->addrlen));
#endif
struct GNUNET_TRANSPORT_ATS_Information distance[2];
+
distance[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE);
distance[0].value = htonl (1);
distance[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
distance[1].value = htonl (0);
delay = pc->plugin->env->receive (pc->plugin->env->cls,
- &pc->identity,
- message,
- (const struct
GNUNET_TRANSPORT_ATS_Information *) &distance, 2,
- ps,
- ps->addr,
- ps->addrlen);
+ &pc->identity,
+ message,
+ (const struct
+ GNUNET_TRANSPORT_ATS_Information *)
+ &distance, 2, ps, ps->addr, ps->addrlen);
pc->delay = delay;
if (pc->reset_task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel (pc->reset_task);
+ GNUNET_SCHEDULER_cancel (pc->reset_task);
if (delay.rel_value > 0)
- {
+ {
#if DEBUG_HTTP
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connection %X: Inbound quota management: delay next read for
%llu ms\n",
- ps, delay.rel_value);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Connection %X: Inbound quota management: delay next read for
%llu ms\n",
+ ps, delay.rel_value);
#endif
- pc->reset_task = GNUNET_SCHEDULER_add_delayed (delay,
&reset_inbound_quota_delay, pc);
- }
+ pc->reset_task =
+ GNUNET_SCHEDULER_add_delayed (delay, &reset_inbound_quota_delay, pc);
+ }
}
@@ -1867,163 +1850,171 @@
* @param ptr destination pointer, passed to the libcurl handle
* @return bytes read from stream
*/
-static size_t
-curl_receive_cb( void *stream, size_t size, size_t nmemb, void *ptr)
+static size_t
+curl_receive_cb (void *stream, size_t size, size_t nmemb, void *ptr)
{
- struct Session * ps = ptr;
+ struct Session *ps = ptr;
if (ps->peercontext->delay.rel_value > 0)
- {
+ {
#if DEBUG_HTTP
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connection %X: no inbound bandwidth available! Next read was
delayed for %llu ms\n",
- ps, ps->peercontext->delay.rel_value);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Connection %X: no inbound bandwidth available! Next read was
delayed for %llu ms\n",
+ ps, ps->peercontext->delay.rel_value);
#endif
- return 0;
- }
+ return 0;
+ }
#if DEBUG_CONNECTIONS
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connection %X: %u bytes received\n",
- ps, size*nmemb);
+ "Connection %X: %u bytes received\n", ps, size * nmemb);
#endif
- GNUNET_SERVER_mst_receive(ps->msgtok, ps,
- stream, size*nmemb,
- GNUNET_NO, GNUNET_NO);
+ GNUNET_SERVER_mst_receive (ps->msgtok, ps,
+ stream, size * nmemb, GNUNET_NO, GNUNET_NO);
return (size * nmemb);
}
-static void
+static void
curl_handle_finished (struct Plugin *plugin)
{
struct Session *ps = NULL;
struct HTTP_PeerContext *pc = NULL;
struct CURLMsg *msg;
- struct HTTP_Message * cur_msg = NULL;
+ struct HTTP_Message *cur_msg = NULL;
int msgs_in_queue;
- char * tmp;
+ char *tmp;
long http_result;
-
+
do
+ {
+ msg = curl_multi_info_read (plugin->multi_handle, &msgs_in_queue);
+ if ((msgs_in_queue == 0) || (msg == NULL))
+ break;
+ /* get session for affected curl handle */
+ GNUNET_assert (msg->easy_handle != NULL);
+ curl_easy_getinfo (msg->easy_handle, CURLINFO_PRIVATE, &tmp);
+ ps = (struct Session *) tmp;
+ GNUNET_assert (ps != NULL);
+ pc = ps->peercontext;
+ GNUNET_assert (pc != NULL);
+ switch (msg->msg)
{
- msg = curl_multi_info_read (plugin->multi_handle, &msgs_in_queue);
- if ((msgs_in_queue == 0) || (msg == NULL))
- break;
- /* get session for affected curl handle */
- GNUNET_assert ( msg->easy_handle != NULL );
- curl_easy_getinfo(msg->easy_handle, CURLINFO_PRIVATE, &tmp);
- ps = (struct Session *) tmp;
- GNUNET_assert ( ps != NULL );
- pc = ps->peercontext;
- GNUNET_assert ( pc != NULL );
- switch (msg->msg)
- {
- case CURLMSG_DONE:
- if ( (msg->data.result != CURLE_OK) &&
- (msg->data.result != CURLE_GOT_NOTHING) )
- {
- /* sending msg failed*/
- if (msg->easy_handle == ps->send_endpoint)
- {
+ case CURLMSG_DONE:
+ if ((msg->data.result != CURLE_OK) &&
+ (msg->data.result != CURLE_GOT_NOTHING))
+ {
+ /* sending msg failed */
+ if (msg->easy_handle == ps->send_endpoint)
+ {
#if DEBUG_CONNECTIONS
- GNUNET_log(GNUNET_ERROR_TYPE_INFO,
- _("Connection %X: HTTP PUT to peer `%s' (`%s')
failed: `%s' `%s'\n"),
- ps,
- GNUNET_i2s(&pc->identity),
- http_plugin_address_to_string(NULL, ps->addr,
ps->addrlen),
- "curl_multi_perform",
- curl_easy_strerror (msg->data.result));
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _
+ ("Connection %X: HTTP PUT to peer `%s' (`%s') failed:
`%s' `%s'\n"),
+ ps, GNUNET_i2s (&pc->identity),
+ http_plugin_address_to_string (NULL, ps->addr,
+ ps->addrlen),
+ "curl_multi_perform",
+ curl_easy_strerror (msg->data.result));
#endif
- ps->send_connected = GNUNET_NO;
- ps->send_active = GNUNET_NO;
-
curl_multi_remove_handle(plugin->multi_handle,ps->send_endpoint);
- while (ps->pending_msgs_tail != NULL)
- {
- cur_msg = ps->pending_msgs_tail;
- if ( NULL != cur_msg->transmit_cont)
- cur_msg->transmit_cont
(cur_msg->transmit_cont_cls,&pc->identity,GNUNET_SYSERR);
- ps->queue_length_cur -= cur_msg->size;
- remove_http_message(ps,cur_msg);
- }
- }
- /* GET connection failed */
- if (msg->easy_handle == ps->recv_endpoint)
- {
+ ps->send_connected = GNUNET_NO;
+ ps->send_active = GNUNET_NO;
+ curl_multi_remove_handle (plugin->multi_handle, ps->send_endpoint);
+ while (ps->pending_msgs_tail != NULL)
+ {
+ cur_msg = ps->pending_msgs_tail;
+ if (NULL != cur_msg->transmit_cont)
+ cur_msg->transmit_cont (cur_msg->transmit_cont_cls,
&pc->identity,
+ GNUNET_SYSERR);
+ ps->queue_length_cur -= cur_msg->size;
+ remove_http_message (ps, cur_msg);
+ }
+ }
+ /* GET connection failed */
+ if (msg->easy_handle == ps->recv_endpoint)
+ {
#if DEBUG_CONNECTIONS
- GNUNET_log(GNUNET_ERROR_TYPE_INFO,
- _("Connection %X: HTTP GET to peer `%s' (`%s')
failed: `%s' `%s'\n"),
- ps,
- GNUNET_i2s(&pc->identity),
- http_plugin_address_to_string(NULL, ps->addr,
ps->addrlen),
- "curl_multi_perform",
- curl_easy_strerror (msg->data.result));
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _
+ ("Connection %X: HTTP GET to peer `%s' (`%s') failed:
`%s' `%s'\n"),
+ ps, GNUNET_i2s (&pc->identity),
+ http_plugin_address_to_string (NULL, ps->addr,
+ ps->addrlen),
+ "curl_multi_perform",
+ curl_easy_strerror (msg->data.result));
#endif
- ps->recv_connected = GNUNET_NO;
- ps->recv_active = GNUNET_NO;
-
curl_multi_remove_handle(plugin->multi_handle,ps->recv_endpoint);
- }
- }
- else
- {
- if (msg->easy_handle == ps->send_endpoint)
- {
- GNUNET_assert (CURLE_OK ==
curl_easy_getinfo(msg->easy_handle, CURLINFO_RESPONSE_CODE, &http_result));
+ ps->recv_connected = GNUNET_NO;
+ ps->recv_active = GNUNET_NO;
+ curl_multi_remove_handle (plugin->multi_handle, ps->recv_endpoint);
+ }
+ }
+ else
+ {
+ if (msg->easy_handle == ps->send_endpoint)
+ {
+ GNUNET_assert (CURLE_OK ==
+ curl_easy_getinfo (msg->easy_handle,
+ CURLINFO_RESPONSE_CODE,
+ &http_result));
#if DEBUG_CONNECTIONS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connection %X: HTTP PUT connection to peer `%s'
(`%s') was closed with HTTP code %u\n",
- ps,
- GNUNET_i2s(&pc->identity),
- http_plugin_address_to_string(NULL, ps->addr,
ps->addrlen),
- http_result);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Connection %X: HTTP PUT connection to peer `%s' (`%s')
was closed with HTTP code %u\n",
+ ps,
+ GNUNET_i2s (&pc->identity),
+ http_plugin_address_to_string (NULL, ps->addr,
+ ps->addrlen),
http_result);
#endif
- /* Calling transmit continuation */
- while (ps->pending_msgs_tail != NULL)
- {
- cur_msg = ps->pending_msgs_tail;
- if ( NULL != cur_msg->transmit_cont)
- {
- /* HTTP 1xx : Last message before here was
informational */
- if ((http_result >=100) && (http_result < 200))
- cur_msg->transmit_cont
(cur_msg->transmit_cont_cls,&pc->identity,GNUNET_OK);
- /* HTTP 2xx: successful operations */
- if ((http_result >=200) && (http_result < 300))
- cur_msg->transmit_cont
(cur_msg->transmit_cont_cls,&pc->identity,GNUNET_OK);
- /* HTTP 3xx..5xx: error */
- if ((http_result >=300) && (http_result < 600))
- cur_msg->transmit_cont
(cur_msg->transmit_cont_cls,&pc->identity,GNUNET_SYSERR);
- }
- ps->queue_length_cur -= cur_msg->size;
- remove_http_message(ps,cur_msg);
- }
-
- ps->send_connected = GNUNET_NO;
- ps->send_active = GNUNET_NO;
-
curl_multi_remove_handle(plugin->multi_handle,ps->send_endpoint);
- }
- if (msg->easy_handle == ps->recv_endpoint)
- {
+ /* Calling transmit continuation */
+ while (ps->pending_msgs_tail != NULL)
+ {
+ cur_msg = ps->pending_msgs_tail;
+ if (NULL != cur_msg->transmit_cont)
+ {
+ /* HTTP 1xx : Last message before here was informational */
+ if ((http_result >= 100) && (http_result < 200))
+ cur_msg->transmit_cont (cur_msg->transmit_cont_cls,
+ &pc->identity, GNUNET_OK);
+ /* HTTP 2xx: successful operations */
+ if ((http_result >= 200) && (http_result < 300))
+ cur_msg->transmit_cont (cur_msg->transmit_cont_cls,
+ &pc->identity, GNUNET_OK);
+ /* HTTP 3xx..5xx: error */
+ if ((http_result >= 300) && (http_result < 600))
+ cur_msg->transmit_cont (cur_msg->transmit_cont_cls,
+ &pc->identity, GNUNET_SYSERR);
+ }
+ ps->queue_length_cur -= cur_msg->size;
+ remove_http_message (ps, cur_msg);
+ }
+
+ ps->send_connected = GNUNET_NO;
+ ps->send_active = GNUNET_NO;
+ curl_multi_remove_handle (plugin->multi_handle, ps->send_endpoint);
+ }
+ if (msg->easy_handle == ps->recv_endpoint)
+ {
#if DEBUG_CONNECTIONS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connection %X: HTTP GET connection to peer `%s'
(`%s') was closed with HTTP code %u\n",
- ps,
- GNUNET_i2s(&pc->identity),
- http_plugin_address_to_string(NULL, ps->addr,
ps->addrlen),
- http_result);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Connection %X: HTTP GET connection to peer `%s' (`%s')
was closed with HTTP code %u\n",
+ ps,
+ GNUNET_i2s (&pc->identity),
+ http_plugin_address_to_string (NULL, ps->addr,
+ ps->addrlen),
http_result);
#endif
- ps->recv_connected = GNUNET_NO;
- ps->recv_active = GNUNET_NO;
-
curl_multi_remove_handle(plugin->multi_handle,ps->recv_endpoint);
- }
- plugin->current_connections--;
- }
- if ((ps->recv_connected == GNUNET_NO) && (ps->send_connected ==
GNUNET_NO))
- remove_session (pc, ps, GNUNET_YES, GNUNET_SYSERR);
- break;
- default:
- break;
- }
+ ps->recv_connected = GNUNET_NO;
+ ps->recv_active = GNUNET_NO;
+ curl_multi_remove_handle (plugin->multi_handle, ps->recv_endpoint);
+ }
+ plugin->current_connections--;
+ }
+ if ((ps->recv_connected == GNUNET_NO) &&
+ (ps->send_connected == GNUNET_NO))
+ remove_session (pc, ps, GNUNET_YES, GNUNET_SYSERR);
+ break;
+ default:
+ break;
}
- while ( (msgs_in_queue > 0) );
+ }
+ while ((msgs_in_queue > 0));
}
@@ -2032,29 +2023,29 @@
* @param cls plugin as closure
* @param tc gnunet scheduler task context
*/
-static void curl_perform (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+static void
+curl_perform (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct Plugin *plugin = cls;
static unsigned int handles_last_run;
int running;
CURLMcode mret;
- GNUNET_assert(cls !=NULL);
+ GNUNET_assert (cls != NULL);
plugin->http_curl_task = GNUNET_SCHEDULER_NO_TASK;
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
return;
do
- {
- running = 0;
- mret = curl_multi_perform (plugin->multi_handle, &running);
- if ((running < handles_last_run) && (running>0))
- curl_handle_finished(plugin);
- handles_last_run = running;
- }
+ {
+ running = 0;
+ mret = curl_multi_perform (plugin->multi_handle, &running);
+ if ((running < handles_last_run) && (running > 0))
+ curl_handle_finished (plugin);
+ handles_last_run = running;
+ }
while (mret == CURLM_CALL_MULTI_PERFORM);
- curl_schedule(plugin);
+ curl_schedule (plugin);
}
@@ -2064,8 +2055,8 @@
* @param plugin plugin as closure
* @return GNUNET_SYSERR for hard failure, GNUNET_OK for ok
*/
-static int
-curl_schedule(struct Plugin *plugin)
+static int
+curl_schedule (struct Plugin *plugin)
{
fd_set rs;
fd_set ws;
@@ -2077,48 +2068,50 @@
CURLMcode mret;
/* Cancel previous scheduled task */
- if (plugin->http_curl_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel(plugin->http_curl_task);
- plugin->http_curl_task = GNUNET_SCHEDULER_NO_TASK;
- }
-
+ if (plugin->http_curl_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (plugin->http_curl_task);
+ plugin->http_curl_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+
max = -1;
FD_ZERO (&rs);
FD_ZERO (&ws);
FD_ZERO (&es);
mret = curl_multi_fdset (plugin->multi_handle, &rs, &ws, &es, &max);
if (mret != CURLM_OK)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("%s failed at %s:%d: `%s'\n"),
- "curl_multi_fdset", __FILE__, __LINE__,
- curl_multi_strerror (mret));
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("%s failed at %s:%d: `%s'\n"),
+ "curl_multi_fdset", __FILE__, __LINE__,
+ curl_multi_strerror (mret));
+ return GNUNET_SYSERR;
+ }
mret = curl_multi_timeout (plugin->multi_handle, &to);
if (mret != CURLM_OK)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("%s failed at %s:%d: `%s'\n"),
- "curl_multi_timeout", __FILE__, __LINE__,
- curl_multi_strerror (mret));
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("%s failed at %s:%d: `%s'\n"),
+ "curl_multi_timeout", __FILE__, __LINE__,
+ curl_multi_strerror (mret));
+ return GNUNET_SYSERR;
+ }
grs = GNUNET_NETWORK_fdset_create ();
gws = GNUNET_NETWORK_fdset_create ();
GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1);
GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1);
- plugin->http_curl_task = GNUNET_SCHEDULER_add_select
(GNUNET_SCHEDULER_PRIORITY_DEFAULT,
-
GNUNET_SCHEDULER_NO_TASK,
- (to == -1)
- ?
GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
- :
GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, to),
- grs,
- gws,
- &curl_perform,
- plugin);
+ plugin->http_curl_task =
+ GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
+ GNUNET_SCHEDULER_NO_TASK,
+ (to ==
+ -1) ?
+ GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS,
+ 5) :
+ GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MILLISECONDS, to), grs,
+ gws, &curl_perform, plugin);
GNUNET_NETWORK_fdset_destroy (gws);
GNUNET_NETWORK_fdset_destroy (grs);
return GNUNET_OK;
@@ -2135,28 +2128,24 @@
* @param cls closure
* @return 0
*/
-static int
+static int
curl_logger (CURL * curl,
- curl_infotype type,
- char * data, size_t size,
- void * cls)
+ curl_infotype type, char *data, size_t size, void *cls)
{
if (type == CURLINFO_TEXT)
+ {
+ char text[size + 2];
+
+ memcpy (text, data, size);
+ if (text[size - 1] == '\n')
+ text[size] = '\0';
+ else
{
- char text[size+2];
- memcpy(text,data,size);
- if (text[size-1] == '\n')
- text[size] = '\0';
- else
- {
- text[size] = '\n';
- text[size+1] = '\0';
- }
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "CURL: Connection %X - %s",
- cls,
- text);
+ text[size] = '\n';
+ text[size + 1] = '\0';
}
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CURL: Connection %X - %s", cls,
text);
+ }
return 0;
}
#endif
@@ -2169,184 +2158,203 @@
* @param ps session
* @return GNUNET_SYSERR on failure, GNUNET_NO if connecting, GNUNET_YES if ok
*/
-static int
-send_check_connections (struct Plugin *plugin,
- struct Session *ps)
+static int
+send_check_connections (struct Plugin *plugin, struct Session *ps)
{
CURLMcode mret;
- struct GNUNET_TIME_Relative timeout =
GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT;
+ struct GNUNET_TIME_Relative timeout =
+ GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT;
- if ((ps->direction == OUTBOUND) && (plugin->current_connections <
plugin->max_connect_per_transport))
+ if ((ps->direction == OUTBOUND) &&
+ (plugin->current_connections < plugin->max_connect_per_transport))
+ {
+ /* RECV DIRECTION */
+ /* Check if session is connected to receive data, otherwise connect to
peer */
+
+ if (ps->recv_connected == GNUNET_NO)
{
- /* RECV DIRECTION */
- /* Check if session is connected to receive data, otherwise connect to
peer */
+ int fresh = GNUNET_NO;
- if (ps->recv_connected == GNUNET_NO)
- {
- int fresh = GNUNET_NO;
- if (ps->recv_endpoint == NULL)
- {
- fresh = GNUNET_YES;
- ps->recv_endpoint = curl_easy_init();
- }
+ if (ps->recv_endpoint == NULL)
+ {
+ fresh = GNUNET_YES;
+ ps->recv_endpoint = curl_easy_init ();
+ }
#if DEBUG_CURL
- curl_easy_setopt(ps->recv_endpoint, CURLOPT_VERBOSE, 1L);
- curl_easy_setopt(ps->recv_endpoint, CURLOPT_DEBUGFUNCTION ,
&curl_logger);
- curl_easy_setopt(ps->recv_endpoint, CURLOPT_DEBUGDATA ,
ps->recv_endpoint);
+ curl_easy_setopt (ps->recv_endpoint, CURLOPT_VERBOSE, 1L);
+ curl_easy_setopt (ps->recv_endpoint, CURLOPT_DEBUGFUNCTION,
&curl_logger);
+ curl_easy_setopt (ps->recv_endpoint, CURLOPT_DEBUGDATA,
+ ps->recv_endpoint);
#endif
#if BUILD_HTTPS
- curl_easy_setopt(ps->recv_endpoint, CURLOPT_SSLVERSION,
CURL_SSLVERSION_TLSv1);
- curl_easy_setopt(ps->recv_endpoint, CURLOPT_SSL_VERIFYPEER, 0);
- curl_easy_setopt(ps->recv_endpoint, CURLOPT_SSL_VERIFYHOST, 0);
+ curl_easy_setopt (ps->recv_endpoint, CURLOPT_SSLVERSION,
+ CURL_SSLVERSION_TLSv1);
+ curl_easy_setopt (ps->recv_endpoint, CURLOPT_SSL_VERIFYPEER, 0);
+ curl_easy_setopt (ps->recv_endpoint, CURLOPT_SSL_VERIFYHOST, 0);
#endif
- curl_easy_setopt(ps->recv_endpoint, CURLOPT_URL, ps->url);
- curl_easy_setopt(ps->recv_endpoint, CURLOPT_HEADERFUNCTION,
&curl_get_header_cb);
- curl_easy_setopt(ps->recv_endpoint, CURLOPT_WRITEHEADER, ps);
- curl_easy_setopt(ps->recv_endpoint, CURLOPT_READFUNCTION,
curl_send_cb);
- curl_easy_setopt(ps->recv_endpoint, CURLOPT_READDATA, ps);
- curl_easy_setopt(ps->recv_endpoint, CURLOPT_WRITEFUNCTION,
curl_receive_cb);
- curl_easy_setopt(ps->recv_endpoint, CURLOPT_WRITEDATA, ps);
- curl_easy_setopt(ps->recv_endpoint, CURLOPT_TIMEOUT, (long)
timeout.rel_value);
- curl_easy_setopt(ps->recv_endpoint, CURLOPT_PRIVATE, ps);
- curl_easy_setopt(ps->recv_endpoint, CURLOPT_CONNECTTIMEOUT,
HTTP_CONNECT_TIMEOUT);
- curl_easy_setopt(ps->recv_endpoint, CURLOPT_BUFFERSIZE,
2*GNUNET_SERVER_MAX_MESSAGE_SIZE);
+ curl_easy_setopt (ps->recv_endpoint, CURLOPT_URL, ps->url);
+ curl_easy_setopt (ps->recv_endpoint, CURLOPT_HEADERFUNCTION,
+ &curl_get_header_cb);
+ curl_easy_setopt (ps->recv_endpoint, CURLOPT_WRITEHEADER, ps);
+ curl_easy_setopt (ps->recv_endpoint, CURLOPT_READFUNCTION, curl_send_cb);
+ curl_easy_setopt (ps->recv_endpoint, CURLOPT_READDATA, ps);
+ curl_easy_setopt (ps->recv_endpoint, CURLOPT_WRITEFUNCTION,
+ curl_receive_cb);
+ curl_easy_setopt (ps->recv_endpoint, CURLOPT_WRITEDATA, ps);
+ curl_easy_setopt (ps->recv_endpoint, CURLOPT_TIMEOUT,
+ (long) timeout.rel_value);
+ curl_easy_setopt (ps->recv_endpoint, CURLOPT_PRIVATE, ps);
+ curl_easy_setopt (ps->recv_endpoint, CURLOPT_CONNECTTIMEOUT,
+ HTTP_CONNECT_TIMEOUT);
+ curl_easy_setopt (ps->recv_endpoint, CURLOPT_BUFFERSIZE,
+ 2 * GNUNET_SERVER_MAX_MESSAGE_SIZE);
#if CURL_TCP_NODELAY
- curl_easy_setopt(ps->recv_endpoint, CURLOPT_TCP_NODELAY, 1);
+ curl_easy_setopt (ps->recv_endpoint, CURLOPT_TCP_NODELAY, 1);
#endif
- if (fresh==GNUNET_YES)
- {
- mret = curl_multi_add_handle(plugin->multi_handle,
ps->recv_endpoint);
- if (mret != CURLM_OK)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Connection: %X: %s failed at %s:%d: `%s'\n"),
- ps,
- "curl_multi_add_handle", __FILE__, __LINE__,
- curl_multi_strerror (mret));
- return GNUNET_SYSERR;
- }
- }
- if (plugin->http_curl_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel(plugin->http_curl_task);
- plugin->http_curl_task = GNUNET_SCHEDULER_NO_TASK;
- }
- plugin->current_connections ++;
- plugin->http_curl_task = GNUNET_SCHEDULER_add_now (&curl_perform,
plugin);
- }
-
- /* waiting for receive direction */
- if (ps->recv_connected==GNUNET_NO)
- return GNUNET_NO;
-
- /* SEND DIRECTION */
- /* Check if session is connected to send data, otherwise connect to peer
*/
- if ((ps->send_connected == GNUNET_YES) && (ps->send_endpoint!= NULL))
- {
- if (ps->send_active == GNUNET_YES)
- {
+ if (fresh == GNUNET_YES)
+ {
+ mret = curl_multi_add_handle (plugin->multi_handle, ps->recv_endpoint);
+ if (mret != CURLM_OK)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Connection: %X: %s failed at %s:%d: `%s'\n"),
+ ps,
+ "curl_multi_add_handle", __FILE__, __LINE__,
+ curl_multi_strerror (mret));
+ return GNUNET_SYSERR;
+ }
+ }
+ if (plugin->http_curl_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (plugin->http_curl_task);
+ plugin->http_curl_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ plugin->current_connections++;
+ plugin->http_curl_task = GNUNET_SCHEDULER_add_now (&curl_perform,
plugin);
+ }
+
+ /* waiting for receive direction */
+ if (ps->recv_connected == GNUNET_NO)
+ return GNUNET_NO;
+
+ /* SEND DIRECTION */
+ /* Check if session is connected to send data, otherwise connect to peer */
+ if ((ps->send_connected == GNUNET_YES) && (ps->send_endpoint != NULL))
+ {
+ if (ps->send_active == GNUNET_YES)
+ {
#if DEBUG_CONNECTIONS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connection %X: outbound active, enqueueing
message\n",
- ps);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Connection %X: outbound active, enqueueing message\n",
ps);
#endif
- return GNUNET_YES;
- }
- if (ps->send_active == GNUNET_NO)
- {
+ return GNUNET_YES;
+ }
+ if (ps->send_active == GNUNET_NO)
+ {
#if DEBUG_CONNECTIONS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connection %X: outbound paused, unpausing existing
connection and enqueueing message\n",
- ps);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Connection %X: outbound paused, unpausing existing
connection and enqueueing message\n",
+ ps);
#endif
- if (CURLE_OK == curl_easy_pause(ps->send_endpoint,CURLPAUSE_CONT))
- {
- ps->send_active=GNUNET_YES;
- if (plugin->http_curl_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel(plugin->http_curl_task);
- plugin->http_curl_task = GNUNET_SCHEDULER_NO_TASK;
- }
- plugin->http_curl_task = GNUNET_SCHEDULER_add_now
(&curl_perform, plugin);
- return GNUNET_YES;
- }
- else
- return GNUNET_SYSERR;
- }
- }
- /* not connected, initiate connection */
- if ((ps->send_connected==GNUNET_NO) && (plugin->current_connections <
plugin->max_connect_per_transport))
- {
- int fresh = GNUNET_NO;
- if (NULL == ps->send_endpoint)
- {
- ps->send_endpoint = curl_easy_init();
- fresh = GNUNET_YES;
- }
- GNUNET_assert (ps->send_endpoint != NULL);
- GNUNET_assert (NULL != ps->pending_msgs_tail);
+ if (CURLE_OK == curl_easy_pause (ps->send_endpoint, CURLPAUSE_CONT))
+ {
+ ps->send_active = GNUNET_YES;
+ if (plugin->http_curl_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (plugin->http_curl_task);
+ plugin->http_curl_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ plugin->http_curl_task =
+ GNUNET_SCHEDULER_add_now (&curl_perform, plugin);
+ return GNUNET_YES;
+ }
+ else
+ return GNUNET_SYSERR;
+ }
+ }
+ /* not connected, initiate connection */
+ if ((ps->send_connected == GNUNET_NO) &&
+ (plugin->current_connections < plugin->max_connect_per_transport))
+ {
+ int fresh = GNUNET_NO;
+
+ if (NULL == ps->send_endpoint)
+ {
+ ps->send_endpoint = curl_easy_init ();
+ fresh = GNUNET_YES;
+ }
+ GNUNET_assert (ps->send_endpoint != NULL);
+ GNUNET_assert (NULL != ps->pending_msgs_tail);
#if DEBUG_CONNECTIONS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connection %X: outbound not connected, initiating
connection\n",
- ps);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Connection %X: outbound not connected, initiating
connection\n",
+ ps);
#endif
- ps->send_active = GNUNET_NO;
-
+ ps->send_active = GNUNET_NO;
+
#if DEBUG_CURL
- curl_easy_setopt(ps->send_endpoint, CURLOPT_VERBOSE, 1L);
- curl_easy_setopt(ps->send_endpoint, CURLOPT_DEBUGFUNCTION ,
&curl_logger);
- curl_easy_setopt(ps->send_endpoint, CURLOPT_DEBUGDATA ,
ps->send_endpoint);
+ curl_easy_setopt (ps->send_endpoint, CURLOPT_VERBOSE, 1L);
+ curl_easy_setopt (ps->send_endpoint, CURLOPT_DEBUGFUNCTION,
&curl_logger);
+ curl_easy_setopt (ps->send_endpoint, CURLOPT_DEBUGDATA,
+ ps->send_endpoint);
#endif
#if BUILD_HTTPS
- curl_easy_setopt (ps->send_endpoint, CURLOPT_SSLVERSION,
CURL_SSLVERSION_TLSv1);
- curl_easy_setopt(ps->send_endpoint, CURLOPT_SSL_VERIFYPEER, 0);
- curl_easy_setopt(ps->send_endpoint, CURLOPT_SSL_VERIFYHOST, 0);
+ curl_easy_setopt (ps->send_endpoint, CURLOPT_SSLVERSION,
+ CURL_SSLVERSION_TLSv1);
+ curl_easy_setopt (ps->send_endpoint, CURLOPT_SSL_VERIFYPEER, 0);
+ curl_easy_setopt (ps->send_endpoint, CURLOPT_SSL_VERIFYHOST, 0);
#endif
- curl_easy_setopt(ps->send_endpoint, CURLOPT_URL, ps->url);
- curl_easy_setopt(ps->send_endpoint, CURLOPT_PUT, 1L);
- curl_easy_setopt(ps->send_endpoint, CURLOPT_HEADERFUNCTION,
&curl_put_header_cb);
- curl_easy_setopt(ps->send_endpoint, CURLOPT_WRITEHEADER, ps);
- curl_easy_setopt(ps->send_endpoint, CURLOPT_READFUNCTION,
curl_send_cb);
- curl_easy_setopt(ps->send_endpoint, CURLOPT_READDATA, ps);
- curl_easy_setopt(ps->send_endpoint, CURLOPT_WRITEFUNCTION,
curl_receive_cb);
- curl_easy_setopt(ps->send_endpoint, CURLOPT_READDATA, ps);
- curl_easy_setopt(ps->send_endpoint, CURLOPT_TIMEOUT, (long)
timeout.rel_value);
- curl_easy_setopt(ps->send_endpoint, CURLOPT_PRIVATE, ps);
- curl_easy_setopt(ps->send_endpoint, CURLOPT_CONNECTTIMEOUT,
HTTP_CONNECT_TIMEOUT);
- curl_easy_setopt(ps->send_endpoint, CURLOPT_BUFFERSIZE, 2 *
GNUNET_SERVER_MAX_MESSAGE_SIZE);
+ curl_easy_setopt (ps->send_endpoint, CURLOPT_URL, ps->url);
+ curl_easy_setopt (ps->send_endpoint, CURLOPT_PUT, 1L);
+ curl_easy_setopt (ps->send_endpoint, CURLOPT_HEADERFUNCTION,
+ &curl_put_header_cb);
+ curl_easy_setopt (ps->send_endpoint, CURLOPT_WRITEHEADER, ps);
+ curl_easy_setopt (ps->send_endpoint, CURLOPT_READFUNCTION, curl_send_cb);
+ curl_easy_setopt (ps->send_endpoint, CURLOPT_READDATA, ps);
+ curl_easy_setopt (ps->send_endpoint, CURLOPT_WRITEFUNCTION,
+ curl_receive_cb);
+ curl_easy_setopt (ps->send_endpoint, CURLOPT_READDATA, ps);
+ curl_easy_setopt (ps->send_endpoint, CURLOPT_TIMEOUT,
+ (long) timeout.rel_value);
+ curl_easy_setopt (ps->send_endpoint, CURLOPT_PRIVATE, ps);
+ curl_easy_setopt (ps->send_endpoint, CURLOPT_CONNECTTIMEOUT,
+ HTTP_CONNECT_TIMEOUT);
+ curl_easy_setopt (ps->send_endpoint, CURLOPT_BUFFERSIZE,
+ 2 * GNUNET_SERVER_MAX_MESSAGE_SIZE);
#if CURL_TCP_NODELAY
- curl_easy_setopt(ps->send_endpoint, CURLOPT_TCP_NODELAY, 1);
+ curl_easy_setopt (ps->send_endpoint, CURLOPT_TCP_NODELAY, 1);
#endif
- if (fresh==GNUNET_YES)
- {
- mret = curl_multi_add_handle(plugin->multi_handle,
ps->send_endpoint);
- if (mret != CURLM_OK)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Connection: %X: %s failed at %s:%d: `%s'\n"),
- ps,
- "curl_multi_add_handle", __FILE__, __LINE__,
- curl_multi_strerror (mret));
- return GNUNET_SYSERR;
- }
- }
- }
- if (plugin->http_curl_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel(plugin->http_curl_task);
- plugin->http_curl_task = GNUNET_SCHEDULER_NO_TASK;
- }
- plugin->current_connections++;
- plugin->http_curl_task = GNUNET_SCHEDULER_add_now (&curl_perform,
plugin);
- return GNUNET_YES;
+ if (fresh == GNUNET_YES)
+ {
+ mret = curl_multi_add_handle (plugin->multi_handle, ps->send_endpoint);
+ if (mret != CURLM_OK)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Connection: %X: %s failed at %s:%d: `%s'\n"),
+ ps,
+ "curl_multi_add_handle", __FILE__, __LINE__,
+ curl_multi_strerror (mret));
+ return GNUNET_SYSERR;
+ }
+ }
}
- if (ps->direction == INBOUND)
+ if (plugin->http_curl_task != GNUNET_SCHEDULER_NO_TASK)
{
- GNUNET_assert (NULL != ps->pending_msgs_tail);
- if ((ps->recv_connected==GNUNET_YES) && (ps->send_connected==GNUNET_YES)
&&
- (ps->recv_force_disconnect==GNUNET_NO) &&
(ps->recv_force_disconnect==GNUNET_NO))
- return GNUNET_YES;
+ GNUNET_SCHEDULER_cancel (plugin->http_curl_task);
+ plugin->http_curl_task = GNUNET_SCHEDULER_NO_TASK;
}
+ plugin->current_connections++;
+ plugin->http_curl_task = GNUNET_SCHEDULER_add_now (&curl_perform, plugin);
+ return GNUNET_YES;
+ }
+ if (ps->direction == INBOUND)
+ {
+ GNUNET_assert (NULL != ps->pending_msgs_tail);
+ if ((ps->recv_connected == GNUNET_YES) && (ps->send_connected ==
GNUNET_YES)
+ && (ps->recv_force_disconnect == GNUNET_NO) &&
+ (ps->recv_force_disconnect == GNUNET_NO))
+ return GNUNET_YES;
+ }
return GNUNET_SYSERR;
}
@@ -2362,130 +2370,129 @@
* @return selected session
*
*/
-static struct Session *
-send_select_session (struct HTTP_PeerContext *pc,
- const void * addr, size_t addrlen,
- int force_address,
- struct Session * session)
+static struct Session *
+send_select_session (struct HTTP_PeerContext *pc,
+ const void *addr, size_t addrlen,
+ int force_address, struct Session *session)
{
- struct Session * tmp = NULL;
+ struct Session *tmp = NULL;
int addr_given = GNUNET_NO;
-
- if ((addr!=NULL) && (addrlen>0))
+
+ if ((addr != NULL) && (addrlen > 0))
addr_given = GNUNET_YES;
-
+
if (force_address == GNUNET_YES)
+ {
+ /* check session given as argument */
+ if ((session != NULL) && (addr_given == GNUNET_YES))
{
- /* check session given as argument */
- if ((session != NULL) && (addr_given == GNUNET_YES))
- {
- if (0 == memcmp(session->addr, addr, addrlen))
- {
- /* connection can not be used, since it is disconnected */
- if ( (session->recv_force_disconnect==GNUNET_NO) &&
- (session->send_force_disconnect==GNUNET_NO) )
- {
+ if (0 == memcmp (session->addr, addr, addrlen))
+ {
+ /* connection can not be used, since it is disconnected */
+ if ((session->recv_force_disconnect == GNUNET_NO) &&
+ (session->send_force_disconnect == GNUNET_NO))
+ {
#if DEBUG_SESSION_SELECTION
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Session %X selected: Using session passed by
transport to send to forced address \n",
- session);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Session %X selected: Using session passed by transport
to send to forced address \n",
+ session);
#endif
- return session;
- }
- }
- }
- /* check last session used */
- if ((pc->last_session != NULL)&& (addr_given == GNUNET_YES))
- {
- if (0 == memcmp(pc->last_session->addr, addr, addrlen))
- {
- /* connection can not be used, since it is disconnected */
- if ( (pc->last_session->recv_force_disconnect==GNUNET_NO) &&
- (pc->last_session->send_force_disconnect==GNUNET_NO) )
- {
+ return session;
+ }
+ }
+ }
+ /* check last session used */
+ if ((pc->last_session != NULL) && (addr_given == GNUNET_YES))
+ {
+ if (0 == memcmp (pc->last_session->addr, addr, addrlen))
+ {
+ /* connection can not be used, since it is disconnected */
+ if ((pc->last_session->recv_force_disconnect == GNUNET_NO) &&
+ (pc->last_session->send_force_disconnect == GNUNET_NO))
+ {
#if DEBUG_SESSION_SELECTION
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Session %X selected: Using last session used to
send to forced address \n",
- pc->last_session);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Session %X selected: Using last session used to send to
forced address \n",
+ pc->last_session);
#endif
- return pc->last_session;
- }
- }
- }
- /* find session in existing sessions */
- tmp = pc->head;
- while ((tmp!=NULL) && (addr_given == GNUNET_YES))
- {
- if (0 == memcmp(tmp->addr, addr, addrlen))
- {
- /* connection can not be used, since it is disconnected */
- if ( (tmp->recv_force_disconnect==GNUNET_NO) &&
- (tmp->send_force_disconnect==GNUNET_NO) )
- {
+ return pc->last_session;
+ }
+ }
+ }
+ /* find session in existing sessions */
+ tmp = pc->head;
+ while ((tmp != NULL) && (addr_given == GNUNET_YES))
+ {
+ if (0 == memcmp (tmp->addr, addr, addrlen))
+ {
+ /* connection can not be used, since it is disconnected */
+ if ((tmp->recv_force_disconnect == GNUNET_NO) &&
+ (tmp->send_force_disconnect == GNUNET_NO))
+ {
#if DEBUG_SESSION_SELECTION
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Session %X selected: Using existing session to
send to forced address \n",
- session);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Session %X selected: Using existing session to send to
forced address \n",
+ session);
#endif
- return session;
- }
- }
- tmp=tmp->next;
- }
- /* no session to use */
- return NULL;
+ return session;
+ }
+ }
+ tmp = tmp->next;
}
+ /* no session to use */
+ return NULL;
+ }
if ((force_address == GNUNET_NO) || (force_address == GNUNET_SYSERR))
+ {
+ /* check session given as argument */
+ if (session != NULL)
{
- /* check session given as argument */
- if (session != NULL)
- {
- /* connection can not be used, since it is disconnected */
- if ( (session->recv_force_disconnect==GNUNET_NO) &&
- (session->send_force_disconnect==GNUNET_NO) )
- {
+ /* connection can not be used, since it is disconnected */
+ if ((session->recv_force_disconnect == GNUNET_NO) &&
+ (session->send_force_disconnect == GNUNET_NO))
+ {
#if DEBUG_SESSION_SELECTION
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Session %X selected: Using session passed by
transport to send not-forced address\n",
- session);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Session %X selected: Using session passed by transport to
send not-forced address\n",
+ session);
#endif
- return session;
- }
- }
- /* check last session used */
- if (pc->last_session != NULL)
- {
- /* connection can not be used, since it is disconnected */
- if ( (pc->last_session->recv_force_disconnect==GNUNET_NO) &&
- (pc->last_session->send_force_disconnect==GNUNET_NO) )
- {
+ return session;
+ }
+ }
+ /* check last session used */
+ if (pc->last_session != NULL)
+ {
+ /* connection can not be used, since it is disconnected */
+ if ((pc->last_session->recv_force_disconnect == GNUNET_NO) &&
+ (pc->last_session->send_force_disconnect == GNUNET_NO))
+ {
#if DEBUG_SESSION_SELECTION
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Session %X selected: Using last session to send to
not-forced address\n",
- pc->last_session);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Session %X selected: Using last session to send to
not-forced address\n",
+ pc->last_session);
#endif
- return pc->last_session;
- }
- }
- /* find session in existing sessions */
- tmp = pc->head;
- while (tmp!=NULL)
- {
- /* connection can not be used, since it is disconnected */
- if ( (tmp->recv_force_disconnect==GNUNET_NO) &&
- (tmp->send_force_disconnect==GNUNET_NO) )
- {
+ return pc->last_session;
+ }
+ }
+ /* find session in existing sessions */
+ tmp = pc->head;
+ while (tmp != NULL)
+ {
+ /* connection can not be used, since it is disconnected */
+ if ((tmp->recv_force_disconnect == GNUNET_NO) &&
+ (tmp->send_force_disconnect == GNUNET_NO))
+ {
#if DEBUG_SESSION_SELECTION
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Session %X selected: Using existing session to send
to not-forced address\n",
- tmp);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Session %X selected: Using existing session to send to
not-forced address\n",
+ tmp);
#endif
- return tmp;
- }
- tmp=tmp->next;
- }
- return NULL;
+ return tmp;
+ }
+ tmp = tmp->next;
}
+ return NULL;
+ }
return NULL;
}
@@ -2537,117 +2544,112 @@
const void *addr,
size_t addrlen,
int force_address,
- GNUNET_TRANSPORT_TransmitContinuation cont,
- void *cont_cls)
+ GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
{
struct Plugin *plugin = cls;
struct HTTP_Message *msg;
- struct HTTP_PeerContext * pc;
- struct Session * ps = NULL;
+ struct HTTP_PeerContext *pc;
+ struct Session *ps = NULL;
- GNUNET_assert(cls !=NULL);
+ GNUNET_assert (cls != NULL);
#if DEBUG_HTTP
- char * force;
+ char *force;
if (force_address == GNUNET_YES)
- GNUNET_asprintf(&force, "forced addr.");
+ GNUNET_asprintf (&force, "forced addr.");
else if (force_address == GNUNET_NO)
- GNUNET_asprintf(&force, "any addr.");
+ GNUNET_asprintf (&force, "any addr.");
else if (force_address == GNUNET_SYSERR)
- GNUNET_asprintf(&force,"reliable bi-direc. address addr.");
+ GNUNET_asprintf (&force, "reliable bi-direc. address addr.");
else
GNUNET_assert (0);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transport tells me to send %u bytes to `%s' using %s (%s) and
session: %X\n",
- msgbuf_size,
- GNUNET_i2s(target),
- force,
- http_plugin_address_to_string(NULL, addr, addrlen),
- session);
- GNUNET_free(force);
+ "Transport tells me to send %u bytes to `%s' using %s (%s) and
session: %X\n",
+ msgbuf_size,
+ GNUNET_i2s (target),
+ force,
+ http_plugin_address_to_string (NULL, addr, addrlen), session);
+ GNUNET_free (force);
#endif
pc = GNUNET_CONTAINER_multihashmap_get (plugin->peers, &target->hashPubKey);
/* Peer unknown */
- if (pc==NULL)
- {
- pc = GNUNET_malloc(sizeof (struct HTTP_PeerContext));
- pc->plugin = plugin;
- pc->session_id_counter=1;
- pc->last_session = NULL;
- memcpy(&pc->identity, target, sizeof(struct GNUNET_PeerIdentity));
- GNUNET_CONTAINER_multihashmap_put (plugin->peers,
- &pc->identity.hashPubKey,
- pc,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
- GNUNET_STATISTICS_update (plugin->env->stats,
- gettext_noop ("# HTTP peers active"),
- 1,
- GNUNET_NO);
- }
+ if (pc == NULL)
+ {
+ pc = GNUNET_malloc (sizeof (struct HTTP_PeerContext));
+ pc->plugin = plugin;
+ pc->session_id_counter = 1;
+ pc->last_session = NULL;
+ memcpy (&pc->identity, target, sizeof (struct GNUNET_PeerIdentity));
+ GNUNET_CONTAINER_multihashmap_put (plugin->peers,
+ &pc->identity.hashPubKey,
+ pc,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+ GNUNET_STATISTICS_update (plugin->env->stats,
+ gettext_noop ("# HTTP peers active"),
+ 1, GNUNET_NO);
+ }
ps = send_select_session (pc, addr, addrlen, force_address, session);
/* session not existing, but address forced -> creating new session */
- if (ps==NULL)
+ if (ps == NULL)
+ {
+ if ((addr != NULL) && (addrlen != 0))
{
- if ((addr!=NULL) && (addrlen!=0))
- {
- ps = GNUNET_malloc(sizeof (struct Session));
+ ps = GNUNET_malloc (sizeof (struct Session));
#if DEBUG_SESSION_SELECTION
- if (force_address == GNUNET_YES)
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "No existing connection & forced address: creating new
session %X to peer %s\n",
- ps, GNUNET_i2s(target));
- if (force_address != GNUNET_YES)
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "No existing connection: creating new session %X to
peer %s\n",
- ps, GNUNET_i2s(target));
+ if (force_address == GNUNET_YES)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "No existing connection & forced address: creating new
session %X to peer %s\n",
+ ps, GNUNET_i2s (target));
+ if (force_address != GNUNET_YES)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "No existing connection: creating new session %X to peer
%s\n",
+ ps, GNUNET_i2s (target));
#endif
- ps->addr = GNUNET_malloc(addrlen);
- memcpy(ps->addr,addr,addrlen);
- ps->addrlen = addrlen;
- ps->direction=OUTBOUND;
- ps->recv_connected = GNUNET_NO;
- ps->recv_force_disconnect = GNUNET_NO;
- ps->send_connected = GNUNET_NO;
- ps->send_force_disconnect = GNUNET_NO;
- ps->pending_msgs_head = NULL;
- ps->pending_msgs_tail = NULL;
- ps->peercontext = pc;
- ps->session_id = pc->session_id_counter;
- ps->queue_length_cur = 0;
- ps->queue_length_max = GNUNET_SERVER_MAX_MESSAGE_SIZE;
- pc->session_id_counter++;
- ps->url = create_url (plugin, ps->addr, ps->addrlen, ps->session_id);
- if (ps->msgtok == NULL)
- ps->msgtok = GNUNET_SERVER_mst_create (&curl_receive_mst_cb, ps);
- GNUNET_CONTAINER_DLL_insert(pc->head,pc->tail,ps);
- GNUNET_STATISTICS_update (plugin->env->stats,
- gettext_noop ("# HTTP outbound sessions for
peers active"),
- 1,
- GNUNET_NO);
- }
- else
- {
+ ps->addr = GNUNET_malloc (addrlen);
+ memcpy (ps->addr, addr, addrlen);
+ ps->addrlen = addrlen;
+ ps->direction = OUTBOUND;
+ ps->recv_connected = GNUNET_NO;
+ ps->recv_force_disconnect = GNUNET_NO;
+ ps->send_connected = GNUNET_NO;
+ ps->send_force_disconnect = GNUNET_NO;
+ ps->pending_msgs_head = NULL;
+ ps->pending_msgs_tail = NULL;
+ ps->peercontext = pc;
+ ps->session_id = pc->session_id_counter;
+ ps->queue_length_cur = 0;
+ ps->queue_length_max = GNUNET_SERVER_MAX_MESSAGE_SIZE;
+ pc->session_id_counter++;
+ ps->url = create_url (plugin, ps->addr, ps->addrlen, ps->session_id);
+ if (ps->msgtok == NULL)
+ ps->msgtok = GNUNET_SERVER_mst_create (&curl_receive_mst_cb, ps);
+ GNUNET_CONTAINER_DLL_insert (pc->head, pc->tail, ps);
+ GNUNET_STATISTICS_update (plugin->env->stats,
+ gettext_noop
+ ("# HTTP outbound sessions for peers active"),
+ 1, GNUNET_NO);
+ }
+ else
+ {
#if DEBUG_HTTP
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "No existing session found & and no address given: no way
to send this message to peer `%s'!\n",
- GNUNET_i2s(target));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "No existing session found & and no address given: no way to
send this message to peer `%s'!\n",
+ GNUNET_i2s (target));
#endif
- return GNUNET_SYSERR;
- }
+ return GNUNET_SYSERR;
}
-
+ }
+
if (msgbuf_size >= (ps->queue_length_max - ps->queue_length_cur))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Queue %X full: %u bytes in queue available, message with %u
is too big\n",
- ps,
- (ps->queue_length_max - ps->queue_length_cur),
- msgbuf_size);
- //return GNUNET_SYSERR;
- }
-
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Queue %X full: %u bytes in queue available, message with %u
is too big\n",
+ ps, (ps->queue_length_max - ps->queue_length_cur),
msgbuf_size);
+ //return GNUNET_SYSERR;
+ }
+
/* create msg */
msg = GNUNET_malloc (sizeof (struct HTTP_Message) + msgbuf_size);
msg->next = NULL;
@@ -2656,16 +2658,15 @@
msg->buf = (char *) &msg[1];
msg->transmit_cont = cont;
msg->transmit_cont_cls = cont_cls;
- memcpy (msg->buf,msgbuf, msgbuf_size);
+ memcpy (msg->buf, msgbuf, msgbuf_size);
GNUNET_CONTAINER_DLL_insert (ps->pending_msgs_head,
- ps->pending_msgs_tail,
- msg);
+ ps->pending_msgs_tail, msg);
ps->queue_length_cur += msgbuf_size;
if (send_check_connections (plugin, ps) == GNUNET_SYSERR)
return GNUNET_SYSERR;
if (force_address != GNUNET_YES)
pc->last_session = ps;
- if (pc->last_session==NULL)
+ if (pc->last_session == NULL)
pc->last_session = ps;
return msg->size;
}
@@ -2680,49 +2681,48 @@
* @param target peer from which to disconnect
*/
static void
-http_plugin_disconnect (void *cls,
- const struct GNUNET_PeerIdentity *target)
+http_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
{
struct Plugin *plugin = cls;
struct HTTP_PeerContext *pc = NULL;
struct Session *ps = NULL;
pc = GNUNET_CONTAINER_multihashmap_get (plugin->peers, &target->hashPubKey);
- if (pc==NULL)
+ if (pc == NULL)
return;
ps = pc->head;
- while (ps!=NULL)
+ while (ps != NULL)
+ {
+ /* Telling transport that session is getting disconnected */
+ plugin->env->session_end (plugin, target, ps);
+ if (ps->direction == OUTBOUND)
{
- /* Telling transport that session is getting disconnected */
- plugin->env->session_end(plugin, target, ps);
- if (ps->direction==OUTBOUND)
- {
- if (ps->send_endpoint!=NULL)
- {
- //GNUNET_assert(CURLM_OK ==
curl_multi_remove_handle(plugin->multi_handle,ps->send_endpoint));
- //curl_easy_cleanup(ps->send_endpoint);
- //ps->send_endpoint=NULL;
- ps->send_force_disconnect = GNUNET_YES;
- }
- if (ps->recv_endpoint!=NULL)
- {
- //GNUNET_assert(CURLM_OK ==
curl_multi_remove_handle(plugin->multi_handle,ps->recv_endpoint));
- //curl_easy_cleanup(ps->recv_endpoint);
- //ps->recv_endpoint=NULL;
- ps->recv_force_disconnect = GNUNET_YES;
- }
- }
- if (ps->direction==INBOUND)
- {
- ps->recv_force_disconnect = GNUNET_YES;
- ps->send_force_disconnect = GNUNET_YES;
- }
- while (ps->pending_msgs_head!=NULL)
- remove_http_message(ps, ps->pending_msgs_head);
- ps->recv_active = GNUNET_NO;
- ps->send_active = GNUNET_NO;
- ps=ps->next;
+ if (ps->send_endpoint != NULL)
+ {
+ //GNUNET_assert(CURLM_OK ==
curl_multi_remove_handle(plugin->multi_handle,ps->send_endpoint));
+ //curl_easy_cleanup(ps->send_endpoint);
+ //ps->send_endpoint=NULL;
+ ps->send_force_disconnect = GNUNET_YES;
+ }
+ if (ps->recv_endpoint != NULL)
+ {
+ //GNUNET_assert(CURLM_OK ==
curl_multi_remove_handle(plugin->multi_handle,ps->recv_endpoint));
+ //curl_easy_cleanup(ps->recv_endpoint);
+ //ps->recv_endpoint=NULL;
+ ps->recv_force_disconnect = GNUNET_YES;
+ }
}
+ if (ps->direction == INBOUND)
+ {
+ ps->recv_force_disconnect = GNUNET_YES;
+ ps->send_force_disconnect = GNUNET_YES;
+ }
+ while (ps->pending_msgs_head != NULL)
+ remove_http_message (ps, ps->pending_msgs_head);
+ ps->recv_active = GNUNET_NO;
+ ps->send_active = GNUNET_NO;
+ ps = ps->next;
+ }
}
@@ -2739,11 +2739,11 @@
char *ret;
if (hostname == NULL)
- {
- ppc->asc (ppc->asc_cls, NULL);
- GNUNET_free (ppc);
- return;
- }
+ {
+ ppc->asc (ppc->asc_cls, NULL);
+ GNUNET_free (ppc);
+ return;
+ }
GNUNET_asprintf (&ret, "%s://%s:%d", PROTOCOL_PREFIX, hostname, ppc->port);
ppc->asc (ppc->asc_cls, ret);
@@ -2768,61 +2768,57 @@
*/
static void
http_plugin_address_pretty_printer (void *cls,
- const char *type,
- const void *addr,
- size_t addrlen,
- int numeric,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_TRANSPORT_AddressStringCallback
- asc, void *asc_cls)
+ const char *type,
+ const void *addr,
+ size_t addrlen,
+ int numeric,
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_TRANSPORT_AddressStringCallback
+ asc, void *asc_cls)
{
struct PrettyPrinterContext *ppc;
const void *sb;
size_t sbs;
- struct sockaddr_in a4;
+ struct sockaddr_in a4;
struct sockaddr_in6 a6;
const struct IPv4HttpAddress *t4;
const struct IPv6HttpAddress *t6;
uint16_t port;
if (addrlen == sizeof (struct IPv6HttpAddress))
- {
- t6 = addr;
- memset (&a6, 0, sizeof (a6));
- a6.sin6_family = AF_INET6;
- a6.sin6_port = t6->port;
- memcpy (&a6.sin6_addr,
- &t6->ipv6_addr,
- sizeof (struct in6_addr));
- port = ntohs (t6->port);
- sb = &a6;
- sbs = sizeof (a6);
- }
+ {
+ t6 = addr;
+ memset (&a6, 0, sizeof (a6));
+ a6.sin6_family = AF_INET6;
+ a6.sin6_port = t6->port;
+ memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof (struct in6_addr));
+ port = ntohs (t6->port);
+ sb = &a6;
+ sbs = sizeof (a6);
+ }
else if (addrlen == sizeof (struct IPv4HttpAddress))
- {
- t4 = addr;
- memset (&a4, 0, sizeof (a4));
- a4.sin_family = AF_INET;
- a4.sin_port = t4->port;
- a4.sin_addr.s_addr = t4->ipv4_addr;
- port = ntohs (t4->ipv4_addr);
- sb = &a4;
- sbs = sizeof (a4);
- }
+ {
+ t4 = addr;
+ memset (&a4, 0, sizeof (a4));
+ a4.sin_family = AF_INET;
+ a4.sin_port = t4->port;
+ a4.sin_addr.s_addr = t4->ipv4_addr;
+ port = ntohs (t4->ipv4_addr);
+ sb = &a4;
+ sbs = sizeof (a4);
+ }
else
- {
- /* invalid address */
- GNUNET_break_op (0);
- asc (asc_cls, NULL);
- return;
- }
+ {
+ /* invalid address */
+ GNUNET_break_op (0);
+ asc (asc_cls, NULL);
+ return;
+ }
ppc = GNUNET_malloc (sizeof (struct PrettyPrinterContext));
ppc->asc = asc;
ppc->asc_cls = asc_cls;
ppc->port = port;
- GNUNET_RESOLVER_hostname_get (sb,
- sbs,
- !numeric, timeout, &append_port, ppc);
+ GNUNET_RESOLVER_hostname_get (sb, sbs, !numeric, timeout, &append_port, ppc);
}
@@ -2840,8 +2836,7 @@
* and transport
*/
static int
-http_plugin_address_suggested (void *cls,
- const void *addr, size_t addrlen)
+http_plugin_address_suggested (void *cls, const void *addr, size_t addrlen)
{
struct Plugin *plugin = cls;
struct IPv4HttpAddress *v4;
@@ -2849,52 +2844,59 @@
struct IPv4HttpAddressWrapper *w_tv4 = plugin->ipv4_addr_head;
struct IPv6HttpAddressWrapper *w_tv6 = plugin->ipv6_addr_head;
- GNUNET_assert(cls !=NULL);
+ GNUNET_assert (cls != NULL);
if ((addrlen != sizeof (struct IPv4HttpAddress)) &&
(addrlen != sizeof (struct IPv6HttpAddress)))
return GNUNET_SYSERR;
if (addrlen == sizeof (struct IPv4HttpAddress))
+ {
+ v4 = (struct IPv4HttpAddress *) addr;
+ if (plugin->bind4_address != NULL)
{
- v4 = (struct IPv4HttpAddress *) addr;
- if (plugin->bind4_address!=NULL)
- {
- if (0 == memcmp (&plugin->bind4_address->sin_addr, &v4->ipv4_addr,
sizeof(uint32_t)))
- return GNUNET_OK;
- else
- return GNUNET_SYSERR;
- }
- while (w_tv4!=NULL)
- {
- if (0==memcmp (&w_tv4->addr->ipv4_addr, &v4->ipv4_addr,
sizeof(uint32_t)))
- break;
- w_tv4 = w_tv4->next;
- }
- if (w_tv4 != NULL)
+ if (0 ==
+ memcmp (&plugin->bind4_address->sin_addr, &v4->ipv4_addr,
+ sizeof (uint32_t)))
return GNUNET_OK;
else
- return GNUNET_SYSERR;
+ return GNUNET_SYSERR;
}
+ while (w_tv4 != NULL)
+ {
+ if (0 ==
+ memcmp (&w_tv4->addr->ipv4_addr, &v4->ipv4_addr, sizeof (uint32_t)))
+ break;
+ w_tv4 = w_tv4->next;
+ }
+ if (w_tv4 != NULL)
+ return GNUNET_OK;
+ else
+ return GNUNET_SYSERR;
+ }
if (addrlen == sizeof (struct IPv6HttpAddress))
+ {
+ v6 = (struct IPv6HttpAddress *) addr;
+ if (plugin->bind6_address != NULL)
{
- v6 = (struct IPv6HttpAddress *) addr;
- if (plugin->bind6_address!=NULL)
- {
- if (0 == memcmp (&plugin->bind6_address->sin6_addr, &v6->ipv6_addr,
sizeof(struct in6_addr)))
- return GNUNET_OK;
- else
- return GNUNET_SYSERR;
- }
- while (w_tv6!=NULL)
- {
- if (0 == memcmp (&w_tv6->addr->ipv6_addr, &v6->ipv6_addr,
sizeof(struct in6_addr)))
- break;
- w_tv6 = w_tv6->next;
- }
- if (w_tv6 !=NULL)
+ if (0 ==
+ memcmp (&plugin->bind6_address->sin6_addr, &v6->ipv6_addr,
+ sizeof (struct in6_addr)))
return GNUNET_OK;
else
- return GNUNET_SYSERR;
+ return GNUNET_SYSERR;
}
+ while (w_tv6 != NULL)
+ {
+ if (0 ==
+ memcmp (&w_tv6->addr->ipv6_addr, &v6->ipv6_addr,
+ sizeof (struct in6_addr)))
+ break;
+ w_tv6 = w_tv6->next;
+ }
+ if (w_tv6 != NULL)
+ return GNUNET_OK;
+ else
+ return GNUNET_SYSERR;
+ }
return GNUNET_SYSERR;
}
@@ -2910,50 +2912,44 @@
* @param addrlen length of the address
* @return string representing the same address
*/
-static const char*
-http_plugin_address_to_string (void *cls,
- const void *addr,
- size_t addrlen)
+static const char *
+http_plugin_address_to_string (void *cls, const void *addr, size_t addrlen)
{
const struct IPv4HttpAddress *t4;
const struct IPv6HttpAddress *t6;
struct sockaddr_in a4;
struct sockaddr_in6 a6;
- char * address;
+ char *address;
static char rbuf[INET6_ADDRSTRLEN + 13];
uint16_t port;
int res;
if (addrlen == sizeof (struct IPv6HttpAddress))
- {
- address = GNUNET_malloc (INET6_ADDRSTRLEN);
- t6 = addr;
- a6.sin6_addr = t6->ipv6_addr;
- inet_ntop(AF_INET6, &(a6.sin6_addr),address,INET6_ADDRSTRLEN);
- port = ntohs(t6->port);
- }
+ {
+ address = GNUNET_malloc (INET6_ADDRSTRLEN);
+ t6 = addr;
+ a6.sin6_addr = t6->ipv6_addr;
+ inet_ntop (AF_INET6, &(a6.sin6_addr), address, INET6_ADDRSTRLEN);
+ port = ntohs (t6->port);
+ }
else if (addrlen == sizeof (struct IPv4HttpAddress))
- {
- address = GNUNET_malloc (INET_ADDRSTRLEN);
- t4 = addr;
- a4.sin_addr.s_addr = t4->ipv4_addr;
- inet_ntop(AF_INET, &(a4.sin_addr),address,INET_ADDRSTRLEN);
- port = ntohs(t4->port);
- }
+ {
+ address = GNUNET_malloc (INET_ADDRSTRLEN);
+ t4 = addr;
+ a4.sin_addr.s_addr = t4->ipv4_addr;
+ inet_ntop (AF_INET, &(a4.sin_addr), address, INET_ADDRSTRLEN);
+ port = ntohs (t4->port);
+ }
else
- {
- /* invalid address */
- return NULL;
- }
+ {
+ /* invalid address */
+ return NULL;
+ }
- res = GNUNET_snprintf (rbuf,
- sizeof (rbuf),
- "%s:%u",
- address,
- port);
+ res = GNUNET_snprintf (rbuf, sizeof (rbuf), "%s:%u", address, port);
GNUNET_free (address);
- GNUNET_assert(res != 0);
+ GNUNET_assert (res != 0);
return rbuf;
}
@@ -2968,23 +2964,21 @@
*/
static void
try_connection_reversal (void *cls,
- const struct sockaddr *addr,
- socklen_t addrlen)
+ const struct sockaddr *addr, socklen_t addrlen)
{
}
static void
tcp_nat_cb_add_addr (void *cls,
- int add_remove,
- const struct sockaddr *addr,
- socklen_t addrlen)
+ int add_remove,
+ const struct sockaddr *addr, socklen_t addrlen)
{
struct Plugin *plugin = cls;
- struct IPv4HttpAddress * t4 = NULL;
- struct IPv4HttpAddressWrapper * w_t4 = NULL;
- struct IPv6HttpAddress * t6 = NULL;
- struct IPv6HttpAddressWrapper * w_t6 = NULL;
+ struct IPv4HttpAddress *t4 = NULL;
+ struct IPv4HttpAddressWrapper *w_t4 = NULL;
+ struct IPv6HttpAddress *t6 = NULL;
+ struct IPv6HttpAddressWrapper *w_t6 = NULL;
int af;
af = addr->sa_family;
@@ -2994,61 +2988,63 @@
w_t4 = plugin->ipv4_addr_head;
while (w_t4 != NULL)
{
- int res = memcmp(&w_t4->addr->ipv4_addr,
- &((struct sockaddr_in *) addr)->sin_addr,
- sizeof (struct in_addr));
+ int res = memcmp (&w_t4->addr->ipv4_addr,
+ &((struct sockaddr_in *) addr)->sin_addr,
+ sizeof (struct in_addr));
+
if (0 == res)
break;
w_t4 = w_t4->next;
}
if (w_t4 == NULL)
{
- w_t4 = GNUNET_malloc(sizeof(struct IPv4HttpAddressWrapper));
- t4 = GNUNET_malloc(sizeof(struct IPv4HttpAddress));
+ w_t4 = GNUNET_malloc (sizeof (struct IPv4HttpAddressWrapper));
+ t4 = GNUNET_malloc (sizeof (struct IPv4HttpAddress));
memcpy (&t4->ipv4_addr,
- &((struct sockaddr_in *) addr)->sin_addr,
- sizeof (struct in_addr));
+ &((struct sockaddr_in *) addr)->sin_addr,
+ sizeof (struct in_addr));
t4->port = htons (plugin->port_inbound);
w_t4->addr = t4;
- GNUNET_CONTAINER_DLL_insert(plugin->ipv4_addr_head,
- plugin->ipv4_addr_tail,w_t4);
+ GNUNET_CONTAINER_DLL_insert (plugin->ipv4_addr_head,
+ plugin->ipv4_addr_tail, w_t4);
}
- 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;
while (w_t6)
{
- int res = memcmp(&w_t6->addr->ipv6_addr,
- &((struct sockaddr_in6 *) addr)->sin6_addr,
- sizeof (struct in6_addr));
+ int res = memcmp (&w_t6->addr->ipv6_addr,
+ &((struct sockaddr_in6 *) addr)->sin6_addr,
+ sizeof (struct in6_addr));
+
if (0 == res)
break;
w_t6 = w_t6->next;
}
if (w_t6 == NULL)
{
- w_t6 = GNUNET_malloc(sizeof(struct IPv6HttpAddressWrapper));
- t6 = GNUNET_malloc(sizeof(struct IPv6HttpAddress));
+ w_t6 = GNUNET_malloc (sizeof (struct IPv6HttpAddressWrapper));
+ t6 = GNUNET_malloc (sizeof (struct IPv6HttpAddress));
- memcpy (&t6->ipv6_addr,
- &((struct sockaddr_in6 *) addr)->sin6_addr,
- sizeof (struct in6_addr));
- t6->port = htons (plugin->port_inbound);
+ memcpy (&t6->ipv6_addr,
+ &((struct sockaddr_in6 *) addr)->sin6_addr,
+ sizeof (struct in6_addr));
+ t6->port = htons (plugin->port_inbound);
- w_t6->addr = t6;
+ w_t6->addr = t6;
- GNUNET_CONTAINER_DLL_insert(plugin->ipv6_addr_head,
- plugin->ipv6_addr_tail,w_t6);
+ GNUNET_CONTAINER_DLL_insert (plugin->ipv6_addr_head,
+ plugin->ipv6_addr_tail, w_t6);
}
- plugin->env->notify_address(plugin->env->cls,
- add_remove,
- w_t6->addr, sizeof (struct IPv6HttpAddress));
+ plugin->env->notify_address (plugin->env->cls,
+ add_remove,
+ w_t6->addr, sizeof (struct IPv6HttpAddress));
break;
default:
return;
@@ -3058,13 +3054,12 @@
static void
tcp_nat_cb_remove_addr (void *cls,
- int add_remove,
- const struct sockaddr *addr,
- socklen_t addrlen)
+ int add_remove,
+ const struct sockaddr *addr, socklen_t addrlen)
{
struct Plugin *plugin = cls;
- struct IPv4HttpAddressWrapper * w_t4 = NULL;
- struct IPv6HttpAddressWrapper * w_t6 = NULL;
+ struct IPv4HttpAddressWrapper *w_t4 = NULL;
+ struct IPv6HttpAddressWrapper *w_t6 = NULL;
int af;
af = addr->sa_family;
@@ -3072,45 +3067,47 @@
{
case AF_INET:
w_t4 = plugin->ipv4_addr_head;
- while (w_t4 != NULL)
- {
- int res = memcmp(&w_t4->addr->ipv4_addr,
- &((struct sockaddr_in *) addr)->sin_addr,
- sizeof (struct in_addr));
- if (0 == res)
- break;
- w_t4 = w_t4->next;
- }
- if (w_t4 == NULL)
- return;
- plugin->env->notify_address(plugin->env->cls,
- add_remove,
- w_t4->addr, sizeof (struct IPv4HttpAddress));
+ while (w_t4 != NULL)
+ {
+ int res = memcmp (&w_t4->addr->ipv4_addr,
+ &((struct sockaddr_in *) addr)->sin_addr,
+ sizeof (struct in_addr));
- GNUNET_CONTAINER_DLL_remove(plugin->ipv4_addr_head,
- plugin->ipv4_addr_tail,w_t4);
- GNUNET_free (w_t4->addr);
- GNUNET_free (w_t4);
+ if (0 == res)
+ break;
+ w_t4 = w_t4->next;
+ }
+ if (w_t4 == NULL)
+ return;
+ plugin->env->notify_address (plugin->env->cls,
+ add_remove,
+ w_t4->addr, sizeof (struct IPv4HttpAddress));
+
+ GNUNET_CONTAINER_DLL_remove (plugin->ipv4_addr_head,
+ plugin->ipv4_addr_tail, w_t4);
+ GNUNET_free (w_t4->addr);
+ GNUNET_free (w_t4);
break;
case AF_INET6:
w_t6 = plugin->ipv6_addr_head;
while (w_t6 != NULL)
{
- int res = memcmp(&w_t6->addr->ipv6_addr,
- &((struct sockaddr_in6 *) addr)->sin6_addr,
- sizeof (struct in6_addr));
+ int res = memcmp (&w_t6->addr->ipv6_addr,
+ &((struct sockaddr_in6 *) addr)->sin6_addr,
+ sizeof (struct in6_addr));
+
if (0 == res)
break;
w_t6 = w_t6->next;
}
if (w_t6 == NULL)
return;
- plugin->env->notify_address(plugin->env->cls,
- add_remove,
- w_t6->addr, sizeof (struct IPv6HttpAddress));
+ plugin->env->notify_address (plugin->env->cls,
+ add_remove,
+ w_t6->addr, sizeof (struct IPv6HttpAddress));
- GNUNET_CONTAINER_DLL_remove(plugin->ipv6_addr_head,
- plugin->ipv6_addr_tail,w_t6);
+ GNUNET_CONTAINER_DLL_remove (plugin->ipv6_addr_head,
+ plugin->ipv6_addr_tail, w_t6);
GNUNET_free (w_t6->addr);
GNUNET_free (w_t6);
break;
@@ -3132,10 +3129,9 @@
static void
tcp_nat_port_map_callback (void *cls,
int add_remove,
- const struct sockaddr *addr,
- socklen_t addrlen)
+ const struct sockaddr *addr, socklen_t addrlen)
{
- GNUNET_assert(cls !=NULL );
+ GNUNET_assert (cls != NULL);
#if DEBUG_HTTP
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
"NPMC called to %s address `%s'\n",
@@ -3163,75 +3159,78 @@
struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
struct Plugin *plugin = api->cls;
CURLMcode mret;
- struct IPv4HttpAddressWrapper * w_t4;
- struct IPv6HttpAddressWrapper * w_t6;
- GNUNET_assert(cls !=NULL);
+ struct IPv4HttpAddressWrapper *w_t4;
+ struct IPv6HttpAddressWrapper *w_t6;
+ GNUNET_assert (cls != NULL);
+
if (plugin->nat != NULL)
GNUNET_NAT_unregister (plugin->nat);
if (plugin->http_server_daemon_v4 != NULL)
- {
- MHD_stop_daemon (plugin->http_server_daemon_v4);
- plugin->http_server_daemon_v4 = NULL;
- }
+ {
+ MHD_stop_daemon (plugin->http_server_daemon_v4);
+ plugin->http_server_daemon_v4 = NULL;
+ }
if (plugin->http_server_daemon_v6 != NULL)
- {
- MHD_stop_daemon (plugin->http_server_daemon_v6);
- plugin->http_server_daemon_v6 = NULL;
- }
- if ( plugin->http_server_task_v4 != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel(plugin->http_server_task_v4);
- plugin->http_server_task_v4 = GNUNET_SCHEDULER_NO_TASK;
- }
- if ( plugin->http_server_task_v6 != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel(plugin->http_server_task_v6);
- plugin->http_server_task_v6 = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ MHD_stop_daemon (plugin->http_server_daemon_v6);
+ plugin->http_server_daemon_v6 = NULL;
+ }
+ if (plugin->http_server_task_v4 != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (plugin->http_server_task_v4);
+ plugin->http_server_task_v4 = GNUNET_SCHEDULER_NO_TASK;
+ }
+ if (plugin->http_server_task_v6 != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (plugin->http_server_task_v6);
+ plugin->http_server_task_v6 = GNUNET_SCHEDULER_NO_TASK;
+ }
- while (plugin->ipv4_addr_head!=NULL)
- {
- w_t4 = plugin->ipv4_addr_head;
-
GNUNET_CONTAINER_DLL_remove(plugin->ipv4_addr_head,plugin->ipv4_addr_tail,w_t4);
- GNUNET_free(w_t4->addr);
- GNUNET_free(w_t4);
- }
-
- while (plugin->ipv6_addr_head!=NULL)
- {
- w_t6 = plugin->ipv6_addr_head;
-
GNUNET_CONTAINER_DLL_remove(plugin->ipv6_addr_head,plugin->ipv6_addr_tail,w_t6);
- GNUNET_free(w_t6->addr);
- GNUNET_free(w_t6);
- }
-
+ while (plugin->ipv4_addr_head != NULL)
+ {
+ w_t4 = plugin->ipv4_addr_head;
+ GNUNET_CONTAINER_DLL_remove (plugin->ipv4_addr_head,
plugin->ipv4_addr_tail,
+ w_t4);
+ GNUNET_free (w_t4->addr);
+ GNUNET_free (w_t4);
+ }
+
+ while (plugin->ipv6_addr_head != NULL)
+ {
+ w_t6 = plugin->ipv6_addr_head;
+ GNUNET_CONTAINER_DLL_remove (plugin->ipv6_addr_head,
plugin->ipv6_addr_tail,
+ w_t6);
+ GNUNET_free (w_t6->addr);
+ GNUNET_free (w_t6);
+ }
+
/* free all peer information */
- if (plugin->peers!=NULL)
- {
- GNUNET_CONTAINER_multihashmap_iterate (plugin->peers,
- &remove_peer_context_Iterator,
- plugin);
- GNUNET_CONTAINER_multihashmap_destroy (plugin->peers);
- }
- if (plugin->multi_handle!=NULL)
- {
- mret = curl_multi_cleanup(plugin->multi_handle);
- if (CURLM_OK != mret)
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "curl multihandle clean up failed\n");
- plugin->multi_handle = NULL;
- }
- curl_global_cleanup();
-
- if ( plugin->http_curl_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel(plugin->http_curl_task);
- plugin->http_curl_task = GNUNET_SCHEDULER_NO_TASK;
- }
-
+ if (plugin->peers != NULL)
+ {
+ GNUNET_CONTAINER_multihashmap_iterate (plugin->peers,
+ &remove_peer_context_Iterator,
+ plugin);
+ GNUNET_CONTAINER_multihashmap_destroy (plugin->peers);
+ }
+ if (plugin->multi_handle != NULL)
+ {
+ mret = curl_multi_cleanup (plugin->multi_handle);
+ if (CURLM_OK != mret)
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "curl multihandle clean up failed\n");
+ plugin->multi_handle = NULL;
+ }
+ curl_global_cleanup ();
+ if (plugin->http_curl_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (plugin->http_curl_task);
+ plugin->http_curl_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+
+
GNUNET_free_non_null (plugin->bind4_address);
GNUNET_free_non_null (plugin->bind6_address);
GNUNET_free_non_null (plugin->bind_hostname);
@@ -3244,35 +3243,36 @@
GNUNET_free (api);
#if DEBUG_HTTP
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Unload %s plugin complete...\n",
- PROTOCOL_PREFIX);
+ "Unload %s plugin complete...\n", PROTOCOL_PREFIX);
#endif
return NULL;
}
#if BUILD_HTTPS
static char *
-load_certificate( const char * file )
+load_certificate (const char *file)
{
- struct GNUNET_DISK_FileHandle * gn_file;
+ struct GNUNET_DISK_FileHandle *gn_file;
struct stat fstat;
- char * text = NULL;
+ char *text = NULL;
- if (0 != STAT(file, &fstat))
+ if (0 != STAT (file, &fstat))
return NULL;
- text = GNUNET_malloc (fstat.st_size+1);
- gn_file = GNUNET_DISK_file_open(file, GNUNET_DISK_OPEN_READ,
GNUNET_DISK_PERM_USER_READ);
- if (gn_file==NULL)
- {
- GNUNET_free(text);
- return NULL;
- }
+ text = GNUNET_malloc (fstat.st_size + 1);
+ gn_file =
+ GNUNET_DISK_file_open (file, GNUNET_DISK_OPEN_READ,
+ GNUNET_DISK_PERM_USER_READ);
+ if (gn_file == NULL)
+ {
+ GNUNET_free (text);
+ return NULL;
+ }
if (GNUNET_SYSERR == GNUNET_DISK_file_read (gn_file, text, fstat.st_size))
- {
- GNUNET_free (text);
- GNUNET_DISK_file_close (gn_file);
- return NULL;
- }
+ {
+ GNUNET_free (text);
+ GNUNET_DISK_file_close (gn_file);
+ return NULL;
+ }
text[fstat.st_size] = '\0';
GNUNET_DISK_file_close (gn_file);
return text;
@@ -3295,21 +3295,19 @@
struct sockaddr **addrs;
socklen_t *addrlens;
int ret;
- char * component_name;
+ char *component_name;
+
#if BUILD_HTTPS
- char * key_file = NULL;
- char * cert_file = NULL;
+ char *key_file = NULL;
+ char *cert_file = NULL;
#endif
- GNUNET_assert(cls !=NULL);
+ GNUNET_assert (cls != NULL);
#if DEBUG_HTTP
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Starting %s plugin...\n",
- PROTOCOL_PREFIX);
+ "Starting %s plugin...\n", PROTOCOL_PREFIX);
#endif
- GNUNET_asprintf(&component_name,
- "transport-%s",
- PROTOCOL_PREFIX);
+ GNUNET_asprintf (&component_name, "transport-%s", PROTOCOL_PREFIX);
plugin = GNUNET_malloc (sizeof (struct Plugin));
plugin->stats = env->stats;
@@ -3317,8 +3315,8 @@
plugin->peers = NULL;
plugin->bind4_address = NULL;
plugin->bind6_address = NULL;
- plugin->use_ipv6 = GNUNET_YES;
- plugin->use_ipv4 = GNUNET_YES;
+ plugin->use_ipv6 = GNUNET_YES;
+ plugin->use_ipv4 = GNUNET_YES;
plugin->use_localaddresses = GNUNET_NO;
api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
@@ -3330,207 +3328,207 @@
api->address_to_string = &http_plugin_address_to_string;
/* Hashing our identity to use it in URLs */
- GNUNET_CRYPTO_hash_to_enc (&(plugin->env->my_identity->hashPubKey),
- &plugin->my_ascii_hash_ident);
+ GNUNET_CRYPTO_hash_to_enc (&(plugin->env->my_identity->hashPubKey),
+ &plugin->my_ascii_hash_ident);
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_number (env->cfg,
- component_name,
- "MAX_CONNECTIONS",
- &tneigh))
+ component_name,
+ "MAX_CONNECTIONS", &tneigh))
tneigh = 128;
plugin->max_connect_per_transport = tneigh;
/* Use IPv6? */
- if (GNUNET_CONFIGURATION_have_value (env->cfg,
- component_name, "USE_IPv6"))
- {
- plugin->use_ipv6 = GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
- component_name,
- "USE_IPv6");
- }
+ if (GNUNET_CONFIGURATION_have_value (env->cfg, component_name, "USE_IPv6"))
+ {
+ plugin->use_ipv6 = GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
+ component_name,
+ "USE_IPv6");
+ }
/* Use IPv4? */
- if (GNUNET_CONFIGURATION_have_value (env->cfg,
- component_name, "USE_IPv4"))
- {
- plugin->use_ipv4 = GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
-
component_name,"USE_IPv4");
- }
+ if (GNUNET_CONFIGURATION_have_value (env->cfg, component_name, "USE_IPv4"))
+ {
+ plugin->use_ipv4 = GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
+ component_name,
+ "USE_IPv4");
+ }
/* use local addresses? */
if (GNUNET_CONFIGURATION_have_value (env->cfg,
- component_name, "USE_LOCALADDR"))
- {
- plugin->use_localaddresses = GNUNET_CONFIGURATION_get_value_yesno
(env->cfg,
- component_name,
- "USE_LOCALADDR");
- }
+ component_name, "USE_LOCALADDR"))
+ {
+ plugin->use_localaddresses = GNUNET_CONFIGURATION_get_value_yesno
(env->cfg,
+
component_name,
+
"USE_LOCALADDR");
+ }
/* Reading port number from config file */
if ((GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_number (env->cfg,
- component_name,
- "PORT",
- &port)) ||
- (port > 65535) )
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
- component_name,
- _("Require valid port number for transport plugin `%s'
in configuration!\n"),
- PROTOCOL_PREFIX);
- GNUNET_free(component_name);
- LIBGNUNET_PLUGIN_TRANSPORT_DONE (api);
- return NULL;
- }
+ component_name,
+ "PORT", &port)) || (port >
65535))
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
+ component_name,
+ _
+ ("Require valid port number for transport plugin `%s' in
configuration!\n"),
+ PROTOCOL_PREFIX);
+ GNUNET_free (component_name);
+ LIBGNUNET_PLUGIN_TRANSPORT_DONE (api);
+ return NULL;
+ }
/* Reading ipv4 addresse to bind to from config file */
- if ( (plugin->use_ipv4==GNUNET_YES) &&
- (GNUNET_CONFIGURATION_have_value (env->cfg,
- component_name, "BINDTO4")))
+ if ((plugin->use_ipv4 == GNUNET_YES) &&
+ (GNUNET_CONFIGURATION_have_value (env->cfg, component_name, "BINDTO4")))
+ {
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_string (env->cfg,
+ component_name,
+ "BINDTO4",
+
&plugin->bind_hostname));
+ plugin->bind4_address = GNUNET_malloc (sizeof (struct sockaddr_in));
+ plugin->bind4_address->sin_family = AF_INET;
+ plugin->bind4_address->sin_port = htons (port);
+
+ if (plugin->bind_hostname != NULL)
{
- GNUNET_break (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (env->cfg,
- component_name,
- "BINDTO4",
-
&plugin->bind_hostname));
- plugin->bind4_address = GNUNET_malloc(sizeof(struct sockaddr_in));
- plugin->bind4_address->sin_family = AF_INET;
- plugin->bind4_address->sin_port = htons (port);
-
- if (plugin->bind_hostname!=NULL)
- {
- if (inet_pton(AF_INET,plugin->bind_hostname,
&plugin->bind4_address->sin_addr)<=0)
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
- component_name,
- _("Misconfigured address to bind to in
configuration!\n"));
- GNUNET_free(plugin->bind4_address);
- GNUNET_free(plugin->bind_hostname);
- plugin->bind_hostname = NULL;
- plugin->bind4_address = NULL;
- }
- }
+ if (inet_pton
+ (AF_INET, plugin->bind_hostname,
+ &plugin->bind4_address->sin_addr) <= 0)
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
+ component_name,
+ _
+ ("Misconfigured address to bind to in
configuration!\n"));
+ GNUNET_free (plugin->bind4_address);
+ GNUNET_free (plugin->bind_hostname);
+ plugin->bind_hostname = NULL;
+ plugin->bind4_address = NULL;
+ }
}
-
+ }
+
/* Reading ipv4 addresse to bind to from config file */
- if ( (plugin->use_ipv6==GNUNET_YES) &&
- (GNUNET_CONFIGURATION_have_value (env->cfg,
- component_name, "BINDTO6")))
+ if ((plugin->use_ipv6 == GNUNET_YES) &&
+ (GNUNET_CONFIGURATION_have_value (env->cfg, component_name, "BINDTO6")))
+ {
+ if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (env->cfg,
+ component_name,
+ "BINDTO6",
+
&plugin->bind_hostname))
{
- if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (env->cfg,
- component_name,
- "BINDTO6",
-
&plugin->bind_hostname))
- {
- plugin->bind6_address = GNUNET_malloc(sizeof(struct sockaddr_in6));
- plugin->bind6_address->sin6_family = AF_INET6;
- plugin->bind6_address->sin6_port = htons (port);
- if (plugin->bind_hostname!=NULL)
- {
- if (inet_pton(AF_INET6,plugin->bind_hostname,
&plugin->bind6_address->sin6_addr)<=0)
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
- component_name,
- _("Misconfigured address to bind to in
configuration!\n"));
- GNUNET_free(plugin->bind6_address);
- GNUNET_free(plugin->bind_hostname);
- plugin->bind_hostname = NULL;
- plugin->bind6_address = NULL;
- }
- }
- }
+ plugin->bind6_address = GNUNET_malloc (sizeof (struct sockaddr_in6));
+ plugin->bind6_address->sin6_family = AF_INET6;
+ plugin->bind6_address->sin6_port = htons (port);
+ if (plugin->bind_hostname != NULL)
+ {
+ if (inet_pton
+ (AF_INET6, plugin->bind_hostname,
+ &plugin->bind6_address->sin6_addr) <= 0)
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
+ component_name,
+ _
+ ("Misconfigured address to bind to in
configuration!\n"));
+ GNUNET_free (plugin->bind6_address);
+ GNUNET_free (plugin->bind_hostname);
+ plugin->bind_hostname = NULL;
+ plugin->bind6_address = NULL;
+ }
+ }
}
-
+ }
+
#if BUILD_HTTPS
/* Reading HTTPS crypto related configuration */
- /* Get crypto init string from config */
- if ( (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (env->cfg,
- "transport-https",
- "CRYPTO_INIT",
- &plugin->crypto_init)) ||
- (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (env->cfg,
- "transport-https",
- "KEY_FILE",
- &key_file)) ||
- (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (env->cfg,
- "transport-https",
- "CERT_FILE",
- &cert_file)) )
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
- "https",
- _("Required configuration options missing in section
`%s'\n"),
- "transport-https");
- GNUNET_free (component_name);
- GNUNET_free_non_null (key_file);
- GNUNET_free_non_null (cert_file);
- LIBGNUNET_PLUGIN_TRANSPORT_DONE (api);
- return NULL;
- }
-
+ /* Get crypto init string from config */
+ if ((GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (env->cfg,
+ "transport-https",
+ "CRYPTO_INIT",
+ &plugin->crypto_init)) ||
+ (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_filename (env->cfg,
+ "transport-https",
+ "KEY_FILE",
+ &key_file)) ||
+ (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_filename (env->cfg,
+ "transport-https",
+ "CERT_FILE", &cert_file)))
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
+ "https",
+ _
+ ("Required configuration options missing in section
`%s'\n"),
+ "transport-https");
+ GNUNET_free (component_name);
+ GNUNET_free_non_null (key_file);
+ GNUNET_free_non_null (cert_file);
+ LIBGNUNET_PLUGIN_TRANSPORT_DONE (api);
+ return NULL;
+ }
+
/* read key & certificates from file */
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Loading TLS certificate `%s' `%s'\n",
- key_file, cert_file);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Loading TLS certificate `%s' `%s'\n", key_file, cert_file);
plugin->key = load_certificate (key_file);
plugin->cert = load_certificate (cert_file);
- if ( (plugin->key==NULL) || (plugin->cert==NULL) )
- {
- struct GNUNET_OS_Process *certcreation;
+ if ((plugin->key == NULL) || (plugin->cert == NULL))
+ {
+ struct GNUNET_OS_Process *certcreation;
- GNUNET_free_non_null (plugin->key);
- plugin->key = NULL;
- GNUNET_free_non_null (plugin->cert);
- plugin->cert = NULL;
+ GNUNET_free_non_null (plugin->key);
+ plugin->key = NULL;
+ GNUNET_free_non_null (plugin->cert);
+ plugin->cert = NULL;
#if DEBUG_HTTP
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "No usable TLS certificate found, creating certificate\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "No usable TLS certificate found, creating certificate\n");
#endif
- errno = 0;
- certcreation = GNUNET_OS_start_process (NULL, NULL,
-
"gnunet-transport-certificate-creation",
-
"gnunet-transport-certificate-creation",
- key_file, cert_file,
- NULL);
- if (certcreation == NULL)
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
- "https",
- _("Could not create a new TLS certificate, program
`gnunet-transport-certificate-creation' could not be started!\n"));
- GNUNET_free (key_file);
- GNUNET_free (cert_file);
- GNUNET_free (component_name);
- LIBGNUNET_PLUGIN_TRANSPORT_DONE (api);
- return NULL;
- }
- GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (certcreation));
- GNUNET_OS_process_close (certcreation);
- plugin->key = load_certificate (key_file);
- plugin->cert = load_certificate (cert_file);
- }
- if ( (plugin->key==NULL) || (plugin->cert==NULL) )
+ errno = 0;
+ certcreation = GNUNET_OS_start_process (NULL, NULL,
+
"gnunet-transport-certificate-creation",
+
"gnunet-transport-certificate-creation",
+ key_file, cert_file, NULL);
+ if (certcreation == NULL)
{
GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
- "https",
- _("No usable TLS certificate found and creating one
failed!\n"),
- "transport-https");
+ "https",
+ _
+ ("Could not create a new TLS certificate, program
`gnunet-transport-certificate-creation' could not be started!\n"));
GNUNET_free (key_file);
GNUNET_free (cert_file);
- GNUNET_free (component_name);
+ GNUNET_free (component_name);
LIBGNUNET_PLUGIN_TRANSPORT_DONE (api);
return NULL;
- }
+ }
+ GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (certcreation));
+ GNUNET_OS_process_close (certcreation);
+ plugin->key = load_certificate (key_file);
+ plugin->cert = load_certificate (cert_file);
+ }
+ if ((plugin->key == NULL) || (plugin->cert == NULL))
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
+ "https",
+ _
+ ("No usable TLS certificate found and creating one
failed!\n"),
+ "transport-https");
+ GNUNET_free (key_file);
+ GNUNET_free (cert_file);
+ GNUNET_free (component_name);
+ LIBGNUNET_PLUGIN_TRANSPORT_DONE (api);
+ return NULL;
+ }
GNUNET_free (key_file);
GNUNET_free (cert_file);
#if DEBUG_HTTP
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "TLS certificate loaded\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "TLS certificate loaded\n");
#endif
#endif
@@ -3538,171 +3536,199 @@
plugin->port_inbound = port;
gn_timeout = GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT;
unsigned int timeout = (gn_timeout.rel_value) / 1000;
- if ( (plugin->http_server_daemon_v6 == NULL) &&
- (plugin->use_ipv6 == GNUNET_YES) &&
- (port != 0) )
- {
- struct sockaddr * tmp = (struct sockaddr *) plugin->bind6_address;
- plugin->http_server_daemon_v6 = MHD_start_daemon (
+
+ if ((plugin->http_server_daemon_v6 == NULL) &&
+ (plugin->use_ipv6 == GNUNET_YES) && (port != 0))
+ {
+ struct sockaddr *tmp = (struct sockaddr *) plugin->bind6_address;
+
+ plugin->http_server_daemon_v6 = MHD_start_daemon (
#if DEBUG_MHD
- MHD_USE_DEBUG |
+ MHD_USE_DEBUG |
#endif
#if BUILD_HTTPS
- MHD_USE_SSL |
+ MHD_USE_SSL |
#endif
- MHD_USE_IPv6,
- port,
- &mhd_accept_cb, plugin,
- &mhd_access_cb, plugin,
- MHD_OPTION_SOCK_ADDR,
tmp,
-
MHD_OPTION_CONNECTION_LIMIT, (unsigned int) plugin->max_connect_per_transport,
+ MHD_USE_IPv6,
+ port,
+ &mhd_accept_cb, plugin,
+ &mhd_access_cb, plugin,
+ MHD_OPTION_SOCK_ADDR,
+ tmp,
+
MHD_OPTION_CONNECTION_LIMIT,
+ (unsigned int)
+
plugin->max_connect_per_transport,
#if BUILD_HTTPS
-
MHD_OPTION_HTTPS_PRIORITIES, plugin->crypto_init,
-
MHD_OPTION_HTTPS_MEM_KEY, plugin->key,
-
MHD_OPTION_HTTPS_MEM_CERT, plugin->cert,
+
MHD_OPTION_HTTPS_PRIORITIES,
+ plugin->crypto_init,
+
MHD_OPTION_HTTPS_MEM_KEY,
+ plugin->key,
+
MHD_OPTION_HTTPS_MEM_CERT,
+ plugin->cert,
#endif
-
MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) timeout,
-
MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t) (2 *
GNUNET_SERVER_MAX_MESSAGE_SIZE),
-
MHD_OPTION_NOTIFY_COMPLETED, &mhd_termination_cb, plugin,
-
MHD_OPTION_EXTERNAL_LOGGER, mhd_logger, plugin->mhd_log,
- MHD_OPTION_END);
- }
- if ( (plugin->http_server_daemon_v4 == NULL) &&
- (plugin->use_ipv4 == GNUNET_YES) &&
- (port != 0) )
- {
- plugin->http_server_daemon_v4 = MHD_start_daemon (
+
MHD_OPTION_CONNECTION_TIMEOUT,
+ (unsigned int) timeout,
+
MHD_OPTION_CONNECTION_MEMORY_LIMIT,
+ (size_t) (2 *
+
GNUNET_SERVER_MAX_MESSAGE_SIZE),
+
MHD_OPTION_NOTIFY_COMPLETED,
+ &mhd_termination_cb,
+ plugin,
+
MHD_OPTION_EXTERNAL_LOGGER,
+ mhd_logger,
+ plugin->mhd_log,
+ MHD_OPTION_END);
+ }
+ if ((plugin->http_server_daemon_v4 == NULL) &&
+ (plugin->use_ipv4 == GNUNET_YES) && (port != 0))
+ {
+ plugin->http_server_daemon_v4 = MHD_start_daemon (
#if DEBUG_MHD
- MHD_USE_DEBUG |
+ MHD_USE_DEBUG |
#endif
#if BUILD_HTTPS
- MHD_USE_SSL |
+ MHD_USE_SSL |
#endif
- MHD_NO_FLAG,
- port,
- &mhd_accept_cb, plugin ,
- &mhd_access_cb, plugin,
- MHD_OPTION_SOCK_ADDR,
(struct sockaddr_in *) plugin->bind4_address,
-
MHD_OPTION_CONNECTION_LIMIT, (unsigned int) plugin->max_connect_per_transport,
+ MHD_NO_FLAG,
+ port,
+ &mhd_accept_cb, plugin,
+ &mhd_access_cb, plugin,
+ MHD_OPTION_SOCK_ADDR,
+ (struct sockaddr_in *)
+ plugin->bind4_address,
+
MHD_OPTION_CONNECTION_LIMIT,
+ (unsigned int)
+
plugin->max_connect_per_transport,
#if BUILD_HTTPS
-
MHD_OPTION_HTTPS_PRIORITIES, plugin->crypto_init,
-
-
MHD_OPTION_HTTPS_MEM_KEY, plugin->key,
-
MHD_OPTION_HTTPS_MEM_CERT, plugin->cert,
+
MHD_OPTION_HTTPS_PRIORITIES,
+ plugin->crypto_init,
+
MHD_OPTION_HTTPS_MEM_KEY,
+ plugin->key,
+
MHD_OPTION_HTTPS_MEM_CERT,
+ plugin->cert,
#endif
-
MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) timeout,
-
MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t) (2 *
GNUNET_SERVER_MAX_MESSAGE_SIZE),
-
MHD_OPTION_NOTIFY_COMPLETED, &mhd_termination_cb, plugin,
-
MHD_OPTION_EXTERNAL_LOGGER, mhd_logger, plugin->mhd_log,
- MHD_OPTION_END);
- }
+
MHD_OPTION_CONNECTION_TIMEOUT,
+ (unsigned int) timeout,
+
MHD_OPTION_CONNECTION_MEMORY_LIMIT,
+ (size_t) (2 *
+
GNUNET_SERVER_MAX_MESSAGE_SIZE),
+
MHD_OPTION_NOTIFY_COMPLETED,
+ &mhd_termination_cb,
+ plugin,
+
MHD_OPTION_EXTERNAL_LOGGER,
+ mhd_logger,
+ plugin->mhd_log,
+ MHD_OPTION_END);
+ }
if (plugin->http_server_daemon_v4 != NULL)
- plugin->http_server_task_v4 = http_server_daemon_prepare (plugin,
plugin->http_server_daemon_v4);
+ plugin->http_server_task_v4 =
+ http_server_daemon_prepare (plugin, plugin->http_server_daemon_v4);
if (plugin->http_server_daemon_v6 != NULL)
- plugin->http_server_task_v6 = http_server_daemon_prepare (plugin,
plugin->http_server_daemon_v6);
-
-
+ plugin->http_server_task_v6 =
+ http_server_daemon_prepare (plugin, plugin->http_server_daemon_v6);
+
+
if (plugin->http_server_task_v4 != GNUNET_SCHEDULER_NO_TASK)
- {
+ {
#if DEBUG_HTTP
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Starting MHD with IPv4 bound to %s with port %u\n",
- (plugin->bind_hostname!=NULL) ? plugin->bind_hostname :
"every address",port);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Starting MHD with IPv4 bound to %s with port %u\n",
+ (plugin->bind_hostname !=
+ NULL) ? plugin->bind_hostname : "every address", port);
#endif
- }
- else if ( (plugin->http_server_task_v6 != GNUNET_SCHEDULER_NO_TASK) &&
- (plugin->http_server_task_v4 != GNUNET_SCHEDULER_NO_TASK) )
- {
+ }
+ else if ((plugin->http_server_task_v6 != GNUNET_SCHEDULER_NO_TASK) &&
+ (plugin->http_server_task_v4 != GNUNET_SCHEDULER_NO_TASK))
+ {
#if DEBUG_HTTP
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Starting MHD with IPv6 bound to %s with port %u\n",
- (plugin->bind_hostname!=NULL) ? plugin->bind_hostname :
"every address", port);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Starting MHD with IPv6 bound to %s with port %u\n",
+ (plugin->bind_hostname !=
+ NULL) ? plugin->bind_hostname : "every address", port);
#endif
- }
- else if ( (plugin->http_server_task_v6 != GNUNET_SCHEDULER_NO_TASK) &&
- (plugin->http_server_task_v4 == GNUNET_SCHEDULER_NO_TASK) )
- {
+ }
+ else if ((plugin->http_server_task_v6 != GNUNET_SCHEDULER_NO_TASK) &&
+ (plugin->http_server_task_v4 == GNUNET_SCHEDULER_NO_TASK))
+ {
#if DEBUG_HTTP
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Starting MHD with IPv4 and IPv6 bound to %s with port %u\n",
- (plugin->bind_hostname!=NULL) ? plugin->bind_hostname :
"every address",
- port);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Starting MHD with IPv4 and IPv6 bound to %s with port %u\n",
+ (plugin->bind_hostname !=
+ NULL) ? plugin->bind_hostname : "every address", port);
#endif
- }
+ }
else
- {
- char * tmp = NULL;
- if ((plugin->use_ipv6 == GNUNET_YES) && (plugin->use_ipv4 == GNUNET_YES))
- GNUNET_asprintf(&tmp,"with IPv4 and IPv6 enabled");
- if ((plugin->use_ipv6 == GNUNET_NO) && (plugin->use_ipv4 == GNUNET_YES))
- GNUNET_asprintf(&tmp,"with IPv4 enabled");
- if ((plugin->use_ipv6 == GNUNET_YES) && (plugin->use_ipv4 == GNUNET_NO))
- GNUNET_asprintf(&tmp,"with IPv6 enabled");
- if ((plugin->use_ipv6 == GNUNET_NO) && (plugin->use_ipv4 == GNUNET_NO))
- GNUNET_asprintf(&tmp,"with NO IP PROTOCOL enabled");
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("HTTP Server with %s could not be started on port %u! %s
plugin failed!\n"),
- tmp, port, PROTOCOL_PREFIX);
- GNUNET_free (tmp);
- GNUNET_free (component_name);
- LIBGNUNET_PLUGIN_TRANSPORT_DONE (api);
- return NULL;
- }
-
+ {
+ char *tmp = NULL;
+
+ if ((plugin->use_ipv6 == GNUNET_YES) && (plugin->use_ipv4 == GNUNET_YES))
+ GNUNET_asprintf (&tmp, "with IPv4 and IPv6 enabled");
+ if ((plugin->use_ipv6 == GNUNET_NO) && (plugin->use_ipv4 == GNUNET_YES))
+ GNUNET_asprintf (&tmp, "with IPv4 enabled");
+ if ((plugin->use_ipv6 == GNUNET_YES) && (plugin->use_ipv4 == GNUNET_NO))
+ GNUNET_asprintf (&tmp, "with IPv6 enabled");
+ if ((plugin->use_ipv6 == GNUNET_NO) && (plugin->use_ipv4 == GNUNET_NO))
+ GNUNET_asprintf (&tmp, "with NO IP PROTOCOL enabled");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _
+ ("HTTP Server with %s could not be started on port %u! %s
plugin failed!\n"),
+ tmp, port, PROTOCOL_PREFIX);
+ GNUNET_free (tmp);
+ GNUNET_free (component_name);
+ LIBGNUNET_PLUGIN_TRANSPORT_DONE (api);
+ return NULL;
+ }
+
/* Initializing cURL */
- curl_global_init(CURL_GLOBAL_ALL);
- plugin->multi_handle = curl_multi_init();
-
- if ( NULL == plugin->multi_handle )
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
- component_name,
- _("Could not initialize curl multi handle, failed to
start %s plugin!\n"),
- PROTOCOL_PREFIX);
- GNUNET_free(component_name);
- LIBGNUNET_PLUGIN_TRANSPORT_DONE (api);
- return NULL;
- }
-
+ curl_global_init (CURL_GLOBAL_ALL);
+ plugin->multi_handle = curl_multi_init ();
+
+ if (NULL == plugin->multi_handle)
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
+ component_name,
+ _
+ ("Could not initialize curl multi handle, failed to start
%s plugin!\n"),
+ PROTOCOL_PREFIX);
+ GNUNET_free (component_name);
+ LIBGNUNET_PLUGIN_TRANSPORT_DONE (api);
+ return NULL;
+ }
+
ret = GNUNET_SERVICE_get_server_addresses (component_name,
- env->cfg,
- &addrs,
- &addrlens);
+ env->cfg, &addrs, &addrlens);
if (ret != GNUNET_SYSERR)
{
plugin->nat = GNUNET_NAT_register (env->cfg,
- GNUNET_YES,
- port,
- (unsigned int) ret,
- (const struct sockaddr **) addrs,
- addrlens,
- &tcp_nat_port_map_callback,
- &try_connection_reversal,
- plugin);
- while (ret > 0)
- {
- ret--;
- GNUNET_assert (addrs[ret] != NULL);
- GNUNET_free (addrs[ret]);
- }
- GNUNET_free_non_null (addrs);
- GNUNET_free_non_null (addrlens);
+ GNUNET_YES,
+ port,
+ (unsigned int) ret,
+ (const struct sockaddr **) addrs,
+ addrlens,
+ &tcp_nat_port_map_callback,
+ &try_connection_reversal, plugin);
+ while (ret > 0)
+ {
+ ret--;
+ GNUNET_assert (addrs[ret] != NULL);
+ GNUNET_free (addrs[ret]);
+ }
+ GNUNET_free_non_null (addrs);
+ GNUNET_free_non_null (addrlens);
}
else
{
plugin->nat = GNUNET_NAT_register (env->cfg,
- GNUNET_YES,
- 0,
- 0, NULL, NULL,
- NULL,
- &try_connection_reversal,
- plugin);
+ GNUNET_YES,
+ 0,
+ 0, NULL, NULL,
+ NULL, &try_connection_reversal, plugin);
}
plugin->peers = GNUNET_CONTAINER_multihashmap_create (10);
-
- GNUNET_free(component_name);
+
+ GNUNET_free (component_name);
//GNUNET_SCHEDULER_add_now(address_notification, plugin);
return api;
}
Modified: gnunet/src/transport/plugin_transport_smtp.c
===================================================================
--- gnunet/src/transport/plugin_transport_smtp.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/transport/plugin_transport_smtp.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -146,7 +146,7 @@
#define FILLCHAR '='
static char *cvt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- "abcdefghijklmnopqrstuvwxyz" "0123456789+/";
+ "abcdefghijklmnopqrstuvwxyz" "0123456789+/";
/**
* Encode into Base64.
@@ -179,41 +179,41 @@
opt[1] = '\n';
ret += 2;
for (i = 0; i < len; ++i)
+ {
+ c = (data[i] >> 2) & 0x3f;
+ opt[ret++] = cvt[(int) c];
+ CHECKLINE;
+ c = (data[i] << 4) & 0x3f;
+ if (++i < len)
+ c |= (data[i] >> 4) & 0x0f;
+ opt[ret++] = cvt[(int) c];
+ CHECKLINE;
+ if (i < len)
{
- c = (data[i] >> 2) & 0x3f;
+ c = (data[i] << 2) & 0x3f;
+ if (++i < len)
+ c |= (data[i] >> 6) & 0x03;
opt[ret++] = cvt[(int) c];
CHECKLINE;
- c = (data[i] << 4) & 0x3f;
- if (++i < len)
- c |= (data[i] >> 4) & 0x0f;
+ }
+ else
+ {
+ ++i;
+ opt[ret++] = FILLCHAR;
+ CHECKLINE;
+ }
+ if (i < len)
+ {
+ c = data[i] & 0x3f;
opt[ret++] = cvt[(int) c];
CHECKLINE;
- if (i < len)
- {
- c = (data[i] << 2) & 0x3f;
- if (++i < len)
- c |= (data[i] >> 6) & 0x03;
- opt[ret++] = cvt[(int) c];
- CHECKLINE;
- }
- else
- {
- ++i;
- opt[ret++] = FILLCHAR;
- CHECKLINE;
- }
- if (i < len)
- {
- c = data[i] & 0x3f;
- opt[ret++] = cvt[(int) c];
- CHECKLINE;
- }
- else
- {
- opt[ret++] = FILLCHAR;
- CHECKLINE;
- }
}
+ else
+ {
+ opt[ret++] = FILLCHAR;
+ CHECKLINE;
+ }
+ }
opt[ret++] = FILLCHAR;
return ret;
}
@@ -252,38 +252,38 @@
"base64_decode decoding len=%d\n", len);
#endif
for (i = 0; i < len; ++i)
+ {
+ CHECK_CRLF;
+ if (data[i] == FILLCHAR)
+ break;
+ c = (char) cvtfind (data[i]);
+ ++i;
+ CHECK_CRLF;
+ c1 = (char) cvtfind (data[i]);
+ c = (c << 2) | ((c1 >> 4) & 0x3);
+ (*output)[ret++] = c;
+ if (++i < len)
{
CHECK_CRLF;
- if (data[i] == FILLCHAR)
+ c = data[i];
+ if (FILLCHAR == c)
break;
- c = (char) cvtfind (data[i]);
- ++i;
+ c = (char) cvtfind (c);
+ c1 = ((c1 << 4) & 0xf0) | ((c >> 2) & 0xf);
+ (*output)[ret++] = c1;
+ }
+ if (++i < len)
+ {
CHECK_CRLF;
- c1 = (char) cvtfind (data[i]);
- c = (c << 2) | ((c1 >> 4) & 0x3);
- (*output)[ret++] = c;
- if (++i < len)
- {
- CHECK_CRLF;
- c = data[i];
- if (FILLCHAR == c)
- break;
- c = (char) cvtfind (c);
- c1 = ((c1 << 4) & 0xf0) | ((c >> 2) & 0xf);
- (*output)[ret++] = c1;
- }
- if (++i < len)
- {
- CHECK_CRLF;
- c1 = data[i];
- if (FILLCHAR == c1)
- break;
+ c1 = data[i];
+ if (FILLCHAR == c1)
+ break;
- c1 = (char) cvtfind (c1);
- c = ((c << 6) & 0xc0) | c1;
- (*output)[ret++] = c;
- }
+ c1 = (char) cvtfind (c1);
+ c = ((c << 6) & 0xc0) | c1;
+ (*output)[ret++] = c;
}
+ }
END:
return ret;
}
@@ -323,83 +323,83 @@
while (smtp_shutdown == GNUNET_NO)
+ {
+ fd = OPEN (pipename, O_RDONLY | O_ASYNC);
+ if (fd == -1)
{
- fd = OPEN (pipename, O_RDONLY | O_ASYNC);
- if (fd == -1)
- {
- if (smtp_shutdown == GNUNET_NO)
- GNUNET_thread_sleep (5 * GNUNET_CRON_SECONDS);
- continue;
- }
- fdes = fdopen (fd, "r");
- while (smtp_shutdown == GNUNET_NO)
- {
- /* skip until end of header */
- do
- {
- READLINE (line, linesize);
- }
- while ((line[0] != '\r') && (line[0] != '\n')); /* expect
newline */
- READLINE (line, linesize); /* read base64 encoded message;
decode, process */
- pos = 0;
- while (1)
- {
- pos = strlen (line) - 1; /* ignore new line */
- READLINE (&line[pos], linesize - pos); /* read base64 encoded
message; decode, process */
- if ((line[pos] == '\r') || (line[pos] == '\n'))
- break; /* empty line => end of message! */
- }
- size = base64_decode (line, pos, &out);
- if (size < sizeof (SMTPMessage))
- {
- GNUNET_GE_BREAK (ectx, 0);
- GNUNET_free (out);
- goto END;
- }
+ if (smtp_shutdown == GNUNET_NO)
+ GNUNET_thread_sleep (5 * GNUNET_CRON_SECONDS);
+ continue;
+ }
+ fdes = fdopen (fd, "r");
+ while (smtp_shutdown == GNUNET_NO)
+ {
+ /* skip until end of header */
+ do
+ {
+ READLINE (line, linesize);
+ }
+ while ((line[0] != '\r') && (line[0] != '\n')); /* expect newline */
+ READLINE (line, linesize); /* read base64 encoded message;
decode, process */
+ pos = 0;
+ while (1)
+ {
+ pos = strlen (line) - 1; /* ignore new line */
+ READLINE (&line[pos], linesize - pos); /* read base64 encoded
message; decode, process */
+ if ((line[pos] == '\r') || (line[pos] == '\n'))
+ break; /* empty line => end of message! */
+ }
+ size = base64_decode (line, pos, &out);
+ if (size < sizeof (SMTPMessage))
+ {
+ GNUNET_GE_BREAK (ectx, 0);
+ GNUNET_free (out);
+ goto END;
+ }
- mp = (SMTPMessage *) & out[size - sizeof (SMTPMessage)];
- if (ntohs (mp->header.size) != size)
- {
- GNUNET_GE_LOG (ectx,
- GNUNET_GE_WARNING | GNUNET_GE_BULK |
- GNUNET_GE_USER,
- _
- ("Received malformed message via %s. Ignored.\n"),
- "SMTP");
+ mp = (SMTPMessage *) &out[size - sizeof (SMTPMessage)];
+ if (ntohs (mp->header.size) != size)
+ {
+ GNUNET_GE_LOG (ectx,
+ GNUNET_GE_WARNING | GNUNET_GE_BULK |
+ GNUNET_GE_USER,
+ _
+ ("Received malformed message via %s. Ignored.\n"),
+ "SMTP");
#if DEBUG_SMTP
- GNUNET_GE_LOG (ectx,
- GNUNET_GE_DEBUG | GNUNET_GE_REQUEST |
- GNUNET_GE_USER,
- "Size returned by base64=%d, in the msg=%d.\n",
- size, ntohl (mp->size));
+ GNUNET_GE_LOG (ectx,
+ GNUNET_GE_DEBUG | GNUNET_GE_REQUEST |
+ GNUNET_GE_USER,
+ "Size returned by base64=%d, in the msg=%d.\n",
+ size, ntohl (mp->size));
#endif
- GNUNET_free (out);
- goto END;
- }
- if (stats != NULL)
- stats->change (stat_bytesReceived, size);
- coreMP = GNUNET_malloc (sizeof (GNUNET_TransportPacket));
- coreMP->msg = out;
- coreMP->size = size - sizeof (SMTPMessage);
- coreMP->tsession = NULL;
- coreMP->sender = mp->sender;
+ GNUNET_free (out);
+ goto END;
+ }
+ if (stats != NULL)
+ stats->change (stat_bytesReceived, size);
+ coreMP = GNUNET_malloc (sizeof (GNUNET_TransportPacket));
+ coreMP->msg = out;
+ coreMP->size = size - sizeof (SMTPMessage);
+ coreMP->tsession = NULL;
+ coreMP->sender = mp->sender;
#if DEBUG_SMTP
- GNUNET_GE_LOG (ectx,
- GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,
- "SMTP message passed to the core.\n");
-#endif
-
- coreAPI->receive (coreMP);
- }
- END:
-#if DEBUG_SMTP
GNUNET_GE_LOG (ectx,
GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,
- "SMTP message processed.\n");
+ "SMTP message passed to the core.\n");
#endif
- if (fdes != NULL)
- fclose (fdes);
+
+ coreAPI->receive (coreMP);
}
+END:
+#if DEBUG_SMTP
+ GNUNET_GE_LOG (ectx,
+ GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,
+ "SMTP message processed.\n");
+#endif
+ if (fdes != NULL)
+ fclose (fdes);
+ }
GNUNET_free (line);
return NULL;
}
@@ -425,10 +425,10 @@
sizeof (GNUNET_MessageHello) + ntohs (hello->senderAddressSize)) ||
(maddr->senderAddress[ntohs (hello->senderAddressSize) - 1 -
FILTER_STRING_SIZE] != '\0'))
- {
- GNUNET_GE_BREAK (ectx, 0);
- return GNUNET_SYSERR; /* obviously invalid */
- }
+ {
+ GNUNET_GE_BREAK (ectx, 0);
+ return GNUNET_SYSERR; /* obviously invalid */
+ }
if (NULL == strstr (maddr->filter, ": "))
return GNUNET_SYSERR;
return GNUNET_OK;
@@ -453,27 +453,26 @@
"SMTP", "FILTER",
"X-mailer: GNUnet", &filter);
if (NULL == strstr (filter, ": "))
- {
- GNUNET_GE_LOG (ectx,
- GNUNET_GE_WARNING | GNUNET_GE_BULK | GNUNET_GE_USER,
- _("SMTP filter string to invalid, lacks ': '\n"));
- GNUNET_free (filter);
- return NULL;
- }
+ {
+ GNUNET_GE_LOG (ectx,
+ GNUNET_GE_WARNING | GNUNET_GE_BULK | GNUNET_GE_USER,
+ _("SMTP filter string to invalid, lacks ': '\n"));
+ GNUNET_free (filter);
+ return NULL;
+ }
if (strlen (filter) > FILTER_STRING_SIZE)
- {
- filter[FILTER_STRING_SIZE] = '\0';
- GNUNET_GE_LOG (ectx,
- GNUNET_GE_WARNING | GNUNET_GE_BULK | GNUNET_GE_USER,
- _("SMTP filter string to long, capped to `%s'\n"),
- filter);
- }
+ {
+ filter[FILTER_STRING_SIZE] = '\0';
+ GNUNET_GE_LOG (ectx,
+ GNUNET_GE_WARNING | GNUNET_GE_BULK | GNUNET_GE_USER,
+ _("SMTP filter string to long, capped to `%s'\n"), filter);
+ }
i = (strlen (email) + 8) & (~7); /* make multiple of 8 */
msg =
- GNUNET_malloc (sizeof (GNUNET_MessageHello) + sizeof (EmailAddress) + i);
+ GNUNET_malloc (sizeof (GNUNET_MessageHello) + sizeof (EmailAddress) + i);
memset (msg, 0, sizeof (GNUNET_MessageHello) + sizeof (EmailAddress) + i);
- haddr = (EmailAddress *) & msg[1];
+ haddr = (EmailAddress *) &msg[1];
memset (&haddr->filter[0], 0, FILTER_STRING_SIZE);
strcpy (&haddr->filter[0], filter);
memcpy (&haddr->senderAddress[0], email, strlen (email) + 1);
@@ -501,10 +500,10 @@
*buf = NULL;
if (len == NULL)
- {
- gmc->pos = 0;
- return NULL;
- }
+ {
+ gmc->pos = 0;
+ return NULL;
+ }
if (gmc->pos == gmc->esize)
return NULL; /* done */
*len = gmc->esize;
@@ -535,6 +534,7 @@
smtp_session_t session;
smtp_message_t message;
smtp_recipient_t recipient;
+
#define EBUF_LEN 128
char ebuf[EBUF_LEN];
GNUNET_CronTime now;
@@ -542,10 +542,10 @@
if (smtp_shutdown == GNUNET_YES)
return GNUNET_SYSERR;
if ((size == 0) || (size > smtpAPI.mtu))
- {
- GNUNET_GE_BREAK (ectx, 0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_GE_BREAK (ectx, 0);
+ return GNUNET_SYSERR;
+ }
now = GNUNET_get_time ();
if ((important != GNUNET_YES) &&
((now - last_transmission) * rate_limit) < GNUNET_CRON_HOURS)
@@ -558,42 +558,42 @@
GNUNET_mutex_lock (lock);
session = smtp_create_session ();
if (session == NULL)
- {
- GNUNET_GE_LOG (ectx,
- GNUNET_GE_ERROR | GNUNET_GE_ADMIN | GNUNET_GE_USER |
- GNUNET_GE_IMMEDIATE,
- _("SMTP: `%s' failed: %s.\n"),
- "smtp_create_session",
- smtp_strerror (smtp_errno (), ebuf, EBUF_LEN));
- GNUNET_mutex_unlock (lock);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_GE_LOG (ectx,
+ GNUNET_GE_ERROR | GNUNET_GE_ADMIN | GNUNET_GE_USER |
+ GNUNET_GE_IMMEDIATE,
+ _("SMTP: `%s' failed: %s.\n"),
+ "smtp_create_session",
+ smtp_strerror (smtp_errno (), ebuf, EBUF_LEN));
+ GNUNET_mutex_unlock (lock);
+ return GNUNET_SYSERR;
+ }
if (0 == smtp_set_server (session, smtp_server_name))
- {
- GNUNET_GE_LOG (ectx,
- GNUNET_GE_ERROR | GNUNET_GE_ADMIN | GNUNET_GE_USER |
- GNUNET_GE_IMMEDIATE,
- _("SMTP: `%s' failed: %s.\n"),
- "smtp_set_server",
- smtp_strerror (smtp_errno (), ebuf, EBUF_LEN));
- smtp_destroy_session (session);
- GNUNET_mutex_unlock (lock);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_GE_LOG (ectx,
+ GNUNET_GE_ERROR | GNUNET_GE_ADMIN | GNUNET_GE_USER |
+ GNUNET_GE_IMMEDIATE,
+ _("SMTP: `%s' failed: %s.\n"),
+ "smtp_set_server",
+ smtp_strerror (smtp_errno (), ebuf, EBUF_LEN));
+ smtp_destroy_session (session);
+ GNUNET_mutex_unlock (lock);
+ return GNUNET_SYSERR;
+ }
haddr = (const EmailAddress *) &hello[1];
message = smtp_add_message (session);
if (message == NULL)
- {
- GNUNET_GE_LOG (ectx,
- GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER |
- GNUNET_GE_BULK,
- _("SMTP: `%s' failed: %s.\n"),
- "smtp_add_message",
- smtp_strerror (smtp_errno (), ebuf, EBUF_LEN));
- smtp_destroy_session (session);
- GNUNET_mutex_unlock (lock);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_GE_LOG (ectx,
+ GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER |
+ GNUNET_GE_BULK,
+ _("SMTP: `%s' failed: %s.\n"),
+ "smtp_add_message",
+ smtp_strerror (smtp_errno (), ebuf, EBUF_LEN));
+ smtp_destroy_session (session);
+ GNUNET_mutex_unlock (lock);
+ return GNUNET_SYSERR;
+ }
smtp_set_header (message, "To", NULL, haddr->senderAddress);
smtp_set_header (message, "From", NULL, email);
@@ -603,84 +603,82 @@
fvalue[0] = '\0';
fvalue += 2;
if (0 == smtp_set_header (message, filter, fvalue))
- {
- GNUNET_GE_LOG (ectx,
- GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER |
- GNUNET_GE_BULK,
- _("SMTP: `%s' failed: %s.\n"),
- "smtp_set_header",
- smtp_strerror (smtp_errno (), ebuf, EBUF_LEN));
- smtp_destroy_session (session);
- GNUNET_mutex_unlock (lock);
- GNUNET_free (filter);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_GE_LOG (ectx,
+ GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER |
+ GNUNET_GE_BULK,
+ _("SMTP: `%s' failed: %s.\n"),
+ "smtp_set_header",
+ smtp_strerror (smtp_errno (), ebuf, EBUF_LEN));
+ smtp_destroy_session (session);
+ GNUNET_mutex_unlock (lock);
+ GNUNET_free (filter);
+ return GNUNET_SYSERR;
+ }
GNUNET_free (filter);
m = GNUNET_malloc (size + sizeof (SMTPMessage));
memcpy (m, msg, size);
- mp = (SMTPMessage *) & m[size];
+ mp = (SMTPMessage *) &m[size];
mp->header.size = htons (size + sizeof (SMTPMessage));
mp->header.type = htons (0);
mp->sender = *coreAPI->my_identity;
gm_cls.ebody = NULL;
gm_cls.pos = 0;
- gm_cls.esize =
- base64_encode (m, size + sizeof (SMTPMessage), &gm_cls.ebody);
+ gm_cls.esize = base64_encode (m, size + sizeof (SMTPMessage), &gm_cls.ebody);
GNUNET_free (m);
if (0 == smtp_size_set_estimate (message, gm_cls.esize))
- {
- GNUNET_GE_LOG (ectx,
- GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER |
- GNUNET_GE_BULK,
- _("SMTP: `%s' failed: %s.\n"),
- "smtp_size_set_estimate",
- smtp_strerror (smtp_errno (), ebuf, EBUF_LEN));
- }
+ {
+ GNUNET_GE_LOG (ectx,
+ GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER |
+ GNUNET_GE_BULK,
+ _("SMTP: `%s' failed: %s.\n"),
+ "smtp_size_set_estimate",
+ smtp_strerror (smtp_errno (), ebuf, EBUF_LEN));
+ }
if (0 == smtp_set_messagecb (message, &get_message, &gm_cls))
- {
- GNUNET_GE_LOG (ectx,
- GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER |
- GNUNET_GE_BULK,
- _("SMTP: `%s' failed: %s.\n"),
- "smtp_set_messagecb",
- smtp_strerror (smtp_errno (), ebuf, EBUF_LEN));
- smtp_destroy_session (session);
- GNUNET_mutex_unlock (lock);
- GNUNET_free (gm_cls.ebody);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_GE_LOG (ectx,
+ GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER |
+ GNUNET_GE_BULK,
+ _("SMTP: `%s' failed: %s.\n"),
+ "smtp_set_messagecb",
+ smtp_strerror (smtp_errno (), ebuf, EBUF_LEN));
+ smtp_destroy_session (session);
+ GNUNET_mutex_unlock (lock);
+ GNUNET_free (gm_cls.ebody);
+ return GNUNET_SYSERR;
+ }
recipient = smtp_add_recipient (message, haddr->senderAddress);
if (recipient == NULL)
- {
- GNUNET_GE_LOG (ectx,
- GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER |
- GNUNET_GE_BULK,
- _("SMTP: `%s' failed: %s.\n"),
- "smtp_add_recipient",
- smtp_strerror (smtp_errno (), ebuf, EBUF_LEN));
- smtp_destroy_session (session);
- GNUNET_mutex_unlock (lock);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_GE_LOG (ectx,
+ GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER |
+ GNUNET_GE_BULK,
+ _("SMTP: `%s' failed: %s.\n"),
+ "smtp_add_recipient",
+ smtp_strerror (smtp_errno (), ebuf, EBUF_LEN));
+ smtp_destroy_session (session);
+ GNUNET_mutex_unlock (lock);
+ return GNUNET_SYSERR;
+ }
if (0 == smtp_start_session (session))
- {
- GNUNET_GE_LOG (ectx,
- GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER |
- GNUNET_GE_BULK,
- _("SMTP: `%s' failed: %s.\n"),
- "smtp_start_session",
- smtp_strerror (smtp_errno (), ebuf, EBUF_LEN));
- smtp_destroy_session (session);
- GNUNET_mutex_unlock (lock);
- GNUNET_free (gm_cls.ebody);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_GE_LOG (ectx,
+ GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER |
+ GNUNET_GE_BULK,
+ _("SMTP: `%s' failed: %s.\n"),
+ "smtp_start_session",
+ smtp_strerror (smtp_errno (), ebuf, EBUF_LEN));
+ smtp_destroy_session (session);
+ GNUNET_mutex_unlock (lock);
+ GNUNET_free (gm_cls.ebody);
+ return GNUNET_SYSERR;
+ }
if (stats != NULL)
stats->change (stat_bytesSent, size);
if (coreAPI->load_monitor != NULL)
GNUNET_network_monitor_notify_transmission (coreAPI->load_monitor,
- GNUNET_ND_UPLOAD,
- gm_cls.esize);
+ GNUNET_ND_UPLOAD,
gm_cls.esize);
smtp_message_reset_status (message); /* this is needed to plug a
28-byte/message memory leak in libesmtp */
smtp_destroy_session (session);
GNUNET_mutex_unlock (lock);
@@ -720,11 +718,11 @@
api_disconnect (GNUNET_TSession * tsession)
{
if (tsession != NULL)
- {
- if (tsession->internal != NULL)
- GNUNET_free (tsession->internal);
- GNUNET_free (tsession);
- }
+ {
+ if (tsession->internal != NULL)
+ GNUNET_free (tsession->internal);
+ GNUNET_free (tsession);
+ }
return GNUNET_OK;
}
@@ -737,15 +735,14 @@
{
smtp_shutdown = GNUNET_NO;
/* initialize SMTP network */
- dispatchThread =
- GNUNET_thread_create (&listenAndDistribute, NULL, 1024 * 4);
+ dispatchThread = GNUNET_thread_create (&listenAndDistribute, NULL, 1024 * 4);
if (dispatchThread == NULL)
- {
- GNUNET_GE_DIE_STRERROR (ectx,
- GNUNET_GE_ADMIN | GNUNET_GE_BULK |
- GNUNET_GE_FATAL, "pthread_create");
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_GE_DIE_STRERROR (ectx,
+ GNUNET_GE_ADMIN | GNUNET_GE_BULK |
+ GNUNET_GE_FATAL, "pthread_create");
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
}
@@ -809,13 +806,13 @@
coreAPI = core;
ectx = core->ectx;
if (!GNUNET_GC_have_configuration_value (coreAPI->cfg, "SMTP", "EMAIL"))
- {
- GNUNET_GE_LOG (ectx,
- GNUNET_GE_ERROR | GNUNET_GE_BULK | GNUNET_GE_USER,
- _
- ("No email-address specified, can not start SMTP
transport.\n"));
- return NULL;
- }
+ {
+ GNUNET_GE_LOG (ectx,
+ GNUNET_GE_ERROR | GNUNET_GE_BULK | GNUNET_GE_USER,
+ _
+ ("No email-address specified, can not start SMTP
transport.\n"));
+ return NULL;
+ }
GNUNET_GC_get_configuration_value_number (coreAPI->cfg,
"SMTP",
"MTU",
@@ -828,13 +825,13 @@
0, 0, 1024 * 1024, &rate_limit);
stats = coreAPI->service_request ("stats");
if (stats != NULL)
- {
- stat_bytesReceived
+ {
+ stat_bytesReceived
= stats->create (gettext_noop ("# bytes received via SMTP"));
- stat_bytesSent = stats->create (gettext_noop ("# bytes sent via SMTP"));
- stat_bytesDropped
+ stat_bytesSent = stats->create (gettext_noop ("# bytes sent via SMTP"));
+ stat_bytesDropped
= stats->create (gettext_noop ("# bytes dropped by SMTP (outgoing)"));
- }
+ }
GNUNET_GC_get_configuration_value_filename (coreAPI->cfg,
"SMTP",
"PIPE",
@@ -842,17 +839,17 @@
"/smtp-pipe", &pipename);
UNLINK (pipename);
if (0 != mkfifo (pipename, S_IWUSR | S_IRUSR | S_IWGRP | S_IWOTH))
- {
- GNUNET_GE_LOG_STRERROR (ectx,
- GNUNET_GE_ADMIN | GNUNET_GE_BULK |
- GNUNET_GE_FATAL, "mkfifo");
- GNUNET_free (pipename);
- coreAPI->service_release (stats);
- stats = NULL;
- return NULL;
- }
+ {
+ GNUNET_GE_LOG_STRERROR (ectx,
+ GNUNET_GE_ADMIN | GNUNET_GE_BULK |
+ GNUNET_GE_FATAL, "mkfifo");
+ GNUNET_free (pipename);
+ coreAPI->service_release (stats);
+ stats = NULL;
+ return NULL;
+ }
/* we need to allow the mailer program to send us messages;
- easiest done by giving it write permissions (see Mantis #1142) */
+ * easiest done by giving it write permissions (see Mantis #1142) */
if (0 != chmod (pipename, S_IWUSR | S_IRUSR | S_IWGRP | S_IWOTH))
GNUNET_GE_LOG_STRERROR (ectx,
GNUNET_GE_ADMIN | GNUNET_GE_BULK |
@@ -863,8 +860,7 @@
GNUNET_GC_get_configuration_value_string (coreAPI->cfg,
"SMTP",
"SERVER",
- "localhost:25",
- &smtp_server_name);
+ "localhost:25", &smtp_server_name);
sa.sa_handler = SIG_IGN;
sigemptyset (&sa.sa_mask);
sa.sa_flags = 0;
@@ -892,10 +888,10 @@
sigaction (SIGPIPE, &old_handler, NULL);
GNUNET_free (smtp_server_name);
if (stats != NULL)
- {
- coreAPI->service_release (stats);
- stats = NULL;
- }
+ {
+ coreAPI->service_release (stats);
+ stats = NULL;
+ }
GNUNET_mutex_destroy (lock);
lock = NULL;
UNLINK (pipename);
Modified: gnunet/src/transport/plugin_transport_tcp.c
===================================================================
--- gnunet/src/transport/plugin_transport_tcp.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/transport/plugin_transport_tcp.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -343,7 +343,7 @@
* Map of peers we have tried to contact behind a NAT
*/
struct GNUNET_CONTAINER_MultiHashMap *nat_wait_conns;
-
+
/**
* List of active TCP probes.
*/
@@ -358,7 +358,7 @@
* Handle for (DYN)DNS lookup of our external IP.
*/
struct GNUNET_RESOLVER_RequestHandle *ext_dns;
-
+
/**
* How many more TCP sessions are we allowed to open right now?
*/
@@ -397,9 +397,8 @@
*/
static int
plugin_tcp_access_check (void *cls,
- const struct GNUNET_CONNECTION_Credentials *ucred,
- const struct sockaddr *addr,
- socklen_t addrlen)
+ const struct GNUNET_CONNECTION_Credentials *ucred,
+ const struct sockaddr *addr, socklen_t addrlen)
{
struct Plugin *plugin = cls;
@@ -421,9 +420,8 @@
*/
static void
tcp_nat_port_map_callback (void *cls,
- int add_remove,
- const struct sockaddr *addr,
- socklen_t addrlen)
+ int add_remove,
+ const struct sockaddr *addr, socklen_t addrlen)
{
struct Plugin *plugin = cls;
struct IPv4TcpAddress t4;
@@ -432,37 +430,34 @@
size_t args;
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "tcp",
- "NPMC called with %d for address `%s'\n",
- add_remove,
- GNUNET_a2s (addr, addrlen));
+ "tcp",
+ "NPMC called with %d for address `%s'\n",
+ add_remove, GNUNET_a2s (addr, addrlen));
/* convert 'addr' to our internal format */
switch (addr->sa_family)
- {
- case AF_INET:
- GNUNET_assert (addrlen == sizeof (struct sockaddr_in));
- t4.ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr;
- t4.t4_port = ((struct sockaddr_in *) addr)->sin_port;
- arg = &t4;
- args = sizeof (t4);
- break;
- case AF_INET6:
- GNUNET_assert (addrlen == sizeof (struct sockaddr_in6));
- memcpy (&t6.ipv6_addr,
- &((struct sockaddr_in6 *) addr)->sin6_addr,
- sizeof (struct in6_addr));
- t6.t6_port = ((struct sockaddr_in6 *) addr)->sin6_port;
- arg = &t6;
- args = sizeof (t6);
- break;
- default:
- GNUNET_break (0);
- return;
- }
+ {
+ case AF_INET:
+ GNUNET_assert (addrlen == sizeof (struct sockaddr_in));
+ t4.ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr;
+ t4.t4_port = ((struct sockaddr_in *) addr)->sin_port;
+ arg = &t4;
+ args = sizeof (t4);
+ break;
+ case AF_INET6:
+ GNUNET_assert (addrlen == sizeof (struct sockaddr_in6));
+ memcpy (&t6.ipv6_addr,
+ &((struct sockaddr_in6 *) addr)->sin6_addr,
+ sizeof (struct in6_addr));
+ t6.t6_port = ((struct sockaddr_in6 *) addr)->sin6_port;
+ arg = &t6;
+ args = sizeof (t6);
+ break;
+ default:
+ GNUNET_break (0);
+ return;
+ }
/* modify our published address list */
- plugin->env->notify_address (plugin->env->cls,
- add_remove,
- arg, args);
+ plugin->env->notify_address (plugin->env->cls, add_remove, arg, args);
}
@@ -477,10 +472,8 @@
* @param addrlen length of the address
* @return string representing the same address
*/
-static const char*
-tcp_address_to_string (void *cls,
- const void *addr,
- size_t addrlen)
+static const char *
+tcp_address_to_string (void *cls, const void *addr, size_t addrlen)
{
static char rbuf[INET6_ADDRSTRLEN + 12];
char buf[INET6_ADDRSTRLEN];
@@ -493,40 +486,38 @@
uint16_t port;
if (addrlen == sizeof (struct IPv6TcpAddress))
- {
- t6 = addr;
- af = AF_INET6;
- port = ntohs (t6->t6_port);
- memcpy (&a6, &t6->ipv6_addr, sizeof (a6));
- sb = &a6;
- }
+ {
+ t6 = addr;
+ af = AF_INET6;
+ port = ntohs (t6->t6_port);
+ memcpy (&a6, &t6->ipv6_addr, sizeof (a6));
+ sb = &a6;
+ }
else if (addrlen == sizeof (struct IPv4TcpAddress))
- {
- t4 = addr;
- af = AF_INET;
- port = ntohs (t4->t4_port);
- memcpy (&a4, &t4->ipv4_addr, sizeof (a4));
- sb = &a4;
- }
+ {
+ t4 = addr;
+ af = AF_INET;
+ port = ntohs (t4->t4_port);
+ memcpy (&a4, &t4->ipv4_addr, sizeof (a4));
+ sb = &a4;
+ }
else
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
- "tcp",
- _("Unexpected address length: %u bytes\n"),
- (unsigned int) addrlen);
- GNUNET_break (0);
- return NULL;
- }
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
+ "tcp",
+ _("Unexpected address length: %u bytes\n"),
+ (unsigned int) addrlen);
+ GNUNET_break (0);
+ return NULL;
+ }
if (NULL == inet_ntop (af, sb, buf, INET6_ADDRSTRLEN))
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop");
- return NULL;
- }
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop");
+ return NULL;
+ }
GNUNET_snprintf (rbuf,
- sizeof (rbuf),
- (af == AF_INET6) ? "[%s]:%u" : "%s:%u",
- buf,
- port);
+ sizeof (rbuf),
+ (af == AF_INET6) ? "[%s]:%u" : "%s:%u", buf, port);
return rbuf;
}
@@ -565,8 +556,7 @@
static struct Session *
create_session (struct Plugin *plugin,
const struct GNUNET_PeerIdentity *target,
- struct GNUNET_SERVER_Client *client,
- int is_nat)
+ struct GNUNET_SERVER_Client *client, int is_nat)
{
struct Session *ret;
struct PendingMessage *pm;
@@ -578,24 +568,25 @@
GNUNET_assert (client == NULL);
#if DEBUG_TCP
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "tcp",
- "Creating new session for peer `%4s'\n",
- GNUNET_i2s (target));
+ "tcp",
+ "Creating new session for peer `%4s'\n",
+ GNUNET_i2s (target));
#endif
ret = GNUNET_malloc (sizeof (struct Session));
ret->last_activity = GNUNET_TIME_absolute_get ();
ret->plugin = plugin;
ret->is_nat = is_nat;
- if (is_nat != GNUNET_YES) /* If not a NAT WAIT conn, add it to global list */
- {
- ret->next = plugin->sessions;
- plugin->sessions = ret;
- }
+ if (is_nat != GNUNET_YES) /* If not a NAT WAIT conn, add it to global
list */
+ {
+ ret->next = plugin->sessions;
+ plugin->sessions = ret;
+ }
ret->client = client;
ret->target = *target;
ret->expecting_welcome = GNUNET_YES;
- pm = GNUNET_malloc (sizeof (struct PendingMessage) + sizeof (struct
WelcomeMessage));
- pm->msg = (const char*) &pm[1];
+ pm = GNUNET_malloc (sizeof (struct PendingMessage) +
+ sizeof (struct WelcomeMessage));
+ pm->msg = (const char *) &pm[1];
pm->message_size = sizeof (struct WelcomeMessage);
welcome.header.size = htons (sizeof (struct WelcomeMessage));
welcome.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME);
@@ -603,17 +594,14 @@
memcpy (&pm[1], &welcome, sizeof (welcome));
pm->timeout = GNUNET_TIME_UNIT_FOREVER_ABS;
GNUNET_STATISTICS_update (plugin->env->stats,
- gettext_noop ("# bytes currently in TCP buffers"),
- pm->message_size,
- GNUNET_NO);
+ gettext_noop ("# bytes currently in TCP buffers"),
+ pm->message_size, GNUNET_NO);
GNUNET_CONTAINER_DLL_insert (ret->pending_messages_head,
- ret->pending_messages_tail,
- pm);
+ ret->pending_messages_tail, pm);
if (is_nat != GNUNET_YES)
GNUNET_STATISTICS_update (plugin->env->stats,
gettext_noop ("# TCP sessions active"),
- 1,
- GNUNET_NO);
+ 1, GNUNET_NO);
return ret;
}
@@ -655,111 +643,101 @@
session->transmit_handle = NULL;
plugin = session->plugin;
if (buf == NULL)
+ {
+#if DEBUG_TCP
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ "tcp",
+ "Timeout trying to transmit to peer `%4s', discarding
message queue.\n",
+ GNUNET_i2s (&session->target));
+#endif
+ /* timeout; cancel all messages that have already expired */
+ hd = NULL;
+ tl = NULL;
+ ret = 0;
+ now = GNUNET_TIME_absolute_get ();
+ while ((NULL != (pos = session->pending_messages_head)) &&
+ (pos->timeout.abs_value <= now.abs_value))
{
+ GNUNET_CONTAINER_DLL_remove (session->pending_messages_head,
+ session->pending_messages_tail, pos);
#if DEBUG_TCP
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "tcp",
- "Timeout trying to transmit to peer `%4s', discarding
message queue.\n",
- GNUNET_i2s (&session->target));
+ "tcp",
+ "Failed to transmit %u byte message to `%4s'.\n",
+ pos->message_size, GNUNET_i2s (&session->target));
#endif
- /* timeout; cancel all messages that have already expired */
- hd = NULL;
- tl = NULL;
- ret = 0;
- now = GNUNET_TIME_absolute_get ();
- while ( (NULL != (pos = session->pending_messages_head)) &&
- (pos->timeout.abs_value <= now.abs_value) )
- {
- GNUNET_CONTAINER_DLL_remove (session->pending_messages_head,
- session->pending_messages_tail,
- pos);
-#if DEBUG_TCP
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "tcp",
- "Failed to transmit %u byte message to `%4s'.\n",
- pos->message_size,
- GNUNET_i2s (&session->target));
-#endif
- ret += pos->message_size;
- GNUNET_CONTAINER_DLL_insert_after (hd, tl, tl, pos);
- }
- /* do this call before callbacks (so that if callbacks destroy
- session, they have a chance to cancel actions done by this
- call) */
- process_pending_messages (session);
- pid = session->target;
- /* no do callbacks and do not use session again since
- the callbacks may abort the session */
- while (NULL != (pos = hd))
- {
- GNUNET_CONTAINER_DLL_remove (hd, tl, pos);
- if (pos->transmit_cont != NULL)
- pos->transmit_cont (pos->transmit_cont_cls,
- &pid, GNUNET_SYSERR);
- GNUNET_free (pos);
- }
- GNUNET_STATISTICS_update (plugin->env->stats,
- gettext_noop ("# bytes currently in TCP
buffers"),
- - (int64_t) ret,
- GNUNET_NO);
- GNUNET_STATISTICS_update (plugin->env->stats,
- gettext_noop ("# bytes discarded by TCP
(timeout)"),
- ret,
- GNUNET_NO);
- return 0;
+ ret += pos->message_size;
+ GNUNET_CONTAINER_DLL_insert_after (hd, tl, tl, pos);
}
+ /* do this call before callbacks (so that if callbacks destroy
+ * session, they have a chance to cancel actions done by this
+ * call) */
+ process_pending_messages (session);
+ pid = session->target;
+ /* no do callbacks and do not use session again since
+ * the callbacks may abort the session */
+ while (NULL != (pos = hd))
+ {
+ GNUNET_CONTAINER_DLL_remove (hd, tl, pos);
+ if (pos->transmit_cont != NULL)
+ pos->transmit_cont (pos->transmit_cont_cls, &pid, GNUNET_SYSERR);
+ GNUNET_free (pos);
+ }
+ GNUNET_STATISTICS_update (plugin->env->stats,
+ gettext_noop ("# bytes currently in TCP
buffers"),
+ -(int64_t) ret, GNUNET_NO);
+ GNUNET_STATISTICS_update (plugin->env->stats,
+ gettext_noop
+ ("# bytes discarded by TCP (timeout)"), ret,
+ GNUNET_NO);
+ return 0;
+ }
/* copy all pending messages that would fit */
ret = 0;
cbuf = buf;
hd = NULL;
tl = NULL;
while (NULL != (pos = session->pending_messages_head))
- {
- if (ret + pos->message_size > size)
- break;
- GNUNET_CONTAINER_DLL_remove (session->pending_messages_head,
- session->pending_messages_tail,
- pos);
- GNUNET_assert (size >= pos->message_size);
- /* FIXME: this memcpy can be up to 7% of our total runtime */
- memcpy (cbuf, pos->msg, pos->message_size);
- cbuf += pos->message_size;
- ret += pos->message_size;
- size -= pos->message_size;
- GNUNET_CONTAINER_DLL_insert_after (hd, tl, tl, pos);
- }
+ {
+ if (ret + pos->message_size > size)
+ break;
+ GNUNET_CONTAINER_DLL_remove (session->pending_messages_head,
+ session->pending_messages_tail, pos);
+ GNUNET_assert (size >= pos->message_size);
+ /* FIXME: this memcpy can be up to 7% of our total runtime */
+ memcpy (cbuf, pos->msg, pos->message_size);
+ cbuf += pos->message_size;
+ ret += pos->message_size;
+ size -= pos->message_size;
+ GNUNET_CONTAINER_DLL_insert_after (hd, tl, tl, pos);
+ }
/* schedule 'continuation' before callbacks so that callbacks that
- cancel everything don't cause us to use a session that no longer
- exists... */
+ * cancel everything don't cause us to use a session that no longer
+ * exists... */
process_pending_messages (session);
session->last_activity = GNUNET_TIME_absolute_get ();
pid = session->target;
/* we'll now call callbacks that may cancel the session; hence
- we should not use 'session' after this point */
+ * we should not use 'session' after this point */
while (NULL != (pos = hd))
- {
- GNUNET_CONTAINER_DLL_remove (hd, tl, pos);
- if (pos->transmit_cont != NULL)
- pos->transmit_cont (pos->transmit_cont_cls,
- &pid, GNUNET_OK);
- GNUNET_free (pos);
- }
+ {
+ GNUNET_CONTAINER_DLL_remove (hd, tl, pos);
+ if (pos->transmit_cont != NULL)
+ pos->transmit_cont (pos->transmit_cont_cls, &pid, GNUNET_OK);
+ GNUNET_free (pos);
+ }
GNUNET_assert (hd == NULL);
GNUNET_assert (tl == NULL);
#if DEBUG_TCP > 1
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "tcp",
- "Transmitting %u bytes\n",
- ret);
+ "tcp", "Transmitting %u bytes\n", ret);
#endif
GNUNET_STATISTICS_update (plugin->env->stats,
- gettext_noop ("# bytes currently in TCP buffers"),
- - (int64_t) ret,
- GNUNET_NO);
+ gettext_noop ("# bytes currently in TCP buffers"),
+ -(int64_t) ret, GNUNET_NO);
GNUNET_STATISTICS_update (plugin->env->stats,
- gettext_noop ("# bytes transmitted via TCP"),
- ret,
- GNUNET_NO);
+ gettext_noop ("# bytes transmitted via TCP"),
+ ret, GNUNET_NO);
return ret;
}
@@ -782,11 +760,11 @@
return;
session->transmit_handle
- = GNUNET_SERVER_notify_transmit_ready (session->client,
- pm->message_size,
- GNUNET_TIME_absolute_get_remaining
- (pm->timeout),
- &do_transmit, session);
+ = GNUNET_SERVER_notify_transmit_ready (session->client,
+ pm->message_size,
+ GNUNET_TIME_absolute_get_remaining
+ (pm->timeout),
+ &do_transmit, session);
}
@@ -806,22 +784,22 @@
#if DEBUG_TCP
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "tcp",
+ "tcp",
"Disconnecting from `%4s' at %s.\n",
GNUNET_i2s (&session->target),
(session->connect_addr != NULL) ?
tcp_address_to_string (session->plugin,
- session->connect_addr,
- session->connect_alen) : "*");
+ session->connect_addr,
+ session->connect_alen) : "*");
#endif
/* remove from session list */
prev = NULL;
pos = session->plugin->sessions;
while (pos != session)
- {
- prev = pos;
- pos = pos->next;
- }
+ {
+ prev = pos;
+ pos = pos->next;
+ }
if (prev == NULL)
session->plugin->sessions = session->next;
else
@@ -829,57 +807,51 @@
/* clean up state */
if (session->transmit_handle != NULL)
- {
- GNUNET_CONNECTION_notify_transmit_ready_cancel
- (session->transmit_handle);
- session->transmit_handle = NULL;
- }
+ {
+ GNUNET_CONNECTION_notify_transmit_ready_cancel (session->transmit_handle);
+ session->transmit_handle = NULL;
+ }
session->plugin->env->session_end (session->plugin->env->cls,
- &session->target,
- session);
+ &session->target, session);
while (NULL != (pm = session->pending_messages_head))
- {
+ {
#if DEBUG_TCP
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "tcp",
- pm->transmit_cont != NULL
- ? "Could not deliver message to `%4s'.\n"
- : "Could not deliver message to `%4s', notifying.\n",
- GNUNET_i2s (&session->target));
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ "tcp",
+ pm->transmit_cont != NULL
+ ? "Could not deliver message to `%4s'.\n"
+ : "Could not deliver message to `%4s', notifying.\n",
+ GNUNET_i2s (&session->target));
#endif
- GNUNET_STATISTICS_update (session->plugin->env->stats,
- gettext_noop ("# bytes currently in TCP
buffers"),
- - (int64_t) pm->message_size,
- GNUNET_NO);
- GNUNET_STATISTICS_update (session->plugin->env->stats,
- gettext_noop ("# bytes discarded by TCP
(disconnect)"),
- pm->message_size,
- GNUNET_NO);
- GNUNET_CONTAINER_DLL_remove (session->pending_messages_head,
- session->pending_messages_tail,
- pm);
- if (NULL != pm->transmit_cont)
- pm->transmit_cont (pm->transmit_cont_cls,
- &session->target, GNUNET_SYSERR);
- GNUNET_free (pm);
- }
+ GNUNET_STATISTICS_update (session->plugin->env->stats,
+ gettext_noop ("# bytes currently in TCP
buffers"),
+ -(int64_t) pm->message_size, GNUNET_NO);
+ GNUNET_STATISTICS_update (session->plugin->env->stats,
+ gettext_noop
+ ("# bytes discarded by TCP (disconnect)"),
+ pm->message_size, GNUNET_NO);
+ GNUNET_CONTAINER_DLL_remove (session->pending_messages_head,
+ session->pending_messages_tail, pm);
+ if (NULL != pm->transmit_cont)
+ pm->transmit_cont (pm->transmit_cont_cls,
+ &session->target, GNUNET_SYSERR);
+ GNUNET_free (pm);
+ }
GNUNET_break (session->client != NULL);
if (session->receive_delay_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (session->receive_delay_task);
- if (session->client != NULL)
- GNUNET_SERVER_receive_done (session->client,
- GNUNET_SYSERR);
- }
+ {
+ GNUNET_SCHEDULER_cancel (session->receive_delay_task);
+ if (session->client != NULL)
+ GNUNET_SERVER_receive_done (session->client, GNUNET_SYSERR);
+ }
if (session->client != NULL)
- {
- GNUNET_SERVER_client_drop (session->client);
- session->client = NULL;
- }
+ {
+ GNUNET_SERVER_client_drop (session->client);
+ session->client = NULL;
+ }
GNUNET_STATISTICS_update (session->plugin->env->stats,
- gettext_noop ("# TCP sessions active"),
- -1,
- GNUNET_NO);
+ gettext_noop ("# TCP sessions active"),
+ -1, GNUNET_NO);
GNUNET_free_non_null (session->connect_addr);
GNUNET_assert (NULL == session->transmit_handle);
GNUNET_free (session);
@@ -894,28 +866,25 @@
* @return "better" session (more active)
*/
static struct Session *
-select_better_session (struct Session *s1,
- struct Session *s2)
+select_better_session (struct Session *s1, struct Session *s2)
{
if (s1 == NULL)
return s2;
if (s2 == NULL)
return s1;
- if ( (s1->expecting_welcome == GNUNET_NO) &&
- (s2->expecting_welcome == GNUNET_YES) )
+ if ((s1->expecting_welcome == GNUNET_NO) &&
+ (s2->expecting_welcome == GNUNET_YES))
return s1;
- if ( (s1->expecting_welcome == GNUNET_YES) &&
- (s2->expecting_welcome == GNUNET_NO) )
+ if ((s1->expecting_welcome == GNUNET_YES) &&
+ (s2->expecting_welcome == GNUNET_NO))
return s2;
if (s1->last_activity.abs_value < s2->last_activity.abs_value)
return s2;
if (s1->last_activity.abs_value > s2->last_activity.abs_value)
return s1;
- if ( (GNUNET_YES == s1->inbound) &&
- (GNUNET_NO == s2->inbound) )
+ if ((GNUNET_YES == s1->inbound) && (GNUNET_NO == s2->inbound))
return s1;
- if ( (GNUNET_NO == s1->inbound) &&
- (GNUNET_YES == s2->inbound) )
+ if ((GNUNET_NO == s1->inbound) && (GNUNET_YES == s2->inbound))
return s2;
return s1;
}
@@ -965,10 +934,10 @@
size_t msgbuf_size,
uint32_t priority,
struct GNUNET_TIME_Relative timeout,
- struct Session *session,
- const void *addr,
- size_t addrlen,
- int force_address,
+ struct Session *session,
+ const void *addr,
+ size_t addrlen,
+ int force_address,
GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
{
struct Plugin *plugin = cls;
@@ -986,234 +955,217 @@
unsigned int is_natd;
GNUNET_STATISTICS_update (plugin->env->stats,
- gettext_noop ("# bytes TCP was asked to transmit"),
- msgbuf_size,
- GNUNET_NO);
+ gettext_noop ("# bytes TCP was asked to transmit"),
+ msgbuf_size, GNUNET_NO);
/* FIXME: we could do this cheaper with a hash table
- where we could restrict the iteration to entries that match
- the target peer... */
+ * where we could restrict the iteration to entries that match
+ * the target peer... */
is_natd = GNUNET_NO;
if (session == NULL)
+ {
+ cand_session = NULL;
+ next = plugin->sessions;
+ while (NULL != (session = next))
{
- cand_session = NULL;
- next = plugin->sessions;
- while (NULL != (session = next))
- {
- next = session->next;
- GNUNET_assert (session->client != NULL);
- if (0 != memcmp (target,
- &session->target,
- sizeof (struct GNUNET_PeerIdentity)))
- continue;
- if ( ( (GNUNET_SYSERR == force_address) &&
- (session->expecting_welcome == GNUNET_NO) ) ||
- (GNUNET_NO == force_address) )
- {
- cand_session = select_better_session (cand_session,
- session);
- continue;
- }
- if (GNUNET_SYSERR == force_address)
- continue;
- GNUNET_break (GNUNET_YES == force_address);
- if (addr == NULL)
- {
- GNUNET_break (0);
- break;
- }
- if ( (addrlen != session->connect_alen) &&
- (session->is_nat == GNUNET_NO) )
- continue;
- if ((0 != memcmp (session->connect_addr,
- addr,
- addrlen)) && (session->is_nat == GNUNET_NO))
- continue;
- cand_session = select_better_session (cand_session,
- session);
- }
- session = cand_session;
+ next = session->next;
+ GNUNET_assert (session->client != NULL);
+ if (0 != memcmp (target,
+ &session->target, sizeof (struct GNUNET_PeerIdentity)))
+ continue;
+ if (((GNUNET_SYSERR == force_address) &&
+ (session->expecting_welcome == GNUNET_NO)) ||
+ (GNUNET_NO == force_address))
+ {
+ cand_session = select_better_session (cand_session, session);
+ continue;
+ }
+ if (GNUNET_SYSERR == force_address)
+ continue;
+ GNUNET_break (GNUNET_YES == force_address);
+ if (addr == NULL)
+ {
+ GNUNET_break (0);
+ break;
+ }
+ if ((addrlen != session->connect_alen) && (session->is_nat == GNUNET_NO))
+ continue;
+ if ((0 != memcmp (session->connect_addr,
+ addr, addrlen)) && (session->is_nat == GNUNET_NO))
+ continue;
+ cand_session = select_better_session (cand_session, session);
}
- if ( (session == NULL) &&
- (addr == NULL) )
- {
+ session = cand_session;
+ }
+ if ((session == NULL) && (addr == NULL))
+ {
#if DEBUG_TCP
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "tcp",
- "Asked to transmit to `%4s' without address and I have
no existing connection (failing).\n",
- GNUNET_i2s (target));
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ "tcp",
+ "Asked to transmit to `%4s' without address and I have no
existing connection (failing).\n",
+ GNUNET_i2s (target));
#endif
- GNUNET_STATISTICS_update (plugin->env->stats,
- gettext_noop ("# bytes discarded by TCP (no
address and no connection)"),
- msgbuf_size,
- GNUNET_NO);
- return -1;
- }
+ GNUNET_STATISTICS_update (plugin->env->stats,
+ gettext_noop
+ ("# bytes discarded by TCP (no address and no
connection)"),
+ msgbuf_size, GNUNET_NO);
+ return -1;
+ }
if (session == NULL)
+ {
+ if (addrlen == sizeof (struct IPv6TcpAddress))
{
- if (addrlen == sizeof (struct IPv6TcpAddress))
- {
- t6 = addr;
- af = AF_INET6;
- memset (&a6, 0, sizeof (a6));
+ t6 = addr;
+ af = AF_INET6;
+ memset (&a6, 0, sizeof (a6));
#if HAVE_SOCKADDR_IN_SIN_LEN
- a6.sin6_len = sizeof (a6);
+ a6.sin6_len = sizeof (a6);
#endif
- a6.sin6_family = AF_INET6;
- a6.sin6_port = t6->t6_port;
- if (t6->t6_port == 0)
- is_natd = GNUNET_YES;
- memcpy (&a6.sin6_addr,
- &t6->ipv6_addr,
- sizeof (struct in6_addr));
- sb = &a6;
- sbs = sizeof (a6);
- }
- else if (addrlen == sizeof (struct IPv4TcpAddress))
- {
- t4 = addr;
- af = AF_INET;
- memset (&a4, 0, sizeof (a4));
+ a6.sin6_family = AF_INET6;
+ a6.sin6_port = t6->t6_port;
+ if (t6->t6_port == 0)
+ is_natd = GNUNET_YES;
+ memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof (struct in6_addr));
+ sb = &a6;
+ sbs = sizeof (a6);
+ }
+ else if (addrlen == sizeof (struct IPv4TcpAddress))
+ {
+ t4 = addr;
+ af = AF_INET;
+ memset (&a4, 0, sizeof (a4));
#if HAVE_SOCKADDR_IN_SIN_LEN
- a4.sin_len = sizeof (a4);
+ a4.sin_len = sizeof (a4);
#endif
- a4.sin_family = AF_INET;
- a4.sin_port = t4->t4_port;
- if (t4->t4_port == 0)
- is_natd = GNUNET_YES;
- a4.sin_addr.s_addr = t4->ipv4_addr;
- sb = &a4;
- sbs = sizeof (a4);
- }
- else
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
- "tcp",
- _("Address of unexpected length: %u\n"),
- addrlen);
- GNUNET_break (0);
- return -1;
- }
+ a4.sin_family = AF_INET;
+ a4.sin_port = t4->t4_port;
+ if (t4->t4_port == 0)
+ is_natd = GNUNET_YES;
+ a4.sin_addr.s_addr = t4->ipv4_addr;
+ sb = &a4;
+ sbs = sizeof (a4);
+ }
+ else
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
+ "tcp", _("Address of unexpected length: %u\n"),
addrlen);
+ GNUNET_break (0);
+ return -1;
+ }
- if ((is_natd == GNUNET_YES) && (addrlen == sizeof (struct
IPv6TcpAddress)))
- return -1; /* NAT client only works with IPv4 addresses */
- if (0 == plugin->max_connections)
- return -1; /* saturated */
+ if ((is_natd == GNUNET_YES) && (addrlen == sizeof (struct IPv6TcpAddress)))
+ return -1; /* NAT client only works with IPv4 addresses */
+ if (0 == plugin->max_connections)
+ return -1; /* saturated */
- if ( (is_natd == GNUNET_YES) &&
- (NULL != plugin->nat) &&
- (GNUNET_NO ==
GNUNET_CONTAINER_multihashmap_contains(plugin->nat_wait_conns,
-
&target->hashPubKey)) )
- {
+ if ((is_natd == GNUNET_YES) &&
+ (NULL != plugin->nat) &&
+ (GNUNET_NO ==
+ GNUNET_CONTAINER_multihashmap_contains (plugin->nat_wait_conns,
+ &target->hashPubKey)))
+ {
#if DEBUG_TCP_NAT
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "tcp",
- _("Found valid IPv4 NAT address (creating
session)!\n"));
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ "tcp",
+ _("Found valid IPv4 NAT address (creating
session)!\n"));
#endif
- session = create_session (plugin,
- target,
- NULL,
- GNUNET_YES);
- GNUNET_assert (session != NULL);
+ session = create_session (plugin, target, NULL, GNUNET_YES);
+ GNUNET_assert (session != NULL);
- /* create new message entry */
- pm = GNUNET_malloc (sizeof (struct PendingMessage) + msgbuf_size);
- /* FIXME: the memset of this malloc can be up to 2% of our total
runtime */
- pm->msg = (const char*) &pm[1];
- memcpy (&pm[1], msg, msgbuf_size);
- /* FIXME: this memcpy can be up to 7% of our total run-time
- (for transport service) */
- pm->message_size = msgbuf_size;
- pm->timeout = GNUNET_TIME_relative_to_absolute (timeout);
- pm->transmit_cont = cont;
- pm->transmit_cont_cls = cont_cls;
+ /* create new message entry */
+ pm = GNUNET_malloc (sizeof (struct PendingMessage) + msgbuf_size);
+ /* FIXME: the memset of this malloc can be up to 2% of our total runtime
*/
+ pm->msg = (const char *) &pm[1];
+ memcpy (&pm[1], msg, msgbuf_size);
+ /* FIXME: this memcpy can be up to 7% of our total run-time
+ * (for transport service) */
+ pm->message_size = msgbuf_size;
+ pm->timeout = GNUNET_TIME_relative_to_absolute (timeout);
+ pm->transmit_cont = cont;
+ pm->transmit_cont_cls = cont_cls;
- /* append pm to pending_messages list */
- GNUNET_CONTAINER_DLL_insert_after (session->pending_messages_head,
- session->pending_messages_tail,
- session->pending_messages_tail,
- pm);
+ /* append pm to pending_messages list */
+ GNUNET_CONTAINER_DLL_insert_after (session->pending_messages_head,
+ session->pending_messages_tail,
+ session->pending_messages_tail, pm);
-
GNUNET_assert(GNUNET_CONTAINER_multihashmap_put(plugin->nat_wait_conns,
- &target->hashPubKey,
- session,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY) == GNUNET_OK);
+ GNUNET_assert (GNUNET_CONTAINER_multihashmap_put (plugin->nat_wait_conns,
+ &target->hashPubKey,
+ session,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)
+ == GNUNET_OK);
#if DEBUG_TCP_NAT
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "tcp",
- "Created NAT WAIT connection to `%4s' at `%s'\n",
- GNUNET_i2s (target),
- GNUNET_a2s (sb, sbs));
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ "tcp",
+ "Created NAT WAIT connection to `%4s' at `%s'\n",
+ GNUNET_i2s (target), GNUNET_a2s (sb, sbs));
#endif
- GNUNET_NAT_run_client (plugin->nat, &a4);
- return 0;
- }
- if ( (is_natd == GNUNET_YES) &&
- (GNUNET_YES ==
GNUNET_CONTAINER_multihashmap_contains(plugin->nat_wait_conns,
-
&target->hashPubKey)) )
- {
- /* Only do one NAT punch attempt per peer identity */
- return -1;
- }
- sa = GNUNET_CONNECTION_create_from_sockaddr (af, sb, sbs);
- if (sa == NULL)
- {
+ GNUNET_NAT_run_client (plugin->nat, &a4);
+ return 0;
+ }
+ if ((is_natd == GNUNET_YES) &&
+ (GNUNET_YES ==
+ GNUNET_CONTAINER_multihashmap_contains (plugin->nat_wait_conns,
+ &target->hashPubKey)))
+ {
+ /* Only do one NAT punch attempt per peer identity */
+ return -1;
+ }
+ sa = GNUNET_CONNECTION_create_from_sockaddr (af, sb, sbs);
+ if (sa == NULL)
+ {
#if DEBUG_TCP
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "tcp",
- "Failed to create connection to `%4s' at `%s'\n",
- GNUNET_i2s (target),
- GNUNET_a2s (sb, sbs));
-#endif
- GNUNET_STATISTICS_update (plugin->env->stats,
- gettext_noop ("# bytes discarded by TCP
(failed to connect)"),
- msgbuf_size,
- GNUNET_NO);
- return -1;
- }
- GNUNET_assert (0 != plugin->max_connections);
- plugin->max_connections--;
-#if DEBUG_TCP_NAT
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "tcp",
- "Asked to transmit to `%4s', creating fresh session
using address `%s'.\n",
- GNUNET_i2s (target),
- GNUNET_a2s (sb, sbs));
+ "tcp",
+ "Failed to create connection to `%4s' at `%s'\n",
+ GNUNET_i2s (target), GNUNET_a2s (sb, sbs));
#endif
- session = create_session (plugin,
- target,
- GNUNET_SERVER_connect_socket (plugin->server,
- sa),
- GNUNET_NO);
- session->connect_addr = GNUNET_malloc (addrlen);
- memcpy (session->connect_addr,
- addr,
- addrlen);
- session->connect_alen = addrlen;
+ GNUNET_STATISTICS_update (plugin->env->stats,
+ gettext_noop
+ ("# bytes discarded by TCP (failed to
connect)"),
+ msgbuf_size, GNUNET_NO);
+ return -1;
}
- else /* session != NULL */
+ GNUNET_assert (0 != plugin->max_connections);
+ plugin->max_connections--;
+#if DEBUG_TCP_NAT
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ "tcp",
+ "Asked to transmit to `%4s', creating fresh session using
address `%s'.\n",
+ GNUNET_i2s (target), GNUNET_a2s (sb, sbs));
+#endif
+ session = create_session (plugin,
+ target,
+ GNUNET_SERVER_connect_socket (plugin->server,
+ sa), GNUNET_NO);
+ session->connect_addr = GNUNET_malloc (addrlen);
+ memcpy (session->connect_addr, addr, addrlen);
+ session->connect_alen = addrlen;
+ }
+ else /* session != NULL */
+ {
+ /* check if session is valid */
+ struct Session *ses = plugin->sessions;
+
+ while ((ses != NULL) && (ses != session))
+ ses = ses->next;
+ if (ses == NULL)
{
- /* check if session is valid */
- struct Session * ses = plugin->sessions;
- while ((ses != NULL) && (ses != session))
- ses = ses->next;
- if (ses == NULL)
- {
- GNUNET_break (0);
- return -1;
- }
+ GNUNET_break (0);
+ return -1;
}
+ }
GNUNET_assert (session != NULL);
GNUNET_assert (session->client != NULL);
- GNUNET_SERVER_client_set_timeout(session->client,
GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
+ GNUNET_SERVER_client_set_timeout (session->client,
+ GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
GNUNET_STATISTICS_update (plugin->env->stats,
- gettext_noop ("# bytes currently in TCP buffers"),
- msgbuf_size,
- GNUNET_NO);
+ gettext_noop ("# bytes currently in TCP buffers"),
+ msgbuf_size, GNUNET_NO);
/* create new message entry */
pm = GNUNET_malloc (sizeof (struct PendingMessage) + msgbuf_size);
- pm->msg = (const char*) &pm[1];
+ pm->msg = (const char *) &pm[1];
memcpy (&pm[1], msg, msgbuf_size);
pm->message_size = msgbuf_size;
pm->timeout = GNUNET_TIME_relative_to_absolute (timeout);
@@ -1222,15 +1174,13 @@
/* append pm to pending_messages list */
GNUNET_CONTAINER_DLL_insert_after (session->pending_messages_head,
- session->pending_messages_tail,
- session->pending_messages_tail,
- pm);
+ session->pending_messages_tail,
+ 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",
- msgbuf_size,
- GNUNET_i2s (target));
+ "tcp",
+ "Asked to transmit %u bytes to `%s', added message to
list.\n",
+ msgbuf_size, GNUNET_i2s (target));
#endif
process_pending_messages (session);
return msgbuf_size;
@@ -1254,8 +1204,7 @@
* to be cancelled
*/
static void
-tcp_plugin_disconnect (void *cls,
- const struct GNUNET_PeerIdentity *target)
+tcp_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
{
struct Plugin *plugin = cls;
struct Session *session;
@@ -1264,31 +1213,29 @@
#if DEBUG_TCP
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "tcp",
- "Asked to cancel session with `%4s'\n",
- GNUNET_i2s (target));
+ "tcp",
+ "Asked to cancel session with `%4s'\n", GNUNET_i2s
(target));
#endif
next = plugin->sessions;
while (NULL != (session = next))
+ {
+ next = session->next;
+ if (0 != memcmp (target,
+ &session->target, sizeof (struct GNUNET_PeerIdentity)))
+ continue;
+ pm = session->pending_messages_head;
+ while (pm != NULL)
{
- next = session->next;
- if (0 != memcmp (target,
- &session->target,
- sizeof (struct GNUNET_PeerIdentity)))
- continue;
- pm = session->pending_messages_head;
- while (pm != NULL)
- {
- pm->transmit_cont = NULL;
- pm->transmit_cont_cls = NULL;
- pm = pm->next;
- }
- GNUNET_STATISTICS_update (session->plugin->env->stats,
- gettext_noop ("# transport-service disconnect
requests for TCP"),
- 1,
- GNUNET_NO);
- disconnect_session (session);
+ pm->transmit_cont = NULL;
+ pm->transmit_cont_cls = NULL;
+ pm = pm->next;
}
+ GNUNET_STATISTICS_update (session->plugin->env->stats,
+ gettext_noop
+ ("# transport-service disconnect requests for
TCP"),
+ 1, GNUNET_NO);
+ disconnect_session (session);
+ }
}
@@ -1327,11 +1274,11 @@
char *ret;
if (hostname == NULL)
- {
- ppc->asc (ppc->asc_cls, NULL);
- GNUNET_free (ppc);
- return;
- }
+ {
+ ppc->asc (ppc->asc_cls, NULL);
+ GNUNET_free (ppc);
+ return;
+ }
GNUNET_asprintf (&ret, "%s:%d", hostname, ppc->port);
ppc->asc (ppc->asc_cls, ret);
GNUNET_free (ret);
@@ -1372,43 +1319,39 @@
uint16_t port;
if (addrlen == sizeof (struct IPv6TcpAddress))
- {
- t6 = addr;
- memset (&a6, 0, sizeof (a6));
- a6.sin6_family = AF_INET6;
- a6.sin6_port = t6->t6_port;
- memcpy (&a6.sin6_addr,
- &t6->ipv6_addr,
- sizeof (struct in6_addr));
- port = ntohs (t6->t6_port);
- sb = &a6;
- sbs = sizeof (a6);
- }
+ {
+ t6 = addr;
+ memset (&a6, 0, sizeof (a6));
+ a6.sin6_family = AF_INET6;
+ a6.sin6_port = t6->t6_port;
+ memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof (struct in6_addr));
+ port = ntohs (t6->t6_port);
+ sb = &a6;
+ sbs = sizeof (a6);
+ }
else if (addrlen == sizeof (struct IPv4TcpAddress))
- {
- t4 = addr;
- memset (&a4, 0, sizeof (a4));
- a4.sin_family = AF_INET;
- a4.sin_port = t4->t4_port;
- a4.sin_addr.s_addr = t4->ipv4_addr;
- port = ntohs (t4->t4_port);
- sb = &a4;
- sbs = sizeof (a4);
- }
+ {
+ t4 = addr;
+ memset (&a4, 0, sizeof (a4));
+ a4.sin_family = AF_INET;
+ a4.sin_port = t4->t4_port;
+ a4.sin_addr.s_addr = t4->ipv4_addr;
+ port = ntohs (t4->t4_port);
+ sb = &a4;
+ sbs = sizeof (a4);
+ }
else
- {
- /* invalid address */
- GNUNET_break_op (0);
- asc (asc_cls, NULL);
- return;
- }
+ {
+ /* invalid address */
+ GNUNET_break_op (0);
+ asc (asc_cls, NULL);
+ return;
+ }
ppc = GNUNET_malloc (sizeof (struct PrettyPrinterContext));
ppc->asc = asc;
ppc->asc_cls = asc_cls;
ppc->port = port;
- GNUNET_RESOLVER_hostname_get (sb,
- sbs,
- !numeric, timeout, &append_port, ppc);
+ GNUNET_RESOLVER_hostname_get (sb, sbs, !numeric, timeout, &append_port, ppc);
}
@@ -1423,8 +1366,7 @@
* @return GNUNET_OK if port is either open_port or adv_port
*/
static int
-check_port (struct Plugin *plugin,
- uint16_t in_port)
+check_port (struct Plugin *plugin, uint16_t in_port)
{
if ((in_port == plugin->adv_port) || (in_port == plugin->open_port))
return GNUNET_OK;
@@ -1448,9 +1390,7 @@
* and transport, GNUNET_SYSERR if not
*/
static int
-tcp_plugin_check_address (void *cls,
- const void *addr,
- size_t addrlen)
+tcp_plugin_check_address (void *cls, const void *addr, size_t addrlen)
{
struct Plugin *plugin = cls;
struct IPv4TcpAddress *v4;
@@ -1458,37 +1398,35 @@
if ((addrlen != sizeof (struct IPv4TcpAddress)) &&
(addrlen != sizeof (struct IPv6TcpAddress)))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ if (addrlen == sizeof (struct IPv4TcpAddress))
+ {
+ v4 = (struct IPv4TcpAddress *) addr;
+ if (GNUNET_OK != check_port (plugin, ntohs (v4->t4_port)))
+ return GNUNET_SYSERR;
+ if (GNUNET_OK !=
+ GNUNET_NAT_test_address (plugin->nat,
+ &v4->ipv4_addr, sizeof (struct in_addr)))
+ return GNUNET_SYSERR;
+ }
+ else
+ {
+ v6 = (struct IPv6TcpAddress *) addr;
+ if (IN6_IS_ADDR_LINKLOCAL (&v6->ipv6_addr))
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
- if (addrlen == sizeof (struct IPv4TcpAddress))
- {
- v4 = (struct IPv4TcpAddress *) addr;
- if (GNUNET_OK !=
- check_port (plugin, ntohs (v4->t4_port)))
- return GNUNET_SYSERR;
- if (GNUNET_OK !=
- GNUNET_NAT_test_address (plugin->nat,
- &v4->ipv4_addr, sizeof (struct in_addr)))
- return GNUNET_SYSERR;
- }
- else
- {
- v6 = (struct IPv6TcpAddress *) addr;
- if (IN6_IS_ADDR_LINKLOCAL (&v6->ipv6_addr))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- if (GNUNET_OK !=
- check_port (plugin, ntohs (v6->t6_port)))
- return GNUNET_SYSERR;
- if (GNUNET_OK !=
- GNUNET_NAT_test_address (plugin->nat,
- &v6->ipv6_addr, sizeof (struct in6_addr)))
- return GNUNET_SYSERR;
- }
+ if (GNUNET_OK != check_port (plugin, ntohs (v6->t6_port)))
+ return GNUNET_SYSERR;
+ if (GNUNET_OK !=
+ GNUNET_NAT_test_address (plugin->nat,
+ &v6->ipv6_addr, sizeof (struct in6_addr)))
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
}
@@ -1504,8 +1442,8 @@
*/
static void
handle_tcp_nat_probe (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
struct Plugin *plugin = cls;
struct Session *session;
@@ -1518,9 +1456,7 @@
const struct sockaddr_in6 *s6;
#if DEBUG_TCP_NAT
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "tcp",
- "received NAT probe\n");
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", "received NAT probe\n");
#endif
/* We have received a TCP NAT probe, meaning we (hopefully) initiated
* a connection to this peer by running gnunet-nat-client. This peer
@@ -1528,51 +1464,49 @@
* as the default for that peer. Do so and then send a WELCOME message
* so we can really be connected!
*/
- if (ntohs(message->size) != sizeof(struct TCP_NAT_ProbeMessage))
- {
- GNUNET_break_op(0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ if (ntohs (message->size) != sizeof (struct TCP_NAT_ProbeMessage))
+ {
+ GNUNET_break_op (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
- tcp_nat_probe = (const struct TCP_NAT_ProbeMessage *)message;
+ tcp_nat_probe = (const struct TCP_NAT_ProbeMessage *) message;
if (0 == memcmp (&tcp_nat_probe->clientIdentity,
plugin->env->my_identity,
sizeof (struct GNUNET_PeerIdentity)))
- {
- /* refuse connections from ourselves */
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ {
+ /* refuse connections from ourselves */
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
- session = GNUNET_CONTAINER_multihashmap_get(plugin->nat_wait_conns,
-
&tcp_nat_probe->clientIdentity.hashPubKey);
+ session = GNUNET_CONTAINER_multihashmap_get (plugin->nat_wait_conns,
+ &tcp_nat_probe->
+ clientIdentity.hashPubKey);
if (session == NULL)
- {
+ {
#if DEBUG_TCP_NAT
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "tcp",
- "Did NOT find session for NAT probe!\n");
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ "tcp", "Did NOT find session for NAT probe!\n");
#endif
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
- return;
- }
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ return;
+ }
#if DEBUG_TCP_NAT
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "tcp",
- "Found session for NAT probe!\n");
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ "tcp", "Found session for NAT probe!\n");
#endif
- GNUNET_assert(GNUNET_CONTAINER_multihashmap_remove(plugin->nat_wait_conns,
-
&tcp_nat_probe->clientIdentity.hashPubKey,
- session) == GNUNET_YES);
- if (GNUNET_OK !=
- GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
- {
- GNUNET_break (0);
- GNUNET_free (session);
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
- return;
- }
+ GNUNET_assert (GNUNET_CONTAINER_multihashmap_remove (plugin->nat_wait_conns,
+
&tcp_nat_probe->clientIdentity.hashPubKey,
+ session) == GNUNET_YES);
+ if (GNUNET_OK != GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
+ {
+ GNUNET_break (0);
+ GNUNET_free (session);
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ return;
+ }
GNUNET_SERVER_client_keep (client);
session->client = client;
@@ -1581,51 +1515,47 @@
#if DEBUG_TCP_NAT
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "tcp",
- "Found address `%s' for incoming connection\n",
- GNUNET_a2s (vaddr, alen));
+ "tcp",
+ "Found address `%s' for incoming connection\n",
+ GNUNET_a2s (vaddr, alen));
#endif
- switch (((const struct sockaddr *)vaddr)->sa_family)
- {
- case AF_INET:
- s4 = vaddr;
- t4 = GNUNET_malloc (sizeof (struct IPv4TcpAddress));
- t4->t4_port = s4->sin_port;
- t4->ipv4_addr = s4->sin_addr.s_addr;
- session->connect_addr = t4;
- session->connect_alen = sizeof (struct IPv4TcpAddress);
- break;
- case AF_INET6:
- s6 = vaddr;
- t6 = GNUNET_malloc (sizeof (struct IPv6TcpAddress));
- t6->t6_port = s6->sin6_port;
- memcpy (&t6->ipv6_addr,
- &s6->sin6_addr,
- sizeof (struct in6_addr));
- session->connect_addr = t6;
- session->connect_alen = sizeof (struct IPv6TcpAddress);
- break;
- default:
- GNUNET_break_op (0);
+ switch (((const struct sockaddr *) vaddr)->sa_family)
+ {
+ case AF_INET:
+ s4 = vaddr;
+ t4 = GNUNET_malloc (sizeof (struct IPv4TcpAddress));
+ t4->t4_port = s4->sin_port;
+ t4->ipv4_addr = s4->sin_addr.s_addr;
+ session->connect_addr = t4;
+ session->connect_alen = sizeof (struct IPv4TcpAddress);
+ break;
+ case AF_INET6:
+ s6 = vaddr;
+ t6 = GNUNET_malloc (sizeof (struct IPv6TcpAddress));
+ t6->t6_port = s6->sin6_port;
+ memcpy (&t6->ipv6_addr, &s6->sin6_addr, sizeof (struct in6_addr));
+ session->connect_addr = t6;
+ session->connect_alen = sizeof (struct IPv6TcpAddress);
+ break;
+ default:
+ GNUNET_break_op (0);
#if DEBUG_TCP_NAT
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "tcp",
- "Bad address for incoming connection!\n");
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ "tcp", "Bad address for incoming connection!\n");
#endif
- GNUNET_free (vaddr);
- GNUNET_SERVER_client_drop (client);
- GNUNET_free (session);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ GNUNET_free (vaddr);
+ GNUNET_SERVER_client_drop (client);
+ GNUNET_free (session);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
GNUNET_free (vaddr);
-
+
session->next = plugin->sessions;
plugin->sessions = session;
GNUNET_STATISTICS_update (plugin->env->stats,
- gettext_noop ("# TCP sessions active"),
- 1,
- GNUNET_NO);
+ gettext_noop ("# TCP sessions active"),
+ 1, GNUNET_NO);
process_pending_messages (session);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
@@ -1653,109 +1583,100 @@
struct IPv6TcpAddress *t6;
const struct sockaddr_in *s4;
const struct sockaddr_in6 *s6;
-
+
if (0 == memcmp (&wm->clientIdentity,
- plugin->env->my_identity,
- sizeof (struct GNUNET_PeerIdentity)))
- {
- /* refuse connections from ourselves */
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ plugin->env->my_identity,
+ sizeof (struct GNUNET_PeerIdentity)))
+ {
+ /* refuse connections from ourselves */
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
#if DEBUG_TCP
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "tcp",
+ "tcp",
"Received %s message from `%4s'.\n",
- "WELCOME",
- GNUNET_i2s (&wm->clientIdentity));
+ "WELCOME", GNUNET_i2s (&wm->clientIdentity));
#endif
GNUNET_STATISTICS_update (plugin->env->stats,
- gettext_noop ("# TCP WELCOME messages received"),
- 1,
- GNUNET_NO);
+ gettext_noop ("# TCP WELCOME messages received"),
+ 1, GNUNET_NO);
session = find_session_by_client (plugin, client);
if (session == NULL)
+ {
+#if DEBUG_TCP_NAT
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ "tcp",
+ "Received %s message from a `%4s', creating new
session\n",
+ "WELCOME", GNUNET_i2s (&wm->clientIdentity));
+#endif
+ GNUNET_SERVER_client_keep (client);
+ session = create_session (plugin, &wm->clientIdentity, client, GNUNET_NO);
+ session->inbound = GNUNET_YES;
+ if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
{
#if DEBUG_TCP_NAT
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "tcp",
- "Received %s message from a `%4s', creating new
session\n",
- "WELCOME",
- GNUNET_i2s (&wm->clientIdentity));
+ "tcp",
+ "Found address `%s' for incoming connection\n",
+ GNUNET_a2s (vaddr, alen));
#endif
- GNUNET_SERVER_client_keep (client);
- session = create_session (plugin,
- &wm->clientIdentity,
- client,
- GNUNET_NO);
- session->inbound = GNUNET_YES;
- if (GNUNET_OK ==
- GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
- {
-#if DEBUG_TCP_NAT
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "tcp",
- "Found address `%s' for incoming connection\n",
- GNUNET_a2s (vaddr, alen));
-#endif
- if (alen == sizeof (struct sockaddr_in))
- {
- s4 = vaddr;
- t4 = GNUNET_malloc (sizeof (struct IPv4TcpAddress));
- t4->t4_port = s4->sin_port;
- t4->ipv4_addr = s4->sin_addr.s_addr;
- session->connect_addr = t4;
- session->connect_alen = sizeof (struct IPv4TcpAddress);
- }
- else if (alen == sizeof (struct sockaddr_in6))
- {
- s6 = vaddr;
- t6 = GNUNET_malloc (sizeof (struct IPv6TcpAddress));
- t6->t6_port = s6->sin6_port;
- memcpy (&t6->ipv6_addr,
- &s6->sin6_addr,
- sizeof (struct in6_addr));
- session->connect_addr = t6;
- session->connect_alen = sizeof (struct IPv6TcpAddress);
- }
+ if (alen == sizeof (struct sockaddr_in))
+ {
+ s4 = vaddr;
+ t4 = GNUNET_malloc (sizeof (struct IPv4TcpAddress));
+ t4->t4_port = s4->sin_port;
+ t4->ipv4_addr = s4->sin_addr.s_addr;
+ session->connect_addr = t4;
+ session->connect_alen = sizeof (struct IPv4TcpAddress);
+ }
+ else if (alen == sizeof (struct sockaddr_in6))
+ {
+ s6 = vaddr;
+ t6 = GNUNET_malloc (sizeof (struct IPv6TcpAddress));
+ t6->t6_port = s6->sin6_port;
+ memcpy (&t6->ipv6_addr, &s6->sin6_addr, sizeof (struct in6_addr));
+ session->connect_addr = t6;
+ session->connect_alen = sizeof (struct IPv6TcpAddress);
+ }
- GNUNET_free (vaddr);
- }
- else
- {
+ GNUNET_free (vaddr);
+ }
+ else
+ {
#if DEBUG_TCP
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "tcp",
- "Did not obtain TCP socket address for incoming
connection\n");
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ "tcp",
+ "Did not obtain TCP socket address for incoming
connection\n");
#endif
- }
- process_pending_messages (session);
}
+ process_pending_messages (session);
+ }
else
- {
+ {
#if DEBUG_TCP_NAT
- if (GNUNET_OK ==
- GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "tcp",
- "Found address `%s' (already have session)\n",
- GNUNET_a2s (vaddr, alen));
- GNUNET_free (vaddr);
- }
-#endif
+ if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ "tcp",
+ "Found address `%s' (already have session)\n",
+ GNUNET_a2s (vaddr, alen));
+ GNUNET_free (vaddr);
}
+#endif
+ }
if (session->expecting_welcome != GNUNET_YES)
- {
- GNUNET_break_op (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ {
+ GNUNET_break_op (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
session->last_activity = GNUNET_TIME_absolute_get ();
session->expecting_welcome = GNUNET_NO;
- GNUNET_SERVER_client_set_timeout(client,
GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
+ GNUNET_SERVER_client_set_timeout (client,
+ GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
@@ -1768,24 +1689,20 @@
* @param tc task context (unused)
*/
static void
-delayed_done (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+delayed_done (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct Session *session = cls;
struct GNUNET_TIME_Relative delay;
session->receive_delay_task = GNUNET_SCHEDULER_NO_TASK;
delay = session->plugin->env->receive (session->plugin->env->cls,
- &session->target,
- NULL,
- NULL, 0,
- session,
- NULL, 0);
+ &session->target,
+ NULL, NULL, 0, session, NULL, 0);
if (delay.rel_value == 0)
GNUNET_SERVER_receive_done (session->client, GNUNET_OK);
else
session->receive_delay_task =
- GNUNET_SCHEDULER_add_delayed (delay, &delayed_done, session);
+ GNUNET_SCHEDULER_add_delayed (delay, &delayed_done, session);
}
@@ -1808,60 +1725,62 @@
uint16_t type;
type = ntohs (message->type);
- if ( (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME == type) ||
- (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE == type) )
- {
- /* We don't want to propagate WELCOME and NAT Probe messages up! */
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
- return;
- }
+ if ((GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME == type) ||
+ (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE == type))
+ {
+ /* We don't want to propagate WELCOME and NAT Probe messages up! */
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ return;
+ }
session = find_session_by_client (plugin, client);
- if ( (NULL == session) || (GNUNET_YES == session->expecting_welcome) )
- {
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ if ((NULL == session) || (GNUNET_YES == session->expecting_welcome))
+ {
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
session->last_activity = GNUNET_TIME_absolute_get ();
#if DEBUG_TCP > 1
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "tcp",
- "Passing %u bytes of type %u from `%4s' to transport
service.\n",
+ "tcp",
+ "Passing %u bytes of type %u from `%4s' to transport
service.\n",
(unsigned int) ntohs (message->size),
- (unsigned int) ntohs (message->type),
- GNUNET_i2s (&session->target));
+ (unsigned int) ntohs (message->type),
+ GNUNET_i2s (&session->target));
#endif
GNUNET_STATISTICS_update (plugin->env->stats,
- gettext_noop ("# bytes received via TCP"),
- ntohs (message->size),
- GNUNET_NO);
+ gettext_noop ("# bytes received via TCP"),
+ ntohs (message->size), GNUNET_NO);
struct GNUNET_TRANSPORT_ATS_Information distance[2];
+
distance[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE);
distance[0].value = htonl (1);
distance[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
distance[1].value = htonl (0);
delay = plugin->env->receive (plugin->env->cls, &session->target, message,
- (const struct GNUNET_TRANSPORT_ATS_Information
*) &distance,
- 2,
- session,
- (GNUNET_YES == session->inbound) ? NULL :
session->connect_addr,
- (GNUNET_YES == session->inbound) ? 0 :
session->connect_alen);
+ (const struct GNUNET_TRANSPORT_ATS_Information
+ *) &distance, 2, session,
+ (GNUNET_YES ==
+ session->
+ inbound) ? NULL : session->connect_addr,
+ (GNUNET_YES ==
+ session->inbound) ? 0 :
session->connect_alen);
if (delay.rel_value == 0)
- {
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
- }
+ {
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ }
else
- {
-#if DEBUG_TCP
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "tcp",
- "Throttling receiving from `%s' for %llu ms\n",
- GNUNET_i2s (&session->target),
- (unsigned long long) delay.rel_value);
+ {
+#if DEBUG_TCP
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ "tcp",
+ "Throttling receiving from `%s' for %llu ms\n",
+ GNUNET_i2s (&session->target),
+ (unsigned long long) delay.rel_value);
#endif
- GNUNET_SERVER_disable_receive_done_warning (client);
- session->receive_delay_task =
- GNUNET_SCHEDULER_add_delayed (delay, &delayed_done, session);
- }
+ GNUNET_SERVER_disable_receive_done_warning (client);
+ session->receive_delay_task =
+ GNUNET_SCHEDULER_add_delayed (delay, &delayed_done, session);
+ }
}
@@ -1873,8 +1792,7 @@
* @param client identification of the client
*/
static void
-disconnect_notify (void *cls,
- struct GNUNET_SERVER_Client *client)
+disconnect_notify (void *cls, struct GNUNET_SERVER_Client *client)
{
struct Plugin *plugin = cls;
struct Session *session;
@@ -1887,18 +1805,18 @@
return; /* unknown, nothing to do */
#if DEBUG_TCP
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "tcp",
+ "tcp",
"Destroying session of `%4s' with %s due to network-level
disconnect.\n",
GNUNET_i2s (&session->target),
(session->connect_addr != NULL) ?
tcp_address_to_string (session->plugin,
- session->connect_addr,
- session->connect_alen) : "*");
+ session->connect_addr,
+ session->connect_alen) : "*");
#endif
GNUNET_STATISTICS_update (session->plugin->env->stats,
- gettext_noop ("# network-level TCP disconnect
events"),
- 1,
- GNUNET_NO);
+ gettext_noop
+ ("# network-level TCP disconnect events"), 1,
+ GNUNET_NO);
disconnect_session (session);
}
@@ -1912,9 +1830,7 @@
* @return number of bytes copied into buf
*/
static size_t
-notify_send_probe (void *cls,
- size_t size,
- void *buf)
+notify_send_probe (void *cls, size_t size, void *buf)
{
struct TCPProbeContext *tcp_probe_ctx = cls;
struct Plugin *plugin = tcp_probe_ctx->plugin;
@@ -1922,20 +1838,19 @@
tcp_probe_ctx->transmit_handle = NULL;
GNUNET_CONTAINER_DLL_remove (plugin->probe_head,
- plugin->probe_tail,
- tcp_probe_ctx);
+ plugin->probe_tail, tcp_probe_ctx);
if (buf == NULL)
- {
- GNUNET_CONNECTION_destroy (tcp_probe_ctx->sock, GNUNET_NO);
- GNUNET_free(tcp_probe_ctx);
- return 0;
- }
- GNUNET_assert(size >= sizeof(tcp_probe_ctx->message));
- memcpy(buf, &tcp_probe_ctx->message, sizeof(tcp_probe_ctx->message));
+ {
+ GNUNET_CONNECTION_destroy (tcp_probe_ctx->sock, GNUNET_NO);
+ GNUNET_free (tcp_probe_ctx);
+ return 0;
+ }
+ GNUNET_assert (size >= sizeof (tcp_probe_ctx->message));
+ memcpy (buf, &tcp_probe_ctx->message, sizeof (tcp_probe_ctx->message));
GNUNET_SERVER_connect_socket (tcp_probe_ctx->plugin->server,
tcp_probe_ctx->sock);
- ret = sizeof(tcp_probe_ctx->message);
- GNUNET_free(tcp_probe_ctx);
+ ret = sizeof (tcp_probe_ctx->message);
+ GNUNET_free (tcp_probe_ctx);
return ret;
}
@@ -1951,8 +1866,7 @@
*/
static void
try_connection_reversal (void *cls,
- const struct sockaddr *addr,
- socklen_t addrlen)
+ const struct sockaddr *addr, socklen_t addrlen)
{
struct Plugin *plugin = cls;
struct GNUNET_CONNECTION_Handle *sock;
@@ -1962,37 +1876,34 @@
* We have received an ICMP response, ostensibly from a peer
* that wants to connect to us! Send a message to establish a connection.
*/
- sock = GNUNET_CONNECTION_create_from_sockaddr (AF_INET,
- addr,
- addrlen);
+ sock = GNUNET_CONNECTION_create_from_sockaddr (AF_INET, addr, addrlen);
if (sock == NULL)
- {
- /* failed for some odd reason (out of sockets?); ignore attempt */
- return;
- }
+ {
+ /* failed for some odd reason (out of sockets?); ignore attempt */
+ return;
+ }
/* FIXME: do we need to track these probe context objects so that
- we can clean them up on plugin unload? */
- tcp_probe_ctx
- = GNUNET_malloc(sizeof(struct TCPProbeContext));
+ * we can clean them up on plugin unload? */
+ tcp_probe_ctx = GNUNET_malloc (sizeof (struct TCPProbeContext));
tcp_probe_ctx->message.header.size
- = htons(sizeof(struct TCP_NAT_ProbeMessage));
+ = htons (sizeof (struct TCP_NAT_ProbeMessage));
tcp_probe_ctx->message.header.type
- = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE);
+ = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE);
memcpy (&tcp_probe_ctx->message.clientIdentity,
- plugin->env->my_identity,
- sizeof(struct GNUNET_PeerIdentity));
+ plugin->env->my_identity, sizeof (struct GNUNET_PeerIdentity));
tcp_probe_ctx->plugin = plugin;
tcp_probe_ctx->sock = sock;
GNUNET_CONTAINER_DLL_insert (plugin->probe_head,
- plugin->probe_tail,
- tcp_probe_ctx);
- tcp_probe_ctx->transmit_handle
- = GNUNET_CONNECTION_notify_transmit_ready (sock,
- ntohs
(tcp_probe_ctx->message.header.size),
- GNUNET_TIME_UNIT_FOREVER_REL,
- ¬ify_send_probe,
tcp_probe_ctx);
-
+ plugin->probe_tail, tcp_probe_ctx);
+ tcp_probe_ctx->transmit_handle
+ = GNUNET_CONNECTION_notify_transmit_ready (sock,
+ ntohs (tcp_probe_ctx->
+ message.header.size),
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ ¬ify_send_probe,
+ tcp_probe_ctx);
+
}
@@ -2008,7 +1919,8 @@
static const struct GNUNET_SERVER_MessageHandler my_handlers[] = {
{&handle_tcp_welcome, NULL, GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME,
sizeof (struct WelcomeMessage)},
- {&handle_tcp_nat_probe, NULL, GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE,
sizeof (struct TCP_NAT_ProbeMessage)},
+ {&handle_tcp_nat_probe, NULL, GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE,
+ sizeof (struct TCP_NAT_ProbeMessage)},
{&handle_tcp_data, NULL, GNUNET_MESSAGE_TYPE_ALL, 0},
{NULL, NULL, 0, 0}
};
@@ -2031,42 +1943,41 @@
"MAX_CONNECTIONS",
&max_connections))
max_connections = 128;
-
+
aport = 0;
- if ( (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (env->cfg,
- "transport-tcp",
- "PORT",
- &bport)) ||
- (bport > 65535) ||
- ((GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_number (env->cfg,
- "transport-tcp",
- "ADVERTISED-PORT",
- &aport)) &&
- (aport > 65535)) )
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
- "tcp",
- _("Require valid port number for service `%s' in
configuration!\n"),
- "transport-tcp");
- return NULL;
- }
+ if ((GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_number (env->cfg,
+ "transport-tcp",
+ "PORT",
+ &bport)) ||
+ (bport > 65535) ||
+ ((GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_number (env->cfg,
+ "transport-tcp",
+ "ADVERTISED-PORT",
+ &aport)) && (aport > 65535)))
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
+ "tcp",
+ _
+ ("Require valid port number for service `%s' in
configuration!\n"),
+ "transport-tcp");
+ return NULL;
+ }
if (aport == 0)
aport = bport;
if (bport == 0)
aport = 0;
if (bport != 0)
+ {
+ service = GNUNET_SERVICE_start ("transport-tcp", env->cfg);
+ if (service == NULL)
{
- service = GNUNET_SERVICE_start ("transport-tcp", env->cfg);
- if (service == NULL)
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
- "tcp",
- _("Failed to start service.\n"));
- return NULL;
- }
+ GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
+ "tcp", _("Failed to start service.\n"));
+ return NULL;
}
+ }
else
service = NULL;
@@ -2078,41 +1989,37 @@
plugin->adv_port = aport;
plugin->env = env;
plugin->lsock = NULL;
- if ( (service != NULL) &&
- (GNUNET_SYSERR !=
- (ret = GNUNET_SERVICE_get_server_addresses ("transport-tcp",
- env->cfg,
- &addrs,
- &addrlens))) )
+ if ((service != NULL) &&
+ (GNUNET_SYSERR !=
+ (ret = GNUNET_SERVICE_get_server_addresses ("transport-tcp",
+ env->cfg,
+ &addrs, &addrlens))))
+ {
+ plugin->nat = GNUNET_NAT_register (env->cfg,
+ GNUNET_YES,
+ aport,
+ (unsigned int) ret,
+ (const struct sockaddr **) addrs,
+ addrlens,
+ &tcp_nat_port_map_callback,
+ &try_connection_reversal, plugin);
+ while (ret > 0)
{
- plugin->nat = GNUNET_NAT_register (env->cfg,
- GNUNET_YES,
- aport,
- (unsigned int) ret,
- (const struct sockaddr **) addrs,
- addrlens,
- &tcp_nat_port_map_callback,
- &try_connection_reversal,
- plugin);
- while (ret > 0)
- {
- ret--;
- GNUNET_assert (addrs[ret] != NULL);
- GNUNET_free (addrs[ret]);
- }
- GNUNET_free_non_null (addrs);
- GNUNET_free_non_null (addrlens);
+ ret--;
+ GNUNET_assert (addrs[ret] != NULL);
+ GNUNET_free (addrs[ret]);
}
+ GNUNET_free_non_null (addrs);
+ GNUNET_free_non_null (addrlens);
+ }
else
- {
- plugin->nat = GNUNET_NAT_register (env->cfg,
- GNUNET_YES,
- 0,
- 0, NULL, NULL,
- NULL,
- &try_connection_reversal,
- plugin);
- }
+ {
+ plugin->nat = GNUNET_NAT_register (env->cfg,
+ GNUNET_YES,
+ 0,
+ 0, NULL, NULL,
+ NULL, &try_connection_reversal, plugin);
+ }
api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
api->cls = plugin;
api->send = &tcp_plugin_send;
@@ -2121,32 +2028,31 @@
api->check_address = &tcp_plugin_check_address;
api->address_to_string = &tcp_address_to_string;
plugin->service = service;
- if (service != NULL)
- {
- plugin->server = GNUNET_SERVICE_get_server (service);
- }
+ if (service != NULL)
+ {
+ plugin->server = GNUNET_SERVICE_get_server (service);
+ }
else
+ {
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_time (env->cfg,
+ "transport-tcp",
+ "TIMEOUT", &idle_timeout))
{
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_time (env->cfg,
- "transport-tcp",
- "TIMEOUT",
- &idle_timeout))
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
- "tcp",
- _("Failed to find option %s in section %s!\n"),
- "TIMEOUT",
- "transport-tcp");
- if (plugin->nat != NULL)
- GNUNET_NAT_unregister (plugin->nat);
- GNUNET_free (plugin);
- GNUNET_free (api);
- return NULL;
- }
- plugin->server = GNUNET_SERVER_create_with_sockets
(&plugin_tcp_access_check, plugin, NULL,
- idle_timeout,
GNUNET_YES);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
+ "tcp",
+ _("Failed to find option %s in section %s!\n"),
+ "TIMEOUT", "transport-tcp");
+ if (plugin->nat != NULL)
+ GNUNET_NAT_unregister (plugin->nat);
+ GNUNET_free (plugin);
+ GNUNET_free (api);
+ return NULL;
}
+ plugin->server =
+ GNUNET_SERVER_create_with_sockets (&plugin_tcp_access_check, plugin,
+ NULL, idle_timeout, GNUNET_YES);
+ }
plugin->handlers = GNUNET_malloc (sizeof (my_handlers));
memcpy (plugin->handlers, my_handlers, sizeof (my_handlers));
for (i = 0;
@@ -2154,23 +2060,21 @@
i++)
plugin->handlers[i].callback_cls = plugin;
GNUNET_SERVER_add_handlers (plugin->server, plugin->handlers);
- GNUNET_SERVER_disconnect_notify (plugin->server,
- &disconnect_notify,
- plugin);
- plugin->nat_wait_conns = GNUNET_CONTAINER_multihashmap_create(16);
+ GNUNET_SERVER_disconnect_notify (plugin->server, &disconnect_notify, plugin);
+ plugin->nat_wait_conns = GNUNET_CONTAINER_multihashmap_create (16);
if (bport != 0)
- GNUNET_log_from (GNUNET_ERROR_TYPE_INFO,
- "tcp",
- _("TCP transport listening on port %llu\n"),
- bport);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_INFO,
+ "tcp", _("TCP transport listening on port %llu\n"),
bport);
else
- GNUNET_log_from (GNUNET_ERROR_TYPE_INFO,
- "tcp",
- _("TCP transport not listening on any port (client
only)\n"));
+ GNUNET_log_from (GNUNET_ERROR_TYPE_INFO,
+ "tcp",
+ _
+ ("TCP transport not listening on any port (client
only)\n"));
if (aport != bport)
GNUNET_log_from (GNUNET_ERROR_TYPE_INFO,
- "tcp",
- _("TCP transport advertises itself as being on port
%llu\n"),
+ "tcp",
+ _
+ ("TCP transport advertises itself as being on port
%llu\n"),
aport);
return api;
}
@@ -2197,13 +2101,12 @@
if (plugin->nat != NULL)
GNUNET_NAT_unregister (plugin->nat);
while (NULL != (tcp_probe = plugin->probe_head))
- {
- GNUNET_CONTAINER_DLL_remove (plugin->probe_head,
- plugin->probe_tail,
- tcp_probe);
- GNUNET_CONNECTION_destroy (tcp_probe->sock, GNUNET_NO);
- GNUNET_free (tcp_probe);
- }
+ {
+ GNUNET_CONTAINER_DLL_remove (plugin->probe_head,
+ plugin->probe_tail, tcp_probe);
+ GNUNET_CONNECTION_destroy (tcp_probe->sock, GNUNET_NO);
+ GNUNET_free (tcp_probe);
+ }
GNUNET_CONTAINER_multihashmap_destroy (plugin->nat_wait_conns);
GNUNET_free (plugin);
GNUNET_free (api);
Modified: gnunet/src/transport/plugin_transport_template.c
===================================================================
--- gnunet/src/transport/plugin_transport_template.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/transport/plugin_transport_template.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -152,13 +152,12 @@
*/
static ssize_t
template_plugin_send (void *cls,
- const struct GNUNET_PeerIdentity *
- target,
+ const struct GNUNET_PeerIdentity *target,
const char *msgbuf,
size_t msgbuf_size,
unsigned int priority,
struct GNUNET_TIME_Relative timeout,
- struct Session *session,
+ struct Session *session,
const void *addr,
size_t addrlen,
int force_address,
@@ -166,6 +165,7 @@
cont, void *cont_cls)
{
int bytes_sent = 0;
+
/* struct Plugin *plugin = cls; */
return bytes_sent;
}
@@ -181,8 +181,7 @@
* @param target peer from which to disconnect
*/
static void
-template_plugin_disconnect (void *cls,
- const struct GNUNET_PeerIdentity *target)
+template_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity
*target)
{
// struct Plugin *plugin = cls;
// FIXME
@@ -231,14 +230,12 @@
* and transport
*/
static int
-template_plugin_address_suggested (void *cls,
- const void *addr,
- size_t addrlen)
+template_plugin_address_suggested (void *cls, const void *addr, size_t addrlen)
{
/* struct Plugin *plugin = cls; */
/* check if the address is plausible; if so,
- add it to our list! */
+ * add it to our list! */
return GNUNET_OK;
}
@@ -254,10 +251,8 @@
* @param addrlen length of the address
* @return string representing the same address
*/
-static const char*
-template_plugin_address_to_string (void *cls,
- const void *addr,
- size_t addrlen)
+static const char *
+template_plugin_address_to_string (void *cls, const void *addr, size_t addrlen)
{
GNUNET_break (0);
return NULL;
Modified: gnunet/src/transport/plugin_transport_udp.c
===================================================================
--- gnunet/src/transport/plugin_transport_udp.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/transport/plugin_transport_udp.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -193,7 +193,7 @@
/**
* Node in the defrag heap.
- */
+ */
struct GNUNET_CONTAINER_HeapNode *hnode;
/**
@@ -297,11 +297,10 @@
* @return NULL if we have no session
*/
struct PeerSession *
-find_session (struct Plugin *plugin,
- const struct GNUNET_PeerIdentity *peer)
+find_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *peer)
{
- return GNUNET_CONTAINER_multihashmap_get (plugin->sessions,
- &peer->hashPubKey);
+ return GNUNET_CONTAINER_multihashmap_get (plugin->sessions,
+ &peer->hashPubKey);
}
@@ -322,9 +321,9 @@
if (NULL == session)
return;
GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_remove (plugin->sessions,
- &target->hashPubKey,
- session));
+ GNUNET_CONTAINER_multihashmap_remove (plugin->sessions,
+ &target->hashPubKey,
+ session));
plugin->last_expected_delay = GNUNET_FRAGMENT_context_destroy
(session->frag);
session->cont (session->cont_cls, target, GNUNET_SYSERR);
GNUNET_free (session);
@@ -352,48 +351,43 @@
*/
static ssize_t
udp_send (struct Plugin *plugin,
- const struct sockaddr *sa,
- const struct GNUNET_MessageHeader *msg)
+ const struct sockaddr *sa, const struct GNUNET_MessageHeader *msg)
{
ssize_t sent;
size_t slen;
switch (sa->sa_family)
- {
- case AF_INET:
- if (NULL == plugin->sockv4)
- return 0;
- sent =
- GNUNET_NETWORK_socket_sendto (plugin->sockv4,
- msg,
- ntohs (msg->size),
- sa,
- slen = sizeof (struct sockaddr_in));
- break;
- case AF_INET6:
- if (NULL == plugin->sockv6)
- return 0;
- sent =
- GNUNET_NETWORK_socket_sendto (plugin->sockv6,
- msg,
- ntohs (msg->size),
- sa,
- slen = sizeof (struct sockaddr_in6));
- break;
- default:
- GNUNET_break (0);
+ {
+ case AF_INET:
+ if (NULL == plugin->sockv4)
return 0;
- }
+ sent =
+ GNUNET_NETWORK_socket_sendto (plugin->sockv4,
+ msg,
+ ntohs (msg->size),
+ sa, slen = sizeof (struct sockaddr_in));
+ break;
+ case AF_INET6:
+ if (NULL == plugin->sockv6)
+ return 0;
+ sent =
+ GNUNET_NETWORK_socket_sendto (plugin->sockv6,
+ msg,
+ ntohs (msg->size),
+ sa, slen = sizeof (struct sockaddr_in6));
+ break;
+ default:
+ GNUNET_break (0);
+ return 0;
+ }
if (GNUNET_SYSERR == sent)
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_INFO,
- "sendto");
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_INFO, "sendto");
#if DEBUG_UDP
GNUNET_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");
#endif
return sent;
}
@@ -408,15 +402,12 @@
* @param cls closure, the 'struct PeerSession'
* @param msg the message that was created
*/
-static void
-send_fragment (void *cls,
- const struct GNUNET_MessageHeader *msg)
+static void
+send_fragment (void *cls, const struct GNUNET_MessageHeader *msg)
{
struct PeerSession *session = cls;
- udp_send (session->plugin,
- session->sock_addr,
- msg);
+ udp_send (session->plugin, session->sock_addr, msg);
GNUNET_FRAGMENT_context_transmission_done (session->frag);
}
@@ -447,16 +438,16 @@
*/
static ssize_t
udp_plugin_send (void *cls,
- const struct GNUNET_PeerIdentity *target,
- const char *msgbuf,
- size_t msgbuf_size,
- unsigned int priority,
- struct GNUNET_TIME_Relative timeout,
- struct Session *session,
- const void *addr,
- size_t addrlen,
- int force_address,
- GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
+ const struct GNUNET_PeerIdentity *target,
+ const char *msgbuf,
+ size_t msgbuf_size,
+ unsigned int priority,
+ struct GNUNET_TIME_Relative timeout,
+ struct Session *session,
+ const void *addr,
+ size_t addrlen,
+ int force_address,
+ GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
{
struct Plugin *plugin = cls;
struct PeerSession *peer_session;
@@ -472,50 +463,54 @@
return GNUNET_SYSERR;
GNUNET_assert (NULL == session);
if (mlen >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
switch (addrlen)
+ {
+ case sizeof (struct IPv4UdpAddress):
+ if (NULL == plugin->sockv4)
{
- case sizeof(struct IPv4UdpAddress):
- if (NULL == plugin->sockv4)
- {
- cont (cont_cls, target, GNUNET_SYSERR);
- return 0;
- }
- t4 = addr;
- peer_session = GNUNET_malloc (sizeof (struct PeerSession) + sizeof
(struct sockaddr_in));
- v4 = (struct sockaddr_in*) &peer_session[1];
- v4->sin_family = AF_INET;
+ cont (cont_cls, target, GNUNET_SYSERR);
+ return 0;
+ }
+ t4 = addr;
+ peer_session =
+ GNUNET_malloc (sizeof (struct PeerSession) +
+ sizeof (struct sockaddr_in));
+ v4 = (struct sockaddr_in *) &peer_session[1];
+ v4->sin_family = AF_INET;
#if HAVE_SOCKADDR_IN_SIN_LEN
- v4->sin_len = sizeof (struct sockaddr_in);
+ v4->sin_len = sizeof (struct sockaddr_in);
#endif
- v4->sin_port = t4->u4_port;
- v4->sin_addr.s_addr = t4->ipv4_addr;
- break;
- case sizeof(struct IPv6UdpAddress):
- if (NULL == plugin->sockv6)
- {
- cont (cont_cls, target, GNUNET_SYSERR);
- return 0;
- }
- t6 = addr;
- peer_session = GNUNET_malloc (sizeof (struct PeerSession) + sizeof
(struct sockaddr_in6));
- v6 = (struct sockaddr_in6*) &peer_session[1];
- v6->sin6_family = AF_INET6;
+ v4->sin_port = t4->u4_port;
+ v4->sin_addr.s_addr = t4->ipv4_addr;
+ break;
+ case sizeof (struct IPv6UdpAddress):
+ if (NULL == plugin->sockv6)
+ {
+ cont (cont_cls, target, GNUNET_SYSERR);
+ return 0;
+ }
+ t6 = addr;
+ peer_session =
+ GNUNET_malloc (sizeof (struct PeerSession) +
+ sizeof (struct sockaddr_in6));
+ v6 = (struct sockaddr_in6 *) &peer_session[1];
+ v6->sin6_family = AF_INET6;
#if HAVE_SOCKADDR_IN_SIN_LEN
- v6->sin6_len = sizeof (struct sockaddr_in6);
+ v6->sin6_len = sizeof (struct sockaddr_in6);
#endif
- v6->sin6_port = t6->u6_port;
- v6->sin6_addr = t6->ipv6_addr;
- break;
- default:
- /* Must have a valid address to send to */
- GNUNET_break_op(0);
- return GNUNET_SYSERR;
- }
- udp = (struct UDPMessage*) mbuf;
+ v6->sin6_port = t6->u6_port;
+ v6->sin6_addr = t6->ipv6_addr;
+ break;
+ default:
+ /* Must have a valid address to send to */
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ udp = (struct UDPMessage *) mbuf;
udp->header.size = htons (mlen);
udp->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE);
udp->reserved = htonl (0);
@@ -523,32 +518,30 @@
memcpy (&udp[1], msgbuf, msgbuf_size);
peer_session->target = *target;
peer_session->plugin = plugin;
- peer_session->sock_addr = (const struct sockaddr*) &peer_session[1];
+ peer_session->sock_addr = (const struct sockaddr *) &peer_session[1];
peer_session->cont = cont;
- peer_session->cont_cls = cont_cls;
+ peer_session->cont_cls = cont_cls;
if (mlen <= UDP_MTU)
- {
- mlen = udp_send (plugin,
- peer_session->sock_addr,
- &udp->header);
- cont (cont_cls, target, (mlen > 0) ? GNUNET_OK : GNUNET_SYSERR);
- GNUNET_free (peer_session);
- }
+ {
+ mlen = udp_send (plugin, peer_session->sock_addr, &udp->header);
+ cont (cont_cls, target, (mlen > 0) ? GNUNET_OK : GNUNET_SYSERR);
+ GNUNET_free (peer_session);
+ }
else
- {
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_put (plugin->sessions,
- &target->hashPubKey,
- peer_session,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
- peer_session->frag = GNUNET_FRAGMENT_context_create (plugin->env->stats,
- UDP_MTU,
- &plugin->tracker,
-
plugin->last_expected_delay,
- &udp->header,
- &send_fragment,
- peer_session);
- }
+ {
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONTAINER_multihashmap_put (plugin->sessions,
+ &target->hashPubKey,
+ peer_session,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+ peer_session->frag = GNUNET_FRAGMENT_context_create (plugin->env->stats,
+ UDP_MTU,
+ &plugin->tracker,
+
plugin->last_expected_delay,
+ &udp->header,
+ &send_fragment,
+ peer_session);
+ }
return mlen;
}
@@ -562,7 +555,7 @@
* Sender identity.
*/
struct GNUNET_PeerIdentity sender;
-
+
/**
* Source address.
*/
@@ -585,11 +578,11 @@
*/
static void
process_inbound_tokenized_messages (void *cls,
- void *client,
- const struct GNUNET_MessageHeader *hdr)
+ void *client,
+ const struct GNUNET_MessageHeader *hdr)
{
struct Plugin *plugin = cls;
- struct SourceInformation* si = client;
+ struct SourceInformation *si = client;
struct GNUNET_TRANSPORT_ATS_Information distance[2];
/* setup ATS */
@@ -598,12 +591,8 @@
distance[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
distance[1].value = htonl (0);
- plugin->env->receive (plugin->env->cls,
- &si->sender,
- hdr,
- distance, 2,
- NULL,
- si->arg, si->args);
+ plugin->env->receive (plugin->env->cls,
+ &si->sender, hdr, distance, 2, NULL, si->arg,
si->args);
}
@@ -617,55 +606,56 @@
*/
static void
process_udp_message (struct Plugin *plugin,
- const struct UDPMessage *msg,
- const struct sockaddr *sender_addr,
- socklen_t sender_addr_len)
+ const struct UDPMessage *msg,
+ const struct sockaddr *sender_addr,
+ socklen_t sender_addr_len)
{
struct SourceInformation si;
struct IPv4UdpAddress u4;
struct IPv6UdpAddress u6;
const void *arg;
size_t args;
-
+
if (0 != ntohl (msg->reserved))
- {
- GNUNET_break_op (0);
- return;
- }
- if (ntohs (msg->header.size) < sizeof (struct GNUNET_MessageHeader) + sizeof
(struct UDPMessage))
- {
- GNUNET_break_op (0);
- return;
- }
+ {
+ GNUNET_break_op (0);
+ return;
+ }
+ if (ntohs (msg->header.size) <
+ sizeof (struct GNUNET_MessageHeader) + sizeof (struct UDPMessage))
+ {
+ GNUNET_break_op (0);
+ return;
+ }
/* convert address */
switch (sender_addr->sa_family)
- {
- case AF_INET:
- GNUNET_assert (sender_addr_len == sizeof (struct sockaddr_in));
- u4.ipv4_addr = ((struct sockaddr_in *) sender_addr)->sin_addr.s_addr;
- u4.u4_port = ((struct sockaddr_in *) sender_addr)->sin_port;
- arg = &u4;
- args = sizeof (u4);
- break;
- case AF_INET6:
- GNUNET_assert (sender_addr_len == sizeof (struct sockaddr_in6));
- u6.ipv6_addr = ((struct sockaddr_in6*) sender_addr)->sin6_addr;
- u6.u6_port = ((struct sockaddr_in6 *) sender_addr)->sin6_port;
- arg = &u6;
- args = sizeof (u6);
- break;
- default:
- GNUNET_break (0);
- return;
- }
+ {
+ case AF_INET:
+ GNUNET_assert (sender_addr_len == sizeof (struct sockaddr_in));
+ u4.ipv4_addr = ((struct sockaddr_in *) sender_addr)->sin_addr.s_addr;
+ u4.u4_port = ((struct sockaddr_in *) sender_addr)->sin_port;
+ arg = &u4;
+ args = sizeof (u4);
+ break;
+ case AF_INET6:
+ GNUNET_assert (sender_addr_len == sizeof (struct sockaddr_in6));
+ u6.ipv6_addr = ((struct sockaddr_in6 *) sender_addr)->sin6_addr;
+ u6.u6_port = ((struct sockaddr_in6 *) sender_addr)->sin6_port;
+ arg = &u6;
+ args = sizeof (u6);
+ break;
+ default:
+ GNUNET_break (0);
+ return;
+ }
#if DEBUG_UDP
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "udp",
- "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));
+ "udp",
+ "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
/* iterate over all embedded messages */
@@ -673,11 +663,10 @@
si.arg = arg;
si.args = args;
GNUNET_SERVER_mst_receive (plugin->mst,
- &si,
- (const char*) &msg[1],
- ntohs (msg->header.size) - sizeof (struct
UDPMessage),
- GNUNET_YES,
- GNUNET_NO);
+ &si,
+ (const char *) &msg[1],
+ ntohs (msg->header.size) -
+ sizeof (struct UDPMessage), GNUNET_YES,
GNUNET_NO);
}
@@ -688,26 +677,24 @@
* @param msg the message
*/
static void
-fragment_msg_proc (void *cls,
- const struct GNUNET_MessageHeader *msg)
+fragment_msg_proc (void *cls, const struct GNUNET_MessageHeader *msg)
{
struct ReceiveContext *rc = cls;
if (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE)
- {
- GNUNET_break (0);
- return;
- }
- if (ntohs (msg->size) < sizeof(struct UDPMessage))
- {
- GNUNET_break (0);
- return;
- }
+ {
+ GNUNET_break (0);
+ return;
+ }
+ if (ntohs (msg->size) < sizeof (struct UDPMessage))
+ {
+ GNUNET_break (0);
+ return;
+ }
process_udp_message (rc->plugin,
- (const struct UDPMessage*) msg,
- rc->src_addr,
- rc->addr_len);
-}
+ (const struct UDPMessage *) msg,
+ rc->src_addr, rc->addr_len);
+}
/**
@@ -718,9 +705,7 @@
* @param msg ack to transmit
*/
static void
-ack_proc (void *cls,
- uint32_t id,
- const struct GNUNET_MessageHeader *msg)
+ack_proc (void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg)
{
struct ReceiveContext *rc = cls;
size_t msize = sizeof (struct UDPMessage) + ntohs (msg->size);
@@ -729,22 +714,20 @@
#if DEBUG_UDP
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "udp",
- "Sending ACK to `%s'\n",
- GNUNET_a2s (rc->src_addr,
- (rc->src_addr->sa_family == AF_INET)
- ? sizeof (struct sockaddr_in)
- : sizeof (struct sockaddr_in6)));
+ "udp",
+ "Sending ACK to `%s'\n",
+ GNUNET_a2s (rc->src_addr,
+ (rc->src_addr->sa_family == AF_INET)
+ ? sizeof (struct sockaddr_in)
+ : sizeof (struct sockaddr_in6)));
#endif
- udp = (struct UDPMessage*) buf;
+ udp = (struct UDPMessage *) buf;
udp->header.size = htons ((uint16_t) msize);
udp->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK);
udp->reserved = htonl (0);
udp->sender = *rc->plugin->env->my_identity;
memcpy (&udp[1], msg, ntohs (msg->size));
- (void) udp_send (rc->plugin,
- rc->src_addr,
- &udp->header);
+ (void) udp_send (rc->plugin, rc->src_addr, &udp->header);
}
@@ -782,21 +765,18 @@
*/
static int
find_receive_context (void *cls,
- struct GNUNET_CONTAINER_HeapNode *node,
- void *element,
- GNUNET_CONTAINER_HeapCostType cost)
+ struct GNUNET_CONTAINER_HeapNode *node,
+ void *element, GNUNET_CONTAINER_HeapCostType cost)
{
struct FindReceiveContext *frc = cls;
struct ReceiveContext *e = element;
- if ( (frc->addr_len == e->addr_len) &&
- (0 == memcmp (frc->addr,
- e->src_addr,
- frc->addr_len) ) )
- {
- frc->rc = e;
- return GNUNET_NO;
- }
+ if ((frc->addr_len == e->addr_len) &&
+ (0 == memcmp (frc->addr, e->src_addr, frc->addr_len)))
+ {
+ frc->rc = e;
+ return GNUNET_NO;
+ }
return GNUNET_YES;
}
@@ -808,8 +788,7 @@
* @param rsock socket to read from
*/
static void
-udp_read (struct Plugin *plugin,
- struct GNUNET_NETWORK_Handle *rsock)
+udp_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock)
{
socklen_t fromlen;
char addr[32];
@@ -824,144 +803,142 @@
struct FindReceiveContext frc;
fromlen = sizeof (addr);
- memset (&addr, 0, sizeof(addr));
+ memset (&addr, 0, sizeof (addr));
ret = GNUNET_NETWORK_socket_recvfrom (rsock, buf, sizeof (buf),
- (struct sockaddr *)&addr, &fromlen);
+ (struct sockaddr *) &addr, &fromlen);
if (ret < sizeof (struct GNUNET_MessageHeader))
- {
- GNUNET_break_op (0);
- return;
- }
+ {
+ GNUNET_break_op (0);
+ return;
+ }
#if DEBUG_UDP
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "UDP received %u-byte message from `%s'\n",
- (unsigned int) ret,
- GNUNET_a2s ((const struct sockaddr*) addr, fromlen));
+ "UDP received %u-byte message from `%s'\n",
+ (unsigned int) ret,
+ GNUNET_a2s ((const struct sockaddr *) addr, fromlen));
#endif
msg = (const struct GNUNET_MessageHeader *) buf;
if (ret != ntohs (msg->size))
+ {
+ GNUNET_break_op (0);
+ return;
+ }
+ switch (ntohs (msg->type))
+ {
+ case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE:
+ if (ntohs (msg->size) < sizeof (struct UDPMessage))
{
GNUNET_break_op (0);
return;
}
- switch (ntohs (msg->type))
+ process_udp_message (plugin,
+ (const struct UDPMessage *) msg,
+ (const struct sockaddr *) addr, fromlen);
+ return;
+ case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK:
+ if (ntohs (msg->size) <
+ sizeof (struct UDPMessage) + sizeof (struct GNUNET_MessageHeader))
{
- case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE:
- if (ntohs (msg->size) < sizeof (struct UDPMessage))
- {
- GNUNET_break_op (0);
- return;
- }
- process_udp_message (plugin,
- (const struct UDPMessage *) msg,
- (const struct sockaddr*) addr,
- fromlen);
+ GNUNET_break_op (0);
return;
- case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK:
- if (ntohs (msg->size) < sizeof (struct UDPMessage) + sizeof (struct
GNUNET_MessageHeader))
- {
- GNUNET_break_op (0);
- return;
- }
- udp = (const struct UDPMessage *) msg;
- if (ntohl (udp->reserved) != 0)
- {
- GNUNET_break_op (0);
- return;
- }
- ack = (const struct GNUNET_MessageHeader*) &udp[1];
- if (ntohs (ack->size) != ntohs (msg->size) - sizeof (struct UDPMessage))
- {
- GNUNET_break_op (0);
- return;
- }
+ }
+ udp = (const struct UDPMessage *) msg;
+ if (ntohl (udp->reserved) != 0)
+ {
+ GNUNET_break_op (0);
+ return;
+ }
+ ack = (const struct GNUNET_MessageHeader *) &udp[1];
+ if (ntohs (ack->size) != ntohs (msg->size) - sizeof (struct UDPMessage))
+ {
+ GNUNET_break_op (0);
+ return;
+ }
#if DEBUG_UDP
- GNUNET_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));
+ GNUNET_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));
#endif
- peer_session = find_session (plugin, &udp->sender);
- if (NULL == peer_session)
- {
+ peer_session = find_session (plugin, &udp->sender);
+ if (NULL == peer_session)
+ {
#if DEBUG_UDP
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Session for ACK not found, dropping ACK!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Session for ACK not found, dropping ACK!\n");
#endif
- return;
- }
- if (GNUNET_OK !=
- GNUNET_FRAGMENT_process_ack (peer_session->frag,
- ack))
- return;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_remove (plugin->sessions,
-
&udp->sender.hashPubKey,
- peer_session));
- plugin->last_expected_delay = GNUNET_FRAGMENT_context_destroy
(peer_session->frag);
- peer_session->cont (peer_session->cont_cls,
- &udp->sender,
- GNUNET_OK);
- GNUNET_free (peer_session);
return;
- case GNUNET_MESSAGE_TYPE_FRAGMENT:
- frc.rc = NULL;
- frc.addr = (const struct sockaddr*) addr;
- frc.addr_len = fromlen;
- GNUNET_CONTAINER_heap_iterate (plugin->defrags,
- &find_receive_context,
- &frc);
- now = GNUNET_TIME_absolute_get ();
- rc = frc.rc;
- if (rc == NULL)
- {
- /* need to create a new RC */
- rc = GNUNET_malloc (sizeof (struct ReceiveContext) + fromlen);
- memcpy (&rc[1], addr, fromlen);
- rc->src_addr = (const struct sockaddr*) &rc[1];
- rc->addr_len = fromlen;
- rc->plugin = plugin;
- rc->defrag = GNUNET_DEFRAGMENT_context_create (plugin->env->stats,
- UDP_MTU,
-
UDP_MAX_MESSAGES_IN_DEFRAG,
- rc,
- &fragment_msg_proc,
- &ack_proc);
- rc->hnode = GNUNET_CONTAINER_heap_insert (plugin->defrags,
- rc,
-
(GNUNET_CONTAINER_HeapCostType) now.abs_value);
- }
+ }
+ if (GNUNET_OK != GNUNET_FRAGMENT_process_ack (peer_session->frag, ack))
+ return;
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONTAINER_multihashmap_remove (plugin->sessions,
+ &udp->
+ sender.hashPubKey,
+ peer_session));
+ plugin->last_expected_delay =
+ GNUNET_FRAGMENT_context_destroy (peer_session->frag);
+ peer_session->cont (peer_session->cont_cls, &udp->sender, GNUNET_OK);
+ GNUNET_free (peer_session);
+ return;
+ case GNUNET_MESSAGE_TYPE_FRAGMENT:
+ frc.rc = NULL;
+ frc.addr = (const struct sockaddr *) addr;
+ frc.addr_len = fromlen;
+ GNUNET_CONTAINER_heap_iterate (plugin->defrags,
+ &find_receive_context, &frc);
+ now = GNUNET_TIME_absolute_get ();
+ rc = frc.rc;
+ if (rc == NULL)
+ {
+ /* need to create a new RC */
+ rc = GNUNET_malloc (sizeof (struct ReceiveContext) + fromlen);
+ memcpy (&rc[1], addr, fromlen);
+ rc->src_addr = (const struct sockaddr *) &rc[1];
+ rc->addr_len = fromlen;
+ rc->plugin = plugin;
+ rc->defrag = GNUNET_DEFRAGMENT_context_create (plugin->env->stats,
+ UDP_MTU,
+
UDP_MAX_MESSAGES_IN_DEFRAG,
+ rc,
+ &fragment_msg_proc,
+ &ack_proc);
+ rc->hnode = GNUNET_CONTAINER_heap_insert (plugin->defrags,
+ rc,
+ (GNUNET_CONTAINER_HeapCostType)
+ now.abs_value);
+ }
#if DEBUG_UDP
- GNUNET_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));
+ GNUNET_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))
- {
- /* keep this 'rc' from expiring */
- GNUNET_CONTAINER_heap_update_cost (plugin->defrags,
- rc->hnode,
- (GNUNET_CONTAINER_HeapCostType)
now.abs_value);
- }
- if (GNUNET_CONTAINER_heap_get_size (plugin->defrags) >
UDP_MAX_SENDER_ADDRESSES_WITH_DEFRAG)
- {
- /* remove 'rc' that was inactive the longest */
- rc = GNUNET_CONTAINER_heap_remove_root (plugin->defrags);
- GNUNET_assert (NULL != rc);
- GNUNET_DEFRAGMENT_context_destroy (rc->defrag);
- GNUNET_free (rc);
- }
- return;
- default:
- GNUNET_break_op (0);
- return;
+ if (GNUNET_OK == GNUNET_DEFRAGMENT_process_fragment (rc->defrag, msg))
+ {
+ /* keep this 'rc' from expiring */
+ GNUNET_CONTAINER_heap_update_cost (plugin->defrags,
+ rc->hnode,
+ (GNUNET_CONTAINER_HeapCostType)
+ now.abs_value);
}
+ if (GNUNET_CONTAINER_heap_get_size (plugin->defrags) >
+ UDP_MAX_SENDER_ADDRESSES_WITH_DEFRAG)
+ {
+ /* remove 'rc' that was inactive the longest */
+ rc = GNUNET_CONTAINER_heap_remove_root (plugin->defrags);
+ GNUNET_assert (NULL != rc);
+ GNUNET_DEFRAGMENT_context_destroy (rc->defrag);
+ GNUNET_free (rc);
+ }
+ return;
+ default:
+ GNUNET_break_op (0);
+ return;
+ }
}
@@ -974,28 +951,25 @@
* @param tc the scheduling context (for rescheduling this function again)
*/
static void
-udp_plugin_select (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct Plugin *plugin = cls;
plugin->select_task = GNUNET_SCHEDULER_NO_TASK;
- if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
+ if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
return;
- if ( (NULL != plugin->sockv4) &&
- (GNUNET_NETWORK_fdset_isset (tc->read_ready,
- plugin->sockv4)) )
+ if ((NULL != plugin->sockv4) &&
+ (GNUNET_NETWORK_fdset_isset (tc->read_ready, plugin->sockv4)))
udp_read (plugin, plugin->sockv4);
- if ( (NULL != plugin->sockv6) &&
- (GNUNET_NETWORK_fdset_isset (tc->read_ready,
- plugin->sockv6)) )
+ if ((NULL != plugin->sockv6) &&
+ (GNUNET_NETWORK_fdset_isset (tc->read_ready, plugin->sockv6)))
udp_read (plugin, plugin->sockv6);
plugin->select_task =
- GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
- GNUNET_SCHEDULER_NO_TASK,
- GNUNET_TIME_UNIT_FOREVER_REL, plugin->rs,
- NULL, &udp_plugin_select, plugin);
-
+ GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
+ GNUNET_SCHEDULER_NO_TASK,
+ GNUNET_TIME_UNIT_FOREVER_REL, plugin->rs,
+ NULL, &udp_plugin_select, plugin);
+
}
@@ -1011,8 +985,7 @@
static int
check_port (struct Plugin *plugin, uint16_t in_port)
{
- if ( (in_port == plugin->port) ||
- (in_port == plugin->aport) )
+ if ((in_port == plugin->port) || (in_port == plugin->aport))
return GNUNET_OK;
return GNUNET_SYSERR;
}
@@ -1035,9 +1008,7 @@
*
*/
static int
-udp_plugin_check_address (void *cls,
- const void *addr,
- size_t addrlen)
+udp_plugin_check_address (void *cls, const void *addr, size_t addrlen)
{
struct Plugin *plugin = cls;
struct IPv4UdpAddress *v4;
@@ -1045,37 +1016,35 @@
if ((addrlen != sizeof (struct IPv4UdpAddress)) &&
(addrlen != sizeof (struct IPv6UdpAddress)))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ if (addrlen == sizeof (struct IPv4UdpAddress))
+ {
+ v4 = (struct IPv4UdpAddress *) addr;
+ if (GNUNET_OK != check_port (plugin, ntohs (v4->u4_port)))
+ return GNUNET_SYSERR;
+ if (GNUNET_OK !=
+ GNUNET_NAT_test_address (plugin->nat,
+ &v4->ipv4_addr, sizeof (struct in_addr)))
+ return GNUNET_SYSERR;
+ }
+ else
+ {
+ v6 = (struct IPv6UdpAddress *) addr;
+ if (IN6_IS_ADDR_LINKLOCAL (&v6->ipv6_addr))
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
- if (addrlen == sizeof (struct IPv4UdpAddress))
- {
- v4 = (struct IPv4UdpAddress *) addr;
- if (GNUNET_OK !=
- check_port (plugin, ntohs (v4->u4_port)))
- return GNUNET_SYSERR;
- if (GNUNET_OK !=
- GNUNET_NAT_test_address (plugin->nat,
- &v4->ipv4_addr, sizeof (struct in_addr)))
- return GNUNET_SYSERR;
- }
- else
- {
- v6 = (struct IPv6UdpAddress *) addr;
- if (IN6_IS_ADDR_LINKLOCAL (&v6->ipv6_addr))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- if (GNUNET_OK !=
- check_port (plugin, ntohs (v6->u6_port)))
- return GNUNET_SYSERR;
- if (GNUNET_OK !=
- GNUNET_NAT_test_address (plugin->nat,
- &v6->ipv6_addr, sizeof (struct in6_addr)))
- return GNUNET_SYSERR;
- }
+ if (GNUNET_OK != check_port (plugin, ntohs (v6->u6_port)))
+ return GNUNET_SYSERR;
+ if (GNUNET_OK !=
+ GNUNET_NAT_test_address (plugin->nat,
+ &v6->ipv6_addr, sizeof (struct in6_addr)))
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
}
@@ -1091,10 +1060,8 @@
* @param addrlen length of the address
* @return string representing the same address
*/
-static const char*
-udp_address_to_string (void *cls,
- const void *addr,
- size_t addrlen)
+static const char *
+udp_address_to_string (void *cls, const void *addr, size_t addrlen)
{
static char rbuf[INET6_ADDRSTRLEN + 10];
char buf[INET6_ADDRSTRLEN];
@@ -1107,32 +1074,28 @@
uint16_t port;
if (addrlen == sizeof (struct IPv6UdpAddress))
- {
- t6 = addr;
- af = AF_INET6;
- port = ntohs (t6->u6_port);
- memcpy (&a6, &t6->ipv6_addr, sizeof (a6));
- sb = &a6;
- }
+ {
+ t6 = addr;
+ af = AF_INET6;
+ port = ntohs (t6->u6_port);
+ memcpy (&a6, &t6->ipv6_addr, sizeof (a6));
+ sb = &a6;
+ }
else if (addrlen == sizeof (struct IPv4UdpAddress))
- {
- t4 = addr;
- af = AF_INET;
- port = ntohs (t4->u4_port);
- memcpy (&a4, &t4->ipv4_addr, sizeof (a4));
- sb = &a4;
- }
+ {
+ t4 = addr;
+ af = AF_INET;
+ port = ntohs (t4->u4_port);
+ memcpy (&a4, &t4->ipv4_addr, sizeof (a4));
+ sb = &a4;
+ }
else
- {
- GNUNET_break_op (0);
- return NULL;
- }
+ {
+ GNUNET_break_op (0);
+ return NULL;
+ }
inet_ntop (af, sb, buf, INET6_ADDRSTRLEN);
- GNUNET_snprintf (rbuf,
- sizeof (rbuf),
- "%s:%u",
- buf,
- port);
+ GNUNET_snprintf (rbuf, sizeof (rbuf), "%s:%u", buf, port);
return rbuf;
}
@@ -1172,15 +1135,12 @@
char *ret;
if (hostname == NULL)
- {
- ppc->asc (ppc->asc_cls, NULL);
- GNUNET_free (ppc);
- return;
- }
- GNUNET_asprintf (&ret,
- "%s:%d",
- hostname,
- ppc->port);
+ {
+ ppc->asc (ppc->asc_cls, NULL);
+ GNUNET_free (ppc);
+ return;
+ }
+ GNUNET_asprintf (&ret, "%s:%d", hostname, ppc->port);
ppc->asc (ppc->asc_cls, ret);
GNUNET_free (ret);
}
@@ -1220,50 +1180,45 @@
uint16_t port;
if (addrlen == sizeof (struct IPv6UdpAddress))
- {
- u6 = addr;
- memset (&a6, 0, sizeof (a6));
- a6.sin6_family = AF_INET6;
+ {
+ u6 = addr;
+ memset (&a6, 0, sizeof (a6));
+ a6.sin6_family = AF_INET6;
#if HAVE_SOCKADDR_IN_SIN_LEN
- a6.sin6_len = sizeof (a6);
+ a6.sin6_len = sizeof (a6);
#endif
- a6.sin6_port = u6->u6_port;
- memcpy (&a6.sin6_addr,
- &u6->ipv6_addr,
- sizeof (struct in6_addr));
- port = ntohs (u6->u6_port);
- sb = &a6;
- sbs = sizeof (a6);
- }
+ a6.sin6_port = u6->u6_port;
+ memcpy (&a6.sin6_addr, &u6->ipv6_addr, sizeof (struct in6_addr));
+ port = ntohs (u6->u6_port);
+ sb = &a6;
+ sbs = sizeof (a6);
+ }
else if (addrlen == sizeof (struct IPv4UdpAddress))
- {
- u4 = addr;
- memset (&a4, 0, sizeof (a4));
- a4.sin_family = AF_INET;
+ {
+ u4 = addr;
+ memset (&a4, 0, sizeof (a4));
+ a4.sin_family = AF_INET;
#if HAVE_SOCKADDR_IN_SIN_LEN
- a4.sin_len = sizeof (a4);
+ a4.sin_len = sizeof (a4);
#endif
- a4.sin_port = u4->u4_port;
- a4.sin_addr.s_addr = u4->ipv4_addr;
- port = ntohs (u4->u4_port);
- sb = &a4;
- sbs = sizeof (a4);
- }
+ a4.sin_port = u4->u4_port;
+ a4.sin_addr.s_addr = u4->ipv4_addr;
+ port = ntohs (u4->u4_port);
+ sb = &a4;
+ sbs = sizeof (a4);
+ }
else
- {
- /* invalid address */
- GNUNET_break_op (0);
- asc (asc_cls, NULL);
- return;
- }
+ {
+ /* invalid address */
+ GNUNET_break_op (0);
+ asc (asc_cls, NULL);
+ return;
+ }
ppc = GNUNET_malloc (sizeof (struct PrettyPrinterContext));
ppc->asc = asc;
ppc->asc_cls = asc_cls;
ppc->port = port;
- GNUNET_RESOLVER_hostname_get (sb,
- sbs,
- !numeric, timeout,
- &append_port, ppc);
+ GNUNET_RESOLVER_hostname_get (sb, sbs, !numeric, timeout, &append_port, ppc);
}
@@ -1278,9 +1233,8 @@
*/
static void
udp_nat_port_map_callback (void *cls,
- int add_remove,
- const struct sockaddr *addr,
- socklen_t addrlen)
+ int add_remove,
+ const struct sockaddr *addr, socklen_t addrlen)
{
struct Plugin *plugin = cls;
struct IPv4UdpAddress u4;
@@ -1290,31 +1244,29 @@
/* convert 'addr' to our internal format */
switch (addr->sa_family)
- {
- case AF_INET:
- GNUNET_assert (addrlen == sizeof (struct sockaddr_in));
- u4.ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr;
- u4.u4_port = ((struct sockaddr_in *) addr)->sin_port;
- arg = &u4;
- args = sizeof (u4);
- break;
- case AF_INET6:
- GNUNET_assert (addrlen == sizeof (struct sockaddr_in6));
- memcpy (&u6.ipv6_addr,
- &((struct sockaddr_in6 *) addr)->sin6_addr,
- sizeof (struct in6_addr));
- u6.u6_port = ((struct sockaddr_in6 *) addr)->sin6_port;
- arg = &u6;
- args = sizeof (u6);
- break;
- default:
- GNUNET_break (0);
- return;
- }
+ {
+ case AF_INET:
+ GNUNET_assert (addrlen == sizeof (struct sockaddr_in));
+ u4.ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr;
+ u4.u4_port = ((struct sockaddr_in *) addr)->sin_port;
+ arg = &u4;
+ args = sizeof (u4);
+ break;
+ case AF_INET6:
+ GNUNET_assert (addrlen == sizeof (struct sockaddr_in6));
+ memcpy (&u6.ipv6_addr,
+ &((struct sockaddr_in6 *) addr)->sin6_addr,
+ sizeof (struct in6_addr));
+ u6.u6_port = ((struct sockaddr_in6 *) addr)->sin6_port;
+ arg = &u6;
+ args = sizeof (u6);
+ break;
+ default:
+ GNUNET_break (0);
+ return;
+ }
/* modify our published address list */
- plugin->env->notify_address (plugin->env->cls,
- add_remove,
- arg, args);
+ plugin->env->notify_address (plugin->env->cls, add_remove, arg, args);
}
@@ -1345,38 +1297,32 @@
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_number (env->cfg,
- "transport-udp",
- "PORT",
- &port))
+ "transport-udp", "PORT", &port))
port = 2086;
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_number (env->cfg,
- "transport-udp",
- "MAX_BPS",
- &udp_max_bps))
- udp_max_bps = 1024 * 1024 * 50; /* 50 MB/s == infinity for practical
purposes */
+ "transport-udp",
+ "MAX_BPS", &udp_max_bps))
+ udp_max_bps = 1024 * 1024 * 50; /* 50 MB/s == infinity for practical
purposes */
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_number (env->cfg,
- "transport-udp",
- "ADVERTISED_PORT",
- &aport))
+ "transport-udp",
+ "ADVERTISED_PORT", &aport))
aport = port;
if (port > 65535)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Given `%s' option is out of range: %llu > %u\n"),
- "PORT",
- port,
- 65535);
- return NULL;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Given `%s' option is out of range: %llu > %u\n"),
+ "PORT", port, 65535);
+ return NULL;
+ }
memset (&serverAddrv6, 0, sizeof (serverAddrv6));
memset (&serverAddrv4, 0, sizeof (serverAddrv4));
plugin = GNUNET_malloc (sizeof (struct Plugin));
GNUNET_BANDWIDTH_tracker_init (&plugin->tracker,
- GNUNET_BANDWIDTH_value_init ((uint32_t)
udp_max_bps),
- 30);
+ GNUNET_BANDWIDTH_value_init ((uint32_t)
+ udp_max_bps),
30);
plugin->last_expected_delay = GNUNET_TIME_UNIT_SECONDS;
plugin->port = port;
plugin->aport = aport;
@@ -1390,178 +1336,167 @@
api->address_to_string = &udp_address_to_string;
api->check_address = &udp_plugin_check_address;
- if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string(env->cfg,
- "transport-udp",
- "BINDTO",
-
&plugin->bind4_address))
+ if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (env->cfg,
+ "transport-udp",
+ "BINDTO",
+
&plugin->bind4_address))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Binding udp plugin to specific address: `%s'\n",
+ plugin->bind4_address);
+ if (1 != inet_pton (AF_INET, plugin->bind4_address,
&serverAddrv4.sin_addr))
{
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "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);
- GNUNET_free (plugin);
- GNUNET_free (api);
- return NULL;
- }
+ GNUNET_free (plugin->bind4_address);
+ GNUNET_free (plugin);
+ GNUNET_free (api);
+ return NULL;
}
+ }
- if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string(env->cfg,
- "transport-udp",
- "BINDTO6",
-
&plugin->bind6_address))
+ if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (env->cfg,
+ "transport-udp",
+ "BINDTO6",
+
&plugin->bind6_address))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Binding udp plugin to specific address: `%s'\n",
+ plugin->bind6_address);
+ if (1 != inet_pton (AF_INET6,
+ plugin->bind6_address, &serverAddrv6.sin6_addr))
{
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Binding udp plugin to specific address: `%s'\n",
- plugin->bind6_address);
- if (1 != inet_pton(AF_INET6,
- plugin->bind6_address,
- &serverAddrv6.sin6_addr))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- _("Invalid IPv6 address: `%s'\n"),
- plugin->bind6_address);
- GNUNET_free_non_null (plugin->bind4_address);
- GNUNET_free (plugin->bind6_address);
- GNUNET_free (plugin);
- GNUNET_free (api);
- return NULL;
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Invalid IPv6 address: `%s'\n"), plugin->bind6_address);
+ GNUNET_free_non_null (plugin->bind4_address);
+ GNUNET_free (plugin->bind6_address);
+ GNUNET_free (plugin);
+ GNUNET_free (api);
+ return NULL;
}
+ }
- plugin->defrags = GNUNET_CONTAINER_heap_create
(GNUNET_CONTAINER_HEAP_ORDER_MIN);
- plugin->sessions = GNUNET_CONTAINER_multihashmap_create
(UDP_MAX_SENDER_ADDRESSES_WITH_DEFRAG * 2);
+ plugin->defrags =
+ GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
+ plugin->sessions =
+ GNUNET_CONTAINER_multihashmap_create
(UDP_MAX_SENDER_ADDRESSES_WITH_DEFRAG
+ * 2);
sockets_created = 0;
- if ( (GNUNET_YES !=
- GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg,
- "nat",
- "DISABLEV6")))
+ if ((GNUNET_YES !=
+ GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg,
+ "nat", "DISABLEV6")))
+ {
+ plugin->sockv6 = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_DGRAM, 0);
+ if (NULL == plugin->sockv6)
{
- plugin->sockv6 = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_DGRAM, 0);
- if (NULL == plugin->sockv6)
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "socket");
- }
- else
- {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "socket");
+ }
+ else
+ {
#if HAVE_SOCKADDR_IN_SIN_LEN
- serverAddrv6.sin6_len = sizeof (serverAddrv6);
+ serverAddrv6.sin6_len = sizeof (serverAddrv6);
#endif
- serverAddrv6.sin6_family = AF_INET6;
- serverAddrv6.sin6_addr = in6addr_any;
- serverAddrv6.sin6_port = htons (plugin->port);
- addrlen = sizeof (serverAddrv6);
- serverAddr = (struct sockaddr *) &serverAddrv6;
+ serverAddrv6.sin6_family = AF_INET6;
+ serverAddrv6.sin6_addr = in6addr_any;
+ serverAddrv6.sin6_port = htons (plugin->port);
+ addrlen = sizeof (serverAddrv6);
+ serverAddr = (struct sockaddr *) &serverAddrv6;
#if DEBUG_UDP
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Binding to IPv6 port %d\n",
- ntohs(serverAddrv6.sin6_port));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Binding to IPv6 port %d\n", ntohs (serverAddrv6.sin6_port));
#endif
- tries = 0;
- while (GNUNET_NETWORK_socket_bind (plugin->sockv6,
- serverAddr, addrlen) !=
- GNUNET_OK)
- {
- serverAddrv6.sin6_port
- = htons (GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG,
33537) + 32000); /* Find a good, non-root port */
+ tries = 0;
+ while (GNUNET_NETWORK_socket_bind (plugin->sockv6,
+ serverAddr, addrlen) != GNUNET_OK)
+ {
+ serverAddrv6.sin6_port = htons (GNUNET_CRYPTO_random_u32
(GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a good, non-root
port */
#if DEBUG_UDP
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "IPv6 Binding failed, trying new port %d\n",
- ntohs(serverAddrv6.sin6_port));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "IPv6 Binding failed, trying new port %d\n",
+ ntohs (serverAddrv6.sin6_port));
#endif
- tries++;
- if (tries > 10)
- {
- GNUNET_NETWORK_socket_close (plugin->sockv6);
- plugin->sockv6 = NULL;
- break;
- }
- }
- if (plugin->sockv6 != NULL)
- {
- addrs[sockets_created] = (struct sockaddr*) &serverAddrv6;
- addrlens[sockets_created] = sizeof (serverAddrv6);
- sockets_created++;
- }
- }
+ tries++;
+ if (tries > 10)
+ {
+ GNUNET_NETWORK_socket_close (plugin->sockv6);
+ plugin->sockv6 = NULL;
+ break;
+ }
+ }
+ if (plugin->sockv6 != NULL)
+ {
+ addrs[sockets_created] = (struct sockaddr *) &serverAddrv6;
+ addrlens[sockets_created] = sizeof (serverAddrv6);
+ sockets_created++;
+ }
}
+ }
plugin->mst = GNUNET_SERVER_mst_create (&process_inbound_tokenized_messages,
- plugin);
+ plugin);
plugin->sockv4 = GNUNET_NETWORK_socket_create (PF_INET, SOCK_DGRAM, 0);
if (NULL == plugin->sockv4)
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "socket");
- }
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "socket");
+ }
else
- {
+ {
#if HAVE_SOCKADDR_IN_SIN_LEN
- serverAddrv4.sin_len = sizeof (serverAddrv4);
+ serverAddrv4.sin_len = sizeof (serverAddrv4);
#endif
- serverAddrv4.sin_family = AF_INET;
- serverAddrv4.sin_addr.s_addr = INADDR_ANY;
- serverAddrv4.sin_port = htons (plugin->port);
- addrlen = sizeof (serverAddrv4);
- serverAddr = (struct sockaddr *) &serverAddrv4;
+ serverAddrv4.sin_family = AF_INET;
+ serverAddrv4.sin_addr.s_addr = INADDR_ANY;
+ serverAddrv4.sin_port = htons (plugin->port);
+ addrlen = sizeof (serverAddrv4);
+ serverAddr = (struct sockaddr *) &serverAddrv4;
#if DEBUG_UDP
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Binding to IPv4 port %d\n",
- ntohs(serverAddrv4.sin_port));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Binding to IPv4 port %d\n", ntohs (serverAddrv4.sin_port));
#endif
- tries = 0;
- while (GNUNET_NETWORK_socket_bind (plugin->sockv4, serverAddr, addrlen)
!=
- GNUNET_OK)
- {
- serverAddrv4.sin_port = htons
(GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /*
Find a good, non-root port */
+ tries = 0;
+ while (GNUNET_NETWORK_socket_bind (plugin->sockv4, serverAddr, addrlen) !=
+ GNUNET_OK)
+ {
+ serverAddrv4.sin_port = htons (GNUNET_CRYPTO_random_u32
(GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a good, non-root port
*/
#if DEBUG_UDP
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "IPv4 Binding failed, trying new port %d\n",
- ntohs(serverAddrv4.sin_port));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "IPv4 Binding failed, trying new port %d\n",
+ ntohs (serverAddrv4.sin_port));
#endif
- tries++;
- if (tries > 10)
- {
- GNUNET_NETWORK_socket_close (plugin->sockv4);
- plugin->sockv4 = NULL;
- break;
- }
- }
- if (plugin->sockv4 != NULL)
- {
- addrs[sockets_created] = (struct sockaddr*) &serverAddrv4;
- addrlens[sockets_created] = sizeof (serverAddrv4);
- sockets_created++;
- }
+ tries++;
+ if (tries > 10)
+ {
+ GNUNET_NETWORK_socket_close (plugin->sockv4);
+ plugin->sockv4 = NULL;
+ break;
+ }
}
+ if (plugin->sockv4 != NULL)
+ {
+ addrs[sockets_created] = (struct sockaddr *) &serverAddrv4;
+ addrlens[sockets_created] = sizeof (serverAddrv4);
+ sockets_created++;
+ }
+ }
plugin->rs = GNUNET_NETWORK_fdset_create ();
GNUNET_NETWORK_fdset_zero (plugin->rs);
if (NULL != plugin->sockv4)
- GNUNET_NETWORK_fdset_set (plugin->rs,
- plugin->sockv4);
+ GNUNET_NETWORK_fdset_set (plugin->rs, plugin->sockv4);
if (NULL != plugin->sockv6)
- GNUNET_NETWORK_fdset_set (plugin->rs,
- plugin->sockv6);
+ GNUNET_NETWORK_fdset_set (plugin->rs, plugin->sockv6);
plugin->select_task =
- GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
- GNUNET_SCHEDULER_NO_TASK,
- GNUNET_TIME_UNIT_FOREVER_REL, plugin->rs,
- NULL, &udp_plugin_select, plugin);
+ GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
+ GNUNET_SCHEDULER_NO_TASK,
+ GNUNET_TIME_UNIT_FOREVER_REL, plugin->rs,
+ NULL, &udp_plugin_select, plugin);
if (sockets_created == 0)
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to open UDP sockets\n"));
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Failed to open UDP sockets\n"));
plugin->nat = GNUNET_NAT_register (env->cfg,
- GNUNET_NO,
- port,
- sockets_created,
- (const struct sockaddr**) addrs, addrlens,
- &udp_nat_port_map_callback,
- NULL,
- plugin);
+ GNUNET_NO,
+ port,
+ sockets_created,
+ (const struct sockaddr **) addrs,
addrlens,
+ &udp_nat_port_map_callback, NULL, plugin);
return api;
}
@@ -1575,9 +1510,7 @@
* @return GNUNET_OK (continue to iterate)
*/
static int
-destroy_session (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+destroy_session (void *cls, const GNUNET_HashCode * key, void *value)
{
struct PeerSession *peer_session = value;
@@ -1602,32 +1535,31 @@
/* FIXME: clean up heap and hashmap */
GNUNET_CONTAINER_multihashmap_iterate (plugin->sessions,
- &destroy_session,
- NULL);
+ &destroy_session, NULL);
GNUNET_CONTAINER_multihashmap_destroy (plugin->sessions);
plugin->sessions = NULL;
while (NULL != (rc = GNUNET_CONTAINER_heap_remove_root (plugin->defrags)))
- {
- GNUNET_DEFRAGMENT_context_destroy (rc->defrag);
- GNUNET_free (rc);
- }
+ {
+ GNUNET_DEFRAGMENT_context_destroy (rc->defrag);
+ GNUNET_free (rc);
+ }
GNUNET_CONTAINER_heap_destroy (plugin->defrags);
-
+
if (plugin->select_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (plugin->select_task);
- plugin->select_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (plugin->select_task);
+ plugin->select_task = GNUNET_SCHEDULER_NO_TASK;
+ }
if (plugin->sockv4 != NULL)
- {
- GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv4));
- plugin->sockv4 = NULL;
- }
+ {
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv4));
+ plugin->sockv4 = NULL;
+ }
if (plugin->sockv6 != NULL)
- {
- GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv6));
- plugin->sockv6 = NULL;
- }
+ {
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv6));
+ plugin->sockv6 = NULL;
+ }
GNUNET_SERVER_mst_destroy (plugin->mst);
GNUNET_NETWORK_fdset_destroy (plugin->rs);
GNUNET_NAT_unregister (plugin->nat);
Modified: gnunet/src/transport/plugin_transport_unix.c
===================================================================
--- gnunet/src/transport/plugin_transport_unix.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/transport/plugin_transport_unix.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -375,26 +375,27 @@
pos = retry_list_head;
- while(NULL != (pos = retry_list_head))
+ while (NULL != (pos = retry_list_head))
+ {
+ GNUNET_CONTAINER_DLL_remove (retry_list_head, retry_list_tail, pos);
+ if (GNUNET_SCHEDULER_NO_TASK != pos->retry_ctx->retry_task)
{
- GNUNET_CONTAINER_DLL_remove(retry_list_head, retry_list_tail, pos);
- if (GNUNET_SCHEDULER_NO_TASK != pos->retry_ctx->retry_task)
- {
- GNUNET_SCHEDULER_cancel(pos->retry_ctx->retry_task);
- }
- GNUNET_free(pos->retry_ctx->msg);
- GNUNET_free(pos->retry_ctx->addr);
- GNUNET_free(pos->retry_ctx);
- GNUNET_free(pos);
+ GNUNET_SCHEDULER_cancel (pos->retry_ctx->retry_task);
}
+ GNUNET_free (pos->retry_ctx->msg);
+ GNUNET_free (pos->retry_ctx->addr);
+ GNUNET_free (pos->retry_ctx);
+ GNUNET_free (pos);
+ }
if (plugin->select_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (plugin->select_task);
- plugin->select_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (plugin->select_task);
+ plugin->select_task = GNUNET_SCHEDULER_NO_TASK;
+ }
- GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close
(plugin->unix_sock.desc));
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_NETWORK_socket_close (plugin->unix_sock.desc));
plugin->unix_sock.desc = NULL;
return GNUNET_OK;
@@ -402,18 +403,17 @@
struct PeerSession *
-find_session (struct Plugin *plugin,
- const struct GNUNET_PeerIdentity *peer)
+find_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *peer)
{
struct PeerSession *pos;
pos = plugin->sessions;
while (pos != NULL)
- {
- if (memcmp(&pos->target, peer, sizeof(struct GNUNET_PeerIdentity)) == 0)
- return pos;
- pos = pos->next;
- }
+ {
+ if (memcmp (&pos->target, peer, sizeof (struct GNUNET_PeerIdentity)) == 0)
+ return pos;
+ pos = pos->next;
+ }
return pos;
}
@@ -430,8 +430,7 @@
struct GNUNET_TIME_Relative timeout,
const void *addr,
size_t addrlen,
- GNUNET_TRANSPORT_TransmitContinuation cont,
- void *cont_cls);
+ GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls);
/**
* Retry sending a message.
@@ -439,18 +438,18 @@
* @param cls closure a struct RetrySendContext
* @param tc context information
*/
-void retry_send_message (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext * tc)
+void
+retry_send_message (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct RetrySendContext *retry_ctx = cls;
- if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- {
- GNUNET_free(retry_ctx->msg);
- GNUNET_free(retry_ctx->addr);
- GNUNET_free(retry_ctx);
- return;
- }
+ if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
+ {
+ GNUNET_free (retry_ctx->msg);
+ GNUNET_free (retry_ctx->addr);
+ GNUNET_free (retry_ctx);
+ return;
+ }
unix_real_send (retry_ctx->plugin,
retry_ctx,
@@ -461,9 +460,7 @@
retry_ctx->priority,
GNUNET_TIME_absolute_get_remaining (retry_ctx->timeout),
retry_ctx->addr,
- retry_ctx->addrlen,
- retry_ctx->cont,
- retry_ctx->cont_cls);
+ retry_ctx->addrlen, retry_ctx->cont, retry_ctx->cont_cls);
return;
}
@@ -493,15 +490,14 @@
unix_real_send (void *cls,
struct RetrySendContext *incoming_retry_context,
struct GNUNET_NETWORK_Handle *send_handle,
- const struct GNUNET_PeerIdentity *target,
- const char *msgbuf,
- size_t msgbuf_size,
- unsigned int priority,
- struct GNUNET_TIME_Relative timeout,
- const void *addr,
- size_t addrlen,
- GNUNET_TRANSPORT_TransmitContinuation cont,
- void *cont_cls)
+ const struct GNUNET_PeerIdentity *target,
+ const char *msgbuf,
+ size_t msgbuf_size,
+ unsigned int priority,
+ struct GNUNET_TIME_Relative timeout,
+ const void *addr,
+ size_t addrlen,
+ GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
{
struct Plugin *plugin = cls;
struct UNIXMessage *message;
@@ -516,26 +512,26 @@
int retry;
if (send_handle == NULL)
- {
+ {
#if DEBUG_UNIX
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "unix_real_send with send_handle NULL!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "unix_real_send with send_handle NULL!\n");
#endif
- /* failed to open send socket for AF */
- if (cont != NULL)
- cont (cont_cls, target, GNUNET_SYSERR);
- return 0;
- }
+ /* failed to open send socket for AF */
+ if (cont != NULL)
+ cont (cont_cls, target, GNUNET_SYSERR);
+ return 0;
+ }
if ((addr == NULL) || (addrlen == 0))
- {
+ {
#if DEBUG_UNIX
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "unix_real_send called without address, returning!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "unix_real_send called without address, returning!\n");
#endif
- if (cont != NULL)
- cont (cont_cls, target, GNUNET_SYSERR);
- return 0; /* Can never send if we don't have an address!! */
- }
+ if (cont != NULL)
+ cont (cont_cls, target, GNUNET_SYSERR);
+ return 0; /* Can never send if we don't have an
address!! */
+ }
/* Build the message to be sent */
message = GNUNET_malloc (sizeof (struct UNIXMessage) + msgbuf_size);
@@ -547,13 +543,13 @@
sizeof (struct GNUNET_PeerIdentity));
memcpy (&message[1], msgbuf, msgbuf_size);
- memset(&un, 0, sizeof(un));
+ memset (&un, 0, sizeof (un));
un.sun_family = AF_UNIX;
slen = strlen (addr) + 1;
if (slen >= sizeof (un.sun_path))
slen = sizeof (un.sun_path) - 1;
sent = 0;
- GNUNET_assert(slen < sizeof(un.sun_path));
+ GNUNET_assert (slen < sizeof (un.sun_path));
memcpy (un.sun_path, addr, slen);
un.sun_path[slen] = '\0';
slen = sizeof (struct sockaddr_un);
@@ -563,104 +559,105 @@
#if HAVE_SOCKADDR_IN_SIN_LEN
un.sun_len = (u_char) slen;
#endif
- sb = (struct sockaddr*) &un;
+ sb = (struct sockaddr *) &un;
sbs = slen;
retry = GNUNET_NO;
- sent = GNUNET_NETWORK_socket_sendto(send_handle, message, ssize, sb, sbs);
+ sent = GNUNET_NETWORK_socket_sendto (send_handle, message, ssize, sb, sbs);
if ((GNUNET_SYSERR == sent) && (errno == EAGAIN))
- retry = GNUNET_YES;
+ retry = GNUNET_YES;
if ((GNUNET_SYSERR == sent) && (errno == EMSGSIZE))
{
- socklen_t size = 0;
- socklen_t len = sizeof (size);
- GNUNET_NETWORK_socket_getsockopt ((struct GNUNET_NETWORK_Handle * )
send_handle,
- SOL_SOCKET,
- SO_SNDBUF,
- &size, &len);
+ socklen_t size = 0;
+ socklen_t len = sizeof (size);
- if (size < ssize)
- {
+ GNUNET_NETWORK_socket_getsockopt ((struct GNUNET_NETWORK_Handle *)
+ send_handle, SOL_SOCKET, SO_SNDBUF,
&size,
+ &len);
+
+ if (size < ssize)
+ {
#if DEBUG_UNIX
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Trying to increase socket buffer size from %i to %i for message
size %i\n",
- size,
- ((ssize / 1000) + 2) * 1000, ssize);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Trying to increase socket buffer size from %i to %i for
message size %i\n",
+ size, ((ssize / 1000) + 2) * 1000, ssize);
#endif
- size = ((ssize / 1000) + 2) * 1000;
- if (GNUNET_NETWORK_socket_setsockopt ((struct
GNUNET_NETWORK_Handle * ) send_handle,
- SOL_SOCKET,
- SO_SNDBUF,
- &size, sizeof(size)) == GNUNET_OK)
- retry = GNUNET_YES;
- else
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
"setsockopt");
- }
+ size = ((ssize / 1000) + 2) * 1000;
+ if (GNUNET_NETWORK_socket_setsockopt
+ ((struct GNUNET_NETWORK_Handle *) send_handle, SOL_SOCKET, SO_SNDBUF,
+ &size, sizeof (size)) == GNUNET_OK)
+ retry = GNUNET_YES;
+ else
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "setsockopt");
+ }
}
if (retry == GNUNET_YES)
+ {
+ if (incoming_retry_context == NULL)
{
- if (incoming_retry_context == NULL)
- {
- retry_list_entry = GNUNET_malloc(sizeof(struct RetryList));
- retry_ctx = GNUNET_malloc(sizeof(struct RetrySendContext));
- retry_ctx->addr = GNUNET_malloc(addrlen);
- retry_ctx->msg = GNUNET_malloc(msgbuf_size);
- retry_ctx->plugin = plugin;
- memcpy(retry_ctx->addr, addr, addrlen);
- memcpy(retry_ctx->msg, msgbuf, msgbuf_size);
- retry_ctx->msg_size = msgbuf_size;
- retry_ctx->addrlen = addrlen;
- retry_ctx->send_handle = send_handle;
- retry_ctx->cont = cont;
- retry_ctx->cont_cls = cont_cls;
- retry_ctx->priority = priority;
- retry_ctx->timeout = GNUNET_TIME_relative_to_absolute(timeout);
- memcpy(&retry_ctx->target, target, sizeof(struct
GNUNET_PeerIdentity));
- retry_ctx->delay = GNUNET_TIME_UNIT_MILLISECONDS;
- retry_ctx->retry_list_entry = retry_list_entry;
- retry_list_entry->retry_ctx = retry_ctx;
- GNUNET_CONTAINER_DLL_insert(retry_list_head, retry_list_tail,
retry_list_entry);
- }
- else
- {
- retry_ctx = incoming_retry_context;
- retry_ctx->delay = GNUNET_TIME_relative_multiply(retry_ctx->delay,
2);
- }
- retry_ctx->retry_task = GNUNET_SCHEDULER_add_delayed(retry_ctx->delay,
&retry_send_message, retry_ctx);
-
- //GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, "send");
- GNUNET_free(message);
- return ssize;
+ retry_list_entry = GNUNET_malloc (sizeof (struct RetryList));
+ retry_ctx = GNUNET_malloc (sizeof (struct RetrySendContext));
+ retry_ctx->addr = GNUNET_malloc (addrlen);
+ retry_ctx->msg = GNUNET_malloc (msgbuf_size);
+ retry_ctx->plugin = plugin;
+ memcpy (retry_ctx->addr, addr, addrlen);
+ memcpy (retry_ctx->msg, msgbuf, msgbuf_size);
+ retry_ctx->msg_size = msgbuf_size;
+ retry_ctx->addrlen = addrlen;
+ retry_ctx->send_handle = send_handle;
+ retry_ctx->cont = cont;
+ retry_ctx->cont_cls = cont_cls;
+ retry_ctx->priority = priority;
+ retry_ctx->timeout = GNUNET_TIME_relative_to_absolute (timeout);
+ memcpy (&retry_ctx->target, target, sizeof (struct GNUNET_PeerIdentity));
+ retry_ctx->delay = GNUNET_TIME_UNIT_MILLISECONDS;
+ retry_ctx->retry_list_entry = retry_list_entry;
+ retry_list_entry->retry_ctx = retry_ctx;
+ GNUNET_CONTAINER_DLL_insert (retry_list_head, retry_list_tail,
+ retry_list_entry);
}
+ else
+ {
+ retry_ctx = incoming_retry_context;
+ retry_ctx->delay = GNUNET_TIME_relative_multiply (retry_ctx->delay, 2);
+ }
+ retry_ctx->retry_task =
+ GNUNET_SCHEDULER_add_delayed (retry_ctx->delay, &retry_send_message,
+ retry_ctx);
+
+ //GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, "send");
+ GNUNET_free (message);
+ return ssize;
+ }
#if DEBUG_UNIX
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "UNIX transmit %u-byte message to %s (%d: %s)\n",
- (unsigned int) ssize,
- GNUNET_a2s (sb, sbs),
- (int) sent,
- (sent < 0) ? STRERROR (errno) : "ok");
+ "UNIX transmit %u-byte message to %s (%d: %s)\n",
+ (unsigned int) ssize,
+ GNUNET_a2s (sb, sbs),
+ (int) sent, (sent < 0) ? STRERROR (errno) : "ok");
#endif
if (cont != NULL)
+ {
+ if (sent == GNUNET_SYSERR)
+ cont (cont_cls, target, GNUNET_SYSERR);
+ else
{
- if (sent == GNUNET_SYSERR)
- cont (cont_cls, target, GNUNET_SYSERR);
- else
- {
- cont (cont_cls, target, GNUNET_OK);
- }
+ cont (cont_cls, target, GNUNET_OK);
}
+ }
if (incoming_retry_context != NULL)
- {
- GNUNET_CONTAINER_DLL_remove(retry_list_head, retry_list_tail,
incoming_retry_context->retry_list_entry);
- GNUNET_free(incoming_retry_context->retry_list_entry);
- GNUNET_free(incoming_retry_context->msg);
- GNUNET_free(incoming_retry_context->addr);
- GNUNET_free(incoming_retry_context);
- }
+ {
+ GNUNET_CONTAINER_DLL_remove (retry_list_head, retry_list_tail,
+ incoming_retry_context->retry_list_entry);
+ GNUNET_free (incoming_retry_context->retry_list_entry);
+ GNUNET_free (incoming_retry_context->msg);
+ GNUNET_free (incoming_retry_context->addr);
+ GNUNET_free (incoming_retry_context);
+ }
GNUNET_free (message);
return sent;
@@ -693,16 +690,16 @@
*/
static ssize_t
unix_plugin_send (void *cls,
- const struct GNUNET_PeerIdentity *target,
- const char *msgbuf,
- size_t msgbuf_size,
- unsigned int priority,
- struct GNUNET_TIME_Relative timeout,
- struct Session *session,
- const void *addr,
- size_t addrlen,
- int force_address,
- GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
+ const struct GNUNET_PeerIdentity *target,
+ const char *msgbuf,
+ size_t msgbuf_size,
+ unsigned int priority,
+ struct GNUNET_TIME_Relative timeout,
+ struct Session *session,
+ const void *addr,
+ size_t addrlen,
+ int force_address,
+ GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
{
struct Plugin *plugin = cls;
ssize_t sent;
@@ -712,17 +709,18 @@
GNUNET_assert (NULL == session);
#if DEBUG_UNIX
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Asked to send message to `%s'\n", (char
*)addr);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asked to send message to `%s'\n",
+ (char *) addr);
#endif
- sent = unix_real_send(cls,
- NULL,
- plugin->unix_sock.desc,
- target,
- msgbuf, msgbuf_size,
- priority, timeout, addr, addrlen,
- cont, cont_cls);
+ sent = unix_real_send (cls,
+ NULL,
+ plugin->unix_sock.desc,
+ target,
+ msgbuf, msgbuf_size,
+ priority, timeout, addr, addrlen, cont, cont_cls);
#if DEBUG_UNIX
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sent %d bytes to `%s'\n", sent, (char
*)addr);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent %d bytes to `%s'\n", sent,
+ (char *) addr);
#endif
if (sent == GNUNET_SYSERR)
return 0;
@@ -740,11 +738,10 @@
* @param fromlen the length of the address
*/
static void
-unix_demultiplexer(struct Plugin *plugin,
- struct GNUNET_PeerIdentity *sender,
- const struct GNUNET_MessageHeader *currhdr,
- const struct sockaddr_un *un,
- size_t fromlen)
+unix_demultiplexer (struct Plugin *plugin,
+ struct GNUNET_PeerIdentity *sender,
+ const struct GNUNET_MessageHeader *currhdr,
+ const struct sockaddr_un *un, size_t fromlen)
{
struct GNUNET_TRANSPORT_ATS_Information distance[2];
@@ -753,14 +750,16 @@
distance[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
distance[1].value = htonl (0);
- GNUNET_assert(fromlen >= sizeof(struct sockaddr_un));
+ GNUNET_assert (fromlen >= sizeof (struct sockaddr_un));
#if DEBUG_UNIX
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received message from %s\n",
un->sun_path);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received message from %s\n",
+ un->sun_path);
#endif
plugin->env->receive (plugin->env->cls, sender, currhdr,
- (const struct GNUNET_TRANSPORT_ATS_Information *)
&distance, 2,
- NULL, un->sun_path, strlen(un->sun_path) + 1);
+ (const struct GNUNET_TRANSPORT_ATS_Information *)
+ &distance, 2, NULL, un->sun_path,
+ strlen (un->sun_path) + 1);
}
@@ -774,8 +773,7 @@
*
*/
static void
-unix_plugin_select (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+unix_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct Plugin *plugin = cls;
char buf[65536];
@@ -791,33 +789,35 @@
uint16_t csize;
plugin->select_task = GNUNET_SCHEDULER_NO_TASK;
- if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
+ if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
return;
- addrlen = sizeof(un);
- memset(&un, 0, sizeof(un));
- GNUNET_assert (GNUNET_NETWORK_fdset_isset (tc->read_ready,
plugin->unix_sock.desc));
+ addrlen = sizeof (un);
+ memset (&un, 0, sizeof (un));
+ GNUNET_assert (GNUNET_NETWORK_fdset_isset
+ (tc->read_ready, plugin->unix_sock.desc));
ret =
- GNUNET_NETWORK_socket_recvfrom (plugin->unix_sock.desc, buf, sizeof (buf),
- (struct sockaddr *)&un, &addrlen);
+ GNUNET_NETWORK_socket_recvfrom (plugin->unix_sock.desc, buf, sizeof
(buf),
+ (struct sockaddr *) &un, &addrlen);
if (ret == GNUNET_SYSERR)
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "recvfrom");
- plugin->select_task =
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "recvfrom");
+ plugin->select_task =
GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
GNUNET_SCHEDULER_NO_TASK,
GNUNET_TIME_UNIT_FOREVER_REL, plugin->rs,
NULL, &unix_plugin_select, plugin);
- return;
- }
+ return;
+ }
else
{
#if LINUX
un.sun_path[0] = '/';
#endif
#if DEBUG_UNIX
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Read %d bytes from socket %s\n", ret,
&un.sun_path[0]);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Read %d bytes from socket %s\n", ret,
+ &un.sun_path[0]);
#endif
}
@@ -825,40 +825,38 @@
msg = (struct UNIXMessage *) buf;
csize = ntohs (msg->header.size);
- if ( (csize < sizeof (struct UNIXMessage)) ||
- (csize > ret) )
- {
- GNUNET_break_op (0);
- plugin->select_task =
- GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
- GNUNET_SCHEDULER_NO_TASK,
- GNUNET_TIME_UNIT_FOREVER_REL, plugin->rs,
- NULL, &unix_plugin_select, plugin);
- return;
- }
- msgbuf = (char *)&msg[1];
+ if ((csize < sizeof (struct UNIXMessage)) || (csize > ret))
+ {
+ GNUNET_break_op (0);
+ plugin->select_task =
+ GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
+ GNUNET_SCHEDULER_NO_TASK,
+ GNUNET_TIME_UNIT_FOREVER_REL, plugin->rs,
+ NULL, &unix_plugin_select, plugin);
+ return;
+ }
+ msgbuf = (char *) &msg[1];
memcpy (&sender, &msg->sender, sizeof (struct GNUNET_PeerIdentity));
offset = 0;
tsize = csize - sizeof (struct UNIXMessage);
while (offset + sizeof (struct GNUNET_MessageHeader) <= tsize)
+ {
+ currhdr = (struct GNUNET_MessageHeader *) &msgbuf[offset];
+ csize = ntohs (currhdr->size);
+ if ((csize < sizeof (struct GNUNET_MessageHeader)) ||
+ (csize > tsize - offset))
{
- currhdr = (struct GNUNET_MessageHeader *)&msgbuf[offset];
- csize = ntohs (currhdr->size);
- if ( (csize < sizeof (struct GNUNET_MessageHeader)) ||
- (csize > tsize - offset) )
- {
- GNUNET_break_op (0);
- break;
- }
- unix_demultiplexer(plugin, &sender, currhdr,
- &un, sizeof(un));
- offset += csize;
+ GNUNET_break_op (0);
+ break;
}
+ unix_demultiplexer (plugin, &sender, currhdr, &un, sizeof (un));
+ offset += csize;
+ }
plugin->select_task =
- GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
- GNUNET_SCHEDULER_NO_TASK,
- GNUNET_TIME_UNIT_FOREVER_REL, plugin->rs,
- NULL, &unix_plugin_select, plugin);
+ GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
+ GNUNET_SCHEDULER_NO_TASK,
+ GNUNET_TIME_UNIT_FOREVER_REL, plugin->rs,
+ NULL, &unix_plugin_select, plugin);
}
/**
@@ -876,7 +874,7 @@
struct sockaddr_un un;
size_t slen;
- memset(&un, 0, sizeof(un));
+ memset (&un, 0, sizeof (un));
un.sun_family = AF_UNIX;
slen = strlen (plugin->unix_socket_path) + 1;
if (slen >= sizeof (un.sun_path))
@@ -889,42 +887,40 @@
un.sun_len = (u_char) slen;
#endif
- serverAddr = (struct sockaddr*) &un;
+ serverAddr = (struct sockaddr *) &un;
addrlen = slen;
#if LINUX
un.sun_path[0] = '\0';
#endif
- plugin->unix_sock.desc = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_DGRAM,
0);
+ plugin->unix_sock.desc =
+ GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_DGRAM, 0);
if (NULL == plugin->unix_sock.desc)
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
- return GNUNET_SYSERR;
- }
- if (GNUNET_NETWORK_socket_bind (plugin->unix_sock.desc, serverAddr, addrlen)
!=
- GNUNET_OK)
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind");
- GNUNET_NETWORK_socket_close (plugin->unix_sock.desc);
- plugin->unix_sock.desc = NULL;
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
+ return GNUNET_SYSERR;
+ }
+ if (GNUNET_NETWORK_socket_bind (plugin->unix_sock.desc, serverAddr, addrlen)
+ != GNUNET_OK)
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind");
+ GNUNET_NETWORK_socket_close (plugin->unix_sock.desc);
+ plugin->unix_sock.desc = NULL;
+ return GNUNET_SYSERR;
+ }
#if DEBUG_UNIX
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "unix",
- "Bound to `%s'\n",
- &un.sun_path[0]);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ "unix", "Bound to `%s'\n", &un.sun_path[0]);
#endif
plugin->rs = GNUNET_NETWORK_fdset_create ();
GNUNET_NETWORK_fdset_zero (plugin->rs);
- GNUNET_NETWORK_fdset_set (plugin->rs,
- plugin->unix_sock.desc);
+ GNUNET_NETWORK_fdset_set (plugin->rs, plugin->unix_sock.desc);
plugin->select_task =
- GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
- GNUNET_SCHEDULER_NO_TASK,
- GNUNET_TIME_UNIT_FOREVER_REL, plugin->rs,
- NULL, &unix_plugin_select, plugin);
+ GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
+ GNUNET_SCHEDULER_NO_TASK,
+ GNUNET_TIME_UNIT_FOREVER_REL, plugin->rs,
+ NULL, &unix_plugin_select, plugin);
return 1;
}
@@ -946,15 +942,13 @@
*
*/
static int
-unix_check_address (void *cls,
- const void *addr,
- size_t addrlen)
+unix_check_address (void *cls, const void *addr, size_t addrlen)
{
#if DEBUG_UNIX
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Informing transport service about my address `%s'\n",
- (char *)addr);
+ "Informing transport service about my address `%s'\n",
+ (char *) addr);
#endif
return GNUNET_OK;
}
@@ -970,11 +964,11 @@
char *ret;
if (hostname == NULL)
- {
- ppc->asc (ppc->asc_cls, NULL);
- GNUNET_free (ppc);
- return;
- }
+ {
+ ppc->asc (ppc->asc_cls, NULL);
+ GNUNET_free (ppc);
+ return;
+ }
GNUNET_asprintf (&ret, "%s:%d", hostname, ppc->port);
ppc->asc (ppc->asc_cls, ret);
GNUNET_free (ret);
@@ -997,13 +991,13 @@
*/
static void
unix_plugin_address_pretty_printer (void *cls,
- const char *type,
- const void *addr,
- size_t addrlen,
- int numeric,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_TRANSPORT_AddressStringCallback asc,
- void *asc_cls)
+ const char *type,
+ const void *addr,
+ size_t addrlen,
+ int numeric,
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_TRANSPORT_AddressStringCallback asc,
+ void *asc_cls)
{
struct PrettyPrinterContext *ppc;
const void *sb;
@@ -1015,43 +1009,39 @@
uint16_t port;
if (addrlen == sizeof (struct IPv6UdpAddress))
- {
- u6 = addr;
- memset (&a6, 0, sizeof (a6));
- a6.sin6_family = AF_INET6;
- a6.sin6_port = u6->u6_port;
- memcpy (&a6.sin6_addr,
- &u6->ipv6_addr,
- sizeof (struct in6_addr));
- port = ntohs (u6->u6_port);
- sb = &a6;
- sbs = sizeof (a6);
- }
+ {
+ u6 = addr;
+ memset (&a6, 0, sizeof (a6));
+ a6.sin6_family = AF_INET6;
+ a6.sin6_port = u6->u6_port;
+ memcpy (&a6.sin6_addr, &u6->ipv6_addr, sizeof (struct in6_addr));
+ port = ntohs (u6->u6_port);
+ sb = &a6;
+ sbs = sizeof (a6);
+ }
else if (addrlen == sizeof (struct IPv4UdpAddress))
- {
- u4 = addr;
- memset (&a4, 0, sizeof (a4));
- a4.sin_family = AF_INET;
- a4.sin_port = u4->u_port;
- a4.sin_addr.s_addr = u4->ipv4_addr;
- port = ntohs (u4->u_port);
- sb = &a4;
- sbs = sizeof (a4);
- }
+ {
+ u4 = addr;
+ memset (&a4, 0, sizeof (a4));
+ a4.sin_family = AF_INET;
+ a4.sin_port = u4->u_port;
+ a4.sin_addr.s_addr = u4->ipv4_addr;
+ port = ntohs (u4->u_port);
+ sb = &a4;
+ sbs = sizeof (a4);
+ }
else
- {
- /* invalid address */
- GNUNET_break_op (0);
- asc (asc_cls, NULL);
- return;
- }
+ {
+ /* invalid address */
+ GNUNET_break_op (0);
+ asc (asc_cls, NULL);
+ return;
+ }
ppc = GNUNET_malloc (sizeof (struct PrettyPrinterContext));
ppc->asc = asc;
ppc->asc_cls = asc_cls;
ppc->port = port;
- GNUNET_RESOLVER_hostname_get (sb,
- sbs,
- !numeric, timeout, &append_port, ppc);
+ GNUNET_RESOLVER_hostname_get (sb, sbs, !numeric, timeout, &append_port, ppc);
}
/**
@@ -1065,10 +1055,8 @@
* @param addrlen length of the address
* @return string representing the same address
*/
-static const char*
-unix_address_to_string (void *cls,
- const void *addr,
- size_t addrlen)
+static const char *
+unix_address_to_string (void *cls, const void *addr, size_t addrlen)
{
if ((addr != NULL) && (addrlen > 0))
return (const char *) addr;
@@ -1083,14 +1071,14 @@
* @param tc unused
*/
static void
-address_notification (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+address_notification (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct Plugin *plugin = cls;
- plugin->env->notify_address(plugin->env->cls,
- GNUNET_YES,
- plugin->unix_socket_path,
- strlen(plugin->unix_socket_path) + 1);
+
+ plugin->env->notify_address (plugin->env->cls,
+ GNUNET_YES,
+ plugin->unix_socket_path,
+ strlen (plugin->unix_socket_path) + 1);
}
/**
@@ -1108,17 +1096,14 @@
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_number (env->cfg,
- "transport-unix",
- "PORT",
- &port))
+ "transport-unix", "PORT", &port))
port = UNIX_NAT_DEFAULT_PORT;
plugin = GNUNET_malloc (sizeof (struct Plugin));
plugin->port = port;
plugin->env = env;
- GNUNET_asprintf (&plugin->unix_socket_path,
- "/tmp/unix-plugin-sock.%d",
- plugin->port);
-
+ GNUNET_asprintf (&plugin->unix_socket_path,
+ "/tmp/unix-plugin-sock.%d", plugin->port);
+
api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
api->cls = plugin;
@@ -1129,10 +1114,9 @@
api->check_address = &unix_check_address;
sockets_created = unix_transport_server_start (plugin);
if (sockets_created == 0)
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to open UNIX sockets\n"));
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Failed to open UNIX sockets\n"));
- GNUNET_SCHEDULER_add_now(address_notification, plugin);
+ GNUNET_SCHEDULER_add_now (address_notification, plugin);
return api;
}
Modified: gnunet/src/transport/plugin_transport_wlan.c
===================================================================
--- gnunet/src/transport/plugin_transport_wlan.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/transport/plugin_transport_wlan.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -96,7 +96,7 @@
#define DEBUG_wlan_ip_udp_packets_on_air GNUNET_NO
-#define IEEE80211_ADDR_LEN 6 /* size of 802.11 address */
+#define IEEE80211_ADDR_LEN 6 /* size of 802.11 address */
#define IEEE80211_FC0_VERSION_MASK 0x03
#define IEEE80211_FC0_VERSION_SHIFT 0
@@ -113,25 +113,25 @@
struct iph
{
#if __BYTE_ORDER == __LITTLE_ENDIAN
- unsigned int ip_hl :4; /* header length */
- unsigned int ip_v :4; /* version */
+ unsigned int ip_hl:4; /* header length */
+ unsigned int ip_v:4; /* version */
#endif
#if __BYTE_ORDER == __BIG_ENDIAN
- unsigned int ip_v:4; /* version */
- unsigned int ip_hl:4; /* header length */
+ unsigned int ip_v:4; /* version */
+ unsigned int ip_hl:4; /* header length */
#endif
- u_int8_t ip_tos; /* type of service */
- u_short ip_len; /* total length */
- u_short ip_id; /* identification */
- u_short ip_off; /* fragment offset field */
-#define IP_RF 0x8000 /* reserved fragment flag */
-#define IP_DF 0x4000 /* dont fragment flag */
-#define IP_MF 0x2000 /* more fragments flag */
-#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
- u_int8_t ip_ttl; /* time to live */
- u_int8_t ip_p; /* protocol */
- u_short ip_sum; /* checksum */
- struct in_addr ip_src, ip_dst; /* source and dest address */
+ u_int8_t ip_tos; /* type of service */
+ u_short ip_len; /* total length */
+ u_short ip_id; /* identification */
+ u_short ip_off; /* fragment offset field */
+#define IP_RF 0x8000 /* reserved fragment flag */
+#define IP_DF 0x4000 /* dont fragment flag */
+#define IP_MF 0x2000 /* more fragments flag */
+#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
+ u_int8_t ip_ttl; /* time to live */
+ u_int8_t ip_p; /* protocol */
+ u_short ip_sum; /* checksum */
+ struct in_addr ip_src, ip_dst; /* source and dest address */
};
struct udphdr
@@ -154,11 +154,11 @@
u_int8_t i_addr3[IEEE80211_ADDR_LEN];
u_int8_t i_seq[2];
#if DEBUG_wlan_ip_udp_packets_on_air
-u_int8_t llc[4];
-struct iph ip;
-struct udphdr udp;
+ u_int8_t llc[4];
+ struct iph ip;
+ struct udphdr udp;
#endif
-}GNUNET_PACKED;
+} GNUNET_PACKED;
/**
* Encapsulation of all of the state of the plugin.
@@ -173,12 +173,12 @@
/**
* List of open connections. head
*/
- struct MacEndpoint * mac_head;
+ struct MacEndpoint *mac_head;
/**
* List of open connections. tail
*/
- struct MacEndpoint * mac_tail;
+ struct MacEndpoint *mac_tail;
/**
* Number of connections
@@ -188,12 +188,12 @@
/**
* encapsulation of data from the local wlan helper program
*/
- struct GNUNET_SERVER_MessageStreamTokenizer * suid_tokenizer;
+ struct GNUNET_SERVER_MessageStreamTokenizer *suid_tokenizer;
/**
* encapsulation of packets received from the wlan helper
*/
- struct GNUNET_SERVER_MessageStreamTokenizer * data_tokenizer;
+ struct GNUNET_SERVER_MessageStreamTokenizer *data_tokenizer;
/**
* stdout pipe handle for the gnunet-wlan-helper process
@@ -249,13 +249,13 @@
* Sessions currently pending for transmission
* to a peer, if any.
*/
- struct Sessionqueue * pending_Sessions_head;
+ struct Sessionqueue *pending_Sessions_head;
/**
* Sessions currently pending for transmission
* to a peer (tail), if any.
*/
- struct Sessionqueue * pending_Sessions_tail;
+ struct Sessionqueue *pending_Sessions_tail;
/**
* number of pending sessions
@@ -270,11 +270,11 @@
/**
* messages ready for send, head
*/
- struct FragmentMessage_queue * sending_messages_head;
+ struct FragmentMessage_queue *sending_messages_head;
/**
* messages ready for send, tail
*/
- struct FragmentMessage_queue * sending_messages_tail;
+ struct FragmentMessage_queue *sending_messages_tail;
/**
* time of the next "hello-beacon"
*/
@@ -283,12 +283,12 @@
/**
* queue to send acks for received fragments (head)
*/
- struct AckSendQueue * ack_send_queue_head;
+ struct AckSendQueue *ack_send_queue_head;
/**
* queue to send acks for received fragments (tail)
*/
- struct AckSendQueue * ack_send_queue_tail;
+ struct AckSendQueue *ack_send_queue_tail;
/**
* Tracker for bandwidth limit
@@ -301,9 +301,9 @@
*/
struct Finish_send
{
- struct Plugin * plugin;
- char * msgheader;
- struct GNUNET_MessageHeader * msgstart;
+ struct Plugin *plugin;
+ char *msgheader;
+ struct GNUNET_MessageHeader *msgstart;
ssize_t size;
};
@@ -313,9 +313,9 @@
//TODO DOXIGEN
struct Sessionqueue
{
- struct Sessionqueue * next;
- struct Sessionqueue * prev;
- struct Session * content;
+ struct Sessionqueue *next;
+ struct Sessionqueue *prev;
+ struct Session *content;
};
/**
@@ -324,9 +324,9 @@
//TODO DOXIGEN
struct FragmentMessage_queue
{
- struct FragmentMessage_queue * next;
- struct FragmentMessage_queue * prev;
- struct FragmentMessage * content;
+ struct FragmentMessage_queue *next;
+ struct FragmentMessage_queue *prev;
+ struct FragmentMessage *content;
};
/**
@@ -335,10 +335,10 @@
//TODO DOXIGEN
struct Receive_Fragment_Queue
{
- struct Receive_Fragment_Queue * next;
- struct Receive_Fragment_Queue * prev;
+ struct Receive_Fragment_Queue *next;
+ struct Receive_Fragment_Queue *prev;
uint16_t num;
- const char * msg;
+ const char *msg;
uint16_t size;
struct Radiotap_rx rxinfo;
};
@@ -346,16 +346,16 @@
//TODO DOXIGEN
struct MacEndpoint_id_fragment_triple
{
- struct MacEndpoint * endpoint;
+ struct MacEndpoint *endpoint;
uint32_t message_id;
- struct FragmentMessage * fm;
+ struct FragmentMessage *fm;
};
//TODO DOXIGEN
struct Plugin_Session_pair
{
- struct Plugin * plugin;
- struct Session * session;
+ struct Plugin *plugin;
+ struct Session *session;
};
/**
@@ -367,11 +367,11 @@
/**
* dll next
*/
- struct PendingMessage * next;
+ struct PendingMessage *next;
/**
* dll prev
*/
- struct PendingMessage * prev;
+ struct PendingMessage *prev;
/**
* The pending message
@@ -393,7 +393,7 @@
/**
* Cls for transmit_cont
*/
- void * transmit_cont_cls;
+ void *transmit_cont_cls;
/**
* Timeout value for the pending message.
@@ -411,15 +411,15 @@
/**
* next ack in the ack send queue
*/
- struct AckSendQueue * next;
+ struct AckSendQueue *next;
/**
* previous ack in the ack send queue
*/
- struct AckSendQueue * prev;
+ struct AckSendQueue *prev;
/**
* pointer to the session this ack belongs to
*/
- struct MacEndpoint * endpoint;
+ struct MacEndpoint *endpoint;
/**
* ID of message, to distinguish between the messages, picked randomly.
*/
@@ -428,15 +428,15 @@
/**
* msg to send
*/
- struct GNUNET_MessageHeader * hdr;
+ struct GNUNET_MessageHeader *hdr;
/**
* pointer to the ieee wlan header
*/
- struct ieee80211_frame * ieeewlanheader;
+ struct ieee80211_frame *ieeewlanheader;
/**
* pointer to the radiotap header
*/
- struct Radiotap_Send * radioHeader;
+ struct Radiotap_Send *radioHeader;
};
/**
@@ -448,7 +448,7 @@
/**
* the session this message belongs to
*/
- struct Session * session;
+ struct Session *session;
/**
* peer mac address
*/
@@ -457,7 +457,7 @@
/**
* mac endpoint
*/
- struct MacEndpoint * macendpoint;
+ struct MacEndpoint *macendpoint;
};
/**
@@ -475,13 +475,13 @@
* Message currently pending for transmission
* to this peer, if any. head
*/
- struct PendingMessage * pending_message_head;
+ struct PendingMessage *pending_message_head;
/**
* Message currently pending for transmission
* to this peer, if any. tail
*/
- struct PendingMessage * pending_message_tail;
+ struct PendingMessage *pending_message_tail;
/**
* To whom are we talking to (set to our identity
@@ -509,7 +509,7 @@
/**
* peer connection
*/
- struct MacEndpoint * mac;
+ struct MacEndpoint *mac;
/**
* count of messages in the fragment out queue for this session
@@ -531,22 +531,22 @@
/**
* Struct to hold the session reachable over this mac; head
*/
- struct Sessionqueue * sessions_head;
+ struct Sessionqueue *sessions_head;
/**
* Struct to hold the session reachable over this mac; tail
*/
- struct Sessionqueue * sessions_tail;
+ struct Sessionqueue *sessions_tail;
/**
* Messages currently sending
* to a peer, if any.
*/
- struct FragmentMessage * sending_messages_head;
+ struct FragmentMessage *sending_messages_head;
/**
* Messages currently sending
* to a peer (tail), if any.
*/
- struct FragmentMessage * sending_messages_tail;
+ struct FragmentMessage *sending_messages_tail;
/**
* dll next
*/
@@ -564,7 +564,7 @@
/**
* Defrag context for this mac endpoint
*/
- struct GNUNET_DEFRAGMENT_Context * defrag;
+ struct GNUNET_DEFRAGMENT_Context *defrag;
/**
* count of messages in the fragment out queue for this mac endpoint
@@ -630,7 +630,7 @@
/**
* Fragmentation context
*/
- struct GNUNET_FRAGMENT_Context * fragcontext;
+ struct GNUNET_FRAGMENT_Context *fragcontext;
/**
* Timeout value for the message.
@@ -645,7 +645,7 @@
/**
* Fragment to send
*/
- char * frag;
+ char *frag;
/**
* size of message
@@ -655,20 +655,20 @@
/**
* pointer to the ieee wlan header
*/
- struct ieee80211_frame * ieeewlanheader;
+ struct ieee80211_frame *ieeewlanheader;
/**
* pointer to the radiotap header
*/
- struct Radiotap_Send * radioHeader;
+ struct Radiotap_Send *radioHeader;
};
static void
-do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
+do_transmit (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
static void
-free_session(struct Plugin * plugin, struct Sessionqueue * queue,
- int do_free_macendpoint);
-static struct MacEndpoint *
-create_macendpoint(struct Plugin *plugin, const struct MacAddress *addr);
+free_session (struct Plugin *plugin, struct Sessionqueue *queue,
+ int do_free_macendpoint);
+static struct MacEndpoint *create_macendpoint (struct Plugin *plugin,
+ const struct MacAddress *addr);
/**
* Generates a nice hexdump of a memory area.
@@ -677,51 +677,50 @@
* \param length how many bytes to dump
*/
void
-hexdump(void *mem, unsigned length)
+hexdump (void *mem, unsigned length)
{
char line[80];
- char *src = (char*) mem;
+ char *src = (char *) mem;
- printf(
- "dumping %u bytes from %p\r\n"
- " 0 1 2 3 4 5 6 7 8 9 A B C D E F
0123456789ABCDEF\r\n",
- length, src);
+ printf ("dumping %u bytes from %p\r\n"
+ " 0 1 2 3 4 5 6 7 8 9 A B C D E F
0123456789ABCDEF\r\n",
+ length, src);
unsigned i;
int j;
for (i = 0; i < length; i += 16, src += 16)
+ {
+ char *t = line;
+
+ t += sprintf (t, "%04x: ", i);
+ for (j = 0; j < 16; j++)
{
- char *t = line;
+ if (i + j < length)
+ t += sprintf (t, "%02X", src[j] & 0xff);
+ else
+ t += sprintf (t, " ");
+ t += sprintf (t, j % 2 ? " " : "-");
+ }
- t += sprintf(t, "%04x: ", i);
- for (j = 0; j < 16; j++)
- {
- if (i + j < length)
- t += sprintf(t, "%02X", src[j] & 0xff);
- else
- t += sprintf(t, " ");
- t += sprintf(t, j % 2 ? " " : "-");
- }
+ t += sprintf (t, " ");
+ for (j = 0; j < 16; j++)
+ {
+ if (i + j < length)
+ {
+ if (isprint ((unsigned char) src[j]))
+ t += sprintf (t, "%c", src[j]);
+ else
+ t += sprintf (t, ".");
+ }
+ else
+ {
+ t += sprintf (t, " ");
+ }
+ }
- t += sprintf(t, " ");
- for (j = 0; j < 16; j++)
- {
- if (i + j < length)
- {
- if (isprint((unsigned char)src[j]))
- t += sprintf(t, "%c", src[j]);
- else
- t += sprintf(t, ".");
- }
- else
- {
- t += sprintf(t, " ");
- }
- }
-
- t += sprintf(t, "\r\n");
- printf("%s", line);
- }
+ t += sprintf (t, "\r\n");
+ printf ("%s", line);
+ }
}
/**
@@ -732,28 +731,30 @@
* @return
*/
static struct MacEndpoint *
-get_macendpoint(struct Plugin *plugin, const struct MacAddress *addr,
- int create_new)
+get_macendpoint (struct Plugin *plugin, const struct MacAddress *addr,
+ int create_new)
{
- struct MacEndpoint * queue = plugin->mac_head;
+ struct MacEndpoint *queue = plugin->mac_head;
+
while (queue != NULL)
- {
- GNUNET_assert (queue->sessions_head != NULL);
- if (memcmp(addr, &queue->addr, sizeof(struct MacAddress)) == 0)
- return queue; /* session found */
- queue = queue->next;
- }
+ {
+ GNUNET_assert (queue->sessions_head != NULL);
+ if (memcmp (addr, &queue->addr, sizeof (struct MacAddress)) == 0)
+ return queue; /* session found */
+ queue = queue->next;
+ }
if (create_new == GNUNET_YES)
- {
- return create_macendpoint(plugin, addr);
- }
+ {
+ return create_macendpoint (plugin, addr);
+ }
else
- {
- return NULL;
- }
+ {
+ return NULL;
+ }
}
+
/**
* search for a session with the addr and peer id
*
@@ -763,20 +764,20 @@
* @return returns the session
*/
static struct Session *
-search_session(struct Plugin *plugin, const struct MacEndpoint * endpoint,
- const struct GNUNET_PeerIdentity * peer)
+search_session (struct Plugin *plugin, const struct MacEndpoint *endpoint,
+ const struct GNUNET_PeerIdentity *peer)
{
- GNUNET_assert(endpoint != NULL);
- struct Sessionqueue * queue = endpoint->sessions_head;
+ GNUNET_assert (endpoint != NULL);
+ struct Sessionqueue *queue = endpoint->sessions_head;
while (queue != NULL)
- {
- GNUNET_assert (queue->content != NULL);
- if (memcmp(peer, &queue->content->target,
- sizeof(struct GNUNET_PeerIdentity)) == 0)
- return queue->content; /* session found */
- queue = queue->next;
- }
+ {
+ GNUNET_assert (queue->content != NULL);
+ if (memcmp (peer, &queue->content->target,
+ sizeof (struct GNUNET_PeerIdentity)) == 0)
+ return queue->content; /* session found */
+ queue = queue->next;
+ }
return NULL;
}
@@ -791,21 +792,21 @@
* @param addrlen length of the address
* @return string representing the same address
*/
-static const char*
-wlan_plugin_address_to_string(void *cls, const void *addr, size_t addrlen)
+static const char *
+wlan_plugin_address_to_string (void *cls, const void *addr, size_t addrlen)
{
static char ret[40];
const struct MacAddress *mac;
- if (addrlen != sizeof(struct MacAddress))
- {
- GNUNET_break (0);
- return NULL;
- }
+ if (addrlen != sizeof (struct MacAddress))
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
mac = addr;
- GNUNET_snprintf(ret, sizeof(ret), "%s Mac-Address %X:%X:%X:%X:%X:%X",
- PROTOCOL_PREFIX, mac->mac[0], mac->mac[1], mac->mac[2], mac->mac[3],
- mac->mac[4], mac->mac[5]);
+ GNUNET_snprintf (ret, sizeof (ret), "%s Mac-Address %X:%X:%X:%X:%X:%X",
+ PROTOCOL_PREFIX, mac->mac[0], mac->mac[1], mac->mac[2],
+ mac->mac[3], mac->mac[4], mac->mac[5]);
return ret;
}
@@ -815,25 +816,27 @@
* @param tc pointer to the GNUNET_SCHEDULER_TaskContext
*/
static void
-session_timeout (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc){
- struct Sessionqueue * queue = cls;
- GNUNET_assert(queue != NULL);
+session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ struct Sessionqueue *queue = cls;
+
+ GNUNET_assert (queue != NULL);
queue->content->timeout_task = GNUNET_SCHEDULER_NO_TASK;
- if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN){
- return;
+ if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
+ {
+ return;
}
- if (GNUNET_TIME_absolute_get_remaining(
- GNUNET_TIME_absolute_add(queue->content->last_activity,
SESSION_TIMEOUT)).rel_value
- == 0)
- {
- free_session(queue->content->mac->plugin,queue,GNUNET_YES);
- }
+ if (GNUNET_TIME_absolute_get_remaining
+ (GNUNET_TIME_absolute_add
+ (queue->content->last_activity, SESSION_TIMEOUT)).rel_value == 0)
+ {
+ free_session (queue->content->mac->plugin, queue, GNUNET_YES);
+ }
else
- {
- queue->content->timeout_task =
GNUNET_SCHEDULER_add_delayed(SESSION_TIMEOUT,
- &session_timeout, queue);
- }
+ {
+ queue->content->timeout_task =
+ GNUNET_SCHEDULER_add_delayed (SESSION_TIMEOUT, &session_timeout,
queue);
+ }
}
/**
@@ -845,24 +848,29 @@
*/
static struct Session *
-create_session(struct Plugin *plugin, struct MacEndpoint * endpoint,
- const struct GNUNET_PeerIdentity * peer)
+create_session (struct Plugin *plugin, struct MacEndpoint *endpoint,
+ const struct GNUNET_PeerIdentity *peer)
{
- GNUNET_assert(endpoint != NULL);
- struct Sessionqueue * queue = GNUNET_malloc (sizeof (struct Sessionqueue) +
sizeof (struct Session));
+ GNUNET_assert (endpoint != NULL);
+ struct Sessionqueue *queue =
+ GNUNET_malloc (sizeof (struct Sessionqueue) + sizeof (struct Session));
- GNUNET_CONTAINER_DLL_insert_tail(endpoint->sessions_head,
endpoint->sessions_tail, queue);
+ GNUNET_CONTAINER_DLL_insert_tail (endpoint->sessions_head,
+ endpoint->sessions_tail, queue);
queue->content = (struct Session *) &queue[1];
queue->content->mac = endpoint;
- memcpy(&(queue->content->target), peer, sizeof(struct GNUNET_PeerIdentity));
- queue->content->last_activity = GNUNET_TIME_absolute_get();
- queue->content->timeout_task =
GNUNET_SCHEDULER_add_delayed(SESSION_TIMEOUT,&session_timeout, queue);
+ memcpy (&(queue->content->target), peer, sizeof (struct
GNUNET_PeerIdentity));
+ queue->content->last_activity = GNUNET_TIME_absolute_get ();
+ queue->content->timeout_task =
+ GNUNET_SCHEDULER_add_delayed (SESSION_TIMEOUT, &session_timeout, queue);
#if DEBUG_wlan
- GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, "New session %p
with endpoint %p: %s\n",
- queue->content, endpoint,
- wlan_plugin_address_to_string(NULL, endpoint->addr.mac, 6));
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
+ "New session %p with endpoint %p: %s\n", queue->content,
+ endpoint, wlan_plugin_address_to_string (NULL,
+ endpoint->addr.mac,
+ 6));
#endif
return queue->content;
@@ -877,16 +885,17 @@
* @return returns the session
*/
static struct Session *
-get_session(struct Plugin *plugin, const struct MacAddress *addr,
- const struct GNUNET_PeerIdentity * peer)
+get_session (struct Plugin *plugin, const struct MacAddress *addr,
+ const struct GNUNET_PeerIdentity *peer)
{
- struct MacEndpoint * mac;
- mac = get_macendpoint(plugin, addr, GNUNET_YES);
- struct Session * session = search_session(plugin, mac, peer);
+ struct MacEndpoint *mac;
+ mac = get_macendpoint (plugin, addr, GNUNET_YES);
+ struct Session *session = search_session (plugin, mac, peer);
+
if (session != NULL)
return session;
- return create_session(plugin, mac, peer);
+ return create_session (plugin, mac, peer);
}
/**
@@ -897,35 +906,35 @@
* @param session pointer to the session to add
*/
static void
-queue_session(struct Plugin *plugin, struct Session * session)
+queue_session (struct Plugin *plugin, struct Session *session)
{
- struct Sessionqueue * queue = plugin->pending_Sessions_head;
+ struct Sessionqueue *queue = plugin->pending_Sessions_head;
if (session->pending_message_head != NULL)
+ {
+ while (queue != NULL)
{
- while (queue != NULL)
- {
- // content is never NULL
- GNUNET_assert (queue->content != NULL);
- // is session already in queue?
- if (session == queue->content)
- {
- return;
- }
- // try next
- queue = queue->next;
- }
+ // content is never NULL
+ GNUNET_assert (queue->content != NULL);
+ // is session already in queue?
+ if (session == queue->content)
+ {
+ return;
+ }
+ // try next
+ queue = queue->next;
+ }
- // Session is not in the queue
+ // Session is not in the queue
- queue = GNUNET_malloc (sizeof (struct Sessionqueue));
- queue->content = session;
+ queue = GNUNET_malloc (sizeof (struct Sessionqueue));
+ queue->content = session;
- //insert at the tail
- GNUNET_CONTAINER_DLL_insert_tail(plugin->pending_Sessions_head,
- plugin->pending_Sessions_tail, queue);
- plugin->pendingsessions++;
- }
+ //insert at the tail
+ GNUNET_CONTAINER_DLL_insert_tail (plugin->pending_Sessions_head,
+ plugin->pending_Sessions_tail, queue);
+ plugin->pendingsessions++;
+ }
}
@@ -935,9 +944,10 @@
* @param tc GNUNET_SCHEDULER_TaskContext pointer
*/
static void
-delay_fragment_task(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+delay_fragment_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- struct Plugin * plugin = cls;
+ struct Plugin *plugin = cls;
+
plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK;
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
@@ -945,11 +955,12 @@
// GNUNET_TIME_UNIT_FOREVER_REL is needed to clean up old msg
if (plugin->server_write_task == GNUNET_SCHEDULER_NO_TASK)
- {
- plugin->server_write_task = GNUNET_SCHEDULER_add_write_file(
- GNUNET_TIME_UNIT_FOREVER_REL, plugin->server_stdin_handle,
- &do_transmit, plugin);
- }
+ {
+ plugin->server_write_task =
+ GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ plugin->server_stdin_handle,
+ &do_transmit, plugin);
+ }
}
/**
@@ -958,32 +969,33 @@
*/
static void
-set_next_beacon_time(struct Plugin * const plugin)
+set_next_beacon_time (struct Plugin *const plugin)
{
//under 10 known peers: once a second
if (plugin->mac_count < 10)
- {
- plugin->beacon_time = GNUNET_TIME_absolute_add(
- GNUNET_TIME_absolute_get(),
- GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
- HALLO_BEACON_SCALING_FACTOR));
- }
+ {
+ plugin->beacon_time = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get
(),
+
GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS,
+
HALLO_BEACON_SCALING_FACTOR));
+ }
//under 30 known peers: every 10 seconds
else if (plugin->mac_count < 30)
- {
- plugin->beacon_time = GNUNET_TIME_absolute_add(
- GNUNET_TIME_absolute_get(),
- GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
- 10 * HALLO_BEACON_SCALING_FACTOR));
- }
+ {
+ plugin->beacon_time = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get
(),
+
GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS,
+ 10 *
+
HALLO_BEACON_SCALING_FACTOR));
+ }
//over 30 known peers: once a minute
else
- {
- plugin->beacon_time = GNUNET_TIME_absolute_add(
- GNUNET_TIME_absolute_get(),
- GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES,
- HALLO_BEACON_SCALING_FACTOR));
- }
+ {
+ plugin->beacon_time = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get
(),
+
GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MINUTES,
+
HALLO_BEACON_SCALING_FACTOR));
+ }
}
/**
@@ -992,55 +1004,57 @@
*/
static void
-set_next_send(struct Plugin * const plugin)
+set_next_send (struct Plugin *const plugin)
{
struct GNUNET_TIME_Relative next_send;
//cancel old task
if (plugin->server_write_delay_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel(plugin->server_write_delay_task);
- plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (plugin->server_write_delay_task);
+ plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK;
+ }
//check if some acks are in the queue
if (plugin->ack_send_queue_head != NULL)
- {
- next_send = GNUNET_TIME_UNIT_ZERO;
- }
+ {
+ next_send = GNUNET_TIME_UNIT_ZERO;
+ }
//check if there are some fragments in the queue
else if (plugin->sending_messages_head != NULL)
- {
- next_send = GNUNET_TIME_UNIT_ZERO;
- }
+ {
+ next_send = GNUNET_TIME_UNIT_ZERO;
+ }
else
- {
- next_send = GNUNET_TIME_absolute_get_remaining(plugin->beacon_time);
- }
+ {
+ next_send = GNUNET_TIME_absolute_get_remaining (plugin->beacon_time);
+ }
#if DEBUG_wlan
- GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, "Next packet is
send in: %u\n",
- next_send.rel_value);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
+ "Next packet is send in: %u\n", next_send.rel_value);
#endif
if (next_send.rel_value == GNUNET_TIME_UNIT_ZERO.rel_value)
+ {
+ if (plugin->server_write_task == GNUNET_SCHEDULER_NO_TASK)
{
- if (plugin->server_write_task == GNUNET_SCHEDULER_NO_TASK)
- {
- plugin->server_write_task = GNUNET_SCHEDULER_add_write_file(
- GNUNET_TIME_UNIT_FOREVER_REL, plugin->server_stdin_handle,
- &do_transmit, plugin);
- }
+ plugin->server_write_task =
+ GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ plugin->server_stdin_handle,
+ &do_transmit, plugin);
}
+ }
else
+ {
+ if (plugin->server_write_delay_task == GNUNET_SCHEDULER_NO_TASK)
{
- if (plugin->server_write_delay_task == GNUNET_SCHEDULER_NO_TASK)
- {
- plugin->server_write_delay_task = GNUNET_SCHEDULER_add_delayed(
- next_send, &delay_fragment_task, plugin);
- }
+ plugin->server_write_delay_task =
+ GNUNET_SCHEDULER_add_delayed (next_send, &delay_fragment_task,
+ plugin);
}
+ }
}
/**
@@ -1049,77 +1063,81 @@
* @return pointer to the session found, returns NULL if there is now session
in the queue
*/
static struct Session *
-get_next_queue_session(struct Plugin * plugin)
+get_next_queue_session (struct Plugin *plugin)
{
- struct Session * session;
- struct Sessionqueue * sessionqueue;
- struct Sessionqueue * sessionqueue_alt;
- struct PendingMessage * pm;
+ struct Session *session;
+ struct Sessionqueue *sessionqueue;
+ struct Sessionqueue *sessionqueue_alt;
+ struct PendingMessage *pm;
+
sessionqueue = plugin->pending_Sessions_head;
while (sessionqueue != NULL)
- {
- session = sessionqueue->content;
+ {
+ session = sessionqueue->content;
- GNUNET_assert(session != NULL);
- pm = session->pending_message_head;
+ GNUNET_assert (session != NULL);
+ pm = session->pending_message_head;
#if DEBUG_wlan
- if (pm == NULL)
- {
- GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
- "pending message is empty, should not happen. session %p\n",
- session);
- }
+ if (pm == NULL)
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
+ "pending message is empty, should not happen. session
%p\n",
+ session);
+ }
#endif
- GNUNET_assert(pm != NULL);
+ GNUNET_assert (pm != NULL);
- //check for message timeout
- if (GNUNET_TIME_absolute_get_remaining(pm->timeout).rel_value > 0)
- {
- //check if session has no message in the fragment queue
- if ((session->mac->fragment_messages_out_count
- < FRAGMENT_QUEUE_MESSAGES_OUT_PER_MACENDPOINT)
- && (session->fragment_messages_out_count
- < FRAGMENT_QUEUE_MESSAGES_OUT_PER_SESSION))
- {
- plugin->pendingsessions--;
- GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head,
- plugin->pending_Sessions_tail, sessionqueue);
- GNUNET_free(sessionqueue);
+ //check for message timeout
+ if (GNUNET_TIME_absolute_get_remaining (pm->timeout).rel_value > 0)
+ {
+ //check if session has no message in the fragment queue
+ if ((session->mac->fragment_messages_out_count
+ < FRAGMENT_QUEUE_MESSAGES_OUT_PER_MACENDPOINT)
+ && (session->fragment_messages_out_count
+ < FRAGMENT_QUEUE_MESSAGES_OUT_PER_SESSION))
+ {
+ plugin->pendingsessions--;
+ GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head,
+ plugin->pending_Sessions_tail,
+ sessionqueue);
+ GNUNET_free (sessionqueue);
- return session;
- }
- else
- {
- sessionqueue = sessionqueue->next;
- }
- }
+ return session;
+ }
else
- {
- GNUNET_CONTAINER_DLL_remove(session->pending_message_head,
session->pending_message_tail, pm);
+ {
+ sessionqueue = sessionqueue->next;
+ }
+ }
+ else
+ {
+ GNUNET_CONTAINER_DLL_remove (session->pending_message_head,
+ session->pending_message_tail, pm);
- //call the cont func that it did not work
- if (pm->transmit_cont != NULL)
- pm->transmit_cont(pm->transmit_cont_cls, &(session->target),
- GNUNET_SYSERR);
- GNUNET_free(pm->msg);
- GNUNET_free(pm);
+ //call the cont func that it did not work
+ if (pm->transmit_cont != NULL)
+ pm->transmit_cont (pm->transmit_cont_cls, &(session->target),
+ GNUNET_SYSERR);
+ GNUNET_free (pm->msg);
+ GNUNET_free (pm);
- if (session->pending_message_head == NULL)
- {
- sessionqueue_alt = sessionqueue;
- sessionqueue = sessionqueue->next;
- plugin->pendingsessions--;
- GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head,
- plugin->pending_Sessions_tail, sessionqueue_alt);
+ if (session->pending_message_head == NULL)
+ {
+ sessionqueue_alt = sessionqueue;
+ sessionqueue = sessionqueue->next;
+ plugin->pendingsessions--;
+ GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head,
+ plugin->pending_Sessions_tail,
+ sessionqueue_alt);
- GNUNET_free(sessionqueue_alt);
- }
- }
+ GNUNET_free (sessionqueue_alt);
+ }
+ }
- }
+ }
return NULL;
}
@@ -1129,42 +1147,45 @@
* @param fm message to free
*/
static void
-free_fragment_message(struct Plugin * plugin, struct FragmentMessage * fm)
+free_fragment_message (struct Plugin *plugin, struct FragmentMessage *fm)
{
- struct Session * session = fm->session;
- struct MacEndpoint * endpoint = session->mac;
- struct FragmentMessage_queue * fmq;
- struct FragmentMessage_queue * fmq_next;
+ struct Session *session = fm->session;
+ struct MacEndpoint *endpoint = session->mac;
+ struct FragmentMessage_queue *fmq;
+ struct FragmentMessage_queue *fmq_next;
if (fm != NULL)
+ {
+ fmq = plugin->sending_messages_head;
+ while (fmq != NULL)
{
- fmq = plugin->sending_messages_head;
- while (fmq != NULL)
- {
- 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;
- }
+ 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;
+ }
- (session->mac->fragment_messages_out_count)--;
- session->fragment_messages_out_count--;
- plugin->pending_Fragment_Messages--;
-
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);
- GNUNET_free(fm);
+ (session->mac->fragment_messages_out_count)--;
+ session->fragment_messages_out_count--;
+ plugin->pending_Fragment_Messages--;
+ 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);
+ 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
- }
+ }
}
/**
@@ -1175,22 +1196,22 @@
* @return GNUNET_YES at success
*/
static int
-getRadiotapHeader(struct Plugin * plugin, struct MacEndpoint * endpoint,
- struct Radiotap_Send * header)
+getRadiotapHeader (struct Plugin *plugin, struct MacEndpoint *endpoint,
+ struct Radiotap_Send *header)
{
if (endpoint != NULL)
- {
- header->rate = endpoint->rate;
- header->tx_power = endpoint->tx_power;
- header->antenna = endpoint->antenna;
- }
+ {
+ header->rate = endpoint->rate;
+ header->tx_power = endpoint->tx_power;
+ header->antenna = endpoint->antenna;
+ }
else
- {
- header->rate = 255;
- header->tx_power = 0;
- header->antenna = 0;
- }
+ {
+ header->rate = 255;
+ header->tx_power = 0;
+ header->antenna = 0;
+ }
return GNUNET_YES;
}
@@ -1203,50 +1224,52 @@
* @return GNUNET_YES if there was no error
*/
static int
-getWlanHeader(struct ieee80211_frame * Header,
- const struct MacAddress * to_mac_addr, struct Plugin * plugin,
- unsigned int size)
+getWlanHeader (struct ieee80211_frame *Header,
+ const struct MacAddress *to_mac_addr, struct Plugin *plugin,
+ unsigned int size)
{
- uint16_t * tmp16;
+ uint16_t *tmp16;
const int rate = 11000000;
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, plugin->mac_address.mac,
sizeof(plugin->mac_address));
- memcpy(&Header->i_addr1, to_mac_addr, sizeof(struct MacAddress));
+ memcpy (&Header->i_addr3, &mac_bssid, sizeof (mac_bssid));
+ memcpy (&Header->i_addr2, plugin->mac_address.mac,
+ sizeof (plugin->mac_address));
+ memcpy (&Header->i_addr1, to_mac_addr, sizeof (struct MacAddress));
- tmp16 = (uint16_t*) Header->i_dur;
- *tmp16 = (uint16_t) htole16((size * 1000000) / rate + 290);
+ tmp16 = (uint16_t *) Header->i_dur;
+ *tmp16 = (uint16_t) htole16 ((size * 1000000) / rate + 290);
#if DEBUG_wlan_ip_udp_packets_on_air
uint crc = 0;
- uint16_t * x;
+ uint16_t *x;
int count;
- Header->ip.ip_dst.s_addr = *((uint32_t*) &to_mac_addr->mac[2]);
- Header->ip.ip_src.s_addr = *((uint32_t*) &plugin->mac_address.mac[2]);
+
+ Header->ip.ip_dst.s_addr = *((uint32_t *) & to_mac_addr->mac[2]);
+ Header->ip.ip_src.s_addr = *((uint32_t *) & plugin->mac_address.mac[2]);
Header->ip.ip_v = 4;
Header->ip.ip_hl = 5;
Header->ip.ip_p = 17;
Header->ip.ip_ttl = 1;
- Header->ip.ip_len = htons(size + 8);
+ Header->ip.ip_len = htons (size + 8);
Header->ip.ip_sum = 0;
- x =(uint16_t *) &Header->ip;
- count = sizeof(struct iph);
+ x = (uint16_t *) & Header->ip;
+ count = sizeof (struct iph);
while (count > 1)
- {
- /* This is the inner loop */
- crc += (unsigned short) * x++;
- count -= 2;
- }
+ {
+ /* This is the inner loop */
+ crc += (unsigned short) *x++;
+ count -= 2;
+ }
/* Add left-over byte, if any */
- if( count > 0 )
- crc += * (unsigned char *) x;
+ if (count > 0)
+ crc += *(unsigned char *) x;
crc = (crc & 0xffff) + (crc >> 16);
- Header->ip.ip_sum = htons(~ (unsigned short) crc);
+ Header->ip.ip_sum = htons (~(unsigned short) crc);
Header->llc[0] = 6;
Header->llc[1] = 6;
- Header->udp.len = htons(size - sizeof(struct ieee80211_frame));
+ Header->udp.len = htons (size - sizeof (struct ieee80211_frame));
#endif
@@ -1263,10 +1286,10 @@
*/
uint32_t
-getcrc32(const char *msgbuf, size_t msgbuf_size)
+getcrc32 (const char *msgbuf, size_t msgbuf_size)
{
- return GNUNET_CRYPTO_crc32_n(msgbuf, msgbuf_size);;
+ return GNUNET_CRYPTO_crc32_n (msgbuf, msgbuf_size);;
}
/**
@@ -1279,7 +1302,7 @@
*/
uint16_t
-getcrc16(const char *msgbuf, size_t msgbuf_size)
+getcrc16 (const char *msgbuf, size_t msgbuf_size)
{
//TODO calc some crc
return 0;
@@ -1292,46 +1315,46 @@
*/
void
-add_message_for_send(void *cls, const struct GNUNET_MessageHeader *hdr)
+add_message_for_send (void *cls, const struct GNUNET_MessageHeader *hdr)
{
- struct FragmentMessage * fm = cls;
- struct FragmentMessage_queue * fmqueue;
+ struct FragmentMessage *fm = cls;
+ struct FragmentMessage_queue *fmqueue;
- GNUNET_assert(cls != NULL);
- GNUNET_assert(fm->frag == NULL);
- struct MacEndpoint * endpoint = fm->session->mac;
- struct Plugin * plugin = endpoint->plugin;
- struct GNUNET_MessageHeader * msgheader;
- struct GNUNET_MessageHeader * msgheader2;
+ GNUNET_assert (cls != NULL);
+ GNUNET_assert (fm->frag == NULL);
+ struct MacEndpoint *endpoint = fm->session->mac;
+ struct Plugin *plugin = endpoint->plugin;
+ struct GNUNET_MessageHeader *msgheader;
+ struct GNUNET_MessageHeader *msgheader2;
uint16_t size;
#if DEBUG_wlan_retransmission
- GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
- "Adding fragment of message %p to send, session %p, endpoint %p\n", fm,
- fm->session, endpoint);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
+ "Adding fragment of message %p to send, session %p,
endpoint %p\n",
+ fm, fm->session, endpoint);
#endif
- size = sizeof(struct GNUNET_MessageHeader) + sizeof(struct Radiotap_Send)
- + sizeof(struct ieee80211_frame) + ntohs(hdr->size);
- fm->frag = GNUNET_malloc(size);
+ size = sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_Send)
+ + sizeof (struct ieee80211_frame) + ntohs (hdr->size);
+ fm->frag = GNUNET_malloc (size);
fm->size = size;
msgheader = (struct GNUNET_MessageHeader *) fm->frag;
- msgheader->size = htons(size);
- msgheader->type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
+ msgheader->size = htons (size);
+ msgheader->type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
- fm->radioHeader = (struct Radiotap_Send*) &msgheader[1];
- fm->ieeewlanheader = (struct ieee80211_frame*) &fm->radioHeader[1];
- msgheader2 = (struct GNUNET_MessageHeader*) &fm->ieeewlanheader[1];
- memcpy(msgheader2, hdr, ntohs(hdr->size));
+ fm->radioHeader = (struct Radiotap_Send *) &msgheader[1];
+ fm->ieeewlanheader = (struct ieee80211_frame *) &fm->radioHeader[1];
+ msgheader2 = (struct GNUNET_MessageHeader *) &fm->ieeewlanheader[1];
+ memcpy (msgheader2, hdr, ntohs (hdr->size));
- fmqueue = GNUNET_malloc(sizeof(struct FragmentMessage_queue));
+ fmqueue = GNUNET_malloc (sizeof (struct FragmentMessage_queue));
fmqueue->content = fm;
- GNUNET_CONTAINER_DLL_insert_tail(plugin->sending_messages_head,
- plugin->sending_messages_tail, fmqueue);
- set_next_send(plugin);
+ GNUNET_CONTAINER_DLL_insert_tail (plugin->sending_messages_head,
+ plugin->sending_messages_tail, fmqueue);
+ set_next_send (plugin);
}
/**
@@ -1339,60 +1362,63 @@
* @param plugin pointer to the plugin struct
*/
static void
-send_hello_beacon(struct Plugin * plugin)
+send_hello_beacon (struct Plugin *plugin)
{
#if DEBUG_wlan
- GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, "Sending hello
beacon\n");
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
+ "Sending hello beacon\n");
#endif
uint16_t size;
ssize_t bytes;
uint16_t hallo_size;
- struct GNUNET_MessageHeader * msgheader;
- struct ieee80211_frame * ieeewlanheader;
- struct Radiotap_Send * radioHeader;
- struct GNUNET_MessageHeader * msgheader2;
+ struct GNUNET_MessageHeader *msgheader;
+ struct ieee80211_frame *ieeewlanheader;
+ struct Radiotap_Send *radioHeader;
+ struct GNUNET_MessageHeader *msgheader2;
const struct GNUNET_MessageHeader *hello;
hello = plugin->env->get_our_hello ();
- hallo_size = GNUNET_HELLO_size((struct GNUNET_HELLO_Message*)hello);
- GNUNET_assert(sizeof(struct WlanHeader) + hallo_size <= WLAN_MTU);
- size = sizeof(struct GNUNET_MessageHeader) + sizeof(struct Radiotap_Send)
- + sizeof(struct ieee80211_frame) + sizeof(struct GNUNET_MessageHeader)
+ hallo_size = GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello);
+ GNUNET_assert (sizeof (struct WlanHeader) + hallo_size <= WLAN_MTU);
+ size = sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_Send)
+ + sizeof (struct ieee80211_frame) + sizeof (struct GNUNET_MessageHeader)
+ hallo_size;
- msgheader = GNUNET_malloc(size);
- msgheader->size = htons(size);
- msgheader->type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
+ msgheader = GNUNET_malloc (size);
+ msgheader->size = htons (size);
+ msgheader->type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
- radioHeader = (struct Radiotap_Send*) &msgheader[1];
- getRadiotapHeader(plugin, NULL, radioHeader);
- ieeewlanheader = (struct ieee80211_frame*) &radioHeader[1];
- getWlanHeader(ieeewlanheader, &bc_all_mac, plugin, size);
+ radioHeader = (struct Radiotap_Send *) &msgheader[1];
+ getRadiotapHeader (plugin, NULL, radioHeader);
+ ieeewlanheader = (struct ieee80211_frame *) &radioHeader[1];
+ getWlanHeader (ieeewlanheader, &bc_all_mac, plugin, size);
- msgheader2 = (struct GNUNET_MessageHeader*) &ieeewlanheader[1];
- msgheader2->size = htons(GNUNET_HELLO_size((struct
GNUNET_HELLO_Message*)hello)
- + sizeof(struct GNUNET_MessageHeader));
+ 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);
- memcpy(&msgheader2[1], hello, hallo_size);
+ msgheader2->type = htons (GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT);
+ memcpy (&msgheader2[1], hello, hallo_size);
- bytes = GNUNET_DISK_file_write(plugin->server_stdin_handle, msgheader, size);
+ bytes = GNUNET_DISK_file_write (plugin->server_stdin_handle, msgheader,
size);
if (bytes == GNUNET_SYSERR)
- {
- GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
- _("Error writing to wlan healper. errno == %d, ERROR: %s\n"),
- errno, strerror(errno));
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
+ _
+ ("Error writing to wlan healper. errno == %d, ERROR:
%s\n"),
+ errno, strerror (errno));
- }
- GNUNET_assert(bytes != GNUNET_SYSERR);
- GNUNET_assert(bytes == size);
- GNUNET_free(msgheader);
+ }
+ GNUNET_assert (bytes != GNUNET_SYSERR);
+ GNUNET_assert (bytes == size);
+ GNUNET_free (msgheader);
- set_next_beacon_time(plugin);
- set_next_send(plugin);
+ set_next_beacon_time (plugin);
+ set_next_send (plugin);
}
/**
@@ -1404,50 +1430,50 @@
*/
static void
-add_ack_for_send(void *cls, uint32_t msg_id,
- const struct GNUNET_MessageHeader *hdr)
+add_ack_for_send (void *cls, uint32_t msg_id,
+ const struct GNUNET_MessageHeader *hdr)
{
- struct AckSendQueue * ack;
+ struct AckSendQueue *ack;
- GNUNET_assert(cls != NULL);
- struct MacEndpoint * endpoint = cls;
- struct Plugin * plugin = endpoint->plugin;
- struct GNUNET_MessageHeader * msgheader;
- struct GNUNET_MessageHeader * msgheader2;
+ GNUNET_assert (cls != NULL);
+ struct MacEndpoint *endpoint = cls;
+ struct Plugin *plugin = endpoint->plugin;
+ struct GNUNET_MessageHeader *msgheader;
+ struct GNUNET_MessageHeader *msgheader2;
uint16_t size;
- size = sizeof(struct GNUNET_MessageHeader) + sizeof(struct Radiotap_Send)
- + sizeof(struct ieee80211_frame) + ntohs(hdr->size)
- + sizeof(struct AckSendQueue);
+ size = sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_Send)
+ + sizeof (struct ieee80211_frame) + ntohs (hdr->size)
+ + sizeof (struct AckSendQueue);
- ack = GNUNET_malloc(size);
+ ack = GNUNET_malloc (size);
ack->message_id = msg_id;
ack->endpoint = endpoint;
- size = sizeof(struct GNUNET_MessageHeader) + sizeof(struct Radiotap_Send)
- + sizeof(struct ieee80211_frame) + ntohs(hdr->size);
+ size = sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_Send)
+ + sizeof (struct ieee80211_frame) + ntohs (hdr->size);
msgheader = (struct GNUNET_MessageHeader *) &ack[1];
ack->hdr = (struct GNUNET_MessageHeader *) &ack[1];
- msgheader->size = htons(size);
- msgheader->type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
+ msgheader->size = htons (size);
+ msgheader->type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
- ack->radioHeader = (struct Radiotap_Send*) &msgheader[1];
- ack->ieeewlanheader = (struct ieee80211_frame*) &(ack->radioHeader)[1];
- msgheader2 = (struct GNUNET_MessageHeader*) &(ack->ieeewlanheader)[1];
- memcpy(msgheader2, hdr, ntohs(hdr->size));
+ ack->radioHeader = (struct Radiotap_Send *) &msgheader[1];
+ ack->ieeewlanheader = (struct ieee80211_frame *) &(ack->radioHeader)[1];
+ msgheader2 = (struct GNUNET_MessageHeader *) &(ack->ieeewlanheader)[1];
+ memcpy (msgheader2, hdr, ntohs (hdr->size));
- GNUNET_CONTAINER_DLL_insert_tail(plugin->ack_send_queue_head,
- plugin->ack_send_queue_tail, ack);
+ GNUNET_CONTAINER_DLL_insert_tail (plugin->ack_send_queue_head,
+ plugin->ack_send_queue_tail, ack);
#if DEBUG_wlan_retransmission
- GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
- "Adding ack with message id %u to send, AckSendQueue %p, endpoint %p\n",
- msg_id, ack, endpoint);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
+ "Adding ack with message id %u to send, AckSendQueue %p,
endpoint %p\n",
+ msg_id, ack, endpoint);
#endif
- set_next_send(plugin);
+ set_next_send (plugin);
}
/**
@@ -1457,14 +1483,17 @@
*/
static void
fragmentmessage_timeout (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc){
- struct FragmentMessage * fm = cls;
- GNUNET_assert(fm != NULL);
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ struct FragmentMessage *fm = cls;
+
+ GNUNET_assert (fm != NULL);
fm->timeout_task = GNUNET_SCHEDULER_NO_TASK;
- if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN){
- return;
+ if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
+ {
+ return;
}
- free_fragment_message(fm->session->mac->plugin,fm);
+ free_fragment_message (fm->session->mac->plugin, fm);
}
/**
@@ -1474,66 +1503,75 @@
*/
static void
-check_fragment_queue(struct Plugin * plugin)
+check_fragment_queue (struct Plugin *plugin)
{
- struct Session * session;
- struct FragmentMessage * fm;
+ struct Session *session;
+ struct FragmentMessage *fm;
struct GNUNET_PeerIdentity pid;
- struct PendingMessage * pm;
+ struct PendingMessage *pm;
if (plugin->pending_Fragment_Messages < FRAGMENT_QUEUE_SIZE)
+ {
+ session = get_next_queue_session (plugin);
+ if (session != NULL)
{
- session = get_next_queue_session(plugin);
- if (session != NULL)
- {
- pm = session->pending_message_head;
- GNUNET_CONTAINER_DLL_remove(session->pending_message_head,
session->pending_message_tail, pm);
- session->mac->fragment_messages_out_count++;
- session->fragment_messages_out_count++;
- plugin->pending_Fragment_Messages++;
- GNUNET_assert(pm != NULL);
+ pm = session->pending_message_head;
+ GNUNET_CONTAINER_DLL_remove (session->pending_message_head,
+ session->pending_message_tail, pm);
+ session->mac->fragment_messages_out_count++;
+ session->fragment_messages_out_count++;
+ plugin->pending_Fragment_Messages++;
+ GNUNET_assert (pm != NULL);
- fm = GNUNET_malloc(sizeof(struct FragmentMessage));
- fm->session = session;
- fm->timeout.abs_value = pm->timeout.abs_value;
- fm->frag = NULL;
- fm->fragcontext = GNUNET_FRAGMENT_context_create(plugin->env->stats,
- WLAN_MTU, &plugin->tracker, GNUNET_TIME_UNIT_SECONDS,
- &(pm->msg->header), &add_message_for_send,
- fm);
- fm->timeout_task =
GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_absolute_get_remaining(fm->timeout),fragmentmessage_timeout,fm);
-
GNUNET_CONTAINER_DLL_insert_tail(session->mac->sending_messages_head,session->mac->sending_messages_tail,fm);
+ fm = GNUNET_malloc (sizeof (struct FragmentMessage));
+ fm->session = session;
+ fm->timeout.abs_value = pm->timeout.abs_value;
+ fm->frag = NULL;
+ fm->fragcontext = GNUNET_FRAGMENT_context_create (plugin->env->stats,
+ WLAN_MTU,
+ &plugin->tracker,
+
GNUNET_TIME_UNIT_SECONDS,
+ &(pm->msg->header),
+ &add_message_for_send,
+ fm);
+ fm->timeout_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
+ (fm->timeout), fragmentmessage_timeout,
+ fm);
+ GNUNET_CONTAINER_DLL_insert_tail (session->mac->sending_messages_head,
+ session->mac->sending_messages_tail,
+ fm);
- if (pm->transmit_cont != NULL)
- {
- pid = session->target;
- pm->transmit_cont(pm->transmit_cont_cls, &pid, GNUNET_OK);
+ if (pm->transmit_cont != NULL)
+ {
+ pid = session->target;
+ pm->transmit_cont (pm->transmit_cont_cls, &pid, GNUNET_OK);
#if DEBUG_wlan
- GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
- "called pm->transmit_cont for %p\n", session);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
+ "called pm->transmit_cont for %p\n", session);
#endif
- }
- else
- {
+ }
+ else
+ {
#if DEBUG_wlan
- GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
- "no pm->transmit_cont for %p\n", session);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
+ "no pm->transmit_cont for %p\n", session);
#endif
- }
- GNUNET_free(pm);
+ }
+ GNUNET_free (pm);
- if (session->pending_message_head != NULL)
- {
- //requeue session
- queue_session(plugin, session);
- }
+ if (session->pending_message_head != NULL)
+ {
+ //requeue session
+ queue_session (plugin, session);
+ }
- }
}
+ }
//check if timeout changed
- set_next_send(plugin);
+ set_next_send (plugin);
}
/**
@@ -1542,34 +1580,35 @@
* @param ack pointer to the ack to send
*/
static void
-send_ack(struct Plugin * plugin, struct AckSendQueue * ack)
+send_ack (struct Plugin *plugin, struct AckSendQueue *ack)
{
ssize_t bytes;
#if DEBUG_wlan
- GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
- "Sending ack for message_id %u for mac endpoint %p, size %u\n",
- ack->message_id, ack->endpoint,
- ntohs(ack->hdr->size) - sizeof(struct Radiotap_Send));
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
+ "Sending ack for message_id %u for mac endpoint %p, size
%u\n",
+ ack->message_id, ack->endpoint,
+ ntohs (ack->hdr->size) - sizeof (struct Radiotap_Send));
#endif
- getRadiotapHeader(plugin, ack->endpoint, ack->radioHeader);
- getWlanHeader(ack->ieeewlanheader, &ack->endpoint->addr, plugin,
- ntohs(ack->hdr->size));
+ getRadiotapHeader (plugin, ack->endpoint, ack->radioHeader);
+ getWlanHeader (ack->ieeewlanheader, &ack->endpoint->addr, plugin,
+ ntohs (ack->hdr->size));
- bytes = GNUNET_DISK_file_write(plugin->server_stdin_handle, ack->hdr,
- ntohs(ack->hdr->size));
+ bytes = GNUNET_DISK_file_write (plugin->server_stdin_handle, ack->hdr,
+ ntohs (ack->hdr->size));
if (bytes == GNUNET_SYSERR)
- {
- GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
- _("Error writing to wlan healper. errno == %d, ERROR: %s\n"),
- errno, strerror(errno));
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
+ _
+ ("Error writing to wlan healper. errno == %d, ERROR:
%s\n"),
+ errno, strerror (errno));
- }
- GNUNET_assert(bytes != GNUNET_SYSERR);
- GNUNET_assert(bytes == ntohs(ack->hdr->size));
- set_next_send(plugin);
+ }
+ GNUNET_assert (bytes != GNUNET_SYSERR);
+ GNUNET_assert (bytes == ntohs (ack->hdr->size));
+ set_next_send (plugin);
}
/**
@@ -1578,39 +1617,40 @@
* @param tc TaskContext
*/
static void
-finish_sending(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+finish_sending (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- struct Finish_send * finish = cls;
- struct Plugin * plugin;
+ struct Finish_send *finish = cls;
+ struct Plugin *plugin;
ssize_t bytes;
plugin = finish->plugin;
plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
- {
- GNUNET_free (finish->msgstart);
- GNUNET_free (finish);
- return;
- }
- bytes = GNUNET_DISK_file_write(plugin->server_stdin_handle,
- finish->msgheader, finish->size);
+ {
+ GNUNET_free (finish->msgstart);
+ GNUNET_free (finish);
+ return;
+ }
+ bytes = GNUNET_DISK_file_write (plugin->server_stdin_handle,
+ finish->msgheader, finish->size);
GNUNET_assert (bytes != GNUNET_SYSERR);
if (bytes != finish->size)
- {
- finish->msgheader = finish->msgheader + bytes;
- finish->size = finish->size - bytes;
- plugin->server_write_task = GNUNET_SCHEDULER_add_write_file(
- GNUNET_TIME_UNIT_FOREVER_REL, plugin->server_stdin_handle,
- &finish_sending, finish);
- }
+ {
+ finish->msgheader = finish->msgheader + bytes;
+ finish->size = 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
- {
- GNUNET_free(finish->msgstart);
- GNUNET_free(finish);
- set_next_send(plugin);
- }
+ {
+ GNUNET_free (finish->msgstart);
+ GNUNET_free (finish);
+ set_next_send (plugin);
+ }
}
/**
@@ -1620,96 +1660,99 @@
* @param tc GNUNET_SCHEDULER_TaskContext
*/
static void
-do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_transmit (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- struct Plugin * plugin = cls;
+ struct Plugin *plugin = cls;
plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
return;
- struct Session * session;
- struct FragmentMessage * fm;
- struct Finish_send * finish;
- struct FragmentMessage_queue * fmq;
- struct AckSendQueue * ack;
+ struct Session *session;
+ struct FragmentMessage *fm;
+ struct Finish_send *finish;
+ struct FragmentMessage_queue *fmq;
+ struct AckSendQueue *ack;
ssize_t bytes;
if (plugin->ack_send_queue_head != NULL)
- {
- ack = plugin->ack_send_queue_head;
- GNUNET_CONTAINER_DLL_remove(plugin->ack_send_queue_head,
- plugin->ack_send_queue_tail, ack);
- send_ack(plugin, ack);
- GNUNET_free(ack);
- return;
- }
+ {
+ ack = plugin->ack_send_queue_head;
+ GNUNET_CONTAINER_DLL_remove (plugin->ack_send_queue_head,
+ plugin->ack_send_queue_tail, ack);
+ send_ack (plugin, ack);
+ GNUNET_free (ack);
+ return;
+ }
//test if a "hello-beacon" has to be send
- if (GNUNET_TIME_absolute_get_remaining(plugin->beacon_time).rel_value == 0)
- {
- send_hello_beacon(plugin);
- return;
- }
+ if (GNUNET_TIME_absolute_get_remaining (plugin->beacon_time).rel_value == 0)
+ {
+ send_hello_beacon (plugin);
+ return;
+ }
if (plugin->sending_messages_head != NULL)
- {
- fmq = plugin->sending_messages_head;
- fm = fmq->content;
-
GNUNET_CONTAINER_DLL_remove(plugin->sending_messages_head,plugin->sending_messages_tail,fmq);
- GNUNET_free(fmq);
+ {
+ fmq = plugin->sending_messages_head;
+ fm = fmq->content;
+ GNUNET_CONTAINER_DLL_remove (plugin->sending_messages_head,
+ plugin->sending_messages_tail, fmq);
+ GNUNET_free (fmq);
- session = fm->session;
- GNUNET_assert(session != NULL);
+ session = fm->session;
+ GNUNET_assert (session != NULL);
#if DEBUG_wlan
- GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG,PLUGIN_LOG_NAME,
- "Sending GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT for fragment message %p,
size: %u\n",
- fm, fm->size);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
+ "Sending GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT for fragment
message %p, size: %u\n",
+ fm, fm->size);
#endif
- getRadiotapHeader(plugin, session->mac, fm->radioHeader);
- getWlanHeader(fm->ieeewlanheader, &(fm->session->mac->addr), plugin,
- fm->size);
+ getRadiotapHeader (plugin, session->mac, fm->radioHeader);
+ getWlanHeader (fm->ieeewlanheader, &(fm->session->mac->addr), plugin,
+ fm->size);
- bytes = GNUNET_DISK_file_write(plugin->server_stdin_handle, fm->frag,
- fm->size);
- if (bytes == GNUNET_SYSERR)
- {
- GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
- _("Error writing to wlan healper. errno == %d, ERROR: %s\n"),
- errno, strerror(errno));
+ bytes = GNUNET_DISK_file_write (plugin->server_stdin_handle, fm->frag,
+ fm->size);
+ if (bytes == GNUNET_SYSERR)
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
+ _
+ ("Error writing to wlan healper. errno == %d, ERROR:
%s\n"),
+ errno, strerror (errno));
- }
- GNUNET_assert(bytes != GNUNET_SYSERR);
+ }
+ GNUNET_assert (bytes != GNUNET_SYSERR);
- if (bytes != fm->size)
- {
- finish = GNUNET_malloc(sizeof( struct Finish_send));
- finish->plugin = plugin;
- finish->msgheader = fm->frag + bytes;
- finish->size = fm->size - bytes;
- finish->msgstart = (struct GNUNET_MessageHeader *) fm->frag;
+ if (bytes != fm->size)
+ {
+ finish = GNUNET_malloc (sizeof (struct Finish_send));
+ finish->plugin = plugin;
+ finish->msgheader = fm->frag + bytes;
+ finish->size = fm->size - bytes;
+ finish->msgstart = (struct GNUNET_MessageHeader *) fm->frag;
- GNUNET_assert(plugin->server_write_task == GNUNET_SCHEDULER_NO_TASK);
+ GNUNET_assert (plugin->server_write_task == GNUNET_SCHEDULER_NO_TASK);
- plugin->server_write_task = GNUNET_SCHEDULER_add_write_file(
- GNUNET_TIME_UNIT_FOREVER_REL, plugin->server_stdin_handle,
- &finish_sending, finish);
- fm->frag = NULL;
- }
- else
- {
- GNUNET_free(fm->frag);
- fm->frag = NULL;
- set_next_send(plugin);
- }
- GNUNET_FRAGMENT_context_transmission_done (fm->fragcontext);
- return;
+ plugin->server_write_task =
+ GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ plugin->server_stdin_handle,
+ &finish_sending, finish);
+ fm->frag = NULL;
}
+ else
+ {
+ GNUNET_free (fm->frag);
+ fm->frag = NULL;
+ set_next_send (plugin);
+ }
+ GNUNET_FRAGMENT_context_transmission_done (fm->fragcontext);
+ return;
+ }
- GNUNET_log_from(GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME,
- "do_transmit did nothing, should not happen!\n");
+ GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME,
+ "do_transmit did nothing, should not happen!\n");
}
/**
@@ -1725,21 +1768,21 @@
* and transport
*/
static int
-wlan_plugin_address_suggested(void *cls, const void *addr, size_t addrlen)
+wlan_plugin_address_suggested (void *cls, const void *addr, size_t addrlen)
{
//struct Plugin *plugin = cls;
/* check if the address is plausible; if so,
- add it to our list! */
+ * add it to our list! */
- GNUNET_assert(cls !=NULL);
+ GNUNET_assert (cls != NULL);
//FIXME mitm is not checked
//Mac Address has 6 bytes
if (addrlen == 6)
- {
- /* TODO check for bad addresses like multicast, broadcast, etc */
- return GNUNET_OK;
- }
+ {
+ /* TODO check for bad addresses like multicast, broadcast, etc */
+ return GNUNET_OK;
+ }
return GNUNET_SYSERR;
}
@@ -1771,33 +1814,33 @@
* and does NOT mean that the message was not transmitted (DV)
*/
static ssize_t
-wlan_plugin_send(void *cls, const struct GNUNET_PeerIdentity * target,
- const char *msgbuf, size_t msgbuf_size, unsigned int priority,
- struct GNUNET_TIME_Relative timeout, struct Session *session,
- const void *addr, size_t addrlen, int force_address,
- GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
+wlan_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target,
+ const char *msgbuf, size_t msgbuf_size, unsigned int
priority,
+ struct GNUNET_TIME_Relative timeout, struct Session *session,
+ const void *addr, size_t addrlen, int force_address,
+ GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
{
- struct Plugin * plugin = cls;
- struct PendingMessage * newmsg;
- struct WlanHeader * wlanheader;
+ struct Plugin *plugin = cls;
+ struct PendingMessage *newmsg;
+ struct WlanHeader *wlanheader;
//check if msglen > 0
- GNUNET_assert(msgbuf_size > 0);
+ GNUNET_assert (msgbuf_size > 0);
//get session if needed
if (session == NULL)
+ {
+ if (wlan_plugin_address_suggested (plugin, addr, addrlen) == GNUNET_OK)
{
- if (wlan_plugin_address_suggested(plugin, addr, addrlen) == GNUNET_OK)
- {
- session = get_session(plugin, addr, target);
- }
- else
- {
- GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
- _("Wlan Address len %d is wrong\n"), addrlen);
- return -1;
- }
+ session = get_session (plugin, addr, target);
}
+ else
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
+ _("Wlan Address len %d is wrong\n"), addrlen);
+ return -1;
+ }
+ }
//queue message:
@@ -1805,50 +1848,53 @@
//test if there is no other message in the "queue"
//FIXME: to many send requests
if (session->pending_message_head != NULL)
- {
- newmsg = session->pending_message_head;
- GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
- "wlan_plugin_send: a pending message is already in the queue for
this client\n remaining time to send this message is %u, queued fragment
messages for this mac connection %u\n",
- GNUNET_TIME_absolute_get_remaining(newmsg->timeout).rel_value,
- session->mac->fragment_messages_out_count);
- }
+ {
+ newmsg = session->pending_message_head;
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
+ "wlan_plugin_send: a pending message is already in the
queue for this client\n remaining time to send this message is %u, queued
fragment messages for this mac connection %u\n",
+ GNUNET_TIME_absolute_get_remaining (newmsg->
+ timeout).rel_value,
+ session->mac->fragment_messages_out_count);
+ }
- newmsg = GNUNET_malloc(sizeof(struct PendingMessage));
- newmsg->msg = GNUNET_malloc(msgbuf_size + sizeof(struct WlanHeader));
+ newmsg = GNUNET_malloc (sizeof (struct PendingMessage));
+ newmsg->msg = GNUNET_malloc (msgbuf_size + sizeof (struct WlanHeader));
wlanheader = newmsg->msg;
//copy msg to buffer, not fragmented / segmented yet, but with message header
- wlanheader->header.size = htons(msgbuf_size + sizeof(struct WlanHeader));
- wlanheader->header.type = htons(GNUNET_MESSAGE_TYPE_WLAN_DATA);
- memcpy(&(wlanheader->target), target, sizeof(struct GNUNET_PeerIdentity));
- memcpy(&(wlanheader->source), plugin->env->my_identity,
- sizeof(struct GNUNET_PeerIdentity));
+ wlanheader->header.size = htons (msgbuf_size + sizeof (struct WlanHeader));
+ wlanheader->header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_DATA);
+ memcpy (&(wlanheader->target), target, sizeof (struct GNUNET_PeerIdentity));
+ memcpy (&(wlanheader->source), plugin->env->my_identity,
+ sizeof (struct GNUNET_PeerIdentity));
wlanheader->crc = 0;
- memcpy(&wlanheader[1], msgbuf, msgbuf_size);
- wlanheader->crc = htonl(
- getcrc32((char*) wlanheader, msgbuf_size + sizeof(struct WlanHeader)));
+ memcpy (&wlanheader[1], msgbuf, msgbuf_size);
+ wlanheader->crc =
+ htonl (getcrc32
+ ((char *) wlanheader, msgbuf_size + sizeof (struct WlanHeader)));
//GNUNET_log_from(GNUNET_ERROR_TYPE_INFO, PLUGIN_LOG_NAME, "Wlan message
Header crc: %u, %u\n",getcrc32((char*) wlanheader, msgbuf_size + sizeof(struct
WlanHeader)), wlanheader->crc);
//hexdump(newmsg->msg, msgbuf_size + sizeof(struct WlanHeader));
newmsg->transmit_cont = cont;
newmsg->transmit_cont_cls = cont_cls;
- newmsg->timeout = GNUNET_TIME_relative_to_absolute(timeout);
+ newmsg->timeout = GNUNET_TIME_relative_to_absolute (timeout);
newmsg->timeout.abs_value = newmsg->timeout.abs_value - 500;
- newmsg->message_size = msgbuf_size + sizeof(struct WlanHeader);
+ newmsg->message_size = msgbuf_size + sizeof (struct WlanHeader);
- GNUNET_CONTAINER_DLL_insert_tail(session->pending_message_head,
session->pending_message_tail, newmsg);
+ GNUNET_CONTAINER_DLL_insert_tail (session->pending_message_head,
+ session->pending_message_tail, newmsg);
#if DEBUG_wlan
- GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
- "New message for %p with size (incl wlan header) %u added\n", session,
- newmsg->message_size);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
+ "New message for %p with size (incl wlan header) %u
added\n",
+ session, newmsg->message_size);
#endif
//queue session
- queue_session(plugin, session);
+ queue_session (plugin, session);
- check_fragment_queue(plugin);
+ check_fragment_queue (plugin);
//FIXME not the correct size
return msgbuf_size;
@@ -1860,24 +1906,25 @@
* @param endpoin pointer to the MacEndpoint to free
*/
static void
-free_macendpoint(struct Plugin * plugin, struct MacEndpoint * endpoint)
+free_macendpoint (struct Plugin *plugin, struct MacEndpoint *endpoint)
{
- struct Sessionqueue * sessions;
- struct Sessionqueue * sessions_next;
- GNUNET_assert(endpoint != NULL);
+ struct Sessionqueue *sessions;
+ struct Sessionqueue *sessions_next;
+ GNUNET_assert (endpoint != NULL);
+
sessions = endpoint->sessions_head;
while (sessions != NULL)
- {
- sessions_next = sessions->next;
- free_session(plugin, sessions, GNUNET_NO);
- sessions = sessions_next;
- }
+ {
+ sessions_next = sessions->next;
+ free_session (plugin, sessions, GNUNET_NO);
+ sessions = sessions_next;
+ }
- GNUNET_CONTAINER_DLL_remove(plugin->mac_head,plugin->mac_tail,endpoint);
+ GNUNET_CONTAINER_DLL_remove (plugin->mac_head, plugin->mac_tail, endpoint);
if (endpoint->timeout_task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel(endpoint->timeout_task);
- GNUNET_free(endpoint);
+ GNUNET_SCHEDULER_cancel (endpoint->timeout_task);
+ GNUNET_free (endpoint);
}
@@ -1888,75 +1935,75 @@
* @param free_macendpoint if GNUNET_YES and mac endpoint would be empty, free
mac endpoint
*/
static void
-free_session(struct Plugin * plugin, struct Sessionqueue * queue,
- int do_free_macendpoint)
+free_session (struct Plugin *plugin, struct Sessionqueue *queue,
+ int do_free_macendpoint)
{
- struct Sessionqueue * pendingsession;
- struct Sessionqueue * pendingsession_tmp;
- struct PendingMessage * pm;
- struct MacEndpoint * endpoint;
- struct FragmentMessage * fm;
- struct FragmentMessage * fmnext;
+ struct Sessionqueue *pendingsession;
+ struct Sessionqueue *pendingsession_tmp;
+ struct PendingMessage *pm;
+ struct MacEndpoint *endpoint;
+ struct FragmentMessage *fm;
+ struct FragmentMessage *fmnext;
int check = 0;
- GNUNET_assert(queue != NULL);
- GNUNET_assert(queue->content != NULL);
+ GNUNET_assert (queue != NULL);
+ GNUNET_assert (queue->content != NULL);
//session found
//is this session pending for send
pendingsession = plugin->pending_Sessions_head;
while (pendingsession != NULL)
+ {
+ pendingsession_tmp = pendingsession->next;
+ if (pendingsession->content == queue->content)
{
- pendingsession_tmp = pendingsession->next;
- if (pendingsession->content == queue->content)
- {
- plugin->pendingsessions--;
- GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head,
- plugin->pending_Sessions_tail,
- pendingsession);
- GNUNET_free(pendingsession);
+ plugin->pendingsessions--;
+ GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head,
+ plugin->pending_Sessions_tail,
+ pendingsession);
+ GNUNET_free (pendingsession);
- GNUNET_assert (check == 0);
- check = 1;
- }
- pendingsession = pendingsession_tmp;
+ GNUNET_assert (check == 0);
+ check = 1;
}
+ pendingsession = pendingsession_tmp;
+ }
endpoint = queue->content->mac;
fm = endpoint->sending_messages_head;
while (fm != NULL)
+ {
+ fmnext = fm->next;
+ if (fm->session == queue->content)
{
- fmnext = fm->next;
- if (fm->session == queue->content)
- {
- free_fragment_message(plugin, fm);
- }
- fm = fmnext;
+ free_fragment_message (plugin, fm);
}
+ fm = fmnext;
+ }
// remove PendingMessage
pm = queue->content->pending_message_head;
while (pm != NULL)
- {
-
GNUNET_CONTAINER_DLL_remove(queue->content->pending_message_head,queue->content->pending_message_tail,pm);
- GNUNET_free(pm->msg);
- GNUNET_free(pm);
- pm = queue->content->pending_message_head;
- }
+ {
+ GNUNET_CONTAINER_DLL_remove (queue->content->pending_message_head,
+ queue->content->pending_message_tail, pm);
+ GNUNET_free (pm->msg);
+ GNUNET_free (pm);
+ pm = queue->content->pending_message_head;
+ }
- GNUNET_CONTAINER_DLL_remove(endpoint->sessions_head ,
- endpoint->sessions_tail,
- queue);
+ GNUNET_CONTAINER_DLL_remove (endpoint->sessions_head,
+ endpoint->sessions_tail, queue);
if (endpoint->sessions_head == NULL && do_free_macendpoint == GNUNET_YES)
- {
- free_macendpoint(plugin, endpoint);
- }
+ {
+ free_macendpoint (plugin, endpoint);
+ }
if (queue->content->timeout_task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel(queue->content->timeout_task);
- GNUNET_free(queue);
- check_fragment_queue(plugin);
+ GNUNET_SCHEDULER_cancel (queue->content->timeout_task);
+ GNUNET_free (queue);
+ check_fragment_queue (plugin);
}
/**
@@ -1968,33 +2015,34 @@
* @param target peer from which to disconnect
*/
static void
-wlan_plugin_disconnect(void *cls, const struct GNUNET_PeerIdentity *target)
+wlan_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
{
struct Plugin *plugin = cls;
- struct Sessionqueue * queue;
- struct Sessionqueue * queue_next;
- struct MacEndpoint * endpoint = plugin->mac_head;
- struct MacEndpoint * endpoint_next;
+ struct Sessionqueue *queue;
+ struct Sessionqueue *queue_next;
+ struct MacEndpoint *endpoint = plugin->mac_head;
+ struct MacEndpoint *endpoint_next;
+
// just look at all the session for the needed one
while (endpoint != NULL)
+ {
+ queue = endpoint->sessions_head;
+ endpoint_next = endpoint->next;
+ while (queue != NULL)
{
- queue = endpoint->sessions_head;
- endpoint_next = endpoint->next;
- while (queue != NULL)
- {
- // content is never NULL
- GNUNET_assert (queue->content != NULL);
- queue_next = queue->next;
- if (memcmp(target, &(queue->content->target),
- sizeof(struct GNUNET_PeerIdentity)) == 0)
- {
- free_session(plugin, queue, GNUNET_YES);
- }
- // try next
- queue = queue_next;
- }
- endpoint = endpoint_next;
+ // content is never NULL
+ GNUNET_assert (queue->content != NULL);
+ queue_next = queue->next;
+ if (memcmp (target, &(queue->content->target),
+ sizeof (struct GNUNET_PeerIdentity)) == 0)
+ {
+ free_session (plugin, queue, GNUNET_YES);
+ }
+ // try next
+ queue = queue_next;
}
+ endpoint = endpoint_next;
+ }
}
/**
@@ -2012,26 +2060,29 @@
* @param asc_cls closure for asc
*/
static void
-wlan_plugin_address_pretty_printer(void *cls, const char *type,
- const void *addr, size_t addrlen, int numeric,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_TRANSPORT_AddressStringCallback asc, void *asc_cls)
+wlan_plugin_address_pretty_printer (void *cls, const char *type,
+ const void *addr, size_t addrlen,
+ int numeric,
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_TRANSPORT_AddressStringCallback asc,
+ void *asc_cls)
{
char ret[92];
- const unsigned char * input;
+ const unsigned char *input;
//GNUNET_assert(cls !=NULL);
if (addrlen != 6)
- {
- /* invalid address (MAC addresses have 6 bytes) */GNUNET_break (0);
- asc(asc_cls, NULL);
- return;
- }
- input = (const unsigned char*) addr;
- GNUNET_snprintf(ret, sizeof(ret),
- "%s Mac-Address %.2X:%.2X:%.2X:%.2X:%.2X:%.2X", PROTOCOL_PREFIX,
- input[0], input[1], input[2], input[3], input[4], input[5]);
- asc(asc_cls, ret);
+ {
+ /* invalid address (MAC addresses have 6 bytes) */ GNUNET_break (0);
+ asc (asc_cls, NULL);
+ return;
+ }
+ input = (const unsigned char *) addr;
+ GNUNET_snprintf (ret, sizeof (ret),
+ "%s Mac-Address %.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
+ PROTOCOL_PREFIX, input[0], input[1], input[2], input[3],
+ input[4], input[5]);
+ asc (asc_cls, ret);
}
/**
@@ -2041,136 +2092,137 @@
* @param hdr pointer to the data
*/
static void
-wlan_data_message_handler(void *cls, const struct GNUNET_MessageHeader *hdr)
+wlan_data_message_handler (void *cls, const struct GNUNET_MessageHeader *hdr)
{
- struct MacEndpoint * endpoint = (struct MacEndpoint *) cls;
- struct Plugin * plugin = endpoint->plugin;
- struct WlanHeader * wlanheader;
- struct Session * session;
+ struct MacEndpoint *endpoint = (struct MacEndpoint *) cls;
+ struct Plugin *plugin = endpoint->plugin;
+ struct WlanHeader *wlanheader;
+ struct Session *session;
+
//const char * tempmsg;
- const struct GNUNET_MessageHeader * temp_hdr;
+ const struct GNUNET_MessageHeader *temp_hdr;
struct GNUNET_PeerIdentity tmpsource;
int crc;
- if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_DATA)
- {
+ if (ntohs (hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_DATA)
+ {
#if DEBUG_wlan
- GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
- "Func wlan_data_message_handler got GNUNET_MESSAGE_TYPE_WLAN_DATA
size: %u\n",
- ntohs(hdr->size));
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
+ "Func wlan_data_message_handler got
GNUNET_MESSAGE_TYPE_WLAN_DATA size: %u\n",
+ ntohs (hdr->size));
#endif
- if (ntohs(hdr->size) < sizeof(struct WlanHeader)
- + sizeof(struct GNUNET_MessageHeader))
- {
- //packet not big enought
- return;
- }
+ if (ntohs (hdr->size) < sizeof (struct WlanHeader)
+ + sizeof (struct GNUNET_MessageHeader))
+ {
+ //packet not big enought
+ return;
+ }
- wlanheader = (struct WlanHeader *) hdr;
+ wlanheader = (struct WlanHeader *) hdr;
- session = search_session(plugin, endpoint, &wlanheader->source);
+ session = search_session (plugin, endpoint, &wlanheader->source);
- //tempmsg = (char*) &wlanheader[1];
- temp_hdr = (const struct GNUNET_MessageHeader *) &wlanheader[1];
- crc = ntohl(wlanheader->crc);
- wlanheader->crc = 0;
- if (getcrc32((char *) wlanheader, ntohs(wlanheader->header.size)) != crc)
- {
- //wrong crc, dispose message
- GNUNET_log_from(GNUNET_ERROR_TYPE_INFO, PLUGIN_LOG_NAME,
- "Wlan message header crc was wrong: %u != %u\n",
- getcrc32((char *) wlanheader, ntohs(wlanheader->header.size)),
- crc);
- hexdump((void *) hdr, ntohs(hdr->size));
- return;
- }
+ //tempmsg = (char*) &wlanheader[1];
+ temp_hdr = (const struct GNUNET_MessageHeader *) &wlanheader[1];
+ crc = ntohl (wlanheader->crc);
+ wlanheader->crc = 0;
+ if (getcrc32 ((char *) wlanheader, ntohs (wlanheader->header.size)) != crc)
+ {
+ //wrong crc, dispose message
+ GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, PLUGIN_LOG_NAME,
+ "Wlan message header crc was wrong: %u != %u\n",
+ getcrc32 ((char *) wlanheader,
+ ntohs (wlanheader->header.size)), crc);
+ hexdump ((void *) hdr, ntohs (hdr->size));
+ return;
+ }
- //if not in session list
- if (session == NULL)
- {
+ //if not in session list
+ if (session == NULL)
+ {
#if DEBUG_wlan
- GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
- "WLAN client not in session list: packet size = %u, inner size =
%u, header size = %u\n",
- ntohs(wlanheader->header.size), ntohs(temp_hdr->size),
- sizeof(struct WlanHeader));
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
+ "WLAN client not in session list: packet size = %u,
inner size = %u, header size = %u\n",
+ ntohs (wlanheader->header.size), ntohs (temp_hdr->size),
+ sizeof (struct WlanHeader));
#endif
- //try if it is a hello message
- if (ntohs(wlanheader->header.size) >= ntohs(temp_hdr->size)
- + sizeof(struct WlanHeader))
- {
- if (ntohs(temp_hdr->type) == GNUNET_MESSAGE_TYPE_HELLO)
- {
- if (GNUNET_HELLO_get_id(
- (const struct GNUNET_HELLO_Message *) temp_hdr,
- &tmpsource) == GNUNET_OK)
- {
- session = create_session(plugin, endpoint, &tmpsource);
- }
- else
- {
- GNUNET_log_from(GNUNET_ERROR_TYPE_WARNING,
PLUGIN_LOG_NAME,
- "WLAN client not in session list and hello message
is not okay\n");
- return;
- }
+ //try if it is a hello message
+ if (ntohs (wlanheader->header.size) >= ntohs (temp_hdr->size)
+ + sizeof (struct WlanHeader))
+ {
+ if (ntohs (temp_hdr->type) == GNUNET_MESSAGE_TYPE_HELLO)
+ {
+ if (GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
+ temp_hdr, &tmpsource) == GNUNET_OK)
+ {
+ session = create_session (plugin, endpoint, &tmpsource);
+ }
+ else
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME,
+ "WLAN client not in session list and hello
message is not okay\n");
+ return;
+ }
- }
- else
- {
- GNUNET_log_from(GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME,
- "WLAN client not in session list and not a hello
message\n");
- return;
- }
- }
- else
- {
- GNUNET_log_from(GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME,
- "WLAN client not in session list and message size in does
not fit\npacket size = %u, inner size = %u, header size = %u\n",
- ntohs(wlanheader->header.size), ntohs(temp_hdr->size),
- sizeof(struct WlanHeader));
- return;
- }
}
-
- //"receive" the message
-
- if (memcmp(&wlanheader->source, &session->target,
- sizeof(struct GNUNET_PeerIdentity)) != 0)
+ else
{
- //wrong peer id
-#if DEBUG_wlan
- GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
- "WLAN peer source id doesn't match packet peer source id:
session %p\n",
- session);
-#endif
+ GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME,
+ "WLAN client not in session list and not a hello
message\n");
return;
}
+ }
+ else
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME,
+ "WLAN client not in session list and message size in
does not fit\npacket size = %u, inner size = %u, header size = %u\n",
+ ntohs (wlanheader->header.size),
+ ntohs (temp_hdr->size), sizeof (struct WlanHeader));
+ return;
+ }
+ }
- if (memcmp(&wlanheader->target, plugin->env->my_identity,
- sizeof(struct GNUNET_PeerIdentity)) != 0)
- {
- //wrong peer id
+ //"receive" the message
+
+ if (memcmp (&wlanheader->source, &session->target,
+ sizeof (struct GNUNET_PeerIdentity)) != 0)
+ {
+ //wrong peer id
#if DEBUG_wlan
- GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
- "WLAN peer target id doesn't match our peer id: session %p\n",
- session);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
+ "WLAN peer source id doesn't match packet peer source
id: session %p\n",
+ session);
#endif
- return;
- }
-
- GNUNET_SERVER_mst_receive(plugin->data_tokenizer, session,
- (const char *) temp_hdr,
- ntohs(hdr->size) - sizeof(struct WlanHeader), GNUNET_YES, GNUNET_NO);
-
return;
}
- else
+
+ if (memcmp (&wlanheader->target, plugin->env->my_identity,
+ sizeof (struct GNUNET_PeerIdentity)) != 0)
{
- GNUNET_log_from(GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME,
- "wlan_data_message_handler got wrong message type\n");
+ //wrong peer id
+#if DEBUG_wlan
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
+ "WLAN peer target id doesn't match our peer id: session
%p\n",
+ session);
+#endif
return;
}
+
+ GNUNET_SERVER_mst_receive (plugin->data_tokenizer, session,
+ (const char *) temp_hdr,
+ ntohs (hdr->size) - sizeof (struct WlanHeader),
+ GNUNET_YES, GNUNET_NO);
+
+ return;
+ }
+ else
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME,
+ "wlan_data_message_handler got wrong message type\n");
+ return;
+ }
}
/**
@@ -2181,30 +2233,35 @@
*/
//TODO ATS informations
static void
-process_data(void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
+process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
{
- GNUNET_assert(client != NULL);
- GNUNET_assert(cls != NULL);
- struct Session * session = (struct Session *) client;
- struct Plugin * plugin = (struct Plugin *) cls;
+ GNUNET_assert (client != NULL);
+ GNUNET_assert (cls != NULL);
+ struct Session *session = (struct Session *) client;
+ struct Plugin *plugin = (struct Plugin *) cls;
struct GNUNET_TRANSPORT_ATS_Information distance[2];
- distance[0].type = htonl(GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE);
- distance[0].value = htonl(1);
- distance[1].type = htonl(GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
- distance[1].value = htonl(0);
+ distance[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE);
+ distance[0].value = htonl (1);
+ distance[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
+ distance[1].value = htonl (0);
+
#if DEBUG_wlan
- GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
- "Calling plugin->env->receive for session %p; %s; size: %u\n", session,
- wlan_plugin_address_to_string(NULL, session->mac->addr.mac, 6),
- htons(hdr->size));
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
+ "Calling plugin->env->receive for session %p; %s; size:
%u\n",
+ session, wlan_plugin_address_to_string (NULL,
+ session->mac->
+ addr.mac, 6),
+ htons (hdr->size));
#endif
- plugin->env->receive(plugin->env->cls, &(session->target), hdr,
- (const struct GNUNET_TRANSPORT_ATS_Information *) &distance, 2, session,
- (const char*) &session->mac->addr, sizeof(session->mac->addr));
+ plugin->env->receive (plugin->env->cls, &(session->target), hdr,
+ (const struct GNUNET_TRANSPORT_ATS_Information *)
+ &distance, 2, session,
+ (const char *) &session->mac->addr,
+ sizeof (session->mac->addr));
}
/**
@@ -2215,166 +2272,183 @@
* @param hdr hdr of the GNUNET_MessageHeader
*/
static void
-wlan_data_helper(void *cls, struct Session_light * session_light,
- const struct GNUNET_MessageHeader * hdr, const struct Radiotap_rx * rxinfo)
+wlan_data_helper (void *cls, struct Session_light *session_light,
+ const struct GNUNET_MessageHeader *hdr,
+ const struct Radiotap_rx *rxinfo)
{
struct Plugin *plugin = cls;
- struct FragmentMessage * fm;
- struct FragmentMessage * fm2;
+ struct FragmentMessage *fm;
+ struct FragmentMessage *fm2;
//ADVERTISEMENT
- if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT)
- {
+ if (ntohs (hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT)
+ {
- //TODO better DOS protection, error handling
- //TODO test first than create session
- GNUNET_assert(session_light != NULL);
+ //TODO better DOS protection, error handling
+ //TODO test first than create session
+ GNUNET_assert (session_light != NULL);
#if DEBUG_wlan
- GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
- "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT
size: %u; %s\n",
- ntohs(hdr->size),
- wlan_plugin_address_to_string(NULL, session_light->addr.mac, 6));
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
+ "Func wlan_data_helper got
GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT size: %u; %s\n",
+ ntohs (hdr->size),
+ wlan_plugin_address_to_string (NULL,
+ session_light->addr.mac,
+ 6));
#endif
- if (session_light->macendpoint == NULL)
- {
- session_light->macendpoint = get_macendpoint(plugin,
- &session_light->addr, GNUNET_NO);
- }
- GNUNET_assert(GNUNET_HELLO_get_id(
- (const struct GNUNET_HELLO_Message *) &hdr[1],
- &(session_light->session->target) ) != GNUNET_SYSERR);
-
+ if (session_light->macendpoint == NULL)
+ {
+ session_light->macendpoint = get_macendpoint (plugin,
+ &session_light->addr,
+ GNUNET_NO);
}
+ GNUNET_assert (GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
+ &hdr[1],
+ &(session_light->session->target)) !=
+ GNUNET_SYSERR);
+ }
+
//FRAGMENT
- else if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_FRAGMENT)
+ else if (ntohs (hdr->type) == GNUNET_MESSAGE_TYPE_FRAGMENT)
+ {
+
+ GNUNET_assert (session_light != NULL);
+ if (session_light->macendpoint == NULL)
{
+ session_light->macendpoint = get_macendpoint (plugin,
+ &session_light->addr,
+ GNUNET_YES);
+ }
- GNUNET_assert(session_light != NULL);
- if (session_light->macendpoint == NULL)
- {
- session_light->macendpoint = get_macendpoint(plugin,
- &session_light->addr, GNUNET_YES);
- }
-
#if DEBUG_wlan
- GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
- "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_FRAGMENT with size:
%u; mac endpoint %p: %s\n",
- ntohs(hdr->size), session_light->macendpoint,
- wlan_plugin_address_to_string(NULL, session_light->addr.mac, 6));
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
+ "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_FRAGMENT
with size: %u; mac endpoint %p: %s\n",
+ ntohs (hdr->size), session_light->macendpoint,
+ wlan_plugin_address_to_string (NULL,
+ session_light->addr.mac,
+ 6));
#endif
- int ret = GNUNET_DEFRAGMENT_process_fragment(
- session_light->macendpoint->defrag, hdr);
- if (ret == GNUNET_NO)
- {
- session_light->macendpoint->dups++;
- }
- else if (ret == GNUNET_OK)
- {
- session_light->macendpoint->fragc++;
- }
- set_next_send(plugin);
+ int ret =
+ GNUNET_DEFRAGMENT_process_fragment (session_light->macendpoint->defrag,
+ hdr);
+ if (ret == GNUNET_NO)
+ {
+ session_light->macendpoint->dups++;
}
+ else if (ret == GNUNET_OK)
+ {
+ session_light->macendpoint->fragc++;
+ }
+ set_next_send (plugin);
+ }
+
//ACK
- else if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_FRAGMENT_ACK)
+ else if (ntohs (hdr->type) == GNUNET_MESSAGE_TYPE_FRAGMENT_ACK)
+ {
+ GNUNET_assert (session_light != NULL);
+ if (session_light->macendpoint == NULL)
{
- GNUNET_assert(session_light != NULL);
- if (session_light->macendpoint == NULL)
- {
- session_light->macendpoint = get_macendpoint(plugin,
- &session_light->addr, GNUNET_NO);
- }
+ session_light->macendpoint = get_macendpoint (plugin,
+ &session_light->addr,
+ GNUNET_NO);
+ }
- if (session_light->macendpoint == NULL)
- {
+ if (session_light->macendpoint == NULL)
+ {
#if DEBUG_wlan
- GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
- "Macendpoint does not exist for this
GNUNET_MESSAGE_TYPE_FRAGMENT_ACK size: %u; %s\n",
- ntohs(hdr->size),
- wlan_plugin_address_to_string(NULL, session_light->addr.mac, 6));
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
+ "Macendpoint does not exist for this
GNUNET_MESSAGE_TYPE_FRAGMENT_ACK size: %u; %s\n",
+ ntohs (hdr->size),
+ wlan_plugin_address_to_string (NULL,
+ session_light->addr.mac,
+ 6));
#endif
- return;
- }
+ return;
+ }
#if DEBUG_wlan
- GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
- "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_FRAGMENT_ACK size:
%u; mac endpoint: %p; %s\n",
- ntohs(hdr->size), session_light->macendpoint,
- wlan_plugin_address_to_string(NULL, session_light->addr.mac, 6));
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
+ "Func wlan_data_helper got
GNUNET_MESSAGE_TYPE_FRAGMENT_ACK size: %u; mac endpoint: %p; %s\n",
+ ntohs (hdr->size), session_light->macendpoint,
+ wlan_plugin_address_to_string (NULL,
+ session_light->addr.mac,
+ 6));
#endif
- fm = session_light->macendpoint->sending_messages_head;
- while (fm != NULL)
- {
- fm2 = fm->next;
- int ret = GNUNET_FRAGMENT_process_ack(fm->fragcontext, hdr);
- if (ret == GNUNET_OK)
- {
+ fm = session_light->macendpoint->sending_messages_head;
+ while (fm != NULL)
+ {
+ fm2 = fm->next;
+ int ret = GNUNET_FRAGMENT_process_ack (fm->fragcontext, hdr);
+
+ if (ret == GNUNET_OK)
+ {
#if DEBUG_wlan_retransmission
- GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
- "Got last ack, finished fragment message %p\n", fm);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
+ "Got last ack, finished fragment message %p\n", fm);
#endif
- session_light->macendpoint->acks++;
- fm->session->last_activity = GNUNET_TIME_absolute_get();
- session_light->macendpoint->last_activity =
fm->session->last_activity;
- free_fragment_message(plugin, fm);
- check_fragment_queue(plugin);
- return;
- }
- if (ret == GNUNET_NO)
- {
+ session_light->macendpoint->acks++;
+ fm->session->last_activity = GNUNET_TIME_absolute_get ();
+ session_light->macendpoint->last_activity = fm->session->last_activity;
+ free_fragment_message (plugin, fm);
+ check_fragment_queue (plugin);
+ return;
+ }
+ if (ret == GNUNET_NO)
+ {
#if DEBUG_wlan_retransmission
- GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, "Got
ack for: %p\n", fm);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
+ "Got ack for: %p\n", fm);
#endif
- session_light->macendpoint->acks++;
- return;
- }
- if (ret == GNUNET_SYSERR)
- {
+ session_light->macendpoint->acks++;
+ return;
+ }
+ if (ret == GNUNET_SYSERR)
+ {
- }
+ }
- fm = fm2;
- }
+ fm = fm2;
+ }
#if DEBUG_wlan_retransmission
- GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
- "WLAN fragment not in fragment list\n");
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
+ "WLAN fragment not in fragment list\n");
#endif
- return;
+ return;
- }
+ }
else
- {
- // TODO Wrong data?
- GNUNET_log_from(GNUNET_ERROR_TYPE_INFO, PLUGIN_LOG_NAME,
- "WLAN packet inside the WLAN helper packet has not the right type:
%u size: %u\n",
- ntohs(hdr->type), ntohs(hdr->size));
- GNUNET_break(0);
- return;
- }
+ {
+ // TODO Wrong data?
+ GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, PLUGIN_LOG_NAME,
+ "WLAN packet inside the WLAN helper packet has not the
right type: %u size: %u\n",
+ ntohs (hdr->type), ntohs (hdr->size));
+ GNUNET_break (0);
+ return;
+ }
#if 0
- GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
- "Helper finished\n");
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
+ "Helper finished\n");
#endif
}
//TODO DOXIGEN
const char *
-macprinter(const u_int8_t * mac)
+macprinter (const u_int8_t * mac)
{
static char macstr[20];
- GNUNET_snprintf(macstr, sizeof(macstr), "%X:%X:%X:%X:%X:%X", mac[0], mac[1],
- mac[2], mac[3], mac[4], mac[5]);
+ GNUNET_snprintf (macstr, sizeof (macstr), "%X:%X:%X:%X:%X:%X", mac[0],
mac[1],
+ mac[2], mac[3], mac[4], mac[5]);
return macstr;
}
@@ -2384,25 +2458,28 @@
* @param tc pointer to the GNUNET_SCHEDULER_TaskContext
*/
static void
-macendpoint_timeout (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc){
- struct MacEndpoint * endpoint = cls;
- GNUNET_assert(endpoint != NULL);
+macendpoint_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ struct MacEndpoint *endpoint = cls;
+
+ GNUNET_assert (endpoint != NULL);
endpoint->timeout_task = GNUNET_SCHEDULER_NO_TASK;
- if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN){
- return;
+ if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
+ {
+ return;
}
- if (GNUNET_TIME_absolute_get_remaining(
- GNUNET_TIME_absolute_add(endpoint->last_activity,
MACENDPOINT_TIMEOUT)).rel_value
- == 0)
- {
- free_macendpoint(endpoint->plugin,endpoint);
- }
+ if (GNUNET_TIME_absolute_get_remaining
+ (GNUNET_TIME_absolute_add
+ (endpoint->last_activity, MACENDPOINT_TIMEOUT)).rel_value == 0)
+ {
+ free_macendpoint (endpoint->plugin, endpoint);
+ }
else
- {
- endpoint->timeout_task =
GNUNET_SCHEDULER_add_delayed(MACENDPOINT_TIMEOUT,
- &macendpoint_timeout, endpoint);
- }
+ {
+ endpoint->timeout_task = GNUNET_SCHEDULER_add_delayed (MACENDPOINT_TIMEOUT,
+
&macendpoint_timeout,
+ endpoint);
+ }
}
/**
@@ -2412,25 +2489,31 @@
* @return returns a macendpoint
*/
static struct MacEndpoint *
-create_macendpoint(struct Plugin *plugin, const struct MacAddress *addr)
+create_macendpoint (struct Plugin *plugin, const struct MacAddress *addr)
{
- struct MacEndpoint * newend = GNUNET_malloc(sizeof (struct MacEndpoint));
+ struct MacEndpoint *newend = GNUNET_malloc (sizeof (struct MacEndpoint));
+
newend->addr = *addr;
newend->plugin = plugin;
newend->addr = *addr;
newend->fragment_messages_out_count = 0;
- newend->defrag = GNUNET_DEFRAGMENT_context_create(plugin->env->stats,
- WLAN_MTU, MESSAGES_IN_DEFRAG_QUEUE_PER_MAC, newend,
- &wlan_data_message_handler, &add_ack_for_send);
- newend->last_activity = GNUNET_TIME_absolute_get();
- newend->timeout_task = GNUNET_SCHEDULER_add_delayed(MACENDPOINT_TIMEOUT,
- &macendpoint_timeout, newend);
+ newend->defrag = GNUNET_DEFRAGMENT_context_create (plugin->env->stats,
+ WLAN_MTU,
+
MESSAGES_IN_DEFRAG_QUEUE_PER_MAC,
+ newend,
+
&wlan_data_message_handler,
+ &add_ack_for_send);
+ newend->last_activity = GNUNET_TIME_absolute_get ();
+ newend->timeout_task = GNUNET_SCHEDULER_add_delayed (MACENDPOINT_TIMEOUT,
+ &macendpoint_timeout,
+ newend);
plugin->mac_count++;
- GNUNET_CONTAINER_DLL_insert_tail(plugin->mac_head, plugin->mac_tail, newend);
+ 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, "New Mac Endpoint
%p: %s\n", newend,
- wlan_plugin_address_to_string(NULL, newend->addr.mac, 6));
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
+ "New Mac Endpoint %p: %s\n", newend,
+ wlan_plugin_address_to_string (NULL, newend->addr.mac, 6));
#endif
return newend;
}
@@ -2443,125 +2526,126 @@
* @param hdr header of the GNUNET_MessageHeader
*/
static void
-wlan_process_helper(void *cls, void *client,
- const struct GNUNET_MessageHeader *hdr)
+wlan_process_helper (void *cls, void *client,
+ const struct GNUNET_MessageHeader *hdr)
{
struct Plugin *plugin = cls;
- struct ieee80211_frame * wlanIeeeHeader = NULL;
- struct Session_light * session_light = NULL;
- struct Radiotap_rx * rxinfo;
- const struct GNUNET_MessageHeader * temp_hdr = NULL;
+ struct ieee80211_frame *wlanIeeeHeader = NULL;
+ struct Session_light *session_light = NULL;
+ struct Radiotap_rx *rxinfo;
+ const struct GNUNET_MessageHeader *temp_hdr = NULL;
int datasize = 0;
int pos;
- switch (ntohs(hdr->type))
- {
+ switch (ntohs (hdr->type))
+ {
case GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA:
#if DEBUG_wlan
- GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
- "Func wlan_process_helper got GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA
size: %u\n",
- ntohs(hdr->size));
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
+ "Func wlan_process_helper got
GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA size: %u\n",
+ ntohs (hdr->size));
#endif
//call wlan_process_helper with the message inside, later with wlan:
analyze signal
- if (ntohs(hdr->size) < sizeof(struct ieee80211_frame)
- + sizeof(struct GNUNET_MessageHeader) + sizeof(struct Radiotap_rx))
- {
+ if (ntohs (hdr->size) < sizeof (struct ieee80211_frame)
+ + sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_rx))
+ {
#if DEBUG_wlan
- GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
- "Size of packet is too small; size: %u min size: %u\n",
- ntohs(hdr->size),
- sizeof(struct ieee80211_frame)
- + sizeof(struct GNUNET_MessageHeader));
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
+ "Size of packet is too small; size: %u min size: %u\n",
+ ntohs (hdr->size),
+ sizeof (struct ieee80211_frame)
+ + sizeof (struct GNUNET_MessageHeader));
#endif
- //GNUNET_break (0);
- /* FIXME: restart SUID process */
- return;
- }
+ //GNUNET_break (0);
+ /* FIXME: restart SUID process */
+ return;
+ }
rxinfo = (struct Radiotap_rx *) &hdr[1];
wlanIeeeHeader = (struct ieee80211_frame *) &rxinfo[1];
//process only if it is an broadcast or for this computer both with the
gnunet bssid
//check for bssid
- if (memcmp(&(wlanIeeeHeader->i_addr3), &mac_bssid,
- sizeof(struct MacAddress)) == 0)
+ if (memcmp (&(wlanIeeeHeader->i_addr3), &mac_bssid,
+ sizeof (struct MacAddress)) == 0)
+ {
+ //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)
{
- //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)
- {
- // process the inner data
+ // process the inner data
- datasize = ntohs(hdr->size) - sizeof(struct ieee80211_frame)
- - sizeof(struct GNUNET_MessageHeader)
- - sizeof(struct Radiotap_rx);
+ datasize = ntohs (hdr->size) - sizeof (struct ieee80211_frame)
+ - sizeof (struct GNUNET_MessageHeader)
+ - sizeof (struct Radiotap_rx);
- session_light = GNUNET_malloc(sizeof(struct Session_light));
- memcpy(&session_light->addr, &(wlanIeeeHeader->i_addr2),
- sizeof(struct MacAddress));
- //session_light->session =
search_session(plugin,session_light->addr);
+ session_light = GNUNET_malloc (sizeof (struct Session_light));
+ memcpy (&session_light->addr, &(wlanIeeeHeader->i_addr2),
+ sizeof (struct MacAddress));
+ //session_light->session = search_session(plugin,session_light->addr);
- pos = 0;
- while (pos < datasize)
- {
- temp_hdr = (struct GNUNET_MessageHeader *) &wlanIeeeHeader[1]
- + pos;
+ pos = 0;
+ while (pos < datasize)
+ {
+ temp_hdr = (struct GNUNET_MessageHeader *) &wlanIeeeHeader[1] + pos;
- wlan_data_helper(plugin, session_light, temp_hdr, rxinfo);
- pos += ntohs(temp_hdr->size);
+ wlan_data_helper (plugin, session_light, temp_hdr, rxinfo);
+ pos += ntohs (temp_hdr->size);
- }
+ }
- //clean up
- GNUNET_free(session_light);
- }
- else
- {
+ //clean up
+ GNUNET_free (session_light);
+ }
+ else
+ {
#if DEBUG_wlan
- GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
- "Func wlan_process_helper got wrong MAC: %s\n",
- macprinter(wlanIeeeHeader->i_addr1));
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
+ "Func wlan_process_helper got wrong MAC: %s\n",
+ macprinter (wlanIeeeHeader->i_addr1));
#endif
- }
}
+ }
else
- {
+ {
#if DEBUG_wlan
- GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
- "Func wlan_process_helper got wrong BSSID: %s\n",
- macprinter(wlanIeeeHeader->i_addr2));
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
+ "Func wlan_process_helper got wrong BSSID: %s\n",
+ macprinter (wlanIeeeHeader->i_addr2));
#endif
- }
+ }
break;
case GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL:
//TODO more control messages
//TODO use struct wlan_helper_control
- if (ntohs(hdr->size) != sizeof(struct Wlan_Helper_Control_Message))
- {
- GNUNET_break (0);
- /* FIXME: restart SUID process */
- return;
- }
- memcpy(&plugin->mac_address, &hdr[1], sizeof(struct MacAddress));
+ if (ntohs (hdr->size) != sizeof (struct Wlan_Helper_Control_Message))
+ {
+ GNUNET_break (0);
+ /* FIXME: restart SUID process */
+ return;
+ }
+ memcpy (&plugin->mac_address, &hdr[1], sizeof (struct MacAddress));
#if DEBUG_wlan
- GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
- "Received WLAN_HELPER_CONTROL message with transport of address %s\n",
- wlan_plugin_address_to_string(cls, &plugin->mac_address,
- sizeof(struct MacAddress)));
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
+ "Received WLAN_HELPER_CONTROL message with transport of
address %s\n",
+ wlan_plugin_address_to_string (cls, &plugin->mac_address,
+ sizeof (struct
+ MacAddress)));
#endif
- plugin->env->notify_address(plugin->env->cls, GNUNET_YES,
- &plugin->mac_address, sizeof(struct MacAddress));
+ plugin->env->notify_address (plugin->env->cls, GNUNET_YES,
+ &plugin->mac_address,
+ sizeof (struct MacAddress));
break;
default:
GNUNET_break (0);
return;
- }
+ }
}
/**
@@ -2573,36 +2657,39 @@
* @param tc the scheduling context
*/
static void
-wlan_plugin_helper_read(void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+wlan_plugin_helper_read (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct Plugin *plugin = cls;
+
plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK;
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
return;
- char mybuf[WLAN_MTU + sizeof(struct GNUNET_MessageHeader)];
+ char mybuf[WLAN_MTU + sizeof (struct GNUNET_MessageHeader)];
ssize_t bytes;
- bytes = GNUNET_DISK_file_read(plugin->server_stdout_handle, mybuf,
- sizeof(mybuf));
+ bytes = GNUNET_DISK_file_read (plugin->server_stdout_handle, mybuf,
+ sizeof (mybuf));
if (bytes <= 0)
- {
+ {
#if DEBUG_wlan
- GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
- _("Finished reading from wlan-helper stdout with code: %d\n"),
- bytes);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
+ _
+ ("Finished reading from wlan-helper stdout with code:
%d\n"),
+ bytes);
#endif
- return;
- }
- GNUNET_SERVER_mst_receive(plugin->suid_tokenizer, NULL, mybuf, bytes,
- GNUNET_NO, GNUNET_NO);
+ return;
+ }
+ GNUNET_SERVER_mst_receive (plugin->suid_tokenizer, NULL, mybuf, bytes,
+ GNUNET_NO, GNUNET_NO);
- GNUNET_assert(plugin->server_read_task == GNUNET_SCHEDULER_NO_TASK);
- plugin->server_read_task = GNUNET_SCHEDULER_add_read_file(
- GNUNET_TIME_UNIT_FOREVER_REL, plugin->server_stdout_handle,
- &wlan_plugin_helper_read, plugin);
+ GNUNET_assert (plugin->server_read_task == GNUNET_SCHEDULER_NO_TASK);
+ plugin->server_read_task =
+ GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ plugin->server_stdout_handle,
+ &wlan_plugin_helper_read, plugin);
}
/**
@@ -2613,85 +2700,93 @@
* @return GNUNET_YES if process was started, GNUNET_SYSERR on error
*/
static int
-wlan_transport_start_wlan_helper(struct Plugin *plugin, int testmode)
+wlan_transport_start_wlan_helper (struct Plugin *plugin, int testmode)
{
- const char * filenamehw = "gnunet-transport-wlan-helper";
- const char * filenameloopback = "gnunet-transport-wlan-helper-dummy";
- plugin->server_stdout = GNUNET_DISK_pipe(GNUNET_YES, GNUNET_NO, GNUNET_YES);
+ const char *filenamehw = "gnunet-transport-wlan-helper";
+ const char *filenameloopback = "gnunet-transport-wlan-helper-dummy";
+
+ plugin->server_stdout = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_NO, GNUNET_YES);
if (plugin->server_stdout == NULL)
return GNUNET_SYSERR;
- plugin->server_stdin = GNUNET_DISK_pipe(GNUNET_YES, GNUNET_YES, GNUNET_NO);
+ plugin->server_stdin = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO);
if (plugin->server_stdin == NULL)
return GNUNET_SYSERR;
/* Start the server process */
if (testmode == 0)
- {
+ {
#if DEBUG_wlan
- GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
- "Starting gnunet-wlan-helper process cmd: %s %s %i\n", filenamehw,
- plugin->interface, testmode);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
+ "Starting gnunet-wlan-helper process cmd: %s %s %i\n",
+ filenamehw, plugin->interface, testmode);
#endif
- plugin->server_proc = GNUNET_OS_start_process(plugin->server_stdin,
- plugin->server_stdout, filenamehw, filenamehw, plugin->interface,
- NULL);
- }
+ plugin->server_proc = GNUNET_OS_start_process (plugin->server_stdin,
+ plugin->server_stdout,
+ filenamehw, filenamehw,
+ plugin->interface, NULL);
+ }
else if (testmode == 1)
- {
+ {
#if DEBUG_wlan
- GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
- "Starting gnunet-wlan-helper loopback 1 process cmd: %s %s %i\n",
- filenameloopback, plugin->interface, testmode);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
+ "Starting gnunet-wlan-helper loopback 1 process cmd: %s
%s %i\n",
+ filenameloopback, plugin->interface, testmode);
#endif
- plugin->server_proc = GNUNET_OS_start_process(plugin->server_stdin,
- plugin->server_stdout, filenameloopback, filenameloopback, "1",
NULL);
- }
+ plugin->server_proc = GNUNET_OS_start_process (plugin->server_stdin,
+ plugin->server_stdout,
+ filenameloopback,
+ filenameloopback, "1",
NULL);
+ }
else if (testmode == 2)
- {
+ {
#if DEBUG_wlan
- GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
- "Starting gnunet-wlan-helper loopback 2 process cmd: %s %s %i\n",
- filenameloopback, plugin->interface, testmode);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
+ "Starting gnunet-wlan-helper loopback 2 process cmd: %s
%s %i\n",
+ filenameloopback, plugin->interface, testmode);
#endif
- plugin->server_proc = GNUNET_OS_start_process(plugin->server_stdin,
- plugin->server_stdout, filenameloopback, filenameloopback, "2",
NULL);
- }
+ plugin->server_proc = GNUNET_OS_start_process (plugin->server_stdin,
+ plugin->server_stdout,
+ filenameloopback,
+ filenameloopback, "2",
NULL);
+ }
if (plugin->server_proc == NULL)
- {
+ {
#if DEBUG_wlan
- GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
- "Failed to start gnunet-wlan-helper process\n");
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
+ "Failed to start gnunet-wlan-helper process\n");
#endif
- return GNUNET_SYSERR;
- }
+ return GNUNET_SYSERR;
+ }
/* Close the write end of the read pipe */
- GNUNET_DISK_pipe_close_end(plugin->server_stdout,
GNUNET_DISK_PIPE_END_WRITE);
+ GNUNET_DISK_pipe_close_end (plugin->server_stdout,
+ GNUNET_DISK_PIPE_END_WRITE);
/* Close the read end of the write pipe */
- GNUNET_DISK_pipe_close_end(plugin->server_stdin, GNUNET_DISK_PIPE_END_READ);
+ GNUNET_DISK_pipe_close_end (plugin->server_stdin, GNUNET_DISK_PIPE_END_READ);
- plugin->server_stdout_handle = GNUNET_DISK_pipe_handle(plugin->server_stdout,
- GNUNET_DISK_PIPE_END_READ);
- plugin->server_stdin_handle = GNUNET_DISK_pipe_handle(plugin->server_stdin,
- GNUNET_DISK_PIPE_END_WRITE);
+ plugin->server_stdout_handle = GNUNET_DISK_pipe_handle
(plugin->server_stdout,
+
GNUNET_DISK_PIPE_END_READ);
+ plugin->server_stdin_handle = GNUNET_DISK_pipe_handle (plugin->server_stdin,
+
GNUNET_DISK_PIPE_END_WRITE);
- GNUNET_assert(plugin->server_read_task == GNUNET_SCHEDULER_NO_TASK);
+ GNUNET_assert (plugin->server_read_task == GNUNET_SCHEDULER_NO_TASK);
#if DEBUG_wlan
- GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
- "Adding server_read_task for the wlan-helper\n");
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
+ "Adding server_read_task for the wlan-helper\n");
#endif
- plugin->server_read_task = GNUNET_SCHEDULER_add_read_file(
- GNUNET_TIME_UNIT_FOREVER_REL, plugin->server_stdout_handle,
- &wlan_plugin_helper_read, plugin);
+ plugin->server_read_task =
+ GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ plugin->server_stdout_handle,
+ &wlan_plugin_helper_read, plugin);
return GNUNET_YES;
}
@@ -2703,55 +2798,55 @@
//FIXME cleanup
void *
-libgnunet_plugin_transport_wlan_done(void *cls)
+libgnunet_plugin_transport_wlan_done (void *cls)
{
struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
struct Plugin *plugin = api->cls;
- struct MacEndpoint * endpoint = plugin->mac_head;
- struct MacEndpoint * endpoint_next;
+ struct MacEndpoint *endpoint = plugin->mac_head;
+ struct MacEndpoint *endpoint_next;
#if DEBUG_wlan
- GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
- "libgnunet_plugin_transport_wlan_done started\n");
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
+ "libgnunet_plugin_transport_wlan_done started\n");
#endif
- GNUNET_DISK_pipe_close(plugin->server_stdout);
- GNUNET_DISK_pipe_close(plugin->server_stdin);
- GNUNET_OS_process_kill(plugin->server_proc, 9);
- GNUNET_OS_process_close(plugin->server_proc);
+ GNUNET_DISK_pipe_close (plugin->server_stdout);
+ GNUNET_DISK_pipe_close (plugin->server_stdin);
+ GNUNET_OS_process_kill (plugin->server_proc, 9);
+ GNUNET_OS_process_close (plugin->server_proc);
- GNUNET_assert (cls !=NULL);
+ GNUNET_assert (cls != NULL);
//free sessions
while (endpoint != NULL)
- {
- endpoint_next = endpoint->next;
- free_macendpoint(plugin, endpoint);
- endpoint = endpoint_next;
+ {
+ endpoint_next = endpoint->next;
+ free_macendpoint (plugin, endpoint);
+ endpoint = endpoint_next;
- }
+ }
if (plugin->server_write_delay_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel(plugin->server_write_delay_task);
- plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (plugin->server_write_delay_task);
+ plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK;
+ }
if (plugin->server_write_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel(plugin->server_write_task);
- plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (plugin->server_write_task);
+ plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
+ }
if (plugin->server_read_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel(plugin->server_read_task);
- plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (plugin->server_read_task);
+ plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK;
+ }
if (plugin->suid_tokenizer != NULL)
- GNUNET_SERVER_mst_destroy(plugin->suid_tokenizer);
+ GNUNET_SERVER_mst_destroy (plugin->suid_tokenizer);
if (plugin->data_tokenizer != NULL)
- GNUNET_SERVER_mst_destroy(plugin->data_tokenizer);
+ GNUNET_SERVER_mst_destroy (plugin->data_tokenizer);
- GNUNET_free_non_null(plugin->interface);
+ GNUNET_free_non_null (plugin->interface);
GNUNET_free (plugin);
GNUNET_free (api);
return NULL;
@@ -2764,7 +2859,7 @@
* @return the 'struct GNUNET_TRANSPORT_PluginFunctions*' or NULL on error
*/
void *
-libgnunet_plugin_transport_wlan_init(void *cls)
+libgnunet_plugin_transport_wlan_init (void *cls)
{
//struct GNUNET_SERVICE_Context *service;
struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
@@ -2772,7 +2867,7 @@
struct Plugin *plugin;
static unsigned long long testmode = 0;
- GNUNET_assert(cls !=NULL);
+ GNUNET_assert (cls != NULL);
plugin = GNUNET_malloc (sizeof (struct Plugin));
plugin->env = env;
@@ -2781,13 +2876,14 @@
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;
- GNUNET_BANDWIDTH_tracker_init(&plugin->tracker,
- GNUNET_BANDWIDTH_value_init(100 * 1024 * 1024 / 8), 100);
+ GNUNET_BANDWIDTH_tracker_init (&plugin->tracker,
+ GNUNET_BANDWIDTH_value_init (100 * 1024 *
+ 1024 / 8), 100);
- plugin->suid_tokenizer = GNUNET_SERVER_mst_create(&wlan_process_helper,
- plugin);
+ plugin->suid_tokenizer = GNUNET_SERVER_mst_create (&wlan_process_helper,
+ plugin);
- plugin->data_tokenizer = GNUNET_SERVER_mst_create(&process_data, plugin);
+ plugin->data_tokenizer = GNUNET_SERVER_mst_create (&process_data, plugin);
//plugin->sessions = GNUNET_malloc (sizeof (struct Sessionqueue));
//plugin->pending_Sessions_head = GNUNET_malloc (sizeof (struct
Sessionqueue));
@@ -2801,30 +2897,35 @@
api->address_to_string = &wlan_plugin_address_to_string;
//read config
- if (GNUNET_CONFIGURATION_have_value(env->cfg, "transport-wlan", "TESTMODE"))
- {
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(env->cfg,
- "transport-wlan", "TESTMODE", &testmode))
- testmode = 0; //default value
- }
+ if (GNUNET_CONFIGURATION_have_value (env->cfg, "transport-wlan", "TESTMODE"))
+ {
+ if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (env->cfg,
+
"transport-wlan",
+ "TESTMODE",
+ &testmode))
+ testmode = 0; //default value
+ }
- if (GNUNET_CONFIGURATION_have_value(env->cfg, "transport-wlan", "INTERFACE"))
+ if (GNUNET_CONFIGURATION_have_value (env->cfg, "transport-wlan",
"INTERFACE"))
+ {
+ if (GNUNET_CONFIGURATION_get_value_string (env->cfg, "transport-wlan",
+ "INTERFACE",
+ &(plugin->interface)) !=
+ GNUNET_YES)
{
- if (GNUNET_CONFIGURATION_get_value_string(env->cfg, "transport-wlan",
- "INTERFACE", &(plugin->interface)) != GNUNET_YES)
- {
- libgnunet_plugin_transport_wlan_done(api);
- return NULL;
- }
+ libgnunet_plugin_transport_wlan_done (api);
+ return NULL;
}
+ }
//start the plugin
- set_next_beacon_time(plugin);
+ set_next_beacon_time (plugin);
- wlan_transport_start_wlan_helper(plugin, testmode);
+ wlan_transport_start_wlan_helper (plugin, testmode);
#if DEBUG_wlan
- GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, "wlan init
finished\n");
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
+ "wlan init finished\n");
#endif
return api;
Modified: gnunet/src/transport/plugin_transport_wlan.h
===================================================================
--- gnunet/src/transport/plugin_transport_wlan.h 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/transport/plugin_transport_wlan.h 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -72,41 +72,39 @@
/* Wlan IEEE80211 header default */
//Informations (in German)
http://www.umtslink.at/content/WLAN_macheader-196.html
-static const uint8_t u8aIeeeHeader[] =
- { 0x08, 0x01, // Frame Control 0x08= 00001000 -> | b1,2 = 0 -> Version 0;
- // b3,4 = 10 -> Data; b5-8 = 0 -> Normal Data
- // 0x01 = 00000001 -> | b1 = 1 to DS; b2 = 0 not from DS;
- 0x00, 0x00, // Duration/ID
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // mac1 - in this case receiver
- 0x13, 0x22, 0x33, 0x44, 0x55, 0x66, // mac2 - in this case sender
- 0x13, 0x22, 0x33, 0x44, 0x55, 0x66, // mac3 - in this case bssid
- 0x10, 0x86, //Sequence Control
- };
+static const uint8_t u8aIeeeHeader[] = { 0x08, 0x01, // Frame Control 0x08=
00001000 -> | b1,2 = 0 -> Version 0;
+ // b3,4 = 10 -> Data; b5-8 = 0 -> Normal Data
+ // 0x01 = 00000001 -> | b1 = 1 to DS; b2 = 0 not from DS;
+ 0x00, 0x00, // Duration/ID
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // mac1 - in this case receiver
+ 0x13, 0x22, 0x33, 0x44, 0x55, 0x66, // mac2 - in this case sender
+ 0x13, 0x22, 0x33, 0x44, 0x55, 0x66, // mac3 - in this case bssid
+ 0x10, 0x86, //Sequence Control
+};
// gnunet bssid
-static const struct MacAddress mac_bssid =
- {
- { 0x13, 0x22, 0x33, 0x44, 0x55, 0x66 } };
+static const struct MacAddress mac_bssid = {
+ {0x13, 0x22, 0x33, 0x44, 0x55, 0x66}
+};
// broadcast mac
-static const struct MacAddress bc_all_mac =
- {
- { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } };
+static const struct MacAddress bc_all_mac = {
+ {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}
+};
/* this is the template radiotap header we send packets out with */
-static const uint8_t u8aRadiotapHeader[] =
- { 0x00, 0x00, // <-- radiotap version
- 0x19, 0x00, // <- radiotap header length
- 0x6f, 0x08, 0x00, 0x00, // <-- bitmap
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // <-- timestamp
- 0x00, // <-- flags (Offset +0x10)
- 0x6c, // <-- rate (0ffset +0x11)
- 0x71, 0x09, 0xc0, 0x00, // <-- channel
- 0xde, // <-- antsignal
- 0x00, // <-- antnoise
- 0x01, // <-- antenna
- };
+static const uint8_t u8aRadiotapHeader[] = { 0x00, 0x00, // <--
radiotap version
+ 0x19, 0x00, // <- radiotap header length
+ 0x6f, 0x08, 0x00, 0x00, // <-- bitmap
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // <-- timestamp
+ 0x00, // <-- flags (Offset +0x10)
+ 0x6c, // <-- rate (0ffset +0x11)
+ 0x71, 0x09, 0xc0, 0x00, // <-- channel
+ 0xde, // <-- antsignal
+ 0x00, // <-- antnoise
+ 0x01, // <-- antenna
+};
struct Radiotap_Send
{
Modified: gnunet/src/transport/test_plugin_transport.c
===================================================================
--- gnunet/src/transport/test_plugin_transport.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/transport/test_plugin_transport.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -90,9 +90,8 @@
receive (void *cls,
const struct GNUNET_PeerIdentity
*peer, const struct GNUNET_MessageHeader *message,
- uint32_t distance,
- const char *sender_address,
- size_t sender_address_len)
+ uint32_t distance,
+ const char *sender_address, size_t sender_address_len)
{
/* do nothing */
}
@@ -116,8 +115,7 @@
unload_plugins (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
GNUNET_assert (NULL ==
- GNUNET_PLUGIN_unload ("libgnunet_plugin_transport_tcp",
- api));
+ GNUNET_PLUGIN_unload ("libgnunet_plugin_transport_tcp", api));
if (my_private_key != NULL)
GNUNET_CRYPTO_rsa_key_free (my_private_key);
@@ -128,6 +126,7 @@
unload_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_CONFIGURATION_Handle *cfg = cls;
+
unload_plugins (NULL, cfg);
}
@@ -160,8 +159,7 @@
soaddr.sin_port = htons (2368 /* FIXME: get from config! */ );
soaddr.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
GNUNET_assert (GNUNET_OK ==
- api->check_address (api->cls,
- &soaddr, sizeof (soaddr)));
+ api->check_address (api->cls, &soaddr, sizeof (soaddr)));
ok = 0;
GNUNET_SCHEDULER_add_continuation (&unload_task,
(void *) cfg,
@@ -207,24 +205,23 @@
GNUNET_CONFIGURATION_get_value_filename (c,
"GNUNETD",
"HOSTKEY", &keyfile)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _
- ("Transport service is lacking key configuration settings.
Exiting.\n"));
- GNUNET_SCHEDULER_shutdown (s);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _
+ ("Transport service is lacking key configuration settings.
Exiting.\n"));
+ GNUNET_SCHEDULER_shutdown (s);
+ return;
+ }
max_connect_per_transport = (uint32_t) tneigh;
my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
GNUNET_free (keyfile);
if (my_private_key == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _
- ("Transport service could not access hostkey. Exiting.\n"));
- GNUNET_SCHEDULER_shutdown (s);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Transport service could not access hostkey. Exiting.\n"));
+ GNUNET_SCHEDULER_shutdown (s);
+ return;
+ }
GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key);
GNUNET_CRYPTO_hash (&my_public_key,
sizeof (my_public_key), &my_identity.hashPubKey);
@@ -239,12 +236,12 @@
api = GNUNET_PLUGIN_load (libname, &env);
GNUNET_free (libname);
if (api == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to load transport plugin for tcp\n"));
- /* FIXME: set some error code for main */
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to load transport plugin for tcp\n"));
+ /* FIXME: set some error code for main */
+ return;
+ }
test_validation ();
}
@@ -263,6 +260,7 @@
GNUNET_GETOPT_OPTION_END
};
int ret;
+
char *const argv_prog[] = {
"test_plugin_transport",
"-c",
Modified: gnunet/src/transport/test_plugin_transport_http.c
===================================================================
--- gnunet/src/transport/test_plugin_transport_http.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/transport/test_plugin_transport_http.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -75,12 +75,12 @@
/**
* Next field for linked list
*/
- struct Plugin_Address * next;
+ struct Plugin_Address *next;
/**
* buffer containing data to send
*/
- void * addr;
+ void *addr;
/**
* amount of data to sent
@@ -162,9 +162,9 @@
*/
struct IPv4HttpAddress
{
- struct IPv4HttpAddress * next;
+ struct IPv4HttpAddress *next;
- struct IPv4HttpAddress * prev;
+ struct IPv4HttpAddress *prev;
/**
* IPv4 address, in network byte order.
@@ -184,9 +184,9 @@
*/
struct IPv6HttpAddress
{
- struct IPv6HttpAddress * next;
+ struct IPv6HttpAddress *next;
- struct IPv6HttpAddress * prev;
+ struct IPv6HttpAddress *prev;
/**
* IPv6 address.
@@ -229,7 +229,7 @@
/**
* Peer's addr
*/
-static char * test_addr;
+static char *test_addr;
/**
* Our statistics handle.
@@ -277,12 +277,13 @@
static struct HTTP_Message buffer_in;
-struct Plugin_Address * addr_head;
+struct Plugin_Address *addr_head;
/**
* Did the test pass or fail?
*/
static int fail_notify_address;
+
/**
* Did the test pass or fail?
*/
@@ -386,7 +387,7 @@
*/
static GNUNET_SCHEDULER_TaskIdentifier http_task_send;
-static char * servicehome;
+static char *servicehome;
/**
* Shutdown testcase
@@ -394,54 +395,52 @@
static void
shutdown_clean ()
{
- struct Plugin_Address * tmp;
+ struct Plugin_Address *tmp;
/* Evaluate results */
fail = 0;
- if ( (fail_notify_address == GNUNET_YES) ||
- (fail_pretty_printer == GNUNET_YES) ||
- (fail_addr_to_str == GNUNET_YES))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Phase 0: Test plugin functions failed\n");
- fail = 1;
- }
- if ( (test_no_ident.test_failed == GNUNET_YES) ||
- (test_too_short_ident.test_failed == GNUNET_YES) ||
- (test_too_long_ident.test_failed == GNUNET_YES) ||
- (test_valid_ident.test_failed == GNUNET_YES) )
+ if ((fail_notify_address == GNUNET_YES) ||
+ (fail_pretty_printer == GNUNET_YES) || (fail_addr_to_str == GNUNET_YES))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Phase 0: Test plugin functions failed\n");
+ fail = 1;
+ }
+ if ((test_no_ident.test_failed == GNUNET_YES) ||
+ (test_too_short_ident.test_failed == GNUNET_YES) ||
+ (test_too_long_ident.test_failed == GNUNET_YES) ||
+ (test_valid_ident.test_failed == GNUNET_YES))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Phase 1: Test connect with wrong data failed\n");
fail = 1;
}
- if ( (fail_session_selection_any != GNUNET_NO) ||
- (fail_session_selection_reliable != GNUNET_NO) ||
- (fail_session_selection_session != GNUNET_NO) ||
- (fail_session_selection_session_big != GNUNET_NO) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Phase 2: Test session selection failed\n");
- fail = 1;
- }
- if ( (fail_msgs_transmited_to_local_addrs != count_str_addr) ||
- (fail_multiple_msgs_in_transmission != 2) ||
- (fail_msg_transmited_max_size == GNUNET_YES) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Phase 3: Test sending with plugin failed\n");
- fail = 1;
- }
+ if ((fail_session_selection_any != GNUNET_NO) ||
+ (fail_session_selection_reliable != GNUNET_NO) ||
+ (fail_session_selection_session != GNUNET_NO) ||
+ (fail_session_selection_session_big != GNUNET_NO))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Phase 2: Test session selection failed\n");
+ fail = 1;
+ }
+ if ((fail_msgs_transmited_to_local_addrs != count_str_addr) ||
+ (fail_multiple_msgs_in_transmission != 2) ||
+ (fail_msg_transmited_max_size == GNUNET_YES))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Phase 3: Test sending with plugin failed\n");
+ fail = 1;
+ }
if (fail != 1)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "All tests successful\n");
- }
-
- api->disconnect(api->cls,&my_identity);
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All tests successful\n");
+ }
- curl_multi_cleanup(multi_handle);
+ api->disconnect (api->cls, &my_identity);
+ curl_multi_cleanup (multi_handle);
+
if (NULL != curl_handle)
curl_easy_cleanup (curl_handle);
@@ -451,37 +450,37 @@
tmp = addr_head->next;
GNUNET_free (addr_head->addr);
GNUNET_free (addr_head);
- addr_head=tmp;
+ addr_head = tmp;
}
if (ti_send != GNUNET_SCHEDULER_NO_TASK)
{
- GNUNET_SCHEDULER_cancel(ti_send);
+ GNUNET_SCHEDULER_cancel (ti_send);
ti_send = GNUNET_SCHEDULER_NO_TASK;
}
if (http_task_send != GNUNET_SCHEDULER_NO_TASK)
{
- GNUNET_SCHEDULER_cancel(http_task_send);
+ GNUNET_SCHEDULER_cancel (http_task_send);
http_task_send = GNUNET_SCHEDULER_NO_TASK;
}
if (ti_timeout != GNUNET_SCHEDULER_NO_TASK)
{
- GNUNET_SCHEDULER_cancel(ti_timeout);
+ GNUNET_SCHEDULER_cancel (ti_timeout);
ti_timeout = GNUNET_SCHEDULER_NO_TASK;
}
- GNUNET_free(test_addr);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Unloading http plugin\n");
- GNUNET_assert (NULL == GNUNET_PLUGIN_unload
("libgnunet_gnunet_transport_plugin_http", api));
+ GNUNET_free (test_addr);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Unloading http plugin\n");
+ GNUNET_assert (NULL ==
+ GNUNET_PLUGIN_unload
("libgnunet_gnunet_transport_plugin_http",
+ api));
- GNUNET_SCHEDULER_shutdown();
+ GNUNET_SCHEDULER_shutdown ();
GNUNET_DISK_directory_remove ("/tmp/test_gnunet_transport_plugin_http");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Exiting testcase\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Exiting testcase\n");
if (servicehome != NULL)
{
@@ -489,7 +488,7 @@
GNUNET_free (servicehome);
}
- exit(fail);
+ exit (fail);
return;
}
@@ -502,102 +501,98 @@
*/
static void
-task_send_cont (void *cls,
- const struct GNUNET_PeerIdentity * target,
- int result)
+task_send_cont (void *cls, const struct GNUNET_PeerIdentity *target, int
result)
{
- if ((cls == &fail_msg_transmited_bigger_max_size) && (result ==
GNUNET_SYSERR))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Message bigger max msg size was not sent!\n");
- fail_msg_transmited_bigger_max_size = GNUNET_NO;
- return;
- }
+ if ((cls == &fail_msg_transmited_bigger_max_size) &&
+ (result == GNUNET_SYSERR))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Message bigger max msg size was not sent!\n");
+ fail_msg_transmited_bigger_max_size = GNUNET_NO;
+ return;
+ }
if ((cls == &fail_msg_transmited_max_size) && (result == GNUNET_OK))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Message with max msg size succesfully sent!\n",
- fail_msgs_transmited_to_local_addrs);
- fail_msg_transmited_max_size = GNUNET_NO;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Message with max msg size succesfully sent!\n",
+ fail_msgs_transmited_to_local_addrs);
+ fail_msg_transmited_max_size = GNUNET_NO;
+ }
}
-static void run_connection_tests( int phase , void * cls);
+static void run_connection_tests (int phase, void *cls);
/**
* Recieves messages from plugin, in real world transport
*/
static struct GNUNET_TIME_Relative
receive (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_MessageHeader *message,
- const struct GNUNET_TRANSPORT_ATS_Information *ats,
- uint32_t ats_count,
- struct Session *session,
- const char *sender_address,
- uint16_t sender_address_len)
+ const struct GNUNET_MessageHeader *message,
+ const struct GNUNET_TRANSPORT_ATS_Information *ats,
+ uint32_t ats_count,
+ struct Session *session,
+ const char *sender_address, uint16_t sender_address_len)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Testcase recieved new message from peer `%s' with type %u and
length %u, session %X\n",
- GNUNET_i2s(peer),
- ntohs(message->type),
- ntohs(message->size),
- session);
+ GNUNET_i2s (peer),
+ ntohs (message->type), ntohs (message->size), session);
- if ( (ntohs(message->type)>=10) &&
- (ntohs(message->type)<20) )
- {
- fail_msgs_transmited_to_local_addrs++;
- if (fail_msgs_transmited_to_local_addrs == count_str_addr)
- run_connection_tests(2, session);
- }
- if ((ntohs(message->type)==20))
- {
- fail_session_selection_reliable = GNUNET_NO;
- }
- if ((ntohs(message->type)==21))
- {
- fail_session_selection_any = GNUNET_NO;
- }
- if ((ntohs(message->type)==22))
- {
- fail_session_selection_session = GNUNET_NO;
- }
- if ((ntohs(message->type)==23))
- {
- fail_session_selection_session_big = GNUNET_NO;
- run_connection_tests(3, NULL);
- }
- if ((ntohs(message->type)==30) || (ntohs(message->type)==31))
- {
- fail_multiple_msgs_in_transmission ++;
- }
- if ((ntohs(message->type)==32) && (ntohs(message->size) ==
GNUNET_SERVER_MAX_MESSAGE_SIZE-1))
- {
- fail_msg_transmited_max_size = GNUNET_NO;
- shutdown_clean();
- }
+ if ((ntohs (message->type) >= 10) && (ntohs (message->type) < 20))
+ {
+ fail_msgs_transmited_to_local_addrs++;
+ if (fail_msgs_transmited_to_local_addrs == count_str_addr)
+ run_connection_tests (2, session);
+ }
+ if ((ntohs (message->type) == 20))
+ {
+ fail_session_selection_reliable = GNUNET_NO;
+ }
+ if ((ntohs (message->type) == 21))
+ {
+ fail_session_selection_any = GNUNET_NO;
+ }
+ if ((ntohs (message->type) == 22))
+ {
+ fail_session_selection_session = GNUNET_NO;
+ }
+ if ((ntohs (message->type) == 23))
+ {
+ fail_session_selection_session_big = GNUNET_NO;
+ run_connection_tests (3, NULL);
+ }
+ if ((ntohs (message->type) == 30) || (ntohs (message->type) == 31))
+ {
+ fail_multiple_msgs_in_transmission++;
+ }
+ if ((ntohs (message->type) == 32) &&
+ (ntohs (message->size) == GNUNET_SERVER_MAX_MESSAGE_SIZE - 1))
+ {
+ fail_msg_transmited_max_size = GNUNET_NO;
+ shutdown_clean ();
+ }
return GNUNET_TIME_UNIT_ZERO;
}
-static size_t
+static size_t
send_function (void *stream, size_t size, size_t nmemb, void *ptr)
{
unsigned int len;
len = buffer_out.len;
- if (( buffer_out.pos == len) || (len > (size * nmemb)))
+ if ((buffer_out.pos == len) || (len > (size * nmemb)))
return 0;
- memcpy(stream, buffer_out.buf, len);
+ memcpy (stream, buffer_out.buf, len);
buffer_out.pos = len;
return len;
}
-static size_t
+static size_t
recv_function (void *ptr, size_t size, size_t nmemb, void *ctx)
{
@@ -613,54 +608,50 @@
}
static size_t
-header_function( void *ptr, size_t size, size_t nmemb, void *stream)
+header_function (void *ptr, size_t size, size_t nmemb, void *stream)
{
- struct HTTP_Transfer * res = stream;
- char * tmp;
+ struct HTTP_Transfer *res = stream;
+ char *tmp;
unsigned int len = size * nmemb;
- tmp = GNUNET_malloc ( len+1 );
- memcpy(tmp,ptr,len);
- if (tmp[len-2] == 13)
- tmp[len-2]= '\0';
+ tmp = GNUNET_malloc (len + 1);
+ memcpy (tmp, ptr, len);
+ if (tmp[len - 2] == 13)
+ tmp[len - 2] = '\0';
#if DEBUG_CURL
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Header: `%s'\n",
- tmp);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Header: `%s'\n", tmp);
#endif
- if (0==strcmp (tmp,"HTTP/1.1 100 Continue"))
- {
- res->http_result_code=100;
- }
- if (0==strcmp (tmp,"HTTP/1.1 200 OK"))
- {
- res->http_result_code=200;
- }
- if (0==strcmp (tmp,"HTTP/1.1 400 Bad Request"))
- {
- res->http_result_code=400;
- }
- if (0==strcmp (tmp,"HTTP/1.1 404 Not Found"))
- {
- res->http_result_code=404;
- }
- if (0==strcmp (tmp,"HTTP/1.1 413 Request entity too large"))
- {
- res->http_result_code=413;
- }
-
+ if (0 == strcmp (tmp, "HTTP/1.1 100 Continue"))
+ {
+ res->http_result_code = 100;
+ }
+ if (0 == strcmp (tmp, "HTTP/1.1 200 OK"))
+ {
+ res->http_result_code = 200;
+ }
+ if (0 == strcmp (tmp, "HTTP/1.1 400 Bad Request"))
+ {
+ res->http_result_code = 400;
+ }
+ if (0 == strcmp (tmp, "HTTP/1.1 404 Not Found"))
+ {
+ res->http_result_code = 404;
+ }
+ if (0 == strcmp (tmp, "HTTP/1.1 413 Request entity too large"))
+ {
+ res->http_result_code = 413;
+ }
+
GNUNET_free (tmp);
return size * nmemb;
}
-static size_t
-send_prepare( struct HTTP_Transfer * result);
+static size_t send_prepare (struct HTTP_Transfer *result);
-static void
-send_execute (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+static void
+send_execute (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct HTTP_Transfer *res;
@@ -674,104 +665,106 @@
return;
do
+ {
+ running = 0;
+ mret = curl_multi_perform (multi_handle, &running);
+ if (running == 0)
{
- running = 0;
- mret = curl_multi_perform (multi_handle, &running);
- if (running == 0)
+ do
+ {
+
+ msg = curl_multi_info_read (multi_handle, &running);
+ if (msg == NULL)
+ break;
+ /* get session for affected curl handle */
+ //cs = find_session_by_curlhandle (msg->easy_handle);
+ //GNUNET_assert ( cs != NULL );
+ switch (msg->msg)
{
- do
- {
- msg = curl_multi_info_read (multi_handle, &running);
- if (msg == NULL)
- break;
- /* get session for affected curl handle */
- //cs = find_session_by_curlhandle (msg->easy_handle);
- //GNUNET_assert ( cs != NULL );
- switch (msg->msg)
- {
+ case CURLMSG_DONE:
+ if ((msg->data.result != CURLE_OK) &&
+ (msg->data.result != CURLE_GOT_NOTHING))
+ {
- case CURLMSG_DONE:
- if ( (msg->data.result != CURLE_OK) &&
- (msg->data.result != CURLE_GOT_NOTHING) )
- {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("curl failed for `%s' at %s:%d: `%s'\n"),
+ "curl_multi_perform",
+ __FILE__,
+ __LINE__, curl_easy_strerror (msg->data.result));
+ /* sending msg failed */
+ curl_easy_cleanup (curl_handle);
+ curl_handle = NULL;
- GNUNET_log(GNUNET_ERROR_TYPE_INFO,
- _("curl failed for `%s' at %s:%d: `%s'\n"),
- "curl_multi_perform",
- __FILE__,
- __LINE__,
- curl_easy_strerror (msg->data.result));
- /* sending msg failed*/
- curl_easy_cleanup(curl_handle);
- curl_handle=NULL;
-
- run_connection_tests(0, NULL);
- }
- if (res == &test_no_ident)
- {
- if ((res->http_result_code==404) && (buffer_in.len==208))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connecting to peer without any peer
identification: test passed\n");
- res->test_failed = GNUNET_NO;
- }
- else
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Connecting to peer without any peer
identification: test failed\n"));
- }
- if (res == &test_too_short_ident)
- {
- if ((res->http_result_code==404) && (buffer_in.len==208))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connecting to peer with too short peer
identification: test passed\n");
- res->test_failed = GNUNET_NO;
- }
- else
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Connecting to peer with too short peer
identification: test failed\n"));
- }
- if (res == &test_too_long_ident)
- {
- if ((res->http_result_code==404) && (buffer_in.len==208))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connecting to peer with too long peer
identification: test passed\n");
- res->test_failed = GNUNET_NO;
- }
- else
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Connecting to peer with too long peer
identification: test failed\n"));
- }
- if (res == &test_valid_ident)
- {
- if ((res->http_result_code==200))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connecting to peer with valid peer
identification: test passed\n");
- res->test_failed = GNUNET_NO;
- }
- else
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Connecting to peer with valid peer
identification: test failed\n");
- }
- curl_easy_cleanup(curl_handle);
- curl_handle=NULL;
- if ((res == &test_valid_ident) && (res->test_failed ==
GNUNET_NO))
- run_connection_tests(1, NULL);
- run_connection_tests(0, NULL);
- return;
- default:
- break;
- }
-
+ run_connection_tests (0, NULL);
+ }
+ if (res == &test_no_ident)
+ {
+ if ((res->http_result_code == 404) && (buffer_in.len == 208))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Connecting to peer without any peer identification:
test passed\n");
+ res->test_failed = GNUNET_NO;
}
- while ( (running > 0) );
+ else
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _
+ ("Connecting to peer without any peer
identification: test failed\n"));
+ }
+ if (res == &test_too_short_ident)
+ {
+ if ((res->http_result_code == 404) && (buffer_in.len == 208))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Connecting to peer with too short peer
identification: test passed\n");
+ res->test_failed = GNUNET_NO;
+ }
+ else
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _
+ ("Connecting to peer with too short peer
identification: test failed\n"));
+ }
+ if (res == &test_too_long_ident)
+ {
+ if ((res->http_result_code == 404) && (buffer_in.len == 208))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Connecting to peer with too long peer
identification: test passed\n");
+ res->test_failed = GNUNET_NO;
+ }
+ else
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _
+ ("Connecting to peer with too long peer
identification: test failed\n"));
+ }
+ if (res == &test_valid_ident)
+ {
+ if ((res->http_result_code == 200))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Connecting to peer with valid peer identification:
test passed\n");
+ res->test_failed = GNUNET_NO;
+ }
+ else
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Connecting to peer with valid peer identification:
test failed\n");
+ }
+ curl_easy_cleanup (curl_handle);
+ curl_handle = NULL;
+ if ((res == &test_valid_ident) && (res->test_failed == GNUNET_NO))
+ run_connection_tests (1, NULL);
+ run_connection_tests (0, NULL);
+ return;
+ default:
+ break;
}
+
+ }
+ while ((running > 0));
}
+ }
while (mret == CURLM_CALL_MULTI_PERFORM);
- send_prepare(cls);
+ send_prepare (cls);
}
@@ -781,7 +774,7 @@
* @return bytes sent to peer
*/
static size_t
-send_prepare( struct HTTP_Transfer * result)
+send_prepare (struct HTTP_Transfer *result)
{
fd_set rs;
fd_set ws;
@@ -798,34 +791,33 @@
FD_ZERO (&es);
mret = curl_multi_fdset (multi_handle, &rs, &ws, &es, &max);
if (mret != CURLM_OK)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("%s failed at %s:%d: `%s'\n"),
- "curl_multi_fdset", __FILE__, __LINE__,
- curl_multi_strerror (mret));
- return -1;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("%s failed at %s:%d: `%s'\n"),
+ "curl_multi_fdset", __FILE__, __LINE__,
+ curl_multi_strerror (mret));
+ return -1;
+ }
mret = curl_multi_timeout (multi_handle, &to);
if (mret != CURLM_OK)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("%s failed at %s:%d: `%s'\n"),
- "curl_multi_timeout", __FILE__, __LINE__,
- curl_multi_strerror (mret));
- return -1;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("%s failed at %s:%d: `%s'\n"),
+ "curl_multi_timeout", __FILE__, __LINE__,
+ curl_multi_strerror (mret));
+ return -1;
+ }
grs = GNUNET_NETWORK_fdset_create ();
gws = GNUNET_NETWORK_fdset_create ();
GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1);
GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1);
- http_task_send = GNUNET_SCHEDULER_add_select
(GNUNET_SCHEDULER_PRIORITY_DEFAULT,
- GNUNET_SCHEDULER_NO_TASK,
- GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_SECONDS, 0),
- grs,
- gws,
- &send_execute,
- result);
+ http_task_send =
+ GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
+ GNUNET_SCHEDULER_NO_TASK,
+ GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 0), grs, gws,
+ &send_execute, result);
GNUNET_NETWORK_fdset_destroy (gws);
GNUNET_NETWORK_fdset_destroy (grs);
@@ -836,35 +828,35 @@
/**
* function to send data to server
*/
-static int
-send_data(struct HTTP_Transfer * result,
- char * url)
+static int
+send_data (struct HTTP_Transfer *result, char *url)
{
- curl_handle = curl_easy_init();
- if( NULL == curl_handle)
- {
- printf("easy_init failed \n");
- return GNUNET_SYSERR;
- }
+ curl_handle = curl_easy_init ();
+ if (NULL == curl_handle)
+ {
+ printf ("easy_init failed \n");
+ return GNUNET_SYSERR;
+ }
#if DEBUG_CURL
- curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1L);
+ curl_easy_setopt (curl_handle, CURLOPT_VERBOSE, 1L);
#endif
- curl_easy_setopt(curl_handle, CURLOPT_URL, url);
- curl_easy_setopt(curl_handle, CURLOPT_PUT, 1L);
+ curl_easy_setopt (curl_handle, CURLOPT_URL, url);
+ curl_easy_setopt (curl_handle, CURLOPT_PUT, 1L);
curl_easy_setopt (curl_handle, CURLOPT_HEADERFUNCTION, &header_function);
curl_easy_setopt (curl_handle, CURLOPT_WRITEHEADER, result);
curl_easy_setopt (curl_handle, CURLOPT_WRITEFUNCTION, &recv_function);
curl_easy_setopt (curl_handle, CURLOPT_WRITEDATA, result);
curl_easy_setopt (curl_handle, CURLOPT_READFUNCTION, &send_function);
curl_easy_setopt (curl_handle, CURLOPT_READDATA, result);
- curl_easy_setopt(curl_handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t)
buffer_out.len);
- curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, 30);
- curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT, 20);
+ curl_easy_setopt (curl_handle, CURLOPT_INFILESIZE_LARGE,
+ (curl_off_t) buffer_out.len);
+ curl_easy_setopt (curl_handle, CURLOPT_TIMEOUT, 30);
+ curl_easy_setopt (curl_handle, CURLOPT_CONNECTTIMEOUT, 20);
- curl_multi_add_handle(multi_handle, curl_handle);
+ curl_multi_add_handle (multi_handle, curl_handle);
- send_prepare(result);
+ send_prepare (result);
return GNUNET_OK;
}
@@ -873,58 +865,54 @@
* Plugin notifies transport (aka testcase) about its addresses
*/
static void
-notify_address (void *cls,
- int add_remove,
- const void *addr,
- size_t addrlen)
+notify_address (void *cls, int add_remove, const void *addr, size_t addrlen)
{
char address[INET6_ADDRSTRLEN];
unsigned int port;
- struct Plugin_Address * pl_addr;
- struct Plugin_Address * cur;
+ struct Plugin_Address *pl_addr;
+ struct Plugin_Address *cur;
if (addrlen == (sizeof (struct IPv4HttpAddress)))
- {
- inet_ntop(AF_INET, (struct in_addr *) addr,address,INET_ADDRSTRLEN);
- port = ntohs(((struct IPv4HttpAddress *) addr)->u_port);
- }
+ {
+ inet_ntop (AF_INET, (struct in_addr *) addr, address, INET_ADDRSTRLEN);
+ port = ntohs (((struct IPv4HttpAddress *) addr)->u_port);
+ }
else if (addrlen == (sizeof (struct IPv6HttpAddress)))
- {
- inet_ntop(AF_INET6, (struct in6_addr *) addr,address,INET6_ADDRSTRLEN);
- port = ntohs(((struct IPv6HttpAddress *) addr)->u6_port);
- }
+ {
+ inet_ntop (AF_INET6, (struct in6_addr *) addr, address, INET6_ADDRSTRLEN);
+ port = ntohs (((struct IPv6HttpAddress *) addr)->u6_port);
+ }
else
- {
+ {
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Unknown address size: ipv6 has %u ipv4 has %u but this has
%u\n"),
+ _
+ ("Unknown address size: ipv6 has %u ipv4 has %u but this has
%u\n"),
sizeof (struct IPv6HttpAddress),
- sizeof (struct IPv4HttpAddress),
- addrlen);
- return;
- }
+ sizeof (struct IPv4HttpAddress), addrlen);
+ return;
+ }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
_("Transport plugin notification for address: `%s':%u\n"),
- address,
- port);
- pl_addr = GNUNET_malloc (sizeof (struct Plugin_Address) );
+ address, port);
+ pl_addr = GNUNET_malloc (sizeof (struct Plugin_Address));
pl_addr->addrlen = addrlen;
- pl_addr->addr = GNUNET_malloc(addrlen);
- memcpy(pl_addr->addr,addr,addrlen);
+ pl_addr->addr = GNUNET_malloc (addrlen);
+ memcpy (pl_addr->addr, addr, addrlen);
pl_addr->next = NULL;
- if ( NULL == addr_head)
- {
- addr_head = pl_addr;
- }
+ if (NULL == addr_head)
+ {
+ addr_head = pl_addr;
+ }
else
+ {
+ cur = addr_head;
+ while (NULL != cur->next)
{
- cur = addr_head;
- while (NULL != cur->next)
- {
- cur = cur->next;
- }
- cur->next = pl_addr;
+ cur = cur->next;
}
+ cur->next = pl_addr;
+ }
fail_notify_address_count++;
fail_notify_address = GNUNET_NO;
}
@@ -936,8 +924,7 @@
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Pluging tells me: session %X to peer `%s' ended\n",
- session,
- GNUNET_i2s(peer));
+ session, GNUNET_i2s (peer));
}
@@ -962,8 +949,7 @@
* Task shutting down testcase if it a timeout occurs
*/
static void
-task_timeout (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+task_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
ti_timeout = GNUNET_SCHEDULER_NO_TASK;
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
@@ -971,35 +957,34 @@
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testcase timeout\n");
fail = GNUNET_YES;
- shutdown_clean();
+ shutdown_clean ();
return;
}
-static void
-pretty_printer_cb (void *cls,
- const char *address)
+static void
+pretty_printer_cb (void *cls, const char *address)
{
- if (NULL==address)
+ if (NULL == address)
return;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Plugin returned pretty address: `%s'\n",
- address);
+ "Plugin returned pretty address: `%s'\n", address);
fail_pretty_printer_count++;
}
/**
* Runs every single test to test the plugin
*/
-static void
-run_connection_tests( int phase , void * cls)
+static void
+run_connection_tests (int phase, void *cls)
{
- struct GNUNET_MessageHeader * msg;
+ struct GNUNET_MessageHeader *msg;
unsigned int size;
- if (phase==0)
+ if (phase == 0)
{
- char * host_str = NULL;
+ char *host_str = NULL;
+
/* resetting buffers */
buffer_in.size = HTTP_BUFFER_SIZE;
buffer_in.pos = 0;
@@ -1010,217 +995,210 @@
buffer_out.len = 0;
if (test_no_ident.test_executed == GNUNET_NO)
- {
- /* Connecting to peer without identification */
- const char * ident = "";
- GNUNET_asprintf (&host_str,
- "%s://%s/%s",
- PROTOCOL_PREFIX,
- test_addr,ident);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Connecting to peer without any peer
identification.\n"));
- test_no_ident.test_executed = GNUNET_YES;
- send_data ( &test_no_ident, host_str);
- GNUNET_free (host_str);
- return;
- }
+ {
+ /* Connecting to peer without identification */
+ const char *ident = "";
+
+ GNUNET_asprintf (&host_str,
+ "%s://%s/%s", PROTOCOL_PREFIX, test_addr, ident);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ _("Connecting to peer without any peer identification.\n"));
+ test_no_ident.test_executed = GNUNET_YES;
+ send_data (&test_no_ident, host_str);
+ GNUNET_free (host_str);
+ return;
+ }
if (test_too_short_ident.test_executed == GNUNET_NO)
- {
- const char * ident = "AAAAAAAAAA";
- /* Connecting to peer with too short identification */
- GNUNET_asprintf (&host_str,
- "%s://%s/%s",
- PROTOCOL_PREFIX,
- test_addr,
- ident);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Connecting to peer with too short peer
identification.\n"));
- test_too_short_ident.test_executed = GNUNET_YES;
- send_data ( &test_too_short_ident, host_str);
- GNUNET_free (host_str);
- return;
- }
+ {
+ const char *ident = "AAAAAAAAAA";
+ /* Connecting to peer with too short identification */
+ GNUNET_asprintf (&host_str,
+ "%s://%s/%s", PROTOCOL_PREFIX, test_addr, ident);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ _
+ ("Connecting to peer with too short peer
identification.\n"));
+ test_too_short_ident.test_executed = GNUNET_YES;
+ send_data (&test_too_short_ident, host_str);
+ GNUNET_free (host_str);
+ return;
+ }
+
if (test_too_long_ident.test_executed == GNUNET_NO)
- {
- const char * ident =
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
+ {
+ const char *ident =
+
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
- /* Connecting to peer with too long identification */
- GNUNET_asprintf (&host_str, "%s://%s/%s",PROTOCOL_PREFIX,
test_addr,ident);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Connecting to peer with too long peer
identification.\n"));
- test_too_long_ident.test_executed = GNUNET_YES;
- send_data ( &test_too_long_ident, host_str);
- GNUNET_free (host_str);
- return;
+ /* Connecting to peer with too long identification */
+ GNUNET_asprintf (&host_str, "%s://%s/%s", PROTOCOL_PREFIX, test_addr,
+ ident);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ _("Connecting to peer with too long peer
identification.\n"));
+ test_too_long_ident.test_executed = GNUNET_YES;
+ send_data (&test_too_long_ident, host_str);
+ GNUNET_free (host_str);
+ return;
}
if (test_valid_ident.test_executed == GNUNET_NO)
- {
- struct GNUNET_CRYPTO_HashAsciiEncoded ident;
- GNUNET_CRYPTO_hash_to_enc(&my_identity.hashPubKey,&ident);
- GNUNET_asprintf (&host_str,
- "%s://%s/%s%s",
- PROTOCOL_PREFIX,
- test_addr,
- (char *) &ident,
- ";0");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Connecting to peer with valid peer identification.\n"));
- test_valid_ident.test_executed = GNUNET_YES;
- send_data ( &test_valid_ident, host_str);
- GNUNET_free (host_str);
- return;
- }
- }
- if (phase==1)
{
+ struct GNUNET_CRYPTO_HashAsciiEncoded ident;
+
+ GNUNET_CRYPTO_hash_to_enc (&my_identity.hashPubKey, &ident);
+ GNUNET_asprintf (&host_str,
+ "%s://%s/%s%s",
+ PROTOCOL_PREFIX, test_addr, (char *) &ident, ";0");
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "\nPhase 1: transmit data to all suggested addresses\n\n");
- /* Using one of the addresses the plugin proposed */
- GNUNET_assert (addr_head->addr != NULL);
-
- struct Plugin_Address * tmp_addr;
- struct GNUNET_MessageHeader msg;
- char * tmp = GNUNET_malloc(sizeof(struct GNUNET_MessageHeader));
- char address[INET6_ADDRSTRLEN];
- unsigned int port;
- unsigned int type = 10;
-
- msg.size=htons(sizeof(struct GNUNET_MessageHeader));
- tmp_addr = addr_head;
- /* send a message to all addresses advertised by plugin */
-
- int count = 0;
- while (tmp_addr != NULL)
- {
- if (tmp_addr->addrlen == (sizeof (struct IPv4HttpAddress)))
- {
- inet_ntop(AF_INET, (struct in_addr *)
tmp_addr->addr,address,INET_ADDRSTRLEN);
- port = ntohs(((struct IPv4HttpAddress *)
tmp_addr->addr)->u_port);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending message to addres no. %u: `%s':%u\n",
- count,
- address,
- port);
- }
- if (tmp_addr->addrlen == (sizeof (struct IPv6HttpAddress)))
- {
- inet_ntop(AF_INET6, (struct in6_addr *)
tmp_addr->addr,address,INET6_ADDRSTRLEN);
- port = ntohs(((struct IPv6HttpAddress *)
tmp_addr->addr)->u6_port);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending message to addres no. %u: `%s':%u\n",
- count,
- address,
- port);
- }
- msg.type=htons(type);
- memcpy(tmp,&msg,sizeof(struct GNUNET_MessageHeader));
- api->send(api->cls,
- &my_identity,
- tmp, sizeof(struct GNUNET_MessageHeader),
- 0, TIMEOUT,
- NULL,
- tmp_addr->addr, tmp_addr->addrlen,
- GNUNET_YES,
- &task_send_cont, &fail_msgs_transmited_to_local_addrs);
- tmp_addr = tmp_addr->next;
- count++;
- type++;
- }
- GNUNET_free(tmp);
+ _("Connecting to peer with valid peer identification.\n"));
+ test_valid_ident.test_executed = GNUNET_YES;
+ send_data (&test_valid_ident, host_str);
+ GNUNET_free (host_str);
return;
}
+ }
+ if (phase == 1)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "\nPhase 1: transmit data to all suggested addresses\n\n");
+ /* Using one of the addresses the plugin proposed */
+ GNUNET_assert (addr_head->addr != NULL);
- if (phase==2)
+ struct Plugin_Address *tmp_addr;
+ struct GNUNET_MessageHeader msg;
+ char *tmp = GNUNET_malloc (sizeof (struct GNUNET_MessageHeader));
+ char address[INET6_ADDRSTRLEN];
+ unsigned int port;
+ unsigned int type = 10;
+
+ msg.size = htons (sizeof (struct GNUNET_MessageHeader));
+ tmp_addr = addr_head;
+ /* send a message to all addresses advertised by plugin */
+
+ int count = 0;
+
+ while (tmp_addr != NULL)
{
- struct Session * session = cls;
- msg = GNUNET_malloc (sizeof(struct GNUNET_MessageHeader));
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Phase 2: session selection\n\n");
- size = sizeof(struct GNUNET_MessageHeader);
- msg->size=htons(size);
- msg->type = htons(20);
- api->send(api->cls,
- &my_identity,
- (const char *) msg, size,
- 0, TIMEOUT, NULL, NULL, 0, GNUNET_NO,
- &task_send_cont, NULL);
-
- msg->type = htons(21);
- api->send(api->cls,
- &my_identity,
- (const char *) msg, size,
- 0, TIMEOUT, NULL, NULL, 0, GNUNET_SYSERR,
- &task_send_cont, NULL);
-
- /* answer on session*/
- size = sizeof( struct GNUNET_MessageHeader);
- msg->size = htons(size);
- msg->type = htons(22);
- api->send(api->cls,
- &my_identity,
- (const char *) msg, size,
- 0, TIMEOUT, session, NULL, 0, GNUNET_SYSERR,
- &task_send_cont, NULL);
- GNUNET_free(msg);
-
- /* answer on session with big message not fitting in mhd send buffer*/
- size = GNUNET_SERVER_MAX_MESSAGE_SIZE-1;
- msg = GNUNET_malloc (size);
- msg->size=htons(size);
- msg->type = htons(23);
- api->send(api->cls,
- &my_identity,
- (const char *) msg, size,
- 0, TIMEOUT, session, NULL, 0, GNUNET_NO,
- &task_send_cont, NULL);
- GNUNET_free(msg);
- return;
+ if (tmp_addr->addrlen == (sizeof (struct IPv4HttpAddress)))
+ {
+ inet_ntop (AF_INET, (struct in_addr *) tmp_addr->addr, address,
+ INET_ADDRSTRLEN);
+ port = ntohs (((struct IPv4HttpAddress *) tmp_addr->addr)->u_port);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending message to addres no. %u: `%s':%u\n",
+ count, address, port);
+ }
+ if (tmp_addr->addrlen == (sizeof (struct IPv6HttpAddress)))
+ {
+ inet_ntop (AF_INET6, (struct in6_addr *) tmp_addr->addr, address,
+ INET6_ADDRSTRLEN);
+ port = ntohs (((struct IPv6HttpAddress *) tmp_addr->addr)->u6_port);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending message to addres no. %u: `%s':%u\n",
+ count, address, port);
+ }
+ msg.type = htons (type);
+ memcpy (tmp, &msg, sizeof (struct GNUNET_MessageHeader));
+ api->send (api->cls,
+ &my_identity,
+ tmp, sizeof (struct GNUNET_MessageHeader),
+ 0, TIMEOUT,
+ NULL,
+ tmp_addr->addr, tmp_addr->addrlen,
+ GNUNET_YES,
+ &task_send_cont, &fail_msgs_transmited_to_local_addrs);
+ tmp_addr = tmp_addr->next;
+ count++;
+ type++;
}
-
- if (phase==3)
- {
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ GNUNET_free (tmp);
+ return;
+ }
+
+ if (phase == 2)
+ {
+ struct Session *session = cls;
+
+ msg = GNUNET_malloc (sizeof (struct GNUNET_MessageHeader));
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Phase 2: session selection\n\n");
+ size = sizeof (struct GNUNET_MessageHeader);
+ msg->size = htons (size);
+ msg->type = htons (20);
+ api->send (api->cls,
+ &my_identity,
+ (const char *) msg, size,
+ 0, TIMEOUT, NULL, NULL, 0, GNUNET_NO, &task_send_cont, NULL);
+
+ msg->type = htons (21);
+ api->send (api->cls,
+ &my_identity,
+ (const char *) msg, size,
+ 0, TIMEOUT, NULL, NULL, 0, GNUNET_SYSERR, &task_send_cont,
NULL);
+
+ /* answer on session */
+ size = sizeof (struct GNUNET_MessageHeader);
+ msg->size = htons (size);
+ msg->type = htons (22);
+ api->send (api->cls,
+ &my_identity,
+ (const char *) msg, size,
+ 0, TIMEOUT, session, NULL, 0, GNUNET_SYSERR,
+ &task_send_cont, NULL);
+ GNUNET_free (msg);
+
+ /* answer on session with big message not fitting in mhd send buffer */
+ size = GNUNET_SERVER_MAX_MESSAGE_SIZE - 1;
+ msg = GNUNET_malloc (size);
+ msg->size = htons (size);
+ msg->type = htons (23);
+ api->send (api->cls,
+ &my_identity,
+ (const char *) msg, size,
+ 0, TIMEOUT, session, NULL, 0, GNUNET_NO, &task_send_cont, NULL);
+ GNUNET_free (msg);
+ return;
+ }
+
+ if (phase == 3)
+ {
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Phase 3: send multiple or big messages after disconnect\n\n");
/* disconnect from peer, so new connections are created */
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Disconnect from peer: `%s'\n",
GNUNET_i2s(&my_identity));
- api->disconnect(api->cls, &my_identity);
-
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnect from peer: `%s'\n",
+ GNUNET_i2s (&my_identity));
+ api->disconnect (api->cls, &my_identity);
+
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Phase 3: sending messages\n");
- /* send a multiple GNUNET_messages at a time*/
- size = 2 * sizeof(struct GNUNET_MessageHeader);
- msg = GNUNET_malloc( 2* size);
- msg->size = htons(size);
- msg->type = htons(30);
- struct GNUNET_MessageHeader * msg2 = &msg[2];
- msg2->size = htons(2 * sizeof(struct GNUNET_MessageHeader));
- msg2->type = htons(31);
- api->send(api->cls,
- &my_identity,
- (const char *) msg, 4 * sizeof(struct GNUNET_MessageHeader),
- 0, TIMEOUT, NULL,
- addr_head->addr, addr_head->addrlen,
- GNUNET_NO,
- &task_send_cont, &fail_multiple_msgs_in_transmission);
- GNUNET_free(msg);
+ /* send a multiple GNUNET_messages at a time */
+ size = 2 * sizeof (struct GNUNET_MessageHeader);
+ msg = GNUNET_malloc (2 * size);
+ msg->size = htons (size);
+ msg->type = htons (30);
+ struct GNUNET_MessageHeader *msg2 = &msg[2];
+
+ msg2->size = htons (2 * sizeof (struct GNUNET_MessageHeader));
+ msg2->type = htons (31);
+ api->send (api->cls,
+ &my_identity,
+ (const char *) msg, 4 * sizeof (struct GNUNET_MessageHeader),
+ 0, TIMEOUT, NULL,
+ addr_head->addr, addr_head->addrlen,
+ GNUNET_NO, &task_send_cont,
&fail_multiple_msgs_in_transmission);
+ GNUNET_free (msg);
/* send a message with size GNUNET_SERVER_MAX_MESSAGE_SIZE-1 */
- size = GNUNET_SERVER_MAX_MESSAGE_SIZE-1;
- msg = GNUNET_malloc(size);
- msg->size = htons(size);
- msg->type = htons(32);
- api->send(api->cls,
- &my_identity,
- (const char *) msg, size,
- 0, TIMEOUT, NULL,
- addr_head->addr, addr_head->addrlen,
- GNUNET_NO,
- &task_send_cont, &fail_msg_transmited_max_size);
- GNUNET_free(msg);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "No more tests to run\n");
+ size = GNUNET_SERVER_MAX_MESSAGE_SIZE - 1;
+ msg = GNUNET_malloc (size);
+ msg->size = htons (size);
+ msg->type = htons (32);
+ api->send (api->cls,
+ &my_identity,
+ (const char *) msg, size,
+ 0, TIMEOUT, NULL,
+ addr_head->addr, addr_head->addrlen,
+ GNUNET_NO, &task_send_cont, &fail_msg_transmited_max_size);
+ GNUNET_free (msg);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No more tests to run\n");
}
}
@@ -1236,12 +1214,13 @@
char *const *args,
const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
{
- char * libname;
+ char *libname;
+
cfg = c;
char *keyfile;
unsigned long long tneigh;
- struct Plugin_Address * cur;
- const char * addr_str;
+ struct Plugin_Address *cur;
+ const char *addr_str;
unsigned int suggest_res;
@@ -1260,8 +1239,9 @@
addr_head = NULL;
count_str_addr = 0;
/* parse configuration */
- if (GNUNET_CONFIGURATION_have_value (c,"PATHS", "SERVICEHOME"))
- GNUNET_CONFIGURATION_get_value_string (c, "PATHS", "SERVICEHOME",
&servicehome);
+ if (GNUNET_CONFIGURATION_have_value (c, "PATHS", "SERVICEHOME"))
+ GNUNET_CONFIGURATION_get_value_string (c, "PATHS", "SERVICEHOME",
+ &servicehome);
if ((GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_number (c,
@@ -1272,20 +1252,21 @@
GNUNET_CONFIGURATION_get_value_filename (c,
"GNUNETD",
"HOSTKEY", &keyfile)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Transport service is lacking key configuration settings.
Exiting.\n"));
- GNUNET_SCHEDULER_shutdown ();
- fail = 1;
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _
+ ("Transport service is lacking key configuration settings.
Exiting.\n"));
+ GNUNET_SCHEDULER_shutdown ();
+ fail = 1;
+ return;
+ }
if ((GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (cfg,
- "transport-http",
- "PORT",
- &port)) ||
- (port > 65535) || (port == 0))
+ GNUNET_CONFIGURATION_get_value_number (cfg,
+ "transport-http",
+ "PORT",
+ &port)) ||
+ (port > 65535) || (port == 0))
{
GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
"http",
@@ -1298,16 +1279,17 @@
my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
GNUNET_free (keyfile);
if (my_private_key == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Transport service could not access hostkey.
Exiting.\n"));
- GNUNET_SCHEDULER_shutdown ();
- fail = 1;
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Transport service could not access hostkey. Exiting.\n"));
+ GNUNET_SCHEDULER_shutdown ();
+ fail = 1;
+ return;
+ }
GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key);
- GNUNET_CRYPTO_hash (&my_public_key, sizeof (my_public_key),
&my_identity.hashPubKey);
+ GNUNET_CRYPTO_hash (&my_public_key, sizeof (my_public_key),
+ &my_identity.hashPubKey);
/* assertions before start */
GNUNET_assert ((port > 0) && (port <= 65535));
@@ -1315,9 +1297,8 @@
/* load plugins... */
setup_plugin_environment ();
GNUNET_asprintf (&libname, "libgnunet_plugin_transport_http");
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Loading HTTP transport plugin `%s'\n"),
- libname);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Loading HTTP transport plugin `%s'\n"), libname);
api = GNUNET_PLUGIN_load (libname, &env);
GNUNET_free (libname);
if (api == NULL)
@@ -1332,49 +1313,51 @@
ti_timeout = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, &task_timeout,
NULL);
/* testing plugin functionality */
- GNUNET_assert (0!=fail_notify_address_count);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ GNUNET_assert (0 != fail_notify_address_count);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Transport plugin returned %u addresses to connect to\n",
fail_notify_address_count);
- /* testing pretty printer with all addresses obtained from the plugin*/
+ /* testing pretty printer with all addresses obtained from the plugin */
cur = addr_head;
while (cur != NULL)
{
api->address_pretty_printer (api->cls, "http",
- cur->addr,cur->addrlen,
GNUNET_NO,TEST_TIMEOUT,
- &pretty_printer_cb, NULL);
+ cur->addr, cur->addrlen, GNUNET_NO,
+ TEST_TIMEOUT, &pretty_printer_cb, NULL);
addr_str = api->address_to_string (api->cls, cur->addr, cur->addrlen);
suggest_res = api->check_address (api->cls, cur->addr, cur->addrlen);
GNUNET_assert (GNUNET_OK == suggest_res);
GNUNET_assert (NULL != addr_str);
count_str_addr++;
- GNUNET_free ( (char *) addr_str);
+ GNUNET_free ((char *) addr_str);
cur = cur->next;
}
GNUNET_assert (fail_pretty_printer_count > 0);
- GNUNET_assert (fail_pretty_printer_count==fail_notify_address_count);
- GNUNET_assert (fail_pretty_printer_count==count_str_addr);
- fail_pretty_printer=GNUNET_NO;
- fail_addr_to_str=GNUNET_NO;
+ GNUNET_assert (fail_pretty_printer_count == fail_notify_address_count);
+ GNUNET_assert (fail_pretty_printer_count == count_str_addr);
+ fail_pretty_printer = GNUNET_NO;
+ fail_addr_to_str = GNUNET_NO;
struct IPv4HttpAddress failing_addr;
- /* Suggesting addresses with wrong size*/
- failing_addr.ipv4_addr = htonl(INADDR_LOOPBACK);
- failing_addr.u_port = htons(0);
- suggest_res = api->check_address (api->cls,&failing_addr,sizeof (struct
IPv6HttpAddress));
+ /* Suggesting addresses with wrong size */
+ failing_addr.ipv4_addr = htonl (INADDR_LOOPBACK);
+ failing_addr.u_port = htons (0);
+ suggest_res =
+ api->check_address (api->cls, &failing_addr,
+ sizeof (struct IPv6HttpAddress));
GNUNET_assert (GNUNET_SYSERR == suggest_res);
- /* Suggesting addresses with wrong address*/
- failing_addr.ipv4_addr = htonl(0xffc00000);
- failing_addr.u_port = htons(12389);
- suggest_res = api->check_address (api->cls,&failing_addr,100);
+ /* Suggesting addresses with wrong address */
+ failing_addr.ipv4_addr = htonl (0xffc00000);
+ failing_addr.u_port = htons (12389);
+ suggest_res = api->check_address (api->cls, &failing_addr, 100);
GNUNET_assert (GNUNET_SYSERR == suggest_res);
/* test sending to client */
- multi_handle = curl_multi_init();
+ multi_handle = curl_multi_init ();
/* Setting up buffers */
buffer_in.size = HTTP_BUFFER_SIZE;
@@ -1403,10 +1386,12 @@
test_valid_ident.test_executed = GNUNET_NO;
test_valid_ident.test_failed = GNUNET_YES;
- test_addr = (char *) api->address_to_string
(api->cls,addr_head->addr,addr_head->addrlen);
+ test_addr =
+ (char *) api->address_to_string (api->cls, addr_head->addr,
+ addr_head->addrlen);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Phase 0\n\n"));
- run_connection_tests(0, NULL);
+ run_connection_tests (0, NULL);
/* testing finished */
}
@@ -1425,6 +1410,7 @@
GNUNET_GETOPT_OPTION_END
};
int ret;
+
char *const argv_prog[] = {
"test_gnunet_transport_plugin_http",
"-c",
@@ -1446,11 +1432,15 @@
NULL);
struct GNUNET_CONFIGURATION_Handle *cfg;
+
cfg = GNUNET_CONFIGURATION_create ();
- GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (cfg,
"test_plugin_transport_data_http.conf"));
- if (GNUNET_CONFIGURATION_have_value (cfg,"PATHS", "SERVICEHOME"))
- GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", "SERVICEHOME",
&servicehome);
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONFIGURATION_load (cfg,
+
"test_plugin_transport_data_http.conf"));
+ if (GNUNET_CONFIGURATION_have_value (cfg, "PATHS", "SERVICEHOME"))
+ GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", "SERVICEHOME",
+ &servicehome);
GNUNET_DISK_directory_remove (servicehome);
GNUNET_CONFIGURATION_destroy (cfg);
@@ -1458,7 +1448,8 @@
GNUNET_PROGRAM_run (5,
argv_prog,
"test_gnunet_transport_plugin_http",
- "testcase", options, &run, NULL)) ? GNUNET_NO :
GNUNET_YES;
+ "testcase", options, &run,
+ NULL)) ? GNUNET_NO : GNUNET_YES;
if (servicehome != NULL)
{
Modified: gnunet/src/transport/test_plugin_transport_https.c
===================================================================
--- gnunet/src/transport/test_plugin_transport_https.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/transport/test_plugin_transport_https.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -75,12 +75,12 @@
/**
* Next field for linked list
*/
- struct Plugin_Address * next;
+ struct Plugin_Address *next;
/**
* buffer containing data to send
*/
- void * addr;
+ void *addr;
/**
* amount of data to sent
@@ -162,9 +162,9 @@
*/
struct IPv4HttpAddress
{
- struct IPv4HttpAddress * next;
+ struct IPv4HttpAddress *next;
- struct IPv4HttpAddress * prev;
+ struct IPv4HttpAddress *prev;
/**
* IPv4 address, in network byte order.
@@ -184,9 +184,9 @@
*/
struct IPv6HttpAddress
{
- struct IPv6HttpAddress * next;
+ struct IPv6HttpAddress *next;
- struct IPv6HttpAddress * prev;
+ struct IPv6HttpAddress *prev;
/**
* IPv6 address.
@@ -228,7 +228,7 @@
/**
* Peer's addr
*/
-static char * test_addr;
+static char *test_addr;
/**
* Our statistics handle.
@@ -276,12 +276,13 @@
static struct HTTP_Message buffer_in;
-struct Plugin_Address * addr_head;
+struct Plugin_Address *addr_head;
/**
* Did the test pass or fail?
*/
static int fail_notify_address;
+
/**
* Did the test pass or fail?
*/
@@ -386,10 +387,10 @@
static GNUNET_SCHEDULER_TaskIdentifier http_task_send;
-static char * key_file;
-static char * cert_file;
+static char *key_file;
+static char *cert_file;
-static char * servicehome;
+static char *servicehome;
/**
* Shutdown testcase
@@ -397,28 +398,41 @@
static void
shutdown_clean ()
{
- struct Plugin_Address * tmp;
+ struct Plugin_Address *tmp;
/* Evaluate results */
fail = 0;
- if ((fail_notify_address == GNUNET_YES) || (fail_pretty_printer ==
GNUNET_YES) || (fail_addr_to_str == GNUNET_YES))
+ if ((fail_notify_address == GNUNET_YES) || (fail_pretty_printer ==
GNUNET_YES)
+ || (fail_addr_to_str == GNUNET_YES))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Phase 0: Test plugin functions
failed\n"));
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Phase 0: Test plugin functions failed\n"));
fail = 1;
}
- if ((test_no_ident.test_failed == GNUNET_YES) ||
(test_too_short_ident.test_failed == GNUNET_YES) ||
(test_too_long_ident.test_failed == GNUNET_YES) ||
(test_valid_ident.test_failed == GNUNET_YES))
+ if ((test_no_ident.test_failed == GNUNET_YES) ||
+ (test_too_short_ident.test_failed == GNUNET_YES) ||
+ (test_too_long_ident.test_failed == GNUNET_YES) ||
+ (test_valid_ident.test_failed == GNUNET_YES))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Phase 1: Test connect with wrong
data failed\n"));
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Phase 1: Test connect with wrong data failed\n"));
fail = 1;
}
- if ((fail_session_selection_any != GNUNET_NO) ||
(fail_session_selection_reliable != GNUNET_NO) ||
(fail_session_selection_session != GNUNET_NO) ||
(fail_session_selection_session_big != GNUNET_NO))
+ if ((fail_session_selection_any != GNUNET_NO) ||
+ (fail_session_selection_reliable != GNUNET_NO) ||
+ (fail_session_selection_session != GNUNET_NO) ||
+ (fail_session_selection_session_big != GNUNET_NO))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Phase 2: Test session selection
failed\n"));
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Phase 2: Test session selection failed\n"));
fail = 1;
}
- if ((fail_msgs_transmited_to_local_addrs != count_str_addr) ||
(fail_multiple_msgs_in_transmission != 2) || (fail_msg_transmited_max_size ==
GNUNET_YES))
+ if ((fail_msgs_transmited_to_local_addrs != count_str_addr) ||
+ (fail_multiple_msgs_in_transmission != 2) ||
+ (fail_msg_transmited_max_size == GNUNET_YES))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Phase 3: Test sending with plugin
failed\n"));
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Phase 3: Test sending with plugin failed\n"));
fail = 1;
}
if (fail != 1)
@@ -426,9 +440,9 @@
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All tests successful\n");
}
- api->disconnect(api->cls,&my_identity);
+ api->disconnect (api->cls, &my_identity);
- curl_multi_cleanup(multi_handle);
+ curl_multi_cleanup (multi_handle);
if (NULL != curl_handle)
curl_easy_cleanup (curl_handle);
@@ -439,49 +453,57 @@
tmp = addr_head->next;
GNUNET_free (addr_head->addr);
GNUNET_free (addr_head);
- addr_head=tmp;
+ addr_head = tmp;
}
if (ti_send != GNUNET_SCHEDULER_NO_TASK)
{
- GNUNET_SCHEDULER_cancel(ti_send);
+ GNUNET_SCHEDULER_cancel (ti_send);
ti_send = GNUNET_SCHEDULER_NO_TASK;
}
if (http_task_send != GNUNET_SCHEDULER_NO_TASK)
{
- GNUNET_SCHEDULER_cancel(http_task_send);
+ GNUNET_SCHEDULER_cancel (http_task_send);
http_task_send = GNUNET_SCHEDULER_NO_TASK;
}
if (ti_timeout != GNUNET_SCHEDULER_NO_TASK)
{
- GNUNET_SCHEDULER_cancel(ti_timeout);
+ GNUNET_SCHEDULER_cancel (ti_timeout);
ti_timeout = GNUNET_SCHEDULER_NO_TASK;
}
- GNUNET_free(test_addr);
+ GNUNET_free (test_addr);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Unloading https plugin\n");
- GNUNET_assert (NULL == GNUNET_PLUGIN_unload
("libgnunet_gnunet_transport_plugin.https", api));
+ GNUNET_assert (NULL ==
+ GNUNET_PLUGIN_unload
+ ("libgnunet_gnunet_transport_plugin.https", api));
- GNUNET_SCHEDULER_shutdown();
+ GNUNET_SCHEDULER_shutdown ();
GNUNET_DISK_directory_remove ("/tmp/test_gnunet_transport_plugin.http");
struct stat sbuf;
- if (0 == stat (cert_file, &sbuf ))
+
+ if (0 == stat (cert_file, &sbuf))
{
- if (0 == remove(cert_file))
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully removed
existing certificate file `%s'\n",cert_file);
- else
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to remove
certfile `%s'\n",cert_file);
+ if (0 == remove (cert_file))
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Successfully removed existing certificate file `%s'\n",
+ cert_file);
+ else
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to remove certfile `%s'\n",
+ cert_file);
}
- if (0 == stat (key_file, &sbuf ))
+ if (0 == stat (key_file, &sbuf))
{
- if (0 == remove(key_file))
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully removed
private key file `%s'\n",key_file);
- else
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to private key
file `%s'\n",key_file);
+ if (0 == remove (key_file))
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Successfully removed private key file `%s'\n", key_file);
+ else
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to private key file `%s'\n",
+ key_file);
}
GNUNET_free (key_file);
@@ -495,7 +517,7 @@
GNUNET_free (servicehome);
}
- exit(fail);
+ exit (fail);
return;
}
@@ -507,97 +529,105 @@
* @result GNUNET_OK or GNUNET_SYSERR
*/
-static void task_send_cont (void *cls,
- const struct GNUNET_PeerIdentity * target,
- int result)
+static void
+task_send_cont (void *cls, const struct GNUNET_PeerIdentity *target, int
result)
{
- if ((cls == &fail_msg_transmited_bigger_max_size) && (result ==
GNUNET_SYSERR))
+ if ((cls == &fail_msg_transmited_bigger_max_size) &&
+ (result == GNUNET_SYSERR))
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Message bigger max msg size was not
sent!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Message bigger max msg size was not sent!\n");
fail_msg_transmited_bigger_max_size = GNUNET_NO;
return;
}
if ((cls == &fail_msg_transmited_max_size) && (result == GNUNET_OK))
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Message with max msg size
succesfully sent!\n",fail_msgs_transmited_to_local_addrs);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Message with max msg size succesfully sent!\n",
+ fail_msgs_transmited_to_local_addrs);
fail_msg_transmited_max_size = GNUNET_NO;
}
}
-static void run_connection_tests( int phase , void * cls);
+static void run_connection_tests (int phase, void *cls);
/**
* Recieves messages from plugin, in real world transport
*/
static struct GNUNET_TIME_Relative
receive (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_MessageHeader *message,
- const struct GNUNET_TRANSPORT_ATS_Information *ats,
- uint32_t ats_count,
- struct Session *session,
- const char *sender_address,
- uint16_t sender_address_len)
+ const struct GNUNET_MessageHeader *message,
+ const struct GNUNET_TRANSPORT_ATS_Information *ats,
+ uint32_t ats_count,
+ struct Session *session,
+ const char *sender_address, uint16_t sender_address_len)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testcase recieved new message from
peer `%s' with type %u and length %u, session %X\n", GNUNET_i2s(peer),
ntohs(message->type), ntohs(message->size),session);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Testcase recieved new message from peer `%s' with type %u and
length %u, session %X\n",
+ GNUNET_i2s (peer), ntohs (message->type), ntohs (message->size),
+ session);
- if ((ntohs(message->type)>=10) && (ntohs(message->type)<20))
+ if ((ntohs (message->type) >= 10) && (ntohs (message->type) < 20))
{
fail_msgs_transmited_to_local_addrs++;
if (fail_msgs_transmited_to_local_addrs == count_str_addr)
- run_connection_tests(2, session);
+ run_connection_tests (2, session);
}
- if ((ntohs(message->type)==20))
+ if ((ntohs (message->type) == 20))
{
fail_session_selection_reliable = GNUNET_NO;
}
- if ((ntohs(message->type)==21))
+ if ((ntohs (message->type) == 21))
{
fail_session_selection_any = GNUNET_NO;
}
- if ((ntohs(message->type)==22))
+ if ((ntohs (message->type) == 22))
{
fail_session_selection_session = GNUNET_NO;
}
- if ((ntohs(message->type)==23))
+ if ((ntohs (message->type) == 23))
{
fail_session_selection_session_big = GNUNET_NO;
- run_connection_tests(3, NULL);
+ run_connection_tests (3, NULL);
}
- if ((ntohs(message->type)==30) || (ntohs(message->type)==31))
+ if ((ntohs (message->type) == 30) || (ntohs (message->type) == 31))
{
- fail_multiple_msgs_in_transmission ++;
+ fail_multiple_msgs_in_transmission++;
}
- if ((ntohs(message->type)==32) && (ntohs(message->size) ==
GNUNET_SERVER_MAX_MESSAGE_SIZE-1))
+ if ((ntohs (message->type) == 32) &&
+ (ntohs (message->size) == GNUNET_SERVER_MAX_MESSAGE_SIZE - 1))
{
fail_msg_transmited_max_size = GNUNET_NO;
- shutdown_clean();
+ shutdown_clean ();
}
return GNUNET_TIME_UNIT_ZERO;
}
-static size_t send_function (void *stream, size_t size, size_t nmemb, void
*ptr)
+static size_t
+send_function (void *stream, size_t size, size_t nmemb, void *ptr)
{
unsigned int len;
len = buffer_out.len;
- if (( buffer_out.pos == len) || (len > (size * nmemb)))
+ if ((buffer_out.pos == len) || (len > (size * nmemb)))
return 0;
- memcpy(stream, buffer_out.buf, len);
+ memcpy (stream, buffer_out.buf, len);
buffer_out.pos = len;
return len;
}
-static size_t recv_function (void *ptr, size_t size, size_t nmemb, void *ctx)
+static size_t
+recv_function (void *ptr, size_t size, size_t nmemb, void *ctx)
{
if (buffer_in.pos + size * nmemb > buffer_in.size)
@@ -611,50 +641,51 @@
return buffer_in.pos;
}
-static size_t header_function( void *ptr, size_t size, size_t nmemb, void
*stream)
+static size_t
+header_function (void *ptr, size_t size, size_t nmemb, void *stream)
{
- struct HTTP_Transfer * res = (struct HTTP_Transfer *) stream;
- char * tmp;
+ struct HTTP_Transfer *res = (struct HTTP_Transfer *) stream;
+ char *tmp;
unsigned int len = size * nmemb;
- tmp = GNUNET_malloc ( len+1 );
- memcpy(tmp,ptr,len);
- if (tmp[len-2] == 13)
- tmp[len-2]= '\0';
+ tmp = GNUNET_malloc (len + 1);
+ memcpy (tmp, ptr, len);
+ if (tmp[len - 2] == 13)
+ tmp[len - 2] = '\0';
#if DEBUG_CURL
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Header: `%s'\n",tmp);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Header: `%s'\n", tmp);
#endif
- if (0==strcmp (tmp,"HTTP/1.1 100 Continue"))
+ if (0 == strcmp (tmp, "HTTP/1.1 100 Continue"))
{
- res->http_result_code=100;
+ res->http_result_code = 100;
}
- if (0==strcmp (tmp,"HTTP/1.1 200 OK"))
+ if (0 == strcmp (tmp, "HTTP/1.1 200 OK"))
{
- res->http_result_code=200;
+ res->http_result_code = 200;
}
- if (0==strcmp (tmp,"HTTP/1.1 400 Bad Request"))
+ if (0 == strcmp (tmp, "HTTP/1.1 400 Bad Request"))
{
- res->http_result_code=400;
+ res->http_result_code = 400;
}
- if (0==strcmp (tmp,"HTTP/1.1 404 Not Found"))
+ if (0 == strcmp (tmp, "HTTP/1.1 404 Not Found"))
{
- res->http_result_code=404;
+ res->http_result_code = 404;
}
- if (0==strcmp (tmp,"HTTP/1.1 413 Request entity too large"))
+ if (0 == strcmp (tmp, "HTTP/1.1 413 Request entity too large"))
{
- res->http_result_code=413;
+ res->http_result_code = 413;
}
GNUNET_free (tmp);
return size * nmemb;
}
-static size_t send_prepare( struct HTTP_Transfer * result);
+static size_t send_prepare (struct HTTP_Transfer *result);
-static void send_execute (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+static void
+send_execute (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct HTTP_Transfer *res;
@@ -668,96 +699,107 @@
return;
do
+ {
+ running = 0;
+ mret = curl_multi_perform (multi_handle, &running);
+ if (running == 0)
{
- running = 0;
- mret = curl_multi_perform (multi_handle, &running);
- if (running == 0)
+ do
+ {
+
+ msg = curl_multi_info_read (multi_handle, &running);
+ if (msg == NULL)
+ break;
+ /* get session for affected curl handle */
+ //cs = find_session_by_curlhandle (msg->easy_handle);
+ //GNUNET_assert ( cs != NULL );
+ switch (msg->msg)
{
- do
- {
- msg = curl_multi_info_read (multi_handle, &running);
- if (msg == NULL)
- break;
- /* get session for affected curl handle */
- //cs = find_session_by_curlhandle (msg->easy_handle);
- //GNUNET_assert ( cs != NULL );
- switch (msg->msg)
- {
+ case CURLMSG_DONE:
+ if ((msg->data.result != CURLE_OK) &&
+ (msg->data.result != CURLE_GOT_NOTHING))
+ {
- case CURLMSG_DONE:
- if ( (msg->data.result != CURLE_OK) &&
- (msg->data.result != CURLE_GOT_NOTHING) )
- {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("curl failed for `%s' at %s:%d: `%s'\n"),
+ "curl_multi_perform",
+ __FILE__,
+ __LINE__, curl_easy_strerror (msg->data.result));
+ /* sending msg failed */
+ curl_easy_cleanup (curl_handle);
+ curl_handle = NULL;
- GNUNET_log(GNUNET_ERROR_TYPE_INFO,
- _("curl failed for `%s' at %s:%d: `%s'\n"),
- "curl_multi_perform",
- __FILE__,
- __LINE__,
- curl_easy_strerror (msg->data.result));
- /* sending msg failed*/
- curl_easy_cleanup(curl_handle);
- curl_handle=NULL;
-
- run_connection_tests(0, NULL);
- }
- if (res == &test_no_ident)
- {
- if ((res->http_result_code==404) && (buffer_in.len==208))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Connecting to peer
without any peer identification: test passed\n");
- res->test_failed = GNUNET_NO;
- }
- else
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Connecting to
peer without any peer identification: test failed\n"));
- }
- if (res == &test_too_short_ident)
- {
- if ((res->http_result_code==404) && (buffer_in.len==208))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Connecting to peer
with too short peer identification: test passed\n");
- res->test_failed = GNUNET_NO;
- }
- else
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Connecting to
peer with too short peer identification: test failed\n"));
- }
- if (res == &test_too_long_ident)
- {
- if ((res->http_result_code==404) && (buffer_in.len==208))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Connecting to peer
with too long peer identification: test passed\n");
- res->test_failed = GNUNET_NO;
- }
- else
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Connecting to
peer with too long peer identification: test failed\n"));
- }
- if (res == &test_valid_ident)
- {
- if ((res->http_result_code==200))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Connecting to peer
with valid peer identification: test passed\n");
- res->test_failed = GNUNET_NO;
- }
- else
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Connecting to
peer with valid peer identification: test failed\n"));
- }
- curl_easy_cleanup(curl_handle);
- curl_handle=NULL;
- if ((res == &test_valid_ident) && (res->test_failed ==
GNUNET_NO))
- run_connection_tests(1, NULL);
- run_connection_tests(0, NULL);
- return;
- default:
- break;
- }
-
+ run_connection_tests (0, NULL);
+ }
+ if (res == &test_no_ident)
+ {
+ if ((res->http_result_code == 404) && (buffer_in.len == 208))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Connecting to peer without any peer identification:
test passed\n");
+ res->test_failed = GNUNET_NO;
}
- while ( (running > 0) );
+ else
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _
+ ("Connecting to peer without any peer
identification: test failed\n"));
+ }
+ if (res == &test_too_short_ident)
+ {
+ if ((res->http_result_code == 404) && (buffer_in.len == 208))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Connecting to peer with too short peer
identification: test passed\n");
+ res->test_failed = GNUNET_NO;
+ }
+ else
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _
+ ("Connecting to peer with too short peer
identification: test failed\n"));
+ }
+ if (res == &test_too_long_ident)
+ {
+ if ((res->http_result_code == 404) && (buffer_in.len == 208))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Connecting to peer with too long peer
identification: test passed\n");
+ res->test_failed = GNUNET_NO;
+ }
+ else
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _
+ ("Connecting to peer with too long peer
identification: test failed\n"));
+ }
+ if (res == &test_valid_ident)
+ {
+ if ((res->http_result_code == 200))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Connecting to peer with valid peer identification:
test passed\n");
+ res->test_failed = GNUNET_NO;
+ }
+ else
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _
+ ("Connecting to peer with valid peer identification:
test failed\n"));
+ }
+ curl_easy_cleanup (curl_handle);
+ curl_handle = NULL;
+ if ((res == &test_valid_ident) && (res->test_failed == GNUNET_NO))
+ run_connection_tests (1, NULL);
+ run_connection_tests (0, NULL);
+ return;
+ default:
+ break;
}
+
+ }
+ while ((running > 0));
}
+ }
while (mret == CURLM_CALL_MULTI_PERFORM);
- send_prepare(cls);
+ send_prepare (cls);
}
/**
@@ -765,7 +807,8 @@
* @param ses session to send data to
* @return bytes sent to peer
*/
-static size_t send_prepare( struct HTTP_Transfer * result)
+static size_t
+send_prepare (struct HTTP_Transfer *result)
{
fd_set rs;
fd_set ws;
@@ -782,34 +825,33 @@
FD_ZERO (&es);
mret = curl_multi_fdset (multi_handle, &rs, &ws, &es, &max);
if (mret != CURLM_OK)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("%s failed at %s:%d: `%s'\n"),
- "curl_multi_fdset", __FILE__, __LINE__,
- curl_multi_strerror (mret));
- return -1;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("%s failed at %s:%d: `%s'\n"),
+ "curl_multi_fdset", __FILE__, __LINE__,
+ curl_multi_strerror (mret));
+ return -1;
+ }
mret = curl_multi_timeout (multi_handle, &to);
if (mret != CURLM_OK)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("%s failed at %s:%d: `%s'\n"),
- "curl_multi_timeout", __FILE__, __LINE__,
- curl_multi_strerror (mret));
- return -1;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("%s failed at %s:%d: `%s'\n"),
+ "curl_multi_timeout", __FILE__, __LINE__,
+ curl_multi_strerror (mret));
+ return -1;
+ }
grs = GNUNET_NETWORK_fdset_create ();
gws = GNUNET_NETWORK_fdset_create ();
GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1);
GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1);
- http_task_send = GNUNET_SCHEDULER_add_select
(GNUNET_SCHEDULER_PRIORITY_DEFAULT,
+ http_task_send =
+ GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
GNUNET_SCHEDULER_NO_TASK,
- GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_SECONDS, 0),
- grs,
- gws,
- &send_execute,
- result);
+ GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 0), grs, gws,
+ &send_execute, result);
GNUNET_NETWORK_fdset_destroy (gws);
GNUNET_NETWORK_fdset_destroy (grs);
@@ -820,36 +862,38 @@
/**
* function to send data to server
*/
-static int send_data( struct HTTP_Transfer * result, char * url)
+static int
+send_data (struct HTTP_Transfer *result, char *url)
{
- curl_handle = curl_easy_init();
- if( NULL == curl_handle)
+ curl_handle = curl_easy_init ();
+ if (NULL == curl_handle)
{
- printf("easy_init failed \n");
+ printf ("easy_init failed \n");
return GNUNET_SYSERR;
}
#if DEBUG_CURL
- curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1L);
+ curl_easy_setopt (curl_handle, CURLOPT_VERBOSE, 1L);
#endif
- curl_easy_setopt(curl_handle, CURLOPT_URL, url);
- curl_easy_setopt(curl_handle, CURLOPT_PUT, 1L);
+ curl_easy_setopt (curl_handle, CURLOPT_URL, url);
+ curl_easy_setopt (curl_handle, CURLOPT_PUT, 1L);
//curl_easy_setopt(curl_handle, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
- curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0);
- curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 0);
+ curl_easy_setopt (curl_handle, CURLOPT_SSL_VERIFYPEER, 0);
+ curl_easy_setopt (curl_handle, CURLOPT_SSL_VERIFYHOST, 0);
curl_easy_setopt (curl_handle, CURLOPT_HEADERFUNCTION, &header_function);
curl_easy_setopt (curl_handle, CURLOPT_WRITEHEADER, result);
curl_easy_setopt (curl_handle, CURLOPT_WRITEFUNCTION, &recv_function);
curl_easy_setopt (curl_handle, CURLOPT_WRITEDATA, result);
curl_easy_setopt (curl_handle, CURLOPT_READFUNCTION, &send_function);
curl_easy_setopt (curl_handle, CURLOPT_READDATA, result);
- curl_easy_setopt(curl_handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t)
buffer_out.len);
- curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, 30);
- curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT, 20);
+ curl_easy_setopt (curl_handle, CURLOPT_INFILESIZE_LARGE,
+ (curl_off_t) buffer_out.len);
+ curl_easy_setopt (curl_handle, CURLOPT_TIMEOUT, 30);
+ curl_easy_setopt (curl_handle, CURLOPT_CONNECTTIMEOUT, 20);
- curl_multi_add_handle(multi_handle, curl_handle);
+ curl_multi_add_handle (multi_handle, curl_handle);
- send_prepare(result);
+ send_prepare (result);
return GNUNET_OK;
}
@@ -858,68 +902,66 @@
* Plugin notifies transport (aka testcase) about its addresses
*/
void
-notify_address (void *cls,
- int add_remove,
- const void *addr,
- size_t addrlen)
+notify_address (void *cls, int add_remove, const void *addr, size_t addrlen)
{
char address[INET6_ADDRSTRLEN];
unsigned int port;
- struct Plugin_Address * pl_addr;
- struct Plugin_Address * cur;
+ struct Plugin_Address *pl_addr;
+ struct Plugin_Address *cur;
if (addrlen == (sizeof (struct IPv4HttpAddress)))
- {
- inet_ntop(AF_INET, (struct in_addr *) addr,address,INET_ADDRSTRLEN);
- port = ntohs(((struct IPv4HttpAddress *) addr)->u_port);
- }
+ {
+ inet_ntop (AF_INET, (struct in_addr *) addr, address, INET_ADDRSTRLEN);
+ port = ntohs (((struct IPv4HttpAddress *) addr)->u_port);
+ }
else if (addrlen == (sizeof (struct IPv6HttpAddress)))
- {
- inet_ntop(AF_INET6, (struct in6_addr *) addr,address,INET6_ADDRSTRLEN);
- port = ntohs(((struct IPv6HttpAddress *) addr)->u6_port);
- }
+ {
+ inet_ntop (AF_INET6, (struct in6_addr *) addr, address, INET6_ADDRSTRLEN);
+ port = ntohs (((struct IPv6HttpAddress *) addr)->u6_port);
+ }
else
- {
+ {
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Unknown address size: ipv6 has %u ipv4 has %u but this has
%u\n"),
+ _
+ ("Unknown address size: ipv6 has %u ipv4 has %u but this has
%u\n"),
sizeof (struct IPv6HttpAddress),
- sizeof (struct IPv4HttpAddress),
- addrlen);
- return;
- }
+ sizeof (struct IPv4HttpAddress), addrlen);
+ return;
+ }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Transport plugin notification for address: `%s':%u\n"),
- address,
- port);
- pl_addr = GNUNET_malloc (sizeof (struct Plugin_Address) );
+ _("Transport plugin notification for address: `%s':%u\n"),
+ address, port);
+ pl_addr = GNUNET_malloc (sizeof (struct Plugin_Address));
pl_addr->addrlen = addrlen;
- pl_addr->addr = GNUNET_malloc(addrlen);
- memcpy(pl_addr->addr,addr,addrlen);
+ pl_addr->addr = GNUNET_malloc (addrlen);
+ memcpy (pl_addr->addr, addr, addrlen);
pl_addr->next = NULL;
- if ( NULL == addr_head)
- {
- addr_head = pl_addr;
- }
+ if (NULL == addr_head)
+ {
+ addr_head = pl_addr;
+ }
else
+ {
+ cur = addr_head;
+ while (NULL != cur->next)
{
- cur = addr_head;
- while (NULL != cur->next)
- {
- cur = cur->next;
- }
- cur->next = pl_addr;
+ cur = cur->next;
}
+ cur->next = pl_addr;
+ }
fail_notify_address_count++;
fail_notify_address = GNUNET_NO;
}
static void
-plugin_env_session_end (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- struct Session *session)
+plugin_env_session_end (void *cls,
+ const struct GNUNET_PeerIdentity *peer,
+ struct Session *session)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Pluging tells me: session %X to
peer `%s' ended\n", session, GNUNET_i2s(peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Pluging tells me: session %X to peer `%s' ended\n", session,
+ GNUNET_i2s (peer));
}
@@ -944,8 +986,7 @@
* Task shutting down testcase if it a timeout occurs
*/
static void
-task_timeout (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+task_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
ti_timeout = GNUNET_SCHEDULER_NO_TASK;
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
@@ -953,30 +994,33 @@
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testcase timeout\n");
fail = GNUNET_YES;
- shutdown_clean();
+ shutdown_clean ();
return;
}
-static void pretty_printer_cb (void *cls,
- const char *address)
+static void
+pretty_printer_cb (void *cls, const char *address)
{
- if (NULL==address)
+ if (NULL == address)
return;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Plugin returned pretty address:
`%s'\n",address);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Plugin returned pretty address:
`%s'\n",
+ address);
fail_pretty_printer_count++;
}
/**
* Runs every single test to test the plugin
*/
-static void run_connection_tests( int phase , void * cls)
+static void
+run_connection_tests (int phase, void *cls)
{
- struct GNUNET_MessageHeader * msg;
+ struct GNUNET_MessageHeader *msg;
unsigned int size;
- if (phase==0)
+ if (phase == 0)
{
- char * host_str = NULL;
+ char *host_str = NULL;
+
/* resetting buffers */
buffer_in.size = HTTP_BUFFER_SIZE;
buffer_in.pos = 0;
@@ -989,154 +1033,192 @@
if (test_no_ident.test_executed == GNUNET_NO)
{
/* Connecting to peer without identification */
- char * ident = "";
- GNUNET_asprintf (&host_str, "%s://%s/%s",PROTOCOL_PREFIX,
test_addr,ident);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer without any
peer identification.\n"));
+ char *ident = "";
+
+ GNUNET_asprintf (&host_str, "%s://%s/%s", PROTOCOL_PREFIX, test_addr,
+ ident);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Connecting to peer without any peer identification.\n"));
test_no_ident.test_executed = GNUNET_YES;
- send_data ( &test_no_ident, host_str);
+ send_data (&test_no_ident, host_str);
GNUNET_free (host_str);
return;
}
if (test_too_short_ident.test_executed == GNUNET_NO)
{
- char * ident = "AAAAAAAAAA";
+ char *ident = "AAAAAAAAAA";
+
/* Connecting to peer with too short identification */
- GNUNET_asprintf (&host_str, "%s://%s/%s",PROTOCOL_PREFIX,
test_addr,ident);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with too short
peer identification.\n"));
+ GNUNET_asprintf (&host_str, "%s://%s/%s", PROTOCOL_PREFIX, test_addr,
+ ident);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _
+ ("Connecting to peer with too short peer
identification.\n"));
test_too_short_ident.test_executed = GNUNET_YES;
- send_data ( &test_too_short_ident, host_str);
+ send_data (&test_too_short_ident, host_str);
GNUNET_free (host_str);
return;
}
if (test_too_long_ident.test_executed == GNUNET_NO)
{
- char * ident =
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
+ char *ident =
+
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
/* Connecting to peer with too long identification */
- GNUNET_asprintf (&host_str, "%s://%s/%s",PROTOCOL_PREFIX,
test_addr,ident);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with too long
peer identification.\n"));
+ GNUNET_asprintf (&host_str, "%s://%s/%s", PROTOCOL_PREFIX, test_addr,
+ ident);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Connecting to peer with too long peer
identification.\n"));
test_too_long_ident.test_executed = GNUNET_YES;
- send_data ( &test_too_long_ident, host_str);
+ send_data (&test_too_long_ident, host_str);
GNUNET_free (host_str);
return;
}
if (test_valid_ident.test_executed == GNUNET_NO)
{
struct GNUNET_CRYPTO_HashAsciiEncoded ident;
- GNUNET_CRYPTO_hash_to_enc(&my_identity.hashPubKey,&ident);
- GNUNET_asprintf (&host_str, "%s://%s/%s%s",PROTOCOL_PREFIX,
test_addr,(char *) &ident,";0");
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with valid
peer identification.\n"));
+
+ GNUNET_CRYPTO_hash_to_enc (&my_identity.hashPubKey, &ident);
+ GNUNET_asprintf (&host_str, "%s://%s/%s%s", PROTOCOL_PREFIX, test_addr,
+ (char *) &ident, ";0");
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Connecting to peer with valid peer identification.\n"));
test_valid_ident.test_executed = GNUNET_YES;
- send_data ( &test_valid_ident, host_str);
+ send_data (&test_valid_ident, host_str);
GNUNET_free (host_str);
return;
}
}
- if (phase==1)
+ if (phase == 1)
{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("\nPhase 1: transmit data to all
suggested addresses\n\n"));
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("\nPhase 1: transmit data to all suggested addresses\n\n"));
/* Using one of the addresses the plugin proposed */
GNUNET_assert (addr_head->addr != NULL);
- struct Plugin_Address * tmp_addr;
+ struct Plugin_Address *tmp_addr;
struct GNUNET_MessageHeader msg;
- char * tmp = GNUNET_malloc(sizeof(struct GNUNET_MessageHeader));
+ char *tmp = GNUNET_malloc (sizeof (struct GNUNET_MessageHeader));
char address[INET6_ADDRSTRLEN];
unsigned int port;
unsigned int type = 10;
- msg.size=htons(sizeof(struct GNUNET_MessageHeader));
+ msg.size = htons (sizeof (struct GNUNET_MessageHeader));
tmp_addr = addr_head;
/* send a message to all addresses advertised by plugin */
int count = 0;
+
while (tmp_addr != NULL)
{
if (tmp_addr->addrlen == (sizeof (struct IPv4HttpAddress)))
- {
- inet_ntop(AF_INET, (struct in_addr *)
tmp_addr->addr,address,INET_ADDRSTRLEN);
- port = ntohs(((struct IPv4HttpAddress *) tmp_addr->addr)->u_port);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Sending message to addres no.
%u: `%s':%u\n", count,address, port);
- }
+ {
+ inet_ntop (AF_INET, (struct in_addr *) tmp_addr->addr, address,
+ INET_ADDRSTRLEN);
+ port = ntohs (((struct IPv4HttpAddress *) tmp_addr->addr)->u_port);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending message to addres no. %u: `%s':%u\n", count,
+ address, port);
+ }
if (tmp_addr->addrlen == (sizeof (struct IPv6HttpAddress)))
- {
- inet_ntop(AF_INET6, (struct in6_addr *)
tmp_addr->addr,address,INET6_ADDRSTRLEN);
- port = ntohs(((struct IPv6HttpAddress *) tmp_addr->addr)->u6_port);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Sending message to addres no.
%u: `%s':%u\n", count,address,port);
- }
- msg.type=htons(type);
- memcpy(tmp,&msg,sizeof(struct GNUNET_MessageHeader));
- api->send(api->cls, &my_identity, tmp, sizeof(struct
GNUNET_MessageHeader), 0, TIMEOUT, NULL,tmp_addr->addr, tmp_addr->addrlen,
GNUNET_YES, &task_send_cont, &fail_msgs_transmited_to_local_addrs);
+ {
+ inet_ntop (AF_INET6, (struct in6_addr *) tmp_addr->addr, address,
+ INET6_ADDRSTRLEN);
+ port = ntohs (((struct IPv6HttpAddress *) tmp_addr->addr)->u6_port);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending message to addres no. %u: `%s':%u\n", count,
+ address, port);
+ }
+ msg.type = htons (type);
+ memcpy (tmp, &msg, sizeof (struct GNUNET_MessageHeader));
+ api->send (api->cls, &my_identity, tmp,
+ sizeof (struct GNUNET_MessageHeader), 0, TIMEOUT, NULL,
+ tmp_addr->addr, tmp_addr->addrlen, GNUNET_YES,
&task_send_cont,
+ &fail_msgs_transmited_to_local_addrs);
tmp_addr = tmp_addr->next;
- count ++;
- type ++;
+ count++;
+ type++;
}
- GNUNET_free(tmp);
+ GNUNET_free (tmp);
return;
}
- if (phase==2)
+ if (phase == 2)
{
- struct Session * session = cls;
- msg = GNUNET_malloc (sizeof(struct GNUNET_MessageHeader));
+ struct Session *session = cls;
+ msg = GNUNET_malloc (sizeof (struct GNUNET_MessageHeader));
+
GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("\nPhase 2: session selection\n\n"));
- size = sizeof(struct GNUNET_MessageHeader);
- msg->size=htons(size);
- msg->type = htons(20);
- api->send(api->cls, &my_identity, (const char *) msg, size, 0, TIMEOUT,
NULL, NULL, 0, GNUNET_NO, &task_send_cont, NULL);
+ size = sizeof (struct GNUNET_MessageHeader);
+ msg->size = htons (size);
+ msg->type = htons (20);
+ api->send (api->cls, &my_identity, (const char *) msg, size, 0, TIMEOUT,
+ NULL, NULL, 0, GNUNET_NO, &task_send_cont, NULL);
- msg->type = htons(21);
- api->send(api->cls, &my_identity, (const char *) msg, size, 0, TIMEOUT,
NULL, NULL, 0, GNUNET_SYSERR, &task_send_cont, NULL);
+ msg->type = htons (21);
+ api->send (api->cls, &my_identity, (const char *) msg, size, 0, TIMEOUT,
+ NULL, NULL, 0, GNUNET_SYSERR, &task_send_cont, NULL);
- /* answer on session*/
- size = sizeof( struct GNUNET_MessageHeader);
- msg->size = htons(size);
- msg->type = htons(22);
- api->send(api->cls, &my_identity, (const char *) msg, size, 0, TIMEOUT,
session, NULL, 0, GNUNET_SYSERR, &task_send_cont, NULL);
+ /* answer on session */
+ size = sizeof (struct GNUNET_MessageHeader);
+ msg->size = htons (size);
+ msg->type = htons (22);
+ api->send (api->cls, &my_identity, (const char *) msg, size, 0, TIMEOUT,
+ session, NULL, 0, GNUNET_SYSERR, &task_send_cont, NULL);
- GNUNET_free(msg);
+ GNUNET_free (msg);
- /* answer on session with big message not fitting in mhd send buffer*/
- size = GNUNET_SERVER_MAX_MESSAGE_SIZE-1;
+ /* answer on session with big message not fitting in mhd send buffer */
+ size = GNUNET_SERVER_MAX_MESSAGE_SIZE - 1;
msg = GNUNET_malloc (size);
- msg->size=htons(size);
- msg->type = htons(23);
- api->send(api->cls, &my_identity, (const char *) msg, size, 0, TIMEOUT,
session, NULL, 0, GNUNET_NO, &task_send_cont, NULL);
- GNUNET_free(msg);
+ msg->size = htons (size);
+ msg->type = htons (23);
+ api->send (api->cls, &my_identity, (const char *) msg, size, 0, TIMEOUT,
+ session, NULL, 0, GNUNET_NO, &task_send_cont, NULL);
+ GNUNET_free (msg);
return;
}
- if (phase==3)
+ if (phase == 3)
{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("\nPhase 3: send multiple or big
messages after disconnect\n\n"));
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _
+ ("\nPhase 3: send multiple or big messages after
disconnect\n\n"));
/* disconnect from peer, so new connections are created */
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Disconnect from peer: `%s'\n",
GNUNET_i2s(&my_identity));
- api->disconnect(api->cls, &my_identity);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnect from peer: `%s'\n",
+ GNUNET_i2s (&my_identity));
+ api->disconnect (api->cls, &my_identity);
GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Phase 3: sending messages\n"));
- /* send a multiple GNUNET_messages at a time*/
- size = 2 * sizeof(struct GNUNET_MessageHeader);
- msg = GNUNET_malloc( 2* size);
- msg->size = htons(size);
- msg->type = htons(30);
- struct GNUNET_MessageHeader * msg2 = &msg[2];
- msg2->size = htons(2 * sizeof(struct GNUNET_MessageHeader));
- msg2->type = htons(31);
- api->send(api->cls, &my_identity, (const char *) msg, 4 * sizeof(struct
GNUNET_MessageHeader), 0, TIMEOUT, NULL,addr_head->addr, addr_head->addrlen,
GNUNET_NO, &task_send_cont, &fail_multiple_msgs_in_transmission);
- GNUNET_free(msg);
+ /* send a multiple GNUNET_messages at a time */
+ size = 2 * sizeof (struct GNUNET_MessageHeader);
+ msg = GNUNET_malloc (2 * size);
+ msg->size = htons (size);
+ msg->type = htons (30);
+ struct GNUNET_MessageHeader *msg2 = &msg[2];
+
+ msg2->size = htons (2 * sizeof (struct GNUNET_MessageHeader));
+ msg2->type = htons (31);
+ api->send (api->cls, &my_identity, (const char *) msg,
+ 4 * sizeof (struct GNUNET_MessageHeader), 0, TIMEOUT, NULL,
+ addr_head->addr, addr_head->addrlen, GNUNET_NO, &task_send_cont,
+ &fail_multiple_msgs_in_transmission);
+ GNUNET_free (msg);
/* send a message with size GNUNET_SERVER_MAX_MESSAGE_SIZE-1 */
- size = GNUNET_SERVER_MAX_MESSAGE_SIZE-1;
- msg = GNUNET_malloc(size);
- msg->size = htons(size);
- msg->type = htons(32);
- api->send(api->cls, &my_identity, (const char *) msg, size, 0, TIMEOUT,
NULL,addr_head->addr, addr_head->addrlen, GNUNET_NO, &task_send_cont,
&fail_msg_transmited_max_size);
- GNUNET_free(msg);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"No more tests to run\n");
+ size = GNUNET_SERVER_MAX_MESSAGE_SIZE - 1;
+ msg = GNUNET_malloc (size);
+ msg->size = htons (size);
+ msg->type = htons (32);
+ api->send (api->cls, &my_identity, (const char *) msg, size, 0, TIMEOUT,
+ NULL, addr_head->addr, addr_head->addrlen, GNUNET_NO,
+ &task_send_cont, &fail_msg_transmited_max_size);
+ GNUNET_free (msg);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No more tests to run\n");
}
}
@@ -1152,12 +1234,13 @@
char *const *args,
const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
{
- char * libname;
+ char *libname;
+
cfg = c;
char *keyfile;
unsigned long long tneigh;
- struct Plugin_Address * cur;
- const char * addr_str;
+ struct Plugin_Address *cur;
+ const char *addr_str;
struct stat sbuf;
unsigned int suggest_res;
@@ -1175,8 +1258,9 @@
addr_head = NULL;
count_str_addr = 0;
/* parse configuration */
- if (GNUNET_CONFIGURATION_have_value (c,"PATHS", "SERVICEHOME"))
- GNUNET_CONFIGURATION_get_value_string (c, "PATHS", "SERVICEHOME",
&servicehome);
+ if (GNUNET_CONFIGURATION_have_value (c, "PATHS", "SERVICEHOME"))
+ GNUNET_CONFIGURATION_get_value_string (c, "PATHS", "SERVICEHOME",
+ &servicehome);
if ((GNUNET_OK !=
@@ -1188,21 +1272,21 @@
GNUNET_CONFIGURATION_get_value_filename (c,
"GNUNETD",
"HOSTKEY", &keyfile)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _
- ("Transport service is lacking key configuration settings.
Exiting.\n"));
- GNUNET_SCHEDULER_shutdown ();
- fail = 1;
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _
+ ("Transport service is lacking key configuration settings.
Exiting.\n"));
+ GNUNET_SCHEDULER_shutdown ();
+ fail = 1;
+ return;
+ }
if ((GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (cfg,
- "transport-https",
- "PORT",
- &port)) ||
- (port > 65535) || (port == 0))
+ GNUNET_CONFIGURATION_get_value_number (cfg,
+ "transport-https",
+ "PORT",
+ &port)) ||
+ (port > 65535) || (port == 0))
{
GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
"https",
@@ -1212,59 +1296,63 @@
}
/* Get private key file from config */
- if (GNUNET_CONFIGURATION_have_value (cfg,
-
"transport-https", "KEY_FILE"))
+ if (GNUNET_CONFIGURATION_have_value (cfg, "transport-https", "KEY_FILE"))
{
- GNUNET_CONFIGURATION_get_value_string (cfg,
-
"transport-https",
-
"KEY_FILE",
-
&key_file);
+ GNUNET_CONFIGURATION_get_value_string (cfg,
+ "transport-https",
+ "KEY_FILE", &key_file);
}
if (key_file == NULL)
- GNUNET_asprintf(&key_file,"https.key");
+ GNUNET_asprintf (&key_file, "https.key");
- if (0 == stat (key_file, &sbuf ))
+ if (0 == stat (key_file, &sbuf))
{
- if (0 == remove(key_file))
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Successfully removed
existing private key file `%s'\n",key_file);
- else
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to remove
private key file `%s'\n",key_file);
+ if (0 == remove (key_file))
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Successfully removed existing private key file `%s'\n",
+ key_file);
+ else
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to remove private key file `%s'\n", key_file);
}
/* Get private key file from config */
- if (GNUNET_CONFIGURATION_have_value (cfg,
-
"transport-https", "CERT_FILE"))
+ if (GNUNET_CONFIGURATION_have_value (cfg, "transport-https", "CERT_FILE"))
{
- GNUNET_CONFIGURATION_get_value_string (cfg,
-
"transport-https",
-
"CERT_FILE",
-
&cert_file);
+ GNUNET_CONFIGURATION_get_value_string (cfg,
+ "transport-https",
+ "CERT_FILE", &cert_file);
}
if (cert_file == NULL)
- GNUNET_asprintf(&cert_file,"https.cert");
+ GNUNET_asprintf (&cert_file, "https.cert");
- if (0 == stat (cert_file, &sbuf ))
+ if (0 == stat (cert_file, &sbuf))
{
- if (0 == remove(cert_file))
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Successfully removed
existing certificate file `%s'\n",cert_file);
- else
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to remove
existing certificate file `%s'\n",cert_file);
+ if (0 == remove (cert_file))
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Successfully removed existing certificate file `%s'\n",
+ cert_file);
+ else
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to remove existing certificate file `%s'\n",
+ cert_file);
}
max_connect_per_transport = (uint32_t) tneigh;
my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
GNUNET_free (keyfile);
if (my_private_key == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Transport service could not access hostkey.
Exiting.\n"));
- GNUNET_SCHEDULER_shutdown ();
- fail = 1;
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Transport service could not access hostkey. Exiting.\n"));
+ GNUNET_SCHEDULER_shutdown ();
+ fail = 1;
+ return;
+ }
GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key);
- GNUNET_CRYPTO_hash (&my_public_key, sizeof (my_public_key),
&my_identity.hashPubKey);
+ GNUNET_CRYPTO_hash (&my_public_key, sizeof (my_public_key),
+ &my_identity.hashPubKey);
/* assertions before start */
GNUNET_assert ((port > 0) && (port <= 65535));
@@ -1272,7 +1360,8 @@
/* load plugins... */
setup_plugin_environment ();
GNUNET_asprintf (&libname, "libgnunet_plugin_transport_https");
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading HTTPS transport plugin
`%s'\n"),libname);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Loading HTTPS transport plugin `%s'\n"), libname);
api = GNUNET_PLUGIN_load (libname, &env);
GNUNET_free (libname);
if (api == NULL)
@@ -1286,46 +1375,52 @@
ti_timeout = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, &task_timeout,
NULL);
/* testing plugin functionality */
- GNUNET_assert (0!=fail_notify_address_count);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Transport plugin returned %u
addresses to connect to\n"), fail_notify_address_count);
+ GNUNET_assert (0 != fail_notify_address_count);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Transport plugin returned %u addresses to connect to\n"),
+ fail_notify_address_count);
- /* testing pretty printer with all addresses obtained from the plugin*/
+ /* testing pretty printer with all addresses obtained from the plugin */
cur = addr_head;
while (cur != NULL)
{
- api->address_pretty_printer (api->cls, "http",cur->addr,cur->addrlen,
GNUNET_NO,TEST_TIMEOUT, &pretty_printer_cb,NULL);
+ api->address_pretty_printer (api->cls, "http", cur->addr, cur->addrlen,
+ GNUNET_NO, TEST_TIMEOUT, &pretty_printer_cb,
+ NULL);
addr_str = api->address_to_string (api->cls, cur->addr, cur->addrlen);
suggest_res = api->check_address (api->cls, cur->addr, cur->addrlen);
GNUNET_assert (GNUNET_OK == suggest_res);
GNUNET_assert (NULL != addr_str);
count_str_addr++;
- GNUNET_free ( (char *) addr_str);
+ GNUNET_free ((char *) addr_str);
cur = cur->next;
}
GNUNET_assert (fail_pretty_printer_count > 0);
- GNUNET_assert (fail_pretty_printer_count==fail_notify_address_count);
- GNUNET_assert (fail_pretty_printer_count==count_str_addr);
- fail_pretty_printer=GNUNET_NO;
- fail_addr_to_str=GNUNET_NO;
+ GNUNET_assert (fail_pretty_printer_count == fail_notify_address_count);
+ GNUNET_assert (fail_pretty_printer_count == count_str_addr);
+ fail_pretty_printer = GNUNET_NO;
+ fail_addr_to_str = GNUNET_NO;
struct IPv4HttpAddress failing_addr;
- /* Suggesting addresses with wrong size*/
- failing_addr.ipv4_addr = htonl(INADDR_LOOPBACK);
- failing_addr.u_port = htons(0);
- suggest_res = api->check_address (api->cls,&failing_addr,sizeof (struct
IPv6HttpAddress));
+ /* Suggesting addresses with wrong size */
+ failing_addr.ipv4_addr = htonl (INADDR_LOOPBACK);
+ failing_addr.u_port = htons (0);
+ suggest_res =
+ api->check_address (api->cls, &failing_addr,
+ sizeof (struct IPv6HttpAddress));
GNUNET_assert (GNUNET_SYSERR == suggest_res);
- /* Suggesting addresses with wrong address*/
- failing_addr.ipv4_addr = htonl(0xffc00000);
- failing_addr.u_port = htons(12389);
- suggest_res = api->check_address (api->cls,&failing_addr,100);
+ /* Suggesting addresses with wrong address */
+ failing_addr.ipv4_addr = htonl (0xffc00000);
+ failing_addr.u_port = htons (12389);
+ suggest_res = api->check_address (api->cls, &failing_addr, 100);
GNUNET_assert (GNUNET_SYSERR == suggest_res);
/* test sending to client */
- multi_handle = curl_multi_init();
+ multi_handle = curl_multi_init ();
/* Setting up buffers */
buffer_in.size = HTTP_BUFFER_SIZE;
@@ -1354,10 +1449,12 @@
test_valid_ident.test_executed = GNUNET_NO;
test_valid_ident.test_failed = GNUNET_YES;
- test_addr = (char *) api->address_to_string
(api->cls,addr_head->addr,addr_head->addrlen);
+ test_addr =
+ (char *) api->address_to_string (api->cls, addr_head->addr,
+ addr_head->addrlen);
GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("\nPhase 0\n\n"));
- run_connection_tests(0, NULL);
+ run_connection_tests (0, NULL);
/* testing finished */
@@ -1380,6 +1477,7 @@
GNUNET_GETOPT_OPTION_END
};
int ret;
+
char *const argv_prog[] = {
"test_gnunet_transport_plugin.https",
"-c",
@@ -1401,11 +1499,15 @@
NULL);
struct GNUNET_CONFIGURATION_Handle *cfg;
+
cfg = GNUNET_CONFIGURATION_create ();
- GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (cfg,
"test_plugin_transport_data_http.conf"));
- if (GNUNET_CONFIGURATION_have_value (cfg,"PATHS", "SERVICEHOME"))
- GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", "SERVICEHOME",
&servicehome);
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONFIGURATION_load (cfg,
+
"test_plugin_transport_data_http.conf"));
+ if (GNUNET_CONFIGURATION_have_value (cfg, "PATHS", "SERVICEHOME"))
+ GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", "SERVICEHOME",
+ &servicehome);
GNUNET_DISK_directory_remove (servicehome);
GNUNET_CONFIGURATION_destroy (cfg);
@@ -1413,7 +1515,8 @@
GNUNET_PROGRAM_run (5,
argv_prog,
"test_gnunet_transport_plugin.https",
- "testcase", options, &run, NULL)) ? GNUNET_NO :
GNUNET_YES;
+ "testcase", options, &run,
+ NULL)) ? GNUNET_NO : GNUNET_YES;
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("\ndelete\n\n"));
if (servicehome != NULL)
{
Modified: gnunet/src/transport/test_plugin_transport_udp.c
===================================================================
--- gnunet/src/transport/test_plugin_transport_udp.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/transport/test_plugin_transport_udp.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -90,11 +90,10 @@
*/
static void
receive (void *cls,
- const struct GNUNET_PeerIdentity * peer,
- const struct GNUNET_MessageHeader * message,
- uint32_t distance,
- const char *sender_address,
- size_t sender_address_len)
+ const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_MessageHeader *message,
+ uint32_t distance,
+ const char *sender_address, size_t sender_address_len)
{
/* do nothing */
}
@@ -118,8 +117,7 @@
unload_plugins (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
GNUNET_assert (NULL ==
- GNUNET_PLUGIN_unload ("libgnunet_plugin_transport_udp",
- api));
+ GNUNET_PLUGIN_unload ("libgnunet_plugin_transport_udp", api));
if (my_private_key != NULL)
GNUNET_CRYPTO_rsa_key_free (my_private_key);
@@ -146,10 +144,9 @@
soaddr.sin_port = htons (2368 /* FIXME: get from config! */ );
soaddr.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
- api->check_address(api->cls,
- &soaddr, sizeof (soaddr));
+ api->check_address (api->cls, &soaddr, sizeof (soaddr));
- unload_plugins(env.cls, env.cfg);
+ unload_plugins (env.cls, env.cfg);
}
@@ -190,24 +187,23 @@
GNUNET_CONFIGURATION_get_value_filename (c,
"GNUNETD",
"HOSTKEY", &keyfile)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _
- ("Transport service is lacking key configuration settings.
Exiting.\n"));
- GNUNET_SCHEDULER_shutdown (s);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _
+ ("Transport service is lacking key configuration settings.
Exiting.\n"));
+ GNUNET_SCHEDULER_shutdown (s);
+ return;
+ }
max_connect_per_transport = (uint32_t) tneigh;
my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
GNUNET_free (keyfile);
if (my_private_key == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _
- ("Transport service could not access hostkey. Exiting.\n"));
- GNUNET_SCHEDULER_shutdown (s);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Transport service could not access hostkey. Exiting.\n"));
+ GNUNET_SCHEDULER_shutdown (s);
+ return;
+ }
GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key);
GNUNET_CRYPTO_hash (&my_public_key,
sizeof (my_public_key), &my_identity.hashPubKey);
@@ -220,12 +216,12 @@
api = GNUNET_PLUGIN_load (libname, &env);
GNUNET_free (libname);
if (api == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to load transport plugin for udp\n"));
- /* FIXME: set some error code for main */
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to load transport plugin for udp\n"));
+ /* FIXME: set some error code for main */
+ return;
+ }
test_validation ();
}
@@ -244,6 +240,7 @@
GNUNET_GETOPT_OPTION_END
};
int ret;
+
char *const argv_prog[] = {
"test_plugin_transport",
"-c",
Modified: gnunet/src/transport/test_plugin_transport_wlan_dummy.c
===================================================================
--- gnunet/src/transport/test_plugin_transport_wlan_dummy.c 2011-08-15
21:40:08 UTC (rev 16580)
+++ gnunet/src/transport/test_plugin_transport_wlan_dummy.c 2011-08-15
21:46:35 UTC (rev 16581)
@@ -55,76 +55,79 @@
static int first;
static void
-sigfunc(int sig)
+sigfunc (int sig)
{
closeprog = 1;
- unlink(FIFO_FILE1);
- unlink(FIFO_FILE2);
+ unlink (FIFO_FILE1);
+ unlink (FIFO_FILE2);
}
static void
-stdin_send(void *cls, void *client,
- const struct GNUNET_MessageHeader *hdr)
+stdin_send (void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
{
struct sendbuf *write_pout = cls;
int sendsize;
struct GNUNET_MessageHeader newheader;
- char * to_data;
- char * to_radiotap;
- char * to_start;
+ char *to_data;
+ char *to_radiotap;
+ char *to_start;
- sendsize = ntohs(hdr->size) - sizeof(struct Radiotap_Send)
- + sizeof(struct Radiotap_rx);
+ sendsize = ntohs (hdr->size) - sizeof (struct Radiotap_Send)
+ + sizeof (struct Radiotap_rx);
- if (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA != ntohs(hdr->type))
- {
- fprintf(stderr, "Function stdin_send: wrong packet type\n");
- exit(1);
- }
+ if (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA != ntohs (hdr->type))
+ {
+ fprintf (stderr, "Function stdin_send: wrong packet type\n");
+ exit (1);
+ }
if ((sendsize + write_pout->size) > MAXLINE * 2)
- {
- fprintf(stderr, "Function stdin_send: Packet too big for buffer\n");
- exit(1);
- }
+ {
+ fprintf (stderr, "Function stdin_send: Packet too big for buffer\n");
+ exit (1);
+ }
- newheader.size = htons(sendsize);
- newheader.type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
+ newheader.size = htons (sendsize);
+ newheader.type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
to_start = write_pout->buf + write_pout->size;
- memcpy(to_start, &newheader, sizeof(struct GNUNET_MessageHeader));
- write_pout->size += sizeof(struct GNUNET_MessageHeader);
+ memcpy (to_start, &newheader, sizeof (struct GNUNET_MessageHeader));
+ write_pout->size += sizeof (struct GNUNET_MessageHeader);
- to_radiotap = to_start + sizeof(struct GNUNET_MessageHeader);
- memset(to_radiotap, 0, sizeof (struct Radiotap_rx));
- write_pout->size += sizeof(struct Radiotap_rx);
+ to_radiotap = to_start + sizeof (struct GNUNET_MessageHeader);
+ memset (to_radiotap, 0, sizeof (struct Radiotap_rx));
+ write_pout->size += sizeof (struct Radiotap_rx);
- to_data = to_radiotap + sizeof(struct Radiotap_rx);
- memcpy(to_data,
- ((char *) hdr) + sizeof(struct Radiotap_Send) + sizeof(struct
GNUNET_MessageHeader),
- ntohs(hdr->size) - sizeof(struct Radiotap_Send) - sizeof(struct
GNUNET_MessageHeader));
- write_pout->size += ntohs(hdr->size) - sizeof(struct Radiotap_Send) -
sizeof(struct GNUNET_MessageHeader);
+ to_data = to_radiotap + sizeof (struct Radiotap_rx);
+ memcpy (to_data,
+ ((char *) hdr) + sizeof (struct Radiotap_Send) +
+ sizeof (struct GNUNET_MessageHeader),
+ ntohs (hdr->size) - sizeof (struct Radiotap_Send) -
+ sizeof (struct GNUNET_MessageHeader));
+ write_pout->size +=
+ ntohs (hdr->size) - sizeof (struct Radiotap_Send) -
+ sizeof (struct GNUNET_MessageHeader);
}
static void
-file_in_send(void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
+file_in_send (void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
{
- struct sendbuf * write_std = cls;
+ struct sendbuf *write_std = cls;
uint16_t sendsize;
- sendsize = ntohs(hdr->size);
+ sendsize = ntohs (hdr->size);
- if (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA != ntohs(hdr->type))
- {
- fprintf(stderr, "Function file_in_send: wrong packet type\n");
- exit(1);
- }
+ if (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA != ntohs (hdr->type))
+ {
+ fprintf (stderr, "Function file_in_send: wrong packet type\n");
+ exit (1);
+ }
if ((sendsize + write_std->size) > MAXLINE * 2)
- {
- fprintf(stderr, "Function file_in_send: Packet too big for buffer\n");
- exit(1);
- }
+ {
+ fprintf (stderr, "Function file_in_send: Packet too big for buffer\n");
+ exit (1);
+ }
- memcpy(write_std->buf + write_std->size, hdr, sendsize);
+ memcpy (write_std->buf + write_std->size, hdr, sendsize);
write_std->size += sendsize;
}
@@ -132,7 +135,7 @@
int
-testmode(int argc, char *argv[])
+testmode (int argc, char *argv[])
{
struct stat st;
int erg;
@@ -144,111 +147,113 @@
int fdpout;
//make the fifos if needed
- if (0 != stat(FIFO_FILE1, &st))
+ if (0 != stat (FIFO_FILE1, &st))
+ {
+ if (0 == stat (FIFO_FILE2, &st))
{
- if (0 == stat(FIFO_FILE2, &st))
- {
- fprintf(stderr, "FIFO_FILE2 exists, but FIFO_FILE1 not\n");
- exit(1);
- }
+ fprintf (stderr, "FIFO_FILE2 exists, but FIFO_FILE1 not\n");
+ exit (1);
+ }
- umask(0);
- //unlink(FIFO_FILE1);
- //unlink(FIFO_FILE2);
- // FIXME: use mkfifo!
- erg = mknod(FIFO_FILE1, S_IFIFO | 0666, 0);
- if (0 != erg)
- {
- fprintf(stderr, "Error at mknode1 \n");
- //exit(1);
- }
- erg = mknod(FIFO_FILE2, S_IFIFO | 0666, 0);
- if (0 != erg)
- {
- fprintf(stderr, "Error at mknode2 \n");
- //exit(1);
- }
-
+ umask (0);
+ //unlink(FIFO_FILE1);
+ //unlink(FIFO_FILE2);
+ // FIXME: use mkfifo!
+ erg = mknod (FIFO_FILE1, S_IFIFO | 0666, 0);
+ if (0 != erg)
+ {
+ fprintf (stderr, "Error at mknode1 \n");
+ //exit(1);
}
- else
+ erg = mknod (FIFO_FILE2, S_IFIFO | 0666, 0);
+ if (0 != erg)
{
+ fprintf (stderr, "Error at mknode2 \n");
+ //exit(1);
+ }
- if (0 != stat(FIFO_FILE2, &st))
- {
- fprintf(stderr, "FIFO_FILE1 exists, but FIFO_FILE2 not\n");
- exit(1);
- }
+ }
+ else
+ {
+ if (0 != stat (FIFO_FILE2, &st))
+ {
+ fprintf (stderr, "FIFO_FILE1 exists, but FIFO_FILE2 not\n");
+ exit (1);
}
- if (strstr(argv[1], "1"))
+ }
+
+ if (strstr (argv[1], "1"))
+ {
+ //fprintf(stderr, "First\n");
+ first = 1;
+ fpin = fopen (FIFO_FILE1, "r");
+ if (NULL == fpin)
{
- //fprintf(stderr, "First\n");
- first = 1;
- fpin = fopen(FIFO_FILE1, "r");
- if (NULL == fpin)
- {
- fprintf(stderr, "fopen of read FIFO_FILE1\n");
- goto end;
- }
- fpout = fopen(FIFO_FILE2, "w");
- if (NULL == fpout)
- {
- fprintf(stderr, "fopen of write FIFO_FILE2\n");
- goto end;
- }
-
+ fprintf (stderr, "fopen of read FIFO_FILE1\n");
+ goto end;
}
- else
+ fpout = fopen (FIFO_FILE2, "w");
+ if (NULL == fpout)
{
- first = 0;
- //fprintf(stderr, "Second\n");
- fpout = fopen(FIFO_FILE1, "w");
- if (NULL == fpout)
- {
- fprintf(stderr, "fopen of write FIFO_FILE1\n");
- goto end;
- }
- fpin = fopen(FIFO_FILE2, "r");
- if (NULL == fpin)
- {
- fprintf(stderr, "fopen of read FIFO_FILE2\n");
- goto end;
- }
-
+ fprintf (stderr, "fopen of write FIFO_FILE2\n");
+ goto end;
}
- fdpin = fileno(fpin);
- GNUNET_assert(fpin >= 0);
-
- if (fdpin >= FD_SETSIZE)
+ }
+ else
+ {
+ first = 0;
+ //fprintf(stderr, "Second\n");
+ fpout = fopen (FIFO_FILE1, "w");
+ if (NULL == fpout)
{
- fprintf(stderr, "File fdpin number too large (%d > %u)\n", fdpin,
- (unsigned int) FD_SETSIZE);
+ fprintf (stderr, "fopen of write FIFO_FILE1\n");
goto end;
}
+ fpin = fopen (FIFO_FILE2, "r");
+ if (NULL == fpin)
+ {
+ fprintf (stderr, "fopen of read FIFO_FILE2\n");
+ goto end;
+ }
- fdpout = fileno(fpout);
- GNUNET_assert(fdpout >= 0 );
+ }
+ fdpin = fileno (fpin);
+ GNUNET_assert (fpin >= 0);
+
+ if (fdpin >= FD_SETSIZE)
+ {
+ fprintf (stderr, "File fdpin number too large (%d > %u)\n", fdpin,
+ (unsigned int) FD_SETSIZE);
+ goto end;
+ }
+
+ fdpout = fileno (fpout);
+ GNUNET_assert (fdpout >= 0);
+
if (fdpout >= FD_SETSIZE)
- {
- fprintf(stderr, "File fdpout number too large (%d > %u)\n", fdpout,
- (unsigned int) FD_SETSIZE);
- goto end;
+ {
+ fprintf (stderr, "File fdpout number too large (%d > %u)\n", fdpout,
+ (unsigned int) FD_SETSIZE);
+ goto end;
- }
+ }
- signal(SIGINT, &sigfunc);
- signal(SIGTERM, &sigfunc);
+ signal (SIGINT, &sigfunc);
+ signal (SIGTERM, &sigfunc);
char readbuf[MAXLINE];
int readsize = 0;
struct sendbuf write_std;
+
write_std.size = 0;
write_std.pos = 0;
struct sendbuf write_pout;
+
write_pout.size = 0;
write_pout.pos = 0;
@@ -260,11 +265,11 @@
struct timeval tv;
int retval;
- struct GNUNET_SERVER_MessageStreamTokenizer * stdin_mst;
- struct GNUNET_SERVER_MessageStreamTokenizer * file_in_mst;
+ struct GNUNET_SERVER_MessageStreamTokenizer *stdin_mst;
+ struct GNUNET_SERVER_MessageStreamTokenizer *file_in_mst;
- stdin_mst = GNUNET_SERVER_mst_create(&stdin_send, &write_pout);
- file_in_mst = GNUNET_SERVER_mst_create(&file_in_send, &write_std);
+ stdin_mst = GNUNET_SERVER_mst_create (&stdin_send, &write_pout);
+ file_in_mst = GNUNET_SERVER_mst_create (&file_in_send, &write_std);
//send mac first
@@ -275,187 +280,185 @@
macaddr.mac[1] = 0x22;
macaddr.mac[2] = 0x33;
macaddr.mac[3] = 0x44;
- macaddr.mac[4] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 256);
- macaddr.mac[5] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, 256);
+ macaddr.mac[4] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG,
256);
+ macaddr.mac[5] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, 256);
- write_std.size = send_mac_to_plugin(write_std.buf, macaddr.mac);
+ write_std.size = send_mac_to_plugin (write_std.buf, macaddr.mac);
while (0 == closeprog)
- {
+ {
- maxfd = 0;
+ maxfd = 0;
- //set timeout
- tv.tv_sec = 5;
- tv.tv_usec = 0;
+ //set timeout
+ tv.tv_sec = 5;
+ tv.tv_usec = 0;
- FD_ZERO(&rfds);
- // if output queue is empty
- if (0 == write_pout.size)
- {
- FD_SET(STDIN_FILENO, &rfds);
+ FD_ZERO (&rfds);
+ // if output queue is empty
+ if (0 == write_pout.size)
+ {
+ FD_SET (STDIN_FILENO, &rfds);
- }
- if (0 == write_std.size)
- {
- FD_SET(fdpin, &rfds);
- maxfd = fdpin;
- }
- FD_ZERO(&wfds);
- // if there is something to write
- if (0 < write_std.size)
- {
- FD_SET(STDOUT_FILENO, &wfds);
- maxfd = MAX(maxfd, STDOUT_FILENO);
- }
+ }
+ if (0 == write_std.size)
+ {
+ FD_SET (fdpin, &rfds);
+ maxfd = fdpin;
+ }
+ FD_ZERO (&wfds);
+ // if there is something to write
+ if (0 < write_std.size)
+ {
+ FD_SET (STDOUT_FILENO, &wfds);
+ maxfd = MAX (maxfd, STDOUT_FILENO);
+ }
- if (0 < write_pout.size)
- {
- FD_SET(fdpout, &wfds);
- maxfd = MAX(maxfd, fdpout);
- }
+ if (0 < write_pout.size)
+ {
+ FD_SET (fdpout, &wfds);
+ maxfd = MAX (maxfd, fdpout);
+ }
- retval = select(maxfd + 1, &rfds, &wfds, NULL, &tv);
+ retval = select (maxfd + 1, &rfds, &wfds, NULL, &tv);
- if (-1 == retval && EINTR == errno)
- {
- continue;
- }
- if (0 > retval)
- {
- fprintf(stderr, "select failed: %s\n", strerror(errno));
- closeprog = 1;
- break;
- }
+ if (-1 == retval && EINTR == errno)
+ {
+ continue;
+ }
+ if (0 > retval)
+ {
+ fprintf (stderr, "select failed: %s\n", strerror (errno));
+ closeprog = 1;
+ break;
+ }
- if (FD_ISSET(STDOUT_FILENO, &wfds))
+ if (FD_ISSET (STDOUT_FILENO, &wfds))
+ {
+ ret = write (STDOUT_FILENO,
+ write_std.buf + write_std.pos,
+ write_std.size - write_std.pos);
+ if (0 > ret)
+ {
+ closeprog = 1;
+ fprintf (stderr, "Write ERROR to STDOUT\n");
+ break;
+ }
+ else
+ {
+ write_std.pos += ret;
+ // check if finished
+ if (write_std.pos == write_std.size)
{
- ret = write(STDOUT_FILENO,
- write_std.buf + write_std.pos,
- write_std.size - write_std.pos);
- if (0 > ret)
- {
- closeprog = 1;
- fprintf(stderr, "Write ERROR to STDOUT\n");
- break;
- }
- else
- {
- write_std.pos += ret;
- // check if finished
- if (write_std.pos == write_std.size)
- {
- write_std.pos = 0;
- write_std.size = 0;
- }
- }
+ write_std.pos = 0;
+ write_std.size = 0;
}
+ }
+ }
- if (FD_ISSET(fdpout, &wfds))
+ if (FD_ISSET (fdpout, &wfds))
+ {
+ ret = write (fdpout,
+ write_pout.buf + write_pout.pos,
+ write_pout.size - write_pout.pos);
+
+ if (0 > ret)
+ {
+ closeprog = 1;
+ fprintf (stderr, "Write ERROR to fdpout\n");
+ }
+ else
+ {
+ write_pout.pos += ret;
+ // check if finished
+ if (write_pout.pos == write_pout.size)
{
- ret = write(fdpout,
- write_pout.buf + write_pout.pos,
- write_pout.size - write_pout.pos);
-
- if (0 > ret)
- {
- closeprog = 1;
- fprintf(stderr, "Write ERROR to fdpout\n");
- }
- else
- {
- write_pout.pos += ret;
- // check if finished
- if (write_pout.pos == write_pout.size)
- {
- write_pout.pos = 0;
- write_pout.size = 0;
- }
- }
+ write_pout.pos = 0;
+ write_pout.size = 0;
}
+ }
+ }
- if (FD_ISSET(STDIN_FILENO, &rfds))
- {
- readsize = read(STDIN_FILENO, readbuf, sizeof(readbuf));
+ if (FD_ISSET (STDIN_FILENO, &rfds))
+ {
+ readsize = read (STDIN_FILENO, readbuf, sizeof (readbuf));
- if (0 > readsize)
- {
- closeprog = 1;
- fprintf(stderr, "Read ERROR to STDIN_FILENO\n");
- }
- else if (0 < readsize)
- {
- GNUNET_SERVER_mst_receive(stdin_mst, NULL, readbuf, readsize,
- GNUNET_NO, GNUNET_NO);
+ if (0 > readsize)
+ {
+ closeprog = 1;
+ fprintf (stderr, "Read ERROR to STDIN_FILENO\n");
+ }
+ else if (0 < readsize)
+ {
+ GNUNET_SERVER_mst_receive (stdin_mst, NULL, readbuf, readsize,
+ GNUNET_NO, GNUNET_NO);
- }
- else
- {
- //eof
- closeprog = 1;
- }
- }
+ }
+ else
+ {
+ //eof
+ closeprog = 1;
+ }
+ }
- if (FD_ISSET(fdpin, &rfds))
- {
- readsize = read(fdpin, readbuf, sizeof(readbuf));
+ if (FD_ISSET (fdpin, &rfds))
+ {
+ readsize = read (fdpin, readbuf, sizeof (readbuf));
- if (0 > readsize)
- {
- closeprog = 1;
- fprintf(stderr, "Read ERROR to fdpin: %s\n", strerror(errno));
- break;
- }
- else if (0 < readsize)
- {
- GNUNET_SERVER_mst_receive(file_in_mst, NULL, readbuf, readsize,
- GNUNET_NO, GNUNET_NO);
+ if (0 > readsize)
+ {
+ closeprog = 1;
+ fprintf (stderr, "Read ERROR to fdpin: %s\n", strerror (errno));
+ break;
+ }
+ else if (0 < readsize)
+ {
+ GNUNET_SERVER_mst_receive (file_in_mst, NULL, readbuf, readsize,
+ GNUNET_NO, GNUNET_NO);
- }
- else
- {
- //eof
- closeprog = 1;
- }
- }
-
+ }
+ else
+ {
+ //eof
+ closeprog = 1;
+ }
}
+ }
+
//clean up
- GNUNET_SERVER_mst_destroy(stdin_mst);
- GNUNET_SERVER_mst_destroy(file_in_mst);
+ GNUNET_SERVER_mst_destroy (stdin_mst);
+ GNUNET_SERVER_mst_destroy (file_in_mst);
- end: if (fpout != NULL)
- fclose(fpout);
+end:if (fpout != NULL)
+ fclose (fpout);
if (fpin != NULL)
- fclose(fpin);
+ fclose (fpin);
if (1 == first)
- {
- unlink(FIFO_FILE1);
- unlink(FIFO_FILE2);
- }
+ {
+ unlink (FIFO_FILE1);
+ unlink (FIFO_FILE2);
+ }
return (0);
}
int
-main(int argc, char *argv[])
+main (int argc, char *argv[])
{
if (2 != argc)
- {
- fprintf (stderr,
- "This program must be started with the operating mode as
argument.\n");
- fprintf (stderr,
- "Usage: options\n"
- "options:\n"
- "1 = first loopback file\n"
- "2 = second loopback file\n"
- "\n");
- return 1;
- }
- if (strstr(argv[1], "1") || strstr(argv[1], "2"))
- return testmode(argc, argv);
+ {
+ fprintf (stderr,
+ "This program must be started with the operating mode as
argument.\n");
+ fprintf (stderr,
+ "Usage: options\n"
+ "options:\n"
+ "1 = first loopback file\n" "2 = second loopback file\n" "\n");
+ return 1;
+ }
+ if (strstr (argv[1], "1") || strstr (argv[1], "2"))
+ return testmode (argc, argv);
return 1;
}
Modified: gnunet/src/transport/test_quota_compliance.c
===================================================================
--- gnunet/src/transport/test_quota_compliance.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/transport/test_quota_compliance.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -141,7 +141,7 @@
static GNUNET_SCHEDULER_TaskIdentifier measurement_task;
static GNUNET_SCHEDULER_TaskIdentifier measurement_counter_task;
-static struct GNUNET_TRANSPORT_TransmitHandle * transmit_handle;
+static struct GNUNET_TRANSPORT_TransmitHandle *transmit_handle;
#define OKPP do { ok++; } while (0)
@@ -151,28 +151,27 @@
{
GNUNET_SCHEDULER_cancel (die_task);
die_task = GNUNET_SCHEDULER_NO_TASK;
-
+
if (measurement_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (measurement_task);
- measurement_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (measurement_task);
+ measurement_task = GNUNET_SCHEDULER_NO_TASK;
+ }
if (measurement_counter_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (measurement_counter_task);
- measurement_counter_task = GNUNET_SCHEDULER_NO_TASK;
- }
- fprintf(stderr,"\n");
+ {
+ GNUNET_SCHEDULER_cancel (measurement_counter_task);
+ measurement_counter_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ fprintf (stderr, "\n");
GNUNET_SCHEDULER_shutdown ();
#if DEBUG_CONNECTIONS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Disconnecting from transports!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n");
#endif
GNUNET_TRANSPORT_disconnect (p1.th);
GNUNET_TRANSPORT_disconnect (p2.th);
#if DEBUG_CONNECTIONS
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transports disconnected, returning success!\n");
+ "Transports disconnected, returning success!\n");
#endif
GNUNET_SCHEDULER_shutdown ();
}
@@ -194,8 +193,7 @@
static void
-end_badly (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
if (measurement_task != GNUNET_SCHEDULER_NO_TASK)
{
@@ -203,16 +201,16 @@
measurement_task = GNUNET_SCHEDULER_NO_TASK;
}
if (measurement_counter_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (measurement_counter_task);
- measurement_counter_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (measurement_counter_task);
+ measurement_counter_task = GNUNET_SCHEDULER_NO_TASK;
+ }
GNUNET_break (0);
if (GNUNET_SCHEDULER_NO_TASK != tct)
- {
- GNUNET_SCHEDULER_cancel (tct);
- tct = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (tct);
+ tct = GNUNET_SCHEDULER_NO_TASK;
+ }
if (p1.th != NULL)
GNUNET_TRANSPORT_disconnect (p1.th);
if (p2.th != NULL)
@@ -235,32 +233,32 @@
static void
notify_receive_new (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_MessageHeader *message,
- const struct GNUNET_TRANSPORT_ATS_Information *ats, uint32_t
ats_count)
+ const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_MessageHeader *message,
+ const struct GNUNET_TRANSPORT_ATS_Information *ats,
+ uint32_t ats_count)
{
const struct TestMessage *hdr;
GNUNET_assert (message != NULL);
- hdr = (const struct TestMessage*) message;
+ hdr = (const struct TestMessage *) message;
if (measurement_running == GNUNET_NO)
- return;
+ return;
if (MTYPE != ntohs (message->type))
return;
#if DEBUG_MEASUREMENT
- if (ntohl(hdr->num) % 5000 == 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Got message %u of size %u\n",
- ntohl (hdr->num),
- ntohs (message->size));
- }
+ if (ntohl (hdr->num) % 5000 == 0)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Got message %u of size %u\n",
+ ntohl (hdr->num), ntohs (message->size));
+ }
#endif
/*
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Got message %u\n",
- ntohl (hdr->num));*/
+ * GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ * "Got message %u\n",
+ * ntohl (hdr->num)); */
last_msg_recv = ntohl (hdr->num);
}
@@ -278,15 +276,15 @@
return 0;
if (buf == NULL)
- {
- ok = 42;
- return 0;
- }
+ {
+ ok = 42;
+ return 0;
+ }
if (measurement_running != GNUNET_YES)
- {
- send_running = GNUNET_NO;
- return 0;
- }
+ {
+ send_running = GNUNET_NO;
+ return 0;
+ }
send_running = GNUNET_YES;
ret = 0;
s = get_size ();
@@ -295,271 +293,268 @@
last_msg_sent++;
cbuf = buf;
do
- {
- hdr.header.size = htons (s);
- hdr.header.type = htons (MTYPE);
- hdr.num = htonl (last_msg_sent);
- memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage));
- ret += sizeof (struct TestMessage);
- memset (&cbuf[ret], last_msg_sent, s - sizeof (struct TestMessage));
- ret += s - sizeof (struct TestMessage);
+ {
+ hdr.header.size = htons (s);
+ hdr.header.type = htons (MTYPE);
+ hdr.num = htonl (last_msg_sent);
+ memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage));
+ ret += sizeof (struct TestMessage);
+ memset (&cbuf[ret], last_msg_sent, s - sizeof (struct TestMessage));
+ ret += s - sizeof (struct TestMessage);
#if DEBUG_MEASUREMENT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending message %u\n",
- last_msg_sent);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending message %u\n",
last_msg_sent);
#endif
- s = get_size ();
- if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16))
- break; /* sometimes pack buffer full, sometimes not */
- }
+ s = get_size ();
+ if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16))
+ break; /* sometimes pack buffer full, sometimes not */
+ }
while (size - ret >= s);
transmit_handle = GNUNET_TRANSPORT_notify_transmit_ready (p2.th,
- &p1.id,
- s, 0, SEND_TIMEOUT,
- ¬ify_ready,
- NULL);
+ &p1.id,
+ s, 0, SEND_TIMEOUT,
+ ¬ify_ready,
+ NULL);
total_bytes_sent += s;
return ret;
}
+static void measure (unsigned long long quota_p1, unsigned long long quota_p2);
+
static void
-measure (unsigned long long quota_p1, unsigned long long quota_p2);
-
-static void
-measurement_counter (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+measurement_counter (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
measurement_counter_task = GNUNET_SCHEDULER_NO_TASK;
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
return;
-
- fprintf(stderr,".");
- measurement_counter_task = GNUNET_SCHEDULER_add_delayed
(GNUNET_TIME_UNIT_SECONDS,
- &measurement_counter,
- NULL);
+
+ fprintf (stderr, ".");
+ measurement_counter_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &measurement_counter, NULL);
}
static void
-measurement_end (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+measurement_end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
static int strike_counter;
static int failed_measurement_counter = 1;
- unsigned long long quota_allowed = 0;
+ unsigned long long quota_allowed = 0;
int delta = 0;
- measurement_task = GNUNET_SCHEDULER_NO_TASK;
+ measurement_task = GNUNET_SCHEDULER_NO_TASK;
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
return;
measurement_running = GNUNET_NO;
struct GNUNET_TIME_Relative duration
- = GNUNET_TIME_absolute_get_difference(start_time,
GNUNET_TIME_absolute_get());
+ = GNUNET_TIME_absolute_get_difference (start_time,
+ GNUNET_TIME_absolute_get ());
if (measurement_counter_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (measurement_counter_task);
- measurement_counter_task = GNUNET_SCHEDULER_NO_TASK;
- }
-
+ {
+ GNUNET_SCHEDULER_cancel (measurement_counter_task);
+ measurement_counter_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+
if (transmit_handle != NULL)
- {
- GNUNET_TRANSPORT_notify_transmit_ready_cancel(transmit_handle);
- transmit_handle = NULL;
- }
-
+ {
+ GNUNET_TRANSPORT_notify_transmit_ready_cancel (transmit_handle);
+ transmit_handle = NULL;
+ }
+
if (current_quota_p1 < current_quota_p2)
quota_allowed = current_quota_p1;
else
quota_allowed = current_quota_p2;
-
-
- if (MEASUREMENT_SOFT_LIMIT > (quota_allowed/3))
+
+
+ if (MEASUREMENT_SOFT_LIMIT > (quota_allowed / 3))
delta = MEASUREMENT_SOFT_LIMIT;
else
- delta = (quota_allowed/3);
-
+ delta = (quota_allowed / 3);
+
/* Throughput is far too slow. This is to prevent the test to exit with
success when throughput is 0 */
- if ((total_bytes_sent/(duration.rel_value / 1000)) < 100)
+ if ((total_bytes_sent / (duration.rel_value / 1000)) < 100)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "\nQuota compliance failed: \n"
+ "Hard quota limit allowed: %10llu kB/s (%llu B/s)\n"
+ "Soft quota limit allowed: %10llu kB/s (%llu B/s)\n"
+ "Throughput : %10llu kB/s (%llu B/s)\n",
+ (quota_allowed / (1024)), quota_allowed,
+ ((quota_allowed + delta) / (1024)), quota_allowed + delta,
+ (total_bytes_sent / (duration.rel_value / 1000) / 1024),
+ total_bytes_sent / (duration.rel_value / 1000));
+ ok = 1;
+ failed_measurement_counter--;
+ if (failed_measurement_counter < 0)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "\nQuota compliance failed: \n" \
- "Hard quota limit allowed: %10llu kB/s (%llu B/s)\n" \
- "Soft quota limit allowed: %10llu kB/s (%llu B/s)\n" \
- "Throughput : %10llu kB/s (%llu B/s)\n",
- (quota_allowed / (1024)), quota_allowed,
- ((quota_allowed+delta) / (1024)), quota_allowed+delta,
- (total_bytes_sent/(duration.rel_value / 1000)/1024),
- total_bytes_sent/(duration.rel_value / 1000));
- ok = 1;
- failed_measurement_counter--;
- if (failed_measurement_counter < 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "\nQuota measurement failed and no free strike: %i\n",
- failed_measurement_counter);
- end();
- return;
- }
- else
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "\nQuota measurement failed and %i free strikes\n",
- failed_measurement_counter);
+ "\nQuota measurement failed and no free strike: %i\n",
+ failed_measurement_counter);
+ end ();
+ return;
}
-
- /* Throughput is bigger than allowed quota + some extra*/
- if ((total_bytes_sent/(duration.rel_value / 1000)) > (quota_allowed + delta))
+ else
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "\nQuota measurement failed and %i free strikes\n",
+ failed_measurement_counter);
+ }
+
+ /* Throughput is bigger than allowed quota + some extra */
+ if ((total_bytes_sent / (duration.rel_value / 1000)) >
+ (quota_allowed + delta))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "\nQuota compliance failed: \n"
+ "Hard quota limit allowed: %10llu kB/s (%llu B/s)\n"
+ "Soft quota limit allowed: %10llu kB/s (%llu B/s)\n"
+ "Throughput : %10llu kB/s (%llu B/s)\n",
+ (quota_allowed / (1024)), quota_allowed,
+ ((quota_allowed + delta) / (1024)), quota_allowed + delta,
+ (total_bytes_sent / (duration.rel_value / 1000) / 1024),
+ total_bytes_sent / (duration.rel_value / 1000));
+ ok = 1;
+ failed_measurement_counter--;
+ if (failed_measurement_counter < 0)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "\nQuota compliance failed: \n" \
- "Hard quota limit allowed: %10llu kB/s (%llu B/s)\n" \
- "Soft quota limit allowed: %10llu kB/s (%llu B/s)\n" \
- "Throughput : %10llu kB/s (%llu B/s)\n",
- (quota_allowed / (1024)), quota_allowed,
- ((quota_allowed+delta) / (1024)), quota_allowed+delta,
- (total_bytes_sent/(duration.rel_value / 1000)/1024),
- total_bytes_sent/(duration.rel_value / 1000));
- ok = 1;
- failed_measurement_counter--;
- if (failed_measurement_counter < 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "\nQuota measurement failed and no free strike:
%i\n",failed_measurement_counter);
- end();
- return;
- }
- else
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "\nQuota measurement failed and %i free
strikes\n",failed_measurement_counter);
+ "\nQuota measurement failed and no free strike: %i\n",
+ failed_measurement_counter);
+ end ();
+ return;
}
+ else
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "\nQuota measurement failed and %i free strikes\n",
+ failed_measurement_counter);
+ }
else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "\nQuota compliance ok: \n"
+ "Quota allowed: %10llu kB/s\n"
+ "Throughput : %10llu kB/s\n",
+ (quota_allowed / (1024)),
+ (total_bytes_sent / (duration.rel_value / 1000) / 1024));
+ if (failed_measurement_counter < 2)
+ failed_measurement_counter++;
+ ok = 0;
+ }
+
+ if ((quota_allowed) > (2 * (total_bytes_sent / (duration.rel_value / 1000))))
+ {
+ if (failed_measurement_counter < 2)
+ failed_measurement_counter++;
+ if (strike_counter == 2)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "\nQuota compliance ok: \n" \
- "Quota allowed: %10llu kB/s\n" \
- "Throughput : %10llu kB/s\n",
- (quota_allowed / (1024)),
- (total_bytes_sent/(duration.rel_value / 1000)/1024));
- if (failed_measurement_counter < 2)
- failed_measurement_counter++;
- ok = 0;
+ "Maximum transmission rate reached, stopping test\n");
+ end ();
+ return;
}
-
- if ((quota_allowed) > (2 *(total_bytes_sent/(duration.rel_value / 1000))))
- {
- if (failed_measurement_counter < 2)
- failed_measurement_counter++;
- if (strike_counter == 2)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Maximum transmission rate reached, stopping test\n");
- end();
- return;
- }
- }
+ }
else
- {
- strike_counter = 0;
- }
-
+ {
+ strike_counter = 0;
+ }
+
if (quota_allowed == MEASUREMENT_MAX_QUOTA)
- {
- end();
- return;
- }
+ {
+ end ();
+ return;
+ }
if (is_asymmetric_send_constant == GNUNET_YES)
- {
- if ((quota_allowed * 2) < MEASUREMENT_MAX_QUOTA)
- measure (current_quota_p1 * 2, MEASUREMENT_MAX_QUOTA);
- else
- measure (MEASUREMENT_MAX_QUOTA, MEASUREMENT_MAX_QUOTA);
- }
+ {
+ if ((quota_allowed * 2) < MEASUREMENT_MAX_QUOTA)
+ measure (current_quota_p1 * 2, MEASUREMENT_MAX_QUOTA);
+ else
+ measure (MEASUREMENT_MAX_QUOTA, MEASUREMENT_MAX_QUOTA);
+ }
else if (is_asymmetric_recv_constant == GNUNET_YES)
- {
- if ((quota_allowed * 2) < MEASUREMENT_MAX_QUOTA)
- measure (MEASUREMENT_MAX_QUOTA, current_quota_p2 * 2);
- else
- measure (MEASUREMENT_MAX_QUOTA, MEASUREMENT_MAX_QUOTA);
- }
+ {
+ if ((quota_allowed * 2) < MEASUREMENT_MAX_QUOTA)
+ measure (MEASUREMENT_MAX_QUOTA, current_quota_p2 * 2);
+ else
+ measure (MEASUREMENT_MAX_QUOTA, MEASUREMENT_MAX_QUOTA);
+ }
else
- {
- if ((quota_allowed * 2) < MEASUREMENT_MAX_QUOTA)
- measure ((current_quota_p1) * 2, (current_quota_p2) * 2);
- else
- measure (MEASUREMENT_MAX_QUOTA, MEASUREMENT_MAX_QUOTA);
- }
+ {
+ if ((quota_allowed * 2) < MEASUREMENT_MAX_QUOTA)
+ measure ((current_quota_p1) * 2, (current_quota_p2) * 2);
+ else
+ measure (MEASUREMENT_MAX_QUOTA, MEASUREMENT_MAX_QUOTA);
+ }
}
-static void
+static void
measure (unsigned long long quota_p1, unsigned long long quota_p2)
{
current_quota_p1 = quota_p1;
current_quota_p2 = quota_p2;
#if VERBOSE
- if ((is_asymmetric_send_constant == GNUNET_YES) ||
(is_asymmetric_recv_constant == GNUNET_YES))
+ if ((is_asymmetric_send_constant == GNUNET_YES) ||
+ (is_asymmetric_recv_constant == GNUNET_YES))
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Starting transport level measurement for %u seconds, receiving
peer quota %llu kB/s, sending peer quota %llu kB/s\n",
- MEASUREMENT_INTERVALL.rel_value / 1000 ,
- current_quota_p1 / 1024,
- current_quota_p2 / 1024);
+ "Starting transport level measurement for %u seconds,
receiving peer quota %llu kB/s, sending peer quota %llu kB/s\n",
+ MEASUREMENT_INTERVALL.rel_value / 1000, current_quota_p1 /
1024,
+ current_quota_p2 / 1024);
else
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Starting transport level measurement for %u seconds, symmetric
quota %llu kB/s\n",
- MEASUREMENT_INTERVALL.rel_value / 1000,
- current_quota_p2 / 1024);
-
+ "Starting transport level measurement for %u seconds,
symmetric quota %llu kB/s\n",
+ MEASUREMENT_INTERVALL.rel_value / 1000,
+ current_quota_p2 / 1024);
+
#endif
GNUNET_TRANSPORT_set_quota (p1.th,
- &p2.id,
- GNUNET_BANDWIDTH_value_init (current_quota_p1),
- GNUNET_BANDWIDTH_value_init (current_quota_p1));
+ &p2.id,
+ GNUNET_BANDWIDTH_value_init (current_quota_p1),
+ GNUNET_BANDWIDTH_value_init (current_quota_p1));
GNUNET_TRANSPORT_set_quota (p2.th,
- &p1.id,
- GNUNET_BANDWIDTH_value_init (current_quota_p2),
- GNUNET_BANDWIDTH_value_init (current_quota_p2));
+ &p1.id,
+ GNUNET_BANDWIDTH_value_init (current_quota_p2),
+ GNUNET_BANDWIDTH_value_init (current_quota_p2));
GNUNET_SCHEDULER_cancel (die_task);
- die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &end_badly,
- NULL);
+ die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
if (measurement_counter_task != GNUNET_SCHEDULER_NO_TASK)
GNUNET_SCHEDULER_cancel (measurement_counter_task);
- measurement_counter_task = GNUNET_SCHEDULER_add_delayed
(GNUNET_TIME_UNIT_SECONDS,
- &measurement_counter,
- NULL);
- measurement_task = GNUNET_SCHEDULER_add_delayed (MEASUREMENT_INTERVALL,
- &measurement_end,
- NULL);
+ measurement_counter_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &measurement_counter, NULL);
+ measurement_task =
+ GNUNET_SCHEDULER_add_delayed (MEASUREMENT_INTERVALL, &measurement_end,
+ NULL);
total_bytes_sent = 0;
last_msg_sent = 0;
last_msg_recv = 0;
measurement_running = GNUNET_YES;
start_time = GNUNET_TIME_absolute_get ();
-
+
if (transmit_handle != NULL)
- GNUNET_TRANSPORT_notify_transmit_ready_cancel(transmit_handle);
+ GNUNET_TRANSPORT_notify_transmit_ready_cancel (transmit_handle);
transmit_handle = GNUNET_TRANSPORT_notify_transmit_ready (p2.th,
- &p1.id,
- get_size (), 0,
SEND_TIMEOUT,
- ¬ify_ready,
- NULL);
+ &p1.id,
+ get_size (), 0,
+ SEND_TIMEOUT,
+ ¬ify_ready,
+ NULL);
}
static void
-exchange_hello_last (void *cls,
- const struct GNUNET_MessageHeader *message)
+exchange_hello_last (void *cls, const struct GNUNET_MessageHeader *message)
{
struct PeerContext *me = cls;
GNUNET_assert (message != NULL);
#if DEBUG_CONNECTIONS
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Exchanging HELLO of size %d with peer (%s)!\n",
- (int) GNUNET_HELLO_size((const struct GNUNET_HELLO_Message
*)message),
- GNUNET_i2s (&me->id));
+ "Exchanging HELLO of size %d with peer (%s)!\n",
+ (int) GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *)
+ message), GNUNET_i2s (&me->id));
#endif
GNUNET_assert (GNUNET_OK ==
GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
@@ -570,8 +565,7 @@
static void
-exchange_hello (void *cls,
- const struct GNUNET_MessageHeader *message)
+exchange_hello (void *cls, const struct GNUNET_MessageHeader *message)
{
struct PeerContext *me = cls;
@@ -581,9 +575,9 @@
message, &me->id));
#if DEBUG_CONNECTIONS
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Exchanging HELLO of size %d from peer %s!\n",
- (int) GNUNET_HELLO_size((const struct GNUNET_HELLO_Message
*)message),
- GNUNET_i2s (&me->id));
+ "Exchanging HELLO of size %d from peer %s!\n",
+ (int) GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *)
+ message), GNUNET_i2s (&me->id));
#endif
GNUNET_TRANSPORT_offer_hello (p2.th, message, NULL, NULL);
}
@@ -592,43 +586,40 @@
static void
notify_connect (void *cls,
const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_TRANSPORT_ATS_Information *ats, uint32_t
ats_count)
-{
+ const struct GNUNET_TRANSPORT_ATS_Information *ats,
+ uint32_t ats_count)
+{
connected++;
- if (cls == &p1)
- {
+ if (cls == &p1)
+ {
#if DEBUG_CONNECTIONS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peer 1 `%4s' connected to us (%p)!\n",
- GNUNET_i2s (peer),
- cls);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Peer 1 `%4s' connected to us (%p)!\n", GNUNET_i2s (peer),
cls);
#endif
- }
+ }
else
- {
+ {
#if DEBUG_CONNECTIONS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peer 2 `%4s' connected to us (%p)!\n",
- GNUNET_i2s (peer),
- cls);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Peer 2 `%4s' connected to us (%p)!\n", GNUNET_i2s (peer),
cls);
#endif
- }
+ }
if (connected == 2)
+ {
+ if (GNUNET_SCHEDULER_NO_TASK != tct)
{
- if (GNUNET_SCHEDULER_NO_TASK != tct)
- {
- GNUNET_SCHEDULER_cancel (tct);
- tct = GNUNET_SCHEDULER_NO_TASK;
- }
- GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_last, &p2);
- GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, &p1);
- if (is_asymmetric_send_constant == GNUNET_YES)
- measure (MEASUREMENT_MIN_QUOTA, MEASUREMENT_MAX_QUOTA);
- else if (is_asymmetric_recv_constant == GNUNET_YES)
- measure (MEASUREMENT_MAX_QUOTA, MEASUREMENT_MIN_QUOTA);
- else
- measure (MEASUREMENT_MIN_QUOTA, MEASUREMENT_MIN_QUOTA);
+ GNUNET_SCHEDULER_cancel (tct);
+ tct = GNUNET_SCHEDULER_NO_TASK;
}
+ GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_last, &p2);
+ GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, &p1);
+ if (is_asymmetric_send_constant == GNUNET_YES)
+ measure (MEASUREMENT_MIN_QUOTA, MEASUREMENT_MAX_QUOTA);
+ else if (is_asymmetric_recv_constant == GNUNET_YES)
+ measure (MEASUREMENT_MAX_QUOTA, MEASUREMENT_MIN_QUOTA);
+ else
+ measure (MEASUREMENT_MIN_QUOTA, MEASUREMENT_MIN_QUOTA);
+ }
}
@@ -636,18 +627,17 @@
notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
{
if (cls == &p2)
+ {
+ if (NULL != transmit_handle)
{
- if (NULL != transmit_handle)
- {
- GNUNET_TRANSPORT_notify_transmit_ready_cancel (transmit_handle);
- transmit_handle = NULL;
- }
+ GNUNET_TRANSPORT_notify_transmit_ready_cancel (transmit_handle);
+ transmit_handle = NULL;
}
+ }
connected--;
#if DEBUG_CONNECTIONS
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peer `%4s' disconnected (%p)!\n",
- GNUNET_i2s (peer), cls);
+ "Peer `%4s' disconnected (%p)!\n", GNUNET_i2s (peer), cls);
#endif
}
@@ -657,46 +647,41 @@
{
p->cfg = GNUNET_CONFIGURATION_create ();
GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
- if (GNUNET_CONFIGURATION_have_value (p->cfg,"PATHS", "SERVICEHOME"))
- {
- GNUNET_CONFIGURATION_get_value_string (p->cfg, "PATHS", "SERVICEHOME",
&p->servicehome);
- GNUNET_DISK_directory_remove (p->servicehome);
- }
+ if (GNUNET_CONFIGURATION_have_value (p->cfg, "PATHS", "SERVICEHOME"))
+ {
+ GNUNET_CONFIGURATION_get_value_string (p->cfg, "PATHS", "SERVICEHOME",
+ &p->servicehome);
+ GNUNET_DISK_directory_remove (p->servicehome);
+ }
#if START_ARM
p->arm_proc = GNUNET_OS_start_process (NULL, NULL,
- "gnunet-service-arm",
- "gnunet-service-arm",
+ "gnunet-service-arm",
+ "gnunet-service-arm",
#if VERBOSE_ARM
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", cfgname, NULL);
+ "-c", cfgname, NULL);
#endif
p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL,
p,
¬ify_receive_new,
- ¬ify_connect,
- ¬ify_disconnect);
+ ¬ify_connect, ¬ify_disconnect);
GNUNET_assert (p->th != NULL);
}
static void
-try_connect (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
#if DEBUG_CONNECTIONS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Asking peers to connect...\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking peers to connect...\n");
#endif
- GNUNET_TRANSPORT_try_connect (p2.th,
- &p1.id);
- GNUNET_TRANSPORT_try_connect (p1.th,
- &p2.id);
+ GNUNET_TRANSPORT_try_connect (p2.th, &p1.id);
+ GNUNET_TRANSPORT_try_connect (p1.th, &p2.id);
tct = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
- &try_connect,
- NULL);
+ &try_connect, NULL);
}
@@ -708,102 +693,100 @@
GNUNET_assert (ok == 1);
OKPP;
- die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &end_badly,
- NULL);
+ die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
measurement_running = GNUNET_NO;
send_running = GNUNET_NO;
recv_running = GNUNET_NO;
if (is_tcp)
- {
- if (is_asymmetric_recv_constant == GNUNET_YES)
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Testing asymmetric quota compliance (receiver quota
constant) for TCP transport plugin\n");
- else if (is_asymmetric_send_constant == GNUNET_YES)
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Testing asymmetric quota compliance (sender quota
constant) for TCP transport plugin\n");
- else
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Testing symmetric quota compliance for TCP transport
plugin\n");
- setup_peer (&p1, "test_quota_compliance_tcp_peer1.conf");
- setup_peer (&p2, "test_quota_compliance_tcp_peer2.conf");
- }
+ {
+ if (is_asymmetric_recv_constant == GNUNET_YES)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Testing asymmetric quota compliance (receiver quota
constant) for TCP transport plugin\n");
+ else if (is_asymmetric_send_constant == GNUNET_YES)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Testing asymmetric quota compliance (sender quota constant)
for TCP transport plugin\n");
+ else
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Testing symmetric quota compliance for TCP transport
plugin\n");
+ setup_peer (&p1, "test_quota_compliance_tcp_peer1.conf");
+ setup_peer (&p2, "test_quota_compliance_tcp_peer2.conf");
+ }
else if (is_http)
- {
- if (is_asymmetric_recv_constant == GNUNET_YES)
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Testing asymmetric quota compliance (receiver quota
constant) for HTTP transport plugin\n");
- else if (is_asymmetric_send_constant == GNUNET_YES)
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Testing asymmetric quota compliance (sender quota
constant) for HTTP transport plugin\n");
- else
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Testing symmetric quota compliance for HTTP transport
plugin\n");
- setup_peer (&p1, "test_quota_compliance_http_peer1.conf");
- setup_peer (&p2, "test_quota_compliance_http_peer2.conf");
- }
+ {
+ if (is_asymmetric_recv_constant == GNUNET_YES)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Testing asymmetric quota compliance (receiver quota
constant) for HTTP transport plugin\n");
+ else if (is_asymmetric_send_constant == GNUNET_YES)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Testing asymmetric quota compliance (sender quota constant)
for HTTP transport plugin\n");
+ else
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Testing symmetric quota compliance for HTTP transport
plugin\n");
+ setup_peer (&p1, "test_quota_compliance_http_peer1.conf");
+ setup_peer (&p2, "test_quota_compliance_http_peer2.conf");
+ }
else if (is_https)
- {
- if (is_asymmetric_recv_constant == GNUNET_YES)
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Testing asymmetric quota compliance (receiver quota
constant) for HTTPS transport plugin\n");
- else if (is_asymmetric_send_constant == GNUNET_YES)
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Testing asymmetric quota compliance (sender quota
constant) for HTTPS transport plugin\n");
- else
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Testing symmetric quota compliance for HTTPS transport
plugin\n");
- setup_peer (&p1, "test_quota_compliance_https_peer1.conf");
- setup_peer (&p2, "test_quota_compliance_https_peer2.conf");
- }
+ {
+ if (is_asymmetric_recv_constant == GNUNET_YES)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Testing asymmetric quota compliance (receiver quota
constant) for HTTPS transport plugin\n");
+ else if (is_asymmetric_send_constant == GNUNET_YES)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Testing asymmetric quota compliance (sender quota constant)
for HTTPS transport plugin\n");
+ else
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Testing symmetric quota compliance for HTTPS transport
plugin\n");
+ setup_peer (&p1, "test_quota_compliance_https_peer1.conf");
+ setup_peer (&p2, "test_quota_compliance_https_peer2.conf");
+ }
else if (is_udp)
- {
- if (is_asymmetric_recv_constant == GNUNET_YES)
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Testing asymmetric quota compliance (receiver quota
constant) for UDP transport plugin\n");
- else if (is_asymmetric_send_constant == GNUNET_YES)
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Testing asymmetric quota compliance (sender quota
constant) for UDP transport plugin\n");
- else
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Testing symmetric quota compliance for UDP transport
plugin\n");
- setup_peer (&p1, "test_quota_compliance_udp_peer1.conf");
- setup_peer (&p2, "test_quota_compliance_udp_peer2.conf");
- }
+ {
+ if (is_asymmetric_recv_constant == GNUNET_YES)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Testing asymmetric quota compliance (receiver quota
constant) for UDP transport plugin\n");
+ else if (is_asymmetric_send_constant == GNUNET_YES)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Testing asymmetric quota compliance (sender quota constant)
for UDP transport plugin\n");
+ else
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Testing symmetric quota compliance for UDP transport
plugin\n");
+ setup_peer (&p1, "test_quota_compliance_udp_peer1.conf");
+ setup_peer (&p2, "test_quota_compliance_udp_peer2.conf");
+ }
else if (is_unix)
- {
- if (is_asymmetric_recv_constant == GNUNET_YES)
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Testing asymmetric quota compliance (receiver quota
constant) for UNIX transport plugin\n");
- else if (is_asymmetric_send_constant == GNUNET_YES)
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Testing asymmetric quota compliance (sender quota
constant) for UNIX transport plugin\n");
- else
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Testing symmetric quota compliance for UNIX transport
plugin\n");
- setup_peer (&p1, "test_quota_compliance_unix_peer1.conf");
- setup_peer (&p2, "test_quota_compliance_unix_peer2.conf");
- }
+ {
+ if (is_asymmetric_recv_constant == GNUNET_YES)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Testing asymmetric quota compliance (receiver quota
constant) for UNIX transport plugin\n");
+ else if (is_asymmetric_send_constant == GNUNET_YES)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Testing asymmetric quota compliance (sender quota constant)
for UNIX transport plugin\n");
+ else
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Testing symmetric quota compliance for UNIX transport
plugin\n");
+ setup_peer (&p1, "test_quota_compliance_unix_peer1.conf");
+ setup_peer (&p2, "test_quota_compliance_unix_peer2.conf");
+ }
else if (is_tcp_nat)
- {
- if (is_asymmetric_recv_constant == GNUNET_YES)
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Testing asymmetric quota compliance (receiver quota
constant) for TCP NAT transport plugin\n");
- else if (is_asymmetric_send_constant == GNUNET_YES)
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Testing asymmetric quota compliance (sender quota
constant) for TCP NAT transport plugin\n");
- else
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Testing symmetric quota compliance for TCP NAT transport
plugin\n");
- setup_peer (&p1, "test_quota_compliance_tcp_peer1.conf");
- setup_peer (&p2, "test_quota_compliance_tcp_peer2.conf");
- }
+ {
+ if (is_asymmetric_recv_constant == GNUNET_YES)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Testing asymmetric quota compliance (receiver quota
constant) for TCP NAT transport plugin\n");
+ else if (is_asymmetric_send_constant == GNUNET_YES)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Testing asymmetric quota compliance (sender quota constant)
for TCP NAT transport plugin\n");
+ else
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Testing symmetric quota compliance for TCP NAT transport
plugin\n");
+ setup_peer (&p1, "test_quota_compliance_tcp_peer1.conf");
+ setup_peer (&p2, "test_quota_compliance_tcp_peer2.conf");
+ }
else
GNUNET_assert (0);
- GNUNET_assert(p1.th != NULL);
- GNUNET_assert(p2.th != NULL);
+ GNUNET_assert (p1.th != NULL);
+ GNUNET_assert (p2.th != NULL);
GNUNET_TRANSPORT_get_hello (p1.th, &exchange_hello, &p1);
GNUNET_TRANSPORT_get_hello (p2.th, &exchange_hello_last, &p2);
tct = GNUNET_SCHEDULER_add_now (&try_connect, NULL);
@@ -814,96 +797,114 @@
main (int argc, char *argv[])
{
int ret = 0;
- if (strstr(argv[0], "tcp_nat") != NULL)
- {
- is_tcp_nat = GNUNET_YES;
- }
- else if (strstr(argv[0], "tcp") != NULL)
- {
- is_tcp = GNUNET_YES;
- }
- else if (strstr(argv[0], "https") != NULL)
- {
- is_https = GNUNET_YES;
- }
- else if (strstr(argv[0], "http") != NULL)
- {
- is_http = GNUNET_YES;
- }
- else if (strstr(argv[0], "udp") != NULL)
- {
- is_udp = GNUNET_YES;
- }
- else if (strstr(argv[0], "unix") != NULL)
- {
- is_unix = GNUNET_YES;
- }
- if (strstr(argv[0], "asymmetric_recv") != NULL)
+ if (strstr (argv[0], "tcp_nat") != NULL)
{
+ is_tcp_nat = GNUNET_YES;
+ }
+ else if (strstr (argv[0], "tcp") != NULL)
+ {
+ is_tcp = GNUNET_YES;
+ }
+ else if (strstr (argv[0], "https") != NULL)
+ {
+ is_https = GNUNET_YES;
+ }
+ else if (strstr (argv[0], "http") != NULL)
+ {
+ is_http = GNUNET_YES;
+ }
+ else if (strstr (argv[0], "udp") != NULL)
+ {
+ is_udp = GNUNET_YES;
+ }
+ else if (strstr (argv[0], "unix") != NULL)
+ {
+ is_unix = GNUNET_YES;
+ }
+
+ if (strstr (argv[0], "asymmetric_recv") != NULL)
+ {
is_asymmetric_recv_constant = GNUNET_YES;
}
else
is_asymmetric_recv_constant = GNUNET_NO;
- if (strstr(argv[0], "asymmetric_send") != NULL)
- {
- is_asymmetric_send_constant = GNUNET_YES;
- }
+ if (strstr (argv[0], "asymmetric_send") != NULL)
+ {
+ is_asymmetric_send_constant = GNUNET_YES;
+ }
else
is_asymmetric_send_constant = GNUNET_NO;
-
- char * logger;
+
+ char *logger;
+
if (is_tcp == GNUNET_YES)
- {
- if (is_asymmetric_recv_constant == GNUNET_YES)
- GNUNET_asprintf(&logger,
"test-quota-compliance-%s-%s","tcp","asymmetric_recv_constant");
- else if (is_asymmetric_send_constant == GNUNET_YES)
- GNUNET_asprintf(&logger,
"test-quota-compliance-%s-%s","tcp","asymmetric_send_constant");
- else
- GNUNET_asprintf(&logger,
"test-quota-compliance-%s-%s","tcp","symmetric");
- }
+ {
+ if (is_asymmetric_recv_constant == GNUNET_YES)
+ GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "tcp",
+ "asymmetric_recv_constant");
+ else if (is_asymmetric_send_constant == GNUNET_YES)
+ GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "tcp",
+ "asymmetric_send_constant");
+ else
+ GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "tcp",
+ "symmetric");
+ }
else if (is_udp == GNUNET_YES)
- {
- if (is_asymmetric_recv_constant == GNUNET_YES)
- GNUNET_asprintf(&logger,
"test-quota-compliance-%s-%s","udp","asymmetric_recv_constant");
- else if (is_asymmetric_send_constant == GNUNET_YES)
- GNUNET_asprintf(&logger,
"test-quota-compliance-%s-%s","udp","asymmetric_send_constant");
- else
- GNUNET_asprintf(&logger,
"test-quota-compliance-%s-%s","udp","symmetric");
- }
+ {
+ if (is_asymmetric_recv_constant == GNUNET_YES)
+ GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "udp",
+ "asymmetric_recv_constant");
+ else if (is_asymmetric_send_constant == GNUNET_YES)
+ GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "udp",
+ "asymmetric_send_constant");
+ else
+ GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "udp",
+ "symmetric");
+ }
else if (is_unix == GNUNET_YES)
- {
- if (is_asymmetric_recv_constant == GNUNET_YES)
- GNUNET_asprintf(&logger,
"test-quota-compliance-%s-%s","unix","asymmetric_recv_constant");
- else if (is_asymmetric_send_constant == GNUNET_YES)
- GNUNET_asprintf(&logger,
"test-quota-compliance-%s-%s","unix","asymmetric_send_constant");
- else
- GNUNET_asprintf(&logger,
"test-quota-compliance-%s-%s","unix","symmetric");
- }
+ {
+ if (is_asymmetric_recv_constant == GNUNET_YES)
+ GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "unix",
+ "asymmetric_recv_constant");
+ else if (is_asymmetric_send_constant == GNUNET_YES)
+ GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "unix",
+ "asymmetric_send_constant");
+ else
+ GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "unix",
+ "symmetric");
+ }
else if (is_http == GNUNET_YES)
- {
- if (is_asymmetric_recv_constant == GNUNET_YES)
- GNUNET_asprintf(&logger,
"test-quota-compliance-%s-%s","http","asymmetric_recv_constant");
- else if (is_asymmetric_send_constant == GNUNET_YES)
- GNUNET_asprintf(&logger,
"test-quota-compliance-%s-%s","http","asymmetric_send_constant");
- else
- GNUNET_asprintf(&logger,
"test-quota-compliance-%s-%s","http","symmetric");
- }
+ {
+ if (is_asymmetric_recv_constant == GNUNET_YES)
+ GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "http",
+ "asymmetric_recv_constant");
+ else if (is_asymmetric_send_constant == GNUNET_YES)
+ GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "http",
+ "asymmetric_send_constant");
+ else
+ GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "http",
+ "symmetric");
+ }
else if (is_https == GNUNET_YES)
- {
- if (is_asymmetric_recv_constant == GNUNET_YES)
- GNUNET_asprintf(&logger,
"test-quota-compliance-%s-%s","https","asymmetric_recv_constant");
- else if (is_asymmetric_send_constant == GNUNET_YES)
- GNUNET_asprintf(&logger,
"test-quota-compliance-%s-%s","https","asymmetric_send_constant");
- else
- GNUNET_asprintf(&logger,
"test-quota-compliance-%s-%s","https","symmetric");
- }
+ {
+ if (is_asymmetric_recv_constant == GNUNET_YES)
+ GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "https",
+ "asymmetric_recv_constant");
+ else if (is_asymmetric_send_constant == GNUNET_YES)
+ GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "https",
+ "asymmetric_send_constant");
+ else
+ GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "https",
+ "symmetric");
+ }
else
- {
- GNUNET_asprintf(&logger,
"test-quota-compliance-%s-%s","noplugin","none");
- }
+ {
+ GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "noplugin",
+ "none");
+ }
- fprintf(stderr, "Running `%s'\n", logger);
+ fprintf (stderr, "Running `%s'\n", logger);
GNUNET_log_setup ("test-quota-compliance",
#if VERBOSE
"DEBUG",
@@ -924,23 +925,22 @@
};
ok = 1;
GNUNET_PROGRAM_run ((sizeof (argv1) / sizeof (char *)) - 1,
- argv1, logger , "nohelp",
- options, &run, &ok);
+ argv1, logger, "nohelp", options, &run, &ok);
ret = ok;
stop_arm (&p1);
stop_arm (&p2);
if (p1.servicehome != NULL)
- {
- GNUNET_DISK_directory_remove (p1.servicehome);
- GNUNET_free(p1.servicehome);
- }
+ {
+ GNUNET_DISK_directory_remove (p1.servicehome);
+ GNUNET_free (p1.servicehome);
+ }
if (p2.servicehome != NULL)
- {
- GNUNET_DISK_directory_remove (p2.servicehome);
- GNUNET_free(p2.servicehome);
- }
- GNUNET_free(logger);
+ {
+ GNUNET_DISK_directory_remove (p2.servicehome);
+ GNUNET_free (p2.servicehome);
+ }
+ GNUNET_free (logger);
return ret;
}
Modified: gnunet/src/transport/test_transport_api.c
===================================================================
--- gnunet/src/transport/test_transport_api.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/transport/test_transport_api.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -57,17 +57,17 @@
static int ok;
-static GNUNET_SCHEDULER_TaskIdentifier die_task;
+static GNUNET_SCHEDULER_TaskIdentifier die_task;
-struct PeerContext * p1;
+struct PeerContext *p1;
-struct PeerContext * p2;
+struct PeerContext *p2;
-struct GNUNET_TRANSPORT_TransmitHandle * th;
+struct GNUNET_TRANSPORT_TransmitHandle *th;
-char * cfg_file_p1;
+char *cfg_file_p1;
-char * cfg_file_p2;
+char *cfg_file_p2;
#if VERBOSE
#define OKPP do { ok++; fprintf (stderr, "Now at stage %u at %s:%u\n", ok,
__FILE__, __LINE__); } while (0)
@@ -82,33 +82,33 @@
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n");
if (die_task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel(die_task);
+ GNUNET_SCHEDULER_cancel (die_task);
if (th != NULL)
- GNUNET_TRANSPORT_notify_transmit_ready_cancel(th);
+ GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
th = NULL;
- GNUNET_TRANSPORT_TESTING_stop_peer(p1);
- GNUNET_TRANSPORT_TESTING_stop_peer(p2);
+ GNUNET_TRANSPORT_TESTING_stop_peer (p1);
+ GNUNET_TRANSPORT_TESTING_stop_peer (p2);
}
static void
end_badly ()
{
if (die_task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel(die_task);
+ GNUNET_SCHEDULER_cancel (die_task);
die_task = GNUNET_SCHEDULER_NO_TASK;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n");
if (th != NULL)
- GNUNET_TRANSPORT_notify_transmit_ready_cancel(th);
+ GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
th = NULL;
if (p1 != NULL)
- GNUNET_TRANSPORT_TESTING_stop_peer(p1);
+ GNUNET_TRANSPORT_TESTING_stop_peer (p1);
if (p2 != NULL)
- GNUNET_TRANSPORT_TESTING_stop_peer(p2);
+ GNUNET_TRANSPORT_TESTING_stop_peer (p2);
ok = GNUNET_SYSERR;
}
@@ -121,22 +121,21 @@
const struct GNUNET_TRANSPORT_ATS_Information *ats,
uint32_t ats_count)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received message of type %d from peer %s!\n",
- ntohs(message->type),
- GNUNET_i2s (peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received message of type %d from peer %s!\n",
+ ntohs (message->type), GNUNET_i2s (peer));
if ((MTYPE == ntohs (message->type)) &&
(sizeof (struct GNUNET_MessageHeader) == ntohs (message->size)))
{
ok = 0;
- end();
+ end ();
}
else
{
GNUNET_break (0);
ok = 1;
- end();
+ end ();
}
}
@@ -150,9 +149,8 @@
th = NULL;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitting message with %u bytes to peer %s\n",
- sizeof (struct GNUNET_MessageHeader),
- GNUNET_i2s (&p->id));
+ "Transmitting message with %u bytes to peer %s\n",
+ sizeof (struct GNUNET_MessageHeader), GNUNET_i2s (&p->id));
GNUNET_assert (size >= 256);
if (buf != NULL)
@@ -172,41 +170,37 @@
uint32_t ats_count)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peer `%4s' connected to us (%p)!\n",
- GNUNET_i2s (peer),
- cls);
+ "Peer `%4s' connected to us (%p)!\n", GNUNET_i2s (peer), cls);
}
static void
-notify_disconnect (void *cls,
- const struct GNUNET_PeerIdentity *peer)
+notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peer `%4s' disconnected (%p)!\n",
- GNUNET_i2s (peer), cls);
+ "Peer `%4s' disconnected (%p)!\n", GNUNET_i2s (peer), cls);
}
static void
sendtask ()
{
th = GNUNET_TRANSPORT_notify_transmit_ready (p1->th,
- &p2->id,
- 256, 0, TIMEOUT, ¬ify_ready,
- &p1);
+ &p2->id,
+ 256, 0, TIMEOUT, ¬ify_ready,
+ &p1);
}
static void
-testing_connect_cb (struct PeerContext * p1, struct PeerContext * p2, void
*cls)
+testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
{
- char * p1_c = strdup (GNUNET_i2s(&p1->id));
+ 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));
+ p1_c, GNUNET_i2s (&p2->id));
GNUNET_free (p1_c);
// FIXME: THIS IS REQUIRED! SEEMS TO BE A BUG!
- GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, &sendtask, NULL);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &sendtask, NULL);
}
static void
@@ -214,21 +208,18 @@
char *const *args,
const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
- die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &end_badly, NULL);
+ die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
- p1 = GNUNET_TRANSPORT_TESTING_start_peer(cfg_file_p1,
- ¬ify_receive,
- ¬ify_connect,
- ¬ify_disconnect,
- NULL);
- p2 = GNUNET_TRANSPORT_TESTING_start_peer(cfg_file_p2,
- ¬ify_receive,
- ¬ify_connect,
- ¬ify_disconnect,
- NULL);
+ p1 = GNUNET_TRANSPORT_TESTING_start_peer (cfg_file_p1,
+ ¬ify_receive,
+ ¬ify_connect,
+ ¬ify_disconnect, NULL);
+ p2 = GNUNET_TRANSPORT_TESTING_start_peer (cfg_file_p2,
+ ¬ify_receive,
+ ¬ify_connect,
+ ¬ify_disconnect, NULL);
- GNUNET_TRANSPORT_TESTING_connect_peers(p1, p2, &testing_connect_cb, NULL);
+ GNUNET_TRANSPORT_TESTING_connect_peers (p1, p2, &testing_connect_cb, NULL);
}
static int
@@ -247,12 +238,11 @@
};
#if WRITECONFIG
- setTransportOptions("test_transport_api_data.conf");
+ setTransportOptions ("test_transport_api_data.conf");
#endif
ok = 1;
GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
- argv, "test-transport-api", "nohelp",
- options, &run, &ok);
+ argv, "test-transport-api", "nohelp", options, &run,
&ok);
return ok;
}
@@ -274,32 +264,32 @@
p = getenv ("PATH");
if (p == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("PATH environment variable is unset.\n"));
- return NULL;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("PATH environment variable is unset.\n"));
+ return NULL;
+ }
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)
{
- *end = '\0';
- sprintf (buf, "%s/%s", pos, binary);
- if (GNUNET_DISK_file_test (buf) == GNUNET_YES)
- {
- GNUNET_free (path);
- return buf;
- }
- pos = end + 1;
- }
- sprintf (buf, "%s/%s", pos, binary);
- if (GNUNET_DISK_file_test (buf) == GNUNET_YES)
- {
GNUNET_free (path);
return buf;
}
+ pos = end + 1;
+ }
+ sprintf (buf, "%s/%s", pos, binary);
+ if (GNUNET_DISK_file_test (buf) == GNUNET_YES)
+ {
+ GNUNET_free (path);
+ return buf;
+ }
GNUNET_free (buf);
GNUNET_free (path);
return NULL;
@@ -316,16 +306,18 @@
* can be run properly, GNUNET_NO otherwise
*/
static int
-check_gnunet_nat_binary(char *binary)
+check_gnunet_nat_binary (char *binary)
{
struct stat statbuf;
char *p;
+
#ifdef MINGW
SOCKET rawsock;
#endif
#ifdef MINGW
char *binaryexe;
+
GNUNET_asprintf (&binaryexe, "%s.exe", binary);
p = get_path_from_PATH (binaryexe);
free (binaryexe);
@@ -333,36 +325,34 @@
p = get_path_from_PATH (binary);
#endif
if (p == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Could not find binary `%s' in PATH!\n"),
- binary);
- return GNUNET_NO;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Could not find binary `%s' in PATH!\n"), binary);
+ return GNUNET_NO;
+ }
if (0 != STAT (p, &statbuf))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("stat (%s) failed: %s\n"),
- p,
- STRERROR (errno));
- GNUNET_free (p);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("stat (%s) failed: %s\n"), p, STRERROR (errno));
+ GNUNET_free (p);
+ return GNUNET_SYSERR;
+ }
GNUNET_free (p);
#ifndef MINGW
- if ( (0 != (statbuf.st_mode & S_ISUID)) &&
- (statbuf.st_uid == 0) )
+ if ((0 != (statbuf.st_mode & S_ISUID)) && (statbuf.st_uid == 0))
return GNUNET_YES;
return GNUNET_NO;
#else
rawsock = socket (AF_INET, SOCK_RAW, IPPROTO_ICMP);
if (INVALID_SOCKET == rawsock)
- {
- DWORD err = GetLastError ();
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "socket (AF_INET, SOCK_RAW, IPPROTO_ICMP) have failed! GLE =
%d\n", err);
- return GNUNET_NO; /* not running as administrator */
- }
+ {
+ DWORD err = GetLastError ();
+
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "socket (AF_INET, SOCK_RAW, IPPROTO_ICMP) have failed! GLE =
%d\n",
+ err);
+ return GNUNET_NO; /* not running as administrator */
+ }
closesocket (rawsock);
return GNUNET_YES;
#endif
@@ -381,13 +371,13 @@
#endif
NULL);
- char * pch = strdup(argv[0]);
- char * backup = pch;
- char * filename = NULL;
+ char *pch = strdup (argv[0]);
+ char *backup = pch;
+ char *filename = NULL;
char *dotexe;
/* get executable filename */
- pch = strtok (pch,"/");
+ pch = strtok (pch, "/");
while (pch != NULL)
{
pch = strtok (NULL, "/");
@@ -395,35 +385,35 @@
filename = pch;
}
/* remove "lt-" */
- filename = strstr(filename, "tes");
+ filename = strstr (filename, "tes");
if (NULL != (dotexe = strstr (filename, ".exe")))
dotexe[0] = '\0';
/* create cfg filename */
- GNUNET_asprintf(&cfg_file_p1, "%s_peer1.conf",filename);
- GNUNET_asprintf(&cfg_file_p2, "%s_peer2.conf", filename);
+ GNUNET_asprintf (&cfg_file_p1, "%s_peer1.conf", filename);
+ GNUNET_asprintf (&cfg_file_p2, "%s_peer2.conf", filename);
GNUNET_free (backup);
- if (strstr(argv[0], "tcp_nat") != NULL)
+ if (strstr (argv[0], "tcp_nat") != NULL)
+ {
+ if (GNUNET_YES != check_gnunet_nat_binary ("gnunet-nat-server"))
{
- if (GNUNET_YES != check_gnunet_nat_binary("gnunet-nat-server"))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "`%s' not properly installed, cannot run NAT test!\n",
- "gnunet-nat-server");
- return 0;
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "`%s' not properly installed, cannot run NAT test!\n",
+ "gnunet-nat-server");
+ return 0;
}
- else if (strstr(argv[0], "udp_nat") != NULL)
+ }
+ else if (strstr (argv[0], "udp_nat") != NULL)
+ {
+ if (GNUNET_YES != check_gnunet_nat_binary ("gnunet-nat-server"))
{
- if (GNUNET_YES != check_gnunet_nat_binary("gnunet-nat-server"))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "`%s' not properly installed, cannot run NAT test!\n",
- "gnunet-nat-server");
- return 0;
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "`%s' not properly installed, cannot run NAT test!\n",
+ "gnunet-nat-server");
+ return 0;
}
+ }
ret = check ();
Modified: gnunet/src/transport/test_transport_api_disconnect.c
===================================================================
--- gnunet/src/transport/test_transport_api_disconnect.c 2011-08-15
21:40:08 UTC (rev 16580)
+++ gnunet/src/transport/test_transport_api_disconnect.c 2011-08-15
21:46:35 UTC (rev 16581)
@@ -67,11 +67,11 @@
static int counter;
static int msgs_recv;
-static GNUNET_SCHEDULER_TaskIdentifier die_task;
+static GNUNET_SCHEDULER_TaskIdentifier die_task;
-static GNUNET_SCHEDULER_TaskIdentifier tct;
+static GNUNET_SCHEDULER_TaskIdentifier tct;
-struct GNUNET_TRANSPORT_TransmitHandle * th;
+struct GNUNET_TRANSPORT_TransmitHandle *th;
#if VERBOSE
#define OKPP do { ok++; fprintf (stderr, "Now at stage %u at %s:%u\n", ok,
__FILE__, __LINE__); } while (0)
@@ -80,18 +80,16 @@
#endif
-static void
-peers_connect ();
+static void peers_connect ();
static void
end ()
{
if (GNUNET_SCHEDULER_NO_TASK != die_task)
GNUNET_SCHEDULER_cancel (die_task);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Disconnecting from transports!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n");
if (th != NULL)
- GNUNET_TRANSPORT_notify_transmit_ready_cancel(th);
+ GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
th = NULL;
if (p1.th != NULL)
@@ -100,8 +98,8 @@
if (p2.th != NULL)
GNUNET_TRANSPORT_disconnect (p2.th);
die_task = GNUNET_SCHEDULER_NO_TASK;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transports disconnected, returning success!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Transports disconnected, returning success!\n");
ok = 0;
}
@@ -110,13 +108,13 @@
{
#if START_ARM
if (NULL != p->arm_proc)
- {
- if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
- GNUNET_OS_process_wait (p->arm_proc);
- GNUNET_OS_process_close (p->arm_proc);
- p->arm_proc = NULL;
- }
+ {
+ if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
+ GNUNET_OS_process_wait (p->arm_proc);
+ GNUNET_OS_process_close (p->arm_proc);
+ p->arm_proc = NULL;
+ }
#endif
GNUNET_CONFIGURATION_destroy (p->cfg);
}
@@ -125,16 +123,15 @@
static void
-exchange_hello_last (void *cls,
- const struct GNUNET_MessageHeader *message)
+exchange_hello_last (void *cls, const struct GNUNET_MessageHeader *message)
{
struct PeerContext *me = cls;
GNUNET_assert (message != NULL);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Exchanging HELLO of size %d with peer (%s)!\n",
- (int) GNUNET_HELLO_size((const struct GNUNET_HELLO_Message
*)message),
- GNUNET_i2s (&me->id));
+ "Exchanging HELLO of size %d with peer (%s)!\n",
+ (int) GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *)
+ message), GNUNET_i2s (&me->id));
GNUNET_assert (GNUNET_OK ==
GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
message, &me->id));
@@ -143,8 +140,7 @@
static void
-exchange_hello (void *cls,
- const struct GNUNET_MessageHeader *message)
+exchange_hello (void *cls, const struct GNUNET_MessageHeader *message)
{
struct PeerContext *me = cls;
@@ -153,9 +149,9 @@
GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
message, &me->id));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Exchanging HELLO of size %d from peer %s!\n",
- (int) GNUNET_HELLO_size((const struct GNUNET_HELLO_Message
*)message),
- GNUNET_i2s (&me->id));
+ "Exchanging HELLO of size %d from peer %s!\n",
+ (int) GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *)
+ message), GNUNET_i2s (&me->id));
GNUNET_TRANSPORT_offer_hello (p2.th, message, NULL, NULL);
}
@@ -167,23 +163,23 @@
GNUNET_break (0);
if (th != NULL)
- {
- GNUNET_TRANSPORT_notify_transmit_ready_cancel(th);
- th = NULL;
- }
+ {
+ GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
+ th = NULL;
+ }
else
- {
- GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_last, &p2);
- GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, &p1);
- }
+ {
+ GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_last, &p2);
+ GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, &p1);
+ }
GNUNET_TRANSPORT_disconnect (p1.th);
GNUNET_TRANSPORT_disconnect (p2.th);
if (GNUNET_SCHEDULER_NO_TASK != tct)
- {
- GNUNET_SCHEDULER_cancel (tct);
- tct = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (tct);
+ tct = GNUNET_SCHEDULER_NO_TASK;
+ }
ok = 1;
}
@@ -196,20 +192,17 @@
uint32_t ats_count)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received message of type %d from peer %s!\n",
- ntohs(message->type),
- GNUNET_i2s (peer));
+ "Received message of type %d from peer %s!\n",
+ ntohs (message->type), GNUNET_i2s (peer));
OKPP;
GNUNET_assert (MTYPE == ntohs (message->type));
- GNUNET_assert (sizeof (struct GNUNET_MessageHeader) ==
- ntohs (message->size));
+ GNUNET_assert (sizeof (struct GNUNET_MessageHeader) == ntohs
(message->size));
msgs_recv++;
}
static void
-peers_disconnect (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+peers_disconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
static size_t
notify_ready (void *cls, size_t size, void *buf)
@@ -220,9 +213,8 @@
th = NULL;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitting message with %u bytes to peer %s\n",
- sizeof (struct GNUNET_MessageHeader),
- GNUNET_i2s (&p->id));
+ "Transmitting message with %u bytes to peer %s\n",
+ sizeof (struct GNUNET_MessageHeader), GNUNET_i2s (&p->id));
GNUNET_assert (size >= 256);
OKPP;
if (buf != NULL)
@@ -245,94 +237,83 @@
uint32_t ats_count)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peer `%4s' connected to us (%p)!\n",
- GNUNET_i2s (peer),
- cls);
+ "Peer `%4s' connected to us (%p)!\n", GNUNET_i2s (peer), cls);
peers_connected++;
if (cls == &p1)
- {
- GNUNET_assert (ok >= 2);
- OKPP;
- OKPP;
- if (GNUNET_SCHEDULER_NO_TASK != die_task)
- GNUNET_SCHEDULER_cancel (die_task);
- if (GNUNET_SCHEDULER_NO_TASK != tct)
- GNUNET_SCHEDULER_cancel (tct);
- tct = GNUNET_SCHEDULER_NO_TASK;
+ {
+ GNUNET_assert (ok >= 2);
+ OKPP;
+ OKPP;
+ if (GNUNET_SCHEDULER_NO_TASK != die_task)
+ GNUNET_SCHEDULER_cancel (die_task);
+ if (GNUNET_SCHEDULER_NO_TASK != tct)
+ GNUNET_SCHEDULER_cancel (tct);
+ tct = GNUNET_SCHEDULER_NO_TASK;
- die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT_TRANSMIT,
- &end_badly, NULL);
- th = GNUNET_TRANSPORT_notify_transmit_ready (p1.th,
- &p2.id,
- 256, 0, TIMEOUT, ¬ify_ready,
- &p1);
- }
+ die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT_TRANSMIT,
+ &end_badly, NULL);
+ th = GNUNET_TRANSPORT_notify_transmit_ready (p1.th,
+ &p2.id,
+ 256, 0, TIMEOUT,
¬ify_ready,
+ &p1);
+ }
}
static void
-notify_disconnect (void *cls,
- const struct GNUNET_PeerIdentity *peer)
+notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peer `%4s' disconnected (%p)!\n",
- GNUNET_i2s (peer), cls);
+ "Peer `%4s' disconnected (%p)!\n", GNUNET_i2s (peer), cls);
peers_connected--;
}
static void
-setup_peer (struct PeerContext *p,
- const char *cfgname)
+setup_peer (struct PeerContext *p, const char *cfgname)
{
p->cfg = GNUNET_CONFIGURATION_create ();
GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
- if (GNUNET_CONFIGURATION_have_value (p->cfg,"PATHS", "SERVICEHOME"))
- GNUNET_CONFIGURATION_get_value_string (p->cfg, "PATHS", "SERVICEHOME",
&p->servicehome);
+ if (GNUNET_CONFIGURATION_have_value (p->cfg, "PATHS", "SERVICEHOME"))
+ GNUNET_CONFIGURATION_get_value_string (p->cfg, "PATHS", "SERVICEHOME",
+ &p->servicehome);
if (NULL != p->servicehome)
- GNUNET_DISK_directory_remove (p->servicehome);
+ GNUNET_DISK_directory_remove (p->servicehome);
#if START_ARM
p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
- "gnunet-service-arm",
+ "gnunet-service-arm",
#if VERBOSE_ARM
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", cfgname, NULL);
+ "-c", cfgname, NULL);
#endif
}
static void
-try_connect (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Asking peers to connect...\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking peers to connect...\n");
/* FIXME: 'pX.id' may still be all-zeros here... */
- GNUNET_TRANSPORT_try_connect (p2.th,
- &p1.id);
- GNUNET_TRANSPORT_try_connect (p1.th,
- &p2.id);
+ GNUNET_TRANSPORT_try_connect (p2.th, &p1.id);
+ GNUNET_TRANSPORT_try_connect (p1.th, &p2.id);
tct = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
- &try_connect,
- NULL);
+ &try_connect, NULL);
}
static void
-peers_disconnect (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+peers_disconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
+ if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
return;
//while (peers_connected > 0);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Disconnecting from Transport \n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from Transport \n");
GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_last, &p2);
GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, &p1);
@@ -343,10 +324,10 @@
GNUNET_TRANSPORT_disconnect (p2.th);
p2.th = NULL;
- while (peers_connected > 0);
+ while (peers_connected > 0) ;
if (counter < ITERATIONS)
- peers_connect();
+ peers_connect ();
else
end ();
}
@@ -354,8 +335,9 @@
static void
peers_connect ()
{
- counter ++;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Iteration %i of %i\n", counter,
ITERATIONS);
+ counter++;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Iteration %i of %i\n", counter,
+ ITERATIONS);
GNUNET_assert (p1.th == NULL);
p1.th = GNUNET_TRANSPORT_connect (p1.cfg,
@@ -369,8 +351,8 @@
¬ify_receive,
¬ify_connect, ¬ify_disconnect);
- GNUNET_assert(p1.th != NULL);
- GNUNET_assert(p2.th != NULL);
+ GNUNET_assert (p1.th != NULL);
+ GNUNET_assert (p2.th != NULL);
GNUNET_TRANSPORT_get_hello (p1.th, &exchange_hello, &p1);
GNUNET_TRANSPORT_get_hello (p2.th, &exchange_hello_last, &p2);
@@ -384,8 +366,7 @@
{
GNUNET_assert (ok == 1);
OKPP;
- die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &end_badly, NULL);
+ die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
setup_peer (&p1, "test_transport_api_tcp_peer1.conf");
setup_peer (&p2, "test_transport_api_tcp_peer2.conf");
@@ -409,25 +390,24 @@
};
#if WRITECONFIG
- setTransportOptions("test_transport_api_data.conf");
+ setTransportOptions ("test_transport_api_data.conf");
#endif
ok = 1;
GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
- argv, "test-transport-api", "nohelp",
- options, &run, &ok);
+ argv, "test-transport-api", "nohelp", options, &run,
&ok);
stop_arm (&p1);
stop_arm (&p2);
if (p1.servicehome != NULL)
- {
+ {
GNUNET_DISK_directory_remove (p1.servicehome);
- GNUNET_free(p1.servicehome);
- }
+ GNUNET_free (p1.servicehome);
+ }
if (p2.servicehome != NULL)
- {
- GNUNET_DISK_directory_remove (p2.servicehome);
- GNUNET_free(p2.servicehome);
- }
+ {
+ GNUNET_DISK_directory_remove (p2.servicehome);
+ GNUNET_free (p2.servicehome);
+ }
return ok;
}
Modified: gnunet/src/transport/test_transport_api_multiaddress.c
===================================================================
--- gnunet/src/transport/test_transport_api_multiaddress.c 2011-08-15
21:40:08 UTC (rev 16580)
+++ gnunet/src/transport/test_transport_api_multiaddress.c 2011-08-15
21:46:35 UTC (rev 16581)
@@ -63,9 +63,9 @@
static int is_tcp;
-static GNUNET_SCHEDULER_TaskIdentifier die_task;
+static GNUNET_SCHEDULER_TaskIdentifier die_task;
-static GNUNET_SCHEDULER_TaskIdentifier tct;
+static GNUNET_SCHEDULER_TaskIdentifier tct;
#if VERBOSE
@@ -81,13 +81,13 @@
{
#if START_ARM
if (NULL != p->arm_proc)
- {
- if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
- GNUNET_OS_process_wait (p->arm_proc);
- GNUNET_OS_process_close (p->arm_proc);
- p->arm_proc = NULL;
- }
+ {
+ if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
+ GNUNET_OS_process_wait (p->arm_proc);
+ GNUNET_OS_process_close (p->arm_proc);
+ p->arm_proc = NULL;
+ }
#endif
GNUNET_CONFIGURATION_destroy (p->cfg);
}
@@ -96,16 +96,15 @@
static void
-exchange_hello_last (void *cls,
- const struct GNUNET_MessageHeader *message)
+exchange_hello_last (void *cls, const struct GNUNET_MessageHeader *message)
{
struct PeerContext *me = cls;
GNUNET_assert (message != NULL);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Exchanging HELLO of size %d with peer (%s)!\n",
- (int) GNUNET_HELLO_size((const struct GNUNET_HELLO_Message
*)message),
- GNUNET_i2s (&me->id));
+ "Exchanging HELLO of size %d with peer (%s)!\n",
+ (int) GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *)
+ message), GNUNET_i2s (&me->id));
GNUNET_assert (GNUNET_OK ==
GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
message, &me->id));
@@ -114,8 +113,7 @@
static void
-exchange_hello (void *cls,
- const struct GNUNET_MessageHeader *message)
+exchange_hello (void *cls, const struct GNUNET_MessageHeader *message)
{
struct PeerContext *me = cls;
@@ -124,9 +122,9 @@
GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
message, &me->id));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Exchanging HELLO of size %d from peer %s!\n",
- (int) GNUNET_HELLO_size((const struct GNUNET_HELLO_Message
*)message),
- GNUNET_i2s (&me->id));
+ "Exchanging HELLO of size %d from peer %s!\n",
+ (int) GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *)
+ message), GNUNET_i2s (&me->id));
GNUNET_TRANSPORT_offer_hello (p2.th, message, NULL, NULL);
}
@@ -142,10 +140,10 @@
GNUNET_TRANSPORT_disconnect (p1.th);
GNUNET_TRANSPORT_disconnect (p2.th);
if (GNUNET_SCHEDULER_NO_TASK != tct)
- {
- GNUNET_SCHEDULER_cancel (tct);
- tct = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (tct);
+ tct = GNUNET_SCHEDULER_NO_TASK;
+ }
ok = 1;
}
@@ -159,10 +157,10 @@
GNUNET_TRANSPORT_disconnect (p1.th);
GNUNET_TRANSPORT_disconnect (p2.th);
if (GNUNET_SCHEDULER_NO_TASK != tct)
- {
- GNUNET_SCHEDULER_cancel (tct);
- tct = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (tct);
+ tct = GNUNET_SCHEDULER_NO_TASK;
+ }
ok = 0;
}
@@ -173,87 +171,76 @@
uint32_t ats_count)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peer `%4s' connected to us (%p)!\n",
- GNUNET_i2s (peer),
- cls);
+ "Peer `%4s' connected to us (%p)!\n", GNUNET_i2s (peer), cls);
if (cls == &p1)
- {
- GNUNET_assert (ok >= 2);
- OKPP;
- OKPP;
- if (GNUNET_SCHEDULER_NO_TASK != die_task)
- GNUNET_SCHEDULER_cancel (die_task);
- if (GNUNET_SCHEDULER_NO_TASK != tct)
- GNUNET_SCHEDULER_cancel (tct);
- tct = GNUNET_SCHEDULER_NO_TASK;
- die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT_TRANSMIT,
- &end_normally, NULL);
- }
+ {
+ GNUNET_assert (ok >= 2);
+ OKPP;
+ OKPP;
+ if (GNUNET_SCHEDULER_NO_TASK != die_task)
+ GNUNET_SCHEDULER_cancel (die_task);
+ if (GNUNET_SCHEDULER_NO_TASK != tct)
+ GNUNET_SCHEDULER_cancel (tct);
+ tct = GNUNET_SCHEDULER_NO_TASK;
+ die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT_TRANSMIT,
+ &end_normally, NULL);
+ }
}
static void
-notify_disconnect (void *cls,
- const struct GNUNET_PeerIdentity *peer)
+notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
{
- if ( (ok != 60) &&
- (GNUNET_SCHEDULER_NO_TASK != die_task) )
- {
- GNUNET_SCHEDULER_cancel (die_task);
- die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
- }
+ if ((ok != 60) && (GNUNET_SCHEDULER_NO_TASK != die_task))
+ {
+ GNUNET_SCHEDULER_cancel (die_task);
+ die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
+ }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peer `%4s' disconnected (%p)!\n",
- GNUNET_i2s (peer), cls);
+ "Peer `%4s' disconnected (%p)!\n", GNUNET_i2s (peer), cls);
}
static void
-setup_peer (struct PeerContext *p,
- const char *cfgname)
+setup_peer (struct PeerContext *p, const char *cfgname)
{
p->cfg = GNUNET_CONFIGURATION_create ();
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_DISK_directory_remove (p->servicehome);
- }
+ 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_DISK_directory_remove (p->servicehome);
+ }
#if START_ARM
p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
- "gnunet-service-arm",
+ "gnunet-service-arm",
#if VERBOSE_ARM
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", cfgname, NULL);
+ "-c", cfgname, NULL);
#endif
p->th = GNUNET_TRANSPORT_connect (p->cfg,
NULL, p,
- NULL,
- ¬ify_connect, ¬ify_disconnect);
+ NULL, ¬ify_connect, ¬ify_disconnect);
GNUNET_assert (p->th != NULL);
}
static void
-try_connect (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Asking peers to connect...\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking peers to connect...\n");
/* FIXME: 'pX.id' may still be all-zeros here... */
- GNUNET_TRANSPORT_try_connect (p2.th,
- &p1.id);
- GNUNET_TRANSPORT_try_connect (p1.th,
- &p2.id);
+ GNUNET_TRANSPORT_try_connect (p2.th, &p1.id);
+ GNUNET_TRANSPORT_try_connect (p1.th, &p2.id);
tct = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
- &try_connect,
- NULL);
+ &try_connect, NULL);
}
@@ -264,15 +251,14 @@
{
GNUNET_assert (ok == 1);
OKPP;
- die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &end_badly, NULL);
+ die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
if (is_tcp)
- {
- setup_peer (&p1, "test_transport_api_multiaddress_tcp_peer1.conf");
- setup_peer (&p2, "test_transport_api_multiaddress_tcp_peer2.conf");
- }
- GNUNET_assert(p1.th != NULL);
- GNUNET_assert(p2.th != NULL);
+ {
+ setup_peer (&p1, "test_transport_api_multiaddress_tcp_peer1.conf");
+ setup_peer (&p2, "test_transport_api_multiaddress_tcp_peer2.conf");
+ }
+ GNUNET_assert (p1.th != NULL);
+ GNUNET_assert (p2.th != NULL);
GNUNET_TRANSPORT_get_hello (p1.th, &exchange_hello, &p1);
GNUNET_TRANSPORT_get_hello (p2.th, &exchange_hello_last, &p2);
@@ -295,25 +281,24 @@
};
#if WRITECONFIG
- setTransportOptions("test_transport_api_data.conf");
+ setTransportOptions ("test_transport_api_data.conf");
#endif
ok = 1;
GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
- argv, "test-transport-api", "nohelp",
- options, &run, &ok);
+ argv, "test-transport-api", "nohelp", options, &run,
&ok);
stop_arm (&p1);
stop_arm (&p2);
if (p1.servicehome != NULL)
- {
- GNUNET_DISK_directory_remove (p1.servicehome);
- GNUNET_free(p1.servicehome);
- }
+ {
+ GNUNET_DISK_directory_remove (p1.servicehome);
+ GNUNET_free (p1.servicehome);
+ }
if (p2.servicehome != NULL)
- {
- GNUNET_DISK_directory_remove (p2.servicehome);
- GNUNET_free(p2.servicehome);
- }
+ {
+ GNUNET_DISK_directory_remove (p2.servicehome);
+ GNUNET_free (p2.servicehome);
+ }
return ok;
}
@@ -331,10 +316,10 @@
#endif
NULL);
- if (strstr(argv[0], "tcp") != NULL)
- {
- is_tcp = GNUNET_YES;
- }
+ if (strstr (argv[0], "tcp") != NULL)
+ {
+ is_tcp = GNUNET_YES;
+ }
ret = check ();
Modified: gnunet/src/transport/test_transport_api_reliability.c
===================================================================
--- gnunet/src/transport/test_transport_api_reliability.c 2011-08-15
21:40:08 UTC (rev 16580)
+++ gnunet/src/transport/test_transport_api_reliability.c 2011-08-15
21:46:35 UTC (rev 16581)
@@ -51,17 +51,17 @@
static int ok;
-static GNUNET_SCHEDULER_TaskIdentifier die_task;
+static GNUNET_SCHEDULER_TaskIdentifier die_task;
-struct PeerContext * p1;
+struct PeerContext *p1;
-struct PeerContext * p2;
+struct PeerContext *p2;
-struct GNUNET_TRANSPORT_TransmitHandle * th;
+struct GNUNET_TRANSPORT_TransmitHandle *th;
-char * cfg_file_p1;
+char *cfg_file_p1;
-char * cfg_file_p2;
+char *cfg_file_p2;
/*
* Testcase specific declarations
@@ -108,27 +108,27 @@
end ()
{
unsigned long long delta;
+
//char *value_name;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n");
delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value;
fprintf (stderr,
- "\nThroughput was %llu kb/s\n",
- total_bytes * 1000 / 1024 / delta);
+ "\nThroughput was %llu kb/s\n", total_bytes * 1000 / 1024 / delta);
//GNUNET_asprintf(&value_name, "reliable_%s", test_name);
//GAUGER ("TRANSPORT", value_name, (int)(total_bytes * 1000 / 1024 /delta),
"kb/s");
//GNUNET_free(value_name);
if (die_task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel(die_task);
+ GNUNET_SCHEDULER_cancel (die_task);
if (th != NULL)
- GNUNET_TRANSPORT_notify_transmit_ready_cancel(th);
+ GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
th = NULL;
- GNUNET_TRANSPORT_TESTING_stop_peer(p1);
- GNUNET_TRANSPORT_TESTING_stop_peer(p2);
+ GNUNET_TRANSPORT_TESTING_stop_peer (p1);
+ GNUNET_TRANSPORT_TESTING_stop_peer (p2);
}
static void
@@ -138,13 +138,13 @@
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n");
if (th != NULL)
- GNUNET_TRANSPORT_notify_transmit_ready_cancel(th);
+ GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
th = NULL;
if (p1 != NULL)
- GNUNET_TRANSPORT_TESTING_stop_peer(p1);
+ GNUNET_TRANSPORT_TESTING_stop_peer (p1);
if (p2 != NULL)
- GNUNET_TRANSPORT_TESTING_stop_peer(p2);
+ GNUNET_TRANSPORT_TESTING_stop_peer (p2);
ok = GNUNET_SYSERR;
}
@@ -172,75 +172,66 @@
char cbuf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1];
const struct TestMessage *hdr;
- hdr = (const struct TestMessage*) message;
+ hdr = (const struct TestMessage *) message;
s = get_size (n);
if (MTYPE != ntohs (message->type))
return;
msg_recv_expected = n;
- msg_recv = ntohl(hdr->num);
+ msg_recv = ntohl (hdr->num);
if (ntohs (message->size) != (s))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Expected message %u of size %u, got %u bytes of message
%u\n",
- n, s,
- ntohs (message->size),
- ntohl (hdr->num));
- 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);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Expected message %u of size %u, got %u bytes of message %u\n",
+ n, s, ntohs (message->size), ntohl (hdr->num));
+ 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);
+ return;
+ }
if (ntohl (hdr->num) != n)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Expected message %u of size %u, got %u bytes of message
%u\n",
- n, s,
- ntohs (message->size),
- ntohl (hdr->num));
- 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);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Expected message %u of size %u, got %u bytes of message %u\n",
+ n, s, ntohs (message->size), ntohl (hdr->num));
+ 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);
+ return;
+ }
memset (cbuf, n, s - sizeof (struct TestMessage));
- if (0 != memcmp (cbuf,
- &hdr[1],
- s - sizeof (struct TestMessage)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Expected message %u with bits %u, but body did not match\n",
- n, (unsigned char) n);
- 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);
- return;
- }
+ if (0 != memcmp (cbuf, &hdr[1], s - sizeof (struct TestMessage)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Expected message %u with bits %u, but body did not match\n",
+ n, (unsigned char) n);
+ 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);
+ return;
+ }
#if VERBOSE
- if (ntohl(hdr->num) % 5000 == 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Got message %u of size %u\n",
- ntohl (hdr->num),
- ntohs (message->size));
- }
+ if (ntohl (hdr->num) % 5000 == 0)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Got message %u of size %u\n",
+ ntohl (hdr->num), ntohs (message->size));
+ }
#endif
n++;
- if (0 == (n % (TOTAL_MSGS/100)))
- {
- fprintf (stderr, ".");
- if (die_task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel (die_task);
- die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &end_badly,
- NULL);
- }
+ if (0 == (n % (TOTAL_MSGS / 100)))
+ {
+ fprintf (stderr, ".");
+ if (die_task != GNUNET_SCHEDULER_NO_TASK)
+ GNUNET_SCHEDULER_cancel (die_task);
+ die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
+ }
if (n == TOTAL_MSGS)
{
ok = 0;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"All messages received\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All messages received\n");
end ();
}
}
@@ -256,11 +247,11 @@
unsigned int ret;
if (buf == NULL)
- {
- GNUNET_break (0);
- ok = 42;
- return 0;
- }
+ {
+ GNUNET_break (0);
+ ok = 42;
+ return 0;
+ }
th = NULL;
ret = 0;
s = get_size (n);
@@ -268,50 +259,46 @@
GNUNET_assert (buf != NULL);
cbuf = buf;
do
- {
- hdr.header.size = htons (s);
- hdr.header.type = htons (MTYPE);
- hdr.num = htonl (n);
- msg_sent = n;
- memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage));
- ret += sizeof (struct TestMessage);
- memset (&cbuf[ret], n, s - sizeof (struct TestMessage));
- ret += s - sizeof (struct TestMessage);
+ {
+ hdr.header.size = htons (s);
+ hdr.header.type = htons (MTYPE);
+ hdr.num = htonl (n);
+ msg_sent = n;
+ memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage));
+ ret += sizeof (struct TestMessage);
+ memset (&cbuf[ret], n, s - sizeof (struct TestMessage));
+ ret += s - sizeof (struct TestMessage);
#if VERBOSE
- if (n % 5000 == 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending message %u of size %u\n",
- n,
- s);
- }
-#endif
- n++;
- s = get_size (n);
- if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16))
- break; /* sometimes pack buffer full, sometimes not */
+ if (n % 5000 == 0)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending message %u of size %u\n", n, s);
}
+#endif
+ n++;
+ s = get_size (n);
+ if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16))
+ break; /* sometimes pack buffer full, sometimes not */
+ }
while (size - ret >= s);
if (n < TOTAL_MSGS)
{
if (th == NULL)
th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th,
- &p1->id,
- s, 0, TIMEOUT,
- ¬ify_ready,
- NULL);
+ &p1->id,
+ s, 0, TIMEOUT,
+ ¬ify_ready, NULL);
msg_scheduled = n;
}
if (n % 5000 == 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Returning total message block of size %u\n",
- ret);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Returning total message block of size %u\n", ret);
+ }
total_bytes += ret;
if (n == TOTAL_MSGS)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"All messages sent\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All messages sent\n");
}
return ret;
}
@@ -325,34 +312,34 @@
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peer `%4s' connected to us (%p)!\n",
- GNUNET_i2s (peer),
- cls);
+ "Peer `%4s' connected to us (%p)!\n", GNUNET_i2s (peer), cls);
if (cls == p1)
- {
- GNUNET_TRANSPORT_set_quota (p1->th,
- &p2->id,
- GNUNET_BANDWIDTH_value_init (1024 * 1024 *
1024),
- GNUNET_BANDWIDTH_value_init (1024 * 1024 *
1024));
- }
- else if (cls == p2)
- {
- GNUNET_TRANSPORT_set_quota (p2->th,
- &p1->id,
- GNUNET_BANDWIDTH_value_init (1024 * 1024 *
1024),
- GNUNET_BANDWIDTH_value_init (1024 * 1024 *
1024));
- }
+ {
+ GNUNET_TRANSPORT_set_quota (p1->th,
+ &p2->id,
+ GNUNET_BANDWIDTH_value_init (1024 * 1024 *
+ 1024),
+ GNUNET_BANDWIDTH_value_init (1024 * 1024 *
+ 1024));
+ }
+ else if (cls == p2)
+ {
+ GNUNET_TRANSPORT_set_quota (p2->th,
+ &p1->id,
+ GNUNET_BANDWIDTH_value_init (1024 * 1024 *
+ 1024),
+ GNUNET_BANDWIDTH_value_init (1024 * 1024 *
+ 1024));
+ }
}
static void
-notify_disconnect (void *cls,
- const struct GNUNET_PeerIdentity *peer)
+notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peer `%4s' disconnected (%p)!\n",
- GNUNET_i2s (peer), cls);
+ "Peer `%4s' disconnected (%p)!\n", GNUNET_i2s (peer), cls);
}
static void
@@ -360,23 +347,22 @@
{
start_time = GNUNET_TIME_absolute_get ();
th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th,
- &p1->id,
- get_size (0), 0, TIMEOUT,
- ¬ify_ready,
- NULL);
+ &p1->id,
+ get_size (0), 0, TIMEOUT,
+ ¬ify_ready, NULL);
}
static void
-testing_connect_cb (struct PeerContext * p1, struct PeerContext * p2, void
*cls)
+testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
{
- char * p1_c = strdup (GNUNET_i2s(&p1->id));
+ 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));
+ p1_c, GNUNET_i2s (&p2->id));
GNUNET_free (p1_c);
// FIXME: THIS IS REQUIRED! SEEMS TO BE A BUG!
- GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, &sendtask, NULL);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &sendtask, NULL);
}
static void
@@ -384,21 +370,18 @@
char *const *args,
const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
- die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &end_badly, NULL);
+ die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
- p1 = GNUNET_TRANSPORT_TESTING_start_peer(cfg_file_p1,
- ¬ify_receive,
- ¬ify_connect,
- ¬ify_disconnect,
- NULL);
- p2 = GNUNET_TRANSPORT_TESTING_start_peer(cfg_file_p2,
- ¬ify_receive,
- ¬ify_connect,
- ¬ify_disconnect,
- NULL);
+ p1 = GNUNET_TRANSPORT_TESTING_start_peer (cfg_file_p1,
+ ¬ify_receive,
+ ¬ify_connect,
+ ¬ify_disconnect, NULL);
+ p2 = GNUNET_TRANSPORT_TESTING_start_peer (cfg_file_p2,
+ ¬ify_receive,
+ ¬ify_connect,
+ ¬ify_disconnect, NULL);
- GNUNET_TRANSPORT_TESTING_connect_peers(p1, p2, &testing_connect_cb, NULL);
+ GNUNET_TRANSPORT_TESTING_connect_peers (p1, p2, &testing_connect_cb, NULL);
}
static int
@@ -417,12 +400,11 @@
};
#if WRITECONFIG
- setTransportOptions("test_transport_api_data.conf");
+ setTransportOptions ("test_transport_api_data.conf");
#endif
ok = 1;
GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
- argv, "test-transport-api", "nohelp",
- options, &run, &ok);
+ argv, "test-transport-api", "nohelp", options, &run,
&ok);
return ok;
}
@@ -444,32 +426,32 @@
p = getenv ("PATH");
if (p == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("PATH environment variable is unset.\n"));
- return NULL;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("PATH environment variable is unset.\n"));
+ return NULL;
+ }
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)
{
- *end = '\0';
- sprintf (buf, "%s/%s", pos, binary);
- if (GNUNET_DISK_file_test (buf) == GNUNET_YES)
- {
- GNUNET_free (path);
- return buf;
- }
- pos = end + 1;
- }
- sprintf (buf, "%s/%s", pos, binary);
- if (GNUNET_DISK_file_test (buf) == GNUNET_YES)
- {
GNUNET_free (path);
return buf;
}
+ pos = end + 1;
+ }
+ sprintf (buf, "%s/%s", pos, binary);
+ if (GNUNET_DISK_file_test (buf) == GNUNET_YES)
+ {
+ GNUNET_free (path);
+ return buf;
+ }
GNUNET_free (buf);
GNUNET_free (path);
return NULL;
@@ -486,16 +468,18 @@
* can be run properly, GNUNET_NO otherwise
*/
static int
-check_gnunet_nat_binary(char *binary)
+check_gnunet_nat_binary (char *binary)
{
struct stat statbuf;
char *p;
+
#ifdef MINGW
SOCKET rawsock;
#endif
#ifdef MINGW
char *binaryexe;
+
GNUNET_asprintf (&binaryexe, "%s.exe", binary);
p = get_path_from_PATH (binaryexe);
free (binaryexe);
@@ -503,36 +487,34 @@
p = get_path_from_PATH (binary);
#endif
if (p == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Could not find binary `%s' in PATH!\n"),
- binary);
- return GNUNET_NO;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Could not find binary `%s' in PATH!\n"), binary);
+ return GNUNET_NO;
+ }
if (0 != STAT (p, &statbuf))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("stat (%s) failed: %s\n"),
- p,
- STRERROR (errno));
- GNUNET_free (p);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("stat (%s) failed: %s\n"), p, STRERROR (errno));
+ GNUNET_free (p);
+ return GNUNET_SYSERR;
+ }
GNUNET_free (p);
#ifndef MINGW
- if ( (0 != (statbuf.st_mode & S_ISUID)) &&
- (statbuf.st_uid == 0) )
+ if ((0 != (statbuf.st_mode & S_ISUID)) && (statbuf.st_uid == 0))
return GNUNET_YES;
return GNUNET_NO;
#else
rawsock = socket (AF_INET, SOCK_RAW, IPPROTO_ICMP);
if (INVALID_SOCKET == rawsock)
- {
- DWORD err = GetLastError ();
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "socket (AF_INET, SOCK_RAW, IPPROTO_ICMP) have failed! GLE =
%d\n", err);
- return GNUNET_NO; /* not running as administrator */
- }
+ {
+ DWORD err = GetLastError ();
+
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "socket (AF_INET, SOCK_RAW, IPPROTO_ICMP) have failed! GLE =
%d\n",
+ err);
+ return GNUNET_NO; /* not running as administrator */
+ }
closesocket (rawsock);
return GNUNET_YES;
#endif
@@ -551,13 +533,13 @@
#endif
NULL);
- char * pch = strdup(argv[0]);
- char * backup = pch;
- char * filename = NULL;
+ char *pch = strdup (argv[0]);
+ char *backup = pch;
+ char *filename = NULL;
char *dotexe;
/* get executable filename */
- pch = strtok (pch,"/");
+ pch = strtok (pch, "/");
while (pch != NULL)
{
pch = strtok (NULL, "/");
@@ -565,35 +547,35 @@
filename = pch;
}
/* remove "lt-" */
- filename = strstr(filename, "tes");
+ filename = strstr (filename, "tes");
if (NULL != (dotexe = strstr (filename, ".exe")))
dotexe[0] = '\0';
/* create cfg filename */
- GNUNET_asprintf(&cfg_file_p1, "%s_peer1.conf",filename);
- GNUNET_asprintf(&cfg_file_p2, "%s_peer2.conf", filename);
+ GNUNET_asprintf (&cfg_file_p1, "%s_peer1.conf", filename);
+ GNUNET_asprintf (&cfg_file_p2, "%s_peer2.conf", filename);
GNUNET_free (backup);
- if (strstr(argv[0], "tcp_nat") != NULL)
+ if (strstr (argv[0], "tcp_nat") != NULL)
+ {
+ if (GNUNET_YES != check_gnunet_nat_binary ("gnunet-nat-server"))
{
- if (GNUNET_YES != check_gnunet_nat_binary("gnunet-nat-server"))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "`%s' not properly installed, cannot run NAT test!\n",
- "gnunet-nat-server");
- return 0;
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "`%s' not properly installed, cannot run NAT test!\n",
+ "gnunet-nat-server");
+ return 0;
}
- else if (strstr(argv[0], "udp_nat") != NULL)
+ }
+ else if (strstr (argv[0], "udp_nat") != NULL)
+ {
+ if (GNUNET_YES != check_gnunet_nat_binary ("gnunet-nat-server"))
{
- if (GNUNET_YES != check_gnunet_nat_binary("gnunet-nat-server"))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "`%s' not properly installed, cannot run NAT test!\n",
- "gnunet-nat-server");
- return 0;
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "`%s' not properly installed, cannot run NAT test!\n",
+ "gnunet-nat-server");
+ return 0;
}
+ }
ret = check ();
Modified: gnunet/src/transport/test_transport_api_unreliability.c
===================================================================
--- gnunet/src/transport/test_transport_api_unreliability.c 2011-08-15
21:40:08 UTC (rev 16580)
+++ gnunet/src/transport/test_transport_api_unreliability.c 2011-08-15
21:46:35 UTC (rev 16581)
@@ -50,7 +50,7 @@
* 'MAX_PENDING' in 'gnunet-service-transport.c', otherwise
* messages may be dropped even for a reliable transport.
*/
-#define TOTAL_MSGS (1024 * 3) /* Total messages should be divisible by 8, so
we can make a nice bitmap */
+#define TOTAL_MSGS (1024 * 3) /* Total messages should be divisible by 8, so
we can make a nice bitmap */
/**
* How long until we give up on transmitting the message?
@@ -91,7 +91,7 @@
static GNUNET_SCHEDULER_TaskIdentifier tct;
-struct GNUNET_TRANSPORT_TransmitHandle * th_p2;
+struct GNUNET_TRANSPORT_TransmitHandle *th_p2;
static char *key_file_p1;
static char *cert_file_p1;
@@ -123,11 +123,13 @@
{
size_t arraySlot;
unsigned int targetBit;
- if (bitIdx >= sizeof(bitmap) * 8)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "tried to set bit %d of
%d(!?!?)\n", bitIdx, sizeof(bitmap) * 8);
- return;
- }
+
+ if (bitIdx >= sizeof (bitmap) * 8)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "tried to set bit %d of %d(!?!?)\n",
+ bitIdx, sizeof (bitmap) * 8);
+ return;
+ }
arraySlot = bitIdx / 8;
targetBit = (1L << (bitIdx % 8));
bitmap[arraySlot] |= targetBit;
@@ -144,10 +146,11 @@
get_bit (const char *map, unsigned int bit)
{
if (bit >= TOTAL_MSGS)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "get bit %d of %d(!?!?)\n", bit,
sizeof(bitmap) * 8);
- return 0;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "get bit %d of %d(!?!?)\n", bit,
+ sizeof (bitmap) * 8);
+ return 0;
+ }
return ((map)[bit >> 3] & (1 << (bit & 7))) > 0;
}
@@ -161,13 +164,13 @@
result = 0;
for (i = 0; i < TOTAL_MSGS; i++)
+ {
+ if (get_bit (bitmap, i) == 0)
{
- if (get_bit(bitmap, i) == 0)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Did not receive message
%d\n", i);
- result = -1;
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Did not receive message %d\n",
i);
+ result = -1;
}
+ }
if (GNUNET_SCHEDULER_NO_TASK != die_task)
GNUNET_SCHEDULER_cancel (die_task);
@@ -176,22 +179,22 @@
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n");
#endif
if (th_p2 != NULL)
- GNUNET_TRANSPORT_notify_transmit_ready_cancel(th_p2);
+ GNUNET_TRANSPORT_notify_transmit_ready_cancel (th_p2);
th_p2 = NULL;
GNUNET_TRANSPORT_disconnect (p1.th);
GNUNET_TRANSPORT_disconnect (p2.th);
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transports disconnected, returning success!\n");
+ "Transports disconnected, returning success!\n");
#endif
delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value;
- GNUNET_asprintf(&value_name, "unreliable_%s", test_name);
- GAUGER ("TRANSPORT", value_name, (int)(total_bytes * 1000 / 1024 /delta),
"kb/s");
- GNUNET_free(value_name);
+ GNUNET_asprintf (&value_name, "unreliable_%s", test_name);
+ GAUGER ("TRANSPORT", value_name, (int) (total_bytes * 1000 / 1024 / delta),
+ "kb/s");
+ GNUNET_free (value_name);
fprintf (stderr,
- "\nThroughput was %llu kb/s\n",
- total_bytes * 1000 / 1024 / delta);
+ "\nThroughput was %llu kb/s\n", total_bytes * 1000 / 1024 / delta);
ok = result;
}
@@ -203,22 +206,23 @@
int i;
int num_failed;
char *value_name;
+
num_failed = 0;
for (i = 0; i < TOTAL_MSGS; i++)
+ {
+ if (get_bit (bitmap, i) == 0)
{
- if (get_bit(bitmap, i) == 0)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Did not receive message %d\n",
i);
- num_failed++;
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Did not receive message %d\n", i);
+ num_failed++;
}
+ }
die_task = GNUNET_SCHEDULER_NO_TASK;
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n");
#endif
if (th_p2 != NULL)
- GNUNET_TRANSPORT_notify_transmit_ready_cancel(th_p2);
+ GNUNET_TRANSPORT_notify_transmit_ready_cancel (th_p2);
GNUNET_TRANSPORT_disconnect (p1.th);
GNUNET_TRANSPORT_disconnect (p2.th);
@@ -228,15 +232,16 @@
#endif
delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value;
fprintf (stderr,
- "\nThroughput was %llu kb/s\n",
- total_bytes * 1000 / 1024 / delta);
- GNUNET_asprintf(&value_name, "unreliable_%s", test_name);
- GAUGER ("TRANSPORT", value_name, (int)(total_bytes * 1000 / 1024 /delta),
"kb/s");
- GNUNET_free(value_name);
- GNUNET_asprintf(&value_name, "unreliable_failed_%s", test_name);
- GAUGER ("TRANSPORT", value_name, (int)num_failed, "msgs");
- GNUNET_free(value_name);
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Had %d failed messages!\n",
num_failed);
+ "\nThroughput was %llu kb/s\n", total_bytes * 1000 / 1024 / delta);
+ GNUNET_asprintf (&value_name, "unreliable_%s", test_name);
+ GAUGER ("TRANSPORT", value_name, (int) (total_bytes * 1000 / 1024 / delta),
+ "kb/s");
+ GNUNET_free (value_name);
+ GNUNET_asprintf (&value_name, "unreliable_failed_%s", test_name);
+ GAUGER ("TRANSPORT", value_name, (int) num_failed, "msgs");
+ GNUNET_free (value_name);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Had %d failed messages!\n",
+ num_failed);
ok = 0;
}
@@ -259,16 +264,15 @@
static void
-exchange_hello_last (void *cls,
- const struct GNUNET_MessageHeader *message)
+exchange_hello_last (void *cls, const struct GNUNET_MessageHeader *message)
{
struct PeerContext *me = cls;
GNUNET_assert (message != NULL);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Exchanging HELLO of size %d with peer (%s)!\n",
- (int) GNUNET_HELLO_size((const struct GNUNET_HELLO_Message
*)message),
- GNUNET_i2s (&me->id));
+ "Exchanging HELLO of size %d with peer (%s)!\n",
+ (int) GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *)
+ message), GNUNET_i2s (&me->id));
GNUNET_assert (GNUNET_OK ==
GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
message, &me->id));
@@ -278,8 +282,7 @@
static void
-exchange_hello (void *cls,
- const struct GNUNET_MessageHeader *message)
+exchange_hello (void *cls, const struct GNUNET_MessageHeader *message)
{
struct PeerContext *me = cls;
@@ -288,52 +291,47 @@
GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
message, &me->id));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Exchanging HELLO of size %d from peer %s!\n",
- (int) GNUNET_HELLO_size((const struct GNUNET_HELLO_Message
*)message),
- GNUNET_i2s (&me->id));
+ "Exchanging HELLO of size %d from peer %s!\n",
+ (int) GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *)
+ message), GNUNET_i2s (&me->id));
GNUNET_TRANSPORT_offer_hello (p2.th, message, NULL, NULL);
}
static void
-end_badly (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
if (test_failed == GNUNET_NO)
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Testcase timeout\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Testcase 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);
-
+ "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);
+
GNUNET_break (0);
if (th_p2 != NULL)
- {
- GNUNET_TRANSPORT_notify_transmit_ready_cancel(th_p2);
- th_p2 = NULL;
- }
+ {
+ GNUNET_TRANSPORT_notify_transmit_ready_cancel (th_p2);
+ th_p2 = NULL;
+ }
if (p2_hello_canceled == GNUNET_NO)
- {
- GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_last, &p2);
- p2_hello_canceled = GNUNET_YES;
- }
+ {
+ GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_last, &p2);
+ p2_hello_canceled = GNUNET_YES;
+ }
if (p1_hello_canceled == GNUNET_NO)
- {
- GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, &p1);
- p1_hello_canceled = GNUNET_YES;
- }
+ {
+ GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, &p1);
+ p1_hello_canceled = GNUNET_YES;
+ }
GNUNET_TRANSPORT_disconnect (p1.th);
GNUNET_TRANSPORT_disconnect (p2.th);
if (GNUNET_SCHEDULER_NO_TASK != tct)
- {
- GNUNET_SCHEDULER_cancel (tct);
- tct = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (tct);
+ tct = GNUNET_SCHEDULER_NO_TASK;
+ }
ok = 1;
}
@@ -368,63 +366,56 @@
char cbuf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1];
const struct TestMessage *hdr;
- hdr = (const struct TestMessage*) message;
+ hdr = (const struct TestMessage *) message;
if (MTYPE != ntohs (message->type))
return;
msg_recv_expected = n;
- msg_recv = ntohl(hdr->num);
- s = get_size (ntohl(hdr->num));
+ msg_recv = ntohl (hdr->num);
+ s = get_size (ntohl (hdr->num));
if (ntohs (message->size) != s)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Expected message %u of size %u, got %u bytes of message
%u\n",
- ntohl(hdr->num), s,
- ntohs (message->size),
- ntohl (hdr->num));
- if (GNUNET_SCHEDULER_NO_TASK != die_task)
- GNUNET_SCHEDULER_cancel (die_task);
- test_failed = GNUNET_YES;
- die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Expected message %u of size %u, got %u bytes of message %u\n",
+ ntohl (hdr->num), s, ntohs (message->size), ntohl (hdr->num));
+ if (GNUNET_SCHEDULER_NO_TASK != die_task)
+ GNUNET_SCHEDULER_cancel (die_task);
+ test_failed = GNUNET_YES;
+ die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
+ return;
+ }
- memset (cbuf, ntohl(hdr->num), s - sizeof (struct TestMessage));
- if (0 != memcmp (cbuf,
- &hdr[1],
- s - sizeof (struct TestMessage)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Expected message %u with bits %u, but body did not match\n",
- ntohl(hdr->num), (unsigned char) n);
- if (GNUNET_SCHEDULER_NO_TASK != die_task)
- GNUNET_SCHEDULER_cancel (die_task);
- test_failed = GNUNET_YES;
- die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
- return;
- }
+ memset (cbuf, ntohl (hdr->num), s - sizeof (struct TestMessage));
+ if (0 != memcmp (cbuf, &hdr[1], s - sizeof (struct TestMessage)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Expected message %u with bits %u, but body did not match\n",
+ ntohl (hdr->num), (unsigned char) n);
+ if (GNUNET_SCHEDULER_NO_TASK != die_task)
+ GNUNET_SCHEDULER_cancel (die_task);
+ test_failed = GNUNET_YES;
+ die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
+ return;
+ }
#if VERBOSE
- if (ntohl(hdr->num) % 5 == 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Got message %u of size %u\n",
- ntohl (hdr->num),
- ntohs (message->size));
- }
+ if (ntohl (hdr->num) % 5 == 0)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Got message %u of size %u\n",
+ ntohl (hdr->num), ntohs (message->size));
+ }
#endif
n++;
- set_bit(ntohl(hdr->num));
+ set_bit (ntohl (hdr->num));
if (0 == (n % (TOTAL_MSGS / 100)))
- {
- fprintf (stderr, ".");
- if (GNUNET_SCHEDULER_NO_TASK != die_task)
- GNUNET_SCHEDULER_cancel (die_task);
- test_failed = GNUNET_YES;
- die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &end_badly,
- NULL);
- }
+ {
+ fprintf (stderr, ".");
+ if (GNUNET_SCHEDULER_NO_TASK != die_task)
+ GNUNET_SCHEDULER_cancel (die_task);
+ test_failed = GNUNET_YES;
+ die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
+ }
if (n == TOTAL_MSGS)
end ();
}
@@ -442,63 +433,62 @@
th_p2 = NULL;
if (buf == NULL)
- {
- GNUNET_break (0);
- ok = 42;
- return 0;
- }
+ {
+ GNUNET_break (0);
+ ok = 42;
+ return 0;
+ }
ret = 0;
s = get_size (n);
GNUNET_assert (size >= s);
GNUNET_assert (buf != NULL);
cbuf = buf;
do
- {
- hdr.header.size = htons (s);
- hdr.header.type = htons (MTYPE);
- hdr.num = htonl (n);
- msg_sent = n;
- memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage));
- ret += sizeof (struct TestMessage);
- memset (&cbuf[ret], n, s - sizeof (struct TestMessage));
- ret += s - sizeof (struct TestMessage);
+ {
+ hdr.header.size = htons (s);
+ hdr.header.type = htons (MTYPE);
+ hdr.num = htonl (n);
+ msg_sent = n;
+ memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage));
+ ret += sizeof (struct TestMessage);
+ memset (&cbuf[ret], n, s - sizeof (struct TestMessage));
+ ret += s - sizeof (struct TestMessage);
#if VERBOSE
- if (n % 5000 == 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending message %u of size %u\n",
- n,
- s);
- }
-#endif
- n++;
- s = get_size (n);
- if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16))
- break; /* sometimes pack buffer full, sometimes not */
+ if (n % 5000 == 0)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending message %u of size %u\n", n, s);
}
+#endif
+ n++;
+ s = get_size (n);
+ if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16))
+ break; /* sometimes pack buffer full, sometimes not */
+ }
while (size - ret >= s);
if (n < TOTAL_MSGS)
{
th_p2 = GNUNET_TRANSPORT_notify_transmit_ready (p2.th,
- &p1.id,
- s, 0, TIMEOUT,
- ¬ify_ready,
- NULL);
+ &p1.id,
+ s, 0, TIMEOUT,
+ ¬ify_ready, NULL);
msg_scheduled = n;
}
else
- {
- 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 (UNRELIABLE_TIMEOUT,
&end_unreliably, NULL);
- }
+ {
+ 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 (UNRELIABLE_TIMEOUT, &end_unreliably,
+ NULL);
+ }
if (n % 5000 == 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Returning total message block of size %u\n",
- ret);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Returning total message block of size %u\n", ret);
+ }
total_bytes += ret;
return ret;
}
@@ -511,14 +501,13 @@
connected--;
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peer `%4s' disconnected (%p)!\n",
- GNUNET_i2s (peer), cls);
+ "Peer `%4s' disconnected (%p)!\n", GNUNET_i2s (peer), cls);
#endif
if (th_p2 != NULL)
- {
- GNUNET_TRANSPORT_notify_transmit_ready_cancel (th_p2);
- th_p2 = NULL;
- }
+ {
+ GNUNET_TRANSPORT_notify_transmit_ready_cancel (th_p2);
+ th_p2 = NULL;
+ }
}
@@ -530,57 +519,57 @@
uint32_t ats_count)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peer `%4s' connected to us (%p)!\n",
- GNUNET_i2s (peer),
- cls);
+ "Peer `%4s' connected to us (%p)!\n", GNUNET_i2s (peer), cls);
if (cls == &p1)
+ {
+ GNUNET_TRANSPORT_set_quota (p1.th,
+ &p2.id,
+ GNUNET_BANDWIDTH_value_init (1024 * 1024 *
+ 1024),
+ GNUNET_BANDWIDTH_value_init (1024 * 1024 *
+ 1024));
+ start_time = GNUNET_TIME_absolute_get ();
+ connected++;
+ }
+ else
+ {
+ GNUNET_TRANSPORT_set_quota (p2.th,
+ &p1.id,
+ GNUNET_BANDWIDTH_value_init (1024 * 1024 *
+ 1024),
+ GNUNET_BANDWIDTH_value_init (1024 * 1024 *
+ 1024));
+ connected++;
+ }
+ if (2 == connected)
+ {
+ if (GNUNET_SCHEDULER_NO_TASK != die_task)
{
- GNUNET_TRANSPORT_set_quota (p1.th,
- &p2.id,
- GNUNET_BANDWIDTH_value_init (1024 * 1024 *
1024),
- GNUNET_BANDWIDTH_value_init (1024 * 1024 *
1024));
- start_time = GNUNET_TIME_absolute_get ();
- connected++;
+ GNUNET_SCHEDULER_cancel (die_task);
}
- else
+ if (GNUNET_SCHEDULER_NO_TASK != tct)
{
- GNUNET_TRANSPORT_set_quota (p2.th,
- &p1.id,
- GNUNET_BANDWIDTH_value_init (1024 * 1024 *
1024),
- GNUNET_BANDWIDTH_value_init (1024 * 1024 *
1024));
- connected++;
+ GNUNET_SCHEDULER_cancel (tct);
+ tct = GNUNET_SCHEDULER_NO_TASK;
}
- if (2 == connected)
+ if (p2_hello_canceled == GNUNET_NO)
{
- if (GNUNET_SCHEDULER_NO_TASK != die_task)
- {
- GNUNET_SCHEDULER_cancel (die_task);
- }
- if (GNUNET_SCHEDULER_NO_TASK != tct)
- {
- GNUNET_SCHEDULER_cancel (tct);
- tct = GNUNET_SCHEDULER_NO_TASK;
- }
- if (p2_hello_canceled == GNUNET_NO)
- {
- GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_last, &p2);
- p2_hello_canceled = GNUNET_YES;
- }
- if (p1_hello_canceled == GNUNET_NO)
- {
- GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, &p1);
- p1_hello_canceled = GNUNET_YES;
- }
-
- die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &end_badly, NULL);
- GNUNET_TRANSPORT_notify_transmit_ready (p2.th,
- &p1.id,
- get_size (0), 0, TIMEOUT,
- ¬ify_ready,
- NULL);
-
+ GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_last, &p2);
+ p2_hello_canceled = GNUNET_YES;
}
+ if (p1_hello_canceled == GNUNET_NO)
+ {
+ GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, &p1);
+ p1_hello_canceled = GNUNET_YES;
+ }
+
+ die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
+ GNUNET_TRANSPORT_notify_transmit_ready (p2.th,
+ &p1.id,
+ get_size (0), 0, TIMEOUT,
+ ¬ify_ready, NULL);
+
+ }
}
@@ -591,31 +580,31 @@
p->cfg = GNUNET_CONFIGURATION_create ();
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_DISK_directory_remove (p->servicehome);
- }
+ 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_DISK_directory_remove (p->servicehome);
+ }
#if START_ARM
p->arm_proc = GNUNET_OS_start_process (NULL, NULL,
- "gnunet-service-arm",
- "gnunet-service-arm",
+ "gnunet-service-arm",
+ "gnunet-service-arm",
#if VERBOSE_ARM
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", cfgname, NULL);
+ "-c", cfgname, NULL);
#endif
p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL,
p,
¬ify_receive,
- ¬ify_connect,
- ¬ify_disconnect);
+ ¬ify_connect, ¬ify_disconnect);
GNUNET_assert (p->th != NULL);
}
@@ -637,32 +626,32 @@
p = getenv ("PATH");
if (p == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("PATH environment variable is unset.\n"));
- return NULL;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("PATH environment variable is unset.\n"));
+ return NULL;
+ }
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)
{
- *end = '\0';
- sprintf (buf, "%s/%s", pos, binary);
- if (GNUNET_DISK_file_test (buf) == GNUNET_YES)
- {
- GNUNET_free (path);
- return buf;
- }
- pos = end + 1;
- }
- sprintf (buf, "%s/%s", pos, binary);
- if (GNUNET_DISK_file_test (buf) == GNUNET_YES)
- {
GNUNET_free (path);
return buf;
}
+ pos = end + 1;
+ }
+ sprintf (buf, "%s/%s", pos, binary);
+ if (GNUNET_DISK_file_test (buf) == GNUNET_YES)
+ {
+ GNUNET_free (path);
+ return buf;
+ }
GNUNET_free (buf);
GNUNET_free (path);
return NULL;
@@ -679,16 +668,18 @@
* can be run properly, GNUNET_NO otherwise
*/
static int
-check_gnunet_nat_binary(char *binary)
+check_gnunet_nat_binary (char *binary)
{
struct stat statbuf;
char *p;
+
#ifdef MINGW
SOCKET rawsock;
#endif
#ifdef MINGW
char *binaryexe;
+
GNUNET_asprintf (&binaryexe, "%s.exe", binary);
p = get_path_from_PATH (binaryexe);
free (binaryexe);
@@ -696,36 +687,34 @@
p = get_path_from_PATH (binary);
#endif
if (p == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Could not find binary `%s' in PATH!\n"),
- binary);
- return GNUNET_NO;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Could not find binary `%s' in PATH!\n"), binary);
+ return GNUNET_NO;
+ }
if (0 != STAT (p, &statbuf))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("stat (%s) failed: %s\n"),
- p,
- STRERROR (errno));
- GNUNET_free (p);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("stat (%s) failed: %s\n"), p, STRERROR (errno));
+ GNUNET_free (p);
+ return GNUNET_SYSERR;
+ }
GNUNET_free (p);
#ifndef MINGW
- if ( (0 != (statbuf.st_mode & S_ISUID)) &&
- (statbuf.st_uid == 0) )
+ if ((0 != (statbuf.st_mode & S_ISUID)) && (statbuf.st_uid == 0))
return GNUNET_YES;
return GNUNET_NO;
#else
rawsock = socket (AF_INET, SOCK_RAW, IPPROTO_ICMP);
if (INVALID_SOCKET == rawsock)
- {
- DWORD err = GetLastError ();
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "socket (AF_INET, SOCK_RAW, IPPROTO_ICMP) have failed! GLE =
%d\n", err);
- return GNUNET_NO; /* not running as administrator */
- }
+ {
+ DWORD err = GetLastError ();
+
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "socket (AF_INET, SOCK_RAW, IPPROTO_ICMP) have failed! GLE =
%d\n",
+ err);
+ return GNUNET_NO; /* not running as administrator */
+ }
closesocket (rawsock);
return GNUNET_YES;
#endif
@@ -733,18 +722,13 @@
static void
-try_connect (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Asking peers to connect...\n");
- GNUNET_TRANSPORT_try_connect (p2.th,
- &p1.id);
- GNUNET_TRANSPORT_try_connect (p1.th,
- &p2.id);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking peers to connect...\n");
+ GNUNET_TRANSPORT_try_connect (p2.th, &p1.id);
+ GNUNET_TRANSPORT_try_connect (p1.th, &p2.id);
tct = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
- &try_connect,
- NULL);
+ &try_connect, NULL);
}
@@ -754,48 +738,46 @@
char *const *args,
const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
- die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &end_badly,
- NULL);
+ die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
if (is_tcp)
- {
- setup_peer (&p1, "test_transport_api_tcp_peer1.conf");
- setup_peer (&p2, "test_transport_api_tcp_peer2.conf");
- }
+ {
+ setup_peer (&p1, "test_transport_api_tcp_peer1.conf");
+ setup_peer (&p2, "test_transport_api_tcp_peer2.conf");
+ }
else if (is_http)
- {
- setup_peer (&p1, "test_transport_api_rel_http_peer1.conf");
- setup_peer (&p2, "test_transport_api_rel_http_peer2.conf");
- }
+ {
+ setup_peer (&p1, "test_transport_api_rel_http_peer1.conf");
+ setup_peer (&p2, "test_transport_api_rel_http_peer2.conf");
+ }
else if (is_https)
- {
- setup_peer (&p1, "test_transport_api_rel_https_peer1.conf");
- setup_peer (&p2, "test_transport_api_rel_https_peer2.conf");
- }
+ {
+ setup_peer (&p1, "test_transport_api_rel_https_peer1.conf");
+ setup_peer (&p2, "test_transport_api_rel_https_peer2.conf");
+ }
else if (is_udp)
- {
- setup_peer (&p1, "test_transport_api_udp_peer1.conf");
- setup_peer (&p2, "test_transport_api_udp_peer2.conf");
- }
+ {
+ setup_peer (&p1, "test_transport_api_udp_peer1.conf");
+ setup_peer (&p2, "test_transport_api_udp_peer2.conf");
+ }
else if (is_unix)
- {
- setup_peer (&p1, "test_transport_api_unix_peer1.conf");
- setup_peer (&p2, "test_transport_api_unix_peer2.conf");
- }
+ {
+ setup_peer (&p1, "test_transport_api_unix_peer1.conf");
+ setup_peer (&p2, "test_transport_api_unix_peer2.conf");
+ }
else if (is_tcp_nat)
- {
- setup_peer (&p1, "test_transport_api_tcp_nat_peer1.conf");
- setup_peer (&p2, "test_transport_api_tcp_nat_peer2.conf");
- }
+ {
+ setup_peer (&p1, "test_transport_api_tcp_nat_peer1.conf");
+ setup_peer (&p2, "test_transport_api_tcp_nat_peer2.conf");
+ }
else if (is_wlan)
- {
- setup_peer (&p1, "test_transport_api_wlan_peer1.conf");
- setup_peer (&p2, "test_transport_api_wlan_peer2.conf");
- }
+ {
+ setup_peer (&p1, "test_transport_api_wlan_peer1.conf");
+ setup_peer (&p2, "test_transport_api_wlan_peer2.conf");
+ }
else
GNUNET_assert (0);
- GNUNET_assert(p1.th != NULL);
- GNUNET_assert(p2.th != NULL);
+ GNUNET_assert (p1.th != NULL);
+ GNUNET_assert (p2.th != NULL);
GNUNET_TRANSPORT_get_hello (p1.th, &exchange_hello, &p1);
p1_hello_canceled = GNUNET_NO;
GNUNET_TRANSPORT_get_hello (p2.th, &exchange_hello_last, &p2);
@@ -820,15 +802,17 @@
};
#if WRITECONFIG
- setTransportOptions("test_transport_api_data.conf");
+ setTransportOptions ("test_transport_api_data.conf");
#endif
ok = 1;
- if ((GNUNET_YES == is_tcp_nat) &&
(check_gnunet_nat_binary("gnunet-nat-server") != GNUNET_YES))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Not running NAT test case,
binaries not properly installed.\n");
- return 0;
- }
+ if ((GNUNET_YES == is_tcp_nat) &&
+ (check_gnunet_nat_binary ("gnunet-nat-server") != GNUNET_YES))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Not running NAT test case, binaries not properly
installed.\n");
+ return 0;
+ }
GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
argv, "test-transport-api-unreliability", "nohelp",
@@ -839,53 +823,66 @@
if (is_https)
{
struct stat sbuf;
- if (0 == stat (cert_file_p1, &sbuf ))
+
+ if (0 == stat (cert_file_p1, &sbuf))
{
- if (0 == remove(cert_file_p1))
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully removed existing
certificate file `%s'\n",cert_file_p1);
+ if (0 == remove (cert_file_p1))
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Successfully removed existing certificate file `%s'\n",
+ cert_file_p1);
else
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to remove certfile
`%s'\n",cert_file_p1);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to remove certfile
`%s'\n",
+ cert_file_p1);
}
- if (0 == stat (key_file_p1, &sbuf ))
+ if (0 == stat (key_file_p1, &sbuf))
{
- if (0 == remove(key_file_p1))
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully removed private key
file `%s'\n",key_file_p1);
+ if (0 == remove (key_file_p1))
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Successfully removed private key file `%s'\n",
+ key_file_p1);
else
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to private key file
`%s'\n",key_file_p1);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to private key file `%s'\n", key_file_p1);
}
- if (0 == stat (cert_file_p2, &sbuf ))
+ if (0 == stat (cert_file_p2, &sbuf))
{
- if (0 == remove(cert_file_p2))
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully removed existing
certificate file `%s'\n",cert_file_p2);
+ if (0 == remove (cert_file_p2))
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Successfully removed existing certificate file `%s'\n",
+ cert_file_p2);
else
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to remove certfile
`%s'\n",cert_file_p2);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to remove certfile
`%s'\n",
+ cert_file_p2);
}
- if (0 == stat (key_file_p2, &sbuf ))
+ if (0 == stat (key_file_p2, &sbuf))
{
- if (0 == remove(key_file_p2))
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully removed private key
file `%s'\n",key_file_p2);
+ if (0 == remove (key_file_p2))
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Successfully removed private key file `%s'\n",
+ key_file_p2);
else
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to private key file
`%s'\n",key_file_p2);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to private key file `%s'\n", key_file_p2);
}
- GNUNET_free(key_file_p1);
- GNUNET_free(key_file_p2);
- GNUNET_free(cert_file_p1);
- GNUNET_free(cert_file_p2);
+ GNUNET_free (key_file_p1);
+ GNUNET_free (key_file_p2);
+ GNUNET_free (cert_file_p1);
+ GNUNET_free (cert_file_p2);
}
- if (p1.servicehome != NULL)
- {
- GNUNET_DISK_directory_remove (p1.servicehome);
- GNUNET_free(p1.servicehome);
- }
+ if (p1.servicehome != NULL)
+ {
+ GNUNET_DISK_directory_remove (p1.servicehome);
+ GNUNET_free (p1.servicehome);
+ }
if (p2.servicehome != NULL)
- {
- GNUNET_DISK_directory_remove (p2.servicehome);
- GNUNET_free(p2.servicehome);
- }
+ {
+ GNUNET_DISK_directory_remove (p2.servicehome);
+ GNUNET_free (p2.servicehome);
+ }
return ok;
}
@@ -900,40 +897,40 @@
GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-transport-peer-1");
GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-transport-peer-2");
- if (strstr(argv[0], "tcp_nat") != NULL)
- {
- is_tcp_nat = GNUNET_YES;
- GNUNET_asprintf(&test_name, "tcp_nat");
- }
- else if (strstr(argv[0], "tcp") != NULL)
- {
- is_tcp = GNUNET_YES;
- GNUNET_asprintf(&test_name, "tcp");
- }
- else if (strstr(argv[0], "https") != NULL)
- {
- is_https = GNUNET_YES;
- GNUNET_asprintf(&test_name, "https");
- }
- else if (strstr(argv[0], "http") != NULL)
- {
- is_http = GNUNET_YES;
- GNUNET_asprintf(&test_name, "http");
- }
- else if (strstr(argv[0], "udp") != NULL)
- {
- is_udp = GNUNET_YES;
- GNUNET_asprintf(&test_name, "udp");
- }
- else if (strstr(argv[0], "unix") != NULL)
- {
- is_unix = GNUNET_YES;
- GNUNET_asprintf(&test_name, "unix");
- }
- else if (strstr(argv[0], "wlan") != NULL)
- {
- is_wlan = GNUNET_YES;
- }
+ if (strstr (argv[0], "tcp_nat") != NULL)
+ {
+ is_tcp_nat = GNUNET_YES;
+ GNUNET_asprintf (&test_name, "tcp_nat");
+ }
+ else if (strstr (argv[0], "tcp") != NULL)
+ {
+ is_tcp = GNUNET_YES;
+ GNUNET_asprintf (&test_name, "tcp");
+ }
+ else if (strstr (argv[0], "https") != NULL)
+ {
+ is_https = GNUNET_YES;
+ GNUNET_asprintf (&test_name, "https");
+ }
+ else if (strstr (argv[0], "http") != NULL)
+ {
+ is_http = GNUNET_YES;
+ GNUNET_asprintf (&test_name, "http");
+ }
+ else if (strstr (argv[0], "udp") != NULL)
+ {
+ is_udp = GNUNET_YES;
+ GNUNET_asprintf (&test_name, "udp");
+ }
+ else if (strstr (argv[0], "unix") != NULL)
+ {
+ is_unix = GNUNET_YES;
+ GNUNET_asprintf (&test_name, "unix");
+ }
+ else if (strstr (argv[0], "wlan") != NULL)
+ {
+ is_wlan = GNUNET_YES;
+ }
GNUNET_log_setup ("test-transport-api-unreliability",
#if VERBOSE
"DEBUG",
@@ -943,7 +940,7 @@
NULL);
ret = check ();
- GNUNET_free_non_null(test_name);
+ GNUNET_free_non_null (test_name);
return ret;
}
Modified: gnunet/src/transport/test_transport_ats.c
===================================================================
--- gnunet/src/transport/test_transport_ats.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/transport/test_transport_ats.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -28,18 +28,17 @@
#define VERBOSE GNUNET_YES
-static struct ATS_Handle * ats;
+static struct ATS_Handle *ats;
-static struct GNUNET_CONFIGURATION_Handle * cfg;
+static struct GNUNET_CONFIGURATION_Handle *cfg;
static struct TransportConfiguration *tc;
-static void
+static void
ats_result_cb ()
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "ATS Result callback\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS Result callback\n");
}
struct TransportConfiguration
@@ -47,35 +46,35 @@
int peers;
int mechanisms;
- struct ATS_peer * p_head;
- struct ATS_peer * p_tail;
+ struct ATS_peer *p_head;
+ struct ATS_peer *p_tail;
- struct ATS_mechanism * m_head;
- struct ATS_mechanism * m_tail;
+ struct ATS_mechanism *m_head;
+ struct ATS_mechanism *m_tail;
};
-static void
-create_ats_information (struct ATS_peer **p, int * c_p,
- struct ATS_mechanism ** m, int * c_m)
-{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "ATS needs addresses\n");
+static void
+create_ats_information (struct ATS_peer **p, int *c_p,
+ struct ATS_mechanism **m, int *c_m)
+{
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS needs addresses\n");
- (*p) = tc->p_head;
- (*c_p) = tc->mechanisms;
- (*m) = tc->m_head;
- (*c_m) = tc->mechanisms;
+ (*p) = tc->p_head;
+ (*c_p) = tc->mechanisms;
+ (*m) = tc->m_head;
+ (*c_m) = tc->mechanisms;
}
-static
-int run_ats ()
+static int
+run_ats ()
{
int ret = 0;
+
ats_calculate_bandwidth_distribution (ats);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Running ATS: %s \n", (ret==0)? "SUCCESSFUL": "FAILED");
+ "Running ATS: %s \n", (ret == 0) ? "SUCCESSFUL" : "FAILED");
return ret;
}
@@ -84,96 +83,96 @@
init_ats ()
{
int ret = 0;
- ats = ats_init(1.0, 1.0, 1.0, 50000, 5, 10, ATS_MAX_EXEC_DURATION,
- create_ats_information,
- ats_result_cb);
+
+ ats = ats_init (1.0, 1.0, 1.0, 50000, 5, 10, ATS_MAX_EXEC_DURATION,
+ create_ats_information, ats_result_cb);
//GNUNET_assert (ats != NULL);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Initializing ATS: %s \n", (ret==0)? "SUCCESSFUL": "FAILED");
+ "Initializing ATS: %s \n", (ret == 0) ? "SUCCESSFUL" : "FAILED");
return ret;
}
-static int
+static int
shutdown_ats ()
{
int ret = 0;
+
ats_delete_problem (ats);
ats_shutdown (ats);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Shutdown ATS: %s \n", (ret==0)? "SUCCESSFUL": "FAILED");
+ "Shutdown ATS: %s \n", (ret == 0) ? "SUCCESSFUL" : "FAILED");
return ret;
}
/* To make compiler happy */
-void
-dummy()
+void
+dummy ()
{
- struct ATS_quality_metric * q = qm;
+ struct ATS_quality_metric *q = qm;
+
q = NULL;
- struct ATS_ressource * r = ressources;
+ struct ATS_ressource *r = ressources;
+
r = NULL;
- q++;
+ q++;
r++;
}
-static void
+static void
iterate_peer_values (void *cls,
- const char *section,
- const char *option,
- const char *value)
+ const char *section, const char *option, const char
*value)
{
if (strcmp (option, "f") == 0)
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "\t %s %s\n", option, value);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "\t %s %s\n", option, value);
}
static void
iterate_mech_values (void *cls,
- const char *section,
- const char *option,
- const char *value)
+ const char *section, const char *option, const char
*value)
{
if (strcmp (option, "f") == 0)
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "\t %s %s\n", option, value);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "\t %s %s\n", option, value);
}
-static void
-iterate_sections (void *cls,
- const char *section)
+static void
+iterate_sections (void *cls, const char *section)
{
- struct TransportConfiguration * tc = cls;
+ struct TransportConfiguration *tc = cls;
+
/* Peer definition */
- if (99 == strlen(section))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Peer '%s`\n", section);
- GNUNET_HashCode h;
- int res =GNUNET_CRYPTO_hash_from_string(section, &h);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "HASH '%s` %i\n", GNUNET_h2s (&h),
res);
- GNUNET_CONFIGURATION_iterate_section_values(cfg, section,
iterate_peer_values, NULL);
- tc->peers++;
- }
- if (10 == strlen(section))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Mechanism '%s`\n",section);
- GNUNET_CONFIGURATION_iterate_section_values(cfg, section,
iterate_mech_values, NULL);
- tc->peers++;
- }
+ if (99 == strlen (section))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Peer '%s`\n", section);
+ GNUNET_HashCode h;
+ int res = GNUNET_CRYPTO_hash_from_string (section, &h);
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "HASH '%s` %i\n", GNUNET_h2s (&h),
res);
+ GNUNET_CONFIGURATION_iterate_section_values (cfg, section,
+ iterate_peer_values, NULL);
+ tc->peers++;
+ }
+ if (10 == strlen (section))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Mechanism '%s`\n", section);
+ GNUNET_CONFIGURATION_iterate_section_values (cfg, section,
+ iterate_mech_values, NULL);
+ tc->peers++;
+ }
}
-static struct TransportConfiguration *
-load_transport_configuration (char * filename)
+static struct TransportConfiguration *
+load_transport_configuration (char *filename)
{
- struct TransportConfiguration * ret = GNUNET_malloc(sizeof (struct
TransportConfiguration));
+ struct TransportConfiguration *ret =
+ GNUNET_malloc (sizeof (struct TransportConfiguration));
- cfg = GNUNET_CONFIGURATION_create();
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_load(cfg, filename));
+ cfg = GNUNET_CONFIGURATION_create ();
+ GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (cfg, filename));
GNUNET_CONFIGURATION_iterate_sections (cfg, iterate_sections, ret);
GNUNET_CONFIGURATION_destroy (cfg);
cfg = NULL;
Modified: gnunet/src/transport/test_transport_ats_multiple_peers.c
===================================================================
--- gnunet/src/transport/test_transport_ats_multiple_peers.c 2011-08-15
21:40:08 UTC (rev 16580)
+++ gnunet/src/transport/test_transport_ats_multiple_peers.c 2011-08-15
21:46:35 UTC (rev 16581)
@@ -46,17 +46,17 @@
static int failed_peers;
static int measurement_started = GNUNET_NO;
-static char * config_file;
+static char *config_file;
static struct GNUNET_TESTING_PeerGroup *pg;
static GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
static GNUNET_SCHEDULER_TaskIdentifier stats_task;
static GNUNET_SCHEDULER_TaskIdentifier send_task;
-struct GNUNET_TESTING_Daemon * master_deamon;
-struct GNUNET_TESTING_Daemon * ping_deamon;
+struct GNUNET_TESTING_Daemon *master_deamon;
+struct GNUNET_TESTING_Daemon *ping_deamon;
-struct GNUNET_STATISTICS_Handle * stats;
+struct GNUNET_STATISTICS_Handle *stats;
struct TEST_result
{
@@ -87,21 +87,21 @@
static int send_msg;
static int machine_parsable;
-static struct TEST_result results_new [MEASUREMENTS+1];
-static struct TEST_result results_modified [MEASUREMENTS+1];
-static struct TEST_result results_unmodified[MEASUREMENTS+1];
+static struct TEST_result results_new[MEASUREMENTS + 1];
+static struct TEST_result results_modified[MEASUREMENTS + 1];
+static struct TEST_result results_unmodified[MEASUREMENTS + 1];
static struct TEST_result current;
-static struct GNUNET_STATISTICS_GetHandle * s_solution;
-static struct GNUNET_STATISTICS_GetHandle * s_time;
-static struct GNUNET_STATISTICS_GetHandle * s_peers;
-static struct GNUNET_STATISTICS_GetHandle * s_mechs;
-static struct GNUNET_STATISTICS_GetHandle * s_duration;
-static struct GNUNET_STATISTICS_GetHandle * s_invalid;
-static struct GNUNET_STATISTICS_GetHandle * s_state;
+static struct GNUNET_STATISTICS_GetHandle *s_solution;
+static struct GNUNET_STATISTICS_GetHandle *s_time;
+static struct GNUNET_STATISTICS_GetHandle *s_peers;
+static struct GNUNET_STATISTICS_GetHandle *s_mechs;
+static struct GNUNET_STATISTICS_GetHandle *s_duration;
+static struct GNUNET_STATISTICS_GetHandle *s_invalid;
+static struct GNUNET_STATISTICS_GetHandle *s_state;
-struct GNUNET_TRANSPORT_TransmitHandle * t;
-struct GNUNET_TRANSPORT_Handle * th;
+struct GNUNET_TRANSPORT_TransmitHandle *t;
+struct GNUNET_TRANSPORT_Handle *th;
/**
* Check whether peers successfully shut down.
@@ -110,463 +110,459 @@
shutdown_callback (void *cls, const char *emsg)
{
if (emsg != NULL)
- {
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Shutdown of peers failed!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n");
#endif
- if (ok == 0)
- ok = 666;
- }
+ if (ok == 0)
+ ok = 666;
+ }
else
- {
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "All peers successfully shut down!\n");
- if (stats != NULL)
- GNUNET_STATISTICS_destroy(stats, GNUNET_NO);
- stats = NULL;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers successfully shut
down!\n");
+ if (stats != NULL)
+ GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
+ stats = NULL;
#endif
- }
+ }
}
static void
-shutdown_peers()
+shutdown_peers ()
{
if (shutdown_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel(shutdown_task);
- shutdown_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (shutdown_task);
+ shutdown_task = GNUNET_SCHEDULER_NO_TASK;
+ }
if (stats_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel(stats_task);
- stats_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (stats_task);
+ stats_task = GNUNET_SCHEDULER_NO_TASK;
+ }
if (send_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel(send_task);
- send_task = GNUNET_SCHEDULER_NO_TASK;
- }
-
+ {
+ GNUNET_SCHEDULER_cancel (send_task);
+ send_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+
if (t != NULL)
- {
- GNUNET_TRANSPORT_notify_transmit_ready_cancel(t);
- t = NULL;
- }
- GNUNET_TRANSPORT_disconnect(th);
+ {
+ GNUNET_TRANSPORT_notify_transmit_ready_cancel (t);
+ t = NULL;
+ }
+ GNUNET_TRANSPORT_disconnect (th);
if (s_time != NULL)
- {
- GNUNET_STATISTICS_get_cancel(s_time);
- s_time = NULL;
- }
+ {
+ GNUNET_STATISTICS_get_cancel (s_time);
+ s_time = NULL;
+ }
if (s_peers != NULL)
- {
- GNUNET_STATISTICS_get_cancel(s_peers);
- s_peers = NULL;
- }
+ {
+ GNUNET_STATISTICS_get_cancel (s_peers);
+ s_peers = NULL;
+ }
if (s_mechs != NULL)
- {
- GNUNET_STATISTICS_get_cancel(s_mechs);
- s_mechs = NULL;
- }
+ {
+ GNUNET_STATISTICS_get_cancel (s_mechs);
+ s_mechs = NULL;
+ }
if (s_solution != NULL)
- {
- GNUNET_STATISTICS_get_cancel(s_solution);
- s_solution = NULL;
- }
+ {
+ GNUNET_STATISTICS_get_cancel (s_solution);
+ s_solution = NULL;
+ }
if (s_duration != NULL)
- {
- GNUNET_STATISTICS_get_cancel(s_duration);
- s_duration = NULL;
- }
+ {
+ GNUNET_STATISTICS_get_cancel (s_duration);
+ s_duration = NULL;
+ }
if (s_invalid != NULL)
- {
- GNUNET_STATISTICS_get_cancel(s_invalid);
- s_invalid = NULL;
- }
+ {
+ GNUNET_STATISTICS_get_cancel (s_invalid);
+ s_invalid = NULL;
+ }
if (s_state != NULL)
- {
- GNUNET_STATISTICS_get_cancel(s_state);
- s_state = NULL;
- }
+ {
+ GNUNET_STATISTICS_get_cancel (s_state);
+ s_state = NULL;
+ }
GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
}
-static void
-evaluate_measurements()
+static void
+evaluate_measurements ()
{
int c;
+
//int mechs = 0;
double average[3];
double stddev[3];
+
//char * output;
c = 1;
-
+
//GNUNET_asprintf(&output, "p,%i,m,%i,",peers, MEASUREMENTS,
results_modified[0].mechs,
-
+
average[0] = 0.0;
- for (c=0; c<c_new;c++)
- {
- average[0] += (double) results_new[c].duration;
- }
+ for (c = 0; c < c_new; c++)
+ {
+ average[0] += (double) results_new[c].duration;
+ }
average[0] /= c_new;
-
+
stddev[0] = 0.0;
- for (c=0; c<c_new;c++)
- {
- stddev[0] += (results_new[c].duration - average[0]) *
- (results_new[c].duration - average[0]);
- }
+ for (c = 0; c < c_new; c++)
+ {
+ stddev[0] += (results_new[c].duration - average[0]) *
+ (results_new[c].duration - average[0]);
+ }
stddev[0] /= c_new;
stddev[0] = sqrt (stddev[0]);
if (!machine_parsable)
fprintf (stderr,
- "new, %i measurements, average: %f stddev: %f\n",
- c_new, average[0], stddev[0]);
-
+ "new, %i measurements, average: %f stddev: %f\n",
+ c_new, average[0], stddev[0]);
+
average[1] = 0.0;
- for (c=0; c<c_modified;c++)
- {
- average[1] += (double) results_modified[c].duration;
- }
+ for (c = 0; c < c_modified; c++)
+ {
+ average[1] += (double) results_modified[c].duration;
+ }
average[1] /= c_modified;
-
+
stddev[1] = 0.0;
- for (c=0; c<c_modified;c++)
- {
- stddev[1] += (results_modified[c].duration - average[1]) *
- (results_modified[c].duration - average[1]);
- }
+ for (c = 0; c < c_modified; c++)
+ {
+ stddev[1] += (results_modified[c].duration - average[1]) *
+ (results_modified[c].duration - average[1]);
+ }
stddev[1] /= c_modified;
stddev[1] = sqrt (stddev[1]);
- if (!machine_parsable)
+ if (!machine_parsable)
fprintf (stderr,
- "modified, %i measurements, average: %f stddev: %f\n",
- c_modified, average[1], stddev[1]);
-
+ "modified, %i measurements, average: %f stddev: %f\n",
+ c_modified, average[1], stddev[1]);
+
average[2] = 0.0;
- for (c=0; c<c_unmodified;c++)
- {
- average[2] += (double) results_unmodified[c].duration;
- }
+ for (c = 0; c < c_unmodified; c++)
+ {
+ average[2] += (double) results_unmodified[c].duration;
+ }
average[2] /= c_unmodified;
stddev[2] = 0.0;
- for (c=0; c<c_unmodified;c++)
- {
- stddev[2] += (results_unmodified[c].duration - average[2]) *
- (results_unmodified[c].duration - average[2]);
- }
+ for (c = 0; c < c_unmodified; c++)
+ {
+ stddev[2] += (results_unmodified[c].duration - average[2]) *
+ (results_unmodified[c].duration - average[2]);
+ }
stddev[2] /= c_unmodified;
stddev[2] = sqrt (stddev[2]);
-
- if (!machine_parsable)
+
+ if (!machine_parsable)
fprintf (stderr,
- "unmodified, %i measurements, average: %f stddev: %f\n",
- c_unmodified, average[2], stddev[2]);
-
+ "unmodified, %i measurements, average: %f stddev: %f\n",
+ c_unmodified, average[2], stddev[2]);
+
if (machine_parsable)
fprintf (stderr,
- "peers,%i,mechs,%llu,"
- "new,%i,%f,%f,"
- "mod,%i,%f,%f,"
- "unmod,%i,%f,%f\n",
- peers-1, (unsigned long long) results_unmodified[0].mechs,
- c_new, average[0], stddev[0],
- c_modified, average[1], stddev[1],
- c_unmodified, average[2], stddev[2]);
- shutdown_peers();
+ "peers,%i,mechs,%llu,"
+ "new,%i,%f,%f,"
+ "mod,%i,%f,%f,"
+ "unmod,%i,%f,%f\n",
+ peers - 1, (unsigned long long) results_unmodified[0].mechs,
+ c_new, average[0], stddev[0],
+ c_modified, average[1], stddev[1],
+ c_unmodified, average[2], stddev[2]);
+ shutdown_peers ();
}
-static int
+static int
stats_cb (void *cls,
- const char *subsystem,
- const char *name,
- uint64_t value,
- int is_persistent)
+ const char *subsystem,
+ const char *name, uint64_t value, int is_persistent)
{
static int printed = GNUNET_NO;
+
#if VERBOSE_ATS
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s = %llu\n", name ,value);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s = %llu\n", name, value);
#endif
- if (0 == strcmp (name,"ATS invalid solutions"))
+ if (0 == strcmp (name, "ATS invalid solutions"))
+ {
+ if (stats_task != GNUNET_SCHEDULER_NO_TASK)
{
- if (stats_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel(stats_task);
- stats_task = GNUNET_SCHEDULER_NO_TASK;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"MLP produced invalid %llu
result(s)!\n",
- value);
- shutdown_peers();
- return GNUNET_SYSERR;
+ GNUNET_SCHEDULER_cancel (stats_task);
+ stats_task = GNUNET_SCHEDULER_NO_TASK;
}
-
- if (0 == strcmp (name,"ATS solution"))
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "MLP produced invalid %llu result(s)!\n", value);
+ shutdown_peers ();
+ return GNUNET_SYSERR;
+ }
+
+ if (0 == strcmp (name, "ATS solution"))
+ {
+ s_solution = NULL;
+ }
+
+ if (0 == strcmp (name, "ATS peers"))
+ {
+ s_peers = NULL;
+ }
+
+ if (0 == strcmp (name, "ATS mechanisms"))
+ {
+ s_mechs = NULL;
+ }
+
+ if (0 == strcmp (name, "ATS duration"))
+ {
+ s_duration = NULL;
+ }
+ if (0 == strcmp (name, "ATS timestamp"))
+ {
+ s_time = NULL;
+ }
+ if (0 == strcmp (name, "ATS state"))
+ {
+ s_state = NULL;
+ }
+
+ if ((measurement_started == GNUNET_NO) &&
+ (0 == strcmp (name, "ATS peers")) && (value == peers - 1))
+ {
+ measurement_started = GNUNET_YES;
+ count = 1;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All %llu peers connected\n", value);
+#if !VERBOSE
+ if (!machine_parsable)
+ fprintf (stderr, "%i", count);
+#endif
+ }
+
+ if (measurement_started == GNUNET_YES)
+ {
+ // GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s == %llu\n", name ,value);
+ if (0 == strcmp (name, "ATS timestamp"))
{
- s_solution = NULL;
+ if (current.timestamp == 0)
+ {
+ printed = GNUNET_NO;
+ current.timestamp = value;
+ }
+ if (current.timestamp == value)
+ {
+ printed = GNUNET_YES;
+ }
+ if (current.timestamp != value)
+ {
+ if (current.state == ATS_NEW)
+ {
+ if (c_new < MEASUREMENTS)
+ {
+ results_new[c_new] = current;
+ c_new++;
+ }
+ else
+ {
+ force_rebuild = GNUNET_NO;
+ force_q_updates = GNUNET_NO;
+ send_msg = GNUNET_NO;
+ }
+ }
+ if (current.state == ATS_UNMODIFIED)
+ {
+ if (c_unmodified < MEASUREMENTS)
+ {
+ results_unmodified[c_unmodified] = current;
+ c_unmodified++;
+ }
+
+ }
+ if (current.state == ATS_QUALITY_UPDATED)
+ {
+ if (c_modified < MEASUREMENTS)
+ {
+ results_modified[c_modified] = current;
+ c_modified++;
+ }
+ else
+ {
+ force_q_updates = GNUNET_NO;
+ force_rebuild = GNUNET_YES;
+ }
+ }
+ count++;
+#if VERBOSE
+ fprintf (stderr,
+ "(new: %i / modified: %i / unmodified: %i) of %i \n",
+ c_new, c_modified, c_unmodified, MEASUREMENTS);
+#endif
+ if ((c_modified >= MEASUREMENTS) &&
+ (c_new >= MEASUREMENTS) && (c_unmodified >= MEASUREMENTS))
+ {
+#if !VERBOSE
+ if (!machine_parsable)
+ fprintf (stdout, "\n");
+#endif
+ if (stats_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (stats_task);
+ stats_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ evaluate_measurements ();
+ return GNUNET_SYSERR;
+ }
+
+ printed = GNUNET_NO;
+ current.timestamp = value;
+#if !VERBOSE
+ if (!machine_parsable)
+ fprintf (stderr, "..%i", count);
+#endif
+ return GNUNET_OK;
+ }
}
-
- if (0 == strcmp (name,"ATS peers"))
+
+ if (0 == strcmp (name, "ATS solution"))
{
- s_peers = NULL;
+ current.solution = value;
+ if (printed == GNUNET_NO)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "[%i] %s: %llu \n",
+ count, name, value);
}
-
- if (0 == strcmp (name,"ATS mechanisms"))
+
+ if (0 == strcmp (name, "ATS peers"))
{
- s_mechs = NULL;
+ current.peers = value;
+ if (printed == GNUNET_NO)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "[%i] %s: %llu \n",
+ count, name, value);
}
-
- if (0 == strcmp (name,"ATS duration"))
+
+ if (0 == strcmp (name, "ATS mechanisms"))
{
- s_duration = NULL;
+ current.mechs = value;
+ if (printed == GNUNET_NO)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "[%i] %s: %llu \n",
+ count, name, value);
}
- if (0 == strcmp (name,"ATS timestamp"))
+
+ if (0 == strcmp (name, "ATS duration"))
{
- s_time = NULL;
+ current.duration = value;
+ if (printed == GNUNET_NO)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "[%i] %s: %llu \n",
+ count, name, value);
}
- if (0 == strcmp (name,"ATS state"))
+ if (0 == strcmp (name, "ATS state"))
{
- s_state = NULL;
+ current.state = value;
+ const char *cont;
+
+ switch (value)
+ {
+ case ATS_NEW:
+ cont = "NEW";
+ break;
+ case ATS_COST_UPDATED:
+ cont = "C_UPDATED";
+ break;
+ case ATS_QUALITY_UPDATED:
+ cont = "Q_UPDATED";
+ break;
+ case ATS_QUALITY_COST_UPDATED:
+ cont = "QC_UPDATED";
+ break;
+ case ATS_UNMODIFIED:
+ cont = "UNMODIFIED";
+ break;
+ default:
+ GNUNET_break (0);
+ cont = "<undefined>";
+ break;
+ }
+ if (printed == GNUNET_NO)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "[%i] ATS state: %s\n", count, cont);
}
-
- if ( (measurement_started == GNUNET_NO) &&
- (0 == strcmp (name, "ATS peers")) &&
- (value == peers-1) )
- {
- measurement_started = GNUNET_YES;
- count = 1;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "All %llu peers connected\n",
- value);
-#if !VERBOSE
- if (! machine_parsable)
- fprintf(stderr, "%i", count);
-#endif
- }
-
- if (measurement_started == GNUNET_YES)
- {
- // GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s == %llu\n", name ,value);
- if (0 == strcmp (name,"ATS timestamp"))
- {
- if (current.timestamp == 0)
- {
- printed = GNUNET_NO;
- current.timestamp = value;
- }
- if (current.timestamp == value)
- {
- printed = GNUNET_YES;
- }
- if (current.timestamp != value)
- {
- if (current.state == ATS_NEW)
- {
- if (c_new < MEASUREMENTS)
- {
- results_new[c_new] = current;
- c_new++;
- }
- else
- {
- force_rebuild = GNUNET_NO;
- force_q_updates = GNUNET_NO;
- send_msg = GNUNET_NO;
- }
- }
- if (current.state == ATS_UNMODIFIED)
- {
- if (c_unmodified < MEASUREMENTS)
- {
- results_unmodified[c_unmodified] = current;
- c_unmodified++;
- }
-
- }
- if (current.state == ATS_QUALITY_UPDATED)
- {
- if (c_modified < MEASUREMENTS)
- {
- results_modified[c_modified] = current;
- c_modified++;
- }
- else
- {
- force_q_updates = GNUNET_NO;
- force_rebuild = GNUNET_YES;
- }
- }
- count ++;
-#if VERBOSE
- fprintf (stderr,
- "(new: %i / modified: %i / unmodified: %i) of %i \n",
- c_new, c_modified, c_unmodified , MEASUREMENTS);
-#endif
- if ((c_modified >= MEASUREMENTS) &&
- (c_new >= MEASUREMENTS) &&
- (c_unmodified >= MEASUREMENTS))
- {
-#if !VERBOSE
- if (!machine_parsable)
- fprintf(stdout, "\n");
-#endif
- if (stats_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel(stats_task);
- stats_task = GNUNET_SCHEDULER_NO_TASK;
- }
- evaluate_measurements();
- return GNUNET_SYSERR;
- }
-
- printed = GNUNET_NO;
- current.timestamp = value;
-#if !VERBOSE
- if (! machine_parsable)
- fprintf(stderr, "..%i", count);
-#endif
- return GNUNET_OK;
- }
- }
-
- if (0 == strcmp (name,"ATS solution"))
- {
- current.solution = value;
- if (printed == GNUNET_NO)
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "[%i] %s: %llu \n",
- count, name, value);
- }
-
- if (0 == strcmp (name,"ATS peers"))
- {
- current.peers = value;
- if (printed == GNUNET_NO)
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "[%i] %s: %llu \n",
- count, name, value);
- }
-
- if (0 == strcmp (name,"ATS mechanisms"))
- {
- current.mechs = value;
- if (printed == GNUNET_NO)
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "[%i] %s: %llu \n",
- count, name, value);
- }
-
- if (0 == strcmp (name,"ATS duration"))
- {
- current.duration = value;
- if (printed == GNUNET_NO)
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "[%i] %s: %llu \n",
- count, name, value);
- }
- if (0 == strcmp (name,"ATS state"))
- {
- current.state = value;
- const char * cont;
- switch (value)
- {
- case ATS_NEW:
- cont = "NEW";
- break;
- case ATS_COST_UPDATED:
- cont = "C_UPDATED";
- break;
- case ATS_QUALITY_UPDATED:
- cont = "Q_UPDATED";
- break;
- case ATS_QUALITY_COST_UPDATED:
- cont = "QC_UPDATED";
- break;
- case ATS_UNMODIFIED:
- cont = "UNMODIFIED";
- break;
- default:
- GNUNET_break (0);
- cont = "<undefined>";
- break;
- }
- if (printed == GNUNET_NO)
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "[%i] ATS state: %s\n",
- count,
- cont);
- }
- }
+ }
return GNUNET_OK;
}
static void
-stats_get_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+stats_get_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
stats_task = GNUNET_SCHEDULER_NO_TASK;
- if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
+ if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
return;
-
+
s_time = GNUNET_STATISTICS_get (stats, "transport", "ATS timestamp",
- TIMEOUT, NULL, &stats_cb, NULL);
+ TIMEOUT, NULL, &stats_cb, NULL);
s_solution = GNUNET_STATISTICS_get (stats, "transport", "ATS solution",
- TIMEOUT, NULL, &stats_cb, NULL);
- s_duration = GNUNET_STATISTICS_get (stats, "transport","ATS duration",
- TIMEOUT, NULL, &stats_cb, NULL);
+ TIMEOUT, NULL, &stats_cb, NULL);
+ s_duration = GNUNET_STATISTICS_get (stats, "transport", "ATS duration",
+ TIMEOUT, NULL, &stats_cb, NULL);
s_peers = GNUNET_STATISTICS_get (stats, "transport", "ATS peers",
- TIMEOUT, NULL, &stats_cb, NULL);
+ TIMEOUT, NULL, &stats_cb, NULL);
s_mechs = GNUNET_STATISTICS_get (stats, "transport", "ATS mechanisms",
- TIMEOUT, NULL, &stats_cb, NULL);
- s_invalid = GNUNET_STATISTICS_get (stats, "transport", "ATS invalid
solutions",
- TIMEOUT, NULL, &stats_cb, NULL);
- s_state = GNUNET_STATISTICS_get (stats, "transport", "ATS state",
- TIMEOUT, NULL, &stats_cb, NULL);
-
- stats_task = GNUNET_SCHEDULER_add_delayed(
- GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 100),
- &stats_get_task,
- NULL);
+ TIMEOUT, NULL, &stats_cb, NULL);
+ s_invalid =
+ GNUNET_STATISTICS_get (stats, "transport", "ATS invalid solutions",
+ TIMEOUT, NULL, &stats_cb, NULL);
+ s_state =
+ GNUNET_STATISTICS_get (stats, "transport", "ATS state", TIMEOUT, NULL,
+ &stats_cb, NULL);
+
+ stats_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MILLISECONDS, 100),
+ &stats_get_task, NULL);
}
static void
-delay (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+delay (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
shutdown_task = GNUNET_SCHEDULER_NO_TASK;
- if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
+ if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
return;
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Delay over\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Delay over\n");
#endif
shutdown_peers ();
}
static void
-connect_peers()
+connect_peers ()
{
- shutdown_task = GNUNET_SCHEDULER_add_delayed(DELAY, &delay, NULL);
+ shutdown_task = GNUNET_SCHEDULER_add_delayed (DELAY, &delay, NULL);
}
/* To make compiler happy */
-void dummy(void)
+void
+dummy (void)
{
- struct ATS_quality_metric * q = qm;
+ struct ATS_quality_metric *q = qm;
+
q = NULL;
q++;
- struct ATS_ressource * r = ressources;
+ struct ATS_ressource *r = ressources;
+
r = NULL;
r++;
}
-static size_t
+static size_t
send_dummy_data_task (void *cls, size_t size, void *buf)
{
int s = sizeof (struct TestMessage);
struct TestMessage hdr;
-
+
hdr.header.size = htons (s);
hdr.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ATS);
if (force_rebuild)
@@ -574,7 +570,7 @@
else if (force_q_updates)
hdr.num = htonl (2);
else
- hdr.num = htonl (0);
+ hdr.num = htonl (0);
memcpy (buf, &hdr, s);
// GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Sent bytes: %i of %i\n", s, s);
t = NULL;
@@ -582,30 +578,29 @@
}
-static void
-send_task_f (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+static void
+send_task_f (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
send_task = GNUNET_SCHEDULER_NO_TASK;
- if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
+ if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
return;
-
- if (t!=NULL)
- {
- GNUNET_TRANSPORT_notify_transmit_ready_cancel(t);
- t = NULL;
- }
+ if (t != NULL)
+ {
+ GNUNET_TRANSPORT_notify_transmit_ready_cancel (t);
+ t = NULL;
+ }
+
if (send_msg == GNUNET_YES)
- t = GNUNET_TRANSPORT_notify_transmit_ready(th,
- &master_deamon->id,
- sizeof (struct TestMessage), 0,
- SEND_TIMEOUT,
- &send_dummy_data_task, NULL);
- send_task = GNUNET_SCHEDULER_add_delayed(
- GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS,1000),
- &send_task_f,
- NULL);
+ t = GNUNET_TRANSPORT_notify_transmit_ready (th,
+ &master_deamon->id,
+ sizeof (struct TestMessage), 0,
+ SEND_TIMEOUT,
+ &send_dummy_data_task, NULL);
+ send_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MILLISECONDS, 1000),
+ &send_task_f, NULL);
}
@@ -615,135 +610,127 @@
const struct GNUNET_TRANSPORT_ATS_Information *ats,
uint32_t ats_count)
{
- send_task = GNUNET_SCHEDULER_add_now(&send_task_f, NULL);
+ send_task = GNUNET_SCHEDULER_add_now (&send_task_f, NULL);
}
static void
-notify_disconnect (void *cls,
- const struct GNUNET_PeerIdentity *peer)
+notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
{
if (GNUNET_SCHEDULER_NO_TASK != send_task)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Disconnect event before transmission request could be
scheduled!\n");
- GNUNET_SCHEDULER_cancel (send_task);
- send_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Disconnect event before transmission request could be
scheduled!\n");
+ GNUNET_SCHEDULER_cancel (send_task);
+ send_task = GNUNET_SCHEDULER_NO_TASK;
+ }
if (NULL != t)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Disconnect event before transmission request could be
completed!\n");
- GNUNET_TRANSPORT_notify_transmit_ready_cancel (t);
- t = NULL;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Disconnect event before transmission request could be
completed!\n");
+ GNUNET_TRANSPORT_notify_transmit_ready_cancel (t);
+ t = NULL;
+ }
}
-static void
-daemon_connect_cb(void *cls,
- const struct GNUNET_PeerIdentity *first,
- const struct GNUNET_PeerIdentity *second,
- uint32_t distance,
- const struct GNUNET_CONFIGURATION_Handle *first_cfg,
- const struct GNUNET_CONFIGURATION_Handle *second_cfg,
- struct GNUNET_TESTING_Daemon *first_daemon,
- struct GNUNET_TESTING_Daemon *second_daemon,
- const char *emsg)
+static void
+daemon_connect_cb (void *cls,
+ const struct GNUNET_PeerIdentity *first,
+ const struct GNUNET_PeerIdentity *second,
+ uint32_t distance,
+ const struct GNUNET_CONFIGURATION_Handle *first_cfg,
+ const struct GNUNET_CONFIGURATION_Handle *second_cfg,
+ struct GNUNET_TESTING_Daemon *first_daemon,
+ struct GNUNET_TESTING_Daemon *second_daemon,
+ const char *emsg)
{
- char * firstc = strdup(GNUNET_i2s(first));
- char * secondc = strdup(GNUNET_i2s(second));
+ char *firstc = strdup (GNUNET_i2s (first));
+ char *secondc = strdup (GNUNET_i2s (second));
+
connected++;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connected peers `%s'<->`%s' (%i/%i)\n",
- firstc, secondc, connected, peers-1);
- GNUNET_free(firstc);
- GNUNET_free(secondc);
-
- if ( ( (first_daemon == ping_deamon) ||
- (second_daemon == ping_deamon) ) &&
- (master_deamon != NULL) &&
- (ping_deamon != NULL) )
- {
- th = GNUNET_TRANSPORT_connect (ping_deamon->cfg,
- &ping_deamon->id,
- NULL, NULL,
- ¬ify_connect,
- ¬ify_disconnect);
- force_q_updates = GNUNET_YES;
- send_msg = GNUNET_YES;
- }
+ "Connected peers `%s'<->`%s' (%i/%i)\n",
+ firstc, secondc, connected, peers - 1);
+ GNUNET_free (firstc);
+ GNUNET_free (secondc);
+
+ if (((first_daemon == ping_deamon) ||
+ (second_daemon == ping_deamon)) &&
+ (master_deamon != NULL) && (ping_deamon != NULL))
+ {
+ th = GNUNET_TRANSPORT_connect (ping_deamon->cfg,
+ &ping_deamon->id,
+ NULL, NULL,
+ ¬ify_connect, ¬ify_disconnect);
+ force_q_updates = GNUNET_YES;
+ send_msg = GNUNET_YES;
+ }
}
static void
daemon_start_cb (void *cls,
- const struct GNUNET_PeerIdentity *id,
- const struct GNUNET_CONFIGURATION_Handle *cfg,
- struct GNUNET_TESTING_Daemon *d, const char *emsg)
+ const struct GNUNET_PeerIdentity *id,
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ struct GNUNET_TESTING_Daemon *d, const char *emsg)
{
if (id == NULL)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Start callback called with error (too long starting peers),
aborting test!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error from testing: `%s'\n");
+ failed_peers++;
+ if (failed_peers == peers_left)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Start callback called with error (too long starting peers),
aborting test!\n");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Error from testing: `%s'\n");
- failed_peers++;
- if (failed_peers == peers_left)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Too many peers failed, ending test!\n");
- ok = 1;
- shutdown_peers ();
- }
- return;
+ "Too many peers failed, ending test!\n");
+ ok = 1;
+ shutdown_peers ();
}
+ return;
+ }
peers_left--;
if (master_deamon == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Master peer `%s' '%s'\n",
- GNUNET_i2s(id), d->cfgfile);
- master_deamon = d;
- stats = GNUNET_STATISTICS_create("transport", master_deamon->cfg);
- GNUNET_assert (stats != NULL);
- stats_task = GNUNET_SCHEDULER_add_now(&stats_get_task, NULL);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Master peer `%s' '%s'\n", GNUNET_i2s (id), d->cfgfile);
+ master_deamon = d;
+ stats = GNUNET_STATISTICS_create ("transport", master_deamon->cfg);
+ GNUNET_assert (stats != NULL);
+ stats_task = GNUNET_SCHEDULER_add_now (&stats_get_task, NULL);
+ }
else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connecting peer `%s'\n",
- GNUNET_i2s(id), GNUNET_i2s(&master_deamon->id));
- GNUNET_TESTING_daemons_connect(d,
- master_deamon,
- TIMEOUT,
- 0,
- GNUNET_YES,
- &daemon_connect_cb,
- NULL);
- }
-
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Connecting peer `%s'\n",
+ GNUNET_i2s (id), GNUNET_i2s (&master_deamon->id));
+ GNUNET_TESTING_daemons_connect (d,
+ master_deamon,
+ TIMEOUT,
+ 0, GNUNET_YES, &daemon_connect_cb, NULL);
+ }
+
if (peers_left == 0)
+ {
+ if (ping_deamon == NULL)
{
- if (ping_deamon == NULL)
- {
- ping_deamon = d;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Ping peer `%s' '%s'\n", GNUNET_i2s(id), d->cfgfile);
- }
-
+ ping_deamon = d;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "All peers started successfully!\n");
- connect_peers();
- ok = 0;
+ "Ping peer `%s' '%s'\n", GNUNET_i2s (id), d->cfgfile);
}
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers started successfully!\n");
+ connect_peers ();
+ ok = 0;
+ }
else if (failed_peers == peers_left)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Too many peers failed, ending test!\n");
- shutdown_peers();
- ok = 1;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Too many peers failed, ending test!\n");
+ shutdown_peers ();
+ ok = 1;
+ }
}
@@ -758,10 +745,9 @@
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting %i peers.\n", peers);
#endif
peers_left = peers;
- pg = GNUNET_TESTING_daemons_start (cfg,
- peers_left, /* Total number of peers */
- peers_left, /* Number of outstanding
connections */
- peers_left, /* Number of parallel ssh
connections, or peers being started at once */
+ pg = GNUNET_TESTING_daemons_start (cfg, peers_left, /* Total number of
peers */
+ peers_left, /* Number of
outstanding connections */
+ peers_left, /* Number of parallel
ssh connections, or peers being started at once */
TIMEOUT,
NULL, NULL,
&daemon_start_cb, NULL, NULL, NULL, NULL);
@@ -808,28 +794,29 @@
config_file = "test_transport_ats_4addr.conf";
int c = 0;
+
if (argc >= 2)
+ {
+ for (c = 0; c < argc; c++)
{
- for (c=0; c<argc; c++)
- {
- /* set peers */
- if ((strcmp(argv[c], "-p") == 0) && c < (argc-1))
- {
- peers = atoi(argv[c+1]);
- peers++;
- }
- /* set machine parsable */
- if (strcmp(argv[c], "-m") == 0)
- {
- machine_parsable = GNUNET_YES;
- }
- /* set config file */
- if ((strcmp(argv[c], "-c") == 0) && c < (argc-1))
- {
- config_file = argv[c+1];
- }
- }
+ /* set peers */
+ if ((strcmp (argv[c], "-p") == 0) && c < (argc - 1))
+ {
+ peers = atoi (argv[c + 1]);
+ peers++;
+ }
+ /* set machine parsable */
+ if (strcmp (argv[c], "-m") == 0)
+ {
+ machine_parsable = GNUNET_YES;
+ }
+ /* set config file */
+ if ((strcmp (argv[c], "-c") == 0) && c < (argc - 1))
+ {
+ config_file = argv[c + 1];
+ }
}
+ }
ret = check ();
/**
Modified: gnunet/src/transport/test_transport_testing.c
===================================================================
--- gnunet/src/transport/test_transport_testing.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/transport/test_transport_testing.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -50,8 +50,8 @@
GNUNET_SCHEDULER_TaskIdentifier timeout_task;
-static struct PeerContext * p1;
-static struct PeerContext * p2;
+static struct PeerContext *p1;
+static struct PeerContext *p2;
static int connected = GNUNET_NO;
@@ -63,10 +63,10 @@
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n");
if (timeout_task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel(timeout_task);
+ GNUNET_SCHEDULER_cancel (timeout_task);
- GNUNET_TRANSPORT_TESTING_stop_peer(p1);
- GNUNET_TRANSPORT_TESTING_stop_peer(p2);
+ GNUNET_TRANSPORT_TESTING_stop_peer (p1);
+ GNUNET_TRANSPORT_TESTING_stop_peer (p2);
}
static void
@@ -75,21 +75,21 @@
timeout_task = GNUNET_SCHEDULER_NO_TASK;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n");
- GNUNET_TRANSPORT_TESTING_stop_peer(p1);
- GNUNET_TRANSPORT_TESTING_stop_peer(p2);
+ GNUNET_TRANSPORT_TESTING_stop_peer (p1);
+ GNUNET_TRANSPORT_TESTING_stop_peer (p2);
ret = GNUNET_SYSERR;
}
static void
-testing_connect_cb (struct PeerContext * p1, struct PeerContext * p2, void
*cls)
+testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
{
- char * p1_c = strdup (GNUNET_i2s(&p1->id));
+ char *p1_c = strdup (GNUNET_i2s (&p1->id));
+
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peers connected: %s <-> %s\n",
- p1_c,
- GNUNET_i2s (&p2->id));
- GNUNET_free(p1_c);
- end();
+ p1_c, GNUNET_i2s (&p2->id));
+ GNUNET_free (p1_c);
+ end ();
}
static void
@@ -99,7 +99,7 @@
uint32_t ats_count)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s' connected \n",
- GNUNET_i2s (peer));
+ GNUNET_i2s (peer));
connected++;
}
@@ -107,7 +107,7 @@
notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s' disconnected \n",
- GNUNET_i2s (peer));
+ GNUNET_i2s (peer));
}
static void
@@ -126,38 +126,39 @@
char *const *args,
const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
- timeout_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MINUTES,
&end_badly, NULL);
+ timeout_task =
+ 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("test_transport_api_tcp_peer1.conf",
- ¬ify_receive,
- ¬ify_connect,
- ¬ify_disconnect,
- p1);
+ p1 = GNUNET_TRANSPORT_TESTING_start_peer
("test_transport_api_tcp_peer1.conf",
+ ¬ify_receive,
+ ¬ify_connect,
+ ¬ify_disconnect, p1);
- p2 = GNUNET_TRANSPORT_TESTING_start_peer("test_transport_api_tcp_peer2.conf",
- ¬ify_receive,
- ¬ify_connect,
- ¬ify_disconnect,
- p2);
+ p2 = GNUNET_TRANSPORT_TESTING_start_peer
("test_transport_api_tcp_peer2.conf",
+ ¬ify_receive,
+ ¬ify_connect,
+ ¬ify_disconnect, p2);
if (p1 != NULL)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer1 was successfully started\n");
else
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer1 was not started
successfully\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Peer1 was not started successfully\n");
GNUNET_assert (p1 != NULL);
GNUNET_assert (p1->th != NULL);
if (p2 != NULL)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer2 was successfully started\n");
else
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer2 was not started
successfully\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Peer2 was not started successfully\n");
GNUNET_assert (p2 != NULL);
GNUNET_assert (p2->th != NULL);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting peers\n");
- GNUNET_TRANSPORT_TESTING_connect_peers(p1, p2, &testing_connect_cb, NULL);
+ GNUNET_TRANSPORT_TESTING_connect_peers (p1, p2, &testing_connect_cb, NULL);
}
int
Modified: gnunet/src/transport/transport-testing.c
===================================================================
--- gnunet/src/transport/transport-testing.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/transport/transport-testing.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -29,11 +29,11 @@
struct ConnectingContext
{
- struct PeerContext * p1;
- struct PeerContext * p2;
+ struct PeerContext *p1;
+ struct PeerContext *p2;
GNUNET_SCHEDULER_TaskIdentifier tct;
GNUNET_TRANSPORT_TESTING_connect_cb cb;
- void * cb_cls;
+ void *cb_cls;
struct GNUNET_TRANSPORT_Handle *th_p1;
struct GNUNET_TRANSPORT_Handle *th_p2;
@@ -42,41 +42,43 @@
};
static void
-exchange_hello_last (void *cb_cls,
- const struct GNUNET_MessageHeader *message);
+exchange_hello_last (void *cb_cls, const struct GNUNET_MessageHeader *message);
static void
-exchange_hello (void *cb_cls,
- const struct GNUNET_MessageHeader *message);
+exchange_hello (void *cb_cls, const struct GNUNET_MessageHeader *message);
static void
notify_connect_internal (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_TRANSPORT_ATS_Information *ats,
- uint32_t ats_count)
+ const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_TRANSPORT_ATS_Information *ats,
+ uint32_t ats_count)
{
- struct ConnectingContext * cc = cls;
+ struct ConnectingContext *cc = cls;
- GNUNET_assert(cc != NULL);
+ GNUNET_assert (cc != NULL);
- if (0 == memcmp (&(*peer).hashPubKey, &cc->p1->id.hashPubKey, sizeof
(GNUNET_HashCode)))
- {
+ if (0 ==
+ memcmp (&(*peer).hashPubKey, &cc->p1->id.hashPubKey,
+ sizeof (GNUNET_HashCode)))
+ {
if (cc->p1_c == GNUNET_NO)
cc->p1_c = GNUNET_YES;
- }
- if (0 == memcmp (&(*peer).hashPubKey, &cc->p2->id.hashPubKey, sizeof
(GNUNET_HashCode)))
- {
+ }
+ if (0 ==
+ memcmp (&(*peer).hashPubKey, &cc->p2->id.hashPubKey,
+ sizeof (GNUNET_HashCode)))
+ {
if (cc->p2_c == GNUNET_NO)
cc->p2_c = GNUNET_YES;
- }
+ }
if ((cc->p2_c == GNUNET_YES) && (cc->p2_c == GNUNET_YES))
{
- /* clean up */
+ /* clean up */
GNUNET_TRANSPORT_get_hello_cancel (cc->th_p2, &exchange_hello_last, cc);
GNUNET_TRANSPORT_get_hello_cancel (cc->th_p1, &exchange_hello, cc);
if (cc->tct != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel(cc->tct);
+ GNUNET_SCHEDULER_cancel (cc->tct);
cc->tct = GNUNET_SCHEDULER_NO_TASK;
@@ -86,7 +88,7 @@
if (cc->cb != NULL)
cc->cb (cc->p1, cc->p2, cc->cb_cls);
- GNUNET_free(cc);
+ GNUNET_free (cc);
}
}
@@ -96,7 +98,8 @@
const struct GNUNET_TRANSPORT_ATS_Information *ats,
uint32_t ats_count)
{
- struct PeerContext * p = cls;
+ struct PeerContext *p = cls;
+
if (p == NULL)
return;
if (p->nc != NULL)
@@ -106,7 +109,8 @@
static void
notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
{
- struct PeerContext * p = cls;
+ struct PeerContext *p = cls;
+
if (p == NULL)
return;
if (p->nd != NULL)
@@ -120,7 +124,8 @@
const struct GNUNET_TRANSPORT_ATS_Information *ats,
uint32_t ats_count)
{
- struct PeerContext * p = cls;
+ struct PeerContext *p = cls;
+
if (p == NULL)
return;
if (p->rec != NULL)
@@ -129,18 +134,18 @@
static void
-exchange_hello_last (void *cb_cls,
- const struct GNUNET_MessageHeader *message)
+exchange_hello_last (void *cb_cls, const struct GNUNET_MessageHeader *message)
{
- struct ConnectingContext * cc = cb_cls;
+ struct ConnectingContext *cc = cb_cls;
struct PeerContext *me = cc->p2;
+
//struct PeerContext *p1 = cc->p1;
GNUNET_assert (message != NULL);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Exchanging HELLO of size %d with peer (%s)!\n",
- (int) GNUNET_HELLO_size((const struct GNUNET_HELLO_Message
*)message),
- GNUNET_i2s (&me->id));
+ (int) GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *)
+ message), GNUNET_i2s (&me->id));
GNUNET_assert (GNUNET_OK ==
GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
message, &me->id));
@@ -149,11 +154,11 @@
static void
-exchange_hello (void *cb_cls,
- const struct GNUNET_MessageHeader *message)
+exchange_hello (void *cb_cls, const struct GNUNET_MessageHeader *message)
{
- struct ConnectingContext * cc = cb_cls;
+ struct ConnectingContext *cc = cb_cls;
struct PeerContext *me = cc->p1;
+
//struct PeerContext *p2 = cc->p2;
GNUNET_assert (message != NULL);
@@ -162,34 +167,29 @@
message, &me->id));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Exchanging HELLO of size %d from peer %s!\n",
- (int) GNUNET_HELLO_size((const struct GNUNET_HELLO_Message
*)message),
- GNUNET_i2s (&me->id));
+ (int) GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *)
+ message), GNUNET_i2s (&me->id));
GNUNET_TRANSPORT_offer_hello (cc->th_p2, message, NULL, NULL);
}
static void
-try_connect (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- struct ConnectingContext * cc = cls;
+ struct ConnectingContext *cc = cls;
struct PeerContext *p1 = cc->p1;
struct PeerContext *p2 = cc->p2;
cc->tct = GNUNET_SCHEDULER_NO_TASK;
- if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
+ if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
return;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Asking peers to connect...\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking peers to connect...\n");
/* FIXME: 'pX.id' may still be all-zeros here... */
- GNUNET_TRANSPORT_try_connect (cc->th_p1,
- &p2->id);
- GNUNET_TRANSPORT_try_connect (cc->th_p2,
- &p1->id);
+ GNUNET_TRANSPORT_try_connect (cc->th_p1, &p2->id);
+ GNUNET_TRANSPORT_try_connect (cc->th_p2, &p1->id);
cc->tct = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
- &try_connect,
- cc);
+ &try_connect, cc);
}
@@ -202,30 +202,30 @@
* @return the peer context
*/
struct PeerContext *
-GNUNET_TRANSPORT_TESTING_start_peer (const char * cfgname,
- GNUNET_TRANSPORT_ReceiveCallback rec,
- GNUNET_TRANSPORT_NotifyConnect nc,
- GNUNET_TRANSPORT_NotifyDisconnect nd,
- void * cb_cls)
+GNUNET_TRANSPORT_TESTING_start_peer (const char *cfgname,
+ GNUNET_TRANSPORT_ReceiveCallback rec,
+ GNUNET_TRANSPORT_NotifyConnect nc,
+ GNUNET_TRANSPORT_NotifyDisconnect nd,
+ void *cb_cls)
{
- struct PeerContext * p = GNUNET_malloc (sizeof (struct PeerContext));
+ struct PeerContext *p = GNUNET_malloc (sizeof (struct PeerContext));
p->cfg = GNUNET_CONFIGURATION_create ();
GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
- if (GNUNET_CONFIGURATION_have_value (p->cfg,"PATHS", "SERVICEHOME"))
- GNUNET_CONFIGURATION_get_value_string (p->cfg, "PATHS", "SERVICEHOME",
&p->servicehome);
+ if (GNUNET_CONFIGURATION_have_value (p->cfg, "PATHS", "SERVICEHOME"))
+ GNUNET_CONFIGURATION_get_value_string (p->cfg, "PATHS", "SERVICEHOME",
+ &p->servicehome);
if (NULL != p->servicehome)
GNUNET_DISK_directory_remove (p->servicehome);
p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
- "gnunet-service-arm",
- "-c", cfgname,
+ "gnunet-service-arm", "-c", cfgname,
#if VERBOSE_PEERS
- "-L", "DEBUG",
+ "-L", "DEBUG",
#else
- "-L", "ERROR",
+ "-L", "ERROR",
#endif
- NULL);
+ NULL);
p->nc = nc;
p->nd = nd;
p->rec = rec;
@@ -234,11 +234,10 @@
else
p->cb_cls = p;
- p->th = GNUNET_TRANSPORT_connect(p->cfg, NULL,
- p,
- ¬ify_receive,
- ¬ify_connect,
- ¬ify_disconnect);
+ p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL,
+ p,
+ ¬ify_receive,
+ ¬ify_connect, ¬ify_disconnect);
GNUNET_assert (p->th != NULL);
return p;
}
@@ -248,25 +247,25 @@
* @param p the peer
*/
void
-GNUNET_TRANSPORT_TESTING_stop_peer (struct PeerContext * p)
+GNUNET_TRANSPORT_TESTING_stop_peer (struct PeerContext *p)
{
if (p->th != NULL)
- GNUNET_TRANSPORT_disconnect(p->th);
+ GNUNET_TRANSPORT_disconnect (p->th);
if (NULL != p->arm_proc)
- {
- if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
- GNUNET_OS_process_wait (p->arm_proc);
- GNUNET_OS_process_close (p->arm_proc);
- p->arm_proc = NULL;
- }
+ {
+ if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
+ GNUNET_OS_process_wait (p->arm_proc);
+ GNUNET_OS_process_close (p->arm_proc);
+ p->arm_proc = NULL;
+ }
GNUNET_CONFIGURATION_destroy (p->cfg);
if (p->servicehome != NULL)
- {
+ {
GNUNET_DISK_directory_remove (p->servicehome);
- GNUNET_free(p->servicehome);
- }
+ GNUNET_free (p->servicehome);
+ }
GNUNET_free (p);
}
@@ -280,12 +279,13 @@
* @param cb_cls callback cls
*/
void
-GNUNET_TRANSPORT_TESTING_connect_peers (struct PeerContext * p1,
- struct PeerContext * p2,
+GNUNET_TRANSPORT_TESTING_connect_peers (struct PeerContext *p1,
+ struct PeerContext *p2,
GNUNET_TRANSPORT_TESTING_connect_cb cb,
- void * cb_cls)
+ void *cb_cls)
{
- struct ConnectingContext * cc = GNUNET_malloc (sizeof (struct
ConnectingContext));
+ struct ConnectingContext *cc =
+ GNUNET_malloc (sizeof (struct ConnectingContext));
GNUNET_assert (p1 != NULL);
GNUNET_assert (p2 != NULL);
@@ -296,17 +296,13 @@
cc->cb = cb;
cc->cb_cls = cb_cls;
- cc->th_p1 = GNUNET_TRANSPORT_connect(cc->p1->cfg, NULL,
- cc,
- NULL,
- ¬ify_connect_internal,
- NULL);
+ cc->th_p1 = GNUNET_TRANSPORT_connect (cc->p1->cfg, NULL,
+ cc,
+ NULL, ¬ify_connect_internal, NULL);
- cc->th_p2 = GNUNET_TRANSPORT_connect(cc->p2->cfg, NULL,
- cc,
- NULL,
- ¬ify_connect_internal,
- NULL);
+ cc->th_p2 = GNUNET_TRANSPORT_connect (cc->p2->cfg, NULL,
+ cc,
+ NULL, ¬ify_connect_internal, NULL);
GNUNET_assert (cc->th_p1 != NULL);
GNUNET_assert (cc->th_p2 != NULL);
Modified: gnunet/src/transport/transport-testing.h
===================================================================
--- gnunet/src/transport/transport-testing.h 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/transport/transport-testing.h 2011-08-15 21:46:35 UTC (rev
16581)
@@ -53,16 +53,18 @@
GNUNET_TRANSPORT_NotifyDisconnect nd;
- void * cb_cls;
+ void *cb_cls;
- char * servicehome;
+ char *servicehome;
};
/**
* Callback when two peers are connected and both have called the connect
callback
* to notify clients about a new peer
*/
-typedef void (*GNUNET_TRANSPORT_TESTING_connect_cb) (struct PeerContext * p1,
struct PeerContext * p2, void *cls);
+typedef void (*GNUNET_TRANSPORT_TESTING_connect_cb) (struct PeerContext * p1,
+ struct PeerContext * p2,
+ void *cls);
/**
@@ -74,12 +76,13 @@
* if NULL passed the PeerContext * will be used!
* @return the peer context
*/
-struct PeerContext *
-GNUNET_TRANSPORT_TESTING_start_peer (const char * cfgname,
- GNUNET_TRANSPORT_ReceiveCallback rec,
- GNUNET_TRANSPORT_NotifyConnect nc,
- GNUNET_TRANSPORT_NotifyDisconnect nd,
- void * cb_cls);
+struct PeerContext *GNUNET_TRANSPORT_TESTING_start_peer (const char *cfgname,
+
GNUNET_TRANSPORT_ReceiveCallback
+ rec,
+
GNUNET_TRANSPORT_NotifyConnect
+ nc,
+
GNUNET_TRANSPORT_NotifyDisconnect
+ nd, void *cb_cls);
/**
@@ -87,8 +90,7 @@
* @param p the peer
*/
-void
-GNUNET_TRANSPORT_TESTING_stop_peer (struct PeerContext * pc);
+void GNUNET_TRANSPORT_TESTING_stop_peer (struct PeerContext *pc);
/**
@@ -101,9 +103,9 @@
* @param cb_cls callback cls
*/
void
-GNUNET_TRANSPORT_TESTING_connect_peers (struct PeerContext * p1,
- struct PeerContext * p2,
- GNUNET_TRANSPORT_TESTING_connect_cb cb,
- void * cls);
+GNUNET_TRANSPORT_TESTING_connect_peers (struct PeerContext *p1,
+ struct PeerContext *p2,
+ GNUNET_TRANSPORT_TESTING_connect_cb cb,
+ void *cls);
/* end of transport_testing.h */
Modified: gnunet/src/transport/transport.h
===================================================================
--- gnunet/src/transport/transport.h 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/transport/transport.h 2011-08-15 21:46:35 UTC (rev 16581)
@@ -319,7 +319,7 @@
uint32_t addrlen GNUNET_PACKED;
/* followed by 'addrlen' bytes of the actual address, then
- followed by the 0-terminated name of the transport */
+ * followed by the 0-terminated name of the transport */
};
Modified: gnunet/src/transport/transport_api.c
===================================================================
--- gnunet/src/transport/transport_api.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/transport/transport_api.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -255,7 +255,7 @@
* specify when we could next send a message to the respective peer.
* Excludes control messages (which can always go out immediately).
* Maps time stamps to 'struct Neighbour' entries.
- */
+ */
struct GNUNET_CONTAINER_Heap *ready_heap;
/**
@@ -295,8 +295,7 @@
*
* @param h transport service to schedule a transmission for
*/
-static void
-schedule_transmission (struct GNUNET_TRANSPORT_Handle *h);
+static void schedule_transmission (struct GNUNET_TRANSPORT_Handle *h);
/**
@@ -320,7 +319,7 @@
neighbour_find (struct GNUNET_TRANSPORT_Handle *h,
const struct GNUNET_PeerIdentity *peer)
{
- return GNUNET_CONTAINER_multihashmap_get(h->neighbours, &peer->hashPubKey);
+ return GNUNET_CONTAINER_multihashmap_get (h->neighbours, &peer->hashPubKey);
}
@@ -337,21 +336,20 @@
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Creating entry for neighbour `%4s'.\n",
- GNUNET_i2s (pid));
+ "Creating entry for neighbour `%4s'.\n", GNUNET_i2s (pid));
#endif
n = GNUNET_malloc (sizeof (struct Neighbour));
n->id = *pid;
n->h = h;
n->is_ready = GNUNET_YES;
GNUNET_BANDWIDTH_tracker_init (&n->out_tracker,
- GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT,
- MAX_BANDWIDTH_CARRY_S);
+ GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT,
+ MAX_BANDWIDTH_CARRY_S);
GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_put (h->neighbours,
- &pid->hashPubKey,
- n,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+ GNUNET_CONTAINER_multihashmap_put (h->neighbours,
+ &pid->hashPubKey,
+ n,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
return n;
}
@@ -367,22 +365,18 @@
* GNUNET_NO if not.
*/
static int
-neighbour_delete (void *cls,
- const GNUNET_HashCode * key,
- void *value)
+neighbour_delete (void *cls, const GNUNET_HashCode * key, void *value)
{
struct GNUNET_TRANSPORT_Handle *handle = cls;
struct Neighbour *n = value;
if (NULL != handle->nd_cb)
- handle->nd_cb (handle->cls,
- &n->id);
+ handle->nd_cb (handle->cls, &n->id);
GNUNET_assert (NULL == n->th);
GNUNET_assert (NULL == n->hn);
GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove (handle->neighbours,
- key,
- n));
+ GNUNET_CONTAINER_multihashmap_remove (handle->neighbours,
+ key, n));
GNUNET_free (n);
return GNUNET_YES;
}
@@ -395,8 +389,7 @@
* @param msg message received, NULL on timeout or fatal error
*/
static void
-demultiplexer (void *cls,
- const struct GNUNET_MessageHeader *msg)
+demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
{
struct GNUNET_TRANSPORT_Handle *h = cls;
const struct DisconnectInfoMessage *dim;
@@ -413,177 +406,171 @@
GNUNET_assert (h->client != NULL);
if (msg == NULL)
- {
+ {
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Error receiving from transport service, disconnecting
temporarily.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Error receiving from transport service, disconnecting
temporarily.\n");
#endif
- disconnect_and_schedule_reconnect (h);
- return;
- }
+ disconnect_and_schedule_reconnect (h);
+ return;
+ }
GNUNET_CLIENT_receive (h->client,
- &demultiplexer, h,
- GNUNET_TIME_UNIT_FOREVER_REL);
+ &demultiplexer, h, GNUNET_TIME_UNIT_FOREVER_REL);
size = ntohs (msg->size);
switch (ntohs (msg->type))
+ {
+ case GNUNET_MESSAGE_TYPE_HELLO:
+ if (GNUNET_OK !=
+ GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) msg, &me))
{
- case GNUNET_MESSAGE_TYPE_HELLO:
- if (GNUNET_OK !=
- GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) msg,
- &me))
- {
- GNUNET_break (0);
- break;
- }
+ GNUNET_break (0);
+ break;
+ }
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Receiving (my own) `%s' message, I am `%4s'.\n",
- "HELLO", GNUNET_i2s (&me));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Receiving (my own) `%s' message, I am `%4s'.\n",
+ "HELLO", GNUNET_i2s (&me));
#endif
- GNUNET_free_non_null (h->my_hello);
- h->my_hello = NULL;
- if (size < sizeof (struct GNUNET_MessageHeader))
- {
- GNUNET_break (0);
- break;
- }
- h->my_hello = GNUNET_malloc (size);
- memcpy (h->my_hello, msg, size);
- hwl = h->hwl_head;
- while (NULL != hwl)
- {
- next_hwl = hwl->next;
- hwl->rec (hwl->rec_cls,
- (const struct GNUNET_MessageHeader *) h->my_hello);
- hwl = next_hwl;
- }
+ GNUNET_free_non_null (h->my_hello);
+ h->my_hello = NULL;
+ if (size < sizeof (struct GNUNET_MessageHeader))
+ {
+ GNUNET_break (0);
break;
- case GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT:
- if (size < sizeof (struct ConnectInfoMessage))
- {
- GNUNET_break (0);
- break;
- }
- cim = (const struct ConnectInfoMessage *) msg;
- ats_count = ntohl (cim->ats_count);
- if (size != sizeof (struct ConnectInfoMessage) + ats_count * sizeof
(struct GNUNET_TRANSPORT_ATS_Information))
- {
- GNUNET_break (0);
- break;
- }
+ }
+ h->my_hello = GNUNET_malloc (size);
+ memcpy (h->my_hello, msg, size);
+ hwl = h->hwl_head;
+ while (NULL != hwl)
+ {
+ next_hwl = hwl->next;
+ hwl->rec (hwl->rec_cls,
+ (const struct GNUNET_MessageHeader *) h->my_hello);
+ hwl = next_hwl;
+ }
+ break;
+ case GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT:
+ if (size < sizeof (struct ConnectInfoMessage))
+ {
+ GNUNET_break (0);
+ break;
+ }
+ cim = (const struct ConnectInfoMessage *) msg;
+ ats_count = ntohl (cim->ats_count);
+ if (size !=
+ sizeof (struct ConnectInfoMessage) +
+ ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information))
+ {
+ GNUNET_break (0);
+ break;
+ }
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Receiving `%s' message for `%4s'.\n",
- "CONNECT", GNUNET_i2s (&cim->id));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Receiving `%s' message for `%4s'.\n",
+ "CONNECT", GNUNET_i2s (&cim->id));
#endif
- n = neighbour_find (h, &cim->id);
- if (n != NULL)
- {
- GNUNET_break (0);
- break;
- }
- n = neighbour_add (h, &cim->id);
- if (h->nc_cb != NULL)
- h->nc_cb (h->cls, &n->id,
- &cim->ats, ats_count);
+ n = neighbour_find (h, &cim->id);
+ if (n != NULL)
+ {
+ GNUNET_break (0);
break;
- case GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT:
- if (size != sizeof (struct DisconnectInfoMessage))
- {
- GNUNET_break (0);
- break;
- }
- dim = (const struct DisconnectInfoMessage *) msg;
- GNUNET_break (ntohl (dim->reserved) == 0);
+ }
+ n = neighbour_add (h, &cim->id);
+ if (h->nc_cb != NULL)
+ h->nc_cb (h->cls, &n->id, &cim->ats, ats_count);
+ break;
+ case GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT:
+ if (size != sizeof (struct DisconnectInfoMessage))
+ {
+ GNUNET_break (0);
+ break;
+ }
+ dim = (const struct DisconnectInfoMessage *) msg;
+ GNUNET_break (ntohl (dim->reserved) == 0);
#if DEBUG_TRANSPORT_DISCONNECT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Receiving `%s' message for `%4s'.\n",
- "DISCONNECT",
- GNUNET_i2s (&dim->peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Receiving `%s' message for `%4s'.\n",
+ "DISCONNECT", GNUNET_i2s (&dim->peer));
#endif
- n = neighbour_find (h, &dim->peer);
- if (n == NULL)
- {
- GNUNET_break (0);
- break;
- }
- neighbour_delete (h, &dim->peer.hashPubKey, n);
+ n = neighbour_find (h, &dim->peer);
+ if (n == NULL)
+ {
+ GNUNET_break (0);
break;
- case GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK:
- if (size != sizeof (struct SendOkMessage))
- {
- GNUNET_break (0);
- break;
- }
- okm = (const struct SendOkMessage *) msg;
+ }
+ neighbour_delete (h, &dim->peer.hashPubKey, n);
+ break;
+ case GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK:
+ if (size != sizeof (struct SendOkMessage))
+ {
+ GNUNET_break (0);
+ break;
+ }
+ okm = (const struct SendOkMessage *) msg;
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Receiving `%s' message, transmission %s.\n", "SEND_OK",
- ntohl (okm->success) == GNUNET_OK ? "succeeded" : "failed");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Receiving `%s' message, transmission %s.\n", "SEND_OK",
+ ntohl (okm->success) == GNUNET_OK ? "succeeded" : "failed");
#endif
- n = neighbour_find (h, &okm->peer);
- if (n == NULL)
- break;
- GNUNET_break (GNUNET_NO == n->is_ready);
- n->is_ready = GNUNET_YES;
- if ( (n->th != NULL) &&
- (n->hn == NULL) )
- {
- GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != n->th->timeout_task);
- GNUNET_SCHEDULER_cancel (n->th->timeout_task);
- n->th->timeout_task = GNUNET_SCHEDULER_NO_TASK;
- /* we've been waiting for this (congestion, not quota,
- caused delayed transmission) */
- n->hn = GNUNET_CONTAINER_heap_insert (h->ready_heap,
- n, 0);
- schedule_transmission (h);
- }
+ n = neighbour_find (h, &okm->peer);
+ if (n == NULL)
break;
- case GNUNET_MESSAGE_TYPE_TRANSPORT_RECV:
+ GNUNET_break (GNUNET_NO == n->is_ready);
+ n->is_ready = GNUNET_YES;
+ if ((n->th != NULL) && (n->hn == NULL))
+ {
+ GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != n->th->timeout_task);
+ GNUNET_SCHEDULER_cancel (n->th->timeout_task);
+ n->th->timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ /* we've been waiting for this (congestion, not quota,
+ * caused delayed transmission) */
+ n->hn = GNUNET_CONTAINER_heap_insert (h->ready_heap, n, 0);
+ schedule_transmission (h);
+ }
+ break;
+ case GNUNET_MESSAGE_TYPE_TRANSPORT_RECV:
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Receiving `%s' message.\n", "RECV");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving `%s' message.\n", "RECV");
#endif
- if (size <
- sizeof (struct InboundMessage) +
- sizeof (struct GNUNET_MessageHeader))
- {
- GNUNET_break (0);
- break;
- }
- im = (const struct InboundMessage *) msg;
- GNUNET_break (0 == ntohl (im->reserved));
- ats_count = ntohl(im->ats_count);
- imm = (const struct GNUNET_MessageHeader *) &((&(im->ats))[ats_count+1]);
+ if (size <
+ sizeof (struct InboundMessage) + sizeof (struct GNUNET_MessageHeader))
+ {
+ GNUNET_break (0);
+ break;
+ }
+ im = (const struct InboundMessage *) msg;
+ GNUNET_break (0 == ntohl (im->reserved));
+ ats_count = ntohl (im->ats_count);
+ imm = (const struct GNUNET_MessageHeader *) &((&(im->ats))[ats_count + 1]);
- if (ntohs (imm->size) + sizeof (struct InboundMessage) + ats_count *
sizeof (struct GNUNET_TRANSPORT_ATS_Information) != size)
- {
- GNUNET_break (0);
- break;
- }
+ if (ntohs (imm->size) + sizeof (struct InboundMessage) +
+ ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information) != size)
+ {
+ GNUNET_break (0);
+ break;
+ }
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received message of type %u from `%4s'.\n",
- ntohs (imm->type), GNUNET_i2s (&im->peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received message of type %u from `%4s'.\n",
+ ntohs (imm->type), GNUNET_i2s (&im->peer));
#endif
- n = neighbour_find (h, &im->peer);
- if (n == NULL)
- {
- GNUNET_break (0);
- break;
- }
- if (h->rec != NULL)
- h->rec (h->cls, &im->peer, imm,
- &im->ats, ats_count);
- break;
- default:
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _
- ("Received unexpected message of type %u in %s:%u\n"),
- ntohs (msg->type), __FILE__, __LINE__);
+ n = neighbour_find (h, &im->peer);
+ if (n == NULL)
+ {
GNUNET_break (0);
break;
}
+ if (h->rec != NULL)
+ h->rec (h->cls, &im->peer, imm, &im->ats, ats_count);
+ break;
+ default:
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _
+ ("Received unexpected message of type %u in %s:%u\n"),
+ ntohs (msg->type), __FILE__, __LINE__);
+ GNUNET_break (0);
+ break;
+ }
}
@@ -596,7 +583,8 @@
*/
static void
timeout_request_due_to_congestion (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext
*tc)
+ const struct GNUNET_SCHEDULER_TaskContext
+ *tc)
{
struct GNUNET_TRANSPORT_TransmitHandle *th = cls;
struct Neighbour *n = th->neighbour;
@@ -633,77 +621,78 @@
GNUNET_assert (NULL != h->client);
h->cth = NULL;
if (NULL == buf)
- {
- /* transmission failed */
- disconnect_and_schedule_reconnect (h);
- return 0;
- }
+ {
+ /* transmission failed */
+ disconnect_and_schedule_reconnect (h);
+ return 0;
+ }
cbuf = buf;
ret = 0;
/* first send control messages */
- while ( (NULL != (th = h->control_head)) &&
- (th->notify_size <= size) )
- {
- GNUNET_CONTAINER_DLL_remove (h->control_head,
- h->control_tail,
- th);
- nret = th->notify (th->notify_cls, size, &cbuf[ret]);
+ while ((NULL != (th = h->control_head)) && (th->notify_size <= size))
+ {
+ GNUNET_CONTAINER_DLL_remove (h->control_head, h->control_tail, th);
+ nret = th->notify (th->notify_cls, size, &cbuf[ret]);
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Added %u bytes of control message at %u\n",
- nret,
- ret);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Added %u bytes of control message at %u\n", nret, ret);
#endif
- GNUNET_free (th);
- ret += nret;
- size -= nret;
- }
+ GNUNET_free (th);
+ ret += nret;
+ size -= nret;
+ }
/* then, if possible and no control messages pending, send data messages */
- while ( (NULL == h->control_head) &&
- (NULL != (n = GNUNET_CONTAINER_heap_peek (h->ready_heap))) )
+ while ((NULL == h->control_head) &&
+ (NULL != (n = GNUNET_CONTAINER_heap_peek (h->ready_heap))))
+ {
+ if (GNUNET_YES != n->is_ready)
{
- if (GNUNET_YES != n->is_ready)
- {
- /* peer not ready, wait for notification! */
- GNUNET_assert (n == GNUNET_CONTAINER_heap_remove_root
(h->ready_heap));
- n->hn = NULL;
- GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == n->th->timeout_task);
- n->th->timeout_task = GNUNET_SCHEDULER_add_delayed
(GNUNET_TIME_absolute_get_remaining (n->th->timeout),
-
&timeout_request_due_to_congestion,
- n->th);
- continue;
- }
- th = n->th;
- if (th->notify_size + sizeof (struct OutboundMessage) > size)
- break; /* does not fit */
- if (GNUNET_BANDWIDTH_tracker_get_delay (&n->out_tracker,
th->notify_size).rel_value > 0)
- break; /* too early */
+ /* peer not ready, wait for notification! */
GNUNET_assert (n == GNUNET_CONTAINER_heap_remove_root (h->ready_heap));
n->hn = NULL;
- n->th = NULL;
- n->is_ready = GNUNET_NO;
- GNUNET_assert (size >= sizeof (struct OutboundMessage));
- mret = th->notify (th->notify_cls,
- size - sizeof (struct OutboundMessage),
- &cbuf[ret + sizeof (struct OutboundMessage)]);
- GNUNET_assert (mret <= size - sizeof (struct OutboundMessage));
- if (mret != 0)
- {
- GNUNET_assert (mret + sizeof (struct OutboundMessage) <
GNUNET_SERVER_MAX_MESSAGE_SIZE);
- obm.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SEND);
- obm.header.size = htons (mret + sizeof (struct OutboundMessage));
- obm.priority = htonl (th->priority);
- obm.timeout = GNUNET_TIME_relative_hton
(GNUNET_TIME_absolute_get_remaining (th->timeout));
- obm.peer = n->id;
- memcpy (&cbuf[ret], &obm, sizeof (struct OutboundMessage));
- ret += (mret + sizeof (struct OutboundMessage));
- size -= (mret + sizeof (struct OutboundMessage));
- GNUNET_BANDWIDTH_tracker_consume (&n->out_tracker, mret);
- }
- GNUNET_free (th);
+ GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == n->th->timeout_task);
+ n->th->timeout_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
+ (n->th->timeout),
+ &timeout_request_due_to_congestion,
+ n->th);
+ continue;
}
+ th = n->th;
+ if (th->notify_size + sizeof (struct OutboundMessage) > size)
+ break; /* does not fit */
+ if (GNUNET_BANDWIDTH_tracker_get_delay
+ (&n->out_tracker, th->notify_size).rel_value > 0)
+ break; /* too early */
+ GNUNET_assert (n == GNUNET_CONTAINER_heap_remove_root (h->ready_heap));
+ n->hn = NULL;
+ n->th = NULL;
+ n->is_ready = GNUNET_NO;
+ GNUNET_assert (size >= sizeof (struct OutboundMessage));
+ mret = th->notify (th->notify_cls,
+ size - sizeof (struct OutboundMessage),
+ &cbuf[ret + sizeof (struct OutboundMessage)]);
+ GNUNET_assert (mret <= size - sizeof (struct OutboundMessage));
+ if (mret != 0)
+ {
+ GNUNET_assert (mret + sizeof (struct OutboundMessage) <
+ GNUNET_SERVER_MAX_MESSAGE_SIZE);
+ obm.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SEND);
+ obm.header.size = htons (mret + sizeof (struct OutboundMessage));
+ obm.priority = htonl (th->priority);
+ obm.timeout =
+ GNUNET_TIME_relative_hton (GNUNET_TIME_absolute_get_remaining
+ (th->timeout));
+ obm.peer = n->id;
+ memcpy (&cbuf[ret], &obm, sizeof (struct OutboundMessage));
+ ret += (mret + sizeof (struct OutboundMessage));
+ size -= (mret + sizeof (struct OutboundMessage));
+ GNUNET_BANDWIDTH_tracker_consume (&n->out_tracker, mret);
+ }
+ GNUNET_free (th);
+ }
/* if there are more pending messages, try to schedule those */
schedule_transmission (h);
#if DEBUG_TRANSPORT
@@ -723,7 +712,7 @@
*/
static void
schedule_transmission_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_TRANSPORT_Handle *h = cls;
size_t size;
@@ -733,48 +722,45 @@
h->quota_task = GNUNET_SCHEDULER_NO_TASK;
GNUNET_assert (NULL != h->client);
/* destroy all requests that have timed out */
- while ( (NULL != (n = GNUNET_CONTAINER_heap_peek (h->ready_heap))) &&
- (GNUNET_TIME_absolute_get_remaining (n->th->timeout).rel_value == 0) )
- {
- /* notify client that the request could not be satisfied within
- the given time constraints */
- th = n->th;
- n->th = NULL;
- GNUNET_assert (n == GNUNET_CONTAINER_heap_remove_root (h->ready_heap));
- n->hn = NULL;
+ while ((NULL != (n = GNUNET_CONTAINER_heap_peek (h->ready_heap))) &&
+ (GNUNET_TIME_absolute_get_remaining (n->th->timeout).rel_value == 0))
+ {
+ /* notify client that the request could not be satisfied within
+ * the given time constraints */
+ th = n->th;
+ n->th = NULL;
+ GNUNET_assert (n == GNUNET_CONTAINER_heap_remove_root (h->ready_heap));
+ n->hn = NULL;
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Signalling timeout for transmission to peer %s due to
congestion\n",
- GNUNET_i2s (&n->id));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Signalling timeout for transmission to peer %s due to
congestion\n",
+ GNUNET_i2s (&n->id));
#endif
- GNUNET_assert (0 ==
- th->notify (th->notify_cls, 0, NULL));
- GNUNET_free (th);
- }
+ GNUNET_assert (0 == th->notify (th->notify_cls, 0, NULL));
+ GNUNET_free (th);
+ }
if (NULL != h->cth)
return;
if (NULL != h->control_head)
- {
- size = h->control_head->notify_size;
- }
+ {
+ size = h->control_head->notify_size;
+ }
else
- {
- n = GNUNET_CONTAINER_heap_peek (h->ready_heap);
- if (NULL == n)
- return; /* no pending messages */
- size = n->th->notify_size + sizeof (struct OutboundMessage);
- }
+ {
+ n = GNUNET_CONTAINER_heap_peek (h->ready_heap);
+ if (NULL == n)
+ return; /* no pending messages */
+ size = n->th->notify_size + sizeof (struct OutboundMessage);
+ }
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Calling notify_transmit_ready\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Calling notify_transmit_ready\n");
#endif
h->cth =
- GNUNET_CLIENT_notify_transmit_ready (h->client,
- size,
- GNUNET_TIME_UNIT_FOREVER_REL,
- GNUNET_NO,
- &transport_notify_ready,
- h);
+ GNUNET_CLIENT_notify_transmit_ready (h->client,
+ size,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_NO,
+ &transport_notify_ready, h);
GNUNET_assert (NULL != h->cth);
}
@@ -793,22 +779,23 @@
GNUNET_assert (NULL != h->client);
if (h->quota_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (h->quota_task);
- h->quota_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (h->quota_task);
+ h->quota_task = GNUNET_SCHEDULER_NO_TASK;
+ }
if (NULL != h->control_head)
delay = GNUNET_TIME_UNIT_ZERO;
- else if (NULL != (n = GNUNET_CONTAINER_heap_peek (h->ready_heap)))
- delay = GNUNET_BANDWIDTH_tracker_get_delay (&n->out_tracker,
n->th->notify_size);
+ else if (NULL != (n = GNUNET_CONTAINER_heap_peek (h->ready_heap)))
+ delay =
+ GNUNET_BANDWIDTH_tracker_get_delay (&n->out_tracker,
+ n->th->notify_size);
else
- return; /* no work to be done */
+ return; /* no work to be done */
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Scheduling next transmission to service in %llu ms\n",
- (unsigned long long) delay.rel_value);
+ "Scheduling next transmission to service in %llu ms\n",
+ (unsigned long long) delay.rel_value);
h->quota_task = GNUNET_SCHEDULER_add_delayed (delay,
- &schedule_transmission_task,
- h);
+ &schedule_transmission_task,
h);
}
@@ -831,16 +818,13 @@
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Control transmit of %u bytes requested\n",
- size);
+ "Control transmit of %u bytes requested\n", size);
#endif
th = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_TransmitHandle));
th->notify = notify;
th->notify_cls = notify_cls;
th->notify_size = size;
- GNUNET_CONTAINER_DLL_insert_tail (h->control_head,
- h->control_tail,
- th);
+ GNUNET_CONTAINER_DLL_insert_tail (h->control_head, h->control_tail, th);
schedule_transmission (h);
}
@@ -860,18 +844,16 @@
struct StartMessage s;
if (buf == NULL)
- {
- /* Can only be shutdown, just give up */
+ {
+ /* Can only be shutdown, just give up */
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Shutdown while trying to transmit `%s' request.\n",
- "START");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Shutdown while trying to transmit `%s' request.\n", "START");
#endif
- return 0;
- }
+ return 0;
+ }
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitting `%s' request.\n", "START");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting `%s' request.\n",
"START");
#endif
GNUNET_assert (size >= sizeof (struct StartMessage));
s.header.size = htons (sizeof (struct StartMessage));
@@ -892,29 +874,25 @@
* @param tc scheduler context
*/
static void
-reconnect (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_TRANSPORT_Handle *h = cls;
h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
- if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- {
- /* shutdown, just give up */
- return;
- }
+ if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
+ {
+ /* shutdown, just give up */
+ return;
+ }
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connecting to transport service.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting to transport service.\n");
#endif
GNUNET_assert (h->client == NULL);
GNUNET_assert (h->control_head == NULL);
GNUNET_assert (h->control_tail == NULL);
h->client = GNUNET_CLIENT_connect ("transport", h->cfg);
GNUNET_assert (h->client != NULL);
- schedule_control_transmit (h,
- sizeof (struct StartMessage),
- &send_start, h);
+ schedule_control_transmit (h, sizeof (struct StartMessage), &send_start, h);
}
@@ -931,50 +909,45 @@
GNUNET_assert (h->reconnect_task == GNUNET_SCHEDULER_NO_TASK);
/* Forget about all neighbours that we used to be connected to */
- GNUNET_CONTAINER_multihashmap_iterate(h->neighbours,
- &neighbour_delete,
- h);
+ GNUNET_CONTAINER_multihashmap_iterate (h->neighbours, &neighbour_delete, h);
if (NULL != h->cth)
- {
- GNUNET_CLIENT_notify_transmit_ready_cancel (h->cth);
- h->cth = NULL;
- }
+ {
+ GNUNET_CLIENT_notify_transmit_ready_cancel (h->cth);
+ h->cth = NULL;
+ }
if (NULL != h->client)
- {
- GNUNET_CLIENT_disconnect (h->client, GNUNET_YES);
- h->client = NULL;
- }
+ {
+ GNUNET_CLIENT_disconnect (h->client, GNUNET_YES);
+ h->client = NULL;
+ }
if (h->quota_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (h->quota_task);
- h->quota_task = GNUNET_SCHEDULER_NO_TASK;
- }
- while ( (NULL != (th = h->control_head)))
- {
- GNUNET_CONTAINER_DLL_remove (h->control_head,
- h->control_tail,
- th);
- th->notify (th->notify_cls, 0, NULL);
- GNUNET_free (th);
- }
+ {
+ GNUNET_SCHEDULER_cancel (h->quota_task);
+ h->quota_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ while ((NULL != (th = h->control_head)))
+ {
+ GNUNET_CONTAINER_DLL_remove (h->control_head, h->control_tail, th);
+ th->notify (th->notify_cls, 0, NULL);
+ GNUNET_free (th);
+ }
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Scheduling task to reconnect to transport service in %llu
ms.\n",
h->reconnect_delay.rel_value);
#endif
h->reconnect_task
- = GNUNET_SCHEDULER_add_delayed (h->reconnect_delay,
- &reconnect, h);
+ = GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h);
if (h->reconnect_delay.rel_value == 0)
- {
- h->reconnect_delay = GNUNET_TIME_UNIT_MILLISECONDS;
- }
+ {
+ h->reconnect_delay = GNUNET_TIME_UNIT_MILLISECONDS;
+ }
else
- {
- h->reconnect_delay = GNUNET_TIME_relative_multiply (h->reconnect_delay,
2);
- h->reconnect_delay = GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_SECONDS,
- h->reconnect_delay);
- }
+ {
+ h->reconnect_delay = GNUNET_TIME_relative_multiply (h->reconnect_delay, 2);
+ h->reconnect_delay = GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_SECONDS,
+ h->reconnect_delay);
+ }
}
@@ -1011,15 +984,14 @@
struct QuotaSetMessage msg;
if (buf == NULL)
- {
- GNUNET_free (sqc);
- return 0;
- }
+ {
+ GNUNET_free (sqc);
+ return 0;
+ }
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Transmitting `%s' request with respect to `%4s'.\n",
- "SET_QUOTA",
- GNUNET_i2s (&sqc->target));
+ "SET_QUOTA", GNUNET_i2s (&sqc->target));
#endif
GNUNET_assert (size >= sizeof (struct QuotaSetMessage));
msg.header.size = htons (sizeof (struct QuotaSetMessage));
@@ -1049,32 +1021,29 @@
{
struct Neighbour *n;
struct SetQuotaContext *sqc;
-
+
n = neighbour_find (handle, target);
if (NULL == n)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Quota changed to %u for peer `%s', but I have no such
neighbour!\n",
- (unsigned int) ntohl (quota_out.value__),
- GNUNET_i2s (target));
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Quota changed to %u for peer `%s', but I have no such
neighbour!\n",
+ (unsigned int) ntohl (quota_out.value__), GNUNET_i2s (target));
+ return;
+ }
GNUNET_assert (NULL != handle->client);
#if DEBUG_TRANSPORT
if (ntohl (quota_out.value__) != n->out_tracker.available_bytes_per_s__)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Quota changed from %u to %u for peer `%s'\n",
- (unsigned int) n->out_tracker.available_bytes_per_s__,
- (unsigned int) ntohl (quota_out.value__),
- GNUNET_i2s (target));
+ "Quota changed from %u to %u for peer `%s'\n",
+ (unsigned int) n->out_tracker.available_bytes_per_s__,
+ (unsigned int) ntohl (quota_out.value__), GNUNET_i2s (target));
else
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Quota remains at %u for peer `%s'\n",
- (unsigned int) n->out_tracker.available_bytes_per_s__,
- GNUNET_i2s (target));
+ "Quota remains at %u for peer `%s'\n",
+ (unsigned int) n->out_tracker.available_bytes_per_s__,
+ GNUNET_i2s (target));
#endif
- GNUNET_BANDWIDTH_tracker_update_quota (&n->out_tracker,
- quota_out);
+ GNUNET_BANDWIDTH_tracker_update_quota (&n->out_tracker, quota_out);
sqc = GNUNET_malloc (sizeof (struct SetQuotaContext));
sqc->target = *target;
sqc->quota_in = quota_in;
@@ -1099,15 +1068,14 @@
struct TransportRequestConnectMessage msg;
if (buf == NULL)
- {
- GNUNET_free (pid);
- return 0;
- }
+ {
+ GNUNET_free (pid);
+ return 0;
+ }
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Transmitting `%s' request with respect to `%4s'.\n",
- "REQUEST_CONNECT",
- GNUNET_i2s (pid));
+ "REQUEST_CONNECT", GNUNET_i2s (pid));
#endif
GNUNET_assert (size >= sizeof (struct TransportRequestConnectMessage));
msg.header.size = htons (sizeof (struct TransportRequestConnectMessage));
@@ -1129,7 +1097,7 @@
*/
void
GNUNET_TRANSPORT_try_connect (struct GNUNET_TRANSPORT_Handle *handle,
- const struct GNUNET_PeerIdentity *target)
+ const struct GNUNET_PeerIdentity *target)
{
struct GNUNET_PeerIdentity *pid;
@@ -1158,18 +1126,16 @@
uint16_t ssize;
if (buf == NULL)
- {
+ {
#if DEBUG_TRANSPORT_TIMEOUT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Timeout while trying to transmit `%s' request.\n",
- "HELLO");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Timeout while trying to transmit `%s' request.\n", "HELLO");
#endif
- GNUNET_free (msg);
- return 0;
- }
+ GNUNET_free (msg);
+ return 0;
+ }
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitting `%s' request.\n", "HELLO");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting `%s' request.\n",
"HELLO");
#endif
ssize = ntohs (msg->size);
GNUNET_assert (size >= ssize);
@@ -1193,8 +1159,7 @@
void
GNUNET_TRANSPORT_offer_hello (struct GNUNET_TRANSPORT_Handle *handle,
const struct GNUNET_MessageHeader *hello,
- GNUNET_SCHEDULER_Task cont,
- void *cls)
+ GNUNET_SCHEDULER_Task cont, void *cls)
{
uint16_t size;
struct GNUNET_PeerIdentity peer;
@@ -1205,23 +1170,20 @@
GNUNET_break (ntohs (hello->type) == GNUNET_MESSAGE_TYPE_HELLO);
size = ntohs (hello->size);
GNUNET_break (size >= sizeof (struct GNUNET_MessageHeader));
- if (GNUNET_OK != GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message*)
hello,
- &peer))
- {
- GNUNET_break (0);
- return;
- }
- msg = GNUNET_malloc(size);
+ if (GNUNET_OK !=
+ GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) hello, &peer))
+ {
+ GNUNET_break (0);
+ return;
+ }
+ msg = GNUNET_malloc (size);
memcpy (msg, hello, size);
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Offering `%s' message of `%4s' to transport for validation.\n",
- "HELLO",
- GNUNET_i2s (&peer));
+ "Offering `%s' message of `%4s' to transport for validation.\n",
+ "HELLO", GNUNET_i2s (&peer));
#endif
- schedule_control_transmit (handle,
- size,
- &send_hello, msg);
+ schedule_control_transmit (handle, size, &send_hello, msg);
}
@@ -1245,9 +1207,7 @@
hwl = GNUNET_malloc (sizeof (struct HelloWaitList));
hwl->rec = rec;
hwl->rec_cls = rec_cls;
- GNUNET_CONTAINER_DLL_insert (handle->hwl_head,
- handle->hwl_tail,
- hwl);
+ GNUNET_CONTAINER_DLL_insert (handle->hwl_head, handle->hwl_tail, hwl);
if (handle->my_hello == NULL)
return;
rec (rec_cls, (const struct GNUNET_MessageHeader *) handle->my_hello);
@@ -1263,25 +1223,22 @@
*/
void
GNUNET_TRANSPORT_get_hello_cancel (struct GNUNET_TRANSPORT_Handle *handle,
- GNUNET_TRANSPORT_HelloUpdateCallback rec,
- void *rec_cls)
+ GNUNET_TRANSPORT_HelloUpdateCallback rec,
+ void *rec_cls)
{
struct HelloWaitList *pos;
pos = handle->hwl_head;
while (pos != NULL)
- {
- if ( (pos->rec == rec) &&
- (pos->rec_cls == rec_cls) )
- break;
- pos = pos->next;
- }
+ {
+ if ((pos->rec == rec) && (pos->rec_cls == rec_cls))
+ break;
+ pos = pos->next;
+ }
GNUNET_break (pos != NULL);
if (pos == NULL)
return;
- GNUNET_CONTAINER_DLL_remove (handle->hwl_head,
- handle->hwl_tail,
- pos);
+ GNUNET_CONTAINER_DLL_remove (handle->hwl_head, handle->hwl_tail, pos);
GNUNET_free (pos);
}
@@ -1300,7 +1257,7 @@
*/
struct GNUNET_TRANSPORT_Handle *
GNUNET_TRANSPORT_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const struct GNUNET_PeerIdentity *self,
+ const struct GNUNET_PeerIdentity *self,
void *cls,
GNUNET_TRANSPORT_ReceiveCallback rec,
GNUNET_TRANSPORT_NotifyConnect nc,
@@ -1310,18 +1267,20 @@
ret = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_Handle));
if (self != NULL)
- {
- ret->self = *self;
- ret->check_self = GNUNET_YES;
- }
+ {
+ ret->self = *self;
+ ret->check_self = GNUNET_YES;
+ }
ret->cfg = cfg;
ret->cls = cls;
ret->rec = rec;
ret->nc_cb = nc;
ret->nd_cb = nd;
ret->reconnect_delay = GNUNET_TIME_UNIT_ZERO;
- ret->neighbours =
GNUNET_CONTAINER_multihashmap_create(STARTING_NEIGHBOURS_SIZE);
- ret->ready_heap = GNUNET_CONTAINER_heap_create
(GNUNET_CONTAINER_HEAP_ORDER_MIN);
+ ret->neighbours =
+ GNUNET_CONTAINER_multihashmap_create (STARTING_NEIGHBOURS_SIZE);
+ ret->ready_heap =
+ GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
ret->reconnect_task = GNUNET_SCHEDULER_add_now (&reconnect, ret);
return ret;
}
@@ -1336,25 +1295,24 @@
GNUNET_TRANSPORT_disconnect (struct GNUNET_TRANSPORT_Handle *handle)
{
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transport disconnect called!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transport disconnect called!\n");
#endif
/* this disconnects all neighbours... */
if (handle->reconnect_task == GNUNET_SCHEDULER_NO_TASK)
disconnect_and_schedule_reconnect (handle);
/* and now we stop trying to connect again... */
if (handle->reconnect_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (handle->reconnect_task);
- handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (handle->reconnect_task);
+ handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
+ }
GNUNET_CONTAINER_multihashmap_destroy (handle->neighbours);
handle->neighbours = NULL;
if (handle->quota_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (handle->quota_task);
- handle->quota_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (handle->quota_task);
+ handle->quota_task = GNUNET_SCHEDULER_NO_TASK;
+ }
GNUNET_free_non_null (handle->my_hello);
handle->my_hello = NULL;
GNUNET_assert (handle->hwl_head == NULL);
@@ -1386,31 +1344,30 @@
*/
struct GNUNET_TRANSPORT_TransmitHandle *
GNUNET_TRANSPORT_notify_transmit_ready (struct GNUNET_TRANSPORT_Handle *handle,
- const struct GNUNET_PeerIdentity
*target,
- size_t size,
- uint32_t priority,
+ const struct GNUNET_PeerIdentity
+ *target, size_t size, uint32_t
priority,
struct GNUNET_TIME_Relative timeout,
- GNUNET_CONNECTION_TransmitReadyNotify
notify,
- void *notify_cls)
+ GNUNET_CONNECTION_TransmitReadyNotify
+ notify, void *notify_cls)
{
struct Neighbour *n;
struct GNUNET_TRANSPORT_TransmitHandle *th;
struct GNUNET_TIME_Relative delay;
-
+
n = neighbour_find (handle, target);
if (NULL == n)
- {
- /* use GNUNET_TRANSPORT_try_connect first, only use this function
- once a connection has been established */
- GNUNET_assert (0);
- return NULL;
- }
+ {
+ /* use GNUNET_TRANSPORT_try_connect first, only use this function
+ * once a connection has been established */
+ GNUNET_assert (0);
+ return NULL;
+ }
if (NULL != n->th)
- {
- /* attempt to send two messages at the same time to the same peer */
- GNUNET_assert (0);
- return NULL;
- }
+ {
+ /* attempt to send two messages at the same time to the same peer */
+ GNUNET_assert (0);
+ return NULL;
+ }
GNUNET_assert (NULL == n->hn);
th = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_TransmitHandle));
th->neighbour = n;
@@ -1423,16 +1380,13 @@
/* calculate when our transmission should be ready */
delay = GNUNET_BANDWIDTH_tracker_get_delay (&n->out_tracker, size);
if (delay.rel_value > timeout.rel_value)
- delay.rel_value = 0; /* notify immediately (with failure) */
+ delay.rel_value = 0; /* notify immediately (with failure) */
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Bandwidth tracker allows next transmission to peer %s in %llu
ms\n",
- GNUNET_i2s (target),
- (unsigned long long) delay.rel_value);
+ "Bandwidth tracker allows next transmission to peer %s in %llu
ms\n",
+ GNUNET_i2s (target), (unsigned long long) delay.rel_value);
#endif
- n->hn = GNUNET_CONTAINER_heap_insert (handle->ready_heap,
- n,
- delay.rel_value);
+ n->hn = GNUNET_CONTAINER_heap_insert (handle->ready_heap, n,
delay.rel_value);
schedule_transmission (handle);
return th;
}
@@ -1444,7 +1398,9 @@
* @param th handle returned from GNUNET_TRANSPORT_notify_transmit_ready
*/
void
-GNUNET_TRANSPORT_notify_transmit_ready_cancel (struct
GNUNET_TRANSPORT_TransmitHandle *th)
+GNUNET_TRANSPORT_notify_transmit_ready_cancel (struct
+ GNUNET_TRANSPORT_TransmitHandle
+ *th)
{
struct Neighbour *n;
@@ -1454,17 +1410,17 @@
GNUNET_assert (th == n->th);
n->th = NULL;
if (n->hn != NULL)
- {
- GNUNET_CONTAINER_heap_remove_node (n->hn);
- n->hn = NULL;
- }
+ {
+ GNUNET_CONTAINER_heap_remove_node (n->hn);
+ n->hn = NULL;
+ }
else
- {
- GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != th->timeout_task);
- GNUNET_SCHEDULER_cancel (th->timeout_task);
- th->timeout_task = GNUNET_SCHEDULER_NO_TASK;
- }
- GNUNET_free (th);
+ {
+ GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != th->timeout_task);
+ GNUNET_SCHEDULER_cancel (th->timeout_task);
+ th->timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ GNUNET_free (th);
}
Modified: gnunet/src/transport/transport_api_address_iterate.c
===================================================================
--- gnunet/src/transport/transport_api_address_iterate.c 2011-08-15
21:40:08 UTC (rev 16580)
+++ gnunet/src/transport/transport_api_address_iterate.c 2011-08-15
21:46:35 UTC (rev 16581)
@@ -82,37 +82,37 @@
uint16_t size;
if (msg == NULL)
- {
- alucb->cb (alucb->cb_cls, NULL);
- GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
- GNUNET_free (alucb);
- return;
- }
- GNUNET_break (ntohs (msg->type) ==
GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
+ {
+ alucb->cb (alucb->cb_cls, NULL);
+ GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
+ GNUNET_free (alucb);
+ return;
+ }
+ GNUNET_break (ntohs (msg->type) ==
+ GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
size = ntohs (msg->size);
if (size == sizeof (struct GNUNET_MessageHeader))
- {
- /* done! */
- alucb->cb (alucb->cb_cls, NULL);
- GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
- GNUNET_free (alucb);
- return;
- }
+ {
+ /* done! */
+ alucb->cb (alucb->cb_cls, NULL);
+ GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
+ GNUNET_free (alucb);
+ return;
+ }
address = (const char *) &msg[1];
if (address[size - sizeof (struct GNUNET_MessageHeader) - 1] != '\0')
- {
- /* invalid reply */
- GNUNET_break (0);
- alucb->cb (alucb->cb_cls, NULL);
- GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
- GNUNET_free (alucb);
- return;
- }
+ {
+ /* invalid reply */
+ GNUNET_break (0);
+ alucb->cb (alucb->cb_cls, NULL);
+ GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
+ GNUNET_free (alucb);
+ return;
+ }
/* expect more replies */
GNUNET_CLIENT_receive (alucb->client,
- &peer_address_response_processor, alucb,
- GNUNET_TIME_absolute_get_remaining
- (alucb->timeout));
+ &peer_address_response_processor, alucb,
+ GNUNET_TIME_absolute_get_remaining (alucb->timeout));
alucb->cb (alucb->cb_cls, address);
}
@@ -128,7 +128,8 @@
void
GNUNET_TRANSPORT_address_iterate (const struct GNUNET_CONFIGURATION_Handle
*cfg,
struct GNUNET_TIME_Relative timeout,
- GNUNET_TRANSPORT_AddressLookUpCallback
peer_address_callback,
+ GNUNET_TRANSPORT_AddressLookUpCallback
+ peer_address_callback,
void *peer_address_callback_cls)
{
struct AddressIterateMessage msg;
@@ -138,13 +139,13 @@
client = GNUNET_CLIENT_connect ("transport", cfg);
if (client == NULL)
- {
- peer_address_callback (peer_address_callback_cls, NULL);
- return;
- }
+ {
+ peer_address_callback (peer_address_callback_cls, NULL);
+ return;
+ }
abs_timeout = GNUNET_TIME_relative_to_absolute (timeout);
- msg.header.size = htons (sizeof(struct AddressLookupMessage));
+ msg.header.size = htons (sizeof (struct AddressLookupMessage));
msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE);
msg.timeout = GNUNET_TIME_absolute_hton (abs_timeout);
peer_address_lookup_cb = GNUNET_malloc (sizeof (struct AddressLookupCtx));
@@ -153,12 +154,12 @@
peer_address_lookup_cb->timeout = abs_timeout;
peer_address_lookup_cb->client = client;
GNUNET_assert (GNUNET_OK ==
- GNUNET_CLIENT_transmit_and_get_response (client,
- &msg.header,
- timeout,
- GNUNET_YES,
-
&peer_address_response_processor,
-
peer_address_lookup_cb));
+ GNUNET_CLIENT_transmit_and_get_response (client,
+ &msg.header,
+ timeout,
+ GNUNET_YES,
+
&peer_address_response_processor,
+
peer_address_lookup_cb));
}
/* end of transport_api_address_iterate.c */
Modified: gnunet/src/transport/transport_api_address_lookup.c
===================================================================
--- gnunet/src/transport/transport_api_address_lookup.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/transport/transport_api_address_lookup.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -62,45 +62,44 @@
* message with the human-readable address
*/
static void
-address_response_processor (void *cls,
- const struct GNUNET_MessageHeader *msg)
+address_response_processor (void *cls, const struct GNUNET_MessageHeader *msg)
{
struct AddressLookupCtx *alucb = cls;
const char *address;
uint16_t size;
if (msg == NULL)
- {
- alucb->cb (alucb->cb_cls, NULL);
- GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
- GNUNET_free (alucb);
- return;
- }
- GNUNET_break (ntohs (msg->type) ==
GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
+ {
+ alucb->cb (alucb->cb_cls, NULL);
+ GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
+ GNUNET_free (alucb);
+ return;
+ }
+ GNUNET_break (ntohs (msg->type) ==
+ GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
size = ntohs (msg->size);
if (size == sizeof (struct GNUNET_MessageHeader))
- {
- /* done! */
- alucb->cb (alucb->cb_cls, NULL);
- GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
- GNUNET_free (alucb);
- return;
- }
+ {
+ /* done! */
+ alucb->cb (alucb->cb_cls, NULL);
+ GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
+ GNUNET_free (alucb);
+ return;
+ }
address = (const char *) &msg[1];
if (address[size - sizeof (struct GNUNET_MessageHeader) - 1] != '\0')
- {
- /* invalid reply */
- GNUNET_break (0);
- alucb->cb (alucb->cb_cls, NULL);
- GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
- GNUNET_free (alucb);
- return;
- }
+ {
+ /* invalid reply */
+ GNUNET_break (0);
+ alucb->cb (alucb->cb_cls, NULL);
+ GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
+ GNUNET_free (alucb);
+ return;
+ }
/* expect more replies */
GNUNET_CLIENT_receive (alucb->client,
- &address_response_processor, alucb,
- GNUNET_TIME_absolute_get_remaining
- (alucb->timeout));
+ &address_response_processor, alucb,
+ GNUNET_TIME_absolute_get_remaining (alucb->timeout));
alucb->cb (alucb->cb_cls, address);
}
@@ -120,9 +119,9 @@
*/
void
GNUNET_TRANSPORT_address_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *address,
- size_t addressLen,
- int numeric,
+ const char *address,
+ size_t addressLen,
+ int numeric,
const char *nameTrans,
struct GNUNET_TIME_Relative timeout,
GNUNET_TRANSPORT_AddressLookUpCallback aluc,
@@ -138,17 +137,17 @@
slen = strlen (nameTrans) + 1;
len = sizeof (struct AddressLookupMessage) + addressLen + slen;
if (len >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
- {
- GNUNET_break (0);
- aluc (aluc_cls, NULL);
- return;
- }
+ {
+ GNUNET_break (0);
+ aluc (aluc_cls, NULL);
+ return;
+ }
client = GNUNET_CLIENT_connect ("transport", cfg);
if (client == NULL)
- {
- aluc (aluc_cls, NULL);
- return;
- }
+ {
+ aluc (aluc_cls, NULL);
+ return;
+ }
msg = GNUNET_malloc (len);
msg->header.size = htons (len);
msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP);
@@ -164,12 +163,12 @@
aluCB->timeout = GNUNET_TIME_relative_to_absolute (timeout);
aluCB->client = client;
GNUNET_assert (GNUNET_OK ==
- GNUNET_CLIENT_transmit_and_get_response (client,
- &msg->header,
- timeout,
- GNUNET_YES,
-
&address_response_processor,
- aluCB));
+ GNUNET_CLIENT_transmit_and_get_response (client,
+ &msg->header,
+ timeout,
+ GNUNET_YES,
+
&address_response_processor,
+ aluCB));
GNUNET_free (msg);
}
Modified: gnunet/src/transport/transport_api_blacklist.c
===================================================================
--- gnunet/src/transport/transport_api_blacklist.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/transport/transport_api_blacklist.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -42,7 +42,7 @@
/**
* Connection to transport service.
*/
- struct GNUNET_CLIENT_Connection * client;
+ struct GNUNET_CLIENT_Connection *client;
/**
* Configuration to use.
@@ -78,8 +78,7 @@
*
* @param br overall handle
*/
-static void
-reconnect (struct GNUNET_TRANSPORT_Blacklist *br);
+static void reconnect (struct GNUNET_TRANSPORT_Blacklist *br);
/**
@@ -87,8 +86,7 @@
*
* @param br our overall context
*/
-static void
-reply (struct GNUNET_TRANSPORT_Blacklist *br);
+static void reply (struct GNUNET_TRANSPORT_Blacklist *br);
/**
@@ -98,19 +96,18 @@
* @param msg query
*/
static void
-query_handler (void *cls,
- const struct GNUNET_MessageHeader *msg)
+query_handler (void *cls, const struct GNUNET_MessageHeader *msg)
{
struct GNUNET_TRANSPORT_Blacklist *br = cls;
const struct BlacklistMessage *bm;
- if ( (ntohs(msg->size) != sizeof (struct BlacklistMessage)) ||
- (ntohs(msg->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY) )
- {
- reconnect (br);
- return;
- }
- bm = (const struct BlacklistMessage *)msg;
+ if ((ntohs (msg->size) != sizeof (struct BlacklistMessage)) ||
+ (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY))
+ {
+ reconnect (br);
+ return;
+ }
+ bm = (const struct BlacklistMessage *) msg;
GNUNET_break (0 == ntohl (bm->is_allowed));
br->peer = bm->peer;
reply (br);
@@ -126,9 +123,7 @@
receive (struct GNUNET_TRANSPORT_Blacklist *br)
{
GNUNET_CLIENT_receive (br->client,
- &query_handler,
- br,
- GNUNET_TIME_UNIT_FOREVER_REL);
+ &query_handler, br, GNUNET_TIME_UNIT_FOREVER_REL);
}
@@ -141,17 +136,16 @@
* @return number of bytes written to buf
*/
static size_t
-transmit_blacklist_init (void *cls,
- size_t size, void *buf)
+transmit_blacklist_init (void *cls, size_t size, void *buf)
{
struct GNUNET_TRANSPORT_Blacklist *br = cls;
struct GNUNET_MessageHeader req;
if (buf == NULL)
- {
- reconnect (br);
- return 0;
- }
+ {
+ reconnect (br);
+ return 0;
+ }
req.size = htons (sizeof (struct GNUNET_MessageHeader));
req.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT);
memcpy (buf, &req, sizeof (req));
@@ -170,15 +164,14 @@
{
if (br->client != NULL)
GNUNET_CLIENT_disconnect (br->client, GNUNET_NO);
- br->client = GNUNET_CLIENT_connect ("transport",
- br->cfg);
+ br->client = GNUNET_CLIENT_connect ("transport", br->cfg);
GNUNET_assert (br->client != NULL);
br->th = GNUNET_CLIENT_notify_transmit_ready (br->client,
- sizeof (struct
GNUNET_MessageHeader),
- GNUNET_TIME_UNIT_FOREVER_REL,
- GNUNET_YES,
- &transmit_blacklist_init,
- br);
+ sizeof (struct
+ GNUNET_MessageHeader),
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_YES,
+ &transmit_blacklist_init, br);
}
@@ -191,17 +184,16 @@
* @return number of bytes written to buf
*/
static size_t
-transmit_blacklist_reply (void *cls,
- size_t size, void *buf)
+transmit_blacklist_reply (void *cls, size_t size, void *buf)
{
struct GNUNET_TRANSPORT_Blacklist *br = cls;
struct BlacklistMessage req;
if (buf == NULL)
- {
- reconnect (br);
- return 0;
- }
+ {
+ reconnect (br);
+ return 0;
+ }
req.header.size = htons (sizeof (req));
req.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY);
req.is_allowed = htonl (br->cb (br->cb_cls, &br->peer));
@@ -221,16 +213,16 @@
reply (struct GNUNET_TRANSPORT_Blacklist *br)
{
br->th = GNUNET_CLIENT_notify_transmit_ready (br->client,
- sizeof (struct
BlacklistMessage),
- GNUNET_TIME_UNIT_FOREVER_REL,
- GNUNET_NO,
- &transmit_blacklist_reply,
- br);
+ sizeof (struct
+ BlacklistMessage),
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_NO,
+ &transmit_blacklist_reply, br);
if (br->th == NULL)
- {
- reconnect (br);
- return;
- }
+ {
+ reconnect (br);
+ return;
+ }
}
@@ -250,10 +242,9 @@
*/
struct GNUNET_TRANSPORT_Blacklist *
GNUNET_TRANSPORT_blacklist (const struct GNUNET_CONFIGURATION_Handle *cfg,
- GNUNET_TRANSPORT_BlacklistCallback cb,
- void *cb_cls)
+ GNUNET_TRANSPORT_BlacklistCallback cb, void
*cb_cls)
{
- struct GNUNET_CLIENT_Connection * client;
+ struct GNUNET_CLIENT_Connection *client;
struct GNUNET_TRANSPORT_Blacklist *ret;
client = GNUNET_CLIENT_connect ("transport", cfg);
@@ -263,11 +254,11 @@
ret->client = client;
ret->cfg = cfg;
ret->th = GNUNET_CLIENT_notify_transmit_ready (client,
- sizeof (struct
GNUNET_MessageHeader),
- GNUNET_TIME_UNIT_FOREVER_REL,
- GNUNET_YES,
- &transmit_blacklist_init,
- ret);
+ sizeof (struct
+ GNUNET_MessageHeader),
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_YES,
+ &transmit_blacklist_init,
ret);
return ret;
}
Modified: gnunet/src/transport/transport_api_peer_address_lookup.c
===================================================================
--- gnunet/src/transport/transport_api_peer_address_lookup.c 2011-08-15
21:40:08 UTC (rev 16580)
+++ gnunet/src/transport/transport_api_peer_address_lookup.c 2011-08-15
21:46:35 UTC (rev 16581)
@@ -82,37 +82,37 @@
uint16_t size;
if (msg == NULL)
- {
- alucb->cb (alucb->cb_cls, NULL);
- GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
- GNUNET_free (alucb);
- return;
- }
- GNUNET_break (ntohs (msg->type) ==
GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
+ {
+ alucb->cb (alucb->cb_cls, NULL);
+ GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
+ GNUNET_free (alucb);
+ return;
+ }
+ GNUNET_break (ntohs (msg->type) ==
+ GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
size = ntohs (msg->size);
if (size == sizeof (struct GNUNET_MessageHeader))
- {
- /* done! */
- alucb->cb (alucb->cb_cls, NULL);
- GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
- GNUNET_free (alucb);
- return;
- }
+ {
+ /* done! */
+ alucb->cb (alucb->cb_cls, NULL);
+ GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
+ GNUNET_free (alucb);
+ return;
+ }
address = (const char *) &msg[1];
if (address[size - sizeof (struct GNUNET_MessageHeader) - 1] != '\0')
- {
- /* invalid reply */
- GNUNET_break (0);
- alucb->cb (alucb->cb_cls, NULL);
- GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
- GNUNET_free (alucb);
- return;
- }
+ {
+ /* invalid reply */
+ GNUNET_break (0);
+ alucb->cb (alucb->cb_cls, NULL);
+ GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
+ GNUNET_free (alucb);
+ return;
+ }
/* expect more replies */
GNUNET_CLIENT_receive (alucb->client,
- &peer_address_response_processor, alucb,
- GNUNET_TIME_absolute_get_remaining
- (alucb->timeout));
+ &peer_address_response_processor, alucb,
+ GNUNET_TIME_absolute_get_remaining (alucb->timeout));
alucb->cb (alucb->cb_cls, address);
}
@@ -127,10 +127,12 @@
* @param peer_address_callback_cls closure for peer_address_callback
*/
void
-GNUNET_TRANSPORT_peer_address_lookup (const struct GNUNET_CONFIGURATION_Handle
*cfg,
+GNUNET_TRANSPORT_peer_address_lookup (const struct GNUNET_CONFIGURATION_Handle
+ *cfg,
const struct GNUNET_PeerIdentity *peer,
struct GNUNET_TIME_Relative timeout,
- GNUNET_TRANSPORT_AddressLookUpCallback
peer_address_callback,
+ GNUNET_TRANSPORT_AddressLookUpCallback
+ peer_address_callback,
void *peer_address_callback_cls)
{
struct PeerAddressLookupMessage msg;
@@ -139,26 +141,26 @@
client = GNUNET_CLIENT_connect ("transport", cfg);
if (client == NULL)
- {
- peer_address_callback (peer_address_callback_cls, NULL);
- return;
- }
- msg.header.size = htons (sizeof(struct PeerAddressLookupMessage));
+ {
+ peer_address_callback (peer_address_callback_cls, NULL);
+ return;
+ }
+ msg.header.size = htons (sizeof (struct PeerAddressLookupMessage));
msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PEER_ADDRESS_LOOKUP);
msg.timeout = GNUNET_TIME_relative_hton (timeout);
- memcpy(&msg.peer, peer, sizeof(struct GNUNET_PeerIdentity));
+ memcpy (&msg.peer, peer, sizeof (struct GNUNET_PeerIdentity));
peer_address_lookup_cb = GNUNET_malloc (sizeof (struct AddressLookupCtx));
peer_address_lookup_cb->cb = peer_address_callback;
peer_address_lookup_cb->cb_cls = peer_address_callback_cls;
peer_address_lookup_cb->timeout = GNUNET_TIME_relative_to_absolute (timeout);
peer_address_lookup_cb->client = client;
GNUNET_assert (GNUNET_OK ==
- GNUNET_CLIENT_transmit_and_get_response (client,
- &msg.header,
- timeout,
- GNUNET_YES,
-
&peer_address_response_processor,
-
peer_address_lookup_cb));
+ GNUNET_CLIENT_transmit_and_get_response (client,
+ &msg.header,
+ timeout,
+ GNUNET_YES,
+
&peer_address_response_processor,
+
peer_address_lookup_cb));
}
/* end of transport_api_peer_address_lookup.c */
Modified: gnunet/src/transport/wlan/byteorder.h
===================================================================
--- gnunet/src/transport/wlan/byteorder.h 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/transport/wlan/byteorder.h 2011-08-15 21:46:35 UTC (rev
16581)
@@ -16,418 +16,493 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
+ */
+
#ifndef _AIRCRACK_NG_BYTEORDER_H_
#define _AIRCRACK_NG_BYTEORDER_H_
+
+#define ___my_swab16(x) \
+ ((u_int16_t) (\
+ (((u_int16_t) (x) & (u_int16_t) 0x00ffU) << 8) | \
+ (((u_int16_t) (x) & (u_int16_t) 0xff00U) >> 8)))
+#define ___my_swab32(x) \
+ ((u_int32_t) (\
+ (((u_int32_t) (x) & (u_int32_t) 0x000000ffUL) << 24) | \
+ (((u_int32_t) (x) & (u_int32_t) 0x0000ff00UL) << 8) | \
+ (((u_int32_t) (x) & (u_int32_t) 0x00ff0000UL) >> 8) | \
+ (((u_int32_t) (x) & (u_int32_t) 0xff000000UL) >> 24)))
+#define ___my_swab64(x) \
+ ((u_int64_t) (\
+ (u_int64_t) (((u_int64_t) (x) & (u_int64_t)
+ 0x00000000000000ffULL) << 56) |
+ \
+(u_int64_t) (((u_int64_t) (x) & (u_int64_t)
+ 0x000000000000ff00ULL) << 40) |
+ \
+(u_int64_t) (((u_int64_t) (x) & (u_int64_t)
+ 0x0000000000ff0000ULL) << 24) |
+ \
+(u_int64_t) (((u_int64_t) (x) & (u_int64_t)
+ 0x00000000ff000000ULL) << 8) |
+ \
+(u_int64_t) (((u_int64_t) (x) & (u_int64_t)
+ 0x000000ff00000000ULL) >> 8) |
+ \
+(u_int64_t) (((u_int64_t) (x) & (u_int64_t)
+ 0x0000ff0000000000ULL) >> 24) |
+ \
+(u_int64_t) (((u_int64_t) (x) & (u_int64_t)
+ 0x00ff000000000000ULL) >> 40) |
+ \
+(u_int64_t) (((u_int64_t) (x) & (u_int64_t)
+ 0xff00000000000000ULL) >> 56)))
+
+
+ /*
+ * Linux
+ */
+#if defined(linux) || defined(Linux) || defined(__linux__) || defined(__linux)
|| defined(__gnu_linux__)
+#include <endian.h>
+#include <unistd.h>
+#include <stdint.h>
+
+#ifndef __int8_t_defined
+typedef uint64_t u_int64_t;
+
+typedef uint32_t u_int32_t;
+
+typedef uint16_t u_int16_t;
+
+typedef uint8_t u_int8_t;
+
- #define ___my_swab16(x) \
- ((u_int16_t)( \
- (((u_int16_t)(x) & (u_int16_t)0x00ffU) << 8) | \
- (((u_int16_t)(x) & (u_int16_t)0xff00U) >> 8) ))
- #define ___my_swab32(x) \
- ((u_int32_t)( \
- (((u_int32_t)(x) & (u_int32_t)0x000000ffUL) << 24) | \
- (((u_int32_t)(x) & (u_int32_t)0x0000ff00UL) << 8) | \
- (((u_int32_t)(x) & (u_int32_t)0x00ff0000UL) >> 8) | \
- (((u_int32_t)(x) & (u_int32_t)0xff000000UL) >> 24) ))
- #define ___my_swab64(x) \
- ((u_int64_t)( \
- (u_int64_t)(((u_int64_t)(x) &
(u_int64_t)0x00000000000000ffULL) << 56) | \
- (u_int64_t)(((u_int64_t)(x) &
(u_int64_t)0x000000000000ff00ULL) << 40) | \
- (u_int64_t)(((u_int64_t)(x) &
(u_int64_t)0x0000000000ff0000ULL) << 24) | \
- (u_int64_t)(((u_int64_t)(x) &
(u_int64_t)0x00000000ff000000ULL) << 8) | \
- (u_int64_t)(((u_int64_t)(x) &
(u_int64_t)0x000000ff00000000ULL) >> 8) | \
- (u_int64_t)(((u_int64_t)(x) &
(u_int64_t)0x0000ff0000000000ULL) >> 24) | \
- (u_int64_t)(((u_int64_t)(x) &
(u_int64_t)0x00ff000000000000ULL) >> 40) | \
- (u_int64_t)(((u_int64_t)(x) &
(u_int64_t)0xff00000000000000ULL) >> 56) ))
-
-
- /*
- * Linux
- */
- #if defined(linux) || defined(Linux) || defined(__linux__) ||
defined(__linux) || defined(__gnu_linux__)
- #include <endian.h>
- #include <unistd.h>
- #include <stdint.h>
-
- #ifndef __int8_t_defined
- typedef uint64_t u_int64_t;
- typedef uint32_t u_int32_t;
- typedef uint16_t u_int16_t;
- typedef uint8_t u_int8_t;
- #endif
-
+#endif /*
+ */
+
#ifndef htole16
-# if __BYTE_ORDER == __LITTLE_ENDIAN
-# define htobe16(x) ___my_swab16 (x)
-# define htole16(x) (x)
-# define be16toh(x) ___my_swab16 (x)
-# define le16toh(x) (x)
-
-# define htobe32(x) ___my_swab32 (x)
-# define htole32(x) (x)
-# define be32toh(x) ___my_swab32 (x)
-# define le32toh(x) (x)
-
-# define htobe64(x) ___my_swab64 (x)
-# define htole64(x) (x)
-# define be64toh(x) ___my_swab64 (x)
-# define le64toh(x) (x)
-# else
-# define htobe16(x) (x)
-# define htole16(x) ___my_swab16 (x)
-# define be16toh(x) (x)
-# define le16toh(x) ___my_swab16 (x)
-
-# define htobe32(x) (x)
-# define htole32(x) ___my_swab32 (x)
-# define be32toh(x) (x)
-# define le32toh(x) ___my_swab32 (x)
-
-# define htobe64(x) (x)
-# define htole64(x) ___my_swab64 (x)
-# define be64toh(x) (x)
-# define le64toh(x) ___my_swab64 (x)
-# endif
-#endif
-
-
-
- #endif
-
- /*
- * Cygwin
- */
- #if defined(__CYGWIN32__)
- #include <asm/byteorder.h>
- #include <unistd.h>
-
- #define __be64_to_cpu(x) ___my_swab64(x)
- #define __be32_to_cpu(x) ___my_swab32(x)
- #define __be16_to_cpu(x) ___my_swab16(x)
- #define __cpu_to_be64(x) ___my_swab64(x)
- #define __cpu_to_be32(x) ___my_swab32(x)
- #define __cpu_to_be16(x) ___my_swab16(x)
- #define __le64_to_cpu(x) (x)
- #define __le32_to_cpu(x) (x)
- #define __le16_to_cpu(x) (x)
- #define __cpu_to_le64(x) (x)
- #define __cpu_to_le32(x) (x)
- #define __cpu_to_le16(x) (x)
-
- #define AIRCRACK_NG_BYTE_ORDER_DEFINED
-
- #endif
-
- /*
- * Windows (DDK)
- */
- #if defined(__WIN__)
-
- #include <io.h>
-
- #define __be64_to_cpu(x) ___my_swab64(x)
- #define __be32_to_cpu(x) ___my_swab32(x)
- #define __be16_to_cpu(x) ___my_swab16(x)
- #define __cpu_to_be64(x) ___my_swab64(x)
- #define __cpu_to_be32(x) ___my_swab32(x)
- #define __cpu_to_be16(x) ___my_swab16(x)
- #define __le64_to_cpu(x) (x)
- #define __le32_to_cpu(x) (x)
- #define __le16_to_cpu(x) (x)
- #define __cpu_to_le64(x) (x)
- #define __cpu_to_le32(x) (x)
- #define __cpu_to_le16(x) (x)
-
- #define AIRCRACK_NG_BYTE_ORDER_DEFINED
-
- #endif
-
- /*
- * MAC (Darwin)
- */
- #if defined(__APPLE_CC__)
- #if defined(__x86_64__) && defined(__APPLE__)
-
- #include <libkern/OSByteOrder.h>
-
- #define __swab64(x) (unsigned long long)
OSSwapInt64((uint64_t)x)
- #define __swab32(x) (unsigned long)
OSSwapInt32((uint32_t)x)
- #define __swab16(x) (unsigned short)
OSSwapInt16((uint16_t)x)
- #define __be64_to_cpu(x) (unsigned long long)
OSSwapBigToHostInt64((uint64_t)x)
- #define __be32_to_cpu(x) (unsigned long)
OSSwapBigToHostInt32((uint32_t)x)
- #define __be16_to_cpu(x) (unsigned short)
OSSwapBigToHostInt16((uint16_t)x)
- #define __le64_to_cpu(x) (unsigned long long)
OSSwapLittleToHostInt64((uint64_t)x)
- #define __le32_to_cpu(x) (unsigned long)
OSSwapLittleToHostInt32((uint32_t)x)
- #define __le16_to_cpu(x) (unsigned short)
OSSwapLittleToHostInt16((uint16_t)x)
- #define __cpu_to_be64(x) (unsigned long long)
OSSwapHostToBigInt64((uint64_t)x)
- #define __cpu_to_be32(x) (unsigned long)
OSSwapHostToBigInt32((uint32_t)x)
- #define __cpu_to_be16(x) (unsigned short)
OSSwapHostToBigInt16((uint16_t)x)
- #define __cpu_to_le64(x) (unsigned long long)
OSSwapHostToLittleInt64((uint64_t)x)
- #define __cpu_to_le32(x) (unsigned long)
OSSwapHostToLittleInt32((uint32_t)x)
- #define __cpu_to_le16(x) (unsigned short)
OSSwapHostToLittleInt16((uint16_t)x)
-
- #else
-
- #include <architecture/byte_order.h>
-
- #define __swab64(x) NXSwapLongLong(x)
- #define __swab32(x) NXSwapLong(x)
- #define __swab16(x) NXSwapShort(x)
- #define __be64_to_cpu(x) NXSwapBigLongLongToHost(x)
- #define __be32_to_cpu(x) NXSwapBigLongToHost(x)
- #define __be16_to_cpu(x) NXSwapBigShortToHost(x)
- #define __le64_to_cpu(x) NXSwapLittleLongLongToHost(x)
- #define __le32_to_cpu(x) NXSwapLittleLongToHost(x)
- #define __le16_to_cpu(x) NXSwapLittleShortToHost(x)
- #define __cpu_to_be64(x) NXSwapHostLongLongToBig(x)
- #define __cpu_to_be32(x) NXSwapHostLongToBig(x)
- #define __cpu_to_be16(x) NXSwapHostShortToBig(x)
- #define __cpu_to_le64(x) NXSwapHostLongLongToLittle(x)
- #define __cpu_to_le32(x) NXSwapHostLongToLittle(x)
- #define __cpu_to_le16(x) NXSwapHostShortToLittle(x)
-
- #endif
-
- #define __LITTLE_ENDIAN 1234
- #define __BIG_ENDIAN 4321
- #define __PDP_ENDIAN 3412
- #define __BYTE_ORDER __BIG_ENDIAN
-
- #define AIRCRACK_NG_BYTE_ORDER_DEFINED
-
- #endif
-
- /*
- * Solaris
- * -------
- */
- #if defined(__sparc__) && defined(__sun__)
- #include <sys/byteorder.h>
- #include <sys/types.h>
- #include <unistd.h>
-
- #define __be64_to_cpu(x) (x)
- #define __be32_to_cpu(x) (x)
- #define __be16_to_cpu(x) (x)
- #define __cpu_to_be64(x) (x)
- #define __cpu_to_be32(x) (x)
- #define __cpu_to_be16(x) (x)
- #define __le64_to_cpu(x) ___my_swab64(x)
- #define __le32_to_cpu(x) ___my_swab32(x)
- #define __le16_to_cpu(x) ___my_swab16(x)
- #define __cpu_to_le64(x) ___my_swab64(x)
- #define __cpu_to_le32(x) ___my_swab32(x)
- #define __cpu_to_le16(x) ___my_swab16(x)
-
- typedef uint64_t u_int64_t;
- typedef uint32_t u_int32_t;
- typedef uint16_t u_int16_t;
- typedef uint8_t u_int8_t;
-
- #define AIRCRACK_NG_BYTE_ORDER_DEFINED
-
- #endif
-
- /*
- * Custom stuff
- */
- #if defined(__MACH__) && !defined(__APPLE_CC__)
- #include <libkern/OSByteOrder.h>
- #define __cpu_to_be64(x) = OSSwapHostToBigInt64(x)
- #define __cpu_to_be32(x) = OSSwapHostToBigInt32(x)
-
- #define AIRCRACK_NG_BYTE_ORDER_DEFINED
-
- #endif
-
-
- // FreeBSD
- #ifdef __FreeBSD__
- #include <machine/endian.h>
- #endif
-
- // XXX: Is there anything to include on OpenBSD/NetBSD/DragonFlyBSD/...?
-
-
- // XXX: Mac: Check
http://www.opensource.apple.com/source/CF/CF-476.18/CFByteOrder.h
- //
http://developer.apple.com/DOCUMENTATION/CoreFoundation/Reference/CFByteOrderUtils/Reference/reference.html
- // Write to apple to ask what should be used.
-
- #if defined(LITTLE_ENDIAN)
- #define AIRCRACK_NG_LITTLE_ENDIAN LITTLE_ENDIAN
- #elif defined(__LITTLE_ENDIAN)
- #define AIRCRACK_NG_LITTLE_ENDIAN __LITTLE_ENDIAN
- #elif defined(_LITTLE_ENDIAN)
- #define AIRCRACK_NG_LITTLE_ENDIAN _LITTLE_ENDIAN
- #endif
-
- #if defined(BIG_ENDIAN)
- #define AIRCRACK_NG_BIG_ENDIAN BIG_ENDIAN
- #elif defined(__BIG_ENDIAN)
- #define AIRCRACK_NG_BIG_ENDIAN __BIG_ENDIAN
- #elif defined(_BIG_ENDIAN)
- #define AIRCRACK_NG_BIG_ENDIAN _BIG_ENDIAN
- #endif
-
- #if !defined(AIRCRACK_NG_LITTLE_ENDIAN) &&
!defined(AIRCRACK_NG_BIG_ENDIAN)
- #error Impossible to determine endianness (Little or Big
endian), please contact the author.
- #endif
-
- #if defined(BYTE_ORDER)
- #if (BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN)
- #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_LITTLE_ENDIAN
- #elif (BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN)
- #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_BIG_ENDIAN
- #endif
- #elif defined(__BYTE_ORDER)
- #if (__BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN)
- #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_LITTLE_ENDIAN
- #elif (__BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN)
- #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_BIG_ENDIAN
- #endif
- #elif defined(_BYTE_ORDER)
- #if (_BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN)
- #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_LITTLE_ENDIAN
- #elif (_BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN)
- #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_BIG_ENDIAN
- #endif
- #endif
-
- #ifndef AIRCRACK_NG_BYTE_ORDER
- #error Impossible to determine endianness (Little or Big
endian), please contact the author.
- #endif
-
- #if (AIRCRACK_NG_BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN)
-
- #ifndef AIRCRACK_NG_BYTE_ORDER_DEFINED
- #define __be64_to_cpu(x) ___my_swab64(x)
- #define __be32_to_cpu(x) ___my_swab32(x)
- #define __be16_to_cpu(x) ___my_swab16(x)
- #define __cpu_to_be64(x) ___my_swab64(x)
- #define __cpu_to_be32(x) ___my_swab32(x)
- #define __cpu_to_be16(x) ___my_swab16(x)
- #define __le64_to_cpu(x) (x)
- #define __le32_to_cpu(x) (x)
- #define __le16_to_cpu(x) (x)
- #define __cpu_to_le64(x) (x)
- #define __cpu_to_le32(x) (x)
- #define __cpu_to_le16(x) (x)
- #endif
-
- #ifndef htobe16
- #define htobe16 ___my_swab16
- #endif
- #ifndef htobe32
- #define htobe32 ___my_swab32
- #endif
- #ifndef betoh16
- #define betoh16 ___my_swab16
- #endif
- #ifndef betoh32
- #define betoh32 ___my_swab32
- #endif
-
- #ifndef htole16
- #define htole16(x) (x)
- #endif
- #ifndef htole32
- #define htole32(x) (x)
- #endif
- #ifndef letoh16
- #define letoh16(x) (x)
- #endif
- #ifndef letoh32
- #define letoh32(x) (x)
- #endif
-
- #endif
-
- #if (AIRCRACK_NG_BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN)
-
- #ifndef AIRCRACK_NG_BYTE_ORDER_DEFINED
- #define __be64_to_cpu(x) (x)
- #define __be32_to_cpu(x) (x)
- #define __be16_to_cpu(x) (x)
- #define __cpu_to_be64(x) (x)
- #define __cpu_to_be32(x) (x)
- #define __cpu_to_be16(x) (x)
- #define __le64_to_cpu(x) ___my_swab64(x)
- #define __le32_to_cpu(x) ___my_swab32(x)
- #define __le16_to_cpu(x) ___my_swab16(x)
- #define __cpu_to_le64(x) ___my_swab64(x)
- #define __cpu_to_le32(x) ___my_swab32(x)
- #define __cpu_to_le16(x) ___my_swab16(x)
- #endif
-
- #ifndef htobe16
- #define htobe16(x) (x)
- #endif
- #ifndef htobe32
- #define htobe32(x) (x)
- #endif
- #ifndef betoh16
- #define betoh16(x) (x)
- #endif
- #ifndef betoh32
- #define betoh32(x) (x)
- #endif
-
- #ifndef htole16
- #define htole16 ___my_swab16
- #endif
- #ifndef htole32
- #define htole32 ___my_swab32
- #endif
- #ifndef letoh16
- #define letoh16 ___my_swab16
- #endif
- #ifndef letoh32
- #define letoh32 ___my_swab32
- #endif
-
- #endif
-
- // Common defines
- #define cpu_to_le64 __cpu_to_le64
- #define le64_to_cpu __le64_to_cpu
- #define cpu_to_le32 __cpu_to_le32
- #define le32_to_cpu __le32_to_cpu
- #define cpu_to_le16 __cpu_to_le16
- #define le16_to_cpu __le16_to_cpu
- #define cpu_to_be64 __cpu_to_be64
- #define be64_to_cpu __be64_to_cpu
- #define cpu_to_be32 __cpu_to_be32
- #define be32_to_cpu __be32_to_cpu
- #define cpu_to_be16 __cpu_to_be16
- #define be16_to_cpu __be16_to_cpu
-
- #ifndef le16toh
- #define le16toh le16_to_cpu
- #endif
- #ifndef be16toh
- #define be16toh be16_to_cpu
- #endif
- #ifndef le32toh
- #define le32toh le32_to_cpu
- #endif
- #ifndef be32toh
- #define be32toh be32_to_cpu
- #endif
-
-
- #ifndef htons
- #define htons be16_to_cpu
- #endif
- #ifndef htonl
- #define htonl cpu_to_be16
- #endif
- #ifndef ntohs
- #define ntohs cpu_to_be16
- #endif
- #ifndef ntohl
- #define ntohl cpu_to_be32
- #endif
-
-#endif
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+#define htobe16(x) ___my_swab16 (x)
+#define htole16(x) (x)
+#define be16toh(x) ___my_swab16 (x)
+#define le16toh(x) (x)
+
+#define htobe32(x) ___my_swab32 (x)
+#define htole32(x) (x)
+#define be32toh(x) ___my_swab32 (x)
+#define le32toh(x) (x)
+
+#define htobe64(x) ___my_swab64 (x)
+#define htole64(x) (x)
+#define be64toh(x) ___my_swab64 (x)
+#define le64toh(x) (x)
+#else /*
+ */
+#define htobe16(x) (x)
+#define htole16(x) ___my_swab16 (x)
+#define be16toh(x) (x)
+#define le16toh(x) ___my_swab16 (x)
+
+#define htobe32(x) (x)
+#define htole32(x) ___my_swab32 (x)
+#define be32toh(x) (x)
+#define le32toh(x) ___my_swab32 (x)
+
+#define htobe64(x) (x)
+#define htole64(x) ___my_swab64 (x)
+#define be64toh(x) (x)
+#define le64toh(x) ___my_swab64 (x)
+#endif /*
+ */
+#endif /*
+ */
+
+
+
+#endif /*
+ */
+
+ /*
+ * Cygwin
+ */
+#if defined(__CYGWIN32__)
+#include <asm/byteorder.h>
+#include <unistd.h>
+
+#define __be64_to_cpu(x) ___my_swab64(x)
+#define __be32_to_cpu(x) ___my_swab32(x)
+#define __be16_to_cpu(x) ___my_swab16(x)
+#define __cpu_to_be64(x) ___my_swab64(x)
+#define __cpu_to_be32(x) ___my_swab32(x)
+#define __cpu_to_be16(x) ___my_swab16(x)
+#define __le64_to_cpu(x) (x)
+#define __le32_to_cpu(x) (x)
+#define __le16_to_cpu(x) (x)
+#define __cpu_to_le64(x) (x)
+#define __cpu_to_le32(x) (x)
+#define __cpu_to_le16(x) (x)
+
+#define AIRCRACK_NG_BYTE_ORDER_DEFINED
+
+#endif /*
+ */
+
+ /*
+ * Windows (DDK)
+ */
+#if defined(__WIN__)
+
+#include <io.h>
+
+#define __be64_to_cpu(x) ___my_swab64(x)
+#define __be32_to_cpu(x) ___my_swab32(x)
+#define __be16_to_cpu(x) ___my_swab16(x)
+#define __cpu_to_be64(x) ___my_swab64(x)
+#define __cpu_to_be32(x) ___my_swab32(x)
+#define __cpu_to_be16(x) ___my_swab16(x)
+#define __le64_to_cpu(x) (x)
+#define __le32_to_cpu(x) (x)
+#define __le16_to_cpu(x) (x)
+#define __cpu_to_le64(x) (x)
+#define __cpu_to_le32(x) (x)
+#define __cpu_to_le16(x) (x)
+
+#define AIRCRACK_NG_BYTE_ORDER_DEFINED
+
+#endif /*
+ */
+
+ /*
+ * MAC (Darwin)
+ */
+#if defined(__APPLE_CC__)
+#if defined(__x86_64__) && defined(__APPLE__)
+
+#include <libkern/OSByteOrder.h>
+
+#define __swab64(x) (unsigned long long) OSSwapInt64((uint64_t)x)
+#define __swab32(x) (unsigned long) OSSwapInt32((uint32_t)x)
+#define __swab16(x) (unsigned short) OSSwapInt16((uint16_t)x)
+#define __be64_to_cpu(x) (unsigned long long) OSSwapBigToHostInt64((uint64_t)x)
+#define __be32_to_cpu(x) (unsigned long) OSSwapBigToHostInt32((uint32_t)x)
+#define __be16_to_cpu(x) (unsigned short) OSSwapBigToHostInt16((uint16_t)x)
+#define __le64_to_cpu(x) (unsigned long long)
OSSwapLittleToHostInt64((uint64_t)x)
+#define __le32_to_cpu(x) (unsigned long) OSSwapLittleToHostInt32((uint32_t)x)
+#define __le16_to_cpu(x) (unsigned short) OSSwapLittleToHostInt16((uint16_t)x)
+#define __cpu_to_be64(x) (unsigned long long) OSSwapHostToBigInt64((uint64_t)x)
+#define __cpu_to_be32(x) (unsigned long) OSSwapHostToBigInt32((uint32_t)x)
+#define __cpu_to_be16(x) (unsigned short) OSSwapHostToBigInt16((uint16_t)x)
+#define __cpu_to_le64(x) (unsigned long long)
OSSwapHostToLittleInt64((uint64_t)x)
+#define __cpu_to_le32(x) (unsigned long) OSSwapHostToLittleInt32((uint32_t)x)
+#define __cpu_to_le16(x) (unsigned short) OSSwapHostToLittleInt16((uint16_t)x)
+
+#else /*
+ */
+
+#include <architecture/byte_order.h>
+
+#define __swab64(x) NXSwapLongLong(x)
+#define __swab32(x) NXSwapLong(x)
+#define __swab16(x) NXSwapShort(x)
+#define __be64_to_cpu(x) NXSwapBigLongLongToHost(x)
+#define __be32_to_cpu(x) NXSwapBigLongToHost(x)
+#define __be16_to_cpu(x) NXSwapBigShortToHost(x)
+#define __le64_to_cpu(x) NXSwapLittleLongLongToHost(x)
+#define __le32_to_cpu(x) NXSwapLittleLongToHost(x)
+#define __le16_to_cpu(x) NXSwapLittleShortToHost(x)
+#define __cpu_to_be64(x) NXSwapHostLongLongToBig(x)
+#define __cpu_to_be32(x) NXSwapHostLongToBig(x)
+#define __cpu_to_be16(x) NXSwapHostShortToBig(x)
+#define __cpu_to_le64(x) NXSwapHostLongLongToLittle(x)
+#define __cpu_to_le32(x) NXSwapHostLongToLittle(x)
+#define __cpu_to_le16(x) NXSwapHostShortToLittle(x)
+
+#endif /*
+ */
+
+#define __LITTLE_ENDIAN 1234
+#define __BIG_ENDIAN 4321
+#define __PDP_ENDIAN 3412
+#define __BYTE_ORDER __BIG_ENDIAN
+
+#define AIRCRACK_NG_BYTE_ORDER_DEFINED
+
+#endif /*
+ */
+
+ /*
+ * Solaris
+ * -------
+ */
+#if defined(__sparc__) && defined(__sun__)
+#include <sys/byteorder.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#define __be64_to_cpu(x) (x)
+#define __be32_to_cpu(x) (x)
+#define __be16_to_cpu(x) (x)
+#define __cpu_to_be64(x) (x)
+#define __cpu_to_be32(x) (x)
+#define __cpu_to_be16(x) (x)
+#define __le64_to_cpu(x) ___my_swab64(x)
+#define __le32_to_cpu(x) ___my_swab32(x)
+#define __le16_to_cpu(x) ___my_swab16(x)
+#define __cpu_to_le64(x) ___my_swab64(x)
+#define __cpu_to_le32(x) ___my_swab32(x)
+#define __cpu_to_le16(x) ___my_swab16(x)
+
+typedef uint64_t u_int64_t;
+
+typedef uint32_t u_int32_t;
+
+typedef uint16_t u_int16_t;
+
+typedef uint8_t u_int8_t;
+
+
+
+#define AIRCRACK_NG_BYTE_ORDER_DEFINED
+
+#endif /*
+ */
+
+ /*
+ * Custom stuff
+ */
+#if defined(__MACH__) && !defined(__APPLE_CC__)
+#include <libkern/OSByteOrder.h>
+#define __cpu_to_be64(x) = OSSwapHostToBigInt64(x)
+#define __cpu_to_be32(x) = OSSwapHostToBigInt32(x)
+
+#define AIRCRACK_NG_BYTE_ORDER_DEFINED
+
+#endif /*
+ */
+
+
+ // FreeBSD
+#ifdef __FreeBSD__
+#include <machine/endian.h>
+#endif /*
+ */
+
+ // XXX: Is there anything to include on OpenBSD/NetBSD/DragonFlyBSD/...?
+
+
+ // XXX: Mac: Check
http://www.opensource.apple.com/source/CF/CF-476.18/CFByteOrder.h
+ //
http://developer.apple.com/DOCUMENTATION/CoreFoundation/Reference/CFByteOrderUtils/Reference/reference.html
+ // Write to apple to ask what should be used.
+
+#if defined(LITTLE_ENDIAN)
+#define AIRCRACK_NG_LITTLE_ENDIAN LITTLE_ENDIAN
+#elif defined(__LITTLE_ENDIAN)
+#define AIRCRACK_NG_LITTLE_ENDIAN __LITTLE_ENDIAN
+#elif defined(_LITTLE_ENDIAN)
+#define AIRCRACK_NG_LITTLE_ENDIAN _LITTLE_ENDIAN
+#endif /*
+ */
+
+#if defined(BIG_ENDIAN)
+#define AIRCRACK_NG_BIG_ENDIAN BIG_ENDIAN
+#elif defined(__BIG_ENDIAN)
+#define AIRCRACK_NG_BIG_ENDIAN __BIG_ENDIAN
+#elif defined(_BIG_ENDIAN)
+#define AIRCRACK_NG_BIG_ENDIAN _BIG_ENDIAN
+#endif /*
+ */
+
+#if !defined(AIRCRACK_NG_LITTLE_ENDIAN) && !defined(AIRCRACK_NG_BIG_ENDIAN)
+#error Impossible to determine endianness (Little or Big endian), please
contact the author.
+#endif /*
+ */
+
+#if defined(BYTE_ORDER)
+#if (BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN)
+#define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_LITTLE_ENDIAN
+#elif (BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN)
+#define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_BIG_ENDIAN
+#endif /*
+ */
+#elif defined(__BYTE_ORDER)
+#if (__BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN)
+#define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_LITTLE_ENDIAN
+#elif (__BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN)
+#define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_BIG_ENDIAN
+#endif /*
+ */
+#elif defined(_BYTE_ORDER)
+#if (_BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN)
+#define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_LITTLE_ENDIAN
+#elif (_BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN)
+#define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_BIG_ENDIAN
+#endif /*
+ */
+#endif /*
+ */
+
+#ifndef AIRCRACK_NG_BYTE_ORDER
+#error Impossible to determine endianness (Little or Big endian), please
contact the author.
+#endif /*
+ */
+
+#if (AIRCRACK_NG_BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN)
+
+#ifndef AIRCRACK_NG_BYTE_ORDER_DEFINED
+#define __be64_to_cpu(x) ___my_swab64(x)
+#define __be32_to_cpu(x) ___my_swab32(x)
+#define __be16_to_cpu(x) ___my_swab16(x)
+#define __cpu_to_be64(x) ___my_swab64(x)
+#define __cpu_to_be32(x) ___my_swab32(x)
+#define __cpu_to_be16(x) ___my_swab16(x)
+#define __le64_to_cpu(x) (x)
+#define __le32_to_cpu(x) (x)
+#define __le16_to_cpu(x) (x)
+#define __cpu_to_le64(x) (x)
+#define __cpu_to_le32(x) (x)
+#define __cpu_to_le16(x) (x)
+#endif /*
+ */
+
+#ifndef htobe16
+#define htobe16 ___my_swab16
+#endif /*
+ */
+#ifndef htobe32
+#define htobe32 ___my_swab32
+#endif /*
+ */
+#ifndef betoh16
+#define betoh16 ___my_swab16
+#endif /*
+ */
+#ifndef betoh32
+#define betoh32 ___my_swab32
+#endif /*
+ */
+
+#ifndef htole16
+#define htole16(x) (x)
+#endif /*
+ */
+#ifndef htole32
+#define htole32(x) (x)
+#endif /*
+ */
+#ifndef letoh16
+#define letoh16(x) (x)
+#endif /*
+ */
+#ifndef letoh32
+#define letoh32(x) (x)
+#endif /*
+ */
+
+#endif /*
+ */
+
+#if (AIRCRACK_NG_BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN)
+
+#ifndef AIRCRACK_NG_BYTE_ORDER_DEFINED
+#define __be64_to_cpu(x) (x)
+#define __be32_to_cpu(x) (x)
+#define __be16_to_cpu(x) (x)
+#define __cpu_to_be64(x) (x)
+#define __cpu_to_be32(x) (x)
+#define __cpu_to_be16(x) (x)
+#define __le64_to_cpu(x) ___my_swab64(x)
+#define __le32_to_cpu(x) ___my_swab32(x)
+#define __le16_to_cpu(x) ___my_swab16(x)
+#define __cpu_to_le64(x) ___my_swab64(x)
+#define __cpu_to_le32(x) ___my_swab32(x)
+#define __cpu_to_le16(x) ___my_swab16(x)
+#endif /*
+ */
+
+#ifndef htobe16
+#define htobe16(x) (x)
+#endif /*
+ */
+#ifndef htobe32
+#define htobe32(x) (x)
+#endif /*
+ */
+#ifndef betoh16
+#define betoh16(x) (x)
+#endif /*
+ */
+#ifndef betoh32
+#define betoh32(x) (x)
+#endif /*
+ */
+
+#ifndef htole16
+#define htole16 ___my_swab16
+#endif /*
+ */
+#ifndef htole32
+#define htole32 ___my_swab32
+#endif /*
+ */
+#ifndef letoh16
+#define letoh16 ___my_swab16
+#endif /*
+ */
+#ifndef letoh32
+#define letoh32 ___my_swab32
+#endif /*
+ */
+
+#endif /*
+ */
+
+ // Common defines
+#define cpu_to_le64 __cpu_to_le64
+#define le64_to_cpu __le64_to_cpu
+#define cpu_to_le32 __cpu_to_le32
+#define le32_to_cpu __le32_to_cpu
+#define cpu_to_le16 __cpu_to_le16
+#define le16_to_cpu __le16_to_cpu
+#define cpu_to_be64 __cpu_to_be64
+#define be64_to_cpu __be64_to_cpu
+#define cpu_to_be32 __cpu_to_be32
+#define be32_to_cpu __be32_to_cpu
+#define cpu_to_be16 __cpu_to_be16
+#define be16_to_cpu __be16_to_cpu
+
+#ifndef le16toh
+#define le16toh le16_to_cpu
+#endif /*
+ */
+#ifndef be16toh
+#define be16toh be16_to_cpu
+#endif /*
+ */
+#ifndef le32toh
+#define le32toh le32_to_cpu
+#endif /*
+ */
+#ifndef be32toh
+#define be32toh be32_to_cpu
+#endif /*
+ */
+
+
+#ifndef htons
+#define htons be16_to_cpu
+#endif /*
+ */
+#ifndef htonl
+#define htonl cpu_to_be16
+#endif /*
+ */
+#ifndef ntohs
+#define ntohs cpu_to_be16
+#endif /*
+ */
+#ifndef ntohl
+#define ntohl cpu_to_be32
+#endif /*
+ */
+
+#endif /*
+ */
Modified: gnunet/src/transport/wlan/crctable_osdep.h
===================================================================
--- gnunet/src/transport/wlan/crctable_osdep.h 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/transport/wlan/crctable_osdep.h 2011-08-15 21:46:35 UTC (rev
16581)
@@ -1,40 +1,71 @@
#ifndef _CRCTABLE_OSDEP_H
#define _CRCTABLE_OSDEP_H
-const unsigned long int crc_tbl_osdep[256] =
-{
- 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F,
0xE963A535, 0x9E6495A3,
- 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD,
0xE7B82D07, 0x90BF1D91,
- 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB,
0xF4D4B551, 0x83D385C7,
- 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9,
0xFA0F3D63, 0x8D080DF5,
- 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, 0x3C03E4D1, 0x4B04D447,
0xD20D85FD, 0xA50AB56B,
- 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75,
0xDCD60DCF, 0xABD13D59,
- 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423,
0xCFBA9599, 0xB8BDA50F,
- 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11,
0xC1611DAB, 0xB6662D3D,
- 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F,
0x9FBFE4A5, 0xE8B8D433,
- 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D,
0x91646C97, 0xE6635C01,
- 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED, 0x1B01A57B,
0x8208F4C1, 0xF50FC457,
- 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49,
0x8CD37CF3, 0xFBD44C65,
- 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7,
0xA4D1C46D, 0xD3D6F4FB,
- 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5,
0xAA0A4C5F, 0xDD0D7CC9,
- 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3,
0xB966D409, 0xCE61E49F,
- 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81,
0xB7BD5C3B, 0xC0BA6CAD,
- 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF,
0x04DB2615, 0x73DC1683,
- 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D,
0x0A00AE27, 0x7D079EB1,
- 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB,
0x196C3671, 0x6E6B06E7,
- 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9,
0x17B7BE43, 0x60B08ED5,
- 0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767,
0x3FB506DD, 0x48B2364B,
- 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55,
0x316E8EEF, 0x4669BE79,
- 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 0xCC0C7795, 0xBB0B4703,
0x220216B9, 0x5505262F,
- 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31,
0x2CD99E8B, 0x5BDEAE1D,
- 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F,
0x72076785, 0x05005713,
- 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D,
0x7CDCEFB7, 0x0BDBDF21,
- 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B,
0x6FB077E1, 0x18B74777,
- 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69,
0x616BFFD3, 0x166CCF45,
- 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7,
0x4969474D, 0x3E6E77DB,
- 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5,
0x47B2CF7F, 0x30B5FFE9,
- 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693,
0x54DE5729, 0x23D967BF,
- 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1,
0x5A05DF1B, 0x2D02EF8D
+const unsigned long int crc_tbl_osdep[256] = {
+ 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F,
+ 0xE963A535, 0x9E6495A3,
+ 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD,
+ 0xE7B82D07, 0x90BF1D91,
+ 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB,
+ 0xF4D4B551, 0x83D385C7,
+ 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9,
+ 0xFA0F3D63, 0x8D080DF5,
+ 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, 0x3C03E4D1, 0x4B04D447,
+ 0xD20D85FD, 0xA50AB56B,
+ 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75,
+ 0xDCD60DCF, 0xABD13D59,
+ 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423,
+ 0xCFBA9599, 0xB8BDA50F,
+ 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11,
+ 0xC1611DAB, 0xB6662D3D,
+ 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F,
+ 0x9FBFE4A5, 0xE8B8D433,
+ 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D,
+ 0x91646C97, 0xE6635C01,
+ 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED, 0x1B01A57B,
+ 0x8208F4C1, 0xF50FC457,
+ 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49,
+ 0x8CD37CF3, 0xFBD44C65,
+ 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7,
+ 0xA4D1C46D, 0xD3D6F4FB,
+ 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5,
+ 0xAA0A4C5F, 0xDD0D7CC9,
+ 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3,
+ 0xB966D409, 0xCE61E49F,
+ 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81,
+ 0xB7BD5C3B, 0xC0BA6CAD,
+ 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF,
+ 0x04DB2615, 0x73DC1683,
+ 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D,
+ 0x0A00AE27, 0x7D079EB1,
+ 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB,
+ 0x196C3671, 0x6E6B06E7,
+ 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9,
+ 0x17B7BE43, 0x60B08ED5,
+ 0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767,
+ 0x3FB506DD, 0x48B2364B,
+ 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55,
+ 0x316E8EEF, 0x4669BE79,
+ 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 0xCC0C7795, 0xBB0B4703,
+ 0x220216B9, 0x5505262F,
+ 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31,
+ 0x2CD99E8B, 0x5BDEAE1D,
+ 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F,
+ 0x72076785, 0x05005713,
+ 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D,
+ 0x7CDCEFB7, 0x0BDBDF21,
+ 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B,
+ 0x6FB077E1, 0x18B74777,
+ 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69,
+ 0x616BFFD3, 0x166CCF45,
+ 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7,
+ 0x4969474D, 0x3E6E77DB,
+ 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5,
+ 0x47B2CF7F, 0x30B5FFE9,
+ 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693,
+ 0x54DE5729, 0x23D967BF,
+ 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1,
+ 0x5A05DF1B, 0x2D02EF8D
};
#endif /* crctable_osdep.h */
Modified: gnunet/src/transport/wlan/helper_common.c
===================================================================
--- gnunet/src/transport/wlan/helper_common.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/transport/wlan/helper_common.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -34,17 +34,17 @@
* @return number of bytes written
*/
int
-send_mac_to_plugin(char * buffer, uint8_t * mac)
+send_mac_to_plugin (char *buffer, uint8_t * mac)
{
struct Wlan_Helper_Control_Message macmsg;
- memcpy(macmsg.mac.mac, mac, sizeof(struct MacAddress));
- macmsg.hdr.size = htons(sizeof(struct Wlan_Helper_Control_Message));
- macmsg.hdr.type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL);
+ memcpy (macmsg.mac.mac, mac, sizeof (struct MacAddress));
+ macmsg.hdr.size = htons (sizeof (struct Wlan_Helper_Control_Message));
+ macmsg.hdr.type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL);
- memcpy(buffer, &macmsg, sizeof(struct Wlan_Helper_Control_Message));
- return sizeof(struct Wlan_Helper_Control_Message);
+ memcpy (buffer, &macmsg, sizeof (struct Wlan_Helper_Control_Message));
+ return sizeof (struct Wlan_Helper_Control_Message);
}
/*
@@ -70,40 +70,54 @@
/**
* Return the frequency in Mhz from a channel number
*/
-int getFrequencyFromChannel(int channel)
+int
+getFrequencyFromChannel (int channel)
{
- static int frequencies[] = {
- -1, // No channel 0
- 2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, 2452, 2457,
2462, 2467, 2472, 2484,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, // Nothing from channel 15 to 34 (exclusive)
- 5170, 5175, 5180, 5185, 5190, 5195, 5200, 5205, 5210, 5215,
5220, 5225, 5230, 5235, 5240, 5245,
- 5250, 5255, 5260, 5265, 5270, 5275, 5280, 5285, 5290, 5295,
5300, 5305, 5310, 5315, 5320, 5325,
- 5330, 5335, 5340, 5345, 5350, 5355, 5360, 5365, 5370, 5375,
5380, 5385, 5390, 5395, 5400, 5405,
- 5410, 5415, 5420, 5425, 5430, 5435, 5440, 5445, 5450, 5455,
5460, 5465, 5470, 5475, 5480, 5485,
- 5490, 5495, 5500, 5505, 5510, 5515, 5520, 5525, 5530, 5535,
5540, 5545, 5550, 5555, 5560, 5565,
- 5570, 5575, 5580, 5585, 5590, 5595, 5600, 5605, 5610, 5615,
5620, 5625, 5630, 5635, 5640, 5645,
- 5650, 5655, 5660, 5665, 5670, 5675, 5680, 5685, 5690, 5695,
5700, 5705, 5710, 5715, 5720, 5725,
- 5730, 5735, 5740, 5745, 5750, 5755, 5760, 5765, 5770, 5775,
5780, 5785, 5790, 5795, 5800, 5805,
- 5810, 5815, 5820, 5825, 5830, 5835, 5840, 5845, 5850, 5855,
5860, 5865, 5870, 5875, 5880, 5885,
- 5890, 5895, 5900, 5905, 5910, 5915, 5920, 5925, 5930, 5935,
5940, 5945, 5950, 5955, 5960, 5965,
- 5970, 5975, 5980, 5985, 5990, 5995, 6000, 6005, 6010, 6015,
6020, 6025, 6030, 6035, 6040, 6045,
- 6050, 6055, 6060, 6065, 6070, 6075, 6080, 6085, 6090, 6095,
6100
- };
+ static int frequencies[] = {
+ -1, // No channel 0
+ 2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, 2452, 2457, 2462, 2467,
+ 2472, 2484,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, // Nothing from channel 15 to 34 (exclusive)
+ 5170, 5175, 5180, 5185, 5190, 5195, 5200, 5205, 5210, 5215, 5220, 5225,
+ 5230, 5235, 5240, 5245,
+ 5250, 5255, 5260, 5265, 5270, 5275, 5280, 5285, 5290, 5295, 5300, 5305,
+ 5310, 5315, 5320, 5325,
+ 5330, 5335, 5340, 5345, 5350, 5355, 5360, 5365, 5370, 5375, 5380, 5385,
+ 5390, 5395, 5400, 5405,
+ 5410, 5415, 5420, 5425, 5430, 5435, 5440, 5445, 5450, 5455, 5460, 5465,
+ 5470, 5475, 5480, 5485,
+ 5490, 5495, 5500, 5505, 5510, 5515, 5520, 5525, 5530, 5535, 5540, 5545,
+ 5550, 5555, 5560, 5565,
+ 5570, 5575, 5580, 5585, 5590, 5595, 5600, 5605, 5610, 5615, 5620, 5625,
+ 5630, 5635, 5640, 5645,
+ 5650, 5655, 5660, 5665, 5670, 5675, 5680, 5685, 5690, 5695, 5700, 5705,
+ 5710, 5715, 5720, 5725,
+ 5730, 5735, 5740, 5745, 5750, 5755, 5760, 5765, 5770, 5775, 5780, 5785,
+ 5790, 5795, 5800, 5805,
+ 5810, 5815, 5820, 5825, 5830, 5835, 5840, 5845, 5850, 5855, 5860, 5865,
+ 5870, 5875, 5880, 5885,
+ 5890, 5895, 5900, 5905, 5910, 5915, 5920, 5925, 5930, 5935, 5940, 5945,
+ 5950, 5955, 5960, 5965,
+ 5970, 5975, 5980, 5985, 5990, 5995, 6000, 6005, 6010, 6015, 6020, 6025,
+ 6030, 6035, 6040, 6045,
+ 6050, 6055, 6060, 6065, 6070, 6075, 6080, 6085, 6090, 6095, 6100
+ };
- return (channel > 0 && channel <= 221) ? frequencies[channel] : -1;
+ return (channel > 0 && channel <= 221) ? frequencies[channel] : -1;
}
/**
* Return the channel from the frequency (in Mhz)
*/
-int getChannelFromFrequency(int frequency)
+int
+getChannelFromFrequency (int frequency)
{
- if (frequency >= 2412 && frequency <= 2472)
- return (frequency - 2407) / 5;
- else if (frequency == 2484)
- return 14;
- else if (frequency >= 5000 && frequency <= 6100)
- return (frequency - 5000) / 5;
- else
- return -1;
+ if (frequency >= 2412 && frequency <= 2472)
+ return (frequency - 2407) / 5;
+ else if (frequency == 2484)
+ return 14;
+ else if (frequency >= 5000 && frequency <= 6100)
+ return (frequency - 5000) / 5;
+ else
+ return -1;
}
Modified: gnunet/src/transport/wlan/helper_common.h
===================================================================
--- gnunet/src/transport/wlan/helper_common.h 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/transport/wlan/helper_common.h 2011-08-15 21:46:35 UTC (rev
16581)
@@ -8,8 +8,8 @@
#ifndef HELPER_COMMON_H_
#define HELPER_COMMON_H_
-int getFrequencyFromChannel(int channel);
-int getChannelFromFrequency(int frequency);
-int send_mac_to_plugin(char * buffer, uint8_t * mac);
+int getFrequencyFromChannel (int channel);
+int getChannelFromFrequency (int frequency);
+int send_mac_to_plugin (char *buffer, uint8_t * mac);
#endif /* HELPER_COMMON_H_ */
Modified: gnunet/src/transport/wlan/ieee80211.h
===================================================================
--- gnunet/src/transport/wlan/ieee80211.h 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/transport/wlan/ieee80211.h 2011-08-15 21:46:35 UTC (rev
16581)
@@ -38,72 +38,78 @@
* 802.11 protocol definitions.
*/
-#define IEEE80211_ADDR_LEN 6 /* size of 802.11
address */
+#define IEEE80211_ADDR_LEN 6 /* size of 802.11 address */
/* is 802.11 address multicast/broadcast? */
#define IEEE80211_IS_MULTICAST(_a) (*(_a) & 0x01)
/* IEEE 802.11 PLCP header */
-struct ieee80211_plcp_hdr {
- u_int16_t i_sfd;
- u_int8_t i_signal;
- u_int8_t i_service;
- u_int16_t i_length;
- u_int16_t i_crc;
+struct ieee80211_plcp_hdr
+{
+ u_int16_t i_sfd;
+ u_int8_t i_signal;
+ u_int8_t i_service;
+ u_int16_t i_length;
+ u_int16_t i_crc;
} GNUNET_PACKED;
-#define IEEE80211_PLCP_SFD 0xF3A0
+#define IEEE80211_PLCP_SFD 0xF3A0
#define IEEE80211_PLCP_SERVICE 0x00
/*
* generic definitions for IEEE 802.11 frames
*/
-struct ieee80211_frame {
- u_int8_t i_fc[2];
- u_int8_t i_dur[2];
- u_int8_t i_addr1[IEEE80211_ADDR_LEN];
- u_int8_t i_addr2[IEEE80211_ADDR_LEN];
- u_int8_t i_addr3[IEEE80211_ADDR_LEN];
- u_int8_t i_seq[2];
- /* possibly followed by addr4[IEEE80211_ADDR_LEN]; */
- /* see below */
+struct ieee80211_frame
+{
+ u_int8_t i_fc[2];
+ u_int8_t i_dur[2];
+ u_int8_t i_addr1[IEEE80211_ADDR_LEN];
+ u_int8_t i_addr2[IEEE80211_ADDR_LEN];
+ u_int8_t i_addr3[IEEE80211_ADDR_LEN];
+ u_int8_t i_seq[2];
+ /* possibly followed by addr4[IEEE80211_ADDR_LEN]; */
+ /* see below */
} GNUNET_PACKED;
-struct ieee80211_qosframe {
- u_int8_t i_fc[2];
- u_int8_t i_dur[2];
- u_int8_t i_addr1[IEEE80211_ADDR_LEN];
- u_int8_t i_addr2[IEEE80211_ADDR_LEN];
- u_int8_t i_addr3[IEEE80211_ADDR_LEN];
- u_int8_t i_seq[2];
- u_int8_t i_qos[2];
- /* possibly followed by addr4[IEEE80211_ADDR_LEN]; */
- /* see below */
+struct ieee80211_qosframe
+{
+ u_int8_t i_fc[2];
+ u_int8_t i_dur[2];
+ u_int8_t i_addr1[IEEE80211_ADDR_LEN];
+ u_int8_t i_addr2[IEEE80211_ADDR_LEN];
+ u_int8_t i_addr3[IEEE80211_ADDR_LEN];
+ u_int8_t i_seq[2];
+ u_int8_t i_qos[2];
+ /* possibly followed by addr4[IEEE80211_ADDR_LEN]; */
+ /* see below */
} GNUNET_PACKED;
-struct ieee80211_qoscntl {
- u_int8_t i_qos[2];
+struct ieee80211_qoscntl
+{
+ u_int8_t i_qos[2];
};
-struct ieee80211_frame_addr4 {
- u_int8_t i_fc[2];
- u_int8_t i_dur[2];
- u_int8_t i_addr1[IEEE80211_ADDR_LEN];
- u_int8_t i_addr2[IEEE80211_ADDR_LEN];
- u_int8_t i_addr3[IEEE80211_ADDR_LEN];
- u_int8_t i_seq[2];
- u_int8_t i_addr4[IEEE80211_ADDR_LEN];
+struct ieee80211_frame_addr4
+{
+ u_int8_t i_fc[2];
+ u_int8_t i_dur[2];
+ u_int8_t i_addr1[IEEE80211_ADDR_LEN];
+ u_int8_t i_addr2[IEEE80211_ADDR_LEN];
+ u_int8_t i_addr3[IEEE80211_ADDR_LEN];
+ u_int8_t i_seq[2];
+ u_int8_t i_addr4[IEEE80211_ADDR_LEN];
} GNUNET_PACKED;
-struct ieee80211_qosframe_addr4 {
- u_int8_t i_fc[2];
- u_int8_t i_dur[2];
- u_int8_t i_addr1[IEEE80211_ADDR_LEN];
- u_int8_t i_addr2[IEEE80211_ADDR_LEN];
- u_int8_t i_addr3[IEEE80211_ADDR_LEN];
- u_int8_t i_seq[2];
- u_int8_t i_addr4[IEEE80211_ADDR_LEN];
- u_int8_t i_qos[2];
+struct ieee80211_qosframe_addr4
+{
+ u_int8_t i_fc[2];
+ u_int8_t i_dur[2];
+ u_int8_t i_addr1[IEEE80211_ADDR_LEN];
+ u_int8_t i_addr2[IEEE80211_ADDR_LEN];
+ u_int8_t i_addr3[IEEE80211_ADDR_LEN];
+ u_int8_t i_seq[2];
+ u_int8_t i_addr4[IEEE80211_ADDR_LEN];
+ u_int8_t i_qos[2];
} GNUNET_PACKED;
#define IEEE80211_FC0_VERSION_MASK 0x03
@@ -149,10 +155,10 @@
#define IEEE80211_FC0_SUBTYPE_QOS_NULL 0xc0
#define IEEE80211_FC1_DIR_MASK 0x03
-#define IEEE80211_FC1_DIR_NODS 0x00 /* STA->STA */
-#define IEEE80211_FC1_DIR_TODS 0x01 /* STA->AP */
-#define IEEE80211_FC1_DIR_FROMDS 0x02 /* AP ->STA */
-#define IEEE80211_FC1_DIR_DSTODS 0x03 /* AP ->AP */
+#define IEEE80211_FC1_DIR_NODS 0x00 /* STA->STA */
+#define IEEE80211_FC1_DIR_TODS 0x01 /* STA->AP */
+#define IEEE80211_FC1_DIR_FROMDS 0x02 /* AP ->STA */
+#define IEEE80211_FC1_DIR_DSTODS 0x03 /* AP ->AP */
#define IEEE80211_FC1_MORE_FRAG 0x04
#define IEEE80211_FC1_RETRY 0x08
@@ -185,65 +191,68 @@
/*
* WME/802.11e information element.
*/
-struct ieee80211_wme_info {
- u_int8_t wme_id; /* IEEE80211_ELEMID_VENDOR */
- u_int8_t wme_len; /* length in bytes */
- u_int8_t wme_oui[3]; /* 0x00, 0x50, 0xf2 */
- u_int8_t wme_type; /* OUI type */
- u_int8_t wme_subtype; /* OUI subtype */
- u_int8_t wme_version; /* spec revision */
- u_int8_t wme_info; /* QoS info */
+struct ieee80211_wme_info
+{
+ u_int8_t wme_id; /* IEEE80211_ELEMID_VENDOR */
+ u_int8_t wme_len; /* length in bytes */
+ u_int8_t wme_oui[3]; /* 0x00, 0x50, 0xf2 */
+ u_int8_t wme_type; /* OUI type */
+ u_int8_t wme_subtype; /* OUI subtype */
+ u_int8_t wme_version; /* spec revision */
+ u_int8_t wme_info; /* QoS info */
} GNUNET_PACKED;
/*
* WME/802.11e Tspec Element
*/
-struct ieee80211_wme_tspec {
- u_int8_t ts_id;
- u_int8_t ts_len;
- u_int8_t ts_oui[3];
- u_int8_t ts_oui_type;
- u_int8_t ts_oui_subtype;
- u_int8_t ts_version;
- u_int8_t ts_tsinfo[3];
- u_int8_t ts_nom_msdu[2];
- u_int8_t ts_max_msdu[2];
- u_int8_t ts_min_svc[4];
- u_int8_t ts_max_svc[4];
- u_int8_t ts_inactv_intv[4];
- u_int8_t ts_susp_intv[4];
- u_int8_t ts_start_svc[4];
- u_int8_t ts_min_rate[4];
- u_int8_t ts_mean_rate[4];
- u_int8_t ts_max_burst[4];
- u_int8_t ts_min_phy[4];
- u_int8_t ts_peak_rate[4];
- u_int8_t ts_delay[4];
- u_int8_t ts_surplus[2];
- u_int8_t ts_medium_time[2];
+struct ieee80211_wme_tspec
+{
+ u_int8_t ts_id;
+ u_int8_t ts_len;
+ u_int8_t ts_oui[3];
+ u_int8_t ts_oui_type;
+ u_int8_t ts_oui_subtype;
+ u_int8_t ts_version;
+ u_int8_t ts_tsinfo[3];
+ u_int8_t ts_nom_msdu[2];
+ u_int8_t ts_max_msdu[2];
+ u_int8_t ts_min_svc[4];
+ u_int8_t ts_max_svc[4];
+ u_int8_t ts_inactv_intv[4];
+ u_int8_t ts_susp_intv[4];
+ u_int8_t ts_start_svc[4];
+ u_int8_t ts_min_rate[4];
+ u_int8_t ts_mean_rate[4];
+ u_int8_t ts_max_burst[4];
+ u_int8_t ts_min_phy[4];
+ u_int8_t ts_peak_rate[4];
+ u_int8_t ts_delay[4];
+ u_int8_t ts_surplus[2];
+ u_int8_t ts_medium_time[2];
} GNUNET_PACKED;
/*
* WME AC parameter field
*/
-struct ieee80211_wme_acparams {
- u_int8_t acp_aci_aifsn;
- u_int8_t acp_logcwminmax;
- u_int16_t acp_txop;
+struct ieee80211_wme_acparams
+{
+ u_int8_t acp_aci_aifsn;
+ u_int8_t acp_logcwminmax;
+ u_int16_t acp_txop;
} GNUNET_PACKED;
-#define WME_NUM_AC 4 /* 4 AC categories */
+#define WME_NUM_AC 4 /* 4 AC categories */
-#define WME_PARAM_ACI 0x60 /* Mask for ACI field */
-#define WME_PARAM_ACI_S 5 /* Shift for ACI field */
-#define WME_PARAM_ACM 0x10 /* Mask for ACM bit */
-#define WME_PARAM_ACM_S 4 /* Shift for ACM bit */
-#define WME_PARAM_AIFSN 0x0f /* Mask for aifsn field */
-#define WME_PARAM_AIFSN_S 0 /* Shift for aifsn field */
-#define WME_PARAM_LOGCWMIN 0x0f /* Mask for CwMin field (in log) */
-#define WME_PARAM_LOGCWMIN_S 0 /* Shift for CwMin field */
-#define WME_PARAM_LOGCWMAX 0xf0 /* Mask for CwMax field (in log) */
-#define WME_PARAM_LOGCWMAX_S 4 /* Shift for CwMax field */
+#define WME_PARAM_ACI 0x60 /* Mask for ACI field */
+#define WME_PARAM_ACI_S 5 /* Shift for ACI field */
+#define WME_PARAM_ACM 0x10 /* Mask for ACM bit */
+#define WME_PARAM_ACM_S 4 /* Shift for ACM bit */
+#define WME_PARAM_AIFSN 0x0f /* Mask for aifsn field */
+#define WME_PARAM_AIFSN_S 0 /* Shift for aifsn field */
+#define WME_PARAM_LOGCWMIN 0x0f /* Mask for CwMin field (in log) */
+#define WME_PARAM_LOGCWMIN_S 0 /* Shift for CwMin field */
+#define WME_PARAM_LOGCWMAX 0xf0 /* Mask for CwMax field (in log) */
+#define WME_PARAM_LOGCWMAX_S 4 /* Shift for CwMax field */
#define WME_AC_TO_TID(_ac) ( \
((_ac) == WME_AC_VO) ? 6 : \
@@ -260,28 +269,31 @@
/*
* WME Parameter Element
*/
-struct ieee80211_wme_param {
- u_int8_t param_id;
- u_int8_t param_len;
- u_int8_t param_oui[3];
- u_int8_t param_oui_type;
- u_int8_t param_oui_sybtype;
- u_int8_t param_version;
- u_int8_t param_qosInfo;
-#define WME_QOSINFO_COUNT 0x0f /* Mask for param count field */
- u_int8_t param_reserved;
- struct ieee80211_wme_acparams params_acParams[WME_NUM_AC];
+struct ieee80211_wme_param
+{
+ u_int8_t param_id;
+ u_int8_t param_len;
+ u_int8_t param_oui[3];
+ u_int8_t param_oui_type;
+ u_int8_t param_oui_sybtype;
+ u_int8_t param_version;
+ u_int8_t param_qosInfo;
+#define WME_QOSINFO_COUNT 0x0f /* Mask for param count field */
+ u_int8_t param_reserved;
+ struct ieee80211_wme_acparams params_acParams[WME_NUM_AC];
} GNUNET_PACKED;
/*
* Management Notification Frame
*/
-struct ieee80211_mnf {
- u_int8_t mnf_category;
- u_int8_t mnf_action;
- u_int8_t mnf_dialog;
- u_int8_t mnf_status;
+struct ieee80211_mnf
+{
+ u_int8_t mnf_category;
+ u_int8_t mnf_action;
+ u_int8_t mnf_dialog;
+ u_int8_t mnf_status;
} GNUNET_PACKED;
+
#define MNF_SETUP_REQ 0
#define MNF_SETUP_RESP 1
#define MNF_TEARDOWN 2
@@ -289,50 +301,56 @@
/*
* Control frames.
*/
-struct ieee80211_frame_min {
- u_int8_t i_fc[2];
- u_int8_t i_dur[2];
- u_int8_t i_addr1[IEEE80211_ADDR_LEN];
- u_int8_t i_addr2[IEEE80211_ADDR_LEN];
- /* FCS */
+struct ieee80211_frame_min
+{
+ u_int8_t i_fc[2];
+ u_int8_t i_dur[2];
+ u_int8_t i_addr1[IEEE80211_ADDR_LEN];
+ u_int8_t i_addr2[IEEE80211_ADDR_LEN];
+ /* FCS */
} GNUNET_PACKED;
-struct ieee80211_frame_rts {
- u_int8_t i_fc[2];
- u_int8_t i_dur[2];
- u_int8_t i_ra[IEEE80211_ADDR_LEN];
- u_int8_t i_ta[IEEE80211_ADDR_LEN];
- /* FCS */
+struct ieee80211_frame_rts
+{
+ u_int8_t i_fc[2];
+ u_int8_t i_dur[2];
+ u_int8_t i_ra[IEEE80211_ADDR_LEN];
+ u_int8_t i_ta[IEEE80211_ADDR_LEN];
+ /* FCS */
} GNUNET_PACKED;
-struct ieee80211_frame_cts {
- u_int8_t i_fc[2];
- u_int8_t i_dur[2];
- u_int8_t i_ra[IEEE80211_ADDR_LEN];
- /* FCS */
+struct ieee80211_frame_cts
+{
+ u_int8_t i_fc[2];
+ u_int8_t i_dur[2];
+ u_int8_t i_ra[IEEE80211_ADDR_LEN];
+ /* FCS */
} GNUNET_PACKED;
-struct ieee80211_frame_ack {
- u_int8_t i_fc[2];
- u_int8_t i_dur[2];
- u_int8_t i_ra[IEEE80211_ADDR_LEN];
- /* FCS */
+struct ieee80211_frame_ack
+{
+ u_int8_t i_fc[2];
+ u_int8_t i_dur[2];
+ u_int8_t i_ra[IEEE80211_ADDR_LEN];
+ /* FCS */
} GNUNET_PACKED;
-struct ieee80211_frame_pspoll {
- u_int8_t i_fc[2];
- u_int8_t i_aid[2];
- u_int8_t i_bssid[IEEE80211_ADDR_LEN];
- u_int8_t i_ta[IEEE80211_ADDR_LEN];
- /* FCS */
+struct ieee80211_frame_pspoll
+{
+ u_int8_t i_fc[2];
+ u_int8_t i_aid[2];
+ u_int8_t i_bssid[IEEE80211_ADDR_LEN];
+ u_int8_t i_ta[IEEE80211_ADDR_LEN];
+ /* FCS */
} GNUNET_PACKED;
-struct ieee80211_frame_cfend { /* NB: also CF-End+CF-Ack */
- u_int8_t i_fc[2];
- u_int8_t i_dur[2]; /* should be zero */
- u_int8_t i_ra[IEEE80211_ADDR_LEN];
- u_int8_t i_bssid[IEEE80211_ADDR_LEN];
- /* FCS */
+struct ieee80211_frame_cfend
+{ /* NB: also CF-End+CF-Ack */
+ u_int8_t i_fc[2];
+ u_int8_t i_dur[2]; /* should be zero */
+ u_int8_t i_ra[IEEE80211_ADDR_LEN];
+ u_int8_t i_bssid[IEEE80211_ADDR_LEN];
+ /* FCS */
} GNUNET_PACKED;
/*
@@ -372,63 +390,68 @@
/*
* 802.11i/WPA information element (maximally sized).
*/
-struct ieee80211_ie_wpa {
- u_int8_t wpa_id; /* IEEE80211_ELEMID_VENDOR */
- u_int8_t wpa_len; /* length in bytes */
- u_int8_t wpa_oui[3]; /* 0x00, 0x50, 0xf2 */
- u_int8_t wpa_type; /* OUI type */
- u_int16_t wpa_version; /* spec revision */
- u_int32_t wpa_mcipher[1]; /* multicast/group key cipher */
- u_int16_t wpa_uciphercnt; /* # pairwise key ciphers */
- u_int32_t wpa_uciphers[8];/* ciphers */
- u_int16_t wpa_authselcnt; /* authentication selector cnt*/
- u_int32_t wpa_authsels[8];/* selectors */
- u_int16_t wpa_caps; /* 802.11i capabilities */
- u_int16_t wpa_pmkidcnt; /* 802.11i pmkid count */
- u_int16_t wpa_pmkids[8]; /* 802.11i pmkids */
+struct ieee80211_ie_wpa
+{
+ u_int8_t wpa_id; /* IEEE80211_ELEMID_VENDOR */
+ u_int8_t wpa_len; /* length in bytes */
+ u_int8_t wpa_oui[3]; /* 0x00, 0x50, 0xf2 */
+ u_int8_t wpa_type; /* OUI type */
+ u_int16_t wpa_version; /* spec revision */
+ u_int32_t wpa_mcipher[1]; /* multicast/group key cipher */
+ u_int16_t wpa_uciphercnt; /* # pairwise key ciphers */
+ u_int32_t wpa_uciphers[8]; /* ciphers */
+ u_int16_t wpa_authselcnt; /* authentication selector cnt */
+ u_int32_t wpa_authsels[8]; /* selectors */
+ u_int16_t wpa_caps; /* 802.11i capabilities */
+ u_int16_t wpa_pmkidcnt; /* 802.11i pmkid count */
+ u_int16_t wpa_pmkids[8]; /* 802.11i pmkids */
} GNUNET_PACKED;
/*
* Management information element payloads.
*/
-enum {
- IEEE80211_ELEMID_SSID = 0,
- IEEE80211_ELEMID_RATES = 1,
- IEEE80211_ELEMID_FHPARMS = 2,
- IEEE80211_ELEMID_DSPARMS = 3,
- IEEE80211_ELEMID_CFPARMS = 4,
- IEEE80211_ELEMID_TIM = 5,
- IEEE80211_ELEMID_IBSSPARMS = 6,
- IEEE80211_ELEMID_COUNTRY = 7,
- IEEE80211_ELEMID_CHALLENGE = 16,
- /* 17-31 reserved for challenge text extension */
- IEEE80211_ELEMID_ERP = 42,
- IEEE80211_ELEMID_RSN = 48,
- IEEE80211_ELEMID_XRATES = 50,
- IEEE80211_ELEMID_TPC = 150,
- IEEE80211_ELEMID_CCKM = 156,
- IEEE80211_ELEMID_VENDOR = 221, /* vendor private */
+enum
+{
+ IEEE80211_ELEMID_SSID = 0,
+ IEEE80211_ELEMID_RATES = 1,
+ IEEE80211_ELEMID_FHPARMS = 2,
+ IEEE80211_ELEMID_DSPARMS = 3,
+ IEEE80211_ELEMID_CFPARMS = 4,
+ IEEE80211_ELEMID_TIM = 5,
+ IEEE80211_ELEMID_IBSSPARMS = 6,
+ IEEE80211_ELEMID_COUNTRY = 7,
+ IEEE80211_ELEMID_CHALLENGE = 16,
+ /* 17-31 reserved for challenge text extension */
+ IEEE80211_ELEMID_ERP = 42,
+ IEEE80211_ELEMID_RSN = 48,
+ IEEE80211_ELEMID_XRATES = 50,
+ IEEE80211_ELEMID_TPC = 150,
+ IEEE80211_ELEMID_CCKM = 156,
+ IEEE80211_ELEMID_VENDOR = 221, /* vendor private */
};
-struct ieee80211_tim_ie {
- u_int8_t tim_ie; /* IEEE80211_ELEMID_TIM */
- u_int8_t tim_len;
- u_int8_t tim_count; /* DTIM count */
- u_int8_t tim_period; /* DTIM period */
- u_int8_t tim_bitctl; /* bitmap control */
- u_int8_t tim_bitmap[1]; /* variable-length bitmap */
+struct ieee80211_tim_ie
+{
+ u_int8_t tim_ie; /* IEEE80211_ELEMID_TIM */
+ u_int8_t tim_len;
+ u_int8_t tim_count; /* DTIM count */
+ u_int8_t tim_period; /* DTIM period */
+ u_int8_t tim_bitctl; /* bitmap control */
+ u_int8_t tim_bitmap[1]; /* variable-length bitmap */
} GNUNET_PACKED;
-struct ieee80211_country_ie {
- u_int8_t ie; /* IEEE80211_ELEMID_COUNTRY */
- u_int8_t len;
- u_int8_t cc[3]; /* ISO CC+(I)ndoor/(O)utdoor */
- struct {
- u_int8_t schan; /* starting channel */
- u_int8_t nchan; /* number channels */
- u_int8_t maxtxpwr; /* tx power cap */
- } GNUNET_PACKED band[4]; /* up to 4 sub bands */
+struct ieee80211_country_ie
+{
+ u_int8_t ie; /* IEEE80211_ELEMID_COUNTRY */
+ u_int8_t len;
+ u_int8_t cc[3]; /* ISO CC+(I)ndoor/(O)utdoor */
+ struct
+ {
+ u_int8_t schan; /* starting channel */
+ u_int8_t nchan; /* number channels */
+ u_int8_t maxtxpwr; /* tx power cap */
+ } GNUNET_PACKED band[4]; /* up to 4 sub bands */
} GNUNET_PACKED;
#define IEEE80211_CHALLENGE_LEN 128
@@ -448,13 +471,13 @@
/* bits 3-6 reserved */
#define ATHEROS_CAP_BOOST 0x80
-#define ATH_OUI 0x7f0300 /* Atheros OUI
*/
+#define ATH_OUI 0x7f0300 /* Atheros OUI */
#define ATH_OUI_TYPE 0x01
#define ATH_OUI_VERSION 0x01
#define WPA_OUI 0xf25000
#define WPA_OUI_TYPE 0x01
-#define WPA_VERSION 1 /* current supported
version */
+#define WPA_VERSION 1 /* current supported version */
#define WPA_CSE_NULL 0x00
#define WPA_CSE_WEP40 0x01
@@ -467,7 +490,7 @@
#define WPA_ASE_8021X_PSK 0x02
#define RSN_OUI 0xac0f00
-#define RSN_VERSION 1 /* current supported
version */
+#define RSN_VERSION 1 /* current supported version */
#define RSN_CSE_NULL 0x00
#define RSN_CSE_WEP40 0x01
@@ -489,10 +512,10 @@
#define WME_VERSION 1
/* WME stream classes */
-#define WME_AC_BE 0 /* best effort */
-#define WME_AC_BK 1 /* background */
-#define WME_AC_VI 2 /* video */
-#define WME_AC_VO 3 /* voice */
+#define WME_AC_BE 0 /* best effort */
+#define WME_AC_BK 1 /* background */
+#define WME_AC_VI 2 /* video */
+#define WME_AC_VO 3 /* voice */
/*
* AUTH management packets
@@ -518,16 +541,18 @@
#define IEEE80211_AUTH_ALG_SHARED 0x0001
#define IEEE80211_AUTH_ALG_LEAP 0x0080
-enum {
- IEEE80211_AUTH_OPEN_REQUEST = 1,
- IEEE80211_AUTH_OPEN_RESPONSE = 2,
+enum
+{
+ IEEE80211_AUTH_OPEN_REQUEST = 1,
+ IEEE80211_AUTH_OPEN_RESPONSE = 2,
};
-enum {
- IEEE80211_AUTH_SHARED_REQUEST = 1,
- IEEE80211_AUTH_SHARED_CHALLENGE = 2,
- IEEE80211_AUTH_SHARED_RESPONSE = 3,
- IEEE80211_AUTH_SHARED_PASS = 4,
+enum
+{
+ IEEE80211_AUTH_SHARED_REQUEST = 1,
+ IEEE80211_AUTH_SHARED_CHALLENGE = 2,
+ IEEE80211_AUTH_SHARED_RESPONSE = 3,
+ IEEE80211_AUTH_SHARED_PASS = 4,
};
/*
@@ -536,47 +561,48 @@
* Unlisted codes are reserved
*/
-enum {
- IEEE80211_REASON_UNSPECIFIED = 1,
- IEEE80211_REASON_AUTH_EXPIRE = 2,
- IEEE80211_REASON_AUTH_LEAVE = 3,
- IEEE80211_REASON_ASSOC_EXPIRE = 4,
- IEEE80211_REASON_ASSOC_TOOMANY = 5,
- IEEE80211_REASON_NOT_AUTHED = 6,
- IEEE80211_REASON_NOT_ASSOCED = 7,
- IEEE80211_REASON_ASSOC_LEAVE = 8,
- IEEE80211_REASON_ASSOC_NOT_AUTHED = 9,
+enum
+{
+ IEEE80211_REASON_UNSPECIFIED = 1,
+ IEEE80211_REASON_AUTH_EXPIRE = 2,
+ IEEE80211_REASON_AUTH_LEAVE = 3,
+ IEEE80211_REASON_ASSOC_EXPIRE = 4,
+ IEEE80211_REASON_ASSOC_TOOMANY = 5,
+ IEEE80211_REASON_NOT_AUTHED = 6,
+ IEEE80211_REASON_NOT_ASSOCED = 7,
+ IEEE80211_REASON_ASSOC_LEAVE = 8,
+ IEEE80211_REASON_ASSOC_NOT_AUTHED = 9,
- IEEE80211_REASON_RSN_REQUIRED = 11,
- IEEE80211_REASON_RSN_INCONSISTENT = 12,
- IEEE80211_REASON_IE_INVALID = 13,
- IEEE80211_REASON_MIC_FAILURE = 14,
+ IEEE80211_REASON_RSN_REQUIRED = 11,
+ IEEE80211_REASON_RSN_INCONSISTENT = 12,
+ IEEE80211_REASON_IE_INVALID = 13,
+ IEEE80211_REASON_MIC_FAILURE = 14,
- IEEE80211_STATUS_SUCCESS = 0,
- IEEE80211_STATUS_UNSPECIFIED = 1,
- IEEE80211_STATUS_CAPINFO = 10,
- IEEE80211_STATUS_NOT_ASSOCED = 11,
- IEEE80211_STATUS_OTHER = 12,
- IEEE80211_STATUS_ALG = 13,
- IEEE80211_STATUS_SEQUENCE = 14,
- IEEE80211_STATUS_CHALLENGE = 15,
- IEEE80211_STATUS_TIMEOUT = 16,
- IEEE80211_STATUS_TOOMANY = 17,
- IEEE80211_STATUS_BASIC_RATE = 18,
- IEEE80211_STATUS_SP_REQUIRED = 19,
- IEEE80211_STATUS_PBCC_REQUIRED = 20,
- IEEE80211_STATUS_CA_REQUIRED = 21,
- IEEE80211_STATUS_TOO_MANY_STATIONS = 22,
- IEEE80211_STATUS_RATES = 23,
- IEEE80211_STATUS_SHORTSLOT_REQUIRED = 25,
- IEEE80211_STATUS_DSSSOFDM_REQUIRED = 26,
+ IEEE80211_STATUS_SUCCESS = 0,
+ IEEE80211_STATUS_UNSPECIFIED = 1,
+ IEEE80211_STATUS_CAPINFO = 10,
+ IEEE80211_STATUS_NOT_ASSOCED = 11,
+ IEEE80211_STATUS_OTHER = 12,
+ IEEE80211_STATUS_ALG = 13,
+ IEEE80211_STATUS_SEQUENCE = 14,
+ IEEE80211_STATUS_CHALLENGE = 15,
+ IEEE80211_STATUS_TIMEOUT = 16,
+ IEEE80211_STATUS_TOOMANY = 17,
+ IEEE80211_STATUS_BASIC_RATE = 18,
+ IEEE80211_STATUS_SP_REQUIRED = 19,
+ IEEE80211_STATUS_PBCC_REQUIRED = 20,
+ IEEE80211_STATUS_CA_REQUIRED = 21,
+ IEEE80211_STATUS_TOO_MANY_STATIONS = 22,
+ IEEE80211_STATUS_RATES = 23,
+ IEEE80211_STATUS_SHORTSLOT_REQUIRED = 25,
+ IEEE80211_STATUS_DSSSOFDM_REQUIRED = 26,
};
-#define IEEE80211_WEP_KEYLEN 5 /* 40bit */
-#define IEEE80211_WEP_IVLEN 3 /* 24bit */
-#define IEEE80211_WEP_KIDLEN 1 /* 1 octet */
-#define IEEE80211_WEP_CRCLEN 4 /* CRC-32 */
-#define IEEE80211_WEP_NKID 4 /* number of key ids */
+#define IEEE80211_WEP_KEYLEN 5 /* 40bit */
+#define IEEE80211_WEP_IVLEN 3 /* 24bit */
+#define IEEE80211_WEP_KIDLEN 1 /* 1 octet */
+#define IEEE80211_WEP_CRCLEN 4 /* CRC-32 */
+#define IEEE80211_WEP_NKID 4 /* number of key ids */
/*
* 802.11i defines an extended IV for use with non-WEP ciphers.
@@ -586,8 +612,8 @@
* CCMP header rather than IV+extended-IV.
*/
#define IEEE80211_WEP_EXTIV 0x20
-#define IEEE80211_WEP_EXTIVLEN 4 /* extended IV length */
-#define IEEE80211_WEP_MICLEN 8 /* trailing MIC */
+#define IEEE80211_WEP_EXTIVLEN 4 /* extended IV length */
+#define IEEE80211_WEP_MICLEN 8 /* trailing MIC */
#define IEEE80211_CRC_LEN 4
@@ -641,16 +667,16 @@
* As above, we treat default as implementation-dependent so
* define it elsewhere.
*/
-#define IEEE80211_BINTVAL_MAX 1000 /* max beacon interval (TU's) */
-#define IEEE80211_BINTVAL_MIN 25 /* min beacon interval (TU's) */
+#define IEEE80211_BINTVAL_MAX 1000 /* max beacon interval (TU's) */
+#define IEEE80211_BINTVAL_MIN 25 /* min beacon interval (TU's) */
/*
* DTIM period (beacons). Min+max are not really defined
* by the protocol but we want them publicly visible so
* define them here.
*/
-#define IEEE80211_DTIM_MAX 15 /* max DTIM period */
-#define IEEE80211_DTIM_MIN 1 /* min DTIM period */
+#define IEEE80211_DTIM_MAX 15 /* max DTIM period */
+#define IEEE80211_DTIM_MIN 1 /* min DTIM period */
/*
* Beacon miss threshold (beacons). As for DTIM, we define
Modified: gnunet/src/transport/wlan/ieee80211_radiotap.h
===================================================================
--- gnunet/src/transport/wlan/ieee80211_radiotap.h 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/transport/wlan/ieee80211_radiotap.h 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -66,25 +66,26 @@
/* The radio capture header precedes the 802.11 header.
* All data in the header is little endian on all platforms.
*/
-struct ieee80211_radiotap_header {
- u8 it_version; /* Version 0. Only increases
- * for drastic changes,
- * introduction of compatible
- * new fields does not count.
- */
- u8 it_pad;
- u16 it_len; /* length of the whole
- * header in bytes, including
- * it_version, it_pad,
- * it_len, and data fields.
- */
- u32 it_present; /* A bitmap telling which
- * fields are present. Set bit 31
- * (0x80000000) to extend the
- * bitmap by another 32 bits.
- * Additional extensions are made
- * by setting bit 31.
- */
+struct ieee80211_radiotap_header
+{
+ u8 it_version; /* Version 0. Only increases
+ * for drastic changes,
+ * introduction of compatible
+ * new fields does not count.
+ */
+ u8 it_pad;
+ u16 it_len; /* length of the whole
+ * header in bytes, including
+ * it_version, it_pad,
+ * it_len, and data fields.
+ */
+ u32 it_present; /* A bitmap telling which
+ * fields are present. Set bit 31
+ * (0x80000000) to extend the
+ * bitmap by another 32 bits.
+ * Additional extensions are made
+ * by setting bit 31.
+ */
};
#define IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK 0x80000000
@@ -186,68 +187,69 @@
* Number of unicast retries a transmitted frame used.
*
*/
-enum ieee80211_radiotap_type {
- IEEE80211_RADIOTAP_TSFT = 0,
- IEEE80211_RADIOTAP_FLAGS = 1,
- IEEE80211_RADIOTAP_RATE = 2,
- IEEE80211_RADIOTAP_CHANNEL = 3,
- IEEE80211_RADIOTAP_FHSS = 4,
- IEEE80211_RADIOTAP_DBM_ANTSIGNAL = 5,
- IEEE80211_RADIOTAP_DBM_ANTNOISE = 6,
- IEEE80211_RADIOTAP_LOCK_QUALITY = 7,
- IEEE80211_RADIOTAP_TX_ATTENUATION = 8,
- IEEE80211_RADIOTAP_DB_TX_ATTENUATION = 9,
- IEEE80211_RADIOTAP_DBM_TX_POWER = 10,
- IEEE80211_RADIOTAP_ANTENNA = 11,
- IEEE80211_RADIOTAP_DB_ANTSIGNAL = 12,
- IEEE80211_RADIOTAP_DB_ANTNOISE = 13,
- IEEE80211_RADIOTAP_RX_FLAGS = 14,
- IEEE80211_RADIOTAP_TX_FLAGS = 15,
- IEEE80211_RADIOTAP_RTS_RETRIES = 16,
- IEEE80211_RADIOTAP_DATA_RETRIES = 17,
- IEEE80211_RADIOTAP_EXT = 31
+enum ieee80211_radiotap_type
+{
+ IEEE80211_RADIOTAP_TSFT = 0,
+ IEEE80211_RADIOTAP_FLAGS = 1,
+ IEEE80211_RADIOTAP_RATE = 2,
+ IEEE80211_RADIOTAP_CHANNEL = 3,
+ IEEE80211_RADIOTAP_FHSS = 4,
+ IEEE80211_RADIOTAP_DBM_ANTSIGNAL = 5,
+ IEEE80211_RADIOTAP_DBM_ANTNOISE = 6,
+ IEEE80211_RADIOTAP_LOCK_QUALITY = 7,
+ IEEE80211_RADIOTAP_TX_ATTENUATION = 8,
+ IEEE80211_RADIOTAP_DB_TX_ATTENUATION = 9,
+ IEEE80211_RADIOTAP_DBM_TX_POWER = 10,
+ IEEE80211_RADIOTAP_ANTENNA = 11,
+ IEEE80211_RADIOTAP_DB_ANTSIGNAL = 12,
+ IEEE80211_RADIOTAP_DB_ANTNOISE = 13,
+ IEEE80211_RADIOTAP_RX_FLAGS = 14,
+ IEEE80211_RADIOTAP_TX_FLAGS = 15,
+ IEEE80211_RADIOTAP_RTS_RETRIES = 16,
+ IEEE80211_RADIOTAP_DATA_RETRIES = 17,
+ IEEE80211_RADIOTAP_EXT = 31
};
/* Channel flags. */
-#define IEEE80211_CHAN_TURBO 0x0010 /* Turbo channel */
-#define IEEE80211_CHAN_CCK 0x0020 /* CCK channel */
-#define IEEE80211_CHAN_OFDM 0x0040 /* OFDM channel */
-#define IEEE80211_CHAN_2GHZ 0x0080 /* 2 GHz spectrum channel. */
-#define IEEE80211_CHAN_5GHZ 0x0100 /* 5 GHz spectrum channel */
-#define IEEE80211_CHAN_PASSIVE 0x0200 /* Only passive scan allowed */
-#define IEEE80211_CHAN_DYN 0x0400 /* Dynamic CCK-OFDM channel */
-#define IEEE80211_CHAN_GFSK 0x0800 /* GFSK channel (FHSS PHY) */
+#define IEEE80211_CHAN_TURBO 0x0010 /* Turbo channel */
+#define IEEE80211_CHAN_CCK 0x0020 /* CCK channel */
+#define IEEE80211_CHAN_OFDM 0x0040 /* OFDM channel */
+#define IEEE80211_CHAN_2GHZ 0x0080 /* 2 GHz spectrum channel. */
+#define IEEE80211_CHAN_5GHZ 0x0100 /* 5 GHz spectrum channel */
+#define IEEE80211_CHAN_PASSIVE 0x0200 /* Only passive scan allowed */
+#define IEEE80211_CHAN_DYN 0x0400 /* Dynamic CCK-OFDM channel */
+#define IEEE80211_CHAN_GFSK 0x0800 /* GFSK channel (FHSS PHY) */
/* For IEEE80211_RADIOTAP_FLAGS */
-#define IEEE80211_RADIOTAP_F_CFP 0x01 /* sent/received
- * during CFP
- */
-#define IEEE80211_RADIOTAP_F_SHORTPRE 0x02 /* sent/received
- * with short
- * preamble
- */
-#define IEEE80211_RADIOTAP_F_WEP 0x04 /* sent/received
- * with WEP encryption
- */
-#define IEEE80211_RADIOTAP_F_FRAG 0x08 /* sent/received
- * with fragmentation
- */
-#define IEEE80211_RADIOTAP_F_FCS 0x10 /* frame includes FCS */
-#define IEEE80211_RADIOTAP_F_DATAPAD 0x20 /* frame has padding
between
- * 802.11 header and payload
- * (to 32-bit boundary)
- */
+#define IEEE80211_RADIOTAP_F_CFP 0x01 /* sent/received
+ * during CFP
+ */
+#define IEEE80211_RADIOTAP_F_SHORTPRE 0x02 /* sent/received
+ * with short
+ * preamble
+ */
+#define IEEE80211_RADIOTAP_F_WEP 0x04 /* sent/received
+ * with WEP encryption
+ */
+#define IEEE80211_RADIOTAP_F_FRAG 0x08 /* sent/received
+ * with fragmentation
+ */
+#define IEEE80211_RADIOTAP_F_FCS 0x10 /* frame includes FCS */
+#define IEEE80211_RADIOTAP_F_DATAPAD 0x20 /* frame has padding
between
+ * 802.11 header and payload
+ * (to 32-bit boundary)
+ */
/* For IEEE80211_RADIOTAP_RX_FLAGS */
-#define IEEE80211_RADIOTAP_F_RX_BADFCS 0x0001 /* frame failed crc check */
+#define IEEE80211_RADIOTAP_F_RX_BADFCS 0x0001 /* frame failed crc check */
/* For IEEE80211_RADIOTAP_TX_FLAGS */
-#define IEEE80211_RADIOTAP_F_TX_FAIL 0x0001 /* failed due to excessive
- * retries */
-#define IEEE80211_RADIOTAP_F_TX_CTS 0x0002 /* used cts 'protection' */
-#define IEEE80211_RADIOTAP_F_TX_RTS 0x0004 /* used rts/cts handshake */
-#define IEEE80211_RADIOTAP_F_TX_NOACK 0x0008 /* frame should not be ACKed */
-#define IEEE80211_RADIOTAP_F_TX_NOSEQ 0x0010 /* sequence number handled
- * by userspace */
+#define IEEE80211_RADIOTAP_F_TX_FAIL 0x0001 /* failed due to excessive
+ * retries */
+#define IEEE80211_RADIOTAP_F_TX_CTS 0x0002 /* used cts 'protection' */
+#define IEEE80211_RADIOTAP_F_TX_RTS 0x0004 /* used rts/cts handshake */
+#define IEEE80211_RADIOTAP_F_TX_NOACK 0x0008 /* frame should not be ACKed */
+#define IEEE80211_RADIOTAP_F_TX_NOSEQ 0x0010 /* sequence number handled
+ * by userspace */
/* Ugly macro to convert literal channel numbers into their mhz equivalents
* There are certianly some conditions that will break this (like feeding it
'30')
@@ -257,4 +259,4 @@
(((x) == 14) ? 2484 : ((x) * 5) + 2407) : \
((x) + 1000) * 5)
-#endif /* IEEE80211_RADIOTAP_H */
+#endif /* IEEE80211_RADIOTAP_H */
Modified: gnunet/src/transport/wlan/loopback_helper.h
===================================================================
--- gnunet/src/transport/wlan/loopback_helper.h 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/transport/wlan/loopback_helper.h 2011-08-15 21:46:35 UTC (rev
16581)
@@ -14,7 +14,6 @@
//static void file_in_send(void *cls, void *client, const struct
GNUNET_MessageHeader *hdr);
-int
-testmode(int argc, char *argv[]);
+int testmode (int argc, char *argv[]);
#endif /* LOOPBACK_HELPER_H_ */
Modified: gnunet/src/transport/wlan/radiotap-parser.c
===================================================================
--- gnunet/src/transport/wlan/radiotap-parser.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/transport/wlan/radiotap-parser.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -38,67 +38,69 @@
*/
-int ieee80211_radiotap_iterator_init(
- struct ieee80211_radiotap_iterator * iterator,
- struct ieee80211_radiotap_header * radiotap_header,
- int max_length)
+int
+ieee80211_radiotap_iterator_init (struct ieee80211_radiotap_iterator *iterator,
+ struct ieee80211_radiotap_header
+ *radiotap_header, int max_length)
{
- if(iterator == NULL)
- return (-EINVAL);
+ if (iterator == NULL)
+ return (-EINVAL);
- if(radiotap_header == NULL)
- return (-EINVAL);
- /* Linux only supports version 0 radiotap format */
+ if (radiotap_header == NULL)
+ return (-EINVAL);
+ /* Linux only supports version 0 radiotap format */
- if (radiotap_header->it_version)
- return (-EINVAL);
+ if (radiotap_header->it_version)
+ return (-EINVAL);
- /* sanity check for allowed length and radiotap length field */
+ /* sanity check for allowed length and radiotap length field */
- if (max_length < (le16_to_cpu(radiotap_header->it_len)))
- return (-EINVAL);
+ if (max_length < (le16_to_cpu (radiotap_header->it_len)))
+ return (-EINVAL);
- iterator->rtheader = radiotap_header;
- iterator->max_length = le16_to_cpu(radiotap_header->it_len);
- iterator->arg_index = 0;
- iterator->bitmap_shifter = le32_to_cpu(radiotap_header->it_present);
- iterator->arg = ((u8 *)radiotap_header) +
- sizeof (struct ieee80211_radiotap_header);
- iterator->this_arg = 0;
+ iterator->rtheader = radiotap_header;
+ iterator->max_length = le16_to_cpu (radiotap_header->it_len);
+ iterator->arg_index = 0;
+ iterator->bitmap_shifter = le32_to_cpu (radiotap_header->it_present);
+ iterator->arg = ((u8 *) radiotap_header) +
+ sizeof (struct ieee80211_radiotap_header);
+ iterator->this_arg = 0;
- /* find payload start allowing for extended bitmap(s) */
+ /* find payload start allowing for extended bitmap(s) */
- if (unlikely(iterator->bitmap_shifter &
- IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK)) {
- while (le32_to_cpu(*((u32 *)iterator->arg)) &
- IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK) {
- iterator->arg += sizeof (u32);
+ if (unlikely (iterator->bitmap_shifter &
+ IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK))
+ {
+ while (le32_to_cpu (*((u32 *) iterator->arg)) &
+ IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK)
+ {
+ iterator->arg += sizeof (u32);
- /*
- * check for insanity where the present bitmaps
- * keep claiming to extend up to or even beyond the
- * stated radiotap header length
- */
+ /*
+ * check for insanity where the present bitmaps
+ * keep claiming to extend up to or even beyond the
+ * stated radiotap header length
+ */
- if ((((void*)iterator->arg) -
((void*)iterator->rtheader)) >
- iterator->max_length)
- return (-EINVAL);
+ if ((((void *) iterator->arg) - ((void *) iterator->rtheader)) >
+ iterator->max_length)
+ return (-EINVAL);
- }
+ }
- iterator->arg += sizeof (u32);
+ iterator->arg += sizeof (u32);
- /*
- * no need to check again for blowing past stated radiotap
- * header length, becuase ieee80211_radiotap_iterator_next
- * checks it before it is dereferenced
- */
+ /*
+ * no need to check again for blowing past stated radiotap
+ * header length, becuase ieee80211_radiotap_iterator_next
+ * checks it before it is dereferenced
+ */
- }
+ }
- /* we are all initialized happily */
+ /* we are all initialized happily */
- return (0);
+ return (0);
}
@@ -115,137 +117,143 @@
* format.
*/
-int ieee80211_radiotap_iterator_next(
- struct ieee80211_radiotap_iterator * iterator)
+int
+ieee80211_radiotap_iterator_next (struct ieee80211_radiotap_iterator *iterator)
{
- /*
- * small length lookup table for all radiotap types we heard of
- * starting from b0 in the bitmap, so we can walk the payload
- * area of the radiotap header
- *
- * There is a requirement to pad args, so that args
- * of a given length must begin at a boundary of that length
- * -- but note that compound args are allowed (eg, 2 x u16
- * for IEEE80211_RADIOTAP_CHANNEL) so total arg length is not
- * a reliable indicator of alignment requirement.
- *
- * upper nybble: content alignment for arg
- * lower nybble: content length for arg
- */
+ /*
+ * small length lookup table for all radiotap types we heard of
+ * starting from b0 in the bitmap, so we can walk the payload
+ * area of the radiotap header
+ *
+ * There is a requirement to pad args, so that args
+ * of a given length must begin at a boundary of that length
+ * -- but note that compound args are allowed (eg, 2 x u16
+ * for IEEE80211_RADIOTAP_CHANNEL) so total arg length is not
+ * a reliable indicator of alignment requirement.
+ *
+ * upper nybble: content alignment for arg
+ * lower nybble: content length for arg
+ */
- static const u8 rt_sizes[] = {
- [IEEE80211_RADIOTAP_TSFT] = 0x88,
- [IEEE80211_RADIOTAP_FLAGS] = 0x11,
- [IEEE80211_RADIOTAP_RATE] = 0x11,
- [IEEE80211_RADIOTAP_CHANNEL] = 0x24,
- [IEEE80211_RADIOTAP_FHSS] = 0x22,
- [IEEE80211_RADIOTAP_DBM_ANTSIGNAL] = 0x11,
- [IEEE80211_RADIOTAP_DBM_ANTNOISE] = 0x11,
- [IEEE80211_RADIOTAP_LOCK_QUALITY] = 0x22,
- [IEEE80211_RADIOTAP_TX_ATTENUATION] = 0x22,
- [IEEE80211_RADIOTAP_DB_TX_ATTENUATION] = 0x22,
- [IEEE80211_RADIOTAP_DBM_TX_POWER] = 0x11,
- [IEEE80211_RADIOTAP_ANTENNA] = 0x11,
- [IEEE80211_RADIOTAP_DB_ANTSIGNAL] = 0x11,
- [IEEE80211_RADIOTAP_DB_ANTNOISE] = 0x11,
- [IEEE80211_RADIOTAP_TX_FLAGS] = 0x22,
- [IEEE80211_RADIOTAP_RX_FLAGS] = 0x22,
- [IEEE80211_RADIOTAP_RTS_RETRIES] = 0x11,
- [IEEE80211_RADIOTAP_DATA_RETRIES] = 0x11
- /*
- * add more here as they are defined in
- * include/net/ieee80211_radiotap.h
- */
- };
+ static const u8 rt_sizes[] = {
+ [IEEE80211_RADIOTAP_TSFT] = 0x88,
+ [IEEE80211_RADIOTAP_FLAGS] = 0x11,
+ [IEEE80211_RADIOTAP_RATE] = 0x11,
+ [IEEE80211_RADIOTAP_CHANNEL] = 0x24,
+ [IEEE80211_RADIOTAP_FHSS] = 0x22,
+ [IEEE80211_RADIOTAP_DBM_ANTSIGNAL] = 0x11,
+ [IEEE80211_RADIOTAP_DBM_ANTNOISE] = 0x11,
+ [IEEE80211_RADIOTAP_LOCK_QUALITY] = 0x22,
+ [IEEE80211_RADIOTAP_TX_ATTENUATION] = 0x22,
+ [IEEE80211_RADIOTAP_DB_TX_ATTENUATION] = 0x22,
+ [IEEE80211_RADIOTAP_DBM_TX_POWER] = 0x11,
+ [IEEE80211_RADIOTAP_ANTENNA] = 0x11,
+ [IEEE80211_RADIOTAP_DB_ANTSIGNAL] = 0x11,
+ [IEEE80211_RADIOTAP_DB_ANTNOISE] = 0x11,
+ [IEEE80211_RADIOTAP_TX_FLAGS] = 0x22,
+ [IEEE80211_RADIOTAP_RX_FLAGS] = 0x22,
+ [IEEE80211_RADIOTAP_RTS_RETRIES] = 0x11,
+ [IEEE80211_RADIOTAP_DATA_RETRIES] = 0x11
+ /*
+ * add more here as they are defined in
+ * include/net/ieee80211_radiotap.h
+ */
+ };
- /*
- * for every radiotap entry we can at
- * least skip (by knowing the length)...
- */
+ /*
+ * for every radiotap entry we can at
+ * least skip (by knowing the length)...
+ */
- while (iterator->arg_index < (int)sizeof (rt_sizes)) {
- int hit = 0;
+ while (iterator->arg_index < (int) sizeof (rt_sizes))
+ {
+ int hit = 0;
- if (!(iterator->bitmap_shifter & 1))
- goto next_entry; /* arg not present */
+ if (!(iterator->bitmap_shifter & 1))
+ goto next_entry; /* arg not present */
- /*
- * arg is present, account for alignment padding
- * 8-bit args can be at any alignment
- * 16-bit args must start on 16-bit boundary
- * 32-bit args must start on 32-bit boundary
- * 64-bit args must start on 64-bit boundary
- *
- * note that total arg size can differ from alignment of
- * elements inside arg, so we use upper nybble of length
- * table to base alignment on
- *
- * also note: these alignments are ** relative to the
- * start of the radiotap header **. There is no guarantee
- * that the radiotap header itself is aligned on any
- * kind of boundary.
- */
+ /*
+ * arg is present, account for alignment padding
+ * 8-bit args can be at any alignment
+ * 16-bit args must start on 16-bit boundary
+ * 32-bit args must start on 32-bit boundary
+ * 64-bit args must start on 64-bit boundary
+ *
+ * note that total arg size can differ from alignment of
+ * elements inside arg, so we use upper nybble of length
+ * table to base alignment on
+ *
+ * also note: these alignments are ** relative to the
+ * start of the radiotap header **. There is no guarantee
+ * that the radiotap header itself is aligned on any
+ * kind of boundary.
+ */
- if ((((void*)iterator->arg)-((void*)iterator->rtheader)) &
- ((rt_sizes[iterator->arg_index] >> 4) - 1))
- iterator->arg_index +=
- (rt_sizes[iterator->arg_index] >> 4) -
- ((((void*)iterator->arg) -
- ((void*)iterator->rtheader)) &
- ((rt_sizes[iterator->arg_index] >> 4) - 1));
+ if ((((void *) iterator->arg) - ((void *) iterator->rtheader)) &
+ ((rt_sizes[iterator->arg_index] >> 4) - 1))
+ iterator->arg_index +=
+ (rt_sizes[iterator->arg_index] >> 4) -
+ ((((void *) iterator->arg) -
+ ((void *) iterator->rtheader)) &
+ ((rt_sizes[iterator->arg_index] >> 4) - 1));
- /*
- * this is what we will return to user, but we need to
- * move on first so next call has something fresh to test
- */
+ /*
+ * this is what we will return to user, but we need to
+ * move on first so next call has something fresh to test
+ */
- iterator->this_arg_index = iterator->arg_index;
- iterator->this_arg = iterator->arg;
- hit = 1;
+ iterator->this_arg_index = iterator->arg_index;
+ iterator->this_arg = iterator->arg;
+ hit = 1;
- /* internally move on the size of this arg */
+ /* internally move on the size of this arg */
- iterator->arg += rt_sizes[iterator->arg_index] & 0x0f;
+ iterator->arg += rt_sizes[iterator->arg_index] & 0x0f;
- /*
- * check for insanity where we are given a bitmap that
- * claims to have more arg content than the length of the
- * radiotap section. We will normally end up equalling this
- * max_length on the last arg, never exceeding it.
- */
+ /*
+ * check for insanity where we are given a bitmap that
+ * claims to have more arg content than the length of the
+ * radiotap section. We will normally end up equalling this
+ * max_length on the last arg, never exceeding it.
+ */
- if ((((void*)iterator->arg) - ((void*)iterator->rtheader)) >
- iterator->max_length)
- return (-EINVAL);
+ if ((((void *) iterator->arg) - ((void *) iterator->rtheader)) >
+ iterator->max_length)
+ return (-EINVAL);
- next_entry:
+next_entry:
- iterator->arg_index++;
- if (unlikely((iterator->arg_index & 31) == 0)) {
- /* completed current u32 bitmap */
- if (iterator->bitmap_shifter & 1) {
- /* b31 was set, there is more */
- /* move to next u32 bitmap */
- iterator->bitmap_shifter = le32_to_cpu(
- *iterator->next_bitmap);
- iterator->next_bitmap++;
- } else {
- /* no more bitmaps: end */
- iterator->arg_index = sizeof (rt_sizes);
- }
- } else { /* just try the next bit */
- iterator->bitmap_shifter >>= 1;
- }
+ iterator->arg_index++;
+ if (unlikely ((iterator->arg_index & 31) == 0))
+ {
+ /* completed current u32 bitmap */
+ if (iterator->bitmap_shifter & 1)
+ {
+ /* b31 was set, there is more */
+ /* move to next u32 bitmap */
+ iterator->bitmap_shifter = le32_to_cpu (*iterator->next_bitmap);
+ iterator->next_bitmap++;
+ }
+ else
+ {
+ /* no more bitmaps: end */
+ iterator->arg_index = sizeof (rt_sizes);
+ }
+ }
+ else
+ { /* just try the next bit */
+ iterator->bitmap_shifter >>= 1;
+ }
- /* if we found a valid arg earlier, return it now */
+ /* if we found a valid arg earlier, return it now */
- if (hit)
- return (iterator->this_arg_index);
+ if (hit)
+ return (iterator->this_arg_index);
- }
+ }
- /* we don't know how to handle any more args, we're done */
+ /* we don't know how to handle any more args, we're done */
- return (-1);
+ return (-1);
}
Modified: gnunet/src/transport/wlan/radiotap-parser.h
===================================================================
--- gnunet/src/transport/wlan/radiotap-parser.h 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/transport/wlan/radiotap-parser.h 2011-08-15 21:46:35 UTC (rev
16581)
@@ -57,22 +57,23 @@
* @bitmap_shifter: internal shifter for curr u32 bitmap, b0 set == arg present
*/
-struct ieee80211_radiotap_iterator {
- struct ieee80211_radiotap_header *rtheader;
- int max_length;
- int this_arg_index;
- u8 * this_arg;
+struct ieee80211_radiotap_iterator
+{
+ struct ieee80211_radiotap_header *rtheader;
+ int max_length;
+ int this_arg_index;
+ u8 *this_arg;
- int arg_index;
- u8 * arg;
- u32 *next_bitmap;
- u32 bitmap_shifter;
+ int arg_index;
+ u8 *arg;
+ u32 *next_bitmap;
+ u32 bitmap_shifter;
};
-int ieee80211_radiotap_iterator_init(
- struct ieee80211_radiotap_iterator * iterator,
- struct ieee80211_radiotap_header * radiotap_header,
- int max_length);
+int ieee80211_radiotap_iterator_init (struct ieee80211_radiotap_iterator
+ *iterator,
+ struct ieee80211_radiotap_header
+ *radiotap_header, int max_length);
-int ieee80211_radiotap_iterator_next(
- struct ieee80211_radiotap_iterator * iterator);
+int ieee80211_radiotap_iterator_next (struct ieee80211_radiotap_iterator
+ *iterator);
Modified: gnunet/src/util/bandwidth.c
===================================================================
--- gnunet/src/util/bandwidth.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/bandwidth.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -42,8 +42,8 @@
#if DEBUG_BANDWIDTH
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Initializing bandwidth of %u Bps\n",
- (unsigned int) bytes_per_second);
+ "Initializing bandwidth of %u Bps\n",
+ (unsigned int) bytes_per_second);
#endif
ret.value__ = htonl (bytes_per_second);
return ret;
@@ -59,10 +59,10 @@
*/
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__)));
+ ntohl (b2.value__)));
}
@@ -74,18 +74,20 @@
* @param deadline when is the deadline
* @return number of bytes available at bps until deadline
*/
-uint64_t
-GNUNET_BANDWIDTH_value_get_available_until (struct GNUNET_BANDWIDTH_Value32NBO
bps,
- struct GNUNET_TIME_Relative
deadline)
+uint64_t
+GNUNET_BANDWIDTH_value_get_available_until (struct GNUNET_BANDWIDTH_Value32NBO
+ bps,
+ struct GNUNET_TIME_Relative
+ deadline)
{
uint64_t b;
b = ntohl (bps.value__);
#if DEBUG_BANDWIDTH
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Bandwidth has %llu bytes available until deadline in %llums\n",
- (unsigned long long) ((b * deadline.rel_value + 500LL) / 1000LL),
- deadline.rel_value);
+ "Bandwidth has %llu bytes available until deadline in %llums\n",
+ (unsigned long long) ((b * deadline.rel_value + 500LL) / 1000LL),
+ deadline.rel_value);
#endif
return (b * deadline.rel_value + 500LL) / 1000LL;
}
@@ -101,26 +103,25 @@
*/
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
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Bandwidth suggests delay of infinity (zero bandwidth)\n");
+ GNUNET_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
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Bandwidth suggests delay of %llu ms for %llu bytes of traffic\n",
- (unsigned long long) ret.rel_value,
- (unsigned long long) size);
+ "Bandwidth suggests delay of %llu ms for %llu bytes of
traffic\n",
+ (unsigned long long) ret.rel_value, (unsigned long long) size);
#endif
return ret;
}
@@ -142,8 +143,8 @@
*/
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 ();
@@ -151,10 +152,10 @@
av->max_carry_s__ = max_carry_s;
#if DEBUG_BANDWIDTH
GNUNET_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);
+ "Tracker %p initialized with %u Bps and max carry %u\n",
+ av,
+ (unsigned int) av->available_bytes_per_s__,
+ (unsigned int) max_carry_s);
#endif
}
@@ -176,26 +177,28 @@
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_avail =
+ (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
GNUNET_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__,
- (unsigned long long) delta_time);
+ "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
}
@@ -214,41 +217,38 @@
*/
int
GNUNET_BANDWIDTH_tracker_consume (struct GNUNET_BANDWIDTH_Tracker *av,
- ssize_t size)
+ ssize_t size)
{
int64_t nc;
#if DEBUG_BANDWIDTH
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Tracker %p consumes %d bytes\n",
- av,
- (int) size);
+ "Tracker %p consumes %d bytes\n", av, (int) size);
#endif
if (size > 0)
+ {
+ nc = av->consumption_since_last_update__ + size;
+ if (nc < av->consumption_since_last_update__)
{
- 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)
- {
+ 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
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Tracker %p consumption %llu bytes above limit\n",
- av,
- (unsigned long long) av->consumption_since_last_update__);
+ GNUNET_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,39 +264,35 @@
*/
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
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Tracker %p delay is infinity\n",
- av);
+ GNUNET_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
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Tracker %p delay for %u bytes is zero\n",
- av,
- (unsigned int) size);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Tracker %p delay for %u bytes is zero\n",
+ av, (unsigned int) size);
#endif
- return GNUNET_TIME_UNIT_ZERO;
- }
- ret.rel_value = 1000LL * bytes_needed / (unsigned long long)
av->available_bytes_per_s__;
+ return GNUNET_TIME_UNIT_ZERO;
+ }
+ ret.rel_value =
+ 1000LL * bytes_needed / (unsigned long long) av->available_bytes_per_s__;
#if DEBUG_BANDWIDTH
GNUNET_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);
+ "Tracker %p delay for %u bytes is %llu ms\n",
+ av, (unsigned int) size, (unsigned long long) ret.rel_value);
#endif
return ret;
}
@@ -309,8 +305,8 @@
* @param av tracker to query
* @return number of bytes available for consumption right now
*/
-int64_t
-GNUNET_BANDWIDTH_tracker_get_available (struct GNUNET_BANDWIDTH_Tracker *av)
+int64_t
+GNUNET_BANDWIDTH_tracker_get_available (struct GNUNET_BANDWIDTH_Tracker * av)
{
struct GNUNET_BANDWIDTH_Value32NBO bps;
uint64_t avail;
@@ -319,13 +315,13 @@
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_TIME_absolute_get_duration
+ (av->last_update__));
used = av->consumption_since_last_update__;
#if DEBUG_BANDWIDTH
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Tracker %p available bandwidth is %lld bytes\n",
- av,
- (long long) (int64_t) (avail - used));
+ "Tracker %p available bandwidth is %lld bytes\n",
+ av, (long long) (int64_t) (avail - used));
#endif
return (int64_t) (avail - used);
}
@@ -339,7 +335,8 @@
*/
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;
@@ -347,15 +344,14 @@
new_limit = ntohl (bytes_per_second_limit.value__);
#if DEBUG_BANDWIDTH
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Tracker %p bandwidth changed to %u Bps\n",
- av,
- (unsigned int) new_limit);
+ "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 */
}
Modified: gnunet/src/util/bio.c
===================================================================
--- gnunet/src/util/bio.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/bio.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -56,8 +56,7 @@
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);
@@ -114,39 +113,37 @@
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;
+ }
+ h->pos = 0;
+ h->have = ret;
+ }
while (pos < len); /* should always be true */
return GNUNET_OK;
}
@@ -162,16 +159,13 @@
* @param len the number of bytes to read
* @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)
+int
+GNUNET_BIO_read_fn (struct GNUNET_BIO_ReadHandle *h,
+ const char *file, int line, void *result, size_t len)
{
char what[1024];
- GNUNET_snprintf (what,
- sizeof(what),
- "%s:%d",
- file, line);
+
+ GNUNET_snprintf (what, sizeof (what), "%s:%d", file, line);
return GNUNET_BIO_read (h, what, result, len);
}
@@ -194,36 +188,34 @@
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;
}
@@ -245,34 +237,33 @@
char *buf;
struct GNUNET_CONTAINER_MetaData *meta;
- if (GNUNET_BIO_read_int32 (h, (int32_t *) &size) != GNUNET_OK)
+ 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;
@@ -290,9 +281,7 @@
*/
int
GNUNET_BIO_read_int32__ (struct GNUNET_BIO_ReadHandle *h,
- const char *file,
- int line,
- int32_t * i)
+ const char *file, int line, int32_t * i)
{
int32_t big;
@@ -314,9 +303,7 @@
*/
int
GNUNET_BIO_read_int64__ (struct GNUNET_BIO_ReadHandle *h,
- const char *file,
- int line,
- int64_t * i)
+ const char *file, int line, int64_t * i)
{
int64_t big;
@@ -359,8 +346,7 @@
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;
@@ -382,18 +368,18 @@
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;
}
@@ -420,26 +406,26 @@
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 */
}
+ h->have = 0;
+ }
while (pos < n); /* should always be true */
GNUNET_break (0);
return GNUNET_OK;
@@ -480,25 +466,25 @@
{
ssize_t size;
char *buf;
-
- if (m == NULL)
- return GNUNET_BIO_write_int32 (h, 0);
+
+ if (m == NULL)
+ 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);
+ &buf,
+ MAX_META_DATA,
+
GNUNET_CONTAINER_META_DATA_SERIALIZE_PART);
if (size == -1)
- {
- 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;
+ }
+ 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_OK;
}
@@ -515,6 +501,7 @@
GNUNET_BIO_write_int32 (struct GNUNET_BIO_WriteHandle *h, int32_t i)
{
int32_t big;
+
big = htonl (i);
return GNUNET_BIO_write (h, &big, sizeof (int32_t));
}
@@ -531,6 +518,7 @@
GNUNET_BIO_write_int64 (struct GNUNET_BIO_WriteHandle *h, int64_t i)
{
int64_t big;
+
big = GNUNET_htonll (i);
return GNUNET_BIO_write (h, &big, sizeof (int64_t));
}
Modified: gnunet/src/util/client.c
===================================================================
--- gnunet/src/util/client.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/client.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -243,7 +243,7 @@
* Are we ignoring shutdown signals?
*/
int ignore_shutdown;
-
+
/**
* How often have we tried to connect?
*/
@@ -262,8 +262,7 @@
*/
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;
@@ -273,27 +272,24 @@
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
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connected to unixpath
`%s'!\n", unixpath);
+ GNUNET_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 !=
@@ -306,57 +302,56 @@
GNUNET_CONFIGURATION_get_value_string (cfg,
service_name,
"HOSTNAME", &hostname)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Could not determine valid hostname and port for service
`%s' from configuration.\n"),
- service_name);
- return NULL;
- }
+ {
+ GNUNET_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);
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Need a non-empty hostname for service `%s'.\n"),
- service_name);
- return NULL;
- }
+ {
+ GNUNET_free (hostname);
+ GNUNET_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
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Port is 0 for service `%s', UNIXPATH did not work, returning
NULL!\n",
- service_name);
+ GNUNET_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);
+ sock = GNUNET_CONNECTION_create_from_connect (cfg, hostname, port);
GNUNET_free (hostname);
return sock;
}
@@ -376,8 +371,7 @@
struct GNUNET_CLIENT_Connection *ret;
struct GNUNET_CONNECTION_Handle *sock;
- sock = do_connect (service_name,
- cfg, 0);
+ sock = do_connect (service_name, cfg, 0);
ret = GNUNET_malloc (sizeof (struct GNUNET_CLIENT_Connection));
ret->attempts = 1;
ret->sock = sock;
@@ -396,12 +390,11 @@
*/
void
GNUNET_CLIENT_ignore_shutdown (struct GNUNET_CLIENT_Connection *h,
- int do_ignore)
+ int do_ignore)
{
h->ignore_shutdown = do_ignore;
if (h->sock != NULL)
- GNUNET_CONNECTION_ignore_shutdown (h->sock,
- do_ignore);
+ GNUNET_CONNECTION_ignore_shutdown (h->sock, do_ignore);
}
@@ -422,33 +415,33 @@
*/
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);
@@ -496,26 +489,25 @@
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
- GNUNET_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));
+ GNUNET_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... */
+ * entire message and we need no copying... */
/* slow path: append to array */
@@ -528,12 +520,12 @@
/* 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,
@@ -553,7 +545,7 @@
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];
@@ -561,9 +553,8 @@
#if DEBUG_CLIENT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received message of type %u and size %u\n",
- ntohs (cmsg->type),
- msize);
+ "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);
@@ -594,32 +585,32 @@
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
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "calling
GNUNET_CONNECTION_receive\n");
+ GNUNET_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);
+ }
}
@@ -630,8 +621,7 @@
service_test_error (GNUNET_SCHEDULER_Task task, void *task_cls)
{
GNUNET_SCHEDULER_add_continuation (task,
- task_cls,
- GNUNET_SCHEDULER_REASON_TIMEOUT);
+ task_cls,
GNUNET_SCHEDULER_REASON_TIMEOUT);
}
@@ -645,23 +635,24 @@
confirm_handler (void *cls, const struct GNUNET_MessageHeader *msg)
{
struct GNUNET_CLIENT_Connection *conn = cls;
+
/* We may want to consider looking at the reply in more
- detail in the future, for example, is this the
- correct service? FIXME! */
+ * detail in the future, for example, is this the
+ * correct service? FIXME! */
if (msg != NULL)
- {
+ {
#if DEBUG_CLIENT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received confirmation that service is running.\n");
+ GNUNET_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);
}
@@ -682,26 +673,26 @@
struct GNUNET_MessageHeader *msg;
if (size < sizeof (struct GNUNET_MessageHeader))
- {
+ {
#if DEBUG_CLIENT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Failure to transmit TEST request.\n"));
+ GNUNET_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
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitting `%s' request.\n", "TEST");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting `%s' request.\n", "TEST");
#endif
msg = (struct GNUNET_MessageHeader *) 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_CLIENT_receive (conn,
+ &confirm_handler,
+ conn,
+ GNUNET_TIME_absolute_get_remaining
+ (conn->test_deadline));
return sizeof (struct GNUNET_MessageHeader);
}
@@ -740,60 +731,53 @@
struct sockaddr_un s_un;
size_t slen;
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))
{
- if (strlen(unixpath) >= sizeof(s_un.sun_path))
- {
- GNUNET_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);
+ GNUNET_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);
#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
@@ -807,128 +791,126 @@
(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;
- }
-
+ service, "HOSTNAME", &hostname)))
+ {
+ /* UNIXPATH failed (if possible) AND IP failed => error */
+ service_test_error (task, task_cls);
+ return;
+ }
+
if (0 == strcmp ("localhost", hostname)
#if WINDOWS
&& 0
#endif
- )
- {
- /* can test using 'bind' */
- struct sockaddr_in s_in;
-
- memset (&s_in, 0, sizeof (s_in));
+ )
+ {
+ /* can test using 'bind' */
+ struct sockaddr_in s_in;
+
+ memset (&s_in, 0, sizeof (s_in));
#if HAVE_SOCKADDR_IN_SIN_LEN
- s_in.sin_len = saddrlens[1];
+ s_in.sin_len = saddrlens[1];
#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 WINDOWS
&& 0
#endif
- )
- {
- /* can test using 'bind' */
- struct sockaddr_in6 s_in6;
-
- memset (&s_in6, 0, sizeof (s_in6));
+ )
+ {
+ /* can test using 'bind' */
+ struct sockaddr_in6 s_in6;
+
+ memset (&s_in6, 0, sizeof (s_in6));
#if HAVE_SOCKADDR_IN_SIN_LEN
- s_in6.sin6_len = saddrlens[1];
+ s_in6.sin6_len = saddrlens[1];
#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)) ||
+ if (((0 == strcmp ("localhost", hostname)) ||
(0 == strcmp ("ip6-localhost", hostname)))
#if WINDOWS
&& 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)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _
- ("Could not connect to service `%s', must not be
running.\n"),
- service);
- service_test_error (task, task_cls);
- return;
- }
+ {
+ GNUNET_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))
- {
- GNUNET_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))
+ {
+ GNUNET_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;
+ }
}
@@ -953,61 +935,60 @@
* @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
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmission failed due to shutdown.\n");
+ GNUNET_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++);
+ 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
- GNUNET_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);
+ GNUNET_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;
- }
- GNUNET_CONNECTION_ignore_shutdown (th->sock->sock,
- th->sock->ignore_shutdown);
+ th->reconnect_task = GNUNET_SCHEDULER_add_delayed (delay,
+ &client_delayed_retry,
+ th);
+ return;
+ }
+ GNUNET_CONNECTION_ignore_shutdown (th->sock->sock,
th->sock->ignore_shutdown);
th->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;
+ }
}
@@ -1030,47 +1011,49 @@
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
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmission failed %u times, giving up.\n",
- MAX_ATTEMPTS - th->attempts_left);
+ GNUNET_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
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Failed to connect to `%s', automatically trying again.\n",
- th->sock->service_name);
+ GNUNET_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
- GNUNET_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);
+ GNUNET_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);
@@ -1108,12 +1091,12 @@
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;
@@ -1124,26 +1107,26 @@
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;
}
@@ -1158,16 +1141,16 @@
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);
}
@@ -1193,16 +1176,17 @@
tc->sock->tag = NULL;
msize = ntohs (tc->hdr->size);
if (NULL == buf)
- {
-#if DEBUG_CLIENT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Could not submit request, not expecting to receive a
response.\n"));
+ {
+#if DEBUG_CLIENT
+ GNUNET_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,
@@ -1263,13 +1247,12 @@
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;
}
Modified: gnunet/src/util/common_allocation.c
===================================================================
--- gnunet/src/util/common_allocation.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/common_allocation.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -55,15 +55,16 @@
GNUNET_xmalloc_ (size_t size, const char *filename, int linenumber)
{
void *ret;
+
/* As a security precaution, we generally do not allow very large
- allocations using the default 'GNUNET_malloc' macro */
+ * allocations using the default 'GNUNET_malloc' macro */
GNUNET_assert_at (size <= GNUNET_MAX_MALLOC_CHECKED, filename, linenumber);
ret = GNUNET_xmalloc_unchecked_ (size, filename, linenumber);
if (ret == NULL)
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "malloc");
- abort ();
- }
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "malloc");
+ abort ();
+ }
return ret;
}
@@ -79,11 +80,14 @@
* @param linenumber line where this call is being made (for debugging)
* @return allocated memory, never NULL
*/
-void *GNUNET_xmemdup_ (const void *buf, size_t size, const char *filename, int
linenumber)
+void *
+GNUNET_xmemdup_ (const void *buf, size_t size, const char *filename,
+ int linenumber)
{
void *ret;
+
/* As a security precaution, we generally do not allow very large
- allocations here */
+ * allocations here */
GNUNET_assert_at (size <= GNUNET_MAX_MALLOC_CHECKED, filename, linenumber);
#ifdef W32_MEM_LIMIT
size += sizeof (size_t);
@@ -93,10 +97,10 @@
GNUNET_assert_at (size < INT_MAX, filename, linenumber);
ret = malloc (size);
if (ret == NULL)
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "malloc");
- abort ();
- }
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "malloc");
+ abort ();
+ }
#ifdef W32_MEM_LIMIT
*((size_t *) ret) = size;
ret = &((size_t *) ret)[1];
@@ -155,9 +159,7 @@
* @return pointer to size bytes of memory
*/
void *
-GNUNET_xrealloc_ (void *ptr,
- size_t n,
- const char *filename, int linenumber)
+GNUNET_xrealloc_ (void *ptr, size_t n, const char *filename, int linenumber)
{
#ifdef W32_MEM_LIMIT
n += sizeof (size_t);
@@ -165,11 +167,11 @@
mem_used = mem_used - *((size_t *) ptr) + n;
#endif
ptr = realloc (ptr, n);
- if ( (NULL == ptr) && (n > 0) )
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "realloc");
- abort ();
- }
+ if ((NULL == ptr) && (n > 0))
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "realloc");
+ abort ();
+ }
#ifdef W32_MEM_LIMIT
ptr = &((size_t *) ptr)[1];
#endif
@@ -226,12 +228,13 @@
* @return strndup(str,len)
*/
char *
-GNUNET_xstrndup_ (const char *str, size_t len, const char *filename, int
linenumber)
+GNUNET_xstrndup_ (const char *str, size_t len, const char *filename,
+ int linenumber)
{
char *res;
GNUNET_assert_at (str != NULL, filename, linenumber);
- len = GNUNET_MIN(len,strlen(str));
+ len = GNUNET_MIN (len, strlen (str));
res = GNUNET_xmalloc_ (len + 1, filename, linenumber);
memcpy (res, str, len);
res[len] = '\0';
@@ -263,22 +266,22 @@
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;
}
Modified: gnunet/src/util/common_logging.c
===================================================================
--- gnunet/src/util/common_logging.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/common_logging.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -107,7 +107,7 @@
/**
* Component when the last bulk was logged. Will be 0-terminated.
*/
-static char last_bulk_comp[COMP_TRACK_SIZE+1];
+static char last_bulk_comp[COMP_TRACK_SIZE + 1];
/**
* Running component.
@@ -187,10 +187,7 @@
QueryPerformanceFrequency (&performance_frequency);
#endif
GNUNET_free_non_null (component);
- GNUNET_asprintf (&component,
- "%s-%d",
- comp,
- getpid());
+ GNUNET_asprintf (&component, "%s-%d", comp, getpid ());
env_loglevel = getenv ("GNUNET_LOGLEVEL");
if (env_loglevel != NULL)
env_minlevel = get_type (env_loglevel);
@@ -205,20 +202,20 @@
if (logfile == NULL)
return GNUNET_OK;
fn = GNUNET_STRINGS_filename_expand (logfile);
- if (NULL == fn)
- return GNUNET_SYSERR;
- dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn));
+ if (NULL == fn)
+ return GNUNET_SYSERR;
+ 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);
@@ -260,10 +257,10 @@
pos = loggers;
while ((pos != NULL) &&
((pos->logger != logger) || (pos->logger_cls != logger_cls)))
- {
- prev = pos;
- pos = pos->next;
- }
+ {
+ prev = pos;
+ pos = pos->next;
+ }
GNUNET_assert (pos != NULL);
if (prev == NULL)
loggers = pos->next;
@@ -286,18 +283,19 @@
const char *comp, 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;
+ }
}
@@ -323,13 +321,12 @@
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);
@@ -352,14 +349,14 @@
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;
}
@@ -387,10 +384,10 @@
va_list vacp;
if (skip_log > 0)
- {
- skip_log--;
- return;
- }
+ {
+ skip_log--;
+ return;
+ }
if ((kind & (~GNUNET_ERROR_TYPE_BULK)) > min_level)
return;
va_copy (vacp, va);
@@ -403,15 +400,18 @@
time (&timetmp);
memset (date, 0, DATE_STR_SIZE);
tmptr = localtime (&timetmp);
- gettimeofday(&timeofday, NULL);
+ 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)));
+ 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);
@@ -422,15 +422,14 @@
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);
- free (buf);
- return;
- }
+ {
+ 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);
+ free (buf);
+ return;
+ }
flush_bulk (date);
strncpy (last_bulk, buf, sizeof (last_bulk));
last_bulk_repeat = 0;
@@ -453,6 +452,7 @@
GNUNET_log (enum GNUNET_ErrorType kind, const char *message, ...)
{
va_list va;
+
va_start (va, message);
mylog (kind, component, message, va);
va_end (va);
@@ -476,11 +476,7 @@
char comp_w_pid[128];
va_start (va, message);
- GNUNET_snprintf (comp_w_pid,
- sizeof (comp_w_pid),
- "%s-%d",
- comp,
- getpid());
+ GNUNET_snprintf (comp_w_pid, sizeof (comp_w_pid), "%s-%d", comp, getpid ());
mylog (kind, comp_w_pid, message, va);
va_end (va);
}
@@ -539,7 +535,7 @@
static struct GNUNET_CRYPTO_HashAsciiEncoded ret;
GNUNET_CRYPTO_hash_to_enc (hc, &ret);
- ret.encoding[sizeof(ret)-1] = '\0';
+ ret.encoding[sizeof (ret) - 1] = '\0';
return (const char *) ret.encoding;
}
@@ -587,46 +583,47 @@
if (addr == NULL)
return _("unknown address");
switch (addr->sa_family)
- {
- case AF_INET:
- if (addrlen != sizeof (struct sockaddr_in))
- return "<invalid v4 address>";
- 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);
+ {
+ case AF_INET:
+ if (addrlen != sizeof (struct sockaddr_in))
+ return "<invalid v4 address>";
+ v4 = (const struct sockaddr_in *) addr;
+ inet_ntop (AF_INET, &v4->sin_addr, buf, INET_ADDRSTRLEN);
+ if (0 == ntohs (v4->sin_port))
return buf;
- case AF_INET6:
- if (addrlen != sizeof (struct sockaddr_in6))
- return "<invalid v4 address>";
- 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 "<unbound UNIX client>";
- 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");
- }
+ 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 "<invalid v4 address>";
+ 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 "<unbound UNIX client>";
+ 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");
+ }
}
Modified: gnunet/src/util/configuration.c
===================================================================
--- gnunet/src/util/configuration.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/configuration.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -168,90 +168,89 @@
return GNUNET_SYSERR;
dirty = cfg->dirty; /* back up value! */
if (NULL == (fp = FOPEN (fn, "r")))
- {
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "fopen", fn);
- GNUNET_free (fn);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_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] == '"')
{
- /* @INLINE@ value */
- if (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, value))
- ret = GNUNET_SYSERR; /* failed to parse included config */
+ value[i] = '\0';
+ i = 1;
}
- 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 */
+ else
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 */
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _
- ("Syntax error in configuration file `%s' at line
%u.\n"),
- filename, nr);
- ret = GNUNET_SYSERR;
- break;
- }
+ }
+ 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 */
+ GNUNET_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 */
+ * came from disk */
cfg->dirty = dirty;
GNUNET_free (section);
return ret;
@@ -295,66 +294,66 @@
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")))
- {
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "fopen", fn);
- GNUNET_free (fn);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_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")))
{
- error = 1;
- break;
+ memmove (&pos[2], &pos[1], strlen (&pos[1]));
+ pos[0] = '\\';
+ pos[1] = 'n';
}
- ent = sec->entries;
- while (ent != NULL)
+ if (0 > fprintf (fp, "%s = %s\n", ent->key, val))
{
- 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;
+ GNUNET_free (val);
break;
}
- sec = sec->next;
+ GNUNET_free (val);
+ }
+ ent = ent->next;
}
+ if (error != 0)
+ break;
+ if (0 > fprintf (fp, "\n"))
+ {
+ error = 1;
+ break;
+ }
+ sec = sec->next;
+ }
if (error != 0)
GNUNET_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_SYSERR; /* last write failed */
+ return GNUNET_SYSERR;
+ }
cfg->dirty = GNUNET_NO; /* last write succeeded */
return GNUNET_OK;
}
@@ -377,15 +376,15 @@
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;
+ }
}
@@ -398,10 +397,11 @@
* @param iter_cls closure for iter
*/
void
-GNUNET_CONFIGURATION_iterate_section_values (const struct
GNUNET_CONFIGURATION_Handle *cfg,
- const char *section,
- GNUNET_CONFIGURATION_Iterator iter,
- void *iter_cls)
+GNUNET_CONFIGURATION_iterate_section_values (const struct
+ GNUNET_CONFIGURATION_Handle *cfg,
+ const char *section,
+ GNUNET_CONFIGURATION_Iterator
iter,
+ void *iter_cls)
{
struct ConfigSection *spos;
struct ConfigEntry *epos;
@@ -415,10 +415,10 @@
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;
+ }
}
@@ -430,20 +430,21 @@
* @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;
+ 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);
+ }
}
/**
@@ -452,39 +453,39 @@
* @param cfg configuration to inspect
* @param section name of the section to remove
*/
-void GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle
*cfg,
- const char *section)
+void
+GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *section)
{
struct ConfigSection *spos;
struct ConfigSection *prev;
struct ConfigEntry *ent;
prev = NULL;
- spos = cfg->sections;
- while (spos != 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,6 +503,7 @@
const char *section, const char *option, const char *value)
{
struct GNUNET_CONFIGURATION_Handle *dst = cls;
+
GNUNET_CONFIGURATION_set_value_string (dst, section, option, value);
}
@@ -531,8 +533,7 @@
* @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;
@@ -584,15 +585,11 @@
{
struct DiffHandle *dh = cls;
struct ConfigEntry *entNew;
-
+
entNew = findEntry (dh->cfgDefault, section, option);
- if ( (entNew != NULL) &&
- (strcmp (entNew->val, value) == 0) )
+ if ((entNew != NULL) && (strcmp (entNew->val, value) == 0))
return;
- GNUNET_CONFIGURATION_set_value_string (dh->cfgDiff,
- section,
- option,
- value);
+ GNUNET_CONFIGURATION_set_value_string (dh->cfgDiff, section, option, value);
}
@@ -606,8 +603,8 @@
int
GNUNET_CONFIGURATION_write_diffs (const struct GNUNET_CONFIGURATION_Handle
*cfgDefault,
- const struct GNUNET_CONFIGURATION_Handle
*cfgNew,
- const char *filename)
+ const struct GNUNET_CONFIGURATION_Handle
+ *cfgNew, const char *filename)
{
int ret;
struct DiffHandle diffHandle;
@@ -640,19 +637,19 @@
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);
@@ -676,6 +673,7 @@
unsigned long long number)
{
char s[64];
+
GNUNET_snprintf (s, 64, "%llu", number);
GNUNET_CONFIGURATION_set_value_string (cfg, section, option, s);
}
@@ -729,12 +727,12 @@
e = findEntry (cfg, section, option);
if (e == NULL)
return GNUNET_SYSERR;
- if ( (0 == strcasecmp (e->val, "infinity")) ||
- (0 == strcasecmp (e->val, "forever")) )
- {
- *time = GNUNET_TIME_UNIT_FOREVER_REL;
- return GNUNET_OK;
- }
+ if ((0 == strcasecmp (e->val, "infinity")) ||
+ (0 == strcasecmp (e->val, "forever")))
+ {
+ *time = GNUNET_TIME_UNIT_FOREVER_REL;
+ return GNUNET_OK;
+ }
if (1 != SSCANF (e->val, "%llu", &num))
return GNUNET_SYSERR;
time->rel_value = (uint64_t) num;
@@ -762,10 +760,10 @@
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;
}
@@ -788,8 +786,7 @@
GNUNET_CONFIGURATION_Handle *cfg,
const char *section,
const char *option,
- const char **choices,
- const char **value)
+ const char **choices, const char
**value)
{
struct ConfigEntry *e;
int i;
@@ -799,19 +796,19 @@
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)
- {
- GNUNET_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;
- }
+ {
+ GNUNET_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;
}
@@ -826,10 +823,10 @@
*/
int
GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle
- *cfg, const char *section,
- const char *option)
+ *cfg, const char *section, const char *option)
{
struct ConfigEntry *e;
+
if ((NULL == (e = findEntry (cfg, section, option))) || (e->val == NULL))
return GNUNET_NO;
return GNUNET_YES;
@@ -861,25 +858,25 @@
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))
+ "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) ||
@@ -912,10 +909,10 @@
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);
@@ -984,46 +981,46 @@
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])
{
- 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++;
+ 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;
}
- 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')
+ }
+ 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;
- pos = end + 1;
+ }
}
+ if (old == '\0')
+ break;
+ pos = end + 1;
+ }
GNUNET_free (list);
return ret;
}
@@ -1047,21 +1044,21 @@
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;
}
@@ -1077,6 +1074,7 @@
test_match (void *cls, const char *fn)
{
const char *of = cls;
+
return (0 == strcmp (of, fn)) ? GNUNET_SYSERR : GNUNET_OK;
}
@@ -1159,56 +1157,55 @@
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'))
{
- while (pos[0] == ' ')
- pos++;
- if (strlen (pos) == 0)
- break;
- end = pos + 1;
- while ((end[0] != ' ') && (end[0] != '\0'))
+ if (end[0] == '\\')
+ {
+ switch (end[1])
{
- 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;
- }
- }
+ case '\\':
+ case ' ':
end++;
+ break;
+ case '\0':
+ /* illegal, but just keep it */
+ break;
+ default:
+ /* illegal, but just ignore that there was a '/' */
+ break;
}
- 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;
+ }
+ 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;
+ }
GNUNET_free (list);
GNUNET_free (match);
return GNUNET_NO;
@@ -1241,19 +1238,17 @@
GNUNET_CONFIGURATION_parse (cfg, baseconfig)) ||
(!((filename == NULL) ||
(GNUNET_OK == GNUNET_CONFIGURATION_parse (cfg, filename)))))
- {
- GNUNET_free (baseconfig);
- return (filename == NULL) ? GNUNET_OK : GNUNET_SYSERR;
- }
+ {
+ GNUNET_free (baseconfig);
+ return (filename == NULL) ? GNUNET_OK : GNUNET_SYSERR;
+ }
GNUNET_free (baseconfig);
- if ( ((GNUNET_YES != GNUNET_CONFIGURATION_have_value (cfg,
- "PATHS",
- "DEFAULTCONFIG"))) &&
- (filename != NULL) )
+ if (((GNUNET_YES != GNUNET_CONFIGURATION_have_value (cfg,
+ "PATHS",
+ "DEFAULTCONFIG"))) &&
+ (filename != NULL))
GNUNET_CONFIGURATION_set_value_string (cfg,
- "PATHS",
- "DEFAULTCONFIG",
- filename);
+ "PATHS", "DEFAULTCONFIG", filename);
if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value (cfg,
"TESTING",
"WEAKRANDOM")) &&
Modified: gnunet/src/util/connection.c
===================================================================
--- gnunet/src/util/connection.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/connection.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -296,7 +296,8 @@
*
* @param sock the connection to set persistent
*/
-void GNUNET_CONNECTION_persist_(struct GNUNET_CONNECTION_Handle *sock)
+void
+GNUNET_CONNECTION_persist_ (struct GNUNET_CONNECTION_Handle *sock)
{
sock->persist = GNUNET_YES;
}
@@ -313,7 +314,8 @@
* @param sock the connection to make flushing and blocking
* @return GNUNET_OK on success
*/
-int GNUNET_CONNECTION_disable_corking (struct GNUNET_CONNECTION_Handle *sock)
+int
+GNUNET_CONNECTION_disable_corking (struct GNUNET_CONNECTION_Handle *sock)
{
return GNUNET_NETWORK_socket_disable_corking (sock->sock);
}
@@ -327,13 +329,13 @@
* @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;
+
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);
+ ret->write_buffer = GNUNET_malloc (ret->write_buffer_size);
ret->sock = osSocket;
return ret;
}
@@ -362,8 +364,9 @@
struct sockaddr_in6 *v6;
struct sockaddr *sa;
void *uaddr;
- struct GNUNET_CONNECTION_Credentials *gcp;
- struct GNUNET_CONNECTION_Credentials gc;
+ struct GNUNET_CONNECTION_Credentials *gcp;
+ struct GNUNET_CONNECTION_Credentials gc;
+
#ifdef SO_PEERCRED
struct ucred uc;
socklen_t olen;
@@ -371,102 +374,98 @@
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)
- {
- GNUNET_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_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;
+ }
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;
+ /* 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);
+ 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)
- GNUNET_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)
+ GNUNET_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);
+ ret->write_buffer = GNUNET_malloc (ret->write_buffer_size);
ret->addr = uaddr;
ret->addrlen = addrlen;
ret->sock = sock;
@@ -521,8 +520,7 @@
* @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;
@@ -531,80 +529,77 @@
sock->destroy_task = GNUNET_SCHEDULER_NO_TASK;
GNUNET_assert (sock->dns_active == NULL);
if (0 != (sock->ccs & COCO_TRANSMIT_READY))
- {
+ {
#if DEBUG_CONNECTION
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Destroy waits for CCS-TR to be done (%p)\n", sock);
+ GNUNET_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
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Destroy waits for write_task to be done (%p)\n", sock);
+ GNUNET_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
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Shutting down socket (%p)\n", sock);
+ GNUNET_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) )
- GNUNET_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))
+ GNUNET_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
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Destroy actually runs (%p)!\n", sock);
+ GNUNET_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->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) ... */
+ }
GNUNET_free_non_null (sock->addr);
GNUNET_free_non_null (sock->hostname);
GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->destroy_task);
@@ -639,12 +634,13 @@
connect_fail_continuation (struct GNUNET_CONNECTION_Handle *h)
{
#if DEBUG_CONNECTION
- GNUNET_log ((0 != 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"),
+ GNUNET_log ((0 != 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);
#endif
/* connect failed / timed out */
@@ -655,43 +651,40 @@
/* trigger jobs that used to wait on "connect_task" */
if (0 != (h->ccs & COCO_RECEIVE_AGAIN))
- {
+ {
#if DEBUG_CONNECTION
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "connect_fail_continuation triggers receive_again (%p)\n",
- h);
+ GNUNET_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
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "connect_fail_continuation cancels timeout_task, triggers
transmit_ready (%p)\n",
- h);
+ GNUNET_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
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "connect_fail_continuation runs destroy_continuation (%p)\n",
- h);
+ GNUNET_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);
+ }
}
@@ -710,46 +703,43 @@
#endif
/* trigger jobs that waited for the connection */
if (0 != (h->ccs & COCO_RECEIVE_AGAIN))
- {
+ {
#if DEBUG_CONNECTION
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "connect_success_continuation runs receive_again (%p)\n",
- h);
+ GNUNET_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
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "connect_success_continuation runs transmit_ready, cancels
timeout_task (%p)\n",
- h);
+ GNUNET_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_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
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "connect_success_continuation runs destroy_continuation
(%p)\n",
- h);
+ GNUNET_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);
+ }
}
@@ -775,18 +765,17 @@
len = sizeof (error);
errno = 0;
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;
- }
+ 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_assert (h->sock == NULL);
h->sock = ap->sock;
GNUNET_assert (h->addr == NULL);
@@ -796,12 +785,12 @@
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);
}
@@ -823,12 +812,12 @@
struct GNUNET_TIME_Relative delay;
if (addr == NULL)
- {
- h->dns_active = NULL;
- if (NULL == h->ap_head)
- connect_fail_continuation (h);
- return;
- }
+ {
+ h->dns_active = NULL;
+ if (NULL == h->ap_head)
+ connect_fail_continuation (h);
+ return;
+ }
if (h->sock != NULL)
return; /* already connected */
GNUNET_assert (h->addr == NULL);
@@ -845,25 +834,24 @@
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
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
_("Trying to connect to `%s' (%p)\n"),
@@ -873,13 +861,13 @@
ap->addr,
ap->addrlen)) &&
(errno != EINPROGRESS))
- {
- /* maybe refused / unsupported address, try next */
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_INFO, "connect");
- GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ap->sock));
- GNUNET_free (ap);
- return;
- }
+ {
+ /* maybe refused / unsupported address, try next */
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_INFO, "connect");
+ 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)
@@ -891,8 +879,8 @@
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);
}
@@ -917,7 +905,7 @@
ret = GNUNET_malloc (sizeof (struct GNUNET_CONNECTION_Handle));
ret->cfg = cfg;
ret->write_buffer_size = GNUNET_SERVER_MIN_BUFFER_SIZE;
- ret->write_buffer = GNUNET_malloc(ret->write_buffer_size);
+ ret->write_buffer = GNUNET_malloc (ret->write_buffer_size);
ret->port = port;
ret->hostname = GNUNET_strdup (hostname);
ret->dns_active = GNUNET_RESOLVER_ip_get (ret->hostname,
@@ -939,8 +927,8 @@
*/
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;
@@ -953,9 +941,7 @@
slen = strlen (unixpath);
if (slen >= sizeof (un->sun_path))
slen = sizeof (un->sun_path) - 1;
- memcpy (un->sun_path,
- unixpath,
- slen);
+ memcpy (un->sun_path, unixpath, slen);
un->sun_path[slen] = '\0';
slen = sizeof (struct sockaddr_un);
#if HAVE_SOCKADDR_IN_SIN_LEN
@@ -967,28 +953,27 @@
ret = GNUNET_malloc (sizeof (struct GNUNET_CONNECTION_Handle));
ret->cfg = cfg;
ret->write_buffer_size = GNUNET_SERVER_MIN_BUFFER_SIZE;
- ret->write_buffer = GNUNET_malloc(ret->write_buffer_size);
+ ret->write_buffer = GNUNET_malloc (ret->write_buffer_size);
ret->port = 0;
ret->hostname = NULL;
- ret->addr = (struct sockaddr*) un;
+ ret->addr = (struct sockaddr *) un;
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;
- }
+ 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;
+ }
connect_success_continuation (ret);
return ret;
#else
@@ -1018,22 +1003,22 @@
s = GNUNET_NETWORK_socket_create (af_family, SOCK_STREAM, 0);
if (s == NULL)
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING |
- GNUNET_ERROR_TYPE_BULK, "socket");
- return NULL;
- }
+ {
+ GNUNET_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 */
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_INFO, "connect");
- GNUNET_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 */
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_INFO, "connect");
+ GNUNET_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);
@@ -1079,27 +1064,26 @@
*/
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);
+ sock->destroy_task = GNUNET_SCHEDULER_add_now (&destroy_continuation, sock);
}
@@ -1128,6 +1112,7 @@
signal_error (struct GNUNET_CONNECTION_Handle *sh, int errcode)
{
GNUNET_CONNECTION_Receiver receiver;
+
GNUNET_assert (NULL != (receiver = sh->receiver));
sh->receiver = NULL;
receiver (sh->receiver_cls, NULL, 0, sh->addr, sh->addrlen, errcode);
@@ -1148,60 +1133,60 @@
GNUNET_CONNECTION_Receiver receiver;
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 */
+ if ((GNUNET_YES == sh->ignore_shutdown) &&
+ (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)))
+ {
+ /* ignore shutdown request, go again immediately */
#if DEBUG_CONNECTION
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Ignoring shutdown signal per configuration\n");
+ GNUNET_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))
- GNUNET_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))
+ GNUNET_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
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Receive encounters error, socket closed... (%p)\n", sh);
+ GNUNET_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
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Error receiving: %s\n", STRERROR (errno));
+ GNUNET_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
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"receive_ready read %u/%u bytes from `%s' (%p)!\n",
@@ -1232,32 +1217,32 @@
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
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Receive encounters error, socket closed (%p)...\n", sh);
+ GNUNET_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
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Receive encounters error: time out (%p)...\n", sh);
+ GNUNET_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);
+ sh->read_task =
+ GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining
+ (sh->receive_timeout), sh->sock,
+ &receive_ready, sh);
}
@@ -1291,17 +1276,17 @@
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;
}
@@ -1314,7 +1299,7 @@
*/
void
GNUNET_CONNECTION_ignore_shutdown (struct GNUNET_CONNECTION_Handle *sock,
- int do_ignore)
+ int do_ignore)
{
sock->ignore_shutdown = do_ignore;
}
@@ -1332,15 +1317,15 @@
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;
}
@@ -1371,18 +1356,17 @@
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]);
+ avail, &sock->write_buffer[sock->write_buffer_off]);
GNUNET_assert (size <= avail);
sock->write_buffer_off += size;
return GNUNET_YES;
@@ -1401,15 +1385,13 @@
* @param tc scheduler context
*/
static void
-transmit_timeout (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+transmit_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_CONNECTION_Handle *sock = cls;
GNUNET_CONNECTION_TransmitReadyNotify notify;
#if DEBUG_CONNECTION
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "transmit_timeout running (%p)\n", sock);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "transmit_timeout running (%p)\n",
sock);
#endif
sock->nth.timeout_task = GNUNET_SCHEDULER_NO_TASK;
#if DEBUG_CONNECTION
@@ -1436,8 +1418,7 @@
* @param tc scheduler context
*/
static void
-connect_error (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+connect_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_CONNECTION_Handle *sock = cls;
GNUNET_CONNECTION_TransmitReadyNotify notify;
@@ -1445,10 +1426,7 @@
#if DEBUG_CONNECTION
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Transmission request of size %u fails (%s/%u), connection
failed (%p).\n",
- sock->nth.notify_size,
- sock->hostname,
- sock->port,
- sock);
+ sock->nth.notify_size, sock->hostname, sock->port, sock);
#endif
sock->write_task = GNUNET_SCHEDULER_NO_TASK;
notify = sock->nth.notify_ready;
@@ -1468,19 +1446,18 @@
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 */
notify = sock->nth.notify_ready;
@@ -1506,102 +1483,99 @@
size_t have;
#if DEBUG_CONNECTION
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "transmit_ready running (%p).\n", sock);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "transmit_ready running (%p).\n", sock);
#endif
GNUNET_assert (sock->write_task != GNUNET_SCHEDULER_NO_TASK);
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)
- goto SCHEDULE_WRITE; /* ignore shutdown, go again immediately */
+ if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
+ {
+ if (sock->ignore_shutdown == GNUNET_YES)
+ goto SCHEDULE_WRITE; /* ignore shutdown, go again immediately */
#if DEBUG_CONNECTION
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmit to `%s' fails, shutdown happened (%p).\n",
- GNUNET_a2s (sock->addr, sock->addrlen), sock);
+ GNUNET_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
- GNUNET_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
+ GNUNET_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
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _
- ("Could not satisfy pending transmission request, socket
closed or connect failed (%p).\n"),
- sock);
+ GNUNET_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;
- }
+ 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;
+ }
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],
+
&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;
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to send to `%s': %s\n"),
- GNUNET_a2s (sock->addr,
- sock->addrlen),
- STRERROR (en));
+ int en = errno;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to send to `%s': %s\n"),
+ GNUNET_a2s (sock->addr, sock->addrlen), STRERROR (en));
#endif
#if DEBUG_CONNECTION
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, "send");
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, "send");
#endif
- transmit_error (sock);
- return;
- }
+ transmit_error (sock);
+ return;
+ }
#if DEBUG_CONNECTION
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"transmit_ready transmitted %u/%u bytes to `%s' (%p)\n",
@@ -1610,11 +1584,11 @@
#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! */
/* not done writing, schedule more */
@@ -1624,14 +1598,15 @@
"Re-scheduling transmit_ready (more to do) (%p).\n", sock);
#endif
have = sock->write_buffer_off - sock->write_buffer_pos;
- GNUNET_assert ( (sock->nth.notify_ready != NULL) || (have > 0) );
+ 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);
}
@@ -1657,10 +1632,10 @@
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);
@@ -1674,39 +1649,37 @@
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
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Scheduling transmit_ready (%p).\n", sock);
+ GNUNET_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
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "CCS-Scheduling transmit_ready, adding timeout task (%p).\n",
- sock);
+ GNUNET_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;
}
@@ -1723,24 +1696,23 @@
{
GNUNET_assert (h->notify_ready != NULL);
if (0 != (h->sh->ccs & COCO_TRANSMIT_READY))
- {
+ {
#if DEBUG_CONNECTION
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "notify_transmit_ready_cancel cancels timeout_task (%p)\n",
- h);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "notify_transmit_ready_cancel cancels timeout_task (%p)\n", h);
#endif
- GNUNET_SCHEDULER_cancel (h->timeout_task);
- h->timeout_task = GNUNET_SCHEDULER_NO_TASK;
- h->sh->ccs -= COCO_TRANSMIT_READY;
- }
+ GNUNET_SCHEDULER_cancel (h->timeout_task);
+ h->timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ h->sh->ccs -= COCO_TRANSMIT_READY;
+ }
else
+ {
+ if (h->sh->write_task != GNUNET_SCHEDULER_NO_TASK)
{
- if (h->sh->write_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (h->sh->write_task);
- h->sh->write_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ GNUNET_SCHEDULER_cancel (h->sh->write_task);
+ h->sh->write_task = GNUNET_SCHEDULER_NO_TASK;
}
+ }
h->notify_ready = NULL;
}
Modified: gnunet/src/util/container_bloomfilter.c
===================================================================
--- gnunet/src/util/container_bloomfilter.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/util/container_bloomfilter.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -82,9 +82,9 @@
* @param bf the filter
* @return number of bytes used for the data of the bloom filter
*/
-size_t
+size_t
GNUNET_CONTAINER_bloomfilter_get_size (const struct
GNUNET_CONTAINER_BloomFilter
- *bf)
+ *bf)
{
if (bf == NULL)
return 0;
@@ -99,11 +99,12 @@
* @return copy of the bf
*/
struct GNUNET_CONTAINER_BloomFilter *
-GNUNET_CONTAINER_bloomfilter_copy (const struct GNUNET_CONTAINER_BloomFilter
*bf)
+GNUNET_CONTAINER_bloomfilter_copy (const struct GNUNET_CONTAINER_BloomFilter
+ *bf)
{
return GNUNET_CONTAINER_bloomfilter_init (bf->bitArray,
- bf->bitArraySize,
- bf->addressesPerElement);
+ bf->bitArraySize,
+ bf->addressesPerElement);
}
@@ -198,15 +199,15 @@
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,
@@ -245,23 +246,23 @@
/* 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));
@@ -290,19 +291,19 @@
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;
}
@@ -319,7 +320,7 @@
* @param bit the current bit
*/
typedef void (*BitIterator) (void *cls,
- const struct GNUNET_CONTAINER_BloomFilter *bf,
+ const struct GNUNET_CONTAINER_BloomFilter * bf,
unsigned int bit);
/**
@@ -333,7 +334,7 @@
*/
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;
@@ -344,26 +345,26 @@
memcpy (&tmp[0], key, sizeof (GNUNET_HashCode));
round = 0;
while (bitCount > 0)
+ {
+ while (slot < (sizeof (GNUNET_HashCode) / sizeof (uint32_t)))
{
- while (slot < (sizeof (GNUNET_HashCode) / sizeof (uint32_t)))
- {
- callback (arg,
- bf,
- (((uint32_t *) &tmp[round & 1])[slot]) &
- ((bf->bitArraySize * 8) - 1));
- 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;
- }
+ callback (arg,
+ bf,
+ (((uint32_t *) & tmp[round & 1])[slot]) &
+ ((bf->bitArraySize * 8) - 1));
+ 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;
+ }
+ }
}
/**
@@ -379,6 +380,7 @@
unsigned int bit)
{
struct GNUNET_CONTAINER_BloomFilter *b = cls;
+
incrementBit (b->bitArray, bit, bf->fh);
}
@@ -395,6 +397,7 @@
unsigned int bit)
{
struct GNUNET_CONTAINER_BloomFilter *b = cls;
+
decrementBit (b->bitArray, bit, bf->fh);
}
@@ -408,9 +411,10 @@
static void
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;
}
@@ -450,25 +454,25 @@
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_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);
@@ -477,28 +481,28 @@
rbuff = GNUNET_malloc (BUFFSIZE);
pos = 0;
while (pos < size * 8)
+ {
+ int res;
+
+ res = GNUNET_DISK_file_read (bf->fh, rbuff, BUFFSIZE);
+ if (res == -1)
{
- int res;
-
- res = GNUNET_DISK_file_read (bf->fh, rbuff, BUFFSIZE);
- if (res == -1)
- {
- GNUNET_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 */
+ GNUNET_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 */
+ }
GNUNET_free (rbuff);
return bf;
}
@@ -530,19 +534,19 @@
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)
@@ -563,8 +567,9 @@
* @return GNUNET_SYSERR if the data array is not big enough
*/
int
-GNUNET_CONTAINER_bloomfilter_get_raw_data (const struct
GNUNET_CONTAINER_BloomFilter
- *bf, char *data, size_t size)
+GNUNET_CONTAINER_bloomfilter_get_raw_data (const struct
+ GNUNET_CONTAINER_BloomFilter *bf,
+ char *data, size_t size)
{
if (NULL == bf)
return GNUNET_SYSERR;
@@ -618,8 +623,8 @@
* @return GNUNET_YES if the element is in the filter, GNUNET_NO if not
*/
int
-GNUNET_CONTAINER_bloomfilter_test (const struct GNUNET_CONTAINER_BloomFilter
*bf,
- const GNUNET_HashCode * e)
+GNUNET_CONTAINER_bloomfilter_test (const struct GNUNET_CONTAINER_BloomFilter
+ *bf, const GNUNET_HashCode * e)
{
int res;
@@ -663,20 +668,20 @@
{
unsigned int i;
unsigned int n;
- unsigned long long* fc;
- const unsigned long long* dc;
+ unsigned long long *fc;
+ const unsigned long long *dc;
if (NULL == bf)
return GNUNET_YES;
if (bf->bitArraySize != size)
return GNUNET_SYSERR;
- fc = (unsigned long long*) bf->bitArray;
- dc = (const unsigned long long*) data;
+ fc = (unsigned long long *) bf->bitArray;
+ dc = (const unsigned long long *) data;
n = size / sizeof (unsigned long long);
for (i = 0; i < n; i++)
fc[i] |= dc[i];
- for (i = n * sizeof(unsigned long long); i < size; i++)
+ for (i = n * sizeof (unsigned long long); i < size; i++)
bf->bitArray[i] |= data[i];
return GNUNET_OK;
}
@@ -693,25 +698,25 @@
*/
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;
- unsigned long long* fc;
- const unsigned long long* dc;
+ unsigned long long *fc;
+ const unsigned long long *dc;
if (NULL == bf)
return GNUNET_YES;
if (bf->bitArraySize != size)
return GNUNET_SYSERR;
- fc = (unsigned long long*) bf->bitArray;
- dc = (const unsigned long long*) to_or->bitArray;
+ fc = (unsigned long long *) bf->bitArray;
+ dc = (const unsigned long long *) to_or->bitArray;
n = size / sizeof (unsigned long long);
for (i = 0; i < n; i++)
fc[i] |= dc[i];
- for (i = n * sizeof(unsigned long long); i < size; i++)
+ for (i = n * sizeof (unsigned long long); i < size; i++)
bf->bitArray[i] |= to_or->bitArray[i];
return GNUNET_OK;
}
Modified: gnunet/src/util/container_heap.c
===================================================================
--- gnunet/src/util/container_heap.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/container_heap.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -94,7 +94,7 @@
* Number of elements in the heap.
*/
unsigned int size;
-
+
/**
* How is the heap sorted?
*/
@@ -108,15 +108,17 @@
* Check if internal invariants hold for the given node.
*
* @param node subtree to check
- */
+ */
static void
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);
}
@@ -194,7 +196,8 @@
* @return cost of the node
*/
GNUNET_CONTAINER_HeapCostType
-GNUNET_CONTAINER_heap_node_get_cost (const struct GNUNET_CONTAINER_HeapNode
*node)
+GNUNET_CONTAINER_heap_node_get_cost (const struct GNUNET_CONTAINER_HeapNode
+ *node)
{
return node->cost;
}
@@ -210,26 +213,18 @@
*/
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;
if (GNUNET_YES != node_iterator (heap,
- node->left_child,
- iterator,
- iterator_cls))
+ node->left_child, iterator, iterator_cls))
return GNUNET_NO;
if (GNUNET_YES != node_iterator (heap,
- node->right_child,
- iterator,
- iterator_cls))
+ node->right_child, iterator, iterator_cls))
return GNUNET_NO;
- return iterator (iterator_cls,
- node,
- node->element,
- node->cost);
+ return iterator (iterator_cls, node, node->element, node->cost);
}
@@ -269,13 +264,12 @@
if (heap->root == NULL)
return NULL;
pos = heap->walk_pos;
- if (pos == NULL)
- pos = heap->root;
+ if (pos == NULL)
+ 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;
+ heap->walk_pos
+ = (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 2))
+ ? pos->right_child : pos->left_child;
return element;
}
@@ -290,51 +284,50 @@
*/
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) )
+ while ((heap->order == GNUNET_CONTAINER_HEAP_ORDER_MAX)
+ ? (pos->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);
@@ -351,8 +344,7 @@
*/
struct GNUNET_CONTAINER_HeapNode *
GNUNET_CONTAINER_heap_insert (struct GNUNET_CONTAINER_Heap *heap,
- void *element,
- GNUNET_CONTAINER_HeapCostType cost)
+ void *element, GNUNET_CONTAINER_HeapCostType
cost)
{
struct GNUNET_CONTAINER_HeapNode *node;
@@ -388,28 +380,28 @@
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) );
+ GNUNET_assert (((heap->size == 0) &&
+ (heap->root == NULL)) ||
+ (heap->size == heap->root->tree_size + 1));
CHECK (heap->root);
#endif
return ret;
@@ -430,7 +422,7 @@
/* update 'size' of the ancestors */
ancestor = node;
- while (NULL != (ancestor = ancestor->parent))
+ while (NULL != (ancestor = ancestor->parent))
ancestor->tree_size--;
/* update 'size' of node itself */
@@ -441,43 +433,43 @@
/* 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;
@@ -498,7 +490,7 @@
void *ret;
struct GNUNET_CONTAINER_Heap *heap;
- heap = node->heap;
+ heap = node->heap;
CHECK (heap->root);
if (heap->walk_pos == node)
(void) GNUNET_CONTAINER_heap_walk_get_next (heap);
@@ -510,9 +502,9 @@
GNUNET_free (node);
#if DEBUG
CHECK (heap->root);
- GNUNET_assert (( (heap->size == 0) &&
- (heap->root == NULL) ) ||
- (heap->size == heap->root->tree_size + 1) );
+ GNUNET_assert (((heap->size == 0) &&
+ (heap->root == NULL)) ||
+ (heap->size == heap->root->tree_size + 1));
#endif
return ret;
}
@@ -527,21 +519,21 @@
*/
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) );
+ GNUNET_assert (((heap->size == 0) &&
+ (heap->root == NULL)) ||
+ (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) );
+ GNUNET_assert (((heap->size == 1) &&
+ (heap->root == NULL)) ||
+ (heap->size == heap->root->tree_size + 2));
#endif
node->cost = new_cost;
if (heap->root == NULL)
@@ -550,9 +542,9 @@
insert_node (heap, heap->root, node);
#if DEBUG
CHECK (heap->root);
- GNUNET_assert ( ( (heap->size == 0) &&
- (heap->root == NULL) ) ||
- (heap->size == heap->root->tree_size + 1) );
+ GNUNET_assert (((heap->size == 0) &&
+ (heap->root == NULL)) ||
+ (heap->size == heap->root->tree_size + 1));
#endif
}
Modified: gnunet/src/util/container_meta_data.c
===================================================================
--- gnunet/src/util/container_meta_data.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/util/container_meta_data.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -39,7 +39,7 @@
{
/**
* This is a linked list.
- */
+ */
struct MetaItem *next;
/**
@@ -160,10 +160,10 @@
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);
}
@@ -174,7 +174,7 @@
*
* @param md metadata to manipulate
*/
-void
+void
GNUNET_CONTAINER_meta_data_clear (struct GNUNET_CONTAINER_MetaData *md)
{
struct MetaItem *item;
@@ -182,10 +182,10 @@
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));
}
@@ -219,27 +219,25 @@
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;
}
@@ -264,12 +262,11 @@
*/
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;
@@ -279,32 +276,29 @@
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;
@@ -315,24 +309,24 @@
md->items = i;
else
prev->next = i;
- i->mime_type = (data_mime_type == NULL) ? NULL : GNUNET_strdup
(data_mime_type);
+ i->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;
}
@@ -353,20 +347,19 @@
* @param data actual meta-data found
* @param data_len number of bytes in data
* @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)
+ */
+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)
{
struct GNUNET_CONTAINER_MetaData *md = cls;
+
(void) GNUNET_CONTAINER_meta_data_insert (md, plugin_name,
- type, format,
- data_mime_type, data, data_len);
+ type, format,
+ data_mime_type, data, data_len);
return 0;
}
@@ -378,9 +371,9 @@
* @param md metadata to extend
* @param in metadata to merge
*/
-void
+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);
}
@@ -398,9 +391,8 @@
*/
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;
@@ -408,26 +400,24 @@
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;
}
@@ -440,25 +430,21 @@
*/
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);
+ EXTRACTOR_METATYPE_PUBLICATION_DATE,
+ NULL, 0);
dat = GNUNET_STRINGS_absolute_time_to_string (t);
- GNUNET_CONTAINER_meta_data_insert (md,
- "<gnunet>",
- EXTRACTOR_METATYPE_PUBLICATION_DATE,
- EXTRACTOR_METAFORMAT_UTF8,
- "text/plain",
- dat,
- strlen(dat)+1);
+ GNUNET_CONTAINER_meta_data_insert (md,
+ "<gnunet>",
+ EXTRACTOR_METATYPE_PUBLICATION_DATE,
+ EXTRACTOR_METAFORMAT_UTF8,
+ "text/plain", dat, strlen (dat) + 1);
GNUNET_free (dat);
}
@@ -473,9 +459,9 @@
*/
int
GNUNET_CONTAINER_meta_data_iterate (const struct
- GNUNET_CONTAINER_MetaData *md,
- EXTRACTOR_MetaDataProcessor
- iter, void *iter_cls)
+ GNUNET_CONTAINER_MetaData *md,
+ EXTRACTOR_MetaDataProcessor
+ iter, void *iter_cls)
{
struct MetaItem *pos;
@@ -485,17 +471,14 @@
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;
}
@@ -520,13 +503,13 @@
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;
}
@@ -556,14 +539,15 @@
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;
}
@@ -590,22 +574,21 @@
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 (match == NULL)
- match = pos;
- else if ( (match->type != EXTRACTOR_METATYPE_THUMBNAIL) &&
- (pos->type == EXTRACTOR_METATYPE_THUMBNAIL) )
- match = pos;
- }
- pos = pos->next;
+ {
+ 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;
}
- if ( (match == NULL) ||
- (match->data_size == 0) )
+ pos = pos->next;
+ }
+ if ((match == NULL) || (match->data_size == 0))
return 0;
*thumb = GNUNET_malloc (match->data_size);
memcpy (*thumb, match->data, match->data_size);
@@ -631,16 +614,15 @@
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;
}
@@ -660,10 +642,8 @@
* GNUNET_NO if compression did not help
*/
static int
-try_compression (const char *data,
- size_t oldSize,
- char **result,
- size_t *newSize)
+try_compression (const char *data,
+ size_t oldSize, char **result, size_t * newSize)
{
char *tmp;
uLongf dlen;
@@ -673,19 +653,19 @@
#else
dlen = oldSize + (oldSize / 100) + 20;
/* documentation says 100.1% oldSize + 12 bytes, but we
- should be able to overshoot by more to be safe */
+ * should be able to overshoot by more to be safe */
#endif
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;
}
@@ -744,7 +724,7 @@
{
/**
* Meta data type. Corresponds to an 'enum EXTRACTOR_MetaType'
- */
+ */
uint32_t type;
/**
@@ -793,8 +773,8 @@
{
struct GNUNET_CONTAINER_MetaData *vmd;
struct MetaItem *pos;
- struct MetaDataHeader ihdr;
- struct MetaDataHeader *hdr;
+ struct MetaDataHeader ihdr;
+ struct MetaDataHeader *hdr;
struct MetaDataEntry *ent;
char *dst;
unsigned int i;
@@ -814,78 +794,76 @@
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;
}
- dst = NULL;
+ 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));
+ 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;
@@ -894,115 +872,102 @@
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);
+ {
+ 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 ((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 (((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++;
+ 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++;
+ }
GNUNET_free (ent);
/* nothing fit, only write header! */
ihdr.version = htonl (2);
ihdr.entries = htonl (0);
ihdr.size = htonl (0);
- if (*target == NULL)
+ if (*target == NULL)
*target = GNUNET_malloc (sizeof (struct MetaDataHeader));
memcpy (*target, &ihdr, sizeof (struct MetaDataHeader));
return sizeof (struct MetaDataHeader);
@@ -1016,18 +981,19 @@
* @return number of bytes needed for serialization, -1 on error
*/
ssize_t
-GNUNET_CONTAINER_meta_data_get_serialized_size (const struct
GNUNET_CONTAINER_MetaData *md)
+GNUNET_CONTAINER_meta_data_get_serialized_size (const struct
+ GNUNET_CONTAINER_MetaData *md)
{
ssize_t ret;
char *ptr;
-
+
if (md->sbuf != NULL)
return md->sbuf_size;
ptr = NULL;
ret = GNUNET_CONTAINER_meta_data_serialize (md,
- &ptr,
- GNUNET_MAX_MALLOC_CHECKED,
-
GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL);
+ &ptr,
+ GNUNET_MAX_MALLOC_CHECKED,
+
GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL);
if (ret != -1)
GNUNET_free (ptr);
return ret;
@@ -1045,9 +1011,7 @@
* @return NULL on error
*/
static char *
-decompress (const char *input,
- size_t inputSize,
- size_t outputSize)
+decompress (const char *input, size_t inputSize, size_t outputSize)
{
char *output;
uLongf olen;
@@ -1056,14 +1020,14 @@
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;
+ }
}
@@ -1100,136 +1064,129 @@
if (size < sizeof (struct MetaDataHeader))
return NULL;
- memcpy (&hdr,
- input,
- sizeof (struct MetaDataHeader));
+ memcpy (&hdr, input, sizeof (struct MetaDataHeader));
version = ntohl (hdr.version) & HEADER_VERSION_MASK;
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);
+ dataSize = ntohl (hdr.size);
if ((sizeof (struct MetaDataEntry) * ic) > dataSize)
- {
- GNUNET_break_op (0);
- return NULL;
- }
+ {
+ GNUNET_break_op (0);
+ return NULL;
+ }
if (compressed)
+ {
+ if (dataSize >= GNUNET_MAX_MALLOC_CHECKED)
{
- 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 =
+ /* 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;
+ if (data == NULL)
+ {
+ 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++)
+ 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];
+ 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);
+ if (mlen > left)
+ {
+ GNUNET_break_op (0);
+ break;
}
- GNUNET_free_non_null (data);
+ 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;
}
Modified: gnunet/src/util/container_multihashmap.c
===================================================================
--- gnunet/src/util/container_multihashmap.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/util/container_multihashmap.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -107,13 +107,13 @@
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 @@
idx_of (const struct GNUNET_CONTAINER_MultiHashMap *m,
const GNUNET_HashCode * key)
{
- GNUNET_assert (m!=NULL);
+ GNUNET_assert (m != NULL);
return (*(unsigned int *) key) % m->map_length;
}
@@ -167,11 +167,11 @@
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;
}
@@ -198,22 +198,22 @@
GNUNET_HashCode kc;
count = 0;
- GNUNET_assert(map != NULL);
+ 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;
}
@@ -242,21 +242,21 @@
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;
}
@@ -283,27 +283,27 @@
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;
}
@@ -326,11 +326,11 @@
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;
}
@@ -345,22 +345,23 @@
* @return GNUNET_YES if such a value exists,
* GNUNET_NO if not
*/
-int GNUNET_CONTAINER_multihashmap_contains_value (const struct
- GNUNET_CONTAINER_MultiHashMap
- *map,
- const GNUNET_HashCode * key,
- const void *value)
+int
+GNUNET_CONTAINER_multihashmap_contains_value (const struct
+ 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;
}
@@ -388,15 +389,15 @@
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);
}
@@ -417,8 +418,7 @@
GNUNET_CONTAINER_multihashmap_put (struct GNUNET_CONTAINER_MultiHashMap *map,
const GNUNET_HashCode * key,
void *value,
- enum GNUNET_CONTAINER_MultiHashMapOption
- opt)
+ enum GNUNET_CONTAINER_MultiHashMapOption
opt)
{
struct MapEntry *e;
unsigned int i;
@@ -426,25 +426,25 @@
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;
@@ -479,14 +479,14 @@
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;
}
Modified: gnunet/src/util/container_slist.c
===================================================================
--- gnunet/src/util/container_slist.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/container_slist.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -113,16 +113,16 @@
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;
@@ -146,7 +146,8 @@
e = create_elem (disp, buf, len);
e->next = l->head;
l->head = e;
- if (l->tail == NULL) l->tail = e;
+ if (l->tail == NULL)
+ l->tail = e;
l->length++;
}
@@ -159,8 +160,8 @@
*/
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;
@@ -180,19 +181,22 @@
* @param src source
*/
void
-GNUNET_CONTAINER_slist_append (struct GNUNET_CONTAINER_SList *dst, struct
GNUNET_CONTAINER_SList *src)
+GNUNET_CONTAINER_slist_append (struct GNUNET_CONTAINER_SList *dst,
+ struct GNUNET_CONTAINER_SList *src)
{
struct GNUNET_CONTAINER_SList_Iterator *i;
for (i = GNUNET_CONTAINER_slist_begin (src); GNUNET_CONTAINER_slist_end (i)
!=
- GNUNET_YES; GNUNET_CONTAINER_slist_next (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);
}
@@ -249,13 +253,13 @@
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;
@@ -394,8 +398,7 @@
* @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)
{
GNUNET_free (i);
}
Modified: gnunet/src/util/crypto_aes.c
===================================================================
--- gnunet/src/util/crypto_aes.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/crypto_aes.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -39,7 +39,7 @@
gcry_randomize (&key->key[0], GNUNET_CRYPTO_AES_KEY_LENGTH,
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));
}
/**
@@ -84,20 +84,19 @@
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));
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));
+ rc = gcry_cipher_setiv (handle, iv,
+ 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);
@@ -127,23 +126,21 @@
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));
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));
+ rc = gcry_cipher_setiv (handle, iv,
+ 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,9 +155,8 @@
*/
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;
@@ -179,12 +175,11 @@
*/
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)
+ 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);
+ GNUNET_CRYPTO_kdf_v (iv->iv, sizeof (iv->iv), salt, salt_len, skey->key,
+ sizeof (skey->key), argp);
}
/* end of crypto_aes.c */
Modified: gnunet/src/util/crypto_crc.c
===================================================================
--- gnunet/src/util/crypto_crc.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/crypto_crc.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -52,7 +52,7 @@
* with the ccorrect final value. Thus, it is safe to call
* even on a table that someone else is using concurrently.
*/
-static void
+static void
crc_init ()
{
static int once;
@@ -64,12 +64,12 @@
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;
+ }
}
/*
@@ -105,6 +105,7 @@
GNUNET_CRYPTO_crc32_n (const void *buf, size_t len)
{
uLong crc;
+
crc = crc32 (0L, Z_NULL, 0);
crc = crc32 (crc, (char *) buf, len);
return crc;
Modified: gnunet/src/util/crypto_hash.c
===================================================================
--- gnunet/src/util/crypto_hash.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/crypto_hash.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -115,8 +115,8 @@
* and free associated resources.
*/
static void
-file_hash_finish (struct GNUNET_CRYPTO_FileHashContext *fhc,
- const GNUNET_HashCode * res)
+file_hash_finish (struct GNUNET_CRYPTO_FileHashContext *fhc,
+ const GNUNET_HashCode * res)
{
fhc->callback (fhc->callback_cls, res);
GNUNET_free (fhc->filename);
@@ -146,22 +146,20 @@
if (fhc->fsize - fhc->offset < delta)
delta = fhc->fsize - fhc->offset;
if (delta != GNUNET_DISK_file_read (fhc->fh, fhc->buffer, delta))
- {
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
- "read", fhc->filename);
- file_hash_finish (fhc, NULL);
- return;
- }
+ {
+ GNUNET_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;
- }
- fhc->task
- = GNUNET_SCHEDULER_add_now (&file_hash_task, fhc);
+ {
+ 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);
}
@@ -185,36 +183,36 @@
struct GNUNET_CRYPTO_FileHashContext *fhc;
GNUNET_assert (blocksize > 0);
- fhc = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_FileHashContext) +
blocksize);
+ fhc =
+ 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);
if (!fhc->fh)
- {
- GNUNET_free (fhc->filename);
- GNUNET_free (fhc);
- return NULL;
- }
- fhc->task
- = GNUNET_SCHEDULER_add_with_priority (priority,
- &file_hash_task, fhc);
+ {
+ GNUNET_free (fhc->filename);
+ GNUNET_free (fhc);
+ return NULL;
+ }
+ fhc->task
+ = GNUNET_SCHEDULER_add_with_priority (priority, &file_hash_task, fhc);
return fhc;
}
@@ -278,23 +276,22 @@
rpos = 0;
bits = 0;
while ((rpos < sizeof (GNUNET_HashCode)) || (vbit > 0))
+ {
+ if ((rpos < sizeof (GNUNET_HashCode)) && (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 = (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;
+ }
GNUNET_assert (wpos == sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1);
GNUNET_assert (vbit == 0);
result->encoding[wpos] = '\0';
@@ -323,17 +320,17 @@
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;
@@ -356,6 +353,7 @@
{
unsigned int x1 = (a->bits[1] - b->bits[1]) >> 16;
unsigned int x2 = (b->bits[1] - a->bits[1]) >> 16;
+
return (x1 * x2);
}
@@ -364,6 +362,7 @@
GNUNET_HashCode * result)
{
int i;
+
for (i = (sizeof (GNUNET_HashCode) / sizeof (uint32_t)) - 1; i >= 0; i--)
result->bits[i] = GNUNET_CRYPTO_random_u32 (mode, UINT32_MAX);
}
@@ -374,31 +373,29 @@
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)
+ 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] = a->bits[i] ^ b->bits[i];
}
@@ -409,15 +406,14 @@
void
GNUNET_CRYPTO_hash_to_aes_key (const GNUNET_HashCode * hc,
struct GNUNET_CRYPTO_AesSessionKey *skey,
- struct GNUNET_CRYPTO_AesInitializationVector
- *iv)
+ struct GNUNET_CRYPTO_AesInitializationVector
*iv)
{
GNUNET_assert (sizeof (GNUNET_HashCode) >=
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));
}
@@ -430,8 +426,7 @@
* @return Bit \a bit from hashcode \a code, -1 for invalid index
*/
int
-GNUNET_CRYPTO_hash_get_bit (const GNUNET_HashCode * code,
- unsigned int bit)
+GNUNET_CRYPTO_hash_get_bit (const GNUNET_HashCode * code, unsigned int bit)
{
GNUNET_assert (bit < 8 * sizeof (GNUNET_HashCode));
return (((unsigned char *) code)[bit >> 3] & (1 << (bit & 7))) > 0;
@@ -449,14 +444,15 @@
*
* @return the number of bits that match
*/
-unsigned int
-GNUNET_CRYPTO_hash_matching_bits(const GNUNET_HashCode *first,
- const GNUNET_HashCode *second)
+unsigned int
+GNUNET_CRYPTO_hash_matching_bits (const GNUNET_HashCode * first,
+ 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))
+ if (GNUNET_CRYPTO_hash_get_bit (first, i) !=
+ GNUNET_CRYPTO_hash_get_bit (second, i))
return i;
return sizeof (GNUNET_HashCode) * 8;
}
@@ -468,8 +464,7 @@
* @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;
@@ -477,14 +472,13 @@
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;
}
@@ -504,14 +498,14 @@
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;
}
@@ -525,11 +519,9 @@
* @param ... pair of void * & size_t for context chunks, terminated by NULL
*/
void
-GNUNET_CRYPTO_hmac_derive_key(struct GNUNET_CRYPTO_AuthKey *key,
- const struct GNUNET_CRYPTO_AesSessionKey *rkey,
- const void *salt,
- size_t salt_len,
- ...)
+GNUNET_CRYPTO_hmac_derive_key (struct GNUNET_CRYPTO_AuthKey *key,
+ const struct GNUNET_CRYPTO_AesSessionKey *rkey,
+ const void *salt, size_t salt_len, ...)
{
va_list argp;
@@ -548,18 +540,14 @@
* @param argp pair of void * & size_t for context chunks, terminated by NULL
*/
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)
+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)
{
GNUNET_CRYPTO_kdf_v (key->key,
- sizeof(key->key),
- salt, salt_len,
- rkey->key,
- sizeof(rkey->key),
- argp);
+ sizeof (key->key),
+ salt, salt_len, rkey->key, sizeof (rkey->key), argp);
}
@@ -571,23 +559,22 @@
* @param plaintext_len length of plaintext
* @param hmac where to store the hmac
*/
-void
+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_setkey (md, key->key, sizeof(key->key));
+ 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);
if (mc != NULL)
- memcpy (hmac->bits, mc, sizeof(hmac->bits));
+ memcpy (hmac->bits, mc, sizeof (hmac->bits));
gcry_md_close (md);
}
Modified: gnunet/src/util/crypto_hkdf.c
===================================================================
--- gnunet/src/util/crypto_hkdf.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/crypto_hkdf.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -71,9 +71,8 @@
* @return HMAC, freed by caller via gcry_md_close/_reset
*/
static const void *
-doHMAC (gcry_md_hd_t mac,
- const void *key, size_t key_len,
- const void *buf, size_t buf_len)
+doHMAC (gcry_md_hd_t mac,
+ const void *key, size_t key_len, const void *buf, size_t buf_len)
{
gcry_md_setkey (mac, key, key_len);
gcry_md_write (mac, buf, buf_len);
@@ -92,38 +91,33 @@
* @return GNUNET_YES on success
*/
static int
-getPRK (gcry_md_hd_t mac,
- const void *xts, size_t xts_len,
- const void *skm, size_t skm_len,
- void *prk)
+getPRK (gcry_md_hd_t mac,
+ const void *xts, size_t xts_len,
+ const void *skm, size_t skm_len, void *prk)
{
const void *ret;
ret = doHMAC (mac, xts, xts_len, skm, skm_len);
if (ret == NULL)
return GNUNET_SYSERR;
- memcpy (prk,
- ret,
- gcry_md_get_algo_dlen (gcry_md_get_algo (mac)));
+ memcpy (prk, ret, gcry_md_get_algo_dlen (gcry_md_get_algo (mac)));
return GNUNET_YES;
}
#if DEBUG_HKDF
-static void
-dump(const char *src,
- const void *p,
- unsigned int l)
+static void
+dump (const char *src, const void *p, unsigned int l)
{
unsigned int i;
- printf("\n%s: ", src);
+ printf ("\n%s: ", src);
for (i = 0; i < l; i++)
- {
- printf("%2x", (int) ((const unsigned char *) p)[i]);
- }
- printf("\n");
+ {
+ printf ("%2x", (int) ((const unsigned char *) p)[i]);
+ }
+ printf ("\n");
}
#endif
@@ -143,10 +137,9 @@
*/
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)
+ 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;
@@ -161,10 +154,10 @@
if (k == 0)
return GNUNET_SYSERR;
- if (gcry_md_open(&xtr, xtr_algo, GCRY_MD_FLAG_HMAC) != GPG_ERR_NO_ERROR)
+ if (gcry_md_open (&xtr, xtr_algo, GCRY_MD_FLAG_HMAC) != GPG_ERR_NO_ERROR)
return GNUNET_SYSERR;
- if (gcry_md_open(&prf, prf_algo, GCRY_MD_FLAG_HMAC) != GPG_ERR_NO_ERROR)
+ if (gcry_md_open (&prf, prf_algo, GCRY_MD_FLAG_HMAC) != GPG_ERR_NO_ERROR)
{
gcry_md_close (xtr);
return GNUNET_SYSERR;
@@ -174,15 +167,15 @@
ctx_len = 0;
while (NULL != va_arg (args, void *))
- ctx_len += va_arg (args, size_t);
- va_end(args);
+ ctx_len += va_arg (args, size_t);
+ va_end (args);
+
memset (result, 0, out_len);
- if (getPRK (xtr, xts, xts_len, skm, skm_len, prk)
- != GNUNET_YES)
+ if (getPRK (xtr, xts, xts_len, skm, skm_len, prk) != GNUNET_YES)
goto hkdf_error;
#if DEBUG_HKDF
- dump("PRK", prk, xtr_len);
+ dump ("PRK", prk, xtr_len);
#endif
t = out_len / k;
@@ -190,46 +183,44 @@
/* K(1) */
{
- size_t plain_len = k + ctx_len + 1;
- char plain[plain_len];
- const void *ctx;
- char *dst;
+ size_t plain_len = k + ctx_len + 1;
+ char plain[plain_len];
+ const void *ctx;
+ char *dst;
- dst = plain + k;
- va_copy (args, argp);
- while ((ctx = va_arg (args, void *)))
- {
- size_t len;
+ dst = plain + k;
+ va_copy (args, argp);
+ while ((ctx = va_arg (args, void *)))
+ {
+ size_t len;
- len = va_arg (args, size_t);
- memcpy (dst, ctx, len);
- dst += len;
- }
- va_end (args);
+ len = va_arg (args, size_t);
+ memcpy (dst, ctx, len);
+ dst += len;
+ }
+ va_end (args);
- if (t > 0)
+ if (t > 0)
{
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);
+ 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++)
+ /* 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);
#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)
@@ -238,18 +229,18 @@
result += k;
}
- /* K(t):d */
- if (d > 0)
+ /* K(t):d */
+ if (d > 0)
{
if (t > 0)
- {
- memcpy (plain, result - k, k);
- i++;
- }
+ {
+ 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);
@@ -260,11 +251,11 @@
memcpy (result, hc, d);
}
#if DEBUG_HKDF
- dump("result", result - k, out_len);
+ dump ("result", result - k, out_len);
#endif
- ret = GNUNET_YES;
- goto hkdf_ok;
+ ret = GNUNET_YES;
+ goto hkdf_ok;
}
hkdf_error:
ret = GNUNET_SYSERR;
@@ -290,18 +281,17 @@
*/
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,
- ...)
+ int xtr_algo, int prf_algo,
+ const void *xts, size_t xts_len,
+ const void *skm, size_t skm_len, ...)
{
va_list argp;
int ret;
- va_start(argp, skm_len);
+ va_start (argp, skm_len);
ret = GNUNET_CRYPTO_hkdf_v (result, out_len, xtr_algo, prf_algo, xts,
- xts_len, skm, skm_len, argp);
- va_end(argp);
+ xts_len, skm, skm_len, argp);
+ va_end (argp);
return ret;
}
Modified: gnunet/src/util/crypto_kdf.c
===================================================================
--- gnunet/src/util/crypto_kdf.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/crypto_kdf.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -42,23 +42,23 @@
*/
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)
+ const void *xts, size_t xts_len, const void *skm,
+ size_t skm_len, va_list argp)
{
/*
- "Finally, we point out to a particularly advantageous instantiation using
- HMAC-SHA512 as XTR and HMAC-SHA256 in PRF* (in which case the output from
SHA-512 is
- truncated to 256 bits). This makes sense in two ways: First, the
extraction part is where we need a
- stronger hash function due to the unconventional demand from the hash
function in the extraction
- setting. Second, as shown in Section 6, using HMAC with a truncated output
as an extractor
- allows to prove the security of HKDF under considerably weaker assumptions
on the underlying
- hash function."
-
- http://eprint.iacr.org/2010/264
+ * "Finally, we point out to a particularly advantageous instantiation using
+ * HMAC-SHA512 as XTR and HMAC-SHA256 in PRF* (in which case the output from
SHA-512 is
+ * truncated to 256 bits). This makes sense in two ways: First, the
extraction part is where we need a
+ * stronger hash function due to the unconventional demand from the hash
function in the extraction
+ * setting. Second, as shown in Section 6, using HMAC with a truncated
output as an extractor
+ * allows to prove the security of HKDF under considerably weaker
assumptions on the underlying
+ * hash function."
+ *
+ * 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);
+ xts, xts_len, skm, skm_len, argp);
}
/**
@@ -74,15 +74,15 @@
*/
int
GNUNET_CRYPTO_kdf (void *result, size_t out_len,
- 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);
+ va_start (argp, skm_len);
ret = GNUNET_CRYPTO_kdf_v (result, out_len, xts, xts_len, skm, skm_len,
argp);
- va_end(argp);
+ va_end (argp);
return ret;
}
Modified: gnunet/src/util/crypto_ksk.c
===================================================================
--- gnunet/src/util/crypto_ksk.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/crypto_ksk.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -49,12 +49,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;
/**
@@ -82,23 +82,23 @@
tmp = *rnd;
for (i = 0; i < cnt; i++)
+ {
+ int j;
+
+ if (i > 0)
+ GNUNET_CRYPTO_hash (&hc, sizeof (GNUNET_HashCode), &tmp);
+ for (j = 0; j < sizeof (GNUNET_HashCode) / sizeof (uint32_t); 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 HAVE_GCRY_MPI_LSHIFT
- gcry_mpi_lshift (n, n, sizeof(uint32_t)*8);
+#if HAVE_GCRY_MPI_LSHIFT
+ 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)
@@ -110,12 +110,12 @@
{
unsigned int idx, cnt;
- cnt = gcry_mpi_get_nbits(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;
}
@@ -154,7 +154,7 @@
a2 = gcry_mpi_set_ui (NULL, 2);
nbits = gcry_mpi_get_nbits (n);
- gcry_mpi_sub_ui(nminus1, n, 1);
+ gcry_mpi_sub_ui (nminus1, n, 1);
/* Find q and k, so that n = 1 + 2^k * q . */
q = gcry_mpi_set (NULL, nminus1);
@@ -162,30 +162,30 @@
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);
}
+ 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:
@@ -208,18 +208,18 @@
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);
+ }
}
static void
-gen_prime (gcry_mpi_t *ptest, unsigned int nbits, GNUNET_HashCode * hc)
+gen_prime (gcry_mpi_t * ptest, unsigned int nbits, GNUNET_HashCode * hc)
{
/* Note: 2 is not included because it can be tested more easily by
- looking at bit 0. The last entry in this list is marked by a zero */
+ * looking at bit 0. The last entry in this list is marked by a zero */
static const uint16_t small_prime_numbers[] = {
3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43,
47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101,
@@ -317,76 +317,77 @@
/* Make nbits fit into mpz_t implementation. */
val_2 = gcry_mpi_set_ui (NULL, 2);
val_3 = gcry_mpi_set_ui (NULL, 3);
- prime = gcry_mpi_snew(0);
- result = gcry_mpi_new(0);
- pminus1 = gcry_mpi_new(0);
- *ptest = gcry_mpi_new(0);
+ prime = gcry_mpi_snew (0);
+ result = gcry_mpi_new (0);
+ pminus1 = gcry_mpi_new (0);
+ *ptest = gcry_mpi_new (0);
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);
+ size_t written;
- /* Calculate all remainders. */
+ 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;
+ {
+ uint16_t x = small_prime_numbers[i];
- 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.
*/
+ 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;
+ 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;
- }
- }
+ /* 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;
+ }
}
+ }
}
/**
@@ -396,11 +397,11 @@
* @param hc the HC to use for PRNG (modified!)
*/
static void
-generate_kblock_key (KBlock_secret_key * sk,
+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;
@@ -409,47 +410,47 @@
nbits++;
sk->e = gcry_mpi_set_ui (NULL, 257);
- sk->n = gcry_mpi_new(0);
- sk->p = gcry_mpi_new(0);
- sk->q = gcry_mpi_new(0);
- sk->d = gcry_mpi_new(0);
- sk->u = gcry_mpi_new(0);
+ sk->n = gcry_mpi_new (0);
+ sk->p = gcry_mpi_new (0);
+ sk->q = gcry_mpi_new (0);
+ sk->d = gcry_mpi_new (0);
+ sk->u = gcry_mpi_new (0);
- t1 = gcry_mpi_new(0);
- t2 = gcry_mpi_new(0);
- phi = gcry_mpi_new(0);
- g = gcry_mpi_new(0);
- f = gcry_mpi_new(0);
+ t1 = gcry_mpi_new (0);
+ t2 = gcry_mpi_new (0);
+ phi = gcry_mpi_new (0);
+ g = gcry_mpi_new (0);
+ 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);
+ 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);
+ 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 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 */
- }
+ /* 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)));
@@ -499,14 +500,14 @@
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 ] */
+ * -- 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;
@@ -516,10 +517,10 @@
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);
@@ -544,10 +545,10 @@
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;
}
@@ -574,10 +575,10 @@
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,
@@ -585,11 +586,11 @@
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,
@@ -597,101 +598,100 @@
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);
+ "(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);
@@ -706,10 +706,10 @@
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;
@@ -739,13 +739,13 @@
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;
@@ -761,10 +761,10 @@
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);
}
Modified: gnunet/src/util/crypto_random.c
===================================================================
--- gnunet/src/util/crypto_random.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/crypto_random.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -61,37 +61,37 @@
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;
}
@@ -117,12 +117,12 @@
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;
}
@@ -142,33 +142,33 @@
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);
+ 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 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;
}
@@ -205,33 +205,33 @@
if (0 != strcmp (what, "need_entropy"))
return;
if (current == total)
+ {
+ if (genproc != NULL)
{
- if (genproc != NULL)
- {
- if (0 != GNUNET_OS_process_kill (genproc, SIGTERM))
- GNUNET_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))
GNUNET_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))
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "kill");
+ GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (genproc));
+ GNUNET_OS_process_close (genproc);
+ genproc = NULL;
+ }
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
_("Starting `%s' process to generate entropy\n"), "find");
genproc = GNUNET_OS_start_process (NULL, NULL, "sh",
@@ -246,11 +246,11 @@
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;
+ }
}
@@ -258,19 +258,20 @@
{
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));
+ SRANDOM (time (NULL) ^
+ GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX));
}
@@ -282,4 +283,3 @@
/* end of crypto_random.c */
-
Modified: gnunet/src/util/crypto_rsa.c
===================================================================
--- gnunet/src/util/crypto_rsa.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/crypto_rsa.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -92,10 +92,10 @@
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);
+ }
}
/**
@@ -142,44 +142,44 @@
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;
}
@@ -193,8 +193,7 @@
GNUNET_CRYPTO_rsa_key_get_public (const struct GNUNET_CRYPTO_RsaPrivateKey
*priv,
struct
- GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
- *pub)
+ GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pub)
{
gcry_mpi_t skey[2];
size_t size;
@@ -207,16 +206,15 @@
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]));
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
@@ -252,38 +250,36 @@
(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);
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;
@@ -309,10 +305,10 @@
#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);
@@ -330,20 +326,20 @@
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);
@@ -368,12 +364,12 @@
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;
}
@@ -388,7 +384,8 @@
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 *encoding =
+ (const struct RsaPrivateKeyBinaryEncoded *) buf;
gcry_sexp_t res;
gcry_mpi_t n, e, d, p, q, u;
int rc;
@@ -396,7 +393,7 @@
int pos;
uint16_t enc_len;
- enc_len = ntohs(encoding->len);
+ enc_len = ntohs (encoding->len);
if (len != enc_len)
return NULL;
@@ -408,10 +405,10 @@
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,
@@ -419,11 +416,11 @@
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,
@@ -431,100 +428,99 @@
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);
+ "(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);
@@ -539,10 +535,10 @@
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;
@@ -579,167 +575,156 @@
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))
{
- 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))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
- "access", filename);
- else
- GNUNET_break (0); /* what is going on!? */
- return NULL;
- }
- continue;
- }
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
- "open", filename);
+ /* must exist but not be accessible, fail for good! */
+ if (0 != ACCESS (filename, R_OK))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
+ "access", filename);
+ else
+ GNUNET_break (0); /* what is going on!? */
return NULL;
}
- cnt = 0;
+ continue;
+ }
+ GNUNET_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;
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _
- ("Could not aquire lock on file `%s': %s...\n"),
- filename, STRERROR (ec));
- }
- }
- GNUNET_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)))
- GNUNET_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);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("I am host `%s'. Stored new private key in `%s'.\n"),
- GNUNET_i2s (&pid),
- filename);
- return ret;
+ while (GNUNET_YES !=
+ GNUNET_DISK_file_lock (fd, 0,
+ sizeof (struct
+ RsaPrivateKeyBinaryEncoded),
+ GNUNET_YES))
+ {
+ sleep (1);
+ if (0 == ++cnt % 10)
+ {
+ ec = errno;
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _
+ ("Could not aquire lock on file `%s': %s...\n"),
+ filename, STRERROR (ec));
+ }
}
+ GNUNET_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)))
+ GNUNET_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);
+ GNUNET_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);
if (NULL == fd)
- {
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", filename);
- return NULL;
- }
+ {
+ GNUNET_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))
{
+ if (0 == ++cnt % 60)
+ {
+ ec = errno;
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Could not aquire lock on file `%s': %s...\n"),
+ filename, STRERROR (ec));
+ GNUNET_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!? */
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", filename);
if (GNUNET_YES !=
- GNUNET_DISK_file_lock (fd, 0,
- sizeof (struct RsaPrivateKeyBinaryEncoded),
- GNUNET_NO))
- {
- if (0 == ++cnt % 60)
- {
- ec = errno;
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Could not aquire lock on file `%s': %s...\n"),
- filename, STRERROR (ec));
- GNUNET_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!? */
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
- "stat", filename);
- if (GNUNET_YES !=
- GNUNET_DISK_file_unlock (fd, 0,
- sizeof (struct
- RsaPrivateKeyBinaryEncoded)))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "fcntl",
- filename);
- GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd));
+ GNUNET_DISK_file_unlock (fd, 0,
+ sizeof (struct RsaPrivateKeyBinaryEncoded)))
+ GNUNET_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)))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "fcntl",
- filename);
- if (0 == ++cnt % 10)
- {
- GNUNET_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));
- GNUNET_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;
+ 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)))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "fcntl",
filename);
+ if (0 == ++cnt % 10)
+ {
+ GNUNET_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));
+ GNUNET_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))))
+ if ((len != fs) ||
+ (NULL == (ret = GNUNET_CRYPTO_rsa_decode_key ((char *) enc, len))))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _
+ ("File `%s' does not contain a valid private key. Deleting
it.\n"),
+ filename);
+ if (0 != UNLINK (filename))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _
- ("File `%s' does not contain a valid private key. Deleting
it.\n"),
- filename);
- if (0 != UNLINK (filename))
- {
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
- "unlink",
- filename);
- }
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename);
}
+ }
GNUNET_free (enc);
if (GNUNET_YES !=
GNUNET_DISK_file_unlock (fd, 0,
@@ -747,14 +732,13 @@
GNUNET_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);
- GNUNET_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);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("I am host `%s'. Read private key from `%s'.\n"),
+ GNUNET_i2s (&pid), filename);
+ }
return ret;
}
@@ -853,8 +837,7 @@
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);
@@ -946,8 +929,7 @@
size = sizeof (struct GNUNET_CRYPTO_RsaSignature);
GNUNET_assert (0 == gcry_mpi_scan (&val,
GCRYMPI_FMT_USG,
- (const unsigned char *) sig, size,
- &size));
+ (const unsigned char *) sig, size,
&size));
GNUNET_assert (0 ==
gcry_sexp_build (&sigdata, &erroff, "(sig-val(rsa(s %m)))",
val));
@@ -963,22 +945,22 @@
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)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("RSA signature verification failed at %s:%d: %s\n"),
- __FILE__, __LINE__, gcry_strerror (rc));
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_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;
}
Modified: gnunet/src/util/disk.c
===================================================================
--- gnunet/src/util/disk.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/disk.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -109,7 +109,8 @@
};
-int translate_unix_perms(enum GNUNET_DISK_AccessPermissions perm)
+int
+translate_unix_perms (enum GNUNET_DISK_AccessPermissions perm)
{
int mode;
@@ -149,6 +150,7 @@
getSizeRec (void *cls, const char *fn)
{
struct GetFileSizeData *gfsd = cls;
+
#ifdef HAVE_STAT64
struct stat64 buf;
#else
@@ -157,26 +159,26 @@
#ifdef HAVE_STAT64
if (0 != STAT64 (fn, &buf))
- {
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat64", fn);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat64", fn);
+ return GNUNET_SYSERR;
+ }
#else
if (0 != STAT (fn, &buf))
- {
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", fn);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_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;
}
@@ -211,23 +213,24 @@
enum GNUNET_DISK_Seek whence)
{
if (h == NULL)
- {
- errno = EINVAL;
- return GNUNET_SYSERR;
- }
+ {
+ errno = EINVAL;
+ return GNUNET_SYSERR;
+ }
#ifdef MINGW
DWORD ret;
+
static DWORD t[] = {[GNUNET_DISK_SEEK_SET] = FILE_BEGIN,
[GNUNET_DISK_SEEK_CUR] = FILE_CURRENT,[GNUNET_DISK_SEEK_END] = FILE_END
};
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,
@@ -291,39 +294,39 @@
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;
- }
+ 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;
+ }
#elif WINDOWS
// FIXME NILS: test this
struct GNUNET_DISK_FileHandle *fh;
BY_HANDLE_FILE_INFORMATION info;
int succ;
- fh = GNUNET_DISK_file_open(filename, GNUNET_DISK_OPEN_READ, 0);
+ fh = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ, 0);
if (fh == NULL)
return GNUNET_SYSERR;
- succ = GetFileInformationByHandle(fh->h, &info);
- GNUNET_DISK_file_close(fh);
+ 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;
@@ -351,40 +354,39 @@
char *tmpl;
char *fn;
- if ( (t[0] != '/') &&
- (t[0] != '\\')
+ if ((t[0] != '/') && (t[0] != '\\')
#if WINDOWS
- && ! (isalpha ((int) t[0]) && (t[0] != '\0') && (t[1] == ':'))
+ && !(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)
- {
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "mkstemp", fn);
- GNUNET_free (fn);
- return NULL;
- }
+ {
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "mkstemp", fn);
+ GNUNET_free (fn);
+ return NULL;
+ }
if (0 != CLOSE (fd))
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "close", fn);
return fn;
@@ -405,10 +407,10 @@
struct statvfs buf;
if (0 != statvfs (part, &buf))
- {
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "statfs", part);
- return -1;
- }
+ {
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "statfs", part);
+ return -1;
+ }
return buf.f_bavail;
#elif MINGW
DWORD dwDummy;
@@ -423,21 +425,22 @@
GNUNET_free (path);
szDrive[3] = 0;
if (!GetDiskFreeSpace (szDrive, &dwDummy, &dwDummy, &dwBlocks, &dwDummy))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("`%s' failed for drive `%s': %u\n"),
- "GetDiskFreeSpace", szDrive, GetLastError ());
+ {
+ GNUNET_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))
- {
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "statfs", part);
- return -1;
- }
+ {
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "statfs", part);
+ return -1;
+ }
return s.f_bavail;
#endif
}
@@ -461,21 +464,21 @@
ret = STAT (fil, &filestat);
if (ret != 0)
+ {
+ if (errno != ENOENT)
{
- if (errno != ENOENT)
- {
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", fil);
- return GNUNET_SYSERR;
- }
- return GNUNET_NO;
+ GNUNET_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)
- {
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "access", fil);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "access", fil);
+ return GNUNET_SYSERR;
+ }
return GNUNET_YES;
}
@@ -500,27 +503,27 @@
ret = STAT (rdir, &filestat);
if (ret != 0)
+ {
+ if (errno != ENOENT)
{
- if (errno != ENOENT)
- {
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", rdir);
- GNUNET_free (rdir);
- return GNUNET_SYSERR;
- }
+ GNUNET_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)
- {
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "access", rdir);
- GNUNET_free (rdir);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "access", rdir);
+ GNUNET_free (rdir);
+ return GNUNET_SYSERR;
+ }
GNUNET_free (rdir);
return GNUNET_YES;
}
@@ -549,53 +552,52 @@
#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))
- {
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "mkdir",
- rdir);
- GNUNET_free (rdir);
- return GNUNET_SYSERR;
- }
- }
- rdir[pos] = DIR_SEPARATOR;
+ if ((ret != 0) && (errno != EEXIST))
+ {
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "mkdir", rdir);
+ GNUNET_free (rdir);
+ return GNUNET_SYSERR;
}
- pos++;
+ }
+ rdir[pos] = DIR_SEPARATOR;
}
+ pos++;
+ }
GNUNET_free (rdir);
return GNUNET_OK;
}
@@ -645,15 +647,15 @@
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 (h->type != GNUNET_PIPE)
{
if (!ReadFile (h->h, result, len, &bytesRead, NULL))
{
@@ -665,13 +667,13 @@
{
if (!ReadFile (h->h, result, len, NULL, h->oOverlapRead))
{
- if(GetLastError () != ERROR_IO_PENDING )
+ if (GetLastError () != ERROR_IO_PENDING)
{
SetErrnoFromWinError (GetLastError ());
return GNUNET_SYSERR;
}
}
- GetOverlappedResult(h->h, h->oOverlapRead, &bytesRead, TRUE);
+ GetOverlappedResult (h->h, h->oOverlapRead, &bytesRead, TRUE);
}
return bytesRead;
#else
@@ -694,8 +696,7 @@
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);
@@ -717,15 +718,15 @@
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 (h->type != GNUNET_PIPE)
{
if (!WriteFile (h->h, buffer, n, &bytesWritten, NULL))
{
@@ -740,19 +741,19 @@
#endif
if (!WriteFile (h->h, buffer, n, NULL, h->oOverlapWrite))
{
- if(GetLastError () != ERROR_IO_PENDING )
+ if (GetLastError () != ERROR_IO_PENDING)
{
SetErrnoFromWinError (GetLastError ());
#if DEBUG_PIPE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error writing to pipe\n");
#endif
- return GNUNET_SYSERR;
+ return GNUNET_SYSERR;
}
}
#if DEBUG_PIPE
GNUNET_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
@@ -819,64 +820,64 @@
while ((strlen (dname) > 0) && (dname[strlen (dname) - 1] == DIR_SEPARATOR))
dname[strlen (dname) - 1] = '\0';
if (0 != STAT (dname, &istat))
- {
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", dname);
- GNUNET_free (dname);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", dname);
+ GNUNET_free (dname);
+ return GNUNET_SYSERR;
+ }
if (!S_ISDIR (istat.st_mode))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Expected `%s' to be a directory!\n"), dirName);
- GNUNET_free (dname);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_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))
- {
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "opendir", dname);
- if (dinfo != NULL)
- closedir (dinfo);
- GNUNET_free (dname);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_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);
@@ -960,27 +961,26 @@
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_DISK_directory_iterator_next (iter, GNUNET_YES);
+ return GNUNET_NO;
+ }
GNUNET_SCHEDULER_add_with_priority (iter->priority,
&directory_iterator_task, iter);
return GNUNET_YES;
@@ -1011,11 +1011,11 @@
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);
@@ -1058,21 +1058,21 @@
return GNUNET_OK;
if ((errno != EISDIR) &&
/* EISDIR is not sufficient in all cases, e.g.
- sticky /tmp directory may result in EPERM on BSD.
- So we also explicitly check "isDirectory" */
+ * sticky /tmp directory may result in EPERM on BSD.
+ * So we also explicitly check "isDirectory" */
(GNUNET_YES != GNUNET_DISK_directory_test (fileName)))
- {
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "rmdir", fileName);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_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))
- {
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "rmdir", fileName);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "rmdir", fileName);
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
}
@@ -1109,22 +1109,22 @@
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);
@@ -1149,17 +1149,17 @@
idx = fn;
while (*idx)
+ {
+ c = *idx;
+
+ if (c == '/' || c == '\\' || c == ':' || c == '*' || c == '?' ||
+ c == '"' || c == '<' || c == '>' || c == '|')
{
- c = *idx;
+ *idx = '_';
+ }
- if (c == '/' || c == '\\' || c == ':' || c == '*' || c == '?' ||
- c == '"' || c == '<' || c == '>' || c == '|')
- {
- *idx = '_';
- }
-
- idx++;
- }
+ idx++;
+ }
}
@@ -1179,12 +1179,12 @@
pws = getpwnam (user);
if (pws == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Cannot obtain information about user `%s': %s\n"),
- user, STRERROR (errno));
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_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))
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "chown", filename);
#endif
@@ -1205,10 +1205,10 @@
off_t lockEnd, int excl)
{
if (fh == NULL)
- {
- errno = EINVAL;
- return GNUNET_SYSERR;
- }
+ {
+ errno = EINVAL;
+ return GNUNET_SYSERR;
+ }
#ifndef MINGW
struct flock fl;
@@ -1227,12 +1227,11 @@
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;
- }
+ | LOCKFILE_FAIL_IMMEDIATELY, 0, lockEnd - lockStart, 0, &o))
+ {
+ SetErrnoFromWinError (GetLastError ());
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
#endif
@@ -1251,10 +1250,10 @@
off_t unlockEnd)
{
if (fh == NULL)
- {
- errno = EINVAL;
- return GNUNET_SYSERR;
- }
+ {
+ errno = EINVAL;
+ return GNUNET_SYSERR;
+ }
#ifndef MINGW
struct flock fl;
@@ -1273,10 +1272,10 @@
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
@@ -1302,6 +1301,7 @@
{
char *expfn;
struct GNUNET_DISK_FileHandle *ret;
+
#ifdef MINGW
DWORD access;
DWORD disp;
@@ -1324,11 +1324,11 @@
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)
@@ -1336,22 +1336,22 @@
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))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "open", expfn);
- else
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_DEBUG, "open", expfn);
- GNUNET_free (expfn);
- return NULL;
- }
+ {
+ if (0 == (flags & GNUNET_DISK_OPEN_FAILIFEXISTS))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "open", expfn);
+ else
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_DEBUG, "open", expfn);
+ GNUNET_free (expfn);
+ return NULL;
+ }
#else
access = 0;
disp = OPEN_ALWAYS;
@@ -1364,48 +1364,47 @@
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_WRITE, NULL, disp, FILE_ATTRIBUTE_NORMAL, NULL);
if (h == INVALID_HANDLE_VALUE)
+ {
+ SetErrnoFromWinError (GetLastError ());
+ GNUNET_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 ());
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "open", expfn);
+ GNUNET_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 ());
- GNUNET_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));
@@ -1429,28 +1428,28 @@
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 ());
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "close");
- GNUNET_free (h->oOverlapRead);
- GNUNET_free (h->oOverlapWrite);
- GNUNET_free (h);
- return GNUNET_SYSERR;
- }
+ {
+ SetErrnoFromWinError (GetLastError ());
+ GNUNET_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)
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "close");
- GNUNET_free (h);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "close");
+ GNUNET_free (h);
+ return GNUNET_SYSERR;
+ }
#endif
GNUNET_free (h);
return GNUNET_OK;
@@ -1482,43 +1481,44 @@
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)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("No `%s' specified for service `%s' in configuration.\n"),
- "HOME", serviceName);
- return NULL;
- }
+ {
+ GNUNET_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 *);
- if (c == NULL)
- break;
- needed += strlen (c);
- if ((c[strlen (c) - 1] != '/') && (c[strlen (c) - 1] != '\\'))
- needed++;
- }
+ {
+ c = va_arg (ap, const char *);
+
+ 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 *);
- if (c == NULL)
- break;
- if ((c[strlen (c) - 1] != '/') && (c[strlen (c) - 1] != '\\'))
- strcat (ret, DIR_SEPARATOR_STR);
- strcat (ret, c);
- }
+ {
+ 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);
+ }
va_end (ap);
if ((ret[strlen (ret) - 1] != '/') && (ret[strlen (ret) - 1] != '\\'))
(void) GNUNET_DISK_directory_create_for_file (ret);
@@ -1571,52 +1571,52 @@
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
@@ -1631,10 +1631,10 @@
(*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
@@ -1649,21 +1649,22 @@
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
@@ -1681,10 +1682,10 @@
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;
@@ -1715,9 +1716,7 @@
create_selectable_pipe (PHANDLE read_pipe_ptr,
PHANDLE write_pipe_ptr,
LPSECURITY_ATTRIBUTES sa_ptr,
- DWORD psize,
- DWORD dwReadMode,
- DWORD dwWriteMode)
+ DWORD psize, DWORD dwReadMode, DWORD dwWriteMode)
{
/* Default to error. */
*read_pipe_ptr = *write_pipe_ptr = INVALID_HANDLE_VALUE;
@@ -1731,108 +1730,107 @@
char pipename[MAX_PATH];
/* Retry CreateNamedPipe as long as the pipe name is in use.
- Retrying will probably never be necessary, but we want
- to be as robust as possible. */
+ * 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
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CreateNamedPipe: name = %s, size =
%lu\n", pipename, psize);
+ GNUNET_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);
+ /* 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 (read_pipe != INVALID_HANDLE_VALUE)
+ {
#if DEBUG_PIPE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pipe read handle = %p\n",
read_pipe);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pipe read handle = %p\n",
+ read_pipe);
#endif
- break;
- }
+ break;
+ }
- DWORD err = GetLastError ();
- switch (err)
- {
- case ERROR_PIPE_BUSY:
- /* The pipe is already open with compatible parameters.
- Pick a new name and retry. */
+ DWORD err = GetLastError ();
+
+ switch (err)
+ {
+ case ERROR_PIPE_BUSY:
+ /* The pipe is already open with compatible parameters.
+ * Pick a new name and retry. */
#if DEBUG_PIPE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pipe busy, retrying\n");
+ GNUNET_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
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pipe access denied,
retrying\n");
+ GNUNET_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
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CreateNamedPipe not
implemented, resorting to "
- "CreatePipe: size = %lu\n", psize);
+ GNUNET_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
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pipe read handle = %p\n",
*read_pipe_ptr);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pipe write handle = %p\n",
*write_pipe_ptr);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pipe read handle = %p\n",
+ *read_pipe_ptr);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pipe write handle = %p\n",
+ *write_pipe_ptr);
#endif
- return GNUNET_OK;
- }
- err = GetLastError ();
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "CreatePipe failed: %d\n", err);
- return err;
- default:
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "CreateNamedPipe failed: %d\n",
err);
- return err;
- }
- /* NOTREACHED */
+ return GNUNET_OK;
+ }
+ err = GetLastError ();
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "CreatePipe failed: %d\n", err);
+ return err;
+ default:
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "CreateNamedPipe failed: %d\n",
err);
+ return err;
}
+ /* NOTREACHED */
+ }
#if DEBUG_PIPE
GNUNET_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 */
+ * 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 */
if (write_pipe == INVALID_HANDLE_VALUE)
- {
- /* Failure. */
- DWORD err = GetLastError ();
+ {
+ /* Failure. */
+ DWORD err = GetLastError ();
+
#if DEBUG_PIPE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CreateFile failed: %d\n", err);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CreateFile failed: %d\n", err);
#endif
- CloseHandle (read_pipe);
- return err;
- }
+ CloseHandle (read_pipe);
+ return err;
+ }
#if DEBUG_PIPE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pipe write handle = %p\n", write_pipe);
#endif
@@ -1858,9 +1856,8 @@
struct GNUNET_DISK_PipeHandle *p;
struct GNUNET_DISK_FileHandle *fds;
- p =
- GNUNET_malloc (sizeof (struct GNUNET_DISK_PipeHandle) +
- 2 * sizeof (struct GNUNET_DISK_FileHandle));
+ p = GNUNET_malloc (sizeof (struct GNUNET_DISK_PipeHandle) +
+ 2 * sizeof (struct GNUNET_DISK_FileHandle));
fds = (struct GNUNET_DISK_FileHandle *) &p[1];
p->fd[0] = &fds[0];
p->fd[1] = &fds[1];
@@ -1872,13 +1869,13 @@
ret = pipe (fd);
if (ret == -1)
- {
- eno = errno;
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "pipe");
- GNUNET_free (p);
- errno = eno;
- return NULL;
- }
+ {
+ eno = errno;
+ GNUNET_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;
@@ -1902,60 +1899,64 @@
if (0 > fcntl (fd[1], F_SETFD, flags))
ret = -1;
if (ret == -1)
- {
- eno = errno;
- GNUNET_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;
+ GNUNET_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);
+ ret =
+ 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;
- }
- CloseHandle (p->fd[0]->h);
- p->fd[0]->h = tmp_handle;
+ 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;
- }
+ 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;
+ }
CloseHandle (p->fd[1]->h);
p->fd[1]->h = tmp_handle;
if (!blocking)
- {
- DWORD mode;
+ {
+ 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 */
- }
+ 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;
@@ -1984,51 +1985,51 @@
*/
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;
@@ -2048,35 +2049,35 @@
#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;
@@ -2114,93 +2115,104 @@
openMode |= FILE_FLAG_FIRST_PIPE_INSTANCE;
while (h == NULL)
+ {
+ DWORD error_code;
+
+ name = NULL;
+ if (*fn != NULL)
{
- DWORD error_code;
- name = NULL;
- if (*fn != NULL)
- {
- GNUNET_asprintf(&name, "\\\\.\\pipe\\%.246s", fn);
+ GNUNET_asprintf (&name, "\\\\.\\pipe\\%.246s", fn);
#if DEBUG_NPIPE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to create an instance
of named pipe `%s'\n", name);
+ GNUNET_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
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to create unique named
pipe `%s'\n", *fn);
+ GNUNET_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
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Pipe creation have failed
because of %d, errno is %d\n", error_code, errno);
+ GNUNET_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
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Pipe was to be unique,
considering re-creation\n");
+ GNUNET_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
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Pipe name was not unique,
trying again\n");
+ GNUNET_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));
+ ret = GNUNET_malloc (sizeof (*ret));
ret->h = h;
ret->type = GNUNET_PIPE;
ret->oOverlapRead = GNUNET_malloc (sizeof (OVERLAPPED));
ret->oOverlapWrite = GNUNET_malloc (sizeof (OVERLAPPED));
- ret->oOverlapRead->hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
- ret->oOverlapWrite->hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
+ ret->oOverlapRead->hEvent = CreateEvent (NULL, FALSE, FALSE, NULL);
+ ret->oOverlapWrite->hEvent = CreateEvent (NULL, FALSE, FALSE, NULL);
return ret;
#else
if (*fn == NULL)
- {
- char dir[] = "/tmp/gnunet-pipe-XXXXXX";
+ {
+ char dir[] = "/tmp/gnunet-pipe-XXXXXX";
- if (mkdtemp(dir) == NULL)
- {
- GNUNET_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 (mkdtemp (dir) == NULL)
{
- if ( (errno != EEXIST) ||
- (0 != (flags & GNUNET_DISK_OPEN_FAILIFEXISTS)) )
- return NULL;
+ GNUNET_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;
+ }
+
flags = flags & (~GNUNET_DISK_OPEN_FAILIFEXISTS);
- return GNUNET_DISK_file_open(*fn, flags, perm);
+ return GNUNET_DISK_file_open (*fn, flags, perm);
#endif
}
@@ -2232,14 +2244,14 @@
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 = GNUNET_malloc (sizeof (*ret));
ret->h = h;
ret->type = GNUNET_PIPE;
ret->oOverlapRead = GNUNET_malloc (sizeof (OVERLAPPED));
@@ -2250,7 +2262,7 @@
return ret;
#else
flags = flags & (~GNUNET_DISK_OPEN_FAILIFEXISTS);
- return GNUNET_DISK_file_open(fn, flags, perm);
+ return GNUNET_DISK_file_open (fn, flags, perm);
#endif
}
@@ -2263,16 +2275,16 @@
GNUNET_DISK_npipe_close (struct GNUNET_DISK_FileHandle *pipe)
{
#ifndef MINGW
- return close(pipe->fd) == 0 ? GNUNET_OK : GNUNET_SYSERR;
+ return close (pipe->fd) == 0 ? GNUNET_OK : GNUNET_SYSERR;
#else
BOOL ret;
- ret = CloseHandle(pipe->h);
+ ret = CloseHandle (pipe->h);
if (!ret)
- {
- SetErrnoFromWinError(GetLastError());
- return GNUNET_SYSERR;
- }
+ {
+ SetErrnoFromWinError (GetLastError ());
+ return GNUNET_SYSERR;
+ }
else
return GNUNET_OK;
#endif
@@ -2291,14 +2303,14 @@
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;
+ }
}
Modified: gnunet/src/util/disk.h
===================================================================
--- gnunet/src/util/disk.h 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/disk.h 2011-08-15 21:46:35 UTC (rev 16581)
@@ -16,8 +16,8 @@
along with GNUnet; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
-*/
-
+*/
+
/**
* @file util/disk.h
* @brief Internal DISK related helper functions
@@ -25,7 +25,7 @@
*/
#ifndef GNUNET_DISK_H_
#define GNUNET_DISK_H_
-
+
#include "gnunet_disk_lib.h"
/**
@@ -36,10 +36,8 @@
* @param dst destination buffer
* @param dst_len length of dst
* @return GNUNET_OK on success, GNUNET_SYSERR otherwise
- */
+ */
int GNUNET_DISK_internal_file_handle_ (const struct GNUNET_DISK_FileHandle
- *fh,
- void *dst,
- size_t dst_len);
+ *fh, void *dst, size_t dst_len);
-#endif /* GNUNET_DISK_H_ */
+#endif /* GNUNET_DISK_H_ */
Modified: gnunet/src/util/getopt.c
===================================================================
--- gnunet/src/util/getopt.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/getopt.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -43,28 +43,28 @@
#include "gnunet_getopt_lib.h"
#ifdef VMS
-# include <unixlib.h>
-# if HAVE_STRING_H - 0
-# include <string.h>
-# endif
+#include <unixlib.h>
+#if HAVE_STRING_H - 0
+#include <string.h>
#endif
+#endif
#if defined (WIN32) && !defined (__CYGWIN32__)
/* It's not Unix, really. See? Capital letters. */
-# include <windows.h>
-# define getpid() GetCurrentProcessId()
+#include <windows.h>
+#define getpid() GetCurrentProcessId()
#endif
#ifndef _
/* This is for other GNU distributions with internationalized messages.
When compiling libc, the _ macro is predefined. */
-# ifdef HAVE_LIBINTL_H
-# include <libintl.h>
-# define _(msgid) gettext (msgid)
-# else
-# define _(msgid) (msgid)
-# endif
+#ifdef HAVE_LIBINTL_H
+#include <libintl.h>
+#define _(msgid) gettext (msgid)
+#else
+#define _(msgid) (msgid)
#endif
+#endif
/* Describe the long-named options requested by the application.
The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
@@ -91,7 +91,7 @@
{
const char *name;
/* has_arg can't be an enum because some compilers complain about
- type mismatches in all the code that assumes it is an int. */
+ * type mismatches in all the code that assumes it is an int. */
int has_arg;
int *flag;
int val;
@@ -198,15 +198,15 @@
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;
}
@@ -252,17 +252,17 @@
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). */
+ * that we can compare them later. But we must not use malloc(3). */
original_argc = argc;
original_argv = argv;
}
text_set_element (__libc_subinit, store_args_and_env);
-# define SWAP_FLAGS(ch1, ch2) \
+#define SWAP_FLAGS(ch1, ch2) \
if (nonoption_flags_len > 0) \
{ \
char __tmp = __getopt_nonoption_flags[ch1]; \
@@ -270,7 +270,7 @@
__getopt_nonoption_flags[ch2] = __tmp; \
}
#else /* !_LIBC */
-# define SWAP_FLAGS(ch1, ch2)
+#define SWAP_FLAGS(ch1, ch2)
#endif /* _LIBC */
/* Exchange two adjacent subsequences of ARGV.
@@ -288,7 +288,7 @@
static void
exchange (argv)
- char **argv;
+ char **argv;
{
int bottom = first_nonopt;
int middle = last_nonopt;
@@ -296,69 +296,70 @@
char *tem;
/* Exchange the shorter segment with the far end of the longer segment.
- That puts the shorter segment into the right place.
- It leaves the longer segment in the right place overall,
- but it consists of two parts that need to be swapped next. */
+ * That puts the shorter segment into the right place.
+ * It leaves the longer segment in the right place overall,
+ * but it consists of two parts that need to be swapped next. */
#ifdef _LIBC
/* First make sure the handling of the `__getopt_nonoption_flags'
- string can work normally. Our top argument must be in the range
- of the string. */
+ * 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);
+
+ if (new_str == NULL)
+ nonoption_flags_len = nonoption_flags_max_len = 0;
+ else
{
- /* 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;
- }
+ 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;
+ /* 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 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;
- }
+ /* 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. */
@@ -373,13 +374,13 @@
#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
- non-option ARGV-elements is empty. */
+ * is the program name); the sequence of previously skipped
+ * non-option ARGV-elements is empty. */
first_nonopt = last_nonopt = GNoptind;
@@ -390,49 +391,48 @@
/* 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
{
- 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);
- }
- }
+ 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;
+ }
}
+ nonoption_flags_len = nonoption_flags_max_len;
+ }
else
nonoption_flags_len = 0;
#endif
@@ -498,11 +498,10 @@
static int
GN_getopt_internal (int argc,
- char *const *argv,
- const char *optstring,
- const struct GNoption *longopts,
- int *longind,
- int long_only)
+ char *const *argv,
+ const char *optstring,
+ const struct GNoption *longopts,
+ int *longind, int long_only)
{
static int __getopt_initialized = 0;
static int GNopterr = 1;
@@ -510,17 +509,17 @@
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
- from the shell indicating it is not an option. The later information
- is only used when the used in the GNU libc. */
+ * Either it does not have option syntax, or there is an environment flag
+ * from the shell indicating it is not an option. The later information
+ * is only used when the used in the GNU libc. */
#ifdef _LIBC
#define NONOPTION_P (argv[GNoptind][0] != '-' || argv[GNoptind][1] == '\0'
\
|| (GNoptind < nonoption_flags_len \
@@ -530,233 +529,232 @@
#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. */
+ /* If we have just processed some options following some non-options,
+ * exchange them so that the options come first. */
- /* 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)
+ if (first_nonopt != last_nonopt && last_nonopt != GNoptind)
+ exchange ((char **) argv);
+ else if (last_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. */
+ /* Skip any additional non-options
+ * and extend the range of non-options previously skipped. */
- if (first_nonopt != last_nonopt && last_nonopt != GNoptind)
- exchange ((char **) argv);
- else if (last_nonopt != GNoptind)
- first_nonopt = GNoptind;
+ while (GNoptind < argc && NONOPTION_P)
+ GNoptind++;
+ last_nonopt = GNoptind;
+ }
- /* Skip any additional non-options
- and extend the range of non-options previously skipped. */
+ /* 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++;
- while (GNoptind < argc && NONOPTION_P)
- GNoptind++;
- last_nonopt = GNoptind;
- }
+ if (first_nonopt != last_nonopt && last_nonopt != GNoptind)
+ exchange ((char **) argv);
+ else if (first_nonopt == last_nonopt)
+ first_nonopt = GNoptind;
+ last_nonopt = argc;
- /* 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++;
+ GNoptind = argc;
+ }
- if (first_nonopt != last_nonopt && last_nonopt != GNoptind)
- exchange ((char **) argv);
- else if (first_nonopt == last_nonopt)
- first_nonopt = GNoptind;
- last_nonopt = argc;
+ /* If we have done all the ARGV-elements, stop the scan
+ * and back over any non-options that we skipped and permuted. */
- GNoptind = argc;
- }
+ 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 done all the ARGV-elements, stop the scan
- and back over any non-options that we skipped and permuted. */
+ /* 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 (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 (NONOPTION_P)
+ {
+ if (ordering == REQUIRE_ORDER)
+ return -1;
+ GNoptarg = argv[GNoptind++];
+ 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. */
+ /* We have found another option-ARGV-element.
+ * Skip the initial punctuation. */
- if (NONOPTION_P)
- {
- if (ordering == REQUIRE_ORDER)
- return -1;
- GNoptarg = argv[GNoptind++];
- return 1;
- }
+ nextchar = (argv[GNoptind] + 1
+ + (longopts != NULL && argv[GNoptind][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.
+ *
+ * If long_only and the ARGV-element has the form "-f", where f is
+ * a valid short option, don't consider it an abbreviated form of
+ * a long option that starts with f. Otherwise there would be no
+ * way to give the -f short option.
+ *
+ * On the other hand, if there's a long option "fubar" and
+ * the ARGV-element is "-fu", do consider that an abbreviation of
+ * the long option, just like "--fu", and not "-f" with arg "u".
+ *
+ * This distinction seems to be the most useful approach. */
- If long_only and the ARGV-element has the form "-f", where f is
- a valid short option, don't consider it an abbreviated form of
- a long option that starts with f. Otherwise there would be no
- way to give the -f short option.
-
- On the other hand, if there's a long option "fubar" and
- the ARGV-element is "-fu", do consider that an abbreviation of
- the long option, just like "--fu", and not "-f" with arg "u".
-
- This distinction seems to be the most useful approach. */
-
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;
+ {
+ 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. */ ;
+ 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 (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)
- fprintf (stderr, _("%s: option `%s' is ambiguous\n"),
- argv[0], argv[GNoptind]);
+ {
+ 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);
- GNoptind++;
return '?';
}
-
- if (pfound != NULL)
+ }
+ else if (pfound->has_arg == 1)
+ {
+ if (GNoptind < argc)
{
- 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;
+ GNoptarg = argv[GNoptind++];
}
-
- /* 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)
+ else
{
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 '?';
+ {
+ 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 '?';
+ }
+ }
+
/* Look at and handle the next short option-character. */
{
@@ -768,186 +766,185 @@
++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;
+ {
+ 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;
- }
+ /* 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
- /* We already incremented `GNoptind' once;
- increment it again when taking next ARGV-elt as argument. */
- GNoptarg = argv[GNoptind++];
+ 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. */
+ /* GNoptarg is now the argument, see if it's in the
+ * table of longopts. */
- for (nextchar = nameend = GNoptarg; *nameend && *nameend != '=';
- nameend++)
- /* Do nothing. */ ;
+ for (nextchar = nameend = GNoptarg; *nameend && *nameend != '=';
+ nameend++)
+ /* Do nothing. */ ;
- /* Test all long options for either exact match
- or abbreviated matches. */
- if (longopts != NULL)
+ /* 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))
{
- 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;
+ /* Exact match found. */
+ pfound = p;
+ indfound = option_index;
+ exact = 1;
+ break;
}
- if (ambig && !exact)
+ 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' is ambiguous\n"),
- argv[0], argv[GNoptind]);
+ fprintf (stderr, _("\
+%s: option `-W %s' does not allow an argument\n"), argv[0], pfound->name);
+
nextchar += strlen (nextchar);
- GNoptind++;
return '?';
}
- if (pfound != NULL)
+ }
+ else if (pfound->has_arg == 1)
+ {
+ if (GNoptind < argc)
+ GNoptarg = argv[GNoptind++];
+ else
{
- 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] == ':' ? ':' : '?';
- }
- }
+ if (GNopterr)
+ fprintf (stderr,
+ _("%s: option `%s' requires an argument\n"),
+ argv[0], argv[GNoptind - 1]);
nextchar += strlen (nextchar);
- if (longind != NULL)
- *longind = option_index;
- if (pfound->flag)
- {
- *(pfound->flag) = pfound->val;
- return 0;
- }
- return pfound->val;
+ return optstring[0] == ':' ? ':' : '?';
}
- nextchar = NULL;
- return 'W'; /* Let the application handle it. */
+ }
+ 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;
- }
+ /* 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)
{
- /* 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;
+ /* 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;
}
}
@@ -1001,15 +998,15 @@
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,30 +1015,31 @@
cont = GNUNET_OK;
/* main getopt loop */
while (cont == GNUNET_OK)
- {
- int option_index = 0;
- c = GNgetopt_long (argc, argv, shorts, long_options, &option_index);
+ {
+ int option_index = 0;
- if (c == GNUNET_SYSERR)
- break; /* No more flags to process */
+ c = GNgetopt_long (argc, argv, shorts, long_options, &option_index);
- 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;
- }
+ 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;
+ }
+ }
GNUNET_free (shorts);
GNUNET_free (long_options);
Modified: gnunet/src/util/getopt_helpers.c
===================================================================
--- gnunet/src/util/getopt_helpers.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/getopt_helpers.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -83,67 +83,67 @@
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]))
{
- 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';
+ 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;
- p = p + 78 - slen;
+ goto OUTER;
}
- /* print rest */
- if (p < ml)
- printf ("%s\n", &trans[p]);
- if (strlen (trans) == 0)
- printf ("\n");
- i++;
+ }
+ /* 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 address@hidden"
"GNUnet home page: http://www.gnu.org/software/gnunet/\n"
"General help using GNU software: http://www.gnu.org/gethelp/\n");
@@ -172,6 +172,7 @@
const char *value)
{
int *val = scls;
+
(*val)++;
return GNUNET_OK;
}
@@ -196,6 +197,7 @@
void *scls, const char *option, const char *value)
{
int *val = scls;
+
*val = 1;
return GNUNET_OK;
}
@@ -249,12 +251,12 @@
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;
}
@@ -279,11 +281,10 @@
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;
}
Modified: gnunet/src/util/gnunet-config-diff.c
===================================================================
--- gnunet/src/util/gnunet-config-diff.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/util/gnunet-config-diff.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -1,28 +1,24 @@
#include "platform.h"
#include <gnunet_util_lib.h>
-int main(int argc,
- char **argv)
+int
+main (int argc, char **argv)
{
struct GNUNET_CONFIGURATION_Handle *i1;
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])) ||
- (GNUNET_OK !=
- GNUNET_CONFIGURATION_load (i2, argv[2])) )
+ if ((GNUNET_OK !=
+ GNUNET_CONFIGURATION_load (i1, argv[1])) ||
+ (GNUNET_OK != GNUNET_CONFIGURATION_load (i2, argv[2])))
return 1;
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_write_diffs (i1, i2, argv[2]))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_write_diffs (i1, i2, argv[2]))
return 2;
return 0;
}
Modified: gnunet/src/util/gnunet-resolver.c
===================================================================
--- gnunet/src/util/gnunet-resolver.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/gnunet-resolver.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -33,15 +33,11 @@
* Callback function to display address.
*/
static void
-printer (void *cls,
- const struct sockaddr * addr,
- socklen_t addrlen)
+printer (void *cls, const struct sockaddr *addr, socklen_t addrlen)
{
if (addr == NULL)
return;
- FPRINTF (stdout,
- "%s\n",
- GNUNET_a2s (addr, addrlen));
+ FPRINTF (stdout, "%s\n", GNUNET_a2s (addr, addrlen));
}
@@ -56,16 +52,11 @@
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
if (args[0] == NULL)
return;
- GNUNET_RESOLVER_ip_get (args[0],
- AF_UNSPEC,
- GET_TIMEOUT,
- &printer,
- NULL);
+ GNUNET_RESOLVER_ip_get (args[0], AF_UNSPEC, GET_TIMEOUT, &printer, NULL);
}
/**
Modified: gnunet/src/util/gnunet-service-resolver.c
===================================================================
--- gnunet/src/util/gnunet-service-resolver.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/util/gnunet-service-resolver.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -88,8 +88,7 @@
char hostname[256];
if (0 == getnameinfo (cache->sa,
- cache->salen,
- hostname, sizeof (hostname), NULL, 0, 0))
+ cache->salen, hostname, sizeof (hostname), NULL, 0, 0))
cache->addr = GNUNET_strdup (hostname);
}
#endif
@@ -107,18 +106,18 @@
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);
}
@@ -164,74 +163,74 @@
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))))
+ {
+ 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);
+ cache->addr,
+ 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);
}
@@ -256,35 +255,35 @@
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;
}
@@ -302,52 +301,52 @@
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
@@ -362,17 +361,17 @@
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;
@@ -381,9 +380,9 @@
#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);
+ &addr,
+ sizeof (addr),
+
GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
return GNUNET_OK;
}
#endif
@@ -418,7 +417,7 @@
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);
}
@@ -445,79 +444,78 @@
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];
+#endif
+ if (size < sizeof (struct sockaddr))
{
-#if DEBUG_RESOLVER
- char buf[INET6_ADDRSTRLEN];
+ 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);
#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 DEBUG_RESOLVER
- inet_ntop (AF_INET, sa, buf, size);
+ 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);
#endif
- 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);
-#endif
- 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);
-#endif
- get_ip_as_string (client, sa, size);
+ 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);
+#endif
+ get_ip_as_string (client, sa, size);
+ }
}
@@ -561,13 +559,13 @@
&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;
}
Modified: gnunet/src/util/load.c
===================================================================
--- gnunet/src/util/load.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/load.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -31,7 +31,7 @@
/**
* Values we track for load calculations.
*/
-struct GNUNET_LOAD_Value
+struct GNUNET_LOAD_Value
{
/**
@@ -41,7 +41,7 @@
/**
* Last time this load value was updated by an event.
- */
+ */
struct GNUNET_TIME_Absolute last_update;
/**
@@ -50,19 +50,19 @@
* first 4 billion requests).
*/
uint64_t cummulative_delay;
-
+
/**
* Sum of squares of all datastore delays ever observed (in ms). Note that
* delays above 64k ms are excluded (to avoid overflow within
* first 4 billion requests).
*/
uint64_t cummulative_squared_delay;
-
+
/**
* Total number of requests included in the cummulative datastore delay
values.
*/
uint64_t cummulative_request_count;
-
+
/**
* Current running average datastore delay. Its relation to the
* average datastore delay and it std. dev. (as calcualted from the
@@ -92,23 +92,23 @@
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;
+ }
}
@@ -140,10 +140,10 @@
*/
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;
+ load->autodecline = autodecline;
}
@@ -164,25 +164,27 @@
if (load->cummulative_request_count <= 1)
return;
/* calcuate std dev of latency; we have for n values of "i" that:
-
- avg = (sum val_i) / n
- stddev = (sum (val_i - avg)^2) / (n-1)
- = (sum (val_i^2 - 2 avg val_i + avg^2) / (n-1)
- = (sum (val_i^2) - 2 avg sum (val_i) + n * avg^2) / (n-1)
- */
+ *
+ * avg = (sum val_i) / n
+ * stddev = (sum (val_i - avg)^2) / (n-1)
+ * = (sum (val_i^2 - 2 avg val_i + avg^2) / (n-1)
+ * = (sum (val_i^2) - 2 avg sum (val_i) + n * avg^2) / (n-1)
+ */
sum_val_i = (double) load->cummulative_delay;
n = ((double) load->cummulative_request_count);
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;
+ stddev =
+ (((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 */
+ * std dev; or if we are below average, simply assume load zero */
if (load->runavg_delay < avgdel)
load->load = 0.0;
else
- load->load = (load->runavg_delay - avgdel) / stddev;
+ load->load = (load->runavg_delay - avgdel) / stddev;
}
@@ -232,22 +234,21 @@
* @param data latest measurement value (for example, delay)
*/
void
-GNUNET_LOAD_update (struct GNUNET_LOAD_Value *load,
- uint64_t data)
+GNUNET_LOAD_update (struct GNUNET_LOAD_Value *load, uint64_t data)
{
uint32_t dv;
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;
+ load->cummulative_squared_delay += dv * dv;
load->cummulative_request_count++;
load->runavg_delay = ((load->runavg_delay * 7.0) + dv) / 8.0;
}
Modified: gnunet/src/util/network.c
===================================================================
--- gnunet/src/util/network.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/network.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -82,25 +82,27 @@
#if MINGW
u_long mode;
+
mode = !doBlock;
if (ioctlsocket (fd->fd, FIONBIO, &mode) == SOCKET_ERROR)
- {
- SetErrnoFromWinsockError (WSAGetLastError ());
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "ioctlsocket");
- return GNUNET_SYSERR;
- }
+ {
+ SetErrnoFromWinsockError (WSAGetLastError ());
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "ioctlsocket");
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
#else
/* not MINGW */
int flags = fcntl (fd->fd, F_GETFL);
+
if (flags == -1)
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "fcntl");
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "fcntl");
+ return GNUNET_SYSERR;
+ }
if (doBlock)
flags &= ~O_NONBLOCK;
@@ -108,10 +110,10 @@
flags |= O_NONBLOCK;
if (0 != fcntl (fd->fd, F_SETFL, flags))
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "fcntl");
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "fcntl");
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
#endif
}
@@ -130,7 +132,7 @@
{
int i;
- i = fcntl (h->fd, F_GETFD);
+ i = fcntl (h->fd, F_GETFD);
if (i < 0)
return GNUNET_SYSERR;
if (i == (i | FD_CLOEXEC))
@@ -153,8 +155,10 @@
socket_set_nosigpipe (const struct GNUNET_NETWORK_Handle *h)
{
int abs_value = 1;
+
if (0 !=
- setsockopt (h->fd, SOL_SOCKET, SO_NOSIGPIPE, &abs_value, sizeof
(abs_value)))
+ setsockopt (h->fd, SOL_SOCKET, SO_NOSIGPIPE, &abs_value,
+ sizeof (abs_value)))
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt");
}
#endif
@@ -170,15 +174,19 @@
static void
socket_set_nodelay (const struct GNUNET_NETWORK_Handle *h)
{
-#ifndef WINDOWS
+#ifndef WINDOWS
int value = 1;
+
if (0 != setsockopt (h->fd, IPPROTO_TCP, TCP_NODELAY, &value, sizeof
(value)))
GNUNET_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)))
+ const char *abs_value = "1";
+
+ if (0 !=
+ setsockopt (h->fd, IPPROTO_TCP, TCP_NODELAY, abs_value,
+ sizeof (abs_value)))
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt");
-#endif
+#endif
}
@@ -192,8 +200,7 @@
*/
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;
@@ -203,10 +210,11 @@
struct sockaddr name;
int namelen = sizeof (name);
int gsn = getsockname (desc->fd, &name, &namelen);
+
if (gsn == 0)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Accepting connection on `%s'\n",
- GNUNET_a2s (&name, namelen));
+ "Accepting connection on `%s'\n",
+ GNUNET_a2s (&name, namelen));
}
#endif
ret->fd = accept (desc->fd, address, address_len);
@@ -215,31 +223,31 @@
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))
@@ -270,10 +278,11 @@
socklen_t address_len)
{
int ret;
-
-#ifdef IPV6_V6ONLY
+
+#ifdef IPV6_V6ONLY
#ifdef IPPROTO_IPV6
const int on = 1;
+
if (desc->af == AF_INET6)
if (0 != setsockopt (desc->fd, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof
(on)))
GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, "setsockopt");
@@ -287,10 +296,11 @@
#ifndef LINUX
#ifndef MINGW
if (address->sa_family == AF_UNIX)
- {
- const struct sockaddr_un *un = (const struct sockaddr_un*) address;
- (void) unlink (un->sun_path);
- }
+ {
+ const struct sockaddr_un *un = (const struct sockaddr_un *) address;
+
+ (void) unlink (un->sun_path);
+ }
#endif
#endif
ret = bind (desc->fd, address, address_len);
@@ -323,29 +333,33 @@
#ifdef MINGW
DWORD error = 0;
+
#if DEBUG_NETWORK
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_NETWORK_socket_close",
"Closing 0x%x\n", desc->fd);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_NETWORK_socket_close",
+ "Closing 0x%x\n", desc->fd);
#endif
SetLastError (0);
ret = closesocket (desc->fd);
error = WSAGetLastError ();
SetErrnoFromWinsockError (error);
#if DEBUG_NETWORK
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_NETWORK_socket_close",
"Closed 0x%x, closesocket() returned %d, GLE is %u\n", desc->fd, ret, error);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_NETWORK_socket_close",
+ "Closed 0x%x, closesocket() returned %d, GLE is %u\n",
+ desc->fd, ret, error);
#endif
#else
ret = close (desc->fd);
#endif
#ifndef LINUX
#ifndef MINGW
- if ( (desc->af == AF_UNIX) && (NULL != desc->addr) )
- {
- const struct sockaddr_un *un = (const struct sockaddr_un*) desc->addr;
- if (0 != unlink (un->sun_path))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
- "unlink",
- un->sun_path);
- }
+ if ((desc->af == AF_UNIX) && (NULL != desc->addr))
+ {
+ const struct sockaddr_un *un = (const struct sockaddr_un *) desc->addr;
+
+ if (0 != unlink (un->sun_path))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
+ "unlink", un->sun_path);
+ }
#endif
#endif
GNUNET_free_non_null (desc->addr);
@@ -369,8 +383,8 @@
struct GNUNET_NETWORK_Handle *ret;
if (fcntl (fd, F_GETFD) < 0)
- return NULL; /* invalid FD */
- ret = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle));
+ return NULL; /* invalid FD */
+ ret = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle));
ret->fd = fd;
ret->af = AF_UNSPEC;
return ret;
@@ -391,15 +405,16 @@
socklen_t address_len)
{
int ret;
+
ret = connect (desc->fd, address, address_len);
#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;
}
@@ -421,6 +436,7 @@
socklen_t * optlen)
{
int ret;
+
ret = getsockopt (desc->fd, level, optname, optval, optlen);
#ifdef MINGW
@@ -445,6 +461,7 @@
int backlog)
{
int ret;
+
ret = listen (desc->fd, backlog);
#ifdef MINGW
@@ -464,17 +481,19 @@
*/
ssize_t
GNUNET_NETWORK_socket_recvfrom_amount (const struct GNUNET_NETWORK_Handle
- *desc)
+ * desc)
{
int error;
/* How much is there to be read? */
#ifndef WINDOWS
int pending;
+
error = ioctl (desc->fd, FIONREAD, &pending);
if (error == 0)
#else
u_long pending;
+
error = ioctlsocket (desc->fd, FIONREAD, &pending);
if (error != SOCKET_ERROR)
#endif
@@ -496,11 +515,11 @@
ssize_t
GNUNET_NETWORK_socket_recvfrom (const struct GNUNET_NETWORK_Handle * desc,
void *buffer, size_t length,
- struct sockaddr * src_addr,
- socklen_t * addrlen)
+ struct sockaddr * src_addr, socklen_t *
addrlen)
{
int ret;
int flags;
+
flags = 0;
#ifdef MSG_DONTWAIT
@@ -511,7 +530,7 @@
#ifdef MINGW
if (SOCKET_ERROR == ret)
SetErrnoFromWinsockError (WSAGetLastError ());
-#endif
+#endif
return ret;
}
@@ -528,6 +547,7 @@
{
int ret;
int flags;
+
flags = 0;
#ifdef MSG_DONTWAIT
@@ -556,6 +576,7 @@
{
int ret;
int flags;
+
flags = 0;
#ifdef MSG_DONTWAIT
@@ -596,6 +617,7 @@
{
int ret;
int flags;
+
flags = 0;
#ifdef MSG_DONTWAIT
@@ -658,31 +680,31 @@
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))
@@ -692,11 +714,11 @@
#ifdef DARWIN
socket_set_nosigpipe (ret);
#endif
- if ( (type == SOCK_STREAM)
+ if ((type == SOCK_STREAM)
#ifdef AF_UNIX
- && (domain != AF_UNIX)
+ && (domain != AF_UNIX)
#endif
- )
+ )
socket_set_nodelay (ret);
return ret;
}
@@ -736,15 +758,26 @@
{
int value = 0;
int ret = 0;
+
#if WINDOWS
- if (0 != (ret = setsockopt (desc->fd, SOL_SOCKET, SO_SNDBUF, (char *)
&value, sizeof (value))))
+ if (0 !=
+ (ret =
+ setsockopt (desc->fd, SOL_SOCKET, SO_SNDBUF, (char *) &value,
+ sizeof (value))))
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt");
- if (0 != (ret = setsockopt (desc->fd, SOL_SOCKET, SO_RCVBUF, (char *)
&value, sizeof (value))))
+ if (0 !=
+ (ret =
+ setsockopt (desc->fd, SOL_SOCKET, SO_RCVBUF, (char *) &value,
+ sizeof (value))))
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt");
#else
- if (0 != (ret = setsockopt (desc->fd, SOL_SOCKET, SO_SNDBUF, &value, sizeof
(value))))
+ if (0 !=
+ (ret =
+ setsockopt (desc->fd, SOL_SOCKET, SO_SNDBUF, &value, sizeof (value))))
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt");
- if (0 != (ret = setsockopt (desc->fd, SOL_SOCKET, SO_RCVBUF, &value, sizeof
(value))))
+ if (0 !=
+ (ret =
+ setsockopt (desc->fd, SOL_SOCKET, SO_RCVBUF, &value, sizeof (value))))
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt");
#endif
@@ -805,14 +838,15 @@
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
@@ -874,10 +908,10 @@
* @param to destination
* @param nfd native FD to set
*/
-void GNUNET_NETWORK_fdset_set_native (struct GNUNET_NETWORK_FDSet *to,
- int nfd)
+void
+GNUNET_NETWORK_fdset_set_native (struct GNUNET_NETWORK_FDSet *to, int nfd)
{
- GNUNET_assert((nfd >= 0) && (nfd < FD_SETSIZE));
+ GNUNET_assert ((nfd >= 0) && (nfd < FD_SETSIZE));
FD_SET (nfd, &to->sds);
to->nsds = GNUNET_MAX (nfd + 1, to->nsds);
}
@@ -890,11 +924,11 @@
* @param nfd native FD to test, or -1 for none
* @return GNUNET_YES if FD is set in the set
*/
-int
+int
GNUNET_NETWORK_fdset_test_native (const struct GNUNET_NETWORK_FDSet *to,
- int nfd)
+ int nfd)
{
- if ( (nfd == -1) || (to == NULL) )
+ if ((nfd == -1) || (to == NULL))
return GNUNET_NO;
return FD_ISSET (nfd, &to->sds) ? GNUNET_YES : GNUNET_NO;
}
@@ -916,6 +950,7 @@
#else
int fd;
+
GNUNET_DISK_internal_file_handle_ (h, &fd, sizeof (int));
FD_SET (fd, &fds->sds);
if (fd + 1 > fds->nsds)
@@ -938,7 +973,8 @@
#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
@@ -962,11 +998,11 @@
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;
@@ -974,7 +1010,7 @@
int j;
/*This code is somewhat hacky, we are not supposed to know what's
- inside of fd_set; also the O(n^2) is really bad... */
+ * inside of fd_set; also the O(n^2) is really bad... */
for (i = 0; i < fds1->sds.fd_count; i++)
{
@@ -986,33 +1022,36 @@
}
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
- GNUNET_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);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "0x%x\n", fh->h);
- }
+ GNUNET_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);
+ GNUNET_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 (GNUNET_CONTAINER_slist_contains
+ (fds2->handles, h, sizeof (struct GNUNET_DISK_FileHandle)))
+ {
#if DEBUG_NETWORK
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Match!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Match!\n");
#endif
- GNUNET_CONTAINER_slist_iter_destroy (it);
- return GNUNET_YES;
- }
- GNUNET_CONTAINER_slist_next (it);
+ GNUNET_CONTAINER_slist_iter_destroy (it);
+ return GNUNET_YES;
}
+ GNUNET_CONTAINER_slist_next (it);
+ }
GNUNET_CONTAINER_slist_iter_destroy (it);
#endif
return GNUNET_NO;
@@ -1027,6 +1066,7 @@
GNUNET_NETWORK_fdset_create ()
{
struct GNUNET_NETWORK_FDSet *fds;
+
fds = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_FDSet));
#ifdef MINGW
fds->handles = GNUNET_CONTAINER_slist_create ();
@@ -1064,6 +1104,7 @@
const struct GNUNET_TIME_Relative timeout)
{
int nfds = 0;
+
#ifdef MINGW
int handles = 0;
int ex_handles = 0;
@@ -1093,6 +1134,7 @@
struct GNUNET_CONTAINER_SList *handles_read, *handles_write, *handles_except;
fd_set aread, awrite, aexcept;
+
#if DEBUG_NETWORK
fd_set bread, bwrite, bexcept;
#endif
@@ -1103,62 +1145,67 @@
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);
- GNUNET_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);
+ GNUNET_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)
+ if ((nfds == 0) &&
+ (timeout.rel_value == GNUNET_TIME_UNIT_FOREVER_REL.rel_value)
#ifdef MINGW
&& handles == 0
#endif
- )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _
- ("Fatal internal logic error, process hangs in `%s' (abort
with CTRL-C)!\n"),
- "select");
- GNUNET_break (0);
- }
+ )
+ {
+ GNUNET_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));
- return select (nfds,
- (rfds != NULL) ? &rfds->sds : NULL,
+ 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);
+ (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))
@@ -1169,10 +1216,10 @@
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)
@@ -1195,7 +1242,7 @@
hEventPipeWrite = CreateEvent (NULL, TRUE, TRUE, NULL);
readPipes = 0;
writePipePos = -1;
-
+
handles_read = GNUNET_CONTAINER_slist_create ();
handles_write = GNUNET_CONTAINER_slist_create ();
handles_except = GNUNET_CONTAINER_slist_create ();
@@ -1233,40 +1280,49 @@
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))
+ 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);
+
+ 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
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Reading 0 bytes from the pipe
0x%x\n", fh->h);
+ GNUNET_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();
+ DWORD error_code = GetLastError ();
+
if (error_code == ERROR_IO_PENDING)
{
#if DEBUG_NETWORK
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding the pipe's 0x%x
overlapped event to the array as %d\n", fh->h, nhandles);
+ GNUNET_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
+ * {
+ * SetErrnoFromWinError (error_code);
+ * }
+ */
}
else
{
#if DEBUG_NETWORK
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding the read ready event to
the array as %d\n", nhandles);
+ GNUNET_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;
@@ -1275,8 +1331,8 @@
else
{
GNUNET_CONTAINER_slist_add (handles_read,
- GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
- fh, sizeof (struct GNUNET_DISK_FileHandle));
+
GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
+ fh, sizeof (struct
GNUNET_DISK_FileHandle));
}
}
GNUNET_CONTAINER_slist_iter_destroy (i);
@@ -1284,7 +1340,8 @@
if (wfds && write_handles)
{
#if DEBUG_NETWORK
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding the write ready event to the
array as %d\n", nhandles);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Adding the write ready event to the array as %d\n", nhandles);
#endif
handle_array[nhandles++] = hEventPipeWrite;
writePipePos = nhandles;
@@ -1292,21 +1349,24 @@
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))
+ 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);
+ 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));
+
GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
+ fh,
+ sizeof (struct GNUNET_DISK_FileHandle));
newretcode++;
}
}
@@ -1318,21 +1378,27 @@
if (rfds)
{
#if DEBUG_NETWORK
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding the socket read event to
the array as %d\n", nhandles);
+ GNUNET_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);
+ WSAEventSelect (rfds->sds.fd_array[i], hEventRead,
+ FD_ACCEPT | FD_READ | FD_CLOSE);
nsock++;
}
}
if (wfds)
{
int wakeup = 0;
+
#if DEBUG_NETWORK
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding the socket write event to
the array as %d\n", nhandles);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Adding the socket write event to the array as %d\n",
+ nhandles);
#endif
handle_array[nhandles++] = hEventWrite;
nSockEvents++;
@@ -1340,14 +1406,18 @@
{
DWORD error;
int status;
+
status = send (wfds->sds.fd_array[i], NULL, 0, 0);
error = GetLastError ();
#if DEBUG_NETWORK
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pre-send to the socket %d
returned %d (%u)\n", i, status, error);
+ GNUNET_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);
+ WSAEventSelect (wfds->sds.fd_array[i], hEventWrite,
+ FD_WRITE | FD_CONNECT | FD_CLOSE);
nsock++;
}
if (wakeup)
@@ -1356,13 +1426,16 @@
if (efds)
{
#if DEBUG_NETWORK
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding the socket error event to
the array as %d\n", nhandles);
+ GNUNET_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);
+ WSAEventSelect (efds->sds.fd_array[i], hEventException,
+ FD_OOB | FD_CLOSE);
nsock++;
}
}
@@ -1378,11 +1451,13 @@
#endif
if (nhandles)
- returncode = WaitForMultipleObjects (nhandles, handle_array, FALSE,
ms_total);
+ returncode =
+ WaitForMultipleObjects (nhandles, handle_array, FALSE, ms_total);
#if DEBUG_NETWORK
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "WaitForMultipleObjects Returned :
%d\n", returncode);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "WaitForMultipleObjects Returned :
%d\n",
+ returncode);
#endif
-
+
returnedpos = returncode - WAIT_OBJECT_0;
#if DEBUG_NETWORK
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "return pos is : %d\n", returnedpos);
@@ -1390,16 +1465,18 @@
/* FIXME: THIS LINE IS WRONG !! We should add to handles only handles that
fired the events, not all ! */
/*
- if(rfds)
- GNUNET_CONTAINER_slist_append (handles_read, rfds->handles);
- */
+ * if(rfds)
+ * GNUNET_CONTAINER_slist_append (handles_read, rfds->handles);
+ */
if (nhandles && (returnedpos < nhandles))
{
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);
@@ -1423,48 +1500,55 @@
#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);
+ * GNUNET_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++;
+ * GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Added read Pipe\n");
+ * }
+ */
for (i = 0; i < readPipes; i++)
{
- waitstatus = WaitForSingleObject (handle_array[i], 0);
- GNUNET_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++;
- GNUNET_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);
+ bret =
+ PeekNamedPipe (readArray[i]->h, NULL, 0, NULL, &waitstatus, NULL);
error = GetLastError ();
#if DEBUG_NETWORK
- GNUNET_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);
+ GNUNET_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 || waitstatus <= 0)
continue;
GNUNET_CONTAINER_slist_add (handles_read,
- GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
- readArray[i], sizeof (struct GNUNET_DISK_FileHandle));
+
GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
+ readArray[i],
+ sizeof (struct GNUNET_DISK_FileHandle));
retcode++;
#if DEBUG_NETWORK
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Added read Pipe 0x%x (0x%x)\n",
readArray[i], readArray[i]->h);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Added read Pipe 0x%x (0x%x)\n",
+ readArray[i], readArray[i]->h);
#endif
}
}
waitstatus = WaitForSingleObject (hEventWrite, 0);
#if DEBUG_NETWORK
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Wait for the write event returned
%d\n", waitstatus);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Wait for the write event returned %d\n", waitstatus);
#endif
if (waitstatus == WAIT_OBJECT_0)
{
@@ -1474,15 +1558,21 @@
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);
+ 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
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "send to the socket %d returned
%d (%u)\n", i, status, error);
+ GNUNET_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))
+ || (status == -1 && gso_result == 0 && error == WSAENOTCONN &&
+ so_error == WSAECONNREFUSED))
{
FD_SET (wfds->sds.fd_array[i], &awrite);
retcode += 1;
@@ -1492,22 +1582,26 @@
}
#if DEBUG_NETWORK
if (!nhandles || (returnedpos >= nhandles))
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Returning from _select() with
nothing!\n");
+ GNUNET_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++)
{
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))
+ 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);
+
+ fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (t,
+ NULL);
if (fh->type == GNUNET_PIPE)
{
CancelIo (fh->h);
@@ -1559,17 +1653,23 @@
if (rfds)
{
struct GNUNET_CONTAINER_SList_Iterator *t;
+
for (i = 0; i < bread.fd_count; i++)
{
if (bread.fd_array[i] != 0)
- GNUNET_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");
+ GNUNET_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))
+ 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);
+
+ fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (t,
+ NULL);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is SET in rfds\n", fh->h);
}
}
@@ -1578,7 +1678,10 @@
for (i = 0; i < bwrite.fd_count; i++)
{
if (bwrite.fd_array[i] != 0)
- GNUNET_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");
+ GNUNET_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)
@@ -1586,7 +1689,10 @@
for (i = 0; i < bexcept.fd_count; i++)
{
if (bexcept.fd_array[i] != 0)
- GNUNET_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");
+ GNUNET_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");
}
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Returning %d or 0\n", retcode);
Modified: gnunet/src/util/os_installation.c
===================================================================
--- gnunet/src/util/os_installation.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/os_installation.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -51,25 +51,21 @@
FILE *f;
char *lgu;
- GNUNET_snprintf (fn,
- sizeof(fn),
- "/proc/%u/maps",
- getpid ());
+ GNUNET_snprintf (fn, sizeof (fn), "/proc/%u/maps", getpid ());
f = fopen (fn, "r");
if (f == NULL)
return NULL;
- while (NULL != fgets (line, sizeof(line), f))
+ 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;
}
@@ -84,23 +80,22 @@
char lnk[1024];
ssize_t size;
- GNUNET_snprintf (fn,
- sizeof(fn), "/proc/%u/exe", getpid ());
- size = readlink (fn, lnk, sizeof (lnk)-1);
+ GNUNET_snprintf (fn, sizeof (fn), "/proc/%u/exe", getpid ());
+ size = readlink (fn, lnk, sizeof (lnk) - 1);
if (size <= 0)
- {
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "readlink", fn);
- return NULL;
- }
+ {
+ GNUNET_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);
}
@@ -116,7 +111,7 @@
char path[4097];
char *idx;
- GetModuleFileName (NULL, path, sizeof(path)-1);
+ GetModuleFileName (NULL, path, sizeof (path) - 1);
idx = path + strlen (path);
while ((idx > path) && (*idx != '\\') && (*idx != '/'))
idx--;
@@ -139,7 +134,7 @@
path = NULL;
func =
- (MyNSGetExecutablePathProto) dlsym (RTLD_DEFAULT, "_NSGetExecutablePath");
+ (MyNSGetExecutablePathProto) dlsym (RTLD_DEFAULT,
"_NSGetExecutablePath");
if (!func)
return NULL;
path = &zero;
@@ -151,10 +146,10 @@
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--;
@@ -173,22 +168,22 @@
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 = 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 = strdup (path);
+ s = p + strlen (p);
+ while ((s > p) && (*s != '/'))
+ s--;
+ s++;
+ *s = '\0';
+ }
+ break;
}
+ }
return p;
}
#endif
@@ -214,28 +209,28 @@
return NULL;
path = GNUNET_strdup (p); /* because we write on it */
buf = GNUNET_malloc (strlen (path) + 20);
- pos = path;
+ 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)
{
- *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;
}
+ 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;
@@ -294,8 +289,7 @@
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_
("Could not determine installation path for %s. Set `%s'
environment variable.\n"),
- "GNUnet",
- "GNUNET_PREFIX");
+ "GNUnet", "GNUNET_PREFIX");
return NULL;
}
@@ -361,11 +355,11 @@
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';
@@ -374,62 +368,59 @@
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;
- }
+ {
+ /* 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:
+ {
+ 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 "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 "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;
- }
+ break;
+ default:
+ GNUNET_free (execpath);
+ return NULL;
+ }
tmp = GNUNET_malloc (strlen (execpath) + strlen (dirname) + 1);
sprintf (tmp, "%s%s", execpath, dirname);
GNUNET_free (execpath);
@@ -454,6 +445,7 @@
struct stat statbuf;
char *p;
char *pf;
+
#ifdef MINGW
SOCKET rawsock;
char *binaryexe;
@@ -461,61 +453,59 @@
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)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Could not find binary `%s' in PATH!\n"),
- binary);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Could not find binary `%s' in PATH!\n"), binary);
+ return GNUNET_SYSERR;
+ }
if (0 != STAT (p, &statbuf))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("stat (%s) failed: %s\n"),
- p,
- STRERROR (errno));
- GNUNET_free (p);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_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;
- }
+ if ((0 != (statbuf.st_mode & S_ISUID)) && (statbuf.st_uid == 0))
+ {
+ 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 ();
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "socket (AF_INET, SOCK_RAW, IPPROTO_ICMP) failed! GLE =
%d\n", err);
- return GNUNET_NO; /* not running as administrator */
- }
+ {
+ DWORD err = GetLastError ();
+
+ GNUNET_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
Modified: gnunet/src/util/os_network.c
===================================================================
--- gnunet/src/util/os_network.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/os_network.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -51,120 +51,118 @@
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;
+ 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;
- }
- }
+ /* Get IP-Address */
+ int i;
- if (dwIP)
- {
- BYTE bPhysAddr[MAXLEN_PHYSADDR];
- char *pszIfName = NULL;
- char dst[INET_ADDRSTRLEN];
- struct sockaddr_in sa;
+ for (i = 0; i < pAddrTable->dwNumEntries; i++)
+ {
+ if (pAddrTable->table[i].dwIndex == pTable->table[dwIfIdx].dwIndex)
+ {
+ dwIP = pAddrTable->table[i].dwAddr;
+ break;
+ }
+ }
- /* Get friendly interface name */
- pAdapterInfo =
- (IP_ADAPTER_INFO *) malloc (sizeof (IP_ADAPTER_INFO));
- ULONG ulOutBufLen = sizeof (IP_ADAPTER_INFO);
+ if (dwIP)
+ {
+ BYTE bPhysAddr[MAXLEN_PHYSADDR];
+ char *pszIfName = NULL;
+ char dst[INET_ADDRSTRLEN];
+ struct sockaddr_in sa;
- /* 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);
- }
+ /* Get friendly interface name */
+ pAdapterInfo = (IP_ADAPTER_INFO *) malloc (sizeof (IP_ADAPTER_INFO));
+ ULONG ulOutBufLen = sizeof (IP_ADAPTER_INFO);
- if ((dwRetVal =
- GGetAdaptersInfo (pAdapterInfo, &ulOutBufLen)) == NO_ERROR)
- {
- pAdapter = pAdapterInfo;
- while (pAdapter)
- {
- if (pTable->table[dwIfIdx].dwIndex == pAdapter->Index)
- {
- char szKey[251];
- long lLen = 250;
+ /* 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);
+ }
- 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);
+ if ((dwRetVal =
+ GGetAdaptersInfo (pAdapterInfo, &ulOutBufLen)) == NO_ERROR)
+ {
+ pAdapter = pAdapterInfo;
+ while (pAdapter)
+ {
+ if (pTable->table[dwIfIdx].dwIndex == pAdapter->Index)
+ {
+ char szKey[251];
+ long lLen = 250;
- /* Set entry */
- memset (bPhysAddr, 0, MAXLEN_PHYSADDR);
- memcpy (bPhysAddr,
- pTable->table[dwIfIdx].bPhysAddr,
- pTable->table[dwIfIdx].dwPhysAddrLen);
+ 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);
- 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;
+ /* Set entry */
+ memset (bPhysAddr, 0, MAXLEN_PHYSADDR);
+ memcpy (bPhysAddr,
+ pTable->table[dwIfIdx].bPhysAddr,
+ pTable->table[dwIfIdx].dwPhysAddrLen);
- if (pszIfName)
- free (pszIfName);
+ 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;
- sa.sin_family = AF_INET;
+ 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;
+ 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);
+ if (GNUNET_OK !=
+ proc (proc_cls,
+ szEntry,
+ pTable->table[dwIfIdx].dwIndex == dwExternalNIC,
+ (const struct sockaddr *) &sa, sizeof (sa)))
+ break;
+ }
}
+ GlobalFree (pAddrTable);
+ GlobalFree (pTable);
+ }
return;
@@ -175,29 +173,29 @@
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;
@@ -218,78 +216,77 @@
else
f = popen ("ifconfig -a 2> /dev/null", "r");
if (!f)
- {
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING |
- GNUNET_ERROR_TYPE_BULK, "popen", "ifconfig");
- return;
- }
+ {
+ GNUNET_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)
{
- 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;
+ 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;
#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
}
Modified: gnunet/src/util/os_priority.c
===================================================================
--- gnunet/src/util/os_priority.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/os_priority.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -53,44 +53,42 @@
*/
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 *control_pipe =
+ (struct GNUNET_DISK_FileHandle *) cls;
int sig;
#if DEBUG_OS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "`%s' invoked because of %d\n",
- __FUNCTION__,
- tc->reason);
+ GNUNET_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))
+ 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))
{
+ GNUNET_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))
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
- "GNUNET_DISK_file_read");
- GNUNET_DISK_npipe_close (control_pipe);
- }
- else
- {
#if DEBUG_OS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Got control code %d from parent\n", sig);
+ GNUNET_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);
}
+ }
}
@@ -100,39 +98,36 @@
void
GNUNET_OS_install_parent_control_handler (void *cls,
const struct
- GNUNET_SCHEDULER_TaskContext * tc)
+ 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) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Not installing a handler because $%s=%s\n"),
- GNUNET_OS_CONTROL_PIPE,
- env_buf);
- return;
- }
+ if ((env_buf == NULL) || (strlen (env_buf) <= 0))
+ {
+ GNUNET_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_OPEN_READ,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE);
if (control_pipe == NULL)
- {
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
- "open",
- env_buf);
- return;
- }
+ {
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "open", env_buf);
+ return;
+ }
#if DEBUG_OS
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Adding parent control handler pipe `%s' to the scheduler\n",
- env_buf);
+ "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);
+ GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ control_pipe,
+ &parent_control_handler, control_pipe);
}
@@ -164,27 +159,27 @@
int res = 0;
int ret = 0;
- ret = GNUNET_DISK_file_write (proc->control_pipe, &sig, sizeof(sig));
- if (ret != sizeof(sig))
+ ret = GNUNET_DISK_file_write (proc->control_pipe, &sig, sizeof (sig));
+ if (ret != sizeof (sig))
{
if (errno == ECOMM)
{
/* Child process is not controllable via pipe */
#if DEBUG_OS
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Child process is not controllable, will kill it directly\n");
+ "Child process is not controllable, will kill it
directly\n");
#endif
}
else if (errno == EPIPE)
{
#if DEBUG_OS
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Failed to write into control pipe, because pipe is invalid (the
child is most likely dead)\n");
+ "Failed to write into control pipe, because pipe is invalid
(the child is most likely dead)\n");
#endif
}
else
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Failed to write into control pipe , errno is %d\n", errno);
+ "Failed to write into control pipe , errno is %d\n", errno);
#if WINDOWS && !defined(__CYGWIN__)
TerminateProcess (proc->handle, 0);
#else
@@ -195,7 +190,7 @@
{
#if DEBUG_OS
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Wrote control code into control pipe, now waiting\n");
+ "Wrote control code into control pipe, now waiting\n");
#endif
#if WINDOWS
@@ -225,27 +220,28 @@
while (1)
{
ret = GNUNET_NETWORK_socket_select (rfds, NULL, efds,
- GNUNET_TIME_relative_multiply (GNUNET_TIME_relative_get_unit (),
- 5000));
+ 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;
- }
+ 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);
+ {
+ 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;
- }
- }
+ /* Child signaled shutdown is in progress */
+ continue;
+ }
+ }
#endif
}
@@ -263,7 +259,7 @@
* @return the current process id
*/
pid_t
-GNUNET_OS_process_get_pid (struct GNUNET_OS_Process *proc)
+GNUNET_OS_process_get_pid (struct GNUNET_OS_Process * proc)
{
return proc->pid;
}
@@ -303,6 +299,7 @@
ChildWaitThread (void *arg)
{
struct GNUNET_OS_Process *proc = (struct GNUNET_OS_Process *) arg;
+
WaitForSingleObject (proc->handle, INFINITE);
if (w32_sigchld_handler)
@@ -331,91 +328,90 @@
/* 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
{
HANDLE h = proc->handle;
+
GNUNET_assert (h != NULL);
SetPriorityClass (h, rprio);
}
-#elif LINUX
+#elif LINUX
pid_t pid;
pid = proc->pid;
- if ( (0 == pid) ||
- (pid == getpid () ) )
+ 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) )
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING |
- GNUNET_ERROR_TYPE_BULK, "nice");
- return GNUNET_SYSERR;
- }
+ GNUNET_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))
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING |
- GNUNET_ERROR_TYPE_BULK, "setpriority");
- return GNUNET_SYSERR;
- }
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING |
+ GNUNET_ERROR_TYPE_BULK, "setpriority");
+ return GNUNET_SYSERR;
}
+ }
#else
#if DEBUG_OS
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
- "Priority management not availabe for this platform\n");
+ "Priority management not availabe for this platform\n");
#endif
#endif
return GNUNET_OK;
@@ -434,10 +430,11 @@
size_t var_len;
char *var;
char *val;
+
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++)
@@ -446,6 +443,7 @@
{
size_t len = strlen (ptr);
int found = 0;
+
for (var_ptr = vars; *var_ptr; var_ptr++)
{
var = *var_ptr++;
@@ -461,7 +459,7 @@
}
if (!found)
tablesize += len + 1;
- ptr += len + 1;
+ ptr += len + 1;
}
for (n_found = 0, c = 0, var_ptr = vars; *var_ptr; var_ptr++, c++)
{
@@ -475,6 +473,7 @@
{
size_t len = strlen (ptr);
int found = 0;
+
for (c = 0, var_ptr = vars; *var_ptr; var_ptr++, c++)
{
var = *var_ptr++;
@@ -531,12 +530,12 @@
* @return pointer to process structure of the new process, NULL on error
*/
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)
+GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin,
+ struct GNUNET_DISK_PipeHandle *pipe_stdout,
+ const char *filename, va_list va)
{
va_list ap;
+
#if ENABLE_WINDOWS_WORKAROUNDS
char *childpipename = NULL;
struct GNUNET_DISK_FileHandle *control_pipe = NULL;
@@ -554,8 +553,9 @@
#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_OPEN_WRITE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE);
if (control_pipe == NULL)
return NULL;
#endif
@@ -563,24 +563,35 @@
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 ();
@@ -588,44 +599,44 @@
ret = fork ();
#endif
if (ret != 0)
+ {
+ if (ret == -1)
{
- if (ret == -1)
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "fork");
+ GNUNET_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);
@@ -633,21 +644,21 @@
#endif
if (pipe_stdout != NULL)
- {
- GNUNET_break (0 == close (fd_stdout_read));
- if (-1 == dup2(fd_stdout_write, 1))
- GNUNET_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))
+ GNUNET_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))
- GNUNET_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))
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "dup2");
+ GNUNET_break (0 == close (fd_stdin_read));
+ }
execvp (filename, argv);
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "execvp", filename);
_exit (1);
@@ -682,7 +693,9 @@
pathbuf_len = GetEnvironmentVariableA ("PATH", (char *) &pathbuf, 0);
- alloc_len = pathbuf_len + 1 + strlen (self_prefix) + 1 + strlen (bindir) + 1
+ strlen (libdir);
+ alloc_len =
+ pathbuf_len + 1 + strlen (self_prefix) + 1 + strlen (bindir) + 1 +
+ strlen (libdir);
pathbuf = GNUNET_malloc (alloc_len * sizeof (char));
@@ -704,36 +717,39 @@
/* Check that this is the full path. If it isn't, search. */
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 ());
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "SearchPath",
non_const_filename);
- GNUNET_free (non_const_filename);
- GNUNET_free (pathbuf);
- return NULL;
- }
+ else if (!SearchPathA
+ (pathbuf, non_const_filename, NULL, sizeof (path) / sizeof (char),
+ path, NULL))
+ {
+ SetErrnoFromWinError (GetLastError ());
+ GNUNET_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);
@@ -744,20 +760,26 @@
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_OPEN_WRITE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE);
if (control_pipe == NULL)
{
GNUNET_free (cmd);
@@ -766,9 +788,8 @@
}
#if DEBUG_OS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Opened the parent end of the pipe `%s'\n",
- childpipename);
+ GNUNET_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);
@@ -781,13 +802,13 @@
if (!CreateProcessA
(path, cmd, NULL, NULL, TRUE, DETACHED_PROCESS | CREATE_SUSPENDED,
env_block, NULL, &start, &proc))
- {
- SetErrnoFromWinError (GetLastError ());
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "CreateProcess",
path);
- GNUNET_free (env_block);
- GNUNET_free (cmd);
- return NULL;
- }
+ {
+ SetErrnoFromWinError (GetLastError ());
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "CreateProcess", path);
+ GNUNET_free (env_block);
+ GNUNET_free (cmd);
+ return NULL;
+ }
GNUNET_free (env_block);
@@ -820,18 +841,15 @@
*
*/
struct GNUNET_OS_Process *
-GNUNET_OS_start_process (struct GNUNET_DISK_PipeHandle *pipe_stdin,
- struct GNUNET_DISK_PipeHandle *pipe_stdout,
- const char *filename, ...)
+GNUNET_OS_start_process (struct GNUNET_DISK_PipeHandle *pipe_stdin,
+ struct GNUNET_DISK_PipeHandle *pipe_stdout,
+ const char *filename, ...)
{
struct GNUNET_OS_Process *ret;
va_list ap;
va_start (ap, filename);
- ret = GNUNET_OS_start_process_va (pipe_stdin,
- pipe_stdout,
- filename,
- ap);
+ ret = GNUNET_OS_start_process_va (pipe_stdin, pipe_stdout, filename, ap);
va_end (ap);
return ret;
}
@@ -848,7 +866,7 @@
*/
struct GNUNET_OS_Process *
GNUNET_OS_start_process_v (const int *lsocks,
- const char *filename, char *const argv[])
+ const char *filename, char *const argv[])
{
#if ENABLE_WINDOWS_WORKAROUNDS
struct GNUNET_DISK_FileHandle *control_pipe = NULL;
@@ -866,12 +884,13 @@
int tgt;
int flags;
int *lscp;
- unsigned int ls;
+ unsigned int ls;
#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_OPEN_WRITE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE);
if (control_pipe == NULL)
return NULL;
#endif
@@ -879,100 +898,100 @@
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)
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "fork");
+ GNUNET_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);
- GNUNET_free (childpipename);
+ setenv (GNUNET_OS_CONTROL_PIPE, childpipename, 1);
+ GNUNET_free (childpipename);
#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);
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "execvp", filename);
@@ -1009,7 +1028,9 @@
pathbuf_len = GetEnvironmentVariableA ("PATH", (char *) &pathbuf, 0);
- alloc_len = pathbuf_len + 1 + strlen (self_prefix) + 1 + strlen (bindir) + 1
+ strlen (libdir);
+ alloc_len =
+ pathbuf_len + 1 + strlen (self_prefix) + 1 + strlen (bindir) + 1 +
+ strlen (libdir);
pathbuf = GNUNET_malloc (alloc_len * sizeof (char));
@@ -1023,7 +1044,7 @@
if (alloc_len != pathbuf_len - 1)
{
GNUNET_free (pathbuf);
- errno = ENOSYS; /* PATH changed on the fly. What kind of error is that? */
+ errno = ENOSYS; /* PATH changed on the fly. What kind of error
is that? */
return NULL;
}
@@ -1036,24 +1057,27 @@
/* Check that this is the full path. If it isn't, search. */
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 ());
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "SearchPath",
non_const_filename);
- GNUNET_free (non_const_filename);
- GNUNET_free (pathbuf);
- return NULL;
- }
+ else if (!SearchPathA
+ (pathbuf, non_const_filename, NULL, sizeof (path) / sizeof (char),
+ path, NULL))
+ {
+ SetErrnoFromWinError (GetLastError ());
+ GNUNET_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));
@@ -1062,33 +1086,33 @@
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]);
@@ -1098,8 +1122,9 @@
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_OPEN_WRITE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE);
if (control_pipe == NULL)
{
GNUNET_free (cmd);
@@ -1108,7 +1133,8 @@
}
#if DEBUG_OS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Opened the parent end of the pipe
`%s'\n", childpipename);
+ GNUNET_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);
@@ -1121,13 +1147,13 @@
if (!CreateProcess
(path, cmd, NULL, NULL, FALSE, DETACHED_PROCESS | CREATE_SUSPENDED,
env_block, NULL, &start, &proc))
- {
- SetErrnoFromWinError (GetLastError ());
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "CreateProcess");
- GNUNET_free (env_block);
- GNUNET_free (cmd);
- return NULL;
- }
+ {
+ SetErrnoFromWinError (GetLastError ());
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "CreateProcess");
+ GNUNET_free (env_block);
+ GNUNET_free (cmd);
+ return NULL;
+ }
GNUNET_free (env_block);
@@ -1155,8 +1181,8 @@
* @return GNUNET_OK on success, GNUNET_NO if the process is still running,
GNUNET_SYSERR otherwise
*/
int
-GNUNET_OS_process_status (struct GNUNET_OS_Process *proc,
- enum GNUNET_OS_ProcessStatusType *type,
+GNUNET_OS_process_status (struct GNUNET_OS_Process *proc,
+ enum GNUNET_OS_ProcessStatusType *type,
unsigned long *code)
{
#ifndef MINGW
@@ -1166,48 +1192,48 @@
GNUNET_assert (0 != proc);
ret = waitpid (proc->pid, &status, WNOHANG);
if (ret < 0)
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_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)
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_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;
@@ -1215,10 +1241,11 @@
h = proc->handle;
ret = proc->pid;
if (h == NULL || ret == 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Invalid process information {%d,
%08X}\n", ret, h);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Invalid process information {%d, %08X}\n", ret, h);
+ return GNUNET_SYSERR;
+ }
if (h == NULL)
h = GetCurrentProcess ();
@@ -1227,16 +1254,16 @@
error_code = GetLastError ();
if (ret == 0 || error_code != NO_ERROR)
{
- SetErrnoFromWinError (error_code);
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "GetExitCodeProcess");
- return GNUNET_SYSERR;
+ SetErrnoFromWinError (error_code);
+ GNUNET_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
@@ -1256,6 +1283,7 @@
#ifndef MINGW
pid_t pid = proc->pid;
+
if (pid != waitpid (pid, NULL, 0))
return GNUNET_SYSERR;
return GNUNET_OK;
@@ -1265,21 +1293,19 @@
h = proc->handle;
if (NULL == h)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Invalid process information {%d, %08X}\n",
- proc->pid,
- h);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_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;
@@ -1303,7 +1329,7 @@
* Handle to the output pipe.
*/
struct GNUNET_DISK_PipeHandle *opipe;
-
+
/**
* Read-end of output pipe.
*/
@@ -1318,12 +1344,12 @@
* Closure for 'proc'.
*/
void *proc_cls;
-
+
/**
* Buffer for the output.
*/
char buf[1024];
-
+
/**
* Task reading from pipe.
*/
@@ -1353,13 +1379,12 @@
{
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_break (GNUNET_OK == GNUNET_OS_process_wait (cmd->eip));
GNUNET_OS_process_close (cmd->eip);
GNUNET_DISK_pipe_close (cmd->opipe);
GNUNET_free (cmd);
@@ -1373,8 +1398,7 @@
* @param tc scheduler context
*/
static void
-cmd_read (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+cmd_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_OS_CommandHandle *cmd = cls;
GNUNET_OS_LineProcessor proc;
@@ -1382,47 +1406,42 @@
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);
+ &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);
- }
- cmd->rtask = GNUNET_SCHEDULER_add_read_file
(GNUNET_TIME_absolute_get_remaining (cmd->timeout),
- cmd->r,
- &cmd_read,
- cmd);
+ {
+ *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);
}
@@ -1439,30 +1458,26 @@
*/
struct GNUNET_OS_CommandHandle *
GNUNET_OS_command_run (GNUNET_OS_LineProcessor proc,
- void *proc_cls,
- struct GNUNET_TIME_Relative timeout,
- const char *binary,
- ...)
+ void *proc_cls,
+ struct GNUNET_TIME_Relative timeout,
+ const char *binary, ...)
{
struct GNUNET_OS_CommandHandle *cmd;
struct GNUNET_OS_Process *eip;
struct GNUNET_DISK_PipeHandle *opipe;
va_list ap;
- opipe = GNUNET_DISK_pipe (GNUNET_YES,
- GNUNET_NO,
- GNUNET_YES);
+ opipe = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_NO, GNUNET_YES);
if (NULL == opipe)
return NULL;
va_start (ap, binary);
- eip = GNUNET_OS_start_process_va (NULL, opipe,
- binary, ap);
+ 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);
@@ -1470,12 +1485,8 @@
cmd->opipe = opipe;
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->r = GNUNET_DISK_pipe_handle (opipe, GNUNET_DISK_PIPE_END_READ);
+ cmd->rtask = GNUNET_SCHEDULER_add_read_file (timeout, cmd->r, &cmd_read,
cmd);
return cmd;
}
Modified: gnunet/src/util/peer.c
===================================================================
--- gnunet/src/util/peer.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/peer.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -91,14 +91,14 @@
off = (long) GNUNET_CONTAINER_multihashmap_get (map, &pid->hashPubKey);
e = (off == 0) ? NULL : &table[off];
if (e != NULL)
- {
- GNUNET_assert (e->rc > 0);
- return e->pid;
- }
+ {
+ GNUNET_assert (e->rc > 0);
+ return e->pid;
+ }
else
- {
- return 0;
- }
+ {
+ return 0;
+ }
}
/**
@@ -123,24 +123,24 @@
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;
@@ -148,10 +148,10 @@
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;
}
@@ -163,7 +163,7 @@
* @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;
@@ -171,23 +171,24 @@
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;
}
+ }
}
@@ -207,14 +208,15 @@
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;
+ }
}
@@ -228,11 +230,11 @@
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;
Modified: gnunet/src/util/perf_crypto_hash.c
===================================================================
--- gnunet/src/util/perf_crypto_hash.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/perf_crypto_hash.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -42,11 +42,11 @@
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);
}
@@ -60,7 +60,10 @@
printf ("Hash perf took %llu ms\n",
(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");
+ GAUGER ("UTIL", "Cryptographic hashing",
+ 1024 * 64 * 1024 / (1 +
+ GNUNET_TIME_absolute_get_duration
+ (start).rel_value), "kb/s");
return 0;
}
Modified: gnunet/src/util/plugin.c
===================================================================
--- gnunet/src/util/plugin.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/plugin.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -73,7 +73,7 @@
/**
* Setup libtool paths.
*/
-static void
+static void
plugin_init ()
{
int err;
@@ -83,34 +83,31 @@
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);
+ }
+ }
}
@@ -122,10 +119,10 @@
{
lt_dlsetsearchpath (old_dlsearchpath);
if (old_dlsearchpath != NULL)
- {
- GNUNET_free (old_dlsearchpath);
- old_dlsearchpath = NULL;
- }
+ {
+ GNUNET_free (old_dlsearchpath);
+ old_dlsearchpath = NULL;
+ }
lt_dlexit ();
}
@@ -167,23 +164,23 @@
GNUNET_PLUGIN_Callback init;
struct PluginList plug;
- if (! initialized)
- {
- initialized = GNUNET_YES;
- plugin_init ();
- }
+ if (!initialized)
+ {
+ initialized = GNUNET_YES;
+ plugin_init ();
+ }
libhandle = lt_dlopenext (library_name);
if (libhandle == NULL)
return GNUNET_NO;
plug.handle = libhandle;
- plug.name = (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;
}
@@ -209,19 +206,19 @@
GNUNET_PLUGIN_Callback init;
void *ret;
- if (! initialized)
- {
- initialized = GNUNET_YES;
- plugin_init ();
- }
+ if (!initialized)
+ {
+ initialized = GNUNET_YES;
+ plugin_init ();
+ }
libhandle = lt_dlopenext (library_name);
if (libhandle == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("`%s' failed for library `%s' with error: %s\n"),
- "lt_dlopenext", library_name, lt_dlerror ());
- return NULL;
- }
+ {
+ GNUNET_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);
@@ -229,13 +226,13 @@
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;
}
@@ -259,10 +256,10 @@
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;
@@ -278,10 +275,10 @@
GNUNET_free (pos->name);
GNUNET_free (pos);
if (plugins == NULL)
- {
- plugin_fini();
- initialized = GNUNET_NO;
- }
+ {
+ plugin_fini ();
+ initialized = GNUNET_NO;
+ }
return ret;
}
Modified: gnunet/src/util/program.c
===================================================================
--- gnunet/src/util/program.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/program.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -95,9 +95,12 @@
{
__const struct GNUNET_GETOPT_CommandLineOption *c1 = a1;
__const struct GNUNET_GETOPT_CommandLineOption *c2 = a2;
- if (toupper ( (unsigned char) c1->shortName) > toupper ( (unsigned char)
c2->shortName))
+
+ if (toupper ((unsigned char) c1->shortName) >
+ toupper ((unsigned char) c2->shortName))
return 1;
- if (toupper ( (unsigned char) c1->shortName) < toupper ( (unsigned char)
c2->shortName))
+ if (toupper ((unsigned char) c1->shortName) <
+ toupper ((unsigned char) c2->shortName))
return -1;
if (c1->shortName > c2->shortName)
return 1;
@@ -138,6 +141,7 @@
unsigned long long skew_variance;
long long clock_offset;
struct GNUNET_CONFIGURATION_Handle *cfg;
+
struct GNUNET_GETOPT_CommandLineOption defoptions[] = {
GNUNET_GETOPT_OPTION_CFG_FILE (&cc.cfgfile),
GNUNET_GETOPT_OPTION_HELP (binaryHelp),
@@ -153,29 +157,29 @@
logfile = NULL;
gargs = getenv ("GNUNET_ARGS");
if (gargs != NULL)
+ {
+ 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)
{
- 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;
+ 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;
@@ -187,26 +191,25 @@
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);
+ cnt += sizeof (defoptions) / sizeof (struct GNUNET_GETOPT_CommandLineOption);
qsort (allopts, cnt, sizeof (struct GNUNET_GETOPT_CommandLineOption),
&cmd_sorter);
loglev = GNUNET_strdup ("WARNING");
@@ -222,22 +225,26 @@
loglev,
logfile)) ||
(GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, cc.cfgfile))))
- {
- GNUNET_CONFIGURATION_destroy (cfg);
- GNUNET_free_non_null (cc.cfgfile);
- GNUNET_free (loglev);
- GNUNET_free (allopts);
- GNUNET_free (lpfx);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_CONFIGURATION_destroy (cfg);
+ GNUNET_free_non_null (cc.cfgfile);
+ GNUNET_free (loglev);
+ GNUNET_free (allopts);
+ GNUNET_free (lpfx);
+ return GNUNET_SYSERR;
+ }
GNUNET_free (allopts);
GNUNET_free (lpfx);
- if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(cc.cfg, "testing",
"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);
- }
+ if (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_number (cc.cfg, "testing", "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);
+ }
/* run */
cc.args = &argv[ret];
GNUNET_SCHEDULER_run (&program_main, &cc);
Modified: gnunet/src/util/pseudonym.c
===================================================================
--- gnunet/src/util/pseudonym.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/pseudonym.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -84,10 +84,10 @@
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;
+ }
}
/**
@@ -131,10 +131,10 @@
pos = head;
while ((pos != NULL) &&
((pos->callback != iterator) || (pos->closure != closure)))
- {
- prev = pos;
- pos = pos->next;
- }
+ {
+ prev = pos;
+ pos = pos->next;
+ }
if (pos == NULL)
return GNUNET_SYSERR;
if (prev == NULL)
@@ -190,29 +190,29 @@
fn = get_data_filename (cfg, PS_METADATA_DIR, nsid);
GNUNET_assert (fn != NULL);
- fileW = GNUNET_BIO_write_open(fn);
- if (NULL != fileW)
+ 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
- here => refactor code to only create the entry! */
+ * here => refactor code to only create the entry! */
GNUNET_free_non_null (GNUNET_PSEUDONYM_id_to_name (cfg, nsid));
}
@@ -237,41 +237,43 @@
fn = get_data_filename (cfg, PS_METADATA_DIR, nsid);
GNUNET_assert (fn != NULL);
- fileR = GNUNET_BIO_read_open(fn);
+ 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)) ||
- (GNUNET_OK != 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;
- }
- if (GNUNET_OK != GNUNET_BIO_read_close(fileR, &emsg))
- {
- GNUNET_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;
- }
+ if ((GNUNET_OK != GNUNET_BIO_read_int32 (fileR, ranking)) ||
+ (GNUNET_OK !=
+ 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;
+ }
+ if (GNUNET_OK != GNUNET_BIO_read_close (fileR, &emsg))
+ {
+ GNUNET_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;
}
@@ -305,24 +307,24 @@
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);
@@ -341,22 +343,22 @@
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)))
{
- if (0 == memcmp (&nh, nsid, sizeof (GNUNET_HashCode)))
- {
- idx = i;
- break;
- }
- i++;
- len -= sizeof (GNUNET_HashCode);
+ idx = i;
+ break;
}
+ i++;
+ len -= sizeof (GNUNET_HashCode);
+ }
if (idx == -1)
- {
- idx = i;
- if (sizeof (GNUNET_HashCode) !=
- GNUNET_DISK_file_write (fh, nsid, sizeof (GNUNET_HashCode)))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", fn);
- }
+ {
+ idx = i;
+ if (sizeof (GNUNET_HashCode) !=
+ GNUNET_DISK_file_write (fh, nsid, sizeof (GNUNET_HashCode)))
+ GNUNET_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);
@@ -401,10 +403,10 @@
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 |
@@ -414,10 +416,10 @@
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;
}
@@ -466,9 +468,8 @@
if (strlen (fullname) < sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded))
return GNUNET_OK;
- fn =
- &fullname[strlen (fullname) + 1 -
- sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)];
+ fn = &fullname[strlen (fullname) + 1 -
+ sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)];
if (fn[-1] != DIR_SEPARATOR)
return GNUNET_OK;
ret = GNUNET_OK;
@@ -534,10 +535,10 @@
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);
@@ -572,16 +573,16 @@
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);
}
Modified: gnunet/src/util/resolver_api.c
===================================================================
--- gnunet/src/util/resolver_api.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/resolver_api.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -53,7 +53,7 @@
* Configuration.
*/
static const struct GNUNET_CONFIGURATION_Handle *cfg;
-
+
/**
* Our connection to the resolver service, created on-demand, but then
* persists until error or shutdown.
@@ -69,7 +69,7 @@
* Tail of DLL of requests.
*/
static struct GNUNET_RESOLVER_RequestHandle *req_tail;
-
+
/**
* How long should we wait to reconnect?
*/
@@ -192,28 +192,27 @@
#endif
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
- "resolver",
- "HOSTNAME", &hostname))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Must specify `%s' for `%s' in configuration!\n"),
- "HOSTNAME", "resolver");
- GNUNET_assert (0);
- }
+ "resolver", "HOSTNAME",
&hostname))
+ {
+ GNUNET_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;
- }
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_
("Must specify `%s' or numeric IP address for `%s' of `%s' in
configuration!\n"),
@@ -247,24 +246,23 @@
GNUNET_assert (NULL == req_head);
GNUNET_assert (NULL == req_tail);
if (NULL != client)
- {
+ {
#if DEBUG_RESOLVER
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Disconnecting from DNS service\n");
+ GNUNET_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;
+ }
}
@@ -285,37 +283,37 @@
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))
- {
- GNUNET_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))
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop");
- return NULL;
- }
- ret = GNUNET_strdup (inet6);
- break;
- default:
- ret = NULL;
- break;
+ GNUNET_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))
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop");
+ return NULL;
+ }
+ ret = GNUNET_strdup (inet6);
+ break;
+ default:
+ ret = NULL;
+ break;
+ }
return ret;
}
@@ -323,8 +321,7 @@
/**
* Adjust exponential back-off and reconnect to the service.
*/
-static void
-reconnect ();
+static void reconnect ();
/**
@@ -332,8 +329,7 @@
*
* @param h handle to the resolver
*/
-static void
-process_requests ();
+static void process_requests ();
/**
@@ -343,8 +339,7 @@
* @param msg message with the hostname, NULL on error
*/
static void
-handle_response (void *cls,
- const struct GNUNET_MessageHeader *msg)
+handle_response (void *cls, const struct GNUNET_MessageHeader *msg)
{
struct GNUNET_RESOLVER_RequestHandle *rh = cls;
uint16_t size;
@@ -353,138 +348,129 @@
socklen_t salen;
#if DEBUG_RESOLVER
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Receiving response from DNS service\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving response from DNS
service\n");
#endif
if (msg == NULL)
+ {
+ if (NULL != rh->name_callback)
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Timeout trying to resolve IP address `%s'.\n"),
+ GNUNET_a2s ((const void *) &rh[1], rh->data_len));
+ else
+ GNUNET_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)
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Timeout trying to resolve IP address `%s'.\n"),
- GNUNET_a2s ((const void*) &rh[1], rh->data_len));
- else
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Timeout trying to resolve hostname `%s'.\n"),
- (const char *) &rh[1]);
- /* check if request was canceled */
+ {
+ /* 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;
+ }
+ 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')
+ {
+ GNUNET_break (0);
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);
+ 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 (GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE != ntohs (msg->type))
+#if DEBUG_RESOLVER
+ GNUNET_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));
+ }
+ /* 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))
{
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;
}
- 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')
- {
- 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
+ {
+ char *ips = no_resolve (sa, salen);
+
GNUNET_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));
+ "Resolver returns `%s' for `%s'.\n",
+ ips, (const char *) &rh[1]);
+ GNUNET_free (ips);
}
- /* 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))
- {
- 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);
- GNUNET_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));
- }
+ rh->addr_callback (rh->cls, sa, salen);
+ GNUNET_CLIENT_receive (client,
+ &handle_response,
+ rh,
+ GNUNET_TIME_absolute_get_remaining (rh->timeout));
+ }
}
@@ -514,30 +500,29 @@
#if HAVE_SOCKADDR_IN_SIN_LEN
v6.sin6_len = sizeof (v6);
#endif
- hostname = (const char*) &rh[1];
+ 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);
@@ -572,21 +557,21 @@
#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);
}
@@ -614,46 +599,46 @@
struct GNUNET_RESOLVER_GetMessage *msg;
char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1];
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);
memcpy (&msg[1], &rh[1], rh->data_len);
#if DEBUG_RESOLVER
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitting DNS resolution request to DNS service\n");
+ "Transmitting DNS resolution request to DNS service\n");
#endif
if (GNUNET_OK !=
GNUNET_CLIENT_transmit_and_get_response (client,
&msg->header,
-
GNUNET_TIME_absolute_get_remaining (rh->timeout),
- GNUNET_YES,
+
GNUNET_TIME_absolute_get_remaining
+ (rh->timeout), GNUNET_YES,
&handle_response, rh))
- {
- GNUNET_CLIENT_disconnect (client, GNUNET_NO);
- client = NULL;
- reconnect ();
- return;
- }
+ {
+ GNUNET_CLIENT_disconnect (client, GNUNET_NO);
+ client = NULL;
+ reconnect ();
+ return;
+ }
rh->was_transmitted = GNUNET_YES;
}
@@ -665,26 +650,24 @@
* @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)
{
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
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Trying to connect to DNS service\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to connect to DNS service\n");
#endif
client = GNUNET_CLIENT_connect ("resolver", cfg);
if (NULL == client)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Failed to connect, will try again later\n");
- reconnect ();
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to connect, will try again later\n");
+ reconnect ();
+ return;
+ }
process_requests ();
}
@@ -701,37 +684,33 @@
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
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Will try to connect to DNS service in %llu ms\n",
- (unsigned long long) backoff.rel_value);
+ "Will try to connect to DNS service in %llu ms\n",
+ (unsigned long long) backoff.rel_value);
#endif
GNUNET_assert (NULL != cfg);
- r_task = GNUNET_SCHEDULER_add_delayed (backoff,
- &reconnect_task,
- NULL);
+ r_task = GNUNET_SCHEDULER_add_delayed (backoff, &reconnect_task, NULL);
backoff = GNUNET_TIME_relative_multiply (backoff, 2);
}
@@ -760,11 +739,12 @@
struct in6_addr v6;
slen = strlen (hostname) + 1;
- if (slen + sizeof (struct GNUNET_RESOLVER_GetMessage) >=
GNUNET_SERVER_MAX_MESSAGE_SIZE)
- {
- GNUNET_break (0);
- return NULL;
- }
+ if (slen + sizeof (struct GNUNET_RESOLVER_GetMessage) >=
+ GNUNET_SERVER_MAX_MESSAGE_SIZE)
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
rh = GNUNET_malloc (sizeof (struct GNUNET_RESOLVER_RequestHandle) + slen);
rh->domain = domain;
rh->addr_callback = callback;
@@ -782,27 +762,25 @@
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;
- }
- 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;
+ 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;
+ }
process_requests ();
return rh;
}
@@ -816,8 +794,7 @@
* @param tc unused scheduler context
*/
static void
-numeric_reverse (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+numeric_reverse (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_RESOLVER_RequestHandle *rh = cls;
char *result;
@@ -827,10 +804,10 @@
GNUNET_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);
}
@@ -868,25 +845,24 @@
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;
- }
- if (salen + sizeof (struct GNUNET_RESOLVER_GetMessage) >=
GNUNET_SERVER_MAX_MESSAGE_SIZE)
- {
- GNUNET_break (0);
- GNUNET_free (rh);
- return NULL;
- }
- GNUNET_CONTAINER_DLL_insert_tail (req_head,
- req_tail,
- 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_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;
}
@@ -901,26 +877,25 @@
GNUNET_RESOLVER_local_fqdn_get ()
{
struct hostent *host;
- char hostname[GNUNET_OS_get_hostname_max_length() + 1];
+ 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 NULL;
- }
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR |
+ GNUNET_ERROR_TYPE_BULK, "gethostname");
+ return NULL;
+ }
#if DEBUG_RESOLVER
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
_("Resolving our FQDN `%s'\n"), hostname);
#endif
host = gethostbyname (hostname);
if (NULL == host)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Could not resolve our FQDN : %s\n"),
- hstrerror (h_errno));
- return NULL;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Could not resolve our FQDN : %s\n"), hstrerror (h_errno));
+ return NULL;
+ }
return GNUNET_strdup (host->h_name);
}
@@ -940,22 +915,19 @@
GNUNET_RESOLVER_AddressCallback callback,
void *cls)
{
- char hostname[GNUNET_OS_get_hostname_max_length() + 1];
+ 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 NULL;
- }
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR |
+ GNUNET_ERROR_TYPE_BULK, "gethostname");
+ return NULL;
+ }
#if DEBUG_RESOLVER
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
_("Resolving our hostname `%s'\n"), hostname);
#endif
- return GNUNET_RESOLVER_ip_get (hostname,
- domain,
- timeout,
- callback, cls);
+ return GNUNET_RESOLVER_ip_get (hostname, domain, timeout, callback, cls);
}
@@ -971,21 +943,19 @@
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 */
}
Modified: gnunet/src/util/scheduler.c
===================================================================
--- gnunet/src/util/scheduler.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/scheduler.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -149,7 +149,7 @@
* Set if we only wait for writing to a single FD, otherwise -1.
*/
int write_fd;
-
+
/**
* Should the existence of this task in the queue be counted as
* reason to not shutdown the scheduler?
@@ -264,7 +264,7 @@
*/
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;
@@ -308,15 +308,26 @@
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;
@@ -324,18 +335,7 @@
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;
}
@@ -359,41 +359,41 @@
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;
- }
+ 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;
+ }
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;
+ }
}
@@ -410,15 +410,15 @@
set_overlaps (const struct GNUNET_NETWORK_FDSet *ready,
struct GNUNET_NETWORK_FDSet *want)
{
- if ( (NULL == want) || (NULL == ready) )
+ 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;
}
@@ -444,27 +444,27 @@
reason = task->reason;
if (now.abs_value >= task->timeout.abs_value)
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) ) ) )
+ 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))))
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))
) ||
- (set_overlaps (ws, task->write_set) ) ) )
+ (((task->write_fd != -1) &&
+ (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;
}
@@ -479,6 +479,7 @@
queue_ready_task (struct Task *task)
{
enum GNUNET_SCHEDULER_Priority p = task->priority;
+
if (0 != (task->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
p = GNUNET_SCHEDULER_PRIORITY_SHUTDOWN;
task->next = ready[check_priority (p)];
@@ -507,40 +508,40 @@
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
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Checking readiness of task: %llu / %p\n",
- pos->id, pos->callback_cls);
+ GNUNET_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;
+ }
}
@@ -559,34 +560,34 @@
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
- will do that later, possibly adding additional
- readiness-factors */
+ * 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
- will do that later, possibly adding additional
- readiness-factors */
- pos = pos->next;
- }
- }
+ }
}
@@ -620,8 +621,7 @@
* @param ws FDs ready for writing
*/
static void
-run_ready (struct GNUNET_NETWORK_FDSet *rs,
- struct GNUNET_NETWORK_FDSet *ws)
+run_ready (struct GNUNET_NETWORK_FDSet *rs, struct GNUNET_NETWORK_FDSet *ws)
{
enum GNUNET_SCHEDULER_Priority p;
struct Task *pos;
@@ -629,74 +629,72 @@
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)
- {
- GNUNET_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)
+ {
+ GNUNET_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
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Running task: %llu / %p\n", pos->id, pos->callback_cls);
+ GNUNET_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;
- for (i=0;i<pos->num_backtrace_strings;i++)
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Task %llu trace %d: %s\n",
- pos->id,
- i,
- pos->backtrace_strings[i]);
+ int i;
+
+ for (i = 0; i < pos->num_backtrace_strings; i++)
+ GNUNET_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++;
- }
- while ( (pending == NULL) || (p >= max_priority_added) );
+ active_task = NULL;
+ destroy_task (pos);
+ tasks_run++;
+ }
+ while ((pending == NULL) || (p >= max_priority_added));
}
/**
@@ -721,11 +719,11 @@
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;
}
@@ -738,9 +736,10 @@
* GNUNET_NO to exit
*/
static int
-check_lifeness()
+check_lifeness ()
{
struct Task *t;
+
if (ready_count > 0)
return GNUNET_OK;
for (t = pending; NULL != t; t = t->next)
@@ -748,12 +747,12 @@
return GNUNET_OK;
for (t = pending_timeout; NULL != t; t = t->next)
if (t->lifeness == GNUNET_YES)
- return GNUNET_OK;
- if ( (NULL != pending) || (NULL != pending_timeout) )
- {
- GNUNET_SCHEDULER_shutdown ();
return GNUNET_OK;
- }
+ if ((NULL != pending) || (NULL != pending_timeout))
+ {
+ GNUNET_SCHEDULER_shutdown ();
+ return GNUNET_OK;
+ }
return GNUNET_NO;
}
@@ -781,6 +780,7 @@
int ret;
struct GNUNET_SIGNAL_Context *shc_int;
struct GNUNET_SIGNAL_Context *shc_term;
+
#ifndef MINGW
struct GNUNET_SIGNAL_Context *shc_quit;
struct GNUNET_SIGNAL_Context *shc_hup;
@@ -795,9 +795,10 @@
rs = GNUNET_NETWORK_fdset_create ();
ws = GNUNET_NETWORK_fdset_create ();
GNUNET_assert (shutdown_pipe_handle == NULL);
- shutdown_pipe_handle = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO);
+ 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);
+ pr = GNUNET_DISK_pipe_handle (shutdown_pipe_handle,
+ 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);
@@ -809,79 +810,77 @@
current_priority = GNUNET_SCHEDULER_PRIORITY_DEFAULT;
current_lifeness = GNUNET_YES;
GNUNET_SCHEDULER_add_continuation (task,
- task_cls,
- GNUNET_SCHEDULER_REASON_STARTUP);
+ task_cls,
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;
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "select");
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "select");
#ifndef MINGW
#if USE_LSOF
- char lsof[512];
- snprintf (lsof, sizeof (lsof), "lsof -p %d", getpid());
- (void) close (1);
- (void) dup2 (2, 1);
- if (0 != system (lsof))
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "system");
+ char lsof[512];
+
+ snprintf (lsof, sizeof (lsof), "lsof -p %d", getpid ());
+ (void) close (1);
+ (void) dup2 (2, 1);
+ if (0 != system (lsof))
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "system");
#endif
#endif
- abort ();
- break;
- }
- if ((ret == 0) && (timeout.rel_value == 0) && (busy_wait_warning > 16))
- {
- GNUNET_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))
+ {
+ GNUNET_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 +933,10 @@
ret = 0;
pos = ready[check_priority (p)];
while (pos != NULL)
- {
- pos = pos->next;
- ret++;
- }
+ {
+ pos = pos->next;
+ ret++;
+ }
return ret;
}
@@ -963,73 +962,73 @@
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;
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)
- {
- GNUNET_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;
- }
+ GNUNET_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
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1055,17 +1054,19 @@
enum GNUNET_SCHEDULER_Reason reason)
{
struct Task *t;
+
#if EXECINFO
void *backtrace_array[50];
#endif
GNUNET_assert (NULL != task);
- GNUNET_assert ( (active_task != NULL) ||
- (reason == GNUNET_SCHEDULER_REASON_STARTUP) );
+ GNUNET_assert ((active_task != NULL) ||
+ (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);
+ t->num_backtrace_strings = backtrace (backtrace_array, 50);
+ t->backtrace_strings =
+ backtrace_symbols (backtrace_array, t->num_backtrace_strings);
#endif
t->read_fd = -1;
t->write_fd = -1;
@@ -1080,8 +1081,7 @@
t->lifeness = current_lifeness;
#if DEBUG_TASKS
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Adding continuation task: %llu / %p\n",
- t->id, t->callback_cls);
+ "Adding continuation task: %llu / %p\n", t->id, t->callback_cls);
#endif
queue_ready_task (t);
}
@@ -1126,8 +1126,7 @@
*/
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,
@@ -1158,6 +1157,7 @@
struct Task *t;
struct Task *pos;
struct Task *prev;
+
#if EXECINFO
void *backtrace_array[MAX_TRACE_DEPTH];
#endif
@@ -1168,8 +1168,9 @@
t->callback = task;
t->callback_cls = task_cls;
#if EXECINFO
- t->num_backtrace_strings = backtrace(backtrace_array, MAX_TRACE_DEPTH);
- t->backtrace_strings = backtrace_symbols(backtrace_array,
t->num_backtrace_strings);
+ t->num_backtrace_strings = backtrace (backtrace_array, MAX_TRACE_DEPTH);
+ t->backtrace_strings =
+ backtrace_symbols (backtrace_array, t->num_backtrace_strings);
#endif
t->read_fd = -1;
t->write_fd = -1;
@@ -1181,27 +1182,27 @@
t->priority = current_priority;
t->lifeness = current_lifeness;
/* try tail first (optimization in case we are
- appending to a long list of tasks with timeouts) */
+ * 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 != NULL)
+ {
+ 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;
- }
- while ( (pos != NULL) &&
- ( (pos->timeout.abs_value <= t->timeout.abs_value) ||
- (pos->reason != 0) ) )
- {
- prev = pos;
- pos = pos->next;
- }
+ {
+ /* 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;
+ }
if (prev == NULL)
pending_timeout = t;
else
@@ -1217,12 +1218,9 @@
#if EXECINFO
int i;
- for (i=0;i<t->num_backtrace_strings;i++)
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Task %llu trace %d: %s\n",
- t->id,
- i,
- t->backtrace_strings[i]);
+ for (i = 0; i < t->num_backtrace_strings; i++)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Task %llu trace %d: %s\n", t->id, i, t->backtrace_strings[i]);
#endif
return t->id;
@@ -1246,12 +1244,11 @@
* only valid until "task" is started!
*/
GNUNET_SCHEDULER_TaskIdentifier
-GNUNET_SCHEDULER_add_now (GNUNET_SCHEDULER_Task task,
- void *task_cls)
+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,
+ GNUNET_TIME_UNIT_ZERO,
NULL, NULL, task, task_cls);
}
@@ -1272,15 +1269,15 @@
*/
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_NO_TASK,
+ GNUNET_TIME_UNIT_ZERO,
+ NULL, NULL, task, task_cls);
GNUNET_assert (pending->id == ret);
pending->lifeness = lifeness;
return ret;
@@ -1318,11 +1315,10 @@
#ifndef MINGW
GNUNET_SCHEDULER_TaskIdentifier
add_without_sets (struct GNUNET_TIME_Relative delay,
- int rfd,
- int wfd,
- GNUNET_SCHEDULER_Task task, void *task_cls)
+ int rfd, int wfd, GNUNET_SCHEDULER_Task task, void *task_cls)
{
struct Task *t;
+
#if EXECINFO
void *backtrace_array[MAX_TRACE_DEPTH];
#endif
@@ -1333,47 +1329,50 @@
t->callback = task;
t->callback_cls = task_cls;
#if EXECINFO
- t->num_backtrace_strings = backtrace(backtrace_array, MAX_TRACE_DEPTH);
- t->backtrace_strings = backtrace_symbols(backtrace_array,
t->num_backtrace_strings);
+ t->num_backtrace_strings = backtrace (backtrace_array, MAX_TRACE_DEPTH);
+ t->backtrace_strings =
+ backtrace_symbols (backtrace_array, t->num_backtrace_strings);
#endif
#if DEBUG_FDS
if (-1 != rfd)
+ {
+ int flags = fcntl (rfd, F_GETFD);
+
+ if (flags == -1 && errno == EBADF)
{
- int flags = fcntl(rfd, F_GETFD);
- if (flags == -1 && errno == EBADF)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Got invalid file descriptor
%d!\n", rfd);
+ GNUNET_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++)
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Trace: %s\n",
- t->backtrace_strings[i]);
+ for (i = 0; i < t->num_backtrace_strings; i++)
+ GNUNET_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);
+
+ if (flags == -1 && errno == EBADF)
{
- int flags = fcntl(wfd, F_GETFD);
- if (flags == -1 && errno == EBADF)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Got invalid file descriptor
%d!\n", wfd);
+ GNUNET_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++)
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Trace: %s\n",
- t->backtrace_strings[i]);
+ for (i = 0; i < t->num_backtrace_strings; i++)
+ GNUNET_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);
+ GNUNET_assert (wfd >= -1);
t->write_fd = wfd;
t->id = ++last_id;
#if PROFILE_DELAYS
@@ -1385,8 +1384,7 @@
t->lifeness = current_lifeness;
t->next = pending;
pending = t;
- max_priority_added = GNUNET_MAX (max_priority_added,
- t->priority);
+ max_priority_added = GNUNET_MAX (max_priority_added, t->priority);
#if DEBUG_TASKS
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Adding task: %llu / %p\n", t->id, t->callback_cls);
@@ -1394,12 +1392,9 @@
#if EXECINFO
int i;
- for (i=0;i<t->num_backtrace_strings;i++)
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Task %llu trace %d: %s\n",
- t->id,
- i,
- t->backtrace_strings[i]);
+ for (i = 0; i < t->num_backtrace_strings; i++)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Task %llu trace %d: %s\n", t->id, i, t->backtrace_strings[i]);
#endif
return t->id;
}
@@ -1425,7 +1420,7 @@
*/
GNUNET_SCHEDULER_TaskIdentifier
GNUNET_SCHEDULER_add_read_net (struct GNUNET_TIME_Relative delay,
- struct GNUNET_NETWORK_Handle * rfd,
+ struct GNUNET_NETWORK_Handle *rfd,
GNUNET_SCHEDULER_Task task, void *task_cls)
{
#if MINGW
@@ -1442,10 +1437,7 @@
return ret;
#else
return add_without_sets (delay,
- GNUNET_NETWORK_get_fd (rfd),
- -1,
- task,
- task_cls);
+ GNUNET_NETWORK_get_fd (rfd), -1, task, task_cls);
#endif
}
@@ -1468,7 +1460,7 @@
*/
GNUNET_SCHEDULER_TaskIdentifier
GNUNET_SCHEDULER_add_write_net (struct GNUNET_TIME_Relative delay,
- struct GNUNET_NETWORK_Handle * wfd,
+ struct GNUNET_NETWORK_Handle *wfd,
GNUNET_SCHEDULER_Task task, void *task_cls)
{
#if MINGW
@@ -1484,12 +1476,9 @@
GNUNET_NETWORK_fdset_destroy (ws);
return ret;
#else
- GNUNET_assert(GNUNET_NETWORK_get_fd(wfd) >= 0);
+ GNUNET_assert (GNUNET_NETWORK_get_fd (wfd) >= 0);
return add_without_sets (delay,
- -1,
- GNUNET_NETWORK_get_fd (wfd),
- task,
- task_cls);
+ -1, GNUNET_NETWORK_get_fd (wfd), task, task_cls);
#endif
}
@@ -1512,7 +1501,7 @@
*/
GNUNET_SCHEDULER_TaskIdentifier
GNUNET_SCHEDULER_add_read_file (struct GNUNET_TIME_Relative delay,
- const struct GNUNET_DISK_FileHandle * rfd,
+ const struct GNUNET_DISK_FileHandle *rfd,
GNUNET_SCHEDULER_Task task, void *task_cls)
{
#if MINGW
@@ -1531,11 +1520,7 @@
int fd;
GNUNET_DISK_internal_file_handle_ (rfd, &fd, sizeof (int));
- return add_without_sets (delay,
- fd,
- -1,
- task,
- task_cls);
+ return add_without_sets (delay, fd, -1, task, task_cls);
#endif
}
@@ -1559,7 +1544,7 @@
*/
GNUNET_SCHEDULER_TaskIdentifier
GNUNET_SCHEDULER_add_write_file (struct GNUNET_TIME_Relative delay,
- const struct GNUNET_DISK_FileHandle * wfd,
+ const struct GNUNET_DISK_FileHandle *wfd,
GNUNET_SCHEDULER_Task task, void *task_cls)
{
#if MINGW
@@ -1578,12 +1563,8 @@
int fd;
GNUNET_DISK_internal_file_handle_ (wfd, &fd, sizeof (int));
- GNUNET_assert(fd >= 0);
- return add_without_sets (delay,
- -1,
- fd,
- task,
- task_cls);
+ GNUNET_assert (fd >= 0);
+ return add_without_sets (delay, -1, fd, task, task_cls);
#endif
}
@@ -1627,11 +1608,12 @@
GNUNET_SCHEDULER_TaskIdentifier
prerequisite_task,
struct GNUNET_TIME_Relative delay,
- const struct GNUNET_NETWORK_FDSet * rs,
- const struct GNUNET_NETWORK_FDSet * ws,
+ const struct GNUNET_NETWORK_FDSet *rs,
+ const struct GNUNET_NETWORK_FDSet *ws,
GNUNET_SCHEDULER_Task task, void *task_cls)
{
struct Task *t;
+
#if EXECINFO
void *backtrace_array[MAX_TRACE_DEPTH];
#endif
@@ -1642,21 +1624,22 @@
t->callback = task;
t->callback_cls = task_cls;
#if EXECINFO
- t->num_backtrace_strings = backtrace(backtrace_array, MAX_TRACE_DEPTH);
- t->backtrace_strings = backtrace_symbols(backtrace_array,
t->num_backtrace_strings);
+ t->num_backtrace_strings = backtrace (backtrace_array, MAX_TRACE_DEPTH);
+ t->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 ();
@@ -1664,14 +1647,13 @@
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);
+ max_priority_added = GNUNET_MAX (max_priority_added, t->priority);
#if DEBUG_TASKS
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Adding task: %llu / %p\n", t->id, t->callback_cls);
@@ -1679,12 +1661,9 @@
#if EXECINFO
int i;
- for (i=0;i<t->num_backtrace_strings;i++)
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Task %llu trace %d: %s\n",
- t->id,
- i,
- t->backtrace_strings[i]);
+ for (i = 0; i < t->num_backtrace_strings; i++)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Task %llu trace %d: %s\n", t->id, i, t->backtrace_strings[i]);
#endif
return t->id;
}
Modified: gnunet/src/util/server.c
===================================================================
--- gnunet/src/util/server.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/server.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -242,7 +242,7 @@
* be used in special cases!
*/
int persist;
-
+
/**
* Type of last message processed (for warn_no_receive_done).
*/
@@ -258,8 +258,7 @@
* @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;
@@ -273,49 +272,46 @@
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
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Server accepted incoming connection.\n");
+ GNUNET_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);
+ 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);
}
@@ -336,88 +332,88 @@
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)
- {
- GNUNET_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)
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "setsockopt");
+ {
+ GNUNET_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)
+ GNUNET_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) )
- GNUNET_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))
+ GNUNET_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' */
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind");
- if (port != 0)
- GNUNET_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)
- GNUNET_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)
- GNUNET_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' */
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind");
+ if (port != 0)
+ GNUNET_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
{
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "listen");
- GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
- errno = 0;
- return NULL;
+ if (port != 0)
+ GNUNET_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)
+ GNUNET_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))
+ {
+ GNUNET_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)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -440,11 +436,11 @@
* (typically, "port" already in use)
*/
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)
+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)
{
struct GNUNET_SERVER_Handle *ret;
struct GNUNET_NETWORK_FDSet *r;
@@ -457,19 +453,18 @@
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;
}
@@ -503,34 +498,32 @@
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)
- GNUNET_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)
+ GNUNET_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);
+ lsocks,
+ idle_timeout, require_found);
}
@@ -550,32 +543,32 @@
GNUNET_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);
}
@@ -595,8 +588,7 @@
*/
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;
@@ -614,19 +606,21 @@
* @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);
+ &warn_no_receive_done,
+ client);
if (0 == (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
GNUNET_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);
}
@@ -641,10 +635,10 @@
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;
+ }
}
@@ -686,53 +680,49 @@
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
- GNUNET_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);
+ GNUNET_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++;
+ return GNUNET_SYSERR;
}
- pos = pos->next;
+ 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)
- {
- GNUNET_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;
- }
+ {
+ GNUNET_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;
}
@@ -751,8 +741,7 @@
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);
/**
@@ -769,51 +758,49 @@
* GNUNET_SYSERR if we should instantly abort due to error in a
previous step
*/
static void
-process_mst (struct GNUNET_SERVER_Client *client,
- int ret)
+process_mst (struct GNUNET_SERVER_Client *client, int ret)
{
- while ( (ret != GNUNET_SYSERR) &&
- (client->server != NULL) &&
- (GNUNET_YES != client->shutdown_now) &&
- (0 == client->suspended) )
+ while ((ret != GNUNET_SYSERR) &&
+ (client->server != NULL) &&
+ (GNUNET_YES != client->shutdown_now) && (0 == client->suspended))
+ {
+ if (ret == GNUNET_OK)
{
- if (ret == GNUNET_OK)
- {
- client->receive_pending = GNUNET_YES;
+ client->receive_pending = GNUNET_YES;
#if DEBUG_SERVER
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Server re-enters receive loop, timeout: %llu.\n",
client->idle_timeout.rel_value);
+ GNUNET_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;
- }
+ GNUNET_CONNECTION_receive (client->connection,
+ GNUNET_SERVER_MAX_MESSAGE_SIZE - 1,
+ client->idle_timeout,
+ &process_incoming, client);
+ break;
+ }
#if DEBUG_SERVER
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Server processes additional
messages instantly.\n");
+ GNUNET_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);
- }
+ ret =
+ GNUNET_SERVER_mst_receive (client->mst, client, NULL, 0, GNUNET_NO,
+ GNUNET_YES);
+ }
#if DEBUG_SERVER
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Server leaves instant processing loop: ret = %d, server = %p,
shutdown = %d, suspended = %u\n",
- ret,
- client->server,
- client->shutdown_now,
- client->suspended);
+ "Server leaves instant processing loop: ret = %d, server = %p,
shutdown = %d, suspended = %u\n",
+ ret, client->server, client->shutdown_now, client->suspended);
#endif
if (ret == GNUNET_NO)
- {
+ {
#if DEBUG_SERVER
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Server has more data pending but is suspended.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Server has more data pending but is suspended.\n");
#endif
- client->receive_pending = GNUNET_SYSERR; /* data pending */
- }
- if ( (ret == GNUNET_SYSERR) ||
- (GNUNET_YES == client->shutdown_now) )
+ 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);
}
@@ -833,8 +820,7 @@
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;
@@ -845,48 +831,48 @@
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) */
+ 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) */
#if DEBUG_SERVER
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Receive time out, but no disconnect due to sending (%p)\n",
- GNUNET_a2s (addr, addrlen));
+ GNUNET_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;
- }
+ 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;
- }
+ {
+ /* other side closed connection, error connecting, etc. */
+ GNUNET_SERVER_client_disconnect (client);
+ return;
+ }
#if DEBUG_SERVER
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Server receives %u bytes from `%s'.\n",
- (unsigned int) available,
- GNUNET_a2s (addr, addrlen));
+ (unsigned int) available, GNUNET_a2s (addr, addrlen));
#endif
GNUNET_SERVER_client_keep (client);
client->last_activity = now;
- ret = GNUNET_SERVER_mst_receive (client->mst, client, buf, available,
GNUNET_NO, GNUNET_YES);
+ ret =
+ GNUNET_SERVER_mst_receive (client->mst, client, buf, available,
GNUNET_NO,
+ GNUNET_YES);
process_mst (client, ret);
}
@@ -899,34 +885,33 @@
* @param tc scheduler context (unused)
*/
static void
-restart_processing (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+restart_processing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_SERVER_Client *client = cls;
struct GNUNET_SERVER_Handle *server = client->server;
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;
- }
+ if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) &&
+ (GNUNET_NO == server->clients_ignore_shutdown))
+ {
+ GNUNET_SERVER_client_disconnect (client);
+ return;
+ }
if (client->receive_pending == GNUNET_NO)
- {
+ {
#if DEBUG_SERVER
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Server begins to read again from client.\n");
+ GNUNET_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
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Server continues processing messages still in the buffer.\n");
+ "Server continues processing messages still in the buffer.\n");
#endif
GNUNET_SERVER_client_keep (client);
client->receive_pending = GNUNET_NO;
@@ -944,8 +929,8 @@
*/
static void
client_message_tokenizer_callback (void *cls,
- void *client,
- const struct GNUNET_MessageHeader *message)
+ void *client,
+ const struct GNUNET_MessageHeader *message)
{
struct GNUNET_SERVER_Handle *server = cls;
struct GNUNET_SERVER_Client *sender = client;
@@ -954,14 +939,14 @@
#if DEBUG_SERVER
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Tokenizer gives server message of type %u from client\n",
- ntohs (message->type));
+ "Tokenizer gives server message of type %u from client\n",
+ ntohs (message->type));
#endif
sender->in_process_client_buffer = GNUNET_YES;
ret = GNUNET_SERVER_inject (server, sender, message);
sender->in_process_client_buffer = GNUNET_NO;
if (GNUNET_OK != ret)
- GNUNET_SERVER_client_disconnect (sender);
+ GNUNET_SERVER_client_disconnect (sender);
}
@@ -988,7 +973,7 @@
client = GNUNET_malloc (sizeof (struct GNUNET_SERVER_Client));
client->connection = connection;
client->mst = GNUNET_SERVER_mst_create (&client_message_tokenizer_callback,
- server);
+ server);
client->reference_count = 1;
client->server = server;
client->last_activity = GNUNET_TIME_absolute_get ();
@@ -999,8 +984,8 @@
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;
}
@@ -1014,8 +999,8 @@
* @param timeout new timeout for activities on the socket
*/
void
-GNUNET_SERVER_client_set_timeout(struct GNUNET_SERVER_Client *client,
- struct GNUNET_TIME_Relative timeout)
+GNUNET_SERVER_client_set_timeout (struct GNUNET_SERVER_Client *client,
+ struct GNUNET_TIME_Relative timeout)
{
client->idle_timeout = timeout;
}
@@ -1048,8 +1033,7 @@
{
GNUNET_assert (client->reference_count > 0);
client->reference_count--;
- if ( (client->shutdown_now == GNUNET_YES) &&
- (client->reference_count == 0) )
+ if ((client->shutdown_now == GNUNET_YES) && (client->reference_count == 0))
GNUNET_SERVER_client_disconnect (client);
}
@@ -1066,8 +1050,7 @@
GNUNET_SERVER_client_get_address (struct GNUNET_SERVER_Client *client,
void **addr, size_t * addrlen)
{
- return GNUNET_CONNECTION_get_address (client->connection,
- addr, addrlen);
+ return GNUNET_CONNECTION_get_address (client->connection, addr, addrlen);
}
@@ -1105,8 +1088,8 @@
*/
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;
@@ -1114,18 +1097,17 @@
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
@@ -1153,81 +1135,81 @@
#if DEBUG_SERVER
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Client is being disconnected from the server.\n");
+ "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)
+ n = server->disconnect_notify_list;
+ while (n != NULL)
{
- GNUNET_CONNECTION_receive_cancel (client->connection);
- client->receive_pending = GNUNET_NO;
+ n->callback (n->callback_cls, client);
+ n = n->next;
}
-
- 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)
- {
- 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;
- }
- }
+ }
if (rc > 0)
- {
+ {
#if DEBUG_SERVER
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "RC still positive, not destroying everything.\n");
+ GNUNET_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
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Still processing inputs, not destroying everything.\n");
+ GNUNET_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);
+ GNUNET_CONNECTION_persist_ (client->connection);
GNUNET_CONNECTION_destroy (client->connection, GNUNET_NO);
GNUNET_SERVER_mst_destroy (client->mst);
- GNUNET_free (client);
+ GNUNET_free (client);
}
@@ -1255,7 +1237,7 @@
* @param buf where to copy the message
* @return number of bytes actually transmitted
*/
-static size_t
+static size_t
transmit_ready_callback_wrapper (void *cls, size_t size, void *buf)
{
struct GNUNET_SERVER_Client *client = cls;
@@ -1263,7 +1245,7 @@
ret = client->callback (client->callback_cls, size, buf);
if (ret > 0)
- client->last_activity = GNUNET_TIME_absolute_get();
+ client->last_activity = GNUNET_TIME_absolute_get ();
return ret;
}
@@ -1293,9 +1275,10 @@
client->callback_cls = callback_cls;
client->callback = callback;
return GNUNET_CONNECTION_notify_transmit_ready (client->connection,
- size,
- timeout,
-
&transmit_ready_callback_wrapper, client);
+ size,
+ timeout,
+
&transmit_ready_callback_wrapper,
+ client);
}
@@ -1332,47 +1315,46 @@
GNUNET_assert (client->suspended > 0);
client->suspended--;
if (success != GNUNET_OK)
- {
+ {
#if DEBUG_SERVER
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "GNUNET_SERVER_receive_done called with failure
indication\n");
+ GNUNET_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
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "GNUNET_SERVER_receive_done called, but more clients
pending\n");
+ GNUNET_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
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "GNUNET_SERVER_receive_done called while still in processing
loop\n");
+ GNUNET_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
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "GNUNET_SERVER_receive_done causes restart in reading from the
socket\n");
+ "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);
}
Modified: gnunet/src/util/server_mst.c
===================================================================
--- gnunet/src/util/server_mst.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/server_mst.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -50,7 +50,7 @@
* Function to call on completed messages.
*/
GNUNET_SERVER_MessageTokenizerCallback cb;
-
+
/**
* Closure for cb.
*/
@@ -89,12 +89,12 @@
*/
struct GNUNET_SERVER_MessageStreamTokenizer *
GNUNET_SERVER_mst_create (GNUNET_SERVER_MessageTokenizerCallback cb,
- void *cb_cls)
+ void *cb_cls)
{
struct GNUNET_SERVER_MessageStreamTokenizer *ret;
ret = GNUNET_malloc (sizeof (struct GNUNET_SERVER_MessageStreamTokenizer));
- ret->hdr = GNUNET_malloc(GNUNET_SERVER_MIN_BUFFER_SIZE);
+ ret->hdr = GNUNET_malloc (GNUNET_SERVER_MIN_BUFFER_SIZE);
ret->curr_buf = GNUNET_SERVER_MIN_BUFFER_SIZE;
ret->cb = cb;
ret->cb_cls = cb_cls;
@@ -119,11 +119,9 @@
*/
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;
@@ -135,169 +133,160 @@
#if DEBUG_SERVER_MST
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Server-mst receives %u bytes with %u bytes already in private
buffer\n",
- (unsigned int) size,
- (unsigned int) (mst->pos - mst->off));
+ "Server-mst receives %u bytes with %u bytes already in private
buffer\n",
+ (unsigned int) size, (unsigned int) (mst->pos - mst->off));
#endif
ret = GNUNET_OK;
- ibuf = (char*)mst->hdr;
+ 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
+ GNUNET_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
- GNUNET_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) )
+ }
+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;
+ mst->off = 0;
#if DEBUG_SERVER_MST
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Server-mst leaves %u bytes in private buffer\n",
- (unsigned int) (mst->pos - mst->off));
+ "Server-mst leaves %u bytes in private buffer\n",
+ (unsigned int) (mst->pos - mst->off));
#endif
return ret;
}
Modified: gnunet/src/util/server_nc.c
===================================================================
--- gnunet/src/util/server_nc.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/server_nc.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -44,12 +44,12 @@
/**
* This is a doubly-linked list.
- */
+ */
struct PendingMessageList *next;
/**
* This is a doubly-linked list.
- */
+ */
struct PendingMessageList *prev;
/**
@@ -60,7 +60,7 @@
/**
* Can this message be dropped?
- */
+ */
int can_drop;
};
@@ -74,7 +74,7 @@
/**
* This is a linked list.
- */
+ */
struct ClientList *next;
/**
@@ -94,12 +94,12 @@
/**
* Head of linked list of requests queued for transmission.
- */
+ */
struct PendingMessageList *pending_head;
/**
* Tail of linked list of requests queued for transmission.
- */
+ */
struct PendingMessageList *pending_tail;
/**
@@ -146,8 +146,7 @@
* @param client handle of client that disconnected
*/
static void
-handle_client_disconnect (void *cls,
- struct GNUNET_SERVER_Client *client)
+handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
{
struct GNUNET_SERVER_NotificationContext *nc = cls;
struct ClientList *pos;
@@ -155,42 +154,40 @@
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
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Client disconnected, cleaning up %u messages in NC queue\n",
- pos->num_pending);
+ "Client disconnected, cleaning up %u messages in NC queue\n",
+ pos->num_pending);
#endif
if (prev == NULL)
nc->clients = pos->next;
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);
}
@@ -207,16 +204,14 @@
*/
struct GNUNET_SERVER_NotificationContext *
GNUNET_SERVER_notification_context_create (struct GNUNET_SERVER_Handle *server,
- unsigned int queue_length)
+ unsigned int queue_length)
{
struct GNUNET_SERVER_NotificationContext *ret;
ret = GNUNET_malloc (sizeof (struct GNUNET_SERVER_NotificationContext));
ret->server = server;
ret->queue_length = queue_length;
- GNUNET_SERVER_disconnect_notify (server,
- &handle_client_disconnect,
- ret);
+ GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, ret);
return ret;
}
@@ -227,28 +222,27 @@
* @param nc context to destroy.
*/
void
-GNUNET_SERVER_notification_context_destroy (struct
GNUNET_SERVER_NotificationContext *nc)
+GNUNET_SERVER_notification_context_destroy (struct
+ 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);
}
@@ -260,8 +254,9 @@
* @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;
@@ -285,9 +280,7 @@
* @return number of bytes written to buf
*/
static size_t
-transmit_message (void *cls,
- size_t size,
- void *buf)
+transmit_message (void *cls, size_t size, void *buf)
{
struct ClientList *cl = cls;
char *cbuf = buf;
@@ -297,48 +290,44 @@
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
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Failed to transmit message from NC queue to client\n");
+ GNUNET_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);
+ 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);
#if DEBUG_SERVER_NC
- GNUNET_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);
+ GNUNET_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--;
- }
- if (pml != NULL)
- {
+ memcpy (&cbuf[ret], pml->msg, msize);
+ ret += msize;
+ size -= msize;
+ GNUNET_free (pml);
+ cl->num_pending--;
+ }
+ if (pml != NULL)
+ {
#if DEBUG_SERVER_NC
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Have %u messages left in NC queue, will try transmission
again\n",
- cl->num_pending);
+ GNUNET_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;
@@ -355,52 +344,49 @@
*/
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) )
- {
- GNUNET_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) && (GNUNET_YES == can_drop))
+ {
+ GNUNET_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);
- pml->msg = (const struct GNUNET_MessageHeader*) &pml[1];
- pml->can_drop = can_drop;
+ pml->msg = (const struct GNUNET_MessageHeader *) &pml[1];
+ pml->can_drop = can_drop;
#if DEBUG_SERVER_NC
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Adding message of type %u and size %u to pending queue (which
has %u entries)\n",
- ntohs (msg->type),
- ntohs (msg->size),
- (unsigned int) nc->queue_length);
+ "Adding message of type %u and size %u to pending queue (which
has %u entries)\n",
+ ntohs (msg->type),
+ ntohs (msg->size), (unsigned int) nc->queue_length);
#endif
memcpy (&pml[1], msg, size);
/* append */
GNUNET_CONTAINER_DLL_insert_tail (client->pending_head,
- client->pending_tail,
- pml);
+ 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);
-}
+ ntohs
+ (client->pending_head->
+ msg->size),
+
GNUNET_TIME_UNIT_FOREVER_REL,
+ &transmit_message,
+ client);
+}
/**
@@ -413,22 +399,24 @@
* @param can_drop can this message be dropped due to queue length limitations
*/
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_notification_context_unicast (struct
+ 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);
+ do_unicast (nc, pos, msg, can_drop);
}
@@ -440,18 +428,20 @@
* @param can_drop can this message be dropped due to queue length limitations
*/
void
-GNUNET_SERVER_notification_context_broadcast (struct
GNUNET_SERVER_NotificationContext *nc,
- const struct GNUNET_MessageHeader
*msg,
- int can_drop)
+GNUNET_SERVER_notification_context_broadcast (struct
+ 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;
+ }
}
Modified: gnunet/src/util/server_tc.c
===================================================================
--- gnunet/src/util/server_tc.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/server_tc.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -79,14 +79,15 @@
{
struct GNUNET_SERVER_TransmitContext *tc = cls;
size_t msize;
+
if (buf == NULL)
- {
- GNUNET_SERVER_receive_done (tc->client, GNUNET_SYSERR);
- GNUNET_SERVER_client_drop (tc->client);
- GNUNET_free_non_null (tc->buf);
- GNUNET_free (tc);
- return 0;
- }
+ {
+ GNUNET_SERVER_receive_done (tc->client, GNUNET_SYSERR);
+ GNUNET_SERVER_client_drop (tc->client);
+ GNUNET_free_non_null (tc->buf);
+ GNUNET_free (tc);
+ return 0;
+ }
if (tc->total - tc->off > size)
msize = size;
else
@@ -94,30 +95,29 @@
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);
+ }
+ 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))
{
- GNUNET_SERVER_receive_done (tc->client, GNUNET_OK);
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (tc->client, GNUNET_SYSERR);
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))
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (tc->client, GNUNET_SYSERR);
- GNUNET_SERVER_client_drop (tc->client);
- GNUNET_free_non_null (tc->buf);
- GNUNET_free (tc);
- }
- }
+ }
return msize;
}
@@ -154,8 +154,8 @@
*/
void
GNUNET_SERVER_transmit_context_append_data (struct
GNUNET_SERVER_TransmitContext
- *tc, const void *data, size_t
length,
- uint16_t type)
+ *tc, const void *data,
+ size_t length, uint16_t type)
{
struct GNUNET_MessageHeader *msg;
size_t size;
@@ -181,8 +181,11 @@
* @param msg message to append
*/
void
-GNUNET_SERVER_transmit_context_append_message(struct
GNUNET_SERVER_TransmitContext
- *tc, const struct
GNUNET_MessageHeader *msg)
+GNUNET_SERVER_transmit_context_append_message (struct
+ GNUNET_SERVER_TransmitContext
+ *tc,
+ const struct
GNUNET_MessageHeader
+ *msg)
{
struct GNUNET_MessageHeader *m;
uint16_t size;
@@ -214,13 +217,13 @@
GNUNET_MIN (MIN_BLOCK_SIZE,
tc->total), timeout,
&transmit_response, tc))
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (tc->client, GNUNET_SYSERR);
- GNUNET_SERVER_client_drop (tc->client);
- GNUNET_free_non_null (tc->buf);
- GNUNET_free (tc);
- }
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (tc->client, GNUNET_SYSERR);
+ GNUNET_SERVER_client_drop (tc->client);
+ GNUNET_free_non_null (tc->buf);
+ GNUNET_free (tc);
+ }
}
/* end of server_tc.c */
Modified: gnunet/src/util/service.c
===================================================================
--- gnunet/src/util/service.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/service.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -98,128 +98,123 @@
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)
{
- for (j = 0; j < 8; j++)
- if (temps[j] > 0xFF)
- {
- GNUNET_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;
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Invalid format for IP: `%s'\n"), &routeList[pos]);
+ GNUNET_free (result);
+ return NULL;
}
- /* try second notation */
- cnt = sscanf (&routeList[pos],
- "%u.%u.%u.%u/%u;",
- &temps[0], &temps[1], &temps[2], &temps[3], &slash);
- if (cnt == 5)
+ 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)
{
- for (j = 0; j < 4; j++)
- if (temps[j] > 0xFF)
- {
- GNUNET_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
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _
- ("Invalid network notation ('/%d' is not legal in
IPv4 CIDR)."),
- slash);
- GNUNET_free (result);
- return NULL; /* error */
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Invalid format for IP: `%s'\n"), &routeList[pos]);
+ GNUNET_free (result);
+ return NULL;
}
- /* try third notation */
- slash = 32;
- cnt = sscanf (&routeList[pos],
- "%u.%u.%u.%u;",
- &temps[0], &temps[1], &temps[2], &temps[3]);
- if (cnt == 4)
+ 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)
{
- for (j = 0; j < 4; j++)
- if (temps[j] > 0xFF)
- {
- GNUNET_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;
+ result[i].netmask.s_addr
+ = (result[i].netmask.s_addr >> 1) + 0x80000000;
+ slash--;
}
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Invalid format for IP: `%s'\n"), &routeList[pos]);
- GNUNET_free (result);
- return NULL; /* error */
+ result[i].netmask.s_addr = htonl (result[i].netmask.s_addr);
+ while (routeList[pos] != ';')
+ pos++;
+ pos++;
+ i++;
+ continue;
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _
+ ("Invalid network notation ('/%d' is not legal in IPv4
CIDR)."),
+ slash);
+ GNUNET_free (result);
+ return NULL; /* error */
+ }
}
- if (pos < strlen (routeList))
+ /* try third notation */
+ slash = 32;
+ cnt = sscanf (&routeList[pos],
+ "%u.%u.%u.%u;", &temps[0], &temps[1], &temps[2], &temps[3]);
+ if (cnt == 4)
{
- GNUNET_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)
+ {
+ GNUNET_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;
}
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Invalid format for IP: `%s'\n"), &routeList[pos]);
+ GNUNET_free (result);
+ return NULL; /* error */
+ }
+ if (pos < strlen (routeList))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Invalid format for IP: `%s'\n"), &routeList[pos]);
+ GNUNET_free (result);
+ return NULL; /* oops */
+ }
return result; /* ok */
}
@@ -262,88 +257,85 @@
if (routeList[i] == ';')
count++;
if (routeList[len - 1] != ';')
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _
- ("Invalid network notation (does not end with ';': `%s')\n"),
- routeList);
- GNUNET_free (routeList);
- return NULL;
- }
+ {
+ GNUNET_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)
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Wrong format `%s' for netmask\n"),
- &routeList[slash + 1]);
- else
- {
- errno = save;
- GNUNET_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)
+ {
+ save = errno;
+ if ((1 != SSCANF (&routeList[slash + 1], "%u", &bits)) || (bits >=
128))
{
if (ret == 0)
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Wrong format `%s' for network\n"),
+ _("Wrong format `%s' for netmask\n"),
&routeList[slash + 1]);
else
- GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "inet_pton");
+ {
+ errno = save;
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "inet_pton");
+ }
GNUNET_free (result);
GNUNET_free (routeList);
return NULL;
}
- pos++;
- i++;
+ 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)
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Wrong format `%s' for network\n"),
+ &routeList[slash + 1]);
+ else
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "inet_pton");
+ GNUNET_free (result);
+ GNUNET_free (routeList);
+ return NULL;
+ }
+ pos++;
+ i++;
+ }
GNUNET_free (routeList);
return result;
}
@@ -357,8 +349,7 @@
* @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;
@@ -367,12 +358,12 @@
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;
}
@@ -384,8 +375,7 @@
* @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;
@@ -398,16 +388,16 @@
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;
}
@@ -482,7 +472,7 @@
/**
* Array of the lengths of the entries in addrs.
*/
- socklen_t * addrlens;
+ socklen_t *addrlens;
/**
* NULL-terminated array of listen sockets we should take over.
@@ -541,10 +531,10 @@
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));
@@ -601,9 +591,9 @@
* for unknown address family (will be denied).
*/
static int
-check_access (void *cls,
- const struct GNUNET_CONNECTION_Credentials *uc,
- const struct sockaddr *addr, socklen_t addrlen)
+check_access (void *cls,
+ const struct GNUNET_CONNECTION_Credentials *uc,
+ const struct sockaddr *addr, socklen_t addrlen)
{
struct GNUNET_SERVICE_Context *sctx = cls;
const struct sockaddr_in *i4;
@@ -611,57 +601,54 @@
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)))
+ {
+ 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)))
+ 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;
+ 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
- GNUNET_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:
+ 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
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Unknown address family %d\n"), addr->sa_family);
- return GNUNET_SYSERR;
- }
+ _("Access denied to UID %d / GID %d\n"),
+ (uc == NULL) ? -1 : uc->uid, (uc == NULL) ? -1 : uc->gid);
+ break;
+#endif
+ default:
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Unknown address family %d\n"), addr->sa_family);
+ return GNUNET_SYSERR;
+ }
if (ret != GNUNET_OK)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Access from `%s' denied to service `%s'\n"),
- GNUNET_a2s (addr, addrlen), sctx->serviceName);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Access from `%s' denied to service `%s'\n"),
+ GNUNET_a2s (addr, addrlen), sctx->serviceName);
+ }
return ret;
}
@@ -701,14 +688,14 @@
sctx->serviceName,
option, &opt));
if (NULL == (*ret = parse_ipv4_specification (opt)))
- {
- GNUNET_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_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;
}
@@ -722,6 +709,7 @@
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 ==
@@ -729,14 +717,14 @@
sctx->serviceName,
option, &opt));
if (NULL == (*ret = parse_ipv6_specification (opt)))
- {
- GNUNET_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_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;
}
@@ -751,10 +739,9 @@
*/
static void
add_unixpath (struct sockaddr **saddrs,
- socklen_t *saddrlens,
- const char *unixpath)
+ socklen_t * saddrlens, const char *unixpath)
{
-#ifdef AF_UNIX
+#ifdef AF_UNIX
struct sockaddr_un *un;
size_t slen;
@@ -763,9 +750,7 @@
slen = strlen (unixpath) + 1;
if (slen >= sizeof (un->sun_path))
slen = sizeof (un->sun_path) - 1;
- memcpy (un->sun_path,
- unixpath,
- slen);
+ memcpy (un->sun_path, unixpath, slen);
un->sun_path[slen] = '\0';
slen = sizeof (struct sockaddr_un);
#if LINUX
@@ -774,11 +759,11 @@
#if HAVE_SOCKADDR_IN_SIN_LEN
un->sun_len = (u_char) slen;
#endif
- *saddrs = (struct sockaddr*) un;
+ *saddrs = (struct sockaddr *) un;
*saddrlens = slen;
#else
/* this function should never be called
- unless AF_UNIX is defined! */
+ * unless AF_UNIX is defined! */
GNUNET_assert (0);
#endif
}
@@ -806,9 +791,9 @@
*/
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;
@@ -828,292 +813,282 @@
*addrs = NULL;
*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_CONFIGURATION_have_value (cfg, serviceName, "DISABLEV6"))
+ {
+ 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))
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
- return GNUNET_SYSERR;
- }
- GNUNET_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))
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
+ return GNUNET_SYSERR;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _
+ ("Disabling IPv6 support for service `%s', failed to create
IPv6 socket: %s\n"),
+ serviceName, STRERROR (errno));
+ disablev6 = GNUNET_YES;
}
-
- port = 0;
- if (GNUNET_CONFIGURATION_have_value (cfg,
- serviceName, "PORT"))
+ else
{
- GNUNET_break (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_number (cfg,
- serviceName,
- "PORT",
- &port));
- if (port > 65535)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _
- ("Require valid port number for service `%s' in
configuration!\n"),
- serviceName);
- return GNUNET_SYSERR;
- }
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc));
+ desc = NULL;
}
+ }
- if (GNUNET_CONFIGURATION_have_value (cfg,
- serviceName, "BINDTO"))
+ 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_string (cfg,
- serviceName,
- "BINDTO",
- &hostname));
+ GNUNET_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));
+ }
else
hostname = NULL;
unixpath = NULL;
#ifdef AF_UNIX
if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value (cfg,
- serviceName, "UNIXPATH"))
&&
- (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg,
- serviceName,
- "UNIXPATH",
- &unixpath)) &&
- (0 < strlen(unixpath)))
+ serviceName, "UNIXPATH"))
+ && (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_string (cfg, serviceName, "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;
+ GNUNET_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;
+ }
- if (strlen(unixpath) >= sizeof(s_un.sun_path))
- {
- GNUNET_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))
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
- GNUNET_free_non_null (hostname);
- GNUNET_free (unixpath);
- return GNUNET_SYSERR;
- }
- GNUNET_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;
- }
+ desc = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0);
+ if (NULL == desc)
+ {
+ if ((errno == ENOBUFS) ||
+ (errno == ENOMEM) || (errno == ENFILE) || (errno == EACCES))
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
+ GNUNET_free_non_null (hostname);
+ GNUNET_free (unixpath);
+ return GNUNET_SYSERR;
+ }
+ GNUNET_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) )
+ if ((port == 0) && (unixpath == NULL))
+ {
+ GNUNET_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
+ GNUNET_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))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Have neither PORT nor UNIXPATH for service `%s', but one
is required\n"),
- serviceName);
- GNUNET_free_non_null(hostname);
+ _("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)
+ {
+ GNUNET_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
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Resolving `%s' since that is where `%s' will bind to.\n",
- hostname,
- serviceName);
+ "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))
- {
- GNUNET_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)
- {
- GNUNET_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++;
- saddrs = GNUNET_malloc ((resi+1) * sizeof(struct sockaddr*));
- saddrlens = GNUNET_malloc ((resi+1) * sizeof (socklen_t));
+ 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++;
- }
- 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
- GNUNET_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]);
+ /* 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_in *) saddrs[i])->sin_len = saddrlens[i];
+ ((struct sockaddr_in6 *) saddrs[i])->sin6_len = saddrlens[0];
#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]);
+ ((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_in6 *) saddrs[i])->sin6_len = saddrlens[0];
+ ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[1];
#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]);
-#if HAVE_SOCKADDR_IN_SIN_LEN
- ((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;
@@ -1143,6 +1118,7 @@
{
struct GNUNET_TIME_Relative idleout;
int tolerant;
+
#ifndef MINGW
const char *lpid;
unsigned int pid;
@@ -1151,92 +1127,89 @@
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))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Specified value for `%s' of service `%s' is
invalid\n"),
- "TIMEOUT",
- sctx->serviceName);
- return GNUNET_SYSERR;
- }
- sctx->timeout = idleout;
+ GNUNET_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")))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Specified value for `%s' of service `%s' is
invalid\n"),
- "TOLERANT",
- sctx->serviceName);
- return GNUNET_SYSERR;
- }
+ GNUNET_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;
#ifndef MINGW
errno = 0;
- if ( (NULL != (lpid = getenv ("LISTEN_PID"))) &&
- (1 == sscanf (lpid, "%u", &pid)) &&
- (getpid () == (pid_t) pid) &&
- (NULL != (nfds = getenv ("LISTEN_FDS"))) &&
- (1 == sscanf (nfds, "%u", &cnt)) &&
- (cnt > 0) &&
- (cnt < FD_SETSIZE) &&
- (cnt + 4 < FD_SETSIZE) )
+ if ((NULL != (lpid = getenv ("LISTEN_PID"))) &&
+ (1 == sscanf (lpid, "%u", &pid)) &&
+ (getpid () == (pid_t) pid) &&
+ (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))) )
- {
- GNUNET_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))))
+ {
+ GNUNET_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)) )
+ if ((sctx->lsocks == NULL) &&
+ (GNUNET_SYSERR ==
+ GNUNET_SERVICE_get_server_addresses (sctx->serviceName,
+ sctx->cfg,
+ &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");
+ sctx->serviceName,
+ "UNIX_MATCH_UID");
sctx->match_gid = GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg,
- sctx->serviceName,
- "UNIX_MATCH_GID");
+ 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");
@@ -1285,30 +1258,30 @@
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))
- {
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "access", rdir);
- GNUNET_free (rdir);
- GNUNET_free_non_null (user);
- GNUNET_free (pif);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_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)
- {
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "fopen", pif);
- GNUNET_free (pif);
- GNUNET_free_non_null (user);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_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))
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "fprintf", pif);
GNUNET_break (0 == fclose (pidfd));
@@ -1347,39 +1320,40 @@
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);
+ 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);
+ 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)
- {
- GNUNET_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)
+ {
+ GNUNET_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;
@@ -1387,24 +1361,24 @@
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)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Service `%s' runs at %s\n"),
- sctx->serviceName,
- GNUNET_a2s (sctx->addrs[i], sctx->addrlens[i]));
- i++;
- }
+ GNUNET_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);
}
@@ -1421,46 +1395,45 @@
int filedes[2];
if (0 != PIPE (filedes))
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "pipe");
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "pipe");
+ return GNUNET_SYSERR;
+ }
pid = fork ();
if (pid < 0)
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "fork");
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "fork");
+ return GNUNET_SYSERR;
+ }
if (pid != 0)
- {
- /* Parent */
- char c;
+ {
+ /* Parent */
+ char c;
- GNUNET_break (0 == CLOSE (filedes[1]));
- c = 'X';
- if (1 != READ (filedes[0], &c, sizeof (char)))
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "read");
- fflush (stdout);
- switch (c)
- {
- case '.':
- exit (0);
- case 'I':
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Service process failed to initialize\n"));
- break;
- case 'S':
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _
- ("Service process could not initialize server
function\n"));
- break;
- case 'X':
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Service process failed to report status\n"));
- break;
- }
- exit (1); /* child reported error */
+ GNUNET_break (0 == CLOSE (filedes[1]));
+ c = 'X';
+ if (1 != READ (filedes[0], &c, sizeof (char)))
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "read");
+ fflush (stdout);
+ switch (c)
+ {
+ case '.':
+ exit (0);
+ case 'I':
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Service process failed to initialize\n"));
+ break;
+ case 'S':
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Service process could not initialize server function\n"));
+ break;
+ case 'X':
+ GNUNET_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]));
@@ -1469,11 +1442,11 @@
return GNUNET_SYSERR;
/* set stdin/stdout to /dev/null */
if ((dup2 (nullfd, 0) < 0) || (dup2 (nullfd, 1) < 0))
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "dup2");
- (void) CLOSE (nullfd);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "dup2");
+ (void) CLOSE (nullfd);
+ return GNUNET_SYSERR;
+ }
(void) CLOSE (nullfd);
/* Detach from controlling terminal */
pid = setsid ();
@@ -1482,7 +1455,7 @@
sctx->ready_confirm_fd = filedes[1];
#else
/* FIXME: we probably need to do something else
- elsewhere in order to fork the process itself... */
+ * elsewhere in order to fork the process itself... */
FreeConsole ();
#endif
return GNUNET_OK;
@@ -1505,29 +1478,29 @@
errno = 0;
pws = getpwnam (user);
if (pws == NULL)
- {
- GNUNET_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;
- }
+ {
+ GNUNET_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)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Cannot change user/group to `%s': %s\n"), user,
- STRERROR (errno));
- GNUNET_free (user);
- return GNUNET_SYSERR;
- }
+ GNUNET_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;
@@ -1541,6 +1514,7 @@
pid_file_delete (struct GNUNET_SERVICE_Context *sctx)
{
char *pif = get_pid_file_name (sctx);
+
if (pif == NULL)
return; /* no PID file */
if (0 != UNLINK (pif))
@@ -1582,6 +1556,7 @@
long long clock_offset;
struct GNUNET_SERVICE_Context sctx;
struct GNUNET_CONFIGURATION_Handle *cfg;
+
struct GNUNET_GETOPT_CommandLineOption service_options[] = {
GNUNET_GETOPT_OPTION_CFG_FILE (&cfg_fn),
{'d', "daemonize", NULL,
@@ -1609,7 +1584,7 @@
sctx.cfg = cfg = GNUNET_CONFIGURATION_create ();
/* setup subsystems */
if (GNUNET_SYSERR == GNUNET_GETOPT_run (serviceName, service_options, argc,
- argv))
+ argv))
goto shutdown;
if (GNUNET_OK != GNUNET_log_setup (serviceName, loglev, logfile))
HANDLE_ERROR;
@@ -1617,7 +1592,7 @@
goto shutdown;
if (GNUNET_OK != setup_service (&sctx))
goto shutdown;
- if ( (do_daemonize == 1) && (GNUNET_OK != detach_terminal (&sctx)))
+ if ((do_daemonize == 1) && (GNUNET_OK != detach_terminal (&sctx)))
HANDLE_ERROR;
if (GNUNET_OK != set_user_id (&sctx))
goto shutdown;
@@ -1626,15 +1601,20 @@
"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);
+ 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);
#if DEBUG_SERVICE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Skewing clock by %dll\n",
clock_offset);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Skewing clock by %dll\n",
+ clock_offset);
#endif
- }
+ }
/* actually run service */
GNUNET_SCHEDULER_run (&service_task, &sctx);
@@ -1645,17 +1625,17 @@
shutdown:
if (sctx.ready_confirm_fd != -1)
- {
- if (1 != WRITE (sctx.ready_confirm_fd, err ? "I" : "S", 1))
- GNUNET_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))
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "write");
+ GNUNET_break (0 == CLOSE (sctx.ready_confirm_fd));
+ }
GNUNET_CONFIGURATION_destroy (cfg);
i = 0;
if (sctx.addrs != NULL)
- while (sctx.addrs[i] != NULL)
- GNUNET_free (sctx.addrs[i++]);
+ while (sctx.addrs[i] != NULL)
+ GNUNET_free (sctx.addrs[i++]);
GNUNET_free_non_null (sctx.addrs);
GNUNET_free_non_null (sctx.addrlens);
GNUNET_free_non_null (logfile);
@@ -1694,28 +1674,28 @@
/* 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);
+ 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);
-
+ 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;
@@ -1748,16 +1728,17 @@
GNUNET_SERVICE_stop (struct GNUNET_SERVICE_Context *sctx)
{
unsigned int i;
+
if (NULL != sctx->server)
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);
Modified: gnunet/src/util/signal.c
===================================================================
--- gnunet/src/util/signal.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/signal.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -47,6 +47,7 @@
GNUNET_SIGNAL_handler_install (int signum, GNUNET_SIGNAL_Handler handler)
{
struct GNUNET_SIGNAL_Context *ret;
+
#ifndef MINGW
struct sigaction sig;
#endif
@@ -68,16 +69,15 @@
if (signum == GNUNET_SIGCHLD)
w32_sigchld_handler = handler;
else
+ {
+ __p_sig_fn_t sigret = signal (signum, (__p_sig_fn_t) handler);
+
+ if (sigret == SIG_ERR)
{
- __p_sig_fn_t sigret = signal (signum, (__p_sig_fn_t) handler);
- if (sigret == SIG_ERR)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _
- ("signal (%d, %p) returned %d.\n"),
- signum, handler, sigret);
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("signal (%d, %p) returned %d.\n"), signum, handler,
sigret);
}
+ }
#endif
return ret;
}
Modified: gnunet/src/util/strings.c
===================================================================
--- gnunet/src/util/strings.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/strings.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -55,8 +55,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;
@@ -66,17 +65,18 @@
needed = 0;
va_start (ap, count);
while (count > 0)
+ {
+ s = va_arg (ap, const char *);
+
+ slen = strlen (s) + 1;
+ if (buffer != NULL)
{
- 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--;
+ GNUNET_assert (needed + slen <= size);
+ memcpy (&buffer[needed], s, slen);
}
+ needed += slen;
+ count--;
+ }
va_end (ap);
return needed;
}
@@ -107,20 +107,21 @@
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;
}
@@ -139,25 +140,25 @@
char *ret;
if (size > 5 * 1024)
+ {
+ size = size / 1024;
+ unit = _( /* size unit */ "KiB");
+ if (size > 5 * 1024)
{
size = size / 1024;
- unit = _( /* size unit */ "KiB");
+ unit = _( /* size unit */ "MiB");
if (size > 5 * 1024)
+ {
+ size = size / 1024;
+ unit = _( /* size unit */ "GiB");
+ if (size > 5 * 1024)
{
size = size / 1024;
- unit = _( /* size unit */ "MiB");
- if (size > 5 * 1024)
- {
- size = size / 1024;
- unit = _( /* size unit */ "GiB");
- if (size > 5 * 1024)
- {
- size = size / 1024;
- unit = _( /* size unit */ "TiB");
- }
- }
+ unit = _( /* size unit */ "TiB");
}
+ }
}
+ }
ret = GNUNET_malloc (32);
GNUNET_snprintf (ret, 32, "%llu %s", size, unit);
return ret;
@@ -176,6 +177,7 @@
GNUNET_STRINGS_to_utf8 (const char *input, size_t len, const char *charset)
{
char *ret;
+
#if ENABLE_NLS && HAVE_ICONV
size_t tmpSize;
size_t finSize;
@@ -185,15 +187,15 @@
cd = iconv_open ("UTF-8", charset);
if (cd == (iconv_t) - 1)
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "iconv_open");
- GNUNET_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;
- }
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "iconv_open");
+ GNUNET_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;
@@ -205,15 +207,15 @@
(char **) &input,
#endif
&len, &itmp, &finSize) == SIZE_MAX)
- {
- GNUNET_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;
- }
+ {
+ GNUNET_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';
@@ -241,6 +243,7 @@
GNUNET_STRINGS_filename_expand (const char *fil)
{
char *buffer;
+
#ifndef MINGW
size_t len;
size_t n;
@@ -259,56 +262,56 @@
/* absolute path, just copy */
return GNUNET_strdup (fil);
if (fil[0] == '~')
+ {
+ fm = getenv ("HOME");
+ if (fm == NULL)
{
- fm = getenv ("HOME");
- if (fm == NULL)
- {
- GNUNET_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;
+ GNUNET_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++;
- }
+ /* 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)
- {
- GNUNET_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)
+ {
+ GNUNET_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",
@@ -321,29 +324,28 @@
fn = GNUNET_malloc (MAX_PATH + 1);
if ((lRet = plibc_conv_to_win_path (fil, fn)) != ERROR_SUCCESS)
- {
- SetErrnoFromWinError (lRet);
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
- "plibc_conv_to_win_path");
- return NULL;
- }
+ {
+ SetErrnoFromWinError (lRet);
+ GNUNET_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);
- GNUNET_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);
+ GNUNET_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
@@ -366,25 +368,25 @@
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 */ "h");
+ if (dval > 5 * 24)
{
- 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 / 24;
+ unit = _( /* time unit */ " days");
}
+ }
}
+ }
GNUNET_asprintf (&ret, "%llu %s", dval, unit);
return ret;
}
Modified: gnunet/src/util/test_bio.c
===================================================================
--- gnunet/src/util/test_bio.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/test_bio.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -41,6 +41,7 @@
struct GNUNET_BIO_ReadHandle *fileR;
struct GNUNET_CONTAINER_MetaData *metaDataW;
struct GNUNET_CONTAINER_MetaData *metaDataR;
+
metaDataW = GNUNET_CONTAINER_meta_data_create ();
metaDataR = NULL;
GNUNET_CONTAINER_meta_data_add_publication_date (metaDataW);
@@ -65,8 +66,7 @@
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);
@@ -173,8 +173,8 @@
meta[sizeof (meta) - 1] = '\0';
fileW = GNUNET_BIO_write_open (fileName);
GNUNET_assert (NULL != fileW);
- GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_int32 (fileW, sizeof(meta)));
- GNUNET_assert (GNUNET_OK == GNUNET_BIO_write (fileW, meta, sizeof(meta)));
+ GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_int32 (fileW, sizeof (meta)));
+ GNUNET_assert (GNUNET_OK == GNUNET_BIO_write (fileW, meta, sizeof (meta)));
GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (fileW));
fileR = GNUNET_BIO_read_open (fileName);
@@ -203,7 +203,8 @@
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);
@@ -215,12 +216,12 @@
test_nullfile_rw ()
{
static char fileNameNO[102401];
- struct GNUNET_BIO_WriteHandle *fileWNO;
+ struct GNUNET_BIO_WriteHandle *fileWNO;
struct GNUNET_BIO_ReadHandle *fileRNO;
memset (fileNameNO, 'a', sizeof (fileNameNO));
fileNameNO[sizeof (fileNameNO) - 1] = '\0';
-
+
GNUNET_log_skip (1, GNUNET_NO);
fileWNO = GNUNET_BIO_write_open (fileNameNO);
GNUNET_log_skip (0, GNUNET_YES);
@@ -237,7 +238,7 @@
static int
test_fullfile_rw ()
{
-#ifdef LINUX
+#ifdef LINUX
/* /dev/full only seems to exist on Linux */
char *msg;
int64_t testNum;
@@ -266,7 +267,8 @@
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",
Modified: gnunet/src/util/test_client.c
===================================================================
--- gnunet/src/util/test_client.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/test_client.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -79,8 +79,7 @@
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Receiving message from client, bouncing back\n");
- GNUNET_assert (sizeof (struct GNUNET_MessageHeader) ==
- ntohs (message->size));
+ GNUNET_assert (sizeof (struct GNUNET_MessageHeader) == ntohs
(message->size));
cc = GNUNET_malloc (sizeof (struct CopyContext));
cc->client = client;
cpy = GNUNET_malloc (ntohs (message->size));
@@ -107,12 +106,10 @@
struct GNUNET_MessageHeader msg;
GNUNET_assert (got != NULL); /* timeout */
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Receiving bounce, checking content\n");
+ 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);
@@ -125,6 +122,7 @@
make_msg (void *cls, size_t size, void *buf)
{
struct GNUNET_MessageHeader *msg = buf;
+
GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader));
msg->type = htons (MY_TYPE);
msg->size = htons (sizeof (struct GNUNET_MessageHeader));
@@ -137,10 +135,10 @@
task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct sockaddr_in sa;
- struct sockaddr * sap[2];
+ struct sockaddr *sap[2];
socklen_t slens[2];
- sap[0] = (struct sockaddr*) &sa;
+ sap[0] = (struct sockaddr *) &sa;
slens[0] = sizeof (sa);
sap[1] = NULL;
slens[1] = 0;
@@ -153,7 +151,7 @@
server = GNUNET_SERVER_create (NULL,
NULL,
sap,
- slens,
+ slens,
GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_MILLISECONDS, 10000),
GNUNET_NO);
@@ -187,9 +185,8 @@
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");
ok = 1;
GNUNET_SCHEDULER_run (&task, &ok);
Modified: gnunet/src/util/test_common_allocation.c
===================================================================
--- gnunet/src/util/test_common_allocation.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/util/test_common_allocation.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -38,19 +38,19 @@
/* GNUNET_malloc/GNUNET_free test */
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);
Modified: gnunet/src/util/test_common_logging.c
===================================================================
--- gnunet/src/util/test_common_logging.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/util/test_common_logging.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -31,6 +31,7 @@
const char *component, const char *date, const char *msg)
{
unsigned int *c = ctx;
+
(*c)++;
}
@@ -56,26 +57,23 @@
/* 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)));
+ GNUNET_error_type_to_string
(GNUNET_ERROR_TYPE_ERROR)));
GNUNET_break (0 ==
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)));
+ GNUNET_error_type_to_string (GNUNET_ERROR_TYPE_INFO)));
GNUNET_break (0 ==
strcmp (_("DEBUG"),
- GNUNET_error_type_to_string
- (GNUNET_ERROR_TYPE_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);
@@ -83,16 +81,16 @@
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 */
Modified: gnunet/src/util/test_configuration.c
===================================================================
--- gnunet/src/util/test_configuration.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/util/test_configuration.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -42,7 +42,7 @@
REMOVE_ENTRY,
COMPARE
#if DEBUG
- , PRINT
+ , PRINT
#endif
};
@@ -76,79 +76,80 @@
*/
static void
diffsCallBack (void *cls,
- const char *section, const char *option, const char *value)
+ const char *section, const char *option, 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 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;
+ 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;
- 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 (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;
+ }
#if DEBUG
- 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;
+ }
}
@@ -156,44 +157,45 @@
editConfiguration (struct GNUNET_CONFIGURATION_Handle *cfg, int option)
{
struct DiffsCBData diffsCB;
+
initDiffsCBData (&diffsCB);
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;
}
@@ -218,15 +220,14 @@
/* 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);
@@ -238,16 +239,16 @@
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 DEBUG
@@ -272,65 +273,64 @@
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;
- }
+ "test", "five", &l))
+ {
+ 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);
return 0;
@@ -350,10 +350,10 @@
int *idx = data;
if (0 == strcmp (want[*idx], fn))
- {
- (*idx)++;
- return GNUNET_OK;
- }
+ {
+ (*idx)++;
+ return GNUNET_OK;
+ }
GNUNET_break (0);
return GNUNET_SYSERR;
}
@@ -365,93 +365,90 @@
idx = 0;
if (3 != GNUNET_CONFIGURATION_iterate_value_filenames (cfg,
- "FILENAMES",
- "test",
- &check, &idx))
- {
- GNUNET_break (0);
- return 8;
- }
+ "FILENAMES",
+ "test", &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;
- }
+ "FILENAMES",
+ "test", "/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;
- }
+ "FILENAMES",
+ "test", "/File Name"))
+ {
+ GNUNET_break (0);
+ return 32;
+ }
if (GNUNET_NO !=
GNUNET_CONFIGURATION_remove_value_filename (cfg,
- "FILENAMES",
- "test", "Stuff"))
- {
- GNUNET_break (0);
- return 40;
- }
+ "FILENAMES", "test",
"Stuff"))
+ {
+ GNUNET_break (0);
+ return 40;
+ }
if (GNUNET_NO !=
GNUNET_CONFIGURATION_append_value_filename (cfg,
- "FILENAMES",
- "test", "/Hello"))
- {
- GNUNET_break (0);
- return 48;
- }
+ "FILENAMES",
+ "test", "/Hello"))
+ {
+ GNUNET_break (0);
+ return 48;
+ }
if (GNUNET_NO !=
GNUNET_CONFIGURATION_append_value_filename (cfg,
- "FILENAMES",
- "test", "/World"))
- {
- GNUNET_break (0);
- return 56;
- }
+ "FILENAMES",
+ "test", "/World"))
+ {
+ GNUNET_break (0);
+ return 56;
+ }
if (GNUNET_YES !=
GNUNET_CONFIGURATION_append_value_filename (cfg,
- "FILENAMES",
- "test", "/File 1"))
- {
- GNUNET_break (0);
- return 64;
- }
+ "FILENAMES",
+ "test", "/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;
- }
+ "FILENAMES",
+ "test", "/File 2"))
+ {
+ GNUNET_break (0);
+ return 72;
+ }
idx = 0;
want[1] = "/World";
want[2] = "/File 1";
want[3] = "/File 2";
if (4 != GNUNET_CONFIGURATION_iterate_value_filenames (cfg,
- "FILENAMES",
- "test",
- &check, &idx))
- {
- GNUNET_break (0);
- return 80;
- }
+ "FILENAMES",
+ "test", &check, &idx))
+ {
+ GNUNET_break (0);
+ return 80;
+ }
if (idx != 4)
- {
- GNUNET_break (0);
- return 88;
- }
+ {
+ GNUNET_break (0);
+ return 88;
+ }
return 0;
}
@@ -467,11 +464,11 @@
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;
@@ -481,37 +478,36 @@
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);
@@ -519,11 +515,11 @@
/* 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);
@@ -544,9 +540,9 @@
error:
if (failureCount != 0)
- {
- fprintf (stderr, "Test failed: %u\n", failureCount);
- return 1;
- }
+ {
+ fprintf (stderr, "Test failed: %u\n", failureCount);
+ return 1;
+ }
return 0;
}
Modified: gnunet/src/util/test_connection.c
===================================================================
--- gnunet/src/util/test_connection.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/test_connection.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -66,8 +66,7 @@
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);
@@ -90,25 +89,24 @@
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);
+ }
}
@@ -158,8 +156,7 @@
ls = open_listen_socket ();
lsock = GNUNET_CONNECTION_create_from_existing (ls);
GNUNET_assert (lsock != NULL);
- csock = GNUNET_CONNECTION_create_from_connect (cfg,
- "localhost", PORT);
+ csock = GNUNET_CONNECTION_create_from_connect (cfg, "localhost", PORT);
GNUNET_assert (csock != NULL);
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test asks for write notification\n");
Modified: gnunet/src/util/test_connection_addressing.c
===================================================================
--- gnunet/src/util/test_connection_addressing.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/util/test_connection_addressing.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -66,15 +66,15 @@
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);
- }
+ (const struct sockaddr *) &sa,
+ 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;
}
@@ -92,18 +92,18 @@
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);
+ }
}
@@ -151,6 +151,7 @@
task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct sockaddr_in v4;
+
ls = open_listen_socket ();
lsock = GNUNET_CONNECTION_create_from_existing (ls);
GNUNET_assert (lsock != NULL);
Modified: gnunet/src/util/test_connection_receive_cancel.c
===================================================================
--- gnunet/src/util/test_connection_receive_cancel.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/util/test_connection_receive_cancel.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -65,8 +65,7 @@
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);
@@ -97,8 +96,7 @@
GNUNET_CONNECTION_receive (asock,
1024,
GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS, 5), &dead_receive,
- cls);
+ (GNUNET_TIME_UNIT_SECONDS, 5), &dead_receive,
cls);
}
@@ -106,6 +104,7 @@
receive_cancel_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
int *ok = cls;
+
GNUNET_CONNECTION_receive_cancel (asock);
GNUNET_CONNECTION_destroy (csock, GNUNET_YES);
GNUNET_CONNECTION_destroy (asock, GNUNET_YES);
@@ -120,8 +119,7 @@
ls = open_listen_socket ();
lsock = GNUNET_CONNECTION_create_from_existing (ls);
GNUNET_assert (lsock != NULL);
- csock = GNUNET_CONNECTION_create_from_connect (cfg,
- "localhost", PORT);
+ 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);
Modified: gnunet/src/util/test_connection_timeout.c
===================================================================
--- gnunet/src/util/test_connection_timeout.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/util/test_connection_timeout.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -62,8 +62,7 @@
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);
@@ -76,17 +75,18 @@
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
@@ -109,8 +109,7 @@
ls = open_listen_socket ();
lsock = GNUNET_CONNECTION_create_from_existing (ls);
GNUNET_assert (lsock != NULL);
- csock = GNUNET_CONNECTION_create_from_connect (cfg,
- "localhost", PORT);
+ csock = GNUNET_CONNECTION_create_from_connect (cfg, "localhost", PORT);
GNUNET_assert (csock != NULL);
GNUNET_assert (NULL !=
GNUNET_CONNECTION_notify_transmit_ready (csock,
Modified: gnunet/src/util/test_connection_timeout_no_connect.c
===================================================================
--- gnunet/src/util/test_connection_timeout_no_connect.c 2011-08-15
21:40:08 UTC (rev 16580)
+++ gnunet/src/util/test_connection_timeout_no_connect.c 2011-08-15
21:46:35 UTC (rev 16581)
@@ -39,6 +39,7 @@
handle_timeout (void *cls, size_t size, void *buf)
{
int *ok = cls;
+
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received timeout signal.\n");
#endif
@@ -53,8 +54,7 @@
static void
task_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- csock = GNUNET_CONNECTION_create_from_connect (cfg,
- "localhost", PORT);
+ csock = GNUNET_CONNECTION_create_from_connect (cfg, "localhost", PORT);
GNUNET_assert (csock != NULL);
GNUNET_assert (NULL !=
GNUNET_CONNECTION_notify_transmit_ready (csock,
Modified: gnunet/src/util/test_connection_transmit_cancel.c
===================================================================
--- gnunet/src/util/test_connection_transmit_cancel.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/util/test_connection_transmit_cancel.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -43,15 +43,13 @@
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;
struct GNUNET_CONNECTION_Handle *csock;
- csock = GNUNET_CONNECTION_create_from_connect (cfg,
- "localhost", PORT);
+ csock = GNUNET_CONNECTION_create_from_connect (cfg, "localhost", PORT);
GNUNET_assert (csock != NULL);
th = GNUNET_CONNECTION_notify_transmit_ready (csock,
12,
Modified: gnunet/src/util/test_container_bloomfilter.c
===================================================================
--- gnunet/src/util/test_container_bloomfilter.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/util/test_container_bloomfilter.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -75,30 +75,29 @@
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 @@
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 @@
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);
Modified: gnunet/src/util/test_container_heap.c
===================================================================
--- gnunet/src/util/test_container_heap.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/util/test_container_heap.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -30,20 +30,18 @@
static int
iterator_callback (void *cls,
- struct GNUNET_CONTAINER_HeapNode *node,
- void *element,
- GNUNET_CONTAINER_HeapCostType cost)
+ struct GNUNET_CONTAINER_HeapNode *node,
+ void *element, GNUNET_CONTAINER_HeapCostType cost)
{
return GNUNET_OK;
}
static int
-nstrcmp (const char *a,
- const char *b)
+nstrcmp (const char *a, const char *b)
{
GNUNET_assert (a != NULL);
GNUNET_assert (b != NULL);
- return strcmp (a,b);
+ return strcmp (a, b);
}
static int
@@ -61,47 +59,46 @@
const char *r;
myHeap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
-
+
// GNUNET_CONTAINER_heap_remove_root heap empty, taking if-branch
n1 = GNUNET_CONTAINER_heap_remove_root (myHeap);
GNUNET_assert (NULL == n1);
-
+
// GNUNET_CONTAINER_heap_peek heap empty, taking if-branch
n1 = GNUNET_CONTAINER_heap_peek (myHeap);
- GNUNET_assert (NULL == n1);
-
+ GNUNET_assert (NULL == n1);
+
// GNUNET_CONTAINER_heap_walk_get_next: heap empty, taking if-branch
n1 = GNUNET_CONTAINER_heap_walk_get_next (myHeap);
- GNUNET_assert (NULL == n1);
-
+ GNUNET_assert (NULL == n1);
+
n1 = GNUNET_CONTAINER_heap_insert (myHeap, "11", 11);
GNUNET_assert (NULL != n1);
-
+
// GNUNET_CONTAINER_heap_peek not empty, taking if-branch
n2 = NULL;
n2 = GNUNET_CONTAINER_heap_peek (myHeap);
GNUNET_assert (NULL != n2);
-
+
// GNUNET_CONTAINER_heap_walk_get_next: 1 element
n1 = NULL;
- n1 = GNUNET_CONTAINER_heap_walk_get_next(myHeap);
+ n1 = GNUNET_CONTAINER_heap_walk_get_next (myHeap);
GNUNET_assert (NULL != n1);
-
+
GNUNET_CONTAINER_heap_iterate (myHeap, &iterator_callback, NULL);
GNUNET_assert (1 == GNUNET_CONTAINER_heap_get_size (myHeap));
n2 = GNUNET_CONTAINER_heap_insert (myHeap, "78", 78);
GNUNET_assert (2 == GNUNET_CONTAINER_heap_get_size (myHeap));
- GNUNET_assert (0 == strcmp ("78",
- GNUNET_CONTAINER_heap_remove_node (n2)));
+ GNUNET_assert (0 == strcmp ("78", GNUNET_CONTAINER_heap_remove_node (n2)));
GNUNET_assert (1 == GNUNET_CONTAINER_heap_get_size (myHeap));
GNUNET_CONTAINER_heap_iterate (myHeap, &iterator_callback, NULL);
-
+
n3 = GNUNET_CONTAINER_heap_insert (myHeap, "15", 5);
GNUNET_CONTAINER_heap_update_cost (myHeap, n3, 15);
GNUNET_assert (2 == GNUNET_CONTAINER_heap_get_size (myHeap));
GNUNET_CONTAINER_heap_iterate (myHeap, &iterator_callback, NULL);
-
+
n4 = GNUNET_CONTAINER_heap_insert (myHeap, "50", 50);
GNUNET_CONTAINER_heap_update_cost (myHeap, n4, 50);
GNUNET_assert (3 == GNUNET_CONTAINER_heap_get_size (myHeap));
@@ -111,36 +108,34 @@
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_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 */
+ GNUNET_CONTAINER_heap_remove_node (n3);
+ 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 */
+ GNUNET_assert (0 == strcmp ("50", r));
+ 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));
-
+
GNUNET_CONTAINER_heap_destroy (myHeap);
-
+
// My additions to a complete testcase
// Testing a GNUNET_CONTAINER_HEAP_ORDER_MIN
// Testing remove_node
myHeap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
-
+
n1 = GNUNET_CONTAINER_heap_insert (myHeap, "10", 10);
GNUNET_CONTAINER_heap_update_cost (myHeap, n1, 15);
-
+
r = GNUNET_CONTAINER_heap_remove_node (n1);
GNUNET_assert (NULL != r);
GNUNET_assert (0 == strcmp ("10", r));
-
+
n1 = GNUNET_CONTAINER_heap_insert (myHeap, "10", 10);
n2 = GNUNET_CONTAINER_heap_insert (myHeap, "20", 10);
@@ -151,134 +146,137 @@
r = GNUNET_CONTAINER_heap_remove_node (n1);
GNUNET_assert (NULL != r);
GNUNET_assert (0 == strcmp ("10", r));
-
- n1 = GNUNET_CONTAINER_heap_insert (myHeap, "10", 10);
+
+ n1 = GNUNET_CONTAINER_heap_insert (myHeap, "10", 10);
n2 = GNUNET_CONTAINER_heap_insert (myHeap, "20", 10);
n3 = GNUNET_CONTAINER_heap_insert (myHeap, "30", 10);
-
+
GNUNET_CONTAINER_heap_remove_node (n2);
- GNUNET_CONTAINER_heap_remove_node (n1);
- r = GNUNET_CONTAINER_heap_remove_root (myHeap);
+ GNUNET_CONTAINER_heap_remove_node (n1);
+ r = GNUNET_CONTAINER_heap_remove_root (myHeap);
GNUNET_assert (NULL != r);
GNUNET_assert (0 == strcmp ("30", r));
-
+
n1 = GNUNET_CONTAINER_heap_insert (myHeap, "10", 10);
n2 = GNUNET_CONTAINER_heap_insert (myHeap, "20", 10);
n3 = GNUNET_CONTAINER_heap_insert (myHeap, "30", 10);
GNUNET_CONTAINER_heap_remove_node (n2);
- GNUNET_CONTAINER_heap_remove_node (n1);
- r = GNUNET_CONTAINER_heap_remove_node ( n3);
+ GNUNET_CONTAINER_heap_remove_node (n1);
+ r = GNUNET_CONTAINER_heap_remove_node (n3);
GNUNET_assert (NULL != r);
GNUNET_assert (0 == strcmp ("30", r));
-
+
n1 = GNUNET_CONTAINER_heap_insert (myHeap, "10", 10);
n2 = GNUNET_CONTAINER_heap_insert (myHeap, "20", 20);
n3 = GNUNET_CONTAINER_heap_insert (myHeap, "30", 30);
-
+
GNUNET_assert (0 == nstrcmp ("20", GNUNET_CONTAINER_heap_remove_node (n2)));
- GNUNET_assert (0 == nstrcmp ("10", GNUNET_CONTAINER_heap_remove_root
(myHeap)));
- GNUNET_assert (0 == nstrcmp ("30", GNUNET_CONTAINER_heap_remove_root
(myHeap)));
-
+ GNUNET_assert (0 ==
+ nstrcmp ("10", GNUNET_CONTAINER_heap_remove_root (myHeap)));
+ GNUNET_assert (0 ==
+ nstrcmp ("30", GNUNET_CONTAINER_heap_remove_root (myHeap)));
+
n1 = GNUNET_CONTAINER_heap_insert (myHeap, "10", 10);
n2 = GNUNET_CONTAINER_heap_insert (myHeap, "20", 20);
- n3 = GNUNET_CONTAINER_heap_insert (myHeap, "30", 30);
+ n3 = GNUNET_CONTAINER_heap_insert (myHeap, "30", 30);
n4 = GNUNET_CONTAINER_heap_insert (myHeap, "40", 40);
n5 = GNUNET_CONTAINER_heap_insert (myHeap, "50", 50);
n6 = GNUNET_CONTAINER_heap_insert (myHeap, "60", 60);
-
+
// Inserting nodes deeper in the tree with lower costs
n7 = GNUNET_CONTAINER_heap_insert (myHeap, "70", 10);
- n8 = GNUNET_CONTAINER_heap_insert (myHeap, "80", 10);
-
+ n8 = GNUNET_CONTAINER_heap_insert (myHeap, "80", 10);
+
GNUNET_assert (0 == nstrcmp ("30", GNUNET_CONTAINER_heap_remove_node (n3)));
-
+
// Cleaning up...
- GNUNET_assert (0 == nstrcmp ("60", GNUNET_CONTAINER_heap_remove_node (n6)));
+ GNUNET_assert (0 == nstrcmp ("60", GNUNET_CONTAINER_heap_remove_node (n6)));
GNUNET_assert (0 == nstrcmp ("50", GNUNET_CONTAINER_heap_remove_node (n5)));
-
+
// Testing heap_walk_get_next
GNUNET_CONTAINER_heap_walk_get_next (myHeap);
GNUNET_CONTAINER_heap_walk_get_next (myHeap);
- GNUNET_CONTAINER_heap_walk_get_next (myHeap);;
+ GNUNET_CONTAINER_heap_walk_get_next (myHeap);;
GNUNET_CONTAINER_heap_walk_get_next (myHeap);
- GNUNET_CONTAINER_heap_walk_get_next (myHeap);
-
+ GNUNET_CONTAINER_heap_walk_get_next (myHeap);
+
GNUNET_assert (0 == nstrcmp ("10", GNUNET_CONTAINER_heap_remove_node (n1)));
- GNUNET_assert (0 == nstrcmp ("20", GNUNET_CONTAINER_heap_remove_node (n2)));
+ GNUNET_assert (0 == nstrcmp ("20", GNUNET_CONTAINER_heap_remove_node (n2)));
GNUNET_assert (0 == nstrcmp ("40", GNUNET_CONTAINER_heap_remove_node (n4)));
- GNUNET_assert (0 == nstrcmp ("70", GNUNET_CONTAINER_heap_remove_node (n7)));
+ GNUNET_assert (0 == nstrcmp ("70", GNUNET_CONTAINER_heap_remove_node (n7)));
GNUNET_assert (0 == nstrcmp ("80", GNUNET_CONTAINER_heap_remove_node (n8)));
-
+
// End Testing remove_node
-
+
// Testing a GNUNET_CONTAINER_HEAP_ORDER_MAX
GNUNET_CONTAINER_heap_destroy (myHeap);
-
- myHeap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MAX);
-
+
+ myHeap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MAX);
+
n1 = GNUNET_CONTAINER_heap_insert (myHeap, "10", 10);
GNUNET_CONTAINER_heap_update_cost (myHeap, n1, 15);
-
+
GNUNET_assert (0 == nstrcmp ("10", GNUNET_CONTAINER_heap_remove_node (n1)));
-
+
n1 = GNUNET_CONTAINER_heap_insert (myHeap, "10", 10);
n2 = GNUNET_CONTAINER_heap_insert (myHeap, "20", 10);
GNUNET_CONTAINER_heap_walk_get_next (myHeap);
GNUNET_assert (0 == nstrcmp ("20", GNUNET_CONTAINER_heap_remove_node (n2)));
- GNUNET_assert (0 == nstrcmp ("10", GNUNET_CONTAINER_heap_remove_node (n1)));
-
- n1 = GNUNET_CONTAINER_heap_insert (myHeap, "10", 10);
+ GNUNET_assert (0 == nstrcmp ("10", GNUNET_CONTAINER_heap_remove_node (n1)));
+
+ n1 = GNUNET_CONTAINER_heap_insert (myHeap, "10", 10);
n2 = GNUNET_CONTAINER_heap_insert (myHeap, "20", 10);
n3 = GNUNET_CONTAINER_heap_insert (myHeap, "30", 10);
-
+
GNUNET_CONTAINER_heap_remove_node (n2);
- GNUNET_CONTAINER_heap_remove_node (n1);
- GNUNET_assert (0 == nstrcmp ("30", GNUNET_CONTAINER_heap_remove_root
(myHeap)));
-
+ GNUNET_CONTAINER_heap_remove_node (n1);
+ GNUNET_assert (0 ==
+ nstrcmp ("30", GNUNET_CONTAINER_heap_remove_root (myHeap)));
+
n1 = GNUNET_CONTAINER_heap_insert (myHeap, "10", 10);
n2 = GNUNET_CONTAINER_heap_insert (myHeap, "20", 10);
n3 = GNUNET_CONTAINER_heap_insert (myHeap, "30", 10);
GNUNET_CONTAINER_heap_remove_node (n2);
- GNUNET_CONTAINER_heap_remove_node (n1);
+ GNUNET_CONTAINER_heap_remove_node (n1);
GNUNET_assert (0 == nstrcmp ("30", GNUNET_CONTAINER_heap_remove_node (n3)));
-
+
n1 = GNUNET_CONTAINER_heap_insert (myHeap, "10", 10);
n2 = GNUNET_CONTAINER_heap_insert (myHeap, "20", 20);
- n3 = GNUNET_CONTAINER_heap_insert (myHeap, "30", 30);
+ n3 = GNUNET_CONTAINER_heap_insert (myHeap, "30", 30);
n4 = GNUNET_CONTAINER_heap_insert (myHeap, "40", 40);
n5 = GNUNET_CONTAINER_heap_insert (myHeap, "50", 50);
n6 = GNUNET_CONTAINER_heap_insert (myHeap, "60", 60);
-
+
// Inserting nodes deeper in the tree with lower costs
n7 = GNUNET_CONTAINER_heap_insert (myHeap, "70", 10);
- n8 = GNUNET_CONTAINER_heap_insert (myHeap, "80", 10);
-
+ n8 = GNUNET_CONTAINER_heap_insert (myHeap, "80", 10);
+
GNUNET_assert (0 == nstrcmp ("30", GNUNET_CONTAINER_heap_remove_node (n3)));
-
+
// Cleaning up...
- GNUNET_assert (0 == nstrcmp ("60", GNUNET_CONTAINER_heap_remove_node (n6)));
+ GNUNET_assert (0 == nstrcmp ("60", GNUNET_CONTAINER_heap_remove_node (n6)));
GNUNET_assert (0 == nstrcmp ("50", GNUNET_CONTAINER_heap_remove_node (n5)));
-
+
// Testing heap_walk_get_next
GNUNET_CONTAINER_heap_walk_get_next (myHeap);
GNUNET_CONTAINER_heap_walk_get_next (myHeap);
- GNUNET_CONTAINER_heap_walk_get_next (myHeap);;
+ GNUNET_CONTAINER_heap_walk_get_next (myHeap);;
GNUNET_CONTAINER_heap_walk_get_next (myHeap);
- GNUNET_CONTAINER_heap_walk_get_next (myHeap);
-
+ GNUNET_CONTAINER_heap_walk_get_next (myHeap);
+
GNUNET_assert (0 == nstrcmp ("10", GNUNET_CONTAINER_heap_remove_node (n1)));
- GNUNET_assert (0 == nstrcmp ("20", GNUNET_CONTAINER_heap_remove_node (n2)));
+ GNUNET_assert (0 == nstrcmp ("20", GNUNET_CONTAINER_heap_remove_node (n2)));
GNUNET_assert (0 == nstrcmp ("40", GNUNET_CONTAINER_heap_remove_node (n4)));
- GNUNET_assert (0 == nstrcmp ("70", GNUNET_CONTAINER_heap_remove_node (n7)));
+ GNUNET_assert (0 == nstrcmp ("70", GNUNET_CONTAINER_heap_remove_node (n7)));
GNUNET_assert (0 == nstrcmp ("80", GNUNET_CONTAINER_heap_remove_node (n8)));
-
+
// End Testing remove_node
-
+
GNUNET_CONTAINER_heap_destroy (myHeap);
-
+
return 0;
}
@@ -287,7 +285,7 @@
main (int argc, char **argv)
{
GNUNET_log_setup ("test-container-heap", "WARNING", NULL);
- return check();
+ return check ();
}
/* end of test_container_heap.c */
Modified: gnunet/src/util/test_container_meta_data.c
===================================================================
--- gnunet/src/util/test_container_meta_data.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/util/test_container_meta_data.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -42,116 +42,89 @@
m = GNUNET_CONTAINER_meta_data_create ();
if (GNUNET_OK !=
GNUNET_CONTAINER_meta_data_insert (m,
- "<test>",
- EXTRACTOR_METATYPE_TITLE,
- EXTRACTOR_METAFORMAT_UTF8,
- "text/plain",
- "TestTitle",
- strlen("TestTitle")+1))
+ "<test>",
+ EXTRACTOR_METATYPE_TITLE,
+ EXTRACTOR_METAFORMAT_UTF8,
+ "text/plain",
+ "TestTitle", strlen ("TestTitle") +
1))
ABORT (m);
if (GNUNET_OK !=
- GNUNET_CONTAINER_meta_data_insert (m,
- "<test>",
- EXTRACTOR_METATYPE_AUTHOR_NAME,
- EXTRACTOR_METAFORMAT_UTF8,
- "text/plain",
- "TestTitle",
- strlen ("TestTitle")+1))
+ GNUNET_CONTAINER_meta_data_insert (m,
+ "<test>",
+ EXTRACTOR_METATYPE_AUTHOR_NAME,
+ EXTRACTOR_METAFORMAT_UTF8,
+ "text/plain",
+ "TestTitle", strlen ("TestTitle") +
1))
ABORT (m);
- if (GNUNET_OK == GNUNET_CONTAINER_meta_data_insert (m,
- "<test>",
- EXTRACTOR_METATYPE_TITLE,
- EXTRACTOR_METAFORMAT_UTF8,
- "text/plain",
- "TestTitle",
- strlen ("TestTitle")+1))
/* dup! */
+ if (GNUNET_OK == GNUNET_CONTAINER_meta_data_insert (m, "<test>",
EXTRACTOR_METATYPE_TITLE, EXTRACTOR_METAFORMAT_UTF8, "text/plain", "TestTitle",
strlen ("TestTitle") + 1)) /* dup! */
ABORT (m);
- if (GNUNET_OK == GNUNET_CONTAINER_meta_data_insert (m,
- "<test>",
-
EXTRACTOR_METATYPE_AUTHOR_NAME,
- EXTRACTOR_METAFORMAT_UTF8,
- "text/plain",
- "TestTitle",
- strlen ("TestTitle")+1))
/* dup! */
+ if (GNUNET_OK == GNUNET_CONTAINER_meta_data_insert (m, "<test>",
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))
+ EXTRACTOR_METATYPE_AUTHOR_NAME,
+ "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))
+ GNUNET_CONTAINER_meta_data_delete (m,
+ EXTRACTOR_METATYPE_TITLE,
+ "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,
- "<test>",
- 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,
+ "<test>",
+ 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);
- size =
- GNUNET_CONTAINER_meta_data_get_serialized_size (m);
+ size = GNUNET_CONTAINER_meta_data_get_serialized_size (m);
sval = NULL;
if (size != GNUNET_CONTAINER_meta_data_serialize (m,
- &sval, size,
+ &sval, size,
GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL))
- {
- GNUNET_free_non_null (sval);
- ABORT (m);
- }
+ {
+ 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);
+ ABORT (m);
GNUNET_CONTAINER_meta_data_destroy (m);
return 0;
}
@@ -167,26 +140,23 @@
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,
- "<test>",
- q % EXTRACTOR_metatype_get_max(),
- EXTRACTOR_METAFORMAT_UTF8,
- "text/plain",
- txt,
- strlen (txt)+1);
- }
- size =
- GNUNET_CONTAINER_meta_data_get_serialized_size (meta);
+ {
+ GNUNET_snprintf (txt, 128, "%u -- %u\n", i, q);
+ GNUNET_CONTAINER_meta_data_insert (meta,
+ "<test>",
+ 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_free (data);
+ ABORT (meta);
+ }
GNUNET_CONTAINER_meta_data_destroy (meta);
GNUNET_free (data);
return 0;
@@ -201,26 +171,25 @@
m = GNUNET_CONTAINER_meta_data_create ();
if (GNUNET_OK !=
- GNUNET_CONTAINER_meta_data_insert (m,
- "<test>",
- EXTRACTOR_METATYPE_UNKNOWN,
- EXTRACTOR_METAFORMAT_UTF8,
- "text/plain",
- "link",
- strlen("link")+1))
+ GNUNET_CONTAINER_meta_data_insert (m,
+ "<test>",
+ EXTRACTOR_METATYPE_UNKNOWN,
+ EXTRACTOR_METAFORMAT_UTF8,
+ "text/plain",
+ "link", strlen ("link") + 1))
ABORT (m);
if (GNUNET_OK !=
GNUNET_CONTAINER_meta_data_insert (m,
- "<test>",
- EXTRACTOR_METATYPE_FILENAME,
- EXTRACTOR_METAFORMAT_UTF8,
- "text/plain",
+ "<test>",
+ EXTRACTOR_METATYPE_FILENAME,
+ EXTRACTOR_METAFORMAT_UTF8,
+ "text/plain",
"lib-link.m4",
- strlen ("lib-link.m4")+1))
+ 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);
+ size = 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);
@@ -231,7 +200,7 @@
}
int
-check()
+check ()
{
struct GNUNET_CONTAINER_MetaData *meta;
struct GNUNET_CONTAINER_MetaData *meta2;
@@ -239,126 +208,131 @@
int i = 100;
char txt[128];
char *str;
- unsigned char* thumb;
+ unsigned char *thumb;
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,
- "<test>",
- EXTRACTOR_METATYPE_UNKNOWN,
- EXTRACTOR_METAFORMAT_UTF8,
- "text/plain",
- "TestTitle",
- strlen ("TestTitle")+1);
- GNUNET_CONTAINER_meta_data_insert (meta2,
- "<test>",
- 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,
+ "<test>",
+ EXTRACTOR_METATYPE_UNKNOWN,
+ EXTRACTOR_METAFORMAT_UTF8,
+ "text/plain",
+ "TestTitle", strlen ("TestTitle") + 1);
+ GNUNET_CONTAINER_meta_data_insert (meta2,
+ "<test>",
+ 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);
- }
+ if (GNUNET_YES != GNUNET_CONTAINER_meta_data_test_equal (meta, meta2))
+ {
+ 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_clear (meta2);
+ if (0 != GNUNET_CONTAINER_meta_data_iterate (meta2, NULL, NULL))
+ {
+ 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);
- }
+ if (GNUNET_YES != GNUNET_CONTAINER_meta_data_test_equal (meta, 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);
- }
+ if (GNUNET_NO != GNUNET_CONTAINER_meta_data_test_equal (meta, meta2))
+ {
+ GNUNET_CONTAINER_meta_data_destroy (meta2);
+ ABORT (meta);
+ }
// check meta_data_add_publication_date
- GNUNET_CONTAINER_meta_data_add_publication_date(meta2);
-
+ GNUNET_CONTAINER_meta_data_add_publication_date (meta2);
+
// check meta_data_merge
- 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_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);
+ }
+
// 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);
- }
-
- str = GNUNET_CONTAINER_meta_data_get_by_type (meta,
EXTRACTOR_METATYPE_UNKNOWN);
+ 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);
+ }
+
+ str =
+ 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);
- }
+ 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);
+ }
//check meta_data_get_first_by_types
str = GNUNET_CONTAINER_meta_data_get_first_by_types (meta,
-
EXTRACTOR_METATYPE_UNKNOWN,
- -1);
+
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);
- }
+ if (GNUNET_CONTAINER_meta_data_get_thumbnail (meta, &thumb) != 0)
+ {
+ 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);
+ 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);
- GNUNET_CONTAINER_meta_data_destroy(meta);
- return 0;
+ {
+ GNUNET_CONTAINER_meta_data_destroy (meta2);
+ ABORT (meta);
+ }
+ GNUNET_CONTAINER_meta_data_destroy (meta2);
+ GNUNET_CONTAINER_meta_data_destroy (meta);
+ return 0;
}
@@ -375,8 +349,9 @@
failureCount += testMetaMore (i);
failureCount += testMetaLink ();
- int ret = check();
- if ( ret == 1)
+ int ret = check ();
+
+ if (ret == 1)
return 1;
if (failureCount != 0)
Modified: gnunet/src/util/test_container_multihashmap.c
===================================================================
--- gnunet/src/util/test_container_multihashmap.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/util/test_container_multihashmap.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -52,8 +52,7 @@
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,
@@ -81,10 +80,8 @@
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++)
Modified: gnunet/src/util/test_container_slist.c
===================================================================
--- gnunet/src/util/test_container_slist.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/util/test_container_slist.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -54,21 +54,19 @@
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);
+ {
+ 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));
+ 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 (GNUNET_CONTAINER_slist_count (l) == 200);
i = 198;
@@ -76,30 +74,32 @@
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_CONTAINER_slist_iter_destroy (it);
GNUNET_assert (GNUNET_CONTAINER_slist_count (l) == 100);
i = 99;
- GNUNET_assert (GNUNET_CONTAINER_slist_contains (l, &i, sizeof (i)) ==
GNUNET_NO);
+ GNUNET_assert (GNUNET_CONTAINER_slist_contains (l, &i, sizeof (i)) ==
+ GNUNET_NO);
i = 198;
- GNUNET_assert (GNUNET_CONTAINER_slist_contains (l, &i, sizeof (i)) ==
GNUNET_YES);
+ GNUNET_assert (GNUNET_CONTAINER_slist_contains (l, &i, sizeof (i)) ==
+ GNUNET_YES);
GNUNET_CONTAINER_slist_clear (l);
GNUNET_assert (GNUNET_CONTAINER_slist_count (l) == 0);
@@ -108,18 +108,18 @@
GNUNET_CONTAINER_slist_add (l,
GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
&i, sizeof (i));
- /*check slist_append*/
- GNUNET_CONTAINER_slist_append(l,l);
+ /*check slist_append */
+ GNUNET_CONTAINER_slist_append (l, l);
GNUNET_assert (GNUNET_CONTAINER_slist_count (l) == 200);
GNUNET_CONTAINER_slist_destroy (l);
- /*check slist_add_end*/
+ /*check slist_add_end */
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);
@@ -129,9 +129,7 @@
{
p = GNUNET_CONTAINER_slist_get (it, &s);
- if ((p == NULL) ||
- (i != *(int *) p) ||
- (s != sizeof (i)))
+ if ((p == NULL) || (i != *(int *) p) || (s != sizeof (i)))
{
GNUNET_CONTAINER_slist_iter_destroy (it);
GNUNET_assert (0);
@@ -140,28 +138,28 @@
GNUNET_CONTAINER_slist_iter_destroy (it);
GNUNET_CONTAINER_slist_destroy (l);
- /*check if disp = GNUNET_CONTAINER_SLIST_DISPOSITION_DYNAMIC*/
+ /*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);
GNUNET_assert (p != NULL);
//slist_erase
- GNUNET_assert (GNUNET_CONTAINER_slist_next (it) == GNUNET_YES);
+ GNUNET_assert (GNUNET_CONTAINER_slist_next (it) == GNUNET_YES);
GNUNET_CONTAINER_slist_erase (it);
GNUNET_CONTAINER_slist_iter_destroy (it);
GNUNET_assert (GNUNET_CONTAINER_slist_count (l) == 99);
//slist_clear
- GNUNET_CONTAINER_slist_clear(l);
+ GNUNET_CONTAINER_slist_clear (l);
GNUNET_assert (GNUNET_CONTAINER_slist_count (l) == 0);
GNUNET_CONTAINER_slist_destroy (l);
Modified: gnunet/src/util/test_crypto_aes.c
===================================================================
--- gnunet/src/util/test_crypto_aes.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/test_crypto_aes.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -46,25 +46,25 @@
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);
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;
}
@@ -78,16 +78,16 @@
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
};
@@ -97,16 +97,16 @@
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,
@@ -115,18 +115,18 @@
(const struct
GNUNET_CRYPTO_AesInitializationVector *)
"testtesttesttest", result))
- {
- printf ("Wrong return value from encrypt block.\n");
- ret = 1;
- goto error;
- }
+ {
+ 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);
@@ -137,18 +137,18 @@
(const struct
GNUNET_CRYPTO_AesInitializationVector *)
"testtesttesttest", res))
- {
- printf ("Wrong return value from decrypt block.\n");
- ret = 1;
- goto error;
- }
+ {
+ 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:
@@ -170,10 +170,10 @@
failureCount += verifyCrypto ();
if (failureCount != 0)
- {
- printf ("%d TESTS FAILED!\n", failureCount);
- return -1;
- }
+ {
+ printf ("%d TESTS FAILED!\n", failureCount);
+ return -1;
+ }
return 0;
}
Modified: gnunet/src/util/test_crypto_aes_weak.c
===================================================================
--- gnunet/src/util/test_crypto_aes_weak.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/util/test_crypto_aes_weak.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -38,10 +38,11 @@
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
@@ -56,7 +57,7 @@
memset (&INITVALUE, 42,
sizeof (struct GNUNET_CRYPTO_AesInitializationVector));
/* sorry, this is not a weak key -- I don't have
- any at the moment! */
+ * any at the moment! */
weak_key.key[0] = (char) (0x4c);
weak_key.key[1] = (char) (0x31);
weak_key.key[2] = (char) (0xc6);
@@ -91,30 +92,30 @@
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);
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;
}
@@ -131,43 +132,41 @@
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);
+ 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);
+ 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 (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);
+ 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));
- }
+ 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);
+ gcry_cipher_close (handle);
- }
+ }
return number_of_weak_keys;
}
@@ -180,19 +179,19 @@
GNUNET_log_setup ("test-crypto-aes-weak", "WARNING", NULL);
GNUNET_CRYPTO_random_disable_entropy_gathering ();
if (GENERATE_WEAK_KEYS)
- {
- weak_keys = getWeakKeys ();
+ {
+ 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);
- }
+ 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);
+ }
+ }
if (testWeakKey () != 0)
return -1;
Modified: gnunet/src/util/test_crypto_hash.c
===================================================================
--- gnunet/src/util/test_crypto_hash.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/test_crypto_hash.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -42,10 +42,10 @@
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;
@@ -55,6 +55,7 @@
testEncoding ()
{
int i;
+
for (i = 0; i < 255; i++)
if (0 != test (i))
return 1;
@@ -123,9 +124,8 @@
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));
}
Modified: gnunet/src/util/test_crypto_hkdf.c
===================================================================
--- gnunet/src/util/test_crypto_hkdf.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/test_crypto_hkdf.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -35,239 +35,299 @@
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 };
- unsigned char salt[13] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09,
- 0x0a, 0x0b, 0x0c };
+ 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
+ };
+ unsigned char salt[13] =
+ { 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
};
- unsigned char okm[42] = { 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 };
+ unsigned char okm[42] =
+ { 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
+ };
unsigned char result[44];
int l = 42;
- 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);
- GNUNET_assert (memcmp(result, okm, l) == 0);
- GNUNET_assert (memcmp(result + l, "\0", 2) == 0);
+ 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);
+ GNUNET_assert (memcmp (result, okm, l) == 0);
+ GNUNET_assert (memcmp (result + l, "\0", 2) == 0);
}
void
tc2 ()
{
- unsigned char ikm[80] = { 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,
- 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
- 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45,
- 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f };
- unsigned char salt[80] = { 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,
- 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99,
- 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5,
- 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf };
- unsigned char info[80] = { 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,
- 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
- 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5,
- 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff };
- unsigned char okm[82] = { 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,
- 0x0e, 0x09, 0xda, 0x32, 0x75, 0x60, 0x0c, 0x2f, 0x09, 0xb8, 0x36, 0x77,
- 0x93, 0xa9, 0xac, 0xa3, 0xdb, 0x71, 0xcc, 0x30, 0xc5, 0x81, 0x79, 0xec,
- 0x3e, 0x87, 0xc1, 0x4c, 0x01, 0xd5, 0xc1, 0xf3, 0x43, 0x4f, 0x1d, 0x87 };
+ unsigned char ikm[80] =
+ { 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,
+ 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
+ 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45,
+ 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f
+ };
+ unsigned char salt[80] =
+ { 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,
+ 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99,
+ 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5,
+ 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf
+ };
+ unsigned char info[80] =
+ { 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,
+ 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
+ 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5,
+ 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
+ };
+ unsigned char okm[82] =
+ { 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,
+ 0x0e, 0x09, 0xda, 0x32, 0x75, 0x60, 0x0c, 0x2f, 0x09, 0xb8, 0x36, 0x77,
+ 0x93, 0xa9, 0xac, 0xa3, 0xdb, 0x71, 0xcc, 0x30, 0xc5, 0x81, 0x79, 0xec,
+ 0x3e, 0x87, 0xc1, 0x4c, 0x01, 0xd5, 0xc1, 0xf3, 0x43, 0x4f, 0x1d, 0x87
+ };
char result[84];
int l = 82;
- 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);
- GNUNET_assert (memcmp(result, okm, l) == 0);
- GNUNET_assert (memcmp(result + l, "\0", 2) == 0);
+ 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);
+ GNUNET_assert (memcmp (result, okm, l) == 0);
+ GNUNET_assert (memcmp (result + l, "\0", 2) == 0);
}
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 };
- unsigned char okm[42] = { 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 };
+ 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
+ };
+ unsigned char okm[42] =
+ { 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
+ };
unsigned char result[44];
int l = 42;
- 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);
- GNUNET_assert (memcmp(result, okm, l) == 0);
- GNUNET_assert (memcmp(result + l, "\0", 2) == 0);
+ 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);
+ GNUNET_assert (memcmp (result, okm, l) == 0);
+ GNUNET_assert (memcmp (result + l, "\0", 2) == 0);
}
void
tc4 ()
{
- unsigned char ikm[11] = { 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,
- 0x0a, 0x0b, 0x0c };
+ unsigned char ikm[11] =
+ { 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,
+ 0x0a, 0x0b, 0x0c
+ };
unsigned char
info[10] = { 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9
};
- unsigned char okm[42] = { 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 };
+ unsigned char okm[42] =
+ { 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
+ };
char result[84];
int l = 42;
- 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);
- GNUNET_assert (memcmp(result, okm, l) == 0);
- GNUNET_assert (memcmp(result + l, "\0", 2) == 0);
+ 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);
+ GNUNET_assert (memcmp (result, okm, l) == 0);
+ GNUNET_assert (memcmp (result + l, "\0", 2) == 0);
}
void
tc5 ()
{
- unsigned char ikm[80] = { 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,
- 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
- 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45,
- 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f };
- unsigned char salt[80] = { 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,
- 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99,
- 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5,
- 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf };
- unsigned char info[80] = { 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,
- 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
- 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5,
- 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff };
- unsigned char okm[82] = { 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,
- 0x17, 0x3c, 0x48, 0x6e, 0xa3, 0x7c, 0xe3, 0xd3, 0x97, 0xed, 0x03, 0x4c,
- 0x7f, 0x9d, 0xfe, 0xb1, 0x5c, 0x5e, 0x92, 0x73, 0x36, 0xd0, 0x44, 0x1f,
- 0x4c, 0x43, 0x00, 0xe2, 0xcf, 0xf0, 0xd0, 0x90, 0x0b, 0x52, 0xd3, 0xb4 };
+ unsigned char ikm[80] =
+ { 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,
+ 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
+ 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45,
+ 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f
+ };
+ unsigned char salt[80] =
+ { 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,
+ 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99,
+ 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5,
+ 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf
+ };
+ unsigned char info[80] =
+ { 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,
+ 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
+ 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5,
+ 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
+ };
+ unsigned char okm[82] =
+ { 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,
+ 0x17, 0x3c, 0x48, 0x6e, 0xa3, 0x7c, 0xe3, 0xd3, 0x97, 0xed, 0x03, 0x4c,
+ 0x7f, 0x9d, 0xfe, 0xb1, 0x5c, 0x5e, 0x92, 0x73, 0x36, 0xd0, 0x44, 0x1f,
+ 0x4c, 0x43, 0x00, 0xe2, 0xcf, 0xf0, 0xd0, 0x90, 0x0b, 0x52, 0xd3, 0xb4
+ };
char result[84];
int l = 82;
- 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);
- GNUNET_assert (memcmp(result, okm, l) == 0);
- GNUNET_assert (memcmp(result + l, "\0", 2) == 0);
+ 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);
+ GNUNET_assert (memcmp (result, okm, l) == 0);
+ GNUNET_assert (memcmp (result + l, "\0", 2) == 0);
}
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 };
- unsigned char okm[42] = { 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 };
+ 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
+ };
+ unsigned char okm[42] =
+ { 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
+ };
char result[44];
int l = 42;
- 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);
- GNUNET_assert (memcmp(result, okm, l) == 0);
- GNUNET_assert (memcmp(result + l, "\0", 2) == 0);
+ 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);
+ GNUNET_assert (memcmp (result, okm, l) == 0);
+ GNUNET_assert (memcmp (result + l, "\0", 2) == 0);
}
void
tc7 ()
{
- unsigned char ikm[80] = { 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,
- 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
- 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45,
- 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f };
- unsigned char salt[80] = { 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,
- 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99,
- 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5,
- 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf };
+ unsigned char ikm[80] =
+ { 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,
+ 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
+ 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45,
+ 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f
+ };
+ unsigned char salt[80] =
+ { 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,
+ 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99,
+ 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5,
+ 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf
+ };
unsigned char info1[34] = { 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 };
+ 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
+ };
unsigned char info2[46] = { 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9,
- 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5,
- 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1,
- 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd,
- 0xfe, 0xff };
- unsigned char okm[82] = { 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,
- 0x17, 0x3c, 0x48, 0x6e, 0xa3, 0x7c, 0xe3, 0xd3, 0x97, 0xed, 0x03, 0x4c,
- 0x7f, 0x9d, 0xfe, 0xb1, 0x5c, 0x5e, 0x92, 0x73, 0x36, 0xd0, 0x44, 0x1f,
- 0x4c, 0x43, 0x00, 0xe2, 0xcf, 0xf0, 0xd0, 0x90, 0x0b, 0x52, 0xd3, 0xb4 };
+ 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5,
+ 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1,
+ 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd,
+ 0xfe, 0xff
+ };
+ unsigned char okm[82] =
+ { 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,
+ 0x17, 0x3c, 0x48, 0x6e, 0xa3, 0x7c, 0xe3, 0xd3, 0x97, 0xed, 0x03, 0x4c,
+ 0x7f, 0x9d, 0xfe, 0xb1, 0x5c, 0x5e, 0x92, 0x73, 0x36, 0xd0, 0x44, 0x1f,
+ 0x4c, 0x43, 0x00, 0xe2, 0xcf, 0xf0, 0xd0, 0x90, 0x0b, 0x52, 0xd3, 0xb4
+ };
char result[84];
int l = 82;
- 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);
- GNUNET_assert (memcmp(result, okm, l) == 0);
- GNUNET_assert (memcmp(result + l, "\0", 2) == 0);
+ 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);
+ GNUNET_assert (memcmp (result, okm, l) == 0);
+ GNUNET_assert (memcmp (result + l, "\0", 2) == 0);
}
void
tc8 ()
{
- unsigned char ikm[32] = { 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 ikm[32] =
+ { 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,
- 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,
- 0x07, 0xc9, 0xed, 0x6b, 0x18, 0x90, 0x31, 0xab, 0x0f, 0xb5, 0x6b, 0xec,
- 0x9e, 0x45, 0xa2, 0x83, 0x65, 0x41, 0x69, 0x6e, 0x69, 0x74, 0x69, 0x61,
- 0x6c, 0x69, 0x7a, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x76, 0x65, 0x63,
- 0x74, 0x6f, 0x72, 0x00 };
- unsigned char okm[16] = { 0xd6, 0x90, 0xec, 0x9e, 0x62, 0xdf, 0xb9, 0x41,
0xff, 0x92,
- 0x4f, 0xd2, 0xf6, 0x1d, 0x67, 0xe0 };
+ unsigned char info[86] =
+ { 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,
+ 0x07, 0xc9, 0xed, 0x6b, 0x18, 0x90, 0x31, 0xab, 0x0f, 0xb5, 0x6b, 0xec,
+ 0x9e, 0x45, 0xa2, 0x83, 0x65, 0x41, 0x69, 0x6e, 0x69, 0x74, 0x69, 0x61,
+ 0x6c, 0x69, 0x7a, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x76, 0x65, 0x63,
+ 0x74, 0x6f, 0x72, 0x00
+ };
+ unsigned char okm[16] =
+ { 0xd6, 0x90, 0xec, 0x9e, 0x62, 0xdf, 0xb9, 0x41, 0xff, 0x92,
+ 0x4f, 0xd2, 0xf6, 0x1d, 0x67, 0xe0
+ };
char result[18];
int l = 16;
- 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);
- GNUNET_assert (memcmp(result, okm, l) == 0);
- GNUNET_assert (memcmp(result + l, "\0", 2) == 0);
+ 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);
+ GNUNET_assert (memcmp (result, okm, l) == 0);
+ GNUNET_assert (memcmp (result + l, "\0", 2) == 0);
}
int
@@ -276,16 +336,16 @@
GNUNET_log_setup ("test-crypto-hkdf", "WARNING", NULL);
/* Official test vectors */
- tc1();
- tc2();
- tc3();
- tc4();
- tc5();
- tc6();
+ tc1 ();
+ tc2 ();
+ tc3 ();
+ tc4 ();
+ tc5 ();
+ tc6 ();
/* Additional tests */
- tc7();
- tc8();
+ tc7 ();
+ tc8 ();
return 0;
}
Modified: gnunet/src/util/test_crypto_ksk.c
===================================================================
--- gnunet/src/util/test_crypto_ksk.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/test_crypto_ksk.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -38,7 +38,8 @@
static int
testCorrectKey ()
{
- const char *want =
"010601000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b73c215f7a5e6b09bec55713c901786c09324a150980e014bdb0d04426934929c3b4971a9711af5455536cd6eeb8bfa004ee904972a737455f53c752987d8c82b755bc02882b44950c4acdc1672ba74c3b94d81a4c1ea3d74e7700ae5594c3a4f3c559e4bff2df6844fac302e4b66175e14dc8bad3ce44281d2fec1a1abef06301010000";
+ const char *want =
+
"010601000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b73c215f7a5e6b09bec55713c901786c09324a150980e014bdb0d04426934929c3b4971a9711af5455536cd6eeb8bfa004ee904972a737455f53c752987d8c82b755bc02882b44950c4acdc1672ba74c3b94d81a4c1ea3d74e7700ae5594c3a4f3c559e4bff2df6844fac302e4b66175e14dc8bad3ce44281d2fec1a1abef06301010000";
GNUNET_HashCode in;
struct GNUNET_CRYPTO_RsaPrivateKey *hostkey;
struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey;
@@ -49,29 +50,28 @@
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++)
- printf("%02x", ((unsigned char*) &pkey)[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;
}
@@ -90,37 +90,37 @@
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<sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded);i++)
- printf("%02x", ((unsigned char*) &pkey)[i]);
- printf("\n"); */
+ * for (i=0;i<sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded);i++)
+ * printf("%02x", ((unsigned char*) &pkey)[i]);
+ * printf("\n"); */
GNUNET_CRYPTO_rsa_key_free (hostkey);
for (i = 0; i < UNIQUE_ITER; i++)
+ {
+ fprintf (stderr, ".");
+ hostkey = GNUNET_CRYPTO_rsa_key_create_from_hash (&in);
+ if (hostkey == NULL)
{
- fprintf (stderr, ".");
- hostkey = GNUNET_CRYPTO_rsa_key_create_from_hash (&in);
- if (hostkey == NULL)
- {
- GNUNET_break (0);
- fprintf (stderr, " ERROR\n");
- return GNUNET_SYSERR;
- }
- GNUNET_CRYPTO_rsa_key_get_public (hostkey, &pkey1);
- GNUNET_CRYPTO_rsa_key_free (hostkey);
- if (0 !=
- memcmp (&pkey, &pkey1,
- sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)))
- {
- GNUNET_break (0);
- fprintf (stderr, " ERROR\n");
- return GNUNET_SYSERR;
- }
+ GNUNET_break (0);
+ fprintf (stderr, " ERROR\n");
+ return GNUNET_SYSERR;
}
+ GNUNET_CRYPTO_rsa_key_get_public (hostkey, &pkey1);
+ GNUNET_CRYPTO_rsa_key_free (hostkey);
+ if (0 !=
+ memcmp (&pkey, &pkey1,
+ sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)))
+ {
+ GNUNET_break (0);
+ fprintf (stderr, " ERROR\n");
+ return GNUNET_SYSERR;
+ }
+ }
fprintf (stderr, " OK\n");
return GNUNET_OK;
}
@@ -142,32 +142,32 @@
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;
- }
- if (strncmp (TESTSTRING, result, strlen (TESTSTRING)) != 0)
- {
- printf ("%s != %.*s - testEncryptDecrypt failed!\n",
- TESTSTRING, MAX_TESTVAL, result);
- 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, MAX_TESTVAL, result);
+ ok++;
+ continue;
+ }
+ }
printf ("%d RSA encrypt/decrypt operations %llums (%d failures)\n",
ITER,
(unsigned long long)
@@ -194,31 +194,31 @@
purp.size = htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose));
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, ".");
- 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;
- }
+ 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 ("%d RSA sign/verify operations %llums\n",
ITER,
(unsigned long long)
@@ -240,10 +240,10 @@
GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &in);
hostkey = GNUNET_CRYPTO_rsa_key_create_from_hash (&in);
if (hostkey == NULL)
- {
- printf ("\nGNUNET_CRYPTO_rsa_key_create_from_hash failed!\n");
- return 1;
- }
+ {
+ printf ("\nGNUNET_CRYPTO_rsa_key_create_from_hash failed!\n");
+ return 1;
+ }
if (GNUNET_OK != testMultiKey ("foo"))
failureCount++;
if (GNUNET_OK != testMultiKey ("bar"))
@@ -255,9 +255,9 @@
GNUNET_CRYPTO_rsa_key_free (hostkey);
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;
}
Modified: gnunet/src/util/test_crypto_random.c
===================================================================
--- gnunet/src/util/test_crypto_random.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/util/test_crypto_random.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -39,17 +39,17 @@
for (i = 0; i < 1024; i++)
GNUNET_break (1024 > (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... */
Modified: gnunet/src/util/test_crypto_rsa.c
===================================================================
--- gnunet/src/util/test_crypto_rsa.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/test_crypto_rsa.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -54,33 +54,33 @@
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)
@@ -110,17 +110,17 @@
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)
@@ -151,35 +151,35 @@
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_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;
- }
+ 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 ("%d RSA encrypt/decrypt SK operations %llums (%d failures)\n",
ITER,
(unsigned long long)
@@ -210,31 +210,31 @@
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, ".");
- 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;
- }
+ 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 ("%d RSA sign/verify operations %llums\n",
ITER,
(unsigned long long)
@@ -263,15 +263,15 @@
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);
@@ -292,7 +292,7 @@
GNUNET_assert (NULL != key);
GNUNET_CRYPTO_rsa_key_get_public (key, &p1);
GNUNET_CRYPTO_rsa_key_free (key);
- key = GNUNET_CRYPTO_rsa_key_create_from_file (KEYFILE);
+ key = GNUNET_CRYPTO_rsa_key_create_from_file (KEYFILE);
GNUNET_assert (NULL != key);
GNUNET_CRYPTO_rsa_key_get_public (key, &p2);
GNUNET_assert (0 == memcmp (&p1, &p2, sizeof (p1)));
@@ -331,9 +331,9 @@
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 */
Modified: gnunet/src/util/test_disk.c
===================================================================
--- gnunet/src/util/test_disk.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/test_disk.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -46,36 +46,35 @@
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"));
@@ -117,11 +116,11 @@
while ((avail == GNUNET_DISK_get_blocks_available (".testfile")) &&
(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"));
@@ -162,6 +161,7 @@
const char *filename, const char *dirname)
{
int *i = cls;
+
(*i)++;
GNUNET_DISK_directory_iterator_next (di, GNUNET_NO);
}
@@ -210,7 +210,8 @@
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_break (GNUNET_OK ==
+ GNUNET_DISK_directory_remove ("/tmp/test-gnunet-disk-a"));
return ret;
}
@@ -218,12 +219,13 @@
testCanonicalize ()
{
char *fn = GNUNET_strdup ("ab?><|cd*ef:/g\"");
+
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;
}
@@ -275,9 +277,9 @@
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 */
Modified: gnunet/src/util/test_getopt.c
===================================================================
--- gnunet/src/util/test_getopt.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/test_getopt.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -56,21 +56,22 @@
NULL
};
unsigned int vflags = 0;
+
const struct GNUNET_GETOPT_CommandLineOption verboseoptionlist[] = {
GNUNET_GETOPT_OPTION_VERBOSE (&vflags),
GNUNET_GETOPT_OPTION_END
};
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;
}
@@ -88,10 +89,10 @@
};
if (-1 != GNUNET_GETOPT_run ("test_getopt", versionoptionlist, 2, myargv))
- {
- GNUNET_break (0);
- return 1;
- }
+ {
+ GNUNET_break (0);
+ return 1;
+ }
return 0;
}
@@ -109,10 +110,10 @@
};
if (-1 != GNUNET_GETOPT_run ("test_getopt", aboutoptionlist, 2, myargv))
- {
- GNUNET_break (0);
- return 1;
- }
+ {
+ GNUNET_break (0);
+ return 1;
+ }
return 0;
}
@@ -127,6 +128,7 @@
};
char *level = GNUNET_strdup ("stuff");
char *fn = NULL;
+
const struct GNUNET_GETOPT_CommandLineOption logoptionlist[] = {
GNUNET_GETOPT_OPTION_LOGFILE (&fn),
GNUNET_GETOPT_OPTION_LOGLEVEL (&level),
@@ -134,18 +136,18 @@
};
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;
@@ -164,6 +166,7 @@
int flag = 0;
unsigned int num = 0;
unsigned long long lnum = 0;
+
const struct GNUNET_GETOPT_CommandLineOption logoptionlist[] = {
{'f', "--flag", NULL, "helptext", 0, &GNUNET_GETOPT_set_one,
(void *) &flag},
@@ -175,15 +178,15 @@
};
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;
}
Modified: gnunet/src/util/test_os_start_process.c
===================================================================
--- gnunet/src/util/test_os_start_process.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/util/test_os_start_process.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -39,8 +39,10 @@
static int ok;
static struct GNUNET_OS_Process *proc;
+
/* Pipe to write to started processes stdin (on write end) */
static struct GNUNET_DISK_PipeHandle *hello_pipe_stdin;
+
/* Pipe to read from started processes stdout (on read end) */
static struct GNUNET_DISK_PipeHandle *hello_pipe_stdout;
@@ -51,14 +53,14 @@
{
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(hello_pipe_stdout);
- GNUNET_DISK_pipe_close(hello_pipe_stdin);
+ GNUNET_DISK_pipe_close (hello_pipe_stdout);
+ GNUNET_DISK_pipe_close (hello_pipe_stdin);
}
static void
@@ -66,36 +68,39 @@
{
struct GNUNET_DISK_FileHandle *stdout_read_handle = cls;
char buf[16];
- memset(&buf, 0, sizeof(buf));
+
+ memset (&buf, 0, sizeof (buf));
int bytes;
- bytes = GNUNET_DISK_file_read(stdout_read_handle, &buf, sizeof(buf));
+ bytes = GNUNET_DISK_file_read (stdout_read_handle, &buf, sizeof (buf));
+
#if VERBOSE
- fprintf(stderr, "bytes is %d\n", bytes);
+ fprintf (stderr, "bytes is %d\n", bytes);
#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));
+ ok = strncmp (&buf[0], test_phrase, strlen (test_phrase));
#if VERBOSE
- fprintf(stderr, "read %s\n", &buf[0]);
+ 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);
}
@@ -107,47 +112,53 @@
const struct GNUNET_DISK_FileHandle *stdout_read_handle;
const struct GNUNET_DISK_FileHandle *wh;
- GNUNET_asprintf(&fn, "cat");
+ GNUNET_asprintf (&fn, "cat");
hello_pipe_stdin = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO);
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);
+ "test_gnunet_echo_hello", "-", NULL);
GNUNET_free (fn);
/* Close the write end of the read pipe */
- GNUNET_DISK_pipe_close_end(hello_pipe_stdout, GNUNET_DISK_PIPE_END_WRITE);
+ GNUNET_DISK_pipe_close_end (hello_pipe_stdout, GNUNET_DISK_PIPE_END_WRITE);
/* Close the read end of the write pipe */
- GNUNET_DISK_pipe_close_end(hello_pipe_stdin, GNUNET_DISK_PIPE_END_READ);
+ GNUNET_DISK_pipe_close_end (hello_pipe_stdin, GNUNET_DISK_PIPE_END_READ);
wh = GNUNET_DISK_pipe_handle (hello_pipe_stdin, GNUNET_DISK_PIPE_END_WRITE);
/* 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;
- }
+ if (GNUNET_DISK_file_write (wh, test_phrase, strlen (test_phrase) + 1) !=
+ strlen (test_phrase) + 1)
+ {
+ 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);
+ 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);
+ stdout_read_handle =
+ 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);
+ die_task =
+ 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);
}
Modified: gnunet/src/util/test_peer.c
===================================================================
--- gnunet/src/util/test_peer.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/test_peer.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -43,13 +43,13 @@
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 @@
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);
@@ -127,13 +125,14 @@
main ()
{
int i;
+
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;
}
Modified: gnunet/src/util/test_program.c
===================================================================
--- gnunet/src/util/test_program.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/test_program.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -62,6 +62,7 @@
const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
int *ok = cls;
+
GNUNET_assert (setme1 == 1);
GNUNET_assert (0 == strcmp (args[0], "extra"));
GNUNET_assert (args[1] == NULL);
@@ -78,6 +79,7 @@
check ()
{
int ok = 1;
+
char *const argv[] = {
"test_program",
"-c",
Modified: gnunet/src/util/test_pseudonym.c
===================================================================
--- gnunet/src/util/test_pseudonym.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/test_pseudonym.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -48,10 +48,10 @@
&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;
}
@@ -62,25 +62,27 @@
const struct GNUNET_CONTAINER_MetaData *md, int rating)
{
int *ret = cls;
+
(*ret)++;
return GNUNET_OK;
}
static int
fake_noti_callback (void *cls,
- const GNUNET_HashCode *
- pseudonym,
- const struct GNUNET_CONTAINER_MetaData *md, int rating)
+ const GNUNET_HashCode *
+ pseudonym,
+ const struct GNUNET_CONTAINER_MetaData *md, int rating)
{
- int *ret = cls;
- (*ret)++;
- return GNUNET_OK;
+ int *ret = cls;
+
+ (*ret)++;
+ return GNUNET_OK;
}
static int
false_callback (void *cls,
- const GNUNET_HashCode *pseudonym,
- const struct GNUNET_CONTAINER_MetaData *md, int rating)
+ const GNUNET_HashCode * pseudonym,
+ const struct GNUNET_CONTAINER_MetaData *md, int rating)
{
return GNUNET_OK;
}
@@ -102,43 +104,44 @@
char *name2;
char *name3;
char *noname;
- int notiCount,fakenotiCount;
+ int notiCount, fakenotiCount;
int count;
static char m[1024 * 1024 * 10];
- memset (m, 'b', sizeof (m));
- m[sizeof (m) - 1] = '\0';
+ memset (m, 'b', sizeof (m));
+ m[sizeof (m) - 1] = '\0';
+
GNUNET_log_setup ("test-pseudonym", "WARNING", NULL);
ok = GNUNET_YES;
GNUNET_CRYPTO_random_disable_entropy_gathering ();
(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);
- GNUNET_PSEUDONYM_discovery_callback_register (cfg,
- ¬i_callback, ¬iCount);
+ &fake_noti_callback,
+ &fakenotiCount);
+ GNUNET_PSEUDONYM_discovery_callback_register (cfg, ¬i_callback,
+ ¬iCount);
GNUNET_PSEUDONYM_discovery_callback_unregister (&false_callback, &count);
- GNUNET_PSEUDONYM_discovery_callback_unregister (&fake_noti_callback,
&fakenotiCount);
+ GNUNET_PSEUDONYM_discovery_callback_unregister (&fake_noti_callback,
+ &fakenotiCount);
/* ACTUAL TEST CODE */
old = GNUNET_PSEUDONYM_list_all (cfg, NULL, NULL);
meta = GNUNET_CONTAINER_meta_data_create ();
- GNUNET_CONTAINER_meta_data_insert (meta,
- "<test>",
- EXTRACTOR_METATYPE_TITLE,
- EXTRACTOR_METAFORMAT_UTF8,
- "text/plain",
- "test",
- strlen("test")+1);
+ GNUNET_CONTAINER_meta_data_insert (meta,
+ "<test>",
+ EXTRACTOR_METATYPE_TITLE,
+ 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);
@@ -152,13 +155,14 @@
CHECK (notiCount == 3);
newVal = GNUNET_PSEUDONYM_list_all (cfg, &iter, &ok);
CHECK (old < newVal);
- GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_meta_data_insert (meta,
- "<test>",
-
EXTRACTOR_METATYPE_COMMENT,
-
EXTRACTOR_METAFORMAT_UTF8,
- "text/plain",
- m,
- strlen(m)+1));
+ GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_meta_data_insert (meta,
+ "<test>",
+
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);
@@ -167,7 +171,7 @@
name1 = GNUNET_PSEUDONYM_id_to_name (cfg, &id1);
CHECK (name1 != NULL);
CHECK (0 != strcmp (name1, name2));
- CHECK (GNUNET_SYSERR == GNUNET_PSEUDONYM_name_to_id (cfg, "fake",
&rid2));
+ CHECK (GNUNET_SYSERR == GNUNET_PSEUDONYM_name_to_id (cfg, "fake", &rid2));
CHECK (GNUNET_OK == GNUNET_PSEUDONYM_name_to_id (cfg, name2, &rid2));
CHECK (GNUNET_OK == GNUNET_PSEUDONYM_name_to_id (cfg, name1, &rid1));
CHECK (0 == memcmp (&id1, &rid1, sizeof (GNUNET_HashCode)));
@@ -192,7 +196,8 @@
GNUNET_PSEUDONYM_discovery_callback_unregister (¬i_callback, ¬iCount);
GNUNET_CONTAINER_meta_data_destroy (meta);
GNUNET_CONFIGURATION_destroy (cfg);
- GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove
("/tmp/gnunet-pseudonym-test"));
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_DISK_directory_remove ("/tmp/gnunet-pseudonym-test"));
return (ok == GNUNET_YES) ? 0 : 1;
}
Modified: gnunet/src/util/test_resolver_api.c
===================================================================
--- gnunet/src/util/test_resolver_api.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/test_resolver_api.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -41,112 +41,114 @@
#define ROOTSERVER_IP "198.41.0.4"
static void
-check_hostname(void *cls, const struct sockaddr *sa, socklen_t salen)
+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));
}
static void
-check_localhost_num(void *cls, const char *hostname)
+check_localhost_num (void *cls, const char *hostname)
{
int *ok = cls;
+
if (hostname == NULL)
return;
- if (0 == strcmp(hostname, "127.0.0.1"))
- {
+ 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);
+ }
}
static void
-check_localhost(void *cls, const char *hostname)
+check_localhost (void *cls, const char *hostname)
{
int *ok = cls;
+
if (hostname == NULL)
return;
- if (0 == strcmp(hostname, "localhost"))
- {
+ 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
-check_127(void *cls, const struct sockaddr *sa, socklen_t salen)
+check_127 (void *cls, const struct sockaddr *sa, socklen_t salen)
{
int *ok = cls;
const struct sockaddr_in *sai = (const struct sockaddr_in *) sa;
if (sa == NULL)
return;
- GNUNET_assert(sizeof(struct sockaddr_in) == salen);
- if (sai->sin_addr.s_addr == htonl(INADDR_LOOPBACK))
- {
+ 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
-check_local_fqdn(void *cls, const char *gnunet_fqdn)
+check_local_fqdn (void *cls, const char *gnunet_fqdn)
{
int result = 0;
struct hostent *host;
- char hostname[GNUNET_OS_get_hostname_max_length() + 1];
+ 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);
#endif
- host = gethostbyname ( hostname );
- if ( NULL == host)
+ host = gethostbyname (hostname);
+ if (NULL == host)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("Could not resolve our FQDN : %s %u\n"),
@@ -154,144 +156,150 @@
return;
}
- GNUNET_assert( 0 != host);
+ GNUNET_assert (0 != host);
- result = strcmp(host->h_name, gnunet_fqdn);
- if ( 0 != result )
+ 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");
+ "Local resolved and resolver resolved fqdns are not equal\n");
}
- GNUNET_assert( 0 == result);
+ GNUNET_assert (0 == result);
}
static void
-check_rootserver_ip(void *cls, const struct sockaddr *sa, socklen_t salen)
+check_rootserver_ip (void *cls, const struct sockaddr *sa, socklen_t salen)
{
int *ok = cls;
const struct sockaddr_in *sai = (const struct sockaddr_in *) sa;
if (sa == NULL)
return;
- GNUNET_assert(sizeof(struct sockaddr_in) == salen);
+ GNUNET_assert (sizeof (struct sockaddr_in) == salen);
- if (0 == strcmp(inet_ntoa(sai->sin_addr), ROOTSERVER_IP))
- {
+ 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
-check_rootserver_name(void *cls, const char *hostname)
+check_rootserver_name (void *cls, const char *hostname)
{
int *ok = cls;
+
if (hostname == NULL)
return;
- if (0 == strcmp(hostname, ROOTSERVER_NAME))
- {
+ 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
-run(void *cls, char * const *args,
- const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
+run (void *cls, char *const *args,
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
int *ok = cls;
struct sockaddr_in sa;
- struct GNUNET_TIME_Relative timeout = GNUNET_TIME_relative_multiply(
- GNUNET_TIME_UNIT_SECONDS, 30);
+ struct GNUNET_TIME_Relative timeout =
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30);
int count_ips = 0;
- char * own_fqdn;
+ char *own_fqdn;
- memset(&sa, 0, sizeof(sa));
+ memset (&sa, 0, sizeof (sa));
sa.sin_family = AF_INET;
#if HAVE_SOCKADDR_IN_SIN_LEN
sa.sin_len = (u_char) sizeof (sa);
#endif
- sa.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+ sa.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
/*
* Looking up our own fqdn
*/
- own_fqdn = GNUNET_RESOLVER_local_fqdn_get();
- check_local_fqdn( NULL, own_fqdn);
+ own_fqdn = GNUNET_RESOLVER_local_fqdn_get ();
+ check_local_fqdn (NULL, own_fqdn);
GNUNET_free_non_null (own_fqdn);
/*
* Testing non-local DNS resolution
* DNS rootserver to test: a.root-servers.net - 198.41.0.4
*/
- const char * rootserver_name = ROOTSERVER_NAME;
+ const char *rootserver_name = ROOTSERVER_NAME;
struct hostent *rootserver;
- rootserver = gethostbyname(rootserver_name);
+ 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 (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");
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "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);
+ GNUNET_RESOLVER_ip_get (ROOTSERVER_NAME, AF_INET, timeout,
+ &check_rootserver_ip, cls);
/*
* Success: forward lookups work as expected
@@ -299,129 +307,137 @@
*/
struct in_addr rootserver_addr;
+
rootserver->h_name = "";
- if (1 != inet_pton(AF_INET, ROOTSERVER_IP, &rootserver_addr))
- {
+ 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");
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "System's own reverse name resolution is working\n");
#endif
/* Resolve the same using GNUNET */
- memset(&sa, 0, sizeof(sa));
+ memset (&sa, 0, sizeof (sa));
sa.sin_family = AF_INET;
#if HAVE_SOCKADDR_IN_SIN_LEN
sa.sin_len = (u_char) sizeof (sa);
#endif
#ifndef MINGW
- inet_aton(ROOTSERVER_IP, &sa.sin_addr);
+ inet_aton (ROOTSERVER_IP, &sa.sin_addr);
#else
- sa.sin_addr.S_un.S_addr = inet_addr(ROOTSERVER_IP);
+ 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);
+ GNUNET_RESOLVER_hostname_get ((const struct sockaddr *) &sa,
+ sizeof (struct sockaddr), GNUNET_YES, timeout,
+ &check_rootserver_name, cls);
- memset(&sa, 0, sizeof(sa));
+ memset (&sa, 0, sizeof (sa));
sa.sin_family = AF_INET;
#if HAVE_SOCKADDR_IN_SIN_LEN
sa.sin_len = (u_char) sizeof (sa);
#endif
- sa.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+ sa.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
- 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);
+ 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);
- GNUNET_RESOLVER_hostname_get((const struct sockaddr *) &sa,
- sizeof(struct sockaddr), GNUNET_NO, timeout, &check_localhost_num, cls);
- GNUNET_RESOLVER_hostname_resolve(AF_UNSPEC, timeout,
- &check_hostname, cls);
+ GNUNET_RESOLVER_hostname_get ((const struct sockaddr *) &sa,
+ sizeof (struct sockaddr), GNUNET_NO, timeout,
+ &check_localhost_num, cls);
+ GNUNET_RESOLVER_hostname_resolve (AF_UNSPEC, timeout, &check_hostname, cls);
}
static int
-check()
+check ()
{
int ok = 1 + 2 + 4 + 8;
char *fn;
char *pfx;
struct GNUNET_OS_Process *proc;
- char * const argv[] =
- { "test-resolver-api", "-c", "test_resolver_api_data.conf",
+
+ char *const argv[] =
+ { "test-resolver-api", "-c", "test_resolver_api_data.conf",
#if VERBOSE
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- NULL };
+ NULL
+ };
struct GNUNET_GETOPT_CommandLineOption options[] =
- { 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",
+ { 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_free (fn);
+ GNUNET_assert (GNUNET_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;
if (ok != 0)
- fprintf(stderr, "Missed some resolutions: %u\n", ok);
+ fprintf (stderr, "Missed some resolutions: %u\n", ok);
return ok;
}
int
-main(int argc, char *argv[])
+main (int argc, char *argv[])
{
int ret;
- GNUNET_log_setup("test-resolver-api",
+ GNUNET_log_setup ("test-resolver-api",
#if VERBOSE
- "DEBUG",
+ "DEBUG",
#else
- "WARNING",
+ "WARNING",
#endif
- NULL);
- ret = check();
+ NULL);
+ ret = check ();
return ret;
}
Modified: gnunet/src/util/test_scheduler.c
===================================================================
--- gnunet/src/util/test_scheduler.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/test_scheduler.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -33,8 +33,10 @@
task3 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
int *ok = cls;
+
/* t4 should be ready (albeit with lower priority) */
- GNUNET_assert (1 == GNUNET_SCHEDULER_get_load
(GNUNET_SCHEDULER_PRIORITY_COUNT));
+ GNUNET_assert (1 ==
+ GNUNET_SCHEDULER_get_load (GNUNET_SCHEDULER_PRIORITY_COUNT));
GNUNET_assert (3 == *ok);
(*ok) = 4;
}
@@ -44,6 +46,7 @@
task2 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
int *ok = cls;
+
GNUNET_assert (2 == *ok);
(*ok) = 3;
/* t3 will go before t4: higher priority */
@@ -55,6 +58,7 @@
task4 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
int *ok = cls;
+
GNUNET_assert (4 == *ok);
(*ok) = 5;
}
@@ -68,6 +72,7 @@
{
static char c;
int *ok = cls;
+
GNUNET_assert (6 == *ok);
GNUNET_assert (GNUNET_NETWORK_fdset_handle_isset (tc->write_ready, fds[1]));
(*ok) = 7;
@@ -85,6 +90,7 @@
taskLast (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
int *ok = cls;
+
/* t4 should be ready (albeit with lower priority) */
GNUNET_assert (8 == *ok);
(*ok) = 0;
@@ -95,6 +101,7 @@
{
static char c;
int *ok = cls;
+
GNUNET_assert (7 == *ok);
GNUNET_assert (GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, fds[0]));
GNUNET_assert (1 == GNUNET_DISK_file_read (fds[0], &c, 1));
@@ -109,6 +116,7 @@
task5 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
int *ok = cls;
+
GNUNET_assert (5 == *ok);
(*ok) = 6;
p = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO);
@@ -160,6 +168,7 @@
taskShutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
int *ok = cls;
+
GNUNET_assert (1 == *ok);
*ok = 8;
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &taskLast, cls);
@@ -186,6 +195,7 @@
taskSig (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
int *ok = cls;
+
GNUNET_assert (1 == *ok);
*ok = 8;
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &taskLast, cls);
Modified: gnunet/src/util/test_scheduler_delay.c
===================================================================
--- gnunet/src/util/test_scheduler_delay.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/util/test_scheduler_delay.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -57,14 +57,14 @@
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);
Modified: gnunet/src/util/test_server.c
===================================================================
--- gnunet/src/util/test_server.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/test_server.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -49,8 +49,7 @@
static void
-finish_up (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+finish_up (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GNUNET_assert (ok == 6);
ok = 0;
@@ -68,14 +67,12 @@
GNUNET_assert (ok == 5);
ok = 6;
GNUNET_SERVER_receive_done (client, GNUNET_OK);
- GNUNET_SCHEDULER_add_now (&finish_up,
- NULL);
+ GNUNET_SCHEDULER_add_now (&finish_up, NULL);
}
static void
-first_reply_handler (void *cls,
- const struct GNUNET_MessageHeader *msg)
+first_reply_handler (void *cls, const struct GNUNET_MessageHeader *msg)
{
GNUNET_assert (ok == 4);
ok = 5;
@@ -109,8 +106,7 @@
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,
@@ -128,9 +124,7 @@
static size_t
-transmit_second_message (void *cls,
- size_t size,
- void *buf)
+transmit_second_message (void *cls, size_t size, void *buf)
{
struct GNUNET_MessageHeader msg;
@@ -143,10 +137,8 @@
static size_t
-transmit_initial_message (void *cls,
- size_t size,
- void *buf)
-{
+transmit_initial_message (void *cls, size_t size, void *buf)
+{
struct GNUNET_MessageHeader msg;
GNUNET_assert (ok == 1);
@@ -156,12 +148,12 @@
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);
}
@@ -171,10 +163,10 @@
task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct sockaddr_in sa;
- struct sockaddr * sap[2];
+ struct sockaddr *sap[2];
socklen_t slens[2];
- sap[0] = (struct sockaddr*) &sa;
+ sap[0] = (struct sockaddr *) &sa;
slens[0] = sizeof (sa);
sap[1] = NULL;
slens[1] = 0;
@@ -184,28 +176,24 @@
#endif
sa.sin_family = AF_INET;
sa.sin_port = htons (PORT);
- server = GNUNET_SERVER_create (NULL,
- NULL,
- sap,
- slens,
- TIMEOUT,
- GNUNET_NO);
+ server = GNUNET_SERVER_create (NULL, NULL, sap, slens, TIMEOUT, GNUNET_NO);
GNUNET_assert (server != NULL);
GNUNET_SERVER_add_handlers (server, handlers);
cfg = GNUNET_CONFIGURATION_create ();
GNUNET_CONFIGURATION_set_value_number (cfg, "test-server", "PORT", PORT);
- GNUNET_CONFIGURATION_set_value_string (cfg, "test-server", "HOSTNAME",
"localhost");
- GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME",
"localhost");
- cc = GNUNET_CLIENT_connect ("test-server",
- cfg);
+ GNUNET_CONFIGURATION_set_value_string (cfg, "test-server", "HOSTNAME",
+ "localhost");
+ GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME",
+ "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));
}
Modified: gnunet/src/util/test_server_disconnect.c
===================================================================
--- gnunet/src/util/test_server_disconnect.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/util/test_server_disconnect.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -46,8 +46,7 @@
static void
-finish_up (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+finish_up (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GNUNET_assert (ok == 5);
ok = 0;
@@ -64,8 +63,7 @@
return;
GNUNET_assert (ok == 4);
ok = 5;
- GNUNET_SCHEDULER_add_now (&finish_up,
- NULL);
+ GNUNET_SCHEDULER_add_now (&finish_up, NULL);
}
@@ -73,6 +71,7 @@
server_disconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_SERVER_Client *argclient = cls;
+
GNUNET_assert (ok == 3);
ok = 4;
GNUNET_SERVER_client_disconnect (argclient);
@@ -89,8 +88,7 @@
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);
}
@@ -103,10 +101,8 @@
static size_t
-transmit_initial_message (void *cls,
- size_t size,
- void *buf)
-{
+transmit_initial_message (void *cls, size_t size, void *buf)
+{
struct GNUNET_MessageHeader msg;
GNUNET_assert (ok == 1);
@@ -123,10 +119,10 @@
task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct sockaddr_in sa;
- struct sockaddr * sap[2];
+ struct sockaddr *sap[2];
socklen_t slens[2];
- sap[0] = (struct sockaddr*) &sa;
+ sap[0] = (struct sockaddr *) &sa;
slens[0] = sizeof (sa);
sap[1] = NULL;
slens[1] = 0;
@@ -136,29 +132,25 @@
#endif
sa.sin_family = AF_INET;
sa.sin_port = htons (PORT);
- server = GNUNET_SERVER_create (NULL,
- NULL,
- sap,
- slens,
- TIMEOUT,
- GNUNET_NO);
+ server = GNUNET_SERVER_create (NULL, NULL, sap, slens, TIMEOUT, GNUNET_NO);
GNUNET_assert (server != NULL);
GNUNET_SERVER_add_handlers (server, handlers);
GNUNET_SERVER_disconnect_notify (server, ¬ify_disconnect, NULL);
cfg = GNUNET_CONFIGURATION_create ();
GNUNET_CONFIGURATION_set_value_number (cfg, "test-server", "PORT", PORT);
- GNUNET_CONFIGURATION_set_value_string (cfg, "test-server", "HOSTNAME",
"localhost");
- GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME",
"localhost");
- cc = GNUNET_CLIENT_connect ("test-server",
- cfg);
+ GNUNET_CONFIGURATION_set_value_string (cfg, "test-server", "HOSTNAME",
+ "localhost");
+ GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME",
+ "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));
}
Modified: gnunet/src/util/test_server_with_client.c
===================================================================
--- gnunet/src/util/test_server_with_client.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/util/test_server_with_client.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -49,6 +49,7 @@
send_done (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_SERVER_Client *argclient = cls;
+
GNUNET_assert (ok == 3);
ok++;
GNUNET_SERVER_receive_done (argclient, GNUNET_OK);
@@ -66,8 +67,7 @@
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 +81,21 @@
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);
+ }
}
@@ -156,10 +156,10 @@
task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct sockaddr_in sa;
- struct sockaddr * sap[2];
+ struct sockaddr *sap[2];
socklen_t slens[2];
- sap[0] = (struct sockaddr*) &sa;
+ sap[0] = (struct sockaddr *) &sa;
slens[0] = sizeof (sa);
sap[1] = NULL;
slens[1] = 0;
@@ -172,7 +172,7 @@
server = GNUNET_SERVER_create (NULL,
NULL,
sap,
- slens,
+ slens,
GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_MILLISECONDS, 250),
GNUNET_NO);
@@ -182,8 +182,7 @@
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");
client = GNUNET_CLIENT_connect ("test", cfg);
Modified: gnunet/src/util/test_server_with_client_unix.c
===================================================================
--- gnunet/src/util/test_server_with_client_unix.c 2011-08-15 21:40:08 UTC
(rev 16580)
+++ gnunet/src/util/test_server_with_client_unix.c 2011-08-15 21:46:35 UTC
(rev 16581)
@@ -47,6 +47,7 @@
send_done (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_SERVER_Client *argclient = cls;
+
GNUNET_assert (ok == 3);
ok++;
GNUNET_SERVER_receive_done (argclient, GNUNET_OK);
@@ -59,21 +60,21 @@
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);
+ }
}
@@ -134,12 +135,12 @@
task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct sockaddr_un un;
- const char * unixpath = "/tmp/testsock";
+ const char *unixpath = "/tmp/testsock";
size_t slen = strlen (unixpath);
- struct sockaddr * sap[2];
+ struct sockaddr *sap[2];
socklen_t slens[2];
- memset(&un, 0, sizeof(un));
+ memset (&un, 0, sizeof (un));
un.sun_family = AF_UNIX;
memcpy (un.sun_path, unixpath, slen);
un.sun_path[slen] = '\0';
@@ -151,7 +152,7 @@
#endif
- sap[0] = (struct sockaddr*) &un;
+ sap[0] = (struct sockaddr *) &un;
slens[0] = sizeof (un);
sap[1] = NULL;
slens[1] = 0;
@@ -168,8 +169,7 @@
GNUNET_SERVER_disconnect_notify (server, ¬ify_disconnect, cls);
cfg = GNUNET_CONFIGURATION_create ();
- GNUNET_CONFIGURATION_set_value_string (cfg, "test", "UNIXPATH",
- unixpath);
+ GNUNET_CONFIGURATION_set_value_string (cfg, "test", "UNIXPATH", unixpath);
GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME",
"localhost");
Modified: gnunet/src/util/test_service.c
===================================================================
--- gnunet/src/util/test_service.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/test_service.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -76,8 +76,7 @@
}
static void
-do_stop (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GNUNET_SERVICE_stop (sctx);
}
@@ -143,8 +142,7 @@
GNUNET_SERVICE_run (5,
argv,
"test_service",
- GNUNET_SERVICE_OPTION_NONE,
- &runner, &ok));
+ GNUNET_SERVICE_OPTION_NONE, &runner,
&ok));
GNUNET_assert (0 == ok);
return ok;
}
@@ -217,8 +215,8 @@
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);
@@ -245,6 +243,7 @@
GNUNET_GETOPT_OPTION_END
};
int ret = 1;
+
GNUNET_assert (GNUNET_OK ==
GNUNET_PROGRAM_run (5,
argv,
@@ -278,22 +277,22 @@
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;
Modified: gnunet/src/util/test_strings.c
===================================================================
--- gnunet/src/util/test_strings.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/test_strings.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -49,33 +49,26 @@
b = GNUNET_STRINGS_byte_size_fancy (10240LL * 1024LL * 1024LL * 1024LL);
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));
+ b = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_relative_multiply
+ (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));
+ b = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_relative_multiply
+ (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));
+ b = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MILLISECONDS,
+ 7 * 60 * 60 * 1000));
WANT (buf, b);
#ifndef MINGW
hdir = getenv ("HOME");
#else
hdir = getenv ("USERPROFILE");
#endif
- GNUNET_snprintf (buf,
- sizeof (buf),
- "%s%s",
- hdir,
- DIR_SEPARATOR_STR);
+ GNUNET_snprintf (buf, sizeof (buf), "%s%s", hdir, DIR_SEPARATOR_STR);
b = GNUNET_STRINGS_filename_expand ("~");
GNUNET_assert (b != NULL);
WANT (buf, b);
@@ -92,15 +85,15 @@
at.abs_value = 5000;
r = GNUNET_STRINGS_absolute_time_to_string (at);
/* r should be something like "Wed Dec 31 17:00:05 1969"
- where the details of the day and hour depend on the timezone;
- however, the "0:05 19" should always be there; hence: */
+ * 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);
Modified: gnunet/src/util/test_time.c
===================================================================
--- gnunet/src/util/test_time.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/test_time.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -42,6 +42,7 @@
struct GNUNET_TIME_Relative relUnit;
struct GNUNET_TIME_RelativeNBO reln;
unsigned int i;
+
forever = GNUNET_TIME_absolute_get_forever ();
relForever = GNUNET_TIME_relative_get_forever ();
relUnit = GNUNET_TIME_relative_get_unit ();
@@ -59,9 +60,10 @@
rel = GNUNET_TIME_relative_multiply (rel, 2);
GNUNET_log_skip (0, GNUNET_NO);
GNUNET_assert (rel.rel_value == GNUNET_TIME_UNIT_FOREVER_REL.rel_value);
- /*check zero*/
+ /*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_assert (GNUNET_TIME_relative_get_zero ().rel_value ==
+ GNUNET_TIME_relative_multiply (rel, 0).rel_value);
/* test infinity-check for relative to absolute */
GNUNET_log_skip (1, GNUNET_NO);
@@ -69,14 +71,14 @@
GNUNET_assert (last.abs_value == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value);
GNUNET_log_skip (0, GNUNET_YES);
- /*check relative to absolute*/
+ /*check relative to absolute */
rel.rel_value = 0;
GNUNET_assert (GNUNET_TIME_absolute_get ().abs_value ==
- GNUNET_TIME_relative_to_absolute(rel).abs_value);
- /*check forever*/
+ 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);
@@ -106,8 +108,8 @@
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);
+ GNUNET_assert (GNUNET_TIME_absolute_get_difference (zero, forever).rel_value
+ == forever.abs_value);
past.abs_value = now.abs_value - 1000000;
rel = GNUNET_TIME_absolute_get_duration (future);
@@ -125,7 +127,7 @@
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);
@@ -150,77 +152,80 @@
GNUNET_assert (future.abs_value == now.abs_value);
GNUNET_assert (forever.abs_value ==
- GNUNET_TIME_absolute_subtract (forever,
-
GNUNET_TIME_UNIT_MINUTES).abs_value);
- /*check absolute subtract*/
- now.abs_value= 50000;
+ 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_assert (GNUNET_TIME_UNIT_ZERO_ABS.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);
-
+ /*check relative divide */
+ GNUNET_assert (GNUNET_TIME_UNIT_FOREVER_REL.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);
-
- rel = GNUNET_TIME_relative_divide (relUnit,2);
- GNUNET_assert(rel.rel_value == relUnit.rel_value / 2);
-
+ GNUNET_assert (GNUNET_TIME_UNIT_FOREVER_REL.rel_value ==
+ (GNUNET_TIME_relative_divide (rel, 2)).rel_value);
- /* check Return absolute time of 0ms*/
+ rel = GNUNET_TIME_relative_divide (relUnit, 2);
+ GNUNET_assert (rel.rel_value == relUnit.rel_value / 2);
+
+
+ /* check Return absolute time of 0ms */
zero = GNUNET_TIME_absolute_get_zero ();
/* check GNUNET_TIME_calculate_eta */
last.abs_value = GNUNET_TIME_absolute_get ().abs_value - 1024;
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_assert (GNUNET_TIME_absolute_get_zero ().abs_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_assert (GNUNET_TIME_UNIT_ZERO.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);
+ /*check forever */
+ GNUNET_assert (GNUNET_TIME_UNIT_FOREVER_REL.rel_value ==
+ (GNUNET_TIME_calculate_eta (last, 0, 50000)).rel_value);
- /*check relative subtract*/
+ /*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);
- /*check zero*/
- GNUNET_assert(GNUNET_TIME_relative_get_zero ().rel_value ==
- GNUNET_TIME_relative_subtract(rel,relForever).rel_value);
- /*check forever*/
+ GNUNET_assert (1024 ==
+ 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);
+ /*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_assert (GNUNET_TIME_relative_get_forever ().rel_value ==
+ GNUNET_TIME_relative_subtract (rel, relForever).rel_value);
- /*check GNUNET_TIME_relative_min*/
+ /*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_assert (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);
-
- /*check GNUNET_TIME_absolute_min*/
+ GNUNET_assert (rel.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_assert (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);
+ /*check GNUNET_TIME_absolute_max */
+ GNUNET_assert (now.abs_value ==
+ GNUNET_TIME_absolute_max (now, last).abs_value);
return 0;
}
Modified: gnunet/src/util/time.c
===================================================================
--- gnunet/src/util/time.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/time.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -34,7 +34,7 @@
* @param offset the offset to skew the locale time by
*/
void
-GNUNET_TIME_set_offset(long long offset)
+GNUNET_TIME_set_offset (long long offset)
{
timestamp_offset = offset;
}
@@ -53,8 +53,8 @@
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;
}
@@ -66,6 +66,7 @@
GNUNET_TIME_relative_get_zero ()
{
static struct GNUNET_TIME_Relative zero;
+
return zero;
}
@@ -77,6 +78,7 @@
GNUNET_TIME_absolute_get_zero ()
{
static struct GNUNET_TIME_Absolute zero;
+
return zero;
}
@@ -120,14 +122,16 @@
GNUNET_TIME_relative_to_absolute (struct GNUNET_TIME_Relative rel)
{
struct GNUNET_TIME_Absolute ret;
+
if (rel.rel_value == UINT64_MAX)
return GNUNET_TIME_absolute_get_forever ();
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;
}
@@ -208,9 +212,11 @@
GNUNET_TIME_absolute_get_remaining (struct GNUNET_TIME_Absolute future)
{
struct GNUNET_TIME_Relative ret;
+
if (future.abs_value == UINT64_MAX)
return GNUNET_TIME_relative_get_forever ();
struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
+
if (now.abs_value > future.abs_value)
return GNUNET_TIME_relative_get_zero ();
ret.rel_value = future.abs_value - now.abs_value;
@@ -229,6 +235,7 @@
struct GNUNET_TIME_Absolute end)
{
struct GNUNET_TIME_Relative ret;
+
if (end.abs_value == UINT64_MAX)
return GNUNET_TIME_relative_get_forever ();
if (end.abs_value < start.abs_value)
@@ -270,14 +277,13 @@
{
struct GNUNET_TIME_Absolute ret;
- if ((start.abs_value == UINT64_MAX) ||
- (duration.rel_value == UINT64_MAX))
+ 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;
}
@@ -291,15 +297,13 @@
* @param duration some relative time to subtract
* @return ZERO if start <= duration, or FOREVER if start time is FOREVER;
start-duration otherwise
*/
-struct GNUNET_TIME_Absolute
+struct GNUNET_TIME_Absolute
GNUNET_TIME_absolute_subtract (struct
- GNUNET_TIME_Absolute
- start,
- struct
- GNUNET_TIME_Relative
- duration)
+ GNUNET_TIME_Absolute
+ start, struct GNUNET_TIME_Relative duration)
{
struct GNUNET_TIME_Absolute ret;
+
if (start.abs_value <= duration.rel_value)
return GNUNET_TIME_UNIT_ZERO_ABS;
if (start.abs_value == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value)
@@ -319,14 +323,15 @@
unsigned int factor)
{
struct GNUNET_TIME_Relative ret;
+
if (factor == 0)
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;
}
@@ -340,11 +345,12 @@
*/
struct GNUNET_TIME_Relative
GNUNET_TIME_relative_divide (struct GNUNET_TIME_Relative rel,
- unsigned int factor)
+ unsigned int factor)
{
struct GNUNET_TIME_Relative ret;
- if ( (factor == 0) ||
- (rel.rel_value == GNUNET_TIME_UNIT_FOREVER_REL.rel_value) )
+
+ if ((factor == 0) ||
+ (rel.rel_value == GNUNET_TIME_UNIT_FOREVER_REL.rel_value))
return GNUNET_TIME_UNIT_FOREVER_REL;
ret.rel_value = rel.rel_value / (unsigned long long) factor;
return ret;
@@ -397,10 +403,10 @@
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;
}
@@ -415,13 +421,13 @@
*/
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;
if (a2.rel_value >= a1.rel_value)
return GNUNET_TIME_relative_get_zero ();
- if (a1.rel_value == UINT64_MAX)
+ if (a1.rel_value == UINT64_MAX)
return GNUNET_TIME_relative_get_forever ();
ret.rel_value = a1.rel_value - a2.rel_value;
return ret;
@@ -438,6 +444,7 @@
GNUNET_TIME_relative_hton (struct GNUNET_TIME_Relative a)
{
struct GNUNET_TIME_RelativeNBO ret;
+
ret.rel_value__ = GNUNET_htonll (a.rel_value);
return ret;
}
@@ -452,6 +459,7 @@
GNUNET_TIME_relative_ntoh (struct GNUNET_TIME_RelativeNBO a)
{
struct GNUNET_TIME_Relative ret;
+
ret.rel_value = GNUNET_ntohll (a.rel_value__);
return ret;
@@ -467,6 +475,7 @@
GNUNET_TIME_absolute_hton (struct GNUNET_TIME_Absolute a)
{
struct GNUNET_TIME_AbsoluteNBO ret;
+
ret.abs_value__ = GNUNET_htonll (a.abs_value);
return ret;
}
@@ -481,6 +490,7 @@
GNUNET_TIME_absolute_ntoh (struct GNUNET_TIME_AbsoluteNBO a)
{
struct GNUNET_TIME_Absolute ret;
+
ret.abs_value = GNUNET_ntohll (a.abs_value__);
return ret;
@@ -499,9 +509,10 @@
GNUNET_TIME_relative_to_string (struct GNUNET_TIME_Relative time)
{
static char time_string[21];
- memset(time_string, 0, sizeof(time_string));
- sprintf(time_string, "%llu", (unsigned long long) time.rel_value);
+ memset (time_string, 0, sizeof (time_string));
+
+ sprintf (time_string, "%llu", (unsigned long long) time.rel_value);
return (const char *) time_string;
}
Modified: gnunet/src/util/winproc.c
===================================================================
--- gnunet/src/util/winproc.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/util/winproc.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -99,130 +99,130 @@
/* Function to get CPU usage under Win NT */
if (hNTDLL)
- {
- GNNtQuerySystemInformation = (TNtQuerySystemInformation)
+ {
+ 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)
+ {
+ GNOpenSCManager = (TOpenSCManager)
GetProcAddress (hAdvapi, "OpenSCManagerA");
- GNCreateService = (TCreateService)
+ GNCreateService = (TCreateService)
GetProcAddress (hAdvapi, "CreateServiceA");
- GNCloseServiceHandle = (TCloseServiceHandle)
+ GNCloseServiceHandle = (TCloseServiceHandle)
GetProcAddress (hAdvapi, "CloseServiceHandle");
- GNDeleteService = (TDeleteService)
+ GNDeleteService = (TDeleteService)
GetProcAddress (hAdvapi, "DeleteService");
- GNRegisterServiceCtrlHandler = (TRegisterServiceCtrlHandler)
+ GNRegisterServiceCtrlHandler = (TRegisterServiceCtrlHandler)
GetProcAddress (hAdvapi, "RegisterServiceCtrlHandlerA");
- GNSetServiceStatus = (TSetServiceStatus)
+ GNSetServiceStatus = (TSetServiceStatus)
GetProcAddress (hAdvapi, "SetServiceStatus");
- GNStartServiceCtrlDispatcher = (TStartServiceCtrlDispatcher)
+ GNStartServiceCtrlDispatcher = (TStartServiceCtrlDispatcher)
GetProcAddress (hAdvapi, "StartServiceCtrlDispatcherA");
- GNControlService = (TControlService)
+ GNControlService = (TControlService)
GetProcAddress (hAdvapi, "ControlService");
- GNOpenService = (TOpenService) GetProcAddress (hAdvapi, "OpenServiceA");
+ GNOpenService = (TOpenService) GetProcAddress (hAdvapi, "OpenServiceA");
- GNLsaOpenPolicy = (TLsaOpenPolicy)
+ GNLsaOpenPolicy = (TLsaOpenPolicy)
GetProcAddress (hAdvapi, "LsaOpenPolicy");
- GNLsaAddAccountRights = (TLsaAddAccountRights)
+ GNLsaAddAccountRights = (TLsaAddAccountRights)
GetProcAddress (hAdvapi, "LsaAddAccountRights");
- GNLsaRemoveAccountRights = (TLsaRemoveAccountRights)
+ GNLsaRemoveAccountRights = (TLsaRemoveAccountRights)
GetProcAddress (hAdvapi, "LsaRemoveAccountRights");
- GNLsaClose = (TLsaClose) GetProcAddress (hAdvapi, "LsaClose");
- GNLookupAccountName = (TLookupAccountName)
+ GNLsaClose = (TLsaClose) GetProcAddress (hAdvapi, "LsaClose");
+ GNLookupAccountName = (TLookupAccountName)
GetProcAddress (hAdvapi, "LookupAccountNameA");
- GNGetFileSecurity = (TGetFileSecurity)
+ GNGetFileSecurity = (TGetFileSecurity)
GetProcAddress (hAdvapi, "GetFileSecurityA");
- GNInitializeSecurityDescriptor = (TInitializeSecurityDescriptor)
+ GNInitializeSecurityDescriptor = (TInitializeSecurityDescriptor)
GetProcAddress (hAdvapi, "InitializeSecurityDescriptor");
- GNGetSecurityDescriptorDacl = (TGetSecurityDescriptorDacl)
+ GNGetSecurityDescriptorDacl = (TGetSecurityDescriptorDacl)
GetProcAddress (hAdvapi, "GetSecurityDescriptorDacl");
- GNGetAclInformation = (TGetAclInformation)
+ GNGetAclInformation = (TGetAclInformation)
GetProcAddress (hAdvapi, "GetAclInformation");
- GNInitializeAcl = (TInitializeAcl)
+ GNInitializeAcl = (TInitializeAcl)
GetProcAddress (hAdvapi, "InitializeAcl");
- GNGetAce = (TGetAce) GetProcAddress (hAdvapi, "GetAce");
- GNEqualSid = (TEqualSid) GetProcAddress (hAdvapi, "EqualSid");
- GNAddAce = (TAddAce) GetProcAddress (hAdvapi, "AddAce");
- GNAddAccessAllowedAce = (TAddAccessAllowedAce)
+ GNGetAce = (TGetAce) GetProcAddress (hAdvapi, "GetAce");
+ GNEqualSid = (TEqualSid) GetProcAddress (hAdvapi, "EqualSid");
+ GNAddAce = (TAddAce) GetProcAddress (hAdvapi, "AddAce");
+ GNAddAccessAllowedAce = (TAddAccessAllowedAce)
GetProcAddress (hAdvapi, "AddAccessAllowedAce");
- GNSetNamedSecurityInfo = (TSetNamedSecurityInfo)
+ 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)
+ {
+ GNNetUserAdd = (TNetUserAdd) GetProcAddress (hNetapi, "NetUserAdd");
+ GNNetUserSetInfo = (TNetUserSetInfo)
GetProcAddress (hNetapi, "NetUserSetInfo");
- }
+ }
else
- {
- GNNetUserAdd = NULL;
- GNNetUserSetInfo = NULL;
- }
+ {
+ GNNetUserAdd = NULL;
+ GNNetUserSetInfo = NULL;
+ }
return ret;
}
Modified: gnunet/src/vpn/gnunet-daemon-exit.c
===================================================================
--- gnunet/src/vpn/gnunet-daemon-exit.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/vpn/gnunet-daemon-exit.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -132,11 +132,12 @@
struct redirect_service *serv;
struct remote_addr remote;
- struct GNUNET_CONTAINER_HeapNode* heap_node;
+ struct GNUNET_CONTAINER_HeapNode *heap_node;
struct GNUNET_CONTAINER_MultiHashMap *hashmap;
GNUNET_HashCode hash;
- enum { SERVICE, REMOTE } type;
+ enum
+ { SERVICE, REMOTE } type;
/**
* The source-address and -port of this connection
@@ -152,9 +153,9 @@
struct tunnel_notify_queue
{
- struct tunnel_notify_queue* next;
- struct tunnel_notify_queue* prev;
- void* cls;
+ struct tunnel_notify_queue *next;
+ struct tunnel_notify_queue *prev;
+ void *cls;
size_t len;
};
@@ -162,9 +163,10 @@
* Function that frees everything from a hashmap
*/
static int
-free_iterate(void* cls __attribute__((unused)), const GNUNET_HashCode* hash
__attribute__((unused)), void* value)
+free_iterate (void *cls __attribute__ ((unused)), const GNUNET_HashCode * hash
+ __attribute__ ((unused)), void *value)
{
- GNUNET_free(value);
+ GNUNET_free (value);
return GNUNET_YES;
}
@@ -172,46 +174,47 @@
* Function scheduled as very last function, cleans up after us
*/
static void
-cleanup(void* cls __attribute__((unused)), const struct
GNUNET_SCHEDULER_TaskContext* tskctx) {
- GNUNET_assert (0 != (tskctx->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN));
+cleanup (void *cls
+ __attribute__ ((unused)),
+ const struct GNUNET_SCHEDULER_TaskContext *tskctx)
+{
+ GNUNET_assert (0 != (tskctx->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN));
- GNUNET_CONTAINER_multihashmap_iterate(udp_connections,
- free_iterate,
- NULL);
+ GNUNET_CONTAINER_multihashmap_iterate (udp_connections, free_iterate, NULL);
- GNUNET_CONTAINER_multihashmap_iterate(tcp_connections,
- free_iterate,
- NULL);
+ GNUNET_CONTAINER_multihashmap_iterate (tcp_connections, free_iterate, NULL);
- if (mesh_handle != NULL)
- {
- GNUNET_MESH_disconnect(mesh_handle);
- mesh_handle = NULL;
- }
+ if (mesh_handle != NULL)
+ {
+ GNUNET_MESH_disconnect (mesh_handle);
+ mesh_handle = NULL;
+ }
}
static void
-collect_connections(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tc) {
- if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
+collect_connections (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
+ return;
- struct GNUNET_CONTAINER_Heap *heap = cls;
+ struct GNUNET_CONTAINER_Heap *heap = cls;
- struct redirect_state* state = GNUNET_CONTAINER_heap_remove_root(heap);
+ struct redirect_state *state = GNUNET_CONTAINER_heap_remove_root (heap);
- /* This is free()ed memory! */
- state->heap_node = NULL;
+ /* This is free()ed memory! */
+ state->heap_node = NULL;
- /* FIXME! GNUNET_MESH_close_tunnel(state->tunnel); */
+ /* FIXME! GNUNET_MESH_close_tunnel(state->tunnel); */
- GNUNET_CONTAINER_multihashmap_remove(state->hashmap, &state->hash, state);
+ GNUNET_CONTAINER_multihashmap_remove (state->hashmap, &state->hash, state);
- GNUNET_free(state);
+ GNUNET_free (state);
}
static void
-hash_redirect_info(GNUNET_HashCode* hash, struct redirect_info* u_i, size_t
addrlen)
+hash_redirect_info (GNUNET_HashCode * hash, struct redirect_info *u_i,
+ size_t addrlen)
{
/* the gnunet hashmap only uses the first sizeof(unsigned int) of the hash
@@ -219,9 +222,12 @@
* build the hash out of the last bytes of the address and the 2 bytes of
* the port
*/
- memcpy(hash, &u_i->pt, sizeof(u_i->pt));
- memcpy(((unsigned char*)hash)+2, u_i->addr+(addrlen-(sizeof(unsigned int) -
2)), (sizeof(unsigned int) - 2));
- memset(((unsigned char*)hash)+sizeof(unsigned int), 0,
sizeof(GNUNET_HashCode) - sizeof(unsigned int));
+ memcpy (hash, &u_i->pt, sizeof (u_i->pt));
+ memcpy (((unsigned char *) hash) + 2,
+ u_i->addr + (addrlen - (sizeof (unsigned int) - 2)),
+ (sizeof (unsigned int) - 2));
+ memset (((unsigned char *) hash) + sizeof (unsigned int), 0,
+ sizeof (GNUNET_HashCode) - sizeof (unsigned int));
}
/**
@@ -231,37 +237,42 @@
static size_t
send_udp_to_peer_notify_callback (void *cls, size_t size, void *buf)
{
- struct GNUNET_MESH_Tunnel** tunnel = cls;
- GNUNET_MESH_tunnel_set_data(*tunnel, NULL);
- struct GNUNET_MessageHeader *hdr = (struct GNUNET_MessageHeader*)(tunnel +
1);
+ struct GNUNET_MESH_Tunnel **tunnel = cls;
+
+ GNUNET_MESH_tunnel_set_data (*tunnel, NULL);
+ struct GNUNET_MessageHeader *hdr =
+ (struct GNUNET_MessageHeader *) (tunnel + 1);
GNUNET_assert (size >= ntohs (hdr->size));
memcpy (buf, hdr, ntohs (hdr->size));
- size = ntohs(hdr->size);
+ size = ntohs (hdr->size);
- if (NULL != GNUNET_MESH_tunnel_get_head(*tunnel))
- {
- struct tunnel_notify_queue* element =
GNUNET_MESH_tunnel_get_head(*tunnel);
- struct tunnel_notify_queue* head = GNUNET_MESH_tunnel_get_head(*tunnel);
- struct tunnel_notify_queue* tail = GNUNET_MESH_tunnel_get_tail(*tunnel);
+ if (NULL != GNUNET_MESH_tunnel_get_head (*tunnel))
+ {
+ struct tunnel_notify_queue *element = GNUNET_MESH_tunnel_get_head
(*tunnel);
+ struct tunnel_notify_queue *head = GNUNET_MESH_tunnel_get_head (*tunnel);
+ struct tunnel_notify_queue *tail = GNUNET_MESH_tunnel_get_tail (*tunnel);
- GNUNET_CONTAINER_DLL_remove(head, tail, element);
+ GNUNET_CONTAINER_DLL_remove (head, tail, element);
- GNUNET_MESH_tunnel_set_head(*tunnel, head);
- GNUNET_MESH_tunnel_set_tail(*tunnel, tail);
+ GNUNET_MESH_tunnel_set_head (*tunnel, head);
+ GNUNET_MESH_tunnel_set_tail (*tunnel, tail);
- struct GNUNET_MESH_TransmitHandle* th =
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,
-
send_udp_to_peer_notify_callback, element->cls);
- /* save the handle */
- GNUNET_MESH_tunnel_set_data(*tunnel, th);
- GNUNET_free(element);
- }
+ struct GNUNET_MESH_TransmitHandle *th =
+ 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,
+ send_udp_to_peer_notify_callback,
+ element->cls);
+ /* save the handle */
+ GNUNET_MESH_tunnel_set_data (*tunnel, th);
+ GNUNET_free (element);
+ }
+
GNUNET_free (cls);
return size;
@@ -291,10 +302,11 @@
/* get tunnel and service-descriptor from this */
GNUNET_HashCode hash;
- hash_redirect_info(&hash, &u_i, addrlen);
+ hash_redirect_info (&hash, &u_i, addrlen);
+
struct redirect_state *state =
- GNUNET_CONTAINER_multihashmap_get (udp_connections, &hash);
+ GNUNET_CONTAINER_multihashmap_get (udp_connections, &hash);
/* Mark this connection as freshly used */
GNUNET_CONTAINER_heap_update_cost (udp_connections_heap, state->heap_node,
@@ -303,80 +315,92 @@
tunnel = state->tunnel;
if (state->type == SERVICE)
+ {
+ /* check if spt == serv.remote if yes: set spt = serv.myport ("nat") */
+ if (ntohs (udp->spt) == state->serv->remote_port)
{
- /* check if spt == serv.remote if yes: set spt = serv.myport ("nat") */
- if (ntohs (udp->spt) == state->serv->remote_port)
- {
- udp->spt = htons (state->serv->my_port);
- }
- else
- {
- /* otherwise the answer came from a different port (tftp does this)
- * add this new port to the list of all services, so that the packets
- * coming back from the client to this new port will be routed
correctly
- */
- struct redirect_service *serv =
- GNUNET_malloc (sizeof (struct redirect_service));
- memcpy (serv, state->serv, sizeof (struct redirect_service));
- serv->my_port = ntohs (udp->spt);
- serv->remote_port = ntohs (udp->spt);
- uint16_t *desc = alloca (sizeof (GNUNET_HashCode) + 2);
- memcpy ((GNUNET_HashCode *) (desc + 1), &state->desc,
- sizeof (GNUNET_HashCode));
- *desc = ntohs (udp->spt);
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_put (udp_services,
-
(GNUNET_HashCode*)desc, serv,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+ udp->spt = htons (state->serv->my_port);
+ }
+ else
+ {
+ /* otherwise the answer came from a different port (tftp does this)
+ * add this new port to the list of all services, so that the packets
+ * coming back from the client to this new port will be routed correctly
+ */
+ struct redirect_service *serv =
+ GNUNET_malloc (sizeof (struct redirect_service));
+ memcpy (serv, state->serv, sizeof (struct redirect_service));
+ serv->my_port = ntohs (udp->spt);
+ serv->remote_port = ntohs (udp->spt);
+ uint16_t *desc = alloca (sizeof (GNUNET_HashCode) + 2);
- state->serv = serv;
- }
+ memcpy ((GNUNET_HashCode *) (desc + 1), &state->desc,
+ sizeof (GNUNET_HashCode));
+ *desc = ntohs (udp->spt);
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONTAINER_multihashmap_put (udp_services,
+ (GNUNET_HashCode *)
+ desc, serv,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+
+ state->serv = serv;
}
+ }
/* send udp-packet back */
len =
- sizeof (struct GNUNET_MessageHeader) + sizeof (GNUNET_HashCode) +
- ntohs (udp->len);
- struct GNUNET_MESH_Tunnel** ctunnel = GNUNET_malloc (sizeof(struct
GNUNET_MESH_TUNNEL*) + len);
+ sizeof (struct GNUNET_MessageHeader) + sizeof (GNUNET_HashCode) +
+ ntohs (udp->len);
+ struct GNUNET_MESH_Tunnel **ctunnel =
+ GNUNET_malloc (sizeof (struct GNUNET_MESH_TUNNEL *) + len);
*ctunnel = tunnel;
- msg = (struct GNUNET_MessageHeader*)(ctunnel + 1);
+ msg = (struct GNUNET_MessageHeader *) (ctunnel + 1);
msg->size = htons (len);
- msg->type = htons (state->type == SERVICE ?
GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP_BACK :
GNUNET_MESSAGE_TYPE_VPN_REMOTE_UDP_BACK);
+ msg->type =
+ htons (state->type ==
+ SERVICE ? GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP_BACK :
+ GNUNET_MESSAGE_TYPE_VPN_REMOTE_UDP_BACK);
GNUNET_HashCode *desc = (GNUNET_HashCode *) (msg + 1);
+
if (state->type == SERVICE)
memcpy (desc, &state->desc, sizeof (GNUNET_HashCode));
else
memcpy (desc, &state->remote, sizeof (struct remote_addr));
void *_udp = desc + 1;
+
memcpy (_udp, udp, ntohs (udp->len));
- if (NULL == GNUNET_MESH_tunnel_get_data(tunnel))
- {
- /* No notify is pending */
- struct GNUNET_MESH_TransmitHandle* th =
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,
-
send_udp_to_peer_notify_callback, ctunnel);
- /* save the handle */
- GNUNET_MESH_tunnel_set_data(tunnel, th);
- }
+ if (NULL == GNUNET_MESH_tunnel_get_data (tunnel))
+ {
+ /* No notify is pending */
+ struct GNUNET_MESH_TransmitHandle *th =
+ 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,
+ send_udp_to_peer_notify_callback,
+ ctunnel);
+
+ /* save the handle */
+ GNUNET_MESH_tunnel_set_data (tunnel, th);
+ }
else
- {
- struct tunnel_notify_queue* head = GNUNET_MESH_tunnel_get_head(tunnel);
- struct tunnel_notify_queue* tail = GNUNET_MESH_tunnel_get_tail(tunnel);
+ {
+ struct tunnel_notify_queue *head = GNUNET_MESH_tunnel_get_head (tunnel);
+ struct tunnel_notify_queue *tail = GNUNET_MESH_tunnel_get_tail (tunnel);
- struct tunnel_notify_queue* element = GNUNET_malloc(sizeof(struct
tunnel_notify_queue));
- element->cls = ctunnel;
- element->len = len;
+ struct tunnel_notify_queue *element =
+ GNUNET_malloc (sizeof (struct tunnel_notify_queue));
+ element->cls = ctunnel;
+ element->len = len;
- GNUNET_CONTAINER_DLL_insert_tail(head, tail, element);
- GNUNET_MESH_tunnel_set_head(tunnel, head);
- GNUNET_MESH_tunnel_set_tail(tunnel, tail);
- }
+ GNUNET_CONTAINER_DLL_insert_tail (head, tail, element);
+ GNUNET_MESH_tunnel_set_head (tunnel, head);
+ GNUNET_MESH_tunnel_set_tail (tunnel, tail);
+ }
}
/**
@@ -404,16 +428,19 @@
/* get tunnel and service-descriptor from this */
GNUNET_HashCode hash;
- hash_redirect_info(&hash, &u_i, addrlen);
+ hash_redirect_info (&hash, &u_i, addrlen);
+
struct redirect_state *state =
- GNUNET_CONTAINER_multihashmap_get (tcp_connections, &hash);
+ GNUNET_CONTAINER_multihashmap_get (tcp_connections, &hash);
if (state == NULL)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "No mapping for this connection;
hash is %x\n", *((uint32_t*)&hash));
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "No mapping for this connection; hash is %x\n",
+ *((uint32_t *) & hash));
+ return;
+ }
/* Mark this connection as freshly used */
GNUNET_CONTAINER_heap_update_cost (tcp_connections_heap, state->heap_node,
@@ -422,61 +449,72 @@
tunnel = state->tunnel;
if (state->type == SERVICE)
+ {
+ /* check if spt == serv.remote if yes: set spt = serv.myport ("nat") */
+ if (ntohs (tcp->spt) == state->serv->remote_port)
{
- /* check if spt == serv.remote if yes: set spt = serv.myport ("nat") */
- if (ntohs (tcp->spt) == state->serv->remote_port)
- {
- tcp->spt = htons (state->serv->my_port);
- }
- else
- {
- // This is an illegal packet.
- return;
- }
+ tcp->spt = htons (state->serv->my_port);
}
+ else
+ {
+ // This is an illegal packet.
+ return;
+ }
+ }
/* send tcp-packet back */
len =
- sizeof (struct GNUNET_MessageHeader) + sizeof (GNUNET_HashCode) + pktlen;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "len: %d\n", pktlen);
- struct GNUNET_MESH_Tunnel** ctunnel = GNUNET_malloc (sizeof(struct
GNUNET_MESH_TUNNEL*) + len);
+ sizeof (struct GNUNET_MessageHeader) + sizeof (GNUNET_HashCode) + pktlen;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "len: %d\n", pktlen);
+ struct GNUNET_MESH_Tunnel **ctunnel =
+ GNUNET_malloc (sizeof (struct GNUNET_MESH_TUNNEL *) + len);
*ctunnel = tunnel;
- msg = (struct GNUNET_MessageHeader*)(ctunnel + 1);
+ msg = (struct GNUNET_MessageHeader *) (ctunnel + 1);
msg->size = htons (len);
- msg->type = htons (state->type == SERVICE ?
GNUNET_MESSAGE_TYPE_VPN_SERVICE_TCP_BACK :
GNUNET_MESSAGE_TYPE_VPN_REMOTE_TCP_BACK);
+ msg->type =
+ htons (state->type ==
+ SERVICE ? GNUNET_MESSAGE_TYPE_VPN_SERVICE_TCP_BACK :
+ GNUNET_MESSAGE_TYPE_VPN_REMOTE_TCP_BACK);
GNUNET_HashCode *desc = (GNUNET_HashCode *) (msg + 1);
+
if (state->type == SERVICE)
memcpy (desc, &state->desc, sizeof (GNUNET_HashCode));
else
memcpy (desc, &state->remote, sizeof (struct remote_addr));
void *_tcp = desc + 1;
+
memcpy (_tcp, tcp, pktlen);
- if (NULL == GNUNET_MESH_tunnel_get_data(tunnel))
- {
- /* No notify is pending */
- struct GNUNET_MESH_TransmitHandle* th =
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, send_udp_to_peer_notify_callback,
- ctunnel);
- /* save the handle */
- GNUNET_MESH_tunnel_set_data(tunnel, th);
- }
+ if (NULL == GNUNET_MESH_tunnel_get_data (tunnel))
+ {
+ /* No notify is pending */
+ struct GNUNET_MESH_TransmitHandle *th =
+ 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,
+ send_udp_to_peer_notify_callback,
+ ctunnel);
+
+ /* save the handle */
+ GNUNET_MESH_tunnel_set_data (tunnel, th);
+ }
else
- {
- struct tunnel_notify_queue* head = GNUNET_MESH_tunnel_get_head(tunnel);
- struct tunnel_notify_queue* tail = GNUNET_MESH_tunnel_get_tail(tunnel);
+ {
+ struct tunnel_notify_queue *head = GNUNET_MESH_tunnel_get_head (tunnel);
+ struct tunnel_notify_queue *tail = GNUNET_MESH_tunnel_get_tail (tunnel);
- struct tunnel_notify_queue* element = GNUNET_malloc(sizeof(struct
tunnel_notify_queue));
- element->cls = ctunnel;
- element->len = len;
+ struct tunnel_notify_queue *element =
+ GNUNET_malloc (sizeof (struct tunnel_notify_queue));
+ element->cls = ctunnel;
+ element->len = len;
- GNUNET_CONTAINER_DLL_insert_tail(head, tail, element);
- }
+ GNUNET_CONTAINER_DLL_insert_tail (head, tail, element);
+ }
}
@@ -484,8 +522,10 @@
* Receive packets from the helper-process
*/
static void
-message_token (void *cls __attribute__((unused)),
- void *client __attribute__((unused)), const struct
GNUNET_MessageHeader *message)
+message_token (void *cls __attribute__ ((unused)),
+ void *client
+ __attribute__ ((unused)),
+ const struct GNUNET_MessageHeader *message)
{
GNUNET_assert (ntohs (message->type) == GNUNET_MESSAGE_TYPE_VPN_HELPER);
@@ -493,37 +533,40 @@
/* ethertype is ipv6 */
if (ntohs (pkt_tun->tun.type) == 0x86dd)
- {
- struct ip6_pkt *pkt6 = (struct ip6_pkt *) pkt_tun;
- if (0x11 == pkt6->ip6_hdr.nxthdr)
- udp_from_helper (&((struct ip6_udp *) pkt6)->udp_hdr,
- (unsigned char *) &pkt6->ip6_hdr.dadr, 16);
- else if (0x06 == pkt6->ip6_hdr.nxthdr)
- tcp_from_helper (&((struct ip6_tcp *) pkt6)->tcp_hdr,
- (unsigned char *) &pkt6->ip6_hdr.dadr, 16,
- ntohs (pkt6->ip6_hdr.paylgth));
- }
+ {
+ struct ip6_pkt *pkt6 = (struct ip6_pkt *) pkt_tun;
+
+ if (0x11 == pkt6->ip6_hdr.nxthdr)
+ udp_from_helper (&((struct ip6_udp *) pkt6)->udp_hdr,
+ (unsigned char *) &pkt6->ip6_hdr.dadr, 16);
+ else if (0x06 == pkt6->ip6_hdr.nxthdr)
+ tcp_from_helper (&((struct ip6_tcp *) pkt6)->tcp_hdr,
+ (unsigned char *) &pkt6->ip6_hdr.dadr, 16,
+ ntohs (pkt6->ip6_hdr.paylgth));
+ }
else if (ntohs (pkt_tun->tun.type) == 0x0800)
+ {
+ struct ip_pkt *pkt4 = (struct ip_pkt *) pkt_tun;
+ uint32_t tmp = pkt4->ip_hdr.dadr;
+
+ if (0x11 == pkt4->ip_hdr.proto)
+ udp_from_helper (&((struct ip_udp *) pkt4)->udp_hdr,
+ (unsigned char *) &tmp, 4);
+ else if (0x06 == pkt4->ip_hdr.proto)
{
- struct ip_pkt *pkt4 = (struct ip_pkt *) pkt_tun;
- uint32_t tmp = pkt4->ip_hdr.dadr;
- if (0x11 == pkt4->ip_hdr.proto)
- udp_from_helper (&((struct ip_udp *) pkt4)->udp_hdr,
- (unsigned char *) &tmp, 4);
- else if (0x06 == pkt4->ip_hdr.proto)
- {
- size_t pktlen = ntohs(pkt4->ip_hdr.tot_lngth);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "tot: %d\n", pktlen);
- pktlen -= 4*pkt4->ip_hdr.hdr_lngth;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "-hdr: %d\n", pktlen);
- tcp_from_helper (&((struct ip_tcp *) pkt4)->tcp_hdr,
- (unsigned char *) &tmp, 4, pktlen);
- }
+ size_t pktlen = ntohs (pkt4->ip_hdr.tot_lngth);
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tot: %d\n", pktlen);
+ pktlen -= 4 * pkt4->ip_hdr.hdr_lngth;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "-hdr: %d\n", pktlen);
+ tcp_from_helper (&((struct ip_tcp *) pkt4)->tcp_hdr,
+ (unsigned char *) &tmp, 4, pktlen);
}
+ }
else
- {
- return;
- }
+ {
+ return;
+ }
}
/**
@@ -533,18 +576,21 @@
* @param section name of section in config, equal to hostname
*/
static void
-read_service_conf (void *cls __attribute__((unused)), const char *section)
+read_service_conf (void *cls __attribute__ ((unused)), const char *section)
{
- if ((strlen(section) < 8) || (0 != strcmp (".gnunet.", section +
(strlen(section) - 8))))
+ if ((strlen (section) < 8) ||
+ (0 != strcmp (".gnunet.", section + (strlen (section) - 8))))
return;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Parsing dns-name %d %s %s\n",
strlen(section), section, section + (strlen(section) - 8));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Parsing dns-name %d %s %s\n",
+ strlen (section), section, section + (strlen (section) - 8));
char *cpy;
char *redirect;
char *hostname;
char *hostport;
uint16_t *desc = alloca (sizeof (GNUNET_HashCode) + 2);
+
GNUNET_CRYPTO_hash (section, strlen (section) + 1,
(GNUNET_HashCode *) (desc + 1));
@@ -554,96 +600,105 @@
int proto = UDP;
do
+ {
+ if (proto == UDP &&
+ (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (cfg, section, "UDP_REDIRECTS",
+ &cpy)))
+ goto next;
+ else if (proto == TCP &&
+ (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (cfg, section,
+ "TCP_REDIRECTS", &cpy)))
+ goto next;
+
+ for (redirect = strtok (cpy, " "); redirect != NULL; redirect = strtok
+ (NULL, " "))
{
- if (proto == UDP && (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string(cfg, section, "UDP_REDIRECTS", &cpy)))
- goto next;
- else if (proto == TCP && (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string(cfg, section, "TCP_REDIRECTS", &cpy)))
- goto next;
+ if (NULL == (hostname = strstr (redirect, ":")))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Warning: option %s is not formatted correctly!\n",
+ redirect);
+ continue;
+ }
+ hostname[0] = '\0';
+ hostname++;
+ if (NULL == (hostport = strstr (hostname, ":")))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Warning: option %s is not formatted correctly!\n",
+ redirect);
+ continue;
+ }
+ hostport[0] = '\0';
+ hostport++;
- for (redirect = strtok (cpy, " "); redirect != NULL; redirect = strtok
- (NULL, " "))
- {
- if (NULL == (hostname = strstr (redirect, ":")))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Warning: option %s is
not formatted correctly!\n",
- redirect);
- continue;
- }
- hostname[0] = '\0';
- hostname++;
- if (NULL == (hostport = strstr (hostname, ":")))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Warning: option %s is
not formatted correctly!\n",
- redirect);
- continue;
- }
- hostport[0] = '\0';
- hostport++;
+ int local_port = atoi (redirect);
- int local_port = atoi (redirect);
- if (!((local_port > 0) && (local_port < 65536)))
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Warning: %s is not a
correct port.",
- redirect);
+ if (!((local_port > 0) && (local_port < 65536)))
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Warning: %s is not a correct port.", redirect);
- *desc = local_port;
+ *desc = local_port;
- struct redirect_service *serv =
- GNUNET_malloc (sizeof (struct redirect_service));
- memset (serv, 0, sizeof (struct redirect_service));
- serv->my_port = local_port;
+ struct redirect_service *serv =
+ GNUNET_malloc (sizeof (struct redirect_service));
+ memset (serv, 0, sizeof (struct redirect_service));
+ serv->my_port = local_port;
- if (0 == strcmp ("localhost4", hostname))
- {
- serv->version = 4;
+ if (0 == strcmp ("localhost4", hostname))
+ {
+ serv->version = 4;
- char *ip4addr;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "exit",
- "IPV4ADDR",
- &ip4addr));
- GNUNET_assert (1 ==
- inet_pton (AF_INET, ip4addr,
- serv->v4.ip4address));
- GNUNET_free (ip4addr);
- }
- else if (0 == strcmp ("localhost6", hostname))
- {
- serv->version = 6;
+ char *ip4addr;
- char *ip6addr;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "exit",
- "IPV6ADDR",
- &ip6addr));
- GNUNET_assert (1 ==
- inet_pton (AF_INET6, ip6addr,
- serv->v6.ip6address));
- GNUNET_free (ip6addr);
- }
- else
- {
- // TODO Lookup, yadayadayada
- GNUNET_assert (0);
- }
- serv->remote_port = atoi (hostport);
- if (UDP == proto)
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_put (udp_services,
-
(GNUNET_HashCode*)desc, serv,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
- else
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_put (tcp_services,
-
(GNUNET_HashCode*)desc, serv,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_string (cfg,
+ "exit",
+ "IPV4ADDR",
+ &ip4addr));
+ GNUNET_assert (1 == inet_pton (AF_INET, ip4addr, serv->v4.ip4address));
+ GNUNET_free (ip4addr);
+ }
+ else if (0 == strcmp ("localhost6", hostname))
+ {
+ serv->version = 6;
- }
- GNUNET_free (cpy);
+ char *ip6addr;
+
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_string (cfg,
+ "exit",
+ "IPV6ADDR",
+ &ip6addr));
+ GNUNET_assert (1 == inet_pton (AF_INET6, ip6addr,
serv->v6.ip6address));
+ GNUNET_free (ip6addr);
+ }
+ else
+ {
+ // TODO Lookup, yadayadayada
+ GNUNET_assert (0);
+ }
+ serv->remote_port = atoi (hostport);
+ if (UDP == proto)
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONTAINER_multihashmap_put (udp_services,
+ (GNUNET_HashCode *)
+ desc, serv,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+ else
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONTAINER_multihashmap_put (tcp_services,
+ (GNUNET_HashCode *)
+ desc, serv,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+
+ }
+ GNUNET_free (cpy);
next:
- proto = (proto == UDP) ? TCP : UDP;
- }
+ proto = (proto == UDP) ? TCP : UDP;
+ }
while (proto != UDP);
}
@@ -654,71 +709,84 @@
* helper. cls is then taken as handle to the old helper and is cleaned up.
*/
static void
-start_helper_and_schedule(void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc) {
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
+start_helper_and_schedule (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
+ return;
- if (cls != NULL)
- cleanup_helper(cls);
- cls = NULL;
+ if (cls != NULL)
+ cleanup_helper (cls);
+ cls = NULL;
- char* ifname;
- char* ipv6addr;
- char* ipv6prefix;
- char* ipv4addr;
- char* ipv4mask;
+ char *ifname;
+ char *ipv6addr;
+ char *ipv6prefix;
+ char *ipv4addr;
+ char *ipv4mask;
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "exit",
"IFNAME", &ifname))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "No entry 'IFNAME' in
configuration!\n");
- exit(1);
- }
+ if (GNUNET_SYSERR ==
+ GNUNET_CONFIGURATION_get_value_string (cfg, "exit", "IFNAME", &ifname))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "No entry 'IFNAME' in configuration!\n");
+ exit (1);
+ }
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "exit",
"IPV6ADDR", &ipv6addr))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "No entry 'IPV6ADDR' in
configuration!\n");
- exit(1);
- }
+ if (GNUNET_SYSERR ==
+ GNUNET_CONFIGURATION_get_value_string (cfg, "exit", "IPV6ADDR",
+ &ipv6addr))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "No entry 'IPV6ADDR' in configuration!\n");
+ exit (1);
+ }
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "exit",
"IPV6PREFIX", &ipv6prefix))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "No entry 'IPV6PREFIX' in
configuration!\n");
- exit(1);
- }
+ if (GNUNET_SYSERR ==
+ GNUNET_CONFIGURATION_get_value_string (cfg, "exit", "IPV6PREFIX",
+ &ipv6prefix))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "No entry 'IPV6PREFIX' in configuration!\n");
+ exit (1);
+ }
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "exit",
"IPV4ADDR", &ipv4addr))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "No entry 'IPV4ADDR' in
configuration!\n");
- exit(1);
- }
+ if (GNUNET_SYSERR ==
+ GNUNET_CONFIGURATION_get_value_string (cfg, "exit", "IPV4ADDR",
+ &ipv4addr))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "No entry 'IPV4ADDR' in configuration!\n");
+ exit (1);
+ }
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "exit",
"IPV4MASK", &ipv4mask))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "No entry 'IPV4MASK' in
configuration!\n");
- exit(1);
- }
+ if (GNUNET_SYSERR ==
+ GNUNET_CONFIGURATION_get_value_string (cfg, "exit", "IPV4MASK",
+ &ipv4mask))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "No entry 'IPV4MASK' in configuration!\n");
+ exit (1);
+ }
- /* Start the helper
- * Messages get passed to the function message_token
- * When the helper dies, this function will be called again with the
- * helper_handle as cls.
- */
- helper_handle = start_helper(ifname,
- ipv6addr,
- ipv6prefix,
- ipv4addr,
- ipv4mask,
- "exit-gnunet",
- start_helper_and_schedule,
- message_token,
- NULL);
+ /* Start the helper
+ * Messages get passed to the function message_token
+ * When the helper dies, this function will be called again with the
+ * helper_handle as cls.
+ */
+ helper_handle = start_helper (ifname,
+ ipv6addr,
+ ipv6prefix,
+ ipv4addr,
+ ipv4mask,
+ "exit-gnunet",
+ start_helper_and_schedule, message_token,
NULL);
- GNUNET_free(ipv6addr);
- GNUNET_free(ipv6prefix);
- GNUNET_free(ipv4addr);
- GNUNET_free(ipv4mask);
- GNUNET_free(ifname);
+ GNUNET_free (ipv6addr);
+ GNUNET_free (ipv6prefix);
+ GNUNET_free (ipv4addr);
+ GNUNET_free (ipv4mask);
+ GNUNET_free (ifname);
}
static void
@@ -752,14 +820,13 @@
/* Generate a new src-address */
char *ipv4addr;
char *ipv4mask;
+
GNUNET_assert (GNUNET_OK ==
GNUNET_CONFIGURATION_get_value_string (cfg, "exit",
- "IPV4ADDR",
- &ipv4addr));
+ "IPV4ADDR",
&ipv4addr));
GNUNET_assert (GNUNET_OK ==
GNUNET_CONFIGURATION_get_value_string (cfg, "exit",
- "IPV4MASK",
- &ipv4mask));
+ "IPV4MASK",
&ipv4mask));
inet_pton (AF_INET, ipv4addr, &tmp);
inet_pton (AF_INET, ipv4mask, &tmp2);
GNUNET_free (ipv4addr);
@@ -774,41 +841,44 @@
memcpy (&state->redirect_info.addr, &tmp, 4);
if (0x11 == protocol)
- {
- struct ip_udp* pkt4_udp = (struct ip_udp*)pkt4;
- state->redirect_info.pt = pkt4_udp->udp_hdr.spt;
+ {
+ struct ip_udp *pkt4_udp = (struct ip_udp *) pkt4;
- pkt4_udp->udp_hdr.crc = 0; /* Optional for IPv4 */
- }
+ state->redirect_info.pt = pkt4_udp->udp_hdr.spt;
+
+ pkt4_udp->udp_hdr.crc = 0; /* Optional for IPv4 */
+ }
else if (0x06 == protocol)
- {
- struct ip_tcp* pkt4_tcp = (struct ip_tcp*)pkt4;
- state->redirect_info.pt = pkt4_tcp->tcp_hdr.spt;
+ {
+ struct ip_tcp *pkt4_tcp = (struct ip_tcp *) pkt4;
- pkt4_tcp->tcp_hdr.crc = 0;
- uint32_t sum = 0;
- tmp = pkt4->ip_hdr.sadr;
- sum =
- calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
- tmp = pkt4->ip_hdr.dadr;
- sum =
- calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
+ state->redirect_info.pt = pkt4_tcp->tcp_hdr.spt;
- tmp = (protocol << 16) | (0xffff & pktlen);
+ pkt4_tcp->tcp_hdr.crc = 0;
+ uint32_t sum = 0;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "line: %08x, %x \n", tmp, (0xffff &
pktlen));
+ tmp = pkt4->ip_hdr.sadr;
+ sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
+ tmp = pkt4->ip_hdr.dadr;
+ sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
- tmp = htonl(tmp);
+ tmp = (protocol << 16) | (0xffff & pktlen);
- sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "line: %08x, %x \n", tmp,
+ (0xffff & pktlen));
- sum =
- calculate_checksum_update (sum, (uint16_t *) & pkt4_tcp->tcp_hdr,
pktlen);
- pkt4_tcp->tcp_hdr.crc = calculate_checksum_end (sum);
- }
+ tmp = htonl (tmp);
+ sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
+
+ sum =
+ calculate_checksum_update (sum, (uint16_t *) & pkt4_tcp->tcp_hdr,
+ pktlen);
+ pkt4_tcp->tcp_hdr.crc = calculate_checksum_end (sum);
+ }
+
pkt4->ip_hdr.chks =
- calculate_ip_checksum ((uint16_t *) & pkt4->ip_hdr, 5 * 4);
+ calculate_ip_checksum ((uint16_t *) & pkt4->ip_hdr, 5 * 4);
}
static void
@@ -838,10 +908,10 @@
* the host-mask*/
char *ipv6addr;
unsigned long long ipv6prefix;
+
GNUNET_assert (GNUNET_OK ==
GNUNET_CONFIGURATION_get_value_string (cfg, "exit",
- "IPV6ADDR",
- &ipv6addr));
+ "IPV6ADDR",
&ipv6addr));
GNUNET_assert (GNUNET_OK ==
GNUNET_CONFIGURATION_get_value_number (cfg, "exit",
"IPV6PREFIX",
@@ -856,6 +926,7 @@
ipv6prefix = 16 - sizeof (void *);
unsigned int offset = ipv6prefix - (16 - sizeof (void *));
+
memcpy ((((char *) &pkt6->ip6_hdr.sadr)) + ipv6prefix,
((char *) &tunnel) + offset, 16 - ipv6prefix);
@@ -863,66 +934,74 @@
memcpy (&state->redirect_info.addr, &pkt6->ip6_hdr.sadr, 16);
if (0x11 == protocol)
- {
- struct ip6_udp* pkt6_udp = (struct ip6_udp*)pkt6;
- state->redirect_info.pt = pkt6_udp->udp_hdr.spt;
+ {
+ struct ip6_udp *pkt6_udp = (struct ip6_udp *) pkt6;
- pkt6_udp->udp_hdr.crc = 0;
- uint32_t sum = 0;
- sum =
- calculate_checksum_update (sum, (uint16_t *) & pkt6_udp->ip6_hdr.sadr,
16);
- sum =
- calculate_checksum_update (sum, (uint16_t *) & pkt6_udp->ip6_hdr.dadr,
16);
- tmp = (htons (pktlen) & 0xffff);
- sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
- tmp = htons (((pkt6_udp->ip6_hdr.nxthdr & 0x00ff)));
- sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
+ state->redirect_info.pt = pkt6_udp->udp_hdr.spt;
- sum =
+ pkt6_udp->udp_hdr.crc = 0;
+ uint32_t sum = 0;
+
+ sum =
+ calculate_checksum_update (sum, (uint16_t *) & pkt6_udp->ip6_hdr.sadr,
+ 16);
+ sum =
+ calculate_checksum_update (sum, (uint16_t *) & pkt6_udp->ip6_hdr.dadr,
+ 16);
+ tmp = (htons (pktlen) & 0xffff);
+ sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
+ tmp = htons (((pkt6_udp->ip6_hdr.nxthdr & 0x00ff)));
+ sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
+
+ sum =
calculate_checksum_update (sum, (uint16_t *) & pkt6_udp->udp_hdr,
ntohs (pkt6_udp->udp_hdr.len));
- pkt6_udp->udp_hdr.crc = calculate_checksum_end (sum);
- }
+ pkt6_udp->udp_hdr.crc = calculate_checksum_end (sum);
+ }
else if (0x06 == protocol)
- {
- struct ip6_tcp* pkt6_tcp = (struct ip6_tcp*)pkt6;
- state->redirect_info.pt = pkt6_tcp->tcp_hdr.spt;
+ {
+ struct ip6_tcp *pkt6_tcp = (struct ip6_tcp *) pkt6;
- pkt6_tcp->tcp_hdr.crc = 0;
- uint32_t sum = 0;
- sum =
+ state->redirect_info.pt = pkt6_tcp->tcp_hdr.spt;
+
+ pkt6_tcp->tcp_hdr.crc = 0;
+ uint32_t sum = 0;
+
+ sum =
calculate_checksum_update (sum, (uint16_t *) & pkt6->ip6_hdr.sadr, 16);
- sum =
+ sum =
calculate_checksum_update (sum, (uint16_t *) & pkt6->ip6_hdr.dadr, 16);
- tmp = htonl(pktlen);
- sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
- tmp = htonl (((pkt6->ip6_hdr.nxthdr & 0x000000ff)));
- sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
+ tmp = htonl (pktlen);
+ sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
+ tmp = htonl (((pkt6->ip6_hdr.nxthdr & 0x000000ff)));
+ sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
- sum =
+ sum =
calculate_checksum_update (sum, (uint16_t *) & pkt6_tcp->tcp_hdr,
ntohs (pkt6->ip6_hdr.paylgth));
- pkt6_tcp->tcp_hdr.crc = calculate_checksum_end (sum);
- }
+ pkt6_tcp->tcp_hdr.crc = calculate_checksum_end (sum);
+ }
}
/**
* The messages are one GNUNET_HashCode for the service followed by a struct
tcp_pkt
*/
static int
-receive_tcp_service (void *cls __attribute__((unused)),
+receive_tcp_service (void *cls __attribute__ ((unused)),
struct GNUNET_MESH_Tunnel *tunnel,
- void **tunnel_ctx __attribute__((unused)),
- const struct GNUNET_PeerIdentity *sender
__attribute__((unused)),
+ void **tunnel_ctx __attribute__ ((unused)),
+ const struct GNUNET_PeerIdentity *sender
+ __attribute__ ((unused)),
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi
__attribute__((unused)))
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi
+ __attribute__ ((unused)))
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received TCP-Packet\n");
GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1);
struct tcp_pkt *pkt = (struct tcp_pkt *) (desc + 1);
unsigned int pkt_len = ntohs (message->size) - sizeof (struct
GNUNET_MessageHeader)
- - sizeof (GNUNET_HashCode);
+ - sizeof (GNUNET_HashCode);
/** Get the configuration from the services-hashmap.
*
@@ -934,13 +1013,15 @@
memcpy (tcp_desc + 1, desc, sizeof (GNUNET_HashCode));
*tcp_desc = ntohs (pkt->dpt);
struct redirect_service *serv =
- GNUNET_CONTAINER_multihashmap_get (tcp_services,
(GNUNET_HashCode*)tcp_desc);
+ GNUNET_CONTAINER_multihashmap_get (tcp_services,
+ (GNUNET_HashCode *) tcp_desc);
+
if (NULL == serv)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "No service found for TCP dpt %d!\n", *tcp_desc);
- return GNUNET_YES;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "No service found for TCP dpt %d!\n", *tcp_desc);
+ return GNUNET_YES;
+ }
pkt->dpt = htons (serv->remote_port);
@@ -955,8 +1036,8 @@
* This will be saved in the hashmap, so that the receiving procedure knows
* through which tunnel this connection has to be routed.
*/
- struct redirect_state *state =
- GNUNET_malloc (sizeof (struct redirect_state));
+ struct redirect_state *state = GNUNET_malloc (sizeof (struct
redirect_state));
+
memset (state, 0, sizeof (struct redirect_state));
state->tunnel = tunnel;
state->serv = serv;
@@ -965,44 +1046,46 @@
memcpy (&state->desc, desc, sizeof (GNUNET_HashCode));
len = sizeof (struct GNUNET_MessageHeader) + sizeof (struct pkt_tun) +
- sizeof (struct ip6_hdr) + pkt_len;
+ sizeof (struct ip6_hdr) + pkt_len;
buf = alloca (len);
memset (buf, 0, len);
switch (serv->version)
- {
- case 4:
- prepare_ipv4_packet (len, pkt_len, pkt, 0x06, /* TCP */
- &serv->v4.ip4address,
- tunnel, state, (struct ip_pkt *) buf);
- break;
- case 6:
- prepare_ipv6_packet (len, pkt_len, pkt, 0x06, /* TCP */
- &serv->v6.ip6address,
- tunnel, state, (struct ip6_pkt *) buf);
+ {
+ case 4:
+ prepare_ipv4_packet (len, pkt_len, pkt, 0x06, /* TCP */
+ &serv->v4.ip4address,
+ tunnel, state, (struct ip_pkt *) buf);
+ break;
+ case 6:
+ prepare_ipv6_packet (len, pkt_len, pkt, 0x06, /* TCP */
+ &serv->v6.ip6address,
+ tunnel, state, (struct ip6_pkt *) buf);
- break;
- default:
- GNUNET_assert (0);
- break;
- }
+ break;
+ default:
+ GNUNET_assert (0);
+ break;
+ }
- hash_redirect_info(&state->hash, &state->redirect_info, serv->version == 4 ?
4 : 16);
+ hash_redirect_info (&state->hash, &state->redirect_info,
+ serv->version == 4 ? 4 : 16);
if (GNUNET_NO ==
GNUNET_CONTAINER_multihashmap_contains (tcp_connections, &state->hash))
- {
- GNUNET_CONTAINER_multihashmap_put (tcp_connections, &state->hash, state,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+ {
+ GNUNET_CONTAINER_multihashmap_put (tcp_connections, &state->hash, state,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
- state->heap_node =
+ state->heap_node =
GNUNET_CONTAINER_heap_insert (tcp_connections_heap, state,
GNUNET_TIME_absolute_get ().abs_value);
- if (GNUNET_CONTAINER_heap_get_size(tcp_connections_heap) >
max_tcp_connections)
- GNUNET_SCHEDULER_add_now(collect_connections, tcp_connections_heap);
- }
+ if (GNUNET_CONTAINER_heap_get_size (tcp_connections_heap) >
+ max_tcp_connections)
+ GNUNET_SCHEDULER_add_now (collect_connections, tcp_connections_heap);
+ }
else
GNUNET_free (state);
@@ -1011,22 +1094,26 @@
}
static int
-receive_tcp_remote (void *cls __attribute__((unused)),
- struct GNUNET_MESH_Tunnel *tunnel,
- void **tunnel_ctx __attribute__((unused)),
- const struct GNUNET_PeerIdentity *sender
__attribute__((unused)),
- const struct GNUNET_MessageHeader *message,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi
__attribute__((unused)))
+receive_tcp_remote (void *cls __attribute__ ((unused)),
+ struct GNUNET_MESH_Tunnel *tunnel,
+ void **tunnel_ctx __attribute__ ((unused)),
+ const struct GNUNET_PeerIdentity *sender
+ __attribute__ ((unused)),
+ const struct GNUNET_MessageHeader *message,
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi
+ __attribute__ ((unused)))
{
GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1);
struct tcp_pkt *pkt = (struct tcp_pkt *) (desc + 1);
struct remote_addr *s = (struct remote_addr *) desc;
char *buf;
size_t len;
- unsigned int pkt_len = ntohs (message->size) - sizeof (struct
GNUNET_MessageHeader) - sizeof (GNUNET_HashCode);
+ unsigned int pkt_len =
+ ntohs (message->size) - sizeof (struct GNUNET_MessageHeader) -
+ sizeof (GNUNET_HashCode);
- struct redirect_state *state =
- GNUNET_malloc (sizeof (struct redirect_state));
+ struct redirect_state *state = GNUNET_malloc (sizeof (struct
redirect_state));
+
memset (state, 0, sizeof (struct redirect_state));
state->tunnel = tunnel;
state->type = REMOTE;
@@ -1034,44 +1121,45 @@
memcpy (&state->remote, s, sizeof (struct remote_addr));
len = sizeof (struct GNUNET_MessageHeader) + sizeof (struct pkt_tun) +
- sizeof (struct ip6_hdr) + pkt_len;
+ sizeof (struct ip6_hdr) + pkt_len;
buf = alloca (len);
memset (buf, 0, len);
switch (s->addrlen)
- {
- case 4:
- prepare_ipv4_packet (len, pkt_len, pkt, 0x06, /* TCP */
- &s->addr, tunnel, state, (struct ip_pkt *) buf);
- break;
- case 16:
- prepare_ipv6_packet (len, pkt_len, pkt, 0x06, /* TCP */
- &s->addr, tunnel, state, (struct ip6_pkt *) buf);
- break;
- default:
- return GNUNET_SYSERR;
- break;
- }
+ {
+ case 4:
+ prepare_ipv4_packet (len, pkt_len, pkt, 0x06, /* TCP */
+ &s->addr, tunnel, state, (struct ip_pkt *) buf);
+ break;
+ case 16:
+ prepare_ipv6_packet (len, pkt_len, pkt, 0x06, /* TCP */
+ &s->addr, tunnel, state, (struct ip6_pkt *) buf);
+ break;
+ default:
+ return GNUNET_SYSERR;
+ break;
+ }
hash_redirect_info (&state->hash, &state->redirect_info, s->addrlen);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Packet from remote; hash is %x\n",
*((uint32_t*)&state->hash));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Packet from remote; hash is %x\n",
+ *((uint32_t *) & state->hash));
if (GNUNET_NO ==
GNUNET_CONTAINER_multihashmap_contains (tcp_connections, &state->hash))
- {
- GNUNET_CONTAINER_multihashmap_put (tcp_connections, &state->hash, state,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+ {
+ GNUNET_CONTAINER_multihashmap_put (tcp_connections, &state->hash, state,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
- state->heap_node =
+ state->heap_node =
GNUNET_CONTAINER_heap_insert (tcp_connections_heap, state,
GNUNET_TIME_absolute_get ().abs_value);
- if (GNUNET_CONTAINER_heap_get_size (tcp_connections_heap) >
- max_tcp_connections)
- GNUNET_SCHEDULER_add_now (collect_connections, tcp_connections_heap);
- }
+ if (GNUNET_CONTAINER_heap_get_size (tcp_connections_heap) >
+ max_tcp_connections)
+ GNUNET_SCHEDULER_add_now (collect_connections, tcp_connections_heap);
+ }
else
GNUNET_free (state);
@@ -1081,12 +1169,14 @@
}
static int
-receive_udp_remote (void *cls __attribute__((unused)),
+receive_udp_remote (void *cls __attribute__ ((unused)),
struct GNUNET_MESH_Tunnel *tunnel,
- void **tunnel_ctx __attribute__((unused)),
- const struct GNUNET_PeerIdentity *sender
__attribute__((unused)),
+ void **tunnel_ctx __attribute__ ((unused)),
+ const struct GNUNET_PeerIdentity *sender
+ __attribute__ ((unused)),
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi
__attribute__((unused)))
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi
+ __attribute__ ((unused)))
{
GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1);
struct udp_pkt *pkt = (struct udp_pkt *) (desc + 1);
@@ -1103,8 +1193,8 @@
* This will be saved in the hashmap, so that the receiving procedure knows
* through which tunnel this connection has to be routed.
*/
- struct redirect_state *state =
- GNUNET_malloc (sizeof (struct redirect_state));
+ struct redirect_state *state = GNUNET_malloc (sizeof (struct
redirect_state));
+
memset (state, 0, sizeof (struct redirect_state));
state->tunnel = tunnel;
state->hashmap = udp_connections;
@@ -1112,42 +1202,42 @@
memcpy (&state->remote, s, sizeof (struct remote_addr));
len = sizeof (struct GNUNET_MessageHeader) + sizeof (struct pkt_tun) +
- sizeof (struct ip6_hdr) + ntohs (pkt->len);
+ sizeof (struct ip6_hdr) + ntohs (pkt->len);
buf = alloca (len);
memset (buf, 0, len);
switch (s->addrlen)
- {
- case 4:
- prepare_ipv4_packet (len, ntohs (pkt->len), pkt, 0x11, /* UDP */
- &s->addr, tunnel, state, (struct ip_pkt *) buf);
- break;
- case 16:
- prepare_ipv6_packet (len, ntohs (pkt->len), pkt, 0x11, /* UDP */
- &s->addr, tunnel, state, (struct ip6_pkt *) buf);
- break;
- default:
- GNUNET_assert (0);
- break;
- }
+ {
+ case 4:
+ prepare_ipv4_packet (len, ntohs (pkt->len), pkt, 0x11, /* UDP */
+ &s->addr, tunnel, state, (struct ip_pkt *) buf);
+ break;
+ case 16:
+ prepare_ipv6_packet (len, ntohs (pkt->len), pkt, 0x11, /* UDP */
+ &s->addr, tunnel, state, (struct ip6_pkt *) buf);
+ break;
+ default:
+ GNUNET_assert (0);
+ break;
+ }
hash_redirect_info (&state->hash, &state->redirect_info, s->addrlen);
if (GNUNET_NO ==
GNUNET_CONTAINER_multihashmap_contains (udp_connections, &state->hash))
- {
- GNUNET_CONTAINER_multihashmap_put (udp_connections, &state->hash, state,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+ {
+ GNUNET_CONTAINER_multihashmap_put (udp_connections, &state->hash, state,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
- state->heap_node =
+ state->heap_node =
GNUNET_CONTAINER_heap_insert (udp_connections_heap, state,
GNUNET_TIME_absolute_get ().abs_value);
- if (GNUNET_CONTAINER_heap_get_size (udp_connections_heap) >
- max_udp_connections)
- GNUNET_SCHEDULER_add_now (collect_connections, udp_connections_heap);
- }
+ if (GNUNET_CONTAINER_heap_get_size (udp_connections_heap) >
+ max_udp_connections)
+ GNUNET_SCHEDULER_add_now (collect_connections, udp_connections_heap);
+ }
else
GNUNET_free (state);
@@ -1159,12 +1249,14 @@
* The messages are one GNUNET_HashCode for the service, followed by a struct
udp_pkt
*/
static int
-receive_udp_service (void *cls __attribute__((unused)),
+receive_udp_service (void *cls __attribute__ ((unused)),
struct GNUNET_MESH_Tunnel *tunnel,
- void **tunnel_ctx __attribute__((unused)),
- const struct GNUNET_PeerIdentity *sender
__attribute__((unused)),
+ void **tunnel_ctx __attribute__ ((unused)),
+ const struct GNUNET_PeerIdentity *sender
+ __attribute__ ((unused)),
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi
__attribute__((unused)))
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi
+ __attribute__ ((unused)))
{
GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1);
struct udp_pkt *pkt = (struct udp_pkt *) (desc + 1);
@@ -1176,16 +1268,19 @@
/* Get the configuration from the hashmap */
uint16_t *udp_desc = alloca (sizeof (GNUNET_HashCode) + 2);
+
memcpy (udp_desc + 1, desc, sizeof (GNUNET_HashCode));
*udp_desc = ntohs (pkt->dpt);
struct redirect_service *serv =
- GNUNET_CONTAINER_multihashmap_get (udp_services,
(GNUNET_HashCode*)udp_desc);
+ GNUNET_CONTAINER_multihashmap_get (udp_services,
+ (GNUNET_HashCode *) udp_desc);
+
if (NULL == serv)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "No service found for UDP dpt %d!\n", *udp_desc);
- return GNUNET_YES;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "No service found for UDP dpt %d!\n", *udp_desc);
+ return GNUNET_YES;
+ }
pkt->dpt = htons (serv->remote_port);
@@ -1200,8 +1295,8 @@
* This will be saved in the hashmap, so that the receiving procedure knows
* through which tunnel this connection has to be routed.
*/
- struct redirect_state *state =
- GNUNET_malloc (sizeof (struct redirect_state));
+ struct redirect_state *state = GNUNET_malloc (sizeof (struct
redirect_state));
+
memset (state, 0, sizeof (struct redirect_state));
state->tunnel = tunnel;
state->serv = serv;
@@ -1210,44 +1305,46 @@
memcpy (&state->desc, desc, sizeof (GNUNET_HashCode));
len = sizeof (struct GNUNET_MessageHeader) + sizeof (struct pkt_tun) +
- sizeof (struct ip6_hdr) + ntohs (pkt->len);
+ sizeof (struct ip6_hdr) + ntohs (pkt->len);
buf = alloca (len);
memset (buf, 0, len);
switch (serv->version)
- {
- case 4:
- prepare_ipv4_packet (len, ntohs (pkt->len), pkt, 0x11, /* UDP */
- &serv->v4.ip4address,
- tunnel, state, (struct ip_pkt *) buf);
- break;
- case 6:
- prepare_ipv6_packet (len, ntohs (pkt->len), pkt, 0x11, /* UDP */
- &serv->v6.ip6address,
- tunnel, state, (struct ip6_pkt *) buf);
+ {
+ case 4:
+ prepare_ipv4_packet (len, ntohs (pkt->len), pkt, 0x11, /* UDP */
+ &serv->v4.ip4address,
+ tunnel, state, (struct ip_pkt *) buf);
+ break;
+ case 6:
+ prepare_ipv6_packet (len, ntohs (pkt->len), pkt, 0x11, /* UDP */
+ &serv->v6.ip6address,
+ tunnel, state, (struct ip6_pkt *) buf);
- break;
- default:
- GNUNET_assert (0);
- break;
- }
+ break;
+ default:
+ GNUNET_assert (0);
+ break;
+ }
- hash_redirect_info(&state->hash, &state->redirect_info, serv->version == 4 ?
4 : 16);
+ hash_redirect_info (&state->hash, &state->redirect_info,
+ serv->version == 4 ? 4 : 16);
if (GNUNET_NO ==
GNUNET_CONTAINER_multihashmap_contains (udp_connections, &state->hash))
- {
- GNUNET_CONTAINER_multihashmap_put (udp_connections, &state->hash, state,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+ {
+ GNUNET_CONTAINER_multihashmap_put (udp_connections, &state->hash, state,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
- state->heap_node =
+ state->heap_node =
GNUNET_CONTAINER_heap_insert (udp_connections_heap, state,
GNUNET_TIME_absolute_get ().abs_value);
- if (GNUNET_CONTAINER_heap_get_size(udp_connections_heap) >
max_udp_connections)
- GNUNET_SCHEDULER_add_now(collect_connections, udp_connections_heap);
- }
+ if (GNUNET_CONTAINER_heap_get_size (udp_connections_heap) >
+ max_udp_connections)
+ GNUNET_SCHEDULER_add_now (collect_connections, udp_connections_heap);
+ }
else
GNUNET_free (state);
@@ -1256,13 +1353,13 @@
}
static void
-connect_to_mesh()
+connect_to_mesh ()
{
int udp, tcp;
int handler_idx, app_idx;
- udp = GNUNET_CONFIGURATION_get_value_yesno(cfg, "exit", "ENABLE_UDP");
- tcp = GNUNET_CONFIGURATION_get_value_yesno(cfg, "exit", "ENABLE_TCP");
+ udp = GNUNET_CONFIGURATION_get_value_yesno (cfg, "exit", "ENABLE_UDP");
+ tcp = GNUNET_CONFIGURATION_get_value_yesno (cfg, "exit", "ENABLE_TCP");
static struct GNUNET_MESH_MessageHandler handlers[] = {
{receive_udp_service, GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP, 0},
@@ -1272,35 +1369,34 @@
{NULL, 0, 0}
};
- static GNUNET_MESH_ApplicationType apptypes[] =
- {
- GNUNET_APPLICATION_TYPE_END,
- GNUNET_APPLICATION_TYPE_END,
- GNUNET_APPLICATION_TYPE_END
- };
+ static GNUNET_MESH_ApplicationType apptypes[] = {
+ GNUNET_APPLICATION_TYPE_END,
+ GNUNET_APPLICATION_TYPE_END,
+ GNUNET_APPLICATION_TYPE_END
+ };
app_idx = 0;
handler_idx = 2;
if (GNUNET_YES == udp)
- {
- handlers[handler_idx].callback = receive_udp_remote;
- handlers[handler_idx].expected_size = 0;
- handlers[handler_idx].type = GNUNET_MESSAGE_TYPE_VPN_REMOTE_UDP;
- apptypes[app_idx] = GNUNET_APPLICATION_TYPE_INTERNET_UDP_GATEWAY;
- handler_idx++;
- app_idx++;
- }
+ {
+ handlers[handler_idx].callback = receive_udp_remote;
+ handlers[handler_idx].expected_size = 0;
+ handlers[handler_idx].type = GNUNET_MESSAGE_TYPE_VPN_REMOTE_UDP;
+ apptypes[app_idx] = GNUNET_APPLICATION_TYPE_INTERNET_UDP_GATEWAY;
+ handler_idx++;
+ app_idx++;
+ }
if (GNUNET_YES == tcp)
- {
- handlers[handler_idx].callback = receive_tcp_remote;
- handlers[handler_idx].expected_size = 0;
- handlers[handler_idx].type = GNUNET_MESSAGE_TYPE_VPN_REMOTE_TCP;
- apptypes[app_idx] = GNUNET_APPLICATION_TYPE_INTERNET_TCP_GATEWAY;
- handler_idx++;
- app_idx++;
- }
+ {
+ handlers[handler_idx].callback = receive_tcp_remote;
+ handlers[handler_idx].expected_size = 0;
+ handlers[handler_idx].type = GNUNET_MESSAGE_TYPE_VPN_REMOTE_TCP;
+ apptypes[app_idx] = GNUNET_APPLICATION_TYPE_INTERNET_TCP_GATEWAY;
+ handler_idx++;
+ app_idx++;
+ }
mesh_handle = GNUNET_MESH_connect (cfg, NULL, NULL, handlers, apptypes);
}
@@ -1315,19 +1411,20 @@
*/
static void
run (void *cls,
- char *const *args __attribute__((unused)),
- const char *cfgfile __attribute__((unused)), const struct
GNUNET_CONFIGURATION_Handle *cfg_)
+ char *const *args __attribute__ ((unused)),
+ const char *cfgfile
+ __attribute__ ((unused)), const struct GNUNET_CONFIGURATION_Handle *cfg_)
{
cfg = cfg_;
- connect_to_mesh();
+ connect_to_mesh ();
udp_connections = GNUNET_CONTAINER_multihashmap_create (65536);
udp_connections_heap =
- GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
+ GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
tcp_connections = GNUNET_CONTAINER_multihashmap_create (65536);
tcp_connections_heap =
- GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
+ GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
udp_services = GNUNET_CONTAINER_multihashmap_create (65536);
tcp_services = GNUNET_CONTAINER_multihashmap_create (65536);
@@ -1350,18 +1447,18 @@
* @return 0 ok, 1 on error
*/
int
-main (int argc, char *const *argv) {
- static const struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_OPTION_END
- };
+main (int argc, char *const *argv)
+{
+ static const struct GNUNET_GETOPT_CommandLineOption options[] = {
+ GNUNET_GETOPT_OPTION_END
+ };
- return (GNUNET_OK ==
- GNUNET_PROGRAM_run (argc,
- argv,
- "exit",
- gettext_noop ("help text"),
- options, &run, NULL)) ? ret : 1;
+ return (GNUNET_OK ==
+ GNUNET_PROGRAM_run (argc,
+ argv,
+ "exit",
+ gettext_noop ("help text"),
+ options, &run, NULL)) ? ret : 1;
}
/* end of gnunet-daemon-exit.c */
-
Modified: gnunet/src/vpn/gnunet-daemon-vpn-dns.c
===================================================================
--- gnunet/src/vpn/gnunet-daemon-vpn-dns.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/vpn/gnunet-daemon-vpn-dns.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -52,56 +52,67 @@
* {{{
*/
size_t
-send_query(void* cls __attribute__((unused)), size_t size, void* buf) {
- size_t len;
+send_query (void *cls __attribute__ ((unused)), size_t size, void *buf)
+{
+ size_t len;
+
+ /*
+ * Send the rehijack-message
+ */
+ if (restart_hijack == 1)
+ {
+ restart_hijack = 0;
/*
- * Send the rehijack-message
+ * The message is just a header
*/
- if (restart_hijack == 1)
- {
- restart_hijack = 0;
- /*
- * The message is just a header
- */
- GNUNET_assert(sizeof(struct GNUNET_MessageHeader) <= size);
- struct GNUNET_MessageHeader* hdr = buf;
- len = sizeof(struct GNUNET_MessageHeader);
- hdr->size = htons(len);
- hdr->type = htons(GNUNET_MESSAGE_TYPE_REHIJACK);
- }
- else if (head != NULL)
- {
- struct query_packet_list* query = head;
- len = ntohs(query->pkt.hdr.size);
+ GNUNET_assert (sizeof (struct GNUNET_MessageHeader) <= size);
+ struct GNUNET_MessageHeader *hdr = buf;
- GNUNET_assert(len <= size);
+ len = sizeof (struct GNUNET_MessageHeader);
+ hdr->size = htons (len);
+ hdr->type = htons (GNUNET_MESSAGE_TYPE_REHIJACK);
+ }
+ else if (head != NULL)
+ {
+ struct query_packet_list *query = head;
- memcpy(buf, &query->pkt.hdr, len);
+ len = ntohs (query->pkt.hdr.size);
- GNUNET_CONTAINER_DLL_remove (head, tail, query);
+ GNUNET_assert (len <= size);
- GNUNET_free(query);
- }
- else
- {
- GNUNET_break(0);
- len = 0;
- }
+ memcpy (buf, &query->pkt.hdr, len);
- /*
- * Check whether more data is to be sent
- */
- if (head != NULL)
- {
- 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)
- {
- GNUNET_CLIENT_notify_transmit_ready(dns_connection, sizeof(struct
GNUNET_MessageHeader), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, &send_query,
NULL);
- }
+ GNUNET_CONTAINER_DLL_remove (head, tail, query);
- return len;
+ GNUNET_free (query);
+ }
+ else
+ {
+ GNUNET_break (0);
+ len = 0;
+ }
+
+ /*
+ * Check whether more data is to be sent
+ */
+ if (head != NULL)
+ {
+ 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)
+ {
+ GNUNET_CLIENT_notify_transmit_ready (dns_connection,
+ sizeof (struct GNUNET_MessageHeader),
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_YES, &send_query, NULL);
+ }
+
+ return len;
}
+
/* }}} */
@@ -109,33 +120,37 @@
* Connect to the service-dns
*/
void
-connect_to_service_dns (void *cls __attribute__((unused)),
- const struct GNUNET_SCHEDULER_TaskContext *tc) {
- conn_task = GNUNET_SCHEDULER_NO_TASK;
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connecting to service-dns\n");
- GNUNET_assert (dns_connection == NULL);
- dns_connection = GNUNET_CLIENT_connect ("dns", cfg);
- /* This would most likely be a misconfiguration */
- GNUNET_assert(NULL != dns_connection);
- GNUNET_CLIENT_receive(dns_connection, &dns_answer_handler, NULL,
GNUNET_TIME_UNIT_FOREVER_REL);
+connect_to_service_dns (void *cls __attribute__ ((unused)),
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ conn_task = GNUNET_SCHEDULER_NO_TASK;
+ if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
+ return;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting to service-dns\n");
+ GNUNET_assert (dns_connection == NULL);
+ dns_connection = GNUNET_CLIENT_connect ("dns", cfg);
+ /* This would most likely be a misconfiguration */
+ GNUNET_assert (NULL != dns_connection);
+ GNUNET_CLIENT_receive (dns_connection, &dns_answer_handler, NULL,
+ GNUNET_TIME_UNIT_FOREVER_REL);
- /* We might not yet be connected. Yay, mps. */
- if (NULL == dns_connection) return;
+ /* We might not yet be connected. Yay, mps. */
+ if (NULL == dns_connection)
+ return;
- /* If a packet is already in the list, schedule to send it */
- if (head != NULL)
- 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)
- {
- GNUNET_CLIENT_notify_transmit_ready(dns_connection, sizeof(struct
GNUNET_MessageHeader), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, &send_query,
NULL);
- }
+ /* If a packet is already in the list, schedule to send it */
+ if (head != NULL)
+ 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)
+ {
+ GNUNET_CLIENT_notify_transmit_ready (dns_connection,
+ sizeof (struct GNUNET_MessageHeader),
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_YES, &send_query, NULL);
+ }
}
/**
@@ -143,33 +158,34 @@
* handle it
*/
void
-dns_answer_handler(void* cls __attribute__((unused)), const struct
GNUNET_MessageHeader *msg) {
- /* the service disconnected, reconnect after short wait */
- if (msg == NULL)
- {
- GNUNET_CLIENT_disconnect(dns_connection, GNUNET_NO);
- dns_connection = NULL;
- conn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
- &connect_to_service_dns,
- NULL);
- return;
- }
+dns_answer_handler (void *cls
+ __attribute__ ((unused)),
+ const struct GNUNET_MessageHeader *msg)
+{
+ /* the service disconnected, reconnect after short wait */
+ if (msg == NULL)
+ {
+ GNUNET_CLIENT_disconnect (dns_connection, GNUNET_NO);
+ dns_connection = NULL;
+ conn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &connect_to_service_dns, NULL);
+ return;
+ }
- /* the service did something strange, reconnect immediately */
- if (msg->type != htons(GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_RESPONSE_DNS))
- {
- GNUNET_break (0);
- GNUNET_CLIENT_disconnect(dns_connection, GNUNET_NO);
- dns_connection = NULL;
- conn_task = GNUNET_SCHEDULER_add_now (&connect_to_service_dns,
- NULL);
- return;
- }
- void *pkt = GNUNET_malloc(ntohs(msg->size));
+ /* the service did something strange, reconnect immediately */
+ if (msg->type != htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_RESPONSE_DNS))
+ {
+ GNUNET_break (0);
+ GNUNET_CLIENT_disconnect (dns_connection, GNUNET_NO);
+ dns_connection = NULL;
+ conn_task = GNUNET_SCHEDULER_add_now (&connect_to_service_dns, NULL);
+ return;
+ }
+ void *pkt = GNUNET_malloc (ntohs (msg->size));
- memcpy(pkt, msg, ntohs(msg->size));
+ memcpy (pkt, msg, ntohs (msg->size));
- GNUNET_SCHEDULER_add_now(process_answer, pkt);
- GNUNET_CLIENT_receive(dns_connection, &dns_answer_handler, NULL,
GNUNET_TIME_UNIT_FOREVER_REL);
+ GNUNET_SCHEDULER_add_now (process_answer, pkt);
+ GNUNET_CLIENT_receive (dns_connection, &dns_answer_handler, NULL,
+ GNUNET_TIME_UNIT_FOREVER_REL);
}
-
Modified: gnunet/src/vpn/gnunet-daemon-vpn-dns.h
===================================================================
--- gnunet/src/vpn/gnunet-daemon-vpn-dns.h 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/vpn/gnunet-daemon-vpn-dns.h 2011-08-15 21:46:35 UTC (rev
16581)
@@ -40,19 +40,19 @@
* Callback called by notify_transmit_ready; sends dns-queries or
rehijack-messages
* to the service-dns
*/
-size_t send_query(void* cls, size_t size, void* buf);
+size_t send_query (void *cls, size_t size, void *buf);
/**
* Connect to the service-dns
*/
void connect_to_service_dns (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+ const struct GNUNET_SCHEDULER_TaskContext *tc);
/**
* This receives packets from the service-dns and schedules process_answer to
* handle it
*/
-void dns_answer_handler(void* cls, const struct GNUNET_MessageHeader *msg);
+void dns_answer_handler (void *cls, const struct GNUNET_MessageHeader *msg);
/**
* The connection to the service-dns
Modified: gnunet/src/vpn/gnunet-daemon-vpn-helper.c
===================================================================
--- gnunet/src/vpn/gnunet-daemon-vpn-helper.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/vpn/gnunet-daemon-vpn-helper.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -48,8 +48,8 @@
/**
* The tunnels that will be used to send tcp- and udp-packets
*/
-static struct GNUNET_MESH_Tunnel* tcp_tunnel;
-static struct GNUNET_MESH_Tunnel* udp_tunnel;
+static struct GNUNET_MESH_Tunnel *tcp_tunnel;
+static struct GNUNET_MESH_Tunnel *udp_tunnel;
/**
* Start the helper-process
@@ -59,166 +59,189 @@
* {{{
*/
void
-start_helper_and_schedule(void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc) {
+start_helper_and_schedule (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
shs_task = GNUNET_SCHEDULER_NO_TASK;
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
+ if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
+ return;
- if (cls != NULL)
- cleanup_helper(cls);
- cls = NULL;
+ if (cls != NULL)
+ cleanup_helper (cls);
+ cls = NULL;
- char* ifname;
- char* ipv6addr;
- char* ipv6prefix;
- char* ipv4addr;
- char* ipv4mask;
+ char *ifname;
+ char *ipv6addr;
+ char *ipv6prefix;
+ char *ipv4addr;
+ char *ipv4mask;
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "vpn",
"IFNAME", &ifname))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "No entry 'IFNAME' in
configuration!\n");
- exit(1);
- }
+ if (GNUNET_SYSERR ==
+ GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "IFNAME", &ifname))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "No entry 'IFNAME' in configuration!\n");
+ exit (1);
+ }
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "vpn",
"IPV6ADDR", &ipv6addr))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "No entry 'IPV6ADDR' in
configuration!\n");
- exit(1);
- }
+ if (GNUNET_SYSERR ==
+ GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "IPV6ADDR",
&ipv6addr))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "No entry 'IPV6ADDR' in configuration!\n");
+ exit (1);
+ }
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "vpn",
"IPV6PREFIX", &ipv6prefix))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "No entry 'IPV6PREFIX' in
configuration!\n");
- exit(1);
- }
+ if (GNUNET_SYSERR ==
+ GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "IPV6PREFIX",
+ &ipv6prefix))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "No entry 'IPV6PREFIX' in configuration!\n");
+ exit (1);
+ }
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "vpn",
"IPV4ADDR", &ipv4addr))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "No entry 'IPV4ADDR' in
configuration!\n");
- exit(1);
- }
+ if (GNUNET_SYSERR ==
+ GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "IPV4ADDR",
&ipv4addr))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "No entry 'IPV4ADDR' in configuration!\n");
+ exit (1);
+ }
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "vpn",
"IPV4MASK", &ipv4mask))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "No entry 'IPV4MASK' in
configuration!\n");
- exit(1);
- }
+ if (GNUNET_SYSERR ==
+ GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "IPV4MASK",
&ipv4mask))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "No entry 'IPV4MASK' in configuration!\n");
+ exit (1);
+ }
- /* Start the helper
- * Messages get passed to the function message_token
- * When the helper dies, this function will be called again with the
- * helper_handle as cls.
- */
- helper_handle = start_helper(ifname,
- ipv6addr,
- ipv6prefix,
- ipv4addr,
- ipv4mask,
- "vpn-gnunet",
- start_helper_and_schedule,
- message_token,
- NULL);
+ /* Start the helper
+ * Messages get passed to the function message_token
+ * When the helper dies, this function will be called again with the
+ * helper_handle as cls.
+ */
+ helper_handle = start_helper (ifname,
+ ipv6addr,
+ ipv6prefix,
+ ipv4addr,
+ ipv4mask,
+ "vpn-gnunet",
+ start_helper_and_schedule, message_token,
NULL);
- GNUNET_free(ipv6addr);
- GNUNET_free(ipv6prefix);
- GNUNET_free(ipv4addr);
- GNUNET_free(ipv4mask);
- GNUNET_free(ifname);
+ GNUNET_free (ipv6addr);
+ GNUNET_free (ipv6prefix);
+ GNUNET_free (ipv4addr);
+ GNUNET_free (ipv4mask);
+ GNUNET_free (ifname);
- /* Tell the dns-service to rehijack the dns-port
- * The routing-table gets flushed if an interface disappears.
- */
- restart_hijack = 1;
- if (NULL != dns_connection)
- GNUNET_CLIENT_notify_transmit_ready(dns_connection, sizeof(struct
GNUNET_MessageHeader), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, &send_query,
NULL);
+ /* Tell the dns-service to rehijack the dns-port
+ * The routing-table gets flushed if an interface disappears.
+ */
+ restart_hijack = 1;
+ if (NULL != dns_connection)
+ 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, NULL);
+ GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ helper_handle->fh_to_helper, &helper_write,
+ NULL);
}
+
/*}}}*/
/**
* Send an dns-answer-packet to the helper
*/
void
-helper_write(void* cls __attribute__((unused)), const struct
GNUNET_SCHEDULER_TaskContext* tsdkctx) {
- if (tsdkctx->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)
- return;
+helper_write (void *cls
+ __attribute__ ((unused)),
+ const struct GNUNET_SCHEDULER_TaskContext *tsdkctx)
+{
+ if (tsdkctx->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)
+ return;
- struct answer_packet_list* ans = answer_proc_head;
+ struct answer_packet_list *ans = answer_proc_head;
- if (NULL == ans) return;
+ if (NULL == ans)
+ return;
- size_t len = ntohs(ans->pkt.hdr.size);
+ size_t len = ntohs (ans->pkt.hdr.size);
- GNUNET_assert(ans->pkt.subtype == GNUNET_DNS_ANSWER_TYPE_IP);
+ GNUNET_assert (ans->pkt.subtype == GNUNET_DNS_ANSWER_TYPE_IP);
- GNUNET_assert (20 == sizeof (struct ip_hdr));
- GNUNET_assert (8 == sizeof (struct udp_pkt));
- size_t data_len = len - sizeof(struct answer_packet) + 1;
- size_t net_len = sizeof(struct ip_hdr) + sizeof(struct udp_dns) + data_len;
- size_t pkt_len = sizeof(struct GNUNET_MessageHeader) + sizeof(struct
pkt_tun) + net_len;
+ GNUNET_assert (20 == sizeof (struct ip_hdr));
+ GNUNET_assert (8 == sizeof (struct udp_pkt));
+ size_t data_len = len - sizeof (struct answer_packet) + 1;
+ size_t net_len = sizeof (struct ip_hdr) + sizeof (struct udp_dns) + data_len;
+ size_t 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);
+ struct ip_udp_dns *pkt = alloca (pkt_len);
- /* set the gnunet-header */
- pkt->shdr.size = htons(pkt_len);
- pkt->shdr.type = htons(GNUNET_MESSAGE_TYPE_VPN_HELPER);
+ GNUNET_assert (pkt != NULL);
+ memset (pkt, 0, pkt_len);
- /* set the tun-header (no flags and ethertype of IPv4) */
- pkt->tun.flags = 0;
- pkt->tun.type = htons(0x0800);
+ /* set the gnunet-header */
+ pkt->shdr.size = htons (pkt_len);
+ pkt->shdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
- /* 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 = 0x11; /* UDP */
- pkt->ip_hdr.chks = 0; /* Will be calculated later*/
- pkt->ip_hdr.sadr = ans->pkt.from;
- pkt->ip_hdr.dadr = ans->pkt.to;
+ /* set the tun-header (no flags and ethertype of IPv4) */
+ pkt->tun.flags = 0;
+ pkt->tun.type = htons (0x0800);
- pkt->ip_hdr.chks = calculate_ip_checksum((uint16_t*)&pkt->ip_hdr, 5*4);
+ /* 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 = 0x11; /* UDP */
+ pkt->ip_hdr.chks = 0; /* Will be calculated later */
+ pkt->ip_hdr.sadr = ans->pkt.from;
+ pkt->ip_hdr.dadr = ans->pkt.to;
- /* 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 */
+ pkt->ip_hdr.chks = calculate_ip_checksum ((uint16_t *) & pkt->ip_hdr, 5 * 4);
- memcpy(&pkt->udp_dns.data, ans->pkt.data, data_len);
+ /* 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 */
- GNUNET_CONTAINER_DLL_remove (answer_proc_head, answer_proc_tail, ans);
- GNUNET_free(ans);
+ memcpy (&pkt->udp_dns.data, ans->pkt.data, data_len);
- if (GNUNET_DISK_file_write(helper_handle->fh_to_helper, pkt, pkt_len) < 0)
- {
- cleanup_helper(helper_handle);
- GNUNET_SCHEDULER_add_now(start_helper_and_schedule, NULL);
- return;
- }
+ GNUNET_CONTAINER_DLL_remove (answer_proc_head, answer_proc_tail, ans);
+ GNUNET_free (ans);
- /* if more packets are available, reschedule */
- if (answer_proc_head != NULL)
- GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
- helper_handle->fh_to_helper,
- &helper_write,
- NULL);
+ if (GNUNET_DISK_file_write (helper_handle->fh_to_helper, pkt, pkt_len) < 0)
+ {
+ cleanup_helper (helper_handle);
+ GNUNET_SCHEDULER_add_now (start_helper_and_schedule, NULL);
+ return;
+ }
+
+ /* if more packets are available, reschedule */
+ if (answer_proc_head != NULL)
+ GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ helper_handle->fh_to_helper,
+ &helper_write, NULL);
}
/**
* Receive packets from the helper-process
*/
void
-message_token (void *cls __attribute__((unused)),
- void *client __attribute__((unused)), const struct
GNUNET_MessageHeader *message)
+message_token (void *cls __attribute__ ((unused)),
+ void *client
+ __attribute__ ((unused)),
+ const struct GNUNET_MessageHeader *message)
{
GNUNET_assert (ntohs (message->type) == GNUNET_MESSAGE_TYPE_VPN_HELPER);
@@ -227,374 +250,367 @@
/* ethertype is ipv6 */
if (ntohs (pkt_tun->tun.type) == 0x86dd)
+ {
+ struct ip6_pkt *pkt6 = (struct ip6_pkt *) message;
+
+ GNUNET_assert (pkt6->ip6_hdr.version == 6);
+ struct ip6_tcp *pkt6_tcp;
+ struct ip6_udp *pkt6_udp;
+ struct ip6_icmp *pkt6_icmp;
+
+ switch (pkt6->ip6_hdr.nxthdr)
{
- struct ip6_pkt *pkt6 = (struct ip6_pkt *) message;
- GNUNET_assert (pkt6->ip6_hdr.version == 6);
- struct ip6_tcp *pkt6_tcp;
- struct ip6_udp *pkt6_udp;
- struct ip6_icmp *pkt6_icmp;
+ case 0x06: /* TCP */
+ case 0x11: /* UDP */
+ pkt6_tcp = (struct ip6_tcp *) pkt6;
+ pkt6_udp = (struct ip6_udp *) pkt6;
- switch (pkt6->ip6_hdr.nxthdr)
- {
- case 0x06: /* TCP */
- case 0x11: /* UDP */
- pkt6_tcp = (struct ip6_tcp *) pkt6;
- pkt6_udp = (struct ip6_udp *) pkt6;
+ if ((key = address6_mapping_exists (pkt6->ip6_hdr.dadr)) != NULL)
+ {
+ struct map_entry *me = GNUNET_CONTAINER_multihashmap_get (hashmap,
key);
- if ((key = address6_mapping_exists (pkt6->ip6_hdr.dadr)) != NULL)
- {
- struct map_entry *me =
- GNUNET_CONTAINER_multihashmap_get (hashmap, key);
- GNUNET_assert (me != NULL);
- GNUNET_free (key);
+ GNUNET_assert (me != NULL);
+ GNUNET_free (key);
- size_t size =
- sizeof (struct GNUNET_MESH_Tunnel *) +
- sizeof (struct GNUNET_MessageHeader) +
- sizeof (GNUNET_HashCode) + ntohs (pkt6->ip6_hdr.paylgth);
+ size_t size =
+ sizeof (struct GNUNET_MESH_Tunnel *) +
+ sizeof (struct GNUNET_MessageHeader) +
+ sizeof (GNUNET_HashCode) + ntohs (pkt6->ip6_hdr.paylgth);
- struct GNUNET_MESH_Tunnel **cls = GNUNET_malloc (size);
- struct GNUNET_MessageHeader *hdr =
- (struct GNUNET_MessageHeader *) (cls + 1);
- GNUNET_HashCode *hc = (GNUNET_HashCode *) (hdr + 1);
+ struct GNUNET_MESH_Tunnel **cls = GNUNET_malloc (size);
+ struct GNUNET_MessageHeader *hdr =
+ (struct GNUNET_MessageHeader *) (cls + 1);
+ GNUNET_HashCode *hc = (GNUNET_HashCode *) (hdr + 1);
- hdr->size = htons (sizeof (struct GNUNET_MessageHeader) +
- sizeof (GNUNET_HashCode) +
- ntohs (pkt6->ip6_hdr.paylgth));
+ hdr->size = htons (sizeof (struct GNUNET_MessageHeader) +
+ sizeof (GNUNET_HashCode) +
+ ntohs (pkt6->ip6_hdr.paylgth));
- GNUNET_MESH_ApplicationType app_type;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "me->addrlen is %d\n",
me->addrlen);
- if (me->addrlen == 0)
- {
- /* This is a mapping to a gnunet-service */
- memcpy (hc, &me->desc.service_descriptor,
- sizeof (GNUNET_HashCode));
+ GNUNET_MESH_ApplicationType app_type;
- if (0x11 == pkt6->ip6_hdr.nxthdr
- && (me->desc.
- service_type & htonl (GNUNET_DNS_SERVICE_TYPE_UDP))
- && (port_in_ports (me->desc.ports, pkt6_udp->udp_hdr.dpt)
- || testBit (me->additional_ports,
- ntohs (pkt6_udp->udp_hdr.dpt))))
- {
- hdr->type = ntohs (GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "me->addrlen is %d\n",
+ me->addrlen);
+ if (me->addrlen == 0)
+ {
+ /* This is a mapping to a gnunet-service */
+ memcpy (hc, &me->desc.service_descriptor, sizeof (GNUNET_HashCode));
- memcpy (hc + 1, &pkt6_udp->udp_hdr,
- ntohs (pkt6_udp->udp_hdr.len));
+ if (0x11 == pkt6->ip6_hdr.nxthdr
+ && (me->desc.service_type & htonl (GNUNET_DNS_SERVICE_TYPE_UDP))
+ && (port_in_ports (me->desc.ports, pkt6_udp->udp_hdr.dpt)
+ || testBit (me->additional_ports,
+ ntohs (pkt6_udp->udp_hdr.dpt))))
+ {
+ hdr->type = ntohs (GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP);
- }
- else if (0x06 == pkt6->ip6_hdr.nxthdr
- && (me->desc.
- service_type & htonl
(GNUNET_DNS_SERVICE_TYPE_TCP))
- &&
- (port_in_ports (me->desc.ports,
pkt6_tcp->tcp_hdr.dpt)))
- {
- hdr->type = ntohs (GNUNET_MESSAGE_TYPE_VPN_SERVICE_TCP);
+ memcpy (hc + 1, &pkt6_udp->udp_hdr, ntohs (pkt6_udp->udp_hdr.len));
- memcpy (hc + 1, &pkt6_tcp->tcp_hdr,
- ntohs (pkt6->ip6_hdr.paylgth));
+ }
+ else if (0x06 == pkt6->ip6_hdr.nxthdr
+ && (me->desc.
+ service_type & htonl (GNUNET_DNS_SERVICE_TYPE_TCP)) &&
+ (port_in_ports (me->desc.ports, pkt6_tcp->tcp_hdr.dpt)))
+ {
+ hdr->type = ntohs (GNUNET_MESSAGE_TYPE_VPN_SERVICE_TCP);
- }
- if (me->tunnel == NULL && NULL != cls)
- {
- *cls =
- GNUNET_MESH_peer_request_connect_all (mesh_handle,
-
GNUNET_TIME_UNIT_FOREVER_REL,
- 1,
- (struct
-
GNUNET_PeerIdentity
- *)
&me->desc.peer,
- send_pkt_to_peer,
- NULL, cls);
- me->tunnel = *cls;
- }
- else if (NULL != cls)
- {
- *cls = me->tunnel;
- send_pkt_to_peer (cls, (struct GNUNET_PeerIdentity *) 1,
- NULL);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Queued to send to peer %x, type %d\n",
- *((unsigned int *) &me->desc.peer),
ntohs(hdr->type));
- }
- }
- else
- {
- /* This is a mapping to a "real" address */
- struct remote_addr *s = (struct remote_addr*) hc;
- s->addrlen = me->addrlen;
- memcpy(s->addr, me->addr, me->addrlen);
- s->proto= pkt6->ip6_hdr.nxthdr;
- if (s->proto == 0x11)
- {
- 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;
- if (NULL != udp_tunnel)
- me->tunnel = udp_tunnel;
- }
- else if (s->proto == 0x06)
- {
- hdr->type = htons(GNUNET_MESSAGE_TYPE_VPN_REMOTE_TCP);
- memcpy (hc + 1, &pkt6_tcp->tcp_hdr,
- ntohs (pkt6->ip6_hdr.paylgth));
- app_type = GNUNET_APPLICATION_TYPE_INTERNET_TCP_GATEWAY;
- if (NULL != tcp_tunnel)
- me->tunnel = tcp_tunnel;
- }
- if (me->tunnel == NULL && NULL != cls)
- {
- *cls =
GNUNET_MESH_peer_request_connect_by_type(mesh_handle,
-
GNUNET_TIME_UNIT_FOREVER_REL,
- app_type,
-
send_pkt_to_peer,
- NULL,
- cls);
- me->tunnel = *cls;
- if (GNUNET_APPLICATION_TYPE_INTERNET_UDP_GATEWAY ==
app_type)
- udp_tunnel = *cls;
- else if (GNUNET_APPLICATION_TYPE_INTERNET_TCP_GATEWAY ==
app_type)
- tcp_tunnel = *cls;
- }
- else if (NULL != cls)
- {
- *cls = me->tunnel;
- send_pkt_to_peer(cls, (struct GNUNET_PeerIdentity*) 1,
NULL);
- }
- }
- }
- else
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Packet to
%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x, which
has no mapping\n", pkt6->ip6_hdr.dadr[0],
- pkt6->ip6_hdr.dadr[1],
- pkt6->ip6_hdr.dadr[2],
- pkt6->ip6_hdr.dadr[3],
- pkt6->ip6_hdr.dadr[4],
- pkt6->ip6_hdr.dadr[5],
- pkt6->ip6_hdr.dadr[6],
- pkt6->ip6_hdr.dadr[7],
- pkt6->ip6_hdr.dadr[8],
- pkt6->ip6_hdr.dadr[9],
- pkt6->ip6_hdr.dadr[10],
- pkt6->ip6_hdr.dadr[11],
- pkt6->ip6_hdr.dadr[12],
- pkt6->ip6_hdr.dadr[13],
- pkt6->ip6_hdr.dadr[14],
- pkt6->ip6_hdr.dadr[15]);
- }
- break;
- case 0x3a:
- /* ICMPv6 */
- pkt6_icmp = (struct ip6_icmp *) pkt6;
- /* If this packet is an icmp-echo-request and a mapping exists,
answer */
- if (pkt6_icmp->icmp_hdr.type == 0x80
- && (key = address6_mapping_exists (pkt6->ip6_hdr.dadr)) != NULL)
- {
- GNUNET_free (key);
- pkt6_icmp = GNUNET_malloc (ntohs (pkt6->shdr.size));
- memcpy (pkt6_icmp, pkt6, ntohs (pkt6->shdr.size));
- GNUNET_SCHEDULER_add_now (&send_icmp6_response, pkt6_icmp);
- }
- break;
+ memcpy (hc + 1, &pkt6_tcp->tcp_hdr, ntohs (pkt6->ip6_hdr.paylgth));
+
+ }
+ if (me->tunnel == NULL && NULL != cls)
+ {
+ *cls =
+ GNUNET_MESH_peer_request_connect_all (mesh_handle,
+
GNUNET_TIME_UNIT_FOREVER_REL,
+ 1,
+ (struct
+ GNUNET_PeerIdentity
+ *) &me->desc.peer,
+ send_pkt_to_peer,
+ NULL, cls);
+ me->tunnel = *cls;
+ }
+ else if (NULL != cls)
+ {
+ *cls = me->tunnel;
+ send_pkt_to_peer (cls, (struct GNUNET_PeerIdentity *) 1, NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Queued to send to peer %x, type %d\n",
+ *((unsigned int *) &me->desc.peer), ntohs (hdr->type));
+ }
}
+ else
+ {
+ /* This is a mapping to a "real" address */
+ struct remote_addr *s = (struct remote_addr *) hc;
+
+ s->addrlen = me->addrlen;
+ memcpy (s->addr, me->addr, me->addrlen);
+ s->proto = pkt6->ip6_hdr.nxthdr;
+ if (s->proto == 0x11)
+ {
+ 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;
+ if (NULL != udp_tunnel)
+ me->tunnel = udp_tunnel;
+ }
+ else if (s->proto == 0x06)
+ {
+ hdr->type = htons (GNUNET_MESSAGE_TYPE_VPN_REMOTE_TCP);
+ memcpy (hc + 1, &pkt6_tcp->tcp_hdr, ntohs (pkt6->ip6_hdr.paylgth));
+ app_type = GNUNET_APPLICATION_TYPE_INTERNET_TCP_GATEWAY;
+ if (NULL != tcp_tunnel)
+ me->tunnel = tcp_tunnel;
+ }
+ if (me->tunnel == NULL && NULL != cls)
+ {
+ *cls = GNUNET_MESH_peer_request_connect_by_type (mesh_handle,
+
GNUNET_TIME_UNIT_FOREVER_REL,
+ app_type,
+ send_pkt_to_peer,
+ NULL, cls);
+ me->tunnel = *cls;
+ if (GNUNET_APPLICATION_TYPE_INTERNET_UDP_GATEWAY == app_type)
+ udp_tunnel = *cls;
+ else if (GNUNET_APPLICATION_TYPE_INTERNET_TCP_GATEWAY == app_type)
+ tcp_tunnel = *cls;
+ }
+ else if (NULL != cls)
+ {
+ *cls = me->tunnel;
+ send_pkt_to_peer (cls, (struct GNUNET_PeerIdentity *) 1, NULL);
+ }
+ }
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Packet to
%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x, which
has no mapping\n",
+ pkt6->ip6_hdr.dadr[0], pkt6->ip6_hdr.dadr[1],
+ pkt6->ip6_hdr.dadr[2], pkt6->ip6_hdr.dadr[3],
+ pkt6->ip6_hdr.dadr[4], pkt6->ip6_hdr.dadr[5],
+ pkt6->ip6_hdr.dadr[6], pkt6->ip6_hdr.dadr[7],
+ pkt6->ip6_hdr.dadr[8], pkt6->ip6_hdr.dadr[9],
+ pkt6->ip6_hdr.dadr[10], pkt6->ip6_hdr.dadr[11],
+ pkt6->ip6_hdr.dadr[12], pkt6->ip6_hdr.dadr[13],
+ pkt6->ip6_hdr.dadr[14], pkt6->ip6_hdr.dadr[15]);
+ }
+ break;
+ case 0x3a:
+ /* ICMPv6 */
+ pkt6_icmp = (struct ip6_icmp *) pkt6;
+ /* If this packet is an icmp-echo-request and a mapping exists, answer */
+ if (pkt6_icmp->icmp_hdr.type == 0x80
+ && (key = address6_mapping_exists (pkt6->ip6_hdr.dadr)) != NULL)
+ {
+ GNUNET_free (key);
+ pkt6_icmp = GNUNET_malloc (ntohs (pkt6->shdr.size));
+ memcpy (pkt6_icmp, pkt6, ntohs (pkt6->shdr.size));
+ GNUNET_SCHEDULER_add_now (&send_icmp6_response, pkt6_icmp);
+ }
+ break;
}
+ }
/* ethertype is ipv4 */
else if (ntohs (pkt_tun->tun.type) == 0x0800)
+ {
+ struct ip_pkt *pkt = (struct ip_pkt *) message;
+ struct ip_udp *udp = (struct ip_udp *) message;
+ struct ip_tcp *pkt_tcp;
+ struct ip_udp *pkt_udp;
+ struct ip_icmp *pkt_icmp;
+
+ GNUNET_assert (pkt->ip_hdr.version == 4);
+
+ /* Send dns-packets to the service-dns */
+ if (pkt->ip_hdr.proto == 0x11 && ntohs (udp->udp_hdr.dpt) == 53)
{
- struct ip_pkt *pkt = (struct ip_pkt *) message;
- struct ip_udp *udp = (struct ip_udp *) message;
- struct ip_tcp *pkt_tcp;
- struct ip_udp *pkt_udp;
- struct ip_icmp *pkt_icmp;
- GNUNET_assert (pkt->ip_hdr.version == 4);
+ /* 9 = 8 for the udp-header + 1 for the unsigned char data[1]; */
+ size_t len = sizeof (struct query_packet) + ntohs (udp->udp_hdr.len) - 9;
- /* Send dns-packets to the service-dns */
- if (pkt->ip_hdr.proto == 0x11 && ntohs (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 (udp->udp_hdr.len) - 9;
+ struct query_packet_list *query =
+ GNUNET_malloc (len + 2 * sizeof (struct query_packet_list *));
+ query->pkt.hdr.type = htons
(GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_QUERY_DNS);
+ query->pkt.hdr.size = htons (len);
+ query->pkt.orig_to = pkt->ip_hdr.dadr;
+ query->pkt.orig_from = pkt->ip_hdr.sadr;
+ query->pkt.src_port = udp->udp_hdr.spt;
+ memcpy (query->pkt.data, udp->data, ntohs (udp->udp_hdr.len) - 8);
- struct query_packet_list *query =
- GNUNET_malloc (len + 2 * sizeof (struct query_packet_list *));
- query->pkt.hdr.type = htons
(GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_QUERY_DNS);
- query->pkt.hdr.size = htons (len);
- query->pkt.orig_to = pkt->ip_hdr.dadr;
- query->pkt.orig_from = pkt->ip_hdr.sadr;
- query->pkt.src_port = udp->udp_hdr.spt;
- memcpy (query->pkt.data, udp->data, ntohs (udp->udp_hdr.len) - 8);
+ GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, query);
- GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, query);
+ GNUNET_assert (head != NULL);
- GNUNET_assert (head != NULL);
+ if (dns_connection != NULL)
+ GNUNET_CLIENT_notify_transmit_ready (dns_connection,
+ len,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_YES, &send_query, NULL);
+ }
+ else
+ {
+ uint32_t dadr = pkt->ip_hdr.dadr;
+ unsigned char *c = (unsigned char *) &dadr;
- if (dns_connection != NULL)
- GNUNET_CLIENT_notify_transmit_ready (dns_connection,
- len,
- GNUNET_TIME_UNIT_FOREVER_REL,
- GNUNET_YES,
- &send_query, NULL);
- }
- else
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Packet to %d.%d.%d.%d, proto %x\n",
+ c[0], c[1], c[2], c[3], pkt->ip_hdr.proto);
+ switch (pkt->ip_hdr.proto)
+ {
+ case 0x06: /* TCP */
+ case 0x11: /* UDP */
+ pkt_tcp = (struct ip_tcp *) pkt;
+ pkt_udp = (struct ip_udp *) pkt;
+
+ if ((key = address4_mapping_exists (dadr)) != NULL)
{
- uint32_t dadr = pkt->ip_hdr.dadr;
- unsigned char *c = (unsigned char*)&dadr;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Packet to %d.%d.%d.%d, proto
%x\n",
- c[0],
- c[1],
- c[2],
- c[3],
- pkt->ip_hdr.proto);
- switch (pkt->ip_hdr.proto)
- {
- case 0x06: /* TCP */
- case 0x11: /* UDP */
- pkt_tcp = (struct ip_tcp*) pkt;
- pkt_udp = (struct ip_udp*) pkt;
+ struct map_entry *me =
+ GNUNET_CONTAINER_multihashmap_get (hashmap, key);
+ GNUNET_assert (me != NULL);
+ GNUNET_free (key);
- if ((key = address4_mapping_exists (dadr)) != NULL)
- {
- struct map_entry *me =
- GNUNET_CONTAINER_multihashmap_get (hashmap, key);
- GNUNET_assert (me != NULL);
- GNUNET_free (key);
+ size_t size =
+ sizeof (struct GNUNET_MESH_Tunnel *) +
+ sizeof (struct GNUNET_MessageHeader) +
+ sizeof (GNUNET_HashCode) + ntohs (pkt->ip_hdr.tot_lngth) -
+ 4 * pkt->ip_hdr.hdr_lngth;
- size_t size =
- sizeof (struct GNUNET_MESH_Tunnel *) +
- sizeof (struct GNUNET_MessageHeader) +
- sizeof (GNUNET_HashCode) + ntohs (pkt->ip_hdr.tot_lngth) -
4*pkt->ip_hdr.hdr_lngth;
+ struct GNUNET_MESH_Tunnel **cls = GNUNET_malloc (size);
+ struct GNUNET_MessageHeader *hdr =
+ (struct GNUNET_MessageHeader *) (cls + 1);
+ GNUNET_HashCode *hc = (GNUNET_HashCode *) (hdr + 1);
- struct GNUNET_MESH_Tunnel **cls = GNUNET_malloc (size);
- struct GNUNET_MessageHeader *hdr =
- (struct GNUNET_MessageHeader *) (cls + 1);
- GNUNET_HashCode *hc = (GNUNET_HashCode *) (hdr + 1);
+ hdr->size =
+ htons (sizeof (struct GNUNET_MessageHeader) +
+ sizeof (GNUNET_HashCode) + ntohs (pkt->ip_hdr.tot_lngth) -
+ 4 * pkt->ip_hdr.hdr_lngth);
- hdr->size = htons (sizeof (struct GNUNET_MessageHeader) +
sizeof (GNUNET_HashCode) + ntohs (pkt->ip_hdr.tot_lngth) -
4*pkt->ip_hdr.hdr_lngth);
+ GNUNET_MESH_ApplicationType app_type;
- GNUNET_MESH_ApplicationType app_type;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "me->addrlen is %d\n",
me->addrlen);
- if (me->addrlen == 0)
- {
- /* This is a mapping to a gnunet-service */
- memcpy (hc, &me->desc.service_descriptor,
- sizeof (GNUNET_HashCode));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "me->addrlen is %d\n",
+ me->addrlen);
+ if (me->addrlen == 0)
+ {
+ /* This is a mapping to a gnunet-service */
+ memcpy (hc, &me->desc.service_descriptor, sizeof
(GNUNET_HashCode));
- if (0x11 == pkt->ip_hdr.proto
- && (me->desc.
- service_type & htonl
(GNUNET_DNS_SERVICE_TYPE_UDP))
- && (port_in_ports (me->desc.ports,
pkt_udp->udp_hdr.dpt)
- || testBit (me->additional_ports,
- ntohs (pkt_udp->udp_hdr.dpt))))
- {
- hdr->type = ntohs
(GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP);
+ if (0x11 == pkt->ip_hdr.proto
+ && (me->desc.service_type & htonl
(GNUNET_DNS_SERVICE_TYPE_UDP))
+ && (port_in_ports (me->desc.ports, pkt_udp->udp_hdr.dpt)
+ || testBit (me->additional_ports,
+ ntohs (pkt_udp->udp_hdr.dpt))))
+ {
+ hdr->type = ntohs (GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP);
- memcpy (hc + 1, &pkt_udp->udp_hdr,
- ntohs (pkt_udp->udp_hdr.len));
+ memcpy (hc + 1, &pkt_udp->udp_hdr, ntohs (pkt_udp->udp_hdr.len));
- }
- else if (0x06 == pkt->ip_hdr.proto
- && (me->desc.
- service_type & htonl
(GNUNET_DNS_SERVICE_TYPE_TCP))
- &&
- (port_in_ports (me->desc.ports,
pkt_tcp->tcp_hdr.dpt)))
- {
- hdr->type = ntohs
(GNUNET_MESSAGE_TYPE_VPN_SERVICE_TCP);
+ }
+ else if (0x06 == pkt->ip_hdr.proto
+ && (me->desc.service_type &
+ htonl (GNUNET_DNS_SERVICE_TYPE_TCP)) &&
+ (port_in_ports (me->desc.ports, pkt_tcp->tcp_hdr.dpt)))
+ {
+ hdr->type = ntohs (GNUNET_MESSAGE_TYPE_VPN_SERVICE_TCP);
- memcpy (hc + 1, &pkt_tcp->tcp_hdr,
- ntohs (pkt->ip_hdr.tot_lngth) -
4*pkt->ip_hdr.hdr_lngth);
+ memcpy (hc + 1, &pkt_tcp->tcp_hdr,
+ ntohs (pkt->ip_hdr.tot_lngth) -
+ 4 * pkt->ip_hdr.hdr_lngth);
- }
- if (me->tunnel == NULL && NULL != cls)
- {
- *cls =
- GNUNET_MESH_peer_request_connect_all (mesh_handle,
-
GNUNET_TIME_UNIT_FOREVER_REL,
- 1,
- (struct
-
GNUNET_PeerIdentity
- *)
&me->desc.peer,
-
send_pkt_to_peer,
- NULL, cls);
- me->tunnel = *cls;
- }
- else if (NULL != cls)
- {
- *cls = me->tunnel;
- send_pkt_to_peer (cls, (struct GNUNET_PeerIdentity
*) 1,
- NULL);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Queued to send to peer %x, type %d\n",
- *((unsigned int *) &me->desc.peer),
ntohs(hdr->type));
- }
- }
- else
- {
- /* This is a mapping to a "real" address */
- struct remote_addr *s = (struct remote_addr*) hc;
- s->addrlen = me->addrlen;
- memcpy(s->addr, me->addr, me->addrlen);
- s->proto= pkt->ip_hdr.proto;
- if (s->proto == 0x11)
- {
- hdr->type =
htons(GNUNET_MESSAGE_TYPE_VPN_REMOTE_UDP);
- memcpy (hc + 1, &pkt_udp->udp_hdr,
- ntohs (pkt_udp->udp_hdr.len));
- app_type =
GNUNET_APPLICATION_TYPE_INTERNET_UDP_GATEWAY;
- }
- else if (s->proto == 0x06)
- {
- hdr->type =
htons(GNUNET_MESSAGE_TYPE_VPN_REMOTE_TCP);
- memcpy (hc + 1, &pkt_tcp->tcp_hdr,
- ntohs (pkt->ip_hdr.tot_lngth) -
4*pkt->ip_hdr.hdr_lngth);
- app_type =
GNUNET_APPLICATION_TYPE_INTERNET_TCP_GATEWAY;
- }
- if (me->tunnel == NULL && NULL != cls)
- {
- *cls =
GNUNET_MESH_peer_request_connect_by_type(mesh_handle,
-
GNUNET_TIME_UNIT_FOREVER_REL,
-
app_type,
-
send_pkt_to_peer,
- NULL,
- cls);
- me->tunnel = *cls;
- }
- else if (NULL != cls)
- {
- *cls = me->tunnel;
- send_pkt_to_peer(cls, (struct GNUNET_PeerIdentity*)
1, NULL);
- }
- }
- }
- else
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Packet to %x which has
no mapping\n", dadr);
- }
- break;
- case 0x01:
- /* ICMP */
- pkt_icmp = (struct ip_icmp*)pkt;
- if (pkt_icmp->icmp_hdr.type == 0x8 &&
- (key = address4_mapping_exists (dadr)) != NULL)
- {
- GNUNET_free(key);
- pkt_icmp = GNUNET_malloc(ntohs(pkt->shdr.size));
- memcpy(pkt_icmp, pkt, ntohs(pkt->shdr.size));
- GNUNET_SCHEDULER_add_now (&send_icmp4_response, pkt_icmp);
- }
- break;
}
+ if (me->tunnel == NULL && NULL != cls)
+ {
+ *cls =
+ GNUNET_MESH_peer_request_connect_all (mesh_handle,
+
GNUNET_TIME_UNIT_FOREVER_REL,
+ 1,
+ (struct
+ GNUNET_PeerIdentity
+ *) &me->desc.peer,
+ send_pkt_to_peer,
+ NULL, cls);
+ me->tunnel = *cls;
+ }
+ else if (NULL != cls)
+ {
+ *cls = me->tunnel;
+ send_pkt_to_peer (cls, (struct GNUNET_PeerIdentity *) 1, NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Queued to send to peer %x, type %d\n",
+ *((unsigned int *) &me->desc.peer),
+ ntohs (hdr->type));
+ }
+ }
+ else
+ {
+ /* This is a mapping to a "real" address */
+ struct remote_addr *s = (struct remote_addr *) hc;
+
+ s->addrlen = me->addrlen;
+ memcpy (s->addr, me->addr, me->addrlen);
+ s->proto = pkt->ip_hdr.proto;
+ if (s->proto == 0x11)
+ {
+ hdr->type = htons (GNUNET_MESSAGE_TYPE_VPN_REMOTE_UDP);
+ memcpy (hc + 1, &pkt_udp->udp_hdr, ntohs (pkt_udp->udp_hdr.len));
+ app_type = GNUNET_APPLICATION_TYPE_INTERNET_UDP_GATEWAY;
+ }
+ else if (s->proto == 0x06)
+ {
+ hdr->type = htons (GNUNET_MESSAGE_TYPE_VPN_REMOTE_TCP);
+ memcpy (hc + 1, &pkt_tcp->tcp_hdr,
+ ntohs (pkt->ip_hdr.tot_lngth) -
+ 4 * pkt->ip_hdr.hdr_lngth);
+ app_type = GNUNET_APPLICATION_TYPE_INTERNET_TCP_GATEWAY;
+ }
+ if (me->tunnel == NULL && NULL != cls)
+ {
+ *cls = GNUNET_MESH_peer_request_connect_by_type (mesh_handle,
+
GNUNET_TIME_UNIT_FOREVER_REL,
+ app_type,
+
send_pkt_to_peer,
+ NULL, cls);
+ me->tunnel = *cls;
+ }
+ else if (NULL != cls)
+ {
+ *cls = me->tunnel;
+ send_pkt_to_peer (cls, (struct GNUNET_PeerIdentity *) 1, NULL);
+ }
+ }
}
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Packet to %x which has no mapping\n", dadr);
+ }
+ break;
+ case 0x01:
+ /* ICMP */
+ pkt_icmp = (struct ip_icmp *) pkt;
+ if (pkt_icmp->icmp_hdr.type == 0x8 &&
+ (key = address4_mapping_exists (dadr)) != NULL)
+ {
+ GNUNET_free (key);
+ pkt_icmp = GNUNET_malloc (ntohs (pkt->shdr.size));
+ memcpy (pkt_icmp, pkt, ntohs (pkt->shdr.size));
+ GNUNET_SCHEDULER_add_now (&send_icmp4_response, pkt_icmp);
+ }
+ break;
+ }
}
+ }
}
-void write_to_helper(void* buf, size_t len)
+void
+write_to_helper (void *buf, size_t len)
{
- (void)GNUNET_DISK_file_write(helper_handle->fh_to_helper, buf, len);
+ (void) GNUNET_DISK_file_write (helper_handle->fh_to_helper, buf, len);
}
-void schedule_helper_write(struct GNUNET_TIME_Relative time, void* cls)
+void
+schedule_helper_write (struct GNUNET_TIME_Relative time, void *cls)
{
- if (GNUNET_SCHEDULER_NO_TASK != shs_task) return;
- GNUNET_SCHEDULER_add_write_file (time, helper_handle->fh_to_helper,
&helper_write, cls);
+ if (GNUNET_SCHEDULER_NO_TASK != shs_task)
+ return;
+ GNUNET_SCHEDULER_add_write_file (time, helper_handle->fh_to_helper,
+ &helper_write, cls);
}
Modified: gnunet/src/vpn/gnunet-daemon-vpn-helper.h
===================================================================
--- gnunet/src/vpn/gnunet-daemon-vpn-helper.h 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/vpn/gnunet-daemon-vpn-helper.h 2011-08-15 21:46:35 UTC (rev
16581)
@@ -38,33 +38,35 @@
/**
* Start the helper-process
*/
-void start_helper_and_schedule(void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+void start_helper_and_schedule (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc);
/**
* Restart the helper-process
*/
-void restart_helper(void* cls, const struct GNUNET_SCHEDULER_TaskContext*
tskctx);
+void restart_helper (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tskctx);
/**
* Read from the helper-process
*/
-void helper_read(void* cls, const struct GNUNET_SCHEDULER_TaskContext*
tsdkctx);
+void helper_read (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tsdkctx);
/**
* Send an dns-answer-packet to the helper
*/
-void helper_write(void* cls, const struct GNUNET_SCHEDULER_TaskContext*
tsdkctx);
+void helper_write (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tsdkctx);
/**
* Receive packets from the helper-process
*/
-void message_token(void *cls,
- void *client,
- const struct GNUNET_MessageHeader *message);
+void message_token (void *cls,
+ void *client, const struct GNUNET_MessageHeader *message);
-void write_to_helper(void* buf, size_t len);
+void write_to_helper (void *buf, size_t len);
-void schedule_helper_write(struct GNUNET_TIME_Relative, void* cls);
+void schedule_helper_write (struct GNUNET_TIME_Relative, void *cls);
#endif /* end of include guard: GNUNET-DAEMON-VPN-HELPER_H */
Modified: gnunet/src/vpn/gnunet-daemon-vpn.c
===================================================================
--- gnunet/src/vpn/gnunet-daemon-vpn.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/vpn/gnunet-daemon-vpn.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -42,15 +42,15 @@
const struct GNUNET_CONFIGURATION_Handle *cfg;
struct GNUNET_MESH_Handle *mesh_handle;
-struct GNUNET_CONTAINER_MultiHashMap* hashmap;
+struct GNUNET_CONTAINER_MultiHashMap *hashmap;
static struct GNUNET_CONTAINER_Heap *heap;
struct tunnel_notify_queue
{
- struct tunnel_notify_queue* next;
- struct tunnel_notify_queue* prev;
+ struct tunnel_notify_queue *next;
+ struct tunnel_notify_queue *prev;
size_t len;
- void* cls;
+ void *cls;
};
/**
@@ -78,56 +78,63 @@
*{{{
*/
static void
-cleanup(void* cls __attribute__((unused)), const struct
GNUNET_SCHEDULER_TaskContext* tskctx) {
- GNUNET_assert (0 != (tskctx->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN));
+cleanup (void *cls
+ __attribute__ ((unused)),
+ const struct GNUNET_SCHEDULER_TaskContext *tskctx)
+{
+ GNUNET_assert (0 != (tskctx->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN));
- /* stop the helper */
- cleanup_helper(helper_handle);
+ /* stop the helper */
+ cleanup_helper (helper_handle);
- /* close the connection to the service-dns */
- if (dns_connection != NULL)
- {
- GNUNET_CLIENT_disconnect (dns_connection, GNUNET_NO);
- dns_connection = NULL;
- }
+ /* close the connection to the service-dns */
+ if (dns_connection != NULL)
+ {
+ GNUNET_CLIENT_disconnect (dns_connection, GNUNET_NO);
+ dns_connection = NULL;
+ }
- if (mesh_handle != NULL)
- {
- GNUNET_MESH_disconnect(mesh_handle);
- mesh_handle = NULL;
- }
- if (GNUNET_SCHEDULER_NO_TASK != shs_task)
- {
- GNUNET_SCHEDULER_cancel (shs_task);
- shs_task = GNUNET_SCHEDULER_NO_TASK;
- }
- if (GNUNET_SCHEDULER_NO_TASK != conn_task)
- {
- GNUNET_SCHEDULER_cancel (conn_task);
- conn_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ if (mesh_handle != NULL)
+ {
+ GNUNET_MESH_disconnect (mesh_handle);
+ mesh_handle = NULL;
+ }
+ if (GNUNET_SCHEDULER_NO_TASK != shs_task)
+ {
+ GNUNET_SCHEDULER_cancel (shs_task);
+ shs_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ if (GNUNET_SCHEDULER_NO_TASK != conn_task)
+ {
+ GNUNET_SCHEDULER_cancel (conn_task);
+ conn_task = GNUNET_SCHEDULER_NO_TASK;
+ }
}
+
/*}}}*/
/**
* @return the hash of the IP-Address if a mapping exists, NULL otherwise
*/
-GNUNET_HashCode*
-address6_mapping_exists(unsigned char addr[]) {
- GNUNET_HashCode* key = GNUNET_malloc(sizeof(GNUNET_HashCode));
- unsigned char* k = (unsigned char*)key;
- memset(key, 0, sizeof(GNUNET_HashCode));
- unsigned int i;
- for (i = 0; i < 16; i++)
- k[15-i] = addr[i];
+GNUNET_HashCode *
+address6_mapping_exists (unsigned char addr[])
+{
+ GNUNET_HashCode *key = GNUNET_malloc (sizeof (GNUNET_HashCode));
+ unsigned char *k = (unsigned char *) key;
- if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains(hashmap, key))
- return key;
- else
- {
- GNUNET_free(key);
- return NULL;
- }
+ memset (key, 0, sizeof (GNUNET_HashCode));
+ unsigned int i;
+
+ for (i = 0; i < 16; i++)
+ k[15 - i] = addr[i];
+
+ if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (hashmap, key))
+ return key;
+ else
+ {
+ GNUNET_free (key);
+ return NULL;
+ }
}
/**
@@ -137,10 +144,12 @@
address4_mapping_exists (uint32_t addr)
{
GNUNET_HashCode *key = GNUNET_malloc (sizeof (GNUNET_HashCode));
+
memset (key, 0, sizeof (GNUNET_HashCode));
unsigned char *c = (unsigned char *) &addr;
unsigned char *k = (unsigned char *) key;
unsigned int i;
+
for (i = 0; i < 4; i++)
k[3 - i] = c[i];
@@ -151,106 +160,116 @@
if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (hashmap, key))
return key;
else
- {
- GNUNET_free (key);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Mapping not found!\n");
- return NULL;
- }
+ {
+ GNUNET_free (key);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Mapping not found!\n");
+ return NULL;
+ }
}
static void
-collect_mappings(void* cls __attribute__((unused)), const struct
GNUNET_SCHEDULER_TaskContext* tc) {
- if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
+collect_mappings (void *cls
+ __attribute__ ((unused)),
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
+ return;
- struct map_entry* me = GNUNET_CONTAINER_heap_remove_root(heap);
+ struct map_entry *me = GNUNET_CONTAINER_heap_remove_root (heap);
- /* This is free()ed memory! */
- me->heap_node = NULL;
+ /* This is free()ed memory! */
+ me->heap_node = NULL;
- /* FIXME! GNUNET_MESH_close_tunnel(me->tunnel); */
+ /* FIXME! GNUNET_MESH_close_tunnel(me->tunnel); */
- GNUNET_CONTAINER_multihashmap_remove(hashmap, &me->hash, me);
+ GNUNET_CONTAINER_multihashmap_remove (hashmap, &me->hash, me);
- GNUNET_free(me);
+ GNUNET_free (me);
}
void
-send_icmp4_response(void* cls, const struct GNUNET_SCHEDULER_TaskContext *tc) {
- if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
+send_icmp4_response (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
+ return;
- struct ip_icmp* request = cls;
+ struct ip_icmp *request = cls;
- struct ip_icmp* response = alloca(ntohs(request->shdr.size));
- GNUNET_assert(response != NULL);
- memset(response, 0, ntohs(request->shdr.size));
+ struct ip_icmp *response = alloca (ntohs (request->shdr.size));
- response->shdr.size = request->shdr.size;
- response->shdr.type = htons(GNUNET_MESSAGE_TYPE_VPN_HELPER);
+ GNUNET_assert (response != NULL);
+ memset (response, 0, ntohs (request->shdr.size));
- response->tun.flags = 0;
- response->tun.type = htons(0x0800);
+ response->shdr.size = request->shdr.size;
+ response->shdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
- response->ip_hdr.hdr_lngth = 5;
- response->ip_hdr.version = 4;
- response->ip_hdr.proto = 0x01;
- response->ip_hdr.dadr = request->ip_hdr.sadr;
- response->ip_hdr.sadr = request->ip_hdr.dadr;
- response->ip_hdr.tot_lngth = request->ip_hdr.tot_lngth;
+ response->tun.flags = 0;
+ response->tun.type = htons (0x0800);
- response->ip_hdr.chks =
calculate_ip_checksum((uint16_t*)&response->ip_hdr, 20);
+ response->ip_hdr.hdr_lngth = 5;
+ response->ip_hdr.version = 4;
+ response->ip_hdr.proto = 0x01;
+ response->ip_hdr.dadr = request->ip_hdr.sadr;
+ response->ip_hdr.sadr = request->ip_hdr.dadr;
+ response->ip_hdr.tot_lngth = request->ip_hdr.tot_lngth;
- response->icmp_hdr.code = 0;
- response->icmp_hdr.type = 0x0;
+ response->ip_hdr.chks =
+ calculate_ip_checksum ((uint16_t *) & response->ip_hdr, 20);
- /* Magic, more Magic! */
- response->icmp_hdr.chks = request->icmp_hdr.chks + 0x8;
+ response->icmp_hdr.code = 0;
+ response->icmp_hdr.type = 0x0;
- /* Copy the rest of the packet */
- memcpy(response+1, request+1, ntohs(request->shdr.size) - sizeof(struct
ip_icmp));
+ /* Magic, more Magic! */
+ response->icmp_hdr.chks = request->icmp_hdr.chks + 0x8;
- write_to_helper(response, ntohs(response->shdr.size));
+ /* Copy the rest of the packet */
+ memcpy (response + 1, request + 1,
+ ntohs (request->shdr.size) - sizeof (struct ip_icmp));
- GNUNET_free(request);
+ write_to_helper (response, ntohs (response->shdr.size));
+
+ GNUNET_free (request);
}
void
-send_icmp6_response(void* cls, const struct GNUNET_SCHEDULER_TaskContext *tc) {
- if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
+send_icmp6_response (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
+ return;
- struct ip6_icmp* request = cls;
+ struct ip6_icmp *request = cls;
- struct ip6_icmp* response = alloca(ntohs(request->shdr.size));
- GNUNET_assert(response != NULL);
- memset(response, 0, ntohs(request->shdr.size));
+ struct ip6_icmp *response = alloca (ntohs (request->shdr.size));
- response->shdr.size = request->shdr.size;
- response->shdr.type = htons(GNUNET_MESSAGE_TYPE_VPN_HELPER);
+ GNUNET_assert (response != NULL);
+ memset (response, 0, ntohs (request->shdr.size));
- response->tun.flags = 0;
- response->tun.type = htons(0x86dd);
+ response->shdr.size = request->shdr.size;
+ response->shdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
- response->ip6_hdr.hoplmt = 255;
- response->ip6_hdr.paylgth = request->ip6_hdr.paylgth;
- response->ip6_hdr.nxthdr = 0x3a;
- response->ip6_hdr.version = 6;
- memcpy(&response->ip6_hdr.sadr, &request->ip6_hdr.dadr, 16);
- memcpy(&response->ip6_hdr.dadr, &request->ip6_hdr.sadr, 16);
+ response->tun.flags = 0;
+ response->tun.type = htons (0x86dd);
- response->icmp_hdr.code = 0;
- response->icmp_hdr.type = 0x81;
+ response->ip6_hdr.hoplmt = 255;
+ response->ip6_hdr.paylgth = request->ip6_hdr.paylgth;
+ response->ip6_hdr.nxthdr = 0x3a;
+ response->ip6_hdr.version = 6;
+ memcpy (&response->ip6_hdr.sadr, &request->ip6_hdr.dadr, 16);
+ memcpy (&response->ip6_hdr.dadr, &request->ip6_hdr.sadr, 16);
- /* Magic, more Magic! */
- response->icmp_hdr.chks = request->icmp_hdr.chks - 0x1;
+ response->icmp_hdr.code = 0;
+ response->icmp_hdr.type = 0x81;
- /* Copy the rest of the packet */
- memcpy(response+1, request+1, ntohs(request->shdr.size) - sizeof(struct
ip6_icmp));
+ /* Magic, more Magic! */
+ response->icmp_hdr.chks = request->icmp_hdr.chks - 0x1;
- write_to_helper(response, ntohs(response->shdr.size));
+ /* Copy the rest of the packet */
+ memcpy (response + 1, request + 1,
+ ntohs (request->shdr.size) - sizeof (struct ip6_icmp));
- GNUNET_free(request);
+ write_to_helper (response, ntohs (response->shdr.size));
+
+ GNUNET_free (request);
}
/**
@@ -261,38 +280,44 @@
send_pkt_to_peer_notify_callback (void *cls, size_t size, void *buf)
{
struct GNUNET_MESH_Tunnel **tunnel = cls;
- GNUNET_MESH_tunnel_set_data(*tunnel, NULL);
+
+ GNUNET_MESH_tunnel_set_data (*tunnel, NULL);
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);
+ (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);
+ size = ntohs (hdr->size);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent!\n");
- if (NULL != GNUNET_MESH_tunnel_get_head(*tunnel))
- {
- struct tunnel_notify_queue* element =
GNUNET_MESH_tunnel_get_head(*tunnel);
- struct tunnel_notify_queue* head = GNUNET_MESH_tunnel_get_head(*tunnel);
- struct tunnel_notify_queue* tail = GNUNET_MESH_tunnel_get_tail(*tunnel);
+ if (NULL != GNUNET_MESH_tunnel_get_head (*tunnel))
+ {
+ struct tunnel_notify_queue *element = GNUNET_MESH_tunnel_get_head
(*tunnel);
+ struct tunnel_notify_queue *head = GNUNET_MESH_tunnel_get_head (*tunnel);
+ struct tunnel_notify_queue *tail = GNUNET_MESH_tunnel_get_tail (*tunnel);
- GNUNET_CONTAINER_DLL_remove(head, tail, element);
+ GNUNET_CONTAINER_DLL_remove (head, tail, element);
- GNUNET_MESH_tunnel_set_head(*tunnel, head);
- GNUNET_MESH_tunnel_set_tail(*tunnel, tail);
+ GNUNET_MESH_tunnel_set_head (*tunnel, head);
+ GNUNET_MESH_tunnel_set_tail (*tunnel, tail);
- struct GNUNET_MESH_TransmitHandle* th =
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,
-
send_pkt_to_peer_notify_callback, element->cls);
- /* save the handle */
- GNUNET_MESH_tunnel_set_data(*tunnel, th);
- GNUNET_free(element);
- }
+ struct GNUNET_MESH_TransmitHandle *th =
+ 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,
+ send_pkt_to_peer_notify_callback,
+ element->cls);
+
+ /* save the handle */
+ GNUNET_MESH_tunnel_set_data (*tunnel, th);
+ GNUNET_free (element);
+ }
GNUNET_free (cls);
return size;
@@ -302,77 +327,95 @@
port_in_ports (uint64_t ports, uint16_t port)
{
uint16_t *ps = (uint16_t *) & ports;
+
return 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_TRANSPORT_ATS_Information *atsi
__attribute__((unused)))
+send_pkt_to_peer (void *cls,
+ const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi
+ __attribute__ ((unused)))
{
/* peer == NULL means that all peers in this request are connected */
- if (peer == NULL) return;
+ if (peer == NULL)
+ return;
struct GNUNET_MESH_Tunnel **tunnel = cls;
struct GNUNET_MessageHeader *hdr =
- (struct GNUNET_MessageHeader *) (tunnel + 1);
+ (struct GNUNET_MessageHeader *) (tunnel + 1);
- GNUNET_assert(NULL != tunnel);
- GNUNET_assert(NULL != *tunnel);
+ GNUNET_assert (NULL != tunnel);
+ GNUNET_assert (NULL != *tunnel);
- if (NULL == GNUNET_MESH_tunnel_get_data(*tunnel))
- {
- struct GNUNET_MESH_TransmitHandle* th =
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),
-
send_pkt_to_peer_notify_callback,
-
cls);
- GNUNET_MESH_tunnel_set_data(*tunnel, th);
- }
+ if (NULL == GNUNET_MESH_tunnel_get_data (*tunnel))
+ {
+ struct GNUNET_MESH_TransmitHandle *th =
+ 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),
+ send_pkt_to_peer_notify_callback,
+ cls);
+
+ GNUNET_MESH_tunnel_set_data (*tunnel, th);
+ }
else
- {
- struct tunnel_notify_queue* head = GNUNET_MESH_tunnel_get_head(*tunnel);
- struct tunnel_notify_queue* tail = GNUNET_MESH_tunnel_get_tail(*tunnel);
- struct tunnel_notify_queue* element = GNUNET_malloc(sizeof *element);
+ {
+ struct tunnel_notify_queue *head = GNUNET_MESH_tunnel_get_head (*tunnel);
+ struct tunnel_notify_queue *tail = GNUNET_MESH_tunnel_get_tail (*tunnel);
+ struct tunnel_notify_queue *element = GNUNET_malloc (sizeof *element);
- element->cls = cls;
- element->len = ntohs(hdr->size);
+ element->cls = cls;
+ element->len = ntohs (hdr->size);
- GNUNET_CONTAINER_DLL_insert_tail(head, tail, element);
+ GNUNET_CONTAINER_DLL_insert_tail (head, tail, element);
- GNUNET_MESH_tunnel_set_head(*tunnel, head);
- GNUNET_MESH_tunnel_set_tail(*tunnel, tail);
- }
+ GNUNET_MESH_tunnel_set_head (*tunnel, head);
+ GNUNET_MESH_tunnel_set_tail (*tunnel, tail);
+ }
}
/**
* Create a new Address from an answer-packet
*/
void
-new_ip6addr(unsigned char* buf, const GNUNET_HashCode *peer, const
GNUNET_HashCode *service_desc) { /* {{{ */
- char* ipv6addr;
- unsigned long long ipv6prefix;
- GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg,
"vpn", "IPV6ADDR", &ipv6addr));
- GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(cfg,
"vpn", "IPV6PREFIX", &ipv6prefix));
- GNUNET_assert(ipv6prefix < 127);
- ipv6prefix = (ipv6prefix + 7)/8;
+new_ip6addr (unsigned char *buf, const GNUNET_HashCode * peer,
+ const GNUNET_HashCode * service_desc)
+{ /* {{{ */
+ char *ipv6addr;
+ unsigned long long ipv6prefix;
- inet_pton (AF_INET6, ipv6addr, buf);
- GNUNET_free(ipv6addr);
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "IPV6ADDR",
+ &ipv6addr));
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_number (cfg, "vpn",
+ "IPV6PREFIX",
+ &ipv6prefix));
+ GNUNET_assert (ipv6prefix < 127);
+ ipv6prefix = (ipv6prefix + 7) / 8;
- int peer_length = 16 - ipv6prefix - 6;
- if (peer_length <= 0)
- peer_length = 0;
+ inet_pton (AF_INET6, ipv6addr, buf);
+ GNUNET_free (ipv6addr);
- int service_length = 16 - ipv6prefix - peer_length;
- if (service_length <= 0)
- service_length = 0;
+ int peer_length = 16 - ipv6prefix - 6;
- memcpy(buf+ipv6prefix, service_desc, service_length);
- memcpy(buf+ipv6prefix+service_length, peer, peer_length);
+ if (peer_length <= 0)
+ peer_length = 0;
+
+ int service_length = 16 - ipv6prefix - peer_length;
+
+ if (service_length <= 0)
+ service_length = 0;
+
+ memcpy (buf + ipv6prefix, service_desc, service_length);
+ memcpy (buf + ipv6prefix + service_length, peer, peer_length);
}
+
/*}}}*/
@@ -384,10 +427,10 @@
{ /* {{{ */
char *ipv6addr;
unsigned long long ipv6prefix;
+
GNUNET_assert (GNUNET_OK ==
GNUNET_CONFIGURATION_get_value_string (cfg, "vpn",
- "IPV6ADDR",
- &ipv6addr));
+ "IPV6ADDR",
&ipv6addr));
GNUNET_assert (GNUNET_OK ==
GNUNET_CONFIGURATION_get_value_number (cfg, "vpn",
"IPV6PREFIX",
@@ -402,6 +445,7 @@
memcpy (buf + ipv6prefix, addr, GNUNET_MIN (addrlen, local_length));
}
+
/*}}}*/
/**
@@ -412,49 +456,53 @@
{ /* {{{ */
char *ipv4addr;
char *ipv4mask;
+
GNUNET_assert (GNUNET_OK ==
GNUNET_CONFIGURATION_get_value_string (cfg, "vpn",
- "IPV4ADDR",
- &ipv4addr));
+ "IPV4ADDR",
&ipv4addr));
GNUNET_assert (GNUNET_OK ==
GNUNET_CONFIGURATION_get_value_string (cfg, "vpn",
- "IPV4MASK",
- &ipv4mask));
+ "IPV4MASK",
&ipv4mask));
uint32_t mask;
+
inet_pton (AF_INET, ipv4addr, buf);
int r = inet_pton (AF_INET, ipv4mask, &mask);
- mask = htonl(mask);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "inet_pton: %d; %m; mask: %08x\n", r,
mask);
+ mask = htonl (mask);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "inet_pton: %d; %m; mask: %08x\n", r,
+ mask);
+
GNUNET_free (ipv4addr);
int c;
if (mask)
+ {
+ mask = (mask ^ (mask - 1)) >> 1;
+ for (c = 0; mask; c++)
{
- mask = (mask ^ (mask - 1)) >> 1;
- for (c = 0; mask; c++)
- {
- mask >>= 1;
- }
+ mask >>= 1;
}
+ }
else
- {
- c = CHAR_BIT * sizeof(mask);
- }
+ {
+ c = CHAR_BIT * sizeof (mask);
+ }
- c = 32-c;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "The mask %s has %d leading 1s.\n",
ipv4mask, c);
+ c = 32 - c;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "The mask %s has %d leading 1s.\n",
+ ipv4mask, c);
GNUNET_free (ipv4mask);
if (c % 8 == 0)
c = c / 8;
else
- GNUNET_assert(0);
+ GNUNET_assert (0);
- memcpy (buf + c, addr, GNUNET_MIN (addrlen, 4-c));
+ memcpy (buf + c, addr, GNUNET_MIN (addrlen, 4 - c));
}
+
/*}}}*/
/**
@@ -465,262 +513,281 @@
* doing nothing for "real" services.
*/
void
-process_answer(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tc) {
- if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
+process_answer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
+ return;
- struct answer_packet* pkt = cls;
- struct answer_packet_list* list;
+ struct answer_packet *pkt = cls;
+ struct answer_packet_list *list;
- /* This answer is about a .gnunet-service
- *
- * It contains an almost complete DNS-Response, we have to fill in the ip
- * at the offset pkt->addroffset
+ /* This answer is about a .gnunet-service
+ *
+ * It contains an almost complete DNS-Response, we have to fill in the ip
+ * at the offset pkt->addroffset
+ */
+ if (pkt->subtype == GNUNET_DNS_ANSWER_TYPE_SERVICE)
+ {
+ pkt->subtype = GNUNET_DNS_ANSWER_TYPE_IP;
+
+ GNUNET_HashCode key;
+
+ memset (&key, 0, sizeof (GNUNET_HashCode));
+
+ unsigned char *c = ((unsigned char *) pkt) + ntohs (pkt->addroffset);
+ unsigned char *k = (unsigned char *) &key;
+
+ new_ip6addr (c, &pkt->service_descr.peer,
+ &pkt->service_descr.service_descriptor);
+ /*
+ * Copy the newly generated ip-address to the key backwarts (as only the
first part is hashed)
*/
- if (pkt->subtype == GNUNET_DNS_ANSWER_TYPE_SERVICE)
- {
- pkt->subtype = GNUNET_DNS_ANSWER_TYPE_IP;
+ unsigned int i;
- GNUNET_HashCode key;
- memset(&key, 0, sizeof(GNUNET_HashCode));
+ for (i = 0; i < 16; i++)
+ k[15 - i] = c[i];
- unsigned char* c = ((unsigned char*)pkt)+ntohs(pkt->addroffset);
- unsigned char* k = (unsigned char*)&key;
- new_ip6addr(c, &pkt->service_descr.peer,
&pkt->service_descr.service_descriptor);
- /*
- * Copy the newly generated ip-address to the key backwarts (as only
the first part is hashed)
- */
- unsigned int i;
- for (i = 0; i < 16; i++)
- k[15-i] = c[i];
+ uint16_t namelen = strlen ((char *) pkt->data + 12) + 1;
- uint16_t namelen = strlen((char*)pkt->data+12)+1;
+ struct map_entry *value =
+ GNUNET_malloc (sizeof (struct map_entry) + namelen);
+ char *name = (char *) (value + 1);
- struct map_entry* value = GNUNET_malloc(sizeof(struct map_entry) +
namelen);
- char* name = (char*)(value +1);
+ value->namelen = namelen;
+ memcpy (name, pkt->data + 12, namelen);
- value->namelen = namelen;
- memcpy(name, pkt->data+12, namelen);
+ memcpy (&value->desc, &pkt->service_descr,
+ sizeof (struct GNUNET_vpn_service_descriptor));
- memcpy(&value->desc, &pkt->service_descr, sizeof(struct
GNUNET_vpn_service_descriptor));
+ memset (value->additional_ports, 0, 8192);
- memset(value->additional_ports, 0, 8192);
+ memcpy (&value->hash, &key, sizeof (GNUNET_HashCode));
- memcpy(&value->hash, &key, sizeof(GNUNET_HashCode));
+ if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (hashmap, &key))
+ {
+ GNUNET_CONTAINER_multihashmap_put (hashmap, &key, value,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
- if (GNUNET_NO ==
- GNUNET_CONTAINER_multihashmap_contains (hashmap, &key))
- {
- GNUNET_CONTAINER_multihashmap_put (hashmap, &key, value,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+ value->heap_node = GNUNET_CONTAINER_heap_insert (heap, value,
+ GNUNET_TIME_absolute_get
+ ().abs_value);
+ if (GNUNET_CONTAINER_heap_get_size (heap) > max_mappings)
+ GNUNET_SCHEDULER_add_now (collect_mappings, NULL);
+ }
+ else
+ GNUNET_free (value);
- value->heap_node = GNUNET_CONTAINER_heap_insert (heap, value,
-
GNUNET_TIME_absolute_get ().abs_value);
- if (GNUNET_CONTAINER_heap_get_size(heap) > max_mappings)
- GNUNET_SCHEDULER_add_now(collect_mappings, NULL);
- }
- else
- GNUNET_free(value);
+ list =
+ GNUNET_malloc (htons (pkt->hdr.size) +
+ 2 * sizeof (struct answer_packet_list *));
- list = GNUNET_malloc(htons(pkt->hdr.size) + 2*sizeof(struct
answer_packet_list*));
+ memcpy (&list->pkt, pkt, htons (pkt->hdr.size));
- memcpy(&list->pkt, pkt, htons(pkt->hdr.size));
+ }
+ else if (pkt->subtype == GNUNET_DNS_ANSWER_TYPE_REV)
+ {
+ GNUNET_HashCode key;
- }
- else if (pkt->subtype == GNUNET_DNS_ANSWER_TYPE_REV)
- {
- GNUNET_HashCode key;
- memset(&key, 0, sizeof key);
- unsigned char* k = (unsigned char*)&key;
- unsigned char* s = pkt->data+12;
- int i = 0;
- /* Whoever designed the reverse IPv6-lookup is batshit insane */
- for (i = 0; i < 16; i++)
- {
- unsigned char c1 = s[(4*i)+1];
- unsigned char c2 = s[(4*i)+3];
- if (c1 <= '9')
- k[i] = c1 - '0';
- else
- k[i] = c1 - 87; /* 87 is the difference between 'a' and 10 */
- if (c2 <= '9')
- k[i] += 16*(c2 - '0');
- else
- k[i] += 16*(c2 - 87);
- }
+ memset (&key, 0, sizeof key);
+ unsigned char *k = (unsigned char *) &key;
+ unsigned char *s = pkt->data + 12;
+ int i = 0;
- struct map_entry* map_entry =
GNUNET_CONTAINER_multihashmap_get(hashmap, &key);
- uint16_t offset = ntohs(pkt->addroffset);
+ /* Whoever designed the reverse IPv6-lookup is batshit insane */
+ for (i = 0; i < 16; i++)
+ {
+ unsigned char c1 = s[(4 * i) + 1];
+ unsigned char c2 = s[(4 * i) + 3];
- if (map_entry == NULL)
- {
- GNUNET_free(pkt);
- return;
- }
+ if (c1 <= '9')
+ k[i] = c1 - '0';
+ else
+ k[i] = c1 - 87; /* 87 is the difference between 'a' and 10 */
+ if (c2 <= '9')
+ k[i] += 16 * (c2 - '0');
+ else
+ k[i] += 16 * (c2 - 87);
+ }
- GNUNET_CONTAINER_heap_update_cost (heap, map_entry->heap_node,
- GNUNET_TIME_absolute_get
().abs_value);
+ struct map_entry *map_entry =
+ GNUNET_CONTAINER_multihashmap_get (hashmap, &key);
+ uint16_t offset = ntohs (pkt->addroffset);
+ if (map_entry == NULL)
+ {
+ GNUNET_free (pkt);
+ return;
+ }
- unsigned short namelen = htons(map_entry->namelen);
- char* name = (char*)(map_entry + 1);
+ GNUNET_CONTAINER_heap_update_cost (heap, map_entry->heap_node,
+ GNUNET_TIME_absolute_get ().abs_value);
- list = GNUNET_malloc(2*sizeof(struct answer_packet_list*) + offset + 2
+ ntohs(namelen));
- struct answer_packet* rpkt = &list->pkt;
+ unsigned short namelen = htons (map_entry->namelen);
+ char *name = (char *) (map_entry + 1);
- /* The offset points to the first byte belonging to the address */
- memcpy(rpkt, pkt, offset - 1);
+ list =
+ GNUNET_malloc (2 * sizeof (struct answer_packet_list *) + offset + 2 +
+ ntohs (namelen));
- rpkt->subtype = GNUNET_DNS_ANSWER_TYPE_IP;
- rpkt->hdr.size = ntohs(offset + 2 + ntohs(namelen));
+ struct answer_packet *rpkt = &list->pkt;
- memcpy(((char*)rpkt)+offset, &namelen, 2);
- memcpy(((char*)rpkt)+offset+2, name, ntohs(namelen));
+ /* The offset points to the first byte belonging to the address */
+ memcpy (rpkt, pkt, offset - 1);
- }
- else if (pkt->subtype == GNUNET_DNS_ANSWER_TYPE_IP)
- {
- list = GNUNET_malloc(htons(pkt->hdr.size) + 2*sizeof(struct
answer_packet_list*));
- memcpy(&list->pkt, pkt, htons(pkt->hdr.size));
- }
- else if (pkt->subtype == GNUNET_DNS_ANSWER_TYPE_REMOTE_AAAA)
- {
- pkt->subtype = GNUNET_DNS_ANSWER_TYPE_IP;
+ rpkt->subtype = GNUNET_DNS_ANSWER_TYPE_IP;
+ rpkt->hdr.size = ntohs (offset + 2 + ntohs (namelen));
- GNUNET_HashCode key;
- memset(&key, 0, sizeof(GNUNET_HashCode));
+ memcpy (((char *) rpkt) + offset, &namelen, 2);
+ memcpy (((char *) rpkt) + offset + 2, name, ntohs (namelen));
- unsigned char* c = ((unsigned char*)pkt)+ntohs(pkt->addroffset);
- new_ip6addr_remote(c, pkt->addr, pkt->addrsize);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "New mapping to
%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x\n",
- c[0],
- c[1],
- c[2],
- c[3],
- c[4],
- c[5],
- c[6],
- c[7],
- c[8],
- c[9],
- c[10],
- c[11],
- c[12],
- c[13],
- c[14],
- c[15]);
- unsigned char* k = (unsigned char*)&key;
- /*
- * Copy the newly generated ip-address to the key backwards (as only
the first part is used in the hash-table)
- */
- unsigned int i;
- for (i = 0; i < 16; i++)
- k[15-i] = c[i];
+ }
+ else if (pkt->subtype == GNUNET_DNS_ANSWER_TYPE_IP)
+ {
+ list =
+ GNUNET_malloc (htons (pkt->hdr.size) +
+ 2 * sizeof (struct answer_packet_list *));
+ memcpy (&list->pkt, pkt, htons (pkt->hdr.size));
+ }
+ else if (pkt->subtype == GNUNET_DNS_ANSWER_TYPE_REMOTE_AAAA)
+ {
+ pkt->subtype = GNUNET_DNS_ANSWER_TYPE_IP;
- uint16_t namelen = strlen((char*)pkt->data+12)+1;
+ GNUNET_HashCode key;
- struct map_entry* value = GNUNET_malloc(sizeof(struct map_entry) +
namelen);
- char* name = (char*)(value +1);
+ memset (&key, 0, sizeof (GNUNET_HashCode));
- value->namelen = namelen;
- memcpy(name, pkt->data+12, namelen);
+ unsigned char *c = ((unsigned char *) pkt) + ntohs (pkt->addroffset);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Setting addrlen to %d\n",
pkt->addrsize);
- value->addrlen = pkt->addrsize;
- memcpy(&value->addr, &pkt->addr, pkt->addrsize);
- memset(value->additional_ports, 0, 8192);
+ new_ip6addr_remote (c, pkt->addr, pkt->addrsize);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "New mapping to
%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x\n",
+ c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7], c[8], c[9],
+ c[10], c[11], c[12], c[13], c[14], c[15]);
+ unsigned char *k = (unsigned char *) &key;
- memcpy(&value->hash, &key, sizeof(GNUNET_HashCode));
+ /*
+ * Copy the newly generated ip-address to the key backwards (as only the
first part is used in the hash-table)
+ */
+ unsigned int i;
- if (GNUNET_NO ==
- GNUNET_CONTAINER_multihashmap_contains (hashmap, &key))
- {
- GNUNET_CONTAINER_multihashmap_put (hashmap, &key, value,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
- value->heap_node = GNUNET_CONTAINER_heap_insert (heap, value,
-
GNUNET_TIME_absolute_get ().abs_value);
- if (GNUNET_CONTAINER_heap_get_size(heap) > max_mappings)
- GNUNET_SCHEDULER_add_now(collect_mappings, NULL);
- }
- else
- GNUNET_free(value);
+ for (i = 0; i < 16; i++)
+ k[15 - i] = c[i];
- list = GNUNET_malloc(htons(pkt->hdr.size) + 2*sizeof(struct
answer_packet_list*));
+ uint16_t namelen = strlen ((char *) pkt->data + 12) + 1;
- memcpy(&list->pkt, pkt, htons(pkt->hdr.size));
- }
- else if (pkt->subtype == GNUNET_DNS_ANSWER_TYPE_REMOTE_A)
- {
- pkt->subtype = GNUNET_DNS_ANSWER_TYPE_IP;
+ struct map_entry *value =
+ GNUNET_malloc (sizeof (struct map_entry) + namelen);
+ char *name = (char *) (value + 1);
- GNUNET_HashCode key;
- memset(&key, 0, sizeof(GNUNET_HashCode));
+ value->namelen = namelen;
+ memcpy (name, pkt->data + 12, namelen);
- unsigned char* c = ((unsigned char*)pkt)+ntohs(pkt->addroffset);
- new_ip4addr_remote(c, pkt->addr, pkt->addrsize);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "New mapping to %d.%d.%d.%d\n",
- c[0],
- c[1],
- c[2],
- c[3]);
- unsigned char* k = (unsigned char*)&key;
- /*
- * Copy the newly generated ip-address to the key backwards (as only
the first part is used in the hash-table)
- */
- unsigned int i;
- for (i = 0; i < 4; i++)
- k[3-i] = c[i];
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Setting addrlen to %d\n",
+ pkt->addrsize);
+ value->addrlen = pkt->addrsize;
+ memcpy (&value->addr, &pkt->addr, pkt->addrsize);
+ memset (value->additional_ports, 0, 8192);
- uint16_t namelen = strlen((char*)pkt->data+12)+1;
+ memcpy (&value->hash, &key, sizeof (GNUNET_HashCode));
- struct map_entry* value = GNUNET_malloc(sizeof(struct map_entry) +
namelen);
- char* name = (char*)(value +1);
+ if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (hashmap, &key))
+ {
+ GNUNET_CONTAINER_multihashmap_put (hashmap, &key, value,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+ value->heap_node = GNUNET_CONTAINER_heap_insert (heap, value,
+ GNUNET_TIME_absolute_get
+ ().abs_value);
+ if (GNUNET_CONTAINER_heap_get_size (heap) > max_mappings)
+ GNUNET_SCHEDULER_add_now (collect_mappings, NULL);
+ }
+ else
+ GNUNET_free (value);
- value->namelen = namelen;
- memcpy(name, pkt->data+12, namelen);
+ list =
+ GNUNET_malloc (htons (pkt->hdr.size) +
+ 2 * sizeof (struct answer_packet_list *));
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Setting addrlen to %d\n",
pkt->addrsize);
- value->addrlen = pkt->addrsize;
- memcpy(&value->addr, &pkt->addr, pkt->addrsize);
- memset(value->additional_ports, 0, 8192);
+ memcpy (&list->pkt, pkt, htons (pkt->hdr.size));
+ }
+ else if (pkt->subtype == GNUNET_DNS_ANSWER_TYPE_REMOTE_A)
+ {
+ pkt->subtype = GNUNET_DNS_ANSWER_TYPE_IP;
- memcpy(&value->hash, &key, sizeof(GNUNET_HashCode));
+ GNUNET_HashCode key;
- if (GNUNET_NO ==
- GNUNET_CONTAINER_multihashmap_contains (hashmap, &key))
- {
- GNUNET_CONTAINER_multihashmap_put (hashmap, &key, value,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
- value->heap_node = GNUNET_CONTAINER_heap_insert (heap, value,
-
GNUNET_TIME_absolute_get ().abs_value);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Mapping is saved in the
hashmap with key %08x.\n",
- *((uint32_t*)(&key)));
- if (GNUNET_CONTAINER_heap_get_size(heap) > max_mappings)
- GNUNET_SCHEDULER_add_now(collect_mappings, NULL);
- }
- else
- GNUNET_free(value);
+ memset (&key, 0, sizeof (GNUNET_HashCode));
- list = GNUNET_malloc(htons(pkt->hdr.size) + 2*sizeof(struct
answer_packet_list*));
+ unsigned char *c = ((unsigned char *) pkt) + ntohs (pkt->addroffset);
- memcpy(&list->pkt, pkt, htons(pkt->hdr.size));
- }
+ new_ip4addr_remote (c, pkt->addr, pkt->addrsize);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New mapping to %d.%d.%d.%d\n",
+ c[0], c[1], c[2], c[3]);
+ unsigned char *k = (unsigned char *) &key;
+
+ /*
+ * Copy the newly generated ip-address to the key backwards (as only the
first part is used in the hash-table)
+ */
+ unsigned int i;
+
+ for (i = 0; i < 4; i++)
+ k[3 - i] = c[i];
+
+ uint16_t namelen = strlen ((char *) pkt->data + 12) + 1;
+
+ struct map_entry *value =
+ GNUNET_malloc (sizeof (struct map_entry) + namelen);
+ char *name = (char *) (value + 1);
+
+ value->namelen = namelen;
+ memcpy (name, pkt->data + 12, namelen);
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Setting addrlen to %d\n",
+ pkt->addrsize);
+ value->addrlen = pkt->addrsize;
+ memcpy (&value->addr, &pkt->addr, pkt->addrsize);
+ memset (value->additional_ports, 0, 8192);
+
+ memcpy (&value->hash, &key, sizeof (GNUNET_HashCode));
+
+ if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (hashmap, &key))
+ {
+ GNUNET_CONTAINER_multihashmap_put (hashmap, &key, value,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+ value->heap_node = GNUNET_CONTAINER_heap_insert (heap, value,
+ GNUNET_TIME_absolute_get
+ ().abs_value);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Mapping is saved in the hashmap with key %08x.\n",
+ *((uint32_t *) (&key)));
+ if (GNUNET_CONTAINER_heap_get_size (heap) > max_mappings)
+ GNUNET_SCHEDULER_add_now (collect_mappings, NULL);
+ }
else
- {
- GNUNET_break(0);
- GNUNET_free(pkt);
- return;
- }
+ GNUNET_free (value);
- GNUNET_free(pkt);
+ list =
+ GNUNET_malloc (htons (pkt->hdr.size) +
+ 2 * sizeof (struct answer_packet_list *));
- GNUNET_CONTAINER_DLL_insert_after(answer_proc_head, answer_proc_tail,
answer_proc_tail, list);
+ memcpy (&list->pkt, pkt, htons (pkt->hdr.size));
+ }
+ else
+ {
+ GNUNET_break (0);
+ GNUNET_free (pkt);
+ return;
+ }
- schedule_helper_write(GNUNET_TIME_UNIT_FOREVER_REL, NULL);
+ GNUNET_free (pkt);
- return;
+ GNUNET_CONTAINER_DLL_insert_after (answer_proc_head, answer_proc_tail,
+ answer_proc_tail, list);
+
+ schedule_helper_write (GNUNET_TIME_UNIT_FOREVER_REL, NULL);
+
+ return;
}
/**
@@ -787,16 +854,18 @@
static void
add_additional_port (struct map_entry *me, uint16_t port)
{
- setBit(me->additional_ports, port);
+ setBit (me->additional_ports, port);
}
static int
receive_udp_back (void *cls
__attribute__ ((unused)), struct GNUNET_MESH_Tunnel *tunnel,
void **tunnel_ctx __attribute__ ((unused)),
- const struct GNUNET_PeerIdentity *sender __attribute__
((unused)),
+ const struct GNUNET_PeerIdentity *sender
+ __attribute__ ((unused)),
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi
__attribute__ ((unused)))
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi
+ __attribute__ ((unused)))
{
GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1);
struct remote_addr *s = (struct remote_addr *) desc;
@@ -804,167 +873,178 @@
const struct GNUNET_PeerIdentity *other = GNUNET_MESH_get_peer (tunnel);
if (16 == s->addrlen)
+ {
+ size_t size =
+ sizeof (struct ip6_udp) + ntohs (pkt->len) - 1 -
+ sizeof (struct udp_pkt);
+
+ struct ip6_udp *pkt6 = alloca (size);
+
+ GNUNET_assert (pkt6 != NULL);
+
+ if (ntohs (message->type) == GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP_BACK)
+ new_ip6addr (pkt6->ip6_hdr.sadr, &other->hashPubKey, desc);
+ else
+ new_ip6addr_remote (pkt6->ip6_hdr.sadr, s->addr, s->addrlen);
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Relaying calc:%d gnu:%d udp:%d bytes!\n", size,
+ ntohs (message->size), ntohs (pkt->len));
+
+ pkt6->shdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
+ pkt6->shdr.size = htons (size);
+
+ pkt6->tun.flags = 0;
+ pkt6->tun.type = htons (0x86dd);
+
+ pkt6->ip6_hdr.version = 6;
+ pkt6->ip6_hdr.tclass_h = 0;
+ pkt6->ip6_hdr.tclass_l = 0;
+ pkt6->ip6_hdr.flowlbl = 0;
+ pkt6->ip6_hdr.paylgth = pkt->len;
+ pkt6->ip6_hdr.nxthdr = 0x11;
+ pkt6->ip6_hdr.hoplmt = 0xff;
+
{
- size_t size =
- sizeof (struct ip6_udp) + ntohs (pkt->len) - 1 - sizeof (struct
udp_pkt);
+ char *ipv6addr;
- struct ip6_udp *pkt6 = alloca (size);
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_string (cfg, "vpn",
+ "IPV6ADDR",
+ &ipv6addr));
+ inet_pton (AF_INET6, ipv6addr, pkt6->ip6_hdr.dadr);
+ GNUNET_free (ipv6addr);
+ }
+ memcpy (&pkt6->udp_hdr, pkt, ntohs (pkt->len));
- GNUNET_assert (pkt6 != NULL);
+ GNUNET_HashCode *key = address6_mapping_exists (pkt6->ip6_hdr.sadr);
- if (ntohs (message->type) == GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP_BACK)
- new_ip6addr (pkt6->ip6_hdr.sadr, &other->hashPubKey, desc);
- else
- new_ip6addr_remote (pkt6->ip6_hdr.sadr, s->addr, s->addrlen);
+ GNUNET_assert (key != NULL);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Relaying calc:%d gnu:%d udp:%d bytes!\n", size,
- ntohs (message->size), ntohs (pkt->len));
+ struct map_entry *me = GNUNET_CONTAINER_multihashmap_get (hashmap, key);
- pkt6->shdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
- pkt6->shdr.size = htons (size);
+ GNUNET_CONTAINER_heap_update_cost (heap, me->heap_node,
+ GNUNET_TIME_absolute_get ().abs_value);
- pkt6->tun.flags = 0;
- pkt6->tun.type = htons (0x86dd);
+ GNUNET_free (key);
- pkt6->ip6_hdr.version = 6;
- pkt6->ip6_hdr.tclass_h = 0;
- pkt6->ip6_hdr.tclass_l = 0;
- pkt6->ip6_hdr.flowlbl = 0;
- pkt6->ip6_hdr.paylgth = pkt->len;
- pkt6->ip6_hdr.nxthdr = 0x11;
- pkt6->ip6_hdr.hoplmt = 0xff;
-
+ GNUNET_assert (me != NULL);
+ if (ntohs (message->type) == GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP_BACK)
+ {
+ GNUNET_assert (me->desc.
+ service_type & htonl (GNUNET_DNS_SERVICE_TYPE_UDP));
+ if (!port_in_ports (me->desc.ports, pkt6->udp_hdr.spt) &&
+ !testBit (me->additional_ports, ntohs (pkt6->udp_hdr.spt)))
{
- char *ipv6addr;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (cfg, "vpn",
- "IPV6ADDR",
- &ipv6addr));
- inet_pton (AF_INET6, ipv6addr, pkt6->ip6_hdr.dadr);
- GNUNET_free (ipv6addr);
+ add_additional_port (me, ntohs (pkt6->udp_hdr.spt));
}
- memcpy (&pkt6->udp_hdr, pkt, ntohs (pkt->len));
+ }
- GNUNET_HashCode *key = address6_mapping_exists (pkt6->ip6_hdr.sadr);
- GNUNET_assert (key != NULL);
+ pkt6->udp_hdr.crc = 0;
+ uint32_t sum = 0;
- struct map_entry *me = GNUNET_CONTAINER_multihashmap_get (hashmap, key);
- GNUNET_CONTAINER_heap_update_cost (heap, me->heap_node,
- GNUNET_TIME_absolute_get ().
- abs_value);
+ sum =
+ calculate_checksum_update (sum, (uint16_t *) & pkt6->ip6_hdr.sadr, 16);
+ sum =
+ calculate_checksum_update (sum, (uint16_t *) & pkt6->ip6_hdr.dadr, 16);
+ uint32_t tmp = (pkt6->udp_hdr.len & 0xffff);
- GNUNET_free (key);
+ sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
+ tmp = htons (((pkt6->ip6_hdr.nxthdr & 0x00ff)));
+ sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
- GNUNET_assert (me != NULL);
- if (ntohs (message->type) == GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP_BACK)
- {
- GNUNET_assert (me->desc.
- service_type & htonl (GNUNET_DNS_SERVICE_TYPE_UDP));
- if (!port_in_ports (me->desc.ports, pkt6->udp_hdr.spt)
- && !testBit (me->additional_ports, ntohs (pkt6->udp_hdr.spt)))
- {
- add_additional_port (me, ntohs (pkt6->udp_hdr.spt));
- }
- }
-
- pkt6->udp_hdr.crc = 0;
- uint32_t sum = 0;
- sum =
- calculate_checksum_update (sum, (uint16_t *) & pkt6->ip6_hdr.sadr,
- 16);
- sum =
- calculate_checksum_update (sum, (uint16_t *) & pkt6->ip6_hdr.dadr,
- 16);
- uint32_t tmp = (pkt6->udp_hdr.len & 0xffff);
- sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
- tmp = htons (((pkt6->ip6_hdr.nxthdr & 0x00ff)));
- sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
-
- sum =
+ sum =
calculate_checksum_update (sum, (uint16_t *) & pkt6->udp_hdr,
ntohs (pkt->len));
- pkt6->udp_hdr.crc = calculate_checksum_end (sum);
+ pkt6->udp_hdr.crc = calculate_checksum_end (sum);
- write_to_helper (pkt6, size);
- }
+ write_to_helper (pkt6, size);
+ }
else
- {
- size_t size =
+ {
+ size_t size =
sizeof (struct ip_udp) + ntohs (pkt->len) - 1 - sizeof (struct
udp_pkt);
- struct ip_udp *pkt4 = alloca (size);
+ struct ip_udp *pkt4 = alloca (size);
- GNUNET_assert (pkt4 != NULL);
+ GNUNET_assert (pkt4 != NULL);
- GNUNET_assert (ntohs (message->type) ==
GNUNET_MESSAGE_TYPE_VPN_REMOTE_UDP_BACK);
- uint32_t sadr;
- new_ip4addr_remote ((unsigned char*)&sadr, s->addr, s->addrlen);
- pkt4->ip_hdr.sadr = sadr;
+ GNUNET_assert (ntohs (message->type) ==
+ GNUNET_MESSAGE_TYPE_VPN_REMOTE_UDP_BACK);
+ uint32_t sadr;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Relaying calc:%d gnu:%d udp:%d bytes!\n", size,
- ntohs (message->size), ntohs (pkt->len));
+ new_ip4addr_remote ((unsigned char *) &sadr, s->addr, s->addrlen);
+ pkt4->ip_hdr.sadr = sadr;
- pkt4->shdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
- pkt4->shdr.size = htons (size);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Relaying calc:%d gnu:%d udp:%d bytes!\n", size,
+ ntohs (message->size), ntohs (pkt->len));
- pkt4->tun.flags = 0;
- pkt4->tun.type = htons (0x0800);
+ pkt4->shdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
+ pkt4->shdr.size = htons (size);
- pkt4->ip_hdr.version = 4;
- pkt4->ip_hdr.hdr_lngth = 5;
- pkt4->ip_hdr.diff_serv = 0;
- pkt4->ip_hdr.tot_lngth = htons (20 + ntohs(pkt->len));
- pkt4->ip_hdr.ident = 0;
- pkt4->ip_hdr.flags = 0;
- pkt4->ip_hdr.frag_off = 0;
- pkt4->ip_hdr.ttl = 255;
- pkt4->ip_hdr.proto = 0x11;
- pkt4->ip_hdr.chks = 0; /* Will be calculated later */
+ pkt4->tun.flags = 0;
+ pkt4->tun.type = htons (0x0800);
- {
- char *ipv4addr;
- uint32_t dadr;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (cfg, "vpn",
- "IPV4ADDR",
- &ipv4addr));
- inet_pton (AF_INET, ipv4addr, &dadr);
- GNUNET_free (ipv4addr);
- pkt4->ip_hdr.dadr = dadr;
- }
- memcpy (&pkt4->udp_hdr, pkt, ntohs (pkt->len));
+ pkt4->ip_hdr.version = 4;
+ pkt4->ip_hdr.hdr_lngth = 5;
+ pkt4->ip_hdr.diff_serv = 0;
+ pkt4->ip_hdr.tot_lngth = htons (20 + ntohs (pkt->len));
+ pkt4->ip_hdr.ident = 0;
+ pkt4->ip_hdr.flags = 0;
+ pkt4->ip_hdr.frag_off = 0;
+ pkt4->ip_hdr.ttl = 255;
+ pkt4->ip_hdr.proto = 0x11;
+ pkt4->ip_hdr.chks = 0; /* Will be calculated later */
- GNUNET_HashCode *key = address4_mapping_exists (pkt4->ip_hdr.sadr);
- GNUNET_assert (key != NULL);
+ {
+ char *ipv4addr;
+ uint32_t dadr;
- struct map_entry *me = GNUNET_CONTAINER_multihashmap_get (hashmap, key);
- GNUNET_CONTAINER_heap_update_cost (heap, me->heap_node,
- GNUNET_TIME_absolute_get ().
- abs_value);
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_string (cfg, "vpn",
+ "IPV4ADDR",
+ &ipv4addr));
+ inet_pton (AF_INET, ipv4addr, &dadr);
+ GNUNET_free (ipv4addr);
+ pkt4->ip_hdr.dadr = dadr;
+ }
+ memcpy (&pkt4->udp_hdr, pkt, ntohs (pkt->len));
- GNUNET_free (key);
+ GNUNET_HashCode *key = address4_mapping_exists (pkt4->ip_hdr.sadr);
- GNUNET_assert (me != NULL);
+ GNUNET_assert (key != NULL);
- pkt4->udp_hdr.crc = 0; /* Optional for IPv4 */
+ struct map_entry *me = GNUNET_CONTAINER_multihashmap_get (hashmap, key);
- pkt4->ip_hdr.chks =
+ GNUNET_CONTAINER_heap_update_cost (heap, me->heap_node,
+ GNUNET_TIME_absolute_get ().abs_value);
+
+ GNUNET_free (key);
+
+ GNUNET_assert (me != NULL);
+
+ pkt4->udp_hdr.crc = 0; /* Optional for IPv4 */
+
+ pkt4->ip_hdr.chks =
calculate_ip_checksum ((uint16_t *) & pkt4->ip_hdr, 5 * 4);
- write_to_helper (pkt4, size);
- }
+ write_to_helper (pkt4, size);
+ }
return GNUNET_OK;
}
static int
-receive_tcp_back (void *cls __attribute__((unused)), struct
GNUNET_MESH_Tunnel* tunnel,
- void **tunnel_ctx __attribute__((unused)),
- const struct GNUNET_PeerIdentity *sender
__attribute__((unused)),
- const struct GNUNET_MessageHeader *message,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi
__attribute__((unused)))
+receive_tcp_back (void *cls
+ __attribute__ ((unused)), struct GNUNET_MESH_Tunnel *tunnel,
+ void **tunnel_ctx
+ __attribute__ ((unused)),
+ const struct GNUNET_PeerIdentity *sender
+ __attribute__ ((unused)),
+ const struct GNUNET_MessageHeader *message,
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi
+ __attribute__ ((unused)))
{
GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1);
struct remote_addr *s = (struct remote_addr *) desc;
@@ -972,164 +1052,169 @@
const struct GNUNET_PeerIdentity *other = GNUNET_MESH_get_peer (tunnel);
size_t pktlen =
- ntohs (message->size) - sizeof (struct GNUNET_MessageHeader) -
- sizeof (GNUNET_HashCode);
+ ntohs (message->size) - sizeof (struct GNUNET_MessageHeader) -
+ sizeof (GNUNET_HashCode);
if (s->addrlen == 16)
- {
- size_t size = pktlen + sizeof (struct ip6_tcp) - 1;
+ {
+ size_t size = pktlen + sizeof (struct ip6_tcp) - 1;
- struct ip6_tcp *pkt6 = alloca (size);
- memset (pkt6, 0, size);
+ struct ip6_tcp *pkt6 = alloca (size);
- GNUNET_assert (pkt6 != NULL);
+ memset (pkt6, 0, size);
- if (ntohs (message->type) == GNUNET_MESSAGE_TYPE_VPN_SERVICE_TCP_BACK)
- new_ip6addr (pkt6->ip6_hdr.sadr, &other->hashPubKey, desc);
- else
- new_ip6addr_remote (pkt6->ip6_hdr.sadr, s->addr, s->addrlen);
+ GNUNET_assert (pkt6 != NULL);
- pkt6->shdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
- pkt6->shdr.size = htons (size);
+ if (ntohs (message->type) == GNUNET_MESSAGE_TYPE_VPN_SERVICE_TCP_BACK)
+ new_ip6addr (pkt6->ip6_hdr.sadr, &other->hashPubKey, desc);
+ else
+ new_ip6addr_remote (pkt6->ip6_hdr.sadr, s->addr, s->addrlen);
- pkt6->tun.flags = 0;
- pkt6->tun.type = htons (0x86dd);
+ pkt6->shdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
+ pkt6->shdr.size = htons (size);
- pkt6->ip6_hdr.version = 6;
- pkt6->ip6_hdr.tclass_h = 0;
- pkt6->ip6_hdr.tclass_l = 0;
- pkt6->ip6_hdr.flowlbl = 0;
- pkt6->ip6_hdr.paylgth = htons (pktlen);
- pkt6->ip6_hdr.nxthdr = 0x06;
- pkt6->ip6_hdr.hoplmt = 0xff;
+ pkt6->tun.flags = 0;
+ pkt6->tun.type = htons (0x86dd);
- {
- char *ipv6addr;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (cfg, "vpn",
- "IPV6ADDR",
- &ipv6addr));
- inet_pton (AF_INET6, ipv6addr, pkt6->ip6_hdr.dadr);
- GNUNET_free (ipv6addr);
- }
- memcpy (&pkt6->tcp_hdr, pkt, pktlen);
+ pkt6->ip6_hdr.version = 6;
+ pkt6->ip6_hdr.tclass_h = 0;
+ pkt6->ip6_hdr.tclass_l = 0;
+ pkt6->ip6_hdr.flowlbl = 0;
+ pkt6->ip6_hdr.paylgth = htons (pktlen);
+ pkt6->ip6_hdr.nxthdr = 0x06;
+ pkt6->ip6_hdr.hoplmt = 0xff;
- GNUNET_HashCode *key = address6_mapping_exists (pkt6->ip6_hdr.sadr);
- GNUNET_assert (key != NULL);
+ {
+ char *ipv6addr;
- struct map_entry *me = GNUNET_CONTAINER_multihashmap_get (hashmap, key);
- GNUNET_CONTAINER_heap_update_cost (heap, me->heap_node,
- GNUNET_TIME_absolute_get ().
- abs_value);
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_string (cfg, "vpn",
+ "IPV6ADDR",
+ &ipv6addr));
+ inet_pton (AF_INET6, ipv6addr, pkt6->ip6_hdr.dadr);
+ GNUNET_free (ipv6addr);
+ }
+ memcpy (&pkt6->tcp_hdr, pkt, pktlen);
- GNUNET_free (key);
+ GNUNET_HashCode *key = address6_mapping_exists (pkt6->ip6_hdr.sadr);
- GNUNET_assert (me != NULL);
- if (ntohs (message->type) == GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP_BACK)
- GNUNET_assert (me->desc.
- service_type & htonl (GNUNET_DNS_SERVICE_TYPE_TCP));
+ GNUNET_assert (key != NULL);
- pkt6->tcp_hdr.crc = 0;
- uint32_t sum = 0;
- uint32_t tmp;
- sum =
- calculate_checksum_update (sum, (uint16_t *) & pkt6->ip6_hdr.sadr,
- 16);
- sum =
- calculate_checksum_update (sum, (uint16_t *) & pkt6->ip6_hdr.dadr,
- 16);
- tmp = htonl (pktlen);
- sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
- tmp = htonl (((pkt6->ip6_hdr.nxthdr & 0x000000ff)));
- sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
+ struct map_entry *me = GNUNET_CONTAINER_multihashmap_get (hashmap, key);
- sum =
+ GNUNET_CONTAINER_heap_update_cost (heap, me->heap_node,
+ GNUNET_TIME_absolute_get ().abs_value);
+
+ GNUNET_free (key);
+
+ GNUNET_assert (me != NULL);
+ if (ntohs (message->type) == GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP_BACK)
+ GNUNET_assert (me->desc.
+ service_type & htonl (GNUNET_DNS_SERVICE_TYPE_TCP));
+
+ pkt6->tcp_hdr.crc = 0;
+ uint32_t sum = 0;
+ uint32_t tmp;
+
+ sum =
+ calculate_checksum_update (sum, (uint16_t *) & pkt6->ip6_hdr.sadr, 16);
+ sum =
+ calculate_checksum_update (sum, (uint16_t *) & pkt6->ip6_hdr.dadr, 16);
+ tmp = htonl (pktlen);
+ sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
+ tmp = htonl (((pkt6->ip6_hdr.nxthdr & 0x000000ff)));
+ sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
+
+ sum =
calculate_checksum_update (sum, (uint16_t *) & pkt6->tcp_hdr,
ntohs (pkt6->ip6_hdr.paylgth));
- pkt6->tcp_hdr.crc = calculate_checksum_end (sum);
+ pkt6->tcp_hdr.crc = calculate_checksum_end (sum);
- write_to_helper (pkt6, size);
- }
+ write_to_helper (pkt6, size);
+ }
else
- {
- size_t size = pktlen + sizeof (struct ip_tcp) - 1;
+ {
+ size_t size = pktlen + sizeof (struct ip_tcp) - 1;
- struct ip_tcp *pkt4 = alloca (size);
- GNUNET_assert (pkt4 != NULL);
- memset (pkt4, 0, size);
+ struct ip_tcp *pkt4 = alloca (size);
- GNUNET_assert (ntohs (message->type) ==
GNUNET_MESSAGE_TYPE_VPN_REMOTE_TCP_BACK);
- uint32_t sadr;
- new_ip4addr_remote ((unsigned char*)&sadr, s->addr, s->addrlen);
- pkt4->ip_hdr.sadr = sadr;
+ GNUNET_assert (pkt4 != NULL);
+ memset (pkt4, 0, size);
- pkt4->shdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
- pkt4->shdr.size = htons (size);
+ GNUNET_assert (ntohs (message->type) ==
+ GNUNET_MESSAGE_TYPE_VPN_REMOTE_TCP_BACK);
+ uint32_t sadr;
- pkt4->tun.flags = 0;
- pkt4->tun.type = htons (0x0800);
+ new_ip4addr_remote ((unsigned char *) &sadr, s->addr, s->addrlen);
+ pkt4->ip_hdr.sadr = sadr;
- pkt4->ip_hdr.version = 4;
- pkt4->ip_hdr.hdr_lngth = 5;
- pkt4->ip_hdr.diff_serv = 0;
- pkt4->ip_hdr.tot_lngth = htons (20 + pktlen);
- pkt4->ip_hdr.ident = 0;
- pkt4->ip_hdr.flags = 0;
- pkt4->ip_hdr.frag_off = 0;
- pkt4->ip_hdr.ttl = 255;
- pkt4->ip_hdr.proto = 0x06;
- pkt4->ip_hdr.chks = 0; /* Will be calculated later */
+ pkt4->shdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
+ pkt4->shdr.size = htons (size);
- {
- char *ipv4addr;
- uint32_t dadr;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (cfg, "vpn",
- "IPV4ADDR",
- &ipv4addr));
- inet_pton (AF_INET, ipv4addr, &dadr);
- GNUNET_free (ipv4addr);
- pkt4->ip_hdr.dadr = dadr;
- }
+ pkt4->tun.flags = 0;
+ pkt4->tun.type = htons (0x0800);
- memcpy (&pkt4->tcp_hdr, pkt, pktlen);
+ pkt4->ip_hdr.version = 4;
+ pkt4->ip_hdr.hdr_lngth = 5;
+ pkt4->ip_hdr.diff_serv = 0;
+ pkt4->ip_hdr.tot_lngth = htons (20 + pktlen);
+ pkt4->ip_hdr.ident = 0;
+ pkt4->ip_hdr.flags = 0;
+ pkt4->ip_hdr.frag_off = 0;
+ pkt4->ip_hdr.ttl = 255;
+ pkt4->ip_hdr.proto = 0x06;
+ pkt4->ip_hdr.chks = 0; /* Will be calculated later */
- GNUNET_HashCode *key = address4_mapping_exists (pkt4->ip_hdr.sadr);
- GNUNET_assert (key != NULL);
+ {
+ char *ipv4addr;
+ uint32_t dadr;
- struct map_entry *me = GNUNET_CONTAINER_multihashmap_get (hashmap, key);
- GNUNET_CONTAINER_heap_update_cost (heap, me->heap_node,
- GNUNET_TIME_absolute_get ().
- abs_value);
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_string (cfg, "vpn",
+ "IPV4ADDR",
+ &ipv4addr));
+ inet_pton (AF_INET, ipv4addr, &dadr);
+ GNUNET_free (ipv4addr);
+ pkt4->ip_hdr.dadr = dadr;
+ }
- GNUNET_free (key);
+ memcpy (&pkt4->tcp_hdr, pkt, pktlen);
- GNUNET_assert (me != NULL);
- pkt4->tcp_hdr.crc = 0;
- uint32_t sum = 0;
- uint32_t tmp;
- tmp = pkt4->ip_hdr.sadr;
- sum =
- calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
- tmp = pkt4->ip_hdr.dadr;
- sum =
- calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
+ GNUNET_HashCode *key = address4_mapping_exists (pkt4->ip_hdr.sadr);
- tmp = (0x06 << 16) | (0xffff & pktlen);
+ GNUNET_assert (key != NULL);
- tmp = htonl(tmp);
+ struct map_entry *me = GNUNET_CONTAINER_multihashmap_get (hashmap, key);
- sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
+ GNUNET_CONTAINER_heap_update_cost (heap, me->heap_node,
+ GNUNET_TIME_absolute_get ().abs_value);
- sum =
- calculate_checksum_update (sum, (uint16_t *) & pkt4->tcp_hdr, pktlen);
- pkt4->tcp_hdr.crc = calculate_checksum_end (sum);
+ GNUNET_free (key);
- pkt4->ip_hdr.chks =
+ GNUNET_assert (me != NULL);
+ pkt4->tcp_hdr.crc = 0;
+ uint32_t sum = 0;
+ uint32_t tmp;
+
+ tmp = pkt4->ip_hdr.sadr;
+ sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
+ tmp = pkt4->ip_hdr.dadr;
+ sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
+
+ tmp = (0x06 << 16) | (0xffff & pktlen);
+
+ tmp = htonl (tmp);
+
+ sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
+
+ sum = calculate_checksum_update (sum, (uint16_t *) & pkt4->tcp_hdr,
pktlen);
+ pkt4->tcp_hdr.crc = calculate_checksum_end (sum);
+
+ pkt4->ip_hdr.chks =
calculate_ip_checksum ((uint16_t *) & pkt4->ip_hdr, 5 * 4);
- write_to_helper (pkt4, size);
- }
+ write_to_helper (pkt4, size);
+ }
return GNUNET_OK;
}
@@ -1144,37 +1229,34 @@
*/
static void
run (void *cls,
- char *const *args __attribute__((unused)),
- const char *cfgfilep __attribute__((unused)),
+ char *const *args __attribute__ ((unused)),
+ const char *cfgfilep __attribute__ ((unused)),
const struct GNUNET_CONFIGURATION_Handle *cfg_)
{
- static const struct GNUNET_MESH_MessageHandler handlers[] = {
- {receive_udp_back, GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP_BACK, 0},
- {receive_tcp_back, GNUNET_MESSAGE_TYPE_VPN_SERVICE_TCP_BACK, 0},
- {receive_udp_back, GNUNET_MESSAGE_TYPE_VPN_REMOTE_UDP_BACK, 0},
- {receive_tcp_back, GNUNET_MESSAGE_TYPE_VPN_REMOTE_TCP_BACK, 0},
- {NULL, 0, 0}
- };
+ static const struct GNUNET_MESH_MessageHandler handlers[] = {
+ {receive_udp_back, GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP_BACK, 0},
+ {receive_tcp_back, GNUNET_MESSAGE_TYPE_VPN_SERVICE_TCP_BACK, 0},
+ {receive_udp_back, GNUNET_MESSAGE_TYPE_VPN_REMOTE_UDP_BACK, 0},
+ {receive_tcp_back, GNUNET_MESSAGE_TYPE_VPN_REMOTE_TCP_BACK, 0},
+ {NULL, 0, 0}
+ };
- static const GNUNET_MESH_ApplicationType types[] = {
- GNUNET_APPLICATION_TYPE_END
- };
+ static const GNUNET_MESH_ApplicationType types[] = {
+ GNUNET_APPLICATION_TYPE_END
+ };
- mesh_handle = GNUNET_MESH_connect(cfg_,
- NULL,
- NULL,
- handlers,
- types);
- cfg = cfg_;
- restart_hijack = 0;
- hashmap = GNUNET_CONTAINER_multihashmap_create(65536);
- heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
- GNUNET_CONFIGURATION_get_value_number (cfg, "vpn", "MAX_MAPPINGg",
- &max_mappings);
- udp_connections = GNUNET_CONTAINER_multihashmap_create(65536);
- conn_task = GNUNET_SCHEDULER_add_now (connect_to_service_dns, NULL);
- shs_task = GNUNET_SCHEDULER_add_after (conn_task,
start_helper_and_schedule, NULL);
- GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_FOREVER_REL, &cleanup, cls);
+ mesh_handle = GNUNET_MESH_connect (cfg_, NULL, NULL, handlers, types);
+ cfg = cfg_;
+ restart_hijack = 0;
+ hashmap = GNUNET_CONTAINER_multihashmap_create (65536);
+ heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
+ GNUNET_CONFIGURATION_get_value_number (cfg, "vpn", "MAX_MAPPINGg",
+ &max_mappings);
+ udp_connections = GNUNET_CONTAINER_multihashmap_create (65536);
+ conn_task = GNUNET_SCHEDULER_add_now (connect_to_service_dns, NULL);
+ shs_task =
+ GNUNET_SCHEDULER_add_after (conn_task, start_helper_and_schedule, NULL);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup, cls);
}
/**
@@ -1185,18 +1267,18 @@
* @return 0 ok, 1 on error
*/
int
-main (int argc, char *const *argv) {
- static const struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_OPTION_END
- };
+main (int argc, char *const *argv)
+{
+ static const struct GNUNET_GETOPT_CommandLineOption options[] = {
+ GNUNET_GETOPT_OPTION_END
+ };
- return (GNUNET_OK ==
- GNUNET_PROGRAM_run (argc,
- argv,
- "vpn",
- gettext_noop ("help text"),
- options, &run, NULL)) ? ret : 1;
+ return (GNUNET_OK ==
+ GNUNET_PROGRAM_run (argc,
+ argv,
+ "vpn",
+ gettext_noop ("help text"),
+ options, &run, NULL)) ? ret : 1;
}
/* end of gnunet-daemon-vpn.c */
-
Modified: gnunet/src/vpn/gnunet-daemon-vpn.h
===================================================================
--- gnunet/src/vpn/gnunet-daemon-vpn.h 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/vpn/gnunet-daemon-vpn.h 2011-08-15 21:46:35 UTC (rev 16581)
@@ -35,24 +35,25 @@
* At the moment this means "inventing" and IPv6-Address for .gnunet-services
and
* doing nothing for "real" services.
*/
-void
-process_answer(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tc);
+void process_answer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
-void send_icmp6_response(void* cls, const struct GNUNET_SCHEDULER_TaskContext
*tc);
-void send_icmp4_response(void* cls, const struct GNUNET_SCHEDULER_TaskContext
*tc);
+void send_icmp6_response (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc);
+void send_icmp4_response (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc);
size_t
-send_udp_service (void *cls, size_t size, void *buf);
+ send_udp_service (void *cls, size_t size, void *buf);
-GNUNET_HashCode* address6_mapping_exists(unsigned char addr[]);
-GNUNET_HashCode* address4_mapping_exists(uint32_t addr);
+GNUNET_HashCode *address6_mapping_exists (unsigned char addr[]);
+GNUNET_HashCode *address4_mapping_exists (uint32_t addr);
unsigned int port_in_ports (uint64_t ports, uint16_t port);
void
send_pkt_to_peer (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi);
+ const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi);
/**
* The configuration to use
@@ -67,22 +68,23 @@
/**
* The hashmap containing the mappings from ipv6-addresses to
gnunet-descriptors
*/
-extern struct GNUNET_CONTAINER_MultiHashMap* hashmap;
+extern struct GNUNET_CONTAINER_MultiHashMap *hashmap;
-struct map_entry {
+struct map_entry
+{
/** The description of the service (used for service) */
- struct GNUNET_vpn_service_descriptor desc;
+ struct GNUNET_vpn_service_descriptor desc;
/** The real address of the service (used for remote) */
- char addrlen;
- char addr[16];
+ char addrlen;
+ char addr[16];
- struct GNUNET_MESH_Tunnel *tunnel;
- uint16_t namelen;
- char additional_ports[8192];
+ struct GNUNET_MESH_Tunnel *tunnel;
+ uint16_t namelen;
+ char additional_ports[8192];
- struct GNUNET_CONTAINER_HeapNode* heap_node;
- GNUNET_HashCode hash;
+ struct GNUNET_CONTAINER_HeapNode *heap_node;
+ GNUNET_HashCode hash;
/**
* After this struct the name is located in DNS-Format!
*/
Modified: gnunet/src/vpn/gnunet-dns-parser.c
===================================================================
--- gnunet/src/vpn/gnunet-dns-parser.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/vpn/gnunet-dns-parser.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -11,29 +11,33 @@
* @returns The offset of the first unparsed byte (the byte right behind the
name)
*/
static unsigned int
-parse_dns_name(char* d, const unsigned char* src, unsigned short idx) {/*{{{*/
- char* dest = d;
+parse_dns_name (char *d, const unsigned char *src, unsigned short idx)
+{ /*{{{ */
+ char *dest = d;
- int len = src[idx++];
- while (len != 0)
- {
- if (len & 0xC0)
- { /* Compressed name, offset in this and the next octet */
- unsigned short offset = ((len & 0x3F) << 8) | src[idx++];
- parse_dns_name(dest, src, offset - 12); /* 12 for the Header of the
DNS-Packet, idx starts at 0 which is 12 bytes from the start of the packet */
- return idx;
- }
- memcpy(dest, src+idx, len);
- idx += len;
- dest += len;
- *dest = '.';
- dest++;
- len = src[idx++];
- };
- *dest = 0;
+ int len = src[idx++];
- return idx;
+ while (len != 0)
+ {
+ if (len & 0xC0)
+ { /* Compressed name, offset in this and the
next octet */
+ unsigned short offset = ((len & 0x3F) << 8) | src[idx++];
+
+ parse_dns_name (dest, src, offset - 12); /* 12 for the Header of the
DNS-Packet, idx starts at 0 which is 12 bytes from the start of the packet */
+ return idx;
+ }
+ memcpy (dest, src + idx, len);
+ idx += len;
+ dest += len;
+ *dest = '.';
+ dest++;
+ len = src[idx++];
+ };
+ *dest = 0;
+
+ return idx;
}
+
/*}}}*/
/**
@@ -46,116 +50,127 @@
* @returns The offset of the first unparsed byte (the byte right behind the
last record)
*/
static unsigned short
-parse_dns_record(unsigned char* data, /*{{{*/
- struct dns_record** dst,
- unsigned short count,
- unsigned short idx) {
- int i;
- unsigned short _idx;
- for (i = 0; i < count; i++) {
- dst[i] = GNUNET_malloc(sizeof(struct dns_record));
- dst[i]->name = alloca(255); // see RFC1035, no name can be longer than
this.
- char* name = dst[i]->name;
+parse_dns_record (unsigned char *data, /*{{{ */
+ struct dns_record **dst,
+ unsigned short count, unsigned short idx)
+{
+ int i;
+ unsigned short _idx;
- _idx = parse_dns_name(name, data, idx);
- dst[i]->namelen = _idx - idx;
+ for (i = 0; i < count; i++)
+ {
+ dst[i] = GNUNET_malloc (sizeof (struct dns_record));
+ dst[i]->name = alloca (255); // see RFC1035, no name can be longer
than this.
+ char *name = dst[i]->name;
- dst[i]->name = GNUNET_malloc(dst[i]->namelen);
- memcpy(dst[i]->name, name, dst[i]->namelen);
+ _idx = parse_dns_name (name, data, idx);
+ dst[i]->namelen = _idx - idx;
- idx = _idx;
+ dst[i]->name = GNUNET_malloc (dst[i]->namelen);
+ memcpy (dst[i]->name, name, dst[i]->namelen);
- dst[i]->type = *((unsigned short*)(data+idx));
- idx += 2;
- dst[i]->class = *((unsigned short*)(data+idx));
- idx += 2;
- dst[i]->ttl = *((unsigned int*)(data+idx));
- idx += 4;
- dst[i]->data_len = *((unsigned short*)(data+idx));
- idx += 2;
- dst[i]->data = GNUNET_malloc(ntohs(dst[i]->data_len));
- memcpy(dst[i]->data, data+idx, ntohs(dst[i]->data_len));
- idx += ntohs(dst[i]->data_len);
- }
- return idx;
-}/*}}}*/
+ idx = _idx;
+ dst[i]->type = *((unsigned short *) (data + idx));
+ idx += 2;
+ dst[i]->class = *((unsigned short *) (data + idx));
+ idx += 2;
+ dst[i]->ttl = *((unsigned int *) (data + idx));
+ idx += 4;
+ dst[i]->data_len = *((unsigned short *) (data + idx));
+ idx += 2;
+ dst[i]->data = GNUNET_malloc (ntohs (dst[i]->data_len));
+ memcpy (dst[i]->data, data + idx, ntohs (dst[i]->data_len));
+ idx += ntohs (dst[i]->data_len);
+ }
+ return idx;
+} /*}}} */
+
/**
* Parse a raw DNS-Packet into an usable struct
*/
-struct dns_pkt_parsed*
-parse_dns_packet(struct dns_pkt* pkt) {/*{{{*/
- struct dns_pkt_parsed* ppkt = GNUNET_malloc(sizeof(struct dns_pkt_parsed));
- memcpy(&ppkt->s, &pkt->s, sizeof pkt->s);
+struct dns_pkt_parsed *
+parse_dns_packet (struct dns_pkt *pkt)
+{ /*{{{ */
+ struct dns_pkt_parsed *ppkt = GNUNET_malloc (sizeof (struct dns_pkt_parsed));
- unsigned short qdcount = ntohs(ppkt->s.qdcount);
- unsigned short ancount = ntohs(ppkt->s.ancount);
- unsigned short nscount = ntohs(ppkt->s.nscount);
- unsigned short arcount = ntohs(ppkt->s.arcount);
+ memcpy (&ppkt->s, &pkt->s, sizeof pkt->s);
- ppkt->queries = GNUNET_malloc(qdcount*sizeof(struct dns_query*));
- ppkt->answers = GNUNET_malloc(ancount*sizeof(struct dns_record*));
- ppkt->nameservers = GNUNET_malloc(nscount*sizeof(struct dns_record*));
- ppkt->additional = GNUNET_malloc(arcount*sizeof(struct dns_record*));
+ unsigned short qdcount = ntohs (ppkt->s.qdcount);
+ unsigned short ancount = ntohs (ppkt->s.ancount);
+ unsigned short nscount = ntohs (ppkt->s.nscount);
+ unsigned short arcount = ntohs (ppkt->s.arcount);
- unsigned short idx = 0, _idx; /* This keeps track how far we have parsed
the data */
+ ppkt->queries = GNUNET_malloc (qdcount * sizeof (struct dns_query *));
+ ppkt->answers = GNUNET_malloc (ancount * sizeof (struct dns_record *));
+ ppkt->nameservers = GNUNET_malloc (nscount * sizeof (struct dns_record *));
+ ppkt->additional = GNUNET_malloc (arcount * sizeof (struct dns_record *));
- /* Parse the Query */
- int i;
- for (i = 0; i < qdcount; i++)
- { /*{{{*/
- ppkt->queries[i] = GNUNET_malloc(sizeof(struct dns_query));
- char* name = alloca(255); /* see RFC1035, it can't be more than this. */
+ unsigned short idx = 0, _idx; /* This keeps track how far we have parsed the
data */
- _idx = parse_dns_name(name, pkt->data, idx);
- ppkt->queries[i]->namelen = _idx - idx;
- idx = _idx;
+ /* Parse the Query */
+ int i;
- ppkt->queries[i]->name = GNUNET_malloc(ppkt->queries[i]->namelen);
- memcpy(ppkt->queries[i]->name, name, ppkt->queries[i]->namelen);
+ for (i = 0; i < qdcount; i++)
+ { /*{{{ */
+ ppkt->queries[i] = GNUNET_malloc (sizeof (struct dns_query));
+ char *name = alloca (255); /* see RFC1035, it can't be more than this. */
- ppkt->queries[i]->qtype = *((unsigned short*)(pkt->data+idx));
- idx += 2;
- ppkt->queries[i]->qclass = *((unsigned short*)(pkt->data+idx));
- idx += 2;
- }
- /*}}}*/
- idx = parse_dns_record(pkt->data, ppkt->answers, ancount, idx);
- idx = parse_dns_record(pkt->data, ppkt->nameservers, nscount, idx);
- idx = parse_dns_record(pkt->data, ppkt->additional, arcount, idx);
- return ppkt;
-}/*}}}*/
+ _idx = parse_dns_name (name, pkt->data, idx);
+ ppkt->queries[i]->namelen = _idx - idx;
+ idx = _idx;
+ ppkt->queries[i]->name = GNUNET_malloc (ppkt->queries[i]->namelen);
+ memcpy (ppkt->queries[i]->name, name, ppkt->queries[i]->namelen);
+
+ ppkt->queries[i]->qtype = *((unsigned short *) (pkt->data + idx));
+ idx += 2;
+ ppkt->queries[i]->qclass = *((unsigned short *) (pkt->data + idx));
+ idx += 2;
+ }
+ /*}}} */
+ idx = parse_dns_record (pkt->data, ppkt->answers, ancount, idx);
+ idx = parse_dns_record (pkt->data, ppkt->nameservers, nscount, idx);
+ idx = parse_dns_record (pkt->data, ppkt->additional, arcount, idx);
+ return ppkt;
+} /*}}} */
+
void
-free_parsed_dns_packet(struct dns_pkt_parsed* ppkt) {
- unsigned short qdcount = ntohs(ppkt->s.qdcount);
- unsigned short ancount = ntohs(ppkt->s.ancount);
- unsigned short nscount = ntohs(ppkt->s.nscount);
- unsigned short arcount = ntohs(ppkt->s.arcount);
+free_parsed_dns_packet (struct dns_pkt_parsed *ppkt)
+{
+ unsigned short qdcount = ntohs (ppkt->s.qdcount);
+ unsigned short ancount = ntohs (ppkt->s.ancount);
+ unsigned short nscount = ntohs (ppkt->s.nscount);
+ unsigned short arcount = ntohs (ppkt->s.arcount);
- int i;
- for (i = 0; i < qdcount; i++) {
- GNUNET_free(ppkt->queries[i]->name);
- GNUNET_free(ppkt->queries[i]);
- }
- GNUNET_free(ppkt->queries);
- for (i = 0; i < ancount; i++) {
- GNUNET_free(ppkt->answers[i]->name);
- GNUNET_free(ppkt->answers[i]->data);
- GNUNET_free(ppkt->answers[i]);
- }
- GNUNET_free(ppkt->answers);
- for (i = 0; i < nscount; i++) {
- GNUNET_free(ppkt->nameservers[i]->name);
- GNUNET_free(ppkt->nameservers[i]->data);
- GNUNET_free(ppkt->nameservers[i]);
- }
- GNUNET_free(ppkt->nameservers);
- for (i = 0; i < arcount; i++) {
- GNUNET_free(ppkt->additional[i]->name);
- GNUNET_free(ppkt->additional[i]->data);
- GNUNET_free(ppkt->additional[i]);
- }
- GNUNET_free(ppkt->additional);
- GNUNET_free(ppkt);
+ int i;
+
+ for (i = 0; i < qdcount; i++)
+ {
+ GNUNET_free (ppkt->queries[i]->name);
+ GNUNET_free (ppkt->queries[i]);
+ }
+ GNUNET_free (ppkt->queries);
+ for (i = 0; i < ancount; i++)
+ {
+ GNUNET_free (ppkt->answers[i]->name);
+ GNUNET_free (ppkt->answers[i]->data);
+ GNUNET_free (ppkt->answers[i]);
+ }
+ GNUNET_free (ppkt->answers);
+ for (i = 0; i < nscount; i++)
+ {
+ GNUNET_free (ppkt->nameservers[i]->name);
+ GNUNET_free (ppkt->nameservers[i]->data);
+ GNUNET_free (ppkt->nameservers[i]);
+ }
+ GNUNET_free (ppkt->nameservers);
+ for (i = 0; i < arcount; i++)
+ {
+ GNUNET_free (ppkt->additional[i]->name);
+ GNUNET_free (ppkt->additional[i]->data);
+ GNUNET_free (ppkt->additional[i]);
+ }
+ GNUNET_free (ppkt->additional);
+ GNUNET_free (ppkt);
}
Modified: gnunet/src/vpn/gnunet-dns-parser.h
===================================================================
--- gnunet/src/vpn/gnunet-dns-parser.h 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/vpn/gnunet-dns-parser.h 2011-08-15 21:46:35 UTC (rev 16581)
@@ -4,8 +4,8 @@
#include "platform.h"
#include "gnunet-vpn-packet.h"
-struct dns_pkt_parsed* parse_dns_packet(struct dns_pkt* pkt);
+struct dns_pkt_parsed *parse_dns_packet (struct dns_pkt *pkt);
-void free_parsed_dns_packet(struct dns_pkt_parsed* ppkt);
+void free_parsed_dns_packet (struct dns_pkt_parsed *ppkt);
#endif
Modified: gnunet/src/vpn/gnunet-helper-hijack-dns.c
===================================================================
--- gnunet/src/vpn/gnunet-helper-hijack-dns.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/vpn/gnunet-helper-hijack-dns.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -27,75 +27,130 @@
#include "gnunet_common.h"
-int fork_and_exec(char* file, char* cmd[]) {
- pid_t pid = fork();
- if (pid < 0) {
- fprintf(stderr, "could not fork: %s\n", strerror(errno));
- return GNUNET_SYSERR;
- }
+int
+fork_and_exec (char *file, char *cmd[])
+{
+ pid_t pid = fork ();
- int st = 0;
+ if (pid < 0)
+ {
+ fprintf (stderr, "could not fork: %s\n", strerror (errno));
+ return GNUNET_SYSERR;
+ }
- if (pid == 0) {
- execv(file, cmd);
- } else {
- waitpid(pid, &st, 0);
- }
- return WIFEXITED(st) && (WEXITSTATUS(st) == 0);
+ int st = 0;
+
+ if (pid == 0)
+ {
+ execv (file, cmd);
+ }
+ else
+ {
+ waitpid (pid, &st, 0);
+ }
+ return WIFEXITED (st) && (WEXITSTATUS (st) == 0);
}
-int main(int argc, char** argv) {
- int delete = 0;
- int port = 0;
- char* virt_dns;
- if (argc < 3) return GNUNET_SYSERR;
+int
+main (int argc, char **argv)
+{
+ int delete = 0;
+ int port = 0;
+ char *virt_dns;
- if (strncmp(argv[1], "-d", 2) == 0) {
- if (argc < 3) return GNUNET_SYSERR;
- delete = 1;
- port = atoi(argv[2]);
- virt_dns = argv[3];
- } else {
- port = atoi(argv[1]);
- virt_dns = argv[2];
- }
+ if (argc < 3)
+ return GNUNET_SYSERR;
- if (port == 0) return GNUNET_SYSERR;
+ if (strncmp (argv[1], "-d", 2) == 0)
+ {
+ if (argc < 3)
+ return GNUNET_SYSERR;
+ delete = 1;
+ port = atoi (argv[2]);
+ virt_dns = argv[3];
+ }
+ else
+ {
+ port = atoi (argv[1]);
+ virt_dns = argv[2];
+ }
- struct stat s;
- if (stat("/sbin/iptables", &s) < 0) {
- fprintf(stderr, "stat on /sbin/iptables failed: %s\n",
strerror(errno));
- return GNUNET_SYSERR;
- }
- if (stat("/sbin/ip", &s) < 0) {
- fprintf(stderr, "stat on /sbin/ip failed: %s\n",
strerror(errno));
- return GNUNET_SYSERR;
- }
+ if (port == 0)
+ return GNUNET_SYSERR;
- char localport[7];
- snprintf(localport, 7, "%d", port);
+ struct stat s;
- int r;
- if (delete) {
+ if (stat ("/sbin/iptables", &s) < 0)
+ {
+ fprintf (stderr, "stat on /sbin/iptables failed: %s\n", strerror (errno));
+ return GNUNET_SYSERR;
+ }
+ if (stat ("/sbin/ip", &s) < 0)
+ {
+ fprintf (stderr, "stat on /sbin/ip failed: %s\n", strerror (errno));
+ return GNUNET_SYSERR;
+ }
+
+ char localport[7];
+
+ snprintf (localport, 7, "%d", port);
+
+ int r;
+
+ if (delete)
+ {
e4:
- r = fork_and_exec("/sbin/ip", (char*[]){"ip", "route", "del",
"default", "via", virt_dns,"table","2", NULL});
+ r = fork_and_exec ("/sbin/ip", (char *[])
+ {
+ "ip", "route", "del", "default", "via", virt_dns,
+ "table", "2", NULL});
e3:
- r = fork_and_exec("/sbin/ip", (char*[]){"ip", "rule", "del",
"fwmark", "3", "table","2", NULL});
+ r = fork_and_exec ("/sbin/ip", (char *[])
+ {
+ "ip", "rule", "del", "fwmark", "3", "table", "2",
NULL});
e2:
- r = fork_and_exec("/sbin/iptables", (char*[]){"iptables", "-t",
"mangle", "-D", "OUTPUT", "-p", "udp", "--dport", "53", "-j", "MARK",
"--set-mark", "3", NULL});
+ r = fork_and_exec ("/sbin/iptables", (char *[])
+ {
+ "iptables", "-t", "mangle", "-D", "OUTPUT", "-p", "udp",
+ "--dport", "53", "-j", "MARK", "--set-mark", "3",
NULL});
e1:
- r = fork_and_exec("/sbin/iptables", (char*[]){"iptables", "-t",
"mangle", "-D", "OUTPUT", "-p", "udp", "--sport", localport, "--dport", "53",
"-j", "ACCEPT", NULL});
- if (!delete) r = 0;
- } else {
- r = fork_and_exec("/sbin/iptables", (char*[]){"iptables", "-t",
"mangle", "-I", "OUTPUT", "1", "-p", "udp", "--sport", localport, "--dport",
"53", "-j", "ACCEPT", NULL});
- if (!r) goto e1;
- r = fork_and_exec("/sbin/iptables", (char*[]){"iptables", "-t",
"mangle", "-I", "OUTPUT", "2", "-p", "udp", "--dport", "53", "-j", "MARK",
"--set-mark", "3", NULL});
- if (!r) goto e2;
- r = fork_and_exec("/sbin/ip", (char*[]){"ip", "rule", "add",
"fwmark", "3", "table","2", NULL});
- if (!r) goto e3;
- r = fork_and_exec("/sbin/ip", (char*[]){"ip", "route", "add",
"default", "via", virt_dns, "table","2", NULL});
- if (!r) goto e4;
- }
- if (r) return GNUNET_YES;
- return GNUNET_SYSERR;
+ r = fork_and_exec ("/sbin/iptables", (char *[])
+ {
+ "iptables", "-t", "mangle", "-D", "OUTPUT", "-p", "udp",
+ "--sport", localport, "--dport", "53", "-j", "ACCEPT",
+ NULL});
+ if (!delete)
+ r = 0;
+ }
+ else
+ {
+ r = fork_and_exec ("/sbin/iptables", (char *[])
+ {
+ "iptables", "-t", "mangle", "-I", "OUTPUT", "1", "-p",
+ "udp", "--sport", localport, "--dport", "53", "-j",
+ "ACCEPT", NULL});
+ if (!r)
+ goto e1;
+ r = fork_and_exec ("/sbin/iptables", (char *[])
+ {
+ "iptables", "-t", "mangle", "-I", "OUTPUT", "2", "-p",
+ "udp", "--dport", "53", "-j", "MARK", "--set-mark", "3",
+ NULL});
+ if (!r)
+ goto e2;
+ r = fork_and_exec ("/sbin/ip", (char *[])
+ {
+ "ip", "rule", "add", "fwmark", "3", "table", "2",
NULL});
+ if (!r)
+ goto e3;
+ r = fork_and_exec ("/sbin/ip", (char *[])
+ {
+ "ip", "route", "add", "default", "via", virt_dns,
+ "table", "2", NULL});
+ if (!r)
+ goto e4;
+ }
+ if (r)
+ return GNUNET_YES;
+ return GNUNET_SYSERR;
}
Modified: gnunet/src/vpn/gnunet-helper-vpn-api.c
===================================================================
--- gnunet/src/vpn/gnunet-helper-vpn-api.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/vpn/gnunet-helper-vpn-api.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -45,7 +45,7 @@
GNUNET_DISK_pipe_close (handle->helper_in);
GNUNET_DISK_pipe_close (handle->helper_out);
- GNUNET_SERVER_mst_destroy(handle->mst);
+ GNUNET_SERVER_mst_destroy (handle->mst);
}
extern GNUNET_SCHEDULER_TaskIdentifier shs_task;
@@ -57,6 +57,7 @@
helper_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tsdkctx)
{
struct GNUNET_VPN_HELPER_Handle *handle = cls;
+
/* no message can be bigger then 64k */
char buf[65535];
@@ -67,34 +68,32 @@
/* On read-error, restart the helper */
if (t <= 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Read error for header from vpn-helper: %m\n");
- stop_helper (handle);
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Read error for header from vpn-helper: %m\n");
+ stop_helper (handle);
- /* Restart the helper */
- shs_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
- handle->restart_task, handle);
- return;
- }
+ /* Restart the helper */
+ shs_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ handle->restart_task, handle);
+ return;
+ }
if (GNUNET_SYSERR ==
GNUNET_SERVER_mst_receive (handle->mst, handle->client, buf, t, 0, 0))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "SYSERR from mst\n");
- stop_helper (handle);
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "SYSERR from mst\n");
+ stop_helper (handle);
- /* Restart the helper */
- shs_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
- handle->restart_task, handle);
- return;
+ /* Restart the helper */
+ shs_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ handle->restart_task, handle);
+ return;
- }
+ }
GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- handle->fh_from_helper, &helper_read,
- handle);
+ handle->fh_from_helper, &helper_read,
handle);
}
void
@@ -114,7 +113,7 @@
GNUNET_SERVER_MessageTokenizerCallback cb, void *cb_cls)
{
struct GNUNET_VPN_HELPER_Handle *handle =
- GNUNET_malloc (sizeof (struct GNUNET_VPN_HELPER_Handle));
+ GNUNET_malloc (sizeof (struct GNUNET_VPN_HELPER_Handle));
handle->helper_in = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO);
handle->helper_out = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_NO, GNUNET_YES);
@@ -122,20 +121,20 @@
handle->restart_task = restart_task;
if (handle->helper_in == NULL || handle->helper_out == NULL)
- {
- GNUNET_free (handle);
- return NULL;
- }
+ {
+ GNUNET_free (handle);
+ return NULL;
+ }
handle->helper_proc =
- GNUNET_OS_start_process (handle->helper_in, handle->helper_out,
- "gnunet-helper-vpn", process_name, ifname,
- ipv6addr, ipv6prefix, ipv4addr, ipv4mask, NULL);
+ GNUNET_OS_start_process (handle->helper_in, handle->helper_out,
+ "gnunet-helper-vpn", process_name, ifname,
+ ipv6addr, ipv6prefix, ipv4addr, ipv4mask, NULL);
handle->fh_from_helper =
- GNUNET_DISK_pipe_handle (handle->helper_out, GNUNET_DISK_PIPE_END_READ);
+ GNUNET_DISK_pipe_handle (handle->helper_out, GNUNET_DISK_PIPE_END_READ);
handle->fh_to_helper =
- GNUNET_DISK_pipe_handle (handle->helper_in, GNUNET_DISK_PIPE_END_WRITE);
+ GNUNET_DISK_pipe_handle (handle->helper_in, GNUNET_DISK_PIPE_END_WRITE);
GNUNET_DISK_pipe_close_end (handle->helper_out, GNUNET_DISK_PIPE_END_WRITE);
GNUNET_DISK_pipe_close_end (handle->helper_in, GNUNET_DISK_PIPE_END_READ);
@@ -143,8 +142,7 @@
handle->mst = GNUNET_SERVER_mst_create (cb, cb_cls);
GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- handle->fh_from_helper, &helper_read,
- handle);
+ handle->fh_from_helper, &helper_read,
handle);
return handle;
}
Modified: gnunet/src/vpn/gnunet-helper-vpn.c
===================================================================
--- gnunet/src/vpn/gnunet-helper-vpn.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/vpn/gnunet-helper-vpn.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -74,23 +74,23 @@
int fd;
if (NULL == dev)
- {
- errno = EINVAL;
- return -1;
- }
+ {
+ errno = EINVAL;
+ return -1;
+ }
if (-1 == (fd = open ("/dev/net/tun", O_RDWR)))
- {
- fprintf (stderr,
- "Error opening `%s': %s\n", "/dev/net/tun", strerror (errno));
- return -1;
- }
+ {
+ fprintf (stderr,
+ "Error opening `%s': %s\n", "/dev/net/tun", strerror (errno));
+ return -1;
+ }
if (fd >= FD_SETSIZE)
- {
- fprintf (stderr, "File descriptor to large: %d", fd);
- return -1;
- }
+ {
+ fprintf (stderr, "File descriptor to large: %d", fd);
+ return -1;
+ }
memset (&ifr, 0, sizeof (ifr));
ifr.ifr_flags = IFF_TUN;
@@ -99,13 +99,13 @@
strncpy (ifr.ifr_name, dev, IFNAMSIZ);
if (-1 == ioctl (fd, TUNSETIFF, (void *) &ifr))
- {
- fprintf (stderr,
- "Error with ioctl on `%s': %s\n",
- "/dev/net/tun", strerror (errno));
- close (fd);
- return -1;
- }
+ {
+ fprintf (stderr,
+ "Error with ioctl on `%s': %s\n",
+ "/dev/net/tun", strerror (errno));
+ close (fd);
+ return -1;
+ }
strcpy (dev, ifr.ifr_name);
return fd;
}
@@ -119,9 +119,7 @@
* @param prefix_len the length of the network-prefix
*/
static void
-set_address6 (const char *dev,
- const char *address,
- unsigned long prefix_len)
+set_address6 (const char *dev, const char *address, unsigned long prefix_len)
{
struct ifreq ifr;
struct in6_ifreq ifr6;
@@ -133,25 +131,20 @@
*/
memset (&sa6, 0, sizeof (struct sockaddr_in6));
if (1 != inet_pton (AF_INET6, address, sa6.sin6_addr.s6_addr))
- {
- fprintf (stderr,
- "Failed to parse address `%s': %s\n",
- address, strerror (errno));
- exit (1);
- }
+ {
+ fprintf (stderr,
+ "Failed to parse address `%s': %s\n", address, strerror (errno));
+ exit (1);
+ }
if (-1 == (fd = socket (PF_INET6, SOCK_DGRAM, 0)))
- {
- fprintf (stderr,
- "Error creating socket: %s\n",
- strerror (errno));
- exit (1);
- }
+ {
+ fprintf (stderr, "Error creating socket: %s\n", strerror (errno));
+ exit (1);
+ }
sa6.sin6_family = AF_INET6;
- memcpy (&ifr6.ifr6_addr,
- &sa6.sin6_addr,
- sizeof (struct in6_addr));
+ memcpy (&ifr6.ifr6_addr, &sa6.sin6_addr, sizeof (struct in6_addr));
/*
@@ -159,13 +152,10 @@
*/
strncpy (ifr.ifr_name, dev, IFNAMSIZ);
if (-1 == ioctl (fd, SIOGIFINDEX, &ifr))
- {
- fprintf (stderr,
- "ioctl failed at %d: %s\n",
- __LINE__,
- strerror (errno));
- exit (1);
- }
+ {
+ fprintf (stderr, "ioctl failed at %d: %s\n", __LINE__, strerror (errno));
+ exit (1);
+ }
ifr6.ifr6_ifindex = ifr.ifr_ifindex;
ifr6.ifr6_prefixlen = prefix_len;
@@ -174,38 +164,38 @@
* Set the address
*/
if (-1 == ioctl (fd, SIOCSIFADDR, &ifr6))
- {
- fprintf (stderr,
- "ioctl failed at line %d: %s\n", __LINE__, strerror (errno));
- exit (1);
- }
+ {
+ fprintf (stderr,
+ "ioctl failed at line %d: %s\n", __LINE__, strerror (errno));
+ exit (1);
+ }
/*
* Get the flags
*/
if (-1 == ioctl (fd, SIOCGIFFLAGS, &ifr))
- {
- fprintf (stderr,
- "ioctl failed at line %d: %s\n", __LINE__, strerror (errno));
- exit (1);
- }
+ {
+ fprintf (stderr,
+ "ioctl failed at line %d: %s\n", __LINE__, strerror (errno));
+ exit (1);
+ }
/*
* Add the UP and RUNNING flags
*/
ifr.ifr_flags |= IFF_UP | IFF_RUNNING;
if (-1 == ioctl (fd, SIOCSIFFLAGS, &ifr))
- {
- fprintf (stderr,
- "ioctl failed at line %d: %s\n", __LINE__, strerror (errno));
- exit (1);
- }
+ {
+ fprintf (stderr,
+ "ioctl failed at line %d: %s\n", __LINE__, strerror (errno));
+ exit (1);
+ }
if (0 != close (fd))
- {
- fprintf (stderr, "close failed: %s\n", strerror (errno));
- exit (1);
- }
+ {
+ fprintf (stderr, "close failed: %s\n", strerror (errno));
+ exit (1);
+ }
}
@@ -217,9 +207,7 @@
* @param mask the netmask
*/
static void
-set_address4 (const char *dev,
- const char *address,
- const char *mask)
+set_address4 (const char *dev, const char *address, const char *mask)
{
int fd;
struct sockaddr_in *addr;
@@ -235,21 +223,18 @@
* Parse the address
*/
if (1 != inet_pton (AF_INET, address, &addr->sin_addr.s_addr))
- {
- fprintf (stderr,
- "Failed to parse address `%s': %s\n",
- address, strerror (errno));
- exit (1);
- }
+ {
+ fprintf (stderr,
+ "Failed to parse address `%s': %s\n", address, strerror (errno));
+ exit (1);
+ }
-
+
if (-1 == (fd = socket (PF_INET, SOCK_DGRAM, 0)))
- {
- fprintf (stderr,
- "Error creating socket: %s\n",
- strerror (errno));
- exit (1);
- }
+ {
+ fprintf (stderr, "Error creating socket: %s\n", strerror (errno));
+ exit (1);
+ }
strncpy (ifr.ifr_name, dev, IFNAMSIZ);
@@ -257,63 +242,58 @@
* Set the address
*/
if (-1 == ioctl (fd, SIOCSIFADDR, &ifr))
- {
- fprintf (stderr,
- "ioctl failed at %d: %s\n",
- __LINE__,
- strerror (errno));
- exit (1);
- }
+ {
+ fprintf (stderr, "ioctl failed at %d: %s\n", __LINE__, strerror (errno));
+ exit (1);
+ }
/*
* Parse the netmask
*/
addr = (struct sockaddr_in *) &(ifr.ifr_netmask);
if (1 != inet_pton (AF_INET, mask, &addr->sin_addr.s_addr))
- {
- fprintf (stderr,
- "Failed to parse address `%s': %s\n",
- mask,
- strerror (errno));
- exit (1);
- }
+ {
+ fprintf (stderr,
+ "Failed to parse address `%s': %s\n", mask, strerror (errno));
+ exit (1);
+ }
/*
* Set the netmask
*/
if (-1 == ioctl (fd, SIOCSIFNETMASK, &ifr))
- {
- fprintf (stderr,
- "ioctl failed at line %d: %s\n", __LINE__, strerror (errno));
- exit (1);
- }
+ {
+ fprintf (stderr,
+ "ioctl failed at line %d: %s\n", __LINE__, strerror (errno));
+ exit (1);
+ }
/*
* Get the flags
*/
if (-1 == ioctl (fd, SIOCGIFFLAGS, &ifr))
- {
- fprintf (stderr,
- "ioctl failed at line %d: %s\n", __LINE__, strerror (errno));
- exit (1);
- }
+ {
+ fprintf (stderr,
+ "ioctl failed at line %d: %s\n", __LINE__, strerror (errno));
+ exit (1);
+ }
/*
* Add the UP and RUNNING flags
*/
ifr.ifr_flags |= IFF_UP | IFF_RUNNING;
if (-1 == ioctl (fd, SIOCSIFFLAGS, &ifr))
- {
- fprintf (stderr,
- "ioctl failed at line %d: %s\n", __LINE__, strerror (errno));
- exit (1);
- }
+ {
+ fprintf (stderr,
+ "ioctl failed at line %d: %s\n", __LINE__, strerror (errno));
+ exit (1);
+ }
if (0 != close (fd))
- {
- fprintf (stderr, "close failed: %s\n", strerror (errno));
- exit (1);
- }
+ {
+ fprintf (stderr, "close failed: %s\n", strerror (errno));
+ exit (1);
+ }
}
@@ -340,188 +320,182 @@
/* read refers to reading from fd_tun, writing to stdout */
int read_open = 1;
+
/* write refers to reading from stdin, writing to fd_tun */
int write_open = 1;
while ((1 == read_open) || (1 == write_open))
- {
- FD_ZERO (&fds_w);
- FD_ZERO (&fds_r);
+ {
+ FD_ZERO (&fds_w);
+ FD_ZERO (&fds_r);
- /*
- * We are supposed to read and the buffer is empty
- * -> select on read from tun
- */
- if (read_open && (0 == buftun_size))
- FD_SET (fd_tun, &fds_r);
+ /*
+ * We are supposed to read and the buffer is empty
+ * -> select on read from tun
+ */
+ if (read_open && (0 == buftun_size))
+ FD_SET (fd_tun, &fds_r);
- /*
- * We are supposed to read and the buffer is not empty
- * -> select on write to stdout
- */
- if (read_open && (0 != buftun_size))
- FD_SET (1, &fds_w);
+ /*
+ * We are supposed to read and the buffer is not empty
+ * -> select on write to stdout
+ */
+ if (read_open && (0 != buftun_size))
+ FD_SET (1, &fds_w);
- /*
- * We are supposed to write and the buffer is empty
- * -> select on read from stdin
- */
- if (write_open && (NULL == bufin_read))
- FD_SET (0, &fds_r);
+ /*
+ * We are supposed to write and the buffer is empty
+ * -> select on read from stdin
+ */
+ if (write_open && (NULL == bufin_read))
+ FD_SET (0, &fds_r);
- /*
- * We are supposed to write and the buffer is not empty
- * -> select on write to tun
- */
- if (write_open && (NULL != bufin_read))
- FD_SET (fd_tun, &fds_w);
+ /*
+ * We are supposed to write and the buffer is not empty
+ * -> select on write to tun
+ */
+ if (write_open && (NULL != bufin_read))
+ FD_SET (fd_tun, &fds_w);
- int r = select (fd_tun + 1, &fds_r, &fds_w, NULL, NULL);
- if (-1 == r)
- {
- if (EINTR == errno)
- continue;
- fprintf (stderr, "select failed: %s\n", strerror (errno));
- exit (1);
- }
+ int r = select (fd_tun + 1, &fds_r, &fds_w, NULL, NULL);
- if (r > 0)
- {
- if (FD_ISSET (fd_tun, &fds_r))
- {
- buftun_size =
- read (fd_tun, buftun + sizeof (struct GNUNET_MessageHeader),
- MAX_SIZE - sizeof (struct GNUNET_MessageHeader));
- if (-1 == buftun_size)
- {
- fprintf (stderr, "read-error: %s\n", strerror (errno));
- shutdown (fd_tun, SHUT_RD);
- shutdown (1, SHUT_WR);
- read_open = 0;
- buftun_size = 0;
- }
- else if (0 == buftun_size)
- {
- fprintf (stderr, "EOF on tun\n");
- shutdown (fd_tun, SHUT_RD);
- shutdown (1, SHUT_WR);
- read_open = 0;
- buftun_size = 0;
- }
- else
- {
- buftun_read = buftun;
- struct GNUNET_MessageHeader *hdr =
- (struct GNUNET_MessageHeader *) buftun;
- buftun_size += sizeof (struct GNUNET_MessageHeader);
- hdr->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
- hdr->size = htons (buftun_size);
- }
- }
- else if (FD_ISSET (1, &fds_w))
- {
- ssize_t written = write (1, buftun_read, buftun_size);
- if (-1 == written)
- {
- fprintf (stderr,
- "write-error to stdout: %s\n",
- strerror (errno));
- shutdown (fd_tun, SHUT_RD);
- shutdown (1, SHUT_WR);
- read_open = 0;
- buftun_size = 0;
- }
- else if (0 == written)
- {
- fprintf (stderr,
- "write returned 0!?\n");
- exit (1);
- }
- else
- {
- buftun_size -= written;
- buftun_read += written;
- }
- }
+ if (-1 == r)
+ {
+ if (EINTR == errno)
+ continue;
+ fprintf (stderr, "select failed: %s\n", strerror (errno));
+ exit (1);
+ }
- if (FD_ISSET (0, &fds_r))
- {
- bufin_size = read (0, bufin + bufin_rpos, MAX_SIZE - bufin_rpos);
- if (-1 == bufin_size)
- {
- fprintf (stderr,
- "read-error: %s\n",
- strerror (errno));
- shutdown (0, SHUT_RD);
- shutdown (fd_tun, SHUT_WR);
- write_open = 0;
- bufin_size = 0;
- }
- else if (0 == bufin_size)
- {
- fprintf (stderr,
- "EOF on stdin\n");
- shutdown (0, SHUT_RD);
- shutdown (fd_tun, SHUT_WR);
- write_open = 0;
- bufin_size = 0;
- }
- else
- {
- struct GNUNET_MessageHeader *hdr;
+ if (r > 0)
+ {
+ if (FD_ISSET (fd_tun, &fds_r))
+ {
+ buftun_size =
+ read (fd_tun, buftun + sizeof (struct GNUNET_MessageHeader),
+ MAX_SIZE - sizeof (struct GNUNET_MessageHeader));
+ if (-1 == buftun_size)
+ {
+ fprintf (stderr, "read-error: %s\n", strerror (errno));
+ shutdown (fd_tun, SHUT_RD);
+ shutdown (1, SHUT_WR);
+ read_open = 0;
+ buftun_size = 0;
+ }
+ else if (0 == buftun_size)
+ {
+ fprintf (stderr, "EOF on tun\n");
+ shutdown (fd_tun, SHUT_RD);
+ shutdown (1, SHUT_WR);
+ read_open = 0;
+ buftun_size = 0;
+ }
+ else
+ {
+ buftun_read = buftun;
+ struct GNUNET_MessageHeader *hdr =
+ (struct GNUNET_MessageHeader *) buftun;
+ buftun_size += sizeof (struct GNUNET_MessageHeader);
+ hdr->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
+ hdr->size = htons (buftun_size);
+ }
+ }
+ else if (FD_ISSET (1, &fds_w))
+ {
+ ssize_t written = write (1, buftun_read, buftun_size);
- PROCESS_BUFFER:
- bufin_rpos += bufin_size;
- if (bufin_rpos < sizeof (struct GNUNET_MessageHeader))
- continue;
- hdr = (struct GNUNET_MessageHeader *) bufin;
- if (ntohs (hdr->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER)
- {
- fprintf (stderr, "protocol violation!\n");
- exit (1);
- }
- if (ntohs (hdr->size) > bufin_rpos)
- continue;
- bufin_read = bufin + sizeof (struct GNUNET_MessageHeader);
- bufin_size = ntohs (hdr->size) - sizeof (struct
GNUNET_MessageHeader);
- bufin_rpos -= bufin_size + sizeof (struct
GNUNET_MessageHeader);
- }
- }
- else if (FD_ISSET (fd_tun, &fds_w))
- {
- ssize_t written = write (fd_tun, bufin_read, bufin_size);
- if (-1 == written)
- {
- fprintf (stderr, "write-error to tun: %s\n",
- strerror (errno));
- shutdown (0, SHUT_RD);
- shutdown (fd_tun, SHUT_WR);
- write_open = 0;
- bufin_size = 0;
- }
- else if (0 == written)
- {
- fprintf (stderr,
- "write returned 0!?\n");
- exit (1);
- }
- else
- {
- bufin_size -= written;
- bufin_read += written;
- if (0 == bufin_size)
- {
- memmove (bufin,
- bufin_read,
- bufin_rpos);
- bufin_read = NULL; /* start reading again */
- bufin_size = 0;
- goto PROCESS_BUFFER;
- }
- }
- }
- }
+ if (-1 == written)
+ {
+ fprintf (stderr, "write-error to stdout: %s\n", strerror (errno));
+ shutdown (fd_tun, SHUT_RD);
+ shutdown (1, SHUT_WR);
+ read_open = 0;
+ buftun_size = 0;
+ }
+ else if (0 == written)
+ {
+ fprintf (stderr, "write returned 0!?\n");
+ exit (1);
+ }
+ else
+ {
+ buftun_size -= written;
+ buftun_read += written;
+ }
+ }
+
+ if (FD_ISSET (0, &fds_r))
+ {
+ bufin_size = read (0, bufin + bufin_rpos, MAX_SIZE - bufin_rpos);
+ if (-1 == bufin_size)
+ {
+ fprintf (stderr, "read-error: %s\n", strerror (errno));
+ shutdown (0, SHUT_RD);
+ shutdown (fd_tun, SHUT_WR);
+ write_open = 0;
+ bufin_size = 0;
+ }
+ else if (0 == bufin_size)
+ {
+ fprintf (stderr, "EOF on stdin\n");
+ shutdown (0, SHUT_RD);
+ shutdown (fd_tun, SHUT_WR);
+ write_open = 0;
+ bufin_size = 0;
+ }
+ else
+ {
+ struct GNUNET_MessageHeader *hdr;
+
+PROCESS_BUFFER:
+ bufin_rpos += bufin_size;
+ if (bufin_rpos < sizeof (struct GNUNET_MessageHeader))
+ continue;
+ hdr = (struct GNUNET_MessageHeader *) bufin;
+ if (ntohs (hdr->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER)
+ {
+ fprintf (stderr, "protocol violation!\n");
+ exit (1);
+ }
+ if (ntohs (hdr->size) > bufin_rpos)
+ continue;
+ bufin_read = bufin + sizeof (struct GNUNET_MessageHeader);
+ bufin_size = ntohs (hdr->size) - sizeof (struct
GNUNET_MessageHeader);
+ bufin_rpos -= bufin_size + sizeof (struct GNUNET_MessageHeader);
+ }
+ }
+ else if (FD_ISSET (fd_tun, &fds_w))
+ {
+ ssize_t written = write (fd_tun, bufin_read, bufin_size);
+
+ if (-1 == written)
+ {
+ fprintf (stderr, "write-error to tun: %s\n", strerror (errno));
+ shutdown (0, SHUT_RD);
+ shutdown (fd_tun, SHUT_WR);
+ write_open = 0;
+ bufin_size = 0;
+ }
+ else if (0 == written)
+ {
+ fprintf (stderr, "write returned 0!?\n");
+ exit (1);
+ }
+ else
+ {
+ bufin_size -= written;
+ bufin_read += written;
+ if (0 == bufin_size)
+ {
+ memmove (bufin, bufin_read, bufin_rpos);
+ bufin_read = NULL; /* start reading again */
+ bufin_size = 0;
+ goto PROCESS_BUFFER;
+ }
+ }
+ }
}
+ }
}
@@ -532,35 +506,33 @@
int fd_tun;
if (6 != argc)
- {
- fprintf (stderr,
- "Fatal: must supply 5 arguments!\n");
- return 1;
- }
+ {
+ fprintf (stderr, "Fatal: must supply 5 arguments!\n");
+ return 1;
+ }
- strncpy(dev, argv[1], IFNAMSIZ);
+ strncpy (dev, argv[1], IFNAMSIZ);
dev[IFNAMSIZ - 1] = '\0';
if (-1 == (fd_tun = init_tun (dev)))
- {
- fprintf (stderr,
- "Fatal: could not initialize tun-interface\n");
- return 1;
- }
+ {
+ fprintf (stderr, "Fatal: could not initialize tun-interface\n");
+ return 1;
+ }
{
const char *address = argv[2];
- long prefix_len = atol(argv[3]);
+ long prefix_len = atol (argv[3]);
- if ( (prefix_len < 1) || (prefix_len > 127) )
- {
- fprintf(stderr, "Fatal: prefix_len out of range\n");
- return 1;
- }
+ if ((prefix_len < 1) || (prefix_len > 127))
+ {
+ fprintf (stderr, "Fatal: prefix_len out of range\n");
+ return 1;
+ }
set_address6 (dev, address, prefix_len);
}
-
+
{
const char *address = argv[4];
const char *mask = argv[5];
@@ -569,14 +541,12 @@
}
uid_t uid = getuid ();
+
if (0 != setresuid (uid, uid, uid))
- fprintf (stderr,
- "Failed to setresuid: %s\n",
- strerror (errno));
+ fprintf (stderr, "Failed to setresuid: %s\n", strerror (errno));
if (SIG_ERR == signal (SIGPIPE, SIG_IGN))
- fprintf (stderr,
- "Failed to protect against SIGPIPE: %s\n",
- strerror (errno));
+ fprintf (stderr,
+ "Failed to protect against SIGPIPE: %s\n", strerror (errno));
run (fd_tun);
close (fd_tun);
return 0;
Modified: gnunet/src/vpn/gnunet-service-dns-p.h
===================================================================
--- gnunet/src/vpn/gnunet-service-dns-p.h 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/vpn/gnunet-service-dns-p.h 2011-08-15 21:46:35 UTC (rev
16581)
@@ -3,102 +3,108 @@
#include "gnunet_common.h"
-struct query_packet {
- struct GNUNET_MessageHeader hdr;
+struct query_packet
+{
+ struct GNUNET_MessageHeader hdr;
- /**
+ /**
* The IP-Address this query was originally sent to
*/
- unsigned orig_to:32 GNUNET_PACKED;
- /**
+ unsigned orig_to:32 GNUNET_PACKED;
+ /**
* The IP-Address this query was originally sent from
*/
- unsigned orig_from:32 GNUNET_PACKED;
- /**
+ unsigned orig_from:32 GNUNET_PACKED;
+ /**
* The UDP-Portthis query was originally sent from
*/
- unsigned src_port:16 GNUNET_PACKED;
+ unsigned src_port:16 GNUNET_PACKED;
- unsigned char data[1]; /* The DNS-Packet */
+ unsigned char data[1]; /* The DNS-Packet */
};
-struct query_packet_list {
- struct query_packet_list* next GNUNET_PACKED;
- struct query_packet_list* prev GNUNET_PACKED;
- struct query_packet pkt;
+struct query_packet_list
+{
+ struct query_packet_list *next GNUNET_PACKED;
+ struct query_packet_list *prev GNUNET_PACKED;
+ struct query_packet pkt;
};
-enum GNUNET_DNS_ANSWER_Subtype {
+enum GNUNET_DNS_ANSWER_Subtype
+{
/**
* Answers of this type contain a dns-packet that just has to be
transmitted
*/
- GNUNET_DNS_ANSWER_TYPE_IP,
+ GNUNET_DNS_ANSWER_TYPE_IP,
/**
* Answers of this type contain an incomplete dns-packet. The IP-Address
* is all 0s. The addroffset points to it.
*/
- GNUNET_DNS_ANSWER_TYPE_SERVICE,
+ GNUNET_DNS_ANSWER_TYPE_SERVICE,
/**
* Answers of this type contain an incomplete dns-packet as answer to a
* PTR-Query. The resolved name is not allocated. The addroffset points to
it.
*/
- GNUNET_DNS_ANSWER_TYPE_REV,
+ GNUNET_DNS_ANSWER_TYPE_REV,
/**
* Answers of this type contains an IP6-Address but traffic to this IP
should
* be routed through the GNUNet.
*/
- GNUNET_DNS_ANSWER_TYPE_REMOTE_AAAA,
+ GNUNET_DNS_ANSWER_TYPE_REMOTE_AAAA,
/**
* Answers of this type contains an IP4-Address but traffic to this IP
should
* be routed through the GNUNet.
*/
- GNUNET_DNS_ANSWER_TYPE_REMOTE_A
+ GNUNET_DNS_ANSWER_TYPE_REMOTE_A
};
-struct GNUNET_vpn_service_descriptor {
- GNUNET_HashCode peer GNUNET_PACKED;
- GNUNET_HashCode service_descriptor GNUNET_PACKED;
- uint64_t ports GNUNET_PACKED;
- uint32_t service_type GNUNET_PACKED;
+struct GNUNET_vpn_service_descriptor
+{
+ GNUNET_HashCode peer GNUNET_PACKED;
+ GNUNET_HashCode service_descriptor GNUNET_PACKED;
+ uint64_t ports GNUNET_PACKED;
+ uint32_t service_type GNUNET_PACKED;
};
-struct answer_packet {
- /* General data */
- struct GNUNET_MessageHeader hdr;
- enum GNUNET_DNS_ANSWER_Subtype subtype GNUNET_PACKED;
+struct answer_packet
+{
+ /* General data */
+ struct GNUNET_MessageHeader hdr;
+ enum GNUNET_DNS_ANSWER_Subtype subtype GNUNET_PACKED;
- unsigned from:32 GNUNET_PACKED;
- unsigned to:32 GNUNET_PACKED;
- unsigned dst_port:16 GNUNET_PACKED;
- /* -- */
+ unsigned from:32 GNUNET_PACKED;
+ unsigned to:32 GNUNET_PACKED;
+ unsigned dst_port:16 GNUNET_PACKED;
+ /* -- */
- /* Data for GNUNET_DNS_ANSWER_TYPE_SERVICE */
- struct GNUNET_vpn_service_descriptor service_descr;
- /* -- */
+ /* Data for GNUNET_DNS_ANSWER_TYPE_SERVICE */
+ struct GNUNET_vpn_service_descriptor service_descr;
+ /* -- */
- /* Data for GNUNET_DNS_ANSWER_TYPE_REV */
- /* The offsett in octets from the beginning of the struct to the field
- * in data where the IP-Address has to go. */
- uint16_t addroffset GNUNET_PACKED;
- /* -- */
+ /* Data for GNUNET_DNS_ANSWER_TYPE_REV */
+ /* The offsett in octets from the beginning of the struct to the field
+ * in data where the IP-Address has to go. */
+ uint16_t addroffset GNUNET_PACKED;
+ /* -- */
- /* Data for GNUNET_DNS_ANSWER_TYPE_REMOTE */
- /* either 4 or 16 */
- char addrsize;
- unsigned char addr[16];
- /* -- */
+ /* Data for GNUNET_DNS_ANSWER_TYPE_REMOTE */
+ /* either 4 or 16 */
+ char addrsize;
+ unsigned char addr[16];
+ /* -- */
- unsigned char data[1];
+ unsigned char data[1];
};
-struct answer_packet_list {
- struct answer_packet_list* next GNUNET_PACKED;
- struct answer_packet_list* prev GNUNET_PACKED;
- struct answer_packet pkt;
+struct answer_packet_list
+{
+ struct answer_packet_list *next GNUNET_PACKED;
+ struct answer_packet_list *prev GNUNET_PACKED;
+ struct answer_packet pkt;
};
#endif
Modified: gnunet/src/vpn/gnunet-service-dns.c
===================================================================
--- gnunet/src/vpn/gnunet-service-dns.c 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/vpn/gnunet-service-dns.c 2011-08-15 21:46:35 UTC (rev 16581)
@@ -83,31 +83,33 @@
* = 17 MiB on 64 bit.
* = 11 MiB on 32 bit.
*/
-static struct {
- unsigned valid:1;
- struct GNUNET_SERVER_Client* client;
- struct GNUNET_MESH_Tunnel *tunnel;
- uint32_t local_ip;
- uint32_t remote_ip;
- uint16_t local_port;
- char* name;
- uint8_t namelen;
+static struct
+{
+ unsigned valid:1;
+ struct GNUNET_SERVER_Client *client;
+ struct GNUNET_MESH_Tunnel *tunnel;
+ uint32_t local_ip;
+ uint32_t remote_ip;
+ uint16_t local_port;
+ char *name;
+ uint8_t namelen;
} query_states[UINT16_MAX];
/**
* A struct used to give more than one value as
* closure to receive_dht
*/
-struct receive_dht_cls {
- uint16_t id;
- struct GNUNET_DHT_GetHandle* handle;
+struct receive_dht_cls
+{
+ uint16_t id;
+ struct GNUNET_DHT_GetHandle *handle;
};
struct tunnel_notify_queue
{
- struct tunnel_notify_queue* next;
- struct tunnel_notify_queue* prev;
- void* cls;
+ struct tunnel_notify_queue *next;
+ struct tunnel_notify_queue *prev;
+ void *cls;
size_t len;
GNUNET_CONNECTION_TransmitReadyNotify cb;
};
@@ -116,30 +118,31 @@
* Hijack all outgoing DNS-Traffic but for traffic leaving "our" port.
*/
static void
-hijack (void *cls __attribute__((unused)), const struct
GNUNET_SCHEDULER_TaskContext *tc)
+hijack (void *cls
+ __attribute__ ((unused)), const struct GNUNET_SCHEDULER_TaskContext
*tc)
{
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
return;
if (0 == dnsoutport)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Delaying the hijacking, port is
still %d!\n", dnsoutport);
- GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, hijack, NULL);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Delaying the hijacking, port is still %d!\n", dnsoutport);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, hijack, NULL);
+ return;
+ }
char port_s[6];
char *virt_dns;
struct GNUNET_OS_Process *proc;
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);
- }
+ GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "VIRTDNS", &virt_dns))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "No entry 'VIRTDNS' in configuration!\n");
+ exit (1);
+ }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hijacking, port is %d\n", dnsoutport);
snprintf (port_s, 6, "%d", dnsoutport);
@@ -163,13 +166,12 @@
struct GNUNET_OS_Process *proc;
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);
- }
+ GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "VIRTDNS", &virt_dns))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "No entry 'VIRTDNS' in configuration!\n");
+ exit (1);
+ }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "unHijacking, port is %d\n", port);
snprintf (port_s, 6, "%d", port);
@@ -187,33 +189,34 @@
* system.
*/
static size_t
-send_answer(void* cls, size_t size, void* buf) {
- struct answer_packet_list* query = head;
- size_t len = ntohs(query->pkt.hdr.size);
+send_answer (void *cls, size_t size, void *buf)
+{
+ struct answer_packet_list *query = head;
+ size_t len = ntohs (query->pkt.hdr.size);
- GNUNET_assert(len <= size);
+ GNUNET_assert (len <= size);
- memcpy(buf, &query->pkt.hdr, len);
+ memcpy (buf, &query->pkt.hdr, len);
- GNUNET_CONTAINER_DLL_remove (head, tail, query);
+ GNUNET_CONTAINER_DLL_remove (head, tail, query);
- GNUNET_free(query);
+ GNUNET_free (query);
- /* When more data is to be sent, reschedule */
- if (head != NULL)
- GNUNET_SERVER_notify_transmit_ready(cls,
- ntohs(head->pkt.hdr.size),
- GNUNET_TIME_UNIT_FOREVER_REL,
- &send_answer,
- cls);
+ /* When more data is to be sent, reschedule */
+ if (head != NULL)
+ GNUNET_SERVER_notify_transmit_ready (cls,
+ ntohs (head->pkt.hdr.size),
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &send_answer, cls);
- return len;
+ return len;
}
-struct tunnel_cls {
- struct GNUNET_MESH_Tunnel *tunnel GNUNET_PACKED;
- struct GNUNET_MessageHeader hdr;
- struct dns_pkt dns;
+struct tunnel_cls
+{
+ struct GNUNET_MESH_Tunnel *tunnel GNUNET_PACKED;
+ struct GNUNET_MessageHeader hdr;
+ struct dns_pkt dns;
};
struct tunnel_cls *remote_pending[UINT16_MAX];
@@ -224,8 +227,9 @@
GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader));
struct GNUNET_MessageHeader *hdr = buf;
uint32_t *sz = cls;
- struct GNUNET_MESH_Tunnel **tunnel = (struct GNUNET_MESH_Tunnel**)(sz+1);
+ struct GNUNET_MESH_Tunnel **tunnel = (struct GNUNET_MESH_Tunnel **) (sz + 1);
struct dns_pkt *dns = (struct dns_pkt *) (tunnel + 1);
+
hdr->type = htons (GNUNET_MESSAGE_TYPE_VPN_REMOTE_ANSWER_DNS);
hdr->size = htons (*sz + sizeof (struct GNUNET_MessageHeader));
@@ -237,28 +241,30 @@
memcpy (hdr + 1, dns, *sz);
- if (NULL != GNUNET_MESH_tunnel_get_head(*tunnel))
- {
- struct tunnel_notify_queue* element =
GNUNET_MESH_tunnel_get_head(*tunnel);
- struct tunnel_notify_queue* head = GNUNET_MESH_tunnel_get_head(*tunnel);
- struct tunnel_notify_queue* tail = GNUNET_MESH_tunnel_get_tail(*tunnel);
+ if (NULL != GNUNET_MESH_tunnel_get_head (*tunnel))
+ {
+ struct tunnel_notify_queue *element = GNUNET_MESH_tunnel_get_head
(*tunnel);
+ struct tunnel_notify_queue *head = GNUNET_MESH_tunnel_get_head (*tunnel);
+ struct tunnel_notify_queue *tail = GNUNET_MESH_tunnel_get_tail (*tunnel);
- GNUNET_CONTAINER_DLL_remove(head, tail, element);
+ GNUNET_CONTAINER_DLL_remove (head, tail, element);
- GNUNET_MESH_tunnel_set_head(*tunnel, head);
- GNUNET_MESH_tunnel_set_tail(*tunnel, tail);
- struct GNUNET_MESH_TransmitHandle* th =
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);
- /* save the handle */
- GNUNET_MESH_tunnel_set_data(*tunnel, th);
- }
+ GNUNET_MESH_tunnel_set_head (*tunnel, head);
+ GNUNET_MESH_tunnel_set_tail (*tunnel, tail);
+ struct GNUNET_MESH_TransmitHandle *th =
+ 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);
+ /* save the handle */
+ GNUNET_MESH_tunnel_set_data (*tunnel, th);
+ }
+
GNUNET_free (cls);
return ntohs (hdr->size);
@@ -268,38 +274,44 @@
mesh_send (void *cls, size_t size, void *buf)
{
struct tunnel_cls *cls_ = (struct tunnel_cls *) cls;
- GNUNET_MESH_tunnel_set_data(cls_->tunnel, NULL);
- GNUNET_assert(cls_->hdr.size <= size);
+ GNUNET_MESH_tunnel_set_data (cls_->tunnel, NULL);
+ GNUNET_assert (cls_->hdr.size <= size);
+
size = cls_->hdr.size;
- cls_->hdr.size = htons(cls_->hdr.size);
+ cls_->hdr.size = htons (cls_->hdr.size);
- memcpy(buf, &cls_->hdr, size);
+ memcpy (buf, &cls_->hdr, size);
- if (NULL != GNUNET_MESH_tunnel_get_head(cls_->tunnel))
- {
- struct tunnel_notify_queue* element =
GNUNET_MESH_tunnel_get_head(cls_->tunnel);
- struct tunnel_notify_queue* head =
GNUNET_MESH_tunnel_get_head(cls_->tunnel);
- struct tunnel_notify_queue* tail =
GNUNET_MESH_tunnel_get_tail(cls_->tunnel);
+ if (NULL != GNUNET_MESH_tunnel_get_head (cls_->tunnel))
+ {
+ struct tunnel_notify_queue *element =
+ GNUNET_MESH_tunnel_get_head (cls_->tunnel);
+ struct tunnel_notify_queue *head =
+ GNUNET_MESH_tunnel_get_head (cls_->tunnel);
+ struct tunnel_notify_queue *tail =
+ GNUNET_MESH_tunnel_get_tail (cls_->tunnel);
- GNUNET_CONTAINER_DLL_remove(head, tail, element);
+ GNUNET_CONTAINER_DLL_remove (head, tail, element);
- GNUNET_MESH_tunnel_set_head(cls_->tunnel, head);
- GNUNET_MESH_tunnel_set_tail(cls_->tunnel, tail);
- struct GNUNET_MESH_TransmitHandle* th =
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);
- /* save the handle */
- GNUNET_MESH_tunnel_set_data(cls_->tunnel, th);
- GNUNET_free(element);
- }
+ GNUNET_MESH_tunnel_set_head (cls_->tunnel, head);
+ GNUNET_MESH_tunnel_set_tail (cls_->tunnel, tail);
+ struct GNUNET_MESH_TransmitHandle *th =
+ 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);
+ /* save the handle */
+ GNUNET_MESH_tunnel_set_data (cls_->tunnel, th);
+ GNUNET_free (element);
+ }
+
return size;
}
@@ -312,13 +324,14 @@
if (NULL == peer)
return;
struct tunnel_cls *cls_ = (struct tunnel_cls *) cls;
+
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Connected to peer %s, %x, sending query with id %d\n",
GNUNET_i2s (peer), peer, ntohs (cls_->dns.s.id));
if (NULL == GNUNET_MESH_tunnel_get_data (cls_->tunnel))
- {
- struct GNUNET_MESH_TransmitHandle *th =
+ {
+ struct GNUNET_MESH_TransmitHandle *th =
GNUNET_MESH_notify_transmit_ready (cls_->tunnel,
GNUNET_YES,
42,
@@ -328,22 +341,25 @@
mesh_send,
cls);
- GNUNET_MESH_tunnel_set_data (cls_->tunnel, th);
- }
+ GNUNET_MESH_tunnel_set_data (cls_->tunnel, th);
+ }
else
- {
- struct tunnel_notify_queue* head =
GNUNET_MESH_tunnel_get_head(cls_->tunnel);
- struct tunnel_notify_queue* tail =
GNUNET_MESH_tunnel_get_tail(cls_->tunnel);
+ {
+ struct tunnel_notify_queue *head =
+ GNUNET_MESH_tunnel_get_head (cls_->tunnel);
+ struct tunnel_notify_queue *tail =
+ GNUNET_MESH_tunnel_get_tail (cls_->tunnel);
- struct tunnel_notify_queue* element = GNUNET_malloc(sizeof(struct
tunnel_notify_queue));
- element->cls = cls;
- element->len = cls_->hdr.size;
- element->cb = mesh_send;
+ struct tunnel_notify_queue *element =
+ GNUNET_malloc (sizeof (struct tunnel_notify_queue));
+ element->cls = cls;
+ element->len = cls_->hdr.size;
+ element->cb = mesh_send;
- GNUNET_CONTAINER_DLL_insert_tail(head, tail, element);
- GNUNET_MESH_tunnel_set_head(cls_->tunnel, head);
- GNUNET_MESH_tunnel_set_tail(cls_->tunnel, tail);
- }
+ GNUNET_CONTAINER_DLL_insert_tail (head, tail, element);
+ GNUNET_MESH_tunnel_set_head (cls_->tunnel, head);
+ GNUNET_MESH_tunnel_set_tail (cls_->tunnel, tail);
+ }
}
@@ -353,54 +369,58 @@
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
return;
- struct tunnel_cls *cls_ = (struct tunnel_cls*)cls;
+ struct tunnel_cls *cls_ = (struct tunnel_cls *) cls;
- cls_->tunnel = GNUNET_MESH_peer_request_connect_by_type(mesh_handle,
- GNUNET_TIME_UNIT_HOURS,
-
GNUNET_APPLICATION_TYPE_INTERNET_RESOLVER,
- mesh_connect,
- NULL,
- cls_);
+ cls_->tunnel = GNUNET_MESH_peer_request_connect_by_type (mesh_handle,
+
GNUNET_TIME_UNIT_HOURS,
+
GNUNET_APPLICATION_TYPE_INTERNET_RESOLVER,
+ mesh_connect,
+ NULL, cls_);
remote_pending[cls_->dns.s.id] = cls_;
}
static int
-receive_mesh_query (void *cls __attribute__((unused)),
+receive_mesh_query (void *cls __attribute__ ((unused)),
struct GNUNET_MESH_Tunnel *tunnel,
- void **ctx __attribute__((unused)),
- const struct GNUNET_PeerIdentity *sender
__attribute__((unused)),
+ void **ctx __attribute__ ((unused)),
+ const struct GNUNET_PeerIdentity *sender
+ __attribute__ ((unused)),
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi
__attribute__((unused)))
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi
+ __attribute__ ((unused)))
{
- struct dns_pkt *dns = (struct dns_pkt*)(message + 1);
+ struct dns_pkt *dns = (struct dns_pkt *) (message + 1);
struct sockaddr_in dest;
- memset(&dest, 0, sizeof dest);
- dest.sin_port = htons(53);
+
+ memset (&dest, 0, sizeof dest);
+ dest.sin_port = htons (53);
/* TODO: read from config */
- inet_pton(AF_INET, "8.8.8.8", &dest.sin_addr);
+ inet_pton (AF_INET, "8.8.8.8", &dest.sin_addr);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Querying for remote, id=%d\n",
ntohs(dns->s.id));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Querying for remote, id=%d\n",
+ ntohs (dns->s.id));
query_states[dns->s.id].tunnel = tunnel;
query_states[dns->s.id].valid = GNUNET_YES;
- GNUNET_NETWORK_socket_sendto(dnsout,
- dns,
- ntohs(message->size) - sizeof(struct
GNUNET_MessageHeader),
- (struct sockaddr*) &dest,
- sizeof dest);
+ GNUNET_NETWORK_socket_sendto (dnsout,
+ dns,
+ ntohs (message->size) -
+ sizeof (struct GNUNET_MessageHeader),
+ (struct sockaddr *) &dest, sizeof dest);
return GNUNET_SYSERR;
}
static int
-receive_mesh_answer (void *cls __attribute__((unused)),
+receive_mesh_answer (void *cls __attribute__ ((unused)),
struct GNUNET_MESH_Tunnel *tunnel,
- void **ctx __attribute__((unused)),
+ void **ctx __attribute__ ((unused)),
const struct GNUNET_PeerIdentity *sender,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi
__attribute__((unused)))
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi
+ __attribute__ ((unused)))
{
/* TODo: size check */
struct dns_pkt *dns = (struct dns_pkt *) (message + 1);
@@ -410,37 +430,42 @@
|| remote_pending[dns->s.id]->tunnel != tunnel)
return GNUNET_OK;
- GNUNET_free(remote_pending[dns->s.id]);
+ GNUNET_free (remote_pending[dns->s.id]);
remote_pending[dns->s.id] = NULL;
if (query_states[dns->s.id].valid != GNUNET_YES)
return GNUNET_SYSERR;
query_states[dns->s.id].valid = GNUNET_NO;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received answer from peer %s, dns-id
%d\n", GNUNET_i2s(sender), ntohs(dns->s.id));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received answer from peer %s, dns-id %d\n", GNUNET_i2s (sender),
+ ntohs (dns->s.id));
size_t len = sizeof (struct answer_packet) - 1 + sizeof (struct dns_static)
+ query_states[dns->s.id].namelen + sizeof (struct dns_query_line) + 2 /* To
hold the pointer (as defined in RFC1035) to the name */
- + sizeof (struct dns_record_line) - 1 + 16; /* To hold the IPv6-Address */
+ + sizeof (struct dns_record_line) - 1 + 16; /* To hold the
IPv6-Address */
struct answer_packet_list *answer =
- GNUNET_malloc (len + 2 * sizeof (struct answer_packet_list *));
+ GNUNET_malloc (len + 2 * sizeof (struct answer_packet_list *));
memset (answer, 0, len + 2 * sizeof (struct answer_packet_list *));
answer->pkt.hdr.type = htons
(GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_RESPONSE_DNS);
answer->pkt.hdr.size = htons (len);
- struct dns_pkt_parsed* pdns = parse_dns_packet(dns);
+ struct dns_pkt_parsed *pdns = parse_dns_packet (dns);
- if (ntohs(pdns->s.ancount) < 1)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Answer only contains %d
answers.\n", ntohs(pdns->s.ancount));
- free_parsed_dns_packet(pdns);
- return GNUNET_OK;
- }
+ if (ntohs (pdns->s.ancount) < 1)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Answer only contains %d answers.\n",
+ ntohs (pdns->s.ancount));
+ free_parsed_dns_packet (pdns);
+ return GNUNET_OK;
+ }
- answer->pkt.addrsize = ntohs(pdns->answers[0]->data_len);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "The first answer has the addrlen %d\n",
answer->pkt.addrsize);
- memcpy(answer->pkt.addr, pdns->answers[0]->data,
ntohs(pdns->answers[0]->data_len));
+ answer->pkt.addrsize = ntohs (pdns->answers[0]->data_len);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "The first answer has the addrlen %d\n",
+ answer->pkt.addrsize);
+ memcpy (answer->pkt.addr, pdns->answers[0]->data,
+ ntohs (pdns->answers[0]->data_len));
answer->pkt.from = query_states[dns->s.id].remote_ip;
@@ -462,32 +487,32 @@
query_states[dns->s.id].name = NULL;
struct dns_query_line *dque =
- (struct dns_query_line *) (dpkt->data +
- (query_states[dns->s.id].namelen));
+ (struct dns_query_line *) (dpkt->data +
+ (query_states[dns->s.id].namelen));
struct dns_record_line *drec_data =
- (struct dns_record_line *) (dpkt->data +
- (query_states[dns->s.id].namelen) +
- sizeof (struct dns_query_line) + 2);
+ (struct dns_record_line *) (dpkt->data +
+ (query_states[dns->s.id].namelen) +
+ sizeof (struct dns_query_line) + 2);
if (16 == answer->pkt.addrsize)
- {
- 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);
- }
+ {
+ 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
- {
- answer->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_REMOTE_A;
- dque->type = htons (1); /* A */
- drec_data->type = htons (1); /* A*/
- drec_data->data_len = htons (4);
- }
+ {
+ answer->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_REMOTE_A;
+ dque->type = htons (1); /* A */
+ drec_data->type = htons (1); /* A */
+ drec_data->data_len = htons (4);
+ }
dque->class = htons (1); /* IN */
char *anname =
- (char *) (dpkt->data + (query_states[dns->s.id].namelen) +
- sizeof (struct dns_query_line));
+ (char *) (dpkt->data + (query_states[dns->s.id].namelen) +
+ sizeof (struct dns_query_line));
memcpy (anname, "\xc0\x0c", 2);
drec_data->class = htons (1); /* IN */
@@ -496,8 +521,8 @@
/* Calculate at which offset in the packet the IPv6-Address belongs, it is
* filled in by the daemon-vpn */
answer->pkt.addroffset =
- htons ((unsigned short) ((unsigned long) (&drec_data->data) -
- (unsigned long) (&answer->pkt)));
+ htons ((unsigned short) ((unsigned long) (&drec_data->data) -
+ (unsigned long) (&answer->pkt)));
GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, answer);
@@ -507,378 +532,408 @@
&send_answer,
query_states[dns->s.id].client);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sent answer of length %d on to client,
addroffset = %d\n", len, answer->pkt.addroffset);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sent answer of length %d on to client, addroffset = %d\n", len,
+ answer->pkt.addroffset);
- free_parsed_dns_packet(pdns);
+ free_parsed_dns_packet (pdns);
return GNUNET_OK;
}
static void
-send_rev_query(void * cls, const struct GNUNET_SCHEDULER_TaskContext *tc) {
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
+send_rev_query (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
+ return;
- struct dns_pkt_parsed* pdns = (struct dns_pkt_parsed*) cls;
+ struct dns_pkt_parsed *pdns = (struct dns_pkt_parsed *) cls;
- unsigned short id = pdns->s.id;
+ unsigned short id = pdns->s.id;
- free_parsed_dns_packet(pdns);
+ free_parsed_dns_packet (pdns);
- if (query_states[id].valid != GNUNET_YES) return;
- query_states[id].valid = GNUNET_NO;
+ if (query_states[id].valid != GNUNET_YES)
+ return;
+ query_states[id].valid = GNUNET_NO;
- GNUNET_assert(query_states[id].namelen == 74);
+ GNUNET_assert (query_states[id].namelen == 74);
- size_t len = sizeof(struct answer_packet) - 1 \
- + sizeof(struct dns_static) \
- + 74 /* this is the length of a reverse ipv6-lookup */ \
- + sizeof(struct dns_query_line) \
- + 2 /* To hold the pointer (as defined in RFC1035) to the name
*/ \
- + sizeof(struct dns_record_line) - 1 \
- - 2 /* We do not know the lenght of the answer yet*/;
+ size_t len = sizeof (struct answer_packet) - 1 + sizeof (struct dns_static)
+ 74 /* this is the length of a reverse ipv6-lookup */
+ + sizeof (struct dns_query_line) + 2 /* To hold the pointer (as
defined in RFC1035) to the name */
+ + sizeof (struct dns_record_line) - 1
+ - 2 /* We do not know the lenght of the answer yet */ ;
- struct answer_packet_list* answer = GNUNET_malloc(len + 2*sizeof(struct
answer_packet_list*));
- memset(answer, 0, len + 2*sizeof(struct answer_packet_list*));
+ struct answer_packet_list *answer =
+ GNUNET_malloc (len + 2 * sizeof (struct answer_packet_list *));
+ memset (answer, 0, len + 2 * sizeof (struct answer_packet_list *));
- 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;
+ 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;
- answer->pkt.from = query_states[id].remote_ip;
+ answer->pkt.from = query_states[id].remote_ip;
- answer->pkt.to = query_states[id].local_ip;
- answer->pkt.dst_port = query_states[id].local_port;
+ answer->pkt.to = query_states[id].local_ip;
+ answer->pkt.dst_port = query_states[id].local_port;
- struct dns_pkt *dpkt = (struct dns_pkt*)answer->pkt.data;
+ struct dns_pkt *dpkt = (struct dns_pkt *) answer->pkt.data;
- dpkt->s.id = id;
- dpkt->s.aa = 1;
- dpkt->s.qr = 1;
- dpkt->s.ra = 1;
- dpkt->s.qdcount = htons(1);
- dpkt->s.ancount = htons(1);
+ dpkt->s.id = id;
+ dpkt->s.aa = 1;
+ dpkt->s.qr = 1;
+ dpkt->s.ra = 1;
+ dpkt->s.qdcount = htons (1);
+ dpkt->s.ancount = htons (1);
- memcpy(dpkt->data, query_states[id].name, query_states[id].namelen);
- GNUNET_free(query_states[id].name);
+ memcpy (dpkt->data, query_states[id].name, query_states[id].namelen);
+ GNUNET_free (query_states[id].name);
- struct dns_query_line* dque = (struct
dns_query_line*)(dpkt->data+(query_states[id].namelen));
- dque->type = htons(12); /* PTR */
- dque->class = htons(1); /* IN */
+ struct dns_query_line *dque =
+ (struct dns_query_line *) (dpkt->data + (query_states[id].namelen));
+ dque->type = htons (12); /* PTR */
+ dque->class = htons (1); /* IN */
- char* anname = (char*)(dpkt->data+(query_states[id].namelen)+sizeof(struct
dns_query_line));
- memcpy(anname, "\xc0\x0c", 2);
+ char *anname =
+ (char *) (dpkt->data + (query_states[id].namelen) +
+ sizeof (struct dns_query_line));
+ memcpy (anname, "\xc0\x0c", 2);
- struct dns_record_line *drec_data = (struct
dns_record_line*)(dpkt->data+(query_states[id].namelen)+sizeof(struct
dns_query_line)+2);
- drec_data->type = htons(12); /* AAAA */
- drec_data->class = htons(1); /* IN */
- /* FIXME: read the TTL from block:
- * GNUNET_TIME_absolute_get_remaining(rec->expiration_time)
- *
- * But how to get the seconds out of this?
- */
- drec_data->ttl = htonl(3600);
+ struct dns_record_line *drec_data =
+ (struct dns_record_line *) (dpkt->data + (query_states[id].namelen) +
+ sizeof (struct dns_query_line) + 2);
+ drec_data->type = htons (12); /* AAAA */
+ drec_data->class = htons (1); /* IN */
+ /* FIXME: read the TTL from block:
+ * GNUNET_TIME_absolute_get_remaining(rec->expiration_time)
+ *
+ * But how to get the seconds out of this?
+ */
+ drec_data->ttl = htonl (3600);
- /* Calculate at which offset in the packet the length of the name and the
- * name, it is filled in by the daemon-vpn */
- answer->pkt.addroffset = htons((unsigned short)((unsigned
long)(&drec_data->data_len)-(unsigned long)(&answer->pkt)));
+ /* Calculate at which offset in the packet the length of the name and the
+ * name, it is filled in by the daemon-vpn */
+ answer->pkt.addroffset =
+ htons ((unsigned short) ((unsigned long) (&drec_data->data_len) -
+ (unsigned long) (&answer->pkt)));
- GNUNET_CONTAINER_DLL_insert_after(head, tail, tail, answer);
+ GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, answer);
- GNUNET_SERVER_notify_transmit_ready(query_states[id].client,
- len,
- GNUNET_TIME_UNIT_FOREVER_REL,
- &send_answer,
- query_states[id].client);
+ GNUNET_SERVER_notify_transmit_ready (query_states[id].client,
+ len,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &send_answer, query_states[id].client);
}
/**
* Receive a block from the dht.
*/
static void
-receive_dht(void *cls,
- struct GNUNET_TIME_Absolute exp __attribute__((unused)),
- const GNUNET_HashCode *key __attribute__((unused)),
- const struct GNUNET_PeerIdentity *const *get_path
__attribute__((unused)),
- const struct GNUNET_PeerIdentity *const *put_path
__attribute__((unused)),
- enum GNUNET_BLOCK_Type type,
- size_t size,
- const void *data) {
+receive_dht (void *cls,
+ struct GNUNET_TIME_Absolute exp __attribute__ ((unused)),
+ const GNUNET_HashCode * key __attribute__ ((unused)),
+ const struct GNUNET_PeerIdentity *const *get_path
+ __attribute__ ((unused)),
+ const struct GNUNET_PeerIdentity *const *put_path
+ __attribute__ ((unused)), enum GNUNET_BLOCK_Type type, size_t
size,
+ const void *data)
+{
- unsigned short id = ((struct receive_dht_cls*)cls)->id;
- struct GNUNET_DHT_GetHandle* handle = ((struct
receive_dht_cls*)cls)->handle;
- GNUNET_free(cls);
+ unsigned short id = ((struct receive_dht_cls *) cls)->id;
+ struct GNUNET_DHT_GetHandle *handle =
+ ((struct receive_dht_cls *) cls)->handle;
+ GNUNET_free (cls);
- GNUNET_assert(type == GNUNET_BLOCK_TYPE_DNS);
+ GNUNET_assert (type == GNUNET_BLOCK_TYPE_DNS);
- /* If no query with this id is pending, ignore the block */
- if (query_states[id].valid != GNUNET_YES) return;
- query_states[id].valid = GNUNET_NO;
+ /* If no query with this id is pending, ignore the block */
+ if (query_states[id].valid != GNUNET_YES)
+ return;
+ query_states[id].valid = GNUNET_NO;
- const struct GNUNET_DNS_Record* rec = data;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Got block of size %d, peer: %08x, desc: %08x\n",
- size,
- *((unsigned int*)&rec->peer),
- *((unsigned int*)&rec->service_descriptor));
+ const struct GNUNET_DNS_Record *rec = data;
- size_t len = sizeof(struct answer_packet) - 1 \
- + sizeof(struct dns_static) \
- + query_states[id].namelen \
- + sizeof(struct dns_query_line) \
- + 2 /* To hold the pointer (as defined in RFC1035) to the name
*/ \
- + sizeof(struct dns_record_line) - 1 \
- + 16; /* To hold the IPv6-Address */
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Got block of size %d, peer: %08x, desc: %08x\n",
+ size,
+ *((unsigned int *) &rec->peer),
+ *((unsigned int *) &rec->service_descriptor));
- struct answer_packet_list* answer = GNUNET_malloc(len + 2*sizeof(struct
answer_packet_list*));
- memset(answer, 0, len + 2*sizeof(struct answer_packet_list*));
+ size_t len = sizeof (struct answer_packet) - 1 + sizeof (struct dns_static)
+ query_states[id].namelen + sizeof (struct dns_query_line) + 2 /* To hold
the pointer (as defined in RFC1035) to the name */
+ + sizeof (struct dns_record_line) - 1 + 16; /* To hold the
IPv6-Address */
- 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_SERVICE;
+ struct answer_packet_list *answer =
+ GNUNET_malloc (len + 2 * sizeof (struct answer_packet_list *));
+ memset (answer, 0, len + 2 * sizeof (struct answer_packet_list *));
- GNUNET_CRYPTO_hash(&rec->peer,
- sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
- &answer->pkt.service_descr.peer);
+ 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_SERVICE;
- memcpy(&answer->pkt.service_descr.service_descriptor,
- &rec->service_descriptor,
- sizeof(GNUNET_HashCode));
- memcpy(&answer->pkt.service_descr.service_type,
- &rec->service_type,
- sizeof(answer->pkt.service_descr.service_type));
- memcpy(&answer->pkt.service_descr.ports, &rec->ports,
sizeof(answer->pkt.service_descr.ports));
+ GNUNET_CRYPTO_hash (&rec->peer,
+ sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+ &answer->pkt.service_descr.peer);
- answer->pkt.from = query_states[id].remote_ip;
+ memcpy (&answer->pkt.service_descr.service_descriptor,
+ &rec->service_descriptor, sizeof (GNUNET_HashCode));
+ memcpy (&answer->pkt.service_descr.service_type,
+ &rec->service_type, sizeof (answer->pkt.service_descr.service_type));
+ memcpy (&answer->pkt.service_descr.ports, &rec->ports,
+ sizeof (answer->pkt.service_descr.ports));
- answer->pkt.to = query_states[id].local_ip;
- answer->pkt.dst_port = query_states[id].local_port;
+ answer->pkt.from = query_states[id].remote_ip;
- struct dns_pkt *dpkt = (struct dns_pkt*)answer->pkt.data;
+ answer->pkt.to = query_states[id].local_ip;
+ answer->pkt.dst_port = query_states[id].local_port;
- dpkt->s.id = id;
- dpkt->s.aa = 1;
- dpkt->s.qr = 1;
- dpkt->s.ra = 1;
- dpkt->s.qdcount = htons(1);
- dpkt->s.ancount = htons(1);
+ struct dns_pkt *dpkt = (struct dns_pkt *) answer->pkt.data;
- memcpy(dpkt->data, query_states[id].name, query_states[id].namelen);
- GNUNET_free(query_states[id].name);
+ dpkt->s.id = id;
+ dpkt->s.aa = 1;
+ dpkt->s.qr = 1;
+ dpkt->s.ra = 1;
+ dpkt->s.qdcount = htons (1);
+ dpkt->s.ancount = htons (1);
- struct dns_query_line* dque = (struct
dns_query_line*)(dpkt->data+(query_states[id].namelen));
- dque->type = htons(28); /* AAAA */
- dque->class = htons(1); /* IN */
+ memcpy (dpkt->data, query_states[id].name, query_states[id].namelen);
+ GNUNET_free (query_states[id].name);
- char* anname = (char*)(dpkt->data+(query_states[id].namelen)+sizeof(struct
dns_query_line));
- memcpy(anname, "\xc0\x0c", 2);
+ struct dns_query_line *dque =
+ (struct dns_query_line *) (dpkt->data + (query_states[id].namelen));
+ dque->type = htons (28); /* AAAA */
+ dque->class = htons (1); /* IN */
- struct dns_record_line *drec_data = (struct
dns_record_line*)(dpkt->data+(query_states[id].namelen)+sizeof(struct
dns_query_line)+2);
- drec_data->type = htons(28); /* AAAA */
- drec_data->class = htons(1); /* IN */
+ char *anname =
+ (char *) (dpkt->data + (query_states[id].namelen) +
+ sizeof (struct dns_query_line));
+ memcpy (anname, "\xc0\x0c", 2);
- /* FIXME: read the TTL from block:
- * GNUNET_TIME_absolute_get_remaining(rec->expiration_time)
- *
- * But how to get the seconds out of this?
- */
- drec_data->ttl = htonl(3600);
- drec_data->data_len = htons(16);
+ struct dns_record_line *drec_data =
+ (struct dns_record_line *) (dpkt->data + (query_states[id].namelen) +
+ sizeof (struct dns_query_line) + 2);
+ drec_data->type = htons (28); /* AAAA */
+ drec_data->class = htons (1); /* IN */
- /* Calculate at which offset in the packet the IPv6-Address belongs, it is
- * filled in by the daemon-vpn */
- answer->pkt.addroffset = htons((unsigned short)((unsigned
long)(&drec_data->data)-(unsigned long)(&answer->pkt)));
+ /* FIXME: read the TTL from block:
+ * GNUNET_TIME_absolute_get_remaining(rec->expiration_time)
+ *
+ * But how to get the seconds out of this?
+ */
+ drec_data->ttl = htonl (3600);
+ drec_data->data_len = htons (16);
- GNUNET_CONTAINER_DLL_insert_after(head, tail, tail, answer);
+ /* Calculate at which offset in the packet the IPv6-Address belongs, it is
+ * filled in by the daemon-vpn */
+ answer->pkt.addroffset =
+ htons ((unsigned short) ((unsigned long) (&drec_data->data) -
+ (unsigned long) (&answer->pkt)));
- GNUNET_SERVER_notify_transmit_ready(query_states[id].client,
- len,
- GNUNET_TIME_UNIT_FOREVER_REL,
- &send_answer,
- query_states[id].client);
+ GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, answer);
- GNUNET_DHT_get_stop(handle);
+ GNUNET_SERVER_notify_transmit_ready (query_states[id].client,
+ len,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &send_answer, query_states[id].client);
+
+ GNUNET_DHT_get_stop (handle);
}
/**
* This receives a GNUNET_MESSAGE_TYPE_REHIJACK and rehijacks the DNS
*/
static void
-rehijack(void *cls __attribute__((unused)),
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message __attribute__((unused))) {
- unhijack(dnsoutport);
- GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, hijack, NULL);
+rehijack (void *cls __attribute__ ((unused)),
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message __attribute__ ((unused)))
+{
+ unhijack (dnsoutport);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, hijack, NULL);
- GNUNET_SERVER_receive_done(client, GNUNET_OK);
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
/**
* This receives the dns-payload from the daemon-vpn and sends it on over the
udp-socket
*/
static void
-receive_query(void *cls __attribute__((unused)),
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message) {
- struct query_packet* pkt = (struct query_packet*)message;
- struct dns_pkt* dns = (struct dns_pkt*)pkt->data;
- struct dns_pkt_parsed* pdns = parse_dns_packet(dns);
+receive_query (void *cls __attribute__ ((unused)),
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
+{
+ struct query_packet *pkt = (struct query_packet *) message;
+ struct dns_pkt *dns = (struct dns_pkt *) pkt->data;
+ struct dns_pkt_parsed *pdns = parse_dns_packet (dns);
- query_states[dns->s.id].valid = GNUNET_YES;
- query_states[dns->s.id].client = client;
- query_states[dns->s.id].local_ip = pkt->orig_from;
- query_states[dns->s.id].local_port = pkt->src_port;
- query_states[dns->s.id].remote_ip = pkt->orig_to;
- 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);
- query_states[dns->s.id].name =
GNUNET_malloc(query_states[dns->s.id].namelen);
- memcpy(query_states[dns->s.id].name, dns->data,
query_states[dns->s.id].namelen);
+ query_states[dns->s.id].valid = GNUNET_YES;
+ query_states[dns->s.id].client = client;
+ query_states[dns->s.id].local_ip = pkt->orig_from;
+ query_states[dns->s.id].local_port = pkt->src_port;
+ query_states[dns->s.id].remote_ip = pkt->orig_to;
+ 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);
+ query_states[dns->s.id].name =
+ GNUNET_malloc (query_states[dns->s.id].namelen);
+ memcpy (query_states[dns->s.id].name, dns->data,
+ query_states[dns->s.id].namelen);
- /* The query is for a .gnunet-address */
- if (pdns->queries[0]->namelen > 9 &&
- 0 == strncmp(pdns->queries[0]->name+(pdns->queries[0]->namelen - 9),
".gnunet.", 9))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Query for .gnunet!\n");
- GNUNET_HashCode key;
- GNUNET_CRYPTO_hash(pdns->queries[0]->name, pdns->queries[0]->namelen,
&key);
+ /* The query is for a .gnunet-address */
+ if (pdns->queries[0]->namelen > 9 &&
+ 0 == strncmp (pdns->queries[0]->name + (pdns->queries[0]->namelen - 9),
+ ".gnunet.", 9))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Query for .gnunet!\n");
+ GNUNET_HashCode key;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Getting with key %08x, len is %d\n",
- *((unsigned int*)&key),
- pdns->queries[0]->namelen);
+ GNUNET_CRYPTO_hash (pdns->queries[0]->name, pdns->queries[0]->namelen,
+ &key);
- struct receive_dht_cls* cls = GNUNET_malloc(sizeof(struct
receive_dht_cls));
- cls->id = dns->s.id;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Getting with key %08x, len is %d\n",
+ *((unsigned int *) &key), pdns->queries[0]->namelen);
- cls->handle = GNUNET_DHT_get_start(dht,
- GNUNET_TIME_UNIT_MINUTES,
- GNUNET_BLOCK_TYPE_DNS,
- &key,
- DEFAULT_GET_REPLICATION,
- GNUNET_DHT_RO_NONE,
- NULL,
- 0,
- NULL,
- 0,
- receive_dht,
- cls);
+ struct receive_dht_cls *cls =
+ GNUNET_malloc (sizeof (struct receive_dht_cls));
+ cls->id = dns->s.id;
- goto outfree;
- }
+ cls->handle = GNUNET_DHT_get_start (dht,
+ GNUNET_TIME_UNIT_MINUTES,
+ GNUNET_BLOCK_TYPE_DNS,
+ &key,
+ DEFAULT_GET_REPLICATION,
+ GNUNET_DHT_RO_NONE,
+ NULL, 0, NULL, 0, receive_dht, cls);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Query for '%s'; namelen=%d\n",
pdns->queries[0]->name, pdns->queries[0]->namelen);
+ goto outfree;
+ }
- /* This is a PTR-Query. Check if it is for "our" network */
- if (htons(pdns->queries[0]->qtype) == 12 &&
- 74 == pdns->queries[0]->namelen)
- {
- char* ipv6addr;
- char ipv6[16];
- char ipv6rev[74] =
"X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.ip6.arpa.";
- unsigned int i;
- unsigned long long ipv6prefix;
- unsigned int comparelen;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Query for '%s'; namelen=%d\n",
+ pdns->queries[0]->name, pdns->queries[0]->namelen);
- GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg,
"vpn", "IPV6ADDR", &ipv6addr));
- inet_pton (AF_INET6, ipv6addr, ipv6);
- GNUNET_free(ipv6addr);
+ /* This is a PTR-Query. Check if it is for "our" network */
+ if (htons (pdns->queries[0]->qtype) == 12 && 74 == pdns->queries[0]->namelen)
+ {
+ char *ipv6addr;
+ char ipv6[16];
+ char ipv6rev[74] =
+
"X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.ip6.arpa.";
+ unsigned int i;
+ unsigned long long ipv6prefix;
+ unsigned int comparelen;
- GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(cfg,
"vpn", "IPV6PREFIX", &ipv6prefix));
- GNUNET_assert(ipv6prefix < 127);
- ipv6prefix = (ipv6prefix + 7)/8;
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_string (cfg, "vpn",
+ "IPV6ADDR",
+ &ipv6addr));
+ inet_pton (AF_INET6, ipv6addr, ipv6);
+ GNUNET_free (ipv6addr);
- for (i = ipv6prefix; i < 16; i++)
- ipv6[i] = 0;
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_number (cfg, "vpn",
+ "IPV6PREFIX",
+ &ipv6prefix));
+ GNUNET_assert (ipv6prefix < 127);
+ ipv6prefix = (ipv6prefix + 7) / 8;
- for (i = 0; i < 16; i++)
- {
- unsigned char c1 = ipv6[i] >> 4;
- unsigned char c2 = ipv6[i] & 0xf;
+ for (i = ipv6prefix; i < 16; i++)
+ ipv6[i] = 0;
- if (c1 <= 9)
- ipv6rev[62-(4*i)] = c1 + '0';
- else
- ipv6rev[62-(4*i)] = c1 + 87; /* 87 is the difference between 'a'
and 10 */
+ for (i = 0; i < 16; i++)
+ {
+ unsigned char c1 = ipv6[i] >> 4;
+ unsigned char c2 = ipv6[i] & 0xf;
- if (c2 <= 9)
- ipv6rev[62-((4*i)+2)] = c2 + '0';
- else
- ipv6rev[62-((4*i)+2)] = c2 + 87;
- }
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "My network is %s'.\n", ipv6rev);
- comparelen = 10 + 4*ipv6prefix;
- if(0 == strncmp(pdns->queries[0]->name+(pdns->queries[0]->namelen -
comparelen),
- ipv6rev + (74 - comparelen),
- comparelen))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Reverse-Query for
.gnunet!\n");
+ if (c1 <= 9)
+ ipv6rev[62 - (4 * i)] = c1 + '0';
+ else
+ ipv6rev[62 - (4 * i)] = c1 + 87; /* 87 is the difference
between 'a' and 10 */
- GNUNET_SCHEDULER_add_now(send_rev_query, pdns);
+ if (c2 <= 9)
+ ipv6rev[62 - ((4 * i) + 2)] = c2 + '0';
+ else
+ ipv6rev[62 - ((4 * i) + 2)] = c2 + 87;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "My network is %s'.\n", ipv6rev);
+ comparelen = 10 + 4 * ipv6prefix;
+ if (0 ==
+ strncmp (pdns->queries[0]->name +
+ (pdns->queries[0]->namelen - comparelen),
+ ipv6rev + (74 - comparelen), comparelen))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Reverse-Query for .gnunet!\n");
- goto out;
- }
- }
+ GNUNET_SCHEDULER_add_now (send_rev_query, pdns);
- char* virt_dns;
- unsigned int virt_dns_bytes;
- 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);
- }
+ goto out;
+ }
+ }
- 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;
+ unsigned int virt_dns_bytes;
- GNUNET_free(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 (virt_dns_bytes == pkt->orig_to)
- {
- /* This is a packet that was sent directly to the virtual dns-server
- *
- * This means we have to send this query over gnunet
- */
+ 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);
+ }
- 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);
- cls_->hdr.size = size - sizeof(struct GNUNET_MESH_Tunnel*);
+ GNUNET_free (virt_dns);
- cls_->hdr.type = ntohs(GNUNET_MESSAGE_TYPE_VPN_REMOTE_QUERY_DNS);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "size: %d\n", size);
+ if (virt_dns_bytes == pkt->orig_to)
+ {
+ /* This is a packet that was sent directly to the virtual dns-server
+ *
+ * This means we have to send this query over gnunet
+ */
- memcpy(&cls_->dns, dns, cls_->hdr.size - sizeof(struct
GNUNET_MessageHeader));
- GNUNET_SCHEDULER_add_now(send_mesh_query, cls_);
+ 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);
- goto outfree;
- }
+ 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);
- /* The query should be sent to the network */
+ memcpy (&cls_->dns, dns,
+ cls_->hdr.size - sizeof (struct GNUNET_MessageHeader));
+ GNUNET_SCHEDULER_add_now (send_mesh_query, cls_);
- struct sockaddr_in dest;
- memset(&dest, 0, sizeof dest);
- dest.sin_port = htons(53);
- dest.sin_addr.s_addr = pkt->orig_to;
+ goto outfree;
+ }
- GNUNET_NETWORK_socket_sendto(dnsout,
- dns,
- ntohs(pkt->hdr.size) - sizeof(struct
query_packet) + 1,
- (struct sockaddr*) &dest,
- sizeof dest);
+ /* The query should be sent to the network */
+
+ struct sockaddr_in dest;
+
+ memset (&dest, 0, sizeof dest);
+ dest.sin_port = htons (53);
+ dest.sin_addr.s_addr = pkt->orig_to;
+
+ GNUNET_NETWORK_socket_sendto (dnsout,
+ dns,
+ ntohs (pkt->hdr.size) -
+ sizeof (struct query_packet) + 1,
+ (struct sockaddr *) &dest, sizeof dest);
+
outfree:
- free_parsed_dns_packet(pdns);
- pdns = NULL;
+ free_parsed_dns_packet (pdns);
+ pdns = NULL;
out:
- GNUNET_SERVER_receive_done(client, GNUNET_OK);
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
static void read_response (void *cls,
@@ -900,14 +955,14 @@
sizeof (struct sockaddr_in));
if (err != GNUNET_OK)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Could not bind a port: %m\n");
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not bind a port: %m\n");
+ return GNUNET_SYSERR;
+ }
/* Read the port we bound to */
socklen_t addrlen = sizeof (struct sockaddr_in);
+
err = getsockname (GNUNET_NETWORK_get_fd (dnsout),
(struct sockaddr *) &addr, &addrlen);
@@ -941,12 +996,12 @@
#ifndef MINGW
if (0 != ioctl (GNUNET_NETWORK_get_fd (dnsout), FIONREAD, &len))
- {
- unhijack (dnsoutport);
- if (GNUNET_YES == open_port ())
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, hijack, NULL);
- return;
- }
+ {
+ unhijack (dnsoutport);
+ if (GNUNET_YES == open_port ())
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, hijack, NULL);
+ return;
+ }
#else
/* port the code above? */
len = 65536;
@@ -961,83 +1016,90 @@
(struct sockaddr *) &addr, &addrlen);
if (r < 0)
- {
- unhijack (dnsoutport);
- if (GNUNET_YES == open_port ())
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, hijack,
NULL);
- return;
- }
+ {
+ unhijack (dnsoutport);
+ if (GNUNET_YES == open_port ())
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, hijack, NULL);
+ return;
+ }
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Answer to query %d\n",
ntohs(dns->s.id));
+ 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)
{
- 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);
- if (NULL ==
- GNUNET_MESH_tunnel_get_data (query_states[dns->s.id].tunnel))
- {
- struct GNUNET_MESH_TransmitHandle *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);
- GNUNET_MESH_tunnel_set_data (query_states[dns->s.id].tunnel,
- th);
- }
- else
- {
- struct tunnel_notify_queue* head =
GNUNET_MESH_tunnel_get_head(query_states[dns->s.id].tunnel);
- struct tunnel_notify_queue* tail =
GNUNET_MESH_tunnel_get_tail(query_states[dns->s.id].tunnel);
+ 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);
- 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;
+ *t = query_states[dns->s.id].tunnel;
+ memcpy (t + 1, dns, r);
+ if (NULL ==
+ GNUNET_MESH_tunnel_get_data (query_states[dns->s.id].tunnel))
+ {
+ struct GNUNET_MESH_TransmitHandle *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);
- GNUNET_CONTAINER_DLL_insert_tail(head, tail, element);
- GNUNET_MESH_tunnel_set_head(query_states[dns->s.id].tunnel,
head);
- GNUNET_MESH_tunnel_set_tail(query_states[dns->s.id].tunnel,
tail);
- }
- }
+ GNUNET_MESH_tunnel_set_data (query_states[dns->s.id].tunnel, th);
+ }
else
- {
- query_states[dns->s.id].valid = GNUNET_NO;
+ {
+ struct tunnel_notify_queue *head =
+ GNUNET_MESH_tunnel_get_head (query_states[dns->s.id].tunnel);
+ struct tunnel_notify_queue *tail =
+ GNUNET_MESH_tunnel_get_tail (query_states[dns->s.id].tunnel);
- size_t len = sizeof (struct answer_packet) + r - 1; /* 1 for the
unsigned char data[1]; */
- struct answer_packet_list *answer =
- GNUNET_malloc (len + 2 * sizeof (struct answer_packet_list *));
- 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.from = addr.sin_addr.s_addr;
- answer->pkt.to = query_states[dns->s.id].local_ip;
- answer->pkt.dst_port = query_states[dns->s.id].local_port;
- memcpy (answer->pkt.data, buf, r);
+ 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_after (head, tail, tail, answer);
+ GNUNET_CONTAINER_DLL_insert_tail (head, tail, element);
+ GNUNET_MESH_tunnel_set_head (query_states[dns->s.id].tunnel, head);
+ GNUNET_MESH_tunnel_set_tail (query_states[dns->s.id].tunnel, tail);
+ }
+ }
+ else
+ {
+ query_states[dns->s.id].valid = GNUNET_NO;
- GNUNET_SERVER_notify_transmit_ready (query_states
- [dns->s.id].client, len,
- GNUNET_TIME_UNIT_FOREVER_REL,
- &send_answer,
- query_states[dns->s.
- id].client);
- }
+ size_t len = sizeof (struct answer_packet) + r - 1; /* 1 for the
unsigned char data[1]; */
+ struct answer_packet_list *answer =
+ GNUNET_malloc (len + 2 * sizeof (struct answer_packet_list *));
+ 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.from = addr.sin_addr.s_addr;
+ answer->pkt.to = query_states[dns->s.id].local_ip;
+ answer->pkt.dst_port = query_states[dns->s.id].local_port;
+ memcpy (answer->pkt.data, buf, r);
+
+ GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, answer);
+
+ GNUNET_SERVER_notify_transmit_ready (query_states
+ [dns->s.id].client, len,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &send_answer,
+ query_states[dns->s.id].client);
}
+ }
}
GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
dnsout, &read_response, NULL);
@@ -1051,14 +1113,14 @@
* @param tc unused
*/
static void
-cleanup_task (void *cls __attribute__((unused)),
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+cleanup_task (void *cls __attribute__ ((unused)),
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- GNUNET_assert(0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN));
+ GNUNET_assert (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN));
- unhijack(dnsoutport);
- GNUNET_DHT_disconnect(dht);
- GNUNET_MESH_disconnect(mesh_handle);
+ unhijack (dnsoutport);
+ GNUNET_DHT_disconnect (dht);
+ GNUNET_MESH_disconnect (mesh_handle);
}
/**
@@ -1073,70 +1135,78 @@
get_port_from_redirects (const char *udp_redirects, const char *tcp_redirects)
{
uint64_t ret = 0;
- char* cpy, *hostname, *redirect;
+ char *cpy, *hostname, *redirect;
int local_port, count = 0;
if (NULL != udp_redirects)
+ {
+ cpy = GNUNET_strdup (udp_redirects);
+ for (redirect = strtok (cpy, " "); redirect != NULL;
+ redirect = strtok (NULL, " "))
{
- cpy = GNUNET_strdup (udp_redirects);
- for (redirect = strtok (cpy, " "); redirect != NULL; redirect = strtok
(NULL, " "))
- {
- if (NULL == (hostname = strstr (redirect, ":")))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Warning: option %s is not
formatted correctly!\n", redirect);
- continue;
- }
- hostname[0] = '\0';
- local_port = atoi (redirect);
- if (!((local_port > 0) && (local_port < 65536)))
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Warning: %s is not a
correct port.", redirect);
+ if (NULL == (hostname = strstr (redirect, ":")))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Warning: option %s is not formatted correctly!\n",
+ redirect);
+ continue;
+ }
+ hostname[0] = '\0';
+ local_port = atoi (redirect);
+ if (!((local_port > 0) && (local_port < 65536)))
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Warning: %s is not a correct port.", redirect);
- ret |= (0xFFFF & htons(local_port));
- ret <<= 16;
- count ++;
+ ret |= (0xFFFF & htons (local_port));
+ ret <<= 16;
+ count++;
- if(count > 4)
- {
- ret = 0;
- goto out;
- }
- }
- GNUNET_free(cpy);
- cpy = NULL;
+ if (count > 4)
+ {
+ ret = 0;
+ goto out;
+ }
}
+ GNUNET_free (cpy);
+ cpy = NULL;
+ }
if (NULL != tcp_redirects)
+ {
+ cpy = GNUNET_strdup (tcp_redirects);
+ for (redirect = strtok (cpy, " "); redirect != NULL;
+ redirect = strtok (NULL, " "))
{
- cpy = GNUNET_strdup (tcp_redirects);
- for (redirect = strtok (cpy, " "); redirect != NULL; redirect = strtok
(NULL, " "))
- {
- if (NULL == (hostname = strstr (redirect, ":")))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Warning: option %s is not
formatted correctly!\n", redirect);
- continue;
- }
- hostname[0] = '\0';
- local_port = atoi (redirect);
- if (!((local_port > 0) && (local_port < 65536)))
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Warning: %s is not a
correct port.", redirect);
+ if (NULL == (hostname = strstr (redirect, ":")))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Warning: option %s is not formatted correctly!\n",
+ redirect);
+ continue;
+ }
+ hostname[0] = '\0';
+ local_port = atoi (redirect);
+ if (!((local_port > 0) && (local_port < 65536)))
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Warning: %s is not a correct port.", redirect);
- ret |= (0xFFFF & htons(local_port));
- ret <<= 16;
- count ++;
+ ret |= (0xFFFF & htons (local_port));
+ ret <<= 16;
+ count++;
- if(count > 4)
- {
- ret = 0;
- goto out;
- }
- }
- GNUNET_free(cpy);
- cpy = NULL;
+ if (count > 4)
+ {
+ ret = 0;
+ goto out;
+ }
}
+ GNUNET_free (cpy);
+ cpy = NULL;
+ }
out:
if (NULL != cpy)
- GNUNET_free(cpy);
+ GNUNET_free (cpy);
return ret;
}
@@ -1146,10 +1216,10 @@
{
size_t size = sizeof (struct GNUNET_DNS_Record);
struct GNUNET_DNS_Record data;
+
memset (&data, 0, size);
- data.purpose.size =
- htonl (size - sizeof (struct GNUNET_CRYPTO_RsaSignature));
+ data.purpose.size = htonl (size - sizeof (struct
GNUNET_CRYPTO_RsaSignature));
data.purpose.purpose = GNUNET_SIGNATURE_PURPOSE_DNS_RECORD;
GNUNET_CRYPTO_hash (name, strlen (name) + 1, &data.service_descriptor);
@@ -1162,15 +1232,16 @@
GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &data.peer);
data.expiration_time =
- GNUNET_TIME_relative_to_absolute
(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, 2));
+ GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_HOURS, 2));
/* Sign the block */
if (GNUNET_OK != GNUNET_CRYPTO_rsa_sign (my_private_key,
&data.purpose, &data.signature))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "could not sign DNS_Record\n");
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "could not sign DNS_Record\n");
+ return;
+ }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Putting with key %08x, size = %d\n",
@@ -1194,15 +1265,16 @@
* @param section the current section
*/
void
-publish_iterate (void *cls __attribute__((unused)), const char *section)
+publish_iterate (void *cls __attribute__ ((unused)), const char *section)
{
- if ((strlen(section) < 8) || (0 != strcmp (".gnunet.", section +
(strlen(section) - 8))))
+ if ((strlen (section) < 8) ||
+ (0 != strcmp (".gnunet.", section + (strlen (section) - 8))))
return;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Parsing dns-name %s\n", section);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Parsing dns-name %s\n", section);
char *udp_redirects, *tcp_redirects, *alternative_names, *alternative_name,
- *keyfile;
+ *keyfile;
GNUNET_CONFIGURATION_get_value_string (cfg, section,
"UDP_REDIRECTS", &udp_redirects);
@@ -1212,15 +1284,15 @@
if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "GNUNETD",
"HOSTKEY",
&keyfile))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "could not read keyfile-value\n");
- if (keyfile != NULL)
- GNUNET_free (keyfile);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "could not read keyfile-value\n");
+ if (keyfile != NULL)
+ GNUNET_free (keyfile);
+ return;
+ }
struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key =
- GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
+ GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
GNUNET_free (keyfile);
GNUNET_assert (my_private_key != NULL);
@@ -1243,17 +1315,17 @@
&alternative_names);
for (alternative_name = strtok (alternative_names, " ");
alternative_name != NULL; alternative_name = strtok (NULL, " "))
- {
- char *altname =
+ {
+ char *altname =
alloca (strlen (alternative_name) + strlen (section) + 1 + 1);
- strcpy (altname, alternative_name);
- strcpy (altname + strlen (alternative_name) + 1, section);
- altname[strlen (alternative_name)] = '.';
+ strcpy (altname, alternative_name);
+ strcpy (altname + strlen (alternative_name) + 1, section);
+ altname[strlen (alternative_name)] = '.';
- publish_name (altname, ports, service_type, my_private_key);
- }
+ publish_name (altname, ports, service_type, my_private_key);
+ }
- GNUNET_free_non_null(alternative_names);
+ GNUNET_free_non_null (alternative_names);
GNUNET_CRYPTO_rsa_key_free (my_private_key);
GNUNET_free_non_null (udp_redirects);
GNUNET_free_non_null (tcp_redirects);
@@ -1263,16 +1335,15 @@
* Publish a DNS-record in the DHT.
*/
static void
-publish_names (void *cls __attribute__((unused)),
- const struct GNUNET_SCHEDULER_TaskContext *tc) {
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
+publish_names (void *cls __attribute__ ((unused)),
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
+ return;
- GNUNET_CONFIGURATION_iterate_sections(cfg, publish_iterate, NULL);
+ GNUNET_CONFIGURATION_iterate_sections (cfg, publish_iterate, NULL);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_HOURS,
- publish_names,
- NULL);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_HOURS, publish_names, NULL);
}
/**
@@ -1299,35 +1370,31 @@
{NULL, 0, 0}
};
- static GNUNET_MESH_ApplicationType *apptypes;
+ static GNUNET_MESH_ApplicationType apptypes[] = {
+ GNUNET_APPLICATION_TYPE_END,
+ GNUNET_APPLICATION_TYPE_END
+ };
+
if (GNUNET_YES != open_port ())
- {
- GNUNET_SCHEDULER_shutdown();
- return;
- }
+ {
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
if (GNUNET_YES ==
GNUNET_CONFIGURATION_get_value_yesno (cfg_, "dns", "PROVIDE_EXIT"))
- apptypes = (GNUNET_MESH_ApplicationType[])
- {
- GNUNET_APPLICATION_TYPE_INTERNET_RESOLVER,
- GNUNET_APPLICATION_TYPE_END};
- else
- apptypes = (GNUNET_MESH_ApplicationType[])
- {
- GNUNET_APPLICATION_TYPE_END};
+ apptypes[0] = GNUNET_APPLICATION_TYPE_INTERNET_RESOLVER;
+ mesh_handle = GNUNET_MESH_connect (cfg_, NULL, NULL, mesh_handlers,
apptypes);
- mesh_handle =
- GNUNET_MESH_connect (cfg_, NULL, NULL, mesh_handlers, apptypes);
-
cfg = cfg_;
unsigned int i;
+
for (i = 0; i < 65536; i++)
- {
- query_states[i].valid = GNUNET_NO;
- }
+ {
+ query_states[i].valid = GNUNET_NO;
+ }
dht = GNUNET_DHT_connect (cfg, 1024);
@@ -1349,9 +1416,8 @@
main (int argc, char *const *argv)
{
return (GNUNET_OK ==
- GNUNET_SERVICE_run (argc,
- argv,
- "dns",
- GNUNET_SERVICE_OPTION_NONE,
- &run, NULL)) ? 0 : 1;
+ GNUNET_SERVICE_run (argc,
+ argv,
+ "dns",
+ GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
}
Modified: gnunet/src/vpn/gnunet-vpn-checksum.c
===================================================================
--- gnunet/src/vpn/gnunet-vpn-checksum.c 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/vpn/gnunet-vpn-checksum.c 2011-08-15 21:46:35 UTC (rev
16581)
@@ -26,26 +26,32 @@
#include "gnunet-vpn-checksum.h"
-uint32_t calculate_checksum_update(uint32_t sum, uint16_t *hdr, short len) {
- for(; len >= 2; len -= 2)
- sum += *(hdr++);
- if (len == 1)
- sum += *((unsigned char*)hdr);
- return sum;
+uint32_t
+calculate_checksum_update (uint32_t sum, uint16_t * hdr, short len)
+{
+ for (; len >= 2; len -= 2)
+ sum += *(hdr++);
+ if (len == 1)
+ sum += *((unsigned char *) hdr);
+ return sum;
}
-uint16_t calculate_checksum_end(uint32_t sum) {
- while (sum >> 16)
- sum = (sum >> 16) + (sum & 0xFFFF);
+uint16_t
+calculate_checksum_end (uint32_t sum)
+{
+ while (sum >> 16)
+ sum = (sum >> 16) + (sum & 0xFFFF);
- return ~sum;
+ return ~sum;
}
/**
* Calculate the checksum of an IPv4-Header
*/
uint16_t
-calculate_ip_checksum(uint16_t* hdr, short len) {
- uint32_t sum = calculate_checksum_update(0, hdr, len);
- return calculate_checksum_end(sum);
+calculate_ip_checksum (uint16_t * hdr, short len)
+{
+ uint32_t sum = calculate_checksum_update (0, hdr, len);
+
+ return calculate_checksum_end (sum);
}
Modified: gnunet/src/vpn/gnunet-vpn-checksum.h
===================================================================
--- gnunet/src/vpn/gnunet-vpn-checksum.h 2011-08-15 21:40:08 UTC (rev
16580)
+++ gnunet/src/vpn/gnunet-vpn-checksum.h 2011-08-15 21:46:35 UTC (rev
16581)
@@ -4,13 +4,13 @@
#include <platform.h>
-uint32_t calculate_checksum_update(uint32_t sum, uint16_t *hdr, short len);
+uint32_t calculate_checksum_update (uint32_t sum, uint16_t * hdr, short len);
-uint16_t calculate_checksum_end(uint32_t sum);
+uint16_t calculate_checksum_end (uint32_t sum);
/**
* Calculate the checksum of an IPv4-Header
*/
-uint16_t calculate_ip_checksum(uint16_t* hdr, short len);
+uint16_t calculate_ip_checksum (uint16_t * hdr, short len);
#endif /* end of include guard: GNUNET-VPN-CHECKSUM_H */
Modified: gnunet/src/vpn/gnunet-vpn-packet.h
===================================================================
--- gnunet/src/vpn/gnunet-vpn-packet.h 2011-08-15 21:40:08 UTC (rev 16580)
+++ gnunet/src/vpn/gnunet-vpn-packet.h 2011-08-15 21:46:35 UTC (rev 16581)
@@ -5,221 +5,246 @@
#include "gnunet_common.h"
// Headers
-struct pkt_tun {
- unsigned flags:16 GNUNET_PACKED;
- unsigned type:16 GNUNET_PACKED;
+struct pkt_tun
+{
+ unsigned flags:16 GNUNET_PACKED;
+ unsigned type:16 GNUNET_PACKED;
};
-struct ip6_hdr {
- unsigned tclass_h:4 GNUNET_PACKED;
- unsigned version:4 GNUNET_PACKED;
- unsigned tclass_l:4 GNUNET_PACKED;
- unsigned flowlbl:20 GNUNET_PACKED;
- unsigned paylgth:16 GNUNET_PACKED;
- unsigned nxthdr:8 GNUNET_PACKED;
- unsigned hoplmt:8 GNUNET_PACKED;
- unsigned char sadr[16];
- unsigned char dadr[16];
+struct ip6_hdr
+{
+ unsigned tclass_h:4 GNUNET_PACKED;
+ unsigned version:4 GNUNET_PACKED;
+ unsigned tclass_l:4 GNUNET_PACKED;
+ unsigned flowlbl:20 GNUNET_PACKED;
+ unsigned paylgth:16 GNUNET_PACKED;
+ unsigned nxthdr:8 GNUNET_PACKED;
+ unsigned hoplmt:8 GNUNET_PACKED;
+ unsigned char sadr[16];
+ unsigned char dadr[16];
};
-struct ip_hdr {
- unsigned hdr_lngth:4 GNUNET_PACKED;
- unsigned version:4 GNUNET_PACKED;
+struct ip_hdr
+{
+ unsigned hdr_lngth:4 GNUNET_PACKED;
+ unsigned version:4 GNUNET_PACKED;
- unsigned diff_serv:8 GNUNET_PACKED;
- unsigned tot_lngth:16 GNUNET_PACKED;
+ unsigned diff_serv:8 GNUNET_PACKED;
+ unsigned tot_lngth:16 GNUNET_PACKED;
- unsigned ident:16 GNUNET_PACKED;
- unsigned flags:3 GNUNET_PACKED;
- unsigned frag_off:13 GNUNET_PACKED;
+ unsigned ident:16 GNUNET_PACKED;
+ unsigned flags:3 GNUNET_PACKED;
+ unsigned frag_off:13 GNUNET_PACKED;
- unsigned ttl:8 GNUNET_PACKED;
- unsigned proto:8 GNUNET_PACKED;
- unsigned chks:16 GNUNET_PACKED;
+ unsigned ttl:8 GNUNET_PACKED;
+ unsigned proto:8 GNUNET_PACKED;
+ unsigned chks:16 GNUNET_PACKED;
- unsigned sadr:32 GNUNET_PACKED;
- unsigned dadr:32 GNUNET_PACKED;
+ unsigned sadr:32 GNUNET_PACKED;
+ unsigned dadr:32 GNUNET_PACKED;
};
#define TCP_FLAG_SYN 2
-struct tcp_pkt {
- unsigned spt:16 GNUNET_PACKED;
- unsigned dpt:16 GNUNET_PACKED;
- unsigned seq:32 GNUNET_PACKED;
- unsigned ack:32 GNUNET_PACKED;
- unsigned off:4 GNUNET_PACKED;
- unsigned rsv:4 GNUNET_PACKED;
- unsigned flg:8 GNUNET_PACKED;
- unsigned wsz:16 GNUNET_PACKED;
- unsigned crc:16 GNUNET_PACKED;
- unsigned urg:16 GNUNET_PACKED;
+struct tcp_pkt
+{
+ unsigned spt:16 GNUNET_PACKED;
+ unsigned dpt:16 GNUNET_PACKED;
+ unsigned seq:32 GNUNET_PACKED;
+ unsigned ack:32 GNUNET_PACKED;
+ unsigned off:4 GNUNET_PACKED;
+ unsigned rsv:4 GNUNET_PACKED;
+ unsigned flg:8 GNUNET_PACKED;
+ unsigned wsz:16 GNUNET_PACKED;
+ unsigned crc:16 GNUNET_PACKED;
+ unsigned urg:16 GNUNET_PACKED;
};
-struct udp_pkt {
- unsigned spt:16 GNUNET_PACKED;
- unsigned dpt:16 GNUNET_PACKED;
- unsigned len:16 GNUNET_PACKED;
- unsigned crc:16 GNUNET_PACKED;
+struct udp_pkt
+{
+ unsigned spt:16 GNUNET_PACKED;
+ unsigned dpt:16 GNUNET_PACKED;
+ unsigned len:16 GNUNET_PACKED;
+ unsigned crc:16 GNUNET_PACKED;
};
-struct icmp_hdr {
- unsigned type:8 GNUNET_PACKED;
- unsigned code:8 GNUNET_PACKED;
- unsigned chks:16 GNUNET_PACKED;
+struct icmp_hdr
+{
+ unsigned type:8 GNUNET_PACKED;
+ unsigned code:8 GNUNET_PACKED;
+ unsigned chks:16 GNUNET_PACKED;
};
// DNS-Stuff
-struct dns_static {
- uint16_t id GNUNET_PACKED;
+struct dns_static
+{
+ uint16_t id GNUNET_PACKED;
- unsigned rd:1 GNUNET_PACKED; // recursion desired (client -> server)
- unsigned tc:1 GNUNET_PACKED; // message is truncated
- unsigned aa:1 GNUNET_PACKED; // authoritative answer
- unsigned op:4 GNUNET_PACKED; // query:0, inverse q.:1, status: 2
- unsigned qr:1 GNUNET_PACKED; // query:0, response:1
+ unsigned rd:1 GNUNET_PACKED; // recursion desired (client -> server)
+ unsigned tc:1 GNUNET_PACKED; // message is truncated
+ unsigned aa:1 GNUNET_PACKED; // authoritative answer
+ unsigned op:4 GNUNET_PACKED; // query:0, inverse q.:1, status: 2
+ unsigned qr:1 GNUNET_PACKED; // query:0, response:1
- unsigned rcode:4 GNUNET_PACKED; // 0 No error
- // 1 Format error
- // 2 Server failure
- // 3 Name Error
- // 4 Not Implemented
- // 5 Refused
- unsigned z:3 GNUNET_PACKED; // reserved
- unsigned ra:1 GNUNET_PACKED; // recursion available (server -> client)
+ unsigned rcode:4 GNUNET_PACKED; // 0 No error
+ // 1 Format error
+ // 2 Server failure
+ // 3 Name Error
+ // 4 Not Implemented
+ // 5 Refused
+ unsigned z:3 GNUNET_PACKED; // reserved
+ unsigned ra:1 GNUNET_PACKED; // recursion available (server -> client)
- uint16_t qdcount GNUNET_PACKED; // number of questions
- uint16_t ancount GNUNET_PACKED; // number of answers
- uint16_t nscount GNUNET_PACKED; // number of authority-records
- uint16_t arcount GNUNET_PACKED; // number of additional records
+ uint16_t qdcount GNUNET_PACKED; // number of questions
+ uint16_t ancount GNUNET_PACKED; // number of answers
+ uint16_t nscount GNUNET_PACKED; // number of authority-records
+ uint16_t arcount GNUNET_PACKED; // number of additional records
};
-struct dns_pkt {
- struct dns_static s;
- unsigned char data[1];
+struct dns_pkt
+{
+ struct dns_static s;
+ unsigned char data[1];
};
-struct dns_pkt_parsed {
- struct dns_static s;
- struct dns_query** queries;
- struct dns_record** answers;
- struct dns_record** nameservers;
- struct dns_record** additional;
+struct dns_pkt_parsed
+{
+ struct dns_static s;
+ struct dns_query **queries;
+ struct dns_record **answers;
+ struct dns_record **nameservers;
+ struct dns_record **additional;
};
-struct dns_query_line {
- unsigned short type;
- unsigned short class;
+struct dns_query_line
+{
+ unsigned short type;
+ unsigned short class;
};
-struct dns_query {
- char* name;
- unsigned char namelen;
- unsigned short qtype;
- unsigned short qclass;
+struct dns_query
+{
+ char *name;
+ unsigned char namelen;
+ unsigned short qtype;
+ unsigned short qclass;
};
-struct dns_record_line {
- unsigned short type;
- unsigned short class;
- unsigned int ttl;
- unsigned short data_len;
- unsigned char data;
+struct dns_record_line
+{
+ unsigned short type;
+ unsigned short class;
+ unsigned int ttl;
+ unsigned short data_len;
+ unsigned char data;
};
-struct dns_record {
- char* name;
- unsigned char namelen;
- unsigned short type;
- unsigned short class;
- unsigned int ttl;
- unsigned short data_len;
- unsigned char* data;
+struct dns_record
+{
+ char *name;
+ unsigned char namelen;
+ unsigned short type;
+ unsigned short class;
+ unsigned int ttl;
+ unsigned short data_len;
+ unsigned char *data;
};
-struct udp_dns {
- struct udp_pkt udp_hdr;
- struct dns_pkt data;
+struct udp_dns
+{
+ struct udp_pkt udp_hdr;
+ struct dns_pkt data;
};
// Complete Packets
-struct tun_pkt {
- struct GNUNET_MessageHeader shdr;
- struct pkt_tun tun;
+struct tun_pkt
+{
+ struct GNUNET_MessageHeader shdr;
+ struct pkt_tun tun;
};
-struct ip6_pkt {
- struct GNUNET_MessageHeader shdr;
- struct pkt_tun tun;
- struct ip6_hdr ip6_hdr;
- unsigned char data[1];
+struct ip6_pkt
+{
+ struct GNUNET_MessageHeader shdr;
+ struct pkt_tun tun;
+ struct ip6_hdr ip6_hdr;
+ unsigned char data[1];
};
-struct ip6_tcp {
- struct GNUNET_MessageHeader shdr;
- struct pkt_tun tun;
- struct ip6_hdr ip6_hdr;
- struct tcp_pkt tcp_hdr;
- unsigned char data[1];
+struct ip6_tcp
+{
+ struct GNUNET_MessageHeader shdr;
+ struct pkt_tun tun;
+ struct ip6_hdr ip6_hdr;
+ struct tcp_pkt tcp_hdr;
+ unsigned char data[1];
};
-struct ip6_icmp {
- struct GNUNET_MessageHeader shdr;
- struct pkt_tun tun;
- struct ip6_hdr ip6_hdr;
- struct icmp_hdr icmp_hdr;
+struct ip6_icmp
+{
+ struct GNUNET_MessageHeader shdr;
+ struct pkt_tun tun;
+ struct ip6_hdr ip6_hdr;
+ struct icmp_hdr icmp_hdr;
};
-struct ip6_udp {
- struct GNUNET_MessageHeader shdr;
- struct pkt_tun tun;
- struct ip6_hdr ip6_hdr;
- struct udp_pkt udp_hdr;
- unsigned char data[1];
+struct ip6_udp
+{
+ struct GNUNET_MessageHeader shdr;
+ struct pkt_tun tun;
+ struct ip6_hdr ip6_hdr;
+ struct udp_pkt udp_hdr;
+ unsigned char data[1];
};
-struct ip6_udp_dns {
- struct GNUNET_MessageHeader shdr;
- struct pkt_tun tun;
- struct ip6_hdr ip6_hdr;
- struct udp_dns udp_dns;
+struct ip6_udp_dns
+{
+ struct GNUNET_MessageHeader shdr;
+ struct pkt_tun tun;
+ struct ip6_hdr ip6_hdr;
+ struct udp_dns udp_dns;
};
-struct ip_pkt {
- struct GNUNET_MessageHeader shdr;
- struct pkt_tun tun;
- struct ip_hdr ip_hdr;
- unsigned char data[1];
+struct ip_pkt
+{
+ struct GNUNET_MessageHeader shdr;
+ struct pkt_tun tun;
+ struct ip_hdr ip_hdr;
+ unsigned char data[1];
};
-struct ip_udp {
- struct GNUNET_MessageHeader shdr;
- struct pkt_tun tun;
- struct ip_hdr ip_hdr;
- struct udp_pkt udp_hdr;
- unsigned char data[1];
+struct ip_udp
+{
+ struct GNUNET_MessageHeader shdr;
+ struct pkt_tun tun;
+ struct ip_hdr ip_hdr;
+ struct udp_pkt udp_hdr;
+ unsigned char data[1];
};
-struct ip_udp_dns {
- struct GNUNET_MessageHeader shdr;
- struct pkt_tun tun;
- struct ip_hdr ip_hdr;
- struct udp_dns udp_dns;
+struct ip_udp_dns
+{
+ struct GNUNET_MessageHeader shdr;
+ struct pkt_tun tun;
+ struct ip_hdr ip_hdr;
+ struct udp_dns udp_dns;
};
-struct ip_tcp {
- struct GNUNET_MessageHeader shdr;
- struct pkt_tun tun;
- struct ip_hdr ip_hdr;
- struct tcp_pkt tcp_hdr;
- unsigned char data[1];
+struct ip_tcp
+{
+ struct GNUNET_MessageHeader shdr;
+ struct pkt_tun tun;
+ struct ip_hdr ip_hdr;
+ struct tcp_pkt tcp_hdr;
+ unsigned char data[1];
};
-struct ip_icmp {
- struct GNUNET_MessageHeader shdr;
- struct pkt_tun tun;
- struct ip_hdr ip_hdr;
- struct icmp_hdr icmp_hdr;
+struct ip_icmp
+{
+ struct GNUNET_MessageHeader shdr;
+ struct pkt_tun tun;
+ struct ip_hdr ip_hdr;
+ struct icmp_hdr icmp_hdr;
};
#endif
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r16581 - in gnunet/src: arm ats block chat core datacache datastore dht dv fragmentation fs hello hostlist include mesh nat nse peerinfo peerinfo-tool statistics template testing topology transport transport/wlan util vpn,
gnunet <=